move {get,set}_sp_limit into Rust-land
This commit is contained in:
parent
b961956ea5
commit
612e854acb
20
src/arch.rs
20
src/arch.rs
|
@ -9,10 +9,6 @@ extern "C" {
|
||||||
pub fn bootstrap();
|
pub fn bootstrap();
|
||||||
#[link_name = "lwt_swapcontext"]
|
#[link_name = "lwt_swapcontext"]
|
||||||
pub fn swapcontext(save: *mut Registers, restore: *mut Registers);
|
pub fn swapcontext(save: *mut Registers, restore: *mut Registers);
|
||||||
#[link_name = "lwt_get_sp_limit"]
|
|
||||||
pub fn get_sp_limit() -> *const u8;
|
|
||||||
#[link_name = "lwt_set_sp_limit"]
|
|
||||||
pub fn set_sp_limit(limit: *const u8);
|
|
||||||
#[link_name = "lwt_abort"]
|
#[link_name = "lwt_abort"]
|
||||||
pub fn abort() -> !;
|
pub fn abort() -> !;
|
||||||
}
|
}
|
||||||
|
@ -77,6 +73,22 @@ pub fn initialise_call_frame(stack: &mut Stack, init: uintptr_t, args: &[uintptr
|
||||||
regs
|
regs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Rust stores a stack limit at [fs:0x70]. These two functions set and retrieve
|
||||||
|
// the limit. They're marked as #[inline(always)] so that they can be used in
|
||||||
|
// situations where the stack limit is invalid.
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub unsafe fn get_sp_limit() -> *const u8 {
|
||||||
|
let limit;
|
||||||
|
asm!("movq %fs:0x70, $0" : "=r"(limit) ::: "volatile");
|
||||||
|
limit
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub unsafe fn set_sp_limit(limit: *const u8) {
|
||||||
|
asm!("movq $0, %fs:0x70" :: "r"(limit) :: "volatile");
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn align_down_mut<T>(sp: *mut T, n: uint) -> *mut T {
|
fn align_down_mut<T>(sp: *mut T, n: uint) -> *mut T {
|
||||||
let sp = (sp as uint) & !(n - 1);
|
let sp = (sp as uint) & !(n - 1);
|
||||||
|
|
16
src/arch.s
16
src/arch.s
|
@ -91,22 +91,6 @@ lwt_bootstrap:
|
||||||
mov r8, r15
|
mov r8, r15
|
||||||
jmp rbx
|
jmp rbx
|
||||||
|
|
||||||
|
|
||||||
;; Rust stores a stack limit at [fs:0x70]. These two functions set and retrieve
|
|
||||||
;; the limit. They could alternatively be implemented as #[inline(always)] Rust
|
|
||||||
;; functions, with inline assembly, but I prefer keeping all the assembly-land
|
|
||||||
;; stuff in here.
|
|
||||||
|
|
||||||
global lwt_set_sp_limit
|
|
||||||
lwt_set_sp_limit:
|
|
||||||
mov [fs:0x70], rdi
|
|
||||||
ret
|
|
||||||
|
|
||||||
global lwt_get_sp_limit
|
|
||||||
lwt_get_sp_limit:
|
|
||||||
mov rax, [fs:0x70]
|
|
||||||
ret
|
|
||||||
|
|
||||||
global lwt_abort
|
global lwt_abort
|
||||||
lwt_abort:
|
lwt_abort:
|
||||||
;; when a context is created for a native thread, it should only be switched
|
;; when a context is created for a native thread, it should only be switched
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#![feature(default_type_params, macro_rules, phase, globs)]
|
#![feature(default_type_params, macro_rules, phase, globs, asm)]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
|
||||||
#[phase(plugin, link)]
|
#[phase(plugin, link)]
|
||||||
|
|
Loading…
Reference in New Issue