-
Notifications
You must be signed in to change notification settings - Fork 43
!syscalls: move signal handling to kernel #670
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
base: master
Are you sure you want to change the base?
Conversation
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.
Summary of Changes
Hello @etiaro, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request introduces a major overhaul of the kernel's signal handling system, transitioning from a custom implementation to one that adheres closely to POSIX standards. The changes involve restructuring data types, centralizing signal configuration within the kernel's process and thread management, and updating the system call interface for signal manipulation. This refactoring aims to provide a more robust and standard-compliant signal delivery mechanism.
Highlights
- POSIX Signal Alignment: The signal handling mechanism has been significantly refactored to align with POSIX standards. This includes replacing custom signal enumerations with standard POSIX signal numbers (e.g.,
SIGHUP
,SIGSEGV
) and introducing comprehensivesigaction
,siginfo_t
, andsigset_t
structures. - Kernel-level Signal Management: Signal handling logic has been moved more deeply into the kernel. The
process_t
structure now stores an array ofsigaction
structures for per-signal configuration and a dedicatedsigtrampoline
address. Signal masks are now primarily managed per-thread, improving granularity. - Updated Signal Delivery and Syscalls: The core signal delivery functions (
threads_sigpost
,_threads_checkSignal
) have been rewritten to utilize the newsigaction
structure, supporting flags likeSA_NODEFER
andSA_RESETHAND
. ThesignalHandle
syscall has been renamed tosignalAction
and updated to acceptsigaction
parameters. Signal mask manipulation now uses a newthreads_updateSigmask
helper. - HAL Integration: The Hardware Abstraction Layer (HAL) function
hal_cpuPushSignal
has been modified to differentiate between the signal trampoline and the actual handler address, ensuring both are correctly passed to the signal context on the stack.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
This pull request refactors the signal handling mechanism, moving it into the kernel and aligning it more closely with POSIX standards. The changes are well-structured, replacing the old system with a more robust sigaction
-based approach. I've identified areas for improvement to enhance correctness and robustness, specifically around input validation in the signal posting logic and a type mismatch in a new function's signature.
da9f58a
to
cdc57ad
Compare
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.
Please don't add me as a reviewer to draft PRs without any extra context (as per our coding guidelines - we're not reviewing drafts, they are work-in-progress until you explicitly mark it as ready-for-review).
As an exception I did a code review of the kernel part, I won't be looking at libphoenix
part unless explicitly asked.
I'm missing a context regarding as to Why the change is needed.
9ea0758
to
c1877cf
Compare
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.
As you've summarised - the signal handling is now cluttered and really not readable. Probably all of the actual signal handling should be done in _threads_checkSignal
(or maybe some wrapper function for that) - all other code paths are "optimizations" which are either prone to a race condition or a little bit convoluted (I'm not saying that we shouldn't eg. handle SIGKILL
as early as possible as an optimization).
You may want to look at other OSes regarding how signal handling is being implemented there (usually in more complex way but the basics - like deciding on action to perform on signal dequeue in the context of receiving thread - are universal).
Please - present the additional test cases You've implemented the code you're pushing here passes - eg. I don't see setting return code of the process killed by a signal anywhere.
@@ -138,7 +138,7 @@ int hal_cpuCreateContext(cpu_context_t **nctx, void *start, void *kstack, size_t | |||
} | |||
|
|||
|
|||
int hal_cpuPushSignal(void *kstack, void (*handler)(void), cpu_context_t *signalCtx, int n, unsigned int oldmask, const int src) | |||
int hal_cpuPushSignal(void *kstack, void (*trampoline)(void), void *handler, cpu_context_t *signalCtx, int n, unsigned int oldmask, const int src) |
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.
probably more kosher (but harder to implement currently) would be to create 2 stack frames - with trampoline (calling sigreturn) below the handler - and jump directly to the handler
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.
I guess i can give it a try once the threads.c logic would be fine
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.
Not sure if it's worth the trouble, would require some additional changes apart from stack modification (eg. setting arm lr register in or before hal_jmp to handler)
c4bee02
to
55c6d5c
Compare
Additional signal tests for phoenix-rtos/phoenix-rtos-kernel#670 moving signal handling to kernel Showcasing issue phoenix-rtos/phoenix-rtos-project#1367 JIRA: RTOS-736
Additional signal tests for phoenix-rtos/phoenix-rtos-kernel#670 moving signal handling to kernel JIRA: RTOS-736
16d9ea3
to
315ade1
Compare
04e0116
to
4a62e15
Compare
f7f2833
to
1089083
Compare
* keep actions for every signal and signal trampoline in process_t struct * remove unused sigmask from process_t struct, rely on thread_t sigmask field * add handler address as signal_trampoline stack parameter * use POSIX signal codes and default behaviors * replaced signalHandle syscall with signalAction * ensure that termination by signal happens before returning from syscall or exception JIRA: RTOS-736
JIRA: RTOS-736
POSIX requirement: It is not possible to block those signals which cannot be ignored. This shall be enforced by the system without causing an error to be indicated. JIRA: RTOS-736
Interrupt when signaling specific intrruptible thread JIRA: RTOS-736
Before this change, a vforked process that received a signal would die and its parent would not be resumed nor killed. Now the parent is resumed and the vforked process is killed. JIRA: RTOS-1101
Removed signalPost syscall as it duplicates functionality of sys_tkill JIRA: RTOS-736
1089083
to
4b21ec0
Compare
Description
Test results
Motivation and Context
Moving singal handlers to kernel enables it to know whether coredump should be run, by knowing whether a signal handler is installed for given signal.
Simplifies handling exceptions with problems like stackoverflow (JIRA: RTOS-1066, currently stackoverflow causes kernel exception during sigsegv handling even with default sigsegv action)
Resolves phoenix-rtos/phoenix-rtos-project#1367
JIRA: RTOS-736
Types of changes
How Has This Been Tested?
Checklist:
Special treatment