8000 feat: `POST_TRAP` callback by elebirds · Pull Request #8 · arceos-org/axcpu · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: POST_TRAP callback #8

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

elebirds
Copy link
Contributor
@elebirds elebirds commented Jun 21, 2025

This PR is a reviewed feature from downstream oscamp/arceos.

For further information, please refer to: oscomp/arceos#34

some linker script updates in arceos-org/arceos#266

Description

This pull request introduces a mechanism to invoke post-trap callbacks across multiple architectures, refactors exception handling in the AArch64 assembly code, and enhances the TrapSource enum with helper functionality. These changes aim to improve modularity and consistency in trap handling across the codebase.

Post-Trap Callback Mechanism:

  • src/trap.rs: Introduced a distributed slice POST_TRAP for registering callbacks to be invoked after a trap, and added a post_trap_callback function to iterate through and call these callbacks. [1] [2]

  • Various architecture-specific trap handlers (src/loongarch64/trap.rs, src/riscv/trap.rs, src/x86_64/trap.rs, src/x86_64/syscall.rs): Updated to call post_trap_callback with appropriate parameters after handling traps. [1] [2] [3] [4]

AArch64 Exception Handling Refactor:

  • src/aarch64/trap.S: Updated macros HANDLE_SYNC and HANDLE_IRQ to accept a source parameter, and modified their invocations in exception_vector_base to pass the appropriate source value. This ensures that the source of the exception is explicitly tracked. [1] [2]

  • src/aarch64/trap.rs: Updated handle_sync_exception and handle_irq_exception to accept a TrapSource parameter, and integrated post_trap_callback into these functions to handle post-trap logic. [1] [2] [3]

Enhancements to TrapSource:

  • src/aarch64/trap.rs: Added an is_from_user method to the TrapSource enum to determine if a trap originated from user space. This simplifies checks for user-originated traps.

Additional Notes

This is a step towards gradually merging downstream oscamp/arceos into the main branch.

@@ -17,6 +17,7 @@ core::arch::global_asm!(
#[unsafe(no_mangle)]
pub(super) fn x86_syscall_handler(tf: &mut TrapFrame) {
tf.rax = crate::trap::handle_syscall(tf, tf.rax as usize) as u64;
crate::trap::post_trap_callback(tf, true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

post_trap_callback will be called twice if x86_syscall_handler is called by x86_trap_handler when tf.vector is LEGACY_SYSCALL_VECTOR.

So that's why we split x86_syscall_handler into two functions like https://github.com/arceos-org/axcpu/pull/4/files#diff-dbe65d6f2e92e2037f4d33be8c0d4b5890892d94c06f707ab1faf49015b6e3d9R19.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, in fact, the PRs I submitted need to be merged one by one in a specific order.
First, #4
Then, this PR
Finally, #9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0