From 92172d91612e3b2673b69c0d040adc9418710ad9 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Tue, 20 Nov 2018 20:23:12 +0100 Subject: [PATCH 1/2] Add SGX C types. --- ci/style.rs | 2 + src/ctypes.rs | 50 +++++++++++ src/lib.rs | 236 ++++++++++++-------------------------------------- src/libc.rs | 134 ++++++++++++++++++++++++++++ src/sgx.rs | 5 ++ 5 files changed, 244 insertions(+), 183 deletions(-) create mode 100644 src/ctypes.rs create mode 100644 src/libc.rs create mode 100644 src/sgx.rs diff --git a/ci/style.rs b/ci/style.rs index 6671d1c4..747e26c0 100644 --- a/ci/style.rs +++ b/ci/style.rs @@ -72,6 +72,8 @@ fn walk(path: &Path, err: &mut Errors) { "dox.rs" | "lib.rs" | + "ctypes.rs" | + "libc.rs" | "macros.rs" => continue, _ => {} diff --git a/src/ctypes.rs b/src/ctypes.rs new file mode 100644 index 00000000..aebbfb77 --- /dev/null +++ b/src/ctypes.rs @@ -0,0 +1,50 @@ +//! Common libc types + +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, + } + } +} + +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 const INT_MIN: c_int = -2147483648; +pub const INT_MAX: c_int = 2147483647; diff --git a/src/lib.rs b/src/lib.rs index bea11024..c8beeedc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -120,8 +120,6 @@ ) )] #![cfg_attr(not(feature = "use_std"), no_std)] -// FIXME: this crate is empty for wasm32-unknown-unknown -#![cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))] #[cfg(all(not(cross_platform_docs), feature = "use_std"))] extern crate std as core; @@ -131,206 +129,78 @@ mod macros; mod dox; -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, - } - } -} - -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 enum FILE {} -pub enum fpos_t {} // TODO: fill this out with a struct - -pub const INT_MIN: c_int = -2147483648; -pub const INT_MAX: c_int = 2147483647; - -extern "C" { - 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; - - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "fopen$UNIX2003" - )] - pub fn fopen(filename: *const c_char, mode: *const c_char) -> *mut FILE; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "freopen$UNIX2003" - )] - 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; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "fputs$UNIX2003" - )] - 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; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "fwrite$UNIX2003" - )] - 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); - #[cfg_attr(target_os = "netbsd", link_name = "__fgetpos50")] - pub fn fgetpos(stream: *mut FILE, ptr: *mut fpos_t) -> c_int; - #[cfg_attr(target_os = "netbsd", link_name = "__fsetpos50")] - 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; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "strtod$UNIX2003" - )] - 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 "C" fn()) -> c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "system$UNIX2003" - )] - 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; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "strerror$UNIX2003" - )] - 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; -} - -// These are all inline functions on android, so they end up just being entirely -// missing on that platform. - -#[cfg(not(target_os = "android"))] -extern "C" { - 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); -} - cfg_if! { if #[cfg(windows)] { + mod libc; + pub use libc::*; + + mod ctypes; + pub use ctypes::*; + mod windows; pub use windows::*; } else if #[cfg(target_os = "redox")] { + mod libc; + pub use libc::*; + + mod ctypes; + pub use ctypes::*; + mod redox; pub use redox::*; } else if #[cfg(target_os = "cloudabi")] { + mod libc; + pub use libc::*; + + mod ctypes; + pub use ctypes::*; + mod cloudabi; pub use cloudabi::*; } else if #[cfg(target_os = "fuchsia")] { + mod libc; + pub use libc::*; + + mod ctypes; + pub use ctypes::*; + mod fuchsia; pub use fuchsia::*; } else if #[cfg(target_os = "switch")] { + mod ctypes; + pub use ctypes::*; + mod switch; pub use switch::*; } else if #[cfg(unix)] { + mod libc; + pub use libc::*; + + mod ctypes; + pub use ctypes::*; + mod unix; pub use unix::*; + } else if #[cfg(target_env = "sgx")] { + mod ctypes; + pub use ctypes::*; + + mod sgx; + pub use sgx::*; + } else if #[cfg(target_os = "emscripten")] { + mod libc; + pub use libc::*; + + mod ctypes; + pub use ctypes::*; + } else if #[cfg(all(target_arch = "wasm32", + target_env = "unknown"))] { + // wasm32-unknown-unknown } else { - // Unknown target_family + mod libc; + pub use libc::*; + + mod ctypes; + pub use ctypes::*; } } diff --git a/src/libc.rs b/src/libc.rs new file mode 100644 index 00000000..6f4aa3b5 --- /dev/null +++ b/src/libc.rs @@ -0,0 +1,134 @@ +//! Common libc APIs + +use ::{c_int, c_uint, c_void, c_double, size_t, wchar_t, c_char, c_long, c_ulong}; + +pub enum FILE {} +pub enum fpos_t {} // TODO: fill this out with a struct + +extern "C" { + 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; + + #[cfg_attr( + all(target_os = "macos", target_arch = "x86"), + link_name = "fopen$UNIX2003" + )] + pub fn fopen(filename: *const c_char, mode: *const c_char) -> *mut FILE; + #[cfg_attr( + all(target_os = "macos", target_arch = "x86"), + link_name = "freopen$UNIX2003" + )] + 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; + #[cfg_attr( + all(target_os = "macos", target_arch = "x86"), + link_name = "fputs$UNIX2003" + )] + 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; + #[cfg_attr( + all(target_os = "macos", target_arch = "x86"), + link_name = "fwrite$UNIX2003" + )] + 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); + #[cfg_attr(target_os = "netbsd", link_name = "__fgetpos50")] + pub fn fgetpos(stream: *mut FILE, ptr: *mut fpos_t) -> c_int; + #[cfg_attr(target_os = "netbsd", link_name = "__fsetpos50")] + 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; + #[cfg_attr( + all(target_os = "macos", target_arch = "x86"), + link_name = "strtod$UNIX2003" + )] + 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 "C" fn()) -> c_int; + #[cfg_attr( + all(target_os = "macos", target_arch = "x86"), + link_name = "system$UNIX2003" + )] + 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; + #[cfg_attr( + all(target_os = "macos", target_arch = "x86"), + link_name = "strerror$UNIX2003" + )] + 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; +} + +// These are all inline functions on android, so they end up just being entirely +// missing on that platform. + +#[cfg(not(target_os = "android"))] +extern "C" { + 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); +} diff --git a/src/sgx.rs b/src/sgx.rs new file mode 100644 index 00000000..b95a9170 --- /dev/null +++ b/src/sgx.rs @@ -0,0 +1,5 @@ +//! SGX C types definition + +pub type c_char = i8; +pub type c_long = i64; +pub type c_ulong = u64; From 5c1a6b8a6d558882927a0816d91c01b9c2a88018 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Wed, 21 Nov 2018 20:34:50 +0100 Subject: [PATCH 2/2] splice the common libc functions and ctypes throughout the library --- libc-test/build.rs | 69 +++++++++---- src/cloudabi/mod.rs | 152 +++++++++++++++++++++++++++++ src/ctypes.rs | 50 ---------- src/fuchsia/mod.rs | 152 +++++++++++++++++++++++++++++ src/lib.rs | 137 +++++++++++++------------- src/libc.rs | 134 ------------------------- src/redox/mod.rs | 154 +++++++++++++++++++++++++++++ src/sgx.rs | 49 ++++++++++ src/switch.rs | 50 ++++++++++ src/unix/bsd/mod.rs | 6 ++ src/unix/haiku/mod.rs | 8 ++ src/unix/hermit/mod.rs | 6 ++ src/unix/mod.rs | 178 ++++++++++++++++++++++++++++++++++ src/unix/newlib/mod.rs | 6 ++ src/unix/notbsd/emscripten.rs | 6 ++ src/unix/notbsd/linux/mod.rs | 6 ++ src/unix/solaris/mod.rs | 6 ++ src/unix/uclibc/mod.rs | 6 ++ src/windows.rs | 152 +++++++++++++++++++++++++++++ 19 files changed, 1053 insertions(+), 274 deletions(-) delete mode 100644 src/ctypes.rs delete mode 100644 src/libc.rs diff --git a/libc-test/build.rs b/libc-test/build.rs index 90c5640b..5fc9aeb7 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -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(), @@ -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") => { @@ -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 @@ -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, @@ -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 @@ -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 @@ -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 @@ -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 @@ -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, }); diff --git a/src/cloudabi/mod.rs b/src/cloudabi/mod.rs index e506414e..f72eeb4d 100644 --- a/src/cloudabi/mod.rs +++ b/src/cloudabi/mod.rs @@ -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; @@ -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; @@ -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; @@ -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, + } + } +} diff --git a/src/ctypes.rs b/src/ctypes.rs deleted file mode 100644 index aebbfb77..00000000 --- a/src/ctypes.rs +++ /dev/null @@ -1,50 +0,0 @@ -//! Common libc types - -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, - } - } -} - -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 const INT_MIN: c_int = -2147483648; -pub const INT_MAX: c_int = 2147483647; diff --git a/src/fuchsia/mod.rs b/src/fuchsia/mod.rs index 7c1d1a49..deb1c5d9 100644 --- a/src/fuchsia/mod.rs +++ b/src/fuchsia/mod.rs @@ -7,6 +7,34 @@ use dox::{mem, Option}; // PUB_TYPE +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 pid_t = i32; pub type uid_t = u32; pub type gid_t = u32; @@ -1049,6 +1077,9 @@ s! { // PUB_CONST +pub const INT_MIN: c_int = -2147483648; +pub const INT_MAX: c_int = 2147483647; + pub const SIG_DFL: sighandler_t = 0 as sighandler_t; pub const SIG_IGN: sighandler_t = 1 as sighandler_t; pub const SIG_ERR: sighandler_t = !0 as sighandler_t; @@ -3011,7 +3042,110 @@ f! { #[link(name = "fdio")] extern {} +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 getpwnam(name: *const ::c_char) -> *mut passwd; pub fn getpwuid(uid: ::uid_t) -> *mut passwd; @@ -3953,3 +4087,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, + } + } +} diff --git a/src/lib.rs b/src/lib.rs index c8beeedc..54f67895 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,31 +21,45 @@ )] #![cfg_attr( all(target_os = "linux", target_arch = "x86_64"), - doc(html_root_url = "https://rust-lang.github.io/libc/x86_64-unknown-linux-gnu") + doc( + html_root_url = "https://rust-lang.github.io/libc/x86_64-unknown-linux-gnu" + ) )] #![cfg_attr( all(target_os = "linux", target_arch = "x86"), - doc(html_root_url = "https://rust-lang.github.io/libc/i686-unknown-linux-gnu") + doc( + html_root_url = "https://rust-lang.github.io/libc/i686-unknown-linux-gnu" + ) )] #![cfg_attr( all(target_os = "linux", target_arch = "arm"), - doc(html_root_url = "https://rust-lang.github.io/libc/arm-unknown-linux-gnueabihf") + doc( + html_root_url = "https://rust-lang.github.io/libc/arm-unknown-linux-gnueabihf" + ) )] #![cfg_attr( all(target_os = "linux", target_arch = "mips"), - doc(html_root_url = "https://rust-lang.github.io/libc/mips-unknown-linux-gnu") + doc( + html_root_url = "https://rust-lang.github.io/libc/mips-unknown-linux-gnu" + ) )] #![cfg_attr( all(target_os = "linux", target_arch = "aarch64"), - doc(html_root_url = "https://rust-lang.github.io/libc/aarch64-unknown-linux-gnu") + doc( + html_root_url = "https://rust-lang.github.io/libc/aarch64-unknown-linux-gnu" + ) )] #![cfg_attr( all(target_os = "linux", target_env = "musl"), - doc(html_root_url = "https://rust-lang.github.io/libc/x86_64-unknown-linux-musl") + doc( + html_root_url = "https://rust-lang.github.io/libc/x86_64-unknown-linux-musl" + ) )] #![cfg_attr( all(target_os = "macos", target_arch = "x86_64"), - doc(html_root_url = "https://rust-lang.github.io/libc/x86_64-apple-darwin") + doc( + html_root_url = "https://rust-lang.github.io/libc/x86_64-apple-darwin" + ) )] #![cfg_attr( all(target_os = "macos", target_arch = "x86"), @@ -53,59 +67,87 @@ )] #![cfg_attr( all(windows, target_arch = "x86_64", target_env = "gnu"), - doc(html_root_url = "https://rust-lang.github.io/libc/x86_64-pc-windows-gnu") + doc( + html_root_url = "https://rust-lang.github.io/libc/x86_64-pc-windows-gnu" + ) )] #![cfg_attr( all(windows, target_arch = "x86", target_env = "gnu"), - doc(html_root_url = "https://rust-lang.github.io/libc/i686-pc-windows-gnu") + doc( + html_root_url = "https://rust-lang.github.io/libc/i686-pc-windows-gnu" + ) )] #![cfg_attr( all(windows, target_arch = "x86_64", target_env = "msvc"), - doc(html_root_url = "https://rust-lang.github.io/libc/x86_64-pc-windows-msvc") + doc( + html_root_url = "https://rust-lang.github.io/libc/x86_64-pc-windows-msvc" + ) )] #![cfg_attr( all(windows, target_arch = "x86", target_env = "msvc"), - doc(html_root_url = "https://rust-lang.github.io/libc/i686-pc-windows-msvc") + doc( + html_root_url = "https://rust-lang.github.io/libc/i686-pc-windows-msvc" + ) )] #![cfg_attr( target_os = "android", - doc(html_root_url = "https://rust-lang.github.io/libc/arm-linux-androideabi") + doc( + html_root_url = "https://rust-lang.github.io/libc/arm-linux-androideabi" + ) )] #![cfg_attr( target_os = "freebsd", - doc(html_root_url = "https://rust-lang.github.io/libc/x86_64-unknown-freebsd") + doc( + html_root_url = "https://rust-lang.github.io/libc/x86_64-unknown-freebsd" + ) )] #![cfg_attr( target_os = "openbsd", - doc(html_root_url = "https://rust-lang.github.io/libc/x86_64-unknown-openbsd") + doc( + html_root_url = "https://rust-lang.github.io/libc/x86_64-unknown-openbsd" + ) )] #![cfg_attr( target_os = "bitrig", - doc(html_root_url = "https://rust-lang.github.io/libc/x86_64-unknown-bitrig") + doc( + html_root_url = "https://rust-lang.github.io/libc/x86_64-unknown-bitrig" + ) )] #![cfg_attr( target_os = "netbsd", - doc(html_root_url = "https://rust-lang.github.io/libc/x86_64-unknown-netbsd") + doc( + html_root_url = "https://rust-lang.github.io/libc/x86_64-unknown-netbsd" + ) )] #![cfg_attr( target_os = "dragonfly", - doc(html_root_url = "https://rust-lang.github.io/libc/x86_64-unknown-dragonfly") + doc( + html_root_url = "https://rust-lang.github.io/libc/x86_64-unknown-dragonfly" + ) )] #![cfg_attr( target_os = "solaris", - doc(html_root_url = "https://rust-lang.github.io/libc/x86_64-sun-solaris") + doc( + html_root_url = "https://rust-lang.github.io/libc/x86_64-sun-solaris" + ) )] #![cfg_attr( all(target_os = "emscripten", target_arch = "asmjs"), - doc(html_root_url = "https://rust-lang.github.io/libc/asmjs-unknown-emscripten") + doc( + html_root_url = "https://rust-lang.github.io/libc/asmjs-unknown-emscripten" + ) )] #![cfg_attr( all(target_os = "emscripten", target_arch = "wasm32"), - doc(html_root_url = "https://rust-lang.github.io/libc/wasm32-unknown-emscripten") + doc( + html_root_url = "https://rust-lang.github.io/libc/wasm32-unknown-emscripten" + ) )] #![cfg_attr( all(target_os = "linux", target_arch = "sparc64"), - doc(html_root_url = "https://rust-lang.github.io/libc/sparc64-unknown-linux-gnu") + doc( + html_root_url = "https://rust-lang.github.io/libc/sparc64-unknown-linux-gnu" + ) )] // Attributes needed when building as part of the standard library #![cfg_attr(feature = "stdbuild", feature(staged_api, cfg_target_vendor))] @@ -131,76 +173,27 @@ mod dox; cfg_if! { if #[cfg(windows)] { - mod libc; - pub use libc::*; - - mod ctypes; - pub use ctypes::*; - mod windows; pub use windows::*; } else if #[cfg(target_os = "redox")] { - mod libc; - pub use libc::*; - - mod ctypes; - pub use ctypes::*; - mod redox; pub use redox::*; } else if #[cfg(target_os = "cloudabi")] { - mod libc; - pub use libc::*; - - mod ctypes; - pub use ctypes::*; - mod cloudabi; pub use cloudabi::*; } else if #[cfg(target_os = "fuchsia")] { - mod libc; - pub use libc::*; - - mod ctypes; - pub use ctypes::*; - mod fuchsia; pub use fuchsia::*; } else if #[cfg(target_os = "switch")] { - mod ctypes; - pub use ctypes::*; - mod switch; pub use switch::*; } else if #[cfg(unix)] { - mod libc; - pub use libc::*; - - mod ctypes; - pub use ctypes::*; - mod unix; pub use unix::*; } else if #[cfg(target_env = "sgx")] { - mod ctypes; - pub use ctypes::*; - mod sgx; pub use sgx::*; - } else if #[cfg(target_os = "emscripten")] { - mod libc; - pub use libc::*; - - mod ctypes; - pub use ctypes::*; - } else if #[cfg(all(target_arch = "wasm32", - target_env = "unknown"))] { - // wasm32-unknown-unknown - } else { - mod libc; - pub use libc::*; - - mod ctypes; - pub use ctypes::*; + } else { + // non-supported targets: empty... } } diff --git a/src/libc.rs b/src/libc.rs deleted file mode 100644 index 6f4aa3b5..00000000 --- a/src/libc.rs +++ /dev/null @@ -1,134 +0,0 @@ -//! Common libc APIs - -use ::{c_int, c_uint, c_void, c_double, size_t, wchar_t, c_char, c_long, c_ulong}; - -pub enum FILE {} -pub enum fpos_t {} // TODO: fill this out with a struct - -extern "C" { - 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; - - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "fopen$UNIX2003" - )] - pub fn fopen(filename: *const c_char, mode: *const c_char) -> *mut FILE; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "freopen$UNIX2003" - )] - 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; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "fputs$UNIX2003" - )] - 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; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "fwrite$UNIX2003" - )] - 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); - #[cfg_attr(target_os = "netbsd", link_name = "__fgetpos50")] - pub fn fgetpos(stream: *mut FILE, ptr: *mut fpos_t) -> c_int; - #[cfg_attr(target_os = "netbsd", link_name = "__fsetpos50")] - 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; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "strtod$UNIX2003" - )] - 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 "C" fn()) -> c_int; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "system$UNIX2003" - )] - 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; - #[cfg_attr( - all(target_os = "macos", target_arch = "x86"), - link_name = "strerror$UNIX2003" - )] - 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; -} - -// These are all inline functions on android, so they end up just being entirely -// missing on that platform. - -#[cfg(not(target_os = "android"))] -extern "C" { - 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); -} diff --git a/src/redox/mod.rs b/src/redox/mod.rs index 7c7f4229..9870fa6d 100644 --- a/src/redox/mod.rs +++ b/src/redox/mod.rs @@ -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 c_char = i8; pub type c_long = i64; pub type c_ulong = u64; @@ -25,6 +54,9 @@ s! { } } +pub const INT_MIN: c_int = -2147483648; +pub const INT_MAX: c_int = 2147483647; + pub const STDIN_FILENO: ::c_int = 0; pub const STDOUT_FILENO: ::c_int = 1; pub const STDERR_FILENO: ::c_int = 2; @@ -117,7 +149,111 @@ pub const SIGIO: ::c_int = 29; pub const SIGPWR: ::c_int = 30; pub const SIGSYS: ::c_int = 31; +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 chown(path: *const c_char, uid: uid_t, gid: gid_t) -> ::c_int; pub fn close(fd: ::c_int) -> ::c_int; pub fn fchown(fd: ::c_int, uid: ::uid_t, gid: ::gid_t) -> ::c_int; @@ -140,3 +276,21 @@ extern {} pub use self::net::*; mod net; + +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, + } + } +} diff --git a/src/sgx.rs b/src/sgx.rs index b95a9170..04513339 100644 --- a/src/sgx.rs +++ b/src/sgx.rs @@ -1,5 +1,54 @@ //! SGX C types definition +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_char = i8; pub type c_long = i64; pub type c_ulong = u64; + +pub const INT_MIN: c_int = -2147483648; +pub const INT_MAX: c_int = 2147483647; + +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, + } + } +} diff --git a/src/switch.rs b/src/switch.rs index 240e9380..e2d9b491 100644 --- a/src/switch.rs +++ b/src/switch.rs @@ -1,7 +1,57 @@ //! Switch C type definitions +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 off_t = i64; pub type c_char = u8; pub type c_long = i64; pub type c_ulong = u64; pub type wchar_t = u32; + +pub const INT_MIN: c_int = -2147483648; +pub const INT_MAX: c_int = 2147483647; + +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, + } + } +} + diff --git a/src/unix/bsd/mod.rs b/src/unix/bsd/mod.rs index 05cf8fee..a2df23bf 100644 --- a/src/unix/bsd/mod.rs +++ b/src/unix/bsd/mod.rs @@ -417,6 +417,12 @@ f! { } extern { + 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 getifaddrs(ifap: *mut *mut ::ifaddrs) -> ::c_int; pub fn freeifaddrs(ifa: *mut ::ifaddrs); pub fn setgroups(ngroups: ::c_int, diff --git a/src/unix/haiku/mod.rs b/src/unix/haiku/mod.rs index 307a5a40..e65bca7f 100644 --- a/src/unix/haiku/mod.rs +++ b/src/unix/haiku/mod.rs @@ -1086,6 +1086,14 @@ f! { } } +extern { + 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); +} + #[link(name = "bsd")] extern { pub fn clock_gettime(clk_id: ::c_int, tp: *mut ::timespec) -> ::c_int; diff --git a/src/unix/hermit/mod.rs b/src/unix/hermit/mod.rs index bed6f7ae..aadfa1cf 100644 --- a/src/unix/hermit/mod.rs +++ b/src/unix/hermit/mod.rs @@ -696,6 +696,12 @@ f! { } extern { + 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 bind(s: ::c_int, name: *const ::sockaddr, namelen: ::socklen_t) -> ::c_int; diff --git a/src/unix/mod.rs b/src/unix/mod.rs index 06275a69..2d25690b 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -5,6 +5,34 @@ use dox::Option; +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 pid_t = i32; pub type uid_t = u32; pub type gid_t = u32; @@ -188,6 +216,9 @@ s! { } } +pub const INT_MIN: c_int = -2147483648; +pub const INT_MAX: c_int = 2147483647; + pub const SIG_DFL: sighandler_t = 0 as sighandler_t; pub const SIG_IGN: sighandler_t = 1 as sighandler_t; pub const SIG_ERR: sighandler_t = !0 as sighandler_t; @@ -337,6 +368,135 @@ cfg_if! { } } +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; + #[cfg_attr( + all(target_os = "macos", target_arch = "x86"), + link_name = "fopen$UNIX2003" + )] + pub fn fopen(filename: *const c_char, mode: *const c_char) -> *mut FILE; + #[cfg_attr( + all(target_os = "macos", target_arch = "x86"), + link_name = "freopen$UNIX2003" + )] + 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; + #[cfg_attr( + all(target_os = "macos", target_arch = "x86"), + link_name = "fputs$UNIX2003" + )] + 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; + #[cfg_attr( + all(target_os = "macos", target_arch = "x86"), + link_name = "fwrite$UNIX2003" + )] + 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); + #[cfg_attr(target_os = "netbsd", link_name = "__fgetpos50")] + pub fn fgetpos(stream: *mut FILE, ptr: *mut fpos_t) -> c_int; + #[cfg_attr(target_os = "netbsd", link_name = "__fsetpos50")] + 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; + #[cfg_attr( + all(target_os = "macos", target_arch = "x86"), + link_name = "strtod$UNIX2003" + )] + 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; + #[cfg_attr( + all(target_os = "macos", target_arch = "x86"), + link_name = "system$UNIX2003" + )] + 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; + #[cfg_attr( + all(target_os = "macos", target_arch = "x86"), + link_name = "strerror$UNIX2003" + )] + 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; +} + extern { #[cfg_attr(target_os = "netbsd", link_name = "__getpwnam50")] pub fn getpwnam(name: *const ::c_char) -> *mut passwd; @@ -984,3 +1144,21 @@ cfg_if! { // Unknown target_os } } + +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, + } + } +} diff --git a/src/unix/newlib/mod.rs b/src/unix/newlib/mod.rs index 9968d366..77a4eb99 100644 --- a/src/unix/newlib/mod.rs +++ b/src/unix/newlib/mod.rs @@ -654,6 +654,12 @@ f! { } extern { + 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 bind(fd: ::c_int, addr: *const sockaddr, len: socklen_t) -> ::c_int; pub fn closesocket(sockfd: ::c_int) -> ::c_int; pub fn ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int; diff --git a/src/unix/notbsd/emscripten.rs b/src/unix/notbsd/emscripten.rs index e680032c..28791d8f 100644 --- a/src/unix/notbsd/emscripten.rs +++ b/src/unix/notbsd/emscripten.rs @@ -1573,6 +1573,12 @@ f! { } extern { + 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 setpwent(); pub fn endpwent(); pub fn getpwent() -> *mut passwd; diff --git a/src/unix/notbsd/linux/mod.rs b/src/unix/notbsd/linux/mod.rs index a47e809c..78dced15 100644 --- a/src/unix/notbsd/linux/mod.rs +++ b/src/unix/notbsd/linux/mod.rs @@ -1754,6 +1754,12 @@ f! { } extern { + 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 aio_read(aiocbp: *mut aiocb) -> ::c_int; pub fn aio_write(aiocbp: *mut aiocb) -> ::c_int; pub fn aio_fsync(op: ::c_int, aiocbp: *mut aiocb) -> ::c_int; diff --git a/src/unix/solaris/mod.rs b/src/unix/solaris/mod.rs index 0df424dd..c4ec111b 100644 --- a/src/unix/solaris/mod.rs +++ b/src/unix/solaris/mod.rs @@ -1258,6 +1258,12 @@ f! { } extern { + 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 getifaddrs(ifap: *mut *mut ::ifaddrs) -> ::c_int; pub fn freeifaddrs(ifa: *mut ::ifaddrs); diff --git a/src/unix/uclibc/mod.rs b/src/unix/uclibc/mod.rs index 03a8594f..2c80fd19 100644 --- a/src/unix/uclibc/mod.rs +++ b/src/unix/uclibc/mod.rs @@ -1551,6 +1551,12 @@ f! { } extern { + 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 fdatasync(fd: ::c_int) -> ::c_int; pub fn mincore(addr: *mut ::c_void, len: ::size_t, vec: *mut ::c_uchar) -> ::c_int; diff --git a/src/windows.rs b/src/windows.rs index bdb0e02f..4fc2c16a 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -1,5 +1,33 @@ //! Windows CRT definitions +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_char = i8; pub type c_long = i32; pub type c_ulong = u32; @@ -66,6 +94,9 @@ s! { } } +pub const INT_MIN: c_int = -2147483648; +pub const INT_MAX: c_int = 2147483647; + pub const EXIT_FAILURE: ::c_int = 1; pub const EXIT_SUCCESS: ::c_int = 0; pub const RAND_MAX: ::c_int = 32767; @@ -164,7 +195,110 @@ pub const STRUNCATE: ::c_int = 80; #[link(name = "libcmt", cfg(target_feature = "crt-static"))] extern {} +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); + #[link_name = "_chmod"] pub fn chmod(path: *const c_char, mode: ::c_int) -> ::c_int; #[link_name = "_wchmod"] @@ -246,3 +380,21 @@ extern { pub fn wsetlocale(category: ::c_int, locale: *const wchar_t) -> *mut wchar_t; } + +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, + } + } +}