Skip to content
Snippets Groups Projects
Verified Commit 42f212e6 authored by Jeremy Soller's avatar Jeremy Soller
Browse files

Verify current system before continuing.

parent 47235d44
No related branches found
No related tags found
No related merge requests found
...@@ -435,4 +435,9 @@ impl Pal for Sys { ...@@ -435,4 +435,9 @@ impl Pal for Sys {
fn write(fildes: c_int, buf: &[u8]) -> ssize_t { fn write(fildes: c_int, buf: &[u8]) -> ssize_t {
e(unsafe { syscall!(WRITE, fildes, buf.as_ptr(), buf.len()) }) as ssize_t e(unsafe { syscall!(WRITE, fildes, buf.as_ptr(), buf.len()) }) as ssize_t
} }
fn verify() -> bool {
// GETPID on Linux is 39, which does not exist on Redox
e(unsafe { sc::syscall5(sc::nr::GETPID, !0, !0, !0, !0, !0) }) != !0
}
} }
...@@ -155,4 +155,6 @@ pub trait Pal { ...@@ -155,4 +155,6 @@ pub trait Pal {
fn waitpid(pid: pid_t, stat_loc: *mut c_int, options: c_int) -> pid_t; fn waitpid(pid: pid_t, stat_loc: *mut c_int, options: c_int) -> pid_t;
fn write(fildes: c_int, buf: &[u8]) -> ssize_t; fn write(fildes: c_int, buf: &[u8]) -> ssize_t;
fn verify() -> bool;
} }
...@@ -1164,4 +1164,9 @@ impl Pal for Sys { ...@@ -1164,4 +1164,9 @@ impl Pal for Sys {
fn write(fd: c_int, buf: &[u8]) -> ssize_t { fn write(fd: c_int, buf: &[u8]) -> ssize_t {
e(syscall::write(fd as usize, buf)) as ssize_t e(syscall::write(fd as usize, buf)) as ssize_t
} }
fn verify() -> bool {
// GETPID on Redox is 20, which is WRITEV on Linux
e(unsafe { syscall::syscall5(syscall::number::SYS_GETPID, !0, !0, !0, !0, !0) }) != !0
}
} }
use alloc::vec::Vec; use alloc::vec::Vec;
use core::ptr; use core::{intrinsics, ptr};
use header::{stdio, stdlib}; use header::{stdio, stdlib};
use platform; use platform;
use platform::{Pal, Sys};
use platform::types::*; use platform::types::*;
#[repr(C)] #[repr(C)]
...@@ -44,6 +45,15 @@ unsafe fn copy_string_array(array: *const *const c_char, len: usize) -> Vec<*mut ...@@ -44,6 +45,15 @@ unsafe fn copy_string_array(array: *const *const c_char, len: usize) -> Vec<*mut
vec vec
} }
// Since Redox and Linux are so similar, it is easy to accidentally run a binary from one on the
// other. This will test that the current system is compatible with the current binary
#[no_mangle]
pub unsafe fn relibc_verify_host() {
if ! Sys::verify() {
intrinsics::abort();
}
}
#[inline(never)] #[inline(never)]
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn relibc_start(sp: &'static Stack) -> ! { pub unsafe extern "C" fn relibc_start(sp: &'static Stack) -> ! {
...@@ -58,6 +68,9 @@ pub unsafe extern "C" fn relibc_start(sp: &'static Stack) -> ! { ...@@ -58,6 +68,9 @@ pub unsafe extern "C" fn relibc_start(sp: &'static Stack) -> ! {
fn main(argc: isize, argv: *mut *mut c_char, envp: *mut *mut c_char) -> c_int; fn main(argc: isize, argv: *mut *mut c_char, envp: *mut *mut c_char) -> c_int;
} }
// Ensure correct host system before executing more system calls
relibc_verify_host();
// Set up argc and argv // Set up argc and argv
let argc = sp.argc(); let argc = sp.argc();
let argv = sp.argv(); let argv = sp.argv();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment