Skip to content

Commit d3303cb

Browse files
whitequarkedef1c
authored andcommitted
Don't use core::intrinsics.
The core::intrinsics::unreachable() we used at the end of every naked function is essentially pointless, as #[naked] implies that intrinsic at the end of the function. rustc currently does not implement that behavior (rust-lang/rust#32487), but it is a bug. On top of that, anything except a single asm!() in naked functions is likely to be disallowed in the future (rust-lang/rust#32490). A nice side effect is that we avoid the core_intrinsics feature, which will be never stabilized, though neither asm nor naked_functions are likely to be stabilized soon.
1 parent 8043496 commit d3303cb

File tree

3 files changed

+13
-23
lines changed

3 files changed

+13
-23
lines changed

src/arch/x86.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,14 @@
2828
// after. A .cfi_def_* pseudoinstruction changes the CFA value similarly.
2929
// * Simulating return is as easy as restoring register values from the CFI table
3030
// and then setting stack pointer to CFA.
31-
use core::intrinsics;
3231
use stack::Stack;
3332

3433
#[derive(Debug)]
3534
pub struct StackPointer(*mut usize);
3635

3736
pub unsafe fn init(stack: &Stack, f: unsafe extern "C" fn(usize) -> !) -> StackPointer {
3837
#[naked]
39-
unsafe extern "C" fn init_trampoline_1() -> ! {
38+
unsafe extern "C" fn init_trampoline_1() {
4039
asm!(
4140
r#"
4241
# gdb has a hardcoded check that rejects backtraces where frame addresses
@@ -60,12 +59,11 @@ pub unsafe fn init(stack: &Stack, f: unsafe extern "C" fn(usize) -> !) -> StackP
6059
.Lend:
6160
.size __morestack, .Lend-__morestack
6261
"#
63-
: : "s" (init_trampoline_2 as usize) : "memory" : "volatile");
64-
intrinsics::unreachable()
62+
: : "s" (init_trampoline_2 as usize) : "memory" : "volatile")
6563
}
6664

6765
#[naked]
68-
unsafe extern "C" fn init_trampoline_2() -> ! {
66+
unsafe extern "C" fn init_trampoline_2() {
6967
asm!(
7068
r#"
7169
# Set up the second part of our DWARF CFI.
@@ -78,8 +76,7 @@ pub unsafe fn init(stack: &Stack, f: unsafe extern "C" fn(usize) -> !) -> StackP
7876
# Call the provided function.
7977
call *8(%esp)
8078
"#
81-
: : : "memory" : "volatile");
82-
intrinsics::unreachable()
79+
: : : "memory" : "volatile")
8380
}
8481

8582
unsafe fn push(sp: &mut StackPointer, val: usize) {
@@ -102,7 +99,7 @@ pub unsafe fn swap(arg: usize, old_sp: &mut StackPointer, new_sp: &StackPointer,
10299
let new_cfa = (new_stack.top() as *mut usize).offset(-1);
103100

104101
#[naked]
105-
unsafe extern "C" fn swap_trampoline() -> ! {
102+
unsafe extern "C" fn swap_trampoline() {
106103
asm!(
107104
r#"
108105
# Save frame pointer explicitly; the unwinder uses it to find CFA of
@@ -125,8 +122,7 @@ pub unsafe fn swap(arg: usize, old_sp: &mut StackPointer, new_sp: &StackPointer,
125122
popl %ebx
126123
jmpl *%ebx
127124
"#
128-
: : : "memory" : "volatile");
129-
intrinsics::unreachable();
125+
: : : "memory" : "volatile")
130126
}
131127

132128
let ret: usize;

src/arch/x86_64.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,14 @@
3232
// after. A .cfi_def_* pseudoinstruction changes the CFA value similarly.
3333
// * Simulating return is as easy as restoring register values from the CFI table
3434
// and then setting stack pointer to CFA.
35-
use core::intrinsics;
3635
use stack::Stack;
3736

3837
#[derive(Debug)]
3938
pub struct StackPointer(*mut usize);
4039

4140
pub unsafe fn init(stack: &Stack, f: unsafe extern "C" fn(usize) -> !) -> StackPointer {
4241
#[naked]
43-
unsafe extern "C" fn init_trampoline_1() -> ! {
42+
unsafe extern "C" fn init_trampoline_1() {
4443
asm!(
4544
r#"
4645
# gdb has a hardcoded check that rejects backtraces where frame addresses
@@ -64,12 +63,11 @@ pub unsafe fn init(stack: &Stack, f: unsafe extern "C" fn(usize) -> !) -> StackP
6463
.Lend:
6564
.size __morestack, .Lend-__morestack
6665
"#
67-
: : "s" (init_trampoline_2 as usize) : "memory" : "volatile");
68-
intrinsics::unreachable()
66+
: : "s" (init_trampoline_2 as usize) : "memory" : "volatile")
6967
}
7068

7169
#[naked]
72-
unsafe extern "C" fn init_trampoline_2() -> ! {
70+
unsafe extern "C" fn init_trampoline_2() {
7371
asm!(
7472
r#"
7573
# Set up the second part of our DWARF CFI.
@@ -79,8 +77,7 @@ pub unsafe fn init(stack: &Stack, f: unsafe extern "C" fn(usize) -> !) -> StackP
7977
# Call the provided function.
8078
call *8(%rsp)
8179
"#
82-
: : : "memory" : "volatile");
83-
intrinsics::unreachable()
80+
: : : "memory" : "volatile")
8481
}
8582

8683
unsafe fn push(sp: &mut StackPointer, val: usize) {
@@ -104,7 +101,7 @@ pub unsafe fn swap(arg: usize, old_sp: &mut StackPointer, new_sp: &StackPointer,
104101
let new_cfa = (new_stack.top() as *mut usize).offset(-1);
105102

106103
#[naked]
107-
unsafe extern "C" fn swap_trampoline() -> ! {
104+
unsafe extern "C" fn swap_trampoline() {
108105
asm!(
109106
r#"
110107
# Save frame pointer explicitly; the unwinder uses it to find CFA of
@@ -127,8 +124,7 @@ pub unsafe fn swap(arg: usize, old_sp: &mut StackPointer, new_sp: &StackPointer,
127124
popq %rbx
128125
jmpq *%rbx
129126
"#
130-
: : : "memory" : "volatile");
131-
intrinsics::unreachable();
127+
: : : "memory" : "volatile")
132128
}
133129

134130
let ret: usize;

src/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
// This file is part of libfringe, a low-level green threading library.
22
// Copyright (c) Nathan Zadoks <[email protected]>
33
// See the LICENSE file included in this distribution.
4-
#![feature(asm)]
4+
#![feature(asm, naked_functions)]
55
#![cfg_attr(test, feature(test, thread_local, const_fn))]
6-
#![cfg_attr(target_arch = "x86", feature(naked_functions, core_intrinsics))]
7-
#![cfg_attr(target_arch = "x86_64", feature(naked_functions, core_intrinsics))]
86
#![no_std]
97

108
//! libfringe is a library implementing safe, lightweight context switches,

0 commit comments

Comments
 (0)