Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make most of kernel crate-visible only, rather than public. #1089

Merged
merged 1 commit into from Jul 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 5 additions & 8 deletions kernel/src/callback.rs
Expand Up @@ -14,11 +14,11 @@ pub struct AppId {
const KERNEL_APPID_BOUNDARY: usize = 100;

impl AppId {
pub(crate) fn new(idx: usize) -> AppId {
crate fn new(idx: usize) -> AppId {
AppId { idx: idx }
}

pub(crate) const fn kernel_new(idx: usize) -> AppId {
crate const fn kernel_new(idx: usize) -> AppId {
AppId { idx: idx }
}

Expand All @@ -40,7 +40,7 @@ impl AppId {
}

#[derive(Clone, Copy, Debug)]
pub enum RustOrRawFnPtr {
crate enum RustOrRawFnPtr {
Raw {
ptr: NonNull<*mut ()>,
},
Expand All @@ -58,18 +58,15 @@ pub struct Callback {
}

impl Callback {
pub(crate) fn new(appid: AppId, appdata: usize, fn_ptr: NonNull<*mut ()>) -> Callback {
crate fn new(appid: AppId, appdata: usize, fn_ptr: NonNull<*mut ()>) -> Callback {
Callback {
app_id: appid,
appdata: appdata,
fn_ptr: RustOrRawFnPtr::Raw { ptr: fn_ptr },
}
}

pub(crate) const fn kernel_new(
appid: AppId,
fn_ptr: fn(usize, usize, usize, usize),
) -> Callback {
crate const fn kernel_new(appid: AppId, fn_ptr: fn(usize, usize, usize, usize)) -> Callback {
Callback {
app_id: appid,
appdata: 0,
Expand Down
8 changes: 4 additions & 4 deletions kernel/src/common/deferred_call.rs
Expand Up @@ -23,21 +23,21 @@ struct AtomicUsize {
}

impl AtomicUsize {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be crate-restricted? I could imagine cases when peripherals (e.g., that directly handle interrupts) might need it. Right now we put all interrupts through kernel serialization but it's important that chips be able to do this in theory. Also, depending on the memory consistency model, they might need to.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, though #1083 proposes getting rid of this anyway since there now there is a replacement for it in Rust's core library (which is like what other code should use).

pub const fn new(v: usize) -> AtomicUsize {
crate const fn new(v: usize) -> AtomicUsize {
AtomicUsize {
v: UnsafeCell::new(v),
}
}

pub fn load_relaxed(&self) -> usize {
crate fn load_relaxed(&self) -> usize {
unsafe { intrinsics::atomic_load_relaxed(self.v.get()) }
}

pub fn store_relaxed(&self, val: usize) {
crate fn store_relaxed(&self, val: usize) {
unsafe { intrinsics::atomic_store_relaxed(self.v.get(), val) }
}

pub fn fetch_or_relaxed(&self, val: usize) {
crate fn fetch_or_relaxed(&self, val: usize) {
unsafe { intrinsics::atomic_store_relaxed(self.v.get(), self.load_relaxed() | val) }
}
}
Expand Down
4 changes: 2 additions & 2 deletions kernel/src/grant.rs
Expand Up @@ -8,7 +8,7 @@ use core::ptr::{read_volatile, write_volatile, Unique};
use debug;
use process::{self, Error};

pub static mut CONTAINER_COUNTER: usize = 0;
crate static mut CONTAINER_COUNTER: usize = 0;

pub struct Grant<T: Default> {
grant_num: usize,
Expand All @@ -26,7 +26,7 @@ pub struct AppliedGrant<T> {
/// stored in a processes array, and finding apps is a matter of iterating that
/// array. Kernel "apps" currently (June 2018) have no such structure, so
/// finding them is a bit more ad-hoc.
pub unsafe fn kernel_grant_for<T>(app_id: usize) -> *mut T {
crate unsafe fn kernel_grant_for<T>(app_id: usize) -> *mut T {
match app_id {
debug::APPID_IDX => debug::get_grant(),
_ => panic!("lookup for invalid kernel grant {}", app_id),
Expand Down
3 changes: 2 additions & 1 deletion kernel/src/lib.rs
Expand Up @@ -8,7 +8,8 @@

#![feature(asm, core_intrinsics, unique, ptr_internals, const_fn)]
#![feature(use_extern_macros, try_from, used)]
#![feature(in_band_lifetimes)]
#![feature(in_band_lifetimes, crate_visibility_modifier)]
#![warn(unreachable_pub)]
#![no_std]

extern crate tock_cells;
Expand Down
4 changes: 2 additions & 2 deletions kernel/src/mem.rs
Expand Up @@ -62,7 +62,7 @@ pub struct AppSlice<L, T> {
}

impl<L, T> AppSlice<L, T> {
pub(crate) fn new(ptr: *mut T, len: usize, appid: AppId) -> AppSlice<L, T> {
crate fn new(ptr: *mut T, len: usize, appid: AppId) -> AppSlice<L, T> {
unsafe {
AppSlice {
ptr: AppPtr::new(ptr, appid),
Expand All @@ -79,7 +79,7 @@ impl<L, T> AppSlice<L, T> {
unsafe { self.ptr.ptr.as_ref() as *const T }
}

pub unsafe fn expose_to(&self, appid: AppId) -> bool {
crate unsafe fn expose_to(&self, appid: AppId) -> bool {
let ps = &mut process::PROCS;
if appid.idx() != self.ptr.process.idx() && ps.len() > appid.idx() {
ps[appid.idx()]
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/memop.rs
Expand Up @@ -36,7 +36,7 @@ use returncode::ReturnCode;
/// where the app has put the start of its heap. This is not strictly
/// necessary for correct operation, but allows for better debugging if the
/// app crashes.
pub fn memop(process: &mut Process) -> ReturnCode {
crate fn memop(process: &mut Process) -> ReturnCode {
let op_type = process.r0();
let r1 = process.r1();

Expand Down
2 changes: 1 addition & 1 deletion kernel/src/platform/mod.rs
Expand Up @@ -3,7 +3,7 @@
use driver::Driver;

pub mod mpu;
pub mod systick;
crate mod systick;

/// Interface for individual boards.
pub trait Platform {
Expand Down