Add ARM64 support to pkg/sentry/loader
Signed-off-by: Bin Lu <bin.lu@arm.com>
This commit is contained in:
parent
eefa817cfd
commit
ffe45f38e6
|
@ -33,6 +33,8 @@ type Arch int
|
||||||
const (
|
const (
|
||||||
// AMD64 is the x86-64 architecture.
|
// AMD64 is the x86-64 architecture.
|
||||||
AMD64 Arch = iota
|
AMD64 Arch = iota
|
||||||
|
// ARM64 is the aarch64 architecture.
|
||||||
|
ARM64
|
||||||
)
|
)
|
||||||
|
|
||||||
// String implements fmt.Stringer.
|
// String implements fmt.Stringer.
|
||||||
|
@ -40,6 +42,8 @@ func (a Arch) String() string {
|
||||||
switch a {
|
switch a {
|
||||||
case AMD64:
|
case AMD64:
|
||||||
return "amd64"
|
return "amd64"
|
||||||
|
case ARM64:
|
||||||
|
return "arm64"
|
||||||
default:
|
default:
|
||||||
return fmt.Sprintf("Arch(%d)", a)
|
return fmt.Sprintf("Arch(%d)", a)
|
||||||
}
|
}
|
||||||
|
|
|
@ -148,12 +148,17 @@ func parseHeader(ctx context.Context, f *fs.File) (elfInfo, error) {
|
||||||
}
|
}
|
||||||
binary.Unmarshal(hdrBuf, byteOrder, &hdr)
|
binary.Unmarshal(hdrBuf, byteOrder, &hdr)
|
||||||
|
|
||||||
// We only support amd64.
|
// We support amd64 and arm64.
|
||||||
if machine := elf.Machine(hdr.Machine); machine != elf.EM_X86_64 {
|
var a arch.Arch
|
||||||
|
switch machine := elf.Machine(hdr.Machine); machine {
|
||||||
|
case elf.EM_X86_64:
|
||||||
|
a = arch.AMD64
|
||||||
|
case elf.EM_AARCH64:
|
||||||
|
a = arch.ARM64
|
||||||
|
default:
|
||||||
log.Infof("Unsupported ELF machine %d", machine)
|
log.Infof("Unsupported ELF machine %d", machine)
|
||||||
return elfInfo{}, syserror.ENOEXEC
|
return elfInfo{}, syserror.ENOEXEC
|
||||||
}
|
}
|
||||||
a := arch.AMD64
|
|
||||||
|
|
||||||
var sharedObject bool
|
var sharedObject bool
|
||||||
elfType := elf.Type(hdr.Type)
|
elfType := elf.Type(hdr.Type)
|
||||||
|
@ -560,6 +565,12 @@ func loadInitialELF(ctx context.Context, m *mm.MemoryManager, fs *cpuid.FeatureS
|
||||||
return loadedELF{}, nil, err
|
return loadedELF{}, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check Image Compatibility.
|
||||||
|
if arch.Host != info.arch {
|
||||||
|
ctx.Warningf("Found mismatch for platform %s with ELF type %s", arch.Host.String(), info.arch.String())
|
||||||
|
return loadedELF{}, nil, syserror.ENOEXEC
|
||||||
|
}
|
||||||
|
|
||||||
// Create the arch.Context now so we can prepare the mmap layout before
|
// Create the arch.Context now so we can prepare the mmap layout before
|
||||||
// mapping anything.
|
// mapping anything.
|
||||||
ac := arch.New(info.arch, fs)
|
ac := arch.New(info.arch, fs)
|
||||||
|
|
Loading…
Reference in New Issue