authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-05-30 15:48:22-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2019-05-30 15:48:22-04:00
log0ccd91faea5ec27a1dce9d3bae84e1feca7fc0ea
tree6aa7ef4a698b9ed7d634e88cf4e1a3a29dfdc082
parent78f32259daa79aaced1c49bcdace936121a2ccc5
parent51fc375b0d17f50bb6e0a542e9eebfff1534c581
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #2593 from LemonBoy/aarch64-stuff

Fix some syscalls on arm64

6 files changed, 41 insertions(+), 33 deletions(-)

std/c/linux.zig+1-1
...@@ -7,7 +7,7 @@ pub const _errno = __errno_location;...@@ -7,7 +7,7 @@ pub const _errno = __errno_location;
7pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) c_int;7pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) c_int;
8pub extern "c" fn sched_getaffinity(pid: c_int, size: usize, set: *cpu_set_t) c_int;8pub extern "c" fn sched_getaffinity(pid: c_int, size: usize, set: *cpu_set_t) c_int;
9pub extern "c" fn eventfd(initval: c_uint, flags: c_uint) c_int;9pub 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;
11pub extern "c" fn epoll_create1(flags: c_uint) c_int;11pub extern "c" fn epoll_create1(flags: c_uint) c_int;
12pub extern "c" fn epoll_wait(epfd: fd_t, events: [*]epoll_event, maxevents: c_uint, timeout: c_int) c_int;12pub extern "c" fn epoll_wait(epfd: fd_t, events: [*]epoll_event, maxevents: c_uint, timeout: c_int) c_int;
13pub extern "c" fn epoll_pwait(13pub extern "c" fn epoll_pwait(
std/event/loop.zig+1-1
...@@ -421,7 +421,7 @@ pub const Loop = struct {...@@ -421,7 +421,7 @@ pub const Loop = struct {
421 }421 }
422422
423 pub fn linuxRemoveFd(self: *Loop, fd: i32) void {423 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 {};
425 self.finishOneEvent();425 self.finishOneEvent();
426 }426 }
427427
std/os.zig+1-1
...@@ -1509,7 +1509,7 @@ pub const EpollCtlError = error{...@@ -1509,7 +1509,7 @@ pub const EpollCtlError = error{
1509 Unexpected,1509 Unexpected,
1510};1510};
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 {
1513 const rc = system.epoll_ctl(epfd, op, fd, event);1513 const rc = system.epoll_ctl(epfd, op, fd, event);
1514 switch (errno(rc)) {1514 switch (errno(rc)) {
1515 0 => return,1515 0 => return,
std/os/bits/linux.zig+6-6
...@@ -762,16 +762,16 @@ pub const epoll_data = extern union {...@@ -762,16 +762,16 @@ pub const epoll_data = extern union {
762762
763// On x86_64 the structure is packed so that it matches the definition of its763// On x86_64 the structure is packed so that it matches the definition of its
764// 32bit counterpart764// 32bit counterpart
765pub const epoll_event = if (builtin.arch != .x86_64)765pub const epoll_event = switch (builtin.arch) {
766 extern struct {766 .x86_64 => packed struct {
767 events: u32,767 events: u32,
768 data: epoll_data,768 data: epoll_data,
769 }769 },
770else770 else => extern struct {
771 packed struct {
772 events: u32,771 events: u32,
773 data: epoll_data,772 data: epoll_data,
774 };773 },
774};
775775
776pub const _LINUX_CAPABILITY_VERSION_1 = 0x19980330;776pub const _LINUX_CAPABILITY_VERSION_1 = 0x19980330;
777pub const _LINUX_CAPABILITY_U32S_1 = 1;777pub const _LINUX_CAPABILITY_U32S_1 = 1;
std/os/bits/linux/arm64.zig+5-5
...@@ -299,16 +299,16 @@ pub const O_NONBLOCK = 0o4000;...@@ -299,16 +299,16 @@ pub const O_NONBLOCK = 0o4000;
299pub const O_DSYNC = 0o10000;299pub const O_DSYNC = 0o10000;
300pub const O_SYNC = 0o4010000;300pub const O_SYNC = 0o4010000;
301pub const O_RSYNC = 0o4010000;301pub const O_RSYNC = 0o4010000;
302pub const O_DIRECTORY = 0o200000;302pub const O_DIRECTORY = 0o40000;
303pub const O_NOFOLLOW = 0o400000;303pub const O_NOFOLLOW = 0o100000;
304pub const O_CLOEXEC = 0o2000000;304pub const O_CLOEXEC = 0o2000000;
305305
306pub const O_ASYNC = 0o20000;306pub const O_ASYNC = 0o20000;
307pub const O_DIRECT = 0o40000;307pub const O_DIRECT = 0o200000;
308pub const O_LARGEFILE = 0;308pub const O_LARGEFILE = 0o400000;
309pub const O_NOATIME = 0o1000000;309pub const O_NOATIME = 0o1000000;
310pub const O_PATH = 0o10000000;310pub const O_PATH = 0o10000000;
311pub const O_TMPFILE = 0o20200000;311pub const O_TMPFILE = 0o20040000;
312pub const O_NDELAY = O_NONBLOCK;312pub const O_NDELAY = O_NONBLOCK;
313313
314pub const F_DUPFD = 0;314pub const F_DUPFD = 0;
std/os/linux.zig+27-19
...@@ -131,7 +131,7 @@ pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usiz...@@ -131,7 +131,7 @@ pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usiz
131 if (@hasDecl(@This(), "SYS_readlink")) {131 if (@hasDecl(@This(), "SYS_readlink")) {
132 return syscall3(SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);132 return syscall3(SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
133 } else {133 } 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);
135 }135 }
136}136}
137137
...@@ -145,7 +145,7 @@ pub fn mkdir(path: [*]const u8, mode: u32) usize {...@@ -145,7 +145,7 @@ pub fn mkdir(path: [*]const u8, mode: u32) usize {
145 if (@hasDecl(@This(), "SYS_mkdir")) {145 if (@hasDecl(@This(), "SYS_mkdir")) {
146 return syscall2(SYS_mkdir, @ptrToInt(path), mode);146 return syscall2(SYS_mkdir, @ptrToInt(path), mode);
147 } else {147 } else {
148 return syscall3(SYS_mkdirat, AT_FDCWD, @ptrToInt(path), mode);148 return syscall3(SYS_mkdirat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), mode);
149 }149 }
150}150}
151151
...@@ -206,7 +206,7 @@ pub fn rmdir(path: [*]const u8) usize {...@@ -206,7 +206,7 @@ pub fn rmdir(path: [*]const u8) usize {
206 if (@hasDecl(@This(), "SYS_rmdir")) {206 if (@hasDecl(@This(), "SYS_rmdir")) {
207 return syscall1(SYS_rmdir, @ptrToInt(path));207 return syscall1(SYS_rmdir, @ptrToInt(path));
208 } else {208 } 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);
210 }210 }
211}211}
212212
...@@ -215,7 +215,7 @@ pub fn symlink(existing: [*]const u8, new: [*]const u8) usize {...@@ -215,7 +215,7 @@ pub fn symlink(existing: [*]const u8, new: [*]const u8) usize {
215 if (@hasDecl(@This(), "SYS_symlink")) {215 if (@hasDecl(@This(), "SYS_symlink")) {
216 return syscall2(SYS_symlink, @ptrToInt(existing), @ptrToInt(new));216 return syscall2(SYS_symlink, @ptrToInt(existing), @ptrToInt(new));
217 } else {217 } 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));
219 }219 }
220}220}
221221
...@@ -231,12 +231,16 @@ pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize {...@@ -231,12 +231,16 @@ pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize {
231231
232// TODO https://github.com/ziglang/zig/issues/265232// TODO https://github.com/ziglang/zig/issues/265
233pub fn access(path: [*]const u8, mode: u32) usize {233pub 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 }
235}239}
236240
237// TODO https://github.com/ziglang/zig/issues/265241// TODO https://github.com/ziglang/zig/issues/265
238pub fn faccessat(dirfd: i32, path: [*]const u8, mode: u32) usize {242pub fn faccessat(dirfd: i32, path: [*]const u8, mode: u32, flags: u32) usize {
239 return syscall3(SYS_faccessat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), mode);243 return syscall4(SYS_faccessat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), mode, flags);
240}244}
241245
242pub fn pipe(fd: *[2]i32) usize {246pub fn pipe(fd: *[2]i32) usize {
...@@ -264,9 +268,9 @@ pub fn rename(old: [*]const u8, new: [*]const u8) usize {...@@ -264,9 +268,9 @@ pub fn rename(old: [*]const u8, new: [*]const u8) usize {
264 if (@hasDecl(@This(), "SYS_rename")) {268 if (@hasDecl(@This(), "SYS_rename")) {
265 return syscall2(SYS_rename, @ptrToInt(old), @ptrToInt(new));269 return syscall2(SYS_rename, @ptrToInt(old), @ptrToInt(new));
266 } else if (@hasDecl(@This(), "SYS_renameat")) {270 } 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));
268 } else {272 } 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);
270 }274 }
271}275}
272276
...@@ -305,7 +309,17 @@ pub fn renameat2(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const...@@ -305,7 +309,17 @@ pub fn renameat2(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const
305309
306// TODO https://github.com/ziglang/zig/issues/265310// TODO https://github.com/ziglang/zig/issues/265
307pub fn open(path: [*]const u8, flags: u32, perm: usize) usize {311pub 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 }
309}323}
310324
311// TODO https://github.com/ziglang/zig/issues/265325// TODO https://github.com/ziglang/zig/issues/265
...@@ -373,7 +387,7 @@ pub fn unlink(path: [*]const u8) usize {...@@ -373,7 +387,7 @@ pub fn unlink(path: [*]const u8) usize {
373 if (@hasDecl(@This(), "SYS_unlink")) {387 if (@hasDecl(@This(), "SYS_unlink")) {
374 return syscall1(SYS_unlink, @ptrToInt(path));388 return syscall1(SYS_unlink, @ptrToInt(path));
375 } else {389 } else {
376 return syscall3(SYS_unlinkat, AT_FDCWD, @ptrToInt(path), 0);390 return syscall3(SYS_unlinkat, @bitCast(usize, isize(AT_FDCWD)), @ptrToInt(path), 0);
377 }391 }
378}392}
379393
...@@ -759,18 +773,12 @@ pub fn epoll_create1(flags: usize) usize {...@@ -759,18 +773,12 @@ pub fn epoll_create1(flags: usize) usize {
759 return syscall1(SYS_epoll_create1, flags);773 return syscall1(SYS_epoll_create1, flags);
760}774}
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 {
763 return syscall4(SYS_epoll_ctl, @bitCast(usize, isize(epoll_fd)), @intCast(usize, op), @bitCast(usize, isize(fd)), @ptrToInt(ev));777 return syscall4(SYS_epoll_ctl, @bitCast(usize, isize(epoll_fd)), @intCast(usize, op), @bitCast(usize, isize(fd)), @ptrToInt(ev));
764}778}
765779
766pub fn epoll_wait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32) usize {780pub fn epoll_wait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32) usize {
767 return syscall4(781 return epoll_pwait(epoll_fd, events, maxevents, timeout, null);
768 SYS_epoll_wait,
769 @bitCast(usize, isize(epoll_fd)),
770 @ptrToInt(events),
771 maxevents,
772 @bitCast(usize, isize(timeout)),
773 );
774}782}
775783
776pub fn epoll_pwait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32, sigmask: ?*sigset_t) usize {784pub fn epoll_pwait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32, sigmask: ?*sigset_t) usize {