Skip to content

Add SGX C types #1129

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

Merged
merged 2 commits into from
Nov 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ci/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ fn walk(path: &Path, err: &mut Errors) {

"dox.rs" |
"lib.rs" |
"ctypes.rs" |
"libc.rs" |
"macros.rs" => continue,

_ => {}
Expand Down
69 changes: 51 additions & 18 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,10 @@ fn main() {
cfg.type_name(move |ty, is_struct, is_union| {
match ty {
// Just pass all these through, no need for a "struct" prefix
"FILE" | "fd_set" | "Dl_info" | "DIR" | "Elf32_Phdr" | "Elf64_Phdr" | "Elf32_Shdr"
| "Elf64_Shdr" | "Elf32_Sym" | "Elf64_Sym" | "Elf32_Ehdr" | "Elf64_Ehdr"
| "Elf32_Chdr" | "Elf64_Chdr" => ty.to_string(),
"FILE" | "fd_set" | "Dl_info" | "DIR" | "Elf32_Phdr"
| "Elf64_Phdr" | "Elf32_Shdr" | "Elf64_Shdr" | "Elf32_Sym"
| "Elf64_Sym" | "Elf32_Ehdr" | "Elf64_Ehdr" | "Elf32_Chdr"
| "Elf64_Chdr" => ty.to_string(),

// Fixup a few types on windows that don't actually exist.
"time64_t" if windows => "__time64_t".to_string(),
Expand Down Expand Up @@ -391,8 +392,12 @@ fn main() {
let target2 = target.clone();
cfg.field_name(move |struct_, field| {
match field {
"st_birthtime" if openbsd && struct_ == "stat" => "__st_birthtime".to_string(),
"st_birthtime_nsec" if openbsd && struct_ == "stat" => "__st_birthtimensec".to_string(),
"st_birthtime" if openbsd && struct_ == "stat" => {
"__st_birthtime".to_string()
}
"st_birthtime_nsec" if openbsd && struct_ == "stat" => {
"__st_birthtimensec".to_string()
}
// Our stat *_nsec fields normally don't actually exist but are part
// of a timeval struct
s if s.ends_with("_nsec") && struct_.starts_with("stat") => {
Expand Down Expand Up @@ -459,8 +464,9 @@ fn main() {

// Present on historical versions of iOS but missing in more recent
// SDKs
"bpf_hdr" | "proc_taskinfo" | "proc_taskallinfo" | "proc_bsdinfo"
| "proc_threadinfo" | "sockaddr_inarp" | "sockaddr_ctl" | "arphdr"
"bpf_hdr" | "proc_taskinfo" | "proc_taskallinfo"
| "proc_bsdinfo" | "proc_threadinfo" | "sockaddr_inarp"
| "sockaddr_ctl" | "arphdr"
if ios =>
{
true
Expand All @@ -472,7 +478,10 @@ fn main() {

cfg.skip_signededness(move |c| {
match c {
"LARGE_INTEGER" | "mach_timebase_info_data_t" | "float" | "double" => true,
"LARGE_INTEGER"
| "mach_timebase_info_data_t"
| "float"
| "double" => true,
// uuid_t is a struct, not an integer.
"uuid_t" if dragonfly => true,
n if n.starts_with("pthread") => true,
Expand Down Expand Up @@ -512,7 +521,12 @@ fn main() {

// Skip constants not defined in MUSL but just passed down to the
// kernel regardless
"RLIMIT_NLIMITS" | "TCP_COOKIE_TRANSACTIONS" | "RLIMIT_RTTIME" | "MSG_COPY" if musl => {
"RLIMIT_NLIMITS"
| "TCP_COOKIE_TRANSACTIONS"
| "RLIMIT_RTTIME"
| "MSG_COPY"
if musl =>
{
true
}
// work around super old mips toolchain
Expand All @@ -532,11 +546,16 @@ fn main() {
// These constants were removed in FreeBSD 11 (svn r262489),
// and they've never had any legitimate use outside of the
// base system anyway.
"CTL_MAXID" | "KERN_MAXID" | "HW_MAXID" | "NET_MAXID" | "USER_MAXID" if freebsd => true,
"CTL_MAXID" | "KERN_MAXID" | "HW_MAXID" | "NET_MAXID"
| "USER_MAXID"
if freebsd =>
{
true
}

// These constants were added in FreeBSD 11
"EVFILT_PROCDESC" | "EVFILT_SENDFILE" | "EVFILT_EMPTY" | "PD_CLOEXEC"
| "PD_ALLOWED_AT_FORK"
"EVFILT_PROCDESC" | "EVFILT_SENDFILE" | "EVFILT_EMPTY"
| "PD_CLOEXEC" | "PD_ALLOWED_AT_FORK"
if freebsd =>
{
true
Expand Down Expand Up @@ -613,13 +632,19 @@ fn main() {
// These constants are tested in a separate test program generated below because there
// are header conflicts if we try to include the headers that define them here.
"F_CANCELLK" | "F_ADD_SEALS" | "F_GET_SEALS" => true,
"F_SEAL_SEAL" | "F_SEAL_SHRINK" | "F_SEAL_GROW" | "F_SEAL_WRITE" => true,
"QFMT_VFS_OLD" | "QFMT_VFS_V0" | "QFMT_VFS_V1" if mips && linux => true, // Only on MIPS
"F_SEAL_SEAL" | "F_SEAL_SHRINK" | "F_SEAL_GROW"
| "F_SEAL_WRITE" => true,
"QFMT_VFS_OLD" | "QFMT_VFS_V0" | "QFMT_VFS_V1"
if mips && linux =>
{
true
} // Only on MIPS
"BOTHER" => true,

"MFD_CLOEXEC" | "MFD_ALLOW_SEALING" if !mips && musl => true,

"DT_FIFO" | "DT_CHR" | "DT_DIR" | "DT_BLK" | "DT_REG" | "DT_LNK" | "DT_SOCK"
"DT_FIFO" | "DT_CHR" | "DT_DIR" | "DT_BLK" | "DT_REG"
| "DT_LNK" | "DT_SOCK"
if solaris =>
{
true
Expand All @@ -628,7 +653,10 @@ fn main() {
"PRIO_MIN" | "PRIO_MAX" if solaris => true,

// These are defined for Solaris 11, but the crate is tested on illumos, where they are currently not defined
"EADI" | "PORT_SOURCE_POSTWAIT" | "PORT_SOURCE_SIGNAL" | "PTHREAD_STACK_MIN" => true,
"EADI"
| "PORT_SOURCE_POSTWAIT"
| "PORT_SOURCE_SIGNAL"
| "PTHREAD_STACK_MIN" => true,

// These change all the time from release to release of linux
// distros, let's just not bother trying to verify them. They
Expand Down Expand Up @@ -899,8 +927,13 @@ fn main() {
cfg.header("asm/termbits.h");
cfg.skip_const(move |name| match name {
"F_CANCELLK" | "F_ADD_SEALS" | "F_GET_SEALS" => false,
"F_SEAL_SEAL" | "F_SEAL_SHRINK" | "F_SEAL_GROW" | "F_SEAL_WRITE" => false,
"QFMT_VFS_OLD" | "QFMT_VFS_V0" | "QFMT_VFS_V1" if mips && linux => false,
"F_SEAL_SEAL" | "F_SEAL_SHRINK" | "F_SEAL_GROW"
| "F_SEAL_WRITE" => false,
"QFMT_VFS_OLD" | "QFMT_VFS_V0" | "QFMT_VFS_V1"
if mips && linux =>
{
false
}
"BOTHER" => false,
_ => true,
});
Expand Down
152 changes: 152 additions & 0 deletions src/cloudabi/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@

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 in_addr_t = u32;
pub type in_port_t = u16;
pub type pthread_key_t = usize;
Expand Down Expand Up @@ -56,6 +85,9 @@ s! {
}
}

pub const INT_MIN: c_int = -2147483648;
pub const INT_MAX: c_int = 2147483647;

pub const _SC_NPROCESSORS_ONLN: ::c_int = 52;
pub const _SC_PAGESIZE: ::c_int = 54;

Expand Down Expand Up @@ -89,7 +121,109 @@ pub const PTHREAD_STACK_MIN: ::size_t = 1024;
pub const SOCK_DGRAM: ::c_int = 128;
pub const SOCK_STREAM: ::c_int = 130;

pub enum FILE {}
pub enum fpos_t {} // TODO: fill this out with a struct

extern {
pub fn isalnum(c: c_int) -> c_int;
pub fn isalpha(c: c_int) -> c_int;
pub fn iscntrl(c: c_int) -> c_int;
pub fn isdigit(c: c_int) -> c_int;
pub fn isgraph(c: c_int) -> c_int;
pub fn islower(c: c_int) -> c_int;
pub fn isprint(c: c_int) -> c_int;
pub fn ispunct(c: c_int) -> c_int;
pub fn isspace(c: c_int) -> c_int;
pub fn isupper(c: c_int) -> c_int;
pub fn isxdigit(c: c_int) -> c_int;
pub fn tolower(c: c_int) -> c_int;
pub fn toupper(c: c_int) -> c_int;
pub fn fopen(filename: *const c_char, mode: *const c_char) -> *mut FILE;
pub fn freopen(filename: *const c_char, mode: *const c_char,
file: *mut FILE) -> *mut FILE;
pub fn fflush(file: *mut FILE) -> c_int;
pub fn fclose(file: *mut FILE) -> c_int;
pub fn remove(filename: *const c_char) -> c_int;
pub fn rename(oldname: *const c_char, newname: *const c_char) -> c_int;
pub fn tmpfile() -> *mut FILE;
pub fn setvbuf(stream: *mut FILE, buffer: *mut c_char, mode: c_int,
size: size_t) -> c_int;
pub fn setbuf(stream: *mut FILE, buf: *mut c_char);
pub fn getchar() -> c_int;
pub fn putchar(c: c_int) -> c_int;
pub fn fgetc(stream: *mut FILE) -> c_int;
pub fn fgets(buf: *mut c_char, n: c_int, stream: *mut FILE) -> *mut c_char;
pub fn fputc(c: c_int, stream: *mut FILE) -> c_int;
pub fn fputs(s: *const c_char, stream: *mut FILE) -> c_int;
pub fn puts(s: *const c_char) -> c_int;
pub fn ungetc(c: c_int, stream: *mut FILE) -> c_int;
pub fn fread(ptr: *mut c_void, size: size_t, nobj: size_t,
stream: *mut FILE) -> size_t;
pub fn fwrite(ptr: *const c_void, size: size_t, nobj: size_t,
stream: *mut FILE) -> size_t;
pub fn fseek(stream: *mut FILE, offset: c_long, whence: c_int) -> c_int;
pub fn ftell(stream: *mut FILE) -> c_long;
pub fn rewind(stream: *mut FILE);
pub fn fgetpos(stream: *mut FILE, ptr: *mut fpos_t) -> c_int;
pub fn fsetpos(stream: *mut FILE, ptr: *const fpos_t) -> c_int;
pub fn feof(stream: *mut FILE) -> c_int;
pub fn ferror(stream: *mut FILE) -> c_int;
pub fn perror(s: *const c_char);
pub fn atoi(s: *const c_char) -> c_int;
pub fn strtod(s: *const c_char, endp: *mut *mut c_char) -> c_double;
pub fn strtol(s: *const c_char, endp: *mut *mut c_char,
base: c_int) -> c_long;
pub fn strtoul(s: *const c_char, endp: *mut *mut c_char,
base: c_int) -> c_ulong;
pub fn calloc(nobj: size_t, size: size_t) -> *mut c_void;
pub fn malloc(size: size_t) -> *mut c_void;
pub fn realloc(p: *mut c_void, size: size_t) -> *mut c_void;
pub fn free(p: *mut c_void);
pub fn abort() -> !;
pub fn exit(status: c_int) -> !;
pub fn _exit(status: c_int) -> !;
pub fn atexit(cb: extern fn()) -> c_int;
pub fn system(s: *const c_char) -> c_int;
pub fn getenv(s: *const c_char) -> *mut c_char;

pub fn strcpy(dst: *mut c_char, src: *const c_char) -> *mut c_char;
pub fn strncpy(dst: *mut c_char, src: *const c_char,
n: size_t) -> *mut c_char;
pub fn strcat(s: *mut c_char, ct: *const c_char) -> *mut c_char;
pub fn strncat(s: *mut c_char, ct: *const c_char, n: size_t) -> *mut c_char;
pub fn strcmp(cs: *const c_char, ct: *const c_char) -> c_int;
pub fn strncmp(cs: *const c_char, ct: *const c_char, n: size_t) -> c_int;
pub fn strcoll(cs: *const c_char, ct: *const c_char) -> c_int;
pub fn strchr(cs: *const c_char, c: c_int) -> *mut c_char;
pub fn strrchr(cs: *const c_char, c: c_int) -> *mut c_char;
pub fn strspn(cs: *const c_char, ct: *const c_char) -> size_t;
pub fn strcspn(cs: *const c_char, ct: *const c_char) -> size_t;
pub fn strdup(cs: *const c_char) -> *mut c_char;
pub fn strpbrk(cs: *const c_char, ct: *const c_char) -> *mut c_char;
pub fn strstr(cs: *const c_char, ct: *const c_char) -> *mut c_char;
pub fn strlen(cs: *const c_char) -> size_t;
pub fn strnlen(cs: *const c_char, maxlen: size_t) -> size_t;
pub fn strerror(n: c_int) -> *mut c_char;
pub fn strtok(s: *mut c_char, t: *const c_char) -> *mut c_char;
pub fn strxfrm(s: *mut c_char, ct: *const c_char, n: size_t) -> size_t;
pub fn wcslen(buf: *const wchar_t) -> size_t;
pub fn wcstombs(dest: *mut c_char, src: *const wchar_t,
n: size_t) -> ::size_t;

pub fn memchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void;
pub fn memcmp(cx: *const c_void, ct: *const c_void, n: size_t) -> c_int;
pub fn memcpy(dest: *mut c_void, src: *const c_void,
n: size_t) -> *mut c_void;
pub fn memmove(dest: *mut c_void, src: *const c_void,
n: size_t) -> *mut c_void;
pub fn memset(dest: *mut c_void, c: c_int, n: size_t) -> *mut c_void;

pub fn abs(i: c_int) -> c_int;
pub fn atof(s: *const c_char) -> c_double;
pub fn labs(i: c_long) -> c_long;
pub fn rand() -> c_int;
pub fn srand(seed: c_uint);

pub fn arc4random_buf(buf: *const ::c_void, len: ::size_t);
pub fn freeaddrinfo(res: *mut addrinfo);
pub fn gai_strerror(errcode: ::c_int) -> *const ::c_char;
Expand Down Expand Up @@ -164,3 +298,21 @@ cfg_if! {
// Unknown target_arch
}
}

cfg_if! {
if #[cfg(core_cvoid)] {
pub use core::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)]
pub enum c_void {
// Two dummy variants so the #[repr] attribute can be used.
#[doc(hidden)]
__variant1,
#[doc(hidden)]
__variant2,
}
}
}
Loading