-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Redox Cross Compilation #38401
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
Redox Cross Compilation #38401
Changes from 1 commit
341d2d1
c7aa284
a621d12
d2707aa
ece703a
f86e014
3e7543a
773a0a2
07e313d
6d7c2ec
57bc1a9
86f85c1
01157e6
e55596f
65eecf8
fd4bc88
7697c72
2ca1f0b
bf50acb
e909e43
92c8e0f
7d3ae87
e7b006d
1eb6c44
2ddd117
474eb62
c59bb49
4dcb867
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
issue = "27783")] | ||
#![feature(allocator)] | ||
#![feature(staged_api)] | ||
#![cfg_attr(target_os = "redox", feature(libc))] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that |
||
#![cfg_attr(unix, feature(libc))] | ||
|
||
// The minimum alignment guaranteed by the architecture. This value is used to | ||
|
@@ -71,7 +72,49 @@ pub extern "C" fn __rust_usable_size(size: usize, align: usize) -> usize { | |
imp::usable_size(size, align) | ||
} | ||
|
||
#[cfg(unix)] | ||
#[cfg(target_os = "redox")] | ||
mod imp { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just so we have a stub for potentially using a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're the one defining the abi of the system allocator, so this is largely up to you. If you follow unix's malloc/free conventions then I'd recommend unifying with the above block for Unix. That handles bits and pieces such as alignment for more-aligned types (e.g. simd types). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will probably change this to be different from Unix so that it defines externs that ralloc will fulfill. |
||
extern crate libc; | ||
|
||
use core::cmp; | ||
use core::ptr; | ||
use MIN_ALIGN; | ||
|
||
pub unsafe fn allocate(size: usize, _align: usize) -> *mut u8 { | ||
libc::malloc(size as libc::size_t) as *mut u8 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. memalign is not used like in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes I this is one case where I think you'll want to align with the implementation above. This really ends up just needing an allocator interface which supports alignment as an argument, and that's what There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Understood, thanks |
||
} | ||
|
||
pub unsafe fn reallocate(ptr: *mut u8, old_size: usize, size: usize, align: usize) -> *mut u8 { | ||
if align <= MIN_ALIGN { | ||
libc::realloc(ptr as *mut libc::c_void, size as libc::size_t) as *mut u8 | ||
} else { | ||
let new_ptr = allocate(size, align); | ||
if !new_ptr.is_null() { | ||
ptr::copy(ptr, new_ptr, cmp::min(size, old_size)); | ||
deallocate(ptr, old_size, align); | ||
} | ||
new_ptr | ||
} | ||
} | ||
|
||
pub unsafe fn reallocate_inplace(_ptr: *mut u8, | ||
old_size: usize, | ||
_size: usize, | ||
_align: usize) | ||
-> usize { | ||
old_size | ||
} | ||
|
||
pub unsafe fn deallocate(ptr: *mut u8, _old_size: usize, _align: usize) { | ||
libc::free(ptr as *mut libc::c_void) | ||
} | ||
|
||
pub fn usable_size(size: usize, _align: usize) -> usize { | ||
size | ||
} | ||
} | ||
|
||
#[cfg(any(unix))] | ||
mod imp { | ||
extern crate libc; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ fn main() { | |
let target = env::var("TARGET").expect("TARGET was not set"); | ||
let host = env::var("HOST").expect("HOST was not set"); | ||
if cfg!(feature = "backtrace") && !target.contains("apple") && !target.contains("msvc") && | ||
!target.contains("emscripten") && !target.contains("fuchsia") { | ||
!target.contains("emscripten") && !target.contains("fuchsia") && !target.contains("redox") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We disable the build of |
||
build_libbacktrace(&host, &target); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -299,6 +299,7 @@ | |
#![feature(unwind_attributes)] | ||
#![feature(vec_push_all)] | ||
#![feature(zero_one)] | ||
#![cfg_attr(target_os = "redox", feature(naked_functions))] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hygiene error! In order to generate executables, we have to have a naked
|
||
#![cfg_attr(test, feature(update_panic_count))] | ||
|
||
// Explicitly import the prelude. The compiler uses this same unstable attribute | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,6 @@ | |
|
||
#![allow(dead_code, missing_docs, bad_style)] | ||
|
||
pub extern crate syscall; | ||
|
||
use io::{self, ErrorKind}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have moved the |
||
|
||
pub mod args; | ||
|
@@ -33,7 +31,9 @@ pub mod process; | |
pub mod rand; | ||
pub mod rwlock; | ||
pub mod stack_overflow; | ||
pub mod start; | ||
pub mod stdio; | ||
pub mod syscall; | ||
pub mod thread; | ||
pub mod thread_local; | ||
pub mod time; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,10 +20,11 @@ use vec::{IntoIter, Vec}; | |
|
||
use self::dns::{Dns, DnsQuery}; | ||
|
||
pub extern crate libc as netc; | ||
pub use self::tcp::{TcpStream, TcpListener}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We no longer use the |
||
pub use self::udp::UdpSocket; | ||
|
||
pub mod netc; | ||
|
||
mod dns; | ||
mod tcp; | ||
mod udp; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
pub type in_addr_t = u32; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are the definitions from |
||
pub type in_port_t = u16; | ||
|
||
pub type socklen_t = u32; | ||
pub type sa_family_t = u16; | ||
|
||
pub const AF_INET: sa_family_t = 1; | ||
pub const AF_INET6: sa_family_t = 2; | ||
|
||
#[derive(Copy, Clone)] | ||
#[repr(C)] | ||
pub struct in_addr { | ||
pub s_addr: in_addr_t, | ||
} | ||
|
||
#[derive(Copy, Clone)] | ||
#[repr(C)] | ||
pub struct in6_addr { | ||
pub s6_addr: [u8; 16], | ||
__align: [u32; 0], | ||
} | ||
|
||
#[derive(Copy, Clone)] | ||
#[repr(C)] | ||
pub struct sockaddr { | ||
pub sa_family: sa_family_t, | ||
pub sa_data: [u8; 14], | ||
} | ||
|
||
#[derive(Copy, Clone)] | ||
#[repr(C)] | ||
pub struct sockaddr_in { | ||
pub sin_family: sa_family_t, | ||
pub sin_port: in_port_t, | ||
pub sin_addr: in_addr, | ||
pub sin_zero: [u8; 8], | ||
} | ||
|
||
#[derive(Copy, Clone)] | ||
#[repr(C)] | ||
pub struct sockaddr_in6 { | ||
pub sin6_family: sa_family_t, | ||
pub sin6_port: in_port_t, | ||
pub sin6_flowinfo: u32, | ||
pub sin6_addr: in6_addr, | ||
pub sin6_scope_id: u32, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,15 +9,19 @@ | |
// except according to those terms. | ||
|
||
use io; | ||
use libc; | ||
use rand::Rng; | ||
|
||
pub struct OsRng; | ||
// FIXME: Use rand: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have to specify a simple |
||
pub struct OsRng { | ||
state: [u64; 2] | ||
} | ||
|
||
impl OsRng { | ||
/// Create a new `OsRng`. | ||
pub fn new() -> io::Result<OsRng> { | ||
Ok(OsRng) | ||
Ok(OsRng { | ||
state: [0xBADF00D1, 0xDEADBEEF] | ||
}) | ||
} | ||
} | ||
|
||
|
@@ -26,7 +30,20 @@ impl Rng for OsRng { | |
self.next_u64() as u32 | ||
} | ||
fn next_u64(&mut self) -> u64 { | ||
unsafe { libc::random() } | ||
// Store the first and second part. | ||
let mut x = self.state[0]; | ||
let y = self.state[1]; | ||
|
||
// Put the second part into the first slot. | ||
self.state[0] = y; | ||
// Twist the first slot. | ||
x ^= x << 23; | ||
// Update the second slot. | ||
self.state[1] = x ^ y ^ (x >> 17) ^ (y >> 26); | ||
|
||
// Generate the final integer. | ||
self.state[1].wrapping_add(y) | ||
|
||
} | ||
fn fill_bytes(&mut self, buf: &mut [u8]) { | ||
for chunk in buf.chunks_mut(8) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use sys::syscall::exit; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hygiene error! In order to generate executables, we have to have a naked
|
||
|
||
#[allow(private_no_mangle_fns)] | ||
#[no_mangle] | ||
#[naked] | ||
#[cfg(target_arch = "x86")] | ||
pub unsafe fn _start() { | ||
asm!("push esp | ||
call _start_stack | ||
pop esp" | ||
: | ||
: | ||
: "memory" | ||
: "intel", "volatile"); | ||
let _ = exit(0); | ||
} | ||
|
||
#[allow(private_no_mangle_fns)] | ||
#[no_mangle] | ||
#[naked] | ||
#[cfg(target_arch = "x86_64")] | ||
pub unsafe fn _start() { | ||
asm!("mov rdi, rsp | ||
and rsp, 0xFFFFFFFFFFFFFFF0 | ||
call _start_stack" | ||
: | ||
: | ||
: "memory" | ||
: "intel", "volatile"); | ||
let _ = exit(0); | ||
} | ||
|
||
#[allow(private_no_mangle_fns)] | ||
#[no_mangle] | ||
pub unsafe extern "C" fn _start_stack(stack: *const usize){ | ||
extern "C" { | ||
fn main(argc: usize, argv: *const *const u8) -> usize; | ||
} | ||
|
||
let argc = *stack as usize; | ||
let argv = stack.offset(1) as *const *const u8; | ||
let _ = exit(main(argc, argv)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not support jemalloc, so we will build with the dummy.