mirror of
https://github.com/hanzoai/visor.git
synced 2026-09-24 17:04:14 +00:00
Make ExtractErrno a function
PiperOrigin-RevId: 306891171
This commit is contained in:
committed by
gVisor bot
parent
7e4b24467e
commit
73f4a14f78
@@ -353,7 +353,7 @@ func (app *runApp) execute(t *Task) taskRunState {
|
||||
default:
|
||||
// What happened? Can't continue.
|
||||
t.Warningf("Unexpected SwitchToApp error: %v", err)
|
||||
t.PrepareExit(ExitStatus{Code: t.ExtractErrno(err, -1)})
|
||||
t.PrepareExit(ExitStatus{Code: ExtractErrno(err, -1)})
|
||||
return (*runExit)(nil)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ func (t *Task) deliverSignal(info *arch.SignalInfo, act arch.SignalAct) taskRunS
|
||||
fallthrough
|
||||
case (sre == ERESTARTSYS && !act.IsRestart()):
|
||||
t.Debugf("Not restarting syscall %d after errno %d: interrupted by signal %d", t.Arch().SyscallNo(), sre, info.Signo)
|
||||
t.Arch().SetReturn(uintptr(-t.ExtractErrno(syserror.EINTR, -1)))
|
||||
t.Arch().SetReturn(uintptr(-ExtractErrno(syserror.EINTR, -1)))
|
||||
default:
|
||||
t.Debugf("Restarting syscall %d after errno %d: interrupted by signal %d", t.Arch().SyscallNo(), sre, info.Signo)
|
||||
t.Arch().RestartSyscall()
|
||||
|
||||
@@ -312,7 +312,7 @@ func (t *Task) doSyscallInvoke(sysno uintptr, args arch.SyscallArguments) taskRu
|
||||
return ctrl.next
|
||||
}
|
||||
} else if err != nil {
|
||||
t.Arch().SetReturn(uintptr(-t.ExtractErrno(err, int(sysno))))
|
||||
t.Arch().SetReturn(uintptr(-ExtractErrno(err, int(sysno))))
|
||||
t.haveSyscallReturn = true
|
||||
} else {
|
||||
t.Arch().SetReturn(rval)
|
||||
@@ -431,7 +431,7 @@ func (t *Task) doVsyscallInvoke(sysno uintptr, args arch.SyscallArguments, calle
|
||||
// A return is not emulated in this case.
|
||||
return (*runApp)(nil)
|
||||
}
|
||||
t.Arch().SetReturn(uintptr(-t.ExtractErrno(err, int(sysno))))
|
||||
t.Arch().SetReturn(uintptr(-ExtractErrno(err, int(sysno))))
|
||||
}
|
||||
t.Arch().SetIP(t.Arch().Value(caller))
|
||||
t.Arch().SetStack(t.Arch().Stack() + uintptr(t.Arch().Width()))
|
||||
@@ -441,7 +441,7 @@ func (t *Task) doVsyscallInvoke(sysno uintptr, args arch.SyscallArguments, calle
|
||||
// ExtractErrno extracts an integer error number from the error.
|
||||
// The syscall number is purely for context in the error case. Use -1 if
|
||||
// syscall number is unknown.
|
||||
func (t *Task) ExtractErrno(err error, sysno int) int {
|
||||
func ExtractErrno(err error, sysno int) int {
|
||||
switch err := err.(type) {
|
||||
case nil:
|
||||
return 0
|
||||
@@ -455,11 +455,11 @@ func (t *Task) ExtractErrno(err error, sysno int) int {
|
||||
// handled (and the SIGBUS is delivered).
|
||||
return int(syscall.EFAULT)
|
||||
case *os.PathError:
|
||||
return t.ExtractErrno(err.Err, sysno)
|
||||
return ExtractErrno(err.Err, sysno)
|
||||
case *os.LinkError:
|
||||
return t.ExtractErrno(err.Err, sysno)
|
||||
return ExtractErrno(err.Err, sysno)
|
||||
case *os.SyscallError:
|
||||
return t.ExtractErrno(err.Err, sysno)
|
||||
return ExtractErrno(err.Err, sysno)
|
||||
default:
|
||||
if errno, ok := syserror.TranslateError(err); ok {
|
||||
return int(errno)
|
||||
|
||||
@@ -719,7 +719,7 @@ func (s SyscallMap) SyscallEnter(t *kernel.Task, sysno uintptr, args arch.Syscal
|
||||
// SyscallExit implements kernel.Stracer.SyscallExit. It logs the syscall
|
||||
// exit trace.
|
||||
func (s SyscallMap) SyscallExit(context interface{}, t *kernel.Task, sysno, rval uintptr, err error) {
|
||||
errno := t.ExtractErrno(err, int(sysno))
|
||||
errno := kernel.ExtractErrno(err, int(sysno))
|
||||
c := context.(*syscallContext)
|
||||
|
||||
elapsed := time.Since(c.start)
|
||||
|
||||
@@ -290,7 +290,7 @@ func performCallback(t *kernel.Task, file *fs.File, cbAddr usermem.Addr, cb *ioC
|
||||
// Update the result.
|
||||
if err != nil {
|
||||
err = handleIOError(t, ev.Result != 0 /* partial */, err, nil /* never interrupted */, "aio", file)
|
||||
ev.Result = -int64(t.ExtractErrno(err, 0))
|
||||
ev.Result = -int64(kernel.ExtractErrno(err, 0))
|
||||
}
|
||||
|
||||
file.DecRef()
|
||||
|
||||
Reference in New Issue
Block a user