proc: adds pointer pinning to call injection (#3787)

This commit adds a new mode to call injection. If the runtime.debugPinner
function is available in the target executable it obtains a pinner by
calling it and then uses it to pin the pointers in the results of call
injection.

This allows the code for call injection to be refactored to execute the
calls in the normal order, since it doesn't need to be concerned with having
space on the target's memory to store intermediate values.

Updates #3310
This commit is contained in:
Alessandro Arzilli
2024-10-04 19:44:57 +02:00
committed by GitHub
parent 52405ba86b
commit 025d47c6e9
11 changed files with 573 additions and 158 deletions

View File

@ -89,6 +89,8 @@ const (
// variableTrustLen means that when this variable is loaded its length
// should be trusted and used instead of MaxArrayValues
variableTrustLen
variableSaved
)
// Variable represents a variable. It contains the address, name,
@ -1235,7 +1237,7 @@ func (v *Variable) maybeDereference() *Variable {
switch t := v.RealType.(type) {
case *godwarf.PtrType:
if v.Addr == 0 && len(v.Children) == 1 && v.loaded {
if (v.Addr == 0 || v.Flags&VariableFakeAddress != 0) && len(v.Children) == 1 && v.loaded {
// fake pointer variable constructed by casting an integer to a pointer type
return &v.Children[0]
}
@ -1469,7 +1471,7 @@ func convertToEface(srcv, dstv *Variable) error {
}
typeAddr, typeKind, runtimeTypeFound, err := dwarfToRuntimeType(srcv.bi, srcv.mem, srcv.RealType)
if err != nil {
return err
return fmt.Errorf("can not convert value of type %s to %s: %v", srcv.DwarfType.String(), dstv.DwarfType.String(), err)
}
if !runtimeTypeFound || typeKind&kindDirectIface == 0 {
return &typeConvErr{srcv.DwarfType, dstv.RealType}