Skip to content

Commit a7f58a5

Browse files
committed
Add SGX C types.
1 parent 16f6fef commit a7f58a5

File tree

3 files changed

+213
-183
lines changed

3 files changed

+213
-183
lines changed

src/lib.rs

Lines changed: 25 additions & 183 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@
120120
)
121121
)]
122122
#![cfg_attr(not(feature = "use_std"), no_std)]
123-
// FIXME: this crate is empty for wasm32-unknown-unknown
124-
#![cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))]
125123

126124
#[cfg(all(not(cross_platform_docs), feature = "use_std"))]
127125
extern crate std as core;
@@ -131,206 +129,50 @@ mod macros;
131129

132130
mod dox;
133131

134-
cfg_if! {
135-
if #[cfg(core_cvoid)] {
136-
pub use core::ffi::c_void;
137-
} else {
138-
// Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help enable
139-
// more optimization opportunities around it recognizing things like
140-
// malloc/free.
141-
#[repr(u8)]
142-
pub enum c_void {
143-
// Two dummy variants so the #[repr] attribute can be used.
144-
#[doc(hidden)]
145-
__variant1,
146-
#[doc(hidden)]
147-
__variant2,
148-
}
149-
}
150-
}
151-
152-
pub type int8_t = i8;
153-
pub type int16_t = i16;
154-
pub type int32_t = i32;
155-
pub type int64_t = i64;
156-
pub type uint8_t = u8;
157-
pub type uint16_t = u16;
158-
pub type uint32_t = u32;
159-
pub type uint64_t = u64;
160-
161-
pub type c_schar = i8;
162-
pub type c_uchar = u8;
163-
pub type c_short = i16;
164-
pub type c_ushort = u16;
165-
pub type c_int = i32;
166-
pub type c_uint = u32;
167-
pub type c_float = f32;
168-
pub type c_double = f64;
169-
pub type c_longlong = i64;
170-
pub type c_ulonglong = u64;
171-
pub type intmax_t = i64;
172-
pub type uintmax_t = u64;
173-
174-
pub type size_t = usize;
175-
pub type ptrdiff_t = isize;
176-
pub type intptr_t = isize;
177-
pub type uintptr_t = usize;
178-
pub type ssize_t = isize;
179-
180-
pub enum FILE {}
181-
pub enum fpos_t {} // TODO: fill this out with a struct
182-
183-
pub const INT_MIN: c_int = -2147483648;
184-
pub const INT_MAX: c_int = 2147483647;
185-
186-
extern "C" {
187-
pub fn isalnum(c: c_int) -> c_int;
188-
pub fn isalpha(c: c_int) -> c_int;
189-
pub fn iscntrl(c: c_int) -> c_int;
190-
pub fn isdigit(c: c_int) -> c_int;
191-
pub fn isgraph(c: c_int) -> c_int;
192-
pub fn islower(c: c_int) -> c_int;
193-
pub fn isprint(c: c_int) -> c_int;
194-
pub fn ispunct(c: c_int) -> c_int;
195-
pub fn isspace(c: c_int) -> c_int;
196-
pub fn isupper(c: c_int) -> c_int;
197-
pub fn isxdigit(c: c_int) -> c_int;
198-
pub fn tolower(c: c_int) -> c_int;
199-
pub fn toupper(c: c_int) -> c_int;
200-
201-
#[cfg_attr(
202-
all(target_os = "macos", target_arch = "x86"),
203-
link_name = "fopen$UNIX2003"
204-
)]
205-
pub fn fopen(filename: *const c_char, mode: *const c_char) -> *mut FILE;
206-
#[cfg_attr(
207-
all(target_os = "macos", target_arch = "x86"),
208-
link_name = "freopen$UNIX2003"
209-
)]
210-
pub fn freopen(filename: *const c_char, mode: *const c_char, file: *mut FILE) -> *mut FILE;
211-
pub fn fflush(file: *mut FILE) -> c_int;
212-
pub fn fclose(file: *mut FILE) -> c_int;
213-
pub fn remove(filename: *const c_char) -> c_int;
214-
pub fn rename(oldname: *const c_char, newname: *const c_char) -> c_int;
215-
pub fn tmpfile() -> *mut FILE;
216-
pub fn setvbuf(stream: *mut FILE, buffer: *mut c_char, mode: c_int, size: size_t) -> c_int;
217-
pub fn setbuf(stream: *mut FILE, buf: *mut c_char);
218-
pub fn getchar() -> c_int;
219-
pub fn putchar(c: c_int) -> c_int;
220-
pub fn fgetc(stream: *mut FILE) -> c_int;
221-
pub fn fgets(buf: *mut c_char, n: c_int, stream: *mut FILE) -> *mut c_char;
222-
pub fn fputc(c: c_int, stream: *mut FILE) -> c_int;
223-
#[cfg_attr(
224-
all(target_os = "macos", target_arch = "x86"),
225-
link_name = "fputs$UNIX2003"
226-
)]
227-
pub fn fputs(s: *const c_char, stream: *mut FILE) -> c_int;
228-
pub fn puts(s: *const c_char) -> c_int;
229-
pub fn ungetc(c: c_int, stream: *mut FILE) -> c_int;
230-
pub fn fread(ptr: *mut c_void, size: size_t, nobj: size_t, stream: *mut FILE) -> size_t;
231-
#[cfg_attr(
232-
all(target_os = "macos", target_arch = "x86"),
233-
link_name = "fwrite$UNIX2003"
234-
)]
235-
pub fn fwrite(ptr: *const c_void, size: size_t, nobj: size_t, stream: *mut FILE) -> size_t;
236-
pub fn fseek(stream: *mut FILE, offset: c_long, whence: c_int) -> c_int;
237-
pub fn ftell(stream: *mut FILE) -> c_long;
238-
pub fn rewind(stream: *mut FILE);
239-
#[cfg_attr(target_os = "netbsd", link_name = "__fgetpos50")]
240-
pub fn fgetpos(stream: *mut FILE, ptr: *mut fpos_t) -> c_int;
241-
#[cfg_attr(target_os = "netbsd", link_name = "__fsetpos50")]
242-
pub fn fsetpos(stream: *mut FILE, ptr: *const fpos_t) -> c_int;
243-
pub fn feof(stream: *mut FILE) -> c_int;
244-
pub fn ferror(stream: *mut FILE) -> c_int;
245-
pub fn perror(s: *const c_char);
246-
pub fn atoi(s: *const c_char) -> c_int;
247-
#[cfg_attr(
248-
all(target_os = "macos", target_arch = "x86"),
249-
link_name = "strtod$UNIX2003"
250-
)]
251-
pub fn strtod(s: *const c_char, endp: *mut *mut c_char) -> c_double;
252-
pub fn strtol(s: *const c_char, endp: *mut *mut c_char, base: c_int) -> c_long;
253-
pub fn strtoul(s: *const c_char, endp: *mut *mut c_char, base: c_int) -> c_ulong;
254-
pub fn calloc(nobj: size_t, size: size_t) -> *mut c_void;
255-
pub fn malloc(size: size_t) -> *mut c_void;
256-
pub fn realloc(p: *mut c_void, size: size_t) -> *mut c_void;
257-
pub fn free(p: *mut c_void);
258-
pub fn abort() -> !;
259-
pub fn exit(status: c_int) -> !;
260-
pub fn _exit(status: c_int) -> !;
261-
pub fn atexit(cb: extern "C" fn()) -> c_int;
262-
#[cfg_attr(
263-
all(target_os = "macos", target_arch = "x86"),
264-
link_name = "system$UNIX2003"
265-
)]
266-
pub fn system(s: *const c_char) -> c_int;
267-
pub fn getenv(s: *const c_char) -> *mut c_char;
268-
269-
pub fn strcpy(dst: *mut c_char, src: *const c_char) -> *mut c_char;
270-
pub fn strncpy(dst: *mut c_char, src: *const c_char, n: size_t) -> *mut c_char;
271-
pub fn strcat(s: *mut c_char, ct: *const c_char) -> *mut c_char;
272-
pub fn strncat(s: *mut c_char, ct: *const c_char, n: size_t) -> *mut c_char;
273-
pub fn strcmp(cs: *const c_char, ct: *const c_char) -> c_int;
274-
pub fn strncmp(cs: *const c_char, ct: *const c_char, n: size_t) -> c_int;
275-
pub fn strcoll(cs: *const c_char, ct: *const c_char) -> c_int;
276-
pub fn strchr(cs: *const c_char, c: c_int) -> *mut c_char;
277-
pub fn strrchr(cs: *const c_char, c: c_int) -> *mut c_char;
278-
pub fn strspn(cs: *const c_char, ct: *const c_char) -> size_t;
279-
pub fn strcspn(cs: *const c_char, ct: *const c_char) -> size_t;
280-
pub fn strdup(cs: *const c_char) -> *mut c_char;
281-
pub fn strpbrk(cs: *const c_char, ct: *const c_char) -> *mut c_char;
282-
pub fn strstr(cs: *const c_char, ct: *const c_char) -> *mut c_char;
283-
pub fn strlen(cs: *const c_char) -> size_t;
284-
pub fn strnlen(cs: *const c_char, maxlen: size_t) -> size_t;
285-
#[cfg_attr(
286-
all(target_os = "macos", target_arch = "x86"),
287-
link_name = "strerror$UNIX2003"
288-
)]
289-
pub fn strerror(n: c_int) -> *mut c_char;
290-
pub fn strtok(s: *mut c_char, t: *const c_char) -> *mut c_char;
291-
pub fn strxfrm(s: *mut c_char, ct: *const c_char, n: size_t) -> size_t;
292-
pub fn wcslen(buf: *const wchar_t) -> size_t;
293-
pub fn wcstombs(dest: *mut c_char, src: *const wchar_t, n: size_t) -> ::size_t;
294-
295-
pub fn memchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void;
296-
pub fn memcmp(cx: *const c_void, ct: *const c_void, n: size_t) -> c_int;
297-
pub fn memcpy(dest: *mut c_void, src: *const c_void, n: size_t) -> *mut c_void;
298-
pub fn memmove(dest: *mut c_void, src: *const c_void, n: size_t) -> *mut c_void;
299-
pub fn memset(dest: *mut c_void, c: c_int, n: size_t) -> *mut c_void;
300-
}
301-
302-
// These are all inline functions on android, so they end up just being entirely
303-
// missing on that platform.
304-
305-
#[cfg(not(target_os = "android"))]
306-
extern "C" {
307-
pub fn abs(i: c_int) -> c_int;
308-
pub fn atof(s: *const c_char) -> c_double;
309-
pub fn labs(i: c_long) -> c_long;
310-
pub fn rand() -> c_int;
311-
pub fn srand(seed: c_uint);
312-
}
313-
314132
cfg_if! {
315133
if #[cfg(windows)] {
134+
mod libc;
135+
pub use libc::*;
136+
316137
mod windows;
317138
pub use windows::*;
318139
} else if #[cfg(target_os = "redox")] {
140+
mod libc;
141+
pub use libc::*;
142+
319143
mod redox;
320144
pub use redox::*;
321145
} else if #[cfg(target_os = "cloudabi")] {
146+
mod libc;
147+
pub use libc::*;
148+
322149
mod cloudabi;
323150
pub use cloudabi::*;
324151
} else if #[cfg(target_os = "fuchsia")] {
152+
mod libc;
153+
pub use libc::*;
154+
325155
mod fuchsia;
326156
pub use fuchsia::*;
327157
} else if #[cfg(target_os = "switch")] {
158+
mod libc;
159+
pub use libc::*;
160+
328161
mod switch;
329162
pub use switch::*;
330163
} else if #[cfg(unix)] {
164+
mod libc;
165+
pub use libc::*;
166+
331167
mod unix;
332168
pub use unix::*;
169+
} else if #[cfg(target_env = "sgx")] {
170+
mod sgx;
171+
pub use sgx::*;
172+
} else if #[cfg(target_os = "emscripten")] {
173+
mod libc;
174+
pub use libc::*;
333175
} else {
334-
// Unknown target_family
176+
// Unknown target: libc is "empty"
335177
}
336178
}

0 commit comments

Comments
 (0)