From b79e7c0a9bbeda2c285a7551c1206e7ea48c747c Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 11 Aug 2016 23:18:36 +0000 Subject: [PATCH] Rename Stack::top() to Stack::base(), which is correct. Fixes #25. --- src/arch/x86.rs | 4 ++-- src/arch/x86_64.rs | 4 ++-- src/debug/valgrind.rs | 2 +- src/os/mod.rs | 2 +- src/stack.rs | 4 ++-- tests/stack.rs | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/arch/x86.rs b/src/arch/x86.rs index 6272232..75c8fea 100644 --- a/src/arch/x86.rs +++ b/src/arch/x86.rs @@ -84,7 +84,7 @@ pub unsafe fn init(stack: &Stack, f: unsafe extern "C" fn(usize) -> !) -> StackP *sp.0 = val } - let mut sp = StackPointer(stack.top() as *mut usize); + let mut sp = StackPointer(stack.base() as *mut usize); push(&mut sp, 0xdead0cfa); // CFA slot push(&mut sp, f as usize); // function push(&mut sp, trampoline_1 as usize); @@ -96,7 +96,7 @@ pub unsafe fn init(stack: &Stack, f: unsafe extern "C" fn(usize) -> !) -> StackP pub unsafe fn swap(arg: usize, old_sp: &mut StackPointer, new_sp: &StackPointer, new_stack: &Stack) -> usize { // Address of the topmost CFA stack slot. - let new_cfa = (new_stack.top() as *mut usize).offset(-1); + let new_cfa = (new_stack.base() as *mut usize).offset(-1); #[naked] unsafe extern "C" fn trampoline() { diff --git a/src/arch/x86_64.rs b/src/arch/x86_64.rs index 25c808f..ee6510b 100644 --- a/src/arch/x86_64.rs +++ b/src/arch/x86_64.rs @@ -85,7 +85,7 @@ pub unsafe fn init(stack: &Stack, f: unsafe extern "C" fn(usize) -> !) -> StackP *sp.0 = val } - let mut sp = StackPointer(stack.top() as *mut usize); + let mut sp = StackPointer(stack.base() as *mut usize); push(&mut sp, 0xdeaddeaddead0cfa); // CFA slot push(&mut sp, 0 as usize); // alignment push(&mut sp, f as usize); // function @@ -98,7 +98,7 @@ pub unsafe fn init(stack: &Stack, f: unsafe extern "C" fn(usize) -> !) -> StackP pub unsafe fn swap(arg: usize, old_sp: &mut StackPointer, new_sp: &StackPointer, new_stack: &Stack) -> usize { // Address of the topmost CFA stack slot. - let new_cfa = (new_stack.top() as *mut usize).offset(-1); + let new_cfa = (new_stack.base() as *mut usize).offset(-1); #[naked] unsafe extern "C" fn trampoline() { diff --git a/src/debug/valgrind.rs b/src/debug/valgrind.rs index 59dff44..9979cb9 100644 --- a/src/debug/valgrind.rs +++ b/src/debug/valgrind.rs @@ -12,7 +12,7 @@ pub struct StackId(self::valgrind::Value); impl StackId { #[inline(always)] pub fn register(stack: &Stack) -> StackId { - StackId(stack_register(stack.limit(), stack.top())) + StackId(stack_register(stack.limit(), stack.base())) } } diff --git a/src/os/mod.rs b/src/os/mod.rs index 05160a4..fc93def 100644 --- a/src/os/mod.rs +++ b/src/os/mod.rs @@ -51,7 +51,7 @@ impl Stack { impl stack::Stack for Stack { #[inline(always)] - fn top(&self) -> *mut u8 { + fn base(&self) -> *mut u8 { unsafe { self.ptr.offset(self.len as isize) } diff --git a/src/stack.rs b/src/stack.rs index fca5ed0..a861ddd 100644 --- a/src/stack.rs +++ b/src/stack.rs @@ -5,10 +5,10 @@ /// A trait for objects that hold ownership of a stack. pub trait Stack { - /// Returns the top of the stack. + /// Returns the base of the stack. /// On all modern architectures, the stack grows downwards, /// so this is the highest address. - fn top(&self) -> *mut u8; + fn base(&self) -> *mut u8; /// Returns the bottom of the stack. /// On all modern architectures, the stack grows downwards, /// so this is the lowest address. diff --git a/tests/stack.rs b/tests/stack.rs index 6c9f049..e2dd5d0 100644 --- a/tests/stack.rs +++ b/tests/stack.rs @@ -9,12 +9,12 @@ use fringe::{Stack, OsStack}; fn default_stack() { let stack = OsStack::new(0).unwrap(); // Make sure the topmost page of the stack, at least, is accessible. - unsafe { *(stack.top().offset(-1)) = 0; } + unsafe { *(stack.base().offset(-1)) = 0; } } #[test] fn one_page_stack() { let stack = OsStack::new(4096).unwrap(); // Make sure the topmost page of the stack, at least, is accessible. - unsafe { *(stack.top().offset(-1)) = 0; } + unsafe { *(stack.base().offset(-1)) = 0; } }