Skip to content

Commit b980283

Browse files
committed
fix: use std syscall3 function
1 parent fa00464 commit b980283

File tree

1 file changed

+3
-38
lines changed

1 file changed

+3
-38
lines changed

src/macos.zig

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,11 @@ const system = std.posix.system;
55

66
const arch = builtin.cpu.arch;
77

8-
const syscall3 =
9-
if (arch.isX86()) X86_64syscall3 else if (arch.isArm()) Armsyscall3 else if (arch.isAARCH64()) Aarch64syscall3 else @compileError("Not supported arch");
10-
118
const fd_t = posix.fd_t;
129

13-
const ioctl_syscall = 0x36 + 0x2000000;
10+
const ioctl_syscall = 0x2000036;
1411

1512
pub fn ioctl(fd: fd_t, request: u32, arg: usize) usize {
16-
return syscall3(ioctl_syscall, @as(usize, @bitCast(@as(isize, fd))), request, arg);
17-
}
18-
19-
pub fn X86_64syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
20-
return asm volatile ("syscall"
21-
: [ret] "={rax}" (-> usize),
22-
: [number] "{rax}" (number),
23-
[arg1] "{rdi}" (arg1),
24-
[arg2] "{rsi}" (arg2),
25-
[arg3] "{rdx}" (arg3),
26-
: "rcx", "r11", "memory"
27-
);
28-
}
29-
30-
pub fn Armsyscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
31-
return asm volatile ("svc #0"
32-
: [ret] "={r0}" (-> usize),
33-
: [number] "{r7}" (number),
34-
[arg1] "{r0}" (arg1),
35-
[arg2] "{r1}" (arg2),
36-
[arg3] "{r2}" (arg3),
37-
: "memory"
38-
);
39-
}
40-
41-
pub fn Aarch64syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
42-
return asm volatile ("svc #0"
43-
: [ret] "={x0}" (-> usize),
44-
: [number] "{x8}" (number),
45-
[arg1] "{x0}" (arg1),
46-
[arg2] "{x1}" (arg2),
47-
[arg3] "{x2}" (arg3),
48-
: "memory", "cc"
49-
);
13+
@setRuntimeSafety(false);
14+
return std.os.linux.syscall3(@enumFromInt(ioctl_syscall), @as(usize, @bitCast(@as(isize, fd))), request, arg);
5015
}

0 commit comments

Comments
 (0)