authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-03-26 06:39:28-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-03-26 06:39:28-04:00
log5bc9feb5cb98fc13db62d01b2b9fec15677310a7
tree12972dfc1f9b964bb74428ec0d6766e77b9b0be7
parent7ce753a16b0c16b4c6494467f42f2d5fe9a235e6

organize std and make import relative to current file

closes #216

44 files changed, 2625 insertions(+), 2630 deletions(-)

CMakeLists.txt+14-14
......@@ -201,41 +201,41 @@ install(TARGETS zig DESTINATION bin)
201201
202202install(FILES ${C_HEADERS} DESTINATION ${C_HEADERS_DEST})
203203
204install(FILES "${CMAKE_SOURCE_DIR}/std/bootstrap.zig" DESTINATION "${ZIG_STD_DEST}")
205install(FILES "${CMAKE_SOURCE_DIR}/std/build.zig" DESTINATION "${ZIG_STD_DEST}")
206install(FILES "${CMAKE_SOURCE_DIR}/std/builtin.zig" DESTINATION "${ZIG_STD_DEST}")
207204install(FILES "${CMAKE_SOURCE_DIR}/std/c/darwin.zig" DESTINATION "${ZIG_STD_DEST}/c")
208205install(FILES "${CMAKE_SOURCE_DIR}/std/c/index.zig" DESTINATION "${ZIG_STD_DEST}/c")
209206install(FILES "${CMAKE_SOURCE_DIR}/std/c/linux.zig" DESTINATION "${ZIG_STD_DEST}/c")
210207install(FILES "${CMAKE_SOURCE_DIR}/std/c/windows.zig" DESTINATION "${ZIG_STD_DEST}/c")
211install(FILES "${CMAKE_SOURCE_DIR}/std/compiler_rt.zig" DESTINATION "${ZIG_STD_DEST}")
212208install(FILES "${CMAKE_SOURCE_DIR}/std/cstr.zig" DESTINATION "${ZIG_STD_DEST}")
213install(FILES "${CMAKE_SOURCE_DIR}/std/darwin.zig" DESTINATION "${ZIG_STD_DEST}")
214install(FILES "${CMAKE_SOURCE_DIR}/std/darwin_x86_64.zig" DESTINATION "${ZIG_STD_DEST}")
215209install(FILES "${CMAKE_SOURCE_DIR}/std/debug.zig" DESTINATION "${ZIG_STD_DEST}")
216210install(FILES "${CMAKE_SOURCE_DIR}/std/dwarf.zig" DESTINATION "${ZIG_STD_DEST}")
217211install(FILES "${CMAKE_SOURCE_DIR}/std/elf.zig" DESTINATION "${ZIG_STD_DEST}")
218212install(FILES "${CMAKE_SOURCE_DIR}/std/empty.zig" DESTINATION "${ZIG_STD_DEST}")
219213install(FILES "${CMAKE_SOURCE_DIR}/std/endian.zig" DESTINATION "${ZIG_STD_DEST}")
220install(FILES "${CMAKE_SOURCE_DIR}/std/errno.zig" DESTINATION "${ZIG_STD_DEST}")
221214install(FILES "${CMAKE_SOURCE_DIR}/std/fmt.zig" DESTINATION "${ZIG_STD_DEST}")
222215install(FILES "${CMAKE_SOURCE_DIR}/std/hash_map.zig" DESTINATION "${ZIG_STD_DEST}")
223216install(FILES "${CMAKE_SOURCE_DIR}/std/index.zig" DESTINATION "${ZIG_STD_DEST}")
224217install(FILES "${CMAKE_SOURCE_DIR}/std/io.zig" DESTINATION "${ZIG_STD_DEST}")
225install(FILES "${CMAKE_SOURCE_DIR}/std/linux.zig" DESTINATION "${ZIG_STD_DEST}")
226install(FILES "${CMAKE_SOURCE_DIR}/std/linux_i386.zig" DESTINATION "${ZIG_STD_DEST}")
227install(FILES "${CMAKE_SOURCE_DIR}/std/linux_x86_64.zig" DESTINATION "${ZIG_STD_DEST}")
228218install(FILES "${CMAKE_SOURCE_DIR}/std/list.zig" DESTINATION "${ZIG_STD_DEST}")
229219install(FILES "${CMAKE_SOURCE_DIR}/std/math.zig" DESTINATION "${ZIG_STD_DEST}")
230220install(FILES "${CMAKE_SOURCE_DIR}/std/mem.zig" DESTINATION "${ZIG_STD_DEST}")
231221install(FILES "${CMAKE_SOURCE_DIR}/std/net.zig" DESTINATION "${ZIG_STD_DEST}")
232install(FILES "${CMAKE_SOURCE_DIR}/std/os.zig" DESTINATION "${ZIG_STD_DEST}")
233install(FILES "${CMAKE_SOURCE_DIR}/std/panic.zig" DESTINATION "${ZIG_STD_DEST}")
222install(FILES "${CMAKE_SOURCE_DIR}/std/os/darwin.zig" DESTINATION "${ZIG_STD_DEST}/os")
223install(FILES "${CMAKE_SOURCE_DIR}/std/os/darwin_x86_64.zig" DESTINATION "${ZIG_STD_DEST}/os")
224install(FILES "${CMAKE_SOURCE_DIR}/std/os/errno.zig" DESTINATION "${ZIG_STD_DEST}/os")
225install(FILES "${CMAKE_SOURCE_DIR}/std/os/index.zig" DESTINATION "${ZIG_STD_DEST}/os")
226install(FILES "${CMAKE_SOURCE_DIR}/std/os/linux.zig" DESTINATION "${ZIG_STD_DEST}/os")
227install(FILES "${CMAKE_SOURCE_DIR}/std/os/linux_i386.zig" DESTINATION "${ZIG_STD_DEST}/os")
228install(FILES "${CMAKE_SOURCE_DIR}/std/os/linux_x86_64.zig" DESTINATION "${ZIG_STD_DEST}/os")
229install(FILES "${CMAKE_SOURCE_DIR}/std/os/windows.zig" DESTINATION "${ZIG_STD_DEST}/os")
234230install(FILES "${CMAKE_SOURCE_DIR}/std/rand.zig" DESTINATION "${ZIG_STD_DEST}")
235231install(FILES "${CMAKE_SOURCE_DIR}/std/rand_test.zig" DESTINATION "${ZIG_STD_DEST}")
236232install(FILES "${CMAKE_SOURCE_DIR}/std/sort.zig" DESTINATION "${ZIG_STD_DEST}")
237install(FILES "${CMAKE_SOURCE_DIR}/std/test_runner.zig" DESTINATION "${ZIG_STD_DEST}")
238install(FILES "${CMAKE_SOURCE_DIR}/std/windows.zig" DESTINATION "${ZIG_STD_DEST}")
233install(FILES "${CMAKE_SOURCE_DIR}/std/special/bootstrap.zig" DESTINATION "${ZIG_STD_DEST}/special")
234install(FILES "${CMAKE_SOURCE_DIR}/std/special/builtin.zig" DESTINATION "${ZIG_STD_DEST}/special")
235install(FILES "${CMAKE_SOURCE_DIR}/std/special/compiler_rt.zig" DESTINATION "${ZIG_STD_DEST}/special")
236install(FILES "${CMAKE_SOURCE_DIR}/std/special/panic.zig" DESTINATION "${ZIG_STD_DEST}/special")
237install(FILES "${CMAKE_SOURCE_DIR}/std/special/test_runner.zig" DESTINATION "${ZIG_STD_DEST}/special")
238install(FILES "${CMAKE_SOURCE_DIR}/std/target.zig" DESTINATION "${ZIG_STD_DEST}")
239239
240240add_executable(run_tests ${TEST_SOURCES})
241241target_link_libraries(run_tests)
src/all_types.hpp+1
......@@ -1362,6 +1362,7 @@ struct CodeGen {
13621362 Buf *libc_static_lib_dir;
13631363 Buf *libc_include_dir;
13641364 Buf *zig_std_dir;
1365 Buf *zig_std_special_dir;
13651366 Buf *dynamic_linker;
13661367 Buf *ar_path;
13671368 Buf triple_str;
src/analyze.cpp+3-6
......@@ -2874,11 +2874,8 @@ void preview_use_decl(CodeGen *g, AstNode *node) {
28742874ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package,
28752875 Buf *abs_full_path, Buf *src_dirname, Buf *src_basename, Buf *source_code)
28762876{
2877 Buf *full_path = buf_alloc();
2878 os_path_join(src_dirname, src_basename, full_path);
2879
28802877 if (g->verbose) {
2881 fprintf(stderr, "\nOriginal Source (%s):\n", buf_ptr(full_path));
2878 fprintf(stderr, "\nOriginal Source (%s):\n", buf_ptr(abs_full_path));
28822879 fprintf(stderr, "----------------\n");
28832880 fprintf(stderr, "%s\n", buf_ptr(source_code));
28842881
......@@ -2890,7 +2887,7 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package,
28902887 tokenize(source_code, &tokenization);
28912888
28922889 if (tokenization.err) {
2893 ErrorMsg *err = err_msg_create_with_line(full_path, tokenization.err_line, tokenization.err_column,
2890 ErrorMsg *err = err_msg_create_with_line(abs_full_path, tokenization.err_line, tokenization.err_column,
28942891 source_code, tokenization.line_offsets, tokenization.err);
28952892
28962893 print_err_msg(err, g->err_color);
......@@ -2908,7 +2905,7 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package,
29082905 import_entry->package = package;
29092906 import_entry->source_code = source_code;
29102907 import_entry->line_offsets = tokenization.line_offsets;
2911 import_entry->path = full_path;
2908 import_entry->path = abs_full_path;
29122909
29132910 import_entry->root = ast_parse(source_code, tokenization.tokens, import_entry, g->err_color,
29142911 &g->next_node_index);
src/codegen.cpp+7-5
......@@ -80,6 +80,9 @@ CodeGen *codegen_create(Buf *root_source_dir, const ZigTarget *target) {
8080 g->root_package->package_table.put(buf_create_from_str("std"), g->std_package);
8181 g->zig_std_dir = buf_create_from_str(ZIG_STD_DIR);
8282
83 g->zig_std_special_dir = buf_alloc();
84 os_path_join(g->zig_std_dir, buf_sprintf("special"), g->zig_std_special_dir);
85
8386
8487 if (target) {
8588 // cross compiling, so we can't rely on all the configured stuff since
......@@ -4237,10 +4240,9 @@ void codegen_parseh(CodeGen *g, Buf *src_dirname, Buf *src_basename, Buf *source
42374240}
42384241
42394242static ImportTableEntry *add_special_code(CodeGen *g, PackageTableEntry *package, const char *basename) {
4240 Buf *std_dir = g->zig_std_dir;
42414243 Buf *code_basename = buf_create_from_str(basename);
42424244 Buf path_to_code_src = BUF_INIT;
4243 os_path_join(std_dir, code_basename, &path_to_code_src);
4245 os_path_join(g->zig_std_special_dir, code_basename, &path_to_code_src);
42444246 Buf *abs_full_path = buf_alloc();
42454247 int err;
42464248 if ((err = os_path_real(&path_to_code_src, abs_full_path))) {
......@@ -4251,18 +4253,18 @@ static ImportTableEntry *add_special_code(CodeGen *g, PackageTableEntry *package
42514253 zig_panic("unable to open '%s': %s", buf_ptr(&path_to_code_src), err_str(err));
42524254 }
42534255
4254 return add_source_file(g, package, abs_full_path, std_dir, code_basename, import_code);
4256 return add_source_file(g, package, abs_full_path, g->zig_std_special_dir, code_basename, import_code);
42554257}
42564258
42574259static PackageTableEntry *create_bootstrap_pkg(CodeGen *g) {
4258 PackageTableEntry *package = new_package(buf_ptr(g->zig_std_dir), "");
4260 PackageTableEntry *package = new_package(buf_ptr(g->zig_std_special_dir), "");
42594261 package->package_table.put(buf_create_from_str("std"), g->std_package);
42604262 package->package_table.put(buf_create_from_str("@root"), g->root_package);
42614263 return package;
42624264}
42634265
42644266static PackageTableEntry *create_panic_pkg(CodeGen *g) {
4265 PackageTableEntry *package = new_package(buf_ptr(g->zig_std_dir), "");
4267 PackageTableEntry *package = new_package(buf_ptr(g->zig_std_special_dir), "");
42664268 package->package_table.put(buf_create_from_str("std"), g->std_package);
42674269 return package;
42684270}
src/ir.cpp+4-1
......@@ -10385,7 +10385,10 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi
1038510385 // try it as a filename
1038610386 target_package = import->package;
1038710387 import_target_path = import_target_str;
10388 search_dir = &import->package->root_src_dir;
10388
10389 // search relative to importing file
10390 search_dir = buf_alloc();
10391 os_path_dirname(import->path, search_dir);
1038910392 }
1039010393
1039110394 Buf full_path = BUF_INIT;
src/link.cpp+4-4
......@@ -42,10 +42,9 @@ static const char *get_o_file_extension(CodeGen *g) {
4242
4343static Buf *build_o(CodeGen *parent_gen, const char *oname) {
4444 Buf *source_basename = buf_sprintf("%s.zig", oname);
45 Buf *std_dir_path = parent_gen->zig_std_dir;
4645
4746 ZigTarget *child_target = parent_gen->is_native_target ? nullptr : &parent_gen->zig_target;
48 CodeGen *child_gen = codegen_create(std_dir_path, child_target);
47 CodeGen *child_gen = codegen_create(parent_gen->zig_std_special_dir, child_target);
4948 child_gen->link_libc = parent_gen->link_libc;
5049
5150 child_gen->link_libs.resize(parent_gen->link_libs.length);
......@@ -70,13 +69,14 @@ static Buf *build_o(CodeGen *parent_gen, const char *oname) {
7069 codegen_set_mios_version_min(child_gen, parent_gen->mios_version_min);
7170
7271 Buf *full_path = buf_alloc();
73 os_path_join(std_dir_path, source_basename, full_path);
72 os_path_join(parent_gen->zig_std_special_dir, source_basename, full_path);
73
7474 Buf source_code = BUF_INIT;
7575 if (os_fetch_file_path(full_path, &source_code)) {
7676 zig_panic("unable to fetch file: %s\n", buf_ptr(full_path));
7777 }
7878
79 codegen_add_root_code(child_gen, std_dir_path, source_basename, &source_code);
79 codegen_add_root_code(child_gen, parent_gen->zig_std_special_dir, source_basename, &source_code);
8080 const char *o_ext = get_o_file_extension(child_gen);
8181 Buf *o_out = buf_sprintf("%s%s", oname, o_ext);
8282 codegen_link(child_gen, buf_ptr(o_out));
std/bootstrap.zig deleted-63
......@@ -1,63 +0,0 @@
1// This file is in a package which has the root source file exposed as "@root".
2// It is included in the compilation unit when exporting an executable.
3
4const root = @import("@root");
5const std = @import("std");
6
7const want_main_symbol = std.build.linking_libc;
8const want_start_symbol = !want_main_symbol;
9
10const exit = switch(@compileVar("os")) {
11 Os.linux => std.linux.exit,
12 Os.darwin => std.darwin.exit,
13 else => @compileError("Unsupported OS"),
14};
15
16var argc: usize = undefined;
17var argv: &&u8 = undefined;
18
19export nakedcc fn _start() -> noreturn {
20 @setFnVisible(this, want_start_symbol);
21 if (!want_start_symbol) {
22 unreachable;
23 }
24
25 switch (@compileVar("arch")) {
26 Arch.x86_64 => {
27 argc = asm("mov %[argc], [rsp]": [argc] "=r" (-> usize));
28 argv = asm("lea %[argv], [rsp + 8h]": [argv] "=r" (-> &&u8));
29 },
30 Arch.i386 => {
31 argc = asm("mov %[argc], [esp]": [argc] "=r" (-> usize));
32 argv = asm("lea %[argv], [esp + 4h]": [argv] "=r" (-> &&u8));
33 },
34 else => @compileError("unsupported arch"),
35 }
36 callMainAndExit()
37}
38
39fn callMain() -> %void {
40 const args = @alloca([]u8, argc);
41 for (args) |_, i| {
42 const ptr = argv[i];
43 args[i] = ptr[0...std.cstr.len(ptr)];
44 }
45 return root.main(args);
46}
47
48fn callMainAndExit() -> noreturn {
49 callMain() %% exit(1);
50 exit(0);
51}
52
53export fn main(c_argc: i32, c_argv: &&u8) -> i32 {
54 @setFnVisible(this, want_main_symbol);
55 if (!want_main_symbol) {
56 unreachable;
57 }
58
59 argc = usize(c_argc);
60 argv = c_argv;
61 callMain() %% return 1;
62 return 0;
63}
std/build.zig deleted-15
......@@ -1,15 +0,0 @@
1const mem = @import("mem.zig");
2
3pub const linking_libc = linkingLibrary("c");
4
5pub fn linkingLibrary(lib_name: []const u8) -> bool {
6 // TODO shouldn't need this if
7 if (@compileVar("link_libs").len != 0) {
8 for (@compileVar("link_libs")) |link_lib| {
9 if (mem.eql(u8, link_lib, lib_name)) {
10 return true;
11 }
12 }
13 }
14 return false;
15}
std/builtin.zig deleted-36
......@@ -1,36 +0,0 @@
1// These functions are provided when not linking against libc because LLVM
2// sometimes generates code that calls them.
3
4// Note that these functions do not return `dest`, like the libc API.
5// The semantics of these functions is dictated by the corresponding
6// LLVM intrinsics, not by the libc API.
7
8export fn memset(dest: ?&u8, c: u8, n: usize) {
9 @setDebugSafety(this, false);
10
11 if (n == 0)
12 return;
13
14 const d = ??dest;
15 var index: usize = 0;
16 while (index != n; index += 1)
17 d[index] = c;
18}
19
20export fn memcpy(noalias dest: ?&u8, noalias src: ?&const u8, n: usize) {
21 @setDebugSafety(this, false);
22
23 if (n == 0)
24 return;
25
26 const d = ??dest;
27 const s = ??src;
28 var index: usize = 0;
29 while (index != n; index += 1)
30 d[index] = s[index];
31}
32
33// Avoid dragging in the debug safety mechanisms into this .o file.
34pub fn panic(message: []const u8) -> noreturn {
35 unreachable;
36}
std/c/index.zig+5-5
......@@ -1,13 +1,13 @@
1pub use @import("errno.zig");
1pub use @import("../os/errno.zig");
22
33pub use switch(@compileVar("os")) {
4 Os.linux => @import("c/linux.zig"),
5 Os.windows => @import("c/windows.zig"),
6 Os.darwin, Os.macosx, Os.ios => @import("c/darwin.zig"),
4 Os.linux => @import("linux.zig"),
5 Os.windows => @import("windows.zig"),
6 Os.darwin, Os.macosx, Os.ios => @import("darwin.zig"),
77 else => empty_import,
88};
99
1010pub extern fn abort() -> noreturn;
1111
1212
13const empty_import = @import("empty.zig");
13const empty_import = @import("../empty.zig");
std/compiler_rt.zig deleted-515
......@@ -1,515 +0,0 @@
1// Avoid dragging in the debug safety mechanisms into this .o file,
2// unless we're trying to test this file.
3pub fn panic(message: []const u8) -> noreturn {
4 if (@compileVar("is_test")) {
5 @import("std").debug.panic(message);
6 } else {
7 unreachable;
8 }
9}
10
11const CHAR_BIT = 8;
12const du_int = u64;
13const di_int = i64;
14const si_int = c_int;
15const su_int = c_uint;
16
17const udwords = [2]su_int;
18const low = if (@compileVar("is_big_endian")) 1 else 0;
19const high = 1 - low;
20
21export fn __udivdi3(a: du_int, b: du_int) -> du_int {
22 @setDebugSafety(this, false);
23 return __udivmoddi4(a, b, null);
24}
25
26fn du_int_to_udwords(x: du_int) -> udwords {
27 @setDebugSafety(this, false);
28 return *(&udwords)(&x);
29}
30
31export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int {
32 @setDebugSafety(this, false);
33
34 const n_uword_bits = @sizeOf(su_int) * CHAR_BIT;
35 const n_udword_bits = @sizeOf(du_int) * CHAR_BIT;
36 var n = du_int_to_udwords(a);
37 var d = du_int_to_udwords(b);
38 var q: udwords = undefined;
39 var r: udwords = undefined;
40 var sr: c_uint = undefined;
41 // special cases, X is unknown, K != 0
42 if (n[high] == 0) {
43 if (d[high] == 0) {
44 // 0 X
45 // ---
46 // 0 X
47 if (const rem ?= maybe_rem) {
48 *rem = n[low] % d[low];
49 }
50 return n[low] / d[low];
51 }
52 // 0 X
53 // ---
54 // K X
55 if (const rem ?= maybe_rem) {
56 *rem = n[low];
57 }
58 return 0;
59 }
60 // n[high] != 0
61 if (d[low] == 0) {
62 if (d[high] == 0) {
63 // K X
64 // ---
65 // 0 0
66 if (var rem ?= maybe_rem) {
67 *rem = n[high] % d[low];
68 }
69 return n[high] / d[low];
70 }
71 // d[high] != 0
72 if (n[low] == 0) {
73 // K 0
74 // ---
75 // K 0
76 if (var rem ?= maybe_rem) {
77 r[high] = n[high] % d[high];
78 r[low] = 0;
79 *rem = *(&du_int)(&r[0]);
80 }
81 return n[high] / d[high];
82 }
83 // K K
84 // ---
85 // K 0
86 // if d is a power of 2
87 if ((d[high] & (d[high] - 1)) == 0) {
88 if (var rem ?= maybe_rem) {
89 r[low] = n[low];
90 r[high] = n[high] & (d[high] - 1);
91 *rem = *(&du_int)(&r[0]);
92 }
93 return n[high] >> @ctz(d[high]);
94 }
95 // K K
96 // ---
97 // K 0
98 sr = @clz(su_int(d[high])) - @clz(su_int(n[high]));
99 // 0 <= sr <= n_uword_bits - 2 or sr large
100 if (sr > n_uword_bits - 2) {
101 if (var rem ?= maybe_rem) {
102 *rem = *(&du_int)(&n[0]);
103 }
104 return 0;
105 }
106 sr += 1;
107 // 1 <= sr <= n_uword_bits - 1
108 // q.all = n.all << (n_udword_bits - sr);
109 q[low] = 0;
110 q[high] = n[low] << (n_uword_bits - sr);
111 // r.all = n.all >> sr;
112 r[high] = n[high] >> sr;
113 r[low] = (n[high] << (n_uword_bits - sr)) | (n[low] >> sr);
114 } else {
115 // d[low] != 0
116 if (d[high] == 0) {
117 // K X
118 // ---
119 // 0 K
120 // if d is a power of 2
121 if ((d[low] & (d[low] - 1)) == 0) {
122 if (var rem ?= maybe_rem) {
123 *rem = n[low] & (d[low] - 1);
124 }
125 if (d[low] == 1) {
126 return *(&du_int)(&n[0]);
127 }
128 sr = @ctz(d[low]);
129 q[high] = n[high] >> sr;
130 q[low] = (n[high] << (n_uword_bits - sr)) | (n[low] >> sr);
131 return *(&du_int)(&q[0]);
132 }
133 // K X
134 // ---
135 // 0 K
136 sr = 1 + n_uword_bits + @clz(su_int(d[low])) - @clz(su_int(n[high]));
137 // 2 <= sr <= n_udword_bits - 1
138 // q.all = n.all << (n_udword_bits - sr);
139 // r.all = n.all >> sr;
140 if (sr == n_uword_bits) {
141 q[low] = 0;
142 q[high] = n[low];
143 r[high] = 0;
144 r[low] = n[high];
145 } else if (sr < n_uword_bits) {
146 // 2 <= sr <= n_uword_bits - 1
147 q[low] = 0;
148 q[high] = n[low] << (n_uword_bits - sr);
149 r[high] = n[high] >> sr;
150 r[low] = (n[high] << (n_uword_bits - sr)) | (n[low] >> sr);
151 } else {
152 // n_uword_bits + 1 <= sr <= n_udword_bits - 1
153 q[low] = n[low] << (n_udword_bits - sr);
154 q[high] = (n[high] << (n_udword_bits - sr)) |
155 (n[low] >> (sr - n_uword_bits));
156 r[high] = 0;
157 r[low] = n[high] >> (sr - n_uword_bits);
158 }
159 } else {
160 // K X
161 // ---
162 // K K
163 sr = @clz(su_int(d[high])) - @clz(su_int(n[high]));
164 // 0 <= sr <= n_uword_bits - 1 or sr large
165 if (sr > n_uword_bits - 1) {
166 if (var rem ?= maybe_rem) {
167 *rem = *(&du_int)(&n[0]);
168 }
169 return 0;
170 }
171 sr += 1;
172 // 1 <= sr <= n_uword_bits
173 // q.all = n.all << (n_udword_bits - sr);
174 q[low] = 0;
175 if (sr == n_uword_bits) {
176 q[high] = n[low];
177 r[high] = 0;
178 r[low] = n[high];
179 } else {
180 q[high] = n[low] << (n_uword_bits - sr);
181 r[high] = n[high] >> sr;
182 r[low] = (n[high] << (n_uword_bits - sr)) | (n[low] >> sr);
183 }
184 }
185 }
186 // Not a special case
187 // q and r are initialized with:
188 // q.all = n.all << (n_udword_bits - sr);
189 // r.all = n.all >> sr;
190 // 1 <= sr <= n_udword_bits - 1
191 var carry: su_int = 0;
192 while (sr > 0) {
193 // r:q = ((r:q) << 1) | carry
194 r[high] = (r[high] << 1) | (r[low] >> (n_uword_bits - 1));
195 r[low] = (r[low] << 1) | (q[high] >> (n_uword_bits - 1));
196 q[high] = (q[high] << 1) | (q[low] >> (n_uword_bits - 1));
197 q[low] = (q[low] << 1) | carry;
198 // carry = 0;
199 // if (r.all >= d.all)
200 // {
201 // r.all -= d.all;
202 // carry = 1;
203 // }
204 const s: di_int = (di_int)(*(&du_int)(&d[0]) - *(&du_int)(&r[0]) - 1) >> (n_udword_bits - 1);
205 carry = su_int(s & 1);
206 *(&du_int)(&r[0]) -= *(&du_int)(&d[0]) & u64(s);
207
208 sr -= 1;
209 }
210 *(&du_int)(&q[0]) = (*(&du_int)(&q[0]) << 1) | u64(carry);
211 if (var rem ?= maybe_rem) {
212 *rem = *(&du_int)(&r[0]);
213 }
214 return *(&du_int)(&q[0]);
215}
216
217export fn __umoddi3(a: du_int, b: du_int) -> du_int {
218 @setDebugSafety(this, false);
219
220 var r: du_int = undefined;
221 _ = __udivmoddi4(a, b, &r);
222 return r;
223}
224
225fn isArmArch() -> bool {
226 return switch (@compileVar("arch")) {
227 Arch.armv8_2a,
228 Arch.armv8_1a,
229 Arch.armv8,
230 Arch.armv8m_baseline,
231 Arch.armv8m_mainline,
232 Arch.armv7,
233 Arch.armv7em,
234 Arch.armv7m,
235 Arch.armv7s,
236 Arch.armv7k,
237 Arch.armv6,
238 Arch.armv6m,
239 Arch.armv6k,
240 Arch.armv6t2,
241 Arch.armv5,
242 Arch.armv5te,
243 Arch.armv4t,
244 Arch.armeb => true,
245 else => false,
246 };
247}
248
249export nakedcc fn __aeabi_uidivmod() {
250 @setDebugSafety(this, false);
251
252 if (comptime isArmArch()) {
253 asm volatile (
254 \\ push { lr }
255 \\ sub sp, sp, #4
256 \\ mov r2, sp
257 \\ bl __udivmodsi4
258 \\ ldr r1, [sp]
259 \\ add sp, sp, #4
260 \\ pop { pc }
261 ::: "r2", "r1");
262 unreachable;
263 }
264
265 @setFnVisible(this, false);
266}
267
268export fn __udivmodsi4(a: su_int, b: su_int, rem: &su_int) -> su_int {
269 @setDebugSafety(this, false);
270
271 const d = __udivsi3(a, b);
272 *rem = su_int(si_int(a) -% (si_int(d) * si_int(b)));
273 return d;
274}
275
276
277// TODO make this an alias instead of an extra function call
278// https://github.com/andrewrk/zig/issues/256
279
280export fn __aeabi_uidiv(n: su_int, d: su_int) -> su_int {
281 @setDebugSafety(this, false);
282
283 return __udivsi3(n, d);
284}
285
286export fn __udivsi3(n: su_int, d: su_int) -> su_int {
287 @setDebugSafety(this, false);
288
289 const n_uword_bits: c_uint = @sizeOf(su_int) * CHAR_BIT;
290 // special cases
291 if (d == 0)
292 return 0; // ?!
293 if (n == 0)
294 return 0;
295 var sr: c_uint = @clz(d) - @clz(n);
296 // 0 <= sr <= n_uword_bits - 1 or sr large
297 if (sr > n_uword_bits - 1) // d > r
298 return 0;
299 if (sr == n_uword_bits - 1) // d == 1
300 return n;
301 sr += 1;
302 // 1 <= sr <= n_uword_bits - 1
303 // Not a special case
304 var q: su_int = n << (n_uword_bits - sr);
305 var r: su_int = n >> sr;
306 var carry: su_int = 0;
307 while (sr > 0; sr -= 1) {
308 // r:q = ((r:q) << 1) | carry
309 r = (r << 1) | (q >> (n_uword_bits - 1));
310 q = (q << 1) | carry;
311 // carry = 0;
312 // if (r.all >= d.all)
313 // {
314 // r.all -= d.all;
315 // carry = 1;
316 // }
317 const s = si_int(d - r - 1) >> si_int(n_uword_bits - 1);
318 carry = su_int(s & 1);
319 r -= d & su_int(s);
320 }
321 q = (q << 1) | carry;
322 return q;
323}
324
325test "test_umoddi3" {
326 test_one_umoddi3(0, 1, 0);
327 test_one_umoddi3(2, 1, 0);
328 test_one_umoddi3(0x8000000000000000, 1, 0x0);
329 test_one_umoddi3(0x8000000000000000, 2, 0x0);
330 test_one_umoddi3(0xFFFFFFFFFFFFFFFF, 2, 0x1);
331}
332
333fn test_one_umoddi3(a: du_int, b: du_int, expected_r: du_int) {
334 const r = __umoddi3(a, b);
335 assert(r == expected_r);
336}
337
338test "test_udivmoddi4" {
339 const cases = [][4]du_int {
340 []du_int{0x0000000000000000, 0x0000000000000001, 0x0000000000000000, 0x0000000000000000},
341 []du_int{0x0000000080000000, 0x0000000100000001, 0x0000000000000000, 0x0000000080000000},
342 []du_int{0x7FFFFFFF00000001, 0x0000000000000001, 0x7FFFFFFF00000001, 0x0000000000000000},
343 []du_int{0x7FFFFFFF7FFFFFFF, 0xFFFFFFFFFFFFFFFF, 0x0000000000000000, 0x7FFFFFFF7FFFFFFF},
344 []du_int{0x8000000000000002, 0xFFFFFFFFFFFFFFFE, 0x0000000000000000, 0x8000000000000002},
345 []du_int{0x80000000FFFFFFFD, 0xFFFFFFFFFFFFFFFD, 0x0000000000000000, 0x80000000FFFFFFFD},
346 []du_int{0xFFFFFFFD00000010, 0xFFFFFFFF80000000, 0x0000000000000000, 0xFFFFFFFD00000010},
347 []du_int{0xFFFFFFFDFFFFFFFF, 0xFFFFFFFF7FFFFFFF, 0x0000000000000000, 0xFFFFFFFDFFFFFFFF},
348 []du_int{0xFFFFFFFE0747AE14, 0xFFFFFFFF0747AE14, 0x0000000000000000, 0xFFFFFFFE0747AE14},
349 []du_int{0xFFFFFFFF00000001, 0xFFFFFFFF078644FA, 0x0000000000000000, 0xFFFFFFFF00000001},
350 []du_int{0xFFFFFFFF80000000, 0xFFFFFFFF00000010, 0x0000000000000001, 0x000000007FFFFFF0},
351 []du_int{0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0x0000000000000001, 0x0000000000000000},
352 };
353
354 for (cases) |case| {
355 test_one_udivmoddi4(case[0], case[1], case[2], case[3]);
356 }
357}
358
359fn test_one_udivmoddi4(a: du_int, b: du_int, expected_q: du_int, expected_r: du_int) {
360 var r: du_int = undefined;
361 const q = __udivmoddi4(a, b, &r);
362 assert(q == expected_q);
363 assert(r == expected_r);
364}
365
366test "test_udivsi3" {
367 const cases = [][3]su_int {
368 []su_int{0x00000000, 0x00000001, 0x00000000},
369 []su_int{0x00000000, 0x00000002, 0x00000000},
370 []su_int{0x00000000, 0x00000003, 0x00000000},
371 []su_int{0x00000000, 0x00000010, 0x00000000},
372 []su_int{0x00000000, 0x078644FA, 0x00000000},
373 []su_int{0x00000000, 0x0747AE14, 0x00000000},
374 []su_int{0x00000000, 0x7FFFFFFF, 0x00000000},
375 []su_int{0x00000000, 0x80000000, 0x00000000},
376 []su_int{0x00000000, 0xFFFFFFFD, 0x00000000},
377 []su_int{0x00000000, 0xFFFFFFFE, 0x00000000},
378 []su_int{0x00000000, 0xFFFFFFFF, 0x00000000},
379 []su_int{0x00000001, 0x00000001, 0x00000001},
380 []su_int{0x00000001, 0x00000002, 0x00000000},
381 []su_int{0x00000001, 0x00000003, 0x00000000},
382 []su_int{0x00000001, 0x00000010, 0x00000000},
383 []su_int{0x00000001, 0x078644FA, 0x00000000},
384 []su_int{0x00000001, 0x0747AE14, 0x00000000},
385 []su_int{0x00000001, 0x7FFFFFFF, 0x00000000},
386 []su_int{0x00000001, 0x80000000, 0x00000000},
387 []su_int{0x00000001, 0xFFFFFFFD, 0x00000000},
388 []su_int{0x00000001, 0xFFFFFFFE, 0x00000000},
389 []su_int{0x00000001, 0xFFFFFFFF, 0x00000000},
390 []su_int{0x00000002, 0x00000001, 0x00000002},
391 []su_int{0x00000002, 0x00000002, 0x00000001},
392 []su_int{0x00000002, 0x00000003, 0x00000000},
393 []su_int{0x00000002, 0x00000010, 0x00000000},
394 []su_int{0x00000002, 0x078644FA, 0x00000000},
395 []su_int{0x00000002, 0x0747AE14, 0x00000000},
396 []su_int{0x00000002, 0x7FFFFFFF, 0x00000000},
397 []su_int{0x00000002, 0x80000000, 0x00000000},
398 []su_int{0x00000002, 0xFFFFFFFD, 0x00000000},
399 []su_int{0x00000002, 0xFFFFFFFE, 0x00000000},
400 []su_int{0x00000002, 0xFFFFFFFF, 0x00000000},
401 []su_int{0x00000003, 0x00000001, 0x00000003},
402 []su_int{0x00000003, 0x00000002, 0x00000001},
403 []su_int{0x00000003, 0x00000003, 0x00000001},
404 []su_int{0x00000003, 0x00000010, 0x00000000},
405 []su_int{0x00000003, 0x078644FA, 0x00000000},
406 []su_int{0x00000003, 0x0747AE14, 0x00000000},
407 []su_int{0x00000003, 0x7FFFFFFF, 0x00000000},
408 []su_int{0x00000003, 0x80000000, 0x00000000},
409 []su_int{0x00000003, 0xFFFFFFFD, 0x00000000},
410 []su_int{0x00000003, 0xFFFFFFFE, 0x00000000},
411 []su_int{0x00000003, 0xFFFFFFFF, 0x00000000},
412 []su_int{0x00000010, 0x00000001, 0x00000010},
413 []su_int{0x00000010, 0x00000002, 0x00000008},
414 []su_int{0x00000010, 0x00000003, 0x00000005},
415 []su_int{0x00000010, 0x00000010, 0x00000001},
416 []su_int{0x00000010, 0x078644FA, 0x00000000},
417 []su_int{0x00000010, 0x0747AE14, 0x00000000},
418 []su_int{0x00000010, 0x7FFFFFFF, 0x00000000},
419 []su_int{0x00000010, 0x80000000, 0x00000000},
420 []su_int{0x00000010, 0xFFFFFFFD, 0x00000000},
421 []su_int{0x00000010, 0xFFFFFFFE, 0x00000000},
422 []su_int{0x00000010, 0xFFFFFFFF, 0x00000000},
423 []su_int{0x078644FA, 0x00000001, 0x078644FA},
424 []su_int{0x078644FA, 0x00000002, 0x03C3227D},
425 []su_int{0x078644FA, 0x00000003, 0x028216FE},
426 []su_int{0x078644FA, 0x00000010, 0x0078644F},
427 []su_int{0x078644FA, 0x078644FA, 0x00000001},
428 []su_int{0x078644FA, 0x0747AE14, 0x00000001},
429 []su_int{0x078644FA, 0x7FFFFFFF, 0x00000000},
430 []su_int{0x078644FA, 0x80000000, 0x00000000},
431 []su_int{0x078644FA, 0xFFFFFFFD, 0x00000000},
432 []su_int{0x078644FA, 0xFFFFFFFE, 0x00000000},
433 []su_int{0x078644FA, 0xFFFFFFFF, 0x00000000},
434 []su_int{0x0747AE14, 0x00000001, 0x0747AE14},
435 []su_int{0x0747AE14, 0x00000002, 0x03A3D70A},
436 []su_int{0x0747AE14, 0x00000003, 0x026D3A06},
437 []su_int{0x0747AE14, 0x00000010, 0x00747AE1},
438 []su_int{0x0747AE14, 0x078644FA, 0x00000000},
439 []su_int{0x0747AE14, 0x0747AE14, 0x00000001},
440 []su_int{0x0747AE14, 0x7FFFFFFF, 0x00000000},
441 []su_int{0x0747AE14, 0x80000000, 0x00000000},
442 []su_int{0x0747AE14, 0xFFFFFFFD, 0x00000000},
443 []su_int{0x0747AE14, 0xFFFFFFFE, 0x00000000},
444 []su_int{0x0747AE14, 0xFFFFFFFF, 0x00000000},
445 []su_int{0x7FFFFFFF, 0x00000001, 0x7FFFFFFF},
446 []su_int{0x7FFFFFFF, 0x00000002, 0x3FFFFFFF},
447 []su_int{0x7FFFFFFF, 0x00000003, 0x2AAAAAAA},
448 []su_int{0x7FFFFFFF, 0x00000010, 0x07FFFFFF},
449 []su_int{0x7FFFFFFF, 0x078644FA, 0x00000011},
450 []su_int{0x7FFFFFFF, 0x0747AE14, 0x00000011},
451 []su_int{0x7FFFFFFF, 0x7FFFFFFF, 0x00000001},
452 []su_int{0x7FFFFFFF, 0x80000000, 0x00000000},
453 []su_int{0x7FFFFFFF, 0xFFFFFFFD, 0x00000000},
454 []su_int{0x7FFFFFFF, 0xFFFFFFFE, 0x00000000},
455 []su_int{0x7FFFFFFF, 0xFFFFFFFF, 0x00000000},
456 []su_int{0x80000000, 0x00000001, 0x80000000},
457 []su_int{0x80000000, 0x00000002, 0x40000000},
458 []su_int{0x80000000, 0x00000003, 0x2AAAAAAA},
459 []su_int{0x80000000, 0x00000010, 0x08000000},
460 []su_int{0x80000000, 0x078644FA, 0x00000011},
461 []su_int{0x80000000, 0x0747AE14, 0x00000011},
462 []su_int{0x80000000, 0x7FFFFFFF, 0x00000001},
463 []su_int{0x80000000, 0x80000000, 0x00000001},
464 []su_int{0x80000000, 0xFFFFFFFD, 0x00000000},
465 []su_int{0x80000000, 0xFFFFFFFE, 0x00000000},
466 []su_int{0x80000000, 0xFFFFFFFF, 0x00000000},
467 []su_int{0xFFFFFFFD, 0x00000001, 0xFFFFFFFD},
468 []su_int{0xFFFFFFFD, 0x00000002, 0x7FFFFFFE},
469 []su_int{0xFFFFFFFD, 0x00000003, 0x55555554},
470 []su_int{0xFFFFFFFD, 0x00000010, 0x0FFFFFFF},
471 []su_int{0xFFFFFFFD, 0x078644FA, 0x00000022},
472 []su_int{0xFFFFFFFD, 0x0747AE14, 0x00000023},
473 []su_int{0xFFFFFFFD, 0x7FFFFFFF, 0x00000001},
474 []su_int{0xFFFFFFFD, 0x80000000, 0x00000001},
475 []su_int{0xFFFFFFFD, 0xFFFFFFFD, 0x00000001},
476 []su_int{0xFFFFFFFD, 0xFFFFFFFE, 0x00000000},
477 []su_int{0xFFFFFFFD, 0xFFFFFFFF, 0x00000000},
478 []su_int{0xFFFFFFFE, 0x00000001, 0xFFFFFFFE},
479 []su_int{0xFFFFFFFE, 0x00000002, 0x7FFFFFFF},
480 []su_int{0xFFFFFFFE, 0x00000003, 0x55555554},
481 []su_int{0xFFFFFFFE, 0x00000010, 0x0FFFFFFF},
482 []su_int{0xFFFFFFFE, 0x078644FA, 0x00000022},
483 []su_int{0xFFFFFFFE, 0x0747AE14, 0x00000023},
484 []su_int{0xFFFFFFFE, 0x7FFFFFFF, 0x00000002},
485 []su_int{0xFFFFFFFE, 0x80000000, 0x00000001},
486 []su_int{0xFFFFFFFE, 0xFFFFFFFD, 0x00000001},
487 []su_int{0xFFFFFFFE, 0xFFFFFFFE, 0x00000001},
488 []su_int{0xFFFFFFFE, 0xFFFFFFFF, 0x00000000},
489 []su_int{0xFFFFFFFF, 0x00000001, 0xFFFFFFFF},
490 []su_int{0xFFFFFFFF, 0x00000002, 0x7FFFFFFF},
491 []su_int{0xFFFFFFFF, 0x00000003, 0x55555555},
492 []su_int{0xFFFFFFFF, 0x00000010, 0x0FFFFFFF},
493 []su_int{0xFFFFFFFF, 0x078644FA, 0x00000022},
494 []su_int{0xFFFFFFFF, 0x0747AE14, 0x00000023},
495 []su_int{0xFFFFFFFF, 0x7FFFFFFF, 0x00000002},
496 []su_int{0xFFFFFFFF, 0x80000000, 0x00000001},
497 []su_int{0xFFFFFFFF, 0xFFFFFFFD, 0x00000001},
498 []su_int{0xFFFFFFFF, 0xFFFFFFFE, 0x00000001},
499 []su_int{0xFFFFFFFF, 0xFFFFFFFF, 0x00000001},
500 };
501
502 for (cases) |case| {
503 test_one_udivsi3(case[0], case[1], case[2]);
504 }
505}
506
507fn test_one_udivsi3(a: su_int, b: su_int, expected_q: su_int) {
508 const q: su_int = __udivsi3(a, b);
509 assert(q == expected_q);
510}
511
512
513fn assert(ok: bool) {
514 if (!ok) unreachable;
515}
std/darwin.zig deleted-118
......@@ -1,118 +0,0 @@
1
2const arch = switch (@compileVar("arch")) {
3 Arch.x86_64 => @import("darwin_x86_64.zig"),
4 else => @compileError("unsupported arch"),
5};
6
7const errno = @import("errno.zig");
8
9pub const O_LARGEFILE = 0x0000;
10pub const O_RDONLY = 0x0000;
11
12pub const SEEK_SET = 0x0;
13pub const SEEK_CUR = 0x1;
14pub const SEEK_END = 0x2;
15
16pub const SIGHUP = 1;
17pub const SIGINT = 2;
18pub const SIGQUIT = 3;
19pub const SIGILL = 4;
20pub const SIGTRAP = 5;
21pub const SIGABRT = 6;
22pub const SIGIOT = SIGABRT;
23pub const SIGBUS = 7;
24pub const SIGFPE = 8;
25pub const SIGKILL = 9;
26pub const SIGUSR1 = 10;
27pub const SIGSEGV = 11;
28pub const SIGUSR2 = 12;
29pub const SIGPIPE = 13;
30pub const SIGALRM = 14;
31pub const SIGTERM = 15;
32pub const SIGSTKFLT = 16;
33pub const SIGCHLD = 17;
34pub const SIGCONT = 18;
35pub const SIGSTOP = 19;
36pub const SIGTSTP = 20;
37pub const SIGTTIN = 21;
38pub const SIGTTOU = 22;
39pub const SIGURG = 23;
40pub const SIGXCPU = 24;
41pub const SIGXFSZ = 25;
42pub const SIGVTALRM = 26;
43pub const SIGPROF = 27;
44pub const SIGWINCH = 28;
45pub const SIGIO = 29;
46pub const SIGPOLL = 29;
47pub const SIGPWR = 30;
48pub const SIGSYS = 31;
49pub const SIGUNUSED = SIGSYS;
50
51pub fn exit(status: usize) -> noreturn {
52 _ = arch.syscall1(arch.SYS_exit, status);
53 unreachable
54}
55
56/// Get the errno from a syscall return value, or 0 for no error.
57pub fn getErrno(r: usize) -> usize {
58 const signed_r = *(&isize)(&r);
59 if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0
60}
61
62pub fn write(fd: i32, buf: &const u8, count: usize) -> usize {
63 arch.syscall3(arch.SYS_write, usize(fd), usize(buf), count)
64}
65
66pub fn close(fd: i32) -> usize {
67 arch.syscall1(arch.SYS_close, usize(fd))
68}
69
70pub fn open_c(path: &const u8, flags: usize, perm: usize) -> usize {
71 arch.syscall3(arch.SYS_open, usize(path), flags, perm)
72}
73
74pub fn open(path: []const u8, flags: usize, perm: usize) -> usize {
75 const buf = @alloca(u8, path.len + 1);
76 @memcpy(&buf[0], &path[0], path.len);
77 buf[path.len] = 0;
78 return open_c(buf.ptr, flags, perm);
79}
80
81pub fn read(fd: i32, buf: &u8, count: usize) -> usize {
82 arch.syscall3(arch.SYS_read, usize(fd), usize(buf), count)
83}
84
85pub fn lseek(fd: i32, offset: usize, ref_pos: usize) -> usize {
86 arch.syscall3(arch.SYS_lseek, usize(fd), offset, ref_pos)
87}
88
89pub const stat = arch.stat;
90pub const timespec = arch.timespec;
91
92pub fn fstat(fd: i32, stat_buf: &stat) -> usize {
93 arch.syscall2(arch.SYS_fstat, usize(fd), usize(stat_buf))
94}
95
96error Unexpected;
97
98pub fn getrandom(buf: &u8, count: usize) -> usize {
99 const rr = open_c(c"/dev/urandom", O_LARGEFILE | O_RDONLY, 0);
100
101 if(getErrno(rr) > 0) return rr;
102
103 var fd: i32 = i32(rr);
104 const readRes = read(fd, buf, count);
105 readRes
106}
107
108pub fn raise(sig: i32) -> i32 {
109 // TODO investigate whether we need to block signals before calling kill
110 // like we do in the linux version of raise
111
112 //var set: sigset_t = undefined;
113 //blockAppSignals(&set);
114 const pid = i32(arch.syscall0(arch.SYS_getpid));
115 const ret = i32(arch.syscall2(arch.SYS_kill, usize(pid), usize(sig)));
116 //restoreSignals(&set);
117 return ret;
118}
std/darwin_x86_64.zig deleted-87
......@@ -1,87 +0,0 @@
1
2pub const SYSCALL_CLASS_SHIFT = 24;
3pub const SYSCALL_CLASS_MASK = 0xFF << SYSCALL_CLASS_SHIFT;
4// pub const SYSCALL_NUMBER_MASK = ~SYSCALL_CLASS_MASK; // ~ modifier not supported yet
5
6pub const SYSCALL_CLASS_NONE = 0; // Invalid
7pub const SYSCALL_CLASS_MACH = 1; // Mach
8pub const SYSCALL_CLASS_UNIX = 2; // Unix/BSD
9pub const SYSCALL_CLASS_MDEP = 3; // Machine-dependent
10pub const SYSCALL_CLASS_DIAG = 4; // Diagnostics
11
12// TODO: use the above constants to create the below values
13
14pub const SYS_exit = 0x2000001;
15pub const SYS_read = 0x2000003;
16pub const SYS_write = 0x2000004;
17pub const SYS_open = 0x2000005;
18pub const SYS_close = 0x2000006;
19pub const SYS_kill = 0x2000025;
20pub const SYS_getpid = 0x2000030;
21pub const SYS_fstat = 0x20000BD;
22pub const SYS_lseek = 0x20000C7;
23
24pub inline fn syscall0(number: usize) -> usize {
25 asm volatile ("syscall"
26 : [ret] "={rax}" (-> usize)
27 : [number] "{rax}" (number)
28 : "rcx", "r11")
29}
30
31pub inline fn syscall1(number: usize, arg1: usize) -> usize {
32 asm volatile ("syscall"
33 : [ret] "={rax}" (-> usize)
34 : [number] "{rax}" (number),
35 [arg1] "{rdi}" (arg1)
36 : "rcx", "r11")
37}
38
39pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize {
40 asm volatile ("syscall"
41 : [ret] "={rax}" (-> usize)
42 : [number] "{rax}" (number),
43 [arg1] "{rdi}" (arg1),
44 [arg2] "{rsi}" (arg2)
45 : "rcx", "r11")
46}
47
48pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize {
49 asm volatile ("syscall"
50 : [ret] "={rax}" (-> usize)
51 : [number] "{rax}" (number),
52 [arg1] "{rdi}" (arg1),
53 [arg2] "{rsi}" (arg2),
54 [arg3] "{rdx}" (arg3)
55 : "rcx", "r11")
56}
57
58
59
60
61pub const stat = extern struct {
62 dev: u32,
63 mode: u16,
64 nlink: u16,
65 ino: u64,
66 uid: u32,
67 gid: u32,
68 rdev: u64,
69
70 atim: timespec,
71 mtim: timespec,
72 ctim: timespec,
73
74 size: u64,
75 blocks: u64,
76 blksize: u32,
77 flags: u32,
78 gen: u32,
79 lspare: i32,
80 qspare: [2]u64,
81
82};
83
84pub const timespec = extern struct {
85 tv_sec: isize,
86 tv_nsec: isize,
87};
std/debug.zig+1-1
......@@ -1,6 +1,6 @@
11const mem = @import("mem.zig");
22const io = @import("io.zig");
3const os = @import("os.zig");
3const os = @import("os/index.zig");
44const elf = @import("elf.zig");
55const DW = @import("dwarf.zig");
66const List = @import("list.zig").List;
std/errno.zig deleted-146
......@@ -1,146 +0,0 @@
1pub const EPERM = 1; // Operation not permitted
2pub const ENOENT = 2; // No such file or directory
3pub const ESRCH = 3; // No such process
4pub const EINTR = 4; // Interrupted system call
5pub const EIO = 5; // I/O error
6pub const ENXIO = 6; // No such device or address
7pub const E2BIG = 7; // Arg list too long
8pub const ENOEXEC = 8; // Exec format error
9pub const EBADF = 9; // Bad file number
10pub const ECHILD = 10; // No child processes
11pub const EAGAIN = 11; // Try again
12pub const ENOMEM = 12; // Out of memory
13pub const EACCES = 13; // Permission denied
14pub const EFAULT = 14; // Bad address
15pub const ENOTBLK = 15; // Block device required
16pub const EBUSY = 16; // Device or resource busy
17pub const EEXIST = 17; // File exists
18pub const EXDEV = 18; // Cross-device link
19pub const ENODEV = 19; // No such device
20pub const ENOTDIR = 20; // Not a directory
21pub const EISDIR = 21; // Is a directory
22pub const EINVAL = 22; // Invalid argument
23pub const ENFILE = 23; // File table overflow
24pub const EMFILE = 24; // Too many open files
25pub const ENOTTY = 25; // Not a typewriter
26pub const ETXTBSY = 26; // Text file busy
27pub const EFBIG = 27; // File too large
28pub const ENOSPC = 28; // No space left on device
29pub const ESPIPE = 29; // Illegal seek
30pub const EROFS = 30; // Read-only file system
31pub const EMLINK = 31; // Too many links
32pub const EPIPE = 32; // Broken pipe
33pub const EDOM = 33; // Math argument out of domain of func
34pub const ERANGE = 34; // Math result not representable
35pub const EDEADLK = 35; // Resource deadlock would occur
36pub const ENAMETOOLONG = 36; // File name too long
37pub const ENOLCK = 37; // No record locks available
38pub const ENOSYS = 38; // Function not implemented
39pub const ENOTEMPTY = 39; // Directory not empty
40pub const ELOOP = 40; // Too many symbolic links encountered
41pub const EWOULDBLOCK = EAGAIN; // Operation would block
42pub const ENOMSG = 42; // No message of desired type
43pub const EIDRM = 43; // Identifier removed
44pub const ECHRNG = 44; // Channel number out of range
45pub const EL2NSYNC = 45; // Level 2 not synchronized
46pub const EL3HLT = 46; // Level 3 halted
47pub const EL3RST = 47; // Level 3 reset
48pub const ELNRNG = 48; // Link number out of range
49pub const EUNATCH = 49; // Protocol driver not attached
50pub const ENOCSI = 50; // No CSI structure available
51pub const EL2HLT = 51; // Level 2 halted
52pub const EBADE = 52; // Invalid exchange
53pub const EBADR = 53; // Invalid request descriptor
54pub const EXFULL = 54; // Exchange full
55pub const ENOANO = 55; // No anode
56pub const EBADRQC = 56; // Invalid request code
57pub const EBADSLT = 57; // Invalid slot
58
59pub const EBFONT = 59; // Bad font file format
60pub const ENOSTR = 60; // Device not a stream
61pub const ENODATA = 61; // No data available
62pub const ETIME = 62; // Timer expired
63pub const ENOSR = 63; // Out of streams resources
64pub const ENONET = 64; // Machine is not on the network
65pub const ENOPKG = 65; // Package not installed
66pub const EREMOTE = 66; // Object is remote
67pub const ENOLINK = 67; // Link has been severed
68pub const EADV = 68; // Advertise error
69pub const ESRMNT = 69; // Srmount error
70pub const ECOMM = 70; // Communication error on send
71pub const EPROTO = 71; // Protocol error
72pub const EMULTIHOP = 72; // Multihop attempted
73pub const EDOTDOT = 73; // RFS specific error
74pub const EBADMSG = 74; // Not a data message
75pub const EOVERFLOW = 75; // Value too large for defined data type
76pub const ENOTUNIQ = 76; // Name not unique on network
77pub const EBADFD = 77; // File descriptor in bad state
78pub const EREMCHG = 78; // Remote address changed
79pub const ELIBACC = 79; // Can not access a needed shared library
80pub const ELIBBAD = 80; // Accessing a corrupted shared library
81pub const ELIBSCN = 81; // .lib section in a.out corrupted
82pub const ELIBMAX = 82; // Attempting to link in too many shared libraries
83pub const ELIBEXEC = 83; // Cannot exec a shared library directly
84pub const EILSEQ = 84; // Illegal byte sequence
85pub const ERESTART = 85; // Interrupted system call should be restarted
86pub const ESTRPIPE = 86; // Streams pipe error
87pub const EUSERS = 87; // Too many users
88pub const ENOTSOCK = 88; // Socket operation on non-socket
89pub const EDESTADDRREQ = 89; // Destination address required
90pub const EMSGSIZE = 90; // Message too long
91pub const EPROTOTYPE = 91; // Protocol wrong type for socket
92pub const ENOPROTOOPT = 92; // Protocol not available
93pub const EPROTONOSUPPORT = 93; // Protocol not supported
94pub const ESOCKTNOSUPPORT = 94; // Socket type not supported
95pub const EOPNOTSUPP = 95; // Operation not supported on transport endpoint
96pub const EPFNOSUPPORT = 96; // Protocol family not supported
97pub const EAFNOSUPPORT = 97; // Address family not supported by protocol
98pub const EADDRINUSE = 98; // Address already in use
99pub const EADDRNOTAVAIL = 99; // Cannot assign requested address
100pub const ENETDOWN = 100; // Network is down
101pub const ENETUNREACH = 101; // Network is unreachable
102pub const ENETRESET = 102; // Network dropped connection because of reset
103pub const ECONNABORTED = 103; // Software caused connection abort
104pub const ECONNRESET = 104; // Connection reset by peer
105pub const ENOBUFS = 105; // No buffer space available
106pub const EISCONN = 106; // Transport endpoint is already connected
107pub const ENOTCONN = 107; // Transport endpoint is not connected
108pub const ESHUTDOWN = 108; // Cannot send after transport endpoint shutdown
109pub const ETOOMANYREFS = 109; // Too many references: cannot splice
110pub const ETIMEDOUT = 110; // Connection timed out
111pub const ECONNREFUSED = 111; // Connection refused
112pub const EHOSTDOWN = 112; // Host is down
113pub const EHOSTUNREACH = 113; // No route to host
114pub const EALREADY = 114; // Operation already in progress
115pub const EINPROGRESS = 115; // Operation now in progress
116pub const ESTALE = 116; // Stale NFS file handle
117pub const EUCLEAN = 117; // Structure needs cleaning
118pub const ENOTNAM = 118; // Not a XENIX named type file
119pub const ENAVAIL = 119; // No XENIX semaphores available
120pub const EISNAM = 120; // Is a named type file
121pub const EREMOTEIO = 121; // Remote I/O error
122pub const EDQUOT = 122; // Quota exceeded
123
124pub const ENOMEDIUM = 123; // No medium found
125pub const EMEDIUMTYPE = 124; // Wrong medium type
126
127// nameserver query return codes
128pub const ENSROK = 0; // DNS server returned answer with no data
129pub const ENSRNODATA = 160; // DNS server returned answer with no data
130pub const ENSRFORMERR = 161; // DNS server claims query was misformatted
131pub const ENSRSERVFAIL = 162; // DNS server returned general failure
132pub const ENSRNOTFOUND = 163; // Domain name not found
133pub const ENSRNOTIMP = 164; // DNS server does not implement requested operation
134pub const ENSRREFUSED = 165; // DNS server refused query
135pub const ENSRBADQUERY = 166; // Misformatted DNS query
136pub const ENSRBADNAME = 167; // Misformatted domain name
137pub const ENSRBADFAMILY = 168; // Unsupported address family
138pub const ENSRBADRESP = 169; // Misformatted DNS reply
139pub const ENSRCONNREFUSED = 170; // Could not contact DNS servers
140pub const ENSRTIMEOUT = 171; // Timeout while contacting DNS servers
141pub const ENSROF = 172; // End of file
142pub const ENSRFILE = 173; // Error reading file
143pub const ENSRNOMEM = 174; // Out of memory
144pub const ENSRDESTRUCTION = 175; // Application terminated lookup
145pub const ENSRQUERYDOMAINTOOLONG = 176; // Domain name is too long
146pub const ENSRCNAMELOOP = 177; // Domain name is too long
std/index.zig+4-11
......@@ -1,6 +1,7 @@
1pub const build = @import("build.zig");
1pub const c = @import("c/index.zig");
22pub const cstr = @import("cstr.zig");
33pub const debug = @import("debug.zig");
4pub const empty_import = @import("empty.zig");
45pub const fmt = @import("fmt.zig");
56pub const hash_map = @import("hash_map.zig");
67pub const io = @import("io.zig");
......@@ -8,15 +9,7 @@ pub const list = @import("list.zig");
89pub const math = @import("math.zig");
910pub const mem = @import("mem.zig");
1011pub const net = @import("net.zig");
11pub const os = @import("os.zig");
12pub const os = @import("os/index.zig");
1213pub const rand = @import("rand.zig");
1314pub const sort = @import("sort.zig");
14pub const linux = switch(@compileVar("os")) {
15 Os.linux => @import("linux.zig"),
16 else => empty_import,
17};
18pub const darwin = switch(@compileVar("os")) {
19 Os.darwin => @import("darwin.zig"),
20 else => empty_import,
21};
22pub const empty_import = @import("empty.zig");
15pub const target = @import("target.zig");
std/io.zig+4-4
......@@ -1,14 +1,14 @@
11const system = switch(@compileVar("os")) {
2 Os.linux => @import("linux.zig"),
3 Os.darwin => @import("darwin.zig"),
2 Os.linux => @import("os/linux.zig"),
3 Os.darwin => @import("os/darwin.zig"),
44 else => @compileError("Unsupported OS"),
55};
66
7const errno = @import("errno.zig");
7const errno = @import("os/errno.zig");
88const math = @import("math.zig");
99const debug = @import("debug.zig");
1010const assert = debug.assert;
11const os = @import("os.zig");
11const os = @import("os/index.zig");
1212const mem = @import("mem.zig");
1313const Buffer0 = @import("cstr.zig").Buffer0;
1414const fmt = @import("fmt.zig");
std/linux.zig deleted-492
......@@ -1,492 +0,0 @@
1const arch = switch (@compileVar("arch")) {
2 Arch.x86_64 => @import("linux_x86_64.zig"),
3 Arch.i386 => @import("linux_i386.zig"),
4 else => @compileError("unsupported arch"),
5};
6const errno = @import("errno.zig");
7
8pub const MMAP_PROT_NONE = 0;
9pub const MMAP_PROT_READ = 1;
10pub const MMAP_PROT_WRITE = 2;
11pub const MMAP_PROT_EXEC = 4;
12
13pub const MMAP_MAP_FILE = 0;
14pub const MMAP_MAP_SHARED = 1;
15pub const MMAP_MAP_PRIVATE = 2;
16pub const MMAP_MAP_FIXED = 16;
17pub const MMAP_MAP_ANON = 32;
18
19pub const SIGHUP = 1;
20pub const SIGINT = 2;
21pub const SIGQUIT = 3;
22pub const SIGILL = 4;
23pub const SIGTRAP = 5;
24pub const SIGABRT = 6;
25pub const SIGIOT = SIGABRT;
26pub const SIGBUS = 7;
27pub const SIGFPE = 8;
28pub const SIGKILL = 9;
29pub const SIGUSR1 = 10;
30pub const SIGSEGV = 11;
31pub const SIGUSR2 = 12;
32pub const SIGPIPE = 13;
33pub const SIGALRM = 14;
34pub const SIGTERM = 15;
35pub const SIGSTKFLT = 16;
36pub const SIGCHLD = 17;
37pub const SIGCONT = 18;
38pub const SIGSTOP = 19;
39pub const SIGTSTP = 20;
40pub const SIGTTIN = 21;
41pub const SIGTTOU = 22;
42pub const SIGURG = 23;
43pub const SIGXCPU = 24;
44pub const SIGXFSZ = 25;
45pub const SIGVTALRM = 26;
46pub const SIGPROF = 27;
47pub const SIGWINCH = 28;
48pub const SIGIO = 29;
49pub const SIGPOLL = 29;
50pub const SIGPWR = 30;
51pub const SIGSYS = 31;
52pub const SIGUNUSED = SIGSYS;
53
54pub const O_RDONLY = 0o0;
55pub const O_WRONLY = 0o1;
56pub const O_RDWR = 0o2;
57
58pub const O_CREAT = arch.O_CREAT;
59pub const O_EXCL = arch.O_EXCL;
60pub const O_NOCTTY = arch.O_NOCTTY;
61pub const O_TRUNC = arch.O_TRUNC;
62pub const O_APPEND = arch.O_APPEND;
63pub const O_NONBLOCK = arch.O_NONBLOCK;
64pub const O_DSYNC = arch.O_DSYNC;
65pub const O_SYNC = arch.O_SYNC;
66pub const O_RSYNC = arch.O_RSYNC;
67pub const O_DIRECTORY = arch.O_DIRECTORY;
68pub const O_NOFOLLOW = arch.O_NOFOLLOW;
69pub const O_CLOEXEC = arch.O_CLOEXEC;
70
71pub const O_ASYNC = arch.O_ASYNC;
72pub const O_DIRECT = arch.O_DIRECT;
73pub const O_LARGEFILE = arch.O_LARGEFILE;
74pub const O_NOATIME = arch.O_NOATIME;
75pub const O_PATH = arch.O_PATH;
76pub const O_TMPFILE = arch.O_TMPFILE;
77pub const O_NDELAY = arch.O_NDELAY;
78
79pub const SEEK_SET = 0;
80pub const SEEK_CUR = 1;
81pub const SEEK_END = 2;
82
83const SIG_BLOCK = 0;
84const SIG_UNBLOCK = 1;
85const SIG_SETMASK = 2;
86
87pub const SOCK_STREAM = 1;
88pub const SOCK_DGRAM = 2;
89pub const SOCK_RAW = 3;
90pub const SOCK_RDM = 4;
91pub const SOCK_SEQPACKET = 5;
92pub const SOCK_DCCP = 6;
93pub const SOCK_PACKET = 10;
94pub const SOCK_CLOEXEC = 0o2000000;
95pub const SOCK_NONBLOCK = 0o4000;
96
97
98pub const PROTO_ip = 0o000;
99pub const PROTO_icmp = 0o001;
100pub const PROTO_igmp = 0o002;
101pub const PROTO_ggp = 0o003;
102pub const PROTO_ipencap = 0o004;
103pub const PROTO_st = 0o005;
104pub const PROTO_tcp = 0o006;
105pub const PROTO_egp = 0o010;
106pub const PROTO_pup = 0o014;
107pub const PROTO_udp = 0o021;
108pub const PROTO_hmp = 0o024;
109pub const PROTO_xns_idp = 0o026;
110pub const PROTO_rdp = 0o033;
111pub const PROTO_iso_tp4 = 0o035;
112pub const PROTO_xtp = 0o044;
113pub const PROTO_ddp = 0o045;
114pub const PROTO_idpr_cmtp = 0o046;
115pub const PROTO_ipv6 = 0o051;
116pub const PROTO_ipv6_route = 0o053;
117pub const PROTO_ipv6_frag = 0o054;
118pub const PROTO_idrp = 0o055;
119pub const PROTO_rsvp = 0o056;
120pub const PROTO_gre = 0o057;
121pub const PROTO_esp = 0o062;
122pub const PROTO_ah = 0o063;
123pub const PROTO_skip = 0o071;
124pub const PROTO_ipv6_icmp = 0o072;
125pub const PROTO_ipv6_nonxt = 0o073;
126pub const PROTO_ipv6_opts = 0o074;
127pub const PROTO_rspf = 0o111;
128pub const PROTO_vmtp = 0o121;
129pub const PROTO_ospf = 0o131;
130pub const PROTO_ipip = 0o136;
131pub const PROTO_encap = 0o142;
132pub const PROTO_pim = 0o147;
133pub const PROTO_raw = 0o377;
134
135pub const PF_UNSPEC = 0;
136pub const PF_LOCAL = 1;
137pub const PF_UNIX = PF_LOCAL;
138pub const PF_FILE = PF_LOCAL;
139pub const PF_INET = 2;
140pub const PF_AX25 = 3;
141pub const PF_IPX = 4;
142pub const PF_APPLETALK = 5;
143pub const PF_NETROM = 6;
144pub const PF_BRIDGE = 7;
145pub const PF_ATMPVC = 8;
146pub const PF_X25 = 9;
147pub const PF_INET6 = 10;
148pub const PF_ROSE = 11;
149pub const PF_DECnet = 12;
150pub const PF_NETBEUI = 13;
151pub const PF_SECURITY = 14;
152pub const PF_KEY = 15;
153pub const PF_NETLINK = 16;
154pub const PF_ROUTE = PF_NETLINK;
155pub const PF_PACKET = 17;
156pub const PF_ASH = 18;
157pub const PF_ECONET = 19;
158pub const PF_ATMSVC = 20;
159pub const PF_RDS = 21;
160pub const PF_SNA = 22;
161pub const PF_IRDA = 23;
162pub const PF_PPPOX = 24;
163pub const PF_WANPIPE = 25;
164pub const PF_LLC = 26;
165pub const PF_IB = 27;
166pub const PF_MPLS = 28;
167pub const PF_CAN = 29;
168pub const PF_TIPC = 30;
169pub const PF_BLUETOOTH = 31;
170pub const PF_IUCV = 32;
171pub const PF_RXRPC = 33;
172pub const PF_ISDN = 34;
173pub const PF_PHONET = 35;
174pub const PF_IEEE802154 = 36;
175pub const PF_CAIF = 37;
176pub const PF_ALG = 38;
177pub const PF_NFC = 39;
178pub const PF_VSOCK = 40;
179pub const PF_MAX = 41;
180
181pub const AF_UNSPEC = PF_UNSPEC;
182pub const AF_LOCAL = PF_LOCAL;
183pub const AF_UNIX = AF_LOCAL;
184pub const AF_FILE = AF_LOCAL;
185pub const AF_INET = PF_INET;
186pub const AF_AX25 = PF_AX25;
187pub const AF_IPX = PF_IPX;
188pub const AF_APPLETALK = PF_APPLETALK;
189pub const AF_NETROM = PF_NETROM;
190pub const AF_BRIDGE = PF_BRIDGE;
191pub const AF_ATMPVC = PF_ATMPVC;
192pub const AF_X25 = PF_X25;
193pub const AF_INET6 = PF_INET6;
194pub const AF_ROSE = PF_ROSE;
195pub const AF_DECnet = PF_DECnet;
196pub const AF_NETBEUI = PF_NETBEUI;
197pub const AF_SECURITY = PF_SECURITY;
198pub const AF_KEY = PF_KEY;
199pub const AF_NETLINK = PF_NETLINK;
200pub const AF_ROUTE = PF_ROUTE;
201pub const AF_PACKET = PF_PACKET;
202pub const AF_ASH = PF_ASH;
203pub const AF_ECONET = PF_ECONET;
204pub const AF_ATMSVC = PF_ATMSVC;
205pub const AF_RDS = PF_RDS;
206pub const AF_SNA = PF_SNA;
207pub const AF_IRDA = PF_IRDA;
208pub const AF_PPPOX = PF_PPPOX;
209pub const AF_WANPIPE = PF_WANPIPE;
210pub const AF_LLC = PF_LLC;
211pub const AF_IB = PF_IB;
212pub const AF_MPLS = PF_MPLS;
213pub const AF_CAN = PF_CAN;
214pub const AF_TIPC = PF_TIPC;
215pub const AF_BLUETOOTH = PF_BLUETOOTH;
216pub const AF_IUCV = PF_IUCV;
217pub const AF_RXRPC = PF_RXRPC;
218pub const AF_ISDN = PF_ISDN;
219pub const AF_PHONET = PF_PHONET;
220pub const AF_IEEE802154 = PF_IEEE802154;
221pub const AF_CAIF = PF_CAIF;
222pub const AF_ALG = PF_ALG;
223pub const AF_NFC = PF_NFC;
224pub const AF_VSOCK = PF_VSOCK;
225pub const AF_MAX = PF_MAX;
226
227/// Get the errno from a syscall return value, or 0 for no error.
228pub fn getErrno(r: usize) -> usize {
229 const signed_r = *(&isize)(&r);
230 if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0
231}
232
233pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, offset: usize)
234 -> usize
235{
236 arch.syscall6(arch.SYS_mmap, usize(address), length, prot, flags, usize(fd), offset)
237}
238
239pub fn munmap(address: &u8, length: usize) -> usize {
240 arch.syscall2(arch.SYS_munmap, usize(address), length)
241}
242
243pub fn read(fd: i32, buf: &u8, count: usize) -> usize {
244 arch.syscall3(arch.SYS_read, usize(fd), usize(buf), count)
245}
246
247pub fn pread(fd: i32, buf: &u8, count: usize, offset: usize) -> usize {
248 arch.syscall4(arch.SYS_pread, usize(fd), usize(buf), count, offset)
249}
250
251pub fn write(fd: i32, buf: &const u8, count: usize) -> usize {
252 arch.syscall3(arch.SYS_write, usize(fd), usize(buf), count)
253}
254
255pub fn pwrite(fd: i32, buf: &const u8, count: usize, offset: usize) -> usize {
256 arch.syscall4(arch.SYS_pwrite, usize(fd), usize(buf), count, offset)
257}
258
259pub fn open_c(path: &const u8, flags: usize, perm: usize) -> usize {
260 arch.syscall3(arch.SYS_open, usize(path), flags, perm)
261}
262
263pub fn open(path: []const u8, flags: usize, perm: usize) -> usize {
264 const buf = @alloca(u8, path.len + 1);
265 @memcpy(&buf[0], &path[0], path.len);
266 buf[path.len] = 0;
267 return open_c(buf.ptr, flags, perm);
268}
269
270pub fn create_c(path: &const u8, perm: usize) -> usize {
271 arch.syscall2(arch.SYS_creat, usize(path), perm)
272}
273
274pub fn create(path: []const u8, perm: usize) -> usize {
275 const buf = @alloca(u8, path.len + 1);
276 @memcpy(&buf[0], &path[0], path.len);
277 buf[path.len] = 0;
278 return create_c(buf.ptr, perm);
279}
280
281pub fn openat_c(dirfd: i32, path: &const u8, flags: usize, mode: usize) -> usize {
282 arch.syscall4(arch.SYS_openat, usize(dirfd), usize(path), flags, mode)
283}
284
285pub fn openat(dirfd: i32, path: []const u8, flags: usize, mode: usize) -> usize {
286 const buf = @alloca(u8, path.len + 1);
287 @memcpy(&buf[0], &path[0], path.len);
288 buf[path.len] = 0;
289 return openat_c(dirfd, buf.ptr, flags, mode);
290}
291
292pub fn close(fd: i32) -> usize {
293 arch.syscall1(arch.SYS_close, usize(fd))
294}
295
296pub fn lseek(fd: i32, offset: usize, ref_pos: usize) -> usize {
297 arch.syscall3(arch.SYS_lseek, usize(fd), offset, ref_pos)
298}
299
300pub fn exit(status: i32) -> noreturn {
301 _ = arch.syscall1(arch.SYS_exit, usize(status));
302 unreachable
303}
304
305pub fn getrandom(buf: &u8, count: usize, flags: u32) -> usize {
306 arch.syscall3(arch.SYS_getrandom, usize(buf), count, usize(flags))
307}
308
309pub fn kill(pid: i32, sig: i32) -> i32 {
310 i32(arch.syscall2(arch.SYS_kill, usize(pid), usize(sig)))
311}
312
313const NSIG = 65;
314const sigset_t = [128]u8;
315const all_mask = []u8 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, };
316const app_mask = []u8 { 0xff, 0xff, 0xff, 0xfc, 0x7f, 0xff, 0xff, 0xff, };
317
318pub fn raise(sig: i32) -> i32 {
319 var set: sigset_t = undefined;
320 blockAppSignals(&set);
321 const tid = i32(arch.syscall0(arch.SYS_gettid));
322 const ret = i32(arch.syscall2(arch.SYS_tkill, usize(tid), usize(sig)));
323 restoreSignals(&set);
324 return ret;
325}
326
327fn blockAllSignals(set: &sigset_t) {
328 _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_BLOCK, usize(&all_mask), usize(set), NSIG/8);
329}
330
331fn blockAppSignals(set: &sigset_t) {
332 _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_BLOCK, usize(&app_mask), usize(set), NSIG/8);
333}
334
335fn restoreSignals(set: &sigset_t) {
336 _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_SETMASK, usize(set), 0, NSIG/8);
337}
338
339
340pub const sa_family_t = u16;
341pub const socklen_t = u32;
342pub const in_addr = u32;
343pub const in6_addr = [16]u8;
344
345pub const sockaddr = extern struct {
346 family: sa_family_t,
347 port: u16,
348 data: [12]u8,
349};
350
351pub const sockaddr_in = extern struct {
352 family: sa_family_t,
353 port: u16,
354 addr: in_addr,
355 zero: [8]u8,
356};
357
358pub const sockaddr_in6 = extern struct {
359 family: sa_family_t,
360 port: u16,
361 flowinfo: u32,
362 addr: in6_addr,
363 scope_id: u32,
364};
365
366pub const iovec = extern struct {
367 iov_base: &u8,
368 iov_len: usize,
369};
370
371//
372//const IF_NAMESIZE = 16;
373//
374//export struct ifreq {
375// ifrn_name: [IF_NAMESIZE]u8,
376// union {
377// ifru_addr: sockaddr,
378// ifru_dstaddr: sockaddr,
379// ifru_broadaddr: sockaddr,
380// ifru_netmask: sockaddr,
381// ifru_hwaddr: sockaddr,
382// ifru_flags: i16,
383// ifru_ivalue: i32,
384// ifru_mtu: i32,
385// ifru_map: ifmap,
386// ifru_slave: [IF_NAMESIZE]u8,
387// ifru_newname: [IF_NAMESIZE]u8,
388// ifru_data: &u8,
389// } ifr_ifru;
390//}
391//
392
393pub fn getsockname(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize {
394 arch.syscall3(arch.SYS_getsockname, usize(fd), usize(addr), usize(len))
395}
396
397pub fn getpeername(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize {
398 arch.syscall3(arch.SYS_getpeername, usize(fd), usize(addr), usize(len))
399}
400
401pub fn socket(domain: i32, socket_type: i32, protocol: i32) -> usize {
402 arch.syscall3(arch.SYS_socket, usize(domain), usize(socket_type), usize(protocol))
403}
404
405pub fn setsockopt(fd: i32, level: i32, optname: i32, optval: &const u8, optlen: socklen_t) -> usize {
406 arch.syscall5(arch.SYS_setsockopt, usize(fd), usize(level), usize(optname), usize(optval), usize(optlen))
407}
408
409pub fn getsockopt(fd: i32, level: i32, optname: i32, noalias optval: &u8, noalias optlen: &socklen_t) -> usize {
410 arch.syscall5(arch.SYS_getsockopt, usize(fd), usize(level), usize(optname), usize(optval), usize(optlen))
411}
412
413pub fn sendmsg(fd: i32, msg: &const arch.msghdr, flags: u32) -> usize {
414 arch.syscall3(arch.SYS_sendmsg, usize(fd), usize(msg), flags)
415}
416
417pub fn connect(fd: i32, addr: &const sockaddr, len: socklen_t) -> usize {
418 arch.syscall3(arch.SYS_connect, usize(fd), usize(addr), usize(len))
419}
420
421pub fn recvmsg(fd: i32, msg: &arch.msghdr, flags: u32) -> usize {
422 arch.syscall3(arch.SYS_recvmsg, usize(fd), usize(msg), flags)
423}
424
425pub fn recvfrom(fd: i32, noalias buf: &u8, len: usize, flags: u32,
426 noalias addr: ?&sockaddr, noalias alen: ?&socklen_t) -> usize
427{
428 arch.syscall6(arch.SYS_recvfrom, usize(fd), usize(buf), len, flags, usize(addr), usize(alen))
429}
430
431pub fn shutdown(fd: i32, how: i32) -> usize {
432 arch.syscall2(arch.SYS_shutdown, usize(fd), usize(how))
433}
434
435pub fn bind(fd: i32, addr: &const sockaddr, len: socklen_t) -> usize {
436 arch.syscall3(arch.SYS_bind, usize(fd), usize(addr), usize(len))
437}
438
439pub fn listen(fd: i32, backlog: i32) -> usize {
440 arch.syscall2(arch.SYS_listen, usize(fd), usize(backlog))
441}
442
443pub fn sendto(fd: i32, buf: &const u8, len: usize, flags: u32, addr: ?&const sockaddr, alen: socklen_t) -> usize {
444 arch.syscall6(arch.SYS_sendto, usize(fd), usize(buf), len, flags, usize(addr), usize(alen))
445}
446
447pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) -> usize {
448 arch.syscall4(arch.SYS_socketpair, usize(domain), usize(socket_type), usize(protocol), usize(&fd[0]))
449}
450
451pub fn accept(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize {
452 accept4(fd, addr, len, 0)
453}
454
455pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags: u32) -> usize {
456 arch.syscall4(arch.SYS_accept4, usize(fd), usize(addr), usize(len), flags)
457}
458
459// error NameTooLong;
460// error SystemResources;
461// error Io;
462//
463// pub fn if_nametoindex(name: []u8) -> %u32 {
464// var ifr: ifreq = undefined;
465//
466// if (name.len >= ifr.ifr_name.len) {
467// return error.NameTooLong;
468// }
469//
470// const socket_ret = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0);
471// const socket_err = getErrno(socket_ret);
472// if (socket_err > 0) {
473// return error.SystemResources;
474// }
475// const socket_fd = i32(socket_ret);
476// @memcpy(&ifr.ifr_name[0], &name[0], name.len);
477// ifr.ifr_name[name.len] = 0;
478// const ioctl_ret = ioctl(socket_fd, SIOCGIFINDEX, &ifr);
479// close(socket_fd);
480// const ioctl_err = getErrno(ioctl_ret);
481// if (ioctl_err > 0) {
482// return error.Io;
483// }
484// return ifr.ifr_ifindex;
485// }
486
487pub const stat = arch.stat;
488pub const timespec = arch.timespec;
489
490pub fn fstat(fd: i32, stat_buf: &stat) -> usize {
491 arch.syscall2(arch.SYS_fstat, usize(fd), usize(stat_buf))
492}
std/linux_i386.zig deleted-497
......@@ -1,497 +0,0 @@
1const linux = @import("linux.zig");
2const socklen_t = linux.socklen_t;
3const iovec = linux.iovec;
4
5pub const SYS_restart_syscall = 0;
6pub const SYS_exit = 1;
7pub const SYS_fork = 2;
8pub const SYS_read = 3;
9pub const SYS_write = 4;
10pub const SYS_open = 5;
11pub const SYS_close = 6;
12pub const SYS_waitpid = 7;
13pub const SYS_creat = 8;
14pub const SYS_link = 9;
15pub const SYS_unlink = 10;
16pub const SYS_execve = 11;
17pub const SYS_chdir = 12;
18pub const SYS_time = 13;
19pub const SYS_mknod = 14;
20pub const SYS_chmod = 15;
21pub const SYS_lchown = 16;
22pub const SYS_break = 17;
23pub const SYS_oldstat = 18;
24pub const SYS_lseek = 19;
25pub const SYS_getpid = 20;
26pub const SYS_mount = 21;
27pub const SYS_umount = 22;
28pub const SYS_setuid = 23;
29pub const SYS_getuid = 24;
30pub const SYS_stime = 25;
31pub const SYS_ptrace = 26;
32pub const SYS_alarm = 27;
33pub const SYS_oldfstat = 28;
34pub const SYS_pause = 29;
35pub const SYS_utime = 30;
36pub const SYS_stty = 31;
37pub const SYS_gtty = 32;
38pub const SYS_access = 33;
39pub const SYS_nice = 34;
40pub const SYS_ftime = 35;
41pub const SYS_sync = 36;
42pub const SYS_kill = 37;
43pub const SYS_rename = 38;
44pub const SYS_mkdir = 39;
45pub const SYS_rmdir = 40;
46pub const SYS_dup = 41;
47pub const SYS_pipe = 42;
48pub const SYS_times = 43;
49pub const SYS_prof = 44;
50pub const SYS_brk = 45;
51pub const SYS_setgid = 46;
52pub const SYS_getgid = 47;
53pub const SYS_signal = 48;
54pub const SYS_geteuid = 49;
55pub const SYS_getegid = 50;
56pub const SYS_acct = 51;
57pub const SYS_umount2 = 52;
58pub const SYS_lock = 53;
59pub const SYS_ioctl = 54;
60pub const SYS_fcntl = 55;
61pub const SYS_mpx = 56;
62pub const SYS_setpgid = 57;
63pub const SYS_ulimit = 58;
64pub const SYS_oldolduname = 59;
65pub const SYS_umask = 60;
66pub const SYS_chroot = 61;
67pub const SYS_ustat = 62;
68pub const SYS_dup2 = 63;
69pub const SYS_getppid = 64;
70pub const SYS_getpgrp = 65;
71pub const SYS_setsid = 66;
72pub const SYS_sigaction = 67;
73pub const SYS_sgetmask = 68;
74pub const SYS_ssetmask = 69;
75pub const SYS_setreuid = 70;
76pub const SYS_setregid = 71;
77pub const SYS_sigsuspend = 72;
78pub const SYS_sigpending = 73;
79pub const SYS_sethostname = 74;
80pub const SYS_setrlimit = 75;
81pub const SYS_getrlimit = 76;
82pub const SYS_getrusage = 77;
83pub const SYS_gettimeofday = 78;
84pub const SYS_settimeofday = 79;
85pub const SYS_getgroups = 80;
86pub const SYS_setgroups = 81;
87pub const SYS_select = 82;
88pub const SYS_symlink = 83;
89pub const SYS_oldlstat = 84;
90pub const SYS_readlink = 85;
91pub const SYS_uselib = 86;
92pub const SYS_swapon = 87;
93pub const SYS_reboot = 88;
94pub const SYS_readdir = 89;
95pub const SYS_mmap = 90;
96pub const SYS_munmap = 91;
97pub const SYS_truncate = 92;
98pub const SYS_ftruncate = 93;
99pub const SYS_fchmod = 94;
100pub const SYS_fchown = 95;
101pub const SYS_getpriority = 96;
102pub const SYS_setpriority = 97;
103pub const SYS_profil = 98;
104pub const SYS_statfs = 99;
105pub const SYS_fstatfs = 100;
106pub const SYS_ioperm = 101;
107pub const SYS_socketcall = 102;
108pub const SYS_syslog = 103;
109pub const SYS_setitimer = 104;
110pub const SYS_getitimer = 105;
111pub const SYS_stat = 106;
112pub const SYS_lstat = 107;
113pub const SYS_fstat = 108;
114pub const SYS_olduname = 109;
115pub const SYS_iopl = 110;
116pub const SYS_vhangup = 111;
117pub const SYS_idle = 112;
118pub const SYS_vm86old = 113;
119pub const SYS_wait4 = 114;
120pub const SYS_swapoff = 115;
121pub const SYS_sysinfo = 116;
122pub const SYS_ipc = 117;
123pub const SYS_fsync = 118;
124pub const SYS_sigreturn = 119;
125pub const SYS_clone = 120;
126pub const SYS_setdomainname = 121;
127pub const SYS_uname = 122;
128pub const SYS_modify_ldt = 123;
129pub const SYS_adjtimex = 124;
130pub const SYS_mprotect = 125;
131pub const SYS_sigprocmask = 126;
132pub const SYS_create_module = 127;
133pub const SYS_init_module = 128;
134pub const SYS_delete_module = 129;
135pub const SYS_get_kernel_syms = 130;
136pub const SYS_quotactl = 131;
137pub const SYS_getpgid = 132;
138pub const SYS_fchdir = 133;
139pub const SYS_bdflush = 134;
140pub const SYS_sysfs = 135;
141pub const SYS_personality = 136;
142pub const SYS_afs_syscall = 137;
143pub const SYS_setfsuid = 138;
144pub const SYS_setfsgid = 139;
145pub const SYS__llseek = 140;
146pub const SYS_getdents = 141;
147pub const SYS__newselect = 142;
148pub const SYS_flock = 143;
149pub const SYS_msync = 144;
150pub const SYS_readv = 145;
151pub const SYS_writev = 146;
152pub const SYS_getsid = 147;
153pub const SYS_fdatasync = 148;
154pub const SYS__sysctl = 149;
155pub const SYS_mlock = 150;
156pub const SYS_munlock = 151;
157pub const SYS_mlockall = 152;
158pub const SYS_munlockall = 153;
159pub const SYS_sched_setparam = 154;
160pub const SYS_sched_getparam = 155;
161pub const SYS_sched_setscheduler = 156;
162pub const SYS_sched_getscheduler = 157;
163pub const SYS_sched_yield = 158;
164pub const SYS_sched_get_priority_max = 159;
165pub const SYS_sched_get_priority_min = 160;
166pub const SYS_sched_rr_get_interval = 161;
167pub const SYS_nanosleep = 162;
168pub const SYS_mremap = 163;
169pub const SYS_setresuid = 164;
170pub const SYS_getresuid = 165;
171pub const SYS_vm86 = 166;
172pub const SYS_query_module = 167;
173pub const SYS_poll = 168;
174pub const SYS_nfsservctl = 169;
175pub const SYS_setresgid = 170;
176pub const SYS_getresgid = 171;
177pub const SYS_prctl = 172;
178pub const SYS_rt_sigreturn = 173;
179pub const SYS_rt_sigaction = 174;
180pub const SYS_rt_sigprocmask = 175;
181pub const SYS_rt_sigpending = 176;
182pub const SYS_rt_sigtimedwait = 177;
183pub const SYS_rt_sigqueueinfo = 178;
184pub const SYS_rt_sigsuspend = 179;
185pub const SYS_pread64 = 180;
186pub const SYS_pwrite64 = 181;
187pub const SYS_chown = 182;
188pub const SYS_getcwd = 183;
189pub const SYS_capget = 184;
190pub const SYS_capset = 185;
191pub const SYS_sigaltstack = 186;
192pub const SYS_sendfile = 187;
193pub const SYS_getpmsg = 188;
194pub const SYS_putpmsg = 189;
195pub const SYS_vfork = 190;
196pub const SYS_ugetrlimit = 191;
197pub const SYS_mmap2 = 192;
198pub const SYS_truncate64 = 193;
199pub const SYS_ftruncate64 = 194;
200pub const SYS_stat64 = 195;
201pub const SYS_lstat64 = 196;
202pub const SYS_fstat64 = 197;
203pub const SYS_lchown32 = 198;
204pub const SYS_getuid32 = 199;
205pub const SYS_getgid32 = 200;
206pub const SYS_geteuid32 = 201;
207pub const SYS_getegid32 = 202;
208pub const SYS_setreuid32 = 203;
209pub const SYS_setregid32 = 204;
210pub const SYS_getgroups32 = 205;
211pub const SYS_setgroups32 = 206;
212pub const SYS_fchown32 = 207;
213pub const SYS_setresuid32 = 208;
214pub const SYS_getresuid32 = 209;
215pub const SYS_setresgid32 = 210;
216pub const SYS_getresgid32 = 211;
217pub const SYS_chown32 = 212;
218pub const SYS_setuid32 = 213;
219pub const SYS_setgid32 = 214;
220pub const SYS_setfsuid32 = 215;
221pub const SYS_setfsgid32 = 216;
222pub const SYS_pivot_root = 217;
223pub const SYS_mincore = 218;
224pub const SYS_madvise = 219;
225pub const SYS_madvise1 = 219;
226pub const SYS_getdents64 = 220;
227pub const SYS_fcntl64 = 221;
228pub const SYS_gettid = 224;
229pub const SYS_readahead = 225;
230pub const SYS_setxattr = 226;
231pub const SYS_lsetxattr = 227;
232pub const SYS_fsetxattr = 228;
233pub const SYS_getxattr = 229;
234pub const SYS_lgetxattr = 230;
235pub const SYS_fgetxattr = 231;
236pub const SYS_listxattr = 232;
237pub const SYS_llistxattr = 233;
238pub const SYS_flistxattr = 234;
239pub const SYS_removexattr = 235;
240pub const SYS_lremovexattr = 236;
241pub const SYS_fremovexattr = 237;
242pub const SYS_tkill = 238;
243pub const SYS_sendfile64 = 239;
244pub const SYS_futex = 240;
245pub const SYS_sched_setaffinity = 241;
246pub const SYS_sched_getaffinity = 242;
247pub const SYS_set_thread_area = 243;
248pub const SYS_get_thread_area = 244;
249pub const SYS_io_setup = 245;
250pub const SYS_io_destroy = 246;
251pub const SYS_io_getevents = 247;
252pub const SYS_io_submit = 248;
253pub const SYS_io_cancel = 249;
254pub const SYS_fadvise64 = 250;
255pub const SYS_exit_group = 252;
256pub const SYS_lookup_dcookie = 253;
257pub const SYS_epoll_create = 254;
258pub const SYS_epoll_ctl = 255;
259pub const SYS_epoll_wait = 256;
260pub const SYS_remap_file_pages = 257;
261pub const SYS_set_tid_address = 258;
262pub const SYS_timer_create = 259;
263pub const SYS_timer_settime = SYS_timer_create+1;
264pub const SYS_timer_gettime = SYS_timer_create+2;
265pub const SYS_timer_getoverrun = SYS_timer_create+3;
266pub const SYS_timer_delete = SYS_timer_create+4;
267pub const SYS_clock_settime = SYS_timer_create+5;
268pub const SYS_clock_gettime = SYS_timer_create+6;
269pub const SYS_clock_getres = SYS_timer_create+7;
270pub const SYS_clock_nanosleep = SYS_timer_create+8;
271pub const SYS_statfs64 = 268;
272pub const SYS_fstatfs64 = 269;
273pub const SYS_tgkill = 270;
274pub const SYS_utimes = 271;
275pub const SYS_fadvise64_64 = 272;
276pub const SYS_vserver = 273;
277pub const SYS_mbind = 274;
278pub const SYS_get_mempolicy = 275;
279pub const SYS_set_mempolicy = 276;
280pub const SYS_mq_open = 277;
281pub const SYS_mq_unlink = SYS_mq_open+1;
282pub const SYS_mq_timedsend = SYS_mq_open+2;
283pub const SYS_mq_timedreceive = SYS_mq_open+3;
284pub const SYS_mq_notify = SYS_mq_open+4;
285pub const SYS_mq_getsetattr = SYS_mq_open+5;
286pub const SYS_kexec_load = 283;
287pub const SYS_waitid = 284;
288pub const SYS_add_key = 286;
289pub const SYS_request_key = 287;
290pub const SYS_keyctl = 288;
291pub const SYS_ioprio_set = 289;
292pub const SYS_ioprio_get = 290;
293pub const SYS_inotify_init = 291;
294pub const SYS_inotify_add_watch = 292;
295pub const SYS_inotify_rm_watch = 293;
296pub const SYS_migrate_pages = 294;
297pub const SYS_openat = 295;
298pub const SYS_mkdirat = 296;
299pub const SYS_mknodat = 297;
300pub const SYS_fchownat = 298;
301pub const SYS_futimesat = 299;
302pub const SYS_fstatat64 = 300;
303pub const SYS_unlinkat = 301;
304pub const SYS_renameat = 302;
305pub const SYS_linkat = 303;
306pub const SYS_symlinkat = 304;
307pub const SYS_readlinkat = 305;
308pub const SYS_fchmodat = 306;
309pub const SYS_faccessat = 307;
310pub const SYS_pselect6 = 308;
311pub const SYS_ppoll = 309;
312pub const SYS_unshare = 310;
313pub const SYS_set_robust_list = 311;
314pub const SYS_get_robust_list = 312;
315pub const SYS_splice = 313;
316pub const SYS_sync_file_range = 314;
317pub const SYS_tee = 315;
318pub const SYS_vmsplice = 316;
319pub const SYS_move_pages = 317;
320pub const SYS_getcpu = 318;
321pub const SYS_epoll_pwait = 319;
322pub const SYS_utimensat = 320;
323pub const SYS_signalfd = 321;
324pub const SYS_timerfd_create = 322;
325pub const SYS_eventfd = 323;
326pub const SYS_fallocate = 324;
327pub const SYS_timerfd_settime = 325;
328pub const SYS_timerfd_gettime = 326;
329pub const SYS_signalfd4 = 327;
330pub const SYS_eventfd2 = 328;
331pub const SYS_epoll_create1 = 329;
332pub const SYS_dup3 = 330;
333pub const SYS_pipe2 = 331;
334pub const SYS_inotify_init1 = 332;
335pub const SYS_preadv = 333;
336pub const SYS_pwritev = 334;
337pub const SYS_rt_tgsigqueueinfo = 335;
338pub const SYS_perf_event_open = 336;
339pub const SYS_recvmmsg = 337;
340pub const SYS_fanotify_init = 338;
341pub const SYS_fanotify_mark = 339;
342pub const SYS_prlimit64 = 340;
343pub const SYS_name_to_handle_at = 341;
344pub const SYS_open_by_handle_at = 342;
345pub const SYS_clock_adjtime = 343;
346pub const SYS_syncfs = 344;
347pub const SYS_sendmmsg = 345;
348pub const SYS_setns = 346;
349pub const SYS_process_vm_readv = 347;
350pub const SYS_process_vm_writev = 348;
351pub const SYS_kcmp = 349;
352pub const SYS_finit_module = 350;
353pub const SYS_sched_setattr = 351;
354pub const SYS_sched_getattr = 352;
355pub const SYS_renameat2 = 353;
356pub const SYS_seccomp = 354;
357pub const SYS_getrandom = 355;
358pub const SYS_memfd_create = 356;
359pub const SYS_bpf = 357;
360pub const SYS_execveat = 358;
361pub const SYS_socket = 359;
362pub const SYS_socketpair = 360;
363pub const SYS_bind = 361;
364pub const SYS_connect = 362;
365pub const SYS_listen = 363;
366pub const SYS_accept4 = 364;
367pub const SYS_getsockopt = 365;
368pub const SYS_setsockopt = 366;
369pub const SYS_getsockname = 367;
370pub const SYS_getpeername = 368;
371pub const SYS_sendto = 369;
372pub const SYS_sendmsg = 370;
373pub const SYS_recvfrom = 371;
374pub const SYS_recvmsg = 372;
375pub const SYS_shutdown = 373;
376pub const SYS_userfaultfd = 374;
377pub const SYS_membarrier = 375;
378pub const SYS_mlock2 = 376;
379
380
381pub const O_CREAT = 0o100;
382pub const O_EXCL = 0o200;
383pub const O_NOCTTY = 0o400;
384pub const O_TRUNC = 0o1000;
385pub const O_APPEND = 0o2000;
386pub const O_NONBLOCK = 0o4000;
387pub const O_DSYNC = 0o10000;
388pub const O_SYNC = 0o4010000;
389pub const O_RSYNC = 0o4010000;
390pub const O_DIRECTORY = 0o200000;
391pub const O_NOFOLLOW = 0o400000;
392pub const O_CLOEXEC = 0o2000000;
393
394pub const O_ASYNC = 0o20000;
395pub const O_DIRECT = 0o40000;
396pub const O_LARGEFILE = 0o100000;
397pub const O_NOATIME = 0o1000000;
398pub const O_PATH = 0o10000000;
399pub const O_TMPFILE = 0o20200000;
400pub const O_NDELAY = O_NONBLOCK;
401
402pub const F_DUPFD = 0;
403pub const F_GETFD = 1;
404pub const F_SETFD = 2;
405pub const F_GETFL = 3;
406pub const F_SETFL = 4;
407
408pub const F_SETOWN = 8;
409pub const F_GETOWN = 9;
410pub const F_SETSIG = 10;
411pub const F_GETSIG = 11;
412
413pub const F_GETLK = 12;
414pub const F_SETLK = 13;
415pub const F_SETLKW = 14;
416
417pub const F_SETOWN_EX = 15;
418pub const F_GETOWN_EX = 16;
419
420pub const F_GETOWNER_UIDS = 17;
421
422pub inline fn syscall0(number: usize) -> usize {
423 asm volatile ("int 80h"
424 : [ret] "={eax}" (-> usize)
425 : [number] "{eax}" (number))
426}
427
428pub inline fn syscall1(number: usize, arg1: usize) -> usize {
429 asm volatile ("int 80h"
430 : [ret] "={eax}" (-> usize)
431 : [number] "{eax}" (number),
432 [arg1] "{ebx}" (arg1))
433}
434
435pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize {
436 asm volatile ("int 80h"
437 : [ret] "={eax}" (-> usize)
438 : [number] "{eax}" (number),
439 [arg1] "{ebx}" (arg1),
440 [arg2] "{ecx}" (arg2))
441}
442
443pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize {
444 asm volatile ("int 80h"
445 : [ret] "={eax}" (-> usize)
446 : [number] "{eax}" (number),
447 [arg1] "{ebx}" (arg1),
448 [arg2] "{ecx}" (arg2),
449 [arg3] "{edx}" (arg3))
450}
451
452pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) -> usize {
453 asm volatile ("int 80h"
454 : [ret] "={eax}" (-> usize)
455 : [number] "{eax}" (number),
456 [arg1] "{ebx}" (arg1),
457 [arg2] "{ecx}" (arg2),
458 [arg3] "{edx}" (arg3),
459 [arg4] "{esi}" (arg4))
460}
461
462pub inline fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize,
463 arg4: usize, arg5: usize) -> usize
464{
465 asm volatile ("int 80h"
466 : [ret] "={eax}" (-> usize)
467 : [number] "{eax}" (number),
468 [arg1] "{ebx}" (arg1),
469 [arg2] "{ecx}" (arg2),
470 [arg3] "{edx}" (arg3),
471 [arg4] "{esi}" (arg4),
472 [arg5] "{edi}" (arg5))
473}
474
475pub inline fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize,
476 arg4: usize, arg5: usize, arg6: usize) -> usize
477{
478 asm volatile ("int 80h"
479 : [ret] "={eax}" (-> usize)
480 : [number] "{eax}" (number),
481 [arg1] "{ebx}" (arg1),
482 [arg2] "{ecx}" (arg2),
483 [arg3] "{edx}" (arg3),
484 [arg4] "{esi}" (arg4),
485 [arg5] "{edi}" (arg5),
486 [arg6] "{ebp}" (arg6))
487}
488
489export struct msghdr {
490 msg_name: &u8,
491 msg_namelen: socklen_t,
492 msg_iov: &iovec,
493 msg_iovlen: i32,
494 msg_control: &u8,
495 msg_controllen: socklen_t,
496 msg_flags: i32,
497}
std/linux_x86_64.zig deleted-480
......@@ -1,480 +0,0 @@
1const linux = @import("linux.zig");
2const socklen_t = linux.socklen_t;
3const iovec = linux.iovec;
4
5pub const SYS_read = 0;
6pub const SYS_write = 1;
7pub const SYS_open = 2;
8pub const SYS_close = 3;
9pub const SYS_stat = 4;
10pub const SYS_fstat = 5;
11pub const SYS_lstat = 6;
12pub const SYS_poll = 7;
13pub const SYS_lseek = 8;
14pub const SYS_mmap = 9;
15pub const SYS_mprotect = 10;
16pub const SYS_munmap = 11;
17pub const SYS_brk = 12;
18pub const SYS_rt_sigaction = 13;
19pub const SYS_rt_sigprocmask = 14;
20pub const SYS_rt_sigreturn = 15;
21pub const SYS_ioctl = 16;
22pub const SYS_pread = 17;
23pub const SYS_pwrite = 18;
24pub const SYS_readv = 19;
25pub const SYS_writev = 20;
26pub const SYS_access = 21;
27pub const SYS_pipe = 22;
28pub const SYS_select = 23;
29pub const SYS_sched_yield = 24;
30pub const SYS_mremap = 25;
31pub const SYS_msync = 26;
32pub const SYS_mincore = 27;
33pub const SYS_madvise = 28;
34pub const SYS_shmget = 29;
35pub const SYS_shmat = 30;
36pub const SYS_shmctl = 31;
37pub const SYS_dup = 32;
38pub const SYS_dup2 = 33;
39pub const SYS_pause = 34;
40pub const SYS_nanosleep = 35;
41pub const SYS_getitimer = 36;
42pub const SYS_alarm = 37;
43pub const SYS_setitimer = 38;
44pub const SYS_getpid = 39;
45pub const SYS_sendfile = 40;
46pub const SYS_socket = 41;
47pub const SYS_connect = 42;
48pub const SYS_accept = 43;
49pub const SYS_sendto = 44;
50pub const SYS_recvfrom = 45;
51pub const SYS_sendmsg = 46;
52pub const SYS_recvmsg = 47;
53pub const SYS_shutdown = 48;
54pub const SYS_bind = 49;
55pub const SYS_listen = 50;
56pub const SYS_getsockname = 51;
57pub const SYS_getpeername = 52;
58pub const SYS_socketpair = 53;
59pub const SYS_setsockopt = 54;
60pub const SYS_getsockopt = 55;
61pub const SYS_clone = 56;
62pub const SYS_fork = 57;
63pub const SYS_vfork = 58;
64pub const SYS_execve = 59;
65pub const SYS_exit = 60;
66pub const SYS_wait4 = 61;
67pub const SYS_kill = 62;
68pub const SYS_uname = 63;
69pub const SYS_semget = 64;
70pub const SYS_semop = 65;
71pub const SYS_semctl = 66;
72pub const SYS_shmdt = 67;
73pub const SYS_msgget = 68;
74pub const SYS_msgsnd = 69;
75pub const SYS_msgrcv = 70;
76pub const SYS_msgctl = 71;
77pub const SYS_fcntl = 72;
78pub const SYS_flock = 73;
79pub const SYS_fsync = 74;
80pub const SYS_fdatasync = 75;
81pub const SYS_truncate = 76;
82pub const SYS_ftruncate = 77;
83pub const SYS_getdents = 78;
84pub const SYS_getcwd = 79;
85pub const SYS_chdir = 80;
86pub const SYS_fchdir = 81;
87pub const SYS_rename = 82;
88pub const SYS_mkdir = 83;
89pub const SYS_rmdir = 84;
90pub const SYS_creat = 85;
91pub const SYS_link = 86;
92pub const SYS_unlink = 87;
93pub const SYS_symlink = 88;
94pub const SYS_readlink = 89;
95pub const SYS_chmod = 90;
96pub const SYS_fchmod = 91;
97pub const SYS_chown = 92;
98pub const SYS_fchown = 93;
99pub const SYS_lchown = 94;
100pub const SYS_umask = 95;
101pub const SYS_gettimeofday = 96;
102pub const SYS_getrlimit = 97;
103pub const SYS_getrusage = 98;
104pub const SYS_sysinfo = 99;
105pub const SYS_times = 100;
106pub const SYS_ptrace = 101;
107pub const SYS_getuid = 102;
108pub const SYS_syslog = 103;
109pub const SYS_getgid = 104;
110pub const SYS_setuid = 105;
111pub const SYS_setgid = 106;
112pub const SYS_geteuid = 107;
113pub const SYS_getegid = 108;
114pub const SYS_setpgid = 109;
115pub const SYS_getppid = 110;
116pub const SYS_getpgrp = 111;
117pub const SYS_setsid = 112;
118pub const SYS_setreuid = 113;
119pub const SYS_setregid = 114;
120pub const SYS_getgroups = 115;
121pub const SYS_setgroups = 116;
122pub const SYS_setresuid = 117;
123pub const SYS_getresuid = 118;
124pub const SYS_setresgid = 119;
125pub const SYS_getresgid = 120;
126pub const SYS_getpgid = 121;
127pub const SYS_setfsuid = 122;
128pub const SYS_setfsgid = 123;
129pub const SYS_getsid = 124;
130pub const SYS_capget = 125;
131pub const SYS_capset = 126;
132pub const SYS_rt_sigpending = 127;
133pub const SYS_rt_sigtimedwait = 128;
134pub const SYS_rt_sigqueueinfo = 129;
135pub const SYS_rt_sigsuspend = 130;
136pub const SYS_sigaltstack = 131;
137pub const SYS_utime = 132;
138pub const SYS_mknod = 133;
139pub const SYS_uselib = 134;
140pub const SYS_personality = 135;
141pub const SYS_ustat = 136;
142pub const SYS_statfs = 137;
143pub const SYS_fstatfs = 138;
144pub const SYS_sysfs = 139;
145pub const SYS_getpriority = 140;
146pub const SYS_setpriority = 141;
147pub const SYS_sched_setparam = 142;
148pub const SYS_sched_getparam = 143;
149pub const SYS_sched_setscheduler = 144;
150pub const SYS_sched_getscheduler = 145;
151pub const SYS_sched_get_priority_max = 146;
152pub const SYS_sched_get_priority_min = 147;
153pub const SYS_sched_rr_get_interval = 148;
154pub const SYS_mlock = 149;
155pub const SYS_munlock = 150;
156pub const SYS_mlockall = 151;
157pub const SYS_munlockall = 152;
158pub const SYS_vhangup = 153;
159pub const SYS_modify_ldt = 154;
160pub const SYS_pivot_root = 155;
161pub const SYS__sysctl = 156;
162pub const SYS_prctl = 157;
163pub const SYS_arch_prctl = 158;
164pub const SYS_adjtimex = 159;
165pub const SYS_setrlimit = 160;
166pub const SYS_chroot = 161;
167pub const SYS_sync = 162;
168pub const SYS_acct = 163;
169pub const SYS_settimeofday = 164;
170pub const SYS_mount = 165;
171pub const SYS_umount2 = 166;
172pub const SYS_swapon = 167;
173pub const SYS_swapoff = 168;
174pub const SYS_reboot = 169;
175pub const SYS_sethostname = 170;
176pub const SYS_setdomainname = 171;
177pub const SYS_iopl = 172;
178pub const SYS_ioperm = 173;
179pub const SYS_create_module = 174;
180pub const SYS_init_module = 175;
181pub const SYS_delete_module = 176;
182pub const SYS_get_kernel_syms = 177;
183pub const SYS_query_module = 178;
184pub const SYS_quotactl = 179;
185pub const SYS_nfsservctl = 180;
186pub const SYS_getpmsg = 181;
187pub const SYS_putpmsg = 182;
188pub const SYS_afs_syscall = 183;
189pub const SYS_tuxcall = 184;
190pub const SYS_security = 185;
191pub const SYS_gettid = 186;
192pub const SYS_readahead = 187;
193pub const SYS_setxattr = 188;
194pub const SYS_lsetxattr = 189;
195pub const SYS_fsetxattr = 190;
196pub const SYS_getxattr = 191;
197pub const SYS_lgetxattr = 192;
198pub const SYS_fgetxattr = 193;
199pub const SYS_listxattr = 194;
200pub const SYS_llistxattr = 195;
201pub const SYS_flistxattr = 196;
202pub const SYS_removexattr = 197;
203pub const SYS_lremovexattr = 198;
204pub const SYS_fremovexattr = 199;
205pub const SYS_tkill = 200;
206pub const SYS_time = 201;
207pub const SYS_futex = 202;
208pub const SYS_sched_setaffinity = 203;
209pub const SYS_sched_getaffinity = 204;
210pub const SYS_set_thread_area = 205;
211pub const SYS_io_setup = 206;
212pub const SYS_io_destroy = 207;
213pub const SYS_io_getevents = 208;
214pub const SYS_io_submit = 209;
215pub const SYS_io_cancel = 210;
216pub const SYS_get_thread_area = 211;
217pub const SYS_lookup_dcookie = 212;
218pub const SYS_epoll_create = 213;
219pub const SYS_epoll_ctl_old = 214;
220pub const SYS_epoll_wait_old = 215;
221pub const SYS_remap_file_pages = 216;
222pub const SYS_getdents64 = 217;
223pub const SYS_set_tid_address = 218;
224pub const SYS_restart_syscall = 219;
225pub const SYS_semtimedop = 220;
226pub const SYS_fadvise64 = 221;
227pub const SYS_timer_create = 222;
228pub const SYS_timer_settime = 223;
229pub const SYS_timer_gettime = 224;
230pub const SYS_timer_getoverrun = 225;
231pub const SYS_timer_delete = 226;
232pub const SYS_clock_settime = 227;
233pub const SYS_clock_gettime = 228;
234pub const SYS_clock_getres = 229;
235pub const SYS_clock_nanosleep = 230;
236pub const SYS_exit_group = 231;
237pub const SYS_epoll_wait = 232;
238pub const SYS_epoll_ctl = 233;
239pub const SYS_tgkill = 234;
240pub const SYS_utimes = 235;
241pub const SYS_vserver = 236;
242pub const SYS_mbind = 237;
243pub const SYS_set_mempolicy = 238;
244pub const SYS_get_mempolicy = 239;
245pub const SYS_mq_open = 240;
246pub const SYS_mq_unlink = 241;
247pub const SYS_mq_timedsend = 242;
248pub const SYS_mq_timedreceive = 243;
249pub const SYS_mq_notify = 244;
250pub const SYS_mq_getsetattr = 245;
251pub const SYS_kexec_load = 246;
252pub const SYS_waitid = 247;
253pub const SYS_add_key = 248;
254pub const SYS_request_key = 249;
255pub const SYS_keyctl = 250;
256pub const SYS_ioprio_set = 251;
257pub const SYS_ioprio_get = 252;
258pub const SYS_inotify_init = 253;
259pub const SYS_inotify_add_watch = 254;
260pub const SYS_inotify_rm_watch = 255;
261pub const SYS_migrate_pages = 256;
262pub const SYS_openat = 257;
263pub const SYS_mkdirat = 258;
264pub const SYS_mknodat = 259;
265pub const SYS_fchownat = 260;
266pub const SYS_futimesat = 261;
267pub const SYS_newfstatat = 262;
268pub const SYS_unlinkat = 263;
269pub const SYS_renameat = 264;
270pub const SYS_linkat = 265;
271pub const SYS_symlinkat = 266;
272pub const SYS_readlinkat = 267;
273pub const SYS_fchmodat = 268;
274pub const SYS_faccessat = 269;
275pub const SYS_pselect6 = 270;
276pub const SYS_ppoll = 271;
277pub const SYS_unshare = 272;
278pub const SYS_set_robust_list = 273;
279pub const SYS_get_robust_list = 274;
280pub const SYS_splice = 275;
281pub const SYS_tee = 276;
282pub const SYS_sync_file_range = 277;
283pub const SYS_vmsplice = 278;
284pub const SYS_move_pages = 279;
285pub const SYS_utimensat = 280;
286pub const SYS_epoll_pwait = 281;
287pub const SYS_signalfd = 282;
288pub const SYS_timerfd_create = 283;
289pub const SYS_eventfd = 284;
290pub const SYS_fallocate = 285;
291pub const SYS_timerfd_settime = 286;
292pub const SYS_timerfd_gettime = 287;
293pub const SYS_accept4 = 288;
294pub const SYS_signalfd4 = 289;
295pub const SYS_eventfd2 = 290;
296pub const SYS_epoll_create1 = 291;
297pub const SYS_dup3 = 292;
298pub const SYS_pipe2 = 293;
299pub const SYS_inotify_init1 = 294;
300pub const SYS_preadv = 295;
301pub const SYS_pwritev = 296;
302pub const SYS_rt_tgsigqueueinfo = 297;
303pub const SYS_perf_event_open = 298;
304pub const SYS_recvmmsg = 299;
305pub const SYS_fanotify_init = 300;
306pub const SYS_fanotify_mark = 301;
307pub const SYS_prlimit64 = 302;
308pub const SYS_name_to_handle_at = 303;
309pub const SYS_open_by_handle_at = 304;
310pub const SYS_clock_adjtime = 305;
311pub const SYS_syncfs = 306;
312pub const SYS_sendmmsg = 307;
313pub const SYS_setns = 308;
314pub const SYS_getcpu = 309;
315pub const SYS_process_vm_readv = 310;
316pub const SYS_process_vm_writev = 311;
317pub const SYS_kcmp = 312;
318pub const SYS_finit_module = 313;
319pub const SYS_sched_setattr = 314;
320pub const SYS_sched_getattr = 315;
321pub const SYS_renameat2 = 316;
322pub const SYS_seccomp = 317;
323pub const SYS_getrandom = 318;
324pub const SYS_memfd_create = 319;
325pub const SYS_kexec_file_load = 320;
326pub const SYS_bpf = 321;
327pub const SYS_execveat = 322;
328pub const SYS_userfaultfd = 323;
329pub const SYS_membarrier = 324;
330pub const SYS_mlock2 = 325;
331
332pub const O_CREAT = 0o100;
333pub const O_EXCL = 0o200;
334pub const O_NOCTTY = 0o400;
335pub const O_TRUNC = 0o1000;
336pub const O_APPEND = 0o2000;
337pub const O_NONBLOCK = 0o4000;
338pub const O_DSYNC = 0o10000;
339pub const O_SYNC = 0o4010000;
340pub const O_RSYNC = 0o4010000;
341pub const O_DIRECTORY = 0o200000;
342pub const O_NOFOLLOW = 0o400000;
343pub const O_CLOEXEC = 0o2000000;
344
345pub const O_ASYNC = 0o20000;
346pub const O_DIRECT = 0o40000;
347pub const O_LARGEFILE = 0;
348pub const O_NOATIME = 0o1000000;
349pub const O_PATH = 0o10000000;
350pub const O_TMPFILE = 0o20200000;
351pub const O_NDELAY = O_NONBLOCK;
352
353pub const F_DUPFD = 0;
354pub const F_GETFD = 1;
355pub const F_SETFD = 2;
356pub const F_GETFL = 3;
357pub const F_SETFL = 4;
358
359pub const F_SETOWN = 8;
360pub const F_GETOWN = 9;
361pub const F_SETSIG = 10;
362pub const F_GETSIG = 11;
363
364pub const F_GETLK = 5;
365pub const F_SETLK = 6;
366pub const F_SETLKW = 7;
367
368pub const F_SETOWN_EX = 15;
369pub const F_GETOWN_EX = 16;
370
371pub const F_GETOWNER_UIDS = 17;
372
373pub inline fn syscall0(number: usize) -> usize {
374 asm volatile ("syscall"
375 : [ret] "={rax}" (-> usize)
376 : [number] "{rax}" (number)
377 : "rcx", "r11")
378}
379
380pub inline fn syscall1(number: usize, arg1: usize) -> usize {
381 asm volatile ("syscall"
382 : [ret] "={rax}" (-> usize)
383 : [number] "{rax}" (number),
384 [arg1] "{rdi}" (arg1)
385 : "rcx", "r11")
386}
387
388pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize {
389 asm volatile ("syscall"
390 : [ret] "={rax}" (-> usize)
391 : [number] "{rax}" (number),
392 [arg1] "{rdi}" (arg1),
393 [arg2] "{rsi}" (arg2)
394 : "rcx", "r11")
395}
396
397pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize {
398 asm volatile ("syscall"
399 : [ret] "={rax}" (-> usize)
400 : [number] "{rax}" (number),
401 [arg1] "{rdi}" (arg1),
402 [arg2] "{rsi}" (arg2),
403 [arg3] "{rdx}" (arg3)
404 : "rcx", "r11")
405}
406
407pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) -> usize {
408 asm volatile ("syscall"
409 : [ret] "={rax}" (-> usize)
410 : [number] "{rax}" (number),
411 [arg1] "{rdi}" (arg1),
412 [arg2] "{rsi}" (arg2),
413 [arg3] "{rdx}" (arg3),
414 [arg4] "{r10}" (arg4)
415 : "rcx", "r11")
416}
417
418pub inline fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) -> usize {
419 asm volatile ("syscall"
420 : [ret] "={rax}" (-> usize)
421 : [number] "{rax}" (number),
422 [arg1] "{rdi}" (arg1),
423 [arg2] "{rsi}" (arg2),
424 [arg3] "{rdx}" (arg3),
425 [arg4] "{r10}" (arg4),
426 [arg5] "{r8}" (arg5)
427 : "rcx", "r11")
428}
429
430pub inline fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize,
431 arg5: usize, arg6: usize) -> usize
432{
433 asm volatile ("syscall"
434 : [ret] "={rax}" (-> usize)
435 : [number] "{rax}" (number),
436 [arg1] "{rdi}" (arg1),
437 [arg2] "{rsi}" (arg2),
438 [arg3] "{rdx}" (arg3),
439 [arg4] "{r10}" (arg4),
440 [arg5] "{r8}" (arg5),
441 [arg6] "{r9}" (arg6)
442 : "rcx", "r11")
443}
444
445pub const msghdr = extern struct {
446 msg_name: &u8,
447 msg_namelen: socklen_t,
448 msg_iov: &iovec,
449 msg_iovlen: i32,
450 __pad1: i32,
451 msg_control: &u8,
452 msg_controllen: socklen_t,
453 __pad2: socklen_t,
454 msg_flags: i32,
455};
456
457pub const stat = extern struct {
458 dev: u64,
459 ino: u64,
460 nlink: usize,
461
462 mode: u32,
463 uid: u32,
464 gid: u32,
465 __pad0: u32,
466 rdev: u64,
467 size: i64,
468 blksize: isize,
469 blocks: i64,
470
471 atim: timespec,
472 mtim: timespec,
473 ctim: timespec,
474 __unused: [3]isize,
475};
476
477pub const timespec = extern struct {
478 tv_sec: isize,
479 tv_nsec: isize,
480};
std/mem.zig+1-1
......@@ -1,6 +1,6 @@
11const assert = @import("debug.zig").assert;
22const math = @import("math.zig");
3const os = @import("os.zig");
3const os = @import("os/index.zig");
44const io = @import("io.zig");
55
66pub const Cmp = math.Cmp;
std/net.zig+2-2
......@@ -1,5 +1,5 @@
1const linux = @import("linux.zig");
2const errno = @import("errno.zig");
1const linux = @import("os/linux.zig");
2const errno = @import("os/errno.zig");
33const assert = @import("debug.zig").assert;
44const endian = @import("endian.zig");
55
std/os.zig deleted-74
......@@ -1,74 +0,0 @@
1const posix = switch(@compileVar("os")) {
2 Os.linux => @import("linux.zig"),
3 Os.darwin, Os.macosx, Os.ios => @import("darwin.zig"),
4 else => @compileError("Unsupported OS"),
5};
6const windows = @import("windows.zig");
7const errno = @import("errno.zig");
8const linking_libc = @import("build.zig").linking_libc;
9const c = @import("c/index.zig");
10
11error Unexpected;
12
13/// Fills `buf` with random bytes. If linking against libc, this calls the
14/// appropriate OS-specific library call. Otherwise it uses the zig standard
15/// library implementation.
16pub fn getRandomBytes(buf: []u8) -> %void {
17 while (true) {
18 const err = switch (@compileVar("os")) {
19 Os.linux => {
20 if (linking_libc) {
21 if (c.getrandom(buf.ptr, buf.len, 0) == -1) *c._errno() else 0
22 } else {
23 posix.getErrno(posix.getrandom(buf.ptr, buf.len, 0))
24 }
25 },
26 Os.darwin, Os.macosx, Os.ios => {
27 if (linking_libc) {
28 if (posix.getrandom(buf.ptr, buf.len) == -1) *c._errno() else 0
29 } else {
30 posix.getErrno(posix.getrandom(buf.ptr, buf.len))
31 }
32 },
33 Os.windows => {
34 var hCryptProv: windows.HCRYPTPROV = undefined;
35 if (!windows.CryptAcquireContext(&hCryptProv, null, null, windows.PROV_RSA_FULL, 0)) {
36 return error.Unexpected;
37 }
38 defer _ = windows.CryptReleaseContext(hCryptProv, 0);
39
40 if (!windows.CryptGenRandom(hCryptProv, windows.DWORD(buf.len), buf.ptr)) {
41 return error.Unexpected;
42 }
43 return;
44 },
45 else => @compileError("Unsupported OS"),
46 };
47 if (err > 0) {
48 return switch (err) {
49 errno.EINVAL => unreachable,
50 errno.EFAULT => unreachable,
51 errno.EINTR => continue,
52 else => error.Unexpected,
53 }
54 }
55 return;
56 }
57}
58
59/// Raises a signal in the current kernel thread, ending its execution.
60/// If linking against libc, this calls the abort() libc function. Otherwise
61/// it uses the zig standard library implementation.
62pub coldcc fn abort() -> noreturn {
63 if (linking_libc) {
64 c.abort();
65 }
66 switch (@compileVar("os")) {
67 Os.linux => {
68 _ = posix.raise(posix.SIGABRT);
69 _ = posix.raise(posix.SIGKILL);
70 while (true) {}
71 },
72 else => @compileError("Unsupported OS"),
73 }
74}
std/os/darwin.zig created+118
......@@ -0,0 +1,118 @@
1
2const arch = switch (@compileVar("arch")) {
3 Arch.x86_64 => @import("darwin_x86_64.zig"),
4 else => @compileError("unsupported arch"),
5};
6
7const errno = @import("errno.zig");
8
9pub const O_LARGEFILE = 0x0000;
10pub const O_RDONLY = 0x0000;
11
12pub const SEEK_SET = 0x0;
13pub const SEEK_CUR = 0x1;
14pub const SEEK_END = 0x2;
15
16pub const SIGHUP = 1;
17pub const SIGINT = 2;
18pub const SIGQUIT = 3;
19pub const SIGILL = 4;
20pub const SIGTRAP = 5;
21pub const SIGABRT = 6;
22pub const SIGIOT = SIGABRT;
23pub const SIGBUS = 7;
24pub const SIGFPE = 8;
25pub const SIGKILL = 9;
26pub const SIGUSR1 = 10;
27pub const SIGSEGV = 11;
28pub const SIGUSR2 = 12;
29pub const SIGPIPE = 13;
30pub const SIGALRM = 14;
31pub const SIGTERM = 15;
32pub const SIGSTKFLT = 16;
33pub const SIGCHLD = 17;
34pub const SIGCONT = 18;
35pub const SIGSTOP = 19;
36pub const SIGTSTP = 20;
37pub const SIGTTIN = 21;
38pub const SIGTTOU = 22;
39pub const SIGURG = 23;
40pub const SIGXCPU = 24;
41pub const SIGXFSZ = 25;
42pub const SIGVTALRM = 26;
43pub const SIGPROF = 27;
44pub const SIGWINCH = 28;
45pub const SIGIO = 29;
46pub const SIGPOLL = 29;
47pub const SIGPWR = 30;
48pub const SIGSYS = 31;
49pub const SIGUNUSED = SIGSYS;
50
51pub fn exit(status: usize) -> noreturn {
52 _ = arch.syscall1(arch.SYS_exit, status);
53 unreachable
54}
55
56/// Get the errno from a syscall return value, or 0 for no error.
57pub fn getErrno(r: usize) -> usize {
58 const signed_r = *(&isize)(&r);
59 if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0
60}
61
62pub fn write(fd: i32, buf: &const u8, count: usize) -> usize {
63 arch.syscall3(arch.SYS_write, usize(fd), usize(buf), count)
64}
65
66pub fn close(fd: i32) -> usize {
67 arch.syscall1(arch.SYS_close, usize(fd))
68}
69
70pub fn open_c(path: &const u8, flags: usize, perm: usize) -> usize {
71 arch.syscall3(arch.SYS_open, usize(path), flags, perm)
72}
73
74pub fn open(path: []const u8, flags: usize, perm: usize) -> usize {
75 const buf = @alloca(u8, path.len + 1);
76 @memcpy(&buf[0], &path[0], path.len);
77 buf[path.len] = 0;
78 return open_c(buf.ptr, flags, perm);
79}
80
81pub fn read(fd: i32, buf: &u8, count: usize) -> usize {
82 arch.syscall3(arch.SYS_read, usize(fd), usize(buf), count)
83}
84
85pub fn lseek(fd: i32, offset: usize, ref_pos: usize) -> usize {
86 arch.syscall3(arch.SYS_lseek, usize(fd), offset, ref_pos)
87}
88
89pub const stat = arch.stat;
90pub const timespec = arch.timespec;
91
92pub fn fstat(fd: i32, stat_buf: &stat) -> usize {
93 arch.syscall2(arch.SYS_fstat, usize(fd), usize(stat_buf))
94}
95
96error Unexpected;
97
98pub fn getrandom(buf: &u8, count: usize) -> usize {
99 const rr = open_c(c"/dev/urandom", O_LARGEFILE | O_RDONLY, 0);
100
101 if(getErrno(rr) > 0) return rr;
102
103 var fd: i32 = i32(rr);
104 const readRes = read(fd, buf, count);
105 readRes
106}
107
108pub fn raise(sig: i32) -> i32 {
109 // TODO investigate whether we need to block signals before calling kill
110 // like we do in the linux version of raise
111
112 //var set: sigset_t = undefined;
113 //blockAppSignals(&set);
114 const pid = i32(arch.syscall0(arch.SYS_getpid));
115 const ret = i32(arch.syscall2(arch.SYS_kill, usize(pid), usize(sig)));
116 //restoreSignals(&set);
117 return ret;
118}
std/os/darwin_x86_64.zig created+87
......@@ -0,0 +1,87 @@
1
2pub const SYSCALL_CLASS_SHIFT = 24;
3pub const SYSCALL_CLASS_MASK = 0xFF << SYSCALL_CLASS_SHIFT;
4// pub const SYSCALL_NUMBER_MASK = ~SYSCALL_CLASS_MASK; // ~ modifier not supported yet
5
6pub const SYSCALL_CLASS_NONE = 0; // Invalid
7pub const SYSCALL_CLASS_MACH = 1; // Mach
8pub const SYSCALL_CLASS_UNIX = 2; // Unix/BSD
9pub const SYSCALL_CLASS_MDEP = 3; // Machine-dependent
10pub const SYSCALL_CLASS_DIAG = 4; // Diagnostics
11
12// TODO: use the above constants to create the below values
13
14pub const SYS_exit = 0x2000001;
15pub const SYS_read = 0x2000003;
16pub const SYS_write = 0x2000004;
17pub const SYS_open = 0x2000005;
18pub const SYS_close = 0x2000006;
19pub const SYS_kill = 0x2000025;
20pub const SYS_getpid = 0x2000030;
21pub const SYS_fstat = 0x20000BD;
22pub const SYS_lseek = 0x20000C7;
23
24pub inline fn syscall0(number: usize) -> usize {
25 asm volatile ("syscall"
26 : [ret] "={rax}" (-> usize)
27 : [number] "{rax}" (number)
28 : "rcx", "r11")
29}
30
31pub inline fn syscall1(number: usize, arg1: usize) -> usize {
32 asm volatile ("syscall"
33 : [ret] "={rax}" (-> usize)
34 : [number] "{rax}" (number),
35 [arg1] "{rdi}" (arg1)
36 : "rcx", "r11")
37}
38
39pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize {
40 asm volatile ("syscall"
41 : [ret] "={rax}" (-> usize)
42 : [number] "{rax}" (number),
43 [arg1] "{rdi}" (arg1),
44 [arg2] "{rsi}" (arg2)
45 : "rcx", "r11")
46}
47
48pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize {
49 asm volatile ("syscall"
50 : [ret] "={rax}" (-> usize)
51 : [number] "{rax}" (number),
52 [arg1] "{rdi}" (arg1),
53 [arg2] "{rsi}" (arg2),
54 [arg3] "{rdx}" (arg3)
55 : "rcx", "r11")
56}
57
58
59
60
61pub const stat = extern struct {
62 dev: u32,
63 mode: u16,
64 nlink: u16,
65 ino: u64,
66 uid: u32,
67 gid: u32,
68 rdev: u64,
69
70 atim: timespec,
71 mtim: timespec,
72 ctim: timespec,
73
74 size: u64,
75 blocks: u64,
76 blksize: u32,
77 flags: u32,
78 gen: u32,
79 lspare: i32,
80 qspare: [2]u64,
81
82};
83
84pub const timespec = extern struct {
85 tv_sec: isize,
86 tv_nsec: isize,
87};
std/os/errno.zig created+146
......@@ -0,0 +1,146 @@
1pub const EPERM = 1; // Operation not permitted
2pub const ENOENT = 2; // No such file or directory
3pub const ESRCH = 3; // No such process
4pub const EINTR = 4; // Interrupted system call
5pub const EIO = 5; // I/O error
6pub const ENXIO = 6; // No such device or address
7pub const E2BIG = 7; // Arg list too long
8pub const ENOEXEC = 8; // Exec format error
9pub const EBADF = 9; // Bad file number
10pub const ECHILD = 10; // No child processes
11pub const EAGAIN = 11; // Try again
12pub const ENOMEM = 12; // Out of memory
13pub const EACCES = 13; // Permission denied
14pub const EFAULT = 14; // Bad address
15pub const ENOTBLK = 15; // Block device required
16pub const EBUSY = 16; // Device or resource busy
17pub const EEXIST = 17; // File exists
18pub const EXDEV = 18; // Cross-device link
19pub const ENODEV = 19; // No such device
20pub const ENOTDIR = 20; // Not a directory
21pub const EISDIR = 21; // Is a directory
22pub const EINVAL = 22; // Invalid argument
23pub const ENFILE = 23; // File table overflow
24pub const EMFILE = 24; // Too many open files
25pub const ENOTTY = 25; // Not a typewriter
26pub const ETXTBSY = 26; // Text file busy
27pub const EFBIG = 27; // File too large
28pub const ENOSPC = 28; // No space left on device
29pub const ESPIPE = 29; // Illegal seek
30pub const EROFS = 30; // Read-only file system
31pub const EMLINK = 31; // Too many links
32pub const EPIPE = 32; // Broken pipe
33pub const EDOM = 33; // Math argument out of domain of func
34pub const ERANGE = 34; // Math result not representable
35pub const EDEADLK = 35; // Resource deadlock would occur
36pub const ENAMETOOLONG = 36; // File name too long
37pub const ENOLCK = 37; // No record locks available
38pub const ENOSYS = 38; // Function not implemented
39pub const ENOTEMPTY = 39; // Directory not empty
40pub const ELOOP = 40; // Too many symbolic links encountered
41pub const EWOULDBLOCK = EAGAIN; // Operation would block
42pub const ENOMSG = 42; // No message of desired type
43pub const EIDRM = 43; // Identifier removed
44pub const ECHRNG = 44; // Channel number out of range
45pub const EL2NSYNC = 45; // Level 2 not synchronized
46pub const EL3HLT = 46; // Level 3 halted
47pub const EL3RST = 47; // Level 3 reset
48pub const ELNRNG = 48; // Link number out of range
49pub const EUNATCH = 49; // Protocol driver not attached
50pub const ENOCSI = 50; // No CSI structure available
51pub const EL2HLT = 51; // Level 2 halted
52pub const EBADE = 52; // Invalid exchange
53pub const EBADR = 53; // Invalid request descriptor
54pub const EXFULL = 54; // Exchange full
55pub const ENOANO = 55; // No anode
56pub const EBADRQC = 56; // Invalid request code
57pub const EBADSLT = 57; // Invalid slot
58
59pub const EBFONT = 59; // Bad font file format
60pub const ENOSTR = 60; // Device not a stream
61pub const ENODATA = 61; // No data available
62pub const ETIME = 62; // Timer expired
63pub const ENOSR = 63; // Out of streams resources
64pub const ENONET = 64; // Machine is not on the network
65pub const ENOPKG = 65; // Package not installed
66pub const EREMOTE = 66; // Object is remote
67pub const ENOLINK = 67; // Link has been severed
68pub const EADV = 68; // Advertise error
69pub const ESRMNT = 69; // Srmount error
70pub const ECOMM = 70; // Communication error on send
71pub const EPROTO = 71; // Protocol error
72pub const EMULTIHOP = 72; // Multihop attempted
73pub const EDOTDOT = 73; // RFS specific error
74pub const EBADMSG = 74; // Not a data message
75pub const EOVERFLOW = 75; // Value too large for defined data type
76pub const ENOTUNIQ = 76; // Name not unique on network
77pub const EBADFD = 77; // File descriptor in bad state
78pub const EREMCHG = 78; // Remote address changed
79pub const ELIBACC = 79; // Can not access a needed shared library
80pub const ELIBBAD = 80; // Accessing a corrupted shared library
81pub const ELIBSCN = 81; // .lib section in a.out corrupted
82pub const ELIBMAX = 82; // Attempting to link in too many shared libraries
83pub const ELIBEXEC = 83; // Cannot exec a shared library directly
84pub const EILSEQ = 84; // Illegal byte sequence
85pub const ERESTART = 85; // Interrupted system call should be restarted
86pub const ESTRPIPE = 86; // Streams pipe error
87pub const EUSERS = 87; // Too many users
88pub const ENOTSOCK = 88; // Socket operation on non-socket
89pub const EDESTADDRREQ = 89; // Destination address required
90pub const EMSGSIZE = 90; // Message too long
91pub const EPROTOTYPE = 91; // Protocol wrong type for socket
92pub const ENOPROTOOPT = 92; // Protocol not available
93pub const EPROTONOSUPPORT = 93; // Protocol not supported
94pub const ESOCKTNOSUPPORT = 94; // Socket type not supported
95pub const EOPNOTSUPP = 95; // Operation not supported on transport endpoint
96pub const EPFNOSUPPORT = 96; // Protocol family not supported
97pub const EAFNOSUPPORT = 97; // Address family not supported by protocol
98pub const EADDRINUSE = 98; // Address already in use
99pub const EADDRNOTAVAIL = 99; // Cannot assign requested address
100pub const ENETDOWN = 100; // Network is down
101pub const ENETUNREACH = 101; // Network is unreachable
102pub const ENETRESET = 102; // Network dropped connection because of reset
103pub const ECONNABORTED = 103; // Software caused connection abort
104pub const ECONNRESET = 104; // Connection reset by peer
105pub const ENOBUFS = 105; // No buffer space available
106pub const EISCONN = 106; // Transport endpoint is already connected
107pub const ENOTCONN = 107; // Transport endpoint is not connected
108pub const ESHUTDOWN = 108; // Cannot send after transport endpoint shutdown
109pub const ETOOMANYREFS = 109; // Too many references: cannot splice
110pub const ETIMEDOUT = 110; // Connection timed out
111pub const ECONNREFUSED = 111; // Connection refused
112pub const EHOSTDOWN = 112; // Host is down
113pub const EHOSTUNREACH = 113; // No route to host
114pub const EALREADY = 114; // Operation already in progress
115pub const EINPROGRESS = 115; // Operation now in progress
116pub const ESTALE = 116; // Stale NFS file handle
117pub const EUCLEAN = 117; // Structure needs cleaning
118pub const ENOTNAM = 118; // Not a XENIX named type file
119pub const ENAVAIL = 119; // No XENIX semaphores available
120pub const EISNAM = 120; // Is a named type file
121pub const EREMOTEIO = 121; // Remote I/O error
122pub const EDQUOT = 122; // Quota exceeded
123
124pub const ENOMEDIUM = 123; // No medium found
125pub const EMEDIUMTYPE = 124; // Wrong medium type
126
127// nameserver query return codes
128pub const ENSROK = 0; // DNS server returned answer with no data
129pub const ENSRNODATA = 160; // DNS server returned answer with no data
130pub const ENSRFORMERR = 161; // DNS server claims query was misformatted
131pub const ENSRSERVFAIL = 162; // DNS server returned general failure
132pub const ENSRNOTFOUND = 163; // Domain name not found
133pub const ENSRNOTIMP = 164; // DNS server does not implement requested operation
134pub const ENSRREFUSED = 165; // DNS server refused query
135pub const ENSRBADQUERY = 166; // Misformatted DNS query
136pub const ENSRBADNAME = 167; // Misformatted domain name
137pub const ENSRBADFAMILY = 168; // Unsupported address family
138pub const ENSRBADRESP = 169; // Misformatted DNS reply
139pub const ENSRCONNREFUSED = 170; // Could not contact DNS servers
140pub const ENSRTIMEOUT = 171; // Timeout while contacting DNS servers
141pub const ENSROF = 172; // End of file
142pub const ENSRFILE = 173; // Error reading file
143pub const ENSRNOMEM = 174; // Out of memory
144pub const ENSRDESTRUCTION = 175; // Application terminated lookup
145pub const ENSRQUERYDOMAINTOOLONG = 176; // Domain name is too long
146pub const ENSRCNAMELOOP = 177; // Domain name is too long
std/os/index.zig created+78
......@@ -0,0 +1,78 @@
1pub const windows = @import("windows.zig");
2pub const darwin = @import("darwin.zig");
3pub const linux = @import("linux.zig");
4pub const posix = switch(@compileVar("os")) {
5 Os.linux => linux,
6 Os.darwin, Os.macosx, Os.ios => darwin,
7 Os.windows => windows,
8 else => @compileError("Unsupported OS"),
9};
10
11const errno = @import("errno.zig");
12const linking_libc = @import("../target.zig").linking_libc;
13const c = @import("../c/index.zig");
14
15error Unexpected;
16
17/// Fills `buf` with random bytes. If linking against libc, this calls the
18/// appropriate OS-specific library call. Otherwise it uses the zig standard
19/// library implementation.
20pub fn getRandomBytes(buf: []u8) -> %void {
21 while (true) {
22 const err = switch (@compileVar("os")) {
23 Os.linux => {
24 if (linking_libc) {
25 if (c.getrandom(buf.ptr, buf.len, 0) == -1) *c._errno() else 0
26 } else {
27 posix.getErrno(posix.getrandom(buf.ptr, buf.len, 0))
28 }
29 },
30 Os.darwin, Os.macosx, Os.ios => {
31 if (linking_libc) {
32 if (posix.getrandom(buf.ptr, buf.len) == -1) *c._errno() else 0
33 } else {
34 posix.getErrno(posix.getrandom(buf.ptr, buf.len))
35 }
36 },
37 Os.windows => {
38 var hCryptProv: windows.HCRYPTPROV = undefined;
39 if (!windows.CryptAcquireContext(&hCryptProv, null, null, windows.PROV_RSA_FULL, 0)) {
40 return error.Unexpected;
41 }
42 defer _ = windows.CryptReleaseContext(hCryptProv, 0);
43
44 if (!windows.CryptGenRandom(hCryptProv, windows.DWORD(buf.len), buf.ptr)) {
45 return error.Unexpected;
46 }
47 return;
48 },
49 else => @compileError("Unsupported OS"),
50 };
51 if (err > 0) {
52 return switch (err) {
53 errno.EINVAL => unreachable,
54 errno.EFAULT => unreachable,
55 errno.EINTR => continue,
56 else => error.Unexpected,
57 }
58 }
59 return;
60 }
61}
62
63/// Raises a signal in the current kernel thread, ending its execution.
64/// If linking against libc, this calls the abort() libc function. Otherwise
65/// it uses the zig standard library implementation.
66pub coldcc fn abort() -> noreturn {
67 if (linking_libc) {
68 c.abort();
69 }
70 switch (@compileVar("os")) {
71 Os.linux => {
72 _ = posix.raise(posix.SIGABRT);
73 _ = posix.raise(posix.SIGKILL);
74 while (true) {}
75 },
76 else => @compileError("Unsupported OS"),
77 }
78}
std/os/linux.zig created+492
......@@ -0,0 +1,492 @@
1const arch = switch (@compileVar("arch")) {
2 Arch.x86_64 => @import("linux_x86_64.zig"),
3 Arch.i386 => @import("linux_i386.zig"),
4 else => @compileError("unsupported arch"),
5};
6const errno = @import("errno.zig");
7
8pub const MMAP_PROT_NONE = 0;
9pub const MMAP_PROT_READ = 1;
10pub const MMAP_PROT_WRITE = 2;
11pub const MMAP_PROT_EXEC = 4;
12
13pub const MMAP_MAP_FILE = 0;
14pub const MMAP_MAP_SHARED = 1;
15pub const MMAP_MAP_PRIVATE = 2;
16pub const MMAP_MAP_FIXED = 16;
17pub const MMAP_MAP_ANON = 32;
18
19pub const SIGHUP = 1;
20pub const SIGINT = 2;
21pub const SIGQUIT = 3;
22pub const SIGILL = 4;
23pub const SIGTRAP = 5;
24pub const SIGABRT = 6;
25pub const SIGIOT = SIGABRT;
26pub const SIGBUS = 7;
27pub const SIGFPE = 8;
28pub const SIGKILL = 9;
29pub const SIGUSR1 = 10;
30pub const SIGSEGV = 11;
31pub const SIGUSR2 = 12;
32pub const SIGPIPE = 13;
33pub const SIGALRM = 14;
34pub const SIGTERM = 15;
35pub const SIGSTKFLT = 16;
36pub const SIGCHLD = 17;
37pub const SIGCONT = 18;
38pub const SIGSTOP = 19;
39pub const SIGTSTP = 20;
40pub const SIGTTIN = 21;
41pub const SIGTTOU = 22;
42pub const SIGURG = 23;
43pub const SIGXCPU = 24;
44pub const SIGXFSZ = 25;
45pub const SIGVTALRM = 26;
46pub const SIGPROF = 27;
47pub const SIGWINCH = 28;
48pub const SIGIO = 29;
49pub const SIGPOLL = 29;
50pub const SIGPWR = 30;
51pub const SIGSYS = 31;
52pub const SIGUNUSED = SIGSYS;
53
54pub const O_RDONLY = 0o0;
55pub const O_WRONLY = 0o1;
56pub const O_RDWR = 0o2;
57
58pub const O_CREAT = arch.O_CREAT;
59pub const O_EXCL = arch.O_EXCL;
60pub const O_NOCTTY = arch.O_NOCTTY;
61pub const O_TRUNC = arch.O_TRUNC;
62pub const O_APPEND = arch.O_APPEND;
63pub const O_NONBLOCK = arch.O_NONBLOCK;
64pub const O_DSYNC = arch.O_DSYNC;
65pub const O_SYNC = arch.O_SYNC;
66pub const O_RSYNC = arch.O_RSYNC;
67pub const O_DIRECTORY = arch.O_DIRECTORY;
68pub const O_NOFOLLOW = arch.O_NOFOLLOW;
69pub const O_CLOEXEC = arch.O_CLOEXEC;
70
71pub const O_ASYNC = arch.O_ASYNC;
72pub const O_DIRECT = arch.O_DIRECT;
73pub const O_LARGEFILE = arch.O_LARGEFILE;
74pub const O_NOATIME = arch.O_NOATIME;
75pub const O_PATH = arch.O_PATH;
76pub const O_TMPFILE = arch.O_TMPFILE;
77pub const O_NDELAY = arch.O_NDELAY;
78
79pub const SEEK_SET = 0;
80pub const SEEK_CUR = 1;
81pub const SEEK_END = 2;
82
83const SIG_BLOCK = 0;
84const SIG_UNBLOCK = 1;
85const SIG_SETMASK = 2;
86
87pub const SOCK_STREAM = 1;
88pub const SOCK_DGRAM = 2;
89pub const SOCK_RAW = 3;
90pub const SOCK_RDM = 4;
91pub const SOCK_SEQPACKET = 5;
92pub const SOCK_DCCP = 6;
93pub const SOCK_PACKET = 10;
94pub const SOCK_CLOEXEC = 0o2000000;
95pub const SOCK_NONBLOCK = 0o4000;
96
97
98pub const PROTO_ip = 0o000;
99pub const PROTO_icmp = 0o001;
100pub const PROTO_igmp = 0o002;
101pub const PROTO_ggp = 0o003;
102pub const PROTO_ipencap = 0o004;
103pub const PROTO_st = 0o005;
104pub const PROTO_tcp = 0o006;
105pub const PROTO_egp = 0o010;
106pub const PROTO_pup = 0o014;
107pub const PROTO_udp = 0o021;
108pub const PROTO_hmp = 0o024;
109pub const PROTO_xns_idp = 0o026;
110pub const PROTO_rdp = 0o033;
111pub const PROTO_iso_tp4 = 0o035;
112pub const PROTO_xtp = 0o044;
113pub const PROTO_ddp = 0o045;
114pub const PROTO_idpr_cmtp = 0o046;
115pub const PROTO_ipv6 = 0o051;
116pub const PROTO_ipv6_route = 0o053;
117pub const PROTO_ipv6_frag = 0o054;
118pub const PROTO_idrp = 0o055;
119pub const PROTO_rsvp = 0o056;
120pub const PROTO_gre = 0o057;
121pub const PROTO_esp = 0o062;
122pub const PROTO_ah = 0o063;
123pub const PROTO_skip = 0o071;
124pub const PROTO_ipv6_icmp = 0o072;
125pub const PROTO_ipv6_nonxt = 0o073;
126pub const PROTO_ipv6_opts = 0o074;
127pub const PROTO_rspf = 0o111;
128pub const PROTO_vmtp = 0o121;
129pub const PROTO_ospf = 0o131;
130pub const PROTO_ipip = 0o136;
131pub const PROTO_encap = 0o142;
132pub const PROTO_pim = 0o147;
133pub const PROTO_raw = 0o377;
134
135pub const PF_UNSPEC = 0;
136pub const PF_LOCAL = 1;
137pub const PF_UNIX = PF_LOCAL;
138pub const PF_FILE = PF_LOCAL;
139pub const PF_INET = 2;
140pub const PF_AX25 = 3;
141pub const PF_IPX = 4;
142pub const PF_APPLETALK = 5;
143pub const PF_NETROM = 6;
144pub const PF_BRIDGE = 7;
145pub const PF_ATMPVC = 8;
146pub const PF_X25 = 9;
147pub const PF_INET6 = 10;
148pub const PF_ROSE = 11;
149pub const PF_DECnet = 12;
150pub const PF_NETBEUI = 13;
151pub const PF_SECURITY = 14;
152pub const PF_KEY = 15;
153pub const PF_NETLINK = 16;
154pub const PF_ROUTE = PF_NETLINK;
155pub const PF_PACKET = 17;
156pub const PF_ASH = 18;
157pub const PF_ECONET = 19;
158pub const PF_ATMSVC = 20;
159pub const PF_RDS = 21;
160pub const PF_SNA = 22;
161pub const PF_IRDA = 23;
162pub const PF_PPPOX = 24;
163pub const PF_WANPIPE = 25;
164pub const PF_LLC = 26;
165pub const PF_IB = 27;
166pub const PF_MPLS = 28;
167pub const PF_CAN = 29;
168pub const PF_TIPC = 30;
169pub const PF_BLUETOOTH = 31;
170pub const PF_IUCV = 32;
171pub const PF_RXRPC = 33;
172pub const PF_ISDN = 34;
173pub const PF_PHONET = 35;
174pub const PF_IEEE802154 = 36;
175pub const PF_CAIF = 37;
176pub const PF_ALG = 38;
177pub const PF_NFC = 39;
178pub const PF_VSOCK = 40;
179pub const PF_MAX = 41;
180
181pub const AF_UNSPEC = PF_UNSPEC;
182pub const AF_LOCAL = PF_LOCAL;
183pub const AF_UNIX = AF_LOCAL;
184pub const AF_FILE = AF_LOCAL;
185pub const AF_INET = PF_INET;
186pub const AF_AX25 = PF_AX25;
187pub const AF_IPX = PF_IPX;
188pub const AF_APPLETALK = PF_APPLETALK;
189pub const AF_NETROM = PF_NETROM;
190pub const AF_BRIDGE = PF_BRIDGE;
191pub const AF_ATMPVC = PF_ATMPVC;
192pub const AF_X25 = PF_X25;
193pub const AF_INET6 = PF_INET6;
194pub const AF_ROSE = PF_ROSE;
195pub const AF_DECnet = PF_DECnet;
196pub const AF_NETBEUI = PF_NETBEUI;
197pub const AF_SECURITY = PF_SECURITY;
198pub const AF_KEY = PF_KEY;
199pub const AF_NETLINK = PF_NETLINK;
200pub const AF_ROUTE = PF_ROUTE;
201pub const AF_PACKET = PF_PACKET;
202pub const AF_ASH = PF_ASH;
203pub const AF_ECONET = PF_ECONET;
204pub const AF_ATMSVC = PF_ATMSVC;
205pub const AF_RDS = PF_RDS;
206pub const AF_SNA = PF_SNA;
207pub const AF_IRDA = PF_IRDA;
208pub const AF_PPPOX = PF_PPPOX;
209pub const AF_WANPIPE = PF_WANPIPE;
210pub const AF_LLC = PF_LLC;
211pub const AF_IB = PF_IB;
212pub const AF_MPLS = PF_MPLS;
213pub const AF_CAN = PF_CAN;
214pub const AF_TIPC = PF_TIPC;
215pub const AF_BLUETOOTH = PF_BLUETOOTH;
216pub const AF_IUCV = PF_IUCV;
217pub const AF_RXRPC = PF_RXRPC;
218pub const AF_ISDN = PF_ISDN;
219pub const AF_PHONET = PF_PHONET;
220pub const AF_IEEE802154 = PF_IEEE802154;
221pub const AF_CAIF = PF_CAIF;
222pub const AF_ALG = PF_ALG;
223pub const AF_NFC = PF_NFC;
224pub const AF_VSOCK = PF_VSOCK;
225pub const AF_MAX = PF_MAX;
226
227/// Get the errno from a syscall return value, or 0 for no error.
228pub fn getErrno(r: usize) -> usize {
229 const signed_r = *(&isize)(&r);
230 if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0
231}
232
233pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, offset: usize)
234 -> usize
235{
236 arch.syscall6(arch.SYS_mmap, usize(address), length, prot, flags, usize(fd), offset)
237}
238
239pub fn munmap(address: &u8, length: usize) -> usize {
240 arch.syscall2(arch.SYS_munmap, usize(address), length)
241}
242
243pub fn read(fd: i32, buf: &u8, count: usize) -> usize {
244 arch.syscall3(arch.SYS_read, usize(fd), usize(buf), count)
245}
246
247pub fn pread(fd: i32, buf: &u8, count: usize, offset: usize) -> usize {
248 arch.syscall4(arch.SYS_pread, usize(fd), usize(buf), count, offset)
249}
250
251pub fn write(fd: i32, buf: &const u8, count: usize) -> usize {
252 arch.syscall3(arch.SYS_write, usize(fd), usize(buf), count)
253}
254
255pub fn pwrite(fd: i32, buf: &const u8, count: usize, offset: usize) -> usize {
256 arch.syscall4(arch.SYS_pwrite, usize(fd), usize(buf), count, offset)
257}
258
259pub fn open_c(path: &const u8, flags: usize, perm: usize) -> usize {
260 arch.syscall3(arch.SYS_open, usize(path), flags, perm)
261}
262
263pub fn open(path: []const u8, flags: usize, perm: usize) -> usize {
264 const buf = @alloca(u8, path.len + 1);
265 @memcpy(&buf[0], &path[0], path.len);
266 buf[path.len] = 0;
267 return open_c(buf.ptr, flags, perm);
268}
269
270pub fn create_c(path: &const u8, perm: usize) -> usize {
271 arch.syscall2(arch.SYS_creat, usize(path), perm)
272}
273
274pub fn create(path: []const u8, perm: usize) -> usize {
275 const buf = @alloca(u8, path.len + 1);
276 @memcpy(&buf[0], &path[0], path.len);
277 buf[path.len] = 0;
278 return create_c(buf.ptr, perm);
279}
280
281pub fn openat_c(dirfd: i32, path: &const u8, flags: usize, mode: usize) -> usize {
282 arch.syscall4(arch.SYS_openat, usize(dirfd), usize(path), flags, mode)
283}
284
285pub fn openat(dirfd: i32, path: []const u8, flags: usize, mode: usize) -> usize {
286 const buf = @alloca(u8, path.len + 1);
287 @memcpy(&buf[0], &path[0], path.len);
288 buf[path.len] = 0;
289 return openat_c(dirfd, buf.ptr, flags, mode);
290}
291
292pub fn close(fd: i32) -> usize {
293 arch.syscall1(arch.SYS_close, usize(fd))
294}
295
296pub fn lseek(fd: i32, offset: usize, ref_pos: usize) -> usize {
297 arch.syscall3(arch.SYS_lseek, usize(fd), offset, ref_pos)
298}
299
300pub fn exit(status: i32) -> noreturn {
301 _ = arch.syscall1(arch.SYS_exit, usize(status));
302 unreachable
303}
304
305pub fn getrandom(buf: &u8, count: usize, flags: u32) -> usize {
306 arch.syscall3(arch.SYS_getrandom, usize(buf), count, usize(flags))
307}
308
309pub fn kill(pid: i32, sig: i32) -> i32 {
310 i32(arch.syscall2(arch.SYS_kill, usize(pid), usize(sig)))
311}
312
313const NSIG = 65;
314const sigset_t = [128]u8;
315const all_mask = []u8 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, };
316const app_mask = []u8 { 0xff, 0xff, 0xff, 0xfc, 0x7f, 0xff, 0xff, 0xff, };
317
318pub fn raise(sig: i32) -> i32 {
319 var set: sigset_t = undefined;
320 blockAppSignals(&set);
321 const tid = i32(arch.syscall0(arch.SYS_gettid));
322 const ret = i32(arch.syscall2(arch.SYS_tkill, usize(tid), usize(sig)));
323 restoreSignals(&set);
324 return ret;
325}
326
327fn blockAllSignals(set: &sigset_t) {
328 _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_BLOCK, usize(&all_mask), usize(set), NSIG/8);
329}
330
331fn blockAppSignals(set: &sigset_t) {
332 _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_BLOCK, usize(&app_mask), usize(set), NSIG/8);
333}
334
335fn restoreSignals(set: &sigset_t) {
336 _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_SETMASK, usize(set), 0, NSIG/8);
337}
338
339
340pub const sa_family_t = u16;
341pub const socklen_t = u32;
342pub const in_addr = u32;
343pub const in6_addr = [16]u8;
344
345pub const sockaddr = extern struct {
346 family: sa_family_t,
347 port: u16,
348 data: [12]u8,
349};
350
351pub const sockaddr_in = extern struct {
352 family: sa_family_t,
353 port: u16,
354 addr: in_addr,
355 zero: [8]u8,
356};
357
358pub const sockaddr_in6 = extern struct {
359 family: sa_family_t,
360 port: u16,
361 flowinfo: u32,
362 addr: in6_addr,
363 scope_id: u32,
364};
365
366pub const iovec = extern struct {
367 iov_base: &u8,
368 iov_len: usize,
369};
370
371//
372//const IF_NAMESIZE = 16;
373//
374//export struct ifreq {
375// ifrn_name: [IF_NAMESIZE]u8,
376// union {
377// ifru_addr: sockaddr,
378// ifru_dstaddr: sockaddr,
379// ifru_broadaddr: sockaddr,
380// ifru_netmask: sockaddr,
381// ifru_hwaddr: sockaddr,
382// ifru_flags: i16,
383// ifru_ivalue: i32,
384// ifru_mtu: i32,
385// ifru_map: ifmap,
386// ifru_slave: [IF_NAMESIZE]u8,
387// ifru_newname: [IF_NAMESIZE]u8,
388// ifru_data: &u8,
389// } ifr_ifru;
390//}
391//
392
393pub fn getsockname(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize {
394 arch.syscall3(arch.SYS_getsockname, usize(fd), usize(addr), usize(len))
395}
396
397pub fn getpeername(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize {
398 arch.syscall3(arch.SYS_getpeername, usize(fd), usize(addr), usize(len))
399}
400
401pub fn socket(domain: i32, socket_type: i32, protocol: i32) -> usize {
402 arch.syscall3(arch.SYS_socket, usize(domain), usize(socket_type), usize(protocol))
403}
404
405pub fn setsockopt(fd: i32, level: i32, optname: i32, optval: &const u8, optlen: socklen_t) -> usize {
406 arch.syscall5(arch.SYS_setsockopt, usize(fd), usize(level), usize(optname), usize(optval), usize(optlen))
407}
408
409pub fn getsockopt(fd: i32, level: i32, optname: i32, noalias optval: &u8, noalias optlen: &socklen_t) -> usize {
410 arch.syscall5(arch.SYS_getsockopt, usize(fd), usize(level), usize(optname), usize(optval), usize(optlen))
411}
412
413pub fn sendmsg(fd: i32, msg: &const arch.msghdr, flags: u32) -> usize {
414 arch.syscall3(arch.SYS_sendmsg, usize(fd), usize(msg), flags)
415}
416
417pub fn connect(fd: i32, addr: &const sockaddr, len: socklen_t) -> usize {
418 arch.syscall3(arch.SYS_connect, usize(fd), usize(addr), usize(len))
419}
420
421pub fn recvmsg(fd: i32, msg: &arch.msghdr, flags: u32) -> usize {
422 arch.syscall3(arch.SYS_recvmsg, usize(fd), usize(msg), flags)
423}
424
425pub fn recvfrom(fd: i32, noalias buf: &u8, len: usize, flags: u32,
426 noalias addr: ?&sockaddr, noalias alen: ?&socklen_t) -> usize
427{
428 arch.syscall6(arch.SYS_recvfrom, usize(fd), usize(buf), len, flags, usize(addr), usize(alen))
429}
430
431pub fn shutdown(fd: i32, how: i32) -> usize {
432 arch.syscall2(arch.SYS_shutdown, usize(fd), usize(how))
433}
434
435pub fn bind(fd: i32, addr: &const sockaddr, len: socklen_t) -> usize {
436 arch.syscall3(arch.SYS_bind, usize(fd), usize(addr), usize(len))
437}
438
439pub fn listen(fd: i32, backlog: i32) -> usize {
440 arch.syscall2(arch.SYS_listen, usize(fd), usize(backlog))
441}
442
443pub fn sendto(fd: i32, buf: &const u8, len: usize, flags: u32, addr: ?&const sockaddr, alen: socklen_t) -> usize {
444 arch.syscall6(arch.SYS_sendto, usize(fd), usize(buf), len, flags, usize(addr), usize(alen))
445}
446
447pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) -> usize {
448 arch.syscall4(arch.SYS_socketpair, usize(domain), usize(socket_type), usize(protocol), usize(&fd[0]))
449}
450
451pub fn accept(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize {
452 accept4(fd, addr, len, 0)
453}
454
455pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags: u32) -> usize {
456 arch.syscall4(arch.SYS_accept4, usize(fd), usize(addr), usize(len), flags)
457}
458
459// error NameTooLong;
460// error SystemResources;
461// error Io;
462//
463// pub fn if_nametoindex(name: []u8) -> %u32 {
464// var ifr: ifreq = undefined;
465//
466// if (name.len >= ifr.ifr_name.len) {
467// return error.NameTooLong;
468// }
469//
470// const socket_ret = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0);
471// const socket_err = getErrno(socket_ret);
472// if (socket_err > 0) {
473// return error.SystemResources;
474// }
475// const socket_fd = i32(socket_ret);
476// @memcpy(&ifr.ifr_name[0], &name[0], name.len);
477// ifr.ifr_name[name.len] = 0;
478// const ioctl_ret = ioctl(socket_fd, SIOCGIFINDEX, &ifr);
479// close(socket_fd);
480// const ioctl_err = getErrno(ioctl_ret);
481// if (ioctl_err > 0) {
482// return error.Io;
483// }
484// return ifr.ifr_ifindex;
485// }
486
487pub const stat = arch.stat;
488pub const timespec = arch.timespec;
489
490pub fn fstat(fd: i32, stat_buf: &stat) -> usize {
491 arch.syscall2(arch.SYS_fstat, usize(fd), usize(stat_buf))
492}
std/os/linux_i386.zig created+497
......@@ -0,0 +1,497 @@
1const linux = @import("linux.zig");
2const socklen_t = linux.socklen_t;
3const iovec = linux.iovec;
4
5pub const SYS_restart_syscall = 0;
6pub const SYS_exit = 1;
7pub const SYS_fork = 2;
8pub const SYS_read = 3;
9pub const SYS_write = 4;
10pub const SYS_open = 5;
11pub const SYS_close = 6;
12pub const SYS_waitpid = 7;
13pub const SYS_creat = 8;
14pub const SYS_link = 9;
15pub const SYS_unlink = 10;
16pub const SYS_execve = 11;
17pub const SYS_chdir = 12;
18pub const SYS_time = 13;
19pub const SYS_mknod = 14;
20pub const SYS_chmod = 15;
21pub const SYS_lchown = 16;
22pub const SYS_break = 17;
23pub const SYS_oldstat = 18;
24pub const SYS_lseek = 19;
25pub const SYS_getpid = 20;
26pub const SYS_mount = 21;
27pub const SYS_umount = 22;
28pub const SYS_setuid = 23;
29pub const SYS_getuid = 24;
30pub const SYS_stime = 25;
31pub const SYS_ptrace = 26;
32pub const SYS_alarm = 27;
33pub const SYS_oldfstat = 28;
34pub const SYS_pause = 29;
35pub const SYS_utime = 30;
36pub const SYS_stty = 31;
37pub const SYS_gtty = 32;
38pub const SYS_access = 33;
39pub const SYS_nice = 34;
40pub const SYS_ftime = 35;
41pub const SYS_sync = 36;
42pub const SYS_kill = 37;
43pub const SYS_rename = 38;
44pub const SYS_mkdir = 39;
45pub const SYS_rmdir = 40;
46pub const SYS_dup = 41;
47pub const SYS_pipe = 42;
48pub const SYS_times = 43;
49pub const SYS_prof = 44;
50pub const SYS_brk = 45;
51pub const SYS_setgid = 46;
52pub const SYS_getgid = 47;
53pub const SYS_signal = 48;
54pub const SYS_geteuid = 49;
55pub const SYS_getegid = 50;
56pub const SYS_acct = 51;
57pub const SYS_umount2 = 52;
58pub const SYS_lock = 53;
59pub const SYS_ioctl = 54;
60pub const SYS_fcntl = 55;
61pub const SYS_mpx = 56;
62pub const SYS_setpgid = 57;
63pub const SYS_ulimit = 58;
64pub const SYS_oldolduname = 59;
65pub const SYS_umask = 60;
66pub const SYS_chroot = 61;
67pub const SYS_ustat = 62;
68pub const SYS_dup2 = 63;
69pub const SYS_getppid = 64;
70pub const SYS_getpgrp = 65;
71pub const SYS_setsid = 66;
72pub const SYS_sigaction = 67;
73pub const SYS_sgetmask = 68;
74pub const SYS_ssetmask = 69;
75pub const SYS_setreuid = 70;
76pub const SYS_setregid = 71;
77pub const SYS_sigsuspend = 72;
78pub const SYS_sigpending = 73;
79pub const SYS_sethostname = 74;
80pub const SYS_setrlimit = 75;
81pub const SYS_getrlimit = 76;
82pub const SYS_getrusage = 77;
83pub const SYS_gettimeofday = 78;
84pub const SYS_settimeofday = 79;
85pub const SYS_getgroups = 80;
86pub const SYS_setgroups = 81;
87pub const SYS_select = 82;
88pub const SYS_symlink = 83;
89pub const SYS_oldlstat = 84;
90pub const SYS_readlink = 85;
91pub const SYS_uselib = 86;
92pub const SYS_swapon = 87;
93pub const SYS_reboot = 88;
94pub const SYS_readdir = 89;
95pub const SYS_mmap = 90;
96pub const SYS_munmap = 91;
97pub const SYS_truncate = 92;
98pub const SYS_ftruncate = 93;
99pub const SYS_fchmod = 94;
100pub const SYS_fchown = 95;
101pub const SYS_getpriority = 96;
102pub const SYS_setpriority = 97;
103pub const SYS_profil = 98;
104pub const SYS_statfs = 99;
105pub const SYS_fstatfs = 100;
106pub const SYS_ioperm = 101;
107pub const SYS_socketcall = 102;
108pub const SYS_syslog = 103;
109pub const SYS_setitimer = 104;
110pub const SYS_getitimer = 105;
111pub const SYS_stat = 106;
112pub const SYS_lstat = 107;
113pub const SYS_fstat = 108;
114pub const SYS_olduname = 109;
115pub const SYS_iopl = 110;
116pub const SYS_vhangup = 111;
117pub const SYS_idle = 112;
118pub const SYS_vm86old = 113;
119pub const SYS_wait4 = 114;
120pub const SYS_swapoff = 115;
121pub const SYS_sysinfo = 116;
122pub const SYS_ipc = 117;
123pub const SYS_fsync = 118;
124pub const SYS_sigreturn = 119;
125pub const SYS_clone = 120;
126pub const SYS_setdomainname = 121;
127pub const SYS_uname = 122;
128pub const SYS_modify_ldt = 123;
129pub const SYS_adjtimex = 124;
130pub const SYS_mprotect = 125;
131pub const SYS_sigprocmask = 126;
132pub const SYS_create_module = 127;
133pub const SYS_init_module = 128;
134pub const SYS_delete_module = 129;
135pub const SYS_get_kernel_syms = 130;
136pub const SYS_quotactl = 131;
137pub const SYS_getpgid = 132;
138pub const SYS_fchdir = 133;
139pub const SYS_bdflush = 134;
140pub const SYS_sysfs = 135;
141pub const SYS_personality = 136;
142pub const SYS_afs_syscall = 137;
143pub const SYS_setfsuid = 138;
144pub const SYS_setfsgid = 139;
145pub const SYS__llseek = 140;
146pub const SYS_getdents = 141;
147pub const SYS__newselect = 142;
148pub const SYS_flock = 143;
149pub const SYS_msync = 144;
150pub const SYS_readv = 145;
151pub const SYS_writev = 146;
152pub const SYS_getsid = 147;
153pub const SYS_fdatasync = 148;
154pub const SYS__sysctl = 149;
155pub const SYS_mlock = 150;
156pub const SYS_munlock = 151;
157pub const SYS_mlockall = 152;
158pub const SYS_munlockall = 153;
159pub const SYS_sched_setparam = 154;
160pub const SYS_sched_getparam = 155;
161pub const SYS_sched_setscheduler = 156;
162pub const SYS_sched_getscheduler = 157;
163pub const SYS_sched_yield = 158;
164pub const SYS_sched_get_priority_max = 159;
165pub const SYS_sched_get_priority_min = 160;
166pub const SYS_sched_rr_get_interval = 161;
167pub const SYS_nanosleep = 162;
168pub const SYS_mremap = 163;
169pub const SYS_setresuid = 164;
170pub const SYS_getresuid = 165;
171pub const SYS_vm86 = 166;
172pub const SYS_query_module = 167;
173pub const SYS_poll = 168;
174pub const SYS_nfsservctl = 169;
175pub const SYS_setresgid = 170;
176pub const SYS_getresgid = 171;
177pub const SYS_prctl = 172;
178pub const SYS_rt_sigreturn = 173;
179pub const SYS_rt_sigaction = 174;
180pub const SYS_rt_sigprocmask = 175;
181pub const SYS_rt_sigpending = 176;
182pub const SYS_rt_sigtimedwait = 177;
183pub const SYS_rt_sigqueueinfo = 178;
184pub const SYS_rt_sigsuspend = 179;
185pub const SYS_pread64 = 180;
186pub const SYS_pwrite64 = 181;
187pub const SYS_chown = 182;
188pub const SYS_getcwd = 183;
189pub const SYS_capget = 184;
190pub const SYS_capset = 185;
191pub const SYS_sigaltstack = 186;
192pub const SYS_sendfile = 187;
193pub const SYS_getpmsg = 188;
194pub const SYS_putpmsg = 189;
195pub const SYS_vfork = 190;
196pub const SYS_ugetrlimit = 191;
197pub const SYS_mmap2 = 192;
198pub const SYS_truncate64 = 193;
199pub const SYS_ftruncate64 = 194;
200pub const SYS_stat64 = 195;
201pub const SYS_lstat64 = 196;
202pub const SYS_fstat64 = 197;
203pub const SYS_lchown32 = 198;
204pub const SYS_getuid32 = 199;
205pub const SYS_getgid32 = 200;
206pub const SYS_geteuid32 = 201;
207pub const SYS_getegid32 = 202;
208pub const SYS_setreuid32 = 203;
209pub const SYS_setregid32 = 204;
210pub const SYS_getgroups32 = 205;
211pub const SYS_setgroups32 = 206;
212pub const SYS_fchown32 = 207;
213pub const SYS_setresuid32 = 208;
214pub const SYS_getresuid32 = 209;
215pub const SYS_setresgid32 = 210;
216pub const SYS_getresgid32 = 211;
217pub const SYS_chown32 = 212;
218pub const SYS_setuid32 = 213;
219pub const SYS_setgid32 = 214;
220pub const SYS_setfsuid32 = 215;
221pub const SYS_setfsgid32 = 216;
222pub const SYS_pivot_root = 217;
223pub const SYS_mincore = 218;
224pub const SYS_madvise = 219;
225pub const SYS_madvise1 = 219;
226pub const SYS_getdents64 = 220;
227pub const SYS_fcntl64 = 221;
228pub const SYS_gettid = 224;
229pub const SYS_readahead = 225;
230pub const SYS_setxattr = 226;
231pub const SYS_lsetxattr = 227;
232pub const SYS_fsetxattr = 228;
233pub const SYS_getxattr = 229;
234pub const SYS_lgetxattr = 230;
235pub const SYS_fgetxattr = 231;
236pub const SYS_listxattr = 232;
237pub const SYS_llistxattr = 233;
238pub const SYS_flistxattr = 234;
239pub const SYS_removexattr = 235;
240pub const SYS_lremovexattr = 236;
241pub const SYS_fremovexattr = 237;
242pub const SYS_tkill = 238;
243pub const SYS_sendfile64 = 239;
244pub const SYS_futex = 240;
245pub const SYS_sched_setaffinity = 241;
246pub const SYS_sched_getaffinity = 242;
247pub const SYS_set_thread_area = 243;
248pub const SYS_get_thread_area = 244;
249pub const SYS_io_setup = 245;
250pub const SYS_io_destroy = 246;
251pub const SYS_io_getevents = 247;
252pub const SYS_io_submit = 248;
253pub const SYS_io_cancel = 249;
254pub const SYS_fadvise64 = 250;
255pub const SYS_exit_group = 252;
256pub const SYS_lookup_dcookie = 253;
257pub const SYS_epoll_create = 254;
258pub const SYS_epoll_ctl = 255;
259pub const SYS_epoll_wait = 256;
260pub const SYS_remap_file_pages = 257;
261pub const SYS_set_tid_address = 258;
262pub const SYS_timer_create = 259;
263pub const SYS_timer_settime = SYS_timer_create+1;
264pub const SYS_timer_gettime = SYS_timer_create+2;
265pub const SYS_timer_getoverrun = SYS_timer_create+3;
266pub const SYS_timer_delete = SYS_timer_create+4;
267pub const SYS_clock_settime = SYS_timer_create+5;
268pub const SYS_clock_gettime = SYS_timer_create+6;
269pub const SYS_clock_getres = SYS_timer_create+7;
270pub const SYS_clock_nanosleep = SYS_timer_create+8;
271pub const SYS_statfs64 = 268;
272pub const SYS_fstatfs64 = 269;
273pub const SYS_tgkill = 270;
274pub const SYS_utimes = 271;
275pub const SYS_fadvise64_64 = 272;
276pub const SYS_vserver = 273;
277pub const SYS_mbind = 274;
278pub const SYS_get_mempolicy = 275;
279pub const SYS_set_mempolicy = 276;
280pub const SYS_mq_open = 277;
281pub const SYS_mq_unlink = SYS_mq_open+1;
282pub const SYS_mq_timedsend = SYS_mq_open+2;
283pub const SYS_mq_timedreceive = SYS_mq_open+3;
284pub const SYS_mq_notify = SYS_mq_open+4;
285pub const SYS_mq_getsetattr = SYS_mq_open+5;
286pub const SYS_kexec_load = 283;
287pub const SYS_waitid = 284;
288pub const SYS_add_key = 286;
289pub const SYS_request_key = 287;
290pub const SYS_keyctl = 288;
291pub const SYS_ioprio_set = 289;
292pub const SYS_ioprio_get = 290;
293pub const SYS_inotify_init = 291;
294pub const SYS_inotify_add_watch = 292;
295pub const SYS_inotify_rm_watch = 293;
296pub const SYS_migrate_pages = 294;
297pub const SYS_openat = 295;
298pub const SYS_mkdirat = 296;
299pub const SYS_mknodat = 297;
300pub const SYS_fchownat = 298;
301pub const SYS_futimesat = 299;
302pub const SYS_fstatat64 = 300;
303pub const SYS_unlinkat = 301;
304pub const SYS_renameat = 302;
305pub const SYS_linkat = 303;
306pub const SYS_symlinkat = 304;
307pub const SYS_readlinkat = 305;
308pub const SYS_fchmodat = 306;
309pub const SYS_faccessat = 307;
310pub const SYS_pselect6 = 308;
311pub const SYS_ppoll = 309;
312pub const SYS_unshare = 310;
313pub const SYS_set_robust_list = 311;
314pub const SYS_get_robust_list = 312;
315pub const SYS_splice = 313;
316pub const SYS_sync_file_range = 314;
317pub const SYS_tee = 315;
318pub const SYS_vmsplice = 316;
319pub const SYS_move_pages = 317;
320pub const SYS_getcpu = 318;
321pub const SYS_epoll_pwait = 319;
322pub const SYS_utimensat = 320;
323pub const SYS_signalfd = 321;
324pub const SYS_timerfd_create = 322;
325pub const SYS_eventfd = 323;
326pub const SYS_fallocate = 324;
327pub const SYS_timerfd_settime = 325;
328pub const SYS_timerfd_gettime = 326;
329pub const SYS_signalfd4 = 327;
330pub const SYS_eventfd2 = 328;
331pub const SYS_epoll_create1 = 329;
332pub const SYS_dup3 = 330;
333pub const SYS_pipe2 = 331;
334pub const SYS_inotify_init1 = 332;
335pub const SYS_preadv = 333;
336pub const SYS_pwritev = 334;
337pub const SYS_rt_tgsigqueueinfo = 335;
338pub const SYS_perf_event_open = 336;
339pub const SYS_recvmmsg = 337;
340pub const SYS_fanotify_init = 338;
341pub const SYS_fanotify_mark = 339;
342pub const SYS_prlimit64 = 340;
343pub const SYS_name_to_handle_at = 341;
344pub const SYS_open_by_handle_at = 342;
345pub const SYS_clock_adjtime = 343;
346pub const SYS_syncfs = 344;
347pub const SYS_sendmmsg = 345;
348pub const SYS_setns = 346;
349pub const SYS_process_vm_readv = 347;
350pub const SYS_process_vm_writev = 348;
351pub const SYS_kcmp = 349;
352pub const SYS_finit_module = 350;
353pub const SYS_sched_setattr = 351;
354pub const SYS_sched_getattr = 352;
355pub const SYS_renameat2 = 353;
356pub const SYS_seccomp = 354;
357pub const SYS_getrandom = 355;
358pub const SYS_memfd_create = 356;
359pub const SYS_bpf = 357;
360pub const SYS_execveat = 358;
361pub const SYS_socket = 359;
362pub const SYS_socketpair = 360;
363pub const SYS_bind = 361;
364pub const SYS_connect = 362;
365pub const SYS_listen = 363;
366pub const SYS_accept4 = 364;
367pub const SYS_getsockopt = 365;
368pub const SYS_setsockopt = 366;
369pub const SYS_getsockname = 367;
370pub const SYS_getpeername = 368;
371pub const SYS_sendto = 369;
372pub const SYS_sendmsg = 370;
373pub const SYS_recvfrom = 371;
374pub const SYS_recvmsg = 372;
375pub const SYS_shutdown = 373;
376pub const SYS_userfaultfd = 374;
377pub const SYS_membarrier = 375;
378pub const SYS_mlock2 = 376;
379
380
381pub const O_CREAT = 0o100;
382pub const O_EXCL = 0o200;
383pub const O_NOCTTY = 0o400;
384pub const O_TRUNC = 0o1000;
385pub const O_APPEND = 0o2000;
386pub const O_NONBLOCK = 0o4000;
387pub const O_DSYNC = 0o10000;
388pub const O_SYNC = 0o4010000;
389pub const O_RSYNC = 0o4010000;
390pub const O_DIRECTORY = 0o200000;
391pub const O_NOFOLLOW = 0o400000;
392pub const O_CLOEXEC = 0o2000000;
393
394pub const O_ASYNC = 0o20000;
395pub const O_DIRECT = 0o40000;
396pub const O_LARGEFILE = 0o100000;
397pub const O_NOATIME = 0o1000000;
398pub const O_PATH = 0o10000000;
399pub const O_TMPFILE = 0o20200000;
400pub const O_NDELAY = O_NONBLOCK;
401
402pub const F_DUPFD = 0;
403pub const F_GETFD = 1;
404pub const F_SETFD = 2;
405pub const F_GETFL = 3;
406pub const F_SETFL = 4;
407
408pub const F_SETOWN = 8;
409pub const F_GETOWN = 9;
410pub const F_SETSIG = 10;
411pub const F_GETSIG = 11;
412
413pub const F_GETLK = 12;
414pub const F_SETLK = 13;
415pub const F_SETLKW = 14;
416
417pub const F_SETOWN_EX = 15;
418pub const F_GETOWN_EX = 16;
419
420pub const F_GETOWNER_UIDS = 17;
421
422pub inline fn syscall0(number: usize) -> usize {
423 asm volatile ("int 80h"
424 : [ret] "={eax}" (-> usize)
425 : [number] "{eax}" (number))
426}
427
428pub inline fn syscall1(number: usize, arg1: usize) -> usize {
429 asm volatile ("int 80h"
430 : [ret] "={eax}" (-> usize)
431 : [number] "{eax}" (number),
432 [arg1] "{ebx}" (arg1))
433}
434
435pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize {
436 asm volatile ("int 80h"
437 : [ret] "={eax}" (-> usize)
438 : [number] "{eax}" (number),
439 [arg1] "{ebx}" (arg1),
440 [arg2] "{ecx}" (arg2))
441}
442
443pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize {
444 asm volatile ("int 80h"
445 : [ret] "={eax}" (-> usize)
446 : [number] "{eax}" (number),
447 [arg1] "{ebx}" (arg1),
448 [arg2] "{ecx}" (arg2),
449 [arg3] "{edx}" (arg3))
450}
451
452pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) -> usize {
453 asm volatile ("int 80h"
454 : [ret] "={eax}" (-> usize)
455 : [number] "{eax}" (number),
456 [arg1] "{ebx}" (arg1),
457 [arg2] "{ecx}" (arg2),
458 [arg3] "{edx}" (arg3),
459 [arg4] "{esi}" (arg4))
460}
461
462pub inline fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize,
463 arg4: usize, arg5: usize) -> usize
464{
465 asm volatile ("int 80h"
466 : [ret] "={eax}" (-> usize)
467 : [number] "{eax}" (number),
468 [arg1] "{ebx}" (arg1),
469 [arg2] "{ecx}" (arg2),
470 [arg3] "{edx}" (arg3),
471 [arg4] "{esi}" (arg4),
472 [arg5] "{edi}" (arg5))
473}
474
475pub inline fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize,
476 arg4: usize, arg5: usize, arg6: usize) -> usize
477{
478 asm volatile ("int 80h"
479 : [ret] "={eax}" (-> usize)
480 : [number] "{eax}" (number),
481 [arg1] "{ebx}" (arg1),
482 [arg2] "{ecx}" (arg2),
483 [arg3] "{edx}" (arg3),
484 [arg4] "{esi}" (arg4),
485 [arg5] "{edi}" (arg5),
486 [arg6] "{ebp}" (arg6))
487}
488
489export struct msghdr {
490 msg_name: &u8,
491 msg_namelen: socklen_t,
492 msg_iov: &iovec,
493 msg_iovlen: i32,
494 msg_control: &u8,
495 msg_controllen: socklen_t,
496 msg_flags: i32,
497}
std/os/linux_x86_64.zig created+480
......@@ -0,0 +1,480 @@
1const linux = @import("linux.zig");
2const socklen_t = linux.socklen_t;
3const iovec = linux.iovec;
4
5pub const SYS_read = 0;
6pub const SYS_write = 1;
7pub const SYS_open = 2;
8pub const SYS_close = 3;
9pub const SYS_stat = 4;
10pub const SYS_fstat = 5;
11pub const SYS_lstat = 6;
12pub const SYS_poll = 7;
13pub const SYS_lseek = 8;
14pub const SYS_mmap = 9;
15pub const SYS_mprotect = 10;
16pub const SYS_munmap = 11;
17pub const SYS_brk = 12;
18pub const SYS_rt_sigaction = 13;
19pub const SYS_rt_sigprocmask = 14;
20pub const SYS_rt_sigreturn = 15;
21pub const SYS_ioctl = 16;
22pub const SYS_pread = 17;
23pub const SYS_pwrite = 18;
24pub const SYS_readv = 19;
25pub const SYS_writev = 20;
26pub const SYS_access = 21;
27pub const SYS_pipe = 22;
28pub const SYS_select = 23;
29pub const SYS_sched_yield = 24;
30pub const SYS_mremap = 25;
31pub const SYS_msync = 26;
32pub const SYS_mincore = 27;
33pub const SYS_madvise = 28;
34pub const SYS_shmget = 29;
35pub const SYS_shmat = 30;
36pub const SYS_shmctl = 31;
37pub const SYS_dup = 32;
38pub const SYS_dup2 = 33;
39pub const SYS_pause = 34;
40pub const SYS_nanosleep = 35;
41pub const SYS_getitimer = 36;
42pub const SYS_alarm = 37;
43pub const SYS_setitimer = 38;
44pub const SYS_getpid = 39;
45pub const SYS_sendfile = 40;
46pub const SYS_socket = 41;
47pub const SYS_connect = 42;
48pub const SYS_accept = 43;
49pub const SYS_sendto = 44;
50pub const SYS_recvfrom = 45;
51pub const SYS_sendmsg = 46;
52pub const SYS_recvmsg = 47;
53pub const SYS_shutdown = 48;
54pub const SYS_bind = 49;
55pub const SYS_listen = 50;
56pub const SYS_getsockname = 51;
57pub const SYS_getpeername = 52;
58pub const SYS_socketpair = 53;
59pub const SYS_setsockopt = 54;
60pub const SYS_getsockopt = 55;
61pub const SYS_clone = 56;
62pub const SYS_fork = 57;
63pub const SYS_vfork = 58;
64pub const SYS_execve = 59;
65pub const SYS_exit = 60;
66pub const SYS_wait4 = 61;
67pub const SYS_kill = 62;
68pub const SYS_uname = 63;
69pub const SYS_semget = 64;
70pub const SYS_semop = 65;
71pub const SYS_semctl = 66;
72pub const SYS_shmdt = 67;
73pub const SYS_msgget = 68;
74pub const SYS_msgsnd = 69;
75pub const SYS_msgrcv = 70;
76pub const SYS_msgctl = 71;
77pub const SYS_fcntl = 72;
78pub const SYS_flock = 73;
79pub const SYS_fsync = 74;
80pub const SYS_fdatasync = 75;
81pub const SYS_truncate = 76;
82pub const SYS_ftruncate = 77;
83pub const SYS_getdents = 78;
84pub const SYS_getcwd = 79;
85pub const SYS_chdir = 80;
86pub const SYS_fchdir = 81;
87pub const SYS_rename = 82;
88pub const SYS_mkdir = 83;
89pub const SYS_rmdir = 84;
90pub const SYS_creat = 85;
91pub const SYS_link = 86;
92pub const SYS_unlink = 87;
93pub const SYS_symlink = 88;
94pub const SYS_readlink = 89;
95pub const SYS_chmod = 90;
96pub const SYS_fchmod = 91;
97pub const SYS_chown = 92;
98pub const SYS_fchown = 93;
99pub const SYS_lchown = 94;
100pub const SYS_umask = 95;
101pub const SYS_gettimeofday = 96;
102pub const SYS_getrlimit = 97;
103pub const SYS_getrusage = 98;
104pub const SYS_sysinfo = 99;
105pub const SYS_times = 100;
106pub const SYS_ptrace = 101;
107pub const SYS_getuid = 102;
108pub const SYS_syslog = 103;
109pub const SYS_getgid = 104;
110pub const SYS_setuid = 105;
111pub const SYS_setgid = 106;
112pub const SYS_geteuid = 107;
113pub const SYS_getegid = 108;
114pub const SYS_setpgid = 109;
115pub const SYS_getppid = 110;
116pub const SYS_getpgrp = 111;
117pub const SYS_setsid = 112;
118pub const SYS_setreuid = 113;
119pub const SYS_setregid = 114;
120pub const SYS_getgroups = 115;
121pub const SYS_setgroups = 116;
122pub const SYS_setresuid = 117;
123pub const SYS_getresuid = 118;
124pub const SYS_setresgid = 119;
125pub const SYS_getresgid = 120;
126pub const SYS_getpgid = 121;
127pub const SYS_setfsuid = 122;
128pub const SYS_setfsgid = 123;
129pub const SYS_getsid = 124;
130pub const SYS_capget = 125;
131pub const SYS_capset = 126;
132pub const SYS_rt_sigpending = 127;
133pub const SYS_rt_sigtimedwait = 128;
134pub const SYS_rt_sigqueueinfo = 129;
135pub const SYS_rt_sigsuspend = 130;
136pub const SYS_sigaltstack = 131;
137pub const SYS_utime = 132;
138pub const SYS_mknod = 133;
139pub const SYS_uselib = 134;
140pub const SYS_personality = 135;
141pub const SYS_ustat = 136;
142pub const SYS_statfs = 137;
143pub const SYS_fstatfs = 138;
144pub const SYS_sysfs = 139;
145pub const SYS_getpriority = 140;
146pub const SYS_setpriority = 141;
147pub const SYS_sched_setparam = 142;
148pub const SYS_sched_getparam = 143;
149pub const SYS_sched_setscheduler = 144;
150pub const SYS_sched_getscheduler = 145;
151pub const SYS_sched_get_priority_max = 146;
152pub const SYS_sched_get_priority_min = 147;
153pub const SYS_sched_rr_get_interval = 148;
154pub const SYS_mlock = 149;
155pub const SYS_munlock = 150;
156pub const SYS_mlockall = 151;
157pub const SYS_munlockall = 152;
158pub const SYS_vhangup = 153;
159pub const SYS_modify_ldt = 154;
160pub const SYS_pivot_root = 155;
161pub const SYS__sysctl = 156;
162pub const SYS_prctl = 157;
163pub const SYS_arch_prctl = 158;
164pub const SYS_adjtimex = 159;
165pub const SYS_setrlimit = 160;
166pub const SYS_chroot = 161;
167pub const SYS_sync = 162;
168pub const SYS_acct = 163;
169pub const SYS_settimeofday = 164;
170pub const SYS_mount = 165;
171pub const SYS_umount2 = 166;
172pub const SYS_swapon = 167;
173pub const SYS_swapoff = 168;
174pub const SYS_reboot = 169;
175pub const SYS_sethostname = 170;
176pub const SYS_setdomainname = 171;
177pub const SYS_iopl = 172;
178pub const SYS_ioperm = 173;
179pub const SYS_create_module = 174;
180pub const SYS_init_module = 175;
181pub const SYS_delete_module = 176;
182pub const SYS_get_kernel_syms = 177;
183pub const SYS_query_module = 178;
184pub const SYS_quotactl = 179;
185pub const SYS_nfsservctl = 180;
186pub const SYS_getpmsg = 181;
187pub const SYS_putpmsg = 182;
188pub const SYS_afs_syscall = 183;
189pub const SYS_tuxcall = 184;
190pub const SYS_security = 185;
191pub const SYS_gettid = 186;
192pub const SYS_readahead = 187;
193pub const SYS_setxattr = 188;
194pub const SYS_lsetxattr = 189;
195pub const SYS_fsetxattr = 190;
196pub const SYS_getxattr = 191;
197pub const SYS_lgetxattr = 192;
198pub const SYS_fgetxattr = 193;
199pub const SYS_listxattr = 194;
200pub const SYS_llistxattr = 195;
201pub const SYS_flistxattr = 196;
202pub const SYS_removexattr = 197;
203pub const SYS_lremovexattr = 198;
204pub const SYS_fremovexattr = 199;
205pub const SYS_tkill = 200;
206pub const SYS_time = 201;
207pub const SYS_futex = 202;
208pub const SYS_sched_setaffinity = 203;
209pub const SYS_sched_getaffinity = 204;
210pub const SYS_set_thread_area = 205;
211pub const SYS_io_setup = 206;
212pub const SYS_io_destroy = 207;
213pub const SYS_io_getevents = 208;
214pub const SYS_io_submit = 209;
215pub const SYS_io_cancel = 210;
216pub const SYS_get_thread_area = 211;
217pub const SYS_lookup_dcookie = 212;
218pub const SYS_epoll_create = 213;
219pub const SYS_epoll_ctl_old = 214;
220pub const SYS_epoll_wait_old = 215;
221pub const SYS_remap_file_pages = 216;
222pub const SYS_getdents64 = 217;
223pub const SYS_set_tid_address = 218;
224pub const SYS_restart_syscall = 219;
225pub const SYS_semtimedop = 220;
226pub const SYS_fadvise64 = 221;
227pub const SYS_timer_create = 222;
228pub const SYS_timer_settime = 223;
229pub const SYS_timer_gettime = 224;
230pub const SYS_timer_getoverrun = 225;
231pub const SYS_timer_delete = 226;
232pub const SYS_clock_settime = 227;
233pub const SYS_clock_gettime = 228;
234pub const SYS_clock_getres = 229;
235pub const SYS_clock_nanosleep = 230;
236pub const SYS_exit_group = 231;
237pub const SYS_epoll_wait = 232;
238pub const SYS_epoll_ctl = 233;
239pub const SYS_tgkill = 234;
240pub const SYS_utimes = 235;
241pub const SYS_vserver = 236;
242pub const SYS_mbind = 237;
243pub const SYS_set_mempolicy = 238;
244pub const SYS_get_mempolicy = 239;
245pub const SYS_mq_open = 240;
246pub const SYS_mq_unlink = 241;
247pub const SYS_mq_timedsend = 242;
248pub const SYS_mq_timedreceive = 243;
249pub const SYS_mq_notify = 244;
250pub const SYS_mq_getsetattr = 245;
251pub const SYS_kexec_load = 246;
252pub const SYS_waitid = 247;
253pub const SYS_add_key = 248;
254pub const SYS_request_key = 249;
255pub const SYS_keyctl = 250;
256pub const SYS_ioprio_set = 251;
257pub const SYS_ioprio_get = 252;
258pub const SYS_inotify_init = 253;
259pub const SYS_inotify_add_watch = 254;
260pub const SYS_inotify_rm_watch = 255;
261pub const SYS_migrate_pages = 256;
262pub const SYS_openat = 257;
263pub const SYS_mkdirat = 258;
264pub const SYS_mknodat = 259;
265pub const SYS_fchownat = 260;
266pub const SYS_futimesat = 261;
267pub const SYS_newfstatat = 262;
268pub const SYS_unlinkat = 263;
269pub const SYS_renameat = 264;
270pub const SYS_linkat = 265;
271pub const SYS_symlinkat = 266;
272pub const SYS_readlinkat = 267;
273pub const SYS_fchmodat = 268;
274pub const SYS_faccessat = 269;
275pub const SYS_pselect6 = 270;
276pub const SYS_ppoll = 271;
277pub const SYS_unshare = 272;
278pub const SYS_set_robust_list = 273;
279pub const SYS_get_robust_list = 274;
280pub const SYS_splice = 275;
281pub const SYS_tee = 276;
282pub const SYS_sync_file_range = 277;
283pub const SYS_vmsplice = 278;
284pub const SYS_move_pages = 279;
285pub const SYS_utimensat = 280;
286pub const SYS_epoll_pwait = 281;
287pub const SYS_signalfd = 282;
288pub const SYS_timerfd_create = 283;
289pub const SYS_eventfd = 284;
290pub const SYS_fallocate = 285;
291pub const SYS_timerfd_settime = 286;
292pub const SYS_timerfd_gettime = 287;
293pub const SYS_accept4 = 288;
294pub const SYS_signalfd4 = 289;
295pub const SYS_eventfd2 = 290;
296pub const SYS_epoll_create1 = 291;
297pub const SYS_dup3 = 292;
298pub const SYS_pipe2 = 293;
299pub const SYS_inotify_init1 = 294;
300pub const SYS_preadv = 295;
301pub const SYS_pwritev = 296;
302pub const SYS_rt_tgsigqueueinfo = 297;
303pub const SYS_perf_event_open = 298;
304pub const SYS_recvmmsg = 299;
305pub const SYS_fanotify_init = 300;
306pub const SYS_fanotify_mark = 301;
307pub const SYS_prlimit64 = 302;
308pub const SYS_name_to_handle_at = 303;
309pub const SYS_open_by_handle_at = 304;
310pub const SYS_clock_adjtime = 305;
311pub const SYS_syncfs = 306;
312pub const SYS_sendmmsg = 307;
313pub const SYS_setns = 308;
314pub const SYS_getcpu = 309;
315pub const SYS_process_vm_readv = 310;
316pub const SYS_process_vm_writev = 311;
317pub const SYS_kcmp = 312;
318pub const SYS_finit_module = 313;
319pub const SYS_sched_setattr = 314;
320pub const SYS_sched_getattr = 315;
321pub const SYS_renameat2 = 316;
322pub const SYS_seccomp = 317;
323pub const SYS_getrandom = 318;
324pub const SYS_memfd_create = 319;
325pub const SYS_kexec_file_load = 320;
326pub const SYS_bpf = 321;
327pub const SYS_execveat = 322;
328pub const SYS_userfaultfd = 323;
329pub const SYS_membarrier = 324;
330pub const SYS_mlock2 = 325;
331
332pub const O_CREAT = 0o100;
333pub const O_EXCL = 0o200;
334pub const O_NOCTTY = 0o400;
335pub const O_TRUNC = 0o1000;
336pub const O_APPEND = 0o2000;
337pub const O_NONBLOCK = 0o4000;
338pub const O_DSYNC = 0o10000;
339pub const O_SYNC = 0o4010000;
340pub const O_RSYNC = 0o4010000;
341pub const O_DIRECTORY = 0o200000;
342pub const O_NOFOLLOW = 0o400000;
343pub const O_CLOEXEC = 0o2000000;
344
345pub const O_ASYNC = 0o20000;
346pub const O_DIRECT = 0o40000;
347pub const O_LARGEFILE = 0;
348pub const O_NOATIME = 0o1000000;
349pub const O_PATH = 0o10000000;
350pub const O_TMPFILE = 0o20200000;
351pub const O_NDELAY = O_NONBLOCK;
352
353pub const F_DUPFD = 0;
354pub const F_GETFD = 1;
355pub const F_SETFD = 2;
356pub const F_GETFL = 3;
357pub const F_SETFL = 4;
358
359pub const F_SETOWN = 8;
360pub const F_GETOWN = 9;
361pub const F_SETSIG = 10;
362pub const F_GETSIG = 11;
363
364pub const F_GETLK = 5;
365pub const F_SETLK = 6;
366pub const F_SETLKW = 7;
367
368pub const F_SETOWN_EX = 15;
369pub const F_GETOWN_EX = 16;
370
371pub const F_GETOWNER_UIDS = 17;
372
373pub inline fn syscall0(number: usize) -> usize {
374 asm volatile ("syscall"
375 : [ret] "={rax}" (-> usize)
376 : [number] "{rax}" (number)
377 : "rcx", "r11")
378}
379
380pub inline fn syscall1(number: usize, arg1: usize) -> usize {
381 asm volatile ("syscall"
382 : [ret] "={rax}" (-> usize)
383 : [number] "{rax}" (number),
384 [arg1] "{rdi}" (arg1)
385 : "rcx", "r11")
386}
387
388pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize {
389 asm volatile ("syscall"
390 : [ret] "={rax}" (-> usize)
391 : [number] "{rax}" (number),
392 [arg1] "{rdi}" (arg1),
393 [arg2] "{rsi}" (arg2)
394 : "rcx", "r11")
395}
396
397pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize {
398 asm volatile ("syscall"
399 : [ret] "={rax}" (-> usize)
400 : [number] "{rax}" (number),
401 [arg1] "{rdi}" (arg1),
402 [arg2] "{rsi}" (arg2),
403 [arg3] "{rdx}" (arg3)
404 : "rcx", "r11")
405}
406
407pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) -> usize {
408 asm volatile ("syscall"
409 : [ret] "={rax}" (-> usize)
410 : [number] "{rax}" (number),
411 [arg1] "{rdi}" (arg1),
412 [arg2] "{rsi}" (arg2),
413 [arg3] "{rdx}" (arg3),
414 [arg4] "{r10}" (arg4)
415 : "rcx", "r11")
416}
417
418pub inline fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) -> usize {
419 asm volatile ("syscall"
420 : [ret] "={rax}" (-> usize)
421 : [number] "{rax}" (number),
422 [arg1] "{rdi}" (arg1),
423 [arg2] "{rsi}" (arg2),
424 [arg3] "{rdx}" (arg3),
425 [arg4] "{r10}" (arg4),
426 [arg5] "{r8}" (arg5)
427 : "rcx", "r11")
428}
429
430pub inline fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize,
431 arg5: usize, arg6: usize) -> usize
432{
433 asm volatile ("syscall"
434 : [ret] "={rax}" (-> usize)
435 : [number] "{rax}" (number),
436 [arg1] "{rdi}" (arg1),
437 [arg2] "{rsi}" (arg2),
438 [arg3] "{rdx}" (arg3),
439 [arg4] "{r10}" (arg4),
440 [arg5] "{r8}" (arg5),
441 [arg6] "{r9}" (arg6)
442 : "rcx", "r11")
443}
444
445pub const msghdr = extern struct {
446 msg_name: &u8,
447 msg_namelen: socklen_t,
448 msg_iov: &iovec,
449 msg_iovlen: i32,
450 __pad1: i32,
451 msg_control: &u8,
452 msg_controllen: socklen_t,
453 __pad2: socklen_t,
454 msg_flags: i32,
455};
456
457pub const stat = extern struct {
458 dev: u64,
459 ino: u64,
460 nlink: usize,
461
462 mode: u32,
463 uid: u32,
464 gid: u32,
465 __pad0: u32,
466 rdev: u64,
467 size: i64,
468 blksize: isize,
469 blocks: i64,
470
471 atim: timespec,
472 mtim: timespec,
473 ctim: timespec,
474 __unused: [3]isize,
475};
476
477pub const timespec = extern struct {
478 tv_sec: isize,
479 tv_nsec: isize,
480};
std/os/windows.zig created+17
......@@ -0,0 +1,17 @@
1pub extern fn CryptAcquireContext(phProv: &HCRYPTPROV, pszContainer: LPCTSTR,
2 pszProvider: LPCTSTR, dwProvType: DWORD, dwFlags: DWORD) -> bool;
3
4pub extern fn CryptReleaseContext(hProv: HCRYPTPROV, dwFlags: DWORD) -> bool;
5
6pub extern fn CryptGenRandom(hProv: HCRYPTPROV, dwLen: DWORD, pbBuffer: &BYTE) -> bool;
7
8pub const PROV_RSA_FULL = 1;
9
10
11pub const BYTE = u8;
12pub const DWORD = u32;
13// TODO something about unicode WCHAR vs char
14pub const TCHAR = u8;
15pub const LPCTSTR = ?&const TCHAR;
16pub const ULONG_PTR = usize;
17pub const HCRYPTPROV = ULONG_PTR;
std/panic.zig deleted-12
......@@ -1,12 +0,0 @@
1// This file is included if and only if the user's main source file does not
2// include a public panic function.
3// If this file wants to import other files *by name*, support for that would
4// have to be added in the compiler.
5
6pub coldcc fn panic(message: []const u8) -> noreturn {
7 if (@compileVar("os") == Os.freestanding) {
8 while (true) {}
9 } else {
10 @import("std").debug.panic(message);
11 }
12}
std/special/bootstrap.zig created+59
......@@ -0,0 +1,59 @@
1// This file is in a package which has the root source file exposed as "@root".
2// It is included in the compilation unit when exporting an executable.
3
4const root = @import("@root");
5const std = @import("std");
6
7const want_main_symbol = std.target.linking_libc;
8const want_start_symbol = !want_main_symbol;
9
10const exit = std.os.posix.exit;
11
12var argc: usize = undefined;
13var argv: &&u8 = undefined;
14
15export nakedcc fn _start() -> noreturn {
16 @setFnVisible(this, want_start_symbol);
17 if (!want_start_symbol) {
18 unreachable;
19 }
20
21 switch (@compileVar("arch")) {
22 Arch.x86_64 => {
23 argc = asm("mov %[argc], [rsp]": [argc] "=r" (-> usize));
24 argv = asm("lea %[argv], [rsp + 8h]": [argv] "=r" (-> &&u8));
25 },
26 Arch.i386 => {
27 argc = asm("mov %[argc], [esp]": [argc] "=r" (-> usize));
28 argv = asm("lea %[argv], [esp + 4h]": [argv] "=r" (-> &&u8));
29 },
30 else => @compileError("unsupported arch"),
31 }
32 callMainAndExit()
33}
34
35fn callMain() -> %void {
36 const args = @alloca([]u8, argc);
37 for (args) |_, i| {
38 const ptr = argv[i];
39 args[i] = ptr[0...std.cstr.len(ptr)];
40 }
41 return root.main(args);
42}
43
44fn callMainAndExit() -> noreturn {
45 callMain() %% exit(1);
46 exit(0);
47}
48
49export fn main(c_argc: i32, c_argv: &&u8) -> i32 {
50 @setFnVisible(this, want_main_symbol);
51 if (!want_main_symbol) {
52 unreachable;
53 }
54
55 argc = usize(c_argc);
56 argv = c_argv;
57 callMain() %% return 1;
58 return 0;
59}
std/special/builtin.zig created+36
......@@ -0,0 +1,36 @@
1// These functions are provided when not linking against libc because LLVM
2// sometimes generates code that calls them.
3
4// Note that these functions do not return `dest`, like the libc API.
5// The semantics of these functions is dictated by the corresponding
6// LLVM intrinsics, not by the libc API.
7
8export fn memset(dest: ?&u8, c: u8, n: usize) {
9 @setDebugSafety(this, false);
10
11 if (n == 0)
12 return;
13
14 const d = ??dest;
15 var index: usize = 0;
16 while (index != n; index += 1)
17 d[index] = c;
18}
19
20export fn memcpy(noalias dest: ?&u8, noalias src: ?&const u8, n: usize) {
21 @setDebugSafety(this, false);
22
23 if (n == 0)
24 return;
25
26 const d = ??dest;
27 const s = ??src;
28 var index: usize = 0;
29 while (index != n; index += 1)
30 d[index] = s[index];
31}
32
33// Avoid dragging in the debug safety mechanisms into this .o file.
34pub fn panic(message: []const u8) -> noreturn {
35 unreachable;
36}
std/special/compiler_rt.zig created+515
......@@ -0,0 +1,515 @@
1// Avoid dragging in the debug safety mechanisms into this .o file,
2// unless we're trying to test this file.
3pub fn panic(message: []const u8) -> noreturn {
4 if (@compileVar("is_test")) {
5 @import("std").debug.panic(message);
6 } else {
7 unreachable;
8 }
9}
10
11const CHAR_BIT = 8;
12const du_int = u64;
13const di_int = i64;
14const si_int = c_int;
15const su_int = c_uint;
16
17const udwords = [2]su_int;
18const low = if (@compileVar("is_big_endian")) 1 else 0;
19const high = 1 - low;
20
21export fn __udivdi3(a: du_int, b: du_int) -> du_int {
22 @setDebugSafety(this, false);
23 return __udivmoddi4(a, b, null);
24}
25
26fn du_int_to_udwords(x: du_int) -> udwords {
27 @setDebugSafety(this, false);
28 return *(&udwords)(&x);
29}
30
31export fn __udivmoddi4(a: du_int, b: du_int, maybe_rem: ?&du_int) -> du_int {
32 @setDebugSafety(this, false);
33
34 const n_uword_bits = @sizeOf(su_int) * CHAR_BIT;
35 const n_udword_bits = @sizeOf(du_int) * CHAR_BIT;
36 var n = du_int_to_udwords(a);
37 var d = du_int_to_udwords(b);
38 var q: udwords = undefined;
39 var r: udwords = undefined;
40 var sr: c_uint = undefined;
41 // special cases, X is unknown, K != 0
42 if (n[high] == 0) {
43 if (d[high] == 0) {
44 // 0 X
45 // ---
46 // 0 X
47 if (const rem ?= maybe_rem) {
48 *rem = n[low] % d[low];
49 }
50 return n[low] / d[low];
51 }
52 // 0 X
53 // ---
54 // K X
55 if (const rem ?= maybe_rem) {
56 *rem = n[low];
57 }
58 return 0;
59 }
60 // n[high] != 0
61 if (d[low] == 0) {
62 if (d[high] == 0) {
63 // K X
64 // ---
65 // 0 0
66 if (var rem ?= maybe_rem) {
67 *rem = n[high] % d[low];
68 }
69 return n[high] / d[low];
70 }
71 // d[high] != 0
72 if (n[low] == 0) {
73 // K 0
74 // ---
75 // K 0
76 if (var rem ?= maybe_rem) {
77 r[high] = n[high] % d[high];
78 r[low] = 0;
79 *rem = *(&du_int)(&r[0]);
80 }
81 return n[high] / d[high];
82 }
83 // K K
84 // ---
85 // K 0
86 // if d is a power of 2
87 if ((d[high] & (d[high] - 1)) == 0) {
88 if (var rem ?= maybe_rem) {
89 r[low] = n[low];
90 r[high] = n[high] & (d[high] - 1);
91 *rem = *(&du_int)(&r[0]);
92 }
93 return n[high] >> @ctz(d[high]);
94 }
95 // K K
96 // ---
97 // K 0
98 sr = @clz(su_int(d[high])) - @clz(su_int(n[high]));
99 // 0 <= sr <= n_uword_bits - 2 or sr large
100 if (sr > n_uword_bits - 2) {
101 if (var rem ?= maybe_rem) {
102 *rem = *(&du_int)(&n[0]);
103 }
104 return 0;
105 }
106 sr += 1;
107 // 1 <= sr <= n_uword_bits - 1
108 // q.all = n.all << (n_udword_bits - sr);
109 q[low] = 0;
110 q[high] = n[low] << (n_uword_bits - sr);
111 // r.all = n.all >> sr;
112 r[high] = n[high] >> sr;
113 r[low] = (n[high] << (n_uword_bits - sr)) | (n[low] >> sr);
114 } else {
115 // d[low] != 0
116 if (d[high] == 0) {
117 // K X
118 // ---
119 // 0 K
120 // if d is a power of 2
121 if ((d[low] & (d[low] - 1)) == 0) {
122 if (var rem ?= maybe_rem) {
123 *rem = n[low] & (d[low] - 1);
124 }
125 if (d[low] == 1) {
126 return *(&du_int)(&n[0]);
127 }
128 sr = @ctz(d[low]);
129 q[high] = n[high] >> sr;
130 q[low] = (n[high] << (n_uword_bits - sr)) | (n[low] >> sr);
131 return *(&du_int)(&q[0]);
132 }
133 // K X
134 // ---
135 // 0 K
136 sr = 1 + n_uword_bits + @clz(su_int(d[low])) - @clz(su_int(n[high]));
137 // 2 <= sr <= n_udword_bits - 1
138 // q.all = n.all << (n_udword_bits - sr);
139 // r.all = n.all >> sr;
140 if (sr == n_uword_bits) {
141 q[low] = 0;
142 q[high] = n[low];
143 r[high] = 0;
144 r[low] = n[high];
145 } else if (sr < n_uword_bits) {
146 // 2 <= sr <= n_uword_bits - 1
147 q[low] = 0;
148 q[high] = n[low] << (n_uword_bits - sr);
149 r[high] = n[high] >> sr;
150 r[low] = (n[high] << (n_uword_bits - sr)) | (n[low] >> sr);
151 } else {
152 // n_uword_bits + 1 <= sr <= n_udword_bits - 1
153 q[low] = n[low] << (n_udword_bits - sr);
154 q[high] = (n[high] << (n_udword_bits - sr)) |
155 (n[low] >> (sr - n_uword_bits));
156 r[high] = 0;
157 r[low] = n[high] >> (sr - n_uword_bits);
158 }
159 } else {
160 // K X
161 // ---
162 // K K
163 sr = @clz(su_int(d[high])) - @clz(su_int(n[high]));
164 // 0 <= sr <= n_uword_bits - 1 or sr large
165 if (sr > n_uword_bits - 1) {
166 if (var rem ?= maybe_rem) {
167 *rem = *(&du_int)(&n[0]);
168 }
169 return 0;
170 }
171 sr += 1;
172 // 1 <= sr <= n_uword_bits
173 // q.all = n.all << (n_udword_bits - sr);
174 q[low] = 0;
175 if (sr == n_uword_bits) {
176 q[high] = n[low];
177 r[high] = 0;
178 r[low] = n[high];
179 } else {
180 q[high] = n[low] << (n_uword_bits - sr);
181 r[high] = n[high] >> sr;
182 r[low] = (n[high] << (n_uword_bits - sr)) | (n[low] >> sr);
183 }
184 }
185 }
186 // Not a special case
187 // q and r are initialized with:
188 // q.all = n.all << (n_udword_bits - sr);
189 // r.all = n.all >> sr;
190 // 1 <= sr <= n_udword_bits - 1
191 var carry: su_int = 0;
192 while (sr > 0) {
193 // r:q = ((r:q) << 1) | carry
194 r[high] = (r[high] << 1) | (r[low] >> (n_uword_bits - 1));
195 r[low] = (r[low] << 1) | (q[high] >> (n_uword_bits - 1));
196 q[high] = (q[high] << 1) | (q[low] >> (n_uword_bits - 1));
197 q[low] = (q[low] << 1) | carry;
198 // carry = 0;
199 // if (r.all >= d.all)
200 // {
201 // r.all -= d.all;
202 // carry = 1;
203 // }
204 const s: di_int = (di_int)(*(&du_int)(&d[0]) - *(&du_int)(&r[0]) - 1) >> (n_udword_bits - 1);
205 carry = su_int(s & 1);
206 *(&du_int)(&r[0]) -= *(&du_int)(&d[0]) & u64(s);
207
208 sr -= 1;
209 }
210 *(&du_int)(&q[0]) = (*(&du_int)(&q[0]) << 1) | u64(carry);
211 if (var rem ?= maybe_rem) {
212 *rem = *(&du_int)(&r[0]);
213 }
214 return *(&du_int)(&q[0]);
215}
216
217export fn __umoddi3(a: du_int, b: du_int) -> du_int {
218 @setDebugSafety(this, false);
219
220 var r: du_int = undefined;
221 _ = __udivmoddi4(a, b, &r);
222 return r;
223}
224
225fn isArmArch() -> bool {
226 return switch (@compileVar("arch")) {
227 Arch.armv8_2a,
228 Arch.armv8_1a,
229 Arch.armv8,
230 Arch.armv8m_baseline,
231 Arch.armv8m_mainline,
232 Arch.armv7,
233 Arch.armv7em,
234 Arch.armv7m,
235 Arch.armv7s,
236 Arch.armv7k,
237 Arch.armv6,
238 Arch.armv6m,
239 Arch.armv6k,
240 Arch.armv6t2,
241 Arch.armv5,
242 Arch.armv5te,
243 Arch.armv4t,
244 Arch.armeb => true,
245 else => false,
246 };
247}
248
249export nakedcc fn __aeabi_uidivmod() {
250 @setDebugSafety(this, false);
251
252 if (comptime isArmArch()) {
253 asm volatile (
254 \\ push { lr }
255 \\ sub sp, sp, #4
256 \\ mov r2, sp
257 \\ bl __udivmodsi4
258 \\ ldr r1, [sp]
259 \\ add sp, sp, #4
260 \\ pop { pc }
261 ::: "r2", "r1");
262 unreachable;
263 }
264
265 @setFnVisible(this, false);
266}
267
268export fn __udivmodsi4(a: su_int, b: su_int, rem: &su_int) -> su_int {
269 @setDebugSafety(this, false);
270
271 const d = __udivsi3(a, b);
272 *rem = su_int(si_int(a) -% (si_int(d) * si_int(b)));
273 return d;
274}
275
276
277// TODO make this an alias instead of an extra function call
278// https://github.com/andrewrk/zig/issues/256
279
280export fn __aeabi_uidiv(n: su_int, d: su_int) -> su_int {
281 @setDebugSafety(this, false);
282
283 return __udivsi3(n, d);
284}
285
286export fn __udivsi3(n: su_int, d: su_int) -> su_int {
287 @setDebugSafety(this, false);
288
289 const n_uword_bits: c_uint = @sizeOf(su_int) * CHAR_BIT;
290 // special cases
291 if (d == 0)
292 return 0; // ?!
293 if (n == 0)
294 return 0;
295 var sr: c_uint = @clz(d) - @clz(n);
296 // 0 <= sr <= n_uword_bits - 1 or sr large
297 if (sr > n_uword_bits - 1) // d > r
298 return 0;
299 if (sr == n_uword_bits - 1) // d == 1
300 return n;
301 sr += 1;
302 // 1 <= sr <= n_uword_bits - 1
303 // Not a special case
304 var q: su_int = n << (n_uword_bits - sr);
305 var r: su_int = n >> sr;
306 var carry: su_int = 0;
307 while (sr > 0; sr -= 1) {
308 // r:q = ((r:q) << 1) | carry
309 r = (r << 1) | (q >> (n_uword_bits - 1));
310 q = (q << 1) | carry;
311 // carry = 0;
312 // if (r.all >= d.all)
313 // {
314 // r.all -= d.all;
315 // carry = 1;
316 // }
317 const s = si_int(d - r - 1) >> si_int(n_uword_bits - 1);
318 carry = su_int(s & 1);
319 r -= d & su_int(s);
320 }
321 q = (q << 1) | carry;
322 return q;
323}
324
325test "test_umoddi3" {
326 test_one_umoddi3(0, 1, 0);
327 test_one_umoddi3(2, 1, 0);
328 test_one_umoddi3(0x8000000000000000, 1, 0x0);
329 test_one_umoddi3(0x8000000000000000, 2, 0x0);
330 test_one_umoddi3(0xFFFFFFFFFFFFFFFF, 2, 0x1);
331}
332
333fn test_one_umoddi3(a: du_int, b: du_int, expected_r: du_int) {
334 const r = __umoddi3(a, b);
335 assert(r == expected_r);
336}
337
338test "test_udivmoddi4" {
339 const cases = [][4]du_int {
340 []du_int{0x0000000000000000, 0x0000000000000001, 0x0000000000000000, 0x0000000000000000},
341 []du_int{0x0000000080000000, 0x0000000100000001, 0x0000000000000000, 0x0000000080000000},
342 []du_int{0x7FFFFFFF00000001, 0x0000000000000001, 0x7FFFFFFF00000001, 0x0000000000000000},
343 []du_int{0x7FFFFFFF7FFFFFFF, 0xFFFFFFFFFFFFFFFF, 0x0000000000000000, 0x7FFFFFFF7FFFFFFF},
344 []du_int{0x8000000000000002, 0xFFFFFFFFFFFFFFFE, 0x0000000000000000, 0x8000000000000002},
345 []du_int{0x80000000FFFFFFFD, 0xFFFFFFFFFFFFFFFD, 0x0000000000000000, 0x80000000FFFFFFFD},
346 []du_int{0xFFFFFFFD00000010, 0xFFFFFFFF80000000, 0x0000000000000000, 0xFFFFFFFD00000010},
347 []du_int{0xFFFFFFFDFFFFFFFF, 0xFFFFFFFF7FFFFFFF, 0x0000000000000000, 0xFFFFFFFDFFFFFFFF},
348 []du_int{0xFFFFFFFE0747AE14, 0xFFFFFFFF0747AE14, 0x0000000000000000, 0xFFFFFFFE0747AE14},
349 []du_int{0xFFFFFFFF00000001, 0xFFFFFFFF078644FA, 0x0000000000000000, 0xFFFFFFFF00000001},
350 []du_int{0xFFFFFFFF80000000, 0xFFFFFFFF00000010, 0x0000000000000001, 0x000000007FFFFFF0},
351 []du_int{0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0x0000000000000001, 0x0000000000000000},
352 };
353
354 for (cases) |case| {
355 test_one_udivmoddi4(case[0], case[1], case[2], case[3]);
356 }
357}
358
359fn test_one_udivmoddi4(a: du_int, b: du_int, expected_q: du_int, expected_r: du_int) {
360 var r: du_int = undefined;
361 const q = __udivmoddi4(a, b, &r);
362 assert(q == expected_q);
363 assert(r == expected_r);
364}
365
366test "test_udivsi3" {
367 const cases = [][3]su_int {
368 []su_int{0x00000000, 0x00000001, 0x00000000},
369 []su_int{0x00000000, 0x00000002, 0x00000000},
370 []su_int{0x00000000, 0x00000003, 0x00000000},
371 []su_int{0x00000000, 0x00000010, 0x00000000},
372 []su_int{0x00000000, 0x078644FA, 0x00000000},
373 []su_int{0x00000000, 0x0747AE14, 0x00000000},
374 []su_int{0x00000000, 0x7FFFFFFF, 0x00000000},
375 []su_int{0x00000000, 0x80000000, 0x00000000},
376 []su_int{0x00000000, 0xFFFFFFFD, 0x00000000},
377 []su_int{0x00000000, 0xFFFFFFFE, 0x00000000},
378 []su_int{0x00000000, 0xFFFFFFFF, 0x00000000},
379 []su_int{0x00000001, 0x00000001, 0x00000001},
380 []su_int{0x00000001, 0x00000002, 0x00000000},
381 []su_int{0x00000001, 0x00000003, 0x00000000},
382 []su_int{0x00000001, 0x00000010, 0x00000000},
383 []su_int{0x00000001, 0x078644FA, 0x00000000},
384 []su_int{0x00000001, 0x0747AE14, 0x00000000},
385 []su_int{0x00000001, 0x7FFFFFFF, 0x00000000},
386 []su_int{0x00000001, 0x80000000, 0x00000000},
387 []su_int{0x00000001, 0xFFFFFFFD, 0x00000000},
388 []su_int{0x00000001, 0xFFFFFFFE, 0x00000000},
389 []su_int{0x00000001, 0xFFFFFFFF, 0x00000000},
390 []su_int{0x00000002, 0x00000001, 0x00000002},
391 []su_int{0x00000002, 0x00000002, 0x00000001},
392 []su_int{0x00000002, 0x00000003, 0x00000000},
393 []su_int{0x00000002, 0x00000010, 0x00000000},
394 []su_int{0x00000002, 0x078644FA, 0x00000000},
395 []su_int{0x00000002, 0x0747AE14, 0x00000000},
396 []su_int{0x00000002, 0x7FFFFFFF, 0x00000000},
397 []su_int{0x00000002, 0x80000000, 0x00000000},
398 []su_int{0x00000002, 0xFFFFFFFD, 0x00000000},
399 []su_int{0x00000002, 0xFFFFFFFE, 0x00000000},
400 []su_int{0x00000002, 0xFFFFFFFF, 0x00000000},
401 []su_int{0x00000003, 0x00000001, 0x00000003},
402 []su_int{0x00000003, 0x00000002, 0x00000001},
403 []su_int{0x00000003, 0x00000003, 0x00000001},
404 []su_int{0x00000003, 0x00000010, 0x00000000},
405 []su_int{0x00000003, 0x078644FA, 0x00000000},
406 []su_int{0x00000003, 0x0747AE14, 0x00000000},
407 []su_int{0x00000003, 0x7FFFFFFF, 0x00000000},
408 []su_int{0x00000003, 0x80000000, 0x00000000},
409 []su_int{0x00000003, 0xFFFFFFFD, 0x00000000},
410 []su_int{0x00000003, 0xFFFFFFFE, 0x00000000},
411 []su_int{0x00000003, 0xFFFFFFFF, 0x00000000},
412 []su_int{0x00000010, 0x00000001, 0x00000010},
413 []su_int{0x00000010, 0x00000002, 0x00000008},
414 []su_int{0x00000010, 0x00000003, 0x00000005},
415 []su_int{0x00000010, 0x00000010, 0x00000001},
416 []su_int{0x00000010, 0x078644FA, 0x00000000},
417 []su_int{0x00000010, 0x0747AE14, 0x00000000},
418 []su_int{0x00000010, 0x7FFFFFFF, 0x00000000},
419 []su_int{0x00000010, 0x80000000, 0x00000000},
420 []su_int{0x00000010, 0xFFFFFFFD, 0x00000000},
421 []su_int{0x00000010, 0xFFFFFFFE, 0x00000000},
422 []su_int{0x00000010, 0xFFFFFFFF, 0x00000000},
423 []su_int{0x078644FA, 0x00000001, 0x078644FA},
424 []su_int{0x078644FA, 0x00000002, 0x03C3227D},
425 []su_int{0x078644FA, 0x00000003, 0x028216FE},
426 []su_int{0x078644FA, 0x00000010, 0x0078644F},
427 []su_int{0x078644FA, 0x078644FA, 0x00000001},
428 []su_int{0x078644FA, 0x0747AE14, 0x00000001},
429 []su_int{0x078644FA, 0x7FFFFFFF, 0x00000000},
430 []su_int{0x078644FA, 0x80000000, 0x00000000},
431 []su_int{0x078644FA, 0xFFFFFFFD, 0x00000000},
432 []su_int{0x078644FA, 0xFFFFFFFE, 0x00000000},
433 []su_int{0x078644FA, 0xFFFFFFFF, 0x00000000},
434 []su_int{0x0747AE14, 0x00000001, 0x0747AE14},
435 []su_int{0x0747AE14, 0x00000002, 0x03A3D70A},
436 []su_int{0x0747AE14, 0x00000003, 0x026D3A06},
437 []su_int{0x0747AE14, 0x00000010, 0x00747AE1},
438 []su_int{0x0747AE14, 0x078644FA, 0x00000000},
439 []su_int{0x0747AE14, 0x0747AE14, 0x00000001},
440 []su_int{0x0747AE14, 0x7FFFFFFF, 0x00000000},
441 []su_int{0x0747AE14, 0x80000000, 0x00000000},
442 []su_int{0x0747AE14, 0xFFFFFFFD, 0x00000000},
443 []su_int{0x0747AE14, 0xFFFFFFFE, 0x00000000},
444 []su_int{0x0747AE14, 0xFFFFFFFF, 0x00000000},
445 []su_int{0x7FFFFFFF, 0x00000001, 0x7FFFFFFF},
446 []su_int{0x7FFFFFFF, 0x00000002, 0x3FFFFFFF},
447 []su_int{0x7FFFFFFF, 0x00000003, 0x2AAAAAAA},
448 []su_int{0x7FFFFFFF, 0x00000010, 0x07FFFFFF},
449 []su_int{0x7FFFFFFF, 0x078644FA, 0x00000011},
450 []su_int{0x7FFFFFFF, 0x0747AE14, 0x00000011},
451 []su_int{0x7FFFFFFF, 0x7FFFFFFF, 0x00000001},
452 []su_int{0x7FFFFFFF, 0x80000000, 0x00000000},
453 []su_int{0x7FFFFFFF, 0xFFFFFFFD, 0x00000000},
454 []su_int{0x7FFFFFFF, 0xFFFFFFFE, 0x00000000},
455 []su_int{0x7FFFFFFF, 0xFFFFFFFF, 0x00000000},
456 []su_int{0x80000000, 0x00000001, 0x80000000},
457 []su_int{0x80000000, 0x00000002, 0x40000000},
458 []su_int{0x80000000, 0x00000003, 0x2AAAAAAA},
459 []su_int{0x80000000, 0x00000010, 0x08000000},
460 []su_int{0x80000000, 0x078644FA, 0x00000011},
461 []su_int{0x80000000, 0x0747AE14, 0x00000011},
462 []su_int{0x80000000, 0x7FFFFFFF, 0x00000001},
463 []su_int{0x80000000, 0x80000000, 0x00000001},
464 []su_int{0x80000000, 0xFFFFFFFD, 0x00000000},
465 []su_int{0x80000000, 0xFFFFFFFE, 0x00000000},
466 []su_int{0x80000000, 0xFFFFFFFF, 0x00000000},
467 []su_int{0xFFFFFFFD, 0x00000001, 0xFFFFFFFD},
468 []su_int{0xFFFFFFFD, 0x00000002, 0x7FFFFFFE},
469 []su_int{0xFFFFFFFD, 0x00000003, 0x55555554},
470 []su_int{0xFFFFFFFD, 0x00000010, 0x0FFFFFFF},
471 []su_int{0xFFFFFFFD, 0x078644FA, 0x00000022},
472 []su_int{0xFFFFFFFD, 0x0747AE14, 0x00000023},
473 []su_int{0xFFFFFFFD, 0x7FFFFFFF, 0x00000001},
474 []su_int{0xFFFFFFFD, 0x80000000, 0x00000001},
475 []su_int{0xFFFFFFFD, 0xFFFFFFFD, 0x00000001},
476 []su_int{0xFFFFFFFD, 0xFFFFFFFE, 0x00000000},
477 []su_int{0xFFFFFFFD, 0xFFFFFFFF, 0x00000000},
478 []su_int{0xFFFFFFFE, 0x00000001, 0xFFFFFFFE},
479 []su_int{0xFFFFFFFE, 0x00000002, 0x7FFFFFFF},
480 []su_int{0xFFFFFFFE, 0x00000003, 0x55555554},
481 []su_int{0xFFFFFFFE, 0x00000010, 0x0FFFFFFF},
482 []su_int{0xFFFFFFFE, 0x078644FA, 0x00000022},
483 []su_int{0xFFFFFFFE, 0x0747AE14, 0x00000023},
484 []su_int{0xFFFFFFFE, 0x7FFFFFFF, 0x00000002},
485 []su_int{0xFFFFFFFE, 0x80000000, 0x00000001},
486 []su_int{0xFFFFFFFE, 0xFFFFFFFD, 0x00000001},
487 []su_int{0xFFFFFFFE, 0xFFFFFFFE, 0x00000001},
488 []su_int{0xFFFFFFFE, 0xFFFFFFFF, 0x00000000},
489 []su_int{0xFFFFFFFF, 0x00000001, 0xFFFFFFFF},
490 []su_int{0xFFFFFFFF, 0x00000002, 0x7FFFFFFF},
491 []su_int{0xFFFFFFFF, 0x00000003, 0x55555555},
492 []su_int{0xFFFFFFFF, 0x00000010, 0x0FFFFFFF},
493 []su_int{0xFFFFFFFF, 0x078644FA, 0x00000022},
494 []su_int{0xFFFFFFFF, 0x0747AE14, 0x00000023},
495 []su_int{0xFFFFFFFF, 0x7FFFFFFF, 0x00000002},
496 []su_int{0xFFFFFFFF, 0x80000000, 0x00000001},
497 []su_int{0xFFFFFFFF, 0xFFFFFFFD, 0x00000001},
498 []su_int{0xFFFFFFFF, 0xFFFFFFFE, 0x00000001},
499 []su_int{0xFFFFFFFF, 0xFFFFFFFF, 0x00000001},
500 };
501
502 for (cases) |case| {
503 test_one_udivsi3(case[0], case[1], case[2]);
504 }
505}
506
507fn test_one_udivsi3(a: su_int, b: su_int, expected_q: su_int) {
508 const q: su_int = __udivsi3(a, b);
509 assert(q == expected_q);
510}
511
512
513fn assert(ok: bool) {
514 if (!ok) unreachable;
515}
std/special/panic.zig created+12
......@@ -0,0 +1,12 @@
1// This file is included if and only if the user's main source file does not
2// include a public panic function.
3// If this file wants to import other files *by name*, support for that would
4// have to be added in the compiler.
5
6pub coldcc fn panic(message: []const u8) -> noreturn {
7 if (@compileVar("os") == Os.freestanding) {
8 while (true) {}
9 } else {
10 @import("std").debug.panic(message);
11 }
12}
std/special/test_runner.zig created+18
......@@ -0,0 +1,18 @@
1const io = @import("std").io;
2
3const TestFn = struct {
4 name: []u8,
5 func: extern fn(),
6};
7
8extern var zig_test_fn_list: []TestFn;
9
10pub fn main(args: [][]u8) -> %void {
11 for (zig_test_fn_list) |testFn, i| {
12 %%io.stderr.printf("Test {}/{} {}...", i + 1, zig_test_fn_list.len, testFn.name);
13
14 testFn.func();
15
16 %%io.stderr.printf("OK\n");
17 }
18}
std/target.zig created+15
......@@ -0,0 +1,15 @@
1const mem = @import("mem.zig");
2
3pub const linking_libc = linkingLibrary("c");
4
5pub fn linkingLibrary(lib_name: []const u8) -> bool {
6 // TODO shouldn't need this if
7 if (@compileVar("link_libs").len != 0) {
8 for (@compileVar("link_libs")) |link_lib| {
9 if (mem.eql(u8, link_lib, lib_name)) {
10 return true;
11 }
12 }
13 }
14 return false;
15}
std/test_runner.zig deleted-18
......@@ -1,18 +0,0 @@
1const io = @import("std").io;
2
3const TestFn = struct {
4 name: []u8,
5 func: extern fn(),
6};
7
8extern var zig_test_fn_list: []TestFn;
9
10pub fn main(args: [][]u8) -> %void {
11 for (zig_test_fn_list) |testFn, i| {
12 %%io.stderr.printf("Test {}/{} {}...", i + 1, zig_test_fn_list.len, testFn.name);
13
14 testFn.func();
15
16 %%io.stderr.printf("OK\n");
17 }
18}
std/windows.zig deleted-17
......@@ -1,17 +0,0 @@
1pub extern fn CryptAcquireContext(phProv: &HCRYPTPROV, pszContainer: LPCTSTR,
2 pszProvider: LPCTSTR, dwProvType: DWORD, dwFlags: DWORD) -> bool;
3
4pub extern fn CryptReleaseContext(hProv: HCRYPTPROV, dwFlags: DWORD) -> bool;
5
6pub extern fn CryptGenRandom(hProv: HCRYPTPROV, dwLen: DWORD, pbBuffer: &BYTE) -> bool;
7
8pub const PROV_RSA_FULL = 1;
9
10
11pub const BYTE = u8;
12pub const DWORD = u32;
13// TODO something about unicode WCHAR vs char
14pub const TCHAR = u8;
15pub const LPCTSTR = ?&const TCHAR;
16pub const ULONG_PTR = usize;
17pub const HCRYPTPROV = ULONG_PTR;
test/cases/import.zig+1-1
......@@ -1,5 +1,5 @@
11const assert = @import("std").debug.assert;
2const a_namespace = @import("cases/import/a_namespace.zig");
2const a_namespace = @import("import/a_namespace.zig");
33
44test "callFnViaNamespaceLookup" {
55 assert(a_namespace.foo() == 1234);
test/cases/namespace_depends_on_compile_var/index.zig+2-2
......@@ -8,6 +8,6 @@ test "namespaceDependsOnCompileVar" {
88 }
99}
1010const some_namespace = switch(@compileVar("os")) {
11 Os.linux => @import("cases/namespace_depends_on_compile_var/a.zig"),
12 else => @import("cases/namespace_depends_on_compile_var/b.zig"),
11 Os.linux => @import("a.zig"),
12 else => @import("b.zig"),
1313};
test/cases/pub_enum/index.zig+1-1
......@@ -1,4 +1,4 @@
1const other = @import("cases/pub_enum/other.zig");
1const other = @import("other.zig");
22const assert = @import("std").debug.assert;
33
44test "pubEnum" {
test/run_tests.cpp+1-2
......@@ -1254,8 +1254,7 @@ export fn entry() -> usize { @sizeOf(@typeOf(seventh_fib_number)) }
12541254const resource = @embedFile("bogus.txt");
12551255
12561256export fn entry() -> usize { @sizeOf(@typeOf(resource)) }
1257 )SOURCE", 1, ".tmp_source.zig:2:29: error: unable to find './bogus.txt'");
1258
1257 )SOURCE", 2, ".tmp_source.zig:2:29: error: unable to find '", "/bogus.txt'");
12591258
12601259 add_compile_fail_case("non-const expression in struct literal outside function", R"SOURCE(
12611260const Foo = struct {