cf9b21c09f
- Implemented some syscall for MacOSX - tested on : El Capitan 10.11 x86_64 - make self hosted test run on macosx - modified run_test so it does not fail when parseh throws warnings (most of them are related to buildin types from gcc that arent defined in header files and unions) - making -mmacosx-version-min and -mios-version-min works like gcc (command line paramers have precedence over enviroment variables)
41 lines
1.1 KiB
Zig
41 lines
1.1 KiB
Zig
const system = switch(@compileVar("os")) {
|
|
linux => @import("linux.zig"),
|
|
darwin => @import("darwin.zig"),
|
|
else => @compileError("Unsupported OS"),
|
|
};
|
|
const errno = @import("errno.zig");
|
|
|
|
pub error Unexpected;
|
|
|
|
pub fn getRandomBytes(buf: []u8) -> %void {
|
|
while (true) {
|
|
const ret = switch (@compileVar("os")) {
|
|
linux => system.getrandom(buf.ptr, buf.len, 0),
|
|
darwin => system.getrandom(buf.ptr, buf.len),
|
|
else => @compileError("unsupported os"),
|
|
};
|
|
const err = system.getErrno(ret);
|
|
if (err > 0) {
|
|
return switch (err) {
|
|
errno.EINVAL => @unreachable(),
|
|
errno.EFAULT => @unreachable(),
|
|
errno.EINTR => continue,
|
|
else => error.Unexpected,
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
|
|
#attribute("cold")
|
|
pub fn abort() -> unreachable {
|
|
switch (@compileVar("os")) {
|
|
linux, darwin => {
|
|
system.raise(system.SIGABRT);
|
|
system.raise(system.SIGKILL);
|
|
while (true) {}
|
|
},
|
|
else => @compileError("unsupported os"),
|
|
}
|
|
}
|