authorgravatar for i@mgxm.meMarcio Giaxa <i@mgxm.me> 2018-12-18 02:42:54-02:00
committergravatar for i@mgxm.meMarcio Giaxa <i@mgxm.me> 2018-12-19 18:42:00-02:00
log1811e7e6c96844a8381e6a69017948cae0b8b261
tree4ba5e387f6cc16403a7848d73197c21463601877
parent11ced4f99d95ec144d9dbb79ead335b571f714fe

freebsd: remove getrandom dependency from libc

The system call getrandom(2) just landed on FreeBSD 12, so if we want to support some earlier version or at least FreeBSD 11, we can't depend on the system call.

3 files changed, 2 insertions(+), 7 deletions(-)

std/c/freebsd.zig-1
...@@ -15,7 +15,6 @@ pub extern "c" fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usi...@@ -15,7 +15,6 @@ pub extern "c" fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usi
15pub extern "c" fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) c_int;15pub extern "c" fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) c_int;
16pub extern "c" fn getdirentries(fd: c_int, buf_ptr: [*]u8, nbytes: usize, basep: *i64) usize;16pub extern "c" fn getdirentries(fd: c_int, buf_ptr: [*]u8, nbytes: usize, basep: *i64) usize;
17pub extern "c" fn pipe2(arg0: *[2]c_int, arg1: u32) c_int;17pub extern "c" fn pipe2(arg0: *[2]c_int, arg1: u32) c_int;
18pub extern "c" fn getrandom(buf: [*]u8, count: usize, flags: u32) c_int;
1918
20/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.19/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
21pub const Kevent = extern struct {20pub const Kevent = extern struct {
std/os/freebsd/index.zig-4
...@@ -672,10 +672,6 @@ pub fn exit(code: i32) noreturn {...@@ -672,10 +672,6 @@ pub fn exit(code: i32) noreturn {
672 c.exit(code);672 c.exit(code);
673}673}
674674
675pub fn getrandom(buf: [*]u8, count: usize, flags: u32) usize {
676 return errnoWrap(c.getrandom(buf, count, flags));
677}
678
679pub fn kill(pid: i32, sig: i32) usize {675pub fn kill(pid: i32, sig: i32) usize {
680 return arch.syscall2(SYS_kill, @bitCast(usize, isize(pid)), @bitCast(usize, isize(sig)));676 return arch.syscall2(SYS_kill, @bitCast(usize, isize(pid)), @bitCast(usize, isize(sig)));
681}677}
std/os/index.zig+2-2
...@@ -103,7 +103,7 @@ const math = std.math;...@@ -103,7 +103,7 @@ const math = std.math;
103/// library implementation.103/// library implementation.
104pub fn getRandomBytes(buf: []u8) !void {104pub fn getRandomBytes(buf: []u8) !void {
105 switch (builtin.os) {105 switch (builtin.os) {
106 Os.linux, Os.freebsd => while (true) {106 Os.linux => while (true) {
107 // TODO check libc version and potentially call c.getrandom.107 // TODO check libc version and potentially call c.getrandom.
108 // See #397108 // See #397
109 const errno = posix.getErrno(posix.getrandom(buf.ptr, buf.len, 0));109 const errno = posix.getErrno(posix.getrandom(buf.ptr, buf.len, 0));
...@@ -116,7 +116,7 @@ pub fn getRandomBytes(buf: []u8) !void {...@@ -116,7 +116,7 @@ pub fn getRandomBytes(buf: []u8) !void {
116 else => return unexpectedErrorPosix(errno),116 else => return unexpectedErrorPosix(errno),
117 }117 }
118 },118 },
119 Os.macosx, Os.ios => return getRandomBytesDevURandom(buf),119 Os.macosx, Os.ios, Os.freebsd => return getRandomBytesDevURandom(buf),
120 Os.windows => {120 Os.windows => {
121 // Call RtlGenRandom() instead of CryptGetRandom() on Windows121 // Call RtlGenRandom() instead of CryptGetRandom() on Windows
122 // https://github.com/rust-lang-nursery/rand/issues/111122 // https://github.com/rust-lang-nursery/rand/issues/111