-
Notifications
You must be signed in to change notification settings - Fork 46
fix(runtime): restore SIGSEGV signal handler for non-wasm platforms #1383
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| //go:build !wasm && !baremetal | ||
|
|
||
| /* | ||
| * Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package runtime | ||
|
|
||
| import ( | ||
| c "github.com/goplus/llgo/runtime/internal/clite" | ||
| "github.com/goplus/llgo/runtime/internal/clite/signal" | ||
| ) | ||
|
|
||
| const ( | ||
| // SIGSEGV is signal number 11 on all Unix-like systems (Linux, Darwin, BSD, etc.) | ||
| // Using a hardcoded constant avoids importing the syscall package, which would | ||
| // introduce dependencies on errors and internal/reflectlite packages that cause | ||
| // linking issues in c-shared and c-archive build modes. | ||
| SIGSEGV = c.Int(0xb) | ||
| ) | ||
|
|
||
| // This file contains platform-specific runtime initialization for non-wasm targets. | ||
| // The SIGSEGV signal handler enables Go-style panic recovery for nil pointer dereferences | ||
| // instead of immediate process termination. | ||
| // | ||
| // For wasm platform compatibility, signal handling is excluded via build tags. | ||
| // See PR #1059 for wasm platform requirements. | ||
| func init() { | ||
| signal.Signal(SIGSEGV, func(v c.Int) { | ||
| if v == SIGSEGV { | ||
| panic(errorString("invalid memory address or nil pointer dereference")) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This signal handler violates async-signal-safety by calling Risk: If SIGSEGV occurs while inside malloc/free, the handler calling malloc again can cause deadlock or memory corruption. Recommendation: Consider pre-allocating the error value and using only async-signal-safe operations in the handler, similar to how standard Go's runtime handles signals with dedicated signal stacks and atomic operations. |
||
| } | ||
| var buf [20]byte | ||
| panic(errorString("unexpected signal value: " + string(itoa(buf[:], uint64(v))))) | ||
| }) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing Documentation
This file lacks explanatory comments. Given the platform-specific nature and relationship to PR #1059, please add:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done