github.com/usbarmory/GoTEE@v0.0.0-20240405084336-c52770d9fcdb/monitor/syscall.go (about) 1 // Copyright (c) WithSecure Corporation 2 // https://foundry.withsecure.com 3 // 4 // Use of this source code is governed by the license 5 // that can be found in the LICENSE file. 6 7 package monitor 8 9 import "errors" 10 11 // TransferRegion validates the registers used in memory transfer request for 12 // GoTEE secure monitor calls (syscall.Read(), syscall.Write()) and returns the 13 // computed memory offset and transfer size. 14 func (ctx *ExecCtx) TransferRegion() (off int, n int, err error) { 15 off = int(ctx.A1()) - int(ctx.Memory.Start()) 16 n = int(ctx.A2()) 17 s := int(ctx.Memory.Size()) 18 19 if valid := (off >= 0) && (n <= s) && (off < s-n); !valid { 20 err = errors.New("invalid offset") 21 } 22 23 return 24 }