mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 14:23:09 +00:00
The main purpose of this branch is to explore avoiding the `usingnamespace` feature of the zig language, specifically with regards to `std.os` and related functionality. If this experiment is successful, it will provide a data point on whether or not it would be practical to entirely remove `usingnamespace` from the language. In this commit, `usingnamespace` has been completely eliminated from the Linux x86_64 compilation path, aside from io_uring. The behavior tests pass, however that's as far as this branch goes. It is very breaking, and a lot more work is needed before it could be considered mergeable. I wanted to put a pull requset up early so that zig programmers have time to provide feedback. This is progress towards closing #6600 since it clarifies where the actual "owner" of each declaration is, and reduces the number of different ways to import the same declarations. One of the main organizational strategies used here is to do namespacing with real namespaces (e.g. structs) rather than by having declarations share a common prefix (the C strategy). It's no coincidence that `usingnamespace` has similar semantics to `#include` and becomes much less necessary when using proper namespaces.
179 lines
4.8 KiB
Zig
179 lines
4.8 KiB
Zig
pub fn syscall_pipe(fd: *[2]i32) usize {
|
|
return asm volatile (
|
|
\\ mov %[arg], %%g3
|
|
\\ t 0x6d
|
|
\\ bcc,pt %%xcc, 1f
|
|
\\ nop
|
|
\\ # Return the error code
|
|
\\ ba 2f
|
|
\\ neg %%o0
|
|
\\1:
|
|
\\ st %%o0, [%%g3+0]
|
|
\\ st %%o1, [%%g3+4]
|
|
\\ clr %%o0
|
|
\\2:
|
|
: [ret] "={o0}" (-> usize),
|
|
: [number] "{g1}" (@enumToInt(SYS.pipe)),
|
|
[arg] "r" (fd),
|
|
: "memory", "g3"
|
|
);
|
|
}
|
|
|
|
pub fn syscall_fork() usize {
|
|
// Linux/sparc64 fork() returns two values in %o0 and %o1:
|
|
// - On the parent's side, %o0 is the child's PID and %o1 is 0.
|
|
// - On the child's side, %o0 is the parent's PID and %o1 is 1.
|
|
// We need to clear the child's %o0 so that the return values
|
|
// conform to the libc convention.
|
|
return asm volatile (
|
|
\\ t 0x6d
|
|
\\ bcc,pt %%xcc, 1f
|
|
\\ nop
|
|
\\ ba 2f
|
|
\\ neg %%o0
|
|
\\ 1:
|
|
\\ # Clear the child's %%o0
|
|
\\ dec %%o1
|
|
\\ and %%o1, %%o0, %%o0
|
|
\\ 2:
|
|
: [ret] "={o0}" (-> usize),
|
|
: [number] "{g1}" (@enumToInt(SYS.fork)),
|
|
: "memory", "xcc", "o1", "o2", "o3", "o4", "o5", "o7"
|
|
);
|
|
}
|
|
|
|
pub fn syscall0(number: SYS) usize {
|
|
return asm volatile (
|
|
\\ t 0x6d
|
|
\\ bcc,pt %%xcc, 1f
|
|
\\ nop
|
|
\\ neg %%o0
|
|
\\ 1:
|
|
: [ret] "={o0}" (-> usize),
|
|
: [number] "{g1}" (@enumToInt(number)),
|
|
: "memory", "xcc", "o1", "o2", "o3", "o4", "o5", "o7"
|
|
);
|
|
}
|
|
|
|
pub fn syscall1(number: SYS, arg1: usize) usize {
|
|
return asm volatile (
|
|
\\ t 0x6d
|
|
\\ bcc,pt %%xcc, 1f
|
|
\\ nop
|
|
\\ neg %%o0
|
|
\\ 1:
|
|
: [ret] "={o0}" (-> usize),
|
|
: [number] "{g1}" (@enumToInt(number)),
|
|
[arg1] "{o0}" (arg1),
|
|
: "memory", "xcc", "o1", "o2", "o3", "o4", "o5", "o7"
|
|
);
|
|
}
|
|
|
|
pub fn syscall2(number: SYS, arg1: usize, arg2: usize) usize {
|
|
return asm volatile (
|
|
\\ t 0x6d
|
|
\\ bcc,pt %%xcc, 1f
|
|
\\ nop
|
|
\\ neg %%o0
|
|
\\ 1:
|
|
: [ret] "={o0}" (-> usize),
|
|
: [number] "{g1}" (@enumToInt(number)),
|
|
[arg1] "{o0}" (arg1),
|
|
[arg2] "{o1}" (arg2),
|
|
: "memory", "xcc", "o1", "o2", "o3", "o4", "o5", "o7"
|
|
);
|
|
}
|
|
|
|
pub fn syscall3(number: SYS, arg1: usize, arg2: usize, arg3: usize) usize {
|
|
return asm volatile (
|
|
\\ t 0x6d
|
|
\\ bcc,pt %%xcc, 1f
|
|
\\ nop
|
|
\\ neg %%o0
|
|
\\ 1:
|
|
: [ret] "={o0}" (-> usize),
|
|
: [number] "{g1}" (@enumToInt(number)),
|
|
[arg1] "{o0}" (arg1),
|
|
[arg2] "{o1}" (arg2),
|
|
[arg3] "{o2}" (arg3),
|
|
: "memory", "xcc", "o1", "o2", "o3", "o4", "o5", "o7"
|
|
);
|
|
}
|
|
|
|
pub fn syscall4(number: SYS, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize {
|
|
return asm volatile (
|
|
\\ t 0x6d
|
|
\\ bcc,pt %%xcc, 1f
|
|
\\ nop
|
|
\\ neg %%o0
|
|
\\ 1:
|
|
: [ret] "={o0}" (-> usize),
|
|
: [number] "{g1}" (@enumToInt(number)),
|
|
[arg1] "{o0}" (arg1),
|
|
[arg2] "{o1}" (arg2),
|
|
[arg3] "{o2}" (arg3),
|
|
[arg4] "{o3}" (arg4),
|
|
: "memory", "xcc", "o1", "o2", "o3", "o4", "o5", "o7"
|
|
);
|
|
}
|
|
|
|
pub fn syscall5(number: SYS, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize {
|
|
return asm volatile (
|
|
\\ t 0x6d
|
|
\\ bcc,pt %%xcc, 1f
|
|
\\ nop
|
|
\\ neg %%o0
|
|
\\ 1:
|
|
: [ret] "={o0}" (-> usize),
|
|
: [number] "{g1}" (@enumToInt(number)),
|
|
[arg1] "{o0}" (arg1),
|
|
[arg2] "{o1}" (arg2),
|
|
[arg3] "{o2}" (arg3),
|
|
[arg4] "{o3}" (arg4),
|
|
[arg5] "{o4}" (arg5),
|
|
: "memory", "xcc", "o1", "o2", "o3", "o4", "o5", "o7"
|
|
);
|
|
}
|
|
|
|
pub fn syscall6(
|
|
number: SYS,
|
|
arg1: usize,
|
|
arg2: usize,
|
|
arg3: usize,
|
|
arg4: usize,
|
|
arg5: usize,
|
|
arg6: usize,
|
|
) usize {
|
|
return asm volatile (
|
|
\\ t 0x6d
|
|
\\ bcc,pt %%xcc, 1f
|
|
\\ nop
|
|
\\ neg %%o0
|
|
\\ 1:
|
|
: [ret] "={o0}" (-> usize),
|
|
: [number] "{g1}" (@enumToInt(number)),
|
|
[arg1] "{o0}" (arg1),
|
|
[arg2] "{o1}" (arg2),
|
|
[arg3] "{o2}" (arg3),
|
|
[arg4] "{o3}" (arg4),
|
|
[arg5] "{o4}" (arg5),
|
|
[arg6] "{o5}" (arg6),
|
|
: "memory", "xcc", "o1", "o2", "o3", "o4", "o5", "o7"
|
|
);
|
|
}
|
|
|
|
/// This matches the libc clone function.
|
|
pub extern fn clone(func: fn (arg: usize) callconv(.C) u8, stack: usize, flags: usize, arg: usize, ptid: *i32, tls: usize, ctid: *i32) usize;
|
|
|
|
pub const restore = restore_rt;
|
|
|
|
// Need to use C ABI here instead of naked
|
|
// to prevent an infinite loop when calling rt_sigreturn.
|
|
pub fn restore_rt() callconv(.C) void {
|
|
return asm volatile ("t 0x6d"
|
|
:
|
|
: [number] "{g1}" (@enumToInt(SYS.rt_sigreturn)),
|
|
: "memory", "xcc", "o0", "o1", "o2", "o3", "o4", "o5", "o7"
|
|
);
|
|
}
|