2018-07-09 16:54:36 +08:00
|
|
|
const freebsd = @import("index.zig");
|
2017-10-20 14:16:56 +08:00
|
|
|
const socklen_t = freebsd.socklen_t;
|
|
|
|
const iovec = freebsd.iovec;
|
|
|
|
|
|
|
|
pub const SYS_sbrk = 69;
|
|
|
|
|
2018-07-09 16:54:36 +08:00
|
|
|
pub fn syscall0(number: usize) usize {
|
|
|
|
return asm volatile ("syscall"
|
2017-10-20 14:16:56 +08:00
|
|
|
: [ret] "={rax}" (-> usize)
|
|
|
|
: [number] "{rax}" (number)
|
2018-07-09 16:54:36 +08:00
|
|
|
: "rcx", "r11"
|
|
|
|
);
|
2017-10-20 14:16:56 +08:00
|
|
|
}
|
|
|
|
|
2018-07-09 16:54:36 +08:00
|
|
|
pub fn syscall1(number: usize, arg1: usize) usize {
|
|
|
|
return asm volatile ("syscall"
|
2017-10-20 14:16:56 +08:00
|
|
|
: [ret] "={rax}" (-> usize)
|
|
|
|
: [number] "{rax}" (number),
|
2018-07-09 16:54:36 +08:00
|
|
|
[arg1] "{rdi}" (arg1)
|
|
|
|
: "rcx", "r11"
|
|
|
|
);
|
2017-10-20 14:16:56 +08:00
|
|
|
}
|
|
|
|
|
2018-07-09 16:54:36 +08:00
|
|
|
pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize {
|
|
|
|
return asm volatile ("syscall"
|
2017-10-20 14:16:56 +08:00
|
|
|
: [ret] "={rax}" (-> usize)
|
|
|
|
: [number] "{rax}" (number),
|
2018-07-09 16:54:36 +08:00
|
|
|
[arg1] "{rdi}" (arg1),
|
|
|
|
[arg2] "{rsi}" (arg2)
|
|
|
|
: "rcx", "r11"
|
|
|
|
);
|
2017-10-20 14:16:56 +08:00
|
|
|
}
|
|
|
|
|
2018-07-09 16:54:36 +08:00
|
|
|
pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
|
|
|
|
return asm volatile ("syscall"
|
2017-10-20 14:16:56 +08:00
|
|
|
: [ret] "={rax}" (-> usize)
|
|
|
|
: [number] "{rax}" (number),
|
2018-07-09 16:54:36 +08:00
|
|
|
[arg1] "{rdi}" (arg1),
|
|
|
|
[arg2] "{rsi}" (arg2),
|
|
|
|
[arg3] "{rdx}" (arg3)
|
|
|
|
: "rcx", "r11"
|
|
|
|
);
|
2017-10-20 14:16:56 +08:00
|
|
|
}
|
|
|
|
|
2018-07-09 16:54:36 +08:00
|
|
|
pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize {
|
|
|
|
return asm volatile ("syscall"
|
2017-10-20 14:16:56 +08:00
|
|
|
: [ret] "={rax}" (-> usize)
|
|
|
|
: [number] "{rax}" (number),
|
2018-07-09 16:54:36 +08:00
|
|
|
[arg1] "{rdi}" (arg1),
|
|
|
|
[arg2] "{rsi}" (arg2),
|
|
|
|
[arg3] "{rdx}" (arg3),
|
|
|
|
[arg4] "{r10}" (arg4)
|
|
|
|
: "rcx", "r11"
|
|
|
|
);
|
2017-10-20 14:16:56 +08:00
|
|
|
}
|
|
|
|
|
2018-07-09 16:54:36 +08:00
|
|
|
pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize {
|
|
|
|
return asm volatile ("syscall"
|
2017-10-20 14:16:56 +08:00
|
|
|
: [ret] "={rax}" (-> usize)
|
|
|
|
: [number] "{rax}" (number),
|
2018-07-09 16:54:36 +08:00
|
|
|
[arg1] "{rdi}" (arg1),
|
|
|
|
[arg2] "{rsi}" (arg2),
|
|
|
|
[arg3] "{rdx}" (arg3),
|
|
|
|
[arg4] "{r10}" (arg4),
|
|
|
|
[arg5] "{r8}" (arg5)
|
|
|
|
: "rcx", "r11"
|
|
|
|
);
|
2017-10-20 14:16:56 +08:00
|
|
|
}
|
|
|
|
|
2018-07-09 16:54:36 +08:00
|
|
|
pub fn syscall6(
|
|
|
|
number: usize,
|
|
|
|
arg1: usize,
|
|
|
|
arg2: usize,
|
|
|
|
arg3: usize,
|
|
|
|
arg4: usize,
|
|
|
|
arg5: usize,
|
|
|
|
arg6: usize,
|
|
|
|
) usize {
|
|
|
|
return asm volatile ("syscall"
|
2017-10-20 14:16:56 +08:00
|
|
|
: [ret] "={rax}" (-> usize)
|
|
|
|
: [number] "{rax}" (number),
|
2018-07-09 16:54:36 +08:00
|
|
|
[arg1] "{rdi}" (arg1),
|
|
|
|
[arg2] "{rsi}" (arg2),
|
|
|
|
[arg3] "{rdx}" (arg3),
|
|
|
|
[arg4] "{r10}" (arg4),
|
|
|
|
[arg5] "{r8}" (arg5),
|
|
|
|
[arg6] "{r9}" (arg6)
|
|
|
|
: "rcx", "r11"
|
|
|
|
);
|
2017-10-20 14:16:56 +08:00
|
|
|
}
|
|
|
|
|
2018-07-09 16:54:36 +08:00
|
|
|
pub nakedcc fn restore_rt() void {
|
2017-10-20 14:16:56 +08:00
|
|
|
asm volatile ("syscall"
|
|
|
|
:
|
|
|
|
: [number] "{rax}" (usize(SYS_rt_sigreturn))
|
2018-07-09 16:54:36 +08:00
|
|
|
: "rcx", "r11"
|
|
|
|
);
|
2017-10-20 14:16:56 +08:00
|
|
|
}
|
|
|
|
|
2018-11-20 06:28:18 +08:00
|
|
|
pub const msghdr = extern struct {
|
2018-12-13 09:19:46 +08:00
|
|
|
msg_name: *u8,
|
2017-10-20 14:16:56 +08:00
|
|
|
msg_namelen: socklen_t,
|
2018-12-13 09:19:46 +08:00
|
|
|
msg_iov: *iovec,
|
2017-10-20 14:16:56 +08:00
|
|
|
msg_iovlen: i32,
|
|
|
|
__pad1: i32,
|
2018-12-13 09:19:46 +08:00
|
|
|
msg_control: *u8,
|
2017-10-20 14:16:56 +08:00
|
|
|
msg_controllen: socklen_t,
|
|
|
|
__pad2: socklen_t,
|
|
|
|
msg_flags: i32,
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Renamed to Stat to not conflict with the stat function.
|
2018-11-20 06:28:18 +08:00
|
|
|
pub const Stat = extern struct {
|
2017-10-20 14:16:56 +08:00
|
|
|
dev: u64,
|
|
|
|
ino: u64,
|
|
|
|
nlink: usize,
|
|
|
|
|
|
|
|
mode: u32,
|
|
|
|
uid: u32,
|
|
|
|
gid: u32,
|
|
|
|
__pad0: u32,
|
|
|
|
rdev: u64,
|
|
|
|
size: i64,
|
|
|
|
blksize: isize,
|
|
|
|
blocks: i64,
|
|
|
|
|
|
|
|
atim: timespec,
|
|
|
|
mtim: timespec,
|
|
|
|
ctim: timespec,
|
|
|
|
__unused: [3]isize,
|
|
|
|
};
|
|
|
|
|
2018-11-20 06:28:18 +08:00
|
|
|
pub const timespec = extern struct {
|
2017-10-20 14:16:56 +08:00
|
|
|
tv_sec: isize,
|
|
|
|
tv_nsec: isize,
|
|
|
|
};
|