authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-05-30 16:28:33+02:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-05-30 16:28:33+02:00
log477ee9c8b992612c952dfd13c4f951d4e04adb22
tree06986a265f7ed25f1dbd14b473612d88e0764053
parent8ca294c430ecc4e878d9e5cfb178c20c07b83514

Fix some syscalls on arm64


5 files changed, 36 insertions(+), 28 deletions(-)

std/c/linux.zig+1-1
......@@ -7,7 +7,7 @@ pub const _errno = __errno_location;
77pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) c_int;
88pub extern "c" fn sched_getaffinity(pid: c_int, size: usize, set: *cpu_set_t) c_int;
99pub extern "c" fn eventfd(initval: c_uint, flags: c_uint) c_int;
10pub extern "c" fn epoll_ctl(epfd: fd_t, op: c_uint, fd: fd_t, event: *epoll_event) c_int;
10pub extern "c" fn epoll_ctl(epfd: fd_t, op: c_uint, fd: fd_t, event: ?*epoll_event) c_int;
1111pub extern "c" fn epoll_create1(flags: c_uint) c_int;
1212pub extern "c" fn epoll_wait(epfd: fd_t, events: [*]epoll_event, maxevents: c_uint, timeout: c_int) c_int;
1313pub extern "c" fn epoll_pwait(
std/event/loop.zig+1-1
......@@ -421,7 +421,7 @@ pub const Loop = struct {
421421 }
422422
423423 pub fn linuxRemoveFd(self: *Loop, fd: i32) void {
424 os.epoll_ctl(self.os_data.epollfd, os.linux.EPOLL_CTL_DEL, fd, undefined) catch {};
424 os.epoll_ctl(self.os_data.epollfd, os.linux.EPOLL_CTL_DEL, fd, null) catch {};
425425 self.finishOneEvent();
426426 }
427427
std/os.zig+1-1
......@@ -1509,7 +1509,7 @@ pub const EpollCtlError = error{
15091509 Unexpected,
15101510};
15111511
1512pub fn epoll_ctl(epfd: i32, op: u32, fd: i32, event: *epoll_event) EpollCtlError!void {
1512pub fn epoll_ctl(epfd: i32, op: u32, fd: i32, event: ?*epoll_event) EpollCtlError!void {
15131513 const rc = system.epoll_ctl(epfd, op, fd, event);
15141514 switch (errno(rc)) {
15151515 0 => return,
std/os/bits/linux.zig+6-6
......@@ -762,16 +762,16 @@ pub const epoll_data = extern union {
762762
763763// On x86_64 the structure is packed so that it matches the definition of its
764764// 32bit counterpart
765pub const epoll_event = if (builtin.arch != .x86_64)
766 extern struct {
765pub const epoll_event = switch (builtin.arch) {
766 .x86_64 => packed struct {
767767 events: u32,
768768 data: epoll_data,
769 }
770else
771 packed struct {
769 },
770 else => extern struct {
772771 events: u32,
773772 data: epoll_data,
774 };
773 },
774};
775775
776776pub const _LINUX_CAPABILITY_VERSION_1 = 0x19980330;
777777pub const _LINUX_CAPABILITY_U32S_1 = 1;
std/os/linux.zig+27-19
......@@ -131,7 +131,7 @@ pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usiz
131131 if (@hasDecl(@This(), "SYS_readlink")) {
132132 return syscall3(SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
133133 } else {
134 return syscall4(SYS_readlinkat, AT_FDCWD, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
134 return syscall4(SYS_readlinkat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
135135 }
136136}
137137
......@@ -145,7 +145,7 @@ pub fn mkdir(path: [*]const u8, mode: u32) usize {
145145 if (@hasDecl(@This(), "SYS_mkdir")) {
146146 return syscall2(SYS_mkdir, @ptrToInt(path), mode);
147147 } else {
148 return syscall3(SYS_mkdirat, AT_FDCWD, @ptrToInt(path), mode);
148 return syscall3(SYS_mkdirat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), mode);
149149 }
150150}
151151
......@@ -206,7 +206,7 @@ pub fn rmdir(path: [*]const u8) usize {
206206 if (@hasDecl(@This(), "SYS_rmdir")) {
207207 return syscall1(SYS_rmdir, @ptrToInt(path));
208208 } else {
209 return syscall3(SYS_unlinkat, AT_FDCWD, @ptrToInt(path), AT_REMOVEDIR);
209 return syscall3(SYS_unlinkat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), AT_REMOVEDIR);
210210 }
211211}
212212
......@@ -215,7 +215,7 @@ pub fn symlink(existing: [*]const u8, new: [*]const u8) usize {
215215 if (@hasDecl(@This(), "SYS_symlink")) {
216216 return syscall2(SYS_symlink, @ptrToInt(existing), @ptrToInt(new));
217217 } else {
218 return syscall3(SYS_symlinkat, @ptrToInt(existing), AT_FDCWD, @ptrToInt(new));
218 return syscall3(SYS_symlinkat, @ptrToInt(existing), @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(new));
219219 }
220220}
221221
......@@ -231,12 +231,16 @@ pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize {
231231
232232// TODO https://github.com/ziglang/zig/issues/265
233233pub fn access(path: [*]const u8, mode: u32) usize {
234 return syscall2(SYS_access, @ptrToInt(path), mode);
234 if (@hasDecl(@This(), "SYS_access")) {
235 return syscall2(SYS_access, @ptrToInt(path), mode);
236 } else {
237 return syscall4(SYS_faccessat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), mode, 0);
238 }
235239}
236240
237241// TODO https://github.com/ziglang/zig/issues/265
238pub fn faccessat(dirfd: i32, path: [*]const u8, mode: u32) usize {
239 return syscall3(SYS_faccessat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), mode);
242pub fn faccessat(dirfd: i32, path: [*]const u8, mode: u32, flags: u32) usize {
243 return syscall4(SYS_faccessat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), mode, flags);
240244}
241245
242246pub fn pipe(fd: *[2]i32) usize {
......@@ -264,9 +268,9 @@ pub fn rename(old: [*]const u8, new: [*]const u8) usize {
264268 if (@hasDecl(@This(), "SYS_rename")) {
265269 return syscall2(SYS_rename, @ptrToInt(old), @ptrToInt(new));
266270 } else if (@hasDecl(@This(), "SYS_renameat")) {
267 return syscall4(SYS_renameat, AT_FDCWD, @ptrToInt(old), AT_FDCWD, @ptrToInt(new));
271 return syscall4(SYS_renameat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(old), @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(new));
268272 } else {
269 return syscall5(SYS_renameat2, AT_FDCWD, @ptrToInt(old), AT_FDCWD, @ptrToInt(new), 0);
273 return syscall5(SYS_renameat2, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(old), @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(new), 0);
270274 }
271275}
272276
......@@ -305,7 +309,17 @@ pub fn renameat2(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const
305309
306310// TODO https://github.com/ziglang/zig/issues/265
307311pub fn open(path: [*]const u8, flags: u32, perm: usize) usize {
308 return syscall3(SYS_open, @ptrToInt(path), flags, perm);
312 if (@hasDecl(@This(), "SYS_open")) {
313 return syscall3(SYS_open, @ptrToInt(path), flags, perm);
314 } else {
315 return syscall4(
316 SYS_openat,
317 @bitCast(usize, isize(AT_FDCWD)),
318 @ptrToInt(path),
319 flags,
320 perm,
321 );
322 }
309323}
310324
311325// TODO https://github.com/ziglang/zig/issues/265
......@@ -373,7 +387,7 @@ pub fn unlink(path: [*]const u8) usize {
373387 if (@hasDecl(@This(), "SYS_unlink")) {
374388 return syscall1(SYS_unlink, @ptrToInt(path));
375389 } else {
376 return syscall3(SYS_unlinkat, AT_FDCWD, @ptrToInt(path), 0);
390 return syscall3(SYS_unlinkat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), 0);
377391 }
378392}
379393
......@@ -759,18 +773,12 @@ pub fn epoll_create1(flags: usize) usize {
759773 return syscall1(SYS_epoll_create1, flags);
760774}
761775
762pub fn epoll_ctl(epoll_fd: i32, op: u32, fd: i32, ev: *epoll_event) usize {
776pub fn epoll_ctl(epoll_fd: i32, op: u32, fd: i32, ev: ?*epoll_event) usize {
763777 return syscall4(SYS_epoll_ctl, @bitCast(usize, isize(epoll_fd)), @intCast(usize, op), @bitCast(usize, isize(fd)), @ptrToInt(ev));
764778}
765779
766780pub fn epoll_wait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32) usize {
767 return syscall4(
768 SYS_epoll_wait,
769 @bitCast(usize, isize(epoll_fd)),
770 @ptrToInt(events),
771 maxevents,
772 @bitCast(usize, isize(timeout)),
773 );
781 return epoll_pwait(epoll_fd, events, maxevents, timeout, null);
774782}
775783
776784pub fn epoll_pwait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32, sigmask: ?*sigset_t) usize {