Skip to content

Commit e55596f

Browse files
committed
Move rt into sys::rt, fix tidy
1 parent 01157e6 commit e55596f

File tree

18 files changed

+163
-337
lines changed

18 files changed

+163
-337
lines changed

src/libstd/rt.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@
2626
pub use panicking::{begin_panic, begin_panic_fmt, update_panic_count};
2727

2828
// Reexport the start module on platforms that provide it
29-
#[unstable(feature = "start_fn", issue="0")]
30-
#[cfg(target_os = "redox")]
31-
pub use sys::start::*;
29+
#[unstable(feature = "sys_rt", issue="0")]
30+
pub use sys::rt::*;
3231

3332
#[cfg(not(test))]
3433
#[lang = "start"]

src/libstd/sys/redox/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ pub mod path;
2929
pub mod pipe;
3030
pub mod process;
3131
pub mod rand;
32+
pub mod rt;
3233
pub mod rwlock;
3334
pub mod stack_overflow;
34-
pub mod start;
3535
pub mod stdio;
3636
pub mod syscall;
3737
pub mod thread;

src/libstd/sys/redox/net/netc.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
111
pub type in_addr_t = u32;
212
pub type in_port_t = u16;
313

src/libstd/sys/redox/start.rs renamed to src/libstd/sys/redox/rt.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
//! Defintion of functions like _start for the linker
12+
113
use sys::syscall::exit;
214

3-
#[unstable(feature = "start_fn", issue = "0")]
15+
#[unstable(feature = "sys_rt", issue = "0")]
416
#[no_mangle]
517
#[naked]
618
#[cfg(target_arch = "x86")]
@@ -15,7 +27,7 @@ pub unsafe fn _start() {
1527
let _ = exit(0);
1628
}
1729

18-
#[unstable(feature = "start_fn", issue = "0")]
30+
#[unstable(feature = "sys_rt", issue = "0")]
1931
#[no_mangle]
2032
#[naked]
2133
#[cfg(target_arch = "x86_64")]
@@ -30,7 +42,7 @@ pub unsafe fn _start() {
3042
let _ = exit(0);
3143
}
3244

