Skip to content

Commit

Permalink
Auto merge of #1292 - hermitcore:master, r=gnzlbg
Browse files Browse the repository at this point in the history
add HermitCore support even if it doesn't have a UNIX interface

Currently, we redefine the interface between the HermitCore kernel (https://hermitcore.org) and Rust’s standard library. In the future, it will not depend on a POSIX-compatible C library. Consequently, we add the support of HermitCore if the "unix" environment isn’t set. It will be great to integrate this patch because it would simplify our development. The classical interface is still supported and part of the subdirectory "unix".
  • Loading branch information
bors committed Mar 3, 2019
2 parents 234f9a6 + 14353e8 commit 8d94e00
Show file tree
Hide file tree
Showing 6 changed files with 412 additions and 61 deletions.
2 changes: 2 additions & 0 deletions ci/build.sh
Expand Up @@ -167,7 +167,9 @@ done
# FIXME: https://github.com/rust-lang/rust/issues/58564
# sparc-unknown-linux-gnu
RUST_LINUX_NO_CORE_TARGETS="\
x86_64-unknown-hermit \
x86_64-unknown-dragonfly \
aarch64-unknown-hermit \
aarch64-pc-windows-msvc \
aarch64-unknown-cloudabi \
armebv7r-none-eabi \
Expand Down
2 changes: 2 additions & 0 deletions src/hermit/aarch64.rs
@@ -0,0 +1,2 @@
pub type c_char = u8;
pub type wchar_t = u32;
83 changes: 83 additions & 0 deletions src/hermit/mod.rs
@@ -0,0 +1,83 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// libc port for HermitCore (https://hermitcore.org)
//
// Ported by Colin Fink <colin.finck@rwth-aachen.de>
// and Stefan Lankes <slankes@eonerc.rwth-aachen.de>

pub type int8_t = i8;
pub type int16_t = i16;
pub type int32_t = i32;
pub type int64_t = i64;
pub type uint8_t = u8;
pub type uint16_t = u16;
pub type uint32_t = u32;
pub type uint64_t = u64;

pub type c_schar = i8;
pub type c_uchar = u8;
pub type c_short = i16;
pub type c_ushort = u16;
pub type c_int = i32;
pub type c_uint = u32;
pub type c_float = f32;
pub type c_double = f64;
pub type c_longlong = i64;
pub type c_ulonglong = u64;
pub type intmax_t = i64;
pub type uintmax_t = u64;

pub type size_t = usize;
pub type ptrdiff_t = isize;
pub type intptr_t = isize;
pub type uintptr_t = usize;
pub type ssize_t = isize;

pub type c_long = i64;
pub type c_ulong = u64;

pub type wint_t = u32;
pub type wctype_t = i64;

pub type regoff_t = size_t;
pub type off_t = c_long;

cfg_if! {
if #[cfg(target_arch = "aarch64")] {
mod aarch64;
pub use self::aarch64::*;
} else if #[cfg(target_arch = "x86_64")] {
mod x86_64;
pub use self::x86_64::*;
} else {
// Unknown target_arch
}
}

cfg_if! {
if #[cfg(libc_core_cvoid)] {
pub use ::ffi::c_void;
} else {
// Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help
// enable more optimization opportunities around it recognizing things
// like malloc/free.
#[repr(u8)]
#[allow(missing_copy_implementations)]
#[allow(missing_debug_implementations)]
pub enum c_void {
// Two dummy variants so the #[repr] attribute can be used.
#[doc(hidden)]
__variant1,
#[doc(hidden)]
__variant2,
}
}
}
2 changes: 2 additions & 0 deletions src/hermit/x86_64.rs
@@ -0,0 +1,2 @@
pub type c_char = i8;
pub type wchar_t = i32;
3 changes: 3 additions & 0 deletions src/lib.rs
Expand Up @@ -106,6 +106,9 @@ cfg_if! {
} else if #[cfg(unix)] {
mod unix;
pub use unix::*;
} else if #[cfg(target_os = "hermit")] {
mod hermit;
pub use hermit::*;
} else if #[cfg(target_env = "sgx")] {
mod sgx;
pub use sgx::*;
Expand Down

0 comments on commit 8d94e00

Please sign in to comment.