| author | |
| committer | |
| log | 5bc9feb5cb98fc13db62d01b2b9fec15677310a7 |
| tree | 12972dfc1f9b964bb74428ec0d6766e77b9b0be7 |
| parent | 7ce753a16b0c16b4c6494467f42f2d5fe9a235e6 |
closes #21644 files changed, 2625 insertions(+), 2630 deletions(-)
CMakeLists.txt+14-14| ... | ... | @@ -201,41 +201,41 @@ install(TARGETS zig DESTINATION bin) |
| 201 | 201 | |
| 202 | 202 | install(FILES ${C_HEADERS} DESTINATION ${C_HEADERS_DEST}) |
| 203 | 203 | |
| 204 | install(FILES "${CMAKE_SOURCE_DIR}/std/bootstrap.zig" DESTINATION "${ZIG_STD_DEST}") | |
| 205 | install(FILES "${CMAKE_SOURCE_DIR}/std/build.zig" DESTINATION "${ZIG_STD_DEST}") | |
| 206 | install(FILES "${CMAKE_SOURCE_DIR}/std/builtin.zig" DESTINATION "${ZIG_STD_DEST}") | |
| 207 | 204 | install(FILES "${CMAKE_SOURCE_DIR}/std/c/darwin.zig" DESTINATION "${ZIG_STD_DEST}/c") |
| 208 | 205 | install(FILES "${CMAKE_SOURCE_DIR}/std/c/index.zig" DESTINATION "${ZIG_STD_DEST}/c") |
| 209 | 206 | install(FILES "${CMAKE_SOURCE_DIR}/std/c/linux.zig" DESTINATION "${ZIG_STD_DEST}/c") |
| 210 | 207 | install(FILES "${CMAKE_SOURCE_DIR}/std/c/windows.zig" DESTINATION "${ZIG_STD_DEST}/c") |
| 211 | install(FILES "${CMAKE_SOURCE_DIR}/std/compiler_rt.zig" DESTINATION "${ZIG_STD_DEST}") | |
| 212 | 208 | install(FILES "${CMAKE_SOURCE_DIR}/std/cstr.zig" DESTINATION "${ZIG_STD_DEST}") |
| 213 | install(FILES "${CMAKE_SOURCE_DIR}/std/darwin.zig" DESTINATION "${ZIG_STD_DEST}") | |
| 214 | install(FILES "${CMAKE_SOURCE_DIR}/std/darwin_x86_64.zig" DESTINATION "${ZIG_STD_DEST}") | |
| 215 | 209 | install(FILES "${CMAKE_SOURCE_DIR}/std/debug.zig" DESTINATION "${ZIG_STD_DEST}") |
| 216 | 210 | install(FILES "${CMAKE_SOURCE_DIR}/std/dwarf.zig" DESTINATION "${ZIG_STD_DEST}") |
| 217 | 211 | install(FILES "${CMAKE_SOURCE_DIR}/std/elf.zig" DESTINATION "${ZIG_STD_DEST}") |
| 218 | 212 | install(FILES "${CMAKE_SOURCE_DIR}/std/empty.zig" DESTINATION "${ZIG_STD_DEST}") |
| 219 | 213 | install(FILES "${CMAKE_SOURCE_DIR}/std/endian.zig" DESTINATION "${ZIG_STD_DEST}") |
| 220 | install(FILES "${CMAKE_SOURCE_DIR}/std/errno.zig" DESTINATION "${ZIG_STD_DEST}") | |
| 221 | 214 | install(FILES "${CMAKE_SOURCE_DIR}/std/fmt.zig" DESTINATION "${ZIG_STD_DEST}") |
| 222 | 215 | install(FILES "${CMAKE_SOURCE_DIR}/std/hash_map.zig" DESTINATION "${ZIG_STD_DEST}") |
| 223 | 216 | install(FILES "${CMAKE_SOURCE_DIR}/std/index.zig" DESTINATION "${ZIG_STD_DEST}") |
| 224 | 217 | install(FILES "${CMAKE_SOURCE_DIR}/std/io.zig" DESTINATION "${ZIG_STD_DEST}") |
| 225 | install(FILES "${CMAKE_SOURCE_DIR}/std/linux.zig" DESTINATION "${ZIG_STD_DEST}") | |
| 226 | install(FILES "${CMAKE_SOURCE_DIR}/std/linux_i386.zig" DESTINATION "${ZIG_STD_DEST}") | |
| 227 | install(FILES "${CMAKE_SOURCE_DIR}/std/linux_x86_64.zig" DESTINATION "${ZIG_STD_DEST}") | |
| 228 | 218 | install(FILES "${CMAKE_SOURCE_DIR}/std/list.zig" DESTINATION "${ZIG_STD_DEST}") |
| 229 | 219 | install(FILES "${CMAKE_SOURCE_DIR}/std/math.zig" DESTINATION "${ZIG_STD_DEST}") |
| 230 | 220 | install(FILES "${CMAKE_SOURCE_DIR}/std/mem.zig" DESTINATION "${ZIG_STD_DEST}") |
| 231 | 221 | install(FILES "${CMAKE_SOURCE_DIR}/std/net.zig" DESTINATION "${ZIG_STD_DEST}") |
| 232 | install(FILES "${CMAKE_SOURCE_DIR}/std/os.zig" DESTINATION "${ZIG_STD_DEST}") | |
| 233 | install(FILES "${CMAKE_SOURCE_DIR}/std/panic.zig" DESTINATION "${ZIG_STD_DEST}") | |
| 222 | install(FILES "${CMAKE_SOURCE_DIR}/std/os/darwin.zig" DESTINATION "${ZIG_STD_DEST}/os") | |
| 223 | install(FILES "${CMAKE_SOURCE_DIR}/std/os/darwin_x86_64.zig" DESTINATION "${ZIG_STD_DEST}/os") | |
| 224 | install(FILES "${CMAKE_SOURCE_DIR}/std/os/errno.zig" DESTINATION "${ZIG_STD_DEST}/os") | |
| 225 | install(FILES "${CMAKE_SOURCE_DIR}/std/os/index.zig" DESTINATION "${ZIG_STD_DEST}/os") | |
| 226 | install(FILES "${CMAKE_SOURCE_DIR}/std/os/linux.zig" DESTINATION "${ZIG_STD_DEST}/os") | |
| 227 | install(FILES "${CMAKE_SOURCE_DIR}/std/os/linux_i386.zig" DESTINATION "${ZIG_STD_DEST}/os") | |
| 228 | install(FILES "${CMAKE_SOURCE_DIR}/std/os/linux_x86_64.zig" DESTINATION "${ZIG_STD_DEST}/os") | |
| 229 | install(FILES "${CMAKE_SOURCE_DIR}/std/os/windows.zig" DESTINATION "${ZIG_STD_DEST}/os") | |
| 234 | 230 | install(FILES "${CMAKE_SOURCE_DIR}/std/rand.zig" DESTINATION "${ZIG_STD_DEST}") |
| 235 | 231 | install(FILES "${CMAKE_SOURCE_DIR}/std/rand_test.zig" DESTINATION "${ZIG_STD_DEST}") |
| 236 | 232 | install(FILES "${CMAKE_SOURCE_DIR}/std/sort.zig" DESTINATION "${ZIG_STD_DEST}") |
| 237 | install(FILES "${CMAKE_SOURCE_DIR}/std/test_runner.zig" DESTINATION "${ZIG_STD_DEST}") | |
| 238 | install(FILES "${CMAKE_SOURCE_DIR}/std/windows.zig" DESTINATION "${ZIG_STD_DEST}") | |
| 233 | install(FILES "${CMAKE_SOURCE_DIR}/std/special/bootstrap.zig" DESTINATION "${ZIG_STD_DEST}/special") | |
| 234 | install(FILES "${CMAKE_SOURCE_DIR}/std/special/builtin.zig" DESTINATION "${ZIG_STD_DEST}/special") | |
| 235 | install(FILES "${CMAKE_SOURCE_DIR}/std/special/compiler_rt.zig" DESTINATION "${ZIG_STD_DEST}/special") | |
| 236 | install(FILES "${CMAKE_SOURCE_DIR}/std/special/panic.zig" DESTINATION "${ZIG_STD_DEST}/special") | |
| 237 | install(FILES "${CMAKE_SOURCE_DIR}/std/special/test_runner.zig" DESTINATION "${ZIG_STD_DEST}/special") | |
| 238 | install(FILES "${CMAKE_SOURCE_DIR}/std/target.zig" DESTINATION "${ZIG_STD_DEST}") | |
| 239 | 239 | |
| 240 | 240 | add_executable(run_tests ${TEST_SOURCES}) |
| 241 | 241 | target_link_libraries(run_tests) |
src/all_types.hpp+1| ... | ... | @@ -1362,6 +1362,7 @@ struct CodeGen { |
| 1362 | 1362 | Buf *libc_static_lib_dir; |
| 1363 | 1363 | Buf *libc_include_dir; |
| 1364 | 1364 | Buf *zig_std_dir; |
| 1365 | Buf *zig_std_special_dir; | |
| 1365 | 1366 | Buf *dynamic_linker; |
| 1366 | 1367 | Buf *ar_path; |
| 1367 | 1368 | Buf triple_str; |
src/analyze.cpp+3-6| ... | ... | @@ -2874,11 +2874,8 @@ void preview_use_decl(CodeGen *g, AstNode *node) { |
| 2874 | 2874 | ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, |
| 2875 | 2875 | Buf *abs_full_path, Buf *src_dirname, Buf *src_basename, Buf *source_code) |
| 2876 | 2876 | { |
| 2877 | Buf *full_path = buf_alloc(); | |
| 2878 | os_path_join(src_dirname, src_basename, full_path); | |
| 2879 | ||
| 2880 | 2877 | 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)); | |
| 2882 | 2879 | fprintf(stderr, "----------------\n"); |
| 2883 | 2880 | fprintf(stderr, "%s\n", buf_ptr(source_code)); |
| 2884 | 2881 | |
| ... | ... | @@ -2890,7 +2887,7 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, |
| 2890 | 2887 | tokenize(source_code, &tokenization); |
| 2891 | 2888 | |
| 2892 | 2889 | 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, | |
| 2894 | 2891 | source_code, tokenization.line_offsets, tokenization.err); |
| 2895 | 2892 | |
| 2896 | 2893 | print_err_msg(err, g->err_color); |
| ... | ... | @@ -2908,7 +2905,7 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, |
| 2908 | 2905 | import_entry->package = package; |
| 2909 | 2906 | import_entry->source_code = source_code; |
| 2910 | 2907 | import_entry->line_offsets = tokenization.line_offsets; |
| 2911 | import_entry->path = full_path; | |
| 2908 | import_entry->path = abs_full_path; | |
| 2912 | 2909 | |
| 2913 | 2910 | import_entry->root = ast_parse(source_code, tokenization.tokens, import_entry, g->err_color, |
| 2914 | 2911 | &g->next_node_index); |
src/codegen.cpp+7-5| ... | ... | @@ -80,6 +80,9 @@ CodeGen *codegen_create(Buf *root_source_dir, const ZigTarget *target) { |
| 80 | 80 | g->root_package->package_table.put(buf_create_from_str("std"), g->std_package); |
| 81 | 81 | g->zig_std_dir = buf_create_from_str(ZIG_STD_DIR); |
| 82 | 82 | |
| 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 | ||
| 83 | 86 | |
| 84 | 87 | if (target) { |
| 85 | 88 | // 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 |
| 4237 | 4240 | } |
| 4238 | 4241 | |
| 4239 | 4242 | static ImportTableEntry *add_special_code(CodeGen *g, PackageTableEntry *package, const char *basename) { |
| 4240 | Buf *std_dir = g->zig_std_dir; | |
| 4241 | 4243 | Buf *code_basename = buf_create_from_str(basename); |
| 4242 | 4244 | 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); | |
| 4244 | 4246 | Buf *abs_full_path = buf_alloc(); |
| 4245 | 4247 | int err; |
| 4246 | 4248 | 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 |
| 4251 | 4253 | zig_panic("unable to open '%s': %s", buf_ptr(&path_to_code_src), err_str(err)); |
| 4252 | 4254 | } |
| 4253 | 4255 | |
| 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); | |
| 4255 | 4257 | } |
| 4256 | 4258 | |
| 4257 | 4259 | static 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), ""); | |
| 4259 | 4261 | package->package_table.put(buf_create_from_str("std"), g->std_package); |
| 4260 | 4262 | package->package_table.put(buf_create_from_str("@root"), g->root_package); |
| 4261 | 4263 | return package; |
| 4262 | 4264 | } |
| 4263 | 4265 | |
| 4264 | 4266 | static 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), ""); | |
| 4266 | 4268 | package->package_table.put(buf_create_from_str("std"), g->std_package); |
| 4267 | 4269 | return package; |
| 4268 | 4270 | } |
src/ir.cpp+4-1| ... | ... | @@ -10385,7 +10385,10 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi |
| 10385 | 10385 | // try it as a filename |
| 10386 | 10386 | target_package = import->package; |
| 10387 | 10387 | 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); | |
| 10389 | 10392 | } |
| 10390 | 10393 | |
| 10391 | 10394 | Buf full_path = BUF_INIT; |
src/link.cpp+4-4| ... | ... | @@ -42,10 +42,9 @@ static const char *get_o_file_extension(CodeGen *g) { |
| 42 | 42 | |
| 43 | 43 | static Buf *build_o(CodeGen *parent_gen, const char *oname) { |
| 44 | 44 | Buf *source_basename = buf_sprintf("%s.zig", oname); |
| 45 | Buf *std_dir_path = parent_gen->zig_std_dir; | |
| 46 | 45 | |
| 47 | 46 | 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); | |
| 49 | 48 | child_gen->link_libc = parent_gen->link_libc; |
| 50 | 49 | |
| 51 | 50 | child_gen->link_libs.resize(parent_gen->link_libs.length); |
| ... | ... | @@ -70,13 +69,14 @@ static Buf *build_o(CodeGen *parent_gen, const char *oname) { |
| 70 | 69 | codegen_set_mios_version_min(child_gen, parent_gen->mios_version_min); |
| 71 | 70 | |
| 72 | 71 | 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 | ||
| 74 | 74 | Buf source_code = BUF_INIT; |
| 75 | 75 | if (os_fetch_file_path(full_path, &source_code)) { |
| 76 | 76 | zig_panic("unable to fetch file: %s\n", buf_ptr(full_path)); |
| 77 | 77 | } |
| 78 | 78 | |
| 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); | |
| 80 | 80 | const char *o_ext = get_o_file_extension(child_gen); |
| 81 | 81 | Buf *o_out = buf_sprintf("%s%s", oname, o_ext); |
| 82 | 82 | 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 | ||
| 4 | const root = @import("@root"); | |
| 5 | const std = @import("std"); | |
| 6 | ||
| 7 | const want_main_symbol = std.build.linking_libc; | |
| 8 | const want_start_symbol = !want_main_symbol; | |
| 9 | ||
| 10 | const exit = switch(@compileVar("os")) { | |
| 11 | Os.linux => std.linux.exit, | |
| 12 | Os.darwin => std.darwin.exit, | |
| 13 | else => @compileError("Unsupported OS"), | |
| 14 | }; | |
| 15 | ||
| 16 | var argc: usize = undefined; | |
| 17 | var argv: &&u8 = undefined; | |
| 18 | ||
| 19 | export 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 | ||
| 39 | fn 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 | ||
| 48 | fn callMainAndExit() -> noreturn { | |
| 49 | callMain() %% exit(1); | |
| 50 | exit(0); | |
| 51 | } | |
| 52 | ||
| 53 | export 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 @@ |
| 1 | const mem = @import("mem.zig"); | |
| 2 | ||
| 3 | pub const linking_libc = linkingLibrary("c"); | |
| 4 | ||
| 5 | pub 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 | ||
| 8 | export 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 | ||
| 20 | export 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. | |
| 34 | pub fn panic(message: []const u8) -> noreturn { | |
| 35 | unreachable; | |
| 36 | } |
std/c/index.zig+5-5| ... | ... | @@ -1,13 +1,13 @@ |
| 1 | pub use @import("errno.zig"); | |
| 1 | pub use @import("../os/errno.zig"); | |
| 2 | 2 | |
| 3 | 3 | pub 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"), | |
| 7 | 7 | else => empty_import, |
| 8 | 8 | }; |
| 9 | 9 | |
| 10 | 10 | pub extern fn abort() -> noreturn; |
| 11 | 11 | |
| 12 | 12 | |
| 13 | const empty_import = @import("empty.zig"); | |
| 13 | const 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. | |
| 3 | pub fn panic(message: []const u8) -> noreturn { | |
| 4 | if (@compileVar("is_test")) { | |
| 5 | @import("std").debug.panic(message); | |
| 6 | } else { | |
| 7 | unreachable; | |
| 8 | } | |
| 9 | } | |
| 10 | ||
| 11 | const CHAR_BIT = 8; | |
| 12 | const du_int = u64; | |
| 13 | const di_int = i64; | |
| 14 | const si_int = c_int; | |
| 15 | const su_int = c_uint; | |
| 16 | ||
| 17 | const udwords = [2]su_int; | |
| 18 | const low = if (@compileVar("is_big_endian")) 1 else 0; | |
| 19 | const high = 1 - low; | |
| 20 | ||
| 21 | export fn __udivdi3(a: du_int, b: du_int) -> du_int { | |
| 22 | @setDebugSafety(this, false); | |
| 23 | return __udivmoddi4(a, b, null); | |
| 24 | } | |
| 25 | ||
| 26 | fn du_int_to_udwords(x: du_int) -> udwords { | |
| 27 | @setDebugSafety(this, false); | |
| 28 | return *(&udwords)(&x); | |
| 29 | } | |
| 30 | ||
| 31 | export 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 | ||
| 217 | export 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 | ||
| 225 | fn 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 | ||
| 249 | export 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 | ||
| 268 | export 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 | ||
| 280 | export fn __aeabi_uidiv(n: su_int, d: su_int) -> su_int { | |
| 281 | @setDebugSafety(this, false); | |
| 282 | ||
| 283 | return __udivsi3(n, d); | |
| 284 | } | |
| 285 | ||
| 286 | export 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 | ||
| 325 | test "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 | ||
| 333 | fn 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 | ||
| 338 | test "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 | ||
| 359 | fn 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 | ||
| 366 | test "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 | ||
| 507 | fn 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 | ||
| 513 | fn assert(ok: bool) { | |
| 514 | if (!ok) unreachable; | |
| 515 | } |
std/darwin.zig deleted-118| ... | ... | @@ -1,118 +0,0 @@ |
| 1 | ||
| 2 | const arch = switch (@compileVar("arch")) { | |
| 3 | Arch.x86_64 => @import("darwin_x86_64.zig"), | |
| 4 | else => @compileError("unsupported arch"), | |
| 5 | }; | |
| 6 | ||
| 7 | const errno = @import("errno.zig"); | |
| 8 | ||
| 9 | pub const O_LARGEFILE = 0x0000; | |
| 10 | pub const O_RDONLY = 0x0000; | |
| 11 | ||
| 12 | pub const SEEK_SET = 0x0; | |
| 13 | pub const SEEK_CUR = 0x1; | |
| 14 | pub const SEEK_END = 0x2; | |
| 15 | ||
| 16 | pub const SIGHUP = 1; | |
| 17 | pub const SIGINT = 2; | |
| 18 | pub const SIGQUIT = 3; | |
| 19 | pub const SIGILL = 4; | |
| 20 | pub const SIGTRAP = 5; | |
| 21 | pub const SIGABRT = 6; | |
| 22 | pub const SIGIOT = SIGABRT; | |
| 23 | pub const SIGBUS = 7; | |
| 24 | pub const SIGFPE = 8; | |
| 25 | pub const SIGKILL = 9; | |
| 26 | pub const SIGUSR1 = 10; | |
| 27 | pub const SIGSEGV = 11; | |
| 28 | pub const SIGUSR2 = 12; | |
| 29 | pub const SIGPIPE = 13; | |
| 30 | pub const SIGALRM = 14; | |
| 31 | pub const SIGTERM = 15; | |
| 32 | pub const SIGSTKFLT = 16; | |
| 33 | pub const SIGCHLD = 17; | |
| 34 | pub const SIGCONT = 18; | |
| 35 | pub const SIGSTOP = 19; | |
| 36 | pub const SIGTSTP = 20; | |
| 37 | pub const SIGTTIN = 21; | |
| 38 | pub const SIGTTOU = 22; | |
| 39 | pub const SIGURG = 23; | |
| 40 | pub const SIGXCPU = 24; | |
| 41 | pub const SIGXFSZ = 25; | |
| 42 | pub const SIGVTALRM = 26; | |
| 43 | pub const SIGPROF = 27; | |
| 44 | pub const SIGWINCH = 28; | |
| 45 | pub const SIGIO = 29; | |
| 46 | pub const SIGPOLL = 29; | |
| 47 | pub const SIGPWR = 30; | |
| 48 | pub const SIGSYS = 31; | |
| 49 | pub const SIGUNUSED = SIGSYS; | |
| 50 | ||
| 51 | pub 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. | |
| 57 | pub 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 | ||
| 62 | pub fn write(fd: i32, buf: &const u8, count: usize) -> usize { | |
| 63 | arch.syscall3(arch.SYS_write, usize(fd), usize(buf), count) | |
| 64 | } | |
| 65 | ||
| 66 | pub fn close(fd: i32) -> usize { | |
| 67 | arch.syscall1(arch.SYS_close, usize(fd)) | |
| 68 | } | |
| 69 | ||
| 70 | pub fn open_c(path: &const u8, flags: usize, perm: usize) -> usize { | |
| 71 | arch.syscall3(arch.SYS_open, usize(path), flags, perm) | |
| 72 | } | |
| 73 | ||
| 74 | pub 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 | ||
| 81 | pub fn read(fd: i32, buf: &u8, count: usize) -> usize { | |
| 82 | arch.syscall3(arch.SYS_read, usize(fd), usize(buf), count) | |
| 83 | } | |
| 84 | ||
| 85 | pub fn lseek(fd: i32, offset: usize, ref_pos: usize) -> usize { | |
| 86 | arch.syscall3(arch.SYS_lseek, usize(fd), offset, ref_pos) | |
| 87 | } | |
| 88 | ||
| 89 | pub const stat = arch.stat; | |
| 90 | pub const timespec = arch.timespec; | |
| 91 | ||
| 92 | pub fn fstat(fd: i32, stat_buf: &stat) -> usize { | |
| 93 | arch.syscall2(arch.SYS_fstat, usize(fd), usize(stat_buf)) | |
| 94 | } | |
| 95 | ||
| 96 | error Unexpected; | |
| 97 | ||
| 98 | pub 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 | ||
| 108 | pub 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 | ||
| 2 | pub const SYSCALL_CLASS_SHIFT = 24; | |
| 3 | pub const SYSCALL_CLASS_MASK = 0xFF << SYSCALL_CLASS_SHIFT; | |
| 4 | // pub const SYSCALL_NUMBER_MASK = ~SYSCALL_CLASS_MASK; // ~ modifier not supported yet | |
| 5 | ||
| 6 | pub const SYSCALL_CLASS_NONE = 0; // Invalid | |
| 7 | pub const SYSCALL_CLASS_MACH = 1; // Mach | |
| 8 | pub const SYSCALL_CLASS_UNIX = 2; // Unix/BSD | |
| 9 | pub const SYSCALL_CLASS_MDEP = 3; // Machine-dependent | |
| 10 | pub const SYSCALL_CLASS_DIAG = 4; // Diagnostics | |
| 11 | ||
| 12 | // TODO: use the above constants to create the below values | |
| 13 | ||
| 14 | pub const SYS_exit = 0x2000001; | |
| 15 | pub const SYS_read = 0x2000003; | |
| 16 | pub const SYS_write = 0x2000004; | |
| 17 | pub const SYS_open = 0x2000005; | |
| 18 | pub const SYS_close = 0x2000006; | |
| 19 | pub const SYS_kill = 0x2000025; | |
| 20 | pub const SYS_getpid = 0x2000030; | |
| 21 | pub const SYS_fstat = 0x20000BD; | |
| 22 | pub const SYS_lseek = 0x20000C7; | |
| 23 | ||
| 24 | pub inline fn syscall0(number: usize) -> usize { | |
| 25 | asm volatile ("syscall" | |
| 26 | : [ret] "={rax}" (-> usize) | |
| 27 | : [number] "{rax}" (number) | |
| 28 | : "rcx", "r11") | |
| 29 | } | |
| 30 | ||
| 31 | pub 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 | ||
| 39 | pub 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 | ||
| 48 | pub 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 | ||
| 61 | pub 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 | ||
| 84 | pub const timespec = extern struct { | |
| 85 | tv_sec: isize, | |
| 86 | tv_nsec: isize, | |
| 87 | }; |
std/debug.zig+1-1| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | const mem = @import("mem.zig"); |
| 2 | 2 | const io = @import("io.zig"); |
| 3 | const os = @import("os.zig"); | |
| 3 | const os = @import("os/index.zig"); | |
| 4 | 4 | const elf = @import("elf.zig"); |
| 5 | 5 | const DW = @import("dwarf.zig"); |
| 6 | 6 | const List = @import("list.zig").List; |
std/errno.zig deleted-146| ... | ... | @@ -1,146 +0,0 @@ |
| 1 | pub const EPERM = 1; // Operation not permitted | |
| 2 | pub const ENOENT = 2; // No such file or directory | |
| 3 | pub const ESRCH = 3; // No such process | |
| 4 | pub const EINTR = 4; // Interrupted system call | |
| 5 | pub const EIO = 5; // I/O error | |
| 6 | pub const ENXIO = 6; // No such device or address | |
| 7 | pub const E2BIG = 7; // Arg list too long | |
| 8 | pub const ENOEXEC = 8; // Exec format error | |
| 9 | pub const EBADF = 9; // Bad file number | |
| 10 | pub const ECHILD = 10; // No child processes | |
| 11 | pub const EAGAIN = 11; // Try again | |
| 12 | pub const ENOMEM = 12; // Out of memory | |
| 13 | pub const EACCES = 13; // Permission denied | |
| 14 | pub const EFAULT = 14; // Bad address | |
| 15 | pub const ENOTBLK = 15; // Block device required | |
| 16 | pub const EBUSY = 16; // Device or resource busy | |
| 17 | pub const EEXIST = 17; // File exists | |
| 18 | pub const EXDEV = 18; // Cross-device link | |
| 19 | pub const ENODEV = 19; // No such device | |
| 20 | pub const ENOTDIR = 20; // Not a directory | |
| 21 | pub const EISDIR = 21; // Is a directory | |
| 22 | pub const EINVAL = 22; // Invalid argument | |
| 23 | pub const ENFILE = 23; // File table overflow | |
| 24 | pub const EMFILE = 24; // Too many open files | |
| 25 | pub const ENOTTY = 25; // Not a typewriter | |
| 26 | pub const ETXTBSY = 26; // Text file busy | |
| 27 | pub const EFBIG = 27; // File too large | |
| 28 | pub const ENOSPC = 28; // No space left on device | |
| 29 | pub const ESPIPE = 29; // Illegal seek | |
| 30 | pub const EROFS = 30; // Read-only file system | |
| 31 | pub const EMLINK = 31; // Too many links | |
| 32 | pub const EPIPE = 32; // Broken pipe | |
| 33 | pub const EDOM = 33; // Math argument out of domain of func | |
| 34 | pub const ERANGE = 34; // Math result not representable | |
| 35 | pub const EDEADLK = 35; // Resource deadlock would occur | |
| 36 | pub const ENAMETOOLONG = 36; // File name too long | |
| 37 | pub const ENOLCK = 37; // No record locks available | |
| 38 | pub const ENOSYS = 38; // Function not implemented | |
| 39 | pub const ENOTEMPTY = 39; // Directory not empty | |
| 40 | pub const ELOOP = 40; // Too many symbolic links encountered | |
| 41 | pub const EWOULDBLOCK = EAGAIN; // Operation would block | |
| 42 | pub const ENOMSG = 42; // No message of desired type | |
| 43 | pub const EIDRM = 43; // Identifier removed | |
| 44 | pub const ECHRNG = 44; // Channel number out of range | |
| 45 | pub const EL2NSYNC = 45; // Level 2 not synchronized | |
| 46 | pub const EL3HLT = 46; // Level 3 halted | |
| 47 | pub const EL3RST = 47; // Level 3 reset | |
| 48 | pub const ELNRNG = 48; // Link number out of range | |
| 49 | pub const EUNATCH = 49; // Protocol driver not attached | |
| 50 | pub const ENOCSI = 50; // No CSI structure available | |
| 51 | pub const EL2HLT = 51; // Level 2 halted | |
| 52 | pub const EBADE = 52; // Invalid exchange | |
| 53 | pub const EBADR = 53; // Invalid request descriptor | |
| 54 | pub const EXFULL = 54; // Exchange full | |
| 55 | pub const ENOANO = 55; // No anode | |
| 56 | pub const EBADRQC = 56; // Invalid request code | |
| 57 | pub const EBADSLT = 57; // Invalid slot | |
| 58 | ||
| 59 | pub const EBFONT = 59; // Bad font file format | |
| 60 | pub const ENOSTR = 60; // Device not a stream | |
| 61 | pub const ENODATA = 61; // No data available | |
| 62 | pub const ETIME = 62; // Timer expired | |
| 63 | pub const ENOSR = 63; // Out of streams resources | |
| 64 | pub const ENONET = 64; // Machine is not on the network | |
| 65 | pub const ENOPKG = 65; // Package not installed | |
| 66 | pub const EREMOTE = 66; // Object is remote | |
| 67 | pub const ENOLINK = 67; // Link has been severed | |
| 68 | pub const EADV = 68; // Advertise error | |
| 69 | pub const ESRMNT = 69; // Srmount error | |
| 70 | pub const ECOMM = 70; // Communication error on send | |
| 71 | pub const EPROTO = 71; // Protocol error | |
| 72 | pub const EMULTIHOP = 72; // Multihop attempted | |
| 73 | pub const EDOTDOT = 73; // RFS specific error | |
| 74 | pub const EBADMSG = 74; // Not a data message | |
| 75 | pub const EOVERFLOW = 75; // Value too large for defined data type | |
| 76 | pub const ENOTUNIQ = 76; // Name not unique on network | |
| 77 | pub const EBADFD = 77; // File descriptor in bad state | |
| 78 | pub const EREMCHG = 78; // Remote address changed | |
| 79 | pub const ELIBACC = 79; // Can not access a needed shared library | |
| 80 | pub const ELIBBAD = 80; // Accessing a corrupted shared library | |
| 81 | pub const ELIBSCN = 81; // .lib section in a.out corrupted | |
| 82 | pub const ELIBMAX = 82; // Attempting to link in too many shared libraries | |
| 83 | pub const ELIBEXEC = 83; // Cannot exec a shared library directly | |
| 84 | pub const EILSEQ = 84; // Illegal byte sequence | |
| 85 | pub const ERESTART = 85; // Interrupted system call should be restarted | |
| 86 | pub const ESTRPIPE = 86; // Streams pipe error | |
| 87 | pub const EUSERS = 87; // Too many users | |
| 88 | pub const ENOTSOCK = 88; // Socket operation on non-socket | |
| 89 | pub const EDESTADDRREQ = 89; // Destination address required | |
| 90 | pub const EMSGSIZE = 90; // Message too long | |
| 91 | pub const EPROTOTYPE = 91; // Protocol wrong type for socket | |
| 92 | pub const ENOPROTOOPT = 92; // Protocol not available | |
| 93 | pub const EPROTONOSUPPORT = 93; // Protocol not supported | |
| 94 | pub const ESOCKTNOSUPPORT = 94; // Socket type not supported | |
| 95 | pub const EOPNOTSUPP = 95; // Operation not supported on transport endpoint | |
| 96 | pub const EPFNOSUPPORT = 96; // Protocol family not supported | |
| 97 | pub const EAFNOSUPPORT = 97; // Address family not supported by protocol | |
| 98 | pub const EADDRINUSE = 98; // Address already in use | |
| 99 | pub const EADDRNOTAVAIL = 99; // Cannot assign requested address | |
| 100 | pub const ENETDOWN = 100; // Network is down | |
| 101 | pub const ENETUNREACH = 101; // Network is unreachable | |
| 102 | pub const ENETRESET = 102; // Network dropped connection because of reset | |
| 103 | pub const ECONNABORTED = 103; // Software caused connection abort | |
| 104 | pub const ECONNRESET = 104; // Connection reset by peer | |
| 105 | pub const ENOBUFS = 105; // No buffer space available | |
| 106 | pub const EISCONN = 106; // Transport endpoint is already connected | |
| 107 | pub const ENOTCONN = 107; // Transport endpoint is not connected | |
| 108 | pub const ESHUTDOWN = 108; // Cannot send after transport endpoint shutdown | |
| 109 | pub const ETOOMANYREFS = 109; // Too many references: cannot splice | |
| 110 | pub const ETIMEDOUT = 110; // Connection timed out | |
| 111 | pub const ECONNREFUSED = 111; // Connection refused | |
| 112 | pub const EHOSTDOWN = 112; // Host is down | |
| 113 | pub const EHOSTUNREACH = 113; // No route to host | |
| 114 | pub const EALREADY = 114; // Operation already in progress | |
| 115 | pub const EINPROGRESS = 115; // Operation now in progress | |
| 116 | pub const ESTALE = 116; // Stale NFS file handle | |
| 117 | pub const EUCLEAN = 117; // Structure needs cleaning | |
| 118 | pub const ENOTNAM = 118; // Not a XENIX named type file | |
| 119 | pub const ENAVAIL = 119; // No XENIX semaphores available | |
| 120 | pub const EISNAM = 120; // Is a named type file | |
| 121 | pub const EREMOTEIO = 121; // Remote I/O error | |
| 122 | pub const EDQUOT = 122; // Quota exceeded | |
| 123 | ||
| 124 | pub const ENOMEDIUM = 123; // No medium found | |
| 125 | pub const EMEDIUMTYPE = 124; // Wrong medium type | |
| 126 | ||
| 127 | // nameserver query return codes | |
| 128 | pub const ENSROK = 0; // DNS server returned answer with no data | |
| 129 | pub const ENSRNODATA = 160; // DNS server returned answer with no data | |
| 130 | pub const ENSRFORMERR = 161; // DNS server claims query was misformatted | |
| 131 | pub const ENSRSERVFAIL = 162; // DNS server returned general failure | |
| 132 | pub const ENSRNOTFOUND = 163; // Domain name not found | |
| 133 | pub const ENSRNOTIMP = 164; // DNS server does not implement requested operation | |
| 134 | pub const ENSRREFUSED = 165; // DNS server refused query | |
| 135 | pub const ENSRBADQUERY = 166; // Misformatted DNS query | |
| 136 | pub const ENSRBADNAME = 167; // Misformatted domain name | |
| 137 | pub const ENSRBADFAMILY = 168; // Unsupported address family | |
| 138 | pub const ENSRBADRESP = 169; // Misformatted DNS reply | |
| 139 | pub const ENSRCONNREFUSED = 170; // Could not contact DNS servers | |
| 140 | pub const ENSRTIMEOUT = 171; // Timeout while contacting DNS servers | |
| 141 | pub const ENSROF = 172; // End of file | |
| 142 | pub const ENSRFILE = 173; // Error reading file | |
| 143 | pub const ENSRNOMEM = 174; // Out of memory | |
| 144 | pub const ENSRDESTRUCTION = 175; // Application terminated lookup | |
| 145 | pub const ENSRQUERYDOMAINTOOLONG = 176; // Domain name is too long | |
| 146 | pub const ENSRCNAMELOOP = 177; // Domain name is too long |
std/index.zig+4-11| ... | ... | @@ -1,6 +1,7 @@ |
| 1 | pub const build = @import("build.zig"); | |
| 1 | pub const c = @import("c/index.zig"); | |
| 2 | 2 | pub const cstr = @import("cstr.zig"); |
| 3 | 3 | pub const debug = @import("debug.zig"); |
| 4 | pub const empty_import = @import("empty.zig"); | |
| 4 | 5 | pub const fmt = @import("fmt.zig"); |
| 5 | 6 | pub const hash_map = @import("hash_map.zig"); |
| 6 | 7 | pub const io = @import("io.zig"); |
| ... | ... | @@ -8,15 +9,7 @@ pub const list = @import("list.zig"); |
| 8 | 9 | pub const math = @import("math.zig"); |
| 9 | 10 | pub const mem = @import("mem.zig"); |
| 10 | 11 | pub const net = @import("net.zig"); |
| 11 | pub const os = @import("os.zig"); | |
| 12 | pub const os = @import("os/index.zig"); | |
| 12 | 13 | pub const rand = @import("rand.zig"); |
| 13 | 14 | pub const sort = @import("sort.zig"); |
| 14 | pub const linux = switch(@compileVar("os")) { | |
| 15 | Os.linux => @import("linux.zig"), | |
| 16 | else => empty_import, | |
| 17 | }; | |
| 18 | pub const darwin = switch(@compileVar("os")) { | |
| 19 | Os.darwin => @import("darwin.zig"), | |
| 20 | else => empty_import, | |
| 21 | }; | |
| 22 | pub const empty_import = @import("empty.zig"); | |
| 15 | pub const target = @import("target.zig"); |
std/io.zig+4-4| ... | ... | @@ -1,14 +1,14 @@ |
| 1 | 1 | const 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"), | |
| 4 | 4 | else => @compileError("Unsupported OS"), |
| 5 | 5 | }; |
| 6 | 6 | |
| 7 | const errno = @import("errno.zig"); | |
| 7 | const errno = @import("os/errno.zig"); | |
| 8 | 8 | const math = @import("math.zig"); |
| 9 | 9 | const debug = @import("debug.zig"); |
| 10 | 10 | const assert = debug.assert; |
| 11 | const os = @import("os.zig"); | |
| 11 | const os = @import("os/index.zig"); | |
| 12 | 12 | const mem = @import("mem.zig"); |
| 13 | 13 | const Buffer0 = @import("cstr.zig").Buffer0; |
| 14 | 14 | const fmt = @import("fmt.zig"); |
std/linux.zig deleted-492| ... | ... | @@ -1,492 +0,0 @@ |
| 1 | const 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 | }; | |
| 6 | const errno = @import("errno.zig"); | |
| 7 | ||
| 8 | pub const MMAP_PROT_NONE = 0; | |
| 9 | pub const MMAP_PROT_READ = 1; | |
| 10 | pub const MMAP_PROT_WRITE = 2; | |
| 11 | pub const MMAP_PROT_EXEC = 4; | |
| 12 | ||
| 13 | pub const MMAP_MAP_FILE = 0; | |
| 14 | pub const MMAP_MAP_SHARED = 1; | |
| 15 | pub const MMAP_MAP_PRIVATE = 2; | |
| 16 | pub const MMAP_MAP_FIXED = 16; | |
| 17 | pub const MMAP_MAP_ANON = 32; | |
| 18 | ||
| 19 | pub const SIGHUP = 1; | |
| 20 | pub const SIGINT = 2; | |
| 21 | pub const SIGQUIT = 3; | |
| 22 | pub const SIGILL = 4; | |
| 23 | pub const SIGTRAP = 5; | |
| 24 | pub const SIGABRT = 6; | |
| 25 | pub const SIGIOT = SIGABRT; | |
| 26 | pub const SIGBUS = 7; | |
| 27 | pub const SIGFPE = 8; | |
| 28 | pub const SIGKILL = 9; | |
| 29 | pub const SIGUSR1 = 10; | |
| 30 | pub const SIGSEGV = 11; | |
| 31 | pub const SIGUSR2 = 12; | |
| 32 | pub const SIGPIPE = 13; | |
| 33 | pub const SIGALRM = 14; | |
| 34 | pub const SIGTERM = 15; | |
| 35 | pub const SIGSTKFLT = 16; | |
| 36 | pub const SIGCHLD = 17; | |
| 37 | pub const SIGCONT = 18; | |
| 38 | pub const SIGSTOP = 19; | |
| 39 | pub const SIGTSTP = 20; | |
| 40 | pub const SIGTTIN = 21; | |
| 41 | pub const SIGTTOU = 22; | |
| 42 | pub const SIGURG = 23; | |
| 43 | pub const SIGXCPU = 24; | |
| 44 | pub const SIGXFSZ = 25; | |
| 45 | pub const SIGVTALRM = 26; | |
| 46 | pub const SIGPROF = 27; | |
| 47 | pub const SIGWINCH = 28; | |
| 48 | pub const SIGIO = 29; | |
| 49 | pub const SIGPOLL = 29; | |
| 50 | pub const SIGPWR = 30; | |
| 51 | pub const SIGSYS = 31; | |
| 52 | pub const SIGUNUSED = SIGSYS; | |
| 53 | ||
| 54 | pub const O_RDONLY = 0o0; | |
| 55 | pub const O_WRONLY = 0o1; | |
| 56 | pub const O_RDWR = 0o2; | |
| 57 | ||
| 58 | pub const O_CREAT = arch.O_CREAT; | |
| 59 | pub const O_EXCL = arch.O_EXCL; | |
| 60 | pub const O_NOCTTY = arch.O_NOCTTY; | |
| 61 | pub const O_TRUNC = arch.O_TRUNC; | |
| 62 | pub const O_APPEND = arch.O_APPEND; | |
| 63 | pub const O_NONBLOCK = arch.O_NONBLOCK; | |
| 64 | pub const O_DSYNC = arch.O_DSYNC; | |
| 65 | pub const O_SYNC = arch.O_SYNC; | |
| 66 | pub const O_RSYNC = arch.O_RSYNC; | |
| 67 | pub const O_DIRECTORY = arch.O_DIRECTORY; | |
| 68 | pub const O_NOFOLLOW = arch.O_NOFOLLOW; | |
| 69 | pub const O_CLOEXEC = arch.O_CLOEXEC; | |
| 70 | ||
| 71 | pub const O_ASYNC = arch.O_ASYNC; | |
| 72 | pub const O_DIRECT = arch.O_DIRECT; | |
| 73 | pub const O_LARGEFILE = arch.O_LARGEFILE; | |
| 74 | pub const O_NOATIME = arch.O_NOATIME; | |
| 75 | pub const O_PATH = arch.O_PATH; | |
| 76 | pub const O_TMPFILE = arch.O_TMPFILE; | |
| 77 | pub const O_NDELAY = arch.O_NDELAY; | |
| 78 | ||
| 79 | pub const SEEK_SET = 0; | |
| 80 | pub const SEEK_CUR = 1; | |
| 81 | pub const SEEK_END = 2; | |
| 82 | ||
| 83 | const SIG_BLOCK = 0; | |
| 84 | const SIG_UNBLOCK = 1; | |
| 85 | const SIG_SETMASK = 2; | |
| 86 | ||
| 87 | pub const SOCK_STREAM = 1; | |
| 88 | pub const SOCK_DGRAM = 2; | |
| 89 | pub const SOCK_RAW = 3; | |
| 90 | pub const SOCK_RDM = 4; | |
| 91 | pub const SOCK_SEQPACKET = 5; | |
| 92 | pub const SOCK_DCCP = 6; | |
| 93 | pub const SOCK_PACKET = 10; | |
| 94 | pub const SOCK_CLOEXEC = 0o2000000; | |
| 95 | pub const SOCK_NONBLOCK = 0o4000; | |
| 96 | ||
| 97 | ||
| 98 | pub const PROTO_ip = 0o000; | |
| 99 | pub const PROTO_icmp = 0o001; | |
| 100 | pub const PROTO_igmp = 0o002; | |
| 101 | pub const PROTO_ggp = 0o003; | |
| 102 | pub const PROTO_ipencap = 0o004; | |
| 103 | pub const PROTO_st = 0o005; | |
| 104 | pub const PROTO_tcp = 0o006; | |
| 105 | pub const PROTO_egp = 0o010; | |
| 106 | pub const PROTO_pup = 0o014; | |
| 107 | pub const PROTO_udp = 0o021; | |
| 108 | pub const PROTO_hmp = 0o024; | |
| 109 | pub const PROTO_xns_idp = 0o026; | |
| 110 | pub const PROTO_rdp = 0o033; | |
| 111 | pub const PROTO_iso_tp4 = 0o035; | |
| 112 | pub const PROTO_xtp = 0o044; | |
| 113 | pub const PROTO_ddp = 0o045; | |
| 114 | pub const PROTO_idpr_cmtp = 0o046; | |
| 115 | pub const PROTO_ipv6 = 0o051; | |
| 116 | pub const PROTO_ipv6_route = 0o053; | |
| 117 | pub const PROTO_ipv6_frag = 0o054; | |
| 118 | pub const PROTO_idrp = 0o055; | |
| 119 | pub const PROTO_rsvp = 0o056; | |
| 120 | pub const PROTO_gre = 0o057; | |
| 121 | pub const PROTO_esp = 0o062; | |
| 122 | pub const PROTO_ah = 0o063; | |
| 123 | pub const PROTO_skip = 0o071; | |
| 124 | pub const PROTO_ipv6_icmp = 0o072; | |
| 125 | pub const PROTO_ipv6_nonxt = 0o073; | |
| 126 | pub const PROTO_ipv6_opts = 0o074; | |
| 127 | pub const PROTO_rspf = 0o111; | |
| 128 | pub const PROTO_vmtp = 0o121; | |
| 129 | pub const PROTO_ospf = 0o131; | |
| 130 | pub const PROTO_ipip = 0o136; | |
| 131 | pub const PROTO_encap = 0o142; | |
| 132 | pub const PROTO_pim = 0o147; | |
| 133 | pub const PROTO_raw = 0o377; | |
| 134 | ||
| 135 | pub const PF_UNSPEC = 0; | |
| 136 | pub const PF_LOCAL = 1; | |
| 137 | pub const PF_UNIX = PF_LOCAL; | |
| 138 | pub const PF_FILE = PF_LOCAL; | |
| 139 | pub const PF_INET = 2; | |
| 140 | pub const PF_AX25 = 3; | |
| 141 | pub const PF_IPX = 4; | |
| 142 | pub const PF_APPLETALK = 5; | |
| 143 | pub const PF_NETROM = 6; | |
| 144 | pub const PF_BRIDGE = 7; | |
| 145 | pub const PF_ATMPVC = 8; | |
| 146 | pub const PF_X25 = 9; | |
| 147 | pub const PF_INET6 = 10; | |
| 148 | pub const PF_ROSE = 11; | |
| 149 | pub const PF_DECnet = 12; | |
| 150 | pub const PF_NETBEUI = 13; | |
| 151 | pub const PF_SECURITY = 14; | |
| 152 | pub const PF_KEY = 15; | |
| 153 | pub const PF_NETLINK = 16; | |
| 154 | pub const PF_ROUTE = PF_NETLINK; | |
| 155 | pub const PF_PACKET = 17; | |
| 156 | pub const PF_ASH = 18; | |
| 157 | pub const PF_ECONET = 19; | |
| 158 | pub const PF_ATMSVC = 20; | |
| 159 | pub const PF_RDS = 21; | |
| 160 | pub const PF_SNA = 22; | |
| 161 | pub const PF_IRDA = 23; | |
| 162 | pub const PF_PPPOX = 24; | |
| 163 | pub const PF_WANPIPE = 25; | |
| 164 | pub const PF_LLC = 26; | |
| 165 | pub const PF_IB = 27; | |
| 166 | pub const PF_MPLS = 28; | |
| 167 | pub const PF_CAN = 29; | |
| 168 | pub const PF_TIPC = 30; | |
| 169 | pub const PF_BLUETOOTH = 31; | |
| 170 | pub const PF_IUCV = 32; | |
| 171 | pub const PF_RXRPC = 33; | |
| 172 | pub const PF_ISDN = 34; | |
| 173 | pub const PF_PHONET = 35; | |
| 174 | pub const PF_IEEE802154 = 36; | |
| 175 | pub const PF_CAIF = 37; | |
| 176 | pub const PF_ALG = 38; | |
| 177 | pub const PF_NFC = 39; | |
| 178 | pub const PF_VSOCK = 40; | |
| 179 | pub const PF_MAX = 41; | |
| 180 | ||
| 181 | pub const AF_UNSPEC = PF_UNSPEC; | |
| 182 | pub const AF_LOCAL = PF_LOCAL; | |
| 183 | pub const AF_UNIX = AF_LOCAL; | |
| 184 | pub const AF_FILE = AF_LOCAL; | |
| 185 | pub const AF_INET = PF_INET; | |
| 186 | pub const AF_AX25 = PF_AX25; | |
| 187 | pub const AF_IPX = PF_IPX; | |
| 188 | pub const AF_APPLETALK = PF_APPLETALK; | |
| 189 | pub const AF_NETROM = PF_NETROM; | |
| 190 | pub const AF_BRIDGE = PF_BRIDGE; | |
| 191 | pub const AF_ATMPVC = PF_ATMPVC; | |
| 192 | pub const AF_X25 = PF_X25; | |
| 193 | pub const AF_INET6 = PF_INET6; | |
| 194 | pub const AF_ROSE = PF_ROSE; | |
| 195 | pub const AF_DECnet = PF_DECnet; | |
| 196 | pub const AF_NETBEUI = PF_NETBEUI; | |
| 197 | pub const AF_SECURITY = PF_SECURITY; | |
| 198 | pub const AF_KEY = PF_KEY; | |
| 199 | pub const AF_NETLINK = PF_NETLINK; | |
| 200 | pub const AF_ROUTE = PF_ROUTE; | |
| 201 | pub const AF_PACKET = PF_PACKET; | |
| 202 | pub const AF_ASH = PF_ASH; | |
| 203 | pub const AF_ECONET = PF_ECONET; | |
| 204 | pub const AF_ATMSVC = PF_ATMSVC; | |
| 205 | pub const AF_RDS = PF_RDS; | |
| 206 | pub const AF_SNA = PF_SNA; | |
| 207 | pub const AF_IRDA = PF_IRDA; | |
| 208 | pub const AF_PPPOX = PF_PPPOX; | |
| 209 | pub const AF_WANPIPE = PF_WANPIPE; | |
| 210 | pub const AF_LLC = PF_LLC; | |
| 211 | pub const AF_IB = PF_IB; | |
| 212 | pub const AF_MPLS = PF_MPLS; | |
| 213 | pub const AF_CAN = PF_CAN; | |
| 214 | pub const AF_TIPC = PF_TIPC; | |
| 215 | pub const AF_BLUETOOTH = PF_BLUETOOTH; | |
| 216 | pub const AF_IUCV = PF_IUCV; | |
| 217 | pub const AF_RXRPC = PF_RXRPC; | |
| 218 | pub const AF_ISDN = PF_ISDN; | |
| 219 | pub const AF_PHONET = PF_PHONET; | |
| 220 | pub const AF_IEEE802154 = PF_IEEE802154; | |
| 221 | pub const AF_CAIF = PF_CAIF; | |
| 222 | pub const AF_ALG = PF_ALG; | |
| 223 | pub const AF_NFC = PF_NFC; | |
| 224 | pub const AF_VSOCK = PF_VSOCK; | |
| 225 | pub const AF_MAX = PF_MAX; | |
| 226 | ||
| 227 | /// Get the errno from a syscall return value, or 0 for no error. | |
| 228 | pub 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 | ||
| 233 | pub 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 | ||
| 239 | pub fn munmap(address: &u8, length: usize) -> usize { | |
| 240 | arch.syscall2(arch.SYS_munmap, usize(address), length) | |
| 241 | } | |
| 242 | ||
| 243 | pub fn read(fd: i32, buf: &u8, count: usize) -> usize { | |
| 244 | arch.syscall3(arch.SYS_read, usize(fd), usize(buf), count) | |
| 245 | } | |
| 246 | ||
| 247 | pub 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 | ||
| 251 | pub fn write(fd: i32, buf: &const u8, count: usize) -> usize { | |
| 252 | arch.syscall3(arch.SYS_write, usize(fd), usize(buf), count) | |
| 253 | } | |
| 254 | ||
| 255 | pub 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 | ||
| 259 | pub fn open_c(path: &const u8, flags: usize, perm: usize) -> usize { | |
| 260 | arch.syscall3(arch.SYS_open, usize(path), flags, perm) | |
| 261 | } | |
| 262 | ||
| 263 | pub 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 | ||
| 270 | pub fn create_c(path: &const u8, perm: usize) -> usize { | |
| 271 | arch.syscall2(arch.SYS_creat, usize(path), perm) | |
| 272 | } | |
| 273 | ||
| 274 | pub 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 | ||
| 281 | pub 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 | ||
| 285 | pub 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 | ||
| 292 | pub fn close(fd: i32) -> usize { | |
| 293 | arch.syscall1(arch.SYS_close, usize(fd)) | |
| 294 | } | |
| 295 | ||
| 296 | pub fn lseek(fd: i32, offset: usize, ref_pos: usize) -> usize { | |
| 297 | arch.syscall3(arch.SYS_lseek, usize(fd), offset, ref_pos) | |
| 298 | } | |
| 299 | ||
| 300 | pub fn exit(status: i32) -> noreturn { | |
| 301 | _ = arch.syscall1(arch.SYS_exit, usize(status)); | |
| 302 | unreachable | |
| 303 | } | |
| 304 | ||
| 305 | pub fn getrandom(buf: &u8, count: usize, flags: u32) -> usize { | |
| 306 | arch.syscall3(arch.SYS_getrandom, usize(buf), count, usize(flags)) | |
| 307 | } | |
| 308 | ||
| 309 | pub fn kill(pid: i32, sig: i32) -> i32 { | |
| 310 | i32(arch.syscall2(arch.SYS_kill, usize(pid), usize(sig))) | |
| 311 | } | |
| 312 | ||
| 313 | const NSIG = 65; | |
| 314 | const sigset_t = [128]u8; | |
| 315 | const all_mask = []u8 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, }; | |
| 316 | const app_mask = []u8 { 0xff, 0xff, 0xff, 0xfc, 0x7f, 0xff, 0xff, 0xff, }; | |
| 317 | ||
| 318 | pub 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 | ||
| 327 | fn blockAllSignals(set: &sigset_t) { | |
| 328 | _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_BLOCK, usize(&all_mask), usize(set), NSIG/8); | |
| 329 | } | |
| 330 | ||
| 331 | fn blockAppSignals(set: &sigset_t) { | |
| 332 | _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_BLOCK, usize(&app_mask), usize(set), NSIG/8); | |
| 333 | } | |
| 334 | ||
| 335 | fn restoreSignals(set: &sigset_t) { | |
| 336 | _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_SETMASK, usize(set), 0, NSIG/8); | |
| 337 | } | |
| 338 | ||
| 339 | ||
| 340 | pub const sa_family_t = u16; | |
| 341 | pub const socklen_t = u32; | |
| 342 | pub const in_addr = u32; | |
| 343 | pub const in6_addr = [16]u8; | |
| 344 | ||
| 345 | pub const sockaddr = extern struct { | |
| 346 | family: sa_family_t, | |
| 347 | port: u16, | |
| 348 | data: [12]u8, | |
| 349 | }; | |
| 350 | ||
| 351 | pub const sockaddr_in = extern struct { | |
| 352 | family: sa_family_t, | |
| 353 | port: u16, | |
| 354 | addr: in_addr, | |
| 355 | zero: [8]u8, | |
| 356 | }; | |
| 357 | ||
| 358 | pub 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 | ||
| 366 | pub 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 | ||
| 393 | pub 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 | ||
| 397 | pub 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 | ||
| 401 | pub 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 | ||
| 405 | pub 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 | ||
| 409 | pub 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 | ||
| 413 | pub fn sendmsg(fd: i32, msg: &const arch.msghdr, flags: u32) -> usize { | |
| 414 | arch.syscall3(arch.SYS_sendmsg, usize(fd), usize(msg), flags) | |
| 415 | } | |
| 416 | ||
| 417 | pub 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 | ||
| 421 | pub fn recvmsg(fd: i32, msg: &arch.msghdr, flags: u32) -> usize { | |
| 422 | arch.syscall3(arch.SYS_recvmsg, usize(fd), usize(msg), flags) | |
| 423 | } | |
| 424 | ||
| 425 | pub 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 | ||
| 431 | pub fn shutdown(fd: i32, how: i32) -> usize { | |
| 432 | arch.syscall2(arch.SYS_shutdown, usize(fd), usize(how)) | |
| 433 | } | |
| 434 | ||
| 435 | pub 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 | ||
| 439 | pub fn listen(fd: i32, backlog: i32) -> usize { | |
| 440 | arch.syscall2(arch.SYS_listen, usize(fd), usize(backlog)) | |
| 441 | } | |
| 442 | ||
| 443 | pub 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 | ||
| 447 | pub 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 | ||
| 451 | pub fn accept(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize { | |
| 452 | accept4(fd, addr, len, 0) | |
| 453 | } | |
| 454 | ||
| 455 | pub 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 | ||
| 487 | pub const stat = arch.stat; | |
| 488 | pub const timespec = arch.timespec; | |
| 489 | ||
| 490 | pub 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 @@ |
| 1 | const linux = @import("linux.zig"); | |
| 2 | const socklen_t = linux.socklen_t; | |
| 3 | const iovec = linux.iovec; | |
| 4 | ||
| 5 | pub const SYS_restart_syscall = 0; | |
| 6 | pub const SYS_exit = 1; | |
| 7 | pub const SYS_fork = 2; | |
| 8 | pub const SYS_read = 3; | |
| 9 | pub const SYS_write = 4; | |
| 10 | pub const SYS_open = 5; | |
| 11 | pub const SYS_close = 6; | |
| 12 | pub const SYS_waitpid = 7; | |
| 13 | pub const SYS_creat = 8; | |
| 14 | pub const SYS_link = 9; | |
| 15 | pub const SYS_unlink = 10; | |
| 16 | pub const SYS_execve = 11; | |
| 17 | pub const SYS_chdir = 12; | |
| 18 | pub const SYS_time = 13; | |
| 19 | pub const SYS_mknod = 14; | |
| 20 | pub const SYS_chmod = 15; | |
| 21 | pub const SYS_lchown = 16; | |
| 22 | pub const SYS_break = 17; | |
| 23 | pub const SYS_oldstat = 18; | |
| 24 | pub const SYS_lseek = 19; | |
| 25 | pub const SYS_getpid = 20; | |
| 26 | pub const SYS_mount = 21; | |
| 27 | pub const SYS_umount = 22; | |
| 28 | pub const SYS_setuid = 23; | |
| 29 | pub const SYS_getuid = 24; | |
| 30 | pub const SYS_stime = 25; | |
| 31 | pub const SYS_ptrace = 26; | |
| 32 | pub const SYS_alarm = 27; | |
| 33 | pub const SYS_oldfstat = 28; | |
| 34 | pub const SYS_pause = 29; | |
| 35 | pub const SYS_utime = 30; | |
| 36 | pub const SYS_stty = 31; | |
| 37 | pub const SYS_gtty = 32; | |
| 38 | pub const SYS_access = 33; | |
| 39 | pub const SYS_nice = 34; | |
| 40 | pub const SYS_ftime = 35; | |
| 41 | pub const SYS_sync = 36; | |
| 42 | pub const SYS_kill = 37; | |
| 43 | pub const SYS_rename = 38; | |
| 44 | pub const SYS_mkdir = 39; | |
| 45 | pub const SYS_rmdir = 40; | |
| 46 | pub const SYS_dup = 41; | |
| 47 | pub const SYS_pipe = 42; | |
| 48 | pub const SYS_times = 43; | |
| 49 | pub const SYS_prof = 44; | |
| 50 | pub const SYS_brk = 45; | |
| 51 | pub const SYS_setgid = 46; | |
| 52 | pub const SYS_getgid = 47; | |
| 53 | pub const SYS_signal = 48; | |
| 54 | pub const SYS_geteuid = 49; | |
| 55 | pub const SYS_getegid = 50; | |
| 56 | pub const SYS_acct = 51; | |
| 57 | pub const SYS_umount2 = 52; | |
| 58 | pub const SYS_lock = 53; | |
| 59 | pub const SYS_ioctl = 54; | |
| 60 | pub const SYS_fcntl = 55; | |
| 61 | pub const SYS_mpx = 56; | |
| 62 | pub const SYS_setpgid = 57; | |
| 63 | pub const SYS_ulimit = 58; | |
| 64 | pub const SYS_oldolduname = 59; | |
| 65 | pub const SYS_umask = 60; | |
| 66 | pub const SYS_chroot = 61; | |
| 67 | pub const SYS_ustat = 62; | |
| 68 | pub const SYS_dup2 = 63; | |
| 69 | pub const SYS_getppid = 64; | |
| 70 | pub const SYS_getpgrp = 65; | |
| 71 | pub const SYS_setsid = 66; | |
| 72 | pub const SYS_sigaction = 67; | |
| 73 | pub const SYS_sgetmask = 68; | |
| 74 | pub const SYS_ssetmask = 69; | |
| 75 | pub const SYS_setreuid = 70; | |
| 76 | pub const SYS_setregid = 71; | |
| 77 | pub const SYS_sigsuspend = 72; | |
| 78 | pub const SYS_sigpending = 73; | |
| 79 | pub const SYS_sethostname = 74; | |
| 80 | pub const SYS_setrlimit = 75; | |
| 81 | pub const SYS_getrlimit = 76; | |
| 82 | pub const SYS_getrusage = 77; | |
| 83 | pub const SYS_gettimeofday = 78; | |
| 84 | pub const SYS_settimeofday = 79; | |
| 85 | pub const SYS_getgroups = 80; | |
| 86 | pub const SYS_setgroups = 81; | |
| 87 | pub const SYS_select = 82; | |
| 88 | pub const SYS_symlink = 83; | |
| 89 | pub const SYS_oldlstat = 84; | |
| 90 | pub const SYS_readlink = 85; | |
| 91 | pub const SYS_uselib = 86; | |
| 92 | pub const SYS_swapon = 87; | |
| 93 | pub const SYS_reboot = 88; | |
| 94 | pub const SYS_readdir = 89; | |
| 95 | pub const SYS_mmap = 90; | |
| 96 | pub const SYS_munmap = 91; | |
| 97 | pub const SYS_truncate = 92; | |
| 98 | pub const SYS_ftruncate = 93; | |
| 99 | pub const SYS_fchmod = 94; | |
| 100 | pub const SYS_fchown = 95; | |
| 101 | pub const SYS_getpriority = 96; | |
| 102 | pub const SYS_setpriority = 97; | |
| 103 | pub const SYS_profil = 98; | |
| 104 | pub const SYS_statfs = 99; | |
| 105 | pub const SYS_fstatfs = 100; | |
| 106 | pub const SYS_ioperm = 101; | |
| 107 | pub const SYS_socketcall = 102; | |
| 108 | pub const SYS_syslog = 103; | |
| 109 | pub const SYS_setitimer = 104; | |
| 110 | pub const SYS_getitimer = 105; | |
| 111 | pub const SYS_stat = 106; | |
| 112 | pub const SYS_lstat = 107; | |
| 113 | pub const SYS_fstat = 108; | |
| 114 | pub const SYS_olduname = 109; | |
| 115 | pub const SYS_iopl = 110; | |
| 116 | pub const SYS_vhangup = 111; | |
| 117 | pub const SYS_idle = 112; | |
| 118 | pub const SYS_vm86old = 113; | |
| 119 | pub const SYS_wait4 = 114; | |
| 120 | pub const SYS_swapoff = 115; | |
| 121 | pub const SYS_sysinfo = 116; | |
| 122 | pub const SYS_ipc = 117; | |
| 123 | pub const SYS_fsync = 118; | |
| 124 | pub const SYS_sigreturn = 119; | |
| 125 | pub const SYS_clone = 120; | |
| 126 | pub const SYS_setdomainname = 121; | |
| 127 | pub const SYS_uname = 122; | |
| 128 | pub const SYS_modify_ldt = 123; | |
| 129 | pub const SYS_adjtimex = 124; | |
| 130 | pub const SYS_mprotect = 125; | |
| 131 | pub const SYS_sigprocmask = 126; | |
| 132 | pub const SYS_create_module = 127; | |
| 133 | pub const SYS_init_module = 128; | |
| 134 | pub const SYS_delete_module = 129; | |
| 135 | pub const SYS_get_kernel_syms = 130; | |
| 136 | pub const SYS_quotactl = 131; | |
| 137 | pub const SYS_getpgid = 132; | |
| 138 | pub const SYS_fchdir = 133; | |
| 139 | pub const SYS_bdflush = 134; | |
| 140 | pub const SYS_sysfs = 135; | |
| 141 | pub const SYS_personality = 136; | |
| 142 | pub const SYS_afs_syscall = 137; | |
| 143 | pub const SYS_setfsuid = 138; | |
| 144 | pub const SYS_setfsgid = 139; | |
| 145 | pub const SYS__llseek = 140; | |
| 146 | pub const SYS_getdents = 141; | |
| 147 | pub const SYS__newselect = 142; | |
| 148 | pub const SYS_flock = 143; | |
| 149 | pub const SYS_msync = 144; | |
| 150 | pub const SYS_readv = 145; | |
| 151 | pub const SYS_writev = 146; | |
| 152 | pub const SYS_getsid = 147; | |
| 153 | pub const SYS_fdatasync = 148; | |
| 154 | pub const SYS__sysctl = 149; | |
| 155 | pub const SYS_mlock = 150; | |
| 156 | pub const SYS_munlock = 151; | |
| 157 | pub const SYS_mlockall = 152; | |
| 158 | pub const SYS_munlockall = 153; | |
| 159 | pub const SYS_sched_setparam = 154; | |
| 160 | pub const SYS_sched_getparam = 155; | |
| 161 | pub const SYS_sched_setscheduler = 156; | |
| 162 | pub const SYS_sched_getscheduler = 157; | |
| 163 | pub const SYS_sched_yield = 158; | |
| 164 | pub const SYS_sched_get_priority_max = 159; | |
| 165 | pub const SYS_sched_get_priority_min = 160; | |
| 166 | pub const SYS_sched_rr_get_interval = 161; | |
| 167 | pub const SYS_nanosleep = 162; | |
| 168 | pub const SYS_mremap = 163; | |
| 169 | pub const SYS_setresuid = 164; | |
| 170 | pub const SYS_getresuid = 165; | |
| 171 | pub const SYS_vm86 = 166; | |
| 172 | pub const SYS_query_module = 167; | |
| 173 | pub const SYS_poll = 168; | |
| 174 | pub const SYS_nfsservctl = 169; | |
| 175 | pub const SYS_setresgid = 170; | |
| 176 | pub const SYS_getresgid = 171; | |
| 177 | pub const SYS_prctl = 172; | |
| 178 | pub const SYS_rt_sigreturn = 173; | |
| 179 | pub const SYS_rt_sigaction = 174; | |
| 180 | pub const SYS_rt_sigprocmask = 175; | |
| 181 | pub const SYS_rt_sigpending = 176; | |
| 182 | pub const SYS_rt_sigtimedwait = 177; | |
| 183 | pub const SYS_rt_sigqueueinfo = 178; | |
| 184 | pub const SYS_rt_sigsuspend = 179; | |
| 185 | pub const SYS_pread64 = 180; | |
| 186 | pub const SYS_pwrite64 = 181; | |
| 187 | pub const SYS_chown = 182; | |
| 188 | pub const SYS_getcwd = 183; | |
| 189 | pub const SYS_capget = 184; | |
| 190 | pub const SYS_capset = 185; | |
| 191 | pub const SYS_sigaltstack = 186; | |
| 192 | pub const SYS_sendfile = 187; | |
| 193 | pub const SYS_getpmsg = 188; | |
| 194 | pub const SYS_putpmsg = 189; | |
| 195 | pub const SYS_vfork = 190; | |
| 196 | pub const SYS_ugetrlimit = 191; | |
| 197 | pub const SYS_mmap2 = 192; | |
| 198 | pub const SYS_truncate64 = 193; | |
| 199 | pub const SYS_ftruncate64 = 194; | |
| 200 | pub const SYS_stat64 = 195; | |
| 201 | pub const SYS_lstat64 = 196; | |
| 202 | pub const SYS_fstat64 = 197; | |
| 203 | pub const SYS_lchown32 = 198; | |
| 204 | pub const SYS_getuid32 = 199; | |
| 205 | pub const SYS_getgid32 = 200; | |
| 206 | pub const SYS_geteuid32 = 201; | |
| 207 | pub const SYS_getegid32 = 202; | |
| 208 | pub const SYS_setreuid32 = 203; | |
| 209 | pub const SYS_setregid32 = 204; | |
| 210 | pub const SYS_getgroups32 = 205; | |
| 211 | pub const SYS_setgroups32 = 206; | |
| 212 | pub const SYS_fchown32 = 207; | |
| 213 | pub const SYS_setresuid32 = 208; | |
| 214 | pub const SYS_getresuid32 = 209; | |
| 215 | pub const SYS_setresgid32 = 210; | |
| 216 | pub const SYS_getresgid32 = 211; | |
| 217 | pub const SYS_chown32 = 212; | |
| 218 | pub const SYS_setuid32 = 213; | |
| 219 | pub const SYS_setgid32 = 214; | |
| 220 | pub const SYS_setfsuid32 = 215; | |
| 221 | pub const SYS_setfsgid32 = 216; | |
| 222 | pub const SYS_pivot_root = 217; | |
| 223 | pub const SYS_mincore = 218; | |
| 224 | pub const SYS_madvise = 219; | |
| 225 | pub const SYS_madvise1 = 219; | |
| 226 | pub const SYS_getdents64 = 220; | |
| 227 | pub const SYS_fcntl64 = 221; | |
| 228 | pub const SYS_gettid = 224; | |
| 229 | pub const SYS_readahead = 225; | |
| 230 | pub const SYS_setxattr = 226; | |
| 231 | pub const SYS_lsetxattr = 227; | |
| 232 | pub const SYS_fsetxattr = 228; | |
| 233 | pub const SYS_getxattr = 229; | |
| 234 | pub const SYS_lgetxattr = 230; | |
| 235 | pub const SYS_fgetxattr = 231; | |
| 236 | pub const SYS_listxattr = 232; | |
| 237 | pub const SYS_llistxattr = 233; | |
| 238 | pub const SYS_flistxattr = 234; | |
| 239 | pub const SYS_removexattr = 235; | |
| 240 | pub const SYS_lremovexattr = 236; | |
| 241 | pub const SYS_fremovexattr = 237; | |
| 242 | pub const SYS_tkill = 238; | |
| 243 | pub const SYS_sendfile64 = 239; | |
| 244 | pub const SYS_futex = 240; | |
| 245 | pub const SYS_sched_setaffinity = 241; | |
| 246 | pub const SYS_sched_getaffinity = 242; | |
| 247 | pub const SYS_set_thread_area = 243; | |
| 248 | pub const SYS_get_thread_area = 244; | |
| 249 | pub const SYS_io_setup = 245; | |
| 250 | pub const SYS_io_destroy = 246; | |
| 251 | pub const SYS_io_getevents = 247; | |
| 252 | pub const SYS_io_submit = 248; | |
| 253 | pub const SYS_io_cancel = 249; | |
| 254 | pub const SYS_fadvise64 = 250; | |
| 255 | pub const SYS_exit_group = 252; | |
| 256 | pub const SYS_lookup_dcookie = 253; | |
| 257 | pub const SYS_epoll_create = 254; | |
| 258 | pub const SYS_epoll_ctl = 255; | |
| 259 | pub const SYS_epoll_wait = 256; | |
| 260 | pub const SYS_remap_file_pages = 257; | |
| 261 | pub const SYS_set_tid_address = 258; | |
| 262 | pub const SYS_timer_create = 259; | |
| 263 | pub const SYS_timer_settime = SYS_timer_create+1; | |
| 264 | pub const SYS_timer_gettime = SYS_timer_create+2; | |
| 265 | pub const SYS_timer_getoverrun = SYS_timer_create+3; | |
| 266 | pub const SYS_timer_delete = SYS_timer_create+4; | |
| 267 | pub const SYS_clock_settime = SYS_timer_create+5; | |
| 268 | pub const SYS_clock_gettime = SYS_timer_create+6; | |
| 269 | pub const SYS_clock_getres = SYS_timer_create+7; | |
| 270 | pub const SYS_clock_nanosleep = SYS_timer_create+8; | |
| 271 | pub const SYS_statfs64 = 268; | |
| 272 | pub const SYS_fstatfs64 = 269; | |
| 273 | pub const SYS_tgkill = 270; | |
| 274 | pub const SYS_utimes = 271; | |
| 275 | pub const SYS_fadvise64_64 = 272; | |
| 276 | pub const SYS_vserver = 273; | |
| 277 | pub const SYS_mbind = 274; | |
| 278 | pub const SYS_get_mempolicy = 275; | |
| 279 | pub const SYS_set_mempolicy = 276; | |
| 280 | pub const SYS_mq_open = 277; | |
| 281 | pub const SYS_mq_unlink = SYS_mq_open+1; | |
| 282 | pub const SYS_mq_timedsend = SYS_mq_open+2; | |
| 283 | pub const SYS_mq_timedreceive = SYS_mq_open+3; | |
| 284 | pub const SYS_mq_notify = SYS_mq_open+4; | |
| 285 | pub const SYS_mq_getsetattr = SYS_mq_open+5; | |
| 286 | pub const SYS_kexec_load = 283; | |
| 287 | pub const SYS_waitid = 284; | |
| 288 | pub const SYS_add_key = 286; | |
| 289 | pub const SYS_request_key = 287; | |
| 290 | pub const SYS_keyctl = 288; | |
| 291 | pub const SYS_ioprio_set = 289; | |
| 292 | pub const SYS_ioprio_get = 290; | |
| 293 | pub const SYS_inotify_init = 291; | |
| 294 | pub const SYS_inotify_add_watch = 292; | |
| 295 | pub const SYS_inotify_rm_watch = 293; | |
| 296 | pub const SYS_migrate_pages = 294; | |
| 297 | pub const SYS_openat = 295; | |
| 298 | pub const SYS_mkdirat = 296; | |
| 299 | pub const SYS_mknodat = 297; | |
| 300 | pub const SYS_fchownat = 298; | |
| 301 | pub const SYS_futimesat = 299; | |
| 302 | pub const SYS_fstatat64 = 300; | |
| 303 | pub const SYS_unlinkat = 301; | |
| 304 | pub const SYS_renameat = 302; | |
| 305 | pub const SYS_linkat = 303; | |
| 306 | pub const SYS_symlinkat = 304; | |
| 307 | pub const SYS_readlinkat = 305; | |
| 308 | pub const SYS_fchmodat = 306; | |
| 309 | pub const SYS_faccessat = 307; | |
| 310 | pub const SYS_pselect6 = 308; | |
| 311 | pub const SYS_ppoll = 309; | |
| 312 | pub const SYS_unshare = 310; | |
| 313 | pub const SYS_set_robust_list = 311; | |
| 314 | pub const SYS_get_robust_list = 312; | |
| 315 | pub const SYS_splice = 313; | |
| 316 | pub const SYS_sync_file_range = 314; | |
| 317 | pub const SYS_tee = 315; | |
| 318 | pub const SYS_vmsplice = 316; | |
| 319 | pub const SYS_move_pages = 317; | |
| 320 | pub const SYS_getcpu = 318; | |
| 321 | pub const SYS_epoll_pwait = 319; | |
| 322 | pub const SYS_utimensat = 320; | |
| 323 | pub const SYS_signalfd = 321; | |
| 324 | pub const SYS_timerfd_create = 322; | |
| 325 | pub const SYS_eventfd = 323; | |
| 326 | pub const SYS_fallocate = 324; | |
| 327 | pub const SYS_timerfd_settime = 325; | |
| 328 | pub const SYS_timerfd_gettime = 326; | |
| 329 | pub const SYS_signalfd4 = 327; | |
| 330 | pub const SYS_eventfd2 = 328; | |
| 331 | pub const SYS_epoll_create1 = 329; | |
| 332 | pub const SYS_dup3 = 330; | |
| 333 | pub const SYS_pipe2 = 331; | |
| 334 | pub const SYS_inotify_init1 = 332; | |
| 335 | pub const SYS_preadv = 333; | |
| 336 | pub const SYS_pwritev = 334; | |
| 337 | pub const SYS_rt_tgsigqueueinfo = 335; | |
| 338 | pub const SYS_perf_event_open = 336; | |
| 339 | pub const SYS_recvmmsg = 337; | |
| 340 | pub const SYS_fanotify_init = 338; | |
| 341 | pub const SYS_fanotify_mark = 339; | |
| 342 | pub const SYS_prlimit64 = 340; | |
| 343 | pub const SYS_name_to_handle_at = 341; | |
| 344 | pub const SYS_open_by_handle_at = 342; | |
| 345 | pub const SYS_clock_adjtime = 343; | |
| 346 | pub const SYS_syncfs = 344; | |
| 347 | pub const SYS_sendmmsg = 345; | |
| 348 | pub const SYS_setns = 346; | |
| 349 | pub const SYS_process_vm_readv = 347; | |
| 350 | pub const SYS_process_vm_writev = 348; | |
| 351 | pub const SYS_kcmp = 349; | |
| 352 | pub const SYS_finit_module = 350; | |
| 353 | pub const SYS_sched_setattr = 351; | |
| 354 | pub const SYS_sched_getattr = 352; | |
| 355 | pub const SYS_renameat2 = 353; | |
| 356 | pub const SYS_seccomp = 354; | |
| 357 | pub const SYS_getrandom = 355; | |
| 358 | pub const SYS_memfd_create = 356; | |
| 359 | pub const SYS_bpf = 357; | |
| 360 | pub const SYS_execveat = 358; | |
| 361 | pub const SYS_socket = 359; | |
| 362 | pub const SYS_socketpair = 360; | |
| 363 | pub const SYS_bind = 361; | |
| 364 | pub const SYS_connect = 362; | |
| 365 | pub const SYS_listen = 363; | |
| 366 | pub const SYS_accept4 = 364; | |
| 367 | pub const SYS_getsockopt = 365; | |
| 368 | pub const SYS_setsockopt = 366; | |
| 369 | pub const SYS_getsockname = 367; | |
| 370 | pub const SYS_getpeername = 368; | |
| 371 | pub const SYS_sendto = 369; | |
| 372 | pub const SYS_sendmsg = 370; | |
| 373 | pub const SYS_recvfrom = 371; | |
| 374 | pub const SYS_recvmsg = 372; | |
| 375 | pub const SYS_shutdown = 373; | |
| 376 | pub const SYS_userfaultfd = 374; | |
| 377 | pub const SYS_membarrier = 375; | |
| 378 | pub const SYS_mlock2 = 376; | |
| 379 | ||
| 380 | ||
| 381 | pub const O_CREAT = 0o100; | |
| 382 | pub const O_EXCL = 0o200; | |
| 383 | pub const O_NOCTTY = 0o400; | |
| 384 | pub const O_TRUNC = 0o1000; | |
| 385 | pub const O_APPEND = 0o2000; | |
| 386 | pub const O_NONBLOCK = 0o4000; | |
| 387 | pub const O_DSYNC = 0o10000; | |
| 388 | pub const O_SYNC = 0o4010000; | |
| 389 | pub const O_RSYNC = 0o4010000; | |
| 390 | pub const O_DIRECTORY = 0o200000; | |
| 391 | pub const O_NOFOLLOW = 0o400000; | |
| 392 | pub const O_CLOEXEC = 0o2000000; | |
| 393 | ||
| 394 | pub const O_ASYNC = 0o20000; | |
| 395 | pub const O_DIRECT = 0o40000; | |
| 396 | pub const O_LARGEFILE = 0o100000; | |
| 397 | pub const O_NOATIME = 0o1000000; | |
| 398 | pub const O_PATH = 0o10000000; | |
| 399 | pub const O_TMPFILE = 0o20200000; | |
| 400 | pub const O_NDELAY = O_NONBLOCK; | |
| 401 | ||
| 402 | pub const F_DUPFD = 0; | |
| 403 | pub const F_GETFD = 1; | |
| 404 | pub const F_SETFD = 2; | |
| 405 | pub const F_GETFL = 3; | |
| 406 | pub const F_SETFL = 4; | |
| 407 | ||
| 408 | pub const F_SETOWN = 8; | |
| 409 | pub const F_GETOWN = 9; | |
| 410 | pub const F_SETSIG = 10; | |
| 411 | pub const F_GETSIG = 11; | |
| 412 | ||
| 413 | pub const F_GETLK = 12; | |
| 414 | pub const F_SETLK = 13; | |
| 415 | pub const F_SETLKW = 14; | |
| 416 | ||
| 417 | pub const F_SETOWN_EX = 15; | |
| 418 | pub const F_GETOWN_EX = 16; | |
| 419 | ||
| 420 | pub const F_GETOWNER_UIDS = 17; | |
| 421 | ||
| 422 | pub inline fn syscall0(number: usize) -> usize { | |
| 423 | asm volatile ("int 80h" | |
| 424 | : [ret] "={eax}" (-> usize) | |
| 425 | : [number] "{eax}" (number)) | |
| 426 | } | |
| 427 | ||
| 428 | pub 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 | ||
| 435 | pub 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 | ||
| 443 | pub 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 | ||
| 452 | pub 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 | ||
| 462 | pub 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 | ||
| 475 | pub 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 | ||
| 489 | export 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 @@ |
| 1 | const linux = @import("linux.zig"); | |
| 2 | const socklen_t = linux.socklen_t; | |
| 3 | const iovec = linux.iovec; | |
| 4 | ||
| 5 | pub const SYS_read = 0; | |
| 6 | pub const SYS_write = 1; | |
| 7 | pub const SYS_open = 2; | |
| 8 | pub const SYS_close = 3; | |
| 9 | pub const SYS_stat = 4; | |
| 10 | pub const SYS_fstat = 5; | |
| 11 | pub const SYS_lstat = 6; | |
| 12 | pub const SYS_poll = 7; | |
| 13 | pub const SYS_lseek = 8; | |
| 14 | pub const SYS_mmap = 9; | |
| 15 | pub const SYS_mprotect = 10; | |
| 16 | pub const SYS_munmap = 11; | |
| 17 | pub const SYS_brk = 12; | |
| 18 | pub const SYS_rt_sigaction = 13; | |
| 19 | pub const SYS_rt_sigprocmask = 14; | |
| 20 | pub const SYS_rt_sigreturn = 15; | |
| 21 | pub const SYS_ioctl = 16; | |
| 22 | pub const SYS_pread = 17; | |
| 23 | pub const SYS_pwrite = 18; | |
| 24 | pub const SYS_readv = 19; | |
| 25 | pub const SYS_writev = 20; | |
| 26 | pub const SYS_access = 21; | |
| 27 | pub const SYS_pipe = 22; | |
| 28 | pub const SYS_select = 23; | |
| 29 | pub const SYS_sched_yield = 24; | |
| 30 | pub const SYS_mremap = 25; | |
| 31 | pub const SYS_msync = 26; | |
| 32 | pub const SYS_mincore = 27; | |
| 33 | pub const SYS_madvise = 28; | |
| 34 | pub const SYS_shmget = 29; | |
| 35 | pub const SYS_shmat = 30; | |
| 36 | pub const SYS_shmctl = 31; | |
| 37 | pub const SYS_dup = 32; | |
| 38 | pub const SYS_dup2 = 33; | |
| 39 | pub const SYS_pause = 34; | |
| 40 | pub const SYS_nanosleep = 35; | |
| 41 | pub const SYS_getitimer = 36; | |
| 42 | pub const SYS_alarm = 37; | |
| 43 | pub const SYS_setitimer = 38; | |
| 44 | pub const SYS_getpid = 39; | |
| 45 | pub const SYS_sendfile = 40; | |
| 46 | pub const SYS_socket = 41; | |
| 47 | pub const SYS_connect = 42; | |
| 48 | pub const SYS_accept = 43; | |
| 49 | pub const SYS_sendto = 44; | |
| 50 | pub const SYS_recvfrom = 45; | |
| 51 | pub const SYS_sendmsg = 46; | |
| 52 | pub const SYS_recvmsg = 47; | |
| 53 | pub const SYS_shutdown = 48; | |
| 54 | pub const SYS_bind = 49; | |
| 55 | pub const SYS_listen = 50; | |
| 56 | pub const SYS_getsockname = 51; | |
| 57 | pub const SYS_getpeername = 52; | |
| 58 | pub const SYS_socketpair = 53; | |
| 59 | pub const SYS_setsockopt = 54; | |
| 60 | pub const SYS_getsockopt = 55; | |
| 61 | pub const SYS_clone = 56; | |
| 62 | pub const SYS_fork = 57; | |
| 63 | pub const SYS_vfork = 58; | |
| 64 | pub const SYS_execve = 59; | |
| 65 | pub const SYS_exit = 60; | |
| 66 | pub const SYS_wait4 = 61; | |
| 67 | pub const SYS_kill = 62; | |
| 68 | pub const SYS_uname = 63; | |
| 69 | pub const SYS_semget = 64; | |
| 70 | pub const SYS_semop = 65; | |
| 71 | pub const SYS_semctl = 66; | |
| 72 | pub const SYS_shmdt = 67; | |
| 73 | pub const SYS_msgget = 68; | |
| 74 | pub const SYS_msgsnd = 69; | |
| 75 | pub const SYS_msgrcv = 70; | |
| 76 | pub const SYS_msgctl = 71; | |
| 77 | pub const SYS_fcntl = 72; | |
| 78 | pub const SYS_flock = 73; | |
| 79 | pub const SYS_fsync = 74; | |
| 80 | pub const SYS_fdatasync = 75; | |
| 81 | pub const SYS_truncate = 76; | |
| 82 | pub const SYS_ftruncate = 77; | |
| 83 | pub const SYS_getdents = 78; | |
| 84 | pub const SYS_getcwd = 79; | |
| 85 | pub const SYS_chdir = 80; | |
| 86 | pub const SYS_fchdir = 81; | |
| 87 | pub const SYS_rename = 82; | |
| 88 | pub const SYS_mkdir = 83; | |
| 89 | pub const SYS_rmdir = 84; | |
| 90 | pub const SYS_creat = 85; | |
| 91 | pub const SYS_link = 86; | |
| 92 | pub const SYS_unlink = 87; | |
| 93 | pub const SYS_symlink = 88; | |
| 94 | pub const SYS_readlink = 89; | |
| 95 | pub const SYS_chmod = 90; | |
| 96 | pub const SYS_fchmod = 91; | |
| 97 | pub const SYS_chown = 92; | |
| 98 | pub const SYS_fchown = 93; | |
| 99 | pub const SYS_lchown = 94; | |
| 100 | pub const SYS_umask = 95; | |
| 101 | pub const SYS_gettimeofday = 96; | |
| 102 | pub const SYS_getrlimit = 97; | |
| 103 | pub const SYS_getrusage = 98; | |
| 104 | pub const SYS_sysinfo = 99; | |
| 105 | pub const SYS_times = 100; | |
| 106 | pub const SYS_ptrace = 101; | |
| 107 | pub const SYS_getuid = 102; | |
| 108 | pub const SYS_syslog = 103; | |
| 109 | pub const SYS_getgid = 104; | |
| 110 | pub const SYS_setuid = 105; | |
| 111 | pub const SYS_setgid = 106; | |
| 112 | pub const SYS_geteuid = 107; | |
| 113 | pub const SYS_getegid = 108; | |
| 114 | pub const SYS_setpgid = 109; | |
| 115 | pub const SYS_getppid = 110; | |
| 116 | pub const SYS_getpgrp = 111; | |
| 117 | pub const SYS_setsid = 112; | |
| 118 | pub const SYS_setreuid = 113; | |
| 119 | pub const SYS_setregid = 114; | |
| 120 | pub const SYS_getgroups = 115; | |
| 121 | pub const SYS_setgroups = 116; | |
| 122 | pub const SYS_setresuid = 117; | |
| 123 | pub const SYS_getresuid = 118; | |
| 124 | pub const SYS_setresgid = 119; | |
| 125 | pub const SYS_getresgid = 120; | |
| 126 | pub const SYS_getpgid = 121; | |
| 127 | pub const SYS_setfsuid = 122; | |
| 128 | pub const SYS_setfsgid = 123; | |
| 129 | pub const SYS_getsid = 124; | |
| 130 | pub const SYS_capget = 125; | |
| 131 | pub const SYS_capset = 126; | |
| 132 | pub const SYS_rt_sigpending = 127; | |
| 133 | pub const SYS_rt_sigtimedwait = 128; | |
| 134 | pub const SYS_rt_sigqueueinfo = 129; | |
| 135 | pub const SYS_rt_sigsuspend = 130; | |
| 136 | pub const SYS_sigaltstack = 131; | |
| 137 | pub const SYS_utime = 132; | |
| 138 | pub const SYS_mknod = 133; | |
| 139 | pub const SYS_uselib = 134; | |
| 140 | pub const SYS_personality = 135; | |
| 141 | pub const SYS_ustat = 136; | |
| 142 | pub const SYS_statfs = 137; | |
| 143 | pub const SYS_fstatfs = 138; | |
| 144 | pub const SYS_sysfs = 139; | |
| 145 | pub const SYS_getpriority = 140; | |
| 146 | pub const SYS_setpriority = 141; | |
| 147 | pub const SYS_sched_setparam = 142; | |
| 148 | pub const SYS_sched_getparam = 143; | |
| 149 | pub const SYS_sched_setscheduler = 144; | |
| 150 | pub const SYS_sched_getscheduler = 145; | |
| 151 | pub const SYS_sched_get_priority_max = 146; | |
| 152 | pub const SYS_sched_get_priority_min = 147; | |
| 153 | pub const SYS_sched_rr_get_interval = 148; | |
| 154 | pub const SYS_mlock = 149; | |
| 155 | pub const SYS_munlock = 150; | |
| 156 | pub const SYS_mlockall = 151; | |
| 157 | pub const SYS_munlockall = 152; | |
| 158 | pub const SYS_vhangup = 153; | |
| 159 | pub const SYS_modify_ldt = 154; | |
| 160 | pub const SYS_pivot_root = 155; | |
| 161 | pub const SYS__sysctl = 156; | |
| 162 | pub const SYS_prctl = 157; | |
| 163 | pub const SYS_arch_prctl = 158; | |
| 164 | pub const SYS_adjtimex = 159; | |
| 165 | pub const SYS_setrlimit = 160; | |
| 166 | pub const SYS_chroot = 161; | |
| 167 | pub const SYS_sync = 162; | |
| 168 | pub const SYS_acct = 163; | |
| 169 | pub const SYS_settimeofday = 164; | |
| 170 | pub const SYS_mount = 165; | |
| 171 | pub const SYS_umount2 = 166; | |
| 172 | pub const SYS_swapon = 167; | |
| 173 | pub const SYS_swapoff = 168; | |
| 174 | pub const SYS_reboot = 169; | |
| 175 | pub const SYS_sethostname = 170; | |
| 176 | pub const SYS_setdomainname = 171; | |
| 177 | pub const SYS_iopl = 172; | |
| 178 | pub const SYS_ioperm = 173; | |
| 179 | pub const SYS_create_module = 174; | |
| 180 | pub const SYS_init_module = 175; | |
| 181 | pub const SYS_delete_module = 176; | |
| 182 | pub const SYS_get_kernel_syms = 177; | |
| 183 | pub const SYS_query_module = 178; | |
| 184 | pub const SYS_quotactl = 179; | |
| 185 | pub const SYS_nfsservctl = 180; | |
| 186 | pub const SYS_getpmsg = 181; | |
| 187 | pub const SYS_putpmsg = 182; | |
| 188 | pub const SYS_afs_syscall = 183; | |
| 189 | pub const SYS_tuxcall = 184; | |
| 190 | pub const SYS_security = 185; | |
| 191 | pub const SYS_gettid = 186; | |
| 192 | pub const SYS_readahead = 187; | |
| 193 | pub const SYS_setxattr = 188; | |
| 194 | pub const SYS_lsetxattr = 189; | |
| 195 | pub const SYS_fsetxattr = 190; | |
| 196 | pub const SYS_getxattr = 191; | |
| 197 | pub const SYS_lgetxattr = 192; | |
| 198 | pub const SYS_fgetxattr = 193; | |
| 199 | pub const SYS_listxattr = 194; | |
| 200 | pub const SYS_llistxattr = 195; | |
| 201 | pub const SYS_flistxattr = 196; | |
| 202 | pub const SYS_removexattr = 197; | |
| 203 | pub const SYS_lremovexattr = 198; | |
| 204 | pub const SYS_fremovexattr = 199; | |
| 205 | pub const SYS_tkill = 200; | |
| 206 | pub const SYS_time = 201; | |
| 207 | pub const SYS_futex = 202; | |
| 208 | pub const SYS_sched_setaffinity = 203; | |
| 209 | pub const SYS_sched_getaffinity = 204; | |
| 210 | pub const SYS_set_thread_area = 205; | |
| 211 | pub const SYS_io_setup = 206; | |
| 212 | pub const SYS_io_destroy = 207; | |
| 213 | pub const SYS_io_getevents = 208; | |
| 214 | pub const SYS_io_submit = 209; | |
| 215 | pub const SYS_io_cancel = 210; | |
| 216 | pub const SYS_get_thread_area = 211; | |
| 217 | pub const SYS_lookup_dcookie = 212; | |
| 218 | pub const SYS_epoll_create = 213; | |
| 219 | pub const SYS_epoll_ctl_old = 214; | |
| 220 | pub const SYS_epoll_wait_old = 215; | |
| 221 | pub const SYS_remap_file_pages = 216; | |
| 222 | pub const SYS_getdents64 = 217; | |
| 223 | pub const SYS_set_tid_address = 218; | |
| 224 | pub const SYS_restart_syscall = 219; | |
| 225 | pub const SYS_semtimedop = 220; | |
| 226 | pub const SYS_fadvise64 = 221; | |
| 227 | pub const SYS_timer_create = 222; | |
| 228 | pub const SYS_timer_settime = 223; | |
| 229 | pub const SYS_timer_gettime = 224; | |
| 230 | pub const SYS_timer_getoverrun = 225; | |
| 231 | pub const SYS_timer_delete = 226; | |
| 232 | pub const SYS_clock_settime = 227; | |
| 233 | pub const SYS_clock_gettime = 228; | |
| 234 | pub const SYS_clock_getres = 229; | |
| 235 | pub const SYS_clock_nanosleep = 230; | |
| 236 | pub const SYS_exit_group = 231; | |
| 237 | pub const SYS_epoll_wait = 232; | |
| 238 | pub const SYS_epoll_ctl = 233; | |
| 239 | pub const SYS_tgkill = 234; | |
| 240 | pub const SYS_utimes = 235; | |
| 241 | pub const SYS_vserver = 236; | |
| 242 | pub const SYS_mbind = 237; | |
| 243 | pub const SYS_set_mempolicy = 238; | |
| 244 | pub const SYS_get_mempolicy = 239; | |
| 245 | pub const SYS_mq_open = 240; | |
| 246 | pub const SYS_mq_unlink = 241; | |
| 247 | pub const SYS_mq_timedsend = 242; | |
| 248 | pub const SYS_mq_timedreceive = 243; | |
| 249 | pub const SYS_mq_notify = 244; | |
| 250 | pub const SYS_mq_getsetattr = 245; | |
| 251 | pub const SYS_kexec_load = 246; | |
| 252 | pub const SYS_waitid = 247; | |
| 253 | pub const SYS_add_key = 248; | |
| 254 | pub const SYS_request_key = 249; | |
| 255 | pub const SYS_keyctl = 250; | |
| 256 | pub const SYS_ioprio_set = 251; | |
| 257 | pub const SYS_ioprio_get = 252; | |
| 258 | pub const SYS_inotify_init = 253; | |
| 259 | pub const SYS_inotify_add_watch = 254; | |
| 260 | pub const SYS_inotify_rm_watch = 255; | |
| 261 | pub const SYS_migrate_pages = 256; | |
| 262 | pub const SYS_openat = 257; | |
| 263 | pub const SYS_mkdirat = 258; | |
| 264 | pub const SYS_mknodat = 259; | |
| 265 | pub const SYS_fchownat = 260; | |
| 266 | pub const SYS_futimesat = 261; | |
| 267 | pub const SYS_newfstatat = 262; | |
| 268 | pub const SYS_unlinkat = 263; | |
| 269 | pub const SYS_renameat = 264; | |
| 270 | pub const SYS_linkat = 265; | |
| 271 | pub const SYS_symlinkat = 266; | |
| 272 | pub const SYS_readlinkat = 267; | |
| 273 | pub const SYS_fchmodat = 268; | |
| 274 | pub const SYS_faccessat = 269; | |
| 275 | pub const SYS_pselect6 = 270; | |
| 276 | pub const SYS_ppoll = 271; | |
| 277 | pub const SYS_unshare = 272; | |
| 278 | pub const SYS_set_robust_list = 273; | |
| 279 | pub const SYS_get_robust_list = 274; | |
| 280 | pub const SYS_splice = 275; | |
| 281 | pub const SYS_tee = 276; | |
| 282 | pub const SYS_sync_file_range = 277; | |
| 283 | pub const SYS_vmsplice = 278; | |
| 284 | pub const SYS_move_pages = 279; | |
| 285 | pub const SYS_utimensat = 280; | |
| 286 | pub const SYS_epoll_pwait = 281; | |
| 287 | pub const SYS_signalfd = 282; | |
| 288 | pub const SYS_timerfd_create = 283; | |
| 289 | pub const SYS_eventfd = 284; | |
| 290 | pub const SYS_fallocate = 285; | |
| 291 | pub const SYS_timerfd_settime = 286; | |
| 292 | pub const SYS_timerfd_gettime = 287; | |
| 293 | pub const SYS_accept4 = 288; | |
| 294 | pub const SYS_signalfd4 = 289; | |
| 295 | pub const SYS_eventfd2 = 290; | |
| 296 | pub const SYS_epoll_create1 = 291; | |
| 297 | pub const SYS_dup3 = 292; | |
| 298 | pub const SYS_pipe2 = 293; | |
| 299 | pub const SYS_inotify_init1 = 294; | |
| 300 | pub const SYS_preadv = 295; | |
| 301 | pub const SYS_pwritev = 296; | |
| 302 | pub const SYS_rt_tgsigqueueinfo = 297; | |
| 303 | pub const SYS_perf_event_open = 298; | |
| 304 | pub const SYS_recvmmsg = 299; | |
| 305 | pub const SYS_fanotify_init = 300; | |
| 306 | pub const SYS_fanotify_mark = 301; | |
| 307 | pub const SYS_prlimit64 = 302; | |
| 308 | pub const SYS_name_to_handle_at = 303; | |
| 309 | pub const SYS_open_by_handle_at = 304; | |
| 310 | pub const SYS_clock_adjtime = 305; | |
| 311 | pub const SYS_syncfs = 306; | |
| 312 | pub const SYS_sendmmsg = 307; | |
| 313 | pub const SYS_setns = 308; | |
| 314 | pub const SYS_getcpu = 309; | |
| 315 | pub const SYS_process_vm_readv = 310; | |
| 316 | pub const SYS_process_vm_writev = 311; | |
| 317 | pub const SYS_kcmp = 312; | |
| 318 | pub const SYS_finit_module = 313; | |
| 319 | pub const SYS_sched_setattr = 314; | |
| 320 | pub const SYS_sched_getattr = 315; | |
| 321 | pub const SYS_renameat2 = 316; | |
| 322 | pub const SYS_seccomp = 317; | |
| 323 | pub const SYS_getrandom = 318; | |
| 324 | pub const SYS_memfd_create = 319; | |
| 325 | pub const SYS_kexec_file_load = 320; | |
| 326 | pub const SYS_bpf = 321; | |
| 327 | pub const SYS_execveat = 322; | |
| 328 | pub const SYS_userfaultfd = 323; | |
| 329 | pub const SYS_membarrier = 324; | |
| 330 | pub const SYS_mlock2 = 325; | |
| 331 | ||
| 332 | pub const O_CREAT = 0o100; | |
| 333 | pub const O_EXCL = 0o200; | |
| 334 | pub const O_NOCTTY = 0o400; | |
| 335 | pub const O_TRUNC = 0o1000; | |
| 336 | pub const O_APPEND = 0o2000; | |
| 337 | pub const O_NONBLOCK = 0o4000; | |
| 338 | pub const O_DSYNC = 0o10000; | |
| 339 | pub const O_SYNC = 0o4010000; | |
| 340 | pub const O_RSYNC = 0o4010000; | |
| 341 | pub const O_DIRECTORY = 0o200000; | |
| 342 | pub const O_NOFOLLOW = 0o400000; | |
| 343 | pub const O_CLOEXEC = 0o2000000; | |
| 344 | ||
| 345 | pub const O_ASYNC = 0o20000; | |
| 346 | pub const O_DIRECT = 0o40000; | |
| 347 | pub const O_LARGEFILE = 0; | |
| 348 | pub const O_NOATIME = 0o1000000; | |
| 349 | pub const O_PATH = 0o10000000; | |
| 350 | pub const O_TMPFILE = 0o20200000; | |
| 351 | pub const O_NDELAY = O_NONBLOCK; | |
| 352 | ||
| 353 | pub const F_DUPFD = 0; | |
| 354 | pub const F_GETFD = 1; | |
| 355 | pub const F_SETFD = 2; | |
| 356 | pub const F_GETFL = 3; | |
| 357 | pub const F_SETFL = 4; | |
| 358 | ||
| 359 | pub const F_SETOWN = 8; | |
| 360 | pub const F_GETOWN = 9; | |
| 361 | pub const F_SETSIG = 10; | |
| 362 | pub const F_GETSIG = 11; | |
| 363 | ||
| 364 | pub const F_GETLK = 5; | |
| 365 | pub const F_SETLK = 6; | |
| 366 | pub const F_SETLKW = 7; | |
| 367 | ||
| 368 | pub const F_SETOWN_EX = 15; | |
| 369 | pub const F_GETOWN_EX = 16; | |
| 370 | ||
| 371 | pub const F_GETOWNER_UIDS = 17; | |
| 372 | ||
| 373 | pub inline fn syscall0(number: usize) -> usize { | |
| 374 | asm volatile ("syscall" | |
| 375 | : [ret] "={rax}" (-> usize) | |
| 376 | : [number] "{rax}" (number) | |
| 377 | : "rcx", "r11") | |
| 378 | } | |
| 379 | ||
| 380 | pub 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 | ||
| 388 | pub 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 | ||
| 397 | pub 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 | ||
| 407 | pub 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 | ||
| 418 | pub 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 | ||
| 430 | pub 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 | ||
| 445 | pub 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 | ||
| 457 | pub 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 | ||
| 477 | pub const timespec = extern struct { | |
| 478 | tv_sec: isize, | |
| 479 | tv_nsec: isize, | |
| 480 | }; |
std/mem.zig+1-1| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | const assert = @import("debug.zig").assert; |
| 2 | 2 | const math = @import("math.zig"); |
| 3 | const os = @import("os.zig"); | |
| 3 | const os = @import("os/index.zig"); | |
| 4 | 4 | const io = @import("io.zig"); |
| 5 | 5 | |
| 6 | 6 | pub const Cmp = math.Cmp; |
std/net.zig+2-2| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | const linux = @import("linux.zig"); | |
| 2 | const errno = @import("errno.zig"); | |
| 1 | const linux = @import("os/linux.zig"); | |
| 2 | const errno = @import("os/errno.zig"); | |
| 3 | 3 | const assert = @import("debug.zig").assert; |
| 4 | 4 | const endian = @import("endian.zig"); |
| 5 | 5 |
std/os.zig deleted-74| ... | ... | @@ -1,74 +0,0 @@ |
| 1 | const 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 | }; | |
| 6 | const windows = @import("windows.zig"); | |
| 7 | const errno = @import("errno.zig"); | |
| 8 | const linking_libc = @import("build.zig").linking_libc; | |
| 9 | const c = @import("c/index.zig"); | |
| 10 | ||
| 11 | error 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. | |
| 16 | pub 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. | |
| 62 | pub 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 | ||
| 2 | const arch = switch (@compileVar("arch")) { | |
| 3 | Arch.x86_64 => @import("darwin_x86_64.zig"), | |
| 4 | else => @compileError("unsupported arch"), | |
| 5 | }; | |
| 6 | ||
| 7 | const errno = @import("errno.zig"); | |
| 8 | ||
| 9 | pub const O_LARGEFILE = 0x0000; | |
| 10 | pub const O_RDONLY = 0x0000; | |
| 11 | ||
| 12 | pub const SEEK_SET = 0x0; | |
| 13 | pub const SEEK_CUR = 0x1; | |
| 14 | pub const SEEK_END = 0x2; | |
| 15 | ||
| 16 | pub const SIGHUP = 1; | |
| 17 | pub const SIGINT = 2; | |
| 18 | pub const SIGQUIT = 3; | |
| 19 | pub const SIGILL = 4; | |
| 20 | pub const SIGTRAP = 5; | |
| 21 | pub const SIGABRT = 6; | |
| 22 | pub const SIGIOT = SIGABRT; | |
| 23 | pub const SIGBUS = 7; | |
| 24 | pub const SIGFPE = 8; | |
| 25 | pub const SIGKILL = 9; | |
| 26 | pub const SIGUSR1 = 10; | |
| 27 | pub const SIGSEGV = 11; | |
| 28 | pub const SIGUSR2 = 12; | |
| 29 | pub const SIGPIPE = 13; | |
| 30 | pub const SIGALRM = 14; | |
| 31 | pub const SIGTERM = 15; | |
| 32 | pub const SIGSTKFLT = 16; | |
| 33 | pub const SIGCHLD = 17; | |
| 34 | pub const SIGCONT = 18; | |
| 35 | pub const SIGSTOP = 19; | |
| 36 | pub const SIGTSTP = 20; | |
| 37 | pub const SIGTTIN = 21; | |
| 38 | pub const SIGTTOU = 22; | |
| 39 | pub const SIGURG = 23; | |
| 40 | pub const SIGXCPU = 24; | |
| 41 | pub const SIGXFSZ = 25; | |
| 42 | pub const SIGVTALRM = 26; | |
| 43 | pub const SIGPROF = 27; | |
| 44 | pub const SIGWINCH = 28; | |
| 45 | pub const SIGIO = 29; | |
| 46 | pub const SIGPOLL = 29; | |
| 47 | pub const SIGPWR = 30; | |
| 48 | pub const SIGSYS = 31; | |
| 49 | pub const SIGUNUSED = SIGSYS; | |
| 50 | ||
| 51 | pub 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. | |
| 57 | pub 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 | ||
| 62 | pub fn write(fd: i32, buf: &const u8, count: usize) -> usize { | |
| 63 | arch.syscall3(arch.SYS_write, usize(fd), usize(buf), count) | |
| 64 | } | |
| 65 | ||
| 66 | pub fn close(fd: i32) -> usize { | |
| 67 | arch.syscall1(arch.SYS_close, usize(fd)) | |
| 68 | } | |
| 69 | ||
| 70 | pub fn open_c(path: &const u8, flags: usize, perm: usize) -> usize { | |
| 71 | arch.syscall3(arch.SYS_open, usize(path), flags, perm) | |
| 72 | } | |
| 73 | ||
| 74 | pub 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 | ||
| 81 | pub fn read(fd: i32, buf: &u8, count: usize) -> usize { | |
| 82 | arch.syscall3(arch.SYS_read, usize(fd), usize(buf), count) | |
| 83 | } | |
| 84 | ||
| 85 | pub fn lseek(fd: i32, offset: usize, ref_pos: usize) -> usize { | |
| 86 | arch.syscall3(arch.SYS_lseek, usize(fd), offset, ref_pos) | |
| 87 | } | |
| 88 | ||
| 89 | pub const stat = arch.stat; | |
| 90 | pub const timespec = arch.timespec; | |
| 91 | ||
| 92 | pub fn fstat(fd: i32, stat_buf: &stat) -> usize { | |
| 93 | arch.syscall2(arch.SYS_fstat, usize(fd), usize(stat_buf)) | |
| 94 | } | |
| 95 | ||
| 96 | error Unexpected; | |
| 97 | ||
| 98 | pub 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 | ||
| 108 | pub 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 | ||
| 2 | pub const SYSCALL_CLASS_SHIFT = 24; | |
| 3 | pub const SYSCALL_CLASS_MASK = 0xFF << SYSCALL_CLASS_SHIFT; | |
| 4 | // pub const SYSCALL_NUMBER_MASK = ~SYSCALL_CLASS_MASK; // ~ modifier not supported yet | |
| 5 | ||
| 6 | pub const SYSCALL_CLASS_NONE = 0; // Invalid | |
| 7 | pub const SYSCALL_CLASS_MACH = 1; // Mach | |
| 8 | pub const SYSCALL_CLASS_UNIX = 2; // Unix/BSD | |
| 9 | pub const SYSCALL_CLASS_MDEP = 3; // Machine-dependent | |
| 10 | pub const SYSCALL_CLASS_DIAG = 4; // Diagnostics | |
| 11 | ||
| 12 | // TODO: use the above constants to create the below values | |
| 13 | ||
| 14 | pub const SYS_exit = 0x2000001; | |
| 15 | pub const SYS_read = 0x2000003; | |
| 16 | pub const SYS_write = 0x2000004; | |
| 17 | pub const SYS_open = 0x2000005; | |
| 18 | pub const SYS_close = 0x2000006; | |
| 19 | pub const SYS_kill = 0x2000025; | |
| 20 | pub const SYS_getpid = 0x2000030; | |
| 21 | pub const SYS_fstat = 0x20000BD; | |
| 22 | pub const SYS_lseek = 0x20000C7; | |
| 23 | ||
| 24 | pub inline fn syscall0(number: usize) -> usize { | |
| 25 | asm volatile ("syscall" | |
| 26 | : [ret] "={rax}" (-> usize) | |
| 27 | : [number] "{rax}" (number) | |
| 28 | : "rcx", "r11") | |
| 29 | } | |
| 30 | ||
| 31 | pub 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 | ||
| 39 | pub 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 | ||
| 48 | pub 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 | ||
| 61 | pub 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 | ||
| 84 | pub const timespec = extern struct { | |
| 85 | tv_sec: isize, | |
| 86 | tv_nsec: isize, | |
| 87 | }; |
std/os/errno.zig created+146| ... | ... | @@ -0,0 +1,146 @@ |
| 1 | pub const EPERM = 1; // Operation not permitted | |
| 2 | pub const ENOENT = 2; // No such file or directory | |
| 3 | pub const ESRCH = 3; // No such process | |
| 4 | pub const EINTR = 4; // Interrupted system call | |
| 5 | pub const EIO = 5; // I/O error | |
| 6 | pub const ENXIO = 6; // No such device or address | |
| 7 | pub const E2BIG = 7; // Arg list too long | |
| 8 | pub const ENOEXEC = 8; // Exec format error | |
| 9 | pub const EBADF = 9; // Bad file number | |
| 10 | pub const ECHILD = 10; // No child processes | |
| 11 | pub const EAGAIN = 11; // Try again | |
| 12 | pub const ENOMEM = 12; // Out of memory | |
| 13 | pub const EACCES = 13; // Permission denied | |
| 14 | pub const EFAULT = 14; // Bad address | |
| 15 | pub const ENOTBLK = 15; // Block device required | |
| 16 | pub const EBUSY = 16; // Device or resource busy | |
| 17 | pub const EEXIST = 17; // File exists | |
| 18 | pub const EXDEV = 18; // Cross-device link | |
| 19 | pub const ENODEV = 19; // No such device | |
| 20 | pub const ENOTDIR = 20; // Not a directory | |
| 21 | pub const EISDIR = 21; // Is a directory | |
| 22 | pub const EINVAL = 22; // Invalid argument | |
| 23 | pub const ENFILE = 23; // File table overflow | |
| 24 | pub const EMFILE = 24; // Too many open files | |
| 25 | pub const ENOTTY = 25; // Not a typewriter | |
| 26 | pub const ETXTBSY = 26; // Text file busy | |
| 27 | pub const EFBIG = 27; // File too large | |
| 28 | pub const ENOSPC = 28; // No space left on device | |
| 29 | pub const ESPIPE = 29; // Illegal seek | |
| 30 | pub const EROFS = 30; // Read-only file system | |
| 31 | pub const EMLINK = 31; // Too many links | |
| 32 | pub const EPIPE = 32; // Broken pipe | |
| 33 | pub const EDOM = 33; // Math argument out of domain of func | |
| 34 | pub const ERANGE = 34; // Math result not representable | |
| 35 | pub const EDEADLK = 35; // Resource deadlock would occur | |
| 36 | pub const ENAMETOOLONG = 36; // File name too long | |
| 37 | pub const ENOLCK = 37; // No record locks available | |
| 38 | pub const ENOSYS = 38; // Function not implemented | |
| 39 | pub const ENOTEMPTY = 39; // Directory not empty | |
| 40 | pub const ELOOP = 40; // Too many symbolic links encountered | |
| 41 | pub const EWOULDBLOCK = EAGAIN; // Operation would block | |
| 42 | pub const ENOMSG = 42; // No message of desired type | |
| 43 | pub const EIDRM = 43; // Identifier removed | |
| 44 | pub const ECHRNG = 44; // Channel number out of range | |
| 45 | pub const EL2NSYNC = 45; // Level 2 not synchronized | |
| 46 | pub const EL3HLT = 46; // Level 3 halted | |
| 47 | pub const EL3RST = 47; // Level 3 reset | |
| 48 | pub const ELNRNG = 48; // Link number out of range | |
| 49 | pub const EUNATCH = 49; // Protocol driver not attached | |
| 50 | pub const ENOCSI = 50; // No CSI structure available | |
| 51 | pub const EL2HLT = 51; // Level 2 halted | |
| 52 | pub const EBADE = 52; // Invalid exchange | |
| 53 | pub const EBADR = 53; // Invalid request descriptor | |
| 54 | pub const EXFULL = 54; // Exchange full | |
| 55 | pub const ENOANO = 55; // No anode | |
| 56 | pub const EBADRQC = 56; // Invalid request code | |
| 57 | pub const EBADSLT = 57; // Invalid slot | |
| 58 | ||
| 59 | pub const EBFONT = 59; // Bad font file format | |
| 60 | pub const ENOSTR = 60; // Device not a stream | |
| 61 | pub const ENODATA = 61; // No data available | |
| 62 | pub const ETIME = 62; // Timer expired | |
| 63 | pub const ENOSR = 63; // Out of streams resources | |
| 64 | pub const ENONET = 64; // Machine is not on the network | |
| 65 | pub const ENOPKG = 65; // Package not installed | |
| 66 | pub const EREMOTE = 66; // Object is remote | |
| 67 | pub const ENOLINK = 67; // Link has been severed | |
| 68 | pub const EADV = 68; // Advertise error | |
| 69 | pub const ESRMNT = 69; // Srmount error | |
| 70 | pub const ECOMM = 70; // Communication error on send | |
| 71 | pub const EPROTO = 71; // Protocol error | |
| 72 | pub const EMULTIHOP = 72; // Multihop attempted | |
| 73 | pub const EDOTDOT = 73; // RFS specific error | |
| 74 | pub const EBADMSG = 74; // Not a data message | |
| 75 | pub const EOVERFLOW = 75; // Value too large for defined data type | |
| 76 | pub const ENOTUNIQ = 76; // Name not unique on network | |
| 77 | pub const EBADFD = 77; // File descriptor in bad state | |
| 78 | pub const EREMCHG = 78; // Remote address changed | |
| 79 | pub const ELIBACC = 79; // Can not access a needed shared library | |
| 80 | pub const ELIBBAD = 80; // Accessing a corrupted shared library | |
| 81 | pub const ELIBSCN = 81; // .lib section in a.out corrupted | |
| 82 | pub const ELIBMAX = 82; // Attempting to link in too many shared libraries | |
| 83 | pub const ELIBEXEC = 83; // Cannot exec a shared library directly | |
| 84 | pub const EILSEQ = 84; // Illegal byte sequence | |
| 85 | pub const ERESTART = 85; // Interrupted system call should be restarted | |
| 86 | pub const ESTRPIPE = 86; // Streams pipe error | |
| 87 | pub const EUSERS = 87; // Too many users | |
| 88 | pub const ENOTSOCK = 88; // Socket operation on non-socket | |
| 89 | pub const EDESTADDRREQ = 89; // Destination address required | |
| 90 | pub const EMSGSIZE = 90; // Message too long | |
| 91 | pub const EPROTOTYPE = 91; // Protocol wrong type for socket | |
| 92 | pub const ENOPROTOOPT = 92; // Protocol not available | |
| 93 | pub const EPROTONOSUPPORT = 93; // Protocol not supported | |
| 94 | pub const ESOCKTNOSUPPORT = 94; // Socket type not supported | |
| 95 | pub const EOPNOTSUPP = 95; // Operation not supported on transport endpoint | |
| 96 | pub const EPFNOSUPPORT = 96; // Protocol family not supported | |
| 97 | pub const EAFNOSUPPORT = 97; // Address family not supported by protocol | |
| 98 | pub const EADDRINUSE = 98; // Address already in use | |
| 99 | pub const EADDRNOTAVAIL = 99; // Cannot assign requested address | |
| 100 | pub const ENETDOWN = 100; // Network is down | |
| 101 | pub const ENETUNREACH = 101; // Network is unreachable | |
| 102 | pub const ENETRESET = 102; // Network dropped connection because of reset | |
| 103 | pub const ECONNABORTED = 103; // Software caused connection abort | |
| 104 | pub const ECONNRESET = 104; // Connection reset by peer | |
| 105 | pub const ENOBUFS = 105; // No buffer space available | |
| 106 | pub const EISCONN = 106; // Transport endpoint is already connected | |
| 107 | pub const ENOTCONN = 107; // Transport endpoint is not connected | |
| 108 | pub const ESHUTDOWN = 108; // Cannot send after transport endpoint shutdown | |
| 109 | pub const ETOOMANYREFS = 109; // Too many references: cannot splice | |
| 110 | pub const ETIMEDOUT = 110; // Connection timed out | |
| 111 | pub const ECONNREFUSED = 111; // Connection refused | |
| 112 | pub const EHOSTDOWN = 112; // Host is down | |
| 113 | pub const EHOSTUNREACH = 113; // No route to host | |
| 114 | pub const EALREADY = 114; // Operation already in progress | |
| 115 | pub const EINPROGRESS = 115; // Operation now in progress | |
| 116 | pub const ESTALE = 116; // Stale NFS file handle | |
| 117 | pub const EUCLEAN = 117; // Structure needs cleaning | |
| 118 | pub const ENOTNAM = 118; // Not a XENIX named type file | |
| 119 | pub const ENAVAIL = 119; // No XENIX semaphores available | |
| 120 | pub const EISNAM = 120; // Is a named type file | |
| 121 | pub const EREMOTEIO = 121; // Remote I/O error | |
| 122 | pub const EDQUOT = 122; // Quota exceeded | |
| 123 | ||
| 124 | pub const ENOMEDIUM = 123; // No medium found | |
| 125 | pub const EMEDIUMTYPE = 124; // Wrong medium type | |
| 126 | ||
| 127 | // nameserver query return codes | |
| 128 | pub const ENSROK = 0; // DNS server returned answer with no data | |
| 129 | pub const ENSRNODATA = 160; // DNS server returned answer with no data | |
| 130 | pub const ENSRFORMERR = 161; // DNS server claims query was misformatted | |
| 131 | pub const ENSRSERVFAIL = 162; // DNS server returned general failure | |
| 132 | pub const ENSRNOTFOUND = 163; // Domain name not found | |
| 133 | pub const ENSRNOTIMP = 164; // DNS server does not implement requested operation | |
| 134 | pub const ENSRREFUSED = 165; // DNS server refused query | |
| 135 | pub const ENSRBADQUERY = 166; // Misformatted DNS query | |
| 136 | pub const ENSRBADNAME = 167; // Misformatted domain name | |
| 137 | pub const ENSRBADFAMILY = 168; // Unsupported address family | |
| 138 | pub const ENSRBADRESP = 169; // Misformatted DNS reply | |
| 139 | pub const ENSRCONNREFUSED = 170; // Could not contact DNS servers | |
| 140 | pub const ENSRTIMEOUT = 171; // Timeout while contacting DNS servers | |
| 141 | pub const ENSROF = 172; // End of file | |
| 142 | pub const ENSRFILE = 173; // Error reading file | |
| 143 | pub const ENSRNOMEM = 174; // Out of memory | |
| 144 | pub const ENSRDESTRUCTION = 175; // Application terminated lookup | |
| 145 | pub const ENSRQUERYDOMAINTOOLONG = 176; // Domain name is too long | |
| 146 | pub const ENSRCNAMELOOP = 177; // Domain name is too long |
std/os/index.zig created+78| ... | ... | @@ -0,0 +1,78 @@ |
| 1 | pub const windows = @import("windows.zig"); | |
| 2 | pub const darwin = @import("darwin.zig"); | |
| 3 | pub const linux = @import("linux.zig"); | |
| 4 | pub 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 | ||
| 11 | const errno = @import("errno.zig"); | |
| 12 | const linking_libc = @import("../target.zig").linking_libc; | |
| 13 | const c = @import("../c/index.zig"); | |
| 14 | ||
| 15 | error 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. | |
| 20 | pub 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. | |
| 66 | pub 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 @@ |
| 1 | const 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 | }; | |
| 6 | const errno = @import("errno.zig"); | |
| 7 | ||
| 8 | pub const MMAP_PROT_NONE = 0; | |
| 9 | pub const MMAP_PROT_READ = 1; | |
| 10 | pub const MMAP_PROT_WRITE = 2; | |
| 11 | pub const MMAP_PROT_EXEC = 4; | |
| 12 | ||
| 13 | pub const MMAP_MAP_FILE = 0; | |
| 14 | pub const MMAP_MAP_SHARED = 1; | |
| 15 | pub const MMAP_MAP_PRIVATE = 2; | |
| 16 | pub const MMAP_MAP_FIXED = 16; | |
| 17 | pub const MMAP_MAP_ANON = 32; | |
| 18 | ||
| 19 | pub const SIGHUP = 1; | |
| 20 | pub const SIGINT = 2; | |
| 21 | pub const SIGQUIT = 3; | |
| 22 | pub const SIGILL = 4; | |
| 23 | pub const SIGTRAP = 5; | |
| 24 | pub const SIGABRT = 6; | |
| 25 | pub const SIGIOT = SIGABRT; | |
| 26 | pub const SIGBUS = 7; | |
| 27 | pub const SIGFPE = 8; | |
| 28 | pub const SIGKILL = 9; | |
| 29 | pub const SIGUSR1 = 10; | |
| 30 | pub const SIGSEGV = 11; | |
| 31 | pub const SIGUSR2 = 12; | |
| 32 | pub const SIGPIPE = 13; | |
| 33 | pub const SIGALRM = 14; | |
| 34 | pub const SIGTERM = 15; | |
| 35 | pub const SIGSTKFLT = 16; | |
| 36 | pub const SIGCHLD = 17; | |
| 37 | pub const SIGCONT = 18; | |
| 38 | pub const SIGSTOP = 19; | |
| 39 | pub const SIGTSTP = 20; | |
| 40 | pub const SIGTTIN = 21; | |
| 41 | pub const SIGTTOU = 22; | |
| 42 | pub const SIGURG = 23; | |
| 43 | pub const SIGXCPU = 24; | |
| 44 | pub const SIGXFSZ = 25; | |
| 45 | pub const SIGVTALRM = 26; | |
| 46 | pub const SIGPROF = 27; | |
| 47 | pub const SIGWINCH = 28; | |
| 48 | pub const SIGIO = 29; | |
| 49 | pub const SIGPOLL = 29; | |
| 50 | pub const SIGPWR = 30; | |
| 51 | pub const SIGSYS = 31; | |
| 52 | pub const SIGUNUSED = SIGSYS; | |
| 53 | ||
| 54 | pub const O_RDONLY = 0o0; | |
| 55 | pub const O_WRONLY = 0o1; | |
| 56 | pub const O_RDWR = 0o2; | |
| 57 | ||
| 58 | pub const O_CREAT = arch.O_CREAT; | |
| 59 | pub const O_EXCL = arch.O_EXCL; | |
| 60 | pub const O_NOCTTY = arch.O_NOCTTY; | |
| 61 | pub const O_TRUNC = arch.O_TRUNC; | |
| 62 | pub const O_APPEND = arch.O_APPEND; | |
| 63 | pub const O_NONBLOCK = arch.O_NONBLOCK; | |
| 64 | pub const O_DSYNC = arch.O_DSYNC; | |
| 65 | pub const O_SYNC = arch.O_SYNC; | |
| 66 | pub const O_RSYNC = arch.O_RSYNC; | |
| 67 | pub const O_DIRECTORY = arch.O_DIRECTORY; | |
| 68 | pub const O_NOFOLLOW = arch.O_NOFOLLOW; | |
| 69 | pub const O_CLOEXEC = arch.O_CLOEXEC; | |
| 70 | ||
| 71 | pub const O_ASYNC = arch.O_ASYNC; | |
| 72 | pub const O_DIRECT = arch.O_DIRECT; | |
| 73 | pub const O_LARGEFILE = arch.O_LARGEFILE; | |
| 74 | pub const O_NOATIME = arch.O_NOATIME; | |
| 75 | pub const O_PATH = arch.O_PATH; | |
| 76 | pub const O_TMPFILE = arch.O_TMPFILE; | |
| 77 | pub const O_NDELAY = arch.O_NDELAY; | |
| 78 | ||
| 79 | pub const SEEK_SET = 0; | |
| 80 | pub const SEEK_CUR = 1; | |
| 81 | pub const SEEK_END = 2; | |
| 82 | ||
| 83 | const SIG_BLOCK = 0; | |
| 84 | const SIG_UNBLOCK = 1; | |
| 85 | const SIG_SETMASK = 2; | |
| 86 | ||
| 87 | pub const SOCK_STREAM = 1; | |
| 88 | pub const SOCK_DGRAM = 2; | |
| 89 | pub const SOCK_RAW = 3; | |
| 90 | pub const SOCK_RDM = 4; | |
| 91 | pub const SOCK_SEQPACKET = 5; | |
| 92 | pub const SOCK_DCCP = 6; | |
| 93 | pub const SOCK_PACKET = 10; | |
| 94 | pub const SOCK_CLOEXEC = 0o2000000; | |
| 95 | pub const SOCK_NONBLOCK = 0o4000; | |
| 96 | ||
| 97 | ||
| 98 | pub const PROTO_ip = 0o000; | |
| 99 | pub const PROTO_icmp = 0o001; | |
| 100 | pub const PROTO_igmp = 0o002; | |
| 101 | pub const PROTO_ggp = 0o003; | |
| 102 | pub const PROTO_ipencap = 0o004; | |
| 103 | pub const PROTO_st = 0o005; | |
| 104 | pub const PROTO_tcp = 0o006; | |
| 105 | pub const PROTO_egp = 0o010; | |
| 106 | pub const PROTO_pup = 0o014; | |
| 107 | pub const PROTO_udp = 0o021; | |
| 108 | pub const PROTO_hmp = 0o024; | |
| 109 | pub const PROTO_xns_idp = 0o026; | |
| 110 | pub const PROTO_rdp = 0o033; | |
| 111 | pub const PROTO_iso_tp4 = 0o035; | |
| 112 | pub const PROTO_xtp = 0o044; | |
| 113 | pub const PROTO_ddp = 0o045; | |
| 114 | pub const PROTO_idpr_cmtp = 0o046; | |
| 115 | pub const PROTO_ipv6 = 0o051; | |
| 116 | pub const PROTO_ipv6_route = 0o053; | |
| 117 | pub const PROTO_ipv6_frag = 0o054; | |
| 118 | pub const PROTO_idrp = 0o055; | |
| 119 | pub const PROTO_rsvp = 0o056; | |
| 120 | pub const PROTO_gre = 0o057; | |
| 121 | pub const PROTO_esp = 0o062; | |
| 122 | pub const PROTO_ah = 0o063; | |
| 123 | pub const PROTO_skip = 0o071; | |
| 124 | pub const PROTO_ipv6_icmp = 0o072; | |
| 125 | pub const PROTO_ipv6_nonxt = 0o073; | |
| 126 | pub const PROTO_ipv6_opts = 0o074; | |
| 127 | pub const PROTO_rspf = 0o111; | |
| 128 | pub const PROTO_vmtp = 0o121; | |
| 129 | pub const PROTO_ospf = 0o131; | |
| 130 | pub const PROTO_ipip = 0o136; | |
| 131 | pub const PROTO_encap = 0o142; | |
| 132 | pub const PROTO_pim = 0o147; | |
| 133 | pub const PROTO_raw = 0o377; | |
| 134 | ||
| 135 | pub const PF_UNSPEC = 0; | |
| 136 | pub const PF_LOCAL = 1; | |
| 137 | pub const PF_UNIX = PF_LOCAL; | |
| 138 | pub const PF_FILE = PF_LOCAL; | |
| 139 | pub const PF_INET = 2; | |
| 140 | pub const PF_AX25 = 3; | |
| 141 | pub const PF_IPX = 4; | |
| 142 | pub const PF_APPLETALK = 5; | |
| 143 | pub const PF_NETROM = 6; | |
| 144 | pub const PF_BRIDGE = 7; | |
| 145 | pub const PF_ATMPVC = 8; | |
| 146 | pub const PF_X25 = 9; | |
| 147 | pub const PF_INET6 = 10; | |
| 148 | pub const PF_ROSE = 11; | |
| 149 | pub const PF_DECnet = 12; | |
| 150 | pub const PF_NETBEUI = 13; | |
| 151 | pub const PF_SECURITY = 14; | |
| 152 | pub const PF_KEY = 15; | |
| 153 | pub const PF_NETLINK = 16; | |
| 154 | pub const PF_ROUTE = PF_NETLINK; | |
| 155 | pub const PF_PACKET = 17; | |
| 156 | pub const PF_ASH = 18; | |
| 157 | pub const PF_ECONET = 19; | |
| 158 | pub const PF_ATMSVC = 20; | |
| 159 | pub const PF_RDS = 21; | |
| 160 | pub const PF_SNA = 22; | |
| 161 | pub const PF_IRDA = 23; | |
| 162 | pub const PF_PPPOX = 24; | |
| 163 | pub const PF_WANPIPE = 25; | |
| 164 | pub const PF_LLC = 26; | |
| 165 | pub const PF_IB = 27; | |
| 166 | pub const PF_MPLS = 28; | |
| 167 | pub const PF_CAN = 29; | |
| 168 | pub const PF_TIPC = 30; | |
| 169 | pub const PF_BLUETOOTH = 31; | |
| 170 | pub const PF_IUCV = 32; | |
| 171 | pub const PF_RXRPC = 33; | |
| 172 | pub const PF_ISDN = 34; | |
| 173 | pub const PF_PHONET = 35; | |
| 174 | pub const PF_IEEE802154 = 36; | |
| 175 | pub const PF_CAIF = 37; | |
| 176 | pub const PF_ALG = 38; | |
| 177 | pub const PF_NFC = 39; | |
| 178 | pub const PF_VSOCK = 40; | |
| 179 | pub const PF_MAX = 41; | |
| 180 | ||
| 181 | pub const AF_UNSPEC = PF_UNSPEC; | |
| 182 | pub const AF_LOCAL = PF_LOCAL; | |
| 183 | pub const AF_UNIX = AF_LOCAL; | |
| 184 | pub const AF_FILE = AF_LOCAL; | |
| 185 | pub const AF_INET = PF_INET; | |
| 186 | pub const AF_AX25 = PF_AX25; | |
| 187 | pub const AF_IPX = PF_IPX; | |
| 188 | pub const AF_APPLETALK = PF_APPLETALK; | |
| 189 | pub const AF_NETROM = PF_NETROM; | |
| 190 | pub const AF_BRIDGE = PF_BRIDGE; | |
| 191 | pub const AF_ATMPVC = PF_ATMPVC; | |
| 192 | pub const AF_X25 = PF_X25; | |
| 193 | pub const AF_INET6 = PF_INET6; | |
| 194 | pub const AF_ROSE = PF_ROSE; | |
| 195 | pub const AF_DECnet = PF_DECnet; | |
| 196 | pub const AF_NETBEUI = PF_NETBEUI; | |
| 197 | pub const AF_SECURITY = PF_SECURITY; | |
| 198 | pub const AF_KEY = PF_KEY; | |
| 199 | pub const AF_NETLINK = PF_NETLINK; | |
| 200 | pub const AF_ROUTE = PF_ROUTE; | |
| 201 | pub const AF_PACKET = PF_PACKET; | |
| 202 | pub const AF_ASH = PF_ASH; | |
| 203 | pub const AF_ECONET = PF_ECONET; | |
| 204 | pub const AF_ATMSVC = PF_ATMSVC; | |
| 205 | pub const AF_RDS = PF_RDS; | |
| 206 | pub const AF_SNA = PF_SNA; | |
| 207 | pub const AF_IRDA = PF_IRDA; | |
| 208 | pub const AF_PPPOX = PF_PPPOX; | |
| 209 | pub const AF_WANPIPE = PF_WANPIPE; | |
| 210 | pub const AF_LLC = PF_LLC; | |
| 211 | pub const AF_IB = PF_IB; | |
| 212 | pub const AF_MPLS = PF_MPLS; | |
| 213 | pub const AF_CAN = PF_CAN; | |
| 214 | pub const AF_TIPC = PF_TIPC; | |
| 215 | pub const AF_BLUETOOTH = PF_BLUETOOTH; | |
| 216 | pub const AF_IUCV = PF_IUCV; | |
| 217 | pub const AF_RXRPC = PF_RXRPC; | |
| 218 | pub const AF_ISDN = PF_ISDN; | |
| 219 | pub const AF_PHONET = PF_PHONET; | |
| 220 | pub const AF_IEEE802154 = PF_IEEE802154; | |
| 221 | pub const AF_CAIF = PF_CAIF; | |
| 222 | pub const AF_ALG = PF_ALG; | |
| 223 | pub const AF_NFC = PF_NFC; | |
| 224 | pub const AF_VSOCK = PF_VSOCK; | |
| 225 | pub const AF_MAX = PF_MAX; | |
| 226 | ||
| 227 | /// Get the errno from a syscall return value, or 0 for no error. | |
| 228 | pub 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 | ||
| 233 | pub 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 | ||
| 239 | pub fn munmap(address: &u8, length: usize) -> usize { | |
| 240 | arch.syscall2(arch.SYS_munmap, usize(address), length) | |
| 241 | } | |
| 242 | ||
| 243 | pub fn read(fd: i32, buf: &u8, count: usize) -> usize { | |
| 244 | arch.syscall3(arch.SYS_read, usize(fd), usize(buf), count) | |
| 245 | } | |
| 246 | ||
| 247 | pub 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 | ||
| 251 | pub fn write(fd: i32, buf: &const u8, count: usize) -> usize { | |
| 252 | arch.syscall3(arch.SYS_write, usize(fd), usize(buf), count) | |
| 253 | } | |
| 254 | ||
| 255 | pub 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 | ||
| 259 | pub fn open_c(path: &const u8, flags: usize, perm: usize) -> usize { | |
| 260 | arch.syscall3(arch.SYS_open, usize(path), flags, perm) | |
| 261 | } | |
| 262 | ||
| 263 | pub 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 | ||
| 270 | pub fn create_c(path: &const u8, perm: usize) -> usize { | |
| 271 | arch.syscall2(arch.SYS_creat, usize(path), perm) | |
| 272 | } | |
| 273 | ||
| 274 | pub 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 | ||
| 281 | pub 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 | ||
| 285 | pub 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 | ||
| 292 | pub fn close(fd: i32) -> usize { | |
| 293 | arch.syscall1(arch.SYS_close, usize(fd)) | |
| 294 | } | |
| 295 | ||
| 296 | pub fn lseek(fd: i32, offset: usize, ref_pos: usize) -> usize { | |
| 297 | arch.syscall3(arch.SYS_lseek, usize(fd), offset, ref_pos) | |
| 298 | } | |
| 299 | ||
| 300 | pub fn exit(status: i32) -> noreturn { | |
| 301 | _ = arch.syscall1(arch.SYS_exit, usize(status)); | |
| 302 | unreachable | |
| 303 | } | |
| 304 | ||
| 305 | pub fn getrandom(buf: &u8, count: usize, flags: u32) -> usize { | |
| 306 | arch.syscall3(arch.SYS_getrandom, usize(buf), count, usize(flags)) | |
| 307 | } | |
| 308 | ||
| 309 | pub fn kill(pid: i32, sig: i32) -> i32 { | |
| 310 | i32(arch.syscall2(arch.SYS_kill, usize(pid), usize(sig))) | |
| 311 | } | |
| 312 | ||
| 313 | const NSIG = 65; | |
| 314 | const sigset_t = [128]u8; | |
| 315 | const all_mask = []u8 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, }; | |
| 316 | const app_mask = []u8 { 0xff, 0xff, 0xff, 0xfc, 0x7f, 0xff, 0xff, 0xff, }; | |
| 317 | ||
| 318 | pub 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 | ||
| 327 | fn blockAllSignals(set: &sigset_t) { | |
| 328 | _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_BLOCK, usize(&all_mask), usize(set), NSIG/8); | |
| 329 | } | |
| 330 | ||
| 331 | fn blockAppSignals(set: &sigset_t) { | |
| 332 | _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_BLOCK, usize(&app_mask), usize(set), NSIG/8); | |
| 333 | } | |
| 334 | ||
| 335 | fn restoreSignals(set: &sigset_t) { | |
| 336 | _ = arch.syscall4(arch.SYS_rt_sigprocmask, SIG_SETMASK, usize(set), 0, NSIG/8); | |
| 337 | } | |
| 338 | ||
| 339 | ||
| 340 | pub const sa_family_t = u16; | |
| 341 | pub const socklen_t = u32; | |
| 342 | pub const in_addr = u32; | |
| 343 | pub const in6_addr = [16]u8; | |
| 344 | ||
| 345 | pub const sockaddr = extern struct { | |
| 346 | family: sa_family_t, | |
| 347 | port: u16, | |
| 348 | data: [12]u8, | |
| 349 | }; | |
| 350 | ||
| 351 | pub const sockaddr_in = extern struct { | |
| 352 | family: sa_family_t, | |
| 353 | port: u16, | |
| 354 | addr: in_addr, | |
| 355 | zero: [8]u8, | |
| 356 | }; | |
| 357 | ||
| 358 | pub 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 | ||
| 366 | pub 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 | ||
| 393 | pub 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 | ||
| 397 | pub 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 | ||
| 401 | pub 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 | ||
| 405 | pub 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 | ||
| 409 | pub 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 | ||
| 413 | pub fn sendmsg(fd: i32, msg: &const arch.msghdr, flags: u32) -> usize { | |
| 414 | arch.syscall3(arch.SYS_sendmsg, usize(fd), usize(msg), flags) | |
| 415 | } | |
| 416 | ||
| 417 | pub 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 | ||
| 421 | pub fn recvmsg(fd: i32, msg: &arch.msghdr, flags: u32) -> usize { | |
| 422 | arch.syscall3(arch.SYS_recvmsg, usize(fd), usize(msg), flags) | |
| 423 | } | |
| 424 | ||
| 425 | pub 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 | ||
| 431 | pub fn shutdown(fd: i32, how: i32) -> usize { | |
| 432 | arch.syscall2(arch.SYS_shutdown, usize(fd), usize(how)) | |
| 433 | } | |
| 434 | ||
| 435 | pub 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 | ||
| 439 | pub fn listen(fd: i32, backlog: i32) -> usize { | |
| 440 | arch.syscall2(arch.SYS_listen, usize(fd), usize(backlog)) | |
| 441 | } | |
| 442 | ||
| 443 | pub 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 | ||
| 447 | pub 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 | ||
| 451 | pub fn accept(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize { | |
| 452 | accept4(fd, addr, len, 0) | |
| 453 | } | |
| 454 | ||
| 455 | pub 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 | ||
| 487 | pub const stat = arch.stat; | |
| 488 | pub const timespec = arch.timespec; | |
| 489 | ||
| 490 | pub 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 @@ |
| 1 | const linux = @import("linux.zig"); | |
| 2 | const socklen_t = linux.socklen_t; | |
| 3 | const iovec = linux.iovec; | |
| 4 | ||
| 5 | pub const SYS_restart_syscall = 0; | |
| 6 | pub const SYS_exit = 1; | |
| 7 | pub const SYS_fork = 2; | |
| 8 | pub const SYS_read = 3; | |
| 9 | pub const SYS_write = 4; | |
| 10 | pub const SYS_open = 5; | |
| 11 | pub const SYS_close = 6; | |
| 12 | pub const SYS_waitpid = 7; | |
| 13 | pub const SYS_creat = 8; | |
| 14 | pub const SYS_link = 9; | |
| 15 | pub const SYS_unlink = 10; | |
| 16 | pub const SYS_execve = 11; | |
| 17 | pub const SYS_chdir = 12; | |
| 18 | pub const SYS_time = 13; | |
| 19 | pub const SYS_mknod = 14; | |
| 20 | pub const SYS_chmod = 15; | |
| 21 | pub const SYS_lchown = 16; | |
| 22 | pub const SYS_break = 17; | |
| 23 | pub const SYS_oldstat = 18; | |
| 24 | pub const SYS_lseek = 19; | |
| 25 | pub const SYS_getpid = 20; | |
| 26 | pub const SYS_mount = 21; | |
| 27 | pub const SYS_umount = 22; | |
| 28 | pub const SYS_setuid = 23; | |
| 29 | pub const SYS_getuid = 24; | |
| 30 | pub const SYS_stime = 25; | |
| 31 | pub const SYS_ptrace = 26; | |
| 32 | pub const SYS_alarm = 27; | |
| 33 | pub const SYS_oldfstat = 28; | |
| 34 | pub const SYS_pause = 29; | |
| 35 | pub const SYS_utime = 30; | |
| 36 | pub const SYS_stty = 31; | |
| 37 | pub const SYS_gtty = 32; | |
| 38 | pub const SYS_access = 33; | |
| 39 | pub const SYS_nice = 34; | |
| 40 | pub const SYS_ftime = 35; | |
| 41 | pub const SYS_sync = 36; | |
| 42 | pub const SYS_kill = 37; | |
| 43 | pub const SYS_rename = 38; | |
| 44 | pub const SYS_mkdir = 39; | |
| 45 | pub const SYS_rmdir = 40; | |
| 46 | pub const SYS_dup = 41; | |
| 47 | pub const SYS_pipe = 42; | |
| 48 | pub const SYS_times = 43; | |
| 49 | pub const SYS_prof = 44; | |
| 50 | pub const SYS_brk = 45; | |
| 51 | pub const SYS_setgid = 46; | |
| 52 | pub const SYS_getgid = 47; | |
| 53 | pub const SYS_signal = 48; | |
| 54 | pub const SYS_geteuid = 49; | |
| 55 | pub const SYS_getegid = 50; | |
| 56 | pub const SYS_acct = 51; | |
| 57 | pub const SYS_umount2 = 52; | |
| 58 | pub const SYS_lock = 53; | |
| 59 | pub const SYS_ioctl = 54; | |
| 60 | pub const SYS_fcntl = 55; | |
| 61 | pub const SYS_mpx = 56; | |
| 62 | pub const SYS_setpgid = 57; | |
| 63 | pub const SYS_ulimit = 58; | |
| 64 | pub const SYS_oldolduname = 59; | |
| 65 | pub const SYS_umask = 60; | |
| 66 | pub const SYS_chroot = 61; | |
| 67 | pub const SYS_ustat = 62; | |
| 68 | pub const SYS_dup2 = 63; | |
| 69 | pub const SYS_getppid = 64; | |
| 70 | pub const SYS_getpgrp = 65; | |
| 71 | pub const SYS_setsid = 66; | |
| 72 | pub const SYS_sigaction = 67; | |
| 73 | pub const SYS_sgetmask = 68; | |
| 74 | pub const SYS_ssetmask = 69; | |
| 75 | pub const SYS_setreuid = 70; | |
| 76 | pub const SYS_setregid = 71; | |
| 77 | pub const SYS_sigsuspend = 72; | |
| 78 | pub const SYS_sigpending = 73; | |
| 79 | pub const SYS_sethostname = 74; | |
| 80 | pub const SYS_setrlimit = 75; | |
| 81 | pub const SYS_getrlimit = 76; | |
| 82 | pub const SYS_getrusage = 77; | |
| 83 | pub const SYS_gettimeofday = 78; | |
| 84 | pub const SYS_settimeofday = 79; | |
| 85 | pub const SYS_getgroups = 80; | |
| 86 | pub const SYS_setgroups = 81; | |
| 87 | pub const SYS_select = 82; | |
| 88 | pub const SYS_symlink = 83; | |
| 89 | pub const SYS_oldlstat = 84; | |
| 90 | pub const SYS_readlink = 85; | |
| 91 | pub const SYS_uselib = 86; | |
| 92 | pub const SYS_swapon = 87; | |
| 93 | pub const SYS_reboot = 88; | |
| 94 | pub const SYS_readdir = 89; | |
| 95 | pub const SYS_mmap = 90; | |
| 96 | pub const SYS_munmap = 91; | |
| 97 | pub const SYS_truncate = 92; | |
| 98 | pub const SYS_ftruncate = 93; | |
| 99 | pub const SYS_fchmod = 94; | |
| 100 | pub const SYS_fchown = 95; | |
| 101 | pub const SYS_getpriority = 96; | |
| 102 | pub const SYS_setpriority = 97; | |
| 103 | pub const SYS_profil = 98; | |
| 104 | pub const SYS_statfs = 99; | |
| 105 | pub const SYS_fstatfs = 100; | |
| 106 | pub const SYS_ioperm = 101; | |
| 107 | pub const SYS_socketcall = 102; | |
| 108 | pub const SYS_syslog = 103; | |
| 109 | pub const SYS_setitimer = 104; | |
| 110 | pub const SYS_getitimer = 105; | |
| 111 | pub const SYS_stat = 106; | |
| 112 | pub const SYS_lstat = 107; | |
| 113 | pub const SYS_fstat = 108; | |
| 114 | pub const SYS_olduname = 109; | |
| 115 | pub const SYS_iopl = 110; | |
| 116 | pub const SYS_vhangup = 111; | |
| 117 | pub const SYS_idle = 112; | |
| 118 | pub const SYS_vm86old = 113; | |
| 119 | pub const SYS_wait4 = 114; | |
| 120 | pub const SYS_swapoff = 115; | |
| 121 | pub const SYS_sysinfo = 116; | |
| 122 | pub const SYS_ipc = 117; | |
| 123 | pub const SYS_fsync = 118; | |
| 124 | pub const SYS_sigreturn = 119; | |
| 125 | pub const SYS_clone = 120; | |
| 126 | pub const SYS_setdomainname = 121; | |
| 127 | pub const SYS_uname = 122; | |
| 128 | pub const SYS_modify_ldt = 123; | |
| 129 | pub const SYS_adjtimex = 124; | |
| 130 | pub const SYS_mprotect = 125; | |
| 131 | pub const SYS_sigprocmask = 126; | |
| 132 | pub const SYS_create_module = 127; | |
| 133 | pub const SYS_init_module = 128; | |
| 134 | pub const SYS_delete_module = 129; | |
| 135 | pub const SYS_get_kernel_syms = 130; | |
| 136 | pub const SYS_quotactl = 131; | |
| 137 | pub const SYS_getpgid = 132; | |
| 138 | pub const SYS_fchdir = 133; | |
| 139 | pub const SYS_bdflush = 134; | |
| 140 | pub const SYS_sysfs = 135; | |
| 141 | pub const SYS_personality = 136; | |
| 142 | pub const SYS_afs_syscall = 137; | |
| 143 | pub const SYS_setfsuid = 138; | |
| 144 | pub const SYS_setfsgid = 139; | |
| 145 | pub const SYS__llseek = 140; | |
| 146 | pub const SYS_getdents = 141; | |
| 147 | pub const SYS__newselect = 142; | |
| 148 | pub const SYS_flock = 143; | |
| 149 | pub const SYS_msync = 144; | |
| 150 | pub const SYS_readv = 145; | |
| 151 | pub const SYS_writev = 146; | |
| 152 | pub const SYS_getsid = 147; | |
| 153 | pub const SYS_fdatasync = 148; | |
| 154 | pub const SYS__sysctl = 149; | |
| 155 | pub const SYS_mlock = 150; | |
| 156 | pub const SYS_munlock = 151; | |
| 157 | pub const SYS_mlockall = 152; | |
| 158 | pub const SYS_munlockall = 153; | |
| 159 | pub const SYS_sched_setparam = 154; | |
| 160 | pub const SYS_sched_getparam = 155; | |
| 161 | pub const SYS_sched_setscheduler = 156; | |
| 162 | pub const SYS_sched_getscheduler = 157; | |
| 163 | pub const SYS_sched_yield = 158; | |
| 164 | pub const SYS_sched_get_priority_max = 159; | |
| 165 | pub const SYS_sched_get_priority_min = 160; | |
| 166 | pub const SYS_sched_rr_get_interval = 161; | |
| 167 | pub const SYS_nanosleep = 162; | |
| 168 | pub const SYS_mremap = 163; | |
| 169 | pub const SYS_setresuid = 164; | |
| 170 | pub const SYS_getresuid = 165; | |
| 171 | pub const SYS_vm86 = 166; | |
| 172 | pub const SYS_query_module = 167; | |
| 173 | pub const SYS_poll = 168; | |
| 174 | pub const SYS_nfsservctl = 169; | |
| 175 | pub const SYS_setresgid = 170; | |
| 176 | pub const SYS_getresgid = 171; | |
| 177 | pub const SYS_prctl = 172; | |
| 178 | pub const SYS_rt_sigreturn = 173; | |
| 179 | pub const SYS_rt_sigaction = 174; | |
| 180 | pub const SYS_rt_sigprocmask = 175; | |
| 181 | pub const SYS_rt_sigpending = 176; | |
| 182 | pub const SYS_rt_sigtimedwait = 177; | |
| 183 | pub const SYS_rt_sigqueueinfo = 178; | |
| 184 | pub const SYS_rt_sigsuspend = 179; | |
| 185 | pub const SYS_pread64 = 180; | |
| 186 | pub const SYS_pwrite64 = 181; | |
| 187 | pub const SYS_chown = 182; | |
| 188 | pub const SYS_getcwd = 183; | |
| 189 | pub const SYS_capget = 184; | |
| 190 | pub const SYS_capset = 185; | |
| 191 | pub const SYS_sigaltstack = 186; | |
| 192 | pub const SYS_sendfile = 187; | |
| 193 | pub const SYS_getpmsg = 188; | |
| 194 | pub const SYS_putpmsg = 189; | |
| 195 | pub const SYS_vfork = 190; | |
| 196 | pub const SYS_ugetrlimit = 191; | |
| 197 | pub const SYS_mmap2 = 192; | |
| 198 | pub const SYS_truncate64 = 193; | |
| 199 | pub const SYS_ftruncate64 = 194; | |
| 200 | pub const SYS_stat64 = 195; | |
| 201 | pub const SYS_lstat64 = 196; | |
| 202 | pub const SYS_fstat64 = 197; | |
| 203 | pub const SYS_lchown32 = 198; | |
| 204 | pub const SYS_getuid32 = 199; | |
| 205 | pub const SYS_getgid32 = 200; | |
| 206 | pub const SYS_geteuid32 = 201; | |
| 207 | pub const SYS_getegid32 = 202; | |
| 208 | pub const SYS_setreuid32 = 203; | |
| 209 | pub const SYS_setregid32 = 204; | |
| 210 | pub const SYS_getgroups32 = 205; | |
| 211 | pub const SYS_setgroups32 = 206; | |
| 212 | pub const SYS_fchown32 = 207; | |
| 213 | pub const SYS_setresuid32 = 208; | |
| 214 | pub const SYS_getresuid32 = 209; | |
| 215 | pub const SYS_setresgid32 = 210; | |
| 216 | pub const SYS_getresgid32 = 211; | |
| 217 | pub const SYS_chown32 = 212; | |
| 218 | pub const SYS_setuid32 = 213; | |
| 219 | pub const SYS_setgid32 = 214; | |
| 220 | pub const SYS_setfsuid32 = 215; | |
| 221 | pub const SYS_setfsgid32 = 216; | |
| 222 | pub const SYS_pivot_root = 217; | |
| 223 | pub const SYS_mincore = 218; | |
| 224 | pub const SYS_madvise = 219; | |
| 225 | pub const SYS_madvise1 = 219; | |
| 226 | pub const SYS_getdents64 = 220; | |
| 227 | pub const SYS_fcntl64 = 221; | |
| 228 | pub const SYS_gettid = 224; | |
| 229 | pub const SYS_readahead = 225; | |
| 230 | pub const SYS_setxattr = 226; | |
| 231 | pub const SYS_lsetxattr = 227; | |
| 232 | pub const SYS_fsetxattr = 228; | |
| 233 | pub const SYS_getxattr = 229; | |
| 234 | pub const SYS_lgetxattr = 230; | |
| 235 | pub const SYS_fgetxattr = 231; | |
| 236 | pub const SYS_listxattr = 232; | |
| 237 | pub const SYS_llistxattr = 233; | |
| 238 | pub const SYS_flistxattr = 234; | |
| 239 | pub const SYS_removexattr = 235; | |
| 240 | pub const SYS_lremovexattr = 236; | |
| 241 | pub const SYS_fremovexattr = 237; | |
| 242 | pub const SYS_tkill = 238; | |
| 243 | pub const SYS_sendfile64 = 239; | |
| 244 | pub const SYS_futex = 240; | |
| 245 | pub const SYS_sched_setaffinity = 241; | |
| 246 | pub const SYS_sched_getaffinity = 242; | |
| 247 | pub const SYS_set_thread_area = 243; | |
| 248 | pub const SYS_get_thread_area = 244; | |
| 249 | pub const SYS_io_setup = 245; | |
| 250 | pub const SYS_io_destroy = 246; | |
| 251 | pub const SYS_io_getevents = 247; | |
| 252 | pub const SYS_io_submit = 248; | |
| 253 | pub const SYS_io_cancel = 249; | |
| 254 | pub const SYS_fadvise64 = 250; | |
| 255 | pub const SYS_exit_group = 252; | |
| 256 | pub const SYS_lookup_dcookie = 253; | |
| 257 | pub const SYS_epoll_create = 254; | |
| 258 | pub const SYS_epoll_ctl = 255; | |
| 259 | pub const SYS_epoll_wait = 256; | |
| 260 | pub const SYS_remap_file_pages = 257; | |
| 261 | pub const SYS_set_tid_address = 258; | |
| 262 | pub const SYS_timer_create = 259; | |
| 263 | pub const SYS_timer_settime = SYS_timer_create+1; | |
| 264 | pub const SYS_timer_gettime = SYS_timer_create+2; | |
| 265 | pub const SYS_timer_getoverrun = SYS_timer_create+3; | |
| 266 | pub const SYS_timer_delete = SYS_timer_create+4; | |
| 267 | pub const SYS_clock_settime = SYS_timer_create+5; | |
| 268 | pub const SYS_clock_gettime = SYS_timer_create+6; | |
| 269 | pub const SYS_clock_getres = SYS_timer_create+7; | |
| 270 | pub const SYS_clock_nanosleep = SYS_timer_create+8; | |
| 271 | pub const SYS_statfs64 = 268; | |
| 272 | pub const SYS_fstatfs64 = 269; | |
| 273 | pub const SYS_tgkill = 270; | |
| 274 | pub const SYS_utimes = 271; | |
| 275 | pub const SYS_fadvise64_64 = 272; | |
| 276 | pub const SYS_vserver = 273; | |
| 277 | pub const SYS_mbind = 274; | |
| 278 | pub const SYS_get_mempolicy = 275; | |
| 279 | pub const SYS_set_mempolicy = 276; | |
| 280 | pub const SYS_mq_open = 277; | |
| 281 | pub const SYS_mq_unlink = SYS_mq_open+1; | |
| 282 | pub const SYS_mq_timedsend = SYS_mq_open+2; | |
| 283 | pub const SYS_mq_timedreceive = SYS_mq_open+3; | |
| 284 | pub const SYS_mq_notify = SYS_mq_open+4; | |
| 285 | pub const SYS_mq_getsetattr = SYS_mq_open+5; | |
| 286 | pub const SYS_kexec_load = 283; | |
| 287 | pub const SYS_waitid = 284; | |
| 288 | pub const SYS_add_key = 286; | |
| 289 | pub const SYS_request_key = 287; | |
| 290 | pub const SYS_keyctl = 288; | |
| 291 | pub const SYS_ioprio_set = 289; | |
| 292 | pub const SYS_ioprio_get = 290; | |
| 293 | pub const SYS_inotify_init = 291; | |
| 294 | pub const SYS_inotify_add_watch = 292; | |
| 295 | pub const SYS_inotify_rm_watch = 293; | |
| 296 | pub const SYS_migrate_pages = 294; | |
| 297 | pub const SYS_openat = 295; | |
| 298 | pub const SYS_mkdirat = 296; | |
| 299 | pub const SYS_mknodat = 297; | |
| 300 | pub const SYS_fchownat = 298; | |
| 301 | pub const SYS_futimesat = 299; | |
| 302 | pub const SYS_fstatat64 = 300; | |
| 303 | pub const SYS_unlinkat = 301; | |
| 304 | pub const SYS_renameat = 302; | |
| 305 | pub const SYS_linkat = 303; | |
| 306 | pub const SYS_symlinkat = 304; | |
| 307 | pub const SYS_readlinkat = 305; | |
| 308 | pub const SYS_fchmodat = 306; | |
| 309 | pub const SYS_faccessat = 307; | |
| 310 | pub const SYS_pselect6 = 308; | |
| 311 | pub const SYS_ppoll = 309; | |
| 312 | pub const SYS_unshare = 310; | |
| 313 | pub const SYS_set_robust_list = 311; | |
| 314 | pub const SYS_get_robust_list = 312; | |
| 315 | pub const SYS_splice = 313; | |
| 316 | pub const SYS_sync_file_range = 314; | |
| 317 | pub const SYS_tee = 315; | |
| 318 | pub const SYS_vmsplice = 316; | |
| 319 | pub const SYS_move_pages = 317; | |
| 320 | pub const SYS_getcpu = 318; | |
| 321 | pub const SYS_epoll_pwait = 319; | |
| 322 | pub const SYS_utimensat = 320; | |
| 323 | pub const SYS_signalfd = 321; | |
| 324 | pub const SYS_timerfd_create = 322; | |
| 325 | pub const SYS_eventfd = 323; | |
| 326 | pub const SYS_fallocate = 324; | |
| 327 | pub const SYS_timerfd_settime = 325; | |
| 328 | pub const SYS_timerfd_gettime = 326; | |
| 329 | pub const SYS_signalfd4 = 327; | |
| 330 | pub const SYS_eventfd2 = 328; | |
| 331 | pub const SYS_epoll_create1 = 329; | |
| 332 | pub const SYS_dup3 = 330; | |
| 333 | pub const SYS_pipe2 = 331; | |
| 334 | pub const SYS_inotify_init1 = 332; | |
| 335 | pub const SYS_preadv = 333; | |
| 336 | pub const SYS_pwritev = 334; | |
| 337 | pub const SYS_rt_tgsigqueueinfo = 335; | |
| 338 | pub const SYS_perf_event_open = 336; | |
| 339 | pub const SYS_recvmmsg = 337; | |
| 340 | pub const SYS_fanotify_init = 338; | |
| 341 | pub const SYS_fanotify_mark = 339; | |
| 342 | pub const SYS_prlimit64 = 340; | |
| 343 | pub const SYS_name_to_handle_at = 341; | |
| 344 | pub const SYS_open_by_handle_at = 342; | |
| 345 | pub const SYS_clock_adjtime = 343; | |
| 346 | pub const SYS_syncfs = 344; | |
| 347 | pub const SYS_sendmmsg = 345; | |
| 348 | pub const SYS_setns = 346; | |
| 349 | pub const SYS_process_vm_readv = 347; | |
| 350 | pub const SYS_process_vm_writev = 348; | |
| 351 | pub const SYS_kcmp = 349; | |
| 352 | pub const SYS_finit_module = 350; | |
| 353 | pub const SYS_sched_setattr = 351; | |
| 354 | pub const SYS_sched_getattr = 352; | |
| 355 | pub const SYS_renameat2 = 353; | |
| 356 | pub const SYS_seccomp = 354; | |
| 357 | pub const SYS_getrandom = 355; | |
| 358 | pub const SYS_memfd_create = 356; | |
| 359 | pub const SYS_bpf = 357; | |
| 360 | pub const SYS_execveat = 358; | |
| 361 | pub const SYS_socket = 359; | |
| 362 | pub const SYS_socketpair = 360; | |
| 363 | pub const SYS_bind = 361; | |
| 364 | pub const SYS_connect = 362; | |
| 365 | pub const SYS_listen = 363; | |
| 366 | pub const SYS_accept4 = 364; | |
| 367 | pub const SYS_getsockopt = 365; | |
| 368 | pub const SYS_setsockopt = 366; | |
| 369 | pub const SYS_getsockname = 367; | |
| 370 | pub const SYS_getpeername = 368; | |
| 371 | pub const SYS_sendto = 369; | |
| 372 | pub const SYS_sendmsg = 370; | |
| 373 | pub const SYS_recvfrom = 371; | |
| 374 | pub const SYS_recvmsg = 372; | |
| 375 | pub const SYS_shutdown = 373; | |
| 376 | pub const SYS_userfaultfd = 374; | |
| 377 | pub const SYS_membarrier = 375; | |
| 378 | pub const SYS_mlock2 = 376; | |
| 379 | ||
| 380 | ||
| 381 | pub const O_CREAT = 0o100; | |
| 382 | pub const O_EXCL = 0o200; | |
| 383 | pub const O_NOCTTY = 0o400; | |
| 384 | pub const O_TRUNC = 0o1000; | |
| 385 | pub const O_APPEND = 0o2000; | |
| 386 | pub const O_NONBLOCK = 0o4000; | |
| 387 | pub const O_DSYNC = 0o10000; | |
| 388 | pub const O_SYNC = 0o4010000; | |
| 389 | pub const O_RSYNC = 0o4010000; | |
| 390 | pub const O_DIRECTORY = 0o200000; | |
| 391 | pub const O_NOFOLLOW = 0o400000; | |
| 392 | pub const O_CLOEXEC = 0o2000000; | |
| 393 | ||
| 394 | pub const O_ASYNC = 0o20000; | |
| 395 | pub const O_DIRECT = 0o40000; | |
| 396 | pub const O_LARGEFILE = 0o100000; | |
| 397 | pub const O_NOATIME = 0o1000000; | |
| 398 | pub const O_PATH = 0o10000000; | |
| 399 | pub const O_TMPFILE = 0o20200000; | |
| 400 | pub const O_NDELAY = O_NONBLOCK; | |
| 401 | ||
| 402 | pub const F_DUPFD = 0; | |
| 403 | pub const F_GETFD = 1; | |
| 404 | pub const F_SETFD = 2; | |
| 405 | pub const F_GETFL = 3; | |
| 406 | pub const F_SETFL = 4; | |
| 407 | ||
| 408 | pub const F_SETOWN = 8; | |
| 409 | pub const F_GETOWN = 9; | |
| 410 | pub const F_SETSIG = 10; | |
| 411 | pub const F_GETSIG = 11; | |
| 412 | ||
| 413 | pub const F_GETLK = 12; | |
| 414 | pub const F_SETLK = 13; | |
| 415 | pub const F_SETLKW = 14; | |
| 416 | ||
| 417 | pub const F_SETOWN_EX = 15; | |
| 418 | pub const F_GETOWN_EX = 16; | |
| 419 | ||
| 420 | pub const F_GETOWNER_UIDS = 17; | |
| 421 | ||
| 422 | pub inline fn syscall0(number: usize) -> usize { | |
| 423 | asm volatile ("int 80h" | |
| 424 | : [ret] "={eax}" (-> usize) | |
| 425 | : [number] "{eax}" (number)) | |
| 426 | } | |
| 427 | ||
| 428 | pub 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 | ||
| 435 | pub 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 | ||
| 443 | pub 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 | ||
| 452 | pub 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 | ||
| 462 | pub 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 | ||
| 475 | pub 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 | ||
| 489 | export 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 @@ |
| 1 | const linux = @import("linux.zig"); | |
| 2 | const socklen_t = linux.socklen_t; | |
| 3 | const iovec = linux.iovec; | |
| 4 | ||
| 5 | pub const SYS_read = 0; | |
| 6 | pub const SYS_write = 1; | |
| 7 | pub const SYS_open = 2; | |
| 8 | pub const SYS_close = 3; | |
| 9 | pub const SYS_stat = 4; | |
| 10 | pub const SYS_fstat = 5; | |
| 11 | pub const SYS_lstat = 6; | |
| 12 | pub const SYS_poll = 7; | |
| 13 | pub const SYS_lseek = 8; | |
| 14 | pub const SYS_mmap = 9; | |
| 15 | pub const SYS_mprotect = 10; | |
| 16 | pub const SYS_munmap = 11; | |
| 17 | pub const SYS_brk = 12; | |
| 18 | pub const SYS_rt_sigaction = 13; | |
| 19 | pub const SYS_rt_sigprocmask = 14; | |
| 20 | pub const SYS_rt_sigreturn = 15; | |
| 21 | pub const SYS_ioctl = 16; | |
| 22 | pub const SYS_pread = 17; | |
| 23 | pub const SYS_pwrite = 18; | |
| 24 | pub const SYS_readv = 19; | |
| 25 | pub const SYS_writev = 20; | |
| 26 | pub const SYS_access = 21; | |
| 27 | pub const SYS_pipe = 22; | |
| 28 | pub const SYS_select = 23; | |
| 29 | pub const SYS_sched_yield = 24; | |
| 30 | pub const SYS_mremap = 25; | |
| 31 | pub const SYS_msync = 26; | |
| 32 | pub const SYS_mincore = 27; | |
| 33 | pub const SYS_madvise = 28; | |
| 34 | pub const SYS_shmget = 29; | |
| 35 | pub const SYS_shmat = 30; | |
| 36 | pub const SYS_shmctl = 31; | |
| 37 | pub const SYS_dup = 32; | |
| 38 | pub const SYS_dup2 = 33; | |
| 39 | pub const SYS_pause = 34; | |
| 40 | pub const SYS_nanosleep = 35; | |
| 41 | pub const SYS_getitimer = 36; | |
| 42 | pub const SYS_alarm = 37; | |
| 43 | pub const SYS_setitimer = 38; | |
| 44 | pub const SYS_getpid = 39; | |
| 45 | pub const SYS_sendfile = 40; | |
| 46 | pub const SYS_socket = 41; | |
| 47 | pub const SYS_connect = 42; | |
| 48 | pub const SYS_accept = 43; | |
| 49 | pub const SYS_sendto = 44; | |
| 50 | pub const SYS_recvfrom = 45; | |
| 51 | pub const SYS_sendmsg = 46; | |
| 52 | pub const SYS_recvmsg = 47; | |
| 53 | pub const SYS_shutdown = 48; | |
| 54 | pub const SYS_bind = 49; | |
| 55 | pub const SYS_listen = 50; | |
| 56 | pub const SYS_getsockname = 51; | |
| 57 | pub const SYS_getpeername = 52; | |
| 58 | pub const SYS_socketpair = 53; | |
| 59 | pub const SYS_setsockopt = 54; | |
| 60 | pub const SYS_getsockopt = 55; | |
| 61 | pub const SYS_clone = 56; | |
| 62 | pub const SYS_fork = 57; | |
| 63 | pub const SYS_vfork = 58; | |
| 64 | pub const SYS_execve = 59; | |
| 65 | pub const SYS_exit = 60; | |
| 66 | pub const SYS_wait4 = 61; | |
| 67 | pub const SYS_kill = 62; | |
| 68 | pub const SYS_uname = 63; | |
| 69 | pub const SYS_semget = 64; | |
| 70 | pub const SYS_semop = 65; | |
| 71 | pub const SYS_semctl = 66; | |
| 72 | pub const SYS_shmdt = 67; | |
| 73 | pub const SYS_msgget = 68; | |
| 74 | pub const SYS_msgsnd = 69; | |
| 75 | pub const SYS_msgrcv = 70; | |
| 76 | pub const SYS_msgctl = 71; | |
| 77 | pub const SYS_fcntl = 72; | |
| 78 | pub const SYS_flock = 73; | |
| 79 | pub const SYS_fsync = 74; | |
| 80 | pub const SYS_fdatasync = 75; | |
| 81 | pub const SYS_truncate = 76; | |
| 82 | pub const SYS_ftruncate = 77; | |
| 83 | pub const SYS_getdents = 78; | |
| 84 | pub const SYS_getcwd = 79; | |
| 85 | pub const SYS_chdir = 80; | |
| 86 | pub const SYS_fchdir = 81; | |
| 87 | pub const SYS_rename = 82; | |
| 88 | pub const SYS_mkdir = 83; | |
| 89 | pub const SYS_rmdir = 84; | |
| 90 | pub const SYS_creat = 85; | |
| 91 | pub const SYS_link = 86; | |
| 92 | pub const SYS_unlink = 87; | |
| 93 | pub const SYS_symlink = 88; | |
| 94 | pub const SYS_readlink = 89; | |
| 95 | pub const SYS_chmod = 90; | |
| 96 | pub const SYS_fchmod = 91; | |
| 97 | pub const SYS_chown = 92; | |
| 98 | pub const SYS_fchown = 93; | |
| 99 | pub const SYS_lchown = 94; | |
| 100 | pub const SYS_umask = 95; | |
| 101 | pub const SYS_gettimeofday = 96; | |
| 102 | pub const SYS_getrlimit = 97; | |
| 103 | pub const SYS_getrusage = 98; | |
| 104 | pub const SYS_sysinfo = 99; | |
| 105 | pub const SYS_times = 100; | |
| 106 | pub const SYS_ptrace = 101; | |
| 107 | pub const SYS_getuid = 102; | |
| 108 | pub const SYS_syslog = 103; | |
| 109 | pub const SYS_getgid = 104; | |
| 110 | pub const SYS_setuid = 105; | |
| 111 | pub const SYS_setgid = 106; | |
| 112 | pub const SYS_geteuid = 107; | |
| 113 | pub const SYS_getegid = 108; | |
| 114 | pub const SYS_setpgid = 109; | |
| 115 | pub const SYS_getppid = 110; | |
| 116 | pub const SYS_getpgrp = 111; | |
| 117 | pub const SYS_setsid = 112; | |
| 118 | pub const SYS_setreuid = 113; | |
| 119 | pub const SYS_setregid = 114; | |
| 120 | pub const SYS_getgroups = 115; | |
| 121 | pub const SYS_setgroups = 116; | |
| 122 | pub const SYS_setresuid = 117; | |
| 123 | pub const SYS_getresuid = 118; | |
| 124 | pub const SYS_setresgid = 119; | |
| 125 | pub const SYS_getresgid = 120; | |
| 126 | pub const SYS_getpgid = 121; | |
| 127 | pub const SYS_setfsuid = 122; | |
| 128 | pub const SYS_setfsgid = 123; | |
| 129 | pub const SYS_getsid = 124; | |
| 130 | pub const SYS_capget = 125; | |
| 131 | pub const SYS_capset = 126; | |
| 132 | pub const SYS_rt_sigpending = 127; | |
| 133 | pub const SYS_rt_sigtimedwait = 128; | |
| 134 | pub const SYS_rt_sigqueueinfo = 129; | |
| 135 | pub const SYS_rt_sigsuspend = 130; | |
| 136 | pub const SYS_sigaltstack = 131; | |
| 137 | pub const SYS_utime = 132; | |
| 138 | pub const SYS_mknod = 133; | |
| 139 | pub const SYS_uselib = 134; | |
| 140 | pub const SYS_personality = 135; | |
| 141 | pub const SYS_ustat = 136; | |
| 142 | pub const SYS_statfs = 137; | |
| 143 | pub const SYS_fstatfs = 138; | |
| 144 | pub const SYS_sysfs = 139; | |
| 145 | pub const SYS_getpriority = 140; | |
| 146 | pub const SYS_setpriority = 141; | |
| 147 | pub const SYS_sched_setparam = 142; | |
| 148 | pub const SYS_sched_getparam = 143; | |
| 149 | pub const SYS_sched_setscheduler = 144; | |
| 150 | pub const SYS_sched_getscheduler = 145; | |
| 151 | pub const SYS_sched_get_priority_max = 146; | |
| 152 | pub const SYS_sched_get_priority_min = 147; | |
| 153 | pub const SYS_sched_rr_get_interval = 148; | |
| 154 | pub const SYS_mlock = 149; | |
| 155 | pub const SYS_munlock = 150; | |
| 156 | pub const SYS_mlockall = 151; | |
| 157 | pub const SYS_munlockall = 152; | |
| 158 | pub const SYS_vhangup = 153; | |
| 159 | pub const SYS_modify_ldt = 154; | |
| 160 | pub const SYS_pivot_root = 155; | |
| 161 | pub const SYS__sysctl = 156; | |
| 162 | pub const SYS_prctl = 157; | |
| 163 | pub const SYS_arch_prctl = 158; | |
| 164 | pub const SYS_adjtimex = 159; | |
| 165 | pub const SYS_setrlimit = 160; | |
| 166 | pub const SYS_chroot = 161; | |
| 167 | pub const SYS_sync = 162; | |
| 168 | pub const SYS_acct = 163; | |
| 169 | pub const SYS_settimeofday = 164; | |
| 170 | pub const SYS_mount = 165; | |
| 171 | pub const SYS_umount2 = 166; | |
| 172 | pub const SYS_swapon = 167; | |
| 173 | pub const SYS_swapoff = 168; | |
| 174 | pub const SYS_reboot = 169; | |
| 175 | pub const SYS_sethostname = 170; | |
| 176 | pub const SYS_setdomainname = 171; | |
| 177 | pub const SYS_iopl = 172; | |
| 178 | pub const SYS_ioperm = 173; | |
| 179 | pub const SYS_create_module = 174; | |
| 180 | pub const SYS_init_module = 175; | |
| 181 | pub const SYS_delete_module = 176; | |
| 182 | pub const SYS_get_kernel_syms = 177; | |
| 183 | pub const SYS_query_module = 178; | |
| 184 | pub const SYS_quotactl = 179; | |
| 185 | pub const SYS_nfsservctl = 180; | |
| 186 | pub const SYS_getpmsg = 181; | |
| 187 | pub const SYS_putpmsg = 182; | |
| 188 | pub const SYS_afs_syscall = 183; | |
| 189 | pub const SYS_tuxcall = 184; | |
| 190 | pub const SYS_security = 185; | |
| 191 | pub const SYS_gettid = 186; | |
| 192 | pub const SYS_readahead = 187; | |
| 193 | pub const SYS_setxattr = 188; | |
| 194 | pub const SYS_lsetxattr = 189; | |
| 195 | pub const SYS_fsetxattr = 190; | |
| 196 | pub const SYS_getxattr = 191; | |
| 197 | pub const SYS_lgetxattr = 192; | |
| 198 | pub const SYS_fgetxattr = 193; | |
| 199 | pub const SYS_listxattr = 194; | |
| 200 | pub const SYS_llistxattr = 195; | |
| 201 | pub const SYS_flistxattr = 196; | |
| 202 | pub const SYS_removexattr = 197; | |
| 203 | pub const SYS_lremovexattr = 198; | |
| 204 | pub const SYS_fremovexattr = 199; | |
| 205 | pub const SYS_tkill = 200; | |
| 206 | pub const SYS_time = 201; | |
| 207 | pub const SYS_futex = 202; | |
| 208 | pub const SYS_sched_setaffinity = 203; | |
| 209 | pub const SYS_sched_getaffinity = 204; | |
| 210 | pub const SYS_set_thread_area = 205; | |
| 211 | pub const SYS_io_setup = 206; | |
| 212 | pub const SYS_io_destroy = 207; | |
| 213 | pub const SYS_io_getevents = 208; | |
| 214 | pub const SYS_io_submit = 209; | |
| 215 | pub const SYS_io_cancel = 210; | |
| 216 | pub const SYS_get_thread_area = 211; | |
| 217 | pub const SYS_lookup_dcookie = 212; | |
| 218 | pub const SYS_epoll_create = 213; | |
| 219 | pub const SYS_epoll_ctl_old = 214; | |
| 220 | pub const SYS_epoll_wait_old = 215; | |
| 221 | pub const SYS_remap_file_pages = 216; | |
| 222 | pub const SYS_getdents64 = 217; | |
| 223 | pub const SYS_set_tid_address = 218; | |
| 224 | pub const SYS_restart_syscall = 219; | |
| 225 | pub const SYS_semtimedop = 220; | |
| 226 | pub const SYS_fadvise64 = 221; | |
| 227 | pub const SYS_timer_create = 222; | |
| 228 | pub const SYS_timer_settime = 223; | |
| 229 | pub const SYS_timer_gettime = 224; | |
| 230 | pub const SYS_timer_getoverrun = 225; | |
| 231 | pub const SYS_timer_delete = 226; | |
| 232 | pub const SYS_clock_settime = 227; | |
| 233 | pub const SYS_clock_gettime = 228; | |
| 234 | pub const SYS_clock_getres = 229; | |
| 235 | pub const SYS_clock_nanosleep = 230; | |
| 236 | pub const SYS_exit_group = 231; | |
| 237 | pub const SYS_epoll_wait = 232; | |
| 238 | pub const SYS_epoll_ctl = 233; | |
| 239 | pub const SYS_tgkill = 234; | |
| 240 | pub const SYS_utimes = 235; | |
| 241 | pub const SYS_vserver = 236; | |
| 242 | pub const SYS_mbind = 237; | |
| 243 | pub const SYS_set_mempolicy = 238; | |
| 244 | pub const SYS_get_mempolicy = 239; | |
| 245 | pub const SYS_mq_open = 240; | |
| 246 | pub const SYS_mq_unlink = 241; | |
| 247 | pub const SYS_mq_timedsend = 242; | |
| 248 | pub const SYS_mq_timedreceive = 243; | |
| 249 | pub const SYS_mq_notify = 244; | |
| 250 | pub const SYS_mq_getsetattr = 245; | |
| 251 | pub const SYS_kexec_load = 246; | |
| 252 | pub const SYS_waitid = 247; | |
| 253 | pub const SYS_add_key = 248; | |
| 254 | pub const SYS_request_key = 249; | |
| 255 | pub const SYS_keyctl = 250; | |
| 256 | pub const SYS_ioprio_set = 251; | |
| 257 | pub const SYS_ioprio_get = 252; | |
| 258 | pub const SYS_inotify_init = 253; | |
| 259 | pub const SYS_inotify_add_watch = 254; | |
| 260 | pub const SYS_inotify_rm_watch = 255; | |
| 261 | pub const SYS_migrate_pages = 256; | |
| 262 | pub const SYS_openat = 257; | |
| 263 | pub const SYS_mkdirat = 258; | |
| 264 | pub const SYS_mknodat = 259; | |
| 265 | pub const SYS_fchownat = 260; | |
| 266 | pub const SYS_futimesat = 261; | |
| 267 | pub const SYS_newfstatat = 262; | |
| 268 | pub const SYS_unlinkat = 263; | |
| 269 | pub const SYS_renameat = 264; | |
| 270 | pub const SYS_linkat = 265; | |
| 271 | pub const SYS_symlinkat = 266; | |
| 272 | pub const SYS_readlinkat = 267; | |
| 273 | pub const SYS_fchmodat = 268; | |
| 274 | pub const SYS_faccessat = 269; | |
| 275 | pub const SYS_pselect6 = 270; | |
| 276 | pub const SYS_ppoll = 271; | |
| 277 | pub const SYS_unshare = 272; | |
| 278 | pub const SYS_set_robust_list = 273; | |
| 279 | pub const SYS_get_robust_list = 274; | |
| 280 | pub const SYS_splice = 275; | |
| 281 | pub const SYS_tee = 276; | |
| 282 | pub const SYS_sync_file_range = 277; | |
| 283 | pub const SYS_vmsplice = 278; | |
| 284 | pub const SYS_move_pages = 279; | |
| 285 | pub const SYS_utimensat = 280; | |
| 286 | pub const SYS_epoll_pwait = 281; | |
| 287 | pub const SYS_signalfd = 282; | |
| 288 | pub const SYS_timerfd_create = 283; | |
| 289 | pub const SYS_eventfd = 284; | |
| 290 | pub const SYS_fallocate = 285; | |
| 291 | pub const SYS_timerfd_settime = 286; | |
| 292 | pub const SYS_timerfd_gettime = 287; | |
| 293 | pub const SYS_accept4 = 288; | |
| 294 | pub const SYS_signalfd4 = 289; | |
| 295 | pub const SYS_eventfd2 = 290; | |
| 296 | pub const SYS_epoll_create1 = 291; | |
| 297 | pub const SYS_dup3 = 292; | |
| 298 | pub const SYS_pipe2 = 293; | |
| 299 | pub const SYS_inotify_init1 = 294; | |
| 300 | pub const SYS_preadv = 295; | |
| 301 | pub const SYS_pwritev = 296; | |
| 302 | pub const SYS_rt_tgsigqueueinfo = 297; | |
| 303 | pub const SYS_perf_event_open = 298; | |
| 304 | pub const SYS_recvmmsg = 299; | |
| 305 | pub const SYS_fanotify_init = 300; | |
| 306 | pub const SYS_fanotify_mark = 301; | |
| 307 | pub const SYS_prlimit64 = 302; | |
| 308 | pub const SYS_name_to_handle_at = 303; | |
| 309 | pub const SYS_open_by_handle_at = 304; | |
| 310 | pub const SYS_clock_adjtime = 305; | |
| 311 | pub const SYS_syncfs = 306; | |
| 312 | pub const SYS_sendmmsg = 307; | |
| 313 | pub const SYS_setns = 308; | |
| 314 | pub const SYS_getcpu = 309; | |
| 315 | pub const SYS_process_vm_readv = 310; | |
| 316 | pub const SYS_process_vm_writev = 311; | |
| 317 | pub const SYS_kcmp = 312; | |
| 318 | pub const SYS_finit_module = 313; | |
| 319 | pub const SYS_sched_setattr = 314; | |
| 320 | pub const SYS_sched_getattr = 315; | |
| 321 | pub const SYS_renameat2 = 316; | |
| 322 | pub const SYS_seccomp = 317; | |
| 323 | pub const SYS_getrandom = 318; | |
| 324 | pub const SYS_memfd_create = 319; | |
| 325 | pub const SYS_kexec_file_load = 320; | |
| 326 | pub const SYS_bpf = 321; | |
| 327 | pub const SYS_execveat = 322; | |
| 328 | pub const SYS_userfaultfd = 323; | |
| 329 | pub const SYS_membarrier = 324; | |
| 330 | pub const SYS_mlock2 = 325; | |
| 331 | ||
| 332 | pub const O_CREAT = 0o100; | |
| 333 | pub const O_EXCL = 0o200; | |
| 334 | pub const O_NOCTTY = 0o400; | |
| 335 | pub const O_TRUNC = 0o1000; | |
| 336 | pub const O_APPEND = 0o2000; | |
| 337 | pub const O_NONBLOCK = 0o4000; | |
| 338 | pub const O_DSYNC = 0o10000; | |
| 339 | pub const O_SYNC = 0o4010000; | |
| 340 | pub const O_RSYNC = 0o4010000; | |
| 341 | pub const O_DIRECTORY = 0o200000; | |
| 342 | pub const O_NOFOLLOW = 0o400000; | |
| 343 | pub const O_CLOEXEC = 0o2000000; | |
| 344 | ||
| 345 | pub const O_ASYNC = 0o20000; | |
| 346 | pub const O_DIRECT = 0o40000; | |
| 347 | pub const O_LARGEFILE = 0; | |
| 348 | pub const O_NOATIME = 0o1000000; | |
| 349 | pub const O_PATH = 0o10000000; | |
| 350 | pub const O_TMPFILE = 0o20200000; | |
| 351 | pub const O_NDELAY = O_NONBLOCK; | |
| 352 | ||
| 353 | pub const F_DUPFD = 0; | |
| 354 | pub const F_GETFD = 1; | |
| 355 | pub const F_SETFD = 2; | |
| 356 | pub const F_GETFL = 3; | |
| 357 | pub const F_SETFL = 4; | |
| 358 | ||
| 359 | pub const F_SETOWN = 8; | |
| 360 | pub const F_GETOWN = 9; | |
| 361 | pub const F_SETSIG = 10; | |
| 362 | pub const F_GETSIG = 11; | |
| 363 | ||
| 364 | pub const F_GETLK = 5; | |
| 365 | pub const F_SETLK = 6; | |
| 366 | pub const F_SETLKW = 7; | |
| 367 | ||
| 368 | pub const F_SETOWN_EX = 15; | |
| 369 | pub const F_GETOWN_EX = 16; | |
| 370 | ||
| 371 | pub const F_GETOWNER_UIDS = 17; | |
| 372 | ||
| 373 | pub inline fn syscall0(number: usize) -> usize { | |
| 374 | asm volatile ("syscall" | |
| 375 | : [ret] "={rax}" (-> usize) | |
| 376 | : [number] "{rax}" (number) | |
| 377 | : "rcx", "r11") | |
| 378 | } | |
| 379 | ||
| 380 | pub 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 | ||
| 388 | pub 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 | ||
| 397 | pub 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 | ||
| 407 | pub 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 | ||
| 418 | pub 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 | ||
| 430 | pub 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 | ||
| 445 | pub 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 | ||
| 457 | pub 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 | ||
| 477 | pub const timespec = extern struct { | |
| 478 | tv_sec: isize, | |
| 479 | tv_nsec: isize, | |
| 480 | }; |
std/os/windows.zig created+17| ... | ... | @@ -0,0 +1,17 @@ |
| 1 | pub extern fn CryptAcquireContext(phProv: &HCRYPTPROV, pszContainer: LPCTSTR, | |
| 2 | pszProvider: LPCTSTR, dwProvType: DWORD, dwFlags: DWORD) -> bool; | |
| 3 | ||
| 4 | pub extern fn CryptReleaseContext(hProv: HCRYPTPROV, dwFlags: DWORD) -> bool; | |
| 5 | ||
| 6 | pub extern fn CryptGenRandom(hProv: HCRYPTPROV, dwLen: DWORD, pbBuffer: &BYTE) -> bool; | |
| 7 | ||
| 8 | pub const PROV_RSA_FULL = 1; | |
| 9 | ||
| 10 | ||
| 11 | pub const BYTE = u8; | |
| 12 | pub const DWORD = u32; | |
| 13 | // TODO something about unicode WCHAR vs char | |
| 14 | pub const TCHAR = u8; | |
| 15 | pub const LPCTSTR = ?&const TCHAR; | |
| 16 | pub const ULONG_PTR = usize; | |
| 17 | pub 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 | ||
| 6 | pub 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 | ||
| 4 | const root = @import("@root"); | |
| 5 | const std = @import("std"); | |
| 6 | ||
| 7 | const want_main_symbol = std.target.linking_libc; | |
| 8 | const want_start_symbol = !want_main_symbol; | |
| 9 | ||
| 10 | const exit = std.os.posix.exit; | |
| 11 | ||
| 12 | var argc: usize = undefined; | |
| 13 | var argv: &&u8 = undefined; | |
| 14 | ||
| 15 | export 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 | ||
| 35 | fn 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 | ||
| 44 | fn callMainAndExit() -> noreturn { | |
| 45 | callMain() %% exit(1); | |
| 46 | exit(0); | |
| 47 | } | |
| 48 | ||
| 49 | export 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 | ||
| 8 | export 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 | ||
| 20 | export 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. | |
| 34 | pub 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. | |
| 3 | pub fn panic(message: []const u8) -> noreturn { | |
| 4 | if (@compileVar("is_test")) { | |
| 5 | @import("std").debug.panic(message); | |
| 6 | } else { | |
| 7 | unreachable; | |
| 8 | } | |
| 9 | } | |
| 10 | ||
| 11 | const CHAR_BIT = 8; | |
| 12 | const du_int = u64; | |
| 13 | const di_int = i64; | |
| 14 | const si_int = c_int; | |
| 15 | const su_int = c_uint; | |
| 16 | ||
| 17 | const udwords = [2]su_int; | |
| 18 | const low = if (@compileVar("is_big_endian")) 1 else 0; | |
| 19 | const high = 1 - low; | |
| 20 | ||
| 21 | export fn __udivdi3(a: du_int, b: du_int) -> du_int { | |
| 22 | @setDebugSafety(this, false); | |
| 23 | return __udivmoddi4(a, b, null); | |
| 24 | } | |
| 25 | ||
| 26 | fn du_int_to_udwords(x: du_int) -> udwords { | |
| 27 | @setDebugSafety(this, false); | |
| 28 | return *(&udwords)(&x); | |
| 29 | } | |
| 30 | ||
| 31 | export 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 | ||
| 217 | export 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 | ||
| 225 | fn 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 | ||
| 249 | export 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 | ||
| 268 | export 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 | ||
| 280 | export fn __aeabi_uidiv(n: su_int, d: su_int) -> su_int { | |
| 281 | @setDebugSafety(this, false); | |
| 282 | ||
| 283 | return __udivsi3(n, d); | |
| 284 | } | |
| 285 | ||
| 286 | export 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 | ||
| 325 | test "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 | ||
| 333 | fn 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 | ||
| 338 | test "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 | ||
| 359 | fn 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 | ||
| 366 | test "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 | ||
| 507 | fn 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 | ||
| 513 | fn 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 | ||
| 6 | pub 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 @@ |
| 1 | const io = @import("std").io; | |
| 2 | ||
| 3 | const TestFn = struct { | |
| 4 | name: []u8, | |
| 5 | func: extern fn(), | |
| 6 | }; | |
| 7 | ||
| 8 | extern var zig_test_fn_list: []TestFn; | |
| 9 | ||
| 10 | pub 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 @@ |
| 1 | const mem = @import("mem.zig"); | |
| 2 | ||
| 3 | pub const linking_libc = linkingLibrary("c"); | |
| 4 | ||
| 5 | pub 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 @@ |
| 1 | const io = @import("std").io; | |
| 2 | ||
| 3 | const TestFn = struct { | |
| 4 | name: []u8, | |
| 5 | func: extern fn(), | |
| 6 | }; | |
| 7 | ||
| 8 | extern var zig_test_fn_list: []TestFn; | |
| 9 | ||
| 10 | pub 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 @@ |
| 1 | pub extern fn CryptAcquireContext(phProv: &HCRYPTPROV, pszContainer: LPCTSTR, | |
| 2 | pszProvider: LPCTSTR, dwProvType: DWORD, dwFlags: DWORD) -> bool; | |
| 3 | ||
| 4 | pub extern fn CryptReleaseContext(hProv: HCRYPTPROV, dwFlags: DWORD) -> bool; | |
| 5 | ||
| 6 | pub extern fn CryptGenRandom(hProv: HCRYPTPROV, dwLen: DWORD, pbBuffer: &BYTE) -> bool; | |
| 7 | ||
| 8 | pub const PROV_RSA_FULL = 1; | |
| 9 | ||
| 10 | ||
| 11 | pub const BYTE = u8; | |
| 12 | pub const DWORD = u32; | |
| 13 | // TODO something about unicode WCHAR vs char | |
| 14 | pub const TCHAR = u8; | |
| 15 | pub const LPCTSTR = ?&const TCHAR; | |
| 16 | pub const ULONG_PTR = usize; | |
| 17 | pub const HCRYPTPROV = ULONG_PTR; |
test/cases/import.zig+1-1| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const assert = @import("std").debug.assert; |
| 2 | const a_namespace = @import("cases/import/a_namespace.zig"); | |
| 2 | const a_namespace = @import("import/a_namespace.zig"); | |
| 3 | 3 | |
| 4 | 4 | test "callFnViaNamespaceLookup" { |
| 5 | 5 | assert(a_namespace.foo() == 1234); |
test/cases/namespace_depends_on_compile_var/index.zig+2-2| ... | ... | @@ -8,6 +8,6 @@ test "namespaceDependsOnCompileVar" { |
| 8 | 8 | } |
| 9 | 9 | } |
| 10 | 10 | const 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"), | |
| 13 | 13 | }; |
test/cases/pub_enum/index.zig+1-1| ... | ... | @@ -1,4 +1,4 @@ |
| 1 | const other = @import("cases/pub_enum/other.zig"); | |
| 1 | const other = @import("other.zig"); | |
| 2 | 2 | const assert = @import("std").debug.assert; |
| 3 | 3 | |
| 4 | 4 | test "pubEnum" { |
test/run_tests.cpp+1-2| ... | ... | @@ -1254,8 +1254,7 @@ export fn entry() -> usize { @sizeOf(@typeOf(seventh_fib_number)) } |
| 1254 | 1254 | const resource = @embedFile("bogus.txt"); |
| 1255 | 1255 | |
| 1256 | 1256 | export 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'"); | |
| 1259 | 1258 | |
| 1260 | 1259 | add_compile_fail_case("non-const expression in struct literal outside function", R"SOURCE( |
| 1261 | 1260 | const Foo = struct { |