Skip to content

Commit 92b24f5

Browse files
committed
add HermitCore support even if it doesn't have a UNIX interface
1 parent 810b8c6 commit 92b24f5

File tree

4 files changed

+92
-0
lines changed

4 files changed

+92
-0
lines changed

src/hermit/aarch64.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub type c_char = u8;
2+
pub type wchar_t = u32;

src/hermit/mod.rs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Copyright 2018 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+
// libc port for HermitCore (https://hermitcore.org)
12+
//
13+
// Ported by Colin Fink <colin.finck@rwth-aachen.de>
14+
// and Stefan Lankes <slankes@eonerc.rwth-aachen.de>
15+
16+
pub type int8_t = i8;
17+
pub type int16_t = i16;
18+
pub type int32_t = i32;
19+
pub type int64_t = i64;
20+
pub type uint8_t = u8;
21+
pub type uint16_t = u16;
22+
pub type uint32_t = u32;
23+
pub type uint64_t = u64;
24+
25+
pub type c_schar = i8;
26+
pub type c_uchar = u8;
27+
pub type c_short = i16;
28+
pub type c_ushort = u16;
29+
pub type c_int = i32;
30+
pub type c_uint = u32;
31+
pub type c_float = f32;
32+
pub type c_double = f64;
33+
pub type c_longlong = i64;
34+
pub type c_ulonglong = u64;
35+
pub type intmax_t = i64;
36+
pub type uintmax_t = u64;
37+
38+
pub type size_t = usize;
39+
pub type ptrdiff_t = isize;
40+
pub type intptr_t = isize;
41+
pub type uintptr_t = usize;
42+
pub type ssize_t = isize;
43+
44+
pub type c_char = i8;
45+
pub type c_long = i64;
46+
pub type c_ulong = u64;
47+
48+
pub type wchar_t = i32;
49+
pub type wint_t = u32;
50+
pub type wctype_t = i64;
51+
52+
pub type regoff_t = size_t;
53+
pub type off_t = c_long;
54+
55+
cfg_if! {
56+
if #[cfg(target_arch = "aarch64")] {
57+
mod aarch64;
58+
pub use self::aarch64::*;
59+
} else if #[cfg(target_arch = "x86_64")] {
60+
mod x86_64;
61+
pub use self::x86_64::*;
62+
} else {
63+
// Unknown target_arch
64+
}
65+
}
66+
67+
cfg_if! {
68+
if #[cfg(libc_core_cvoid)] {
69+
pub use ::ffi::c_void;
70+
} else {
71+
// Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help
72+
// enable more optimization opportunities around it recognizing things
73+
// like malloc/free.
74+
#[repr(u8)]
75+
#[allow(missing_copy_implementations)]
76+
#[allow(missing_debug_implementations)]
77+
pub enum c_void {
78+
// Two dummy variants so the #[repr] attribute can be used.
79+
#[doc(hidden)]
80+
__variant1,
81+
#[doc(hidden)]
82+
__variant2,
83+
}
84+
}
85+
}

src/hermit/x86_64.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub type c_char = i8;
2+
pub type wchar_t = i32;

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ cfg_if! {
232232
} else if #[cfg(unix)] {
233233
mod unix;
234234
pub use unix::*;
235+
} else if #[cfg(target_os = "hermit")] {
236+
mod redox;
237+
pub use hermit::*;
235238
} else if #[cfg(target_env = "sgx")] {
236239
mod sgx;
237240
pub use sgx::*;

0 commit comments

Comments
 (0)