11//! Architecture-specific assembly code.
22
3+ #[ cfg( any(
4+ feature = "take-charge" ,
5+ all( not( feature = "unwinding" ) , feature = "panic-handler-trap" )
6+ ) ) ]
37use core:: arch:: asm;
48#[ cfg( all( feature = "experimental-relocate" , feature = "origin-start" ) ) ]
59#[ cfg( relocation_model = "pic" ) ]
610use linux_raw_sys:: elf:: { Elf_Dyn , Elf_Ehdr } ;
711#[ cfg( all( feature = "experimental-relocate" , feature = "origin-start" ) ) ]
812#[ cfg( relocation_model = "pic" ) ]
913use linux_raw_sys:: general:: { __NR_mprotect, PROT_READ } ;
14+ #[ cfg( feature = "take-charge" ) ]
1015#[ cfg( feature = "signal" ) ]
1116#[ cfg( test) ]
1217use linux_raw_sys:: general:: { __NR_rt_sigreturn, __NR_sigreturn} ;
18+ #[ cfg( feature = "take-charge" ) ]
1319#[ cfg( feature = "thread" ) ]
1420use {
1521 core:: ffi:: c_void,
@@ -43,6 +49,10 @@ naked_fn!(
4349/// Execute a trap instruction.
4450///
4551/// This is roughly equivalent to `core::intrinsics::abort()`.
52+ #[ cfg( any(
53+ feature = "take-charge" ,
54+ all( not( feature = "unwinding" ) , feature = "panic-handler-trap" )
55+ ) ) ]
4656pub ( super ) fn trap ( ) -> ! {
4757 unsafe {
4858 asm ! ( ".inst 0xe7ffdefe" , options( noreturn, nostack) ) ;
@@ -190,6 +200,7 @@ pub(super) unsafe fn relocation_mprotect_readonly(ptr: usize, len: usize) {
190200}
191201
192202/// The required alignment for the stack pointer.
203+ #[ cfg( feature = "take-charge" ) ]
193204#[ cfg( feature = "thread" ) ]
194205pub ( super ) const STACK_ALIGNMENT : usize = 4 ;
195206
@@ -198,6 +209,7 @@ pub(super) const STACK_ALIGNMENT: usize = 4;
198209/// This can't be implemented in `rustix` because the child starts executing at
199210/// the same point as the parent and we need to use inline asm to have the
200211/// child jump to our new-thread entrypoint.
212+ #[ cfg( feature = "take-charge" ) ]
201213#[ cfg( feature = "thread" ) ]
202214#[ inline]
203215pub ( super ) unsafe fn clone (
@@ -241,6 +253,7 @@ pub(super) unsafe fn clone(
241253}
242254
243255/// Write a value to the platform thread-pointer register.
256+ #[ cfg( feature = "take-charge" ) ]
244257#[ cfg( feature = "thread" ) ]
245258#[ inline]
246259pub ( super ) unsafe fn set_thread_pointer ( ptr : * mut c_void ) {
@@ -250,6 +263,7 @@ pub(super) unsafe fn set_thread_pointer(ptr: *mut c_void) {
250263}
251264
252265/// Read the value of the platform thread-pointer register.
266+ #[ cfg( feature = "take-charge" ) ]
253267#[ cfg( feature = "thread" ) ]
254268#[ inline]
255269pub ( super ) fn thread_pointer ( ) -> * mut c_void {
@@ -262,11 +276,13 @@ pub(super) fn thread_pointer() -> *mut c_void {
262276}
263277
264278/// TLS data starts at the location pointed to by the thread pointer.
279+ #[ cfg( feature = "take-charge" ) ]
265280#[ cfg( feature = "thread" ) ]
266281pub ( super ) const TLS_OFFSET : usize = 0 ;
267282
268283/// `munmap` the current thread, then carefully exit the thread without
269284/// touching the deallocated stack.
285+ #[ cfg( feature = "take-charge" ) ]
270286#[ cfg( feature = "thread" ) ]
271287#[ inline]
272288pub ( super ) unsafe fn munmap_and_exit_thread ( map_addr : * mut c_void , map_len : usize ) -> ! {
@@ -285,6 +301,7 @@ pub(super) unsafe fn munmap_and_exit_thread(map_addr: *mut c_void, map_len: usiz
285301 ) ;
286302}
287303
304+ #[ cfg( feature = "take-charge" ) ]
288305#[ cfg( feature = "signal" ) ]
289306naked_fn ! (
290307 "
@@ -303,11 +320,13 @@ naked_fn!(
303320 "udf #16" ;
304321 //__NR_rt_sigreturn = const __NR_rt_sigreturn // TODO: Use this when `asm_const` is stabilized.
305322) ;
306- #[ cfg( test) ] // TODO: obviate this
323+ #[ cfg( feature = "take-charge" ) ]
324+ #[ test] // TODO: obviate this
307325fn test_rt_sigreturn ( ) {
308326 assert_eq ! ( __NR_rt_sigreturn, 173 ) ;
309327}
310328
329+ #[ cfg( feature = "take-charge" ) ]
311330#[ cfg( feature = "signal" ) ]
312331naked_fn ! (
313332 "
@@ -326,7 +345,8 @@ naked_fn!(
326345 "udf #16" ;
327346 //__NR_sigreturn = const __NR_sigreturn // TODO: Use this when `asm_const` is stabilized.
328347) ;
329- #[ cfg( test) ] // TODO: obviate this
348+ #[ cfg( feature = "take-charge" ) ]
349+ #[ test] // TODO: obviate this
330350fn test_sigreturn ( ) {
331351 assert_eq ! ( __NR_sigreturn, 119 ) ;
332352}
0 commit comments