Cache vdso.so's __kernel_rt_sigreturn location.
PiperOrigin-RevId: 394300607
This commit is contained in:
parent
5da4270a88
commit
702fe7d60d
|
@ -295,15 +295,7 @@ func Load(ctx context.Context, args LoadArgs, extraAuxv []arch.AuxEntry, vdso *V
|
||||||
m.SetEnvvEnd(sl.EnvvEnd)
|
m.SetEnvvEnd(sl.EnvvEnd)
|
||||||
m.SetAuxv(auxv)
|
m.SetAuxv(auxv)
|
||||||
m.SetExecutable(ctx, file)
|
m.SetExecutable(ctx, file)
|
||||||
|
m.SetVDSOSigReturn(uint64(vdsoAddr) + vdsoSigreturnOffset - vdsoPrelink)
|
||||||
symbolValue, err := getSymbolValueFromVDSO("rt_sigreturn")
|
|
||||||
if err != nil {
|
|
||||||
return 0, nil, "", syserr.NewDynamic(fmt.Sprintf("Failed to find rt_sigreturn in vdso: %v", err), syserr.FromError(err).ToLinux())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Found rt_sigretrun.
|
|
||||||
addr := uint64(vdsoAddr) + symbolValue - vdsoPrelink
|
|
||||||
m.SetVDSOSigReturn(addr)
|
|
||||||
|
|
||||||
ac.SetIP(uintptr(loaded.entry))
|
ac.SetIP(uintptr(loaded.entry))
|
||||||
ac.SetStack(uintptr(stack.Bottom))
|
ac.SetStack(uintptr(stack.Bottom))
|
||||||
|
|
|
@ -19,7 +19,6 @@ import (
|
||||||
"debug/elf"
|
"debug/elf"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"gvisor.dev/gvisor/pkg/abi"
|
"gvisor.dev/gvisor/pkg/abi"
|
||||||
"gvisor.dev/gvisor/pkg/context"
|
"gvisor.dev/gvisor/pkg/context"
|
||||||
|
@ -177,27 +176,6 @@ type VDSO struct {
|
||||||
phdrs []elf.ProgHeader `state:".([]elfProgHeader)"`
|
phdrs []elf.ProgHeader `state:".([]elfProgHeader)"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// getSymbolValueFromVDSO returns the specific symbol value in vdso.so.
|
|
||||||
func getSymbolValueFromVDSO(symbol string) (uint64, error) {
|
|
||||||
f, err := elf.NewFile(bytes.NewReader(vdsodata.Binary))
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
syms, err := f.Symbols()
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, sym := range syms {
|
|
||||||
if elf.ST_BIND(sym.Info) != elf.STB_LOCAL && sym.Section != elf.SHN_UNDEF {
|
|
||||||
if strings.Contains(sym.Name, symbol) {
|
|
||||||
return sym.Value, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0, fmt.Errorf("no %v in vdso.so", symbol)
|
|
||||||
}
|
|
||||||
|
|
||||||
// PrepareVDSO validates the system VDSO and returns a VDSO, containing the
|
// PrepareVDSO validates the system VDSO and returns a VDSO, containing the
|
||||||
// param page for updating by the kernel.
|
// param page for updating by the kernel.
|
||||||
func PrepareVDSO(mfp pgalloc.MemoryFileProvider) (*VDSO, error) {
|
func PrepareVDSO(mfp pgalloc.MemoryFileProvider) (*VDSO, error) {
|
||||||
|
@ -388,3 +366,21 @@ func (v *VDSO) Release(ctx context.Context) {
|
||||||
v.ParamPage.DecRef(ctx)
|
v.ParamPage.DecRef(ctx)
|
||||||
v.vdso.DecRef(ctx)
|
v.vdso.DecRef(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var vdsoSigreturnOffset = func() uint64 {
|
||||||
|
f, err := elf.NewFile(bytes.NewReader(vdsodata.Binary))
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Sprintf("failed to parse vdso.so as ELF file: %v", err))
|
||||||
|
}
|
||||||
|
syms, err := f.Symbols()
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Sprintf("failed to read symbols from vdso.so: %v", err))
|
||||||
|
}
|
||||||
|
const sigreturnSymbol = "__kernel_rt_sigreturn"
|
||||||
|
for _, sym := range syms {
|
||||||
|
if elf.ST_BIND(sym.Info) != elf.STB_LOCAL && sym.Section != elf.SHN_UNDEF && sym.Name == sigreturnSymbol {
|
||||||
|
return sym.Value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panic(fmt.Sprintf("no symbol %q in vdso.so", sigreturnSymbol))
|
||||||
|
}()
|
||||||
|
|
Loading…
Reference in New Issue