diff --git a/Cargo.lock b/Cargo.lock index 46a3b52d71..3cda46101e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "autocfg" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "bitflags" @@ -30,7 +30,7 @@ dependencies = [ [[package]] name = "generic-rt" version = "0.1.0" -source = "git+https://gitlab.redox-os.org/redox-os/relibc#1e97bae11b1a51a1589bb6ea44cf8e507d2d1275" +source = "git+https://gitlab.redox-os.org/redox-os/relibc#0a29bfae68121b2639a75b50902d5dd7f0531848" [[package]] name = "goblin" @@ -51,9 +51,9 @@ checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" [[package]] name = "libc" -version = "0.2.155" +version = "0.2.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" [[package]] name = "libredox" @@ -99,18 +99,18 @@ checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" [[package]] name = "proc-macro2" -version = "1.0.86" +version = "1.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.36" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -132,7 +132,7 @@ checksum = "436d45c2b6a5b159d43da708e62b25be3a4a3d5550d654b72216ade4c4bfd717" [[package]] name = "redox-rt" version = "0.1.0" -source = "git+https://gitlab.redox-os.org/redox-os/relibc#1e97bae11b1a51a1589bb6ea44cf8e507d2d1275" +source = "git+https://gitlab.redox-os.org/redox-os/relibc#0a29bfae68121b2639a75b50902d5dd7f0531848" dependencies = [ "bitflags", "generic-rt", @@ -143,8 +143,8 @@ dependencies = [ [[package]] name = "redox-scheme" -version = "0.2.2" -source = "git+https://gitlab.redox-os.org/redox-os/redox-scheme.git#9a2e8a31894e397594ea4e3f033c4a91709bbbdc" +version = "0.2.3" +source = "git+https://gitlab.redox-os.org/redox-os/redox-scheme.git#dc6a047842353ed49c1788396d9135de2c3d7382" dependencies = [ "libredox", "redox_syscall", @@ -152,9 +152,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.4" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0884ad60e090bf1345b93da0a5de8923c93884cd03f40dfcfddd3b4bee661853" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" dependencies = [ "bitflags", ] @@ -196,9 +196,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.71" +version = "2.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b146dcf730474b4bcd16c311627b31ede9ab149045db4d6088b3becaea046462" +checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" dependencies = [ "proc-macro2", "quote", @@ -207,6 +207,6 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.12" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" diff --git a/src/aarch64.rs b/src/aarch64.rs index 0fef48b0c9..56aecc3ee5 100644 --- a/src/aarch64.rs +++ b/src/aarch64.rs @@ -5,7 +5,8 @@ use syscall::{ number::SYS_FMAP, }; -pub const STACK_START: usize = 0x0000_8000_0000_0000 - STACK_SIZE; +pub const USERMODE_END: usize = 0x0000_8000_0000_0000; +pub const STACK_START: usize = USERMODE_END - STACK_SIZE; const STACK_SIZE: usize = 64 * 1024; // 64 KiB static MAP: Map = Map { diff --git a/src/exec.rs b/src/exec.rs index ae03aa2269..0083c906b3 100644 --- a/src/exec.rs +++ b/src/exec.rs @@ -52,6 +52,7 @@ pub fn main() -> ! { default_scheme: Some(DEFAULT_SCHEME), sigprocmask: 0, sigignmask: 0, + umask: redox_rt::sys::get_umask(), }; let path = "/scheme/initfs/bin/init"; diff --git a/src/i686.rs b/src/i686.rs index f07beb4397..a3805d10e2 100644 --- a/src/i686.rs +++ b/src/i686.rs @@ -2,7 +2,8 @@ use core::mem; use syscall::{data::Map, flag::MapFlags, number::SYS_FMAP}; const STACK_SIZE: usize = 64 * 1024; // 64 KiB -pub const STACK_START: usize = 0x8000_0000 - STACK_SIZE; +pub const USERMODE_END: usize = 0x8000_0000; +pub const STACK_START: usize = USERMODE_END - STACK_SIZE; static MAP: Map = Map { offset: 0, diff --git a/src/initfs.rs b/src/initfs.rs index 6b96ea1f60..b1e97cdfbc 100644 --- a/src/initfs.rs +++ b/src/initfs.rs @@ -94,7 +94,7 @@ fn inode_len(inode: InodeStruct<'static>) -> Result { } impl SchemeMut for InitFsScheme { - fn xopen(&mut self, path: &str, flags: usize, ctx: &CallerCtx) -> Result { + fn xopen(&mut self, path: &str, flags: usize, _ctx: &CallerCtx) -> Result { let mut components = path // trim leading and trailing slash .trim_matches('/') @@ -122,7 +122,7 @@ impl SchemeMut for InitFsScheme { InodeKind::Dir(dir) => dir, // TODO: Support symlinks in other position than xopen target - InodeKind::Link(link) => { + InodeKind::Link(_) => { return Err(Error::new(EOPNOTSUPP)); } diff --git a/src/lib.rs b/src/lib.rs index 66d3c7d8f3..7fc400fe98 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,6 +14,10 @@ pub mod arch; #[path = "x86_64.rs"] pub mod arch; +#[cfg(target_arch = "riscv64")] +#[path = "riscv64.rs"] +pub mod arch; + pub mod exec; pub mod initfs; pub mod start; @@ -41,11 +45,7 @@ fn panic_handler(info: &core::panic::PanicInfo) -> ! { core::intrinsics::abort(); } -#[cfg(target_pointer_width = "32")] -const HEAP_OFF: usize = 0x4000_0000; - -#[cfg(target_pointer_width = "64")] -const HEAP_OFF: usize = 0x4000_0000_0000; +const HEAP_OFF: usize = arch::USERMODE_END / 2; struct Allocator; #[global_allocator] diff --git a/src/riscv64.ld b/src/riscv64.ld new file mode 100644 index 0000000000..98b5239bbd --- /dev/null +++ b/src/riscv64.ld @@ -0,0 +1,44 @@ +ENTRY(_start) +OUTPUT_FORMAT(elf64-littleriscv) + +SECTIONS { + . = 4096 + 4096; /* Reserved for the null page and the initfs header prepended by redox-initfs-ar */ + __initfs_header = . - 4096; + . += SIZEOF_HEADERS; + . = ALIGN(4096); + + .text : { + __text_start = .; + *(.text*) + . = ALIGN(4096); + __text_end = .; + } + .rodata : { + __rodata_start = .; + *(.rodata*) + . = ALIGN(4096); + __rodata_end = .; + } + .data : { + __data_start = .; + *(.data*) + *(.sdata*) + *(.got*) + . = ALIGN(4096); + __data_end = .; + + __bss_start = .; + *(.bss*) + *(.sbss*) + . = ALIGN(4096); + __bss_end = .; + } + + /DISCARD/ : { + *(.comment*) + *(.eh_frame*) + *(.gcc_except_table*) + *(.note*) + *(.rel.eh_frame*) + } +} diff --git a/src/riscv64.rs b/src/riscv64.rs new file mode 100644 index 0000000000..6a36039a4f --- /dev/null +++ b/src/riscv64.rs @@ -0,0 +1,47 @@ +use core::mem; +use syscall::{data::Map, flag::MapFlags, number::SYS_FMAP}; + +const STACK_SIZE: usize = 64 * 1024; // 64 KiB +pub const USERMODE_END: usize = 1 << 47; // Assuming Sv48; it should work with Sv57 also +pub const STACK_START: usize = USERMODE_END - STACK_SIZE; + +static MAP: Map = Map { + offset: 0, + size: STACK_SIZE, + flags: MapFlags::PROT_READ + .union(MapFlags::PROT_WRITE) + .union(MapFlags::MAP_PRIVATE) + .union(MapFlags::MAP_FIXED_NOREPLACE), + address: STACK_START, // highest possible user address +}; + +core::arch::global_asm!( + " + .globl _start +_start: + # Setup a stack. + li a7, {number} + li a0, {fd} + la a1, {map} # pointer to Map struct + li a2, {map_size} # size of Map struct + ecall + + # Test for success (nonzero value). + bne a0, x0, 2f + # (failure) + unimp +2: + li sp, {stack_size} + add sp, sp, a0 + mv fp, x0 + + jal start + # `start` must never return. + unimp + ", + fd = const usize::MAX, // dummy fd indicates anonymous map + map = sym MAP, + map_size = const mem::size_of::(), + number = const SYS_FMAP, + stack_size = const STACK_SIZE, +); diff --git a/src/x86_64.rs b/src/x86_64.rs index c4c051ca0a..f7110a64e9 100644 --- a/src/x86_64.rs +++ b/src/x86_64.rs @@ -2,8 +2,8 @@ use core::mem; use syscall::{data::Map, flag::MapFlags, number::SYS_FMAP}; const STACK_SIZE: usize = 64 * 1024; // 64 KiB - -pub const STACK_START: usize = 0x0000_8000_0000_0000 - STACK_SIZE; +pub const USERMODE_END: usize = 0x0000_8000_0000_0000; +pub const STACK_START: usize = USERMODE_END - STACK_SIZE; static MAP: Map = Map { offset: 0,