Skip to content

Commit 533b1e5

Browse files
authored
Remove workarounds for asm_const. (#159)
The `asm_const` feature is now stablized, so we can remove these workarounds.
1 parent 85f3e2c commit 533b1e5

File tree

6 files changed

+22
-108
lines changed

6 files changed

+22
-108
lines changed

src/arch/aarch64.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use core::arch::asm;
1010
use linux_raw_sys::elf::Elf_Ehdr;
1111
#[cfg(feature = "take-charge")]
1212
#[cfg(feature = "signal")]
13-
#[cfg(test)]
1413
use linux_raw_sys::general::__NR_rt_sigreturn;
1514
#[cfg(all(feature = "experimental-relocate", feature = "origin-start"))]
1615
#[cfg(relocation_model = "pic")]
@@ -275,14 +274,13 @@ pub(super) const TLS_OFFSET: usize = 0;
275274
#[cfg(feature = "thread")]
276275
#[inline]
277276
pub(super) unsafe fn munmap_and_exit_thread(map_addr: *mut c_void, map_len: usize) -> ! {
278-
assert_eq!(__NR_exit, 93); // TODO: obviate this
279277
asm!(
280278
"svc 0",
281279
"mov x0, xzr",
282-
"mov x8, 93", // TODO: use {__NR_exit}
280+
"mov x8, {__NR_exit}",
283281
"svc 0",
284282
"udf #16",
285-
//__NR_exit = const __NR_exit, // TODO: Use this when `asm_const` is stabilized.
283+
__NR_exit = const __NR_exit,
286284
in("x8") __NR_munmap,
287285
in("x0") map_addr,
288286
in("x1") map_len,
@@ -304,16 +302,11 @@ naked_fn!(
304302
";
305303
pub(super) fn return_from_signal_handler() -> ();
306304

307-
"mov x8, 139", // TODO: use {__NR_rt_sigreturn}
305+
"mov x8, {__NR_rt_sigreturn}",
308306
"svc 0",
309307
"udf #16";
310-
//__NR_rt_sigreturn = const __NR_rt_sigreturn // TODO: Use this when `asm_const` is stabilized.
308+
__NR_rt_sigreturn = const __NR_rt_sigreturn
311309
);
312-
#[cfg(feature = "take-charge")]
313-
#[test] // TODO: obviate this
314-
fn test_rt_sigreturn() {
315-
assert_eq!(__NR_rt_sigreturn, 139);
316-
}
317310

318311
/// Invoke the appropriate system call to return control from a signal
319312
/// handler that does not use `SA_SIGINFO`. On aarch64, this uses the same

src/arch/arm.rs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use linux_raw_sys::elf::Elf_Ehdr;
1313
use linux_raw_sys::general::{__NR_mprotect, PROT_READ};
1414
#[cfg(feature = "take-charge")]
1515
#[cfg(feature = "signal")]
16-
#[cfg(test)]
1716
use linux_raw_sys::general::{__NR_rt_sigreturn, __NR_sigreturn};
1817
#[cfg(feature = "take-charge")]
1918
#[cfg(feature = "thread")]
@@ -289,14 +288,13 @@ pub(super) const TLS_OFFSET: usize = 0;
289288
#[cfg(feature = "thread")]
290289
#[inline]
291290
pub(super) unsafe fn munmap_and_exit_thread(map_addr: *mut c_void, map_len: usize) -> ! {
292-
assert_eq!(__NR_exit, 1); // TODO: obviate this
293291
asm!(
294292
"svc 0",
295293
"mov r0, #0",
296-
"mov r7, #1", // TODO: use {__NR_exit}
294+
"mov r7, {__NR_exit}",
297295
"svc 0",
298296
"udf #16",
299-
//__NR_exit = const __NR_exit, // TODO: Use this when `asm_const` is stabilized.
297+
__NR_exit = const __NR_exit,
300298
in("r7") __NR_munmap,
301299
in("r0") map_addr,
302300
in("r1") map_len,
@@ -318,16 +316,11 @@ naked_fn!(
318316
";
319317
pub(super) fn return_from_signal_handler() -> ();
320318

321-
"mov r7, 173", // TODO: use {__NR_rt_sigreturn}
319+
"mov r7, {__NR_rt_sigreturn}",
322320
"swi 0",
323321
"udf #16";
324-
//__NR_rt_sigreturn = const __NR_rt_sigreturn // TODO: Use this when `asm_const` is stabilized.
322+
__NR_rt_sigreturn = const __NR_rt_sigreturn
325323
);
326-
#[cfg(feature = "take-charge")]
327-
#[test] // TODO: obviate this
328-
fn test_rt_sigreturn() {
329-
assert_eq!(__NR_rt_sigreturn, 173);
330-
}
331324

332325
#[cfg(feature = "take-charge")]
333326
#[cfg(feature = "signal")]
@@ -343,13 +336,8 @@ naked_fn!(
343336
";
344337
pub(super) fn return_from_signal_handler_noinfo() -> ();
345338

346-
"mov r7, 119", // TODO: use {__NR_sigreturn}
339+
"mov r7, {__NR_sigreturn}",
347340
"swi 0",
348341
"udf #16";
349-
//__NR_sigreturn = const __NR_sigreturn // TODO: Use this when `asm_const` is stabilized.
342+
__NR_sigreturn = const __NR_sigreturn
350343
);
351-
#[cfg(feature = "take-charge")]
352-
#[test] // TODO: obviate this
353-
fn test_sigreturn() {
354-
assert_eq!(__NR_sigreturn, 119);
355-
}

src/arch/riscv64.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,14 +293,13 @@ pub(super) const TLS_OFFSET: usize = 0x800;
293293
#[cfg(feature = "thread")]
294294
#[inline]
295295
pub(super) unsafe fn munmap_and_exit_thread(map_addr: *mut c_void, map_len: usize) -> ! {
296-
assert_eq!(__NR_exit, 93); // TODO: obviate this
297296
asm!(
298297
"ecall",
299298
"mv a0, zero",
300-
"li a7, 93", // TODO: use {__NR_exit}
299+
"li a7, {__NR_exit}",
301300
"ecall",
302301
"unimp",
303-
//__NR_exit = const __NR_exit, // TODO: Use this when `asm_const` is stabilized.
302+
__NR_exit = const __NR_exit,
304303
in("a7") __NR_munmap,
305304
in("a0") map_addr,
306305
in("a1") map_len,

src/arch/x86.rs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use linux_raw_sys::elf::Elf_Ehdr;
1616
use linux_raw_sys::general::{__NR_mprotect, PROT_READ};
1717
#[cfg(feature = "take-charge")]
1818
#[cfg(feature = "signal")]
19-
#[cfg(test)]
2019
use linux_raw_sys::general::{__NR_rt_sigreturn, __NR_sigreturn};
2120
#[cfg(feature = "take-charge")]
2221
#[cfg(feature = "thread")]
@@ -371,16 +370,15 @@ pub(super) const TLS_OFFSET: usize = 0;
371370
#[cfg(feature = "thread")]
372371
#[inline]
373372
pub(super) unsafe fn munmap_and_exit_thread(map_addr: *mut c_void, map_len: usize) -> ! {
374-
assert_eq!(__NR_exit, 1); // TODO: obviate this
375373
asm!(
376374
// Use `int 0x80` instead of vsyscall, since vsyscall would attempt to
377375
// touch the stack after we `munmap` it.
378376
"int 0x80",
379377
"xor ebx, ebx",
380-
"mov eax, 1", // TODO: use {__NR_exit}
378+
"mov eax, {__NR_exit}",
381379
"int 0x80",
382380
"ud2",
383-
//__NR_exit = const __NR_exit, // TODO: Use this when `asm_const` is stabilized.
381+
__NR_exit = const __NR_exit,
384382
in("eax") __NR_munmap,
385383
in("ebx") map_addr,
386384
in("ecx") map_len,
@@ -402,17 +400,11 @@ naked_fn!(
402400
";
403401
pub(super) fn return_from_signal_handler() -> ();
404402

405-
"mov eax, 173", // TODO: use {__NR_rt_sigreturn}
403+
"mov eax, {__NR_rt_sigreturn}",
406404
"int 0x80",
407405
"ud2";
408-
//__NR_rt_sigreturn = const __NR_rt_sigreturn // TODO: Use this when `asm_const` is stabilized.
406+
__NR_rt_sigreturn = const __NR_rt_sigreturn
409407
);
410-
#[cfg(feature = "take-charge")]
411-
#[cfg(feature = "signal")]
412-
#[test] // TODO: obviate this
413-
fn test_rt_sigreturn() {
414-
assert_eq!(__NR_rt_sigreturn, 173);
415-
}
416408

417409
#[cfg(feature = "take-charge")]
418410
#[cfg(feature = "signal")]
@@ -429,14 +421,8 @@ naked_fn!(
429421
pub(super) fn return_from_signal_handler_noinfo() -> ();
430422

431423
"pop eax",
432-
"mov eax, 119", // TODO: use {__NR_sigreturn}
424+
"mov eax, {__NR_sigreturn}",
433425
"int 0x80",
434426
"ud2";
435-
//__NR_sigreturn = const __NR_sigreturn // TODO: Use this when `asm_const` is stabilized.
427+
__NR_sigreturn = const __NR_sigreturn
436428
);
437-
#[cfg(feature = "take-charge")]
438-
#[cfg(feature = "signal")]
439-
#[test] // TODO: obviate this
440-
fn test_sigreturn() {
441-
assert_eq!(__NR_sigreturn, 119);
442-
}

src/arch/x86_64.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use core::arch::asm;
1010
use linux_raw_sys::elf::Elf_Ehdr;
1111
#[cfg(feature = "take-charge")]
1212
#[cfg(feature = "signal")]
13-
#[cfg(test)]
1413
use linux_raw_sys::general::__NR_rt_sigreturn;
1514
#[cfg(all(feature = "experimental-relocate", feature = "origin-start"))]
1615
#[cfg(relocation_model = "pic")]
@@ -283,14 +282,13 @@ pub(super) const TLS_OFFSET: usize = 0;
283282
#[cfg(feature = "thread")]
284283
#[inline]
285284
pub(super) unsafe fn munmap_and_exit_thread(map_addr: *mut c_void, map_len: usize) -> ! {
286-
assert_eq!(__NR_exit, 60); // TODO: obviate this
287285
asm!(
288286
"syscall",
289287
"xor edi, edi",
290-
"mov eax, 60", // TODO: use {__NR_exit}
288+
"mov eax, {__NR_exit}",
291289
"syscall",
292290
"ud2",
293-
//__NR_exit = const __NR_exit, // TODO: Use this when `asm_const` is stabilized.
291+
__NR_exit = const __NR_exit,
294292
in("rax") __NR_munmap,
295293
in("rdi") map_addr,
296294
in("rsi") map_len,
@@ -312,16 +310,11 @@ naked_fn!(
312310
";
313311
pub(super) fn return_from_signal_handler() -> ();
314312

315-
"mov rax, 15", // TODO: use {__NR_rt_sigreturn}
313+
"mov rax, {__NR_rt_sigreturn}",
316314
"syscall",
317315
"ud2";
318-
//__NR_rt_sigreturn = const __NR_rt_sigreturn // TODO: Use this when `asm_const` is stabilized.
316+
__NR_rt_sigreturn = const __NR_rt_sigreturn
319317
);
320-
#[cfg(feature = "take-charge")]
321-
#[test] // TODO: obviate this
322-
fn test_rt_sigreturn() {
323-
assert_eq!(__NR_rt_sigreturn, 15);
324-
}
325318

326319
/// Invoke the appropriate system call to return control from a signal
327320
/// handler that does not use `SA_SIGINFO`. On x86-64, this uses the same

tests/abi.rs

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)