Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/arch/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,26 @@ pub(super) unsafe fn clone(
}

/// Write a value to the platform thread-pointer register.
#[cfg(feature = "origin-thread")]
#[cfg(all(
feature = "origin-thread",
any(feature = "origin-start", feature = "external-start")
))]
#[inline]
pub(super) unsafe fn set_thread_pointer(ptr: *mut c_void) {
asm!("msr tpidr_el0,{0}", in(reg) ptr);
asm!("msr tpidr_el0,{}", in(reg) ptr);
debug_assert_eq!(get_thread_pointer(), ptr);
}

/// Read the value of the platform thread-pointer register.
#[cfg(feature = "origin-thread")]
#[cfg(all(
feature = "origin-thread",
any(feature = "origin-start", feature = "external-start")
))]
#[inline]
pub(super) fn get_thread_pointer() -> *mut c_void {
let ptr;
unsafe {
asm!("mrs {0},tpidr_el0", out(reg) ptr, options(nostack, preserves_flags, readonly));
asm!("mrs {},tpidr_el0", out(reg) ptr, options(nostack, preserves_flags, readonly));
}
ptr
}
Expand Down
12 changes: 9 additions & 3 deletions src/arch/arm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,26 @@ pub(super) unsafe fn clone(
}

/// Write a value to the platform thread-pointer register.
#[cfg(feature = "origin-thread")]
#[cfg(all(
feature = "origin-thread",
any(feature = "origin-start", feature = "external-start")
))]
#[inline]
pub(super) unsafe fn set_thread_pointer(ptr: *mut c_void) {
rustix::runtime::arm_set_tls(ptr).expect("arm_set_tls");
debug_assert_eq!(get_thread_pointer(), ptr);
}

/// Read the value of the platform thread-pointer register.
#[cfg(feature = "origin-thread")]
#[cfg(all(
feature = "origin-thread",
any(feature = "origin-start", feature = "external-start")
))]
#[inline]
pub(super) fn get_thread_pointer() -> *mut c_void {
let ptr;
unsafe {
asm!("mrc p15,0,{0},c13,c0,3", out(reg) ptr);
asm!("mrc p15,0,{},c13,c0,3", out(reg) ptr);
}
ptr
}
Expand Down
14 changes: 10 additions & 4 deletions src/arch/riscv64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,26 @@ pub(super) unsafe fn clone(
}

/// Write a value to the platform thread-pointer register.
#[cfg(feature = "origin-thread")]
#[cfg(all(
feature = "origin-thread",
any(feature = "origin-start", feature = "external-start")
))]
#[inline]
pub(super) unsafe fn set_thread_pointer(ptr: *mut c_void) {
asm!("mv tp,{0}", in(reg) ptr);
asm!("mv tp,{}", in(reg) ptr);
debug_assert_eq!(get_thread_pointer(), ptr);
}

/// Read the value of the platform thread-pointer register.
#[cfg(feature = "origin-thread")]
#[cfg(all(
feature = "origin-thread",
any(feature = "origin-start", feature = "external-start")
))]
#[inline]
pub(super) fn get_thread_pointer() -> *mut c_void {
let ptr;
unsafe {
asm!("mv {0},tp", out(reg) ptr, options(nostack, preserves_flags, readonly));
asm!("mv {},tp", out(reg) ptr, options(nostack, preserves_flags, readonly));
}
ptr
}
Expand Down
12 changes: 9 additions & 3 deletions src/arch/x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ pub(super) unsafe fn clone(
}

/// Write a value to the platform thread-pointer register.
#[cfg(feature = "origin-thread")]
#[cfg(all(
feature = "origin-thread",
any(feature = "origin-start", feature = "external-start")
))]
#[inline]
pub(super) unsafe fn set_thread_pointer(ptr: *mut c_void) {
let mut user_desc = rustix::runtime::UserDesc {
Expand All @@ -113,12 +116,15 @@ pub(super) unsafe fn set_thread_pointer(ptr: *mut c_void) {
}

/// Read the value of the platform thread-pointer register.
#[cfg(feature = "origin-thread")]
#[cfg(all(
feature = "origin-thread",
any(feature = "origin-start", feature = "external-start")
))]
#[inline]
pub(super) fn get_thread_pointer() -> *mut c_void {
let ptr;
unsafe {
asm!("mov {0},DWORD PTR gs:0", out(reg) ptr, options(nostack, preserves_flags, readonly));
asm!("mov {},DWORD PTR gs:0", out(reg) ptr, options(nostack, preserves_flags, readonly));
}
ptr
}
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ unsafe extern "C" fn _start() -> ! {
#[cfg(target_arch = "x86")]
asm!(
"mov eax, esp", // Save the incoming `esp` value.
"push ebp", // Pad for alignment.
"push ebp", // Pad for alignment.
"push ebp", // Pad for alignment.
"push ebp", // Pad for stack pointer alignment.
"push ebp", // Pad for stack pointer alignment.
"push ebp", // Pad for stack pointer alignment.
"push eax", // Pass saved the incoming `esp` as the arg to `entry`.
"push ebp", // Set the return address to zero.
"jmp {entry}", // Jump to `entry`.
Expand Down