Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime: allow panic on syscall.Exit instead of halting #4010

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/runtime/baremetal.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package runtime

import (
"internal/itoa"
"unsafe"
)

Expand Down Expand Up @@ -59,8 +60,30 @@ func runtime_putchar(c byte) {
putchar(c)
}

// ErrExitPanic implements error
type ErrExitPanic int

func (e ErrExitPanic) Error() string {
return "errno " + itoa.Itoa(int(e))
}

var panicOnExit bool

// PanicOnExit enables panic when syscall.Exit is called,
// as opposed to halting. It can be set by, e.g., a u-root
// shell to regain control when commands exit.
// This in turn makes it easier for building unmodified
// commands into u-root, for bare metal environments.
func PanicOnExit() {
panicOnExit = true
}

//go:linkname syscall_Exit syscall.Exit
func syscall_Exit(code int) {
if panicOnExit {
panic(ErrExitPanic(code))
}

exit(code)
}

Expand Down
Loading