33-
#[unstable(feature = "start_fn", issue = "0")]
45+
#[unstable(feature = "sys_rt", issue = "0")]
3446
#[no_mangle]
3547
pub unsafe extern "C" fn _start_stack(stack: *const usize){
3648
extern "C" {
@@ -45,7 +57,7 @@ pub unsafe extern "C" fn _start_stack(stack: *const usize){
4557
/// Memcpy
4658
///
4759
/// Copy N bytes of memory from one location to another.
48-
#[unstable(feature = "start_fn", issue = "0")]
60+
#[unstable(feature = "sys_rt", issue = "0")]
4961
#[no_mangle]
5062
pub unsafe extern fn memcpy(dest: *mut u8, src: *const u8,
5163
n: usize) -> *mut u8 {
@@ -61,7 +73,7 @@ pub unsafe extern fn memcpy(dest: *mut u8, src: *const u8,
6173
/// Memmove
6274
///
6375
/// Copy N bytes of memory from src to dest. The memory areas may overlap.
64-
#[unstable(feature = "start_fn", issue = "0")]
76+
#[unstable(feature = "sys_rt", issue = "0")]
6577
#[no_mangle]
6678
pub unsafe extern fn memmove(dest: *mut u8, src: *const u8,
6779
n: usize) -> *mut u8 {
@@ -85,7 +97,7 @@ pub unsafe extern fn memmove(dest: *mut u8, src: *const u8,
8597
/// Memset
8698
///
8799
/// Fill a block of memory with a specified value.
88-
#[unstable(feature = "start_fn", issue = "0")]
100+
#[unstable(feature = "sys_rt", issue = "0")]
89101
#[no_mangle]
90102
pub unsafe extern fn memset(dest: *mut u8, c: i32, n: usize) -> *mut u8 {
91103
let mut i = 0;
@@ -100,7 +112,7 @@ pub unsafe extern fn memset(dest: *mut u8, c: i32, n: usize) -> *mut u8 {
100112
/// Memcmp
101113
///
102114
/// Compare two blocks of memory.
103-
#[unstable(feature = "start_fn", issue = "0")]
115+
#[unstable(feature = "sys_rt", issue = "0")]
104116
#[no_mangle]
105117
pub unsafe extern fn memcmp(s1: *const u8, s2: *const u8, n: usize) -> i32 {
106118
let mut i = 0;

src/libstd/sys/redox/syscall/arch/arm.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
111
use super::error::{Error, Result};
212

313
pub unsafe fn syscall0(mut a: usize) -> Result<usize> {
@@ -61,7 +71,8 @@ pub unsafe fn syscall4(mut a: usize, b: usize, c: usize, d: usize, e: usize) ->
6171
Error::demux(a)
6272
}
6373

64-
pub unsafe fn syscall5(mut a: usize, b: usize, c: usize, d: usize, e: usize, f: usize) -> Result<usize> {
74+
pub unsafe fn syscall5(mut a: usize, b: usize, c: usize, d: usize, e: usize, f: usize)
75+
-> Result<usize> {
6576
asm!("swi $$0"
6677
: "={r0}"(a)
6778
: "{r7}"(a), "{r0}"(b), "{r1}"(c), "{r2}"(d), "{r3}"(e), "{r4}"(f)

src/libstd/sys/redox/syscall/arch/x86.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
111
use super::error::{Error, Result};
212

313
pub unsafe fn syscall0(mut a: usize) -> Result<usize> {
@@ -61,7 +71,8 @@ pub unsafe fn syscall4(mut a: usize, b: usize, c: usize, d: usize, e: usize) ->
6171
Error::demux(a)
6272
}
6373

64-
pub unsafe fn syscall5(mut a: usize, b: usize, c: usize, d: usize, e: usize, f: usize) -> Result<usize> {
74+
pub unsafe fn syscall5(mut a: usize, b: usize, c: usize, d: usize, e: usize, f: usize)
75+
-> Result<usize> {
6576
asm!("int 0x80"
6677
: "={eax}"(a)
6778
: "{eax}"(a), "{ebx}"(b), "{ecx}"(c), "{edx}"(d), "{esi}"(e), "{edi}"(f)

src/libstd/sys/redox/syscall/arch/x86_64.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
111
use super::error::{Error, Result};
212

313
pub unsafe fn syscall0(mut a: usize) -> Result<usize> {
@@ -25,7 +35,8 @@ pub unsafe fn syscall1_clobber(mut a: usize, b: usize) -> Result<usize> {
2535
asm!("int 0x80"
2636
: "={rax}"(a)
2737
: "{rax}"(a), "{rbx}"(b)
28-
: "memory", "rbx", "rcx", "rdx", "rsi", "rdi", "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
38+
: "memory", "rbx", "rcx", "rdx", "rsi", "rdi", "r8",
39+
"r9", "r10", "r11", "r12", "r13", "r14", "r15"
2940
: "intel", "volatile");
3041

3142
Error::demux(a)
@@ -61,7 +72,8 @@ pub unsafe fn syscall4(mut a: usize, b: usize, c: usize, d: usize, e: usize) ->
6172
Error::demux(a)
6273
}
6374

64-
pub unsafe fn syscall5(mut a: usize, b: usize, c: usize, d: usize, e: usize, f: usize) -> Result<usize> {
75+
pub unsafe fn syscall5(mut a: usize, b: usize, c: usize, d: usize, e: usize, f: usize)
76+
-> Result<usize> {
6577
asm!("int 0x80"
6678
: "={rax}"(a)
6779
: "{rax}"(a), "{rbx}"(b), "{rcx}"(c), "{rdx}"(d), "{rsi}"(e), "{rdi}"(f)

src/libstd/sys/redox/syscall/call.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
111
use super::arch::*;
212
use super::data::{Stat, StatVfs, TimeSpec};
313
use super::error::Result;
@@ -63,7 +73,8 @@ pub fn dup(fd: usize, buf: &[u8]) -> Result<usize> {
6373

6474
/// Replace the current process with a new executable
6575
pub fn execve(path: &str, args: &[[usize; 2]]) -> Result<usize> {
66-
unsafe { syscall4(SYS_EXECVE, path.as_ptr() as usize, path.len(), args.as_ptr() as usize, args.len()) }
76+
unsafe { syscall4(SYS_EXECVE, path.as_ptr() as usize, path.len(),
77+
args.as_ptr() as usize, args.len()) }
6778
}
6879

6980
/// Exit the current process
@@ -116,8 +127,9 @@ pub fn ftruncate(fd: usize, len: usize) -> Result<usize> {
116127
unsafe { syscall2(SYS_FTRUNCATE, fd, len) }
117128
}
118129

119-
/// Fast userspace mutex - TODO: Document
120-
pub unsafe fn futex(addr: *mut i32, op: usize, val: i32, val2: usize, addr2: *mut i32) -> Result<usize> {
130+
/// Fast userspace mutex
131+
pub unsafe fn futex(addr: *mut i32, op: usize, val: i32, val2: usize, addr2: *mut i32)
132+
-> Result<usize> {
121133
syscall5(SYS_FUTEX, addr as usize, op, (val as isize) as usize, val2, addr2 as usize)
122134
}
123135

@@ -188,7 +200,8 @@ pub fn mkns(schemes: &[[usize; 2]]) -> Result<usize> {
188200

189201
/// Sleep for the time specified in `req`
190202
pub fn nanosleep(req: &TimeSpec, rem: &mut TimeSpec) -> Result<usize> {
191-
unsafe { syscall2(SYS_NANOSLEEP, req as *const TimeSpec as usize, rem as *mut TimeSpec as usize) }
203+
unsafe { syscall2(SYS_NANOSLEEP, req as *const TimeSpec as usize,
204+
rem as *mut TimeSpec as usize) }
192205
}
193206

194207
/// Open a file

src/libstd/sys/redox/syscall/data.rs

Lines changed: 12 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,16 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
111
use core::ops::{Deref, DerefMut};
212
use core::{mem, slice};
313

4-
#[derive(Copy, Clone, Debug, Default)]
5-
pub struct Event {
6-
pub id: usize,
7-
pub flags: usize,
8-
pub data: usize
9-
}
10-
11-
impl Deref for Event {
12-
type Target = [u8];
13-
fn deref(&self) -> &[u8] {
14-
unsafe {
15-
slice::from_raw_parts(self as *const Event as *const u8, mem::size_of::<Event>()) as &[u8]
16-
}
17-
}
18-
}
19-
20-
impl DerefMut for Event {
21-
fn deref_mut(&mut self) -> &mut [u8] {
22-
unsafe {
23-
slice::from_raw_parts_mut(self as *mut Event as *mut u8, mem::size_of::<Event>()) as &mut [u8]
24-
}
25-
}
26-
}
27-
28-
#[derive(Copy, Clone, Debug, Default)]
29-
#[repr(packed)]
30-
pub struct Packet {
31-
pub id: u64,
32-
pub pid: usize,
33-
pub uid: u32,
34-
pub gid: u32,
35-
pub a: usize,
36-
pub b: usize,
37-
pub c: usize,
38-
pub d: usize
39-
}
40-
41-
impl Deref for Packet {
42-
type Target = [u8];
43-
fn deref(&self) -> &[u8] {
44-
unsafe {
45-
slice::from_raw_parts(self as *const Packet as *const u8, mem::size_of::<Packet>()) as &[u8]
46-
}
47-
}
48-
}
49-
50-
impl DerefMut for Packet {
51-
fn deref_mut(&mut self) -> &mut [u8] {
52-
unsafe {
53-
slice::from_raw_parts_mut(self as *mut Packet as *mut u8, mem::size_of::<Packet>()) as &mut [u8]
54-
}
55-
}
56-
}
57-
5814
#[derive(Copy, Clone, Debug, Default)]
5915
#[repr(packed)]
6016
pub struct Stat {
@@ -87,34 +43,8 @@ impl Deref for Stat {
8743
impl DerefMut for Stat {
8844
fn deref_mut(&mut self) -> &mut [u8] {
8945
unsafe {
90-
slice::from_raw_parts_mut(self as *mut Stat as *mut u8, mem::size_of::<Stat>()) as &mut [u8]
91-
}
92-
}
93-
}
94-
95-
#[derive(Copy, Clone, Debug, Default)]
96-
#[repr(packed)]
97-
pub struct StatVfs {
98-
pub f_bsize: u32,
99-
pub f_blocks: u64,
100-
pub f_bfree: u64,
101-
pub f_bavail: u64,
102-
//TODO: More fields https://linux.die.net/man/2/statvfs
103-
}
104-
105-
impl Deref for StatVfs {
106-
type Target = [u8];
107-
fn deref(&self) -> &[u8] {
108-
unsafe {
109-
slice::from_raw_parts(self as *const StatVfs as *const u8, mem::size_of::<StatVfs>()) as &[u8]
110-
}
111-
}
112-
}
113-
114-
impl DerefMut for StatVfs {
115-
fn deref_mut(&mut self) -> &mut [u8] {
116-
unsafe {
117-
slice::from_raw_parts_mut(self as *mut StatVfs as *mut u8, mem::size_of::<StatVfs>()) as &mut [u8]
46+
slice::from_raw_parts_mut(self as *mut Stat as *mut u8,
47+
mem::size_of::<Stat>()) as &mut [u8]
11848
}
11949
}
12050
}

src/libstd/sys/redox/syscall/error.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
111
use core::{fmt, result};
212

313
#[derive(Eq, PartialEq)]

src/libstd/sys/redox/syscall/flag.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
111
pub const CLONE_VM: usize = 0x100;
212
pub const CLONE_FS: usize = 0x200;
313
pub const CLONE_FILES: usize = 0x400;

0 commit comments

Comments
 (0)