2015-04-16 20:06:57 +08:00
|
|
|
// This file is part of libfringe, a low-level green threading library.
|
2016-03-22 15:25:23 +08:00
|
|
|
// Copyright (c) edef <edef@edef.eu>
|
2016-08-21 05:45:01 +08:00
|
|
|
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
|
|
|
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
|
|
|
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
|
|
|
// copied, modified, or distributed except according to those terms.
|
2016-08-19 21:58:45 +08:00
|
|
|
//! Traits for stacks.
|
2015-04-16 11:37:17 +08:00
|
|
|
|
|
|
|
/// A trait for objects that hold ownership of a stack.
|
2016-09-03 00:00:11 +08:00
|
|
|
///
|
|
|
|
/// To preserve memory safety, an implementation of this trait must fulfill
|
|
|
|
/// the following contract:
|
|
|
|
///
|
2016-09-03 06:14:07 +08:00
|
|
|
/// * The base address of the stack must be aligned to
|
|
|
|
/// a [`STACK_ALIGNMENT`][align]-byte boundary.
|
2016-09-03 00:00:11 +08:00
|
|
|
/// * Every address between the base and the limit must be readable and writable.
|
|
|
|
///
|
2016-09-03 06:14:07 +08:00
|
|
|
/// [align]: constant.STACK_ALIGNMENT.html
|
2015-01-14 15:31:17 +08:00
|
|
|
pub trait Stack {
|
2016-09-03 06:14:07 +08:00
|
|
|
/// Returns the base address of the stack.
|
2015-04-16 11:37:17 +08:00
|
|
|
/// On all modern architectures, the stack grows downwards,
|
|
|
|
/// so this is the highest address.
|
2016-08-12 07:18:36 +08:00
|
|
|
fn base(&self) -> *mut u8;
|
2016-09-03 06:14:07 +08:00
|
|
|
/// Returns the limit address of the stack.
|
2015-04-16 11:37:17 +08:00
|
|
|
/// On all modern architectures, the stack grows downwards,
|
|
|
|
/// so this is the lowest address.
|
2016-07-16 09:22:41 +08:00
|
|
|
fn limit(&self) -> *mut u8;
|
2014-12-23 11:24:40 +08:00
|
|
|
}
|
2016-07-17 11:45:50 +08:00
|
|
|
|
|
|
|
/// A marker trait for `Stack` objects with a guard page.
|
|
|
|
///
|
2016-09-03 00:00:11 +08:00
|
|
|
/// To preserve memory safety, an implementation of this trait must fulfill
|
|
|
|
/// the following contract, in addition to the [contract](trait.Stack.html) of `Stack`:
|
|
|
|
///
|
|
|
|
/// * Any access of data at addresses `limit()` to `limit().offset(4096)` must
|
|
|
|
/// abnormally terminate, at least, the thread that performs the access.
|
2016-07-17 11:45:50 +08:00
|
|
|
pub unsafe trait GuardedStack {}
|