2016-03-01 21:11:38 +00:00
|
|
|
const linux = @import("linux.zig");
|
2016-02-28 05:06:46 +00:00
|
|
|
const errno = @import("errno.zig");
|
2016-02-04 08:00:54 +00:00
|
|
|
|
|
|
|
pub error SigInterrupt;
|
|
|
|
pub error Unexpected;
|
|
|
|
|
2016-08-18 03:11:04 +00:00
|
|
|
pub fn getRandomBytes(buf: []u8) -> %void {
|
2016-08-17 05:42:50 +00:00
|
|
|
switch (@compileVar("os")) {
|
2016-02-14 05:59:49 +00:00
|
|
|
linux => {
|
2016-07-27 03:40:11 +00:00
|
|
|
const ret = linux.getrandom(buf.ptr, buf.len, 0);
|
2016-08-17 05:42:50 +00:00
|
|
|
const err = linux.getErrno(ret);
|
2016-07-27 03:40:11 +00:00
|
|
|
if (err > 0) {
|
|
|
|
return switch (err) {
|
2016-09-13 20:46:27 +00:00
|
|
|
errno.EINVAL => @unreachable(),
|
|
|
|
errno.EFAULT => @unreachable(),
|
2016-02-28 05:06:46 +00:00
|
|
|
errno.EINTR => error.SigInterrupt,
|
|
|
|
else => error.Unexpected,
|
2016-02-14 05:59:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2016-09-05 21:01:54 +00:00
|
|
|
else => @compileError("unsupported os"),
|
2016-02-04 08:00:54 +00:00
|
|
|
}
|
|
|
|
}
|
2016-04-18 23:42:56 +00:00
|
|
|
|
|
|
|
#attribute("cold")
|
|
|
|
pub fn abort() -> unreachable {
|
2016-08-18 03:11:04 +00:00
|
|
|
switch (@compileVar("os")) {
|
|
|
|
linux => {
|
|
|
|
linux.raise(linux.SIGABRT);
|
|
|
|
linux.raise(linux.SIGKILL);
|
|
|
|
while (true) {}
|
|
|
|
},
|
2016-09-05 21:01:54 +00:00
|
|
|
else => @compileError("unsupported os"),
|
2016-08-18 03:11:04 +00:00
|
|
|
}
|
2016-04-18 23:42:56 +00:00
|
|
|
}
|