!syscalls: move signal handling to kernel#670
Conversation
There was a problem hiding this comment.
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_tstructures. - Kernel-level Signal Management: Signal handling logic has been moved more deeply into the kernel. The
process_tstructure now stores an array ofsigactionstructures for per-signal configuration and a dedicatedsigtrampolineaddress. 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 newsigactionstructure, supporting flags likeSA_NODEFERandSA_RESETHAND. ThesignalHandlesyscall has been renamed tosignalActionand updated to acceptsigactionparameters. Signal mask manipulation now uses a newthreads_updateSigmaskhelper. - HAL Integration: The Hardware Abstraction Layer (HAL) function
hal_cpuPushSignalhas 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.
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
nalajcie
left a comment
There was a problem hiding this comment.
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
nalajcie
left a comment
There was a problem hiding this comment.
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.
|
|
||
|
|
||
| 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.
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.
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
f7c61cb to
3390b9e
Compare
julianuziemblo
left a comment
There was a problem hiding this comment.
small things. I'm not an expert but for me it looks good.
3390b9e to
11d9d21
Compare
11d9d21 to
cfee82c
Compare
Additional signal tests for phoenix-rtos/phoenix-rtos-kernel#670 moving signal handling to kernel JIRA: RTOS-736
cfee82c to
e28ad29
Compare
Unit Test Results (nightly) 1 files 3 070 suites 6h 3m 50s ⏱️ Results for commit c01e4ee. ♻️ This comment has been updated with latest results. |
|
Waiting with rerun for master nightly to work properly. |
e28ad29 to
54e18ec
Compare
54e18ec to
ae74901
Compare
Additional signal tests for phoenix-rtos/phoenix-rtos-kernel#670 moving signal handling to kernel JIRA: RTOS-736
ae74901 to
f3294a7
Compare
181111b to
82a9805
Compare
Additional signal tests for phoenix-rtos/phoenix-rtos-kernel#670 moving signal handling to kernel JIRA: RTOS-736
Previous approach to signal handling split between userspace libphoenix and kernel made it hard, if not impossible, to provide full POSIX-compliance. JIRA: RTOS-736
Reduce size of process_t struct by allocating sigactions array only when needed. 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
Make behavior of direct thread signaling consistent with signaling whole process JIRA: RTOS-736
Resume vfork parent when child is terminated via signal. JIRA: RTOS-1101
Removed signalPost syscall as it duplicates functionality of sys_tkill JIRA: RTOS-736
Ensure WIFSIGNALED works as expected when exit is called with code above 255 and improve POSIX-compliance: "... only the least significant 8 bits (that is, status & 0377) shall be available to a waiting parent process." JIRA: RTOS-1300
82a9805 to
c01e4ee
Compare
Description
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).
Allows improved POSIX compliability (eg. not interrupting sleep by ignored signals).
Resolves phoenix-rtos/phoenix-rtos-project#1367
Resolves phoenix-rtos/phoenix-rtos-project#1456
Resolves phoenix-rtos/phoenix-rtos-project#1464
Resolves phoenix-rtos/phoenix-rtos-project#1453
Resolves phoenix-rtos/phoenix-rtos-project#1432
Resolves phoenix-rtos/phoenix-rtos-project#1448
JIRA: RTOS-736
Depends-On: phoenix-rtos-tests:etiaro/signals
Types of changes
How Has This Been Tested?
Checklist:
Special treatment