authorgravatar for git@l4.pmLuna <git@l4.pm> 2019-12-31 15:33:23-03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-31 15:58:03-05:00
logf0cbf63e1ae38d9c13cb07a151567b4890287ae9
tree91a5365929cb596fef39a21b364986f4e9995aa2
parent997812e8fb9146360aa5200f0adbcd4863183287
signature Commit is signed but in an unrecognized format.

os: use system for memfd_create

- os: update flags type for memfd_create

2 files changed, 5 insertions(+), 8 deletions(-)

lib/std/os.zig+4-7
......@@ -3282,12 +3282,9 @@ pub fn setsockopt(fd: fd_t, level: u32, optname: u32, opt: []const u8) SetSockOp
32823282 }
32833283}
32843284
3285// TODO support for non-null terminated strings?
3286pub fn memfd_createC(name: [*:0]const u8, flags: usize) !fd_t {
3287 if (builtin.os != .linux) @compileError("memfd_create() not implemented for this target");
3288
3289 const rc = linux.memfd_create(name, flags);
3290 switch (linux.getErrno(rc)) {
3285pub fn memfd_createC(name: [*:0]const u8, flags: u32) !fd_t {
3286 const rc = system.memfd_create(name, flags);
3287 switch (errno(rc)) {
32913288 0 => return @intCast(fd_t, rc),
32923289 EFAULT => unreachable, // name has invalid memory
32933290 EINVAL => unreachable, // name/flags are faulty
......@@ -3309,7 +3306,7 @@ fn toMemFdPath(name: []const u8) ![MFD_MAX_NAME_LEN:0]u8 {
33093306 return path_with_null;
33103307}
33113308
3312pub fn memfd_create(name: []const u8, flags: usize) !fd_t {
3309pub fn memfd_create(name: []const u8, flags: u32) !fd_t {
33133310 const name_t = try toMemFdPath(name);
33143311 return try memfd_createC(&name_t, flags);
33153312}
lib/std/os/linux.zig+1-1
......@@ -1110,7 +1110,7 @@ pub fn io_uring_register(fd: i32, opcode: u32, arg: ?*const c_void, nr_args: u32
11101110 return syscall4(SYS_io_uring_register, @bitCast(usize, @as(isize, fd)), opcode, @ptrToInt(arg), nr_args);
11111111}
11121112
1113pub fn memfd_create(name: [*:0]const u8, flags: usize) usize {
1113pub fn memfd_create(name: [*:0]const u8, flags: u32) usize {
11141114 return syscall2(SYS_memfd_create, @ptrToInt(name), flags);
11151115}
11161116