forked from rcore-os/zCore
213 lines
7.9 KiB
Diff
213 lines
7.9 KiB
Diff
diff --git a/src/lib/process_builder/src/lib.rs b/src/lib/process_builder/src/lib.rs
|
|
index 0d49b5bf37a..7929530fe6e 100644
|
|
--- a/src/lib/process_builder/src/lib.rs
|
|
+++ b/src/lib/process_builder/src/lib.rs
|
|
@@ -834,7 +834,7 @@ impl ReservationVmar {
|
|
// (base+len) represents the full address space, assuming this is used with a root VMAR and
|
|
// length extends to the end of the address space, including a region the kernel reserves
|
|
// at the start of the space.
|
|
- let reserve_size = util::page_end((info.base + info.len) / 2) - info.base;
|
|
+ let reserve_size = util::page_end(info.len / 2);
|
|
let (reserve_vmar, reserve_base) =
|
|
vmar.allocate(0, reserve_size, zx::VmarFlags::SPECIFIC).map_err(|s| {
|
|
ProcessBuilderError::GenericStatus("Failed to allocate reservation VMAR", s)
|
|
diff --git a/zircon/kernel/lib/userabi/userboot/start.cc b/zircon/kernel/lib/userabi/userboot/start.cc
|
|
index 70188140fe1..777eccb1403 100644
|
|
--- a/zircon/kernel/lib/userabi/userboot/start.cc
|
|
+++ b/zircon/kernel/lib/userabi/userboot/start.cc
|
|
@@ -81,9 +81,9 @@ zx_handle_t reserve_low_address_space(zx_handle_t log, zx_handle_t root_vmar) {
|
|
"zx_object_get_info failed on child root VMAR handle");
|
|
zx_handle_t vmar;
|
|
uintptr_t addr;
|
|
- size_t reserve_size = (((info.base + info.len) / 2) + PAGE_SIZE - 1) & -PAGE_SIZE;
|
|
+ size_t reserve_size = (info.len / 2 + PAGE_SIZE - 1) & -PAGE_SIZE;
|
|
zx_status_t status =
|
|
- zx_vmar_allocate(root_vmar, ZX_VM_SPECIFIC, 0, reserve_size - info.base, &vmar, &addr);
|
|
+ zx_vmar_allocate(root_vmar, ZX_VM_SPECIFIC, 0, reserve_size, &vmar, &addr);
|
|
check(log, status, "zx_vmar_allocate failed for low address space reservation");
|
|
if (addr != info.base)
|
|
fail(log, "zx_vmar_allocate gave wrong address?!?");
|
|
diff --git a/zircon/system/ulib/launchpad/launchpad.c b/zircon/system/ulib/launchpad/launchpad.c
|
|
index 1a538fadc53..c465e6ae5c4 100644
|
|
--- a/zircon/system/ulib/launchpad/launchpad.c
|
|
+++ b/zircon/system/ulib/launchpad/launchpad.c
|
|
@@ -468,8 +468,8 @@ static zx_status_t reserve_low_address_space(launchpad_t* lp) {
|
|
}
|
|
|
|
uintptr_t addr;
|
|
- size_t reserve_size = (((info.base + info.len) / 2) + PAGE_SIZE - 1) & -PAGE_SIZE;
|
|
- status = zx_vmar_allocate(lp_vmar(lp), ZX_VM_SPECIFIC, 0, reserve_size - info.base,
|
|
+ size_t reserve_size = (info.len / 2 + PAGE_SIZE - 1) & -PAGE_SIZE;
|
|
+ status = zx_vmar_allocate(lp_vmar(lp), ZX_VM_SPECIFIC, 0, reserve_size,
|
|
&lp->reserve_vmar, &addr);
|
|
if (status != ZX_OK) {
|
|
return lp_error(lp, status, "zx_vmar_allocate failed for low address space reservation");
|
|
diff --git a/zircon/system/ulib/zircon/syscalls-x86.S b/zircon/system/ulib/zircon/syscalls-x86.S
|
|
index fa6652d0b47..f197ba7b067 100644
|
|
--- a/zircon/system/ulib/zircon/syscalls-x86.S
|
|
+++ b/zircon/system/ulib/zircon/syscalls-x86.S
|
|
@@ -26,34 +26,17 @@
|
|
|
|
.macro m_syscall name, num, nargs, public
|
|
syscall_entry_begin \name
|
|
- .cfi_same_value %r12
|
|
- .cfi_same_value %r13
|
|
-.if \nargs <= 3
|
|
- zircon_syscall \num, \name, \name
|
|
- ret
|
|
-.elseif \nargs <= 6
|
|
- mov %rcx, %r10 // Argument 4
|
|
- zircon_syscall \num, \name, \name
|
|
- ret
|
|
-.elseif \nargs == 7
|
|
- push_reg %r12
|
|
- mov 0x10(%rsp), %r12 // Argument 7
|
|
- mov %rcx, %r10 // Argument 4
|
|
- zircon_syscall \num, \name, \name
|
|
- pop_reg %r12
|
|
- ret
|
|
-.elseif \nargs == 8
|
|
- push_reg %r12
|
|
- push_reg %r13
|
|
- mov 0x18(%rsp), %r12 // Argument 7
|
|
- mov 0x20(%rsp), %r13 // Argument 8
|
|
- mov %rcx, %r10 // Argument 4
|
|
- zircon_syscall \num, \name, \name
|
|
- pop_reg %r13
|
|
- pop_reg %r12
|
|
- ret
|
|
-.endif
|
|
+ mov $\num, %eax
|
|
+ jmpq *zcore_syscall_entry(%rip)
|
|
+// This symbol at the return address identifies this as an approved call site.
|
|
+ .hidden CODE_SYSRET_\name\()_VIA_\name
|
|
+CODE_SYSRET_\name\()_VIA_\name\():
|
|
syscall_entry_end \name \public
|
|
.endm
|
|
|
|
+.pushsection .rodata
|
|
+zcore_syscall_entry:
|
|
+ .quad 0xdeadbeaf
|
|
+.popsection
|
|
+
|
|
#include "syscalls-stubs.S"
|
|
diff --git a/zircon/system/ulib/zircon/zx_futex_wake_handle_close_thread_exit-x86.S b/zircon/system/ulib/zircon/zx_futex_wake_handle_close_thread_exit-x86.S
|
|
index e3b017cdf22..1a3436a6ad1 100644
|
|
--- a/zircon/system/ulib/zircon/zx_futex_wake_handle_close_thread_exit-x86.S
|
|
+++ b/zircon/system/ulib/zircon/zx_futex_wake_handle_close_thread_exit-x86.S
|
|
@@ -12,36 +12,16 @@
|
|
|
|
// (value_ptr: %rdi, wake_count: %esi, new_value: %edx, handle: %ecx)
|
|
syscall_entry_begin zx_futex_wake_handle_close_thread_exit
|
|
-
|
|
- // Store the value into the futex, which should signal that the stack is no longer in use.
|
|
- // atomic_store_explicit(value_ptr, new_value, memory_order_release)
|
|
- mov %edx, (%rdi)
|
|
-
|
|
- // Now the stack might be gone and we can never return!
|
|
-
|
|
- // Save the handle argument in a callee-saves register (%rbx).
|
|
- // Since this function cannot return, do not bother preserving the old contents.
|
|
- mov %ecx, %ebx
|
|
-
|
|
- zircon_syscall ZX_SYS_futex_wake, zx_futex_wake, zx_futex_wake_handle_close_thread_exit
|
|
- test %eax, %eax
|
|
- jnz .Lfutex_wake_fail
|
|
-
|
|
- mov %ebx, %edi
|
|
- zircon_syscall ZX_SYS_handle_close, zx_handle_close, zx_futex_wake_handle_close_thread_exit
|
|
- test %eax, %eax
|
|
- jnz .Lhandle_close_fail
|
|
-
|
|
- zircon_syscall ZX_SYS_thread_exit, zx_thread_exit, zx_futex_wake_handle_close_thread_exit
|
|
+ mov $200, %eax
|
|
+ jmpq *zcore_syscall_entry(%rip)
|
|
|
|
// It should be impossible to get here.
|
|
.Lthread_exit_returned:
|
|
ud2
|
|
|
|
- // We can't recover in these cases, since our stack may have been freed.
|
|
-.Lfutex_wake_fail:
|
|
- ud2
|
|
-.Lhandle_close_fail:
|
|
- ud2
|
|
-
|
|
syscall_entry_end zx_futex_wake_handle_close_thread_exit
|
|
+
|
|
+.pushsection .rodata
|
|
+zcore_syscall_entry:
|
|
+ .quad 0xdeadbeaf
|
|
+.popsection
|
|
diff --git a/zircon/system/ulib/zircon/zx_vmar_unmap_handle_close_thread_exit-x86.S b/zircon/system/ulib/zircon/zx_vmar_unmap_handle_close_thread_exit-x86.S
|
|
index 7baa69755e0..18cdb981f0c 100644
|
|
--- a/zircon/system/ulib/zircon/zx_vmar_unmap_handle_close_thread_exit-x86.S
|
|
+++ b/zircon/system/ulib/zircon/zx_vmar_unmap_handle_close_thread_exit-x86.S
|
|
@@ -12,34 +12,16 @@
|
|
|
|
// (vmar_handle: %rdi, addr: %rsi, len: %rdx, handle: %ecx)
|
|
syscall_entry_begin zx_vmar_unmap_handle_close_thread_exit
|
|
-
|
|
- // Save the handle argument in a callee-saves register (%rbx).
|
|
- // Callee-save that register so we can unwind in the error case.
|
|
- push_reg %rbx
|
|
- mov %ecx, %ebx
|
|
-
|
|
- zircon_syscall ZX_SYS_vmar_unmap, zx_vmar_unmap, zx_vmar_unmap_handle_close_thread_exit
|
|
- test %eax, %eax
|
|
- jnz .Lvmar_unmap_fail
|
|
-
|
|
- // Now the stack is gone and we can never return!
|
|
-
|
|
- mov %ebx, %edi
|
|
- zircon_syscall ZX_SYS_handle_close, zx_handle_close, zx_vmar_unmap_handle_close_thread_exit
|
|
- test %eax, %eax
|
|
- jnz .Lhandle_close_fail
|
|
-
|
|
- zircon_syscall ZX_SYS_thread_exit, zx_thread_exit, zx_vmar_unmap_handle_close_thread_exit
|
|
+ mov $201, %eax
|
|
+ jmpq *zcore_syscall_entry(%rip)
|
|
|
|
// It should be impossible to get here.
|
|
.Lthread_exit_returned:
|
|
ud2
|
|
|
|
-.Lvmar_unmap_fail:
|
|
- pop_reg %rbx
|
|
- ret
|
|
-
|
|
-.Lhandle_close_fail:
|
|
- ud2
|
|
-
|
|
syscall_entry_end zx_vmar_unmap_handle_close_thread_exit
|
|
+
|
|
+.pushsection .rodata
|
|
+zcore_syscall_entry:
|
|
+ .quad 0xdeadbeaf
|
|
+.popsection
|
|
diff --git a/zircon/system/ulib/zircon/zircon-syscall-arm64.S b/zircon/system/ulib/zircon/zircon-syscall-arm64.S
|
|
index 50598676cb2..fc69f203ed0 100644
|
|
--- a/zircon/system/ulib/zircon/zircon-syscall-arm64.S
|
|
+++ b/zircon/system/ulib/zircon/zircon-syscall-arm64.S
|
|
@@ -6,7 +6,11 @@
|
|
|
|
.macro zircon_syscall num, name, caller
|
|
mov x16, #\num
|
|
- svc #0x0
|
|
+ push_regpair x29, x30
|
|
+ adr x29, zcore_syscall_entry
|
|
+ ldr x29, [x29]
|
|
+ blr x29
|
|
+ pop_regpair x29, x30
|
|
// This symbol at the return address identifies this as an approved call site.
|
|
.hidden CODE_SYSRET_\name\()_VIA_\caller
|
|
CODE_SYSRET_\name\()_VIA_\caller\():
|
|
@@ -46,3 +50,8 @@ CODE_SYSRET_\name\()_VIA_\caller\():
|
|
.cfi_same_value \reg0
|
|
.cfi_same_value \reg1
|
|
.endm
|
|
+
|
|
+.pushsection .rodata
|
|
+zcore_syscall_entry:
|
|
+ .quad 0xdeadbeaf
|
|
+.popsection
|