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...@@ -3282,12 +3282,9 @@ pub fn setsockopt(fd: fd_t, level: u32, optname: u32, opt: []const u8) SetSockOp
3282 }3282 }
3283}3283}
32843284
3285// TODO support for non-null terminated strings?3285pub fn memfd_createC(name: [*:0]const u8, flags: u32) !fd_t {
3286pub fn memfd_createC(name: [*:0]const u8, flags: usize) !fd_t {3286 const rc = system.memfd_create(name, flags);
3287 if (builtin.os != .linux) @compileError("memfd_create() not implemented for this target");3287 switch (errno(rc)) {
3288
3289 const rc = linux.memfd_create(name, flags);
3290 switch (linux.getErrno(rc)) {
3291 0 => return @intCast(fd_t, rc),3288 0 => return @intCast(fd_t, rc),
3292 EFAULT => unreachable, // name has invalid memory3289 EFAULT => unreachable, // name has invalid memory
3293 EINVAL => unreachable, // name/flags are faulty3290 EINVAL => unreachable, // name/flags are faulty
...@@ -3309,7 +3306,7 @@ fn toMemFdPath(name: []const u8) ![MFD_MAX_NAME_LEN:0]u8 {...@@ -3309,7 +3306,7 @@ fn toMemFdPath(name: []const u8) ![MFD_MAX_NAME_LEN:0]u8 {
3309 return path_with_null;3306 return path_with_null;
3310}3307}
33113308
3312pub fn memfd_create(name: []const u8, flags: usize) !fd_t {3309pub fn memfd_create(name: []const u8, flags: u32) !fd_t {
3313 const name_t = try toMemFdPath(name);3310 const name_t = try toMemFdPath(name);
3314 return try memfd_createC(&name_t, flags);3311 return try memfd_createC(&name_t, flags);
3315}3312}
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...@@ -1110,7 +1110,7 @@ pub fn io_uring_register(fd: i32, opcode: u32, arg: ?*const c_void, nr_args: u32
1110 return syscall4(SYS_io_uring_register, @bitCast(usize, @as(isize, fd)), opcode, @ptrToInt(arg), nr_args);1110 return syscall4(SYS_io_uring_register, @bitCast(usize, @as(isize, fd)), opcode, @ptrToInt(arg), nr_args);
1111}1111}
11121112
1113pub fn memfd_create(name: [*:0]const u8, flags: usize) usize {1113pub fn memfd_create(name: [*:0]const u8, flags: u32) usize {
1114 return syscall2(SYS_memfd_create, @ptrToInt(name), flags);1114 return syscall2(SYS_memfd_create, @ptrToInt(name), flags);
1115}1115}
11161116