-
Notifications
You must be signed in to change notification settings - Fork 9
Add translated embedder syscall hook #69
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: main
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -1818,6 +1818,40 @@ int syscall_dispatch(hv_vcpu_t vcpu, guest_t *g, int *exit_code, bool verbose) | |
| slow_path: | ||
| entry = RANGE_CHECK(nr, 0, SC_TABLE_SIZE) ? &syscall_table[nr] : NULL; | ||
|
|
||
| /* Custom Embedder Syscall Hook: | ||
| * Guests running on translated user-space architectures (e.g., x86_64 | ||
| * via Apple Rosetta 2) execute at EL0 and cannot compile or execute | ||
| * native AArch64 'hvc' instructions. | ||
| * | ||
| * To allow such guests to invoke the embedder extension hooks (like the | ||
| * graphics bridge), we intercept a custom system call number | ||
| * (ELFUSE_NR_EMBEDDER_HVC6) as the x86_64 guest counterpart to AArch64 | ||
| * 'hvc 6'. | ||
| * | ||
| * Syscall layout: | ||
| * nr = ELFUSE_NR_EMBEDDER_HVC6 | ||
| * X0 = call number | ||
| * X1 = guest virtual address of the uint64_t args[8] array | ||
| */ | ||
| #ifdef ELFUSE_NR_EMBEDDER_HVC6 | ||
| if (nr == ELFUSE_NR_EMBEDDER_HVC6) { | ||
|
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. Four concerns on this hook:
Style nits: leading comment block at column 0 should be 4-space indented to match function body; "we intercept" should be third-person per spec.md ("elfuse intercepts" or imperative). |
||
| if (g->hvc6_handler) { | ||
| uint64_t call_nr = 0; | ||
| uint64_t args_gva = 0; | ||
| hv_vcpu_get_reg(vcpu, HV_REG_X0, &call_nr); | ||
| hv_vcpu_get_reg(vcpu, HV_REG_X1, &args_gva); | ||
| uint64_t guest_args[8] = {0}; | ||
| if (guest_read_small(g, args_gva, guest_args, sizeof(guest_args)) < | ||
| 0) { | ||
| result = -LINUX_EFAULT; | ||
| } else { | ||
| result = g->hvc6_handler(call_nr, guest_args, g->hvc6_userdata); | ||
| } | ||
| goto fast_done; | ||
| } | ||
| } | ||
| #endif | ||
|
|
||
| hv_vcpu_get_reg(vcpu, HV_REG_X0, &x0); | ||
| hv_vcpu_get_reg(vcpu, HV_REG_X1, &x1); | ||
| hv_vcpu_get_reg(vcpu, HV_REG_X2, &x2); | ||
|
|
||
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.
make ELFUSE_NR_EMBEDDER_HVC6=lets an empty value override?=, then CFLAGS picks up-DELFUSE_NR_EMBEDDER_HVC6=and the C hook becomesif (nr == )-- syntax error. Either skip the-Dwhen the value is empty, or guard the C side with a numeric check: