os: use system for memfd_create

- os: update flags type for memfd_create
This commit is contained in:
Luna 2019-12-31 15:33:23 -03:00 committed by Andrew Kelley
parent 997812e8fb
commit f0cbf63e1a
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
2 changed files with 5 additions and 8 deletions

View File

@ -3282,12 +3282,9 @@ pub fn setsockopt(fd: fd_t, level: u32, optname: u32, opt: []const u8) SetSockOp
}
}
// TODO support for non-null terminated strings?
pub fn memfd_createC(name: [*:0]const u8, flags: usize) !fd_t {
if (builtin.os != .linux) @compileError("memfd_create() not implemented for this target");
const rc = linux.memfd_create(name, flags);
switch (linux.getErrno(rc)) {
pub fn memfd_createC(name: [*:0]const u8, flags: u32) !fd_t {
const rc = system.memfd_create(name, flags);
switch (errno(rc)) {
0 => return @intCast(fd_t, rc),
EFAULT => unreachable, // name has invalid memory
EINVAL => unreachable, // name/flags are faulty
@ -3309,7 +3306,7 @@ fn toMemFdPath(name: []const u8) ![MFD_MAX_NAME_LEN:0]u8 {
return path_with_null;
}
pub fn memfd_create(name: []const u8, flags: usize) !fd_t {
pub fn memfd_create(name: []const u8, flags: u32) !fd_t {
const name_t = try toMemFdPath(name);
return try memfd_createC(&name_t, flags);
}

View File

@ -1110,7 +1110,7 @@ pub fn io_uring_register(fd: i32, opcode: u32, arg: ?*const c_void, nr_args: u32
return syscall4(SYS_io_uring_register, @bitCast(usize, @as(isize, fd)), opcode, @ptrToInt(arg), nr_args);
}
pub fn memfd_create(name: [*:0]const u8, flags: usize) usize {
pub fn memfd_create(name: [*:0]const u8, flags: u32) usize {
return syscall2(SYS_memfd_create, @ptrToInt(name), flags);
}