mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
Merge remote-tracking branch 'origin/master' into llvm13
Conflicts: * cmake/Findclang.cmake * cmake/Findlld.cmake * cmake/Findllvm.cmake In master branch, more search paths were added to these files with "12" in the path. In this commit I updated them to "13". * src/stage1/codegen.cpp * src/zig_llvm.cpp * src/zig_llvm.h In master branch, ZigLLVMBuildCmpXchg is improved to add `is_single_threaded`. However, the LLVM 13 C API has this already, and in the llvm13 branch, ZigLLVMBuildCmpXchg is deleted in favor of the C API. In this commit I updated stage2 to use the LLVM 13 C API rather than depending on an improved ZigLLVMBuildCmpXchg. Additionally, src/target.zig largestAtomicBits needed to be updated to include the new m68k ISA.
This commit is contained in:
commit
f3ebfcae38
@ -363,7 +363,9 @@ set(ZIG_STAGE2_SOURCES
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/crypto/siphash.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/debug.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/dwarf.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/dwarf_bits.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/dwarf/AT.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/dwarf/OP.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/dwarf/TAG.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/elf.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/event.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/event/batch.zig"
|
||||
@ -424,18 +426,13 @@ set(ZIG_STAGE2_SOURCES
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/meta/trait.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/multi_array_list.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/os.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/os/bits.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/errno/generic.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/netlink.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/prctl.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/securebits.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/x86_64.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/os/linux.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/os/linux/errno/generic.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/os/linux/x86_64.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/os/linux.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/os/linux/io_uring.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/os/linux/x86_64.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/os/windows.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/os/windows/bits.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/os/windows/ntstatus.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/os/windows/win32error.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/Progress.zig"
|
||||
@ -447,8 +444,8 @@ set(ZIG_STAGE2_SOURCES
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/addXf3.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/atomics.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/clear_cache.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/clzsi2.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/compareXf2.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/count0bits.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/divdf3.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/divsf3.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/divtf3.zig"
|
||||
@ -532,7 +529,7 @@ set(ZIG_STAGE2_SOURCES
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/time.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/unicode.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/zig.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/zig/ast.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/zig/Ast.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/zig/cross_target.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/zig/parse.zig"
|
||||
"${CMAKE_SOURCE_DIR}/lib/std/zig/render.zig"
|
||||
@ -577,11 +574,11 @@ set(ZIG_STAGE2_SOURCES
|
||||
"${CMAKE_SOURCE_DIR}/src/link/Plan9/aout.zig"
|
||||
"${CMAKE_SOURCE_DIR}/src/link/MachO.zig"
|
||||
"${CMAKE_SOURCE_DIR}/src/link/MachO/Archive.zig"
|
||||
"${CMAKE_SOURCE_DIR}/src/link/MachO/Atom.zig"
|
||||
"${CMAKE_SOURCE_DIR}/src/link/MachO/CodeSignature.zig"
|
||||
"${CMAKE_SOURCE_DIR}/src/link/MachO/DebugSymbols.zig"
|
||||
"${CMAKE_SOURCE_DIR}/src/link/MachO/Dylib.zig"
|
||||
"${CMAKE_SOURCE_DIR}/src/link/MachO/Object.zig"
|
||||
"${CMAKE_SOURCE_DIR}/src/link/MachO/TextBlock.zig"
|
||||
"${CMAKE_SOURCE_DIR}/src/link/MachO/Trie.zig"
|
||||
"${CMAKE_SOURCE_DIR}/src/link/MachO/bind.zig"
|
||||
"${CMAKE_SOURCE_DIR}/src/link/MachO/commands.zig"
|
||||
|
||||
@ -45,6 +45,72 @@
|
||||
"size": "{{AARCH64_LINUX_BYTESIZE}}"
|
||||
}
|
||||
},
|
||||
"0.8.1": {
|
||||
"date": "2021-09-06",
|
||||
"docs": "https://ziglang.org/documentation/0.8.1/",
|
||||
"stdDocs": "https://ziglang.org/documentation/0.8.1/std/",
|
||||
"notes": "https://ziglang.org/download/0.8.1/release-notes.html",
|
||||
"src": {
|
||||
"tarball": "https://ziglang.org/download/0.8.1/zig-0.8.1.tar.xz",
|
||||
"shasum": "8c428e14a0a89cb7a15a6768424a37442292858cdb695e2eb503fa3c7bf47f1a",
|
||||
"size": "12650228"
|
||||
},
|
||||
"bootstrap": {
|
||||
"tarball": "https://ziglang.org/download/0.8.1/zig-bootstrap-0.8.1.tar.xz",
|
||||
"shasum": "fa1239247f830ecd51c42537043f5220e4d1dfefdc54356fa419616a0efb3902",
|
||||
"size": "43613464"
|
||||
},
|
||||
"x86_64-freebsd": {
|
||||
"tarball": "https://ziglang.org/download/0.8.1/zig-freebsd-x86_64-0.8.1.tar.xz",
|
||||
"shasum": "fc4f6478bcf3a9fce1b8ef677a91694f476dd35be6d6c9c4f44a8b76eedbe176",
|
||||
"size": "39150924"
|
||||
},
|
||||
"aarch64-linux": {
|
||||
"tarball": "https://ziglang.org/download/0.8.1/zig-linux-aarch64-0.8.1.tar.xz",
|
||||
"shasum": "2166dc9f2d8df387e8b4122883bb979d739281e1ff3f3d5483fec3a23b957510",
|
||||
"size": "37605932"
|
||||
},
|
||||
"armv7a-linux": {
|
||||
"tarball": "https://ziglang.org/download/0.8.1/zig-linux-armv7a-0.8.1.tar.xz",
|
||||
"shasum": "5ba58141805e2519f38cf8e715933cbf059f4f3dade92c71838cce341045de05",
|
||||
"size": "39185876"
|
||||
},
|
||||
"i386-linux": {
|
||||
"tarball": "https://ziglang.org/download/0.8.1/zig-linux-i386-0.8.1.tar.xz",
|
||||
"shasum": "2f3e84f30492b5f1c5f97cecc0166f07a8a8d50c5f85dbb3a6ef2a4ee6f915e6",
|
||||
"size": "44782932"
|
||||
},
|
||||
"riscv64-linux": {
|
||||
"tarball": "https://ziglang.org/download/0.8.1/zig-linux-riscv64-0.8.1.tar.xz",
|
||||
"shasum": "4adfaf147b025917c03367462fe5018aaa9edbc6439ef9cd0da2b074ae960554",
|
||||
"size": "41234480"
|
||||
},
|
||||
"x86_64-linux": {
|
||||
"tarball": "https://ziglang.org/download/0.8.1/zig-linux-x86_64-0.8.1.tar.xz",
|
||||
"shasum": "6c032fc61b5d77a3f3cf781730fa549f8f059ffdb3b3f6ad1c2994d2b2d87983",
|
||||
"size": "41250060"
|
||||
},
|
||||
"aarch64-macos": {
|
||||
"tarball": "https://ziglang.org/download/0.8.1/zig-macos-aarch64-0.8.1.tar.xz",
|
||||
"shasum": "5351297e3b8408213514b29c0a938002c5cf9f97eee28c2f32920e1227fd8423",
|
||||
"size": "35340712"
|
||||
},
|
||||
"x86_64-macos": {
|
||||
"tarball": "https://ziglang.org/download/0.8.1/zig-macos-x86_64-0.8.1.tar.xz",
|
||||
"shasum": "16b0e1defe4c1807f2e128f72863124bffdd906cefb21043c34b673bf85cd57f",
|
||||
"size": "39946200"
|
||||
},
|
||||
"i386-windows": {
|
||||
"tarball": "https://ziglang.org/download/0.8.1/zig-windows-i386-0.8.1.zip",
|
||||
"shasum": "099605051eb0452a947c8eab8fbbc7e43833c8376d267e94e41131c289a1c535",
|
||||
"size": "64152358"
|
||||
},
|
||||
"x86_64-windows": {
|
||||
"tarball": "https://ziglang.org/download/0.8.1/zig-windows-x86_64-0.8.1.zip",
|
||||
"shasum": "43573db14cd238f7111d6bdf37492d363f11ecd1eba802567a172f277d003926",
|
||||
"size": "61897838"
|
||||
}
|
||||
},
|
||||
"0.8.0": {
|
||||
"date": "2021-06-04",
|
||||
"docs": "https://ziglang.org/documentation/0.8.0/",
|
||||
|
||||
@ -14,6 +14,8 @@ find_path(CLANG_INCLUDE_DIRS NAMES clang/Frontend/ASTUnit.h
|
||||
/usr/lib/llvm-13.0/include
|
||||
/usr/local/llvm130/include
|
||||
/usr/local/llvm13/include
|
||||
/usr/local/opt/llvm@13/include
|
||||
/opt/homebrew/opt/llvm@13/include
|
||||
/mingw64/include
|
||||
)
|
||||
|
||||
@ -30,6 +32,8 @@ if(ZIG_PREFER_CLANG_CPP_DYLIB)
|
||||
/usr/lib/llvm-13/lib
|
||||
/usr/local/llvm130/lib
|
||||
/usr/local/llvm13/lib
|
||||
/usr/local/opt/llvm@13/lib
|
||||
/opt/homebrew/opt/llvm@13/lib
|
||||
)
|
||||
endif()
|
||||
|
||||
@ -44,6 +48,8 @@ if(NOT CLANG_LIBRARIES)
|
||||
/usr/lib/llvm-13.0/lib
|
||||
/usr/local/llvm130/lib
|
||||
/usr/local/llvm13/lib
|
||||
/usr/local/opt/llvm@13/lib
|
||||
/opt/homebrew/opt/llvm@13/lib
|
||||
/mingw64/lib
|
||||
/c/msys64/mingw64/lib
|
||||
c:\\msys64\\mingw64\\lib
|
||||
|
||||
@ -11,6 +11,8 @@ find_path(LLD_INCLUDE_DIRS NAMES lld/Common/Driver.h
|
||||
/usr/lib/llvm-13/include
|
||||
/usr/local/llvm130/include
|
||||
/usr/local/llvm13/include
|
||||
/usr/local/opt/llvm@13/include
|
||||
/opt/homebrew/opt/llvm@13/include
|
||||
/mingw64/include)
|
||||
|
||||
find_library(LLD_LIBRARY NAMES lld-13.0 lld130 lld
|
||||
@ -18,6 +20,8 @@ find_library(LLD_LIBRARY NAMES lld-13.0 lld130 lld
|
||||
/usr/lib/llvm-13/lib
|
||||
/usr/local/llvm130/lib
|
||||
/usr/local/llvm13/lib
|
||||
/usr/local/opt/llvm@13/lib
|
||||
/opt/homebrew/opt/llvm@13/lib
|
||||
)
|
||||
if(EXISTS ${LLD_LIBRARY})
|
||||
set(LLD_LIBRARIES ${LLD_LIBRARY})
|
||||
@ -30,6 +34,8 @@ else()
|
||||
/usr/lib/llvm-13/lib
|
||||
/usr/local/llvm130/lib
|
||||
/usr/local/llvm13/lib
|
||||
/usr/local/opt/llvm@13/lib
|
||||
/opt/homebrew/opt/llvm@13/lib
|
||||
/mingw64/lib
|
||||
/c/msys64/mingw64/lib
|
||||
c:/msys64/mingw64/lib)
|
||||
|
||||
@ -14,6 +14,8 @@ find_path(LLVM_INCLUDE_DIRS NAMES llvm/IR/IRBuilder.h
|
||||
/usr/lib/llvm-13.0/include
|
||||
/usr/local/llvm13/include
|
||||
/usr/local/llvm130/include
|
||||
/usr/local/opt/llvm@13/include
|
||||
/opt/homebrew/opt/llvm@13/include
|
||||
/mingw64/include
|
||||
)
|
||||
|
||||
@ -31,6 +33,8 @@ if(ZIG_PREFER_CLANG_CPP_DYLIB)
|
||||
/usr/lib/llvm-13/lib
|
||||
/usr/local/llvm13/lib
|
||||
/usr/local/llvm130/lib
|
||||
/usr/local/opt/llvm@13/lib
|
||||
/opt/homebrew/opt/llvm@13/lib
|
||||
)
|
||||
|
||||
find_program(LLVM_CONFIG_EXE
|
||||
@ -185,6 +189,8 @@ else()
|
||||
/usr/lib/llvm-13.0/lib
|
||||
/usr/local/llvm130/lib
|
||||
/usr/local/llvm13/lib
|
||||
/usr/local/opt/llvm@13/lib
|
||||
/opt/homebrew/opt/llvm@13/lib
|
||||
/mingw64/lib
|
||||
/c/msys64/mingw64/lib
|
||||
c:\\msys64\\mingw64\\lib)
|
||||
|
||||
456
doc/docgen.zig
456
doc/docgen.zig
@ -280,7 +280,7 @@ const Code = struct {
|
||||
id: Id,
|
||||
name: []const u8,
|
||||
source_token: Token,
|
||||
is_inline: bool,
|
||||
just_check_syntax: bool,
|
||||
mode: std.builtin.Mode,
|
||||
link_objects: []const []const u8,
|
||||
target_str: ?[]const u8,
|
||||
@ -305,6 +305,18 @@ const Link = struct {
|
||||
token: Token,
|
||||
};
|
||||
|
||||
const SyntaxBlock = struct {
|
||||
source_type: SourceType,
|
||||
name: []const u8,
|
||||
source_token: Token,
|
||||
|
||||
const SourceType = enum {
|
||||
zig,
|
||||
c,
|
||||
javascript,
|
||||
};
|
||||
};
|
||||
|
||||
const Node = union(enum) {
|
||||
Content: []const u8,
|
||||
Nav,
|
||||
@ -313,7 +325,9 @@ const Node = union(enum) {
|
||||
SeeAlso: []const SeeAlsoItem,
|
||||
Code: Code,
|
||||
Link: Link,
|
||||
Syntax: Token,
|
||||
InlineSyntax: Token,
|
||||
Shell: Token,
|
||||
SyntaxBlock: SyntaxBlock,
|
||||
};
|
||||
|
||||
const Toc = struct {
|
||||
@ -403,7 +417,7 @@ fn genToc(allocator: *Allocator, tokenizer: *Tokenizer) !Toc {
|
||||
.HeaderOpen = HeaderOpen{
|
||||
.name = content,
|
||||
.url = urlized,
|
||||
.n = header_stack_size,
|
||||
.n = header_stack_size + 1, // highest-level section headers start at h2
|
||||
},
|
||||
});
|
||||
if (try urls.fetchPut(urlized, tag_token)) |kv| {
|
||||
@ -502,7 +516,7 @@ fn genToc(allocator: *Allocator, tokenizer: *Tokenizer) !Toc {
|
||||
}
|
||||
const code_kind_str = tokenizer.buffer[code_kind_tok.start..code_kind_tok.end];
|
||||
var code_kind_id: Code.Id = undefined;
|
||||
var is_inline = false;
|
||||
var just_check_syntax = false;
|
||||
if (mem.eql(u8, code_kind_str, "exe")) {
|
||||
code_kind_id = Code.Id{ .Exe = ExpectedOutcome.Succeed };
|
||||
} else if (mem.eql(u8, code_kind_str, "exe_err")) {
|
||||
@ -526,7 +540,7 @@ fn genToc(allocator: *Allocator, tokenizer: *Tokenizer) !Toc {
|
||||
code_kind_id = Code.Id.Lib;
|
||||
} else if (mem.eql(u8, code_kind_str, "syntax")) {
|
||||
code_kind_id = Code.Id{ .Obj = null };
|
||||
is_inline = true;
|
||||
just_check_syntax = true;
|
||||
} else {
|
||||
return parseError(tokenizer, code_kind_tok, "unrecognized code kind: {s}", .{code_kind_str});
|
||||
}
|
||||
@ -589,7 +603,7 @@ fn genToc(allocator: *Allocator, tokenizer: *Tokenizer) !Toc {
|
||||
.id = code_kind_id,
|
||||
.name = name,
|
||||
.source_token = source_token,
|
||||
.is_inline = is_inline,
|
||||
.just_check_syntax = just_check_syntax,
|
||||
.mode = mode,
|
||||
.link_objects = link_objects.toOwnedSlice(),
|
||||
.target_str = target_str,
|
||||
@ -615,7 +629,67 @@ fn genToc(allocator: *Allocator, tokenizer: *Tokenizer) !Toc {
|
||||
);
|
||||
}
|
||||
_ = try eatToken(tokenizer, Token.Id.BracketClose);
|
||||
try nodes.append(Node{ .Syntax = content_tok });
|
||||
try nodes.append(Node{ .InlineSyntax = content_tok });
|
||||
} else if (mem.eql(u8, tag_name, "shell_samp")) {
|
||||
_ = try eatToken(tokenizer, Token.Id.BracketClose);
|
||||
const content_tok = try eatToken(tokenizer, Token.Id.Content);
|
||||
_ = try eatToken(tokenizer, Token.Id.BracketOpen);
|
||||
const end_syntax_tag = try eatToken(tokenizer, Token.Id.TagContent);
|
||||
const end_tag_name = tokenizer.buffer[end_syntax_tag.start..end_syntax_tag.end];
|
||||
if (!mem.eql(u8, end_tag_name, "end_shell_samp")) {
|
||||
return parseError(
|
||||
tokenizer,
|
||||
end_syntax_tag,
|
||||
"invalid token inside syntax: {s}",
|
||||
.{end_tag_name},
|
||||
);
|
||||
}
|
||||
_ = try eatToken(tokenizer, Token.Id.BracketClose);
|
||||
try nodes.append(Node{ .Shell = content_tok });
|
||||
} else if (mem.eql(u8, tag_name, "syntax_block")) {
|
||||
_ = try eatToken(tokenizer, Token.Id.Separator);
|
||||
const source_type_tok = try eatToken(tokenizer, Token.Id.TagContent);
|
||||
var name: []const u8 = "sample_code";
|
||||
const maybe_sep = tokenizer.next();
|
||||
switch (maybe_sep.id) {
|
||||
Token.Id.Separator => {
|
||||
const name_tok = try eatToken(tokenizer, Token.Id.TagContent);
|
||||
name = tokenizer.buffer[name_tok.start..name_tok.end];
|
||||
_ = try eatToken(tokenizer, Token.Id.BracketClose);
|
||||
},
|
||||
Token.Id.BracketClose => {},
|
||||
else => return parseError(tokenizer, token, "invalid token", .{}),
|
||||
}
|
||||
const source_type_str = tokenizer.buffer[source_type_tok.start..source_type_tok.end];
|
||||
var source_type: SyntaxBlock.SourceType = undefined;
|
||||
if (mem.eql(u8, source_type_str, "zig")) {
|
||||
source_type = SyntaxBlock.SourceType.zig;
|
||||
} else if (mem.eql(u8, source_type_str, "c")) {
|
||||
source_type = SyntaxBlock.SourceType.c;
|
||||
} else if (mem.eql(u8, source_type_str, "javascript")) {
|
||||
source_type = SyntaxBlock.SourceType.javascript;
|
||||
} else {
|
||||
return parseError(tokenizer, source_type_tok, "unrecognized code kind: {s}", .{source_type_str});
|
||||
}
|
||||
const source_token = while (true) {
|
||||
const content_tok = try eatToken(tokenizer, Token.Id.Content);
|
||||
_ = try eatToken(tokenizer, Token.Id.BracketOpen);
|
||||
const end_code_tag = try eatToken(tokenizer, Token.Id.TagContent);
|
||||
const end_tag_name = tokenizer.buffer[end_code_tag.start..end_code_tag.end];
|
||||
if (mem.eql(u8, end_tag_name, "end_syntax_block")) {
|
||||
_ = try eatToken(tokenizer, Token.Id.BracketClose);
|
||||
break content_tok;
|
||||
} else {
|
||||
return parseError(
|
||||
tokenizer,
|
||||
end_code_tag,
|
||||
"invalid token inside code_begin: {s}",
|
||||
.{end_tag_name},
|
||||
);
|
||||
}
|
||||
_ = try eatToken(tokenizer, Token.Id.BracketClose);
|
||||
} else unreachable; // TODO issue #707
|
||||
try nodes.append(Node{ .SyntaxBlock = SyntaxBlock{ .source_type = source_type, .name = name, .source_token = source_token } });
|
||||
} else {
|
||||
return parseError(tokenizer, tag_token, "unrecognized tag name: {s}", .{tag_name});
|
||||
}
|
||||
@ -693,7 +767,7 @@ test "term color" {
|
||||
const input_bytes = "A\x1b[32;1mgreen\x1b[0mB";
|
||||
const result = try termColor(std.testing.allocator, input_bytes);
|
||||
defer std.testing.allocator.free(result);
|
||||
testing.expectEqualSlices(u8, "A<span class=\"t32\">green</span>B", result);
|
||||
try testing.expectEqualSlices(u8, "A<span class=\"t32_1\">green</span>B", result);
|
||||
}
|
||||
|
||||
fn termColor(allocator: *Allocator, input: []const u8) ![]u8 {
|
||||
@ -799,7 +873,7 @@ fn tokenizeAndPrintRaw(
|
||||
) !void {
|
||||
const src_non_terminated = mem.trim(u8, raw_src, " \n");
|
||||
const src = try allocator.dupeZ(u8, src_non_terminated);
|
||||
try out.writeAll("<code class=\"zig\">");
|
||||
try out.writeAll("<code>");
|
||||
var tokenizer = std.zig.Tokenizer.init(src);
|
||||
var index: usize = 0;
|
||||
var next_tok_is_fn = false;
|
||||
@ -1033,6 +1107,47 @@ fn tokenizeAndPrint(
|
||||
return tokenizeAndPrintRaw(allocator, docgen_tokenizer, out, source_token, raw_src);
|
||||
}
|
||||
|
||||
fn printSourceBlock(allocator: *Allocator, docgen_tokenizer: *Tokenizer, out: anytype, syntax_block: SyntaxBlock) !void {
|
||||
const source_type = @tagName(syntax_block.source_type);
|
||||
|
||||
try out.print("<figure><figcaption class=\"{s}-cap\"><cite class=\"file\">{s}</cite></figcaption><pre>", .{ source_type, syntax_block.name });
|
||||
switch (syntax_block.source_type) {
|
||||
.zig => try tokenizeAndPrint(allocator, docgen_tokenizer, out, syntax_block.source_token),
|
||||
else => {
|
||||
const raw_source = docgen_tokenizer.buffer[syntax_block.source_token.start..syntax_block.source_token.end];
|
||||
const trimmed_raw_source = mem.trim(u8, raw_source, " \n");
|
||||
|
||||
try out.writeAll("<code>");
|
||||
try writeEscaped(out, trimmed_raw_source);
|
||||
try out.writeAll("</code>");
|
||||
},
|
||||
}
|
||||
try out.writeAll("</pre></figure>");
|
||||
}
|
||||
|
||||
fn printShell(out: anytype, shell_content: []const u8) !void {
|
||||
const trimmed_shell_content = mem.trim(u8, shell_content, " \n");
|
||||
try out.writeAll("<figure><figcaption class=\"shell-cap\">Shell</figcaption><pre><samp>");
|
||||
var cmd_cont: bool = false;
|
||||
var iter = std.mem.split(u8, trimmed_shell_content, "\n");
|
||||
while (iter.next()) |orig_line| {
|
||||
const line = mem.trimRight(u8, orig_line, " ");
|
||||
if (!cmd_cont and line.len > 1 and mem.eql(u8, line[0..2], "$ ") and line[line.len - 1] != '\\') {
|
||||
try out.print("$ <kbd>{s}</kbd>\n", .{std.mem.trimLeft(u8, line[1..], " ")});
|
||||
} else if (!cmd_cont and line.len > 1 and mem.eql(u8, line[0..2], "$ ") and line[line.len - 1] == '\\') {
|
||||
try out.print("$ <kbd>{s}\n", .{std.mem.trimLeft(u8, line[1..], " ")});
|
||||
cmd_cont = true;
|
||||
} else if (line.len > 0 and line[line.len - 1] != '\\' and cmd_cont) {
|
||||
try out.print("{s}</kbd>\n", .{line});
|
||||
cmd_cont = false;
|
||||
} else {
|
||||
try out.print("{s}\n", .{line});
|
||||
}
|
||||
}
|
||||
|
||||
try out.writeAll("</samp></pre></figure>");
|
||||
}
|
||||
|
||||
fn genHtml(
|
||||
allocator: *Allocator,
|
||||
tokenizer: *Tokenizer,
|
||||
@ -1066,9 +1181,9 @@ fn genHtml(
|
||||
try out.writeAll(toc.toc);
|
||||
},
|
||||
.Builtin => |tok| {
|
||||
try out.writeAll("<pre>");
|
||||
try out.writeAll("<figure><figcaption class=\"zig-cap\"><cite>@import(\"builtin\")</cite></figcaption><pre>");
|
||||
try tokenizeAndPrintRaw(allocator, tokenizer, out, tok, builtin_code);
|
||||
try out.writeAll("</pre>");
|
||||
try out.writeAll("</pre></figure>");
|
||||
},
|
||||
.HeaderOpen => |info| {
|
||||
try out.print(
|
||||
@ -1087,30 +1202,44 @@ fn genHtml(
|
||||
}
|
||||
try out.writeAll("</ul>\n");
|
||||
},
|
||||
.Syntax => |content_tok| {
|
||||
.InlineSyntax => |content_tok| {
|
||||
try tokenizeAndPrint(allocator, tokenizer, out, content_tok);
|
||||
},
|
||||
.Shell => |content_tok| {
|
||||
const raw_shell_content = tokenizer.buffer[content_tok.start..content_tok.end];
|
||||
try printShell(out, raw_shell_content);
|
||||
},
|
||||
.SyntaxBlock => |syntax_block| {
|
||||
try printSourceBlock(allocator, tokenizer, out, syntax_block);
|
||||
},
|
||||
.Code => |code| {
|
||||
const raw_source = tokenizer.buffer[code.source_token.start..code.source_token.end];
|
||||
const trimmed_raw_source = mem.trim(u8, raw_source, " \n");
|
||||
if (!code.is_inline) {
|
||||
try out.print("<p class=\"file\">{s}.zig</p>", .{code.name});
|
||||
}
|
||||
try out.writeAll("<pre>");
|
||||
try tokenizeAndPrint(allocator, tokenizer, out, code.source_token);
|
||||
try out.writeAll("</pre>");
|
||||
const name_plus_ext = try std.fmt.allocPrint(allocator, "{s}.zig", .{code.name});
|
||||
const syntax_block = SyntaxBlock{
|
||||
.source_type = .zig,
|
||||
.name = name_plus_ext,
|
||||
.source_token = code.source_token,
|
||||
};
|
||||
|
||||
if (!do_code_tests) {
|
||||
try printSourceBlock(allocator, tokenizer, out, syntax_block);
|
||||
|
||||
// TODO: remove code.just_check_syntax after updating code samples
|
||||
// that have stopped working due to a change in the compiler.
|
||||
if (!do_code_tests or code.just_check_syntax) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const name_plus_ext = try std.fmt.allocPrint(allocator, "{s}.zig", .{code.name});
|
||||
const raw_source = tokenizer.buffer[code.source_token.start..code.source_token.end];
|
||||
const trimmed_raw_source = mem.trim(u8, raw_source, " \n");
|
||||
const tmp_source_file_name = try fs.path.join(
|
||||
allocator,
|
||||
&[_][]const u8{ tmp_dir_name, name_plus_ext },
|
||||
);
|
||||
try fs.cwd().writeFile(tmp_source_file_name, trimmed_raw_source);
|
||||
|
||||
var shell_buffer = std.ArrayList(u8).init(allocator);
|
||||
defer shell_buffer.deinit();
|
||||
var shell_out = shell_buffer.writer();
|
||||
|
||||
switch (code.id) {
|
||||
Code.Id.Exe => |expected_outcome| code_block: {
|
||||
var build_args = std.ArrayList([]const u8).init(allocator);
|
||||
@ -1121,12 +1250,14 @@ fn genHtml(
|
||||
"--color", "on",
|
||||
"--enable-cache", tmp_source_file_name,
|
||||
});
|
||||
try out.print("<pre><code class=\"shell\">$ zig build-exe {s}.zig", .{code.name});
|
||||
|
||||
try shell_out.print("$ zig build-exe {s} ", .{name_plus_ext});
|
||||
|
||||
switch (code.mode) {
|
||||
.Debug => {},
|
||||
else => {
|
||||
try build_args.appendSlice(&[_][]const u8{ "-O", @tagName(code.mode) });
|
||||
try out.print(" -O {s}", .{@tagName(code.mode)});
|
||||
try shell_out.print("-O {s} ", .{@tagName(code.mode)});
|
||||
},
|
||||
}
|
||||
for (code.link_objects) |link_object| {
|
||||
@ -1136,25 +1267,26 @@ fn genHtml(
|
||||
&[_][]const u8{ tmp_dir_name, name_with_ext },
|
||||
);
|
||||
try build_args.append(full_path_object);
|
||||
try out.print(" {s}", .{name_with_ext});
|
||||
try shell_out.print("{s} ", .{name_with_ext});
|
||||
}
|
||||
if (code.link_libc) {
|
||||
try build_args.append("-lc");
|
||||
try out.print(" -lc", .{});
|
||||
try shell_out.print("-lc ", .{});
|
||||
}
|
||||
const target = try std.zig.CrossTarget.parse(.{
|
||||
.arch_os_abi = code.target_str orelse "native",
|
||||
});
|
||||
if (code.target_str) |triple| {
|
||||
try build_args.appendSlice(&[_][]const u8{ "-target", triple });
|
||||
if (!code.is_inline) {
|
||||
try out.print(" -target {s}", .{triple});
|
||||
}
|
||||
try shell_out.print("-target {s} ", .{triple});
|
||||
}
|
||||
if (code.verbose_cimport) {
|
||||
try build_args.append("--verbose-cimport");
|
||||
try out.print(" --verbose-cimport", .{});
|
||||
try shell_out.print("--verbose-cimport ", .{});
|
||||
}
|
||||
|
||||
try shell_out.print("\n", .{});
|
||||
|
||||
if (expected_outcome == .BuildFail) {
|
||||
const result = try ChildProcess.exec(.{
|
||||
.allocator = allocator,
|
||||
@ -1180,12 +1312,17 @@ fn genHtml(
|
||||
}
|
||||
const escaped_stderr = try escapeHtml(allocator, result.stderr);
|
||||
const colored_stderr = try termColor(allocator, escaped_stderr);
|
||||
try out.print("\n{s}</code></pre>\n", .{colored_stderr});
|
||||
try shell_out.writeAll(colored_stderr);
|
||||
break :code_block;
|
||||
}
|
||||
const exec_result = exec(allocator, &env_map, build_args.items) catch
|
||||
return parseError(tokenizer, code.source_token, "example failed to compile", .{});
|
||||
|
||||
if (code.verbose_cimport) {
|
||||
const escaped_build_stderr = try escapeHtml(allocator, exec_result.stderr);
|
||||
try shell_out.writeAll(escaped_build_stderr);
|
||||
}
|
||||
|
||||
if (code.target_str) |triple| {
|
||||
if (mem.startsWith(u8, triple, "wasm32") or
|
||||
mem.startsWith(u8, triple, "riscv64-linux") or
|
||||
@ -1193,7 +1330,6 @@ fn genHtml(
|
||||
std.Target.current.os.tag != .linux or std.Target.current.cpu.arch != .x86_64))
|
||||
{
|
||||
// skip execution
|
||||
try out.print("</code></pre>\n", .{});
|
||||
break :code_block;
|
||||
}
|
||||
}
|
||||
@ -1241,41 +1377,38 @@ fn genHtml(
|
||||
const colored_stderr = try termColor(allocator, escaped_stderr);
|
||||
const colored_stdout = try termColor(allocator, escaped_stdout);
|
||||
|
||||
if (code.verbose_cimport) {
|
||||
const escaped_build_stderr = try escapeHtml(allocator, exec_result.stderr);
|
||||
try out.print("\n{s}", .{escaped_build_stderr});
|
||||
}
|
||||
try out.print("\n$ ./{s}\n{s}{s}", .{ code.name, colored_stdout, colored_stderr });
|
||||
try shell_out.print("\n$ ./{s}\n{s}{s}", .{ code.name, colored_stdout, colored_stderr });
|
||||
if (exited_with_signal) {
|
||||
try out.print("(process terminated by signal)", .{});
|
||||
try shell_out.print("(process terminated by signal)", .{});
|
||||
}
|
||||
try out.print("</code></pre>\n", .{});
|
||||
try shell_out.writeAll("\n");
|
||||
},
|
||||
Code.Id.Test => {
|
||||
var test_args = std.ArrayList([]const u8).init(allocator);
|
||||
defer test_args.deinit();
|
||||
|
||||
try test_args.appendSlice(&[_][]const u8{ zig_exe, "test", tmp_source_file_name });
|
||||
try out.print("<pre><code class=\"shell\">$ zig test {s}.zig", .{code.name});
|
||||
try shell_out.print("$ zig test {s}.zig ", .{code.name});
|
||||
|
||||
switch (code.mode) {
|
||||
.Debug => {},
|
||||
else => {
|
||||
try test_args.appendSlice(&[_][]const u8{ "-O", @tagName(code.mode) });
|
||||
try out.print(" -O {s}", .{@tagName(code.mode)});
|
||||
try shell_out.print("-O {s} ", .{@tagName(code.mode)});
|
||||
},
|
||||
}
|
||||
if (code.link_libc) {
|
||||
try test_args.append("-lc");
|
||||
try out.print(" -lc", .{});
|
||||
try shell_out.print("-lc ", .{});
|
||||
}
|
||||
if (code.target_str) |triple| {
|
||||
try test_args.appendSlice(&[_][]const u8{ "-target", triple });
|
||||
try out.print(" -target {s}", .{triple});
|
||||
try shell_out.print("-target {s} ", .{triple});
|
||||
}
|
||||
const result = exec(allocator, &env_map, test_args.items) catch return parseError(tokenizer, code.source_token, "test failed", .{});
|
||||
const escaped_stderr = try escapeHtml(allocator, result.stderr);
|
||||
const escaped_stdout = try escapeHtml(allocator, result.stdout);
|
||||
try out.print("\n{s}{s}</code></pre>\n", .{ escaped_stderr, escaped_stdout });
|
||||
try shell_out.print("\n{s}{s}\n", .{ escaped_stderr, escaped_stdout });
|
||||
},
|
||||
Code.Id.TestError => |error_match| {
|
||||
var test_args = std.ArrayList([]const u8).init(allocator);
|
||||
@ -1288,12 +1421,13 @@ fn genHtml(
|
||||
"on",
|
||||
tmp_source_file_name,
|
||||
});
|
||||
try out.print("<pre><code class=\"shell\">$ zig test {s}.zig", .{code.name});
|
||||
try shell_out.print("$ zig test {s}.zig ", .{code.name});
|
||||
|
||||
switch (code.mode) {
|
||||
.Debug => {},
|
||||
else => {
|
||||
try test_args.appendSlice(&[_][]const u8{ "-O", @tagName(code.mode) });
|
||||
try out.print(" -O {s}", .{@tagName(code.mode)});
|
||||
try shell_out.print("-O {s} ", .{@tagName(code.mode)});
|
||||
},
|
||||
}
|
||||
const result = try ChildProcess.exec(.{
|
||||
@ -1325,7 +1459,7 @@ fn genHtml(
|
||||
}
|
||||
const escaped_stderr = try escapeHtml(allocator, result.stderr);
|
||||
const colored_stderr = try termColor(allocator, escaped_stderr);
|
||||
try out.print("\n{s}</code></pre>\n", .{colored_stderr});
|
||||
try shell_out.print("\n{s}\n", .{colored_stderr});
|
||||
},
|
||||
|
||||
Code.Id.TestSafety => |error_match| {
|
||||
@ -1383,7 +1517,7 @@ fn genHtml(
|
||||
}
|
||||
const escaped_stderr = try escapeHtml(allocator, result.stderr);
|
||||
const colored_stderr = try termColor(allocator, escaped_stderr);
|
||||
try out.print("<pre><code class=\"shell\">$ zig test {s}.zig {s}\n{s}</code></pre>\n", .{
|
||||
try shell_out.print("$ zig test {s}.zig {s}\n{s}\n", .{
|
||||
code.name,
|
||||
mode_arg,
|
||||
colored_stderr,
|
||||
@ -1406,23 +1540,20 @@ fn genHtml(
|
||||
tmp_dir_name, fs.path.sep, name_plus_obj_ext,
|
||||
}),
|
||||
});
|
||||
if (!code.is_inline) {
|
||||
try out.print("<pre><code class=\"shell\">$ zig build-obj {s}.zig", .{code.name});
|
||||
}
|
||||
|
||||
try shell_out.print("$ zig build-obj {s}.zig ", .{code.name});
|
||||
|
||||
switch (code.mode) {
|
||||
.Debug => {},
|
||||
else => {
|
||||
try build_args.appendSlice(&[_][]const u8{ "-O", @tagName(code.mode) });
|
||||
if (!code.is_inline) {
|
||||
try out.print(" -O {s}", .{@tagName(code.mode)});
|
||||
}
|
||||
try shell_out.print("-O {s} ", .{@tagName(code.mode)});
|
||||
},
|
||||
}
|
||||
|
||||
if (code.target_str) |triple| {
|
||||
try build_args.appendSlice(&[_][]const u8{ "-target", triple });
|
||||
try out.print(" -target {s}", .{triple});
|
||||
try shell_out.print("-target {s} ", .{triple});
|
||||
}
|
||||
|
||||
if (maybe_error_match) |error_match| {
|
||||
@ -1455,13 +1586,11 @@ fn genHtml(
|
||||
}
|
||||
const escaped_stderr = try escapeHtml(allocator, result.stderr);
|
||||
const colored_stderr = try termColor(allocator, escaped_stderr);
|
||||
try out.print("\n{s}", .{colored_stderr});
|
||||
try shell_out.print("\n{s} ", .{colored_stderr});
|
||||
} else {
|
||||
_ = exec(allocator, &env_map, build_args.items) catch return parseError(tokenizer, code.source_token, "example failed to compile", .{});
|
||||
}
|
||||
if (!code.is_inline) {
|
||||
try out.print("</code></pre>\n", .{});
|
||||
}
|
||||
try shell_out.writeAll("\n");
|
||||
},
|
||||
Code.Id.Lib => {
|
||||
const bin_basename = try std.zig.binNameAlloc(allocator, .{
|
||||
@ -1481,36 +1610,41 @@ fn genHtml(
|
||||
tmp_dir_name, fs.path.sep_str, bin_basename,
|
||||
}),
|
||||
});
|
||||
try out.print("<pre><code class=\"shell\">$ zig build-lib {s}.zig", .{code.name});
|
||||
try shell_out.print("$ zig build-lib {s}.zig ", .{code.name});
|
||||
|
||||
switch (code.mode) {
|
||||
.Debug => {},
|
||||
else => {
|
||||
try test_args.appendSlice(&[_][]const u8{ "-O", @tagName(code.mode) });
|
||||
try out.print(" -O {s}", .{@tagName(code.mode)});
|
||||
try shell_out.print("-O {s} ", .{@tagName(code.mode)});
|
||||
},
|
||||
}
|
||||
if (code.target_str) |triple| {
|
||||
try test_args.appendSlice(&[_][]const u8{ "-target", triple });
|
||||
try out.print(" -target {s}", .{triple});
|
||||
try shell_out.print("-target {s} ", .{triple});
|
||||
}
|
||||
if (code.link_mode) |link_mode| {
|
||||
switch (link_mode) {
|
||||
.Static => {
|
||||
try test_args.append("-static");
|
||||
try out.print(" -static", .{});
|
||||
try shell_out.print("-static ", .{});
|
||||
},
|
||||
.Dynamic => {
|
||||
try test_args.append("-dynamic");
|
||||
try out.print(" -dynamic", .{});
|
||||
try shell_out.print("-dynamic ", .{});
|
||||
},
|
||||
}
|
||||
}
|
||||
const result = exec(allocator, &env_map, test_args.items) catch return parseError(tokenizer, code.source_token, "test failed", .{});
|
||||
const escaped_stderr = try escapeHtml(allocator, result.stderr);
|
||||
const escaped_stdout = try escapeHtml(allocator, result.stdout);
|
||||
try out.print("\n{s}{s}</code></pre>\n", .{ escaped_stderr, escaped_stdout });
|
||||
try shell_out.print("\n{s}{s}\n", .{ escaped_stderr, escaped_stdout });
|
||||
},
|
||||
}
|
||||
|
||||
if (!code.just_check_syntax) {
|
||||
try printShell(out, shell_buffer.items);
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -1551,3 +1685,195 @@ fn dumpArgs(args: []const []const u8) void {
|
||||
else
|
||||
print("\n", .{});
|
||||
}
|
||||
|
||||
test "shell parsed" {
|
||||
const test_allocator = std.testing.allocator;
|
||||
|
||||
{
|
||||
const shell_out =
|
||||
\\$ zig build test.zig
|
||||
;
|
||||
const expected =
|
||||
\\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp>$ <kbd>zig build test.zig</kbd>
|
||||
\\</samp></pre></figure>
|
||||
;
|
||||
|
||||
var buffer = std.ArrayList(u8).init(test_allocator);
|
||||
defer buffer.deinit();
|
||||
|
||||
try printShell(buffer.writer(), shell_out);
|
||||
try testing.expectEqualSlices(u8, expected, buffer.items);
|
||||
}
|
||||
{
|
||||
const shell_out =
|
||||
\\$ zig build test.zig
|
||||
\\build output
|
||||
;
|
||||
const expected =
|
||||
\\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp>$ <kbd>zig build test.zig</kbd>
|
||||
\\build output
|
||||
\\</samp></pre></figure>
|
||||
;
|
||||
|
||||
var buffer = std.ArrayList(u8).init(test_allocator);
|
||||
defer buffer.deinit();
|
||||
|
||||
try printShell(buffer.writer(), shell_out);
|
||||
try testing.expectEqualSlices(u8, expected, buffer.items);
|
||||
}
|
||||
{
|
||||
const shell_out =
|
||||
\\$ zig build test.zig
|
||||
\\build output
|
||||
\\$ ./test
|
||||
;
|
||||
const expected =
|
||||
\\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp>$ <kbd>zig build test.zig</kbd>
|
||||
\\build output
|
||||
\\$ <kbd>./test</kbd>
|
||||
\\</samp></pre></figure>
|
||||
;
|
||||
|
||||
var buffer = std.ArrayList(u8).init(test_allocator);
|
||||
defer buffer.deinit();
|
||||
|
||||
try printShell(buffer.writer(), shell_out);
|
||||
try testing.expectEqualSlices(u8, expected, buffer.items);
|
||||
}
|
||||
{
|
||||
const shell_out =
|
||||
\\$ zig build test.zig
|
||||
\\
|
||||
\\$ ./test
|
||||
\\output
|
||||
;
|
||||
const expected =
|
||||
\\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp>$ <kbd>zig build test.zig</kbd>
|
||||
\\
|
||||
\\$ <kbd>./test</kbd>
|
||||
\\output
|
||||
\\</samp></pre></figure>
|
||||
;
|
||||
|
||||
var buffer = std.ArrayList(u8).init(test_allocator);
|
||||
defer buffer.deinit();
|
||||
|
||||
try printShell(buffer.writer(), shell_out);
|
||||
try testing.expectEqualSlices(u8, expected, buffer.items);
|
||||
}
|
||||
{
|
||||
const shell_out =
|
||||
\\$ zig build test.zig
|
||||
\\$ ./test
|
||||
\\output
|
||||
;
|
||||
const expected =
|
||||
\\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp>$ <kbd>zig build test.zig</kbd>
|
||||
\\$ <kbd>./test</kbd>
|
||||
\\output
|
||||
\\</samp></pre></figure>
|
||||
;
|
||||
|
||||
var buffer = std.ArrayList(u8).init(test_allocator);
|
||||
defer buffer.deinit();
|
||||
|
||||
try printShell(buffer.writer(), shell_out);
|
||||
try testing.expectEqualSlices(u8, expected, buffer.items);
|
||||
}
|
||||
{
|
||||
const shell_out =
|
||||
\\$ zig build test.zig \
|
||||
\\ --build-option
|
||||
\\build output
|
||||
\\$ ./test
|
||||
\\output
|
||||
;
|
||||
const expected =
|
||||
\\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp>$ <kbd>zig build test.zig \
|
||||
\\ --build-option</kbd>
|
||||
\\build output
|
||||
\\$ <kbd>./test</kbd>
|
||||
\\output
|
||||
\\</samp></pre></figure>
|
||||
;
|
||||
|
||||
var buffer = std.ArrayList(u8).init(test_allocator);
|
||||
defer buffer.deinit();
|
||||
|
||||
try printShell(buffer.writer(), shell_out);
|
||||
try testing.expectEqualSlices(u8, expected, buffer.items);
|
||||
}
|
||||
{
|
||||
// intentional space after "--build-option1 \"
|
||||
const shell_out =
|
||||
\\$ zig build test.zig \
|
||||
\\ --build-option1 \
|
||||
\\ --build-option2
|
||||
\\$ ./test
|
||||
;
|
||||
const expected =
|
||||
\\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp>$ <kbd>zig build test.zig \
|
||||
\\ --build-option1 \
|
||||
\\ --build-option2</kbd>
|
||||
\\$ <kbd>./test</kbd>
|
||||
\\</samp></pre></figure>
|
||||
;
|
||||
|
||||
var buffer = std.ArrayList(u8).init(test_allocator);
|
||||
defer buffer.deinit();
|
||||
|
||||
try printShell(buffer.writer(), shell_out);
|
||||
try testing.expectEqualSlices(u8, expected, buffer.items);
|
||||
}
|
||||
{
|
||||
const shell_out =
|
||||
\\$ zig build test.zig \
|
||||
\\$ ./test
|
||||
;
|
||||
const expected =
|
||||
\\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp>$ <kbd>zig build test.zig \
|
||||
\\$ ./test</kbd>
|
||||
\\</samp></pre></figure>
|
||||
;
|
||||
|
||||
var buffer = std.ArrayList(u8).init(test_allocator);
|
||||
defer buffer.deinit();
|
||||
|
||||
try printShell(buffer.writer(), shell_out);
|
||||
try testing.expectEqualSlices(u8, expected, buffer.items);
|
||||
}
|
||||
{
|
||||
const shell_out =
|
||||
\\$ zig build test.zig
|
||||
\\$ ./test
|
||||
\\$1
|
||||
;
|
||||
const expected =
|
||||
\\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp>$ <kbd>zig build test.zig</kbd>
|
||||
\\$ <kbd>./test</kbd>
|
||||
\\$1
|
||||
\\</samp></pre></figure>
|
||||
;
|
||||
|
||||
var buffer = std.ArrayList(u8).init(test_allocator);
|
||||
defer buffer.deinit();
|
||||
|
||||
try printShell(buffer.writer(), shell_out);
|
||||
try testing.expectEqualSlices(u8, expected, buffer.items);
|
||||
}
|
||||
{
|
||||
const shell_out =
|
||||
\\$zig build test.zig
|
||||
;
|
||||
const expected =
|
||||
\\<figure><figcaption class="shell-cap">Shell</figcaption><pre><samp>$zig build test.zig
|
||||
\\</samp></pre></figure>
|
||||
;
|
||||
|
||||
var buffer = std.ArrayList(u8).init(test_allocator);
|
||||
defer buffer.deinit();
|
||||
|
||||
try printShell(buffer.writer(), shell_out);
|
||||
try testing.expectEqualSlices(u8, expected, buffer.items);
|
||||
}
|
||||
}
|
||||
|
||||
1291
doc/langref.html.in
1291
doc/langref.html.in
File diff suppressed because it is too large
Load Diff
55
lib/libc/mingw/math/arm-common/log2.c
vendored
Normal file
55
lib/libc/mingw/math/arm-common/log2.c
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
/**
|
||||
* This file has no copyright assigned and is placed in the Public Domain.
|
||||
* This file is part of the mingw-w64 runtime package.
|
||||
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef union ieee754_double_ {
|
||||
struct __attribute__((__packed__)) {
|
||||
uint64_t f52 : 52;
|
||||
uint64_t exp : 11;
|
||||
uint64_t sgn : 1;
|
||||
};
|
||||
double f;
|
||||
} ieee754_double;
|
||||
|
||||
typedef union ieee754_float_ {
|
||||
struct __attribute__((__packed__)) {
|
||||
uint32_t f23 : 23;
|
||||
uint32_t exp : 8;
|
||||
uint32_t sgn : 1;
|
||||
};
|
||||
float f;
|
||||
} ieee754_float;
|
||||
|
||||
double log2(double x)
|
||||
{
|
||||
ieee754_double u = { .f = x };
|
||||
if (u.sgn == 0 && u.f52 == 0 && u.exp > 0 && u.exp < 0x7ff) {
|
||||
// Handle exact powers of two exactly
|
||||
return (int)u.exp - 1023;
|
||||
}
|
||||
return log(x) / 0.69314718246459960938;
|
||||
}
|
||||
|
||||
float log2f(float x)
|
||||
{
|
||||
ieee754_float u = { .f = x };
|
||||
if (u.sgn == 0 && u.f23 == 0 && u.exp > 0 && u.exp < 0xff) {
|
||||
// Handle exact powers of two exactly
|
||||
return (int)u.exp - 127;
|
||||
}
|
||||
return logf(x) / 0.69314718246459960938f;
|
||||
}
|
||||
|
||||
long double log2l(long double x)
|
||||
{
|
||||
#if defined(__arm__) || defined(_ARM_) || defined(__aarch64__) || defined(_ARM64_)
|
||||
return log2(x);
|
||||
#else
|
||||
#error Not supported on your platform yet
|
||||
#endif
|
||||
}
|
||||
21
lib/libc/mingw/math/arm-common/pow.c
vendored
Normal file
21
lib/libc/mingw/math/arm-common/pow.c
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
/**
|
||||
* This file has no copyright assigned and is placed in the Public Domain.
|
||||
* This file is part of the mingw-w64 runtime package.
|
||||
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <limits.h>
|
||||
|
||||
extern double (* __MINGW_IMP_SYMBOL(pow))(double, double);
|
||||
|
||||
double pow(double x, double y)
|
||||
{
|
||||
if (x == 1.0)
|
||||
return 1.0;
|
||||
if (y == 0.0)
|
||||
return 1.0;
|
||||
if (x == -1.0 && isinf(y))
|
||||
return 1.0;
|
||||
return __MINGW_IMP_SYMBOL(pow)(x, y);
|
||||
}
|
||||
45
lib/libc/mingw/math/arm-common/scalbn.c
vendored
Normal file
45
lib/libc/mingw/math/arm-common/scalbn.c
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
/**
|
||||
* This file has no copyright assigned and is placed in the Public Domain.
|
||||
* This file is part of the mingw-w64 runtime package.
|
||||
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
|
||||
double scalbn(double x, int exp)
|
||||
{
|
||||
return x * exp2(exp);
|
||||
}
|
||||
|
||||
float scalbnf(float x, int exp)
|
||||
{
|
||||
return x * exp2f(exp);
|
||||
}
|
||||
|
||||
long double scalbnl(long double x, int exp)
|
||||
{
|
||||
#if defined(__arm__) || defined(_ARM_) || defined(__aarch64__) || defined(_ARM64_)
|
||||
return scalbn(x, exp);
|
||||
#else
|
||||
#error Not supported on your platform yet
|
||||
#endif
|
||||
}
|
||||
|
||||
double scalbln(double x, long exp)
|
||||
{
|
||||
return x * exp2(exp);
|
||||
}
|
||||
|
||||
float scalblnf(float x, long exp)
|
||||
{
|
||||
return x * exp2f(exp);
|
||||
}
|
||||
|
||||
long double scalblnl(long double x, long exp)
|
||||
{
|
||||
#if defined(__arm__) || defined(_ARM_) || defined(__aarch64__) || defined(_ARM64_)
|
||||
return scalbln(x, exp);
|
||||
#else
|
||||
#error Not supported on your platform yet
|
||||
#endif
|
||||
}
|
||||
148
lib/libc/mingw/math/bsd_private_base.h
vendored
Normal file
148
lib/libc/mingw/math/bsd_private_base.h
vendored
Normal file
@ -0,0 +1,148 @@
|
||||
/*
|
||||
* ====================================================
|
||||
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
||||
*
|
||||
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
||||
* Permission to use, copy, modify, and distribute this
|
||||
* software is freely granted, provided that this notice
|
||||
* is preserved.
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <float.h>
|
||||
|
||||
typedef unsigned int u_int32_t;
|
||||
|
||||
typedef union
|
||||
{
|
||||
double value;
|
||||
struct
|
||||
{
|
||||
u_int32_t lsw;
|
||||
u_int32_t msw;
|
||||
} parts;
|
||||
} ieee_double_shape_type;
|
||||
|
||||
typedef union {
|
||||
float value;
|
||||
u_int32_t word;
|
||||
} ieee_float_shape_type;
|
||||
|
||||
/* Get two 32 bit ints from a double. */
|
||||
|
||||
#define EXTRACT_WORDS(ix0,ix1,d) \
|
||||
do { \
|
||||
ieee_double_shape_type ew_u; \
|
||||
ew_u.value = (d); \
|
||||
(ix0) = ew_u.parts.msw; \
|
||||
(ix1) = ew_u.parts.lsw; \
|
||||
} while (0)
|
||||
|
||||
/* Get the most significant 32 bit int from a double. */
|
||||
|
||||
#define GET_HIGH_WORD(i,d) \
|
||||
do { \
|
||||
ieee_double_shape_type gh_u; \
|
||||
gh_u.value = (d); \
|
||||
(i) = gh_u.parts.msw; \
|
||||
} while (0)
|
||||
|
||||
/* Get the less significant 32 bit int from a double. */
|
||||
|
||||
#define GET_LOW_WORD(i,d) \
|
||||
do { \
|
||||
ieee_double_shape_type gl_u; \
|
||||
gl_u.value = (d); \
|
||||
(i) = gl_u.parts.lsw; \
|
||||
} while (0)
|
||||
|
||||
/* Set a double from two 32 bit ints. */
|
||||
|
||||
#define INSERT_WORDS(d,ix0,ix1) \
|
||||
do { \
|
||||
ieee_double_shape_type iw_u; \
|
||||
iw_u.parts.msw = (ix0); \
|
||||
iw_u.parts.lsw = (ix1); \
|
||||
(d) = iw_u.value; \
|
||||
} while (0)
|
||||
|
||||
/* Set the more significant 32 bits of a double from an int. */
|
||||
|
||||
#define SET_HIGH_WORD(d,v) \
|
||||
do { \
|
||||
ieee_double_shape_type sh_u; \
|
||||
sh_u.value = (d); \
|
||||
sh_u.parts.msw = (v); \
|
||||
(d) = sh_u.value; \
|
||||
} while (0)
|
||||
|
||||
/* Set the less significant 32 bits of a double from an int. */
|
||||
|
||||
#define SET_LOW_WORD(d,v) \
|
||||
do { \
|
||||
ieee_double_shape_type sl_u; \
|
||||
sl_u.value = (d); \
|
||||
sl_u.parts.lsw = (v); \
|
||||
(d) = sl_u.value; \
|
||||
} while (0)
|
||||
|
||||
#define GET_FLOAT_WORD(i,d) do \
|
||||
{ \
|
||||
ieee_float_shape_type gf_u; \
|
||||
gf_u.value = (d); \
|
||||
(i) = gf_u.word; \
|
||||
} while(0)
|
||||
|
||||
#define SET_FLOAT_WORD(d,i) do \
|
||||
{ \
|
||||
ieee_float_shape_type gf_u; \
|
||||
gf_u.word = (i); \
|
||||
(d) = gf_u.value; \
|
||||
} while(0)
|
||||
|
||||
|
||||
#ifdef FLT_EVAL_METHOD
|
||||
/*
|
||||
* Attempt to get strict C99 semantics for assignment with non-C99 compilers.
|
||||
*/
|
||||
#if FLT_EVAL_METHOD == 0 || __GNUC__ == 0
|
||||
#define STRICT_ASSIGN(type, lval, rval) ((lval) = (rval))
|
||||
#else
|
||||
#define STRICT_ASSIGN(type, lval, rval) do { \
|
||||
volatile type __lval; \
|
||||
\
|
||||
if (sizeof(type) >= sizeof(long double)) \
|
||||
(lval) = (rval); \
|
||||
else { \
|
||||
__lval = (rval); \
|
||||
(lval) = __lval; \
|
||||
} \
|
||||
} while (0)
|
||||
#endif
|
||||
#endif /* FLT_EVAL_METHOD */
|
||||
|
||||
/*
|
||||
* Mix 0, 1 or 2 NaNs. First add 0 to each arg. This normally just turns
|
||||
* signaling NaNs into quiet NaNs by setting a quiet bit. We do this
|
||||
* because we want to never return a signaling NaN, and also because we
|
||||
* don't want the quiet bit to affect the result. Then mix the converted
|
||||
* args using the specified operation.
|
||||
*
|
||||
* When one arg is NaN, the result is typically that arg quieted. When both
|
||||
* args are NaNs, the result is typically the quietening of the arg whose
|
||||
* mantissa is largest after quietening. When neither arg is NaN, the
|
||||
* result may be NaN because it is indeterminate, or finite for subsequent
|
||||
* construction of a NaN as the indeterminate 0.0L/0.0L.
|
||||
*
|
||||
* Technical complications: the result in bits after rounding to the final
|
||||
* precision might depend on the runtime precision and/or on compiler
|
||||
* optimizations, especially when different register sets are used for
|
||||
* different precisions. Try to make the result not depend on at least the
|
||||
* runtime precision by always doing the main mixing step in long double
|
||||
* precision. Try to reduce dependencies on optimizations by adding the
|
||||
* the 0's in different precisions (unless everything is in long double
|
||||
* precision).
|
||||
*/
|
||||
#define nan_mix(x, y) (nan_mix_op((x), (y), +))
|
||||
#define nan_mix_op(x, y, op) (((x) + 0.0L) op ((y) + 0))
|
||||
12
lib/libc/mingw/misc/initenv.c
vendored
Normal file
12
lib/libc/mingw/misc/initenv.c
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
/**
|
||||
* This file has no copyright assigned and is placed in the Public Domain.
|
||||
* This file is part of the mingw-w64 runtime package.
|
||||
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
|
||||
*/
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
static char ** local__initenv;
|
||||
static wchar_t ** local__winitenv;
|
||||
char *** __MINGW_IMP_SYMBOL(__initenv) = &local__initenv;
|
||||
wchar_t *** __MINGW_IMP_SYMBOL(__winitenv) = &local__winitenv;
|
||||
@ -558,7 +558,7 @@ const PosixThreadImpl = struct {
|
||||
.openbsd => {
|
||||
var count: c_int = undefined;
|
||||
var count_size: usize = @sizeOf(c_int);
|
||||
const mib = [_]c_int{ os.CTL_HW, os.HW_NCPUONLINE };
|
||||
const mib = [_]c_int{ os.CTL.HW, os.system.HW_NCPUONLINE };
|
||||
os.sysctl(&mib, &count, &count_size, null, 0) catch |err| switch (err) {
|
||||
error.NameTooLong, error.UnknownName => unreachable,
|
||||
else => |e| return e,
|
||||
@ -877,8 +877,8 @@ const LinuxThreadImpl = struct {
|
||||
const mapped = os.mmap(
|
||||
null,
|
||||
map_bytes,
|
||||
os.PROT_NONE,
|
||||
os.MAP_PRIVATE | os.MAP_ANONYMOUS,
|
||||
os.PROT.NONE,
|
||||
os.MAP.PRIVATE | os.MAP.ANONYMOUS,
|
||||
-1,
|
||||
0,
|
||||
) catch |err| switch (err) {
|
||||
@ -893,7 +893,7 @@ const LinuxThreadImpl = struct {
|
||||
// map everything but the guard page as read/write
|
||||
os.mprotect(
|
||||
mapped[guard_offset..],
|
||||
os.PROT_READ | os.PROT_WRITE,
|
||||
os.PROT.READ | os.PROT.WRITE,
|
||||
) catch |err| switch (err) {
|
||||
error.AccessDenied => unreachable,
|
||||
else => |e| return e,
|
||||
@ -923,10 +923,10 @@ const LinuxThreadImpl = struct {
|
||||
.thread = .{ .mapped = mapped },
|
||||
};
|
||||
|
||||
const flags: u32 = os.CLONE_THREAD | os.CLONE_DETACHED |
|
||||
os.CLONE_VM | os.CLONE_FS | os.CLONE_FILES |
|
||||
os.CLONE_PARENT_SETTID | os.CLONE_CHILD_CLEARTID |
|
||||
os.CLONE_SIGHAND | os.CLONE_SYSVSEM | os.CLONE_SETTLS;
|
||||
const flags: u32 = linux.CLONE.THREAD | linux.CLONE.DETACHED |
|
||||
linux.CLONE.VM | linux.CLONE.FS | linux.CLONE.FILES |
|
||||
linux.CLONE.PARENT_SETTID | linux.CLONE.CHILD_CLEARTID |
|
||||
linux.CLONE.SIGHAND | linux.CLONE.SYSVSEM | linux.CLONE.SETTLS;
|
||||
|
||||
switch (linux.getErrno(linux.clone(
|
||||
Instance.entryFn,
|
||||
@ -978,7 +978,7 @@ const LinuxThreadImpl = struct {
|
||||
|
||||
switch (linux.getErrno(linux.futex_wait(
|
||||
&self.thread.child_tid.value,
|
||||
linux.FUTEX_WAIT,
|
||||
linux.FUTEX.WAIT,
|
||||
tid,
|
||||
null,
|
||||
))) {
|
||||
|
||||
@ -142,7 +142,7 @@ const LinuxFutex = struct {
|
||||
|
||||
switch (linux.getErrno(linux.futex_wait(
|
||||
@ptrCast(*const i32, ptr),
|
||||
linux.FUTEX_PRIVATE_FLAG | linux.FUTEX_WAIT,
|
||||
linux.FUTEX.PRIVATE_FLAG | linux.FUTEX.WAIT,
|
||||
@bitCast(i32, expect),
|
||||
ts_ptr,
|
||||
))) {
|
||||
@ -159,7 +159,7 @@ const LinuxFutex = struct {
|
||||
fn wake(ptr: *const Atomic(u32), num_waiters: u32) void {
|
||||
switch (linux.getErrno(linux.futex_wake(
|
||||
@ptrCast(*const i32, ptr),
|
||||
linux.FUTEX_PRIVATE_FLAG | linux.FUTEX_WAKE,
|
||||
linux.FUTEX.PRIVATE_FLAG | linux.FUTEX.WAKE,
|
||||
std.math.cast(i32, num_waiters) catch std.math.maxInt(i32),
|
||||
))) {
|
||||
.SUCCESS => {}, // successful wake up
|
||||
@ -352,7 +352,7 @@ const PosixFutex = struct {
|
||||
var ts_ptr: ?*const std.os.timespec = null;
|
||||
if (timeout) |timeout_ns| {
|
||||
ts_ptr = &ts;
|
||||
std.os.clock_gettime(std.os.CLOCK_REALTIME, &ts) catch unreachable;
|
||||
std.os.clock_gettime(std.os.CLOCK.REALTIME, &ts) catch unreachable;
|
||||
ts.tv_sec += @intCast(@TypeOf(ts.tv_sec), timeout_ns / std.time.ns_per_s);
|
||||
ts.tv_nsec += @intCast(@TypeOf(ts.tv_nsec), timeout_ns % std.time.ns_per_s);
|
||||
if (ts.tv_nsec >= std.time.ns_per_s) {
|
||||
|
||||
@ -133,7 +133,7 @@ pub const AtomicMutex = struct {
|
||||
.linux => {
|
||||
switch (linux.getErrno(linux.futex_wait(
|
||||
@ptrCast(*const i32, &m.state),
|
||||
linux.FUTEX_PRIVATE_FLAG | linux.FUTEX_WAIT,
|
||||
linux.FUTEX.PRIVATE_FLAG | linux.FUTEX.WAIT,
|
||||
@enumToInt(new_state),
|
||||
null,
|
||||
))) {
|
||||
@ -155,7 +155,7 @@ pub const AtomicMutex = struct {
|
||||
.linux => {
|
||||
switch (linux.getErrno(linux.futex_wake(
|
||||
@ptrCast(*const i32, &m.state),
|
||||
linux.FUTEX_PRIVATE_FLAG | linux.FUTEX_WAKE,
|
||||
linux.FUTEX.PRIVATE_FLAG | linux.FUTEX.WAKE,
|
||||
1,
|
||||
))) {
|
||||
.SUCCESS => {},
|
||||
|
||||
@ -152,7 +152,7 @@ pub const PosixEvent = struct {
|
||||
pub fn timedWait(ev: *PosixEvent, timeout_ns: u64) TimedWaitResult {
|
||||
var ts: os.timespec = undefined;
|
||||
var timeout_abs = timeout_ns;
|
||||
os.clock_gettime(os.CLOCK_REALTIME, &ts) catch return .timed_out;
|
||||
os.clock_gettime(os.CLOCK.REALTIME, &ts) catch return .timed_out;
|
||||
timeout_abs += @intCast(u64, ts.tv_sec) * time.ns_per_s;
|
||||
timeout_abs += @intCast(u64, ts.tv_nsec);
|
||||
ts.tv_sec = @intCast(@TypeOf(ts.tv_sec), @divFloor(timeout_abs, time.ns_per_s));
|
||||
|
||||
@ -194,7 +194,7 @@ pub const AtomicEvent = struct {
|
||||
_ = wake_count;
|
||||
const waiting = std.math.maxInt(i32); // wake_count
|
||||
const ptr = @ptrCast(*const i32, waiters);
|
||||
const rc = linux.futex_wake(ptr, linux.FUTEX_WAKE | linux.FUTEX_PRIVATE_FLAG, waiting);
|
||||
const rc = linux.futex_wake(ptr, linux.FUTEX.WAKE | linux.FUTEX.PRIVATE_FLAG, waiting);
|
||||
assert(linux.getErrno(rc) == .SUCCESS);
|
||||
}
|
||||
|
||||
@ -213,7 +213,7 @@ pub const AtomicEvent = struct {
|
||||
return;
|
||||
const expected = @intCast(i32, waiting);
|
||||
const ptr = @ptrCast(*const i32, waiters);
|
||||
const rc = linux.futex_wait(ptr, linux.FUTEX_WAIT | linux.FUTEX_PRIVATE_FLAG, expected, ts_ptr);
|
||||
const rc = linux.futex_wait(ptr, linux.FUTEX.WAIT | linux.FUTEX.PRIVATE_FLAG, expected, ts_ptr);
|
||||
switch (linux.getErrno(rc)) {
|
||||
.SUCCESS => continue,
|
||||
.TIMEDOUT => return error.TimedOut,
|
||||
|
||||
@ -236,8 +236,11 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
|
||||
mem.copy(T, self.items[old_len..], items);
|
||||
}
|
||||
|
||||
pub usingnamespace if (T != u8) struct {} else struct {
|
||||
pub const Writer = std.io.Writer(*Self, error{OutOfMemory}, appendWrite);
|
||||
pub const Writer = if (T != u8)
|
||||
@compileError("The Writer interface is only defined for ArrayList(u8) " ++
|
||||
"but the given type is ArrayList(" ++ @typeName(T) ++ ")")
|
||||
else
|
||||
std.io.Writer(*Self, error{OutOfMemory}, appendWrite);
|
||||
|
||||
/// Initializes a Writer which will append to the list.
|
||||
pub fn writer(self: *Self) Writer {
|
||||
@ -250,7 +253,6 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
|
||||
try self.appendSlice(m);
|
||||
return m.len;
|
||||
}
|
||||
};
|
||||
|
||||
/// Append a value to the list `n` times.
|
||||
/// Allocates more memory as necessary.
|
||||
@ -741,7 +743,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
|
||||
|
||||
/// For a nicer API, `items.len` is the length, not the capacity.
|
||||
/// This requires "unsafe" slicing.
|
||||
fn allocatedSlice(self: Self) Slice {
|
||||
pub fn allocatedSlice(self: Self) Slice {
|
||||
return self.items.ptr[0..self.capacity];
|
||||
}
|
||||
};
|
||||
|
||||
@ -989,10 +989,15 @@ pub const Builder = struct {
|
||||
self.getInstallStep().dependOn(&self.addInstallFileWithDir(.{ .path = src_path }, .lib, dest_rel_path).step);
|
||||
}
|
||||
|
||||
/// Output format (BIN vs Intel HEX) determined by filename
|
||||
pub fn installRaw(self: *Builder, artifact: *LibExeObjStep, dest_filename: []const u8) void {
|
||||
self.getInstallStep().dependOn(&self.addInstallRaw(artifact, dest_filename).step);
|
||||
}
|
||||
|
||||
pub fn installRawWithFormat(self: *Builder, artifact: *LibExeObjStep, dest_filename: []const u8, format: InstallRawStep.RawFormat) void {
|
||||
self.getInstallStep().dependOn(&self.addInstallRawWithFormat(artifact, dest_filename, format).step);
|
||||
}
|
||||
|
||||
///`dest_rel_path` is relative to install prefix path
|
||||
pub fn addInstallFile(self: *Builder, source: FileSource, dest_rel_path: []const u8) *InstallFileStep {
|
||||
return self.addInstallFileWithDir(source.dupe(self), .prefix, dest_rel_path);
|
||||
@ -1009,7 +1014,11 @@ pub const Builder = struct {
|
||||
}
|
||||
|
||||
pub fn addInstallRaw(self: *Builder, artifact: *LibExeObjStep, dest_filename: []const u8) *InstallRawStep {
|
||||
return InstallRawStep.create(self, artifact, dest_filename);
|
||||
return InstallRawStep.create(self, artifact, dest_filename, null);
|
||||
}
|
||||
|
||||
pub fn addInstallRawWithFormat(self: *Builder, artifact: *LibExeObjStep, dest_filename: []const u8, format: InstallRawStep.RawFormat) *InstallRawStep {
|
||||
return InstallRawStep.create(self, artifact, dest_filename, format);
|
||||
}
|
||||
|
||||
pub fn addInstallFileWithDir(
|
||||
@ -1709,6 +1718,10 @@ pub const LibExeObjStep = struct {
|
||||
self.builder.installRaw(self, dest_filename);
|
||||
}
|
||||
|
||||
pub fn installRawWithFormat(self: *LibExeObjStep, dest_filename: []const u8, format: InstallRawStep.RawFormat) void {
|
||||
self.builder.installRawWithFormat(self, dest_filename, format);
|
||||
}
|
||||
|
||||
/// Creates a `RunStep` with an executable built with `addExecutable`.
|
||||
/// Add command line arguments with `addArg`.
|
||||
pub fn run(exe: *LibExeObjStep) *RunStep {
|
||||
@ -2536,7 +2549,22 @@ pub const LibExeObjStep = struct {
|
||||
} else {
|
||||
try zig_args.append("-isystem");
|
||||
}
|
||||
try zig_args.append(self.builder.pathFromRoot(include_path));
|
||||
|
||||
const resolved_include_path = self.builder.pathFromRoot(include_path);
|
||||
|
||||
const common_include_path = if (std.Target.current.os.tag == .windows and builder.sysroot != null and fs.path.isAbsolute(resolved_include_path)) blk: {
|
||||
// We need to check for disk designator and strip it out from dir path so
|
||||
// that zig/clang can concat resolved_include_path with sysroot.
|
||||
const disk_designator = fs.path.diskDesignatorWindows(resolved_include_path);
|
||||
|
||||
if (mem.indexOf(u8, resolved_include_path, disk_designator)) |where| {
|
||||
break :blk resolved_include_path[where + disk_designator.len ..];
|
||||
}
|
||||
|
||||
break :blk resolved_include_path;
|
||||
} else resolved_include_path;
|
||||
|
||||
try zig_args.append(common_include_path);
|
||||
},
|
||||
.other_step => |other| if (other.emit_h) {
|
||||
const h_path = other.getOutputHSource().getPath(self.builder);
|
||||
|
||||
@ -159,7 +159,147 @@ fn writeBinaryElfSection(elf_file: File, out_file: File, section: *BinaryElfSect
|
||||
});
|
||||
}
|
||||
|
||||
fn emitRaw(allocator: *Allocator, elf_path: []const u8, raw_path: []const u8) !void {
|
||||
const HexWriter = struct {
|
||||
prev_addr: ?u32 = null,
|
||||
out_file: File,
|
||||
|
||||
/// Max data bytes per line of output
|
||||
const MAX_PAYLOAD_LEN: u8 = 16;
|
||||
|
||||
fn addressParts(address: u16) [2]u8 {
|
||||
const msb = @truncate(u8, address >> 8);
|
||||
const lsb = @truncate(u8, address);
|
||||
return [2]u8{ msb, lsb };
|
||||
}
|
||||
|
||||
const Record = struct {
|
||||
const Type = enum(u8) {
|
||||
Data = 0,
|
||||
EOF = 1,
|
||||
ExtendedSegmentAddress = 2,
|
||||
ExtendedLinearAddress = 4,
|
||||
};
|
||||
|
||||
address: u16,
|
||||
payload: union(Type) {
|
||||
Data: []const u8,
|
||||
EOF: void,
|
||||
ExtendedSegmentAddress: [2]u8,
|
||||
ExtendedLinearAddress: [2]u8,
|
||||
},
|
||||
|
||||
fn EOF() Record {
|
||||
return Record{
|
||||
.address = 0,
|
||||
.payload = .EOF,
|
||||
};
|
||||
}
|
||||
|
||||
fn Data(address: u32, data: []const u8) Record {
|
||||
return Record{
|
||||
.address = @intCast(u16, address % 0x10000),
|
||||
.payload = .{ .Data = data },
|
||||
};
|
||||
}
|
||||
|
||||
fn Address(address: u32) Record {
|
||||
std.debug.assert(address > 0xFFFF);
|
||||
const segment = @intCast(u16, address / 0x10000);
|
||||
if (address > 0xFFFFF) {
|
||||
return Record{
|
||||
.address = 0,
|
||||
.payload = .{ .ExtendedLinearAddress = addressParts(segment) },
|
||||
};
|
||||
} else {
|
||||
return Record{
|
||||
.address = 0,
|
||||
.payload = .{ .ExtendedSegmentAddress = addressParts(segment << 12) },
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn getPayloadBytes(self: Record) []const u8 {
|
||||
return switch (self.payload) {
|
||||
.Data => |d| d,
|
||||
.EOF => @as([]const u8, &.{}),
|
||||
.ExtendedSegmentAddress, .ExtendedLinearAddress => |*seg| seg,
|
||||
};
|
||||
}
|
||||
|
||||
fn checksum(self: Record) u8 {
|
||||
const payload_bytes = self.getPayloadBytes();
|
||||
|
||||
var sum: u8 = @intCast(u8, payload_bytes.len);
|
||||
const parts = addressParts(self.address);
|
||||
sum +%= parts[0];
|
||||
sum +%= parts[1];
|
||||
sum +%= @enumToInt(self.payload);
|
||||
for (payload_bytes) |byte| {
|
||||
sum +%= byte;
|
||||
}
|
||||
return (sum ^ 0xFF) +% 1;
|
||||
}
|
||||
|
||||
fn write(self: Record, file: File) File.WriteError!void {
|
||||
const linesep = "\r\n";
|
||||
// colon, (length, address, type, payload, checksum) as hex, CRLF
|
||||
const BUFSIZE = 1 + (1 + 2 + 1 + MAX_PAYLOAD_LEN + 1) * 2 + linesep.len;
|
||||
var outbuf: [BUFSIZE]u8 = undefined;
|
||||
const payload_bytes = self.getPayloadBytes();
|
||||
std.debug.assert(payload_bytes.len <= MAX_PAYLOAD_LEN);
|
||||
|
||||
const line = try std.fmt.bufPrint(&outbuf, ":{0X:0>2}{1X:0>4}{2X:0>2}{3s}{4X:0>2}" ++ linesep, .{
|
||||
@intCast(u8, payload_bytes.len),
|
||||
self.address,
|
||||
@enumToInt(self.payload),
|
||||
std.fmt.fmtSliceHexUpper(payload_bytes),
|
||||
self.checksum(),
|
||||
});
|
||||
try file.writeAll(line);
|
||||
}
|
||||
};
|
||||
|
||||
pub fn writeSegment(self: *HexWriter, segment: *const BinaryElfSegment, elf_file: File) !void {
|
||||
var buf: [MAX_PAYLOAD_LEN]u8 = undefined;
|
||||
var bytes_read: usize = 0;
|
||||
while (bytes_read < segment.fileSize) {
|
||||
const row_address = @intCast(u32, segment.physicalAddress + bytes_read);
|
||||
|
||||
const remaining = segment.fileSize - bytes_read;
|
||||
const to_read = @minimum(remaining, MAX_PAYLOAD_LEN);
|
||||
const did_read = try elf_file.preadAll(buf[0..to_read], segment.elfOffset + bytes_read);
|
||||
if (did_read < to_read) return error.UnexpectedEOF;
|
||||
|
||||
try self.writeDataRow(row_address, buf[0..did_read]);
|
||||
|
||||
bytes_read += did_read;
|
||||
}
|
||||
}
|
||||
|
||||
fn writeDataRow(self: *HexWriter, address: u32, data: []const u8) File.WriteError!void {
|
||||
const record = Record.Data(address, data);
|
||||
if (address > 0xFFFF and (self.prev_addr == null or record.address != self.prev_addr.?)) {
|
||||
try Record.Address(address).write(self.out_file);
|
||||
}
|
||||
try record.write(self.out_file);
|
||||
self.prev_addr = @intCast(u32, record.address + data.len);
|
||||
}
|
||||
|
||||
fn writeEOF(self: HexWriter) File.WriteError!void {
|
||||
try Record.EOF().write(self.out_file);
|
||||
}
|
||||
};
|
||||
|
||||
fn containsValidAddressRange(segments: []*BinaryElfSegment) bool {
|
||||
const max_address = std.math.maxInt(u32);
|
||||
for (segments) |segment| {
|
||||
if (segment.fileSize > max_address or
|
||||
segment.physicalAddress > max_address - segment.fileSize) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
fn emitRaw(allocator: *Allocator, elf_path: []const u8, raw_path: []const u8, format: RawFormat) !void {
|
||||
var elf_file = try fs.cwd().openFile(elf_path, .{});
|
||||
defer elf_file.close();
|
||||
|
||||
@ -169,22 +309,54 @@ fn emitRaw(allocator: *Allocator, elf_path: []const u8, raw_path: []const u8) !v
|
||||
var binary_elf_output = try BinaryElfOutput.parse(allocator, elf_file);
|
||||
defer binary_elf_output.deinit();
|
||||
|
||||
switch (format) {
|
||||
.bin => {
|
||||
for (binary_elf_output.sections.items) |section| {
|
||||
try writeBinaryElfSection(elf_file, out_file, section);
|
||||
}
|
||||
},
|
||||
.hex => {
|
||||
if (binary_elf_output.segments.items.len == 0) return;
|
||||
if (!containsValidAddressRange(binary_elf_output.segments.items)) {
|
||||
return error.InvalidHexfileAddressRange;
|
||||
}
|
||||
|
||||
var hex_writer = HexWriter{ .out_file = out_file };
|
||||
for (binary_elf_output.sections.items) |section| {
|
||||
if (section.segment) |segment| {
|
||||
try hex_writer.writeSegment(segment, elf_file);
|
||||
}
|
||||
}
|
||||
try hex_writer.writeEOF();
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
const InstallRawStep = @This();
|
||||
|
||||
pub const base_id = .install_raw;
|
||||
|
||||
pub const RawFormat = enum {
|
||||
bin,
|
||||
hex,
|
||||
};
|
||||
|
||||
step: Step,
|
||||
builder: *Builder,
|
||||
artifact: *LibExeObjStep,
|
||||
dest_dir: InstallDir,
|
||||
dest_filename: []const u8,
|
||||
format: RawFormat,
|
||||
output_file: std.build.GeneratedFile,
|
||||
|
||||
pub fn create(builder: *Builder, artifact: *LibExeObjStep, dest_filename: []const u8) *InstallRawStep {
|
||||
fn detectFormat(filename: []const u8) RawFormat {
|
||||
if (std.mem.endsWith(u8, filename, ".hex") or std.mem.endsWith(u8, filename, ".ihex")) {
|
||||
return .hex;
|
||||
}
|
||||
return .bin;
|
||||
}
|
||||
|
||||
pub fn create(builder: *Builder, artifact: *LibExeObjStep, dest_filename: []const u8, format: ?RawFormat) *InstallRawStep {
|
||||
const self = builder.allocator.create(InstallRawStep) catch unreachable;
|
||||
self.* = InstallRawStep{
|
||||
.step = Step.init(.install_raw, builder.fmt("install raw binary {s}", .{artifact.step.name}), builder.allocator, make),
|
||||
@ -197,6 +369,8 @@ pub fn create(builder: *Builder, artifact: *LibExeObjStep, dest_filename: []cons
|
||||
.lib => unreachable,
|
||||
},
|
||||
.dest_filename = dest_filename,
|
||||
.format = format orelse detectFormat(dest_filename),
|
||||
.output_file = std.build.GeneratedFile{ .step = &self.step },
|
||||
};
|
||||
self.step.dependOn(&artifact.step);
|
||||
|
||||
@ -204,6 +378,10 @@ pub fn create(builder: *Builder, artifact: *LibExeObjStep, dest_filename: []cons
|
||||
return self;
|
||||
}
|
||||
|
||||
pub fn getOutputSource(self: *const InstallRawStep) std.build.FileSource {
|
||||
return std.build.FileSource{ .generated = &self.output_file };
|
||||
}
|
||||
|
||||
fn make(step: *Step) !void {
|
||||
const self = @fieldParentPtr(InstallRawStep, "step", step);
|
||||
const builder = self.builder;
|
||||
@ -217,9 +395,49 @@ fn make(step: *Step) !void {
|
||||
const full_dest_path = builder.getInstallPath(self.dest_dir, self.dest_filename);
|
||||
|
||||
fs.cwd().makePath(builder.getInstallPath(self.dest_dir, "")) catch unreachable;
|
||||
try emitRaw(builder.allocator, full_src_path, full_dest_path);
|
||||
try emitRaw(builder.allocator, full_src_path, full_dest_path, self.format);
|
||||
self.output_file.path = full_dest_path;
|
||||
}
|
||||
|
||||
test {
|
||||
std.testing.refAllDecls(InstallRawStep);
|
||||
}
|
||||
|
||||
test "Detect format from filename" {
|
||||
try std.testing.expectEqual(RawFormat.hex, detectFormat("foo.hex"));
|
||||
try std.testing.expectEqual(RawFormat.hex, detectFormat("foo.ihex"));
|
||||
try std.testing.expectEqual(RawFormat.bin, detectFormat("foo.bin"));
|
||||
try std.testing.expectEqual(RawFormat.bin, detectFormat("foo.bar"));
|
||||
try std.testing.expectEqual(RawFormat.bin, detectFormat("a"));
|
||||
}
|
||||
|
||||
test "containsValidAddressRange" {
|
||||
var segment = BinaryElfSegment{
|
||||
.physicalAddress = 0,
|
||||
.virtualAddress = 0,
|
||||
.elfOffset = 0,
|
||||
.binaryOffset = 0,
|
||||
.fileSize = 0,
|
||||
.firstSection = null,
|
||||
};
|
||||
var buf: [1]*BinaryElfSegment = .{&segment};
|
||||
|
||||
// segment too big
|
||||
segment.fileSize = std.math.maxInt(u32) + 1;
|
||||
try std.testing.expect(!containsValidAddressRange(&buf));
|
||||
|
||||
// start address too big
|
||||
segment.physicalAddress = std.math.maxInt(u32) + 1;
|
||||
segment.fileSize = 2;
|
||||
try std.testing.expect(!containsValidAddressRange(&buf));
|
||||
|
||||
// max address too big
|
||||
segment.physicalAddress = std.math.maxInt(u32) - 1;
|
||||
segment.fileSize = 2;
|
||||
try std.testing.expect(!containsValidAddressRange(&buf));
|
||||
|
||||
// is ok
|
||||
segment.physicalAddress = std.math.maxInt(u32) - 1;
|
||||
segment.fileSize = 1;
|
||||
try std.testing.expect(containsValidAddressRange(&buf));
|
||||
}
|
||||
|
||||
@ -27,7 +27,7 @@ pub const code_model = builtin.code_model;
|
||||
/// used rather than `explicit_subsystem`.
|
||||
/// On non-Windows targets, this is `null`.
|
||||
pub const subsystem: ?std.Target.SubSystem = blk: {
|
||||
if (@hasDecl(builtin, "explicit_subsystem")) break :blk explicit_subsystem;
|
||||
if (@hasDecl(builtin, "explicit_subsystem")) break :blk builtin.explicit_subsystem;
|
||||
switch (os.tag) {
|
||||
.windows => {
|
||||
if (is_test) {
|
||||
|
||||
417
lib/std/c.zig
417
lib/std/c.zig
@ -1,18 +1,45 @@
|
||||
const std = @import("std");
|
||||
const builtin = std.builtin;
|
||||
const c = @This();
|
||||
const page_size = std.mem.page_size;
|
||||
|
||||
pub const tokenizer = @import("c/tokenizer.zig");
|
||||
pub const Token = tokenizer.Token;
|
||||
pub const Tokenizer = tokenizer.Tokenizer;
|
||||
const iovec = std.os.iovec;
|
||||
const iovec_const = std.os.iovec_const;
|
||||
|
||||
test {
|
||||
_ = tokenizer;
|
||||
}
|
||||
|
||||
pub usingnamespace @import("os/bits.zig");
|
||||
pub const tokenizer = @import("c/tokenizer.zig");
|
||||
pub const Token = tokenizer.Token;
|
||||
pub const Tokenizer = tokenizer.Tokenizer;
|
||||
|
||||
pub usingnamespace switch (std.Target.current.os.tag) {
|
||||
/// The return type is `type` to force comptime function call execution.
|
||||
/// TODO: https://github.com/ziglang/zig/issues/425
|
||||
/// If not linking libc, returns struct{pub const ok = false;}
|
||||
/// If linking musl libc, returns struct{pub const ok = true;}
|
||||
/// If linking gnu libc (glibc), the `ok` value will be true if the target
|
||||
/// version is greater than or equal to `glibc_version`.
|
||||
/// If linking a libc other than these, returns `false`.
|
||||
pub fn versionCheck(glibc_version: builtin.Version) type {
|
||||
return struct {
|
||||
pub const ok = blk: {
|
||||
if (!builtin.link_libc) break :blk false;
|
||||
if (builtin.abi.isMusl()) break :blk true;
|
||||
if (builtin.target.isGnuLibC()) {
|
||||
const ver = builtin.os.version_range.linux.glibc;
|
||||
const order = ver.order(glibc_version);
|
||||
break :blk switch (order) {
|
||||
.gt, .eq => true,
|
||||
.lt => false,
|
||||
};
|
||||
} else {
|
||||
break :blk false;
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
pub usingnamespace switch (builtin.os.tag) {
|
||||
.linux => @import("c/linux.zig"),
|
||||
.windows => @import("c/windows.zig"),
|
||||
.macos, .ios, .tvos, .watchos => @import("c/darwin.zig"),
|
||||
@ -30,40 +57,44 @@ pub usingnamespace switch (std.Target.current.os.tag) {
|
||||
else => struct {},
|
||||
};
|
||||
|
||||
pub fn getErrno(rc: anytype) E {
|
||||
pub const whence_t = if (builtin.os.tag == .wasi) std.os.wasi.whence_t else c_int;
|
||||
|
||||
pub usingnamespace switch (builtin.os.tag) {
|
||||
.netbsd, .macos, .ios, .watchos, .tvos, .windows => struct {},
|
||||
else => struct {
|
||||
pub extern "c" fn clock_getres(clk_id: c_int, tp: *c.timespec) c_int;
|
||||
pub extern "c" fn clock_gettime(clk_id: c_int, tp: *c.timespec) c_int;
|
||||
pub extern "c" fn fstat(fd: c.fd_t, buf: *c.Stat) c_int;
|
||||
pub extern "c" fn getrusage(who: c_int, usage: *c.rusage) c_int;
|
||||
pub extern "c" fn gettimeofday(noalias tv: ?*c.timeval, noalias tz: ?*c.timezone) c_int;
|
||||
pub extern "c" fn nanosleep(rqtp: *const c.timespec, rmtp: ?*c.timespec) c_int;
|
||||
pub extern "c" fn sched_yield() c_int;
|
||||
pub extern "c" fn sigaction(sig: c_int, noalias act: ?*const c.Sigaction, noalias oact: ?*c.Sigaction) c_int;
|
||||
pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const c.sigset_t, noalias oset: ?*c.sigset_t) c_int;
|
||||
pub extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
|
||||
pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *c.Stat) c_int;
|
||||
pub extern "c" fn sigfillset(set: ?*c.sigset_t) void;
|
||||
pub extern "c" fn alarm(seconds: c_uint) c_uint;
|
||||
pub extern "c" fn sigwait(set: ?*c.sigset_t, sig: ?*c_int) c_int;
|
||||
},
|
||||
};
|
||||
|
||||
pub usingnamespace switch (builtin.os.tag) {
|
||||
.macos, .ios, .watchos, .tvos => struct {},
|
||||
else => struct {
|
||||
pub extern "c" fn realpath(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8;
|
||||
pub extern "c" fn fstatat(dirfd: c.fd_t, path: [*:0]const u8, stat_buf: *c.Stat, flags: u32) c_int;
|
||||
},
|
||||
};
|
||||
|
||||
pub fn getErrno(rc: anytype) c.E {
|
||||
if (rc == -1) {
|
||||
return @intToEnum(E, _errno().*);
|
||||
return @intToEnum(c.E, c._errno().*);
|
||||
} else {
|
||||
return .SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
/// The return type is `type` to force comptime function call execution.
|
||||
/// TODO: https://github.com/ziglang/zig/issues/425
|
||||
/// If not linking libc, returns struct{pub const ok = false;}
|
||||
/// If linking musl libc, returns struct{pub const ok = true;}
|
||||
/// If linking gnu libc (glibc), the `ok` value will be true if the target
|
||||
/// version is greater than or equal to `glibc_version`.
|
||||
/// If linking a libc other than these, returns `false`.
|
||||
pub fn versionCheck(glibc_version: builtin.Version) type {
|
||||
return struct {
|
||||
pub const ok = blk: {
|
||||
if (!builtin.link_libc) break :blk false;
|
||||
if (std.Target.current.abi.isMusl()) break :blk true;
|
||||
if (std.Target.current.isGnuLibC()) {
|
||||
const ver = std.Target.current.os.version_range.linux.glibc;
|
||||
const order = ver.order(glibc_version);
|
||||
break :blk switch (order) {
|
||||
.gt, .eq => true,
|
||||
.lt => false,
|
||||
};
|
||||
} else {
|
||||
break :blk false;
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
pub extern "c" var environ: [*:null]?[*:0]u8;
|
||||
|
||||
pub extern "c" fn fopen(noalias filename: [*:0]const u8, noalias modes: [*:0]const u8) ?*FILE;
|
||||
@ -75,255 +106,175 @@ pub extern "c" fn printf(format: [*:0]const u8, ...) c_int;
|
||||
pub extern "c" fn abort() noreturn;
|
||||
pub extern "c" fn exit(code: c_int) noreturn;
|
||||
pub extern "c" fn _exit(code: c_int) noreturn;
|
||||
pub extern "c" fn isatty(fd: fd_t) c_int;
|
||||
pub extern "c" fn close(fd: fd_t) c_int;
|
||||
pub extern "c" fn lseek(fd: fd_t, offset: off_t, whence: c_int) off_t;
|
||||
pub extern "c" fn isatty(fd: c.fd_t) c_int;
|
||||
pub extern "c" fn close(fd: c.fd_t) c_int;
|
||||
pub extern "c" fn lseek(fd: c.fd_t, offset: c.off_t, whence: whence_t) c.off_t;
|
||||
pub extern "c" fn open(path: [*:0]const u8, oflag: c_uint, ...) c_int;
|
||||
pub extern "c" fn openat(fd: c_int, path: [*:0]const u8, oflag: c_uint, ...) c_int;
|
||||
pub extern "c" fn ftruncate(fd: c_int, length: off_t) c_int;
|
||||
pub extern "c" fn ftruncate(fd: c_int, length: c.off_t) c_int;
|
||||
pub extern "c" fn raise(sig: c_int) c_int;
|
||||
pub extern "c" fn read(fd: fd_t, buf: [*]u8, nbyte: usize) isize;
|
||||
pub extern "c" fn read(fd: c.fd_t, buf: [*]u8, nbyte: usize) isize;
|
||||
pub extern "c" fn readv(fd: c_int, iov: [*]const iovec, iovcnt: c_uint) isize;
|
||||
pub extern "c" fn pread(fd: fd_t, buf: [*]u8, nbyte: usize, offset: off_t) isize;
|
||||
pub extern "c" fn preadv(fd: c_int, iov: [*]const iovec, iovcnt: c_uint, offset: off_t) isize;
|
||||
pub extern "c" fn pread(fd: c.fd_t, buf: [*]u8, nbyte: usize, offset: c.off_t) isize;
|
||||
pub extern "c" fn preadv(fd: c_int, iov: [*]const iovec, iovcnt: c_uint, offset: c.off_t) isize;
|
||||
pub extern "c" fn writev(fd: c_int, iov: [*]const iovec_const, iovcnt: c_uint) isize;
|
||||
pub extern "c" fn pwritev(fd: c_int, iov: [*]const iovec_const, iovcnt: c_uint, offset: off_t) isize;
|
||||
pub extern "c" fn write(fd: fd_t, buf: [*]const u8, nbyte: usize) isize;
|
||||
pub extern "c" fn pwrite(fd: fd_t, buf: [*]const u8, nbyte: usize, offset: off_t) isize;
|
||||
pub extern "c" fn mmap(addr: ?*align(page_size) c_void, len: usize, prot: c_uint, flags: c_uint, fd: fd_t, offset: off_t) *c_void;
|
||||
pub extern "c" fn pwritev(fd: c_int, iov: [*]const iovec_const, iovcnt: c_uint, offset: c.off_t) isize;
|
||||
pub extern "c" fn write(fd: c.fd_t, buf: [*]const u8, nbyte: usize) isize;
|
||||
pub extern "c" fn pwrite(fd: c.fd_t, buf: [*]const u8, nbyte: usize, offset: c.off_t) isize;
|
||||
pub extern "c" fn mmap(addr: ?*align(page_size) c_void, len: usize, prot: c_uint, flags: c_uint, fd: c.fd_t, offset: c.off_t) *c_void;
|
||||
pub extern "c" fn munmap(addr: *align(page_size) const c_void, len: usize) c_int;
|
||||
pub extern "c" fn mprotect(addr: *align(page_size) c_void, len: usize, prot: c_uint) c_int;
|
||||
pub extern "c" fn link(oldpath: [*:0]const u8, newpath: [*:0]const u8, flags: c_int) c_int;
|
||||
pub extern "c" fn linkat(oldfd: fd_t, oldpath: [*:0]const u8, newfd: fd_t, newpath: [*:0]const u8, flags: c_int) c_int;
|
||||
pub extern "c" fn linkat(oldfd: c.fd_t, oldpath: [*:0]const u8, newfd: c.fd_t, newpath: [*:0]const u8, flags: c_int) c_int;
|
||||
pub extern "c" fn unlink(path: [*:0]const u8) c_int;
|
||||
pub extern "c" fn unlinkat(dirfd: fd_t, path: [*:0]const u8, flags: c_uint) c_int;
|
||||
pub extern "c" fn unlinkat(dirfd: c.fd_t, path: [*:0]const u8, flags: c_uint) c_int;
|
||||
pub extern "c" fn getcwd(buf: [*]u8, size: usize) ?[*]u8;
|
||||
pub extern "c" fn waitpid(pid: pid_t, stat_loc: ?*c_int, options: c_int) pid_t;
|
||||
pub extern "c" fn waitpid(pid: c.pid_t, stat_loc: ?*c_int, options: c_int) c.pid_t;
|
||||
pub extern "c" fn fork() c_int;
|
||||
pub extern "c" fn access(path: [*:0]const u8, mode: c_uint) c_int;
|
||||
pub extern "c" fn faccessat(dirfd: fd_t, path: [*:0]const u8, mode: c_uint, flags: c_uint) c_int;
|
||||
pub extern "c" fn pipe(fds: *[2]fd_t) c_int;
|
||||
pub extern "c" fn faccessat(dirfd: c.fd_t, path: [*:0]const u8, mode: c_uint, flags: c_uint) c_int;
|
||||
pub extern "c" fn pipe(fds: *[2]c.fd_t) c_int;
|
||||
pub extern "c" fn mkdir(path: [*:0]const u8, mode: c_uint) c_int;
|
||||
pub extern "c" fn mkdirat(dirfd: fd_t, path: [*:0]const u8, mode: u32) c_int;
|
||||
pub extern "c" fn mkdirat(dirfd: c.fd_t, path: [*:0]const u8, mode: u32) c_int;
|
||||
pub extern "c" fn symlink(existing: [*:0]const u8, new: [*:0]const u8) c_int;
|
||||
pub extern "c" fn symlinkat(oldpath: [*:0]const u8, newdirfd: fd_t, newpath: [*:0]const u8) c_int;
|
||||
pub extern "c" fn symlinkat(oldpath: [*:0]const u8, newdirfd: c.fd_t, newpath: [*:0]const u8) c_int;
|
||||
pub extern "c" fn rename(old: [*:0]const u8, new: [*:0]const u8) c_int;
|
||||
pub extern "c" fn renameat(olddirfd: fd_t, old: [*:0]const u8, newdirfd: fd_t, new: [*:0]const u8) c_int;
|
||||
pub extern "c" fn renameat(olddirfd: c.fd_t, old: [*:0]const u8, newdirfd: c.fd_t, new: [*:0]const u8) c_int;
|
||||
pub extern "c" fn chdir(path: [*:0]const u8) c_int;
|
||||
pub extern "c" fn fchdir(fd: fd_t) c_int;
|
||||
pub extern "c" fn fchdir(fd: c.fd_t) c_int;
|
||||
pub extern "c" fn execve(path: [*:0]const u8, argv: [*:null]const ?[*:0]const u8, envp: [*:null]const ?[*:0]const u8) c_int;
|
||||
pub extern "c" fn dup(fd: fd_t) c_int;
|
||||
pub extern "c" fn dup2(old_fd: fd_t, new_fd: fd_t) c_int;
|
||||
pub extern "c" fn dup(fd: c.fd_t) c_int;
|
||||
pub extern "c" fn dup2(old_fd: c.fd_t, new_fd: c.fd_t) c_int;
|
||||
pub extern "c" fn readlink(noalias path: [*:0]const u8, noalias buf: [*]u8, bufsize: usize) isize;
|
||||
pub extern "c" fn readlinkat(dirfd: fd_t, noalias path: [*:0]const u8, noalias buf: [*]u8, bufsize: usize) isize;
|
||||
|
||||
pub usingnamespace switch (builtin.os.tag) {
|
||||
.macos, .ios, .watchos, .tvos => struct {
|
||||
pub const realpath = @"realpath$DARWIN_EXTSN";
|
||||
pub const fstatat = _fstatat;
|
||||
},
|
||||
else => struct {
|
||||
pub extern "c" fn realpath(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8;
|
||||
pub extern "c" fn fstatat(dirfd: fd_t, path: [*:0]const u8, stat_buf: *libc_stat, flags: u32) c_int;
|
||||
},
|
||||
};
|
||||
pub extern "c" fn readlinkat(dirfd: c.fd_t, noalias path: [*:0]const u8, noalias buf: [*]u8, bufsize: usize) isize;
|
||||
|
||||
pub extern "c" fn rmdir(path: [*:0]const u8) c_int;
|
||||
pub extern "c" fn getenv(name: [*:0]const u8) ?[*:0]u8;
|
||||
pub extern "c" fn sysctl(name: [*]const c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;
|
||||
pub extern "c" fn sysctlbyname(name: [*:0]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;
|
||||
pub extern "c" fn sysctlnametomib(name: [*:0]const u8, mibp: ?*c_int, sizep: ?*usize) c_int;
|
||||
pub extern "c" fn tcgetattr(fd: fd_t, termios_p: *termios) c_int;
|
||||
pub extern "c" fn tcsetattr(fd: fd_t, optional_action: TCSA, termios_p: *const termios) c_int;
|
||||
pub extern "c" fn fcntl(fd: fd_t, cmd: c_int, ...) c_int;
|
||||
pub extern "c" fn flock(fd: fd_t, operation: c_int) c_int;
|
||||
pub extern "c" fn ioctl(fd: fd_t, request: c_int, ...) c_int;
|
||||
pub extern "c" fn uname(buf: *utsname) c_int;
|
||||
pub extern "c" fn tcgetattr(fd: c.fd_t, termios_p: *c.termios) c_int;
|
||||
pub extern "c" fn tcsetattr(fd: c.fd_t, optional_action: c.TCSA, termios_p: *const c.termios) c_int;
|
||||
pub extern "c" fn fcntl(fd: c.fd_t, cmd: c_int, ...) c_int;
|
||||
pub extern "c" fn flock(fd: c.fd_t, operation: c_int) c_int;
|
||||
pub extern "c" fn ioctl(fd: c.fd_t, request: c_int, ...) c_int;
|
||||
pub extern "c" fn uname(buf: *c.utsname) c_int;
|
||||
|
||||
pub extern "c" fn gethostname(name: [*]u8, len: usize) c_int;
|
||||
pub extern "c" fn shutdown(socket: fd_t, how: c_int) c_int;
|
||||
pub extern "c" fn bind(socket: fd_t, address: ?*const sockaddr, address_len: socklen_t) c_int;
|
||||
pub extern "c" fn socketpair(domain: c_uint, sock_type: c_uint, protocol: c_uint, sv: *[2]fd_t) c_int;
|
||||
pub extern "c" fn listen(sockfd: fd_t, backlog: c_uint) c_int;
|
||||
pub extern "c" fn getsockname(sockfd: fd_t, noalias addr: *sockaddr, noalias addrlen: *socklen_t) c_int;
|
||||
pub extern "c" fn getpeername(sockfd: fd_t, noalias addr: *sockaddr, noalias addrlen: *socklen_t) c_int;
|
||||
pub extern "c" fn connect(sockfd: fd_t, sock_addr: *const sockaddr, addrlen: socklen_t) c_int;
|
||||
pub extern "c" fn accept(sockfd: fd_t, noalias addr: ?*sockaddr, noalias addrlen: ?*socklen_t) c_int;
|
||||
pub extern "c" fn accept4(sockfd: fd_t, noalias addr: ?*sockaddr, noalias addrlen: ?*socklen_t, flags: c_uint) c_int;
|
||||
pub extern "c" fn getsockopt(sockfd: fd_t, level: u32, optname: u32, noalias optval: ?*c_void, noalias optlen: *socklen_t) c_int;
|
||||
pub extern "c" fn setsockopt(sockfd: fd_t, level: u32, optname: u32, optval: ?*const c_void, optlen: socklen_t) c_int;
|
||||
pub extern "c" fn send(sockfd: fd_t, buf: *const c_void, len: usize, flags: u32) isize;
|
||||
pub extern "c" fn shutdown(socket: c.fd_t, how: c_int) c_int;
|
||||
pub extern "c" fn bind(socket: c.fd_t, address: ?*const c.sockaddr, address_len: c.socklen_t) c_int;
|
||||
pub extern "c" fn socketpair(domain: c_uint, sock_type: c_uint, protocol: c_uint, sv: *[2]c.fd_t) c_int;
|
||||
pub extern "c" fn listen(sockfd: c.fd_t, backlog: c_uint) c_int;
|
||||
pub extern "c" fn getsockname(sockfd: c.fd_t, noalias addr: *c.sockaddr, noalias addrlen: *c.socklen_t) c_int;
|
||||
pub extern "c" fn getpeername(sockfd: c.fd_t, noalias addr: *c.sockaddr, noalias addrlen: *c.socklen_t) c_int;
|
||||
pub extern "c" fn connect(sockfd: c.fd_t, sock_addr: *const c.sockaddr, addrlen: c.socklen_t) c_int;
|
||||
pub extern "c" fn accept(sockfd: c.fd_t, noalias addr: ?*c.sockaddr, noalias addrlen: ?*c.socklen_t) c_int;
|
||||
pub extern "c" fn accept4(sockfd: c.fd_t, noalias addr: ?*c.sockaddr, noalias addrlen: ?*c.socklen_t, flags: c_uint) c_int;
|
||||
pub extern "c" fn getsockopt(sockfd: c.fd_t, level: u32, optname: u32, noalias optval: ?*c_void, noalias optlen: *c.socklen_t) c_int;
|
||||
pub extern "c" fn setsockopt(sockfd: c.fd_t, level: u32, optname: u32, optval: ?*const c_void, optlen: c.socklen_t) c_int;
|
||||
pub extern "c" fn send(sockfd: c.fd_t, buf: *const c_void, len: usize, flags: u32) isize;
|
||||
pub extern "c" fn sendto(
|
||||
sockfd: fd_t,
|
||||
sockfd: c.fd_t,
|
||||
buf: *const c_void,
|
||||
len: usize,
|
||||
flags: u32,
|
||||
dest_addr: ?*const sockaddr,
|
||||
addrlen: socklen_t,
|
||||
dest_addr: ?*const c.sockaddr,
|
||||
addrlen: c.socklen_t,
|
||||
) isize;
|
||||
pub extern "c" fn sendmsg(sockfd: fd_t, msg: *const std.x.os.Socket.Message, flags: c_int) isize;
|
||||
pub extern "c" fn sendmsg(sockfd: c.fd_t, msg: *const std.x.os.Socket.Message, flags: c_int) isize;
|
||||
|
||||
pub extern "c" fn recv(sockfd: fd_t, arg1: ?*c_void, arg2: usize, arg3: c_int) isize;
|
||||
pub extern "c" fn recv(sockfd: c.fd_t, arg1: ?*c_void, arg2: usize, arg3: c_int) isize;
|
||||
pub extern "c" fn recvfrom(
|
||||
sockfd: fd_t,
|
||||
sockfd: c.fd_t,
|
||||
noalias buf: *c_void,
|
||||
len: usize,
|
||||
flags: u32,
|
||||
noalias src_addr: ?*sockaddr,
|
||||
noalias addrlen: ?*socklen_t,
|
||||
noalias src_addr: ?*c.sockaddr,
|
||||
noalias addrlen: ?*c.socklen_t,
|
||||
) isize;
|
||||
pub extern "c" fn recvmsg(sockfd: fd_t, msg: *std.x.os.Socket.Message, flags: c_int) isize;
|
||||
pub extern "c" fn recvmsg(sockfd: c.fd_t, msg: *std.x.os.Socket.Message, flags: c_int) isize;
|
||||
|
||||
pub usingnamespace switch (builtin.os.tag) {
|
||||
.netbsd => struct {
|
||||
pub const clock_getres = __clock_getres50;
|
||||
pub const clock_gettime = __clock_gettime50;
|
||||
pub const fstat = __fstat50;
|
||||
pub const getdents = __getdents30;
|
||||
pub const getrusage = __getrusage50;
|
||||
pub const gettimeofday = __gettimeofday50;
|
||||
pub const nanosleep = __nanosleep50;
|
||||
pub const sched_yield = __libc_thr_yield;
|
||||
pub const sigaction = __sigaction14;
|
||||
pub const sigaltstack = __sigaltstack14;
|
||||
pub const sigprocmask = __sigprocmask14;
|
||||
pub const socket = __socket30;
|
||||
pub const stat = __stat50;
|
||||
},
|
||||
.macos, .ios, .watchos, .tvos => struct {
|
||||
// XXX: close -> close$NOCANCEL
|
||||
// XXX: getdirentries -> _getdirentries64
|
||||
pub extern "c" fn clock_getres(clk_id: c_int, tp: *timespec) c_int;
|
||||
pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int;
|
||||
pub const fstat = _fstat;
|
||||
pub extern "c" fn getrusage(who: c_int, usage: *rusage) c_int;
|
||||
pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
|
||||
pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;
|
||||
pub extern "c" fn sched_yield() c_int;
|
||||
pub extern "c" fn sigaction(sig: c_int, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) c_int;
|
||||
pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
|
||||
pub extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
|
||||
pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *libc_stat) c_int;
|
||||
pub extern "c" fn sigfillset(set: ?*sigset_t) void;
|
||||
pub extern "c" fn alarm(seconds: c_uint) c_uint;
|
||||
pub extern "c" fn sigwait(set: ?*sigset_t, sig: ?*c_int) c_int;
|
||||
},
|
||||
.windows => struct {
|
||||
// TODO: copied the else case and removed the socket function (because its in ws2_32)
|
||||
// need to verify which of these is actually supported on windows
|
||||
pub extern "c" fn clock_getres(clk_id: c_int, tp: *timespec) c_int;
|
||||
pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int;
|
||||
pub extern "c" fn fstat(fd: fd_t, buf: *libc_stat) c_int;
|
||||
pub extern "c" fn getrusage(who: c_int, usage: *rusage) c_int;
|
||||
pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
|
||||
pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;
|
||||
pub extern "c" fn sched_yield() c_int;
|
||||
pub extern "c" fn sigaction(sig: c_int, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) c_int;
|
||||
pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
|
||||
pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *libc_stat) c_int;
|
||||
pub extern "c" fn sigfillset(set: ?*sigset_t) void;
|
||||
pub extern "c" fn alarm(seconds: c_uint) c_uint;
|
||||
pub extern "c" fn sigwait(set: ?*sigset_t, sig: ?*c_int) c_int;
|
||||
},
|
||||
else => struct {
|
||||
pub extern "c" fn clock_getres(clk_id: c_int, tp: *timespec) c_int;
|
||||
pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int;
|
||||
pub extern "c" fn fstat(fd: fd_t, buf: *libc_stat) c_int;
|
||||
pub extern "c" fn getrusage(who: c_int, usage: *rusage) c_int;
|
||||
pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
|
||||
pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;
|
||||
pub extern "c" fn sched_yield() c_int;
|
||||
pub extern "c" fn sigaction(sig: c_int, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) c_int;
|
||||
pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
|
||||
pub extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
|
||||
pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *libc_stat) c_int;
|
||||
pub extern "c" fn sigfillset(set: ?*sigset_t) void;
|
||||
pub extern "c" fn alarm(seconds: c_uint) c_uint;
|
||||
pub extern "c" fn sigwait(set: ?*sigset_t, sig: ?*c_int) c_int;
|
||||
},
|
||||
};
|
||||
pub extern "c" fn kill(pid: c.pid_t, sig: c_int) c_int;
|
||||
pub extern "c" fn getdirentries(fd: c.fd_t, buf_ptr: [*]u8, nbytes: usize, basep: *i64) isize;
|
||||
|
||||
pub extern "c" fn kill(pid: pid_t, sig: c_int) c_int;
|
||||
pub extern "c" fn getdirentries(fd: fd_t, buf_ptr: [*]u8, nbytes: usize, basep: *i64) isize;
|
||||
|
||||
pub extern "c" fn setuid(uid: uid_t) c_int;
|
||||
pub extern "c" fn setgid(gid: gid_t) c_int;
|
||||
pub extern "c" fn seteuid(euid: uid_t) c_int;
|
||||
pub extern "c" fn setegid(egid: gid_t) c_int;
|
||||
pub extern "c" fn setreuid(ruid: uid_t, euid: uid_t) c_int;
|
||||
pub extern "c" fn setregid(rgid: gid_t, egid: gid_t) c_int;
|
||||
pub extern "c" fn setresuid(ruid: uid_t, euid: uid_t, suid: uid_t) c_int;
|
||||
pub extern "c" fn setresgid(rgid: gid_t, egid: gid_t, sgid: gid_t) c_int;
|
||||
pub extern "c" fn setuid(uid: c.uid_t) c_int;
|
||||
pub extern "c" fn setgid(gid: c.gid_t) c_int;
|
||||
pub extern "c" fn seteuid(euid: c.uid_t) c_int;
|
||||
pub extern "c" fn setegid(egid: c.gid_t) c_int;
|
||||
pub extern "c" fn setreuid(ruid: c.uid_t, euid: c.uid_t) c_int;
|
||||
pub extern "c" fn setregid(rgid: c.gid_t, egid: c.gid_t) c_int;
|
||||
pub extern "c" fn setresuid(ruid: c.uid_t, euid: c.uid_t, suid: c.uid_t) c_int;
|
||||
pub extern "c" fn setresgid(rgid: c.gid_t, egid: c.gid_t, sgid: c.gid_t) c_int;
|
||||
|
||||
pub extern "c" fn malloc(usize) ?*c_void;
|
||||
pub extern "c" fn realloc(?*c_void, usize) ?*c_void;
|
||||
pub extern "c" fn free(?*c_void) void;
|
||||
|
||||
pub extern "c" fn futimes(fd: fd_t, times: *[2]timeval) c_int;
|
||||
pub extern "c" fn utimes(path: [*:0]const u8, times: *[2]timeval) c_int;
|
||||
pub extern "c" fn futimes(fd: c.fd_t, times: *[2]c.timeval) c_int;
|
||||
pub extern "c" fn utimes(path: [*:0]const u8, times: *[2]c.timeval) c_int;
|
||||
|
||||
pub extern "c" fn utimensat(dirfd: fd_t, pathname: [*:0]const u8, times: *[2]timespec, flags: u32) c_int;
|
||||
pub extern "c" fn futimens(fd: fd_t, times: *const [2]timespec) c_int;
|
||||
pub extern "c" fn utimensat(dirfd: c.fd_t, pathname: [*:0]const u8, times: *[2]c.timespec, flags: u32) c_int;
|
||||
pub extern "c" fn futimens(fd: c.fd_t, times: *const [2]c.timespec) c_int;
|
||||
|
||||
pub extern "c" fn pthread_create(noalias newthread: *pthread_t, noalias attr: ?*const pthread_attr_t, start_routine: fn (?*c_void) callconv(.C) ?*c_void, noalias arg: ?*c_void) E;
|
||||
pub extern "c" fn pthread_attr_init(attr: *pthread_attr_t) E;
|
||||
pub extern "c" fn pthread_attr_setstack(attr: *pthread_attr_t, stackaddr: *c_void, stacksize: usize) E;
|
||||
pub extern "c" fn pthread_attr_setstacksize(attr: *pthread_attr_t, stacksize: usize) E;
|
||||
pub extern "c" fn pthread_attr_setguardsize(attr: *pthread_attr_t, guardsize: usize) E;
|
||||
pub extern "c" fn pthread_attr_destroy(attr: *pthread_attr_t) E;
|
||||
pub extern "c" fn pthread_create(noalias newthread: *pthread_t, noalias attr: ?*const c.pthread_attr_t, start_routine: fn (?*c_void) callconv(.C) ?*c_void, noalias arg: ?*c_void) c.E;
|
||||
pub extern "c" fn pthread_attr_init(attr: *c.pthread_attr_t) c.E;
|
||||
pub extern "c" fn pthread_attr_setstack(attr: *c.pthread_attr_t, stackaddr: *c_void, stacksize: usize) c.E;
|
||||
pub extern "c" fn pthread_attr_setstacksize(attr: *c.pthread_attr_t, stacksize: usize) c.E;
|
||||
pub extern "c" fn pthread_attr_setguardsize(attr: *c.pthread_attr_t, guardsize: usize) c.E;
|
||||
pub extern "c" fn pthread_attr_destroy(attr: *c.pthread_attr_t) c.E;
|
||||
pub extern "c" fn pthread_self() pthread_t;
|
||||
pub extern "c" fn pthread_join(thread: pthread_t, arg_return: ?*?*c_void) E;
|
||||
pub extern "c" fn pthread_detach(thread: pthread_t) E;
|
||||
pub extern "c" fn pthread_join(thread: pthread_t, arg_return: ?*?*c_void) c.E;
|
||||
pub extern "c" fn pthread_detach(thread: pthread_t) c.E;
|
||||
pub extern "c" fn pthread_atfork(
|
||||
prepare: ?fn () callconv(.C) void,
|
||||
parent: ?fn () callconv(.C) void,
|
||||
child: ?fn () callconv(.C) void,
|
||||
) c_int;
|
||||
pub extern "c" fn pthread_key_create(key: *pthread_key_t, destructor: ?fn (value: *c_void) callconv(.C) void) E;
|
||||
pub extern "c" fn pthread_key_delete(key: pthread_key_t) E;
|
||||
pub extern "c" fn pthread_getspecific(key: pthread_key_t) ?*c_void;
|
||||
pub extern "c" fn pthread_setspecific(key: pthread_key_t, value: ?*c_void) c_int;
|
||||
pub extern "c" fn sem_init(sem: *sem_t, pshared: c_int, value: c_uint) c_int;
|
||||
pub extern "c" fn sem_destroy(sem: *sem_t) c_int;
|
||||
pub extern "c" fn sem_post(sem: *sem_t) c_int;
|
||||
pub extern "c" fn sem_wait(sem: *sem_t) c_int;
|
||||
pub extern "c" fn sem_trywait(sem: *sem_t) c_int;
|
||||
pub extern "c" fn sem_timedwait(sem: *sem_t, abs_timeout: *const timespec) c_int;
|
||||
pub extern "c" fn sem_getvalue(sem: *sem_t, sval: *c_int) c_int;
|
||||
pub extern "c" fn pthread_key_create(key: *c.pthread_key_t, destructor: ?fn (value: *c_void) callconv(.C) void) c.E;
|
||||
pub extern "c" fn pthread_key_delete(key: c.pthread_key_t) c.E;
|
||||
pub extern "c" fn pthread_getspecific(key: c.pthread_key_t) ?*c_void;
|
||||
pub extern "c" fn pthread_setspecific(key: c.pthread_key_t, value: ?*c_void) c_int;
|
||||
pub extern "c" fn sem_init(sem: *c.sem_t, pshared: c_int, value: c_uint) c_int;
|
||||
pub extern "c" fn sem_destroy(sem: *c.sem_t) c_int;
|
||||
pub extern "c" fn sem_post(sem: *c.sem_t) c_int;
|
||||
pub extern "c" fn sem_wait(sem: *c.sem_t) c_int;
|
||||
pub extern "c" fn sem_trywait(sem: *c.sem_t) c_int;
|
||||
pub extern "c" fn sem_timedwait(sem: *c.sem_t, abs_timeout: *const c.timespec) c_int;
|
||||
pub extern "c" fn sem_getvalue(sem: *c.sem_t, sval: *c_int) c_int;
|
||||
|
||||
pub extern "c" fn kqueue() c_int;
|
||||
pub extern "c" fn kevent(
|
||||
kq: c_int,
|
||||
changelist: [*]const Kevent,
|
||||
changelist: [*]const c.Kevent,
|
||||
nchanges: c_int,
|
||||
eventlist: [*]Kevent,
|
||||
eventlist: [*]c.Kevent,
|
||||
nevents: c_int,
|
||||
timeout: ?*const timespec,
|
||||
timeout: ?*const c.timespec,
|
||||
) c_int;
|
||||
|
||||
pub extern "c" fn getaddrinfo(
|
||||
noalias node: ?[*:0]const u8,
|
||||
noalias service: ?[*:0]const u8,
|
||||
noalias hints: ?*const addrinfo,
|
||||
noalias res: **addrinfo,
|
||||
) EAI;
|
||||
noalias hints: ?*const c.addrinfo,
|
||||
noalias res: **c.addrinfo,
|
||||
) c.EAI;
|
||||
|
||||
pub extern "c" fn freeaddrinfo(res: *addrinfo) void;
|
||||
pub extern "c" fn freeaddrinfo(res: *c.addrinfo) void;
|
||||
|
||||
pub extern "c" fn getnameinfo(
|
||||
noalias addr: *const sockaddr,
|
||||
addrlen: socklen_t,
|
||||
noalias addr: *const c.sockaddr,
|
||||
addrlen: c.socklen_t,
|
||||
noalias host: [*]u8,
|
||||
hostlen: socklen_t,
|
||||
hostlen: c.socklen_t,
|
||||
noalias serv: [*]u8,
|
||||
servlen: socklen_t,
|
||||
servlen: c.socklen_t,
|
||||
flags: u32,
|
||||
) EAI;
|
||||
) c.EAI;
|
||||
|
||||
pub extern "c" fn gai_strerror(errcode: EAI) [*:0]const u8;
|
||||
pub extern "c" fn gai_strerror(errcode: c.EAI) [*:0]const u8;
|
||||
|
||||
pub extern "c" fn poll(fds: [*]pollfd, nfds: nfds_t, timeout: c_int) c_int;
|
||||
pub extern "c" fn ppoll(fds: [*]pollfd, nfds: nfds_t, timeout: ?*const timespec, sigmask: ?*const sigset_t) c_int;
|
||||
pub extern "c" fn poll(fds: [*]c.pollfd, nfds: c.nfds_t, timeout: c_int) c_int;
|
||||
pub extern "c" fn ppoll(fds: [*]c.pollfd, nfds: c.nfds_t, timeout: ?*const c.timespec, sigmask: ?*const c.sigset_t) c_int;
|
||||
|
||||
pub extern "c" fn dn_expand(
|
||||
msg: [*:0]const u8,
|
||||
@ -333,25 +284,25 @@ pub extern "c" fn dn_expand(
|
||||
length: c_int,
|
||||
) c_int;
|
||||
|
||||
pub const PTHREAD_MUTEX_INITIALIZER = pthread_mutex_t{};
|
||||
pub extern "c" fn pthread_mutex_lock(mutex: *pthread_mutex_t) E;
|
||||
pub extern "c" fn pthread_mutex_unlock(mutex: *pthread_mutex_t) E;
|
||||
pub extern "c" fn pthread_mutex_trylock(mutex: *pthread_mutex_t) E;
|
||||
pub extern "c" fn pthread_mutex_destroy(mutex: *pthread_mutex_t) E;
|
||||
pub const PTHREAD_MUTEX_INITIALIZER = c.pthread_mutex_t{};
|
||||
pub extern "c" fn pthread_mutex_lock(mutex: *c.pthread_mutex_t) c.E;
|
||||
pub extern "c" fn pthread_mutex_unlock(mutex: *c.pthread_mutex_t) c.E;
|
||||
pub extern "c" fn pthread_mutex_trylock(mutex: *c.pthread_mutex_t) c.E;
|
||||
pub extern "c" fn pthread_mutex_destroy(mutex: *c.pthread_mutex_t) c.E;
|
||||
|
||||
pub const PTHREAD_COND_INITIALIZER = pthread_cond_t{};
|
||||
pub extern "c" fn pthread_cond_wait(noalias cond: *pthread_cond_t, noalias mutex: *pthread_mutex_t) E;
|
||||
pub extern "c" fn pthread_cond_timedwait(noalias cond: *pthread_cond_t, noalias mutex: *pthread_mutex_t, noalias abstime: *const timespec) E;
|
||||
pub extern "c" fn pthread_cond_signal(cond: *pthread_cond_t) E;
|
||||
pub extern "c" fn pthread_cond_broadcast(cond: *pthread_cond_t) E;
|
||||
pub extern "c" fn pthread_cond_destroy(cond: *pthread_cond_t) E;
|
||||
pub const PTHREAD_COND_INITIALIZER = c.pthread_cond_t{};
|
||||
pub extern "c" fn pthread_cond_wait(noalias cond: *c.pthread_cond_t, noalias mutex: *c.pthread_mutex_t) c.E;
|
||||
pub extern "c" fn pthread_cond_timedwait(noalias cond: *c.pthread_cond_t, noalias mutex: *c.pthread_mutex_t, noalias abstime: *const c.timespec) c.E;
|
||||
pub extern "c" fn pthread_cond_signal(cond: *c.pthread_cond_t) c.E;
|
||||
pub extern "c" fn pthread_cond_broadcast(cond: *c.pthread_cond_t) c.E;
|
||||
pub extern "c" fn pthread_cond_destroy(cond: *c.pthread_cond_t) c.E;
|
||||
|
||||
pub extern "c" fn pthread_rwlock_destroy(rwl: *pthread_rwlock_t) callconv(.C) E;
|
||||
pub extern "c" fn pthread_rwlock_rdlock(rwl: *pthread_rwlock_t) callconv(.C) E;
|
||||
pub extern "c" fn pthread_rwlock_wrlock(rwl: *pthread_rwlock_t) callconv(.C) E;
|
||||
pub extern "c" fn pthread_rwlock_tryrdlock(rwl: *pthread_rwlock_t) callconv(.C) E;
|
||||
pub extern "c" fn pthread_rwlock_trywrlock(rwl: *pthread_rwlock_t) callconv(.C) E;
|
||||
pub extern "c" fn pthread_rwlock_unlock(rwl: *pthread_rwlock_t) callconv(.C) E;
|
||||
pub extern "c" fn pthread_rwlock_destroy(rwl: *c.pthread_rwlock_t) callconv(.C) c.E;
|
||||
pub extern "c" fn pthread_rwlock_rdlock(rwl: *c.pthread_rwlock_t) callconv(.C) c.E;
|
||||
pub extern "c" fn pthread_rwlock_wrlock(rwl: *c.pthread_rwlock_t) callconv(.C) c.E;
|
||||
pub extern "c" fn pthread_rwlock_tryrdlock(rwl: *c.pthread_rwlock_t) callconv(.C) c.E;
|
||||
pub extern "c" fn pthread_rwlock_trywrlock(rwl: *c.pthread_rwlock_t) callconv(.C) c.E;
|
||||
pub extern "c" fn pthread_rwlock_unlock(rwl: *c.pthread_rwlock_t) callconv(.C) c.E;
|
||||
|
||||
pub const pthread_t = *opaque {};
|
||||
pub const FILE = opaque {};
|
||||
@ -367,8 +318,8 @@ pub extern "c" fn fdatasync(fd: c_int) c_int;
|
||||
|
||||
pub extern "c" fn prctl(option: c_int, ...) c_int;
|
||||
|
||||
pub extern "c" fn getrlimit(resource: rlimit_resource, rlim: *rlimit) c_int;
|
||||
pub extern "c" fn setrlimit(resource: rlimit_resource, rlim: *const rlimit) c_int;
|
||||
pub extern "c" fn getrlimit(resource: c.rlimit_resource, rlim: *c.rlimit) c_int;
|
||||
pub extern "c" fn setrlimit(resource: c.rlimit_resource, rlim: *const c.rlimit) c_int;
|
||||
|
||||
pub extern "c" fn fmemopen(noalias buf: ?*c_void, size: usize, noalias mode: [*:0]const u8) ?*FILE;
|
||||
|
||||
@ -377,9 +328,9 @@ pub extern "c" fn openlog(ident: [*:0]const u8, logopt: c_int, facility: c_int)
|
||||
pub extern "c" fn closelog() void;
|
||||
pub extern "c" fn setlogmask(maskpri: c_int) c_int;
|
||||
|
||||
pub const max_align_t = if (std.Target.current.abi == .msvc)
|
||||
pub const max_align_t = if (builtin.abi == .msvc)
|
||||
f64
|
||||
else if (std.Target.current.isDarwin())
|
||||
else if (builtin.target.isDarwin())
|
||||
c_longdouble
|
||||
else
|
||||
extern struct {
|
||||
|
||||
1763
lib/std/c/darwin.zig
1763
lib/std/c/darwin.zig
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
1303
lib/std/c/haiku.zig
1303
lib/std/c/haiku.zig
File diff suppressed because it is too large
Load Diff
@ -1,3 +1,6 @@
|
||||
const std = @import("std");
|
||||
const maxInt = std.math.maxInt;
|
||||
|
||||
pub const pthread_mutex_t = extern struct {
|
||||
inner: usize = ~@as(usize, 0),
|
||||
};
|
||||
@ -5,5 +8,5 @@ pub const pthread_cond_t = extern struct {
|
||||
inner: usize = ~@as(usize, 0),
|
||||
};
|
||||
pub const pthread_rwlock_t = extern struct {
|
||||
ptr: usize = std.math.maxInt(usize),
|
||||
ptr: usize = maxInt(usize),
|
||||
};
|
||||
|
||||
@ -1,11 +1,106 @@
|
||||
const std = @import("../std.zig");
|
||||
const builtin = @import("builtin");
|
||||
const maxInt = std.math.maxInt;
|
||||
const abi = std.Target.current.abi;
|
||||
const arch = std.Target.current.cpu.arch;
|
||||
const os_tag = std.Target.current.os.tag;
|
||||
usingnamespace std.c;
|
||||
const native_abi = builtin.abi;
|
||||
const native_arch = builtin.cpu.arch;
|
||||
const linux = std.os.linux;
|
||||
const iovec = std.os.iovec;
|
||||
const iovec_const = std.os.iovec_const;
|
||||
const FILE = std.c.FILE;
|
||||
|
||||
pub const _errno = switch (abi) {
|
||||
pub const AF = linux.AF;
|
||||
pub const ARCH = linux.ARCH;
|
||||
pub const AT = linux.AT;
|
||||
pub const CLOCK = linux.CLOCK;
|
||||
pub const CPU_COUNT = linux.CPU_COUNT;
|
||||
pub const E = linux.E;
|
||||
pub const Elf_Symndx = linux.Elf_Symndx;
|
||||
pub const F = linux.F;
|
||||
pub const FD_CLOEXEC = linux.FD_CLOEXEC;
|
||||
pub const F_OK = linux.F_OK;
|
||||
pub const Flock = linux.Flock;
|
||||
pub const HOST_NAME_MAX = linux.HOST_NAME_MAX;
|
||||
pub const IFNAMESIZE = linux.IFNAMESIZE;
|
||||
pub const IOV_MAX = linux.IOV_MAX;
|
||||
pub const IPPROTO = linux.IPPROTO;
|
||||
pub const LOCK = linux.LOCK;
|
||||
pub const MADV = linux.MADV;
|
||||
pub const MAP = struct {
|
||||
pub usingnamespace linux.MAP;
|
||||
/// Only used by libc to communicate failure.
|
||||
pub const FAILED = @intToPtr(*c_void, maxInt(usize));
|
||||
};
|
||||
pub const MMAP2_UNIT = linux.MMAP2_UNIT;
|
||||
pub const MSG = linux.MSG;
|
||||
pub const NAME_MAX = linux.NAME_MAX;
|
||||
pub const O = linux.O;
|
||||
pub const PATH_MAX = linux.PATH_MAX;
|
||||
pub const POLL = linux.POLL;
|
||||
pub const PROT = linux.PROT;
|
||||
pub const REG = linux.REG;
|
||||
pub const RLIM = linux.RLIM;
|
||||
pub const R_OK = linux.R_OK;
|
||||
pub const S = linux.S;
|
||||
pub const SA = linux.SA;
|
||||
pub const SC = linux.SC;
|
||||
pub const SEEK = linux.SEEK;
|
||||
pub const SHUT = linux.SHUT;
|
||||
pub const SIG = linux.SIG;
|
||||
pub const SIOCGIFINDEX = linux.SIOCGIFINDEX;
|
||||
pub const SO = linux.SO;
|
||||
pub const SOCK = linux.SOCK;
|
||||
pub const SOL = linux.SOL;
|
||||
pub const STDERR_FILENO = linux.STDERR_FILENO;
|
||||
pub const STDIN_FILENO = linux.STDIN_FILENO;
|
||||
pub const STDOUT_FILENO = linux.STDOUT_FILENO;
|
||||
pub const SYS = linux.SYS;
|
||||
pub const Sigaction = linux.Sigaction;
|
||||
pub const TCP = linux.TCP;
|
||||
pub const VDSO = linux.VDSO;
|
||||
pub const W = linux.W;
|
||||
pub const W_OK = linux.W_OK;
|
||||
pub const X_OK = linux.X_OK;
|
||||
pub const addrinfo = linux.addrinfo;
|
||||
pub const blkcnt_t = linux.blkcnt_t;
|
||||
pub const blksize_t = linux.blksize_t;
|
||||
pub const clock_t = linux.clock_t;
|
||||
pub const cpu_set_t = linux.cpu_set_t;
|
||||
pub const dev_t = linux.dev_t;
|
||||
pub const dl_phdr_info = linux.dl_phdr_info;
|
||||
pub const empty_sigset = linux.empty_sigset;
|
||||
pub const epoll_event = linux.epoll_event;
|
||||
pub const fd_t = linux.fd_t;
|
||||
pub const gid_t = linux.gid_t;
|
||||
pub const ifreq = linux.ifreq;
|
||||
pub const ino_t = linux.ino_t;
|
||||
pub const mcontext_t = linux.mcontext_t;
|
||||
pub const mode_t = linux.mode_t;
|
||||
pub const msghdr = linux.msghdr;
|
||||
pub const msghdr_const = linux.msghdr_const;
|
||||
pub const nfds_t = linux.nfds_t;
|
||||
pub const nlink_t = linux.nlink_t;
|
||||
pub const off_t = linux.off_t;
|
||||
pub const pid_t = linux.pid_t;
|
||||
pub const pollfd = linux.pollfd;
|
||||
pub const rlim_t = linux.rlim_t;
|
||||
pub const rlimit = linux.rlimit;
|
||||
pub const rlimit_resource = linux.rlimit_resource;
|
||||
pub const siginfo_t = linux.siginfo_t;
|
||||
pub const sigset_t = linux.sigset_t;
|
||||
pub const sockaddr = linux.sockaddr;
|
||||
pub const socklen_t = linux.socklen_t;
|
||||
pub const stack_t = linux.stack_t;
|
||||
pub const time_t = linux.time_t;
|
||||
pub const timespec = linux.timespec;
|
||||
pub const timeval = linux.timeval;
|
||||
pub const timezone = linux.timezone;
|
||||
pub const ucontext_t = linux.ucontext_t;
|
||||
pub const uid_t = linux.uid_t;
|
||||
pub const user_desc = linux.user_desc;
|
||||
pub const utsname = linux.utsname;
|
||||
pub const PR = linux.PR;
|
||||
|
||||
pub const _errno = switch (native_abi) {
|
||||
.android => struct {
|
||||
extern "c" var __errno: c_int;
|
||||
fn getErrno() *c_int {
|
||||
@ -17,22 +112,92 @@ pub const _errno = switch (abi) {
|
||||
}.__errno_location,
|
||||
};
|
||||
|
||||
pub const MAP_FAILED = @intToPtr(*c_void, maxInt(usize));
|
||||
pub const Stat = switch (native_arch) {
|
||||
.sparcv9 => extern struct {
|
||||
dev: u64,
|
||||
ino: ino_t,
|
||||
mode: u32,
|
||||
nlink: usize,
|
||||
|
||||
pub const AI_PASSIVE = 0x01;
|
||||
pub const AI_CANONNAME = 0x02;
|
||||
pub const AI_NUMERICHOST = 0x04;
|
||||
pub const AI_V4MAPPED = 0x08;
|
||||
pub const AI_ALL = 0x10;
|
||||
pub const AI_ADDRCONFIG = 0x20;
|
||||
pub const AI_NUMERICSERV = 0x400;
|
||||
uid: u32,
|
||||
gid: u32,
|
||||
rdev: u64,
|
||||
__pad0: u32,
|
||||
|
||||
pub const NI_NUMERICHOST = 0x01;
|
||||
pub const NI_NUMERICSERV = 0x02;
|
||||
pub const NI_NOFQDN = 0x04;
|
||||
pub const NI_NAMEREQD = 0x08;
|
||||
pub const NI_DGRAM = 0x10;
|
||||
pub const NI_NUMERICSCOPE = 0x100;
|
||||
size: off_t,
|
||||
blksize: isize,
|
||||
blocks: i64,
|
||||
|
||||
atim: timespec,
|
||||
mtim: timespec,
|
||||
ctim: timespec,
|
||||
__unused: [2]isize,
|
||||
|
||||
pub fn atime(self: @This()) timespec {
|
||||
return self.atim;
|
||||
}
|
||||
|
||||
pub fn mtime(self: @This()) timespec {
|
||||
return self.mtim;
|
||||
}
|
||||
|
||||
pub fn ctime(self: @This()) timespec {
|
||||
return self.ctim;
|
||||
}
|
||||
},
|
||||
.mips, .mipsel => extern struct {
|
||||
dev: dev_t,
|
||||
__pad0: [2]u32,
|
||||
ino: ino_t,
|
||||
mode: mode_t,
|
||||
nlink: nlink_t,
|
||||
uid: uid_t,
|
||||
gid: gid_t,
|
||||
rdev: dev_t,
|
||||
__pad1: [2]u32,
|
||||
size: off_t,
|
||||
atim: timespec,
|
||||
mtim: timespec,
|
||||
ctim: timespec,
|
||||
blksize: blksize_t,
|
||||
__pad3: u32,
|
||||
blocks: blkcnt_t,
|
||||
__pad4: [14]u32,
|
||||
|
||||
pub fn atime(self: @This()) timespec {
|
||||
return self.atim;
|
||||
}
|
||||
|
||||
pub fn mtime(self: @This()) timespec {
|
||||
return self.mtim;
|
||||
}
|
||||
|
||||
pub fn ctime(self: @This()) timespec {
|
||||
return self.ctim;
|
||||
}
|
||||
},
|
||||
|
||||
else => std.os.linux.Stat, // libc stat is the same as kernel stat.
|
||||
};
|
||||
|
||||
pub const AI = struct {
|
||||
pub const PASSIVE = 0x01;
|
||||
pub const CANONNAME = 0x02;
|
||||
pub const NUMERICHOST = 0x04;
|
||||
pub const V4MAPPED = 0x08;
|
||||
pub const ALL = 0x10;
|
||||
pub const ADDRCONFIG = 0x20;
|
||||
pub const NUMERICSERV = 0x400;
|
||||
};
|
||||
|
||||
pub const NI = struct {
|
||||
pub const NUMERICHOST = 0x01;
|
||||
pub const NUMERICSERV = 0x02;
|
||||
pub const NOFQDN = 0x04;
|
||||
pub const NAMEREQD = 0x08;
|
||||
pub const DGRAM = 0x10;
|
||||
pub const NUMERICSCOPE = 0x100;
|
||||
};
|
||||
|
||||
pub const EAI = enum(c_int) {
|
||||
BADFLAGS = -1,
|
||||
@ -60,8 +225,8 @@ pub const EAI = enum(c_int) {
|
||||
|
||||
pub extern "c" fn fallocate64(fd: fd_t, mode: c_int, offset: off_t, len: off_t) c_int;
|
||||
pub extern "c" fn fopen64(noalias filename: [*:0]const u8, noalias modes: [*:0]const u8) ?*FILE;
|
||||
pub extern "c" fn fstat64(fd: fd_t, buf: *libc_stat) c_int;
|
||||
pub extern "c" fn fstatat64(dirfd: fd_t, path: [*:0]const u8, stat_buf: *libc_stat, flags: u32) c_int;
|
||||
pub extern "c" fn fstat64(fd: fd_t, buf: *Stat) c_int;
|
||||
pub extern "c" fn fstatat64(dirfd: fd_t, path: [*:0]const u8, stat_buf: *Stat, flags: u32) c_int;
|
||||
pub extern "c" fn ftruncate64(fd: c_int, length: off_t) c_int;
|
||||
pub extern "c" fn getrlimit64(resource: rlimit_resource, rlim: *rlimit) c_int;
|
||||
pub extern "c" fn lseek64(fd: fd_t, offset: i64, whence: c_int) i64;
|
||||
@ -137,7 +302,7 @@ pub const pthread_mutex_t = extern struct {
|
||||
pub const pthread_cond_t = extern struct {
|
||||
size: [__SIZEOF_PTHREAD_COND_T]u8 align(@alignOf(usize)) = [_]u8{0} ** __SIZEOF_PTHREAD_COND_T,
|
||||
};
|
||||
pub const pthread_rwlock_t = switch (abi) {
|
||||
pub const pthread_rwlock_t = switch (native_abi) {
|
||||
.android => switch (@sizeOf(usize)) {
|
||||
4 => extern struct {
|
||||
lock: std.c.pthread_mutex_t = std.c.PTHREAD_MUTEX_INITIALIZER,
|
||||
@ -168,11 +333,11 @@ pub const sem_t = extern struct {
|
||||
};
|
||||
|
||||
const __SIZEOF_PTHREAD_COND_T = 48;
|
||||
const __SIZEOF_PTHREAD_MUTEX_T = if (os_tag == .fuchsia) 40 else switch (abi) {
|
||||
const __SIZEOF_PTHREAD_MUTEX_T = switch (native_abi) {
|
||||
.musl, .musleabi, .musleabihf => if (@sizeOf(usize) == 8) 40 else 24,
|
||||
.gnu, .gnuabin32, .gnuabi64, .gnueabi, .gnueabihf, .gnux32 => switch (arch) {
|
||||
.gnu, .gnuabin32, .gnuabi64, .gnueabi, .gnueabihf, .gnux32 => switch (native_arch) {
|
||||
.aarch64 => 48,
|
||||
.x86_64 => if (abi == .gnux32) 40 else 32,
|
||||
.x86_64 => if (native_abi == .gnux32) 40 else 32,
|
||||
.mips64, .powerpc64, .powerpc64le, .sparcv9 => 40,
|
||||
else => if (@sizeOf(usize) == 8) 40 else 24,
|
||||
},
|
||||
@ -184,9 +349,11 @@ const __SIZEOF_SEM_T = 4 * @sizeOf(usize);
|
||||
pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8) E;
|
||||
pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E;
|
||||
|
||||
pub const RTLD_LAZY = 1;
|
||||
pub const RTLD_NOW = 2;
|
||||
pub const RTLD_NOLOAD = 4;
|
||||
pub const RTLD_NODELETE = 4096;
|
||||
pub const RTLD_GLOBAL = 256;
|
||||
pub const RTLD_LOCAL = 0;
|
||||
pub const RTLD = struct {
|
||||
pub const LAZY = 1;
|
||||
pub const NOW = 2;
|
||||
pub const NOLOAD = 4;
|
||||
pub const NODELETE = 4096;
|
||||
pub const GLOBAL = 256;
|
||||
pub const LOCAL = 0;
|
||||
};
|
||||
|
||||
1399
lib/std/c/netbsd.zig
1399
lib/std/c/netbsd.zig
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,6 @@
|
||||
usingnamespace @import("../os/bits.zig");
|
||||
const std = @import("../std.zig");
|
||||
const wasi = std.os.wasi;
|
||||
const FDFLAG = wasi.FDFLAG;
|
||||
|
||||
extern threadlocal var errno: c_int;
|
||||
|
||||
@ -6,12 +8,25 @@ pub fn _errno() *c_int {
|
||||
return &errno;
|
||||
}
|
||||
|
||||
pub const fd_t = wasi.fd_t;
|
||||
pub const pid_t = c_int;
|
||||
pub const uid_t = u32;
|
||||
pub const gid_t = u32;
|
||||
pub const off_t = i64;
|
||||
pub const ino_t = wasi.ino_t;
|
||||
pub const mode_t = wasi.mode_t;
|
||||
pub const time_t = wasi.time_t;
|
||||
pub const timespec = wasi.timespec;
|
||||
pub const STDERR_FILENO = wasi.STDERR_FILENO;
|
||||
pub const STDIN_FILENO = wasi.STDIN_FILENO;
|
||||
pub const STDOUT_FILENO = wasi.STDOUT_FILENO;
|
||||
pub const E = wasi.E;
|
||||
pub const CLOCK = wasi.CLOCK;
|
||||
pub const S = wasi.S;
|
||||
pub const IOV_MAX = wasi.IOV_MAX;
|
||||
pub const AT = wasi.AT;
|
||||
|
||||
pub const libc_stat = extern struct {
|
||||
pub const Stat = extern struct {
|
||||
dev: i32,
|
||||
ino: ino_t,
|
||||
nlink: u64,
|
||||
@ -53,3 +68,33 @@ pub const libc_stat = extern struct {
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
/// Derived from
|
||||
/// https://github.com/WebAssembly/wasi-libc/blob/main/expected/wasm32-wasi/predefined-macros.txt
|
||||
pub const O = struct {
|
||||
pub const ACCMODE = (EXEC | RDWR | SEARCH);
|
||||
pub const APPEND = FDFLAG.APPEND;
|
||||
pub const CLOEXEC = (0);
|
||||
pub const CREAT = ((1 << 0) << 12); // = __WASI_OFLAGS_CREAT << 12
|
||||
pub const DIRECTORY = ((1 << 1) << 12); // = __WASI_OFLAGS_DIRECTORY << 12
|
||||
pub const DSYNC = FDFLAG.DSYNC;
|
||||
pub const EXCL = ((1 << 2) << 12); // = __WASI_OFLAGS_EXCL << 12
|
||||
pub const EXEC = (0x02000000);
|
||||
pub const NOCTTY = (0);
|
||||
pub const NOFOLLOW = (0x01000000);
|
||||
pub const NONBLOCK = (1 << FDFLAG.NONBLOCK);
|
||||
pub const RDONLY = (0x04000000);
|
||||
pub const RDWR = (RDONLY | WRONLY);
|
||||
pub const RSYNC = (1 << FDFLAG.RSYNC);
|
||||
pub const SEARCH = (0x08000000);
|
||||
pub const SYNC = (1 << FDFLAG.SYNC);
|
||||
pub const TRUNC = ((1 << 3) << 12); // = __WASI_OFLAGS_TRUNC << 12
|
||||
pub const TTY_INIT = (0);
|
||||
pub const WRONLY = (0x10000000);
|
||||
};
|
||||
|
||||
pub const SEEK = struct {
|
||||
pub const SET: wasi.whence_t = .SET;
|
||||
pub const CUR: wasi.whence_t = .CUR;
|
||||
pub const END: wasi.whence_t = .END;
|
||||
};
|
||||
|
||||
@ -1,3 +1,247 @@
|
||||
//! The reference for these types and values is Microsoft Windows's ucrt (Universal C RunTime).
|
||||
const std = @import("../std.zig");
|
||||
const ws2_32 = std.os.windows.ws2_32;
|
||||
const windows = std.os.windows;
|
||||
|
||||
pub extern "c" fn _errno() *c_int;
|
||||
|
||||
pub extern "c" fn _msize(memblock: ?*c_void) usize;
|
||||
|
||||
// TODO: copied the else case and removed the socket function (because its in ws2_32)
|
||||
// need to verify which of these is actually supported on windows
|
||||
pub extern "c" fn clock_getres(clk_id: c_int, tp: *timespec) c_int;
|
||||
pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int;
|
||||
pub extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int;
|
||||
pub extern "c" fn getrusage(who: c_int, usage: *rusage) c_int;
|
||||
pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
|
||||
pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;
|
||||
pub extern "c" fn sched_yield() c_int;
|
||||
pub extern "c" fn sigaction(sig: c_int, noalias act: ?*const Sigaction, noalias oact: ?*Sigaction) c_int;
|
||||
pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
|
||||
pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *Stat) c_int;
|
||||
pub extern "c" fn sigfillset(set: ?*sigset_t) void;
|
||||
pub extern "c" fn alarm(seconds: c_uint) c_uint;
|
||||
pub extern "c" fn sigwait(set: ?*sigset_t, sig: ?*c_int) c_int;
|
||||
|
||||
pub const fd_t = windows.HANDLE;
|
||||
pub const ino_t = windows.LARGE_INTEGER;
|
||||
pub const pid_t = windows.HANDLE;
|
||||
pub const mode_t = u0;
|
||||
|
||||
pub const PATH_MAX = 260;
|
||||
|
||||
pub const time_t = c_longlong;
|
||||
|
||||
pub const timespec = extern struct {
|
||||
tv_sec: time_t,
|
||||
tv_nsec: c_long,
|
||||
};
|
||||
|
||||
pub const timeval = extern struct {
|
||||
tv_sec: c_long,
|
||||
tv_usec: c_long,
|
||||
};
|
||||
|
||||
pub const Stat = @compileError("TODO windows Stat definition");
|
||||
|
||||
pub const sig_atomic_t = c_int;
|
||||
|
||||
pub const sigset_t = @compileError("TODO windows sigset_t definition");
|
||||
pub const Sigaction = @compileError("TODO windows Sigaction definition");
|
||||
pub const timezone = @compileError("TODO windows timezone definition");
|
||||
pub const rusage = @compileError("TODO windows rusage definition");
|
||||
|
||||
/// maximum signal number + 1
|
||||
pub const NSIG = 23;
|
||||
|
||||
/// Signal types
|
||||
pub const SIG = struct {
|
||||
/// interrupt
|
||||
pub const INT = 2;
|
||||
/// illegal instruction - invalid function image
|
||||
pub const ILL = 4;
|
||||
/// floating point exception
|
||||
pub const FPE = 8;
|
||||
/// segment violation
|
||||
pub const SEGV = 11;
|
||||
/// Software termination signal from kill
|
||||
pub const TERM = 15;
|
||||
/// Ctrl-Break sequence
|
||||
pub const BREAK = 21;
|
||||
/// abnormal termination triggered by abort call
|
||||
pub const ABRT = 22;
|
||||
/// SIGABRT compatible with other platforms, same as SIGABRT
|
||||
pub const ABRT_COMPAT = 6;
|
||||
|
||||
// Signal action codes
|
||||
/// default signal action
|
||||
pub const DFL = 0;
|
||||
/// ignore signal
|
||||
pub const IGN = 1;
|
||||
/// return current value
|
||||
pub const GET = 2;
|
||||
/// signal gets error
|
||||
pub const SGE = 3;
|
||||
/// acknowledge
|
||||
pub const ACK = 4;
|
||||
/// Signal error value (returned by signal call on error)
|
||||
pub const ERR = -1;
|
||||
};
|
||||
|
||||
pub const SEEK = struct {
|
||||
pub const SET = 0;
|
||||
pub const CUR = 1;
|
||||
pub const END = 2;
|
||||
};
|
||||
|
||||
pub const E = enum(u16) {
|
||||
/// No error occurred.
|
||||
SUCCESS = 0,
|
||||
PERM = 1,
|
||||
NOENT = 2,
|
||||
SRCH = 3,
|
||||
INTR = 4,
|
||||
IO = 5,
|
||||
NXIO = 6,
|
||||
@"2BIG" = 7,
|
||||
NOEXEC = 8,
|
||||
BADF = 9,
|
||||
CHILD = 10,
|
||||
AGAIN = 11,
|
||||
NOMEM = 12,
|
||||
ACCES = 13,
|
||||
FAULT = 14,
|
||||
BUSY = 16,
|
||||
EXIST = 17,
|
||||
XDEV = 18,
|
||||
NODEV = 19,
|
||||
NOTDIR = 20,
|
||||
ISDIR = 21,
|
||||
NFILE = 23,
|
||||
MFILE = 24,
|
||||
NOTTY = 25,
|
||||
FBIG = 27,
|
||||
NOSPC = 28,
|
||||
SPIPE = 29,
|
||||
ROFS = 30,
|
||||
MLINK = 31,
|
||||
PIPE = 32,
|
||||
DOM = 33,
|
||||
/// Also means `DEADLOCK`.
|
||||
DEADLK = 36,
|
||||
NAMETOOLONG = 38,
|
||||
NOLCK = 39,
|
||||
NOSYS = 40,
|
||||
NOTEMPTY = 41,
|
||||
|
||||
INVAL = 22,
|
||||
RANGE = 34,
|
||||
ILSEQ = 42,
|
||||
|
||||
// POSIX Supplement
|
||||
ADDRINUSE = 100,
|
||||
ADDRNOTAVAIL = 101,
|
||||
AFNOSUPPORT = 102,
|
||||
ALREADY = 103,
|
||||
BADMSG = 104,
|
||||
CANCELED = 105,
|
||||
CONNABORTED = 106,
|
||||
CONNREFUSED = 107,
|
||||
CONNRESET = 108,
|
||||
DESTADDRREQ = 109,
|
||||
HOSTUNREACH = 110,
|
||||
IDRM = 111,
|
||||
INPROGRESS = 112,
|
||||
ISCONN = 113,
|
||||
LOOP = 114,
|
||||
MSGSIZE = 115,
|
||||
NETDOWN = 116,
|
||||
NETRESET = 117,
|
||||
NETUNREACH = 118,
|
||||
NOBUFS = 119,
|
||||
NODATA = 120,
|
||||
NOLINK = 121,
|
||||
NOMSG = 122,
|
||||
NOPROTOOPT = 123,
|
||||
NOSR = 124,
|
||||
NOSTR = 125,
|
||||
NOTCONN = 126,
|
||||
NOTRECOVERABLE = 127,
|
||||
NOTSOCK = 128,
|
||||
NOTSUP = 129,
|
||||
OPNOTSUPP = 130,
|
||||
OTHER = 131,
|
||||
OVERFLOW = 132,
|
||||
OWNERDEAD = 133,
|
||||
PROTO = 134,
|
||||
PROTONOSUPPORT = 135,
|
||||
PROTOTYPE = 136,
|
||||
TIME = 137,
|
||||
TIMEDOUT = 138,
|
||||
TXTBSY = 139,
|
||||
WOULDBLOCK = 140,
|
||||
DQUOT = 10069,
|
||||
_,
|
||||
};
|
||||
|
||||
pub const STRUNCATE = 80;
|
||||
|
||||
pub const F_OK = 0;
|
||||
|
||||
/// Remove directory instead of unlinking file
|
||||
pub const AT = struct {
|
||||
pub const REMOVEDIR = 0x200;
|
||||
};
|
||||
|
||||
pub const in_port_t = u16;
|
||||
pub const sa_family_t = ws2_32.ADDRESS_FAMILY;
|
||||
pub const socklen_t = ws2_32.socklen_t;
|
||||
|
||||
pub const sockaddr = ws2_32.sockaddr;
|
||||
|
||||
pub const in6_addr = [16]u8;
|
||||
pub const in_addr = u32;
|
||||
|
||||
pub const addrinfo = ws2_32.addrinfo;
|
||||
pub const AF = ws2_32.AF;
|
||||
pub const MSG = ws2_32.MSG;
|
||||
pub const SOCK = ws2_32.SOCK;
|
||||
pub const TCP = ws2_32.TCP;
|
||||
pub const IPPROTO = ws2_32.IPPROTO;
|
||||
pub const BTHPROTO_RFCOMM = ws2_32.BTHPROTO_RFCOMM;
|
||||
|
||||
pub const nfds_t = c_ulong;
|
||||
pub const pollfd = ws2_32.pollfd;
|
||||
pub const POLL = ws2_32.POLL;
|
||||
pub const SOL = ws2_32.SOL;
|
||||
pub const SO = ws2_32.SO;
|
||||
pub const PVD_CONFIG = ws2_32.PVD_CONFIG;
|
||||
|
||||
pub const O = struct {
|
||||
pub const RDONLY = 0o0;
|
||||
pub const WRONLY = 0o1;
|
||||
pub const RDWR = 0o2;
|
||||
|
||||
pub const CREAT = 0o100;
|
||||
pub const EXCL = 0o200;
|
||||
pub const NOCTTY = 0o400;
|
||||
pub const TRUNC = 0o1000;
|
||||
pub const APPEND = 0o2000;
|
||||
pub const NONBLOCK = 0o4000;
|
||||
pub const DSYNC = 0o10000;
|
||||
pub const SYNC = 0o4010000;
|
||||
pub const RSYNC = 0o4010000;
|
||||
pub const DIRECTORY = 0o200000;
|
||||
pub const NOFOLLOW = 0o400000;
|
||||
pub const CLOEXEC = 0o2000000;
|
||||
|
||||
pub const ASYNC = 0o20000;
|
||||
pub const DIRECT = 0o40000;
|
||||
pub const LARGEFILE = 0;
|
||||
pub const NOATIME = 0o1000000;
|
||||
pub const PATH = 0o10000000;
|
||||
pub const TMPFILE = 0o20200000;
|
||||
pub const NDELAY = NONBLOCK;
|
||||
};
|
||||
|
||||
pub const IFNAMESIZE = 30;
|
||||
|
||||
@ -7,6 +7,7 @@ const os = std.os;
|
||||
const process = std.process;
|
||||
const File = std.fs.File;
|
||||
const windows = os.windows;
|
||||
const linux = os.linux;
|
||||
const mem = std.mem;
|
||||
const math = std.math;
|
||||
const debug = std.debug;
|
||||
@ -160,7 +161,7 @@ pub const ChildProcess = struct {
|
||||
self.cleanupStreams();
|
||||
return term;
|
||||
}
|
||||
try os.kill(self.pid, os.SIGTERM);
|
||||
try os.kill(self.pid, os.SIG.TERM);
|
||||
self.waitUnwrapped();
|
||||
return self.term.?;
|
||||
}
|
||||
@ -189,8 +190,8 @@ pub const ChildProcess = struct {
|
||||
max_output_bytes: usize,
|
||||
) !void {
|
||||
var poll_fds = [_]os.pollfd{
|
||||
.{ .fd = child.stdout.?.handle, .events = os.POLLIN, .revents = undefined },
|
||||
.{ .fd = child.stderr.?.handle, .events = os.POLLIN, .revents = undefined },
|
||||
.{ .fd = child.stdout.?.handle, .events = os.POLL.IN, .revents = undefined },
|
||||
.{ .fd = child.stderr.?.handle, .events = os.POLL.IN, .revents = undefined },
|
||||
};
|
||||
|
||||
var dead_fds: usize = 0;
|
||||
@ -199,7 +200,7 @@ pub const ChildProcess = struct {
|
||||
// of space an ArrayList will allocate grows exponentially.
|
||||
const bump_amt = 512;
|
||||
|
||||
const err_mask = os.POLLERR | os.POLLNVAL | os.POLLHUP;
|
||||
const err_mask = os.POLL.ERR | os.POLL.NVAL | os.POLL.HUP;
|
||||
|
||||
while (dead_fds < poll_fds.len) {
|
||||
const events = try os.poll(&poll_fds, std.math.maxInt(i32));
|
||||
@ -209,9 +210,9 @@ pub const ChildProcess = struct {
|
||||
var remove_stderr = false;
|
||||
// Try reading whatever is available before checking the error
|
||||
// conditions.
|
||||
// It's still possible to read after a POLLHUP is received, always
|
||||
// It's still possible to read after a POLL.HUP is received, always
|
||||
// check if there's some data waiting to be read first.
|
||||
if (poll_fds[0].revents & os.POLLIN != 0) {
|
||||
if (poll_fds[0].revents & os.POLL.IN != 0) {
|
||||
// stdout is ready.
|
||||
const new_capacity = std.math.min(stdout.items.len + bump_amt, max_output_bytes);
|
||||
try stdout.ensureCapacity(new_capacity);
|
||||
@ -226,7 +227,7 @@ pub const ChildProcess = struct {
|
||||
remove_stdout = poll_fds[0].revents & err_mask != 0;
|
||||
}
|
||||
|
||||
if (poll_fds[1].revents & os.POLLIN != 0) {
|
||||
if (poll_fds[1].revents & os.POLL.IN != 0) {
|
||||
// stderr is ready.
|
||||
const new_capacity = std.math.min(stderr.items.len + bump_amt, max_output_bytes);
|
||||
try stderr.ensureCapacity(new_capacity);
|
||||
@ -461,7 +462,7 @@ pub const ChildProcess = struct {
|
||||
if (builtin.os.tag == .linux) {
|
||||
var fd = [1]std.os.pollfd{std.os.pollfd{
|
||||
.fd = self.err_pipe[0],
|
||||
.events = std.os.POLLIN,
|
||||
.events = std.os.POLL.IN,
|
||||
.revents = undefined,
|
||||
}};
|
||||
|
||||
@ -471,7 +472,7 @@ pub const ChildProcess = struct {
|
||||
|
||||
// According to eventfd(2) the descriptro is readable if the counter
|
||||
// has a value greater than 0
|
||||
if ((fd[0].revents & std.os.POLLIN) != 0) {
|
||||
if ((fd[0].revents & std.os.POLL.IN) != 0) {
|
||||
const err_int = try readIntFd(self.err_pipe[0]);
|
||||
return @errSetCast(SpawnError, @intToError(err_int));
|
||||
}
|
||||
@ -494,18 +495,18 @@ pub const ChildProcess = struct {
|
||||
}
|
||||
|
||||
fn statusToTerm(status: u32) Term {
|
||||
return if (os.WIFEXITED(status))
|
||||
Term{ .Exited = os.WEXITSTATUS(status) }
|
||||
else if (os.WIFSIGNALED(status))
|
||||
Term{ .Signal = os.WTERMSIG(status) }
|
||||
else if (os.WIFSTOPPED(status))
|
||||
Term{ .Stopped = os.WSTOPSIG(status) }
|
||||
return if (os.W.IFEXITED(status))
|
||||
Term{ .Exited = os.W.EXITSTATUS(status) }
|
||||
else if (os.W.IFSIGNALED(status))
|
||||
Term{ .Signal = os.W.TERMSIG(status) }
|
||||
else if (os.W.IFSTOPPED(status))
|
||||
Term{ .Stopped = os.W.STOPSIG(status) }
|
||||
else
|
||||
Term{ .Unknown = status };
|
||||
}
|
||||
|
||||
fn spawnPosix(self: *ChildProcess) SpawnError!void {
|
||||
const pipe_flags = if (io.is_async) os.O_NONBLOCK else 0;
|
||||
const pipe_flags = if (io.is_async) os.O.NONBLOCK else 0;
|
||||
const stdin_pipe = if (self.stdin_behavior == StdIo.Pipe) try os.pipe2(pipe_flags) else undefined;
|
||||
errdefer if (self.stdin_behavior == StdIo.Pipe) {
|
||||
destroyPipe(stdin_pipe);
|
||||
@ -523,7 +524,7 @@ pub const ChildProcess = struct {
|
||||
|
||||
const any_ignore = (self.stdin_behavior == StdIo.Ignore or self.stdout_behavior == StdIo.Ignore or self.stderr_behavior == StdIo.Ignore);
|
||||
const dev_null_fd = if (any_ignore)
|
||||
os.openZ("/dev/null", os.O_RDWR, 0) catch |err| switch (err) {
|
||||
os.openZ("/dev/null", os.O.RDWR, 0) catch |err| switch (err) {
|
||||
error.PathAlreadyExists => unreachable,
|
||||
error.NoSpaceLeft => unreachable,
|
||||
error.FileTooBig => unreachable,
|
||||
@ -575,12 +576,12 @@ pub const ChildProcess = struct {
|
||||
// and execve from the child process to the parent process.
|
||||
const err_pipe = blk: {
|
||||
if (builtin.os.tag == .linux) {
|
||||
const fd = try os.eventfd(0, os.EFD_CLOEXEC);
|
||||
const fd = try os.eventfd(0, linux.EFD.CLOEXEC);
|
||||
// There's no distinction between the readable and the writeable
|
||||
// end with eventfd
|
||||
break :blk [2]os.fd_t{ fd, fd };
|
||||
} else {
|
||||
break :blk try os.pipe2(os.O_CLOEXEC);
|
||||
break :blk try os.pipe2(os.O.CLOEXEC);
|
||||
}
|
||||
};
|
||||
errdefer destroyPipe(err_pipe);
|
||||
|
||||
@ -109,9 +109,11 @@ pub const pwhash = struct {
|
||||
crypt,
|
||||
};
|
||||
pub const KdfError = errors.Error || std.mem.Allocator.Error;
|
||||
pub const HasherError = KdfError || @import("crypto/phc_encoding.zig").Error;
|
||||
pub const HasherError = KdfError || phc_format.Error;
|
||||
pub const Error = HasherError || error{AllocatorRequired};
|
||||
|
||||
pub const phc_format = @import("crypto/phc_encoding.zig");
|
||||
|
||||
pub const bcrypt = @import("crypto/bcrypt.zig");
|
||||
pub const scrypt = @import("crypto/scrypt.zig");
|
||||
pub const pbkdf2 = @import("crypto/pbkdf2.zig").pbkdf2;
|
||||
|
||||
@ -40,9 +40,7 @@ pub const Curve25519 = struct {
|
||||
}
|
||||
|
||||
/// Multiply a point by the cofactor
|
||||
pub fn clearCofactor(p: Edwards25519) Edwards25519 {
|
||||
return p.dbl().dbl().dbl();
|
||||
}
|
||||
pub const clearCofactor = @compileError("TODO what was this function supposed to do? it didn't compile successfully");
|
||||
|
||||
fn ladder(p: Curve25519, s: [32]u8, comptime bits: usize) IdentityElementError!Curve25519 {
|
||||
var x1 = p.x;
|
||||
|
||||
@ -300,10 +300,14 @@ const CryptoPwhash = struct {
|
||||
params: anytype,
|
||||
name: []const u8,
|
||||
};
|
||||
const bcrypt_params = bcrypt.Params{ .rounds_log = 5 };
|
||||
const bcrypt_params = crypto.pwhash.bcrypt.Params{ .rounds_log = 12 };
|
||||
const pwhashes = [_]CryptoPwhash{
|
||||
CryptoPwhash{ .hashFn = bcrypt.strHash, .params = bcrypt_params, .name = "bcrypt" },
|
||||
CryptoPwhash{ .hashFn = scrypt.strHash, .params = scrypt.Params.interactive, .name = "scrypt" },
|
||||
.{ .hashFn = crypto.pwhash.bcrypt.strHash, .params = bcrypt_params, .name = "bcrypt" },
|
||||
.{
|
||||
.hashFn = crypto.pwhash.scrypt.strHash,
|
||||
.params = crypto.pwhash.scrypt.Params.interactive,
|
||||
.name = "scrypt",
|
||||
},
|
||||
};
|
||||
|
||||
fn benchmarkPwhash(
|
||||
|
||||
@ -1766,7 +1766,7 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[
|
||||
var x1: u64 = undefined;
|
||||
var x2: u1 = undefined;
|
||||
addcarryxU64(&x1, &x2, 0x0, (~arg1), @as(u64, 0x1));
|
||||
const x3 = (@as(u1, (x1 >> 63)) & @as(u1, ((arg3[0]) & @as(u64, 0x1))));
|
||||
const x3 = @truncate(u1, (x1 >> 63)) & @truncate(u1, ((arg3[0]) & @as(u64, 0x1)));
|
||||
var x4: u64 = undefined;
|
||||
var x5: u1 = undefined;
|
||||
addcarryxU64(&x4, &x5, 0x0, (~arg1), @as(u64, 0x1));
|
||||
@ -1880,7 +1880,7 @@ pub fn divstep(out1: *u64, out2: *[5]u64, out3: *[5]u64, out4: *[4]u64, out5: *[
|
||||
cmovznzU64(&x72, x3, (arg5[2]), x66);
|
||||
var x73: u64 = undefined;
|
||||
cmovznzU64(&x73, x3, (arg5[3]), x68);
|
||||
const x74 = @as(u1, (x22 & @as(u64, 0x1)));
|
||||
const x74 = @truncate(u1, (x22 & @as(u64, 0x1)));
|
||||
var x75: u64 = undefined;
|
||||
cmovznzU64(&x75, x74, @as(u64, 0x0), x7);
|
||||
var x76: u64 = undefined;
|
||||
|
||||
@ -111,3 +111,16 @@ test "p256 double base multiplication" {
|
||||
const pr2 = (try p1.mul(s1, .Little)).add(try p2.mul(s2, .Little));
|
||||
try testing.expect(pr1.equivalent(pr2));
|
||||
}
|
||||
|
||||
test "p256 scalar inverse" {
|
||||
const expected = "3b549196a13c898a6f6e84dfb3a22c40a8b9b17fb88e408ea674e451cd01d0a6";
|
||||
var out: [32]u8 = undefined;
|
||||
_ = try std.fmt.hexToBytes(&out, expected);
|
||||
|
||||
const scalar = try P256.scalar.Scalar.fromBytes(.{
|
||||
0x94, 0xa1, 0xbb, 0xb1, 0x4b, 0x90, 0x6a, 0x61, 0xa2, 0x80, 0xf2, 0x45, 0xf9, 0xe9, 0x3c, 0x7f,
|
||||
0x3b, 0x4a, 0x62, 0x47, 0x82, 0x4f, 0x5d, 0x33, 0xb9, 0x67, 0x07, 0x87, 0x64, 0x2a, 0x68, 0xde,
|
||||
}, .Big);
|
||||
const inverse = scalar.invert();
|
||||
try std.testing.expectEqualSlices(u8, &out, &inverse.toBytes(.Big));
|
||||
}
|
||||
|
||||
@ -523,7 +523,12 @@ pub fn strVerify(
|
||||
}
|
||||
}
|
||||
|
||||
test "scrypt kdf" {
|
||||
// These tests take way too long to run, so I have disabled them.
|
||||
const run_long_tests = false;
|
||||
|
||||
test "kdf" {
|
||||
if (!run_long_tests) return error.SkipZigTest;
|
||||
|
||||
const password = "testpass";
|
||||
const salt = "saltsalt";
|
||||
|
||||
@ -537,7 +542,9 @@ test "scrypt kdf" {
|
||||
try std.testing.expectEqualSlices(u8, &bytes, &dk);
|
||||
}
|
||||
|
||||
test "scrypt kdf rfc 1" {
|
||||
test "kdf rfc 1" {
|
||||
if (!run_long_tests) return error.SkipZigTest;
|
||||
|
||||
const password = "";
|
||||
const salt = "";
|
||||
|
||||
@ -551,7 +558,9 @@ test "scrypt kdf rfc 1" {
|
||||
try std.testing.expectEqualSlices(u8, &bytes, &dk);
|
||||
}
|
||||
|
||||
test "scrypt kdf rfc 2" {
|
||||
test "kdf rfc 2" {
|
||||
if (!run_long_tests) return error.SkipZigTest;
|
||||
|
||||
const password = "password";
|
||||
const salt = "NaCl";
|
||||
|
||||
@ -565,7 +574,9 @@ test "scrypt kdf rfc 2" {
|
||||
try std.testing.expectEqualSlices(u8, &bytes, &dk);
|
||||
}
|
||||
|
||||
test "scrypt kdf rfc 3" {
|
||||
test "kdf rfc 3" {
|
||||
if (!run_long_tests) return error.SkipZigTest;
|
||||
|
||||
const password = "pleaseletmein";
|
||||
const salt = "SodiumChloride";
|
||||
|
||||
@ -579,11 +590,8 @@ test "scrypt kdf rfc 3" {
|
||||
try std.testing.expectEqualSlices(u8, &bytes, &dk);
|
||||
}
|
||||
|
||||
test "scrypt kdf rfc 4" {
|
||||
// skip slow test
|
||||
if (true) {
|
||||
return error.SkipZigTest;
|
||||
}
|
||||
test "kdf rfc 4" {
|
||||
if (!run_long_tests) return error.SkipZigTest;
|
||||
|
||||
const password = "pleaseletmein";
|
||||
const salt = "SodiumChloride";
|
||||
@ -598,7 +606,9 @@ test "scrypt kdf rfc 4" {
|
||||
try std.testing.expectEqualSlices(u8, &bytes, &dk);
|
||||
}
|
||||
|
||||
test "scrypt password hashing (crypt format)" {
|
||||
test "password hashing (crypt format)" {
|
||||
if (!run_long_tests) return error.SkipZigTest;
|
||||
|
||||
const str = "$7$A6....1....TrXs5Zk6s8sWHpQgWDIXTR8kUU3s6Jc3s.DtdS8M2i4$a4ik5hGDN7foMuHOW.cp.CtX01UyCeO0.JAG.AHPpx5";
|
||||
const password = "Y0!?iQa9M%5ekffW(`";
|
||||
try CryptFormatHasher.verify(std.testing.allocator, str, password);
|
||||
@ -609,7 +619,9 @@ test "scrypt password hashing (crypt format)" {
|
||||
try CryptFormatHasher.verify(std.testing.allocator, str2, password);
|
||||
}
|
||||
|
||||
test "scrypt strHash and strVerify" {
|
||||
test "strHash and strVerify" {
|
||||
if (!run_long_tests) return error.SkipZigTest;
|
||||
|
||||
const alloc = std.testing.allocator;
|
||||
|
||||
const password = "testpass";
|
||||
@ -631,7 +643,9 @@ test "scrypt strHash and strVerify" {
|
||||
try strVerify(s1, password, verify_options);
|
||||
}
|
||||
|
||||
test "scrypt unix-scrypt" {
|
||||
test "unix-scrypt" {
|
||||
if (!run_long_tests) return error.SkipZigTest;
|
||||
|
||||
const alloc = std.testing.allocator;
|
||||
|
||||
// https://gitlab.com/jas/scrypt-unix-crypt/blob/master/unix-scrypt.txt
|
||||
@ -648,7 +662,7 @@ test "scrypt unix-scrypt" {
|
||||
}
|
||||
}
|
||||
|
||||
test "scrypt crypt format" {
|
||||
test "crypt format" {
|
||||
const str = "$7$C6..../....SodiumChloride$kBGj9fHznVYFQMEn/qDCfrDevf9YDtcDdKvEqHJLV8D";
|
||||
const params = try crypt_format.deserialize(crypt_format.HashResult(32), str);
|
||||
var buf: [str.len]u8 = undefined;
|
||||
|
||||
@ -74,8 +74,8 @@ fn tlsCsprngFill(_: *const std.rand.Random, buffer: []u8) void {
|
||||
wipe_mem = os.mmap(
|
||||
null,
|
||||
@sizeOf(Context),
|
||||
os.PROT_READ | os.PROT_WRITE,
|
||||
os.MAP_PRIVATE | os.MAP_ANONYMOUS,
|
||||
os.PROT.READ | os.PROT.WRITE,
|
||||
os.MAP.PRIVATE | os.MAP.ANONYMOUS,
|
||||
-1,
|
||||
0,
|
||||
) catch {
|
||||
@ -111,7 +111,7 @@ fn tlsCsprngFill(_: *const std.rand.Random, buffer: []u8) void {
|
||||
break :wof;
|
||||
} else |_| {}
|
||||
|
||||
if (os.madvise(wipe_mem.ptr, wipe_mem.len, os.MADV_WIPEONFORK)) |_| {
|
||||
if (os.madvise(wipe_mem.ptr, wipe_mem.len, os.MADV.WIPEONFORK)) |_| {
|
||||
return initAndFill(buffer);
|
||||
} else |_| {}
|
||||
}
|
||||
|
||||
@ -948,8 +948,8 @@ fn mapWholeFile(file: File) ![]align(mem.page_size) const u8 {
|
||||
const mapped_mem = try os.mmap(
|
||||
null,
|
||||
file_len,
|
||||
os.PROT_READ,
|
||||
os.MAP_SHARED,
|
||||
os.PROT.READ,
|
||||
os.MAP.SHARED,
|
||||
file.handle,
|
||||
0,
|
||||
);
|
||||
@ -1341,7 +1341,7 @@ pub const ModuleDebugInfo = switch (native_os) {
|
||||
if (o_file_di.findCompileUnit(relocated_address_o)) |compile_unit| {
|
||||
return SymbolInfo{
|
||||
.symbol_name = o_file_di.getSymbolName(relocated_address_o) orelse "???",
|
||||
.compile_unit_name = compile_unit.die.getAttrString(&o_file_di, DW.AT_name) catch |err| switch (err) {
|
||||
.compile_unit_name = compile_unit.die.getAttrString(&o_file_di, DW.AT.name) catch |err| switch (err) {
|
||||
error.MissingDebugInfo, error.InvalidDebugInfo => "???",
|
||||
else => return err,
|
||||
},
|
||||
@ -1438,7 +1438,7 @@ fn getSymbolFromDwarf(address: u64, di: *DW.DwarfInfo) !SymbolInfo {
|
||||
if (nosuspend di.findCompileUnit(address)) |compile_unit| {
|
||||
return SymbolInfo{
|
||||
.symbol_name = nosuspend di.getSymbolName(address) orelse "???",
|
||||
.compile_unit_name = compile_unit.die.getAttrString(di, DW.AT_name) catch |err| switch (err) {
|
||||
.compile_unit_name = compile_unit.die.getAttrString(di, DW.AT.name) catch |err| switch (err) {
|
||||
error.MissingDebugInfo, error.InvalidDebugInfo => "???",
|
||||
else => return err,
|
||||
},
|
||||
@ -1470,7 +1470,7 @@ fn getDebugInfoAllocator() *mem.Allocator {
|
||||
pub const have_segfault_handling_support = switch (native_os) {
|
||||
.linux, .netbsd => true,
|
||||
.windows => true,
|
||||
.freebsd, .openbsd => @hasDecl(os, "ucontext_t"),
|
||||
.freebsd, .openbsd => @hasDecl(os.system, "ucontext_t"),
|
||||
else => false,
|
||||
};
|
||||
pub const enable_segfault_handler: bool = if (@hasDecl(root, "enable_segfault_handler"))
|
||||
@ -1498,12 +1498,12 @@ pub fn attachSegfaultHandler() void {
|
||||
var act = os.Sigaction{
|
||||
.handler = .{ .sigaction = handleSegfaultLinux },
|
||||
.mask = os.empty_sigset,
|
||||
.flags = (os.SA_SIGINFO | os.SA_RESTART | os.SA_RESETHAND),
|
||||
.flags = (os.SA.SIGINFO | os.SA.RESTART | os.SA.RESETHAND),
|
||||
};
|
||||
|
||||
os.sigaction(os.SIGSEGV, &act, null);
|
||||
os.sigaction(os.SIGILL, &act, null);
|
||||
os.sigaction(os.SIGBUS, &act, null);
|
||||
os.sigaction(os.SIG.SEGV, &act, null);
|
||||
os.sigaction(os.SIG.ILL, &act, null);
|
||||
os.sigaction(os.SIG.BUS, &act, null);
|
||||
}
|
||||
|
||||
fn resetSegfaultHandler() void {
|
||||
@ -1515,13 +1515,13 @@ fn resetSegfaultHandler() void {
|
||||
return;
|
||||
}
|
||||
var act = os.Sigaction{
|
||||
.handler = .{ .sigaction = os.SIG_DFL },
|
||||
.handler = .{ .sigaction = os.SIG.DFL },
|
||||
.mask = os.empty_sigset,
|
||||
.flags = 0,
|
||||
};
|
||||
os.sigaction(os.SIGSEGV, &act, null);
|
||||
os.sigaction(os.SIGILL, &act, null);
|
||||
os.sigaction(os.SIGBUS, &act, null);
|
||||
os.sigaction(os.SIG.SEGV, &act, null);
|
||||
os.sigaction(os.SIG.ILL, &act, null);
|
||||
os.sigaction(os.SIG.BUS, &act, null);
|
||||
}
|
||||
|
||||
fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const c_void) callconv(.C) noreturn {
|
||||
@ -1542,9 +1542,9 @@ fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const c_v
|
||||
nosuspend {
|
||||
const stderr = io.getStdErr().writer();
|
||||
_ = switch (sig) {
|
||||
os.SIGSEGV => stderr.print("Segmentation fault at address 0x{x}\n", .{addr}),
|
||||
os.SIGILL => stderr.print("Illegal instruction at address 0x{x}\n", .{addr}),
|
||||
os.SIGBUS => stderr.print("Bus error at address 0x{x}\n", .{addr}),
|
||||
os.SIG.SEGV => stderr.print("Segmentation fault at address 0x{x}\n", .{addr}),
|
||||
os.SIG.ILL => stderr.print("Illegal instruction at address 0x{x}\n", .{addr}),
|
||||
os.SIG.BUS => stderr.print("Bus error at address 0x{x}\n", .{addr}),
|
||||
else => unreachable,
|
||||
} catch os.abort();
|
||||
}
|
||||
@ -1552,20 +1552,20 @@ fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const c_v
|
||||
switch (native_arch) {
|
||||
.i386 => {
|
||||
const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));
|
||||
const ip = @intCast(usize, ctx.mcontext.gregs[os.REG_EIP]);
|
||||
const bp = @intCast(usize, ctx.mcontext.gregs[os.REG_EBP]);
|
||||
const ip = @intCast(usize, ctx.mcontext.gregs[os.REG.EIP]);
|
||||
const bp = @intCast(usize, ctx.mcontext.gregs[os.REG.EBP]);
|
||||
dumpStackTraceFromBase(bp, ip);
|
||||
},
|
||||
.x86_64 => {
|
||||
const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));
|
||||
const ip = switch (native_os) {
|
||||
.linux, .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG_RIP]),
|
||||
.linux, .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG.RIP]),
|
||||
.freebsd => @intCast(usize, ctx.mcontext.rip),
|
||||
.openbsd => @intCast(usize, ctx.sc_rip),
|
||||
else => unreachable,
|
||||
};
|
||||
const bp = switch (native_os) {
|
||||
.linux, .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG_RBP]),
|
||||
.linux, .netbsd => @intCast(usize, ctx.mcontext.gregs[os.REG.RBP]),
|
||||
.openbsd => @intCast(usize, ctx.sc_rbp),
|
||||
.freebsd => @intCast(usize, ctx.mcontext.rbp),
|
||||
else => unreachable,
|
||||
|
||||
@ -9,7 +9,223 @@ const leb = @import("leb128.zig");
|
||||
|
||||
const ArrayList = std.ArrayList;
|
||||
|
||||
pub usingnamespace @import("dwarf_bits.zig");
|
||||
pub const TAG = @import("dwarf/TAG.zig");
|
||||
pub const AT = @import("dwarf/AT.zig");
|
||||
pub const OP = @import("dwarf/OP.zig");
|
||||
|
||||
pub const FORM = struct {
|
||||
pub const addr = 0x01;
|
||||
pub const block2 = 0x03;
|
||||
pub const block4 = 0x04;
|
||||
pub const data2 = 0x05;
|
||||
pub const data4 = 0x06;
|
||||
pub const data8 = 0x07;
|
||||
pub const string = 0x08;
|
||||
pub const block = 0x09;
|
||||
pub const block1 = 0x0a;
|
||||
pub const data1 = 0x0b;
|
||||
pub const flag = 0x0c;
|
||||
pub const sdata = 0x0d;
|
||||
pub const strp = 0x0e;
|
||||
pub const udata = 0x0f;
|
||||
pub const ref_addr = 0x10;
|
||||
pub const ref1 = 0x11;
|
||||
pub const ref2 = 0x12;
|
||||
pub const ref4 = 0x13;
|
||||
pub const ref8 = 0x14;
|
||||
pub const ref_udata = 0x15;
|
||||
pub const indirect = 0x16;
|
||||
pub const sec_offset = 0x17;
|
||||
pub const exprloc = 0x18;
|
||||
pub const flag_present = 0x19;
|
||||
pub const ref_sig8 = 0x20;
|
||||
|
||||
// Extensions for Fission. See http://gcc.gnu.org/wiki/DebugFission.
|
||||
pub const GNU_addr_index = 0x1f01;
|
||||
pub const GNU_str_index = 0x1f02;
|
||||
|
||||
// Extensions for DWZ multifile.
|
||||
// See http://www.dwarfstd.org/ShowIssue.php?issue=120604.1&type=open .
|
||||
pub const GNU_ref_alt = 0x1f20;
|
||||
pub const GNU_strp_alt = 0x1f21;
|
||||
};
|
||||
|
||||
pub const ATE = struct {
|
||||
pub const @"void" = 0x0;
|
||||
pub const address = 0x1;
|
||||
pub const boolean = 0x2;
|
||||
pub const complex_float = 0x3;
|
||||
pub const float = 0x4;
|
||||
pub const signed = 0x5;
|
||||
pub const signed_char = 0x6;
|
||||
pub const unsigned = 0x7;
|
||||
pub const unsigned_char = 0x8;
|
||||
|
||||
// DWARF 3.
|
||||
pub const imaginary_float = 0x9;
|
||||
pub const packed_decimal = 0xa;
|
||||
pub const numeric_string = 0xb;
|
||||
pub const edited = 0xc;
|
||||
pub const signed_fixed = 0xd;
|
||||
pub const unsigned_fixed = 0xe;
|
||||
pub const decimal_float = 0xf;
|
||||
|
||||
// DWARF 4.
|
||||
pub const UTF = 0x10;
|
||||
|
||||
pub const lo_user = 0x80;
|
||||
pub const hi_user = 0xff;
|
||||
|
||||
// HP extensions.
|
||||
pub const HP_float80 = 0x80; // Floating-point (80 bit).
|
||||
pub const HP_complex_float80 = 0x81; // Complex floating-point (80 bit).
|
||||
pub const HP_float128 = 0x82; // Floating-point (128 bit).
|
||||
pub const HP_complex_float128 = 0x83; // Complex fp (128 bit).
|
||||
pub const HP_floathpintel = 0x84; // Floating-point (82 bit IA64).
|
||||
pub const HP_imaginary_float80 = 0x85;
|
||||
pub const HP_imaginary_float128 = 0x86;
|
||||
pub const HP_VAX_float = 0x88; // F or G floating.
|
||||
pub const HP_VAX_float_d = 0x89; // D floating.
|
||||
pub const HP_packed_decimal = 0x8a; // Cobol.
|
||||
pub const HP_zoned_decimal = 0x8b; // Cobol.
|
||||
pub const HP_edited = 0x8c; // Cobol.
|
||||
pub const HP_signed_fixed = 0x8d; // Cobol.
|
||||
pub const HP_unsigned_fixed = 0x8e; // Cobol.
|
||||
pub const HP_VAX_complex_float = 0x8f; // F or G floating complex.
|
||||
pub const HP_VAX_complex_float_d = 0x90; // D floating complex.
|
||||
};
|
||||
|
||||
pub const CFA = struct {
|
||||
pub const advance_loc = 0x40;
|
||||
pub const offset = 0x80;
|
||||
pub const restore = 0xc0;
|
||||
pub const nop = 0x00;
|
||||
pub const set_loc = 0x01;
|
||||
pub const advance_loc1 = 0x02;
|
||||
pub const advance_loc2 = 0x03;
|
||||
pub const advance_loc4 = 0x04;
|
||||
pub const offset_extended = 0x05;
|
||||
pub const restore_extended = 0x06;
|
||||
pub const @"undefined" = 0x07;
|
||||
pub const same_value = 0x08;
|
||||
pub const register = 0x09;
|
||||
pub const remember_state = 0x0a;
|
||||
pub const restore_state = 0x0b;
|
||||
pub const def_cfa = 0x0c;
|
||||
pub const def_cfa_register = 0x0d;
|
||||
pub const def_cfa_offset = 0x0e;
|
||||
|
||||
// DWARF 3.
|
||||
pub const def_cfa_expression = 0x0f;
|
||||
pub const expression = 0x10;
|
||||
pub const offset_extended_sf = 0x11;
|
||||
pub const def_cfa_sf = 0x12;
|
||||
pub const def_cfa_offset_sf = 0x13;
|
||||
pub const val_offset = 0x14;
|
||||
pub const val_offset_sf = 0x15;
|
||||
pub const val_expression = 0x16;
|
||||
|
||||
pub const lo_user = 0x1c;
|
||||
pub const hi_user = 0x3f;
|
||||
|
||||
// SGI/MIPS specific.
|
||||
pub const MIPS_advance_loc8 = 0x1d;
|
||||
|
||||
// GNU extensions.
|
||||
pub const GNU_window_save = 0x2d;
|
||||
pub const GNU_args_size = 0x2e;
|
||||
pub const GNU_negative_offset_extended = 0x2f;
|
||||
};
|
||||
|
||||
pub const CHILDREN = struct {
|
||||
pub const no = 0x00;
|
||||
pub const yes = 0x01;
|
||||
};
|
||||
|
||||
pub const LNS = struct {
|
||||
pub const extended_op = 0x00;
|
||||
pub const copy = 0x01;
|
||||
pub const advance_pc = 0x02;
|
||||
pub const advance_line = 0x03;
|
||||
pub const set_file = 0x04;
|
||||
pub const set_column = 0x05;
|
||||
pub const negate_stmt = 0x06;
|
||||
pub const set_basic_block = 0x07;
|
||||
pub const const_add_pc = 0x08;
|
||||
pub const fixed_advance_pc = 0x09;
|
||||
pub const set_prologue_end = 0x0a;
|
||||
pub const set_epilogue_begin = 0x0b;
|
||||
pub const set_isa = 0x0c;
|
||||
};
|
||||
|
||||
pub const LNE = struct {
|
||||
pub const end_sequence = 0x01;
|
||||
pub const set_address = 0x02;
|
||||
pub const define_file = 0x03;
|
||||
pub const set_discriminator = 0x04;
|
||||
pub const lo_user = 0x80;
|
||||
pub const hi_user = 0xff;
|
||||
};
|
||||
|
||||
pub const LANG = struct {
|
||||
pub const C89 = 0x0001;
|
||||
pub const C = 0x0002;
|
||||
pub const Ada83 = 0x0003;
|
||||
pub const C_plus_plus = 0x0004;
|
||||
pub const Cobol74 = 0x0005;
|
||||
pub const Cobol85 = 0x0006;
|
||||
pub const Fortran77 = 0x0007;
|
||||
pub const Fortran90 = 0x0008;
|
||||
pub const Pascal83 = 0x0009;
|
||||
pub const Modula2 = 0x000a;
|
||||
pub const Java = 0x000b;
|
||||
pub const C99 = 0x000c;
|
||||
pub const Ada95 = 0x000d;
|
||||
pub const Fortran95 = 0x000e;
|
||||
pub const PLI = 0x000f;
|
||||
pub const ObjC = 0x0010;
|
||||
pub const ObjC_plus_plus = 0x0011;
|
||||
pub const UPC = 0x0012;
|
||||
pub const D = 0x0013;
|
||||
pub const Python = 0x0014;
|
||||
pub const Go = 0x0016;
|
||||
pub const C_plus_plus_11 = 0x001a;
|
||||
pub const Rust = 0x001c;
|
||||
pub const C11 = 0x001d;
|
||||
pub const C_plus_plus_14 = 0x0021;
|
||||
pub const Fortran03 = 0x0022;
|
||||
pub const Fortran08 = 0x0023;
|
||||
pub const lo_user = 0x8000;
|
||||
pub const hi_user = 0xffff;
|
||||
pub const Mips_Assembler = 0x8001;
|
||||
pub const Upc = 0x8765;
|
||||
pub const HP_Bliss = 0x8003;
|
||||
pub const HP_Basic91 = 0x8004;
|
||||
pub const HP_Pascal91 = 0x8005;
|
||||
pub const HP_IMacro = 0x8006;
|
||||
pub const HP_Assembler = 0x8007;
|
||||
};
|
||||
|
||||
pub const UT = struct {
|
||||
pub const compile = 0x01;
|
||||
pub const @"type" = 0x02;
|
||||
pub const partial = 0x03;
|
||||
pub const skeleton = 0x04;
|
||||
pub const split_compile = 0x05;
|
||||
pub const split_type = 0x06;
|
||||
pub const lo_user = 0x80;
|
||||
pub const hi_user = 0xff;
|
||||
};
|
||||
|
||||
pub const LNCT = struct {
|
||||
pub const path = 0x1;
|
||||
pub const directory_index = 0x2;
|
||||
pub const timestamp = 0x3;
|
||||
pub const size = 0x4;
|
||||
pub const MD5 = 0x5;
|
||||
pub const lo_user = 0x2000;
|
||||
pub const hi_user = 0x3fff;
|
||||
};
|
||||
|
||||
const PcRange = struct {
|
||||
start: u64,
|
||||
@ -322,43 +538,43 @@ fn parseFormValueRef(allocator: *mem.Allocator, in_stream: anytype, endian: buil
|
||||
// TODO the nosuspends here are workarounds
|
||||
fn parseFormValue(allocator: *mem.Allocator, in_stream: anytype, form_id: u64, endian: builtin.Endian, is_64: bool) anyerror!FormValue {
|
||||
return switch (form_id) {
|
||||
FORM_addr => FormValue{ .Address = try readAddress(in_stream, endian, @sizeOf(usize) == 8) },
|
||||
FORM_block1 => parseFormValueBlock(allocator, in_stream, endian, 1),
|
||||
FORM_block2 => parseFormValueBlock(allocator, in_stream, endian, 2),
|
||||
FORM_block4 => parseFormValueBlock(allocator, in_stream, endian, 4),
|
||||
FORM_block => {
|
||||
FORM.addr => FormValue{ .Address = try readAddress(in_stream, endian, @sizeOf(usize) == 8) },
|
||||
FORM.block1 => parseFormValueBlock(allocator, in_stream, endian, 1),
|
||||
FORM.block2 => parseFormValueBlock(allocator, in_stream, endian, 2),
|
||||
FORM.block4 => parseFormValueBlock(allocator, in_stream, endian, 4),
|
||||
FORM.block => {
|
||||
const block_len = try nosuspend leb.readULEB128(usize, in_stream);
|
||||
return parseFormValueBlockLen(allocator, in_stream, block_len);
|
||||
},
|
||||
FORM_data1 => parseFormValueConstant(allocator, in_stream, false, endian, 1),
|
||||
FORM_data2 => parseFormValueConstant(allocator, in_stream, false, endian, 2),
|
||||
FORM_data4 => parseFormValueConstant(allocator, in_stream, false, endian, 4),
|
||||
FORM_data8 => parseFormValueConstant(allocator, in_stream, false, endian, 8),
|
||||
FORM_udata, FORM_sdata => {
|
||||
const signed = form_id == FORM_sdata;
|
||||
FORM.data1 => parseFormValueConstant(allocator, in_stream, false, endian, 1),
|
||||
FORM.data2 => parseFormValueConstant(allocator, in_stream, false, endian, 2),
|
||||
FORM.data4 => parseFormValueConstant(allocator, in_stream, false, endian, 4),
|
||||
FORM.data8 => parseFormValueConstant(allocator, in_stream, false, endian, 8),
|
||||
FORM.udata, FORM.sdata => {
|
||||
const signed = form_id == FORM.sdata;
|
||||
return parseFormValueConstant(allocator, in_stream, signed, endian, -1);
|
||||
},
|
||||
FORM_exprloc => {
|
||||
FORM.exprloc => {
|
||||
const size = try nosuspend leb.readULEB128(usize, in_stream);
|
||||
const buf = try readAllocBytes(allocator, in_stream, size);
|
||||
return FormValue{ .ExprLoc = buf };
|
||||
},
|
||||
FORM_flag => FormValue{ .Flag = (try nosuspend in_stream.readByte()) != 0 },
|
||||
FORM_flag_present => FormValue{ .Flag = true },
|
||||
FORM_sec_offset => FormValue{ .SecOffset = try readAddress(in_stream, endian, is_64) },
|
||||
FORM.flag => FormValue{ .Flag = (try nosuspend in_stream.readByte()) != 0 },
|
||||
FORM.flag_present => FormValue{ .Flag = true },
|
||||
FORM.sec_offset => FormValue{ .SecOffset = try readAddress(in_stream, endian, is_64) },
|
||||
|
||||
FORM_ref1 => parseFormValueRef(allocator, in_stream, endian, 1),
|
||||
FORM_ref2 => parseFormValueRef(allocator, in_stream, endian, 2),
|
||||
FORM_ref4 => parseFormValueRef(allocator, in_stream, endian, 4),
|
||||
FORM_ref8 => parseFormValueRef(allocator, in_stream, endian, 8),
|
||||
FORM_ref_udata => parseFormValueRef(allocator, in_stream, endian, -1),
|
||||
FORM.ref1 => parseFormValueRef(allocator, in_stream, endian, 1),
|
||||
FORM.ref2 => parseFormValueRef(allocator, in_stream, endian, 2),
|
||||
FORM.ref4 => parseFormValueRef(allocator, in_stream, endian, 4),
|
||||
FORM.ref8 => parseFormValueRef(allocator, in_stream, endian, 8),
|
||||
FORM.ref_udata => parseFormValueRef(allocator, in_stream, endian, -1),
|
||||
|
||||
FORM_ref_addr => FormValue{ .RefAddr = try readAddress(in_stream, endian, is_64) },
|
||||
FORM_ref_sig8 => FormValue{ .Ref = try nosuspend in_stream.readInt(u64, endian) },
|
||||
FORM.ref_addr => FormValue{ .RefAddr = try readAddress(in_stream, endian, is_64) },
|
||||
FORM.ref_sig8 => FormValue{ .Ref = try nosuspend in_stream.readInt(u64, endian) },
|
||||
|
||||
FORM_string => FormValue{ .String = try in_stream.readUntilDelimiterAlloc(allocator, 0, math.maxInt(usize)) },
|
||||
FORM_strp => FormValue{ .StrPtr = try readAddress(in_stream, endian, is_64) },
|
||||
FORM_indirect => {
|
||||
FORM.string => FormValue{ .String = try in_stream.readUntilDelimiterAlloc(allocator, 0, math.maxInt(usize)) },
|
||||
FORM.strp => FormValue{ .StrPtr = try readAddress(in_stream, endian, is_64) },
|
||||
FORM.indirect => {
|
||||
const child_form_id = try nosuspend leb.readULEB128(u64, in_stream);
|
||||
const F = @TypeOf(async parseFormValue(allocator, in_stream, child_form_id, endian, is_64));
|
||||
var frame = try allocator.create(F);
|
||||
@ -441,24 +657,24 @@ pub const DwarfInfo = struct {
|
||||
const after_die_offset = try seekable.getPos();
|
||||
|
||||
switch (die_obj.tag_id) {
|
||||
TAG_subprogram, TAG_inlined_subroutine, TAG_subroutine, TAG_entry_point => {
|
||||
TAG.subprogram, TAG.inlined_subroutine, TAG.subroutine, TAG.entry_point => {
|
||||
const fn_name = x: {
|
||||
var depth: i32 = 3;
|
||||
var this_die_obj = die_obj;
|
||||
// Prenvent endless loops
|
||||
while (depth > 0) : (depth -= 1) {
|
||||
if (this_die_obj.getAttr(AT_name)) |_| {
|
||||
const name = try this_die_obj.getAttrString(di, AT_name);
|
||||
if (this_die_obj.getAttr(AT.name)) |_| {
|
||||
const name = try this_die_obj.getAttrString(di, AT.name);
|
||||
break :x name;
|
||||
} else if (this_die_obj.getAttr(AT_abstract_origin)) |_| {
|
||||
} else if (this_die_obj.getAttr(AT.abstract_origin)) |_| {
|
||||
// Follow the DIE it points to and repeat
|
||||
const ref_offset = try this_die_obj.getAttrRef(AT_abstract_origin);
|
||||
const ref_offset = try this_die_obj.getAttrRef(AT.abstract_origin);
|
||||
if (ref_offset > next_offset) return error.InvalidDebugInfo;
|
||||
try seekable.seekTo(this_unit_offset + ref_offset);
|
||||
this_die_obj = (try di.parseDie(in, abbrev_table, is_64)) orelse return error.InvalidDebugInfo;
|
||||
} else if (this_die_obj.getAttr(AT_specification)) |_| {
|
||||
} else if (this_die_obj.getAttr(AT.specification)) |_| {
|
||||
// Follow the DIE it points to and repeat
|
||||
const ref_offset = try this_die_obj.getAttrRef(AT_specification);
|
||||
const ref_offset = try this_die_obj.getAttrRef(AT.specification);
|
||||
if (ref_offset > next_offset) return error.InvalidDebugInfo;
|
||||
try seekable.seekTo(this_unit_offset + ref_offset);
|
||||
this_die_obj = (try di.parseDie(in, abbrev_table, is_64)) orelse return error.InvalidDebugInfo;
|
||||
@ -471,8 +687,8 @@ pub const DwarfInfo = struct {
|
||||
};
|
||||
|
||||
const pc_range = x: {
|
||||
if (die_obj.getAttrAddr(AT_low_pc)) |low_pc| {
|
||||
if (die_obj.getAttr(AT_high_pc)) |high_pc_value| {
|
||||
if (die_obj.getAttrAddr(AT.low_pc)) |low_pc| {
|
||||
if (die_obj.getAttr(AT.high_pc)) |high_pc_value| {
|
||||
const pc_end = switch (high_pc_value.*) {
|
||||
FormValue.Address => |value| value,
|
||||
FormValue.Const => |value| b: {
|
||||
@ -539,11 +755,11 @@ pub const DwarfInfo = struct {
|
||||
const compile_unit_die = try di.allocator().create(Die);
|
||||
compile_unit_die.* = (try di.parseDie(in, abbrev_table, is_64)) orelse return error.InvalidDebugInfo;
|
||||
|
||||
if (compile_unit_die.tag_id != TAG_compile_unit) return error.InvalidDebugInfo;
|
||||
if (compile_unit_die.tag_id != TAG.compile_unit) return error.InvalidDebugInfo;
|
||||
|
||||
const pc_range = x: {
|
||||
if (compile_unit_die.getAttrAddr(AT_low_pc)) |low_pc| {
|
||||
if (compile_unit_die.getAttr(AT_high_pc)) |high_pc_value| {
|
||||
if (compile_unit_die.getAttrAddr(AT.low_pc)) |low_pc| {
|
||||
if (compile_unit_die.getAttr(AT.high_pc)) |high_pc_value| {
|
||||
const pc_end = switch (high_pc_value.*) {
|
||||
FormValue.Address => |value| value,
|
||||
FormValue.Const => |value| b: {
|
||||
@ -582,16 +798,16 @@ pub const DwarfInfo = struct {
|
||||
if (target_address >= range.start and target_address < range.end) return compile_unit;
|
||||
}
|
||||
if (di.debug_ranges) |debug_ranges| {
|
||||
if (compile_unit.die.getAttrSecOffset(AT_ranges)) |ranges_offset| {
|
||||
if (compile_unit.die.getAttrSecOffset(AT.ranges)) |ranges_offset| {
|
||||
var stream = io.fixedBufferStream(debug_ranges);
|
||||
const in = &stream.reader();
|
||||
const seekable = &stream.seekableStream();
|
||||
|
||||
// All the addresses in the list are relative to the value
|
||||
// specified by DW_AT_low_pc or to some other value encoded
|
||||
// specified by DW_AT.low_pc or to some other value encoded
|
||||
// in the list itself.
|
||||
// If no starting value is specified use zero.
|
||||
var base_address = compile_unit.die.getAttrAddr(AT_low_pc) catch |err| switch (err) {
|
||||
var base_address = compile_unit.die.getAttrAddr(AT.low_pc) catch |err| switch (err) {
|
||||
error.MissingDebugInfo => 0,
|
||||
else => return err,
|
||||
};
|
||||
@ -651,7 +867,7 @@ pub const DwarfInfo = struct {
|
||||
try result.append(AbbrevTableEntry{
|
||||
.abbrev_code = abbrev_code,
|
||||
.tag_id = try leb.readULEB128(u64, in),
|
||||
.has_children = (try in.readByte()) == CHILDREN_yes,
|
||||
.has_children = (try in.readByte()) == CHILDREN.yes,
|
||||
.attrs = ArrayList(AbbrevAttr).init(di.allocator()),
|
||||
});
|
||||
const attrs = &result.items[result.items.len - 1].attrs;
|
||||
@ -693,8 +909,8 @@ pub const DwarfInfo = struct {
|
||||
const in = &stream.reader();
|
||||
const seekable = &stream.seekableStream();
|
||||
|
||||
const compile_unit_cwd = try compile_unit.die.getAttrString(di, AT_comp_dir);
|
||||
const line_info_offset = try compile_unit.die.getAttrSecOffset(AT_stmt_list);
|
||||
const compile_unit_cwd = try compile_unit.die.getAttrString(di, AT.comp_dir);
|
||||
const line_info_offset = try compile_unit.die.getAttrSecOffset(AT.stmt_list);
|
||||
|
||||
try seekable.seekTo(line_info_offset);
|
||||
|
||||
@ -769,21 +985,21 @@ pub const DwarfInfo = struct {
|
||||
while ((try seekable.getPos()) < next_unit_pos) {
|
||||
const opcode = try in.readByte();
|
||||
|
||||
if (opcode == LNS_extended_op) {
|
||||
if (opcode == LNS.extended_op) {
|
||||
const op_size = try leb.readULEB128(u64, in);
|
||||
if (op_size < 1) return error.InvalidDebugInfo;
|
||||
var sub_op = try in.readByte();
|
||||
switch (sub_op) {
|
||||
LNE_end_sequence => {
|
||||
LNE.end_sequence => {
|
||||
prog.end_sequence = true;
|
||||
if (try prog.checkLineMatch()) |info| return info;
|
||||
prog.reset();
|
||||
},
|
||||
LNE_set_address => {
|
||||
LNE.set_address => {
|
||||
const addr = try in.readInt(usize, di.endian);
|
||||
prog.address = addr;
|
||||
},
|
||||
LNE_define_file => {
|
||||
LNE.define_file => {
|
||||
const file_name = try in.readUntilDelimiterAlloc(di.allocator(), 0, math.maxInt(usize));
|
||||
const dir_index = try leb.readULEB128(usize, in);
|
||||
const mtime = try leb.readULEB128(usize, in);
|
||||
@ -811,41 +1027,41 @@ pub const DwarfInfo = struct {
|
||||
prog.basic_block = false;
|
||||
} else {
|
||||
switch (opcode) {
|
||||
LNS_copy => {
|
||||
LNS.copy => {
|
||||
if (try prog.checkLineMatch()) |info| return info;
|
||||
prog.basic_block = false;
|
||||
},
|
||||
LNS_advance_pc => {
|
||||
LNS.advance_pc => {
|
||||
const arg = try leb.readULEB128(usize, in);
|
||||
prog.address += arg * minimum_instruction_length;
|
||||
},
|
||||
LNS_advance_line => {
|
||||
LNS.advance_line => {
|
||||
const arg = try leb.readILEB128(i64, in);
|
||||
prog.line += arg;
|
||||
},
|
||||
LNS_set_file => {
|
||||
LNS.set_file => {
|
||||
const arg = try leb.readULEB128(usize, in);
|
||||
prog.file = arg;
|
||||
},
|
||||
LNS_set_column => {
|
||||
LNS.set_column => {
|
||||
const arg = try leb.readULEB128(u64, in);
|
||||
prog.column = arg;
|
||||
},
|
||||
LNS_negate_stmt => {
|
||||
LNS.negate_stmt => {
|
||||
prog.is_stmt = !prog.is_stmt;
|
||||
},
|
||||
LNS_set_basic_block => {
|
||||
LNS.set_basic_block => {
|
||||
prog.basic_block = true;
|
||||
},
|
||||
LNS_const_add_pc => {
|
||||
LNS.const_add_pc => {
|
||||
const inc_addr = minimum_instruction_length * ((255 - opcode_base) / line_range);
|
||||
prog.address += inc_addr;
|
||||
},
|
||||
LNS_fixed_advance_pc => {
|
||||
LNS.fixed_advance_pc => {
|
||||
const arg = try in.readInt(u16, di.endian);
|
||||
prog.address += arg;
|
||||
},
|
||||
LNS_set_prologue_end => {},
|
||||
LNS.set_prologue_end => {},
|
||||
else => {
|
||||
if (opcode - 1 >= standard_opcode_lengths.len) return error.InvalidDebugInfo;
|
||||
const len_bytes = standard_opcode_lengths[opcode - 1];
|
||||
|
||||
198
lib/std/dwarf/AT.zig
Normal file
198
lib/std/dwarf/AT.zig
Normal file
@ -0,0 +1,198 @@
|
||||
pub const sibling = 0x01;
|
||||
pub const location = 0x02;
|
||||
pub const name = 0x03;
|
||||
pub const ordering = 0x09;
|
||||
pub const subscr_data = 0x0a;
|
||||
pub const byte_size = 0x0b;
|
||||
pub const bit_offset = 0x0c;
|
||||
pub const bit_size = 0x0d;
|
||||
pub const element_list = 0x0f;
|
||||
pub const stmt_list = 0x10;
|
||||
pub const low_pc = 0x11;
|
||||
pub const high_pc = 0x12;
|
||||
pub const language = 0x13;
|
||||
pub const member = 0x14;
|
||||
pub const discr = 0x15;
|
||||
pub const discr_value = 0x16;
|
||||
pub const visibility = 0x17;
|
||||
pub const import = 0x18;
|
||||
pub const string_length = 0x19;
|
||||
pub const common_reference = 0x1a;
|
||||
pub const comp_dir = 0x1b;
|
||||
pub const const_value = 0x1c;
|
||||
pub const containing_type = 0x1d;
|
||||
pub const default_value = 0x1e;
|
||||
pub const @"inline" = 0x20;
|
||||
pub const is_optional = 0x21;
|
||||
pub const lower_bound = 0x22;
|
||||
pub const producer = 0x25;
|
||||
pub const prototyped = 0x27;
|
||||
pub const return_addr = 0x2a;
|
||||
pub const start_scope = 0x2c;
|
||||
pub const bit_stride = 0x2e;
|
||||
pub const upper_bound = 0x2f;
|
||||
pub const abstract_origin = 0x31;
|
||||
pub const accessibility = 0x32;
|
||||
pub const address_class = 0x33;
|
||||
pub const artificial = 0x34;
|
||||
pub const base_types = 0x35;
|
||||
pub const calling_convention = 0x36;
|
||||
pub const count = 0x37;
|
||||
pub const data_member_location = 0x38;
|
||||
pub const decl_column = 0x39;
|
||||
pub const decl_file = 0x3a;
|
||||
pub const decl_line = 0x3b;
|
||||
pub const declaration = 0x3c;
|
||||
pub const discr_list = 0x3d;
|
||||
pub const encoding = 0x3e;
|
||||
pub const external = 0x3f;
|
||||
pub const frame_base = 0x40;
|
||||
pub const friend = 0x41;
|
||||
pub const identifier_case = 0x42;
|
||||
pub const macro_info = 0x43;
|
||||
pub const namelist_items = 0x44;
|
||||
pub const priority = 0x45;
|
||||
pub const segment = 0x46;
|
||||
pub const specification = 0x47;
|
||||
pub const static_link = 0x48;
|
||||
pub const @"type" = 0x49;
|
||||
pub const use_location = 0x4a;
|
||||
pub const variable_parameter = 0x4b;
|
||||
pub const virtuality = 0x4c;
|
||||
pub const vtable_elem_location = 0x4d;
|
||||
|
||||
// DWARF 3 values.
|
||||
pub const allocated = 0x4e;
|
||||
pub const associated = 0x4f;
|
||||
pub const data_location = 0x50;
|
||||
pub const byte_stride = 0x51;
|
||||
pub const entry_pc = 0x52;
|
||||
pub const use_UTF8 = 0x53;
|
||||
pub const extension = 0x54;
|
||||
pub const ranges = 0x55;
|
||||
pub const trampoline = 0x56;
|
||||
pub const call_column = 0x57;
|
||||
pub const call_file = 0x58;
|
||||
pub const call_line = 0x59;
|
||||
pub const description = 0x5a;
|
||||
pub const binary_scale = 0x5b;
|
||||
pub const decimal_scale = 0x5c;
|
||||
pub const small = 0x5d;
|
||||
pub const decimal_sign = 0x5e;
|
||||
pub const digit_count = 0x5f;
|
||||
pub const picture_string = 0x60;
|
||||
pub const mutable = 0x61;
|
||||
pub const threads_scaled = 0x62;
|
||||
pub const explicit = 0x63;
|
||||
pub const object_pointer = 0x64;
|
||||
pub const endianity = 0x65;
|
||||
pub const elemental = 0x66;
|
||||
pub const pure = 0x67;
|
||||
pub const recursive = 0x68;
|
||||
|
||||
// DWARF 4.
|
||||
pub const signature = 0x69;
|
||||
pub const main_subprogram = 0x6a;
|
||||
pub const data_bit_offset = 0x6b;
|
||||
pub const const_expr = 0x6c;
|
||||
pub const enum_class = 0x6d;
|
||||
pub const linkage_name = 0x6e;
|
||||
|
||||
// DWARF 5
|
||||
pub const alignment = 0x88;
|
||||
|
||||
pub const lo_user = 0x2000; // Implementation-defined range start.
|
||||
pub const hi_user = 0x3fff; // Implementation-defined range end.
|
||||
|
||||
// SGI/MIPS extensions.
|
||||
pub const MIPS_fde = 0x2001;
|
||||
pub const MIPS_loop_begin = 0x2002;
|
||||
pub const MIPS_tail_loop_begin = 0x2003;
|
||||
pub const MIPS_epilog_begin = 0x2004;
|
||||
pub const MIPS_loop_unroll_factor = 0x2005;
|
||||
pub const MIPS_software_pipeline_depth = 0x2006;
|
||||
pub const MIPS_linkage_name = 0x2007;
|
||||
pub const MIPS_stride = 0x2008;
|
||||
pub const MIPS_abstract_name = 0x2009;
|
||||
pub const MIPS_clone_origin = 0x200a;
|
||||
pub const MIPS_has_inlines = 0x200b;
|
||||
|
||||
// HP extensions.
|
||||
pub const HP_block_index = 0x2000;
|
||||
pub const HP_unmodifiable = 0x2001; // Same as AT.MIPS_fde.
|
||||
pub const HP_prologue = 0x2005; // Same as AT.MIPS_loop_unroll.
|
||||
pub const HP_epilogue = 0x2008; // Same as AT.MIPS_stride.
|
||||
pub const HP_actuals_stmt_list = 0x2010;
|
||||
pub const HP_proc_per_section = 0x2011;
|
||||
pub const HP_raw_data_ptr = 0x2012;
|
||||
pub const HP_pass_by_reference = 0x2013;
|
||||
pub const HP_opt_level = 0x2014;
|
||||
pub const HP_prof_version_id = 0x2015;
|
||||
pub const HP_opt_flags = 0x2016;
|
||||
pub const HP_cold_region_low_pc = 0x2017;
|
||||
pub const HP_cold_region_high_pc = 0x2018;
|
||||
pub const HP_all_variables_modifiable = 0x2019;
|
||||
pub const HP_linkage_name = 0x201a;
|
||||
pub const HP_prof_flags = 0x201b; // In comp unit of procs_info for -g.
|
||||
pub const HP_unit_name = 0x201f;
|
||||
pub const HP_unit_size = 0x2020;
|
||||
pub const HP_widened_byte_size = 0x2021;
|
||||
pub const HP_definition_points = 0x2022;
|
||||
pub const HP_default_location = 0x2023;
|
||||
pub const HP_is_result_param = 0x2029;
|
||||
|
||||
// GNU extensions.
|
||||
pub const sf_names = 0x2101;
|
||||
pub const src_info = 0x2102;
|
||||
pub const mac_info = 0x2103;
|
||||
pub const src_coords = 0x2104;
|
||||
pub const body_begin = 0x2105;
|
||||
pub const body_end = 0x2106;
|
||||
pub const GNU_vector = 0x2107;
|
||||
// Thread-safety annotations.
|
||||
// See http://gcc.gnu.org/wiki/ThreadSafetyAnnotation .
|
||||
pub const GNU_guarded_by = 0x2108;
|
||||
pub const GNU_pt_guarded_by = 0x2109;
|
||||
pub const GNU_guarded = 0x210a;
|
||||
pub const GNU_pt_guarded = 0x210b;
|
||||
pub const GNU_locks_excluded = 0x210c;
|
||||
pub const GNU_exclusive_locks_required = 0x210d;
|
||||
pub const GNU_shared_locks_required = 0x210e;
|
||||
// One-definition rule violation detection.
|
||||
// See http://gcc.gnu.org/wiki/DwarfSeparateTypeInfo .
|
||||
pub const GNU_odr_signature = 0x210f;
|
||||
// Template template argument name.
|
||||
// See http://gcc.gnu.org/wiki/TemplateParmsDwarf .
|
||||
pub const GNU_template_name = 0x2110;
|
||||
// The GNU call site extension.
|
||||
// See http://www.dwarfstd.org/ShowIssue.php?issue=100909.2&type=open .
|
||||
pub const GNU_call_site_value = 0x2111;
|
||||
pub const GNU_call_site_data_value = 0x2112;
|
||||
pub const GNU_call_site_target = 0x2113;
|
||||
pub const GNU_call_site_target_clobbered = 0x2114;
|
||||
pub const GNU_tail_call = 0x2115;
|
||||
pub const GNU_all_tail_call_sites = 0x2116;
|
||||
pub const GNU_all_call_sites = 0x2117;
|
||||
pub const GNU_all_source_call_sites = 0x2118;
|
||||
// Section offset into .debug_macro section.
|
||||
pub const GNU_macros = 0x2119;
|
||||
// Extensions for Fission. See http://gcc.gnu.org/wiki/DebugFission.
|
||||
pub const GNU_dwo_name = 0x2130;
|
||||
pub const GNU_dwo_id = 0x2131;
|
||||
pub const GNU_ranges_base = 0x2132;
|
||||
pub const GNU_addr_base = 0x2133;
|
||||
pub const GNU_pubnames = 0x2134;
|
||||
pub const GNU_pubtypes = 0x2135;
|
||||
// VMS extensions.
|
||||
pub const VMS_rtnbeg_pd_address = 0x2201;
|
||||
// GNAT extensions.
|
||||
// GNAT descriptive type.
|
||||
// See http://gcc.gnu.org/wiki/DW_AT_GNAT_descriptive_type .
|
||||
pub const use_GNAT_descriptive_type = 0x2301;
|
||||
pub const GNAT_descriptive_type = 0x2302;
|
||||
// UPC extension.
|
||||
pub const upc_threads_scaled = 0x3210;
|
||||
// PGI (STMicroelectronics) extensions.
|
||||
pub const PGI_lbase = 0x3a00;
|
||||
pub const PGI_soffset = 0x3a01;
|
||||
pub const PGI_lstride = 0x3a02;
|
||||
195
lib/std/dwarf/OP.zig
Normal file
195
lib/std/dwarf/OP.zig
Normal file
@ -0,0 +1,195 @@
|
||||
pub const addr = 0x03;
|
||||
pub const deref = 0x06;
|
||||
pub const const1u = 0x08;
|
||||
pub const const1s = 0x09;
|
||||
pub const const2u = 0x0a;
|
||||
pub const const2s = 0x0b;
|
||||
pub const const4u = 0x0c;
|
||||
pub const const4s = 0x0d;
|
||||
pub const const8u = 0x0e;
|
||||
pub const const8s = 0x0f;
|
||||
pub const constu = 0x10;
|
||||
pub const consts = 0x11;
|
||||
pub const dup = 0x12;
|
||||
pub const drop = 0x13;
|
||||
pub const over = 0x14;
|
||||
pub const pick = 0x15;
|
||||
pub const swap = 0x16;
|
||||
pub const rot = 0x17;
|
||||
pub const xderef = 0x18;
|
||||
pub const abs = 0x19;
|
||||
pub const @"and" = 0x1a;
|
||||
pub const div = 0x1b;
|
||||
pub const minus = 0x1c;
|
||||
pub const mod = 0x1d;
|
||||
pub const mul = 0x1e;
|
||||
pub const neg = 0x1f;
|
||||
pub const not = 0x20;
|
||||
pub const @"or" = 0x21;
|
||||
pub const plus = 0x22;
|
||||
pub const plus_uconst = 0x23;
|
||||
pub const shl = 0x24;
|
||||
pub const shr = 0x25;
|
||||
pub const shra = 0x26;
|
||||
pub const xor = 0x27;
|
||||
pub const bra = 0x28;
|
||||
pub const eq = 0x29;
|
||||
pub const ge = 0x2a;
|
||||
pub const gt = 0x2b;
|
||||
pub const le = 0x2c;
|
||||
pub const lt = 0x2d;
|
||||
pub const ne = 0x2e;
|
||||
pub const skip = 0x2f;
|
||||
pub const lit0 = 0x30;
|
||||
pub const lit1 = 0x31;
|
||||
pub const lit2 = 0x32;
|
||||
pub const lit3 = 0x33;
|
||||
pub const lit4 = 0x34;
|
||||
pub const lit5 = 0x35;
|
||||
pub const lit6 = 0x36;
|
||||
pub const lit7 = 0x37;
|
||||
pub const lit8 = 0x38;
|
||||
pub const lit9 = 0x39;
|
||||
pub const lit10 = 0x3a;
|
||||
pub const lit11 = 0x3b;
|
||||
pub const lit12 = 0x3c;
|
||||
pub const lit13 = 0x3d;
|
||||
pub const lit14 = 0x3e;
|
||||
pub const lit15 = 0x3f;
|
||||
pub const lit16 = 0x40;
|
||||
pub const lit17 = 0x41;
|
||||
pub const lit18 = 0x42;
|
||||
pub const lit19 = 0x43;
|
||||
pub const lit20 = 0x44;
|
||||
pub const lit21 = 0x45;
|
||||
pub const lit22 = 0x46;
|
||||
pub const lit23 = 0x47;
|
||||
pub const lit24 = 0x48;
|
||||
pub const lit25 = 0x49;
|
||||
pub const lit26 = 0x4a;
|
||||
pub const lit27 = 0x4b;
|
||||
pub const lit28 = 0x4c;
|
||||
pub const lit29 = 0x4d;
|
||||
pub const lit30 = 0x4e;
|
||||
pub const lit31 = 0x4f;
|
||||
pub const reg0 = 0x50;
|
||||
pub const reg1 = 0x51;
|
||||
pub const reg2 = 0x52;
|
||||
pub const reg3 = 0x53;
|
||||
pub const reg4 = 0x54;
|
||||
pub const reg5 = 0x55;
|
||||
pub const reg6 = 0x56;
|
||||
pub const reg7 = 0x57;
|
||||
pub const reg8 = 0x58;
|
||||
pub const reg9 = 0x59;
|
||||
pub const reg10 = 0x5a;
|
||||
pub const reg11 = 0x5b;
|
||||
pub const reg12 = 0x5c;
|
||||
pub const reg13 = 0x5d;
|
||||
pub const reg14 = 0x5e;
|
||||
pub const reg15 = 0x5f;
|
||||
pub const reg16 = 0x60;
|
||||
pub const reg17 = 0x61;
|
||||
pub const reg18 = 0x62;
|
||||
pub const reg19 = 0x63;
|
||||
pub const reg20 = 0x64;
|
||||
pub const reg21 = 0x65;
|
||||
pub const reg22 = 0x66;
|
||||
pub const reg23 = 0x67;
|
||||
pub const reg24 = 0x68;
|
||||
pub const reg25 = 0x69;
|
||||
pub const reg26 = 0x6a;
|
||||
pub const reg27 = 0x6b;
|
||||
pub const reg28 = 0x6c;
|
||||
pub const reg29 = 0x6d;
|
||||
pub const reg30 = 0x6e;
|
||||
pub const reg31 = 0x6f;
|
||||
pub const breg0 = 0x70;
|
||||
pub const breg1 = 0x71;
|
||||
pub const breg2 = 0x72;
|
||||
pub const breg3 = 0x73;
|
||||
pub const breg4 = 0x74;
|
||||
pub const breg5 = 0x75;
|
||||
pub const breg6 = 0x76;
|
||||
pub const breg7 = 0x77;
|
||||
pub const breg8 = 0x78;
|
||||
pub const breg9 = 0x79;
|
||||
pub const breg10 = 0x7a;
|
||||
pub const breg11 = 0x7b;
|
||||
pub const breg12 = 0x7c;
|
||||
pub const breg13 = 0x7d;
|
||||
pub const breg14 = 0x7e;
|
||||
pub const breg15 = 0x7f;
|
||||
pub const breg16 = 0x80;
|
||||
pub const breg17 = 0x81;
|
||||
pub const breg18 = 0x82;
|
||||
pub const breg19 = 0x83;
|
||||
pub const breg20 = 0x84;
|
||||
pub const breg21 = 0x85;
|
||||
pub const breg22 = 0x86;
|
||||
pub const breg23 = 0x87;
|
||||
pub const breg24 = 0x88;
|
||||
pub const breg25 = 0x89;
|
||||
pub const breg26 = 0x8a;
|
||||
pub const breg27 = 0x8b;
|
||||
pub const breg28 = 0x8c;
|
||||
pub const breg29 = 0x8d;
|
||||
pub const breg30 = 0x8e;
|
||||
pub const breg31 = 0x8f;
|
||||
pub const regx = 0x90;
|
||||
pub const fbreg = 0x91;
|
||||
pub const bregx = 0x92;
|
||||
pub const piece = 0x93;
|
||||
pub const deref_size = 0x94;
|
||||
pub const xderef_size = 0x95;
|
||||
pub const nop = 0x96;
|
||||
|
||||
// DWARF 3 extensions.
|
||||
pub const push_object_address = 0x97;
|
||||
pub const call2 = 0x98;
|
||||
pub const call4 = 0x99;
|
||||
pub const call_ref = 0x9a;
|
||||
pub const form_tls_address = 0x9b;
|
||||
pub const call_frame_cfa = 0x9c;
|
||||
pub const bit_piece = 0x9d;
|
||||
|
||||
// DWARF 4 extensions.
|
||||
pub const implicit_value = 0x9e;
|
||||
pub const stack_value = 0x9f;
|
||||
|
||||
pub const lo_user = 0xe0; // Implementation-defined range start.
|
||||
pub const hi_user = 0xff; // Implementation-defined range end.
|
||||
|
||||
// GNU extensions.
|
||||
pub const GNU_push_tls_address = 0xe0;
|
||||
// The following is for marking variables that are uninitialized.
|
||||
pub const GNU_uninit = 0xf0;
|
||||
pub const GNU_encoded_addr = 0xf1;
|
||||
// The GNU implicit pointer extension.
|
||||
// See http://www.dwarfstd.org/ShowIssue.php?issue=100831.1&type=open .
|
||||
pub const GNU_implicit_pointer = 0xf2;
|
||||
// The GNU entry value extension.
|
||||
// See http://www.dwarfstd.org/ShowIssue.php?issue=100909.1&type=open .
|
||||
pub const GNU_entry_value = 0xf3;
|
||||
// The GNU typed stack extension.
|
||||
// See http://www.dwarfstd.org/doc/040408.1.html .
|
||||
pub const GNU_const_type = 0xf4;
|
||||
pub const GNU_regval_type = 0xf5;
|
||||
pub const GNU_deref_type = 0xf6;
|
||||
pub const GNU_convert = 0xf7;
|
||||
pub const GNU_reinterpret = 0xf9;
|
||||
// The GNU parameter ref extension.
|
||||
pub const GNU_parameter_ref = 0xfa;
|
||||
// Extension for Fission. See http://gcc.gnu.org/wiki/DebugFission.
|
||||
pub const GNU_addr_index = 0xfb;
|
||||
pub const GNU_const_index = 0xfc;
|
||||
// HP extensions.
|
||||
pub const HP_unknown = 0xe0; // Ouch, the same as GNU_push_tls_address.
|
||||
pub const HP_is_value = 0xe1;
|
||||
pub const HP_fltconst4 = 0xe2;
|
||||
pub const HP_fltconst8 = 0xe3;
|
||||
pub const HP_mod_range = 0xe4;
|
||||
pub const HP_unmod_range = 0xe5;
|
||||
pub const HP_tls = 0xe6;
|
||||
// PGI (STMicroelectronics) extensions.
|
||||
pub const PGI_omp_thread_num = 0xf8;
|
||||
108
lib/std/dwarf/TAG.zig
Normal file
108
lib/std/dwarf/TAG.zig
Normal file
@ -0,0 +1,108 @@
|
||||
pub const padding = 0x00;
|
||||
pub const array_type = 0x01;
|
||||
pub const class_type = 0x02;
|
||||
pub const entry_point = 0x03;
|
||||
pub const enumeration_type = 0x04;
|
||||
pub const formal_parameter = 0x05;
|
||||
pub const imported_declaration = 0x08;
|
||||
pub const label = 0x0a;
|
||||
pub const lexical_block = 0x0b;
|
||||
pub const member = 0x0d;
|
||||
pub const pointer_type = 0x0f;
|
||||
pub const reference_type = 0x10;
|
||||
pub const compile_unit = 0x11;
|
||||
pub const string_type = 0x12;
|
||||
pub const structure_type = 0x13;
|
||||
pub const subroutine = 0x14;
|
||||
pub const subroutine_type = 0x15;
|
||||
pub const typedef = 0x16;
|
||||
pub const union_type = 0x17;
|
||||
pub const unspecified_parameters = 0x18;
|
||||
pub const variant = 0x19;
|
||||
pub const common_block = 0x1a;
|
||||
pub const common_inclusion = 0x1b;
|
||||
pub const inheritance = 0x1c;
|
||||
pub const inlined_subroutine = 0x1d;
|
||||
pub const module = 0x1e;
|
||||
pub const ptr_to_member_type = 0x1f;
|
||||
pub const set_type = 0x20;
|
||||
pub const subrange_type = 0x21;
|
||||
pub const with_stmt = 0x22;
|
||||
pub const access_declaration = 0x23;
|
||||
pub const base_type = 0x24;
|
||||
pub const catch_block = 0x25;
|
||||
pub const const_type = 0x26;
|
||||
pub const constant = 0x27;
|
||||
pub const enumerator = 0x28;
|
||||
pub const file_type = 0x29;
|
||||
pub const friend = 0x2a;
|
||||
pub const namelist = 0x2b;
|
||||
pub const namelist_item = 0x2c;
|
||||
pub const packed_type = 0x2d;
|
||||
pub const subprogram = 0x2e;
|
||||
pub const template_type_param = 0x2f;
|
||||
pub const template_value_param = 0x30;
|
||||
pub const thrown_type = 0x31;
|
||||
pub const try_block = 0x32;
|
||||
pub const variant_part = 0x33;
|
||||
pub const variable = 0x34;
|
||||
pub const volatile_type = 0x35;
|
||||
|
||||
// DWARF 3
|
||||
pub const dwarf_procedure = 0x36;
|
||||
pub const restrict_type = 0x37;
|
||||
pub const interface_type = 0x38;
|
||||
pub const namespace = 0x39;
|
||||
pub const imported_module = 0x3a;
|
||||
pub const unspecified_type = 0x3b;
|
||||
pub const partial_unit = 0x3c;
|
||||
pub const imported_unit = 0x3d;
|
||||
pub const condition = 0x3f;
|
||||
pub const shared_type = 0x40;
|
||||
|
||||
// DWARF 4
|
||||
pub const type_unit = 0x41;
|
||||
pub const rvalue_reference_type = 0x42;
|
||||
pub const template_alias = 0x43;
|
||||
|
||||
pub const lo_user = 0x4080;
|
||||
pub const hi_user = 0xffff;
|
||||
|
||||
// SGI/MIPS Extensions.
|
||||
pub const MIPS_loop = 0x4081;
|
||||
|
||||
// HP extensions. See: ftp://ftp.hp.com/pub/lang/tools/WDB/wdb-4.0.tar.gz .
|
||||
pub const HP_array_descriptor = 0x4090;
|
||||
pub const HP_Bliss_field = 0x4091;
|
||||
pub const HP_Bliss_field_set = 0x4092;
|
||||
|
||||
// GNU extensions.
|
||||
pub const format_label = 0x4101; // For FORTRAN 77 and Fortran 90.
|
||||
pub const function_template = 0x4102; // For C++.
|
||||
pub const class_template = 0x4103; //For C++.
|
||||
pub const GNU_BINCL = 0x4104;
|
||||
pub const GNU_EINCL = 0x4105;
|
||||
|
||||
// Template template parameter.
|
||||
// See http://gcc.gnu.org/wiki/TemplateParmsDwarf .
|
||||
pub const GNU_template_template_param = 0x4106;
|
||||
|
||||
// Template parameter pack extension = specified at
|
||||
// http://wiki.dwarfstd.org/index.php?title=C%2B%2B0x:_Variadic_templates
|
||||
// The values of these two TAGS are in the DW_TAG_GNU_* space until the tags
|
||||
// are properly part of DWARF 5.
|
||||
pub const GNU_template_parameter_pack = 0x4107;
|
||||
pub const GNU_formal_parameter_pack = 0x4108;
|
||||
// The GNU call site extension = specified at
|
||||
// http://www.dwarfstd.org/ShowIssue.php?issue=100909.2&type=open .
|
||||
// The values of these two TAGS are in the DW_TAG_GNU_* space until the tags
|
||||
// are properly part of DWARF 5.
|
||||
pub const GNU_call_site = 0x4109;
|
||||
pub const GNU_call_site_parameter = 0x410a;
|
||||
// Extensions for UPC. See: http://dwarfstd.org/doc/DWARF4.pdf.
|
||||
pub const upc_shared_type = 0x8765;
|
||||
pub const upc_strict_type = 0x8766;
|
||||
pub const upc_relaxed_type = 0x8767;
|
||||
// PGI (STMicroelectronics; extensions. No documentation available.
|
||||
pub const PGI_kanji_type = 0xA000;
|
||||
pub const PGI_interface_block = 0xA020;
|
||||
@ -1,699 +0,0 @@
|
||||
pub const TAG_padding = 0x00;
|
||||
pub const TAG_array_type = 0x01;
|
||||
pub const TAG_class_type = 0x02;
|
||||
pub const TAG_entry_point = 0x03;
|
||||
pub const TAG_enumeration_type = 0x04;
|
||||
pub const TAG_formal_parameter = 0x05;
|
||||
pub const TAG_imported_declaration = 0x08;
|
||||
pub const TAG_label = 0x0a;
|
||||
pub const TAG_lexical_block = 0x0b;
|
||||
pub const TAG_member = 0x0d;
|
||||
pub const TAG_pointer_type = 0x0f;
|
||||
pub const TAG_reference_type = 0x10;
|
||||
pub const TAG_compile_unit = 0x11;
|
||||
pub const TAG_string_type = 0x12;
|
||||
pub const TAG_structure_type = 0x13;
|
||||
pub const TAG_subroutine = 0x14;
|
||||
pub const TAG_subroutine_type = 0x15;
|
||||
pub const TAG_typedef = 0x16;
|
||||
pub const TAG_union_type = 0x17;
|
||||
pub const TAG_unspecified_parameters = 0x18;
|
||||
pub const TAG_variant = 0x19;
|
||||
pub const TAG_common_block = 0x1a;
|
||||
pub const TAG_common_inclusion = 0x1b;
|
||||
pub const TAG_inheritance = 0x1c;
|
||||
pub const TAG_inlined_subroutine = 0x1d;
|
||||
pub const TAG_module = 0x1e;
|
||||
pub const TAG_ptr_to_member_type = 0x1f;
|
||||
pub const TAG_set_type = 0x20;
|
||||
pub const TAG_subrange_type = 0x21;
|
||||
pub const TAG_with_stmt = 0x22;
|
||||
pub const TAG_access_declaration = 0x23;
|
||||
pub const TAG_base_type = 0x24;
|
||||
pub const TAG_catch_block = 0x25;
|
||||
pub const TAG_const_type = 0x26;
|
||||
pub const TAG_constant = 0x27;
|
||||
pub const TAG_enumerator = 0x28;
|
||||
pub const TAG_file_type = 0x29;
|
||||
pub const TAG_friend = 0x2a;
|
||||
pub const TAG_namelist = 0x2b;
|
||||
pub const TAG_namelist_item = 0x2c;
|
||||
pub const TAG_packed_type = 0x2d;
|
||||
pub const TAG_subprogram = 0x2e;
|
||||
pub const TAG_template_type_param = 0x2f;
|
||||
pub const TAG_template_value_param = 0x30;
|
||||
pub const TAG_thrown_type = 0x31;
|
||||
pub const TAG_try_block = 0x32;
|
||||
pub const TAG_variant_part = 0x33;
|
||||
pub const TAG_variable = 0x34;
|
||||
pub const TAG_volatile_type = 0x35;
|
||||
|
||||
// DWARF 3
|
||||
pub const TAG_dwarf_procedure = 0x36;
|
||||
pub const TAG_restrict_type = 0x37;
|
||||
pub const TAG_interface_type = 0x38;
|
||||
pub const TAG_namespace = 0x39;
|
||||
pub const TAG_imported_module = 0x3a;
|
||||
pub const TAG_unspecified_type = 0x3b;
|
||||
pub const TAG_partial_unit = 0x3c;
|
||||
pub const TAG_imported_unit = 0x3d;
|
||||
pub const TAG_condition = 0x3f;
|
||||
pub const TAG_shared_type = 0x40;
|
||||
|
||||
// DWARF 4
|
||||
pub const TAG_type_unit = 0x41;
|
||||
pub const TAG_rvalue_reference_type = 0x42;
|
||||
pub const TAG_template_alias = 0x43;
|
||||
|
||||
pub const TAG_lo_user = 0x4080;
|
||||
pub const TAG_hi_user = 0xffff;
|
||||
|
||||
// SGI/MIPS Extensions.
|
||||
pub const TAG_MIPS_loop = 0x4081;
|
||||
|
||||
// HP extensions. See: ftp://ftp.hp.com/pub/lang/tools/WDB/wdb-4.0.tar.gz .
|
||||
pub const TAG_HP_array_descriptor = 0x4090;
|
||||
pub const TAG_HP_Bliss_field = 0x4091;
|
||||
pub const TAG_HP_Bliss_field_set = 0x4092;
|
||||
|
||||
// GNU extensions.
|
||||
pub const TAG_format_label = 0x4101; // For FORTRAN 77 and Fortran 90.
|
||||
pub const TAG_function_template = 0x4102; // For C++.
|
||||
pub const TAG_class_template = 0x4103; //For C++.
|
||||
pub const TAG_GNU_BINCL = 0x4104;
|
||||
pub const TAG_GNU_EINCL = 0x4105;
|
||||
|
||||
// Template template parameter.
|
||||
// See http://gcc.gnu.org/wiki/TemplateParmsDwarf .
|
||||
pub const TAG_GNU_template_template_param = 0x4106;
|
||||
|
||||
// Template parameter pack extension = specified at
|
||||
// http://wiki.dwarfstd.org/index.php?title=C%2B%2B0x:_Variadic_templates
|
||||
// The values of these two TAGS are in the DW_TAG_GNU_* space until the tags
|
||||
// are properly part of DWARF 5.
|
||||
pub const TAG_GNU_template_parameter_pack = 0x4107;
|
||||
pub const TAG_GNU_formal_parameter_pack = 0x4108;
|
||||
// The GNU call site extension = specified at
|
||||
// http://www.dwarfstd.org/ShowIssue.php?issue=100909.2&type=open .
|
||||
// The values of these two TAGS are in the DW_TAG_GNU_* space until the tags
|
||||
// are properly part of DWARF 5.
|
||||
pub const TAG_GNU_call_site = 0x4109;
|
||||
pub const TAG_GNU_call_site_parameter = 0x410a;
|
||||
// Extensions for UPC. See: http://dwarfstd.org/doc/DWARF4.pdf.
|
||||
pub const TAG_upc_shared_type = 0x8765;
|
||||
pub const TAG_upc_strict_type = 0x8766;
|
||||
pub const TAG_upc_relaxed_type = 0x8767;
|
||||
// PGI (STMicroelectronics; extensions. No documentation available.
|
||||
pub const TAG_PGI_kanji_type = 0xA000;
|
||||
pub const TAG_PGI_interface_block = 0xA020;
|
||||
|
||||
pub const FORM_addr = 0x01;
|
||||
pub const FORM_block2 = 0x03;
|
||||
pub const FORM_block4 = 0x04;
|
||||
pub const FORM_data2 = 0x05;
|
||||
pub const FORM_data4 = 0x06;
|
||||
pub const FORM_data8 = 0x07;
|
||||
pub const FORM_string = 0x08;
|
||||
pub const FORM_block = 0x09;
|
||||
pub const FORM_block1 = 0x0a;
|
||||
pub const FORM_data1 = 0x0b;
|
||||
pub const FORM_flag = 0x0c;
|
||||
pub const FORM_sdata = 0x0d;
|
||||
pub const FORM_strp = 0x0e;
|
||||
pub const FORM_udata = 0x0f;
|
||||
pub const FORM_ref_addr = 0x10;
|
||||
pub const FORM_ref1 = 0x11;
|
||||
pub const FORM_ref2 = 0x12;
|
||||
pub const FORM_ref4 = 0x13;
|
||||
pub const FORM_ref8 = 0x14;
|
||||
pub const FORM_ref_udata = 0x15;
|
||||
pub const FORM_indirect = 0x16;
|
||||
pub const FORM_sec_offset = 0x17;
|
||||
pub const FORM_exprloc = 0x18;
|
||||
pub const FORM_flag_present = 0x19;
|
||||
pub const FORM_ref_sig8 = 0x20;
|
||||
|
||||
// Extensions for Fission. See http://gcc.gnu.org/wiki/DebugFission.
|
||||
pub const FORM_GNU_addr_index = 0x1f01;
|
||||
pub const FORM_GNU_str_index = 0x1f02;
|
||||
|
||||
// Extensions for DWZ multifile.
|
||||
// See http://www.dwarfstd.org/ShowIssue.php?issue=120604.1&type=open .
|
||||
pub const FORM_GNU_ref_alt = 0x1f20;
|
||||
pub const FORM_GNU_strp_alt = 0x1f21;
|
||||
|
||||
pub const AT_sibling = 0x01;
|
||||
pub const AT_location = 0x02;
|
||||
pub const AT_name = 0x03;
|
||||
pub const AT_ordering = 0x09;
|
||||
pub const AT_subscr_data = 0x0a;
|
||||
pub const AT_byte_size = 0x0b;
|
||||
pub const AT_bit_offset = 0x0c;
|
||||
pub const AT_bit_size = 0x0d;
|
||||
pub const AT_element_list = 0x0f;
|
||||
pub const AT_stmt_list = 0x10;
|
||||
pub const AT_low_pc = 0x11;
|
||||
pub const AT_high_pc = 0x12;
|
||||
pub const AT_language = 0x13;
|
||||
pub const AT_member = 0x14;
|
||||
pub const AT_discr = 0x15;
|
||||
pub const AT_discr_value = 0x16;
|
||||
pub const AT_visibility = 0x17;
|
||||
pub const AT_import = 0x18;
|
||||
pub const AT_string_length = 0x19;
|
||||
pub const AT_common_reference = 0x1a;
|
||||
pub const AT_comp_dir = 0x1b;
|
||||
pub const AT_const_value = 0x1c;
|
||||
pub const AT_containing_type = 0x1d;
|
||||
pub const AT_default_value = 0x1e;
|
||||
pub const AT_inline = 0x20;
|
||||
pub const AT_is_optional = 0x21;
|
||||
pub const AT_lower_bound = 0x22;
|
||||
pub const AT_producer = 0x25;
|
||||
pub const AT_prototyped = 0x27;
|
||||
pub const AT_return_addr = 0x2a;
|
||||
pub const AT_start_scope = 0x2c;
|
||||
pub const AT_bit_stride = 0x2e;
|
||||
pub const AT_upper_bound = 0x2f;
|
||||
pub const AT_abstract_origin = 0x31;
|
||||
pub const AT_accessibility = 0x32;
|
||||
pub const AT_address_class = 0x33;
|
||||
pub const AT_artificial = 0x34;
|
||||
pub const AT_base_types = 0x35;
|
||||
pub const AT_calling_convention = 0x36;
|
||||
pub const AT_count = 0x37;
|
||||
pub const AT_data_member_location = 0x38;
|
||||
pub const AT_decl_column = 0x39;
|
||||
pub const AT_decl_file = 0x3a;
|
||||
pub const AT_decl_line = 0x3b;
|
||||
pub const AT_declaration = 0x3c;
|
||||
pub const AT_discr_list = 0x3d;
|
||||
pub const AT_encoding = 0x3e;
|
||||
pub const AT_external = 0x3f;
|
||||
pub const AT_frame_base = 0x40;
|
||||
pub const AT_friend = 0x41;
|
||||
pub const AT_identifier_case = 0x42;
|
||||
pub const AT_macro_info = 0x43;
|
||||
pub const AT_namelist_items = 0x44;
|
||||
pub const AT_priority = 0x45;
|
||||
pub const AT_segment = 0x46;
|
||||
pub const AT_specification = 0x47;
|
||||
pub const AT_static_link = 0x48;
|
||||
pub const AT_type = 0x49;
|
||||
pub const AT_use_location = 0x4a;
|
||||
pub const AT_variable_parameter = 0x4b;
|
||||
pub const AT_virtuality = 0x4c;
|
||||
pub const AT_vtable_elem_location = 0x4d;
|
||||
|
||||
// DWARF 3 values.
|
||||
pub const AT_allocated = 0x4e;
|
||||
pub const AT_associated = 0x4f;
|
||||
pub const AT_data_location = 0x50;
|
||||
pub const AT_byte_stride = 0x51;
|
||||
pub const AT_entry_pc = 0x52;
|
||||
pub const AT_use_UTF8 = 0x53;
|
||||
pub const AT_extension = 0x54;
|
||||
pub const AT_ranges = 0x55;
|
||||
pub const AT_trampoline = 0x56;
|
||||
pub const AT_call_column = 0x57;
|
||||
pub const AT_call_file = 0x58;
|
||||
pub const AT_call_line = 0x59;
|
||||
pub const AT_description = 0x5a;
|
||||
pub const AT_binary_scale = 0x5b;
|
||||
pub const AT_decimal_scale = 0x5c;
|
||||
pub const AT_small = 0x5d;
|
||||
pub const AT_decimal_sign = 0x5e;
|
||||
pub const AT_digit_count = 0x5f;
|
||||
pub const AT_picture_string = 0x60;
|
||||
pub const AT_mutable = 0x61;
|
||||
pub const AT_threads_scaled = 0x62;
|
||||
pub const AT_explicit = 0x63;
|
||||
pub const AT_object_pointer = 0x64;
|
||||
pub const AT_endianity = 0x65;
|
||||
pub const AT_elemental = 0x66;
|
||||
pub const AT_pure = 0x67;
|
||||
pub const AT_recursive = 0x68;
|
||||
|
||||
// DWARF 4.
|
||||
pub const AT_signature = 0x69;
|
||||
pub const AT_main_subprogram = 0x6a;
|
||||
pub const AT_data_bit_offset = 0x6b;
|
||||
pub const AT_const_expr = 0x6c;
|
||||
pub const AT_enum_class = 0x6d;
|
||||
pub const AT_linkage_name = 0x6e;
|
||||
|
||||
// DWARF 5
|
||||
pub const AT_alignment = 0x88;
|
||||
|
||||
pub const AT_lo_user = 0x2000; // Implementation-defined range start.
|
||||
pub const AT_hi_user = 0x3fff; // Implementation-defined range end.
|
||||
|
||||
// SGI/MIPS extensions.
|
||||
pub const AT_MIPS_fde = 0x2001;
|
||||
pub const AT_MIPS_loop_begin = 0x2002;
|
||||
pub const AT_MIPS_tail_loop_begin = 0x2003;
|
||||
pub const AT_MIPS_epilog_begin = 0x2004;
|
||||
pub const AT_MIPS_loop_unroll_factor = 0x2005;
|
||||
pub const AT_MIPS_software_pipeline_depth = 0x2006;
|
||||
pub const AT_MIPS_linkage_name = 0x2007;
|
||||
pub const AT_MIPS_stride = 0x2008;
|
||||
pub const AT_MIPS_abstract_name = 0x2009;
|
||||
pub const AT_MIPS_clone_origin = 0x200a;
|
||||
pub const AT_MIPS_has_inlines = 0x200b;
|
||||
|
||||
// HP extensions.
|
||||
pub const AT_HP_block_index = 0x2000;
|
||||
pub const AT_HP_unmodifiable = 0x2001; // Same as AT_MIPS_fde.
|
||||
pub const AT_HP_prologue = 0x2005; // Same as AT_MIPS_loop_unroll.
|
||||
pub const AT_HP_epilogue = 0x2008; // Same as AT_MIPS_stride.
|
||||
pub const AT_HP_actuals_stmt_list = 0x2010;
|
||||
pub const AT_HP_proc_per_section = 0x2011;
|
||||
pub const AT_HP_raw_data_ptr = 0x2012;
|
||||
pub const AT_HP_pass_by_reference = 0x2013;
|
||||
pub const AT_HP_opt_level = 0x2014;
|
||||
pub const AT_HP_prof_version_id = 0x2015;
|
||||
pub const AT_HP_opt_flags = 0x2016;
|
||||
pub const AT_HP_cold_region_low_pc = 0x2017;
|
||||
pub const AT_HP_cold_region_high_pc = 0x2018;
|
||||
pub const AT_HP_all_variables_modifiable = 0x2019;
|
||||
pub const AT_HP_linkage_name = 0x201a;
|
||||
pub const AT_HP_prof_flags = 0x201b; // In comp unit of procs_info for -g.
|
||||
pub const AT_HP_unit_name = 0x201f;
|
||||
pub const AT_HP_unit_size = 0x2020;
|
||||
pub const AT_HP_widened_byte_size = 0x2021;
|
||||
pub const AT_HP_definition_points = 0x2022;
|
||||
pub const AT_HP_default_location = 0x2023;
|
||||
pub const AT_HP_is_result_param = 0x2029;
|
||||
|
||||
// GNU extensions.
|
||||
pub const AT_sf_names = 0x2101;
|
||||
pub const AT_src_info = 0x2102;
|
||||
pub const AT_mac_info = 0x2103;
|
||||
pub const AT_src_coords = 0x2104;
|
||||
pub const AT_body_begin = 0x2105;
|
||||
pub const AT_body_end = 0x2106;
|
||||
pub const AT_GNU_vector = 0x2107;
|
||||
// Thread-safety annotations.
|
||||
// See http://gcc.gnu.org/wiki/ThreadSafetyAnnotation .
|
||||
pub const AT_GNU_guarded_by = 0x2108;
|
||||
pub const AT_GNU_pt_guarded_by = 0x2109;
|
||||
pub const AT_GNU_guarded = 0x210a;
|
||||
pub const AT_GNU_pt_guarded = 0x210b;
|
||||
pub const AT_GNU_locks_excluded = 0x210c;
|
||||
pub const AT_GNU_exclusive_locks_required = 0x210d;
|
||||
pub const AT_GNU_shared_locks_required = 0x210e;
|
||||
// One-definition rule violation detection.
|
||||
// See http://gcc.gnu.org/wiki/DwarfSeparateTypeInfo .
|
||||
pub const AT_GNU_odr_signature = 0x210f;
|
||||
// Template template argument name.
|
||||
// See http://gcc.gnu.org/wiki/TemplateParmsDwarf .
|
||||
pub const AT_GNU_template_name = 0x2110;
|
||||
// The GNU call site extension.
|
||||
// See http://www.dwarfstd.org/ShowIssue.php?issue=100909.2&type=open .
|
||||
pub const AT_GNU_call_site_value = 0x2111;
|
||||
pub const AT_GNU_call_site_data_value = 0x2112;
|
||||
pub const AT_GNU_call_site_target = 0x2113;
|
||||
pub const AT_GNU_call_site_target_clobbered = 0x2114;
|
||||
pub const AT_GNU_tail_call = 0x2115;
|
||||
pub const AT_GNU_all_tail_call_sites = 0x2116;
|
||||
pub const AT_GNU_all_call_sites = 0x2117;
|
||||
pub const AT_GNU_all_source_call_sites = 0x2118;
|
||||
// Section offset into .debug_macro section.
|
||||
pub const AT_GNU_macros = 0x2119;
|
||||
// Extensions for Fission. See http://gcc.gnu.org/wiki/DebugFission.
|
||||
pub const AT_GNU_dwo_name = 0x2130;
|
||||
pub const AT_GNU_dwo_id = 0x2131;
|
||||
pub const AT_GNU_ranges_base = 0x2132;
|
||||
pub const AT_GNU_addr_base = 0x2133;
|
||||
pub const AT_GNU_pubnames = 0x2134;
|
||||
pub const AT_GNU_pubtypes = 0x2135;
|
||||
// VMS extensions.
|
||||
pub const AT_VMS_rtnbeg_pd_address = 0x2201;
|
||||
// GNAT extensions.
|
||||
// GNAT descriptive type.
|
||||
// See http://gcc.gnu.org/wiki/DW_AT_GNAT_descriptive_type .
|
||||
pub const AT_use_GNAT_descriptive_type = 0x2301;
|
||||
pub const AT_GNAT_descriptive_type = 0x2302;
|
||||
// UPC extension.
|
||||
pub const AT_upc_threads_scaled = 0x3210;
|
||||
// PGI (STMicroelectronics) extensions.
|
||||
pub const AT_PGI_lbase = 0x3a00;
|
||||
pub const AT_PGI_soffset = 0x3a01;
|
||||
pub const AT_PGI_lstride = 0x3a02;
|
||||
|
||||
pub const OP_addr = 0x03;
|
||||
pub const OP_deref = 0x06;
|
||||
pub const OP_const1u = 0x08;
|
||||
pub const OP_const1s = 0x09;
|
||||
pub const OP_const2u = 0x0a;
|
||||
pub const OP_const2s = 0x0b;
|
||||
pub const OP_const4u = 0x0c;
|
||||
pub const OP_const4s = 0x0d;
|
||||
pub const OP_const8u = 0x0e;
|
||||
pub const OP_const8s = 0x0f;
|
||||
pub const OP_constu = 0x10;
|
||||
pub const OP_consts = 0x11;
|
||||
pub const OP_dup = 0x12;
|
||||
pub const OP_drop = 0x13;
|
||||
pub const OP_over = 0x14;
|
||||
pub const OP_pick = 0x15;
|
||||
pub const OP_swap = 0x16;
|
||||
pub const OP_rot = 0x17;
|
||||
pub const OP_xderef = 0x18;
|
||||
pub const OP_abs = 0x19;
|
||||
pub const OP_and = 0x1a;
|
||||
pub const OP_div = 0x1b;
|
||||
pub const OP_minus = 0x1c;
|
||||
pub const OP_mod = 0x1d;
|
||||
pub const OP_mul = 0x1e;
|
||||
pub const OP_neg = 0x1f;
|
||||
pub const OP_not = 0x20;
|
||||
pub const OP_or = 0x21;
|
||||
pub const OP_plus = 0x22;
|
||||
pub const OP_plus_uconst = 0x23;
|
||||
pub const OP_shl = 0x24;
|
||||
pub const OP_shr = 0x25;
|
||||
pub const OP_shra = 0x26;
|
||||
pub const OP_xor = 0x27;
|
||||
pub const OP_bra = 0x28;
|
||||
pub const OP_eq = 0x29;
|
||||
pub const OP_ge = 0x2a;
|
||||
pub const OP_gt = 0x2b;
|
||||
pub const OP_le = 0x2c;
|
||||
pub const OP_lt = 0x2d;
|
||||
pub const OP_ne = 0x2e;
|
||||
pub const OP_skip = 0x2f;
|
||||
pub const OP_lit0 = 0x30;
|
||||
pub const OP_lit1 = 0x31;
|
||||
pub const OP_lit2 = 0x32;
|
||||
pub const OP_lit3 = 0x33;
|
||||
pub const OP_lit4 = 0x34;
|
||||
pub const OP_lit5 = 0x35;
|
||||
pub const OP_lit6 = 0x36;
|
||||
pub const OP_lit7 = 0x37;
|
||||
pub const OP_lit8 = 0x38;
|
||||
pub const OP_lit9 = 0x39;
|
||||
pub const OP_lit10 = 0x3a;
|
||||
pub const OP_lit11 = 0x3b;
|
||||
pub const OP_lit12 = 0x3c;
|
||||
pub const OP_lit13 = 0x3d;
|
||||
pub const OP_lit14 = 0x3e;
|
||||
pub const OP_lit15 = 0x3f;
|
||||
pub const OP_lit16 = 0x40;
|
||||
pub const OP_lit17 = 0x41;
|
||||
pub const OP_lit18 = 0x42;
|
||||
pub const OP_lit19 = 0x43;
|
||||
pub const OP_lit20 = 0x44;
|
||||
pub const OP_lit21 = 0x45;
|
||||
pub const OP_lit22 = 0x46;
|
||||
pub const OP_lit23 = 0x47;
|
||||
pub const OP_lit24 = 0x48;
|
||||
pub const OP_lit25 = 0x49;
|
||||
pub const OP_lit26 = 0x4a;
|
||||
pub const OP_lit27 = 0x4b;
|
||||
pub const OP_lit28 = 0x4c;
|
||||
pub const OP_lit29 = 0x4d;
|
||||
pub const OP_lit30 = 0x4e;
|
||||
pub const OP_lit31 = 0x4f;
|
||||
pub const OP_reg0 = 0x50;
|
||||
pub const OP_reg1 = 0x51;
|
||||
pub const OP_reg2 = 0x52;
|
||||
pub const OP_reg3 = 0x53;
|
||||
pub const OP_reg4 = 0x54;
|
||||
pub const OP_reg5 = 0x55;
|
||||
pub const OP_reg6 = 0x56;
|
||||
pub const OP_reg7 = 0x57;
|
||||
pub const OP_reg8 = 0x58;
|
||||
pub const OP_reg9 = 0x59;
|
||||
pub const OP_reg10 = 0x5a;
|
||||
pub const OP_reg11 = 0x5b;
|
||||
pub const OP_reg12 = 0x5c;
|
||||
pub const OP_reg13 = 0x5d;
|
||||
pub const OP_reg14 = 0x5e;
|
||||
pub const OP_reg15 = 0x5f;
|
||||
pub const OP_reg16 = 0x60;
|
||||
pub const OP_reg17 = 0x61;
|
||||
pub const OP_reg18 = 0x62;
|
||||
pub const OP_reg19 = 0x63;
|
||||
pub const OP_reg20 = 0x64;
|
||||
pub const OP_reg21 = 0x65;
|
||||
pub const OP_reg22 = 0x66;
|
||||
pub const OP_reg23 = 0x67;
|
||||
pub const OP_reg24 = 0x68;
|
||||
pub const OP_reg25 = 0x69;
|
||||
pub const OP_reg26 = 0x6a;
|
||||
pub const OP_reg27 = 0x6b;
|
||||
pub const OP_reg28 = 0x6c;
|
||||
pub const OP_reg29 = 0x6d;
|
||||
pub const OP_reg30 = 0x6e;
|
||||
pub const OP_reg31 = 0x6f;
|
||||
pub const OP_breg0 = 0x70;
|
||||
pub const OP_breg1 = 0x71;
|
||||
pub const OP_breg2 = 0x72;
|
||||
pub const OP_breg3 = 0x73;
|
||||
pub const OP_breg4 = 0x74;
|
||||
pub const OP_breg5 = 0x75;
|
||||
pub const OP_breg6 = 0x76;
|
||||
pub const OP_breg7 = 0x77;
|
||||
pub const OP_breg8 = 0x78;
|
||||
pub const OP_breg9 = 0x79;
|
||||
pub const OP_breg10 = 0x7a;
|
||||
pub const OP_breg11 = 0x7b;
|
||||
pub const OP_breg12 = 0x7c;
|
||||
pub const OP_breg13 = 0x7d;
|
||||
pub const OP_breg14 = 0x7e;
|
||||
pub const OP_breg15 = 0x7f;
|
||||
pub const OP_breg16 = 0x80;
|
||||
pub const OP_breg17 = 0x81;
|
||||
pub const OP_breg18 = 0x82;
|
||||
pub const OP_breg19 = 0x83;
|
||||
pub const OP_breg20 = 0x84;
|
||||
pub const OP_breg21 = 0x85;
|
||||
pub const OP_breg22 = 0x86;
|
||||
pub const OP_breg23 = 0x87;
|
||||
pub const OP_breg24 = 0x88;
|
||||
pub const OP_breg25 = 0x89;
|
||||
pub const OP_breg26 = 0x8a;
|
||||
pub const OP_breg27 = 0x8b;
|
||||
pub const OP_breg28 = 0x8c;
|
||||
pub const OP_breg29 = 0x8d;
|
||||
pub const OP_breg30 = 0x8e;
|
||||
pub const OP_breg31 = 0x8f;
|
||||
pub const OP_regx = 0x90;
|
||||
pub const OP_fbreg = 0x91;
|
||||
pub const OP_bregx = 0x92;
|
||||
pub const OP_piece = 0x93;
|
||||
pub const OP_deref_size = 0x94;
|
||||
pub const OP_xderef_size = 0x95;
|
||||
pub const OP_nop = 0x96;
|
||||
|
||||
// DWARF 3 extensions.
|
||||
pub const OP_push_object_address = 0x97;
|
||||
pub const OP_call2 = 0x98;
|
||||
pub const OP_call4 = 0x99;
|
||||
pub const OP_call_ref = 0x9a;
|
||||
pub const OP_form_tls_address = 0x9b;
|
||||
pub const OP_call_frame_cfa = 0x9c;
|
||||
pub const OP_bit_piece = 0x9d;
|
||||
|
||||
// DWARF 4 extensions.
|
||||
pub const OP_implicit_value = 0x9e;
|
||||
pub const OP_stack_value = 0x9f;
|
||||
|
||||
pub const OP_lo_user = 0xe0; // Implementation-defined range start.
|
||||
pub const OP_hi_user = 0xff; // Implementation-defined range end.
|
||||
|
||||
// GNU extensions.
|
||||
pub const OP_GNU_push_tls_address = 0xe0;
|
||||
// The following is for marking variables that are uninitialized.
|
||||
pub const OP_GNU_uninit = 0xf0;
|
||||
pub const OP_GNU_encoded_addr = 0xf1;
|
||||
// The GNU implicit pointer extension.
|
||||
// See http://www.dwarfstd.org/ShowIssue.php?issue=100831.1&type=open .
|
||||
pub const OP_GNU_implicit_pointer = 0xf2;
|
||||
// The GNU entry value extension.
|
||||
// See http://www.dwarfstd.org/ShowIssue.php?issue=100909.1&type=open .
|
||||
pub const OP_GNU_entry_value = 0xf3;
|
||||
// The GNU typed stack extension.
|
||||
// See http://www.dwarfstd.org/doc/040408.1.html .
|
||||
pub const OP_GNU_const_type = 0xf4;
|
||||
pub const OP_GNU_regval_type = 0xf5;
|
||||
pub const OP_GNU_deref_type = 0xf6;
|
||||
pub const OP_GNU_convert = 0xf7;
|
||||
pub const OP_GNU_reinterpret = 0xf9;
|
||||
// The GNU parameter ref extension.
|
||||
pub const OP_GNU_parameter_ref = 0xfa;
|
||||
// Extension for Fission. See http://gcc.gnu.org/wiki/DebugFission.
|
||||
pub const OP_GNU_addr_index = 0xfb;
|
||||
pub const OP_GNU_const_index = 0xfc;
|
||||
// HP extensions.
|
||||
pub const OP_HP_unknown = 0xe0; // Ouch, the same as GNU_push_tls_address.
|
||||
pub const OP_HP_is_value = 0xe1;
|
||||
pub const OP_HP_fltconst4 = 0xe2;
|
||||
pub const OP_HP_fltconst8 = 0xe3;
|
||||
pub const OP_HP_mod_range = 0xe4;
|
||||
pub const OP_HP_unmod_range = 0xe5;
|
||||
pub const OP_HP_tls = 0xe6;
|
||||
// PGI (STMicroelectronics) extensions.
|
||||
pub const OP_PGI_omp_thread_num = 0xf8;
|
||||
|
||||
pub const ATE_void = 0x0;
|
||||
pub const ATE_address = 0x1;
|
||||
pub const ATE_boolean = 0x2;
|
||||
pub const ATE_complex_float = 0x3;
|
||||
pub const ATE_float = 0x4;
|
||||
pub const ATE_signed = 0x5;
|
||||
pub const ATE_signed_char = 0x6;
|
||||
pub const ATE_unsigned = 0x7;
|
||||
pub const ATE_unsigned_char = 0x8;
|
||||
|
||||
// DWARF 3.
|
||||
pub const ATE_imaginary_float = 0x9;
|
||||
pub const ATE_packed_decimal = 0xa;
|
||||
pub const ATE_numeric_string = 0xb;
|
||||
pub const ATE_edited = 0xc;
|
||||
pub const ATE_signed_fixed = 0xd;
|
||||
pub const ATE_unsigned_fixed = 0xe;
|
||||
pub const ATE_decimal_float = 0xf;
|
||||
|
||||
// DWARF 4.
|
||||
pub const ATE_UTF = 0x10;
|
||||
|
||||
pub const ATE_lo_user = 0x80;
|
||||
pub const ATE_hi_user = 0xff;
|
||||
|
||||
// HP extensions.
|
||||
pub const ATE_HP_float80 = 0x80; // Floating-point (80 bit).
|
||||
pub const ATE_HP_complex_float80 = 0x81; // Complex floating-point (80 bit).
|
||||
pub const ATE_HP_float128 = 0x82; // Floating-point (128 bit).
|
||||
pub const ATE_HP_complex_float128 = 0x83; // Complex fp (128 bit).
|
||||
pub const ATE_HP_floathpintel = 0x84; // Floating-point (82 bit IA64).
|
||||
pub const ATE_HP_imaginary_float80 = 0x85;
|
||||
pub const ATE_HP_imaginary_float128 = 0x86;
|
||||
pub const ATE_HP_VAX_float = 0x88; // F or G floating.
|
||||
pub const ATE_HP_VAX_float_d = 0x89; // D floating.
|
||||
pub const ATE_HP_packed_decimal = 0x8a; // Cobol.
|
||||
pub const ATE_HP_zoned_decimal = 0x8b; // Cobol.
|
||||
pub const ATE_HP_edited = 0x8c; // Cobol.
|
||||
pub const ATE_HP_signed_fixed = 0x8d; // Cobol.
|
||||
pub const ATE_HP_unsigned_fixed = 0x8e; // Cobol.
|
||||
pub const ATE_HP_VAX_complex_float = 0x8f; // F or G floating complex.
|
||||
pub const ATE_HP_VAX_complex_float_d = 0x90; // D floating complex.
|
||||
|
||||
pub const CFA_advance_loc = 0x40;
|
||||
pub const CFA_offset = 0x80;
|
||||
pub const CFA_restore = 0xc0;
|
||||
pub const CFA_nop = 0x00;
|
||||
pub const CFA_set_loc = 0x01;
|
||||
pub const CFA_advance_loc1 = 0x02;
|
||||
pub const CFA_advance_loc2 = 0x03;
|
||||
pub const CFA_advance_loc4 = 0x04;
|
||||
pub const CFA_offset_extended = 0x05;
|
||||
pub const CFA_restore_extended = 0x06;
|
||||
pub const CFA_undefined = 0x07;
|
||||
pub const CFA_same_value = 0x08;
|
||||
pub const CFA_register = 0x09;
|
||||
pub const CFA_remember_state = 0x0a;
|
||||
pub const CFA_restore_state = 0x0b;
|
||||
pub const CFA_def_cfa = 0x0c;
|
||||
pub const CFA_def_cfa_register = 0x0d;
|
||||
pub const CFA_def_cfa_offset = 0x0e;
|
||||
|
||||
// DWARF 3.
|
||||
pub const CFA_def_cfa_expression = 0x0f;
|
||||
pub const CFA_expression = 0x10;
|
||||
pub const CFA_offset_extended_sf = 0x11;
|
||||
pub const CFA_def_cfa_sf = 0x12;
|
||||
pub const CFA_def_cfa_offset_sf = 0x13;
|
||||
pub const CFA_val_offset = 0x14;
|
||||
pub const CFA_val_offset_sf = 0x15;
|
||||
pub const CFA_val_expression = 0x16;
|
||||
|
||||
pub const CFA_lo_user = 0x1c;
|
||||
pub const CFA_hi_user = 0x3f;
|
||||
|
||||
// SGI/MIPS specific.
|
||||
pub const CFA_MIPS_advance_loc8 = 0x1d;
|
||||
|
||||
// GNU extensions.
|
||||
pub const CFA_GNU_window_save = 0x2d;
|
||||
pub const CFA_GNU_args_size = 0x2e;
|
||||
pub const CFA_GNU_negative_offset_extended = 0x2f;
|
||||
|
||||
pub const CHILDREN_no = 0x00;
|
||||
pub const CHILDREN_yes = 0x01;
|
||||
|
||||
pub const LNS_extended_op = 0x00;
|
||||
pub const LNS_copy = 0x01;
|
||||
pub const LNS_advance_pc = 0x02;
|
||||
pub const LNS_advance_line = 0x03;
|
||||
pub const LNS_set_file = 0x04;
|
||||
pub const LNS_set_column = 0x05;
|
||||
pub const LNS_negate_stmt = 0x06;
|
||||
pub const LNS_set_basic_block = 0x07;
|
||||
pub const LNS_const_add_pc = 0x08;
|
||||
pub const LNS_fixed_advance_pc = 0x09;
|
||||
pub const LNS_set_prologue_end = 0x0a;
|
||||
pub const LNS_set_epilogue_begin = 0x0b;
|
||||
pub const LNS_set_isa = 0x0c;
|
||||
|
||||
pub const LNE_end_sequence = 0x01;
|
||||
pub const LNE_set_address = 0x02;
|
||||
pub const LNE_define_file = 0x03;
|
||||
pub const LNE_set_discriminator = 0x04;
|
||||
pub const LNE_lo_user = 0x80;
|
||||
pub const LNE_hi_user = 0xff;
|
||||
|
||||
pub const LANG_C89 = 0x0001;
|
||||
pub const LANG_C = 0x0002;
|
||||
pub const LANG_Ada83 = 0x0003;
|
||||
pub const LANG_C_plus_plus = 0x0004;
|
||||
pub const LANG_Cobol74 = 0x0005;
|
||||
pub const LANG_Cobol85 = 0x0006;
|
||||
pub const LANG_Fortran77 = 0x0007;
|
||||
pub const LANG_Fortran90 = 0x0008;
|
||||
pub const LANG_Pascal83 = 0x0009;
|
||||
pub const LANG_Modula2 = 0x000a;
|
||||
pub const LANG_Java = 0x000b;
|
||||
pub const LANG_C99 = 0x000c;
|
||||
pub const LANG_Ada95 = 0x000d;
|
||||
pub const LANG_Fortran95 = 0x000e;
|
||||
pub const LANG_PLI = 0x000f;
|
||||
pub const LANG_ObjC = 0x0010;
|
||||
pub const LANG_ObjC_plus_plus = 0x0011;
|
||||
pub const LANG_UPC = 0x0012;
|
||||
pub const LANG_D = 0x0013;
|
||||
pub const LANG_Python = 0x0014;
|
||||
pub const LANG_Go = 0x0016;
|
||||
pub const LANG_C_plus_plus_11 = 0x001a;
|
||||
pub const LANG_Rust = 0x001c;
|
||||
pub const LANG_C11 = 0x001d;
|
||||
pub const LANG_C_plus_plus_14 = 0x0021;
|
||||
pub const LANG_Fortran03 = 0x0022;
|
||||
pub const LANG_Fortran08 = 0x0023;
|
||||
pub const LANG_lo_user = 0x8000;
|
||||
pub const LANG_hi_user = 0xffff;
|
||||
pub const LANG_Mips_Assembler = 0x8001;
|
||||
pub const LANG_Upc = 0x8765;
|
||||
pub const LANG_HP_Bliss = 0x8003;
|
||||
pub const LANG_HP_Basic91 = 0x8004;
|
||||
pub const LANG_HP_Pascal91 = 0x8005;
|
||||
pub const LANG_HP_IMacro = 0x8006;
|
||||
pub const LANG_HP_Assembler = 0x8007;
|
||||
|
||||
pub const UT_compile = 0x01;
|
||||
pub const UT_type = 0x02;
|
||||
pub const UT_partial = 0x03;
|
||||
pub const UT_skeleton = 0x04;
|
||||
pub const UT_split_compile = 0x05;
|
||||
pub const UT_split_type = 0x06;
|
||||
pub const UT_lo_user = 0x80;
|
||||
pub const UT_hi_user = 0xff;
|
||||
|
||||
pub const LNCT_path = 0x1;
|
||||
pub const LNCT_directory_index = 0x2;
|
||||
pub const LNCT_timestamp = 0x3;
|
||||
pub const LNCT_size = 0x4;
|
||||
pub const LNCT_MD5 = 0x5;
|
||||
pub const LNCT_lo_user = 0x2000;
|
||||
pub const LNCT_hi_user = 0x3fff;
|
||||
@ -115,7 +115,7 @@ pub const ElfDynLib = struct {
|
||||
|
||||
/// Trusts the file. Malicious file will be able to execute arbitrary code.
|
||||
pub fn open(path: []const u8) !ElfDynLib {
|
||||
const fd = try os.open(path, 0, os.O_RDONLY | os.O_CLOEXEC);
|
||||
const fd = try os.open(path, 0, os.O.RDONLY | os.O.CLOEXEC);
|
||||
defer os.close(fd);
|
||||
|
||||
const stat = try os.fstat(fd);
|
||||
@ -126,8 +126,8 @@ pub const ElfDynLib = struct {
|
||||
const file_bytes = try os.mmap(
|
||||
null,
|
||||
mem.alignForward(size, mem.page_size),
|
||||
os.PROT_READ,
|
||||
os.MAP_PRIVATE,
|
||||
os.PROT.READ,
|
||||
os.MAP.PRIVATE,
|
||||
fd,
|
||||
0,
|
||||
);
|
||||
@ -160,12 +160,12 @@ pub const ElfDynLib = struct {
|
||||
}
|
||||
const dynv = maybe_dynv orelse return error.MissingDynamicLinkingInformation;
|
||||
|
||||
// Reserve the entire range (with no permissions) so that we can do MAP_FIXED below.
|
||||
// Reserve the entire range (with no permissions) so that we can do MAP.FIXED below.
|
||||
const all_loaded_mem = try os.mmap(
|
||||
null,
|
||||
virt_addr_end,
|
||||
os.PROT_NONE,
|
||||
os.MAP_PRIVATE | os.MAP_ANONYMOUS,
|
||||
os.PROT.NONE,
|
||||
os.MAP.PRIVATE | os.MAP.ANONYMOUS,
|
||||
-1,
|
||||
0,
|
||||
);
|
||||
@ -197,7 +197,7 @@ pub const ElfDynLib = struct {
|
||||
ptr,
|
||||
extended_memsz,
|
||||
prot,
|
||||
os.MAP_PRIVATE | os.MAP_FIXED,
|
||||
os.MAP.PRIVATE | os.MAP.FIXED,
|
||||
fd,
|
||||
ph.p_offset - extra_bytes,
|
||||
);
|
||||
@ -206,7 +206,7 @@ pub const ElfDynLib = struct {
|
||||
ptr,
|
||||
extended_memsz,
|
||||
prot,
|
||||
os.MAP_PRIVATE | os.MAP_FIXED | os.MAP_ANONYMOUS,
|
||||
os.MAP.PRIVATE | os.MAP.FIXED | os.MAP.ANONYMOUS,
|
||||
-1,
|
||||
0,
|
||||
);
|
||||
@ -294,10 +294,10 @@ pub const ElfDynLib = struct {
|
||||
}
|
||||
|
||||
fn elfToMmapProt(elf_prot: u64) u32 {
|
||||
var result: u32 = os.PROT_NONE;
|
||||
if ((elf_prot & elf.PF_R) != 0) result |= os.PROT_READ;
|
||||
if ((elf_prot & elf.PF_W) != 0) result |= os.PROT_WRITE;
|
||||
if ((elf_prot & elf.PF_X) != 0) result |= os.PROT_EXEC;
|
||||
var result: u32 = os.PROT.NONE;
|
||||
if ((elf_prot & elf.PF_R) != 0) result |= os.PROT.READ;
|
||||
if ((elf_prot & elf.PF_W) != 0) result |= os.PROT.WRITE;
|
||||
if ((elf_prot & elf.PF_X) != 0) result |= os.PROT.EXEC;
|
||||
return result;
|
||||
}
|
||||
};
|
||||
@ -373,7 +373,7 @@ pub const DlDynlib = struct {
|
||||
|
||||
pub fn openZ(path_c: [*:0]const u8) !DlDynlib {
|
||||
return DlDynlib{
|
||||
.handle = system.dlopen(path_c, system.RTLD_LAZY) orelse {
|
||||
.handle = system.dlopen(path_c, system.RTLD.LAZY) orelse {
|
||||
return error.FileNotFound;
|
||||
},
|
||||
};
|
||||
|
||||
@ -9,7 +9,7 @@ pub const RwLocked = @import("event/rwlocked.zig").RwLocked;
|
||||
pub const Loop = @import("event/loop.zig").Loop;
|
||||
pub const WaitGroup = @import("event/wait_group.zig").WaitGroup;
|
||||
|
||||
test "import event tests" {
|
||||
test {
|
||||
_ = @import("event/channel.zig");
|
||||
_ = @import("event/future.zig");
|
||||
_ = @import("event/group.zig");
|
||||
|
||||
@ -222,27 +222,27 @@ pub const Loop = struct {
|
||||
.handle = undefined,
|
||||
.overlapped = ResumeNode.overlapped_init,
|
||||
},
|
||||
.eventfd = try os.eventfd(1, os.EFD_CLOEXEC | os.EFD_NONBLOCK),
|
||||
.epoll_op = os.EPOLL_CTL_ADD,
|
||||
.eventfd = try os.eventfd(1, os.linux.EFD.CLOEXEC | os.linux.EFD.NONBLOCK),
|
||||
.epoll_op = os.linux.EPOLL.CTL_ADD,
|
||||
},
|
||||
.next = undefined,
|
||||
};
|
||||
self.available_eventfd_resume_nodes.push(eventfd_node);
|
||||
}
|
||||
|
||||
self.os_data.epollfd = try os.epoll_create1(os.EPOLL_CLOEXEC);
|
||||
self.os_data.epollfd = try os.epoll_create1(os.linux.EPOLL.CLOEXEC);
|
||||
errdefer os.close(self.os_data.epollfd);
|
||||
|
||||
self.os_data.final_eventfd = try os.eventfd(0, os.EFD_CLOEXEC | os.EFD_NONBLOCK);
|
||||
self.os_data.final_eventfd = try os.eventfd(0, os.linux.EFD.CLOEXEC | os.linux.EFD.NONBLOCK);
|
||||
errdefer os.close(self.os_data.final_eventfd);
|
||||
|
||||
self.os_data.final_eventfd_event = os.epoll_event{
|
||||
.events = os.EPOLLIN,
|
||||
.data = os.epoll_data{ .ptr = @ptrToInt(&self.final_resume_node) },
|
||||
self.os_data.final_eventfd_event = os.linux.epoll_event{
|
||||
.events = os.linux.EPOLL.IN,
|
||||
.data = os.linux.epoll_data{ .ptr = @ptrToInt(&self.final_resume_node) },
|
||||
};
|
||||
try os.epoll_ctl(
|
||||
self.os_data.epollfd,
|
||||
os.EPOLL_CTL_ADD,
|
||||
os.linux.EPOLL.CTL_ADD,
|
||||
self.os_data.final_eventfd,
|
||||
&self.os_data.final_eventfd_event,
|
||||
);
|
||||
@ -266,7 +266,7 @@ pub const Loop = struct {
|
||||
self.extra_threads[extra_thread_index] = try Thread.spawn(.{}, workerRun, .{self});
|
||||
}
|
||||
},
|
||||
.macos, .freebsd, .netbsd, .dragonfly, .openbsd => {
|
||||
.macos, .freebsd, .netbsd, .dragonfly => {
|
||||
self.os_data.kqfd = try os.kqueue();
|
||||
errdefer os.close(self.os_data.kqfd);
|
||||
|
||||
@ -283,8 +283,8 @@ pub const Loop = struct {
|
||||
// this one is for sending events
|
||||
.kevent = os.Kevent{
|
||||
.ident = i,
|
||||
.filter = os.EVFILT_USER,
|
||||
.flags = os.EV_CLEAR | os.EV_ADD | os.EV_DISABLE,
|
||||
.filter = os.system.EVFILT_USER,
|
||||
.flags = os.system.EV_CLEAR | os.system.EV_ADD | os.system.EV_DISABLE,
|
||||
.fflags = 0,
|
||||
.data = 0,
|
||||
.udata = @ptrToInt(&eventfd_node.data.base),
|
||||
@ -295,24 +295,87 @@ pub const Loop = struct {
|
||||
self.available_eventfd_resume_nodes.push(eventfd_node);
|
||||
const kevent_array = @as(*const [1]os.Kevent, &eventfd_node.data.kevent);
|
||||
_ = try os.kevent(self.os_data.kqfd, kevent_array, empty_kevs, null);
|
||||
eventfd_node.data.kevent.flags = os.EV_CLEAR | os.EV_ENABLE;
|
||||
eventfd_node.data.kevent.fflags = os.NOTE_TRIGGER;
|
||||
eventfd_node.data.kevent.flags = os.system.EV_CLEAR | os.system.EV_ENABLE;
|
||||
eventfd_node.data.kevent.fflags = os.system.NOTE_TRIGGER;
|
||||
}
|
||||
|
||||
// Pre-add so that we cannot get error.SystemResources
|
||||
// later when we try to activate it.
|
||||
self.os_data.final_kevent = os.Kevent{
|
||||
.ident = extra_thread_count,
|
||||
.filter = os.EVFILT_USER,
|
||||
.flags = os.EV_ADD | os.EV_DISABLE,
|
||||
.filter = os.system.EVFILT_USER,
|
||||
.flags = os.system.EV_ADD | os.system.EV_DISABLE,
|
||||
.fflags = 0,
|
||||
.data = 0,
|
||||
.udata = @ptrToInt(&self.final_resume_node),
|
||||
};
|
||||
const final_kev_arr = @as(*const [1]os.Kevent, &self.os_data.final_kevent);
|
||||
_ = try os.kevent(self.os_data.kqfd, final_kev_arr, empty_kevs, null);
|
||||
self.os_data.final_kevent.flags = os.EV_ENABLE;
|
||||
self.os_data.final_kevent.fflags = os.NOTE_TRIGGER;
|
||||
self.os_data.final_kevent.flags = os.system.EV_ENABLE;
|
||||
self.os_data.final_kevent.fflags = os.system.NOTE_TRIGGER;
|
||||
|
||||
if (builtin.single_threaded) {
|
||||
assert(extra_thread_count == 0);
|
||||
return;
|
||||
}
|
||||
|
||||
var extra_thread_index: usize = 0;
|
||||
errdefer {
|
||||
_ = os.kevent(self.os_data.kqfd, final_kev_arr, empty_kevs, null) catch unreachable;
|
||||
while (extra_thread_index != 0) {
|
||||
extra_thread_index -= 1;
|
||||
self.extra_threads[extra_thread_index].join();
|
||||
}
|
||||
}
|
||||
while (extra_thread_index < extra_thread_count) : (extra_thread_index += 1) {
|
||||
self.extra_threads[extra_thread_index] = try Thread.spawn(.{}, workerRun, .{self});
|
||||
}
|
||||
},
|
||||
.openbsd => {
|
||||
self.os_data.kqfd = try os.kqueue();
|
||||
errdefer os.close(self.os_data.kqfd);
|
||||
|
||||
const empty_kevs = &[0]os.Kevent{};
|
||||
|
||||
for (self.eventfd_resume_nodes) |*eventfd_node, i| {
|
||||
eventfd_node.* = std.atomic.Stack(ResumeNode.EventFd).Node{
|
||||
.data = ResumeNode.EventFd{
|
||||
.base = ResumeNode{
|
||||
.id = ResumeNode.Id.EventFd,
|
||||
.handle = undefined,
|
||||
.overlapped = ResumeNode.overlapped_init,
|
||||
},
|
||||
// this one is for sending events
|
||||
.kevent = os.Kevent{
|
||||
.ident = i,
|
||||
.filter = os.system.EVFILT_TIMER,
|
||||
.flags = os.system.EV_CLEAR | os.system.EV_ADD | os.system.EV_DISABLE | os.system.EV_ONESHOT,
|
||||
.fflags = 0,
|
||||
.data = 0,
|
||||
.udata = @ptrToInt(&eventfd_node.data.base),
|
||||
},
|
||||
},
|
||||
.next = undefined,
|
||||
};
|
||||
self.available_eventfd_resume_nodes.push(eventfd_node);
|
||||
const kevent_array = @as(*const [1]os.Kevent, &eventfd_node.data.kevent);
|
||||
_ = try os.kevent(self.os_data.kqfd, kevent_array, empty_kevs, null);
|
||||
eventfd_node.data.kevent.flags = os.system.EV_CLEAR | os.system.EV_ENABLE;
|
||||
}
|
||||
|
||||
// Pre-add so that we cannot get error.SystemResources
|
||||
// later when we try to activate it.
|
||||
self.os_data.final_kevent = os.Kevent{
|
||||
.ident = extra_thread_count,
|
||||
.filter = os.system.EVFILT_TIMER,
|
||||
.flags = os.system.EV_ADD | os.system.EV_ONESHOT | os.system.EV_DISABLE,
|
||||
.fflags = 0,
|
||||
.data = 0,
|
||||
.udata = @ptrToInt(&self.final_resume_node),
|
||||
};
|
||||
const final_kev_arr = @as(*const [1]os.Kevent, &self.os_data.final_kevent);
|
||||
_ = try os.kevent(self.os_data.kqfd, final_kev_arr, empty_kevs, null);
|
||||
self.os_data.final_kevent.flags = os.system.EV_ENABLE;
|
||||
|
||||
if (builtin.single_threaded) {
|
||||
assert(extra_thread_count == 0);
|
||||
@ -404,19 +467,19 @@ pub const Loop = struct {
|
||||
/// resume_node must live longer than the anyframe that it holds a reference to.
|
||||
/// flags must contain EPOLLET
|
||||
pub fn linuxAddFd(self: *Loop, fd: i32, resume_node: *ResumeNode, flags: u32) !void {
|
||||
assert(flags & os.EPOLLET == os.EPOLLET);
|
||||
assert(flags & os.linux.EPOLL.ET == os.linux.EPOLL.ET);
|
||||
self.beginOneEvent();
|
||||
errdefer self.finishOneEvent();
|
||||
try self.linuxModFd(
|
||||
fd,
|
||||
os.EPOLL_CTL_ADD,
|
||||
os.linux.EPOLL.CTL_ADD,
|
||||
flags,
|
||||
resume_node,
|
||||
);
|
||||
}
|
||||
|
||||
pub fn linuxModFd(self: *Loop, fd: i32, op: u32, flags: u32, resume_node: *ResumeNode) !void {
|
||||
assert(flags & os.EPOLLET == os.EPOLLET);
|
||||
assert(flags & os.linux.EPOLL.ET == os.linux.EPOLL.ET);
|
||||
var ev = os.linux.epoll_event{
|
||||
.events = flags,
|
||||
.data = os.linux.epoll_data{ .ptr = @ptrToInt(resume_node) },
|
||||
@ -425,13 +488,13 @@ pub const Loop = struct {
|
||||
}
|
||||
|
||||
pub fn linuxRemoveFd(self: *Loop, fd: i32) void {
|
||||
os.epoll_ctl(self.os_data.epollfd, os.linux.EPOLL_CTL_DEL, fd, null) catch {};
|
||||
os.epoll_ctl(self.os_data.epollfd, os.linux.EPOLL.CTL_DEL, fd, null) catch {};
|
||||
self.finishOneEvent();
|
||||
}
|
||||
|
||||
pub fn linuxWaitFd(self: *Loop, fd: i32, flags: u32) void {
|
||||
assert(flags & os.EPOLLET == os.EPOLLET);
|
||||
assert(flags & os.EPOLLONESHOT == os.EPOLLONESHOT);
|
||||
assert(flags & os.linux.EPOLL.ET == os.linux.EPOLL.ET);
|
||||
assert(flags & os.linux.EPOLL.ONESHOT == os.linux.EPOLL.ONESHOT);
|
||||
var resume_node = ResumeNode.Basic{
|
||||
.base = ResumeNode{
|
||||
.id = .Basic,
|
||||
@ -457,8 +520,8 @@ pub const Loop = struct {
|
||||
// Fall back to a blocking poll(). Ideally this codepath is never hit, since
|
||||
// epoll should be just fine. But this is better than incorrect behavior.
|
||||
var poll_flags: i16 = 0;
|
||||
if ((flags & os.EPOLLIN) != 0) poll_flags |= os.POLLIN;
|
||||
if ((flags & os.EPOLLOUT) != 0) poll_flags |= os.POLLOUT;
|
||||
if ((flags & os.linux.EPOLL.IN) != 0) poll_flags |= os.POLL.IN;
|
||||
if ((flags & os.linux.EPOLL.OUT) != 0) poll_flags |= os.POLL.OUT;
|
||||
var pfd = [1]os.pollfd{os.pollfd{
|
||||
.fd = fd,
|
||||
.events = poll_flags,
|
||||
@ -484,10 +547,10 @@ pub const Loop = struct {
|
||||
pub fn waitUntilFdReadable(self: *Loop, fd: os.fd_t) void {
|
||||
switch (builtin.os.tag) {
|
||||
.linux => {
|
||||
self.linuxWaitFd(fd, os.EPOLLET | os.EPOLLONESHOT | os.EPOLLIN);
|
||||
self.linuxWaitFd(fd, os.linux.EPOLL.ET | os.linux.EPOLL.ONESHOT | os.linux.EPOLL.IN);
|
||||
},
|
||||
.macos, .freebsd, .netbsd, .dragonfly, .openbsd => {
|
||||
self.bsdWaitKev(@intCast(usize, fd), os.EVFILT_READ, os.EV_ONESHOT);
|
||||
self.bsdWaitKev(@intCast(usize, fd), os.system.EVFILT_READ, os.system.EV_ONESHOT);
|
||||
},
|
||||
else => @compileError("Unsupported OS"),
|
||||
}
|
||||
@ -496,10 +559,10 @@ pub const Loop = struct {
|
||||
pub fn waitUntilFdWritable(self: *Loop, fd: os.fd_t) void {
|
||||
switch (builtin.os.tag) {
|
||||
.linux => {
|
||||
self.linuxWaitFd(fd, os.EPOLLET | os.EPOLLONESHOT | os.EPOLLOUT);
|
||||
self.linuxWaitFd(fd, os.linux.EPOLL.ET | os.linux.EPOLL.ONESHOT | os.linux.EPOLL.OUT);
|
||||
},
|
||||
.macos, .freebsd, .netbsd, .dragonfly, .openbsd => {
|
||||
self.bsdWaitKev(@intCast(usize, fd), os.EVFILT_WRITE, os.EV_ONESHOT);
|
||||
self.bsdWaitKev(@intCast(usize, fd), os.system.EVFILT_WRITE, os.system.EV_ONESHOT);
|
||||
},
|
||||
else => @compileError("Unsupported OS"),
|
||||
}
|
||||
@ -508,11 +571,11 @@ pub const Loop = struct {
|
||||
pub fn waitUntilFdWritableOrReadable(self: *Loop, fd: os.fd_t) void {
|
||||
switch (builtin.os.tag) {
|
||||
.linux => {
|
||||
self.linuxWaitFd(fd, os.EPOLLET | os.EPOLLONESHOT | os.EPOLLOUT | os.EPOLLIN);
|
||||
self.linuxWaitFd(fd, os.linux.EPOLL.ET | os.linux.EPOLL.ONESHOT | os.linux.EPOLL.OUT | os.linux.EPOLL.IN);
|
||||
},
|
||||
.macos, .freebsd, .netbsd, .dragonfly, .openbsd => {
|
||||
self.bsdWaitKev(@intCast(usize, fd), os.EVFILT_READ, os.EV_ONESHOT);
|
||||
self.bsdWaitKev(@intCast(usize, fd), os.EVFILT_WRITE, os.EV_ONESHOT);
|
||||
self.bsdWaitKev(@intCast(usize, fd), os.system.EVFILT_READ, os.system.EV_ONESHOT);
|
||||
self.bsdWaitKev(@intCast(usize, fd), os.system.EVFILT_WRITE, os.system.EV_ONESHOT);
|
||||
},
|
||||
else => @compileError("Unsupported OS"),
|
||||
}
|
||||
@ -530,7 +593,7 @@ pub const Loop = struct {
|
||||
|
||||
defer {
|
||||
// If the kevent was set to be ONESHOT, it doesn't need to be deleted manually.
|
||||
if (flags & os.EV_ONESHOT != 0) {
|
||||
if (flags & os.system.EV_ONESHOT != 0) {
|
||||
self.bsdRemoveKev(ident, filter);
|
||||
}
|
||||
}
|
||||
@ -547,7 +610,7 @@ pub const Loop = struct {
|
||||
var kev = [1]os.Kevent{os.Kevent{
|
||||
.ident = ident,
|
||||
.filter = filter,
|
||||
.flags = os.EV_ADD | os.EV_ENABLE | os.EV_CLEAR | flags,
|
||||
.flags = os.system.EV_ADD | os.system.EV_ENABLE | os.system.EV_CLEAR | flags,
|
||||
.fflags = 0,
|
||||
.data = 0,
|
||||
.udata = @ptrToInt(&resume_node.base),
|
||||
@ -560,7 +623,7 @@ pub const Loop = struct {
|
||||
var kev = [1]os.Kevent{os.Kevent{
|
||||
.ident = ident,
|
||||
.filter = filter,
|
||||
.flags = os.EV_DELETE,
|
||||
.flags = os.system.EV_DELETE,
|
||||
.fflags = 0,
|
||||
.data = 0,
|
||||
.udata = 0,
|
||||
@ -590,8 +653,8 @@ pub const Loop = struct {
|
||||
},
|
||||
.linux => {
|
||||
// the pending count is already accounted for
|
||||
const epoll_events = os.EPOLLONESHOT | os.linux.EPOLLIN | os.linux.EPOLLOUT |
|
||||
os.linux.EPOLLET;
|
||||
const epoll_events = os.linux.EPOLL.ONESHOT | os.linux.EPOLL.IN | os.linux.EPOLL.OUT |
|
||||
os.linux.EPOLL.ET;
|
||||
self.linuxModFd(
|
||||
eventfd_node.eventfd,
|
||||
eventfd_node.epoll_op,
|
||||
@ -903,12 +966,12 @@ pub const Loop = struct {
|
||||
/// will return a value greater than was supplied to the call.
|
||||
addr_size: *os.socklen_t,
|
||||
/// The following values can be bitwise ORed in flags to obtain different behavior:
|
||||
/// * `SOCK_CLOEXEC` - Set the close-on-exec (`FD_CLOEXEC`) flag on the new file descriptor. See the
|
||||
/// description of the `O_CLOEXEC` flag in `open` for reasons why this may be useful.
|
||||
/// * `SOCK.CLOEXEC` - Set the close-on-exec (`FD_CLOEXEC`) flag on the new file descriptor. See the
|
||||
/// description of the `O.CLOEXEC` flag in `open` for reasons why this may be useful.
|
||||
flags: u32,
|
||||
) os.AcceptError!os.socket_t {
|
||||
while (true) {
|
||||
return os.accept(sockfd, addr, addr_size, flags | os.SOCK_NONBLOCK) catch |err| switch (err) {
|
||||
return os.accept(sockfd, addr, addr_size, flags | os.SOCK.NONBLOCK) catch |err| switch (err) {
|
||||
error.WouldBlock => {
|
||||
self.waitUntilFdReadable(sockfd);
|
||||
continue;
|
||||
@ -1344,7 +1407,7 @@ pub const Loop = struct {
|
||||
.Stop => return,
|
||||
.EventFd => {
|
||||
const event_fd_node = @fieldParentPtr(ResumeNode.EventFd, "base", resume_node);
|
||||
event_fd_node.epoll_op = os.EPOLL_CTL_MOD;
|
||||
event_fd_node.epoll_op = os.linux.EPOLL.CTL_MOD;
|
||||
const stack_node = @fieldParentPtr(std.atomic.Stack(ResumeNode.EventFd).Node, "data", event_fd_node);
|
||||
self.available_eventfd_resume_nodes.push(stack_node);
|
||||
},
|
||||
|
||||
@ -4,6 +4,7 @@ const assert = std.debug.assert;
|
||||
const testing = std.testing;
|
||||
const mem = std.mem;
|
||||
const Loop = std.event.Loop;
|
||||
const Allocator = std.mem.Allocator;
|
||||
|
||||
/// Thread-safe async/await lock.
|
||||
/// Functions which are waiting for the lock are suspended, and
|
||||
|
||||
@ -902,7 +902,7 @@ pub fn formatText(
|
||||
} else if (comptime std.mem.eql(u8, fmt, "Z")) {
|
||||
@compileError("specifier 'Z' has been deprecated, wrap your argument in std.zig.fmtEscapes instead");
|
||||
} else {
|
||||
@compileError("Unsupported format string '" ++ fmt ++ "' for type '" ++ @typeName(@TypeOf(value)) ++ "'");
|
||||
@compileError("Unsupported format string '" ++ fmt ++ "' when formatting text");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
307
lib/std/fs.zig
307
lib/std/fs.zig
@ -304,7 +304,7 @@ pub const Dir = struct {
|
||||
.macos, .ios, .freebsd, .netbsd, .dragonfly, .openbsd => struct {
|
||||
dir: Dir,
|
||||
seek: i64,
|
||||
buf: [8192]u8, // TODO align(@alignOf(os.dirent)),
|
||||
buf: [8192]u8, // TODO align(@alignOf(os.system.dirent)),
|
||||
index: usize,
|
||||
end_index: usize,
|
||||
|
||||
@ -344,7 +344,7 @@ pub const Dir = struct {
|
||||
self.index = 0;
|
||||
self.end_index = @intCast(usize, rc);
|
||||
}
|
||||
const darwin_entry = @ptrCast(*align(1) os.dirent, &self.buf[self.index]);
|
||||
const darwin_entry = @ptrCast(*align(1) os.system.dirent, &self.buf[self.index]);
|
||||
const next_index = self.index + darwin_entry.reclen();
|
||||
self.index = next_index;
|
||||
|
||||
@ -355,14 +355,14 @@ pub const Dir = struct {
|
||||
}
|
||||
|
||||
const entry_kind = switch (darwin_entry.d_type) {
|
||||
os.DT_BLK => Entry.Kind.BlockDevice,
|
||||
os.DT_CHR => Entry.Kind.CharacterDevice,
|
||||
os.DT_DIR => Entry.Kind.Directory,
|
||||
os.DT_FIFO => Entry.Kind.NamedPipe,
|
||||
os.DT_LNK => Entry.Kind.SymLink,
|
||||
os.DT_REG => Entry.Kind.File,
|
||||
os.DT_SOCK => Entry.Kind.UnixDomainSocket,
|
||||
os.DT_WHT => Entry.Kind.Whiteout,
|
||||
os.DT.BLK => Entry.Kind.BlockDevice,
|
||||
os.DT.CHR => Entry.Kind.CharacterDevice,
|
||||
os.DT.DIR => Entry.Kind.Directory,
|
||||
os.DT.FIFO => Entry.Kind.NamedPipe,
|
||||
os.DT.LNK => Entry.Kind.SymLink,
|
||||
os.DT.REG => Entry.Kind.File,
|
||||
os.DT.SOCK => Entry.Kind.UnixDomainSocket,
|
||||
os.DT.WHT => Entry.Kind.Whiteout,
|
||||
else => Entry.Kind.Unknown,
|
||||
};
|
||||
return Entry{
|
||||
@ -391,7 +391,7 @@ pub const Dir = struct {
|
||||
self.index = 0;
|
||||
self.end_index = @intCast(usize, rc);
|
||||
}
|
||||
const bsd_entry = @ptrCast(*align(1) os.dirent, &self.buf[self.index]);
|
||||
const bsd_entry = @ptrCast(*align(1) os.system.dirent, &self.buf[self.index]);
|
||||
const next_index = self.index + bsd_entry.reclen();
|
||||
self.index = next_index;
|
||||
|
||||
@ -409,14 +409,14 @@ pub const Dir = struct {
|
||||
}
|
||||
|
||||
const entry_kind = switch (bsd_entry.d_type) {
|
||||
os.DT_BLK => Entry.Kind.BlockDevice,
|
||||
os.DT_CHR => Entry.Kind.CharacterDevice,
|
||||
os.DT_DIR => Entry.Kind.Directory,
|
||||
os.DT_FIFO => Entry.Kind.NamedPipe,
|
||||
os.DT_LNK => Entry.Kind.SymLink,
|
||||
os.DT_REG => Entry.Kind.File,
|
||||
os.DT_SOCK => Entry.Kind.UnixDomainSocket,
|
||||
os.DT_WHT => Entry.Kind.Whiteout,
|
||||
os.DT.BLK => Entry.Kind.BlockDevice,
|
||||
os.DT.CHR => Entry.Kind.CharacterDevice,
|
||||
os.DT.DIR => Entry.Kind.Directory,
|
||||
os.DT.FIFO => Entry.Kind.NamedPipe,
|
||||
os.DT.LNK => Entry.Kind.SymLink,
|
||||
os.DT.REG => Entry.Kind.File,
|
||||
os.DT.SOCK => Entry.Kind.UnixDomainSocket,
|
||||
os.DT.WHT => Entry.Kind.Whiteout,
|
||||
else => Entry.Kind.Unknown,
|
||||
};
|
||||
return Entry{
|
||||
@ -462,7 +462,7 @@ pub const Dir = struct {
|
||||
self.index = 0;
|
||||
self.end_index = @intCast(usize, rc);
|
||||
}
|
||||
const haiku_entry = @ptrCast(*align(1) os.dirent, &self.buf[self.index]);
|
||||
const haiku_entry = @ptrCast(*align(1) os.system.dirent, &self.buf[self.index]);
|
||||
const next_index = self.index + haiku_entry.reclen();
|
||||
self.index = next_index;
|
||||
const name = mem.spanZ(@ptrCast([*:0]u8, &haiku_entry.d_name));
|
||||
@ -471,7 +471,7 @@ pub const Dir = struct {
|
||||
continue :start_over;
|
||||
}
|
||||
|
||||
var stat_info: os.libc_stat = undefined;
|
||||
var stat_info: os.Stat = undefined;
|
||||
_ = os.system._kern_read_stat(
|
||||
self.dir.fd,
|
||||
&haiku_entry.d_name,
|
||||
@ -479,15 +479,15 @@ pub const Dir = struct {
|
||||
&stat_info,
|
||||
0,
|
||||
);
|
||||
const statmode = stat_info.mode & os.S_IFMT;
|
||||
const statmode = stat_info.mode & os.S.IFMT;
|
||||
|
||||
const entry_kind = switch (statmode) {
|
||||
os.S_IFDIR => Entry.Kind.Directory,
|
||||
os.S_IFBLK => Entry.Kind.BlockDevice,
|
||||
os.S_IFCHR => Entry.Kind.CharacterDevice,
|
||||
os.S_IFLNK => Entry.Kind.SymLink,
|
||||
os.S_IFREG => Entry.Kind.File,
|
||||
os.S_IFIFO => Entry.Kind.NamedPipe,
|
||||
os.S.IFDIR => Entry.Kind.Directory,
|
||||
os.S.IFBLK => Entry.Kind.BlockDevice,
|
||||
os.S.IFCHR => Entry.Kind.CharacterDevice,
|
||||
os.S.IFLNK => Entry.Kind.SymLink,
|
||||
os.S.IFREG => Entry.Kind.File,
|
||||
os.S.IFIFO => Entry.Kind.NamedPipe,
|
||||
else => Entry.Kind.Unknown,
|
||||
};
|
||||
|
||||
@ -500,13 +500,14 @@ pub const Dir = struct {
|
||||
},
|
||||
.linux => struct {
|
||||
dir: Dir,
|
||||
// The if guard is solely there to prevent compile errors from missing `os.linux.dirent64`
|
||||
// The if guard is solely there to prevent compile errors from missing `linux.dirent64`
|
||||
// definition when compiling for other OSes. It doesn't do anything when compiling for Linux.
|
||||
buf: [8192]u8 align(if (builtin.os.tag != .linux) 1 else @alignOf(os.linux.dirent64)),
|
||||
buf: [8192]u8 align(if (builtin.os.tag != .linux) 1 else @alignOf(linux.dirent64)),
|
||||
index: usize,
|
||||
end_index: usize,
|
||||
|
||||
const Self = @This();
|
||||
const linux = os.linux;
|
||||
|
||||
pub const Error = IteratorError;
|
||||
|
||||
@ -515,8 +516,8 @@ pub const Dir = struct {
|
||||
pub fn next(self: *Self) Error!?Entry {
|
||||
start_over: while (true) {
|
||||
if (self.index >= self.end_index) {
|
||||
const rc = os.linux.getdents64(self.dir.fd, &self.buf, self.buf.len);
|
||||
switch (os.linux.getErrno(rc)) {
|
||||
const rc = linux.getdents64(self.dir.fd, &self.buf, self.buf.len);
|
||||
switch (linux.getErrno(rc)) {
|
||||
.SUCCESS => {},
|
||||
.BADF => unreachable, // Dir is invalid or was opened without iteration ability
|
||||
.FAULT => unreachable,
|
||||
@ -528,7 +529,7 @@ pub const Dir = struct {
|
||||
self.index = 0;
|
||||
self.end_index = rc;
|
||||
}
|
||||
const linux_entry = @ptrCast(*align(1) os.dirent64, &self.buf[self.index]);
|
||||
const linux_entry = @ptrCast(*align(1) linux.dirent64, &self.buf[self.index]);
|
||||
const next_index = self.index + linux_entry.reclen();
|
||||
self.index = next_index;
|
||||
|
||||
@ -540,13 +541,13 @@ pub const Dir = struct {
|
||||
}
|
||||
|
||||
const entry_kind = switch (linux_entry.d_type) {
|
||||
os.DT_BLK => Entry.Kind.BlockDevice,
|
||||
os.DT_CHR => Entry.Kind.CharacterDevice,
|
||||
os.DT_DIR => Entry.Kind.Directory,
|
||||
os.DT_FIFO => Entry.Kind.NamedPipe,
|
||||
os.DT_LNK => Entry.Kind.SymLink,
|
||||
os.DT_REG => Entry.Kind.File,
|
||||
os.DT_SOCK => Entry.Kind.UnixDomainSocket,
|
||||
linux.DT.BLK => Entry.Kind.BlockDevice,
|
||||
linux.DT.CHR => Entry.Kind.CharacterDevice,
|
||||
linux.DT.DIR => Entry.Kind.Directory,
|
||||
linux.DT.FIFO => Entry.Kind.NamedPipe,
|
||||
linux.DT.LNK => Entry.Kind.SymLink,
|
||||
linux.DT.REG => Entry.Kind.File,
|
||||
linux.DT.SOCK => Entry.Kind.UnixDomainSocket,
|
||||
else => Entry.Kind.Unknown,
|
||||
};
|
||||
return Entry{
|
||||
@ -677,12 +678,12 @@ pub const Dir = struct {
|
||||
}
|
||||
|
||||
const entry_kind = switch (entry.d_type) {
|
||||
w.FILETYPE_BLOCK_DEVICE => Entry.Kind.BlockDevice,
|
||||
w.FILETYPE_CHARACTER_DEVICE => Entry.Kind.CharacterDevice,
|
||||
w.FILETYPE_DIRECTORY => Entry.Kind.Directory,
|
||||
w.FILETYPE_SYMBOLIC_LINK => Entry.Kind.SymLink,
|
||||
w.FILETYPE_REGULAR_FILE => Entry.Kind.File,
|
||||
w.FILETYPE_SOCKET_STREAM, wasi.FILETYPE_SOCKET_DGRAM => Entry.Kind.UnixDomainSocket,
|
||||
.BLOCK_DEVICE => Entry.Kind.BlockDevice,
|
||||
.CHARACTER_DEVICE => Entry.Kind.CharacterDevice,
|
||||
.DIRECTORY => Entry.Kind.Directory,
|
||||
.SYMBOLIC_LINK => Entry.Kind.SymLink,
|
||||
.REGULAR_FILE => Entry.Kind.File,
|
||||
.SOCKET_STREAM, .SOCKET_DGRAM => Entry.Kind.UnixDomainSocket,
|
||||
else => Entry.Kind.Unknown,
|
||||
};
|
||||
return Entry{
|
||||
@ -879,20 +880,20 @@ pub const Dir = struct {
|
||||
var fdflags: w.fdflags_t = 0x0;
|
||||
var base: w.rights_t = 0x0;
|
||||
if (flags.read) {
|
||||
base |= w.RIGHT_FD_READ | w.RIGHT_FD_TELL | w.RIGHT_FD_SEEK | w.RIGHT_FD_FILESTAT_GET;
|
||||
base |= w.RIGHT.FD_READ | w.RIGHT.FD_TELL | w.RIGHT.FD_SEEK | w.RIGHT.FD_FILESTAT_GET;
|
||||
}
|
||||
if (flags.write) {
|
||||
fdflags |= w.FDFLAG_APPEND;
|
||||
base |= w.RIGHT_FD_WRITE |
|
||||
w.RIGHT_FD_TELL |
|
||||
w.RIGHT_FD_SEEK |
|
||||
w.RIGHT_FD_DATASYNC |
|
||||
w.RIGHT_FD_FDSTAT_SET_FLAGS |
|
||||
w.RIGHT_FD_SYNC |
|
||||
w.RIGHT_FD_ALLOCATE |
|
||||
w.RIGHT_FD_ADVISE |
|
||||
w.RIGHT_FD_FILESTAT_SET_TIMES |
|
||||
w.RIGHT_FD_FILESTAT_SET_SIZE;
|
||||
fdflags |= w.FDFLAG.APPEND;
|
||||
base |= w.RIGHT.FD_WRITE |
|
||||
w.RIGHT.FD_TELL |
|
||||
w.RIGHT.FD_SEEK |
|
||||
w.RIGHT.FD_DATASYNC |
|
||||
w.RIGHT.FD_FDSTAT_SET_FLAGS |
|
||||
w.RIGHT.FD_SYNC |
|
||||
w.RIGHT.FD_ALLOCATE |
|
||||
w.RIGHT.FD_ADVISE |
|
||||
w.RIGHT.FD_FILESTAT_SET_TIMES |
|
||||
w.RIGHT.FD_FILESTAT_SET_SIZE;
|
||||
}
|
||||
const fd = try os.openatWasi(self.fd, sub_path, 0x0, 0x0, fdflags, base, 0x0);
|
||||
return File{ .handle = fd };
|
||||
@ -907,35 +908,35 @@ pub const Dir = struct {
|
||||
return self.openFileW(path_w.span(), flags);
|
||||
}
|
||||
|
||||
var os_flags: u32 = os.O_CLOEXEC;
|
||||
// Use the O_ locking flags if the os supports them to acquire the lock
|
||||
var os_flags: u32 = os.O.CLOEXEC;
|
||||
// Use the O locking flags if the os supports them to acquire the lock
|
||||
// atomically.
|
||||
const has_flock_open_flags = @hasDecl(os, "O_EXLOCK");
|
||||
const has_flock_open_flags = @hasDecl(os.O, "EXLOCK");
|
||||
if (has_flock_open_flags) {
|
||||
// Note that the O_NONBLOCK flag is removed after the openat() call
|
||||
// Note that the O.NONBLOCK flag is removed after the openat() call
|
||||
// is successful.
|
||||
const nonblocking_lock_flag: u32 = if (flags.lock_nonblocking)
|
||||
os.O_NONBLOCK
|
||||
os.O.NONBLOCK
|
||||
else
|
||||
0;
|
||||
os_flags |= switch (flags.lock) {
|
||||
.None => @as(u32, 0),
|
||||
.Shared => os.O_SHLOCK | nonblocking_lock_flag,
|
||||
.Exclusive => os.O_EXLOCK | nonblocking_lock_flag,
|
||||
.Shared => os.O.SHLOCK | nonblocking_lock_flag,
|
||||
.Exclusive => os.O.EXLOCK | nonblocking_lock_flag,
|
||||
};
|
||||
}
|
||||
if (@hasDecl(os, "O_LARGEFILE")) {
|
||||
os_flags |= os.O_LARGEFILE;
|
||||
if (@hasDecl(os.O, "LARGEFILE")) {
|
||||
os_flags |= os.O.LARGEFILE;
|
||||
}
|
||||
if (!flags.allow_ctty) {
|
||||
os_flags |= os.O_NOCTTY;
|
||||
os_flags |= os.O.NOCTTY;
|
||||
}
|
||||
os_flags |= if (flags.write and flags.read)
|
||||
@as(u32, os.O_RDWR)
|
||||
@as(u32, os.O.RDWR)
|
||||
else if (flags.write)
|
||||
@as(u32, os.O_WRONLY)
|
||||
@as(u32, os.O.WRONLY)
|
||||
else
|
||||
@as(u32, os.O_RDONLY);
|
||||
@as(u32, os.O.RDONLY);
|
||||
const fd = if (flags.intended_io_mode != .blocking)
|
||||
try std.event.Loop.instance.?.openatZ(self.fd, sub_path, os_flags, 0)
|
||||
else
|
||||
@ -947,24 +948,24 @@ pub const Dir = struct {
|
||||
if (builtin.target.os.tag != .wasi) {
|
||||
if (!has_flock_open_flags and flags.lock != .None) {
|
||||
// TODO: integrate async I/O
|
||||
const lock_nonblocking = if (flags.lock_nonblocking) os.LOCK_NB else @as(i32, 0);
|
||||
const lock_nonblocking = if (flags.lock_nonblocking) os.LOCK.NB else @as(i32, 0);
|
||||
try os.flock(fd, switch (flags.lock) {
|
||||
.None => unreachable,
|
||||
.Shared => os.LOCK_SH | lock_nonblocking,
|
||||
.Exclusive => os.LOCK_EX | lock_nonblocking,
|
||||
.Shared => os.LOCK.SH | lock_nonblocking,
|
||||
.Exclusive => os.LOCK.EX | lock_nonblocking,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (has_flock_open_flags and flags.lock_nonblocking) {
|
||||
var fl_flags = os.fcntl(fd, os.F_GETFL, 0) catch |err| switch (err) {
|
||||
var fl_flags = os.fcntl(fd, os.F.GETFL, 0) catch |err| switch (err) {
|
||||
error.FileBusy => unreachable,
|
||||
error.Locked => unreachable,
|
||||
error.PermissionDenied => unreachable,
|
||||
else => |e| return e,
|
||||
};
|
||||
fl_flags &= ~@as(usize, os.O_NONBLOCK);
|
||||
_ = os.fcntl(fd, os.F_SETFL, fl_flags) catch |err| switch (err) {
|
||||
fl_flags &= ~@as(usize, os.O.NONBLOCK);
|
||||
_ = os.fcntl(fd, os.F.SETFL, fl_flags) catch |err| switch (err) {
|
||||
error.FileBusy => unreachable,
|
||||
error.Locked => unreachable,
|
||||
error.PermissionDenied => unreachable,
|
||||
@ -1038,26 +1039,26 @@ pub const Dir = struct {
|
||||
/// Same as `createFile` but WASI only.
|
||||
pub fn createFileWasi(self: Dir, sub_path: []const u8, flags: File.CreateFlags) File.OpenError!File {
|
||||
const w = os.wasi;
|
||||
var oflags = w.O_CREAT;
|
||||
var base: w.rights_t = w.RIGHT_FD_WRITE |
|
||||
w.RIGHT_FD_DATASYNC |
|
||||
w.RIGHT_FD_SEEK |
|
||||
w.RIGHT_FD_TELL |
|
||||
w.RIGHT_FD_FDSTAT_SET_FLAGS |
|
||||
w.RIGHT_FD_SYNC |
|
||||
w.RIGHT_FD_ALLOCATE |
|
||||
w.RIGHT_FD_ADVISE |
|
||||
w.RIGHT_FD_FILESTAT_SET_TIMES |
|
||||
w.RIGHT_FD_FILESTAT_SET_SIZE |
|
||||
w.RIGHT_FD_FILESTAT_GET;
|
||||
var oflags = w.O.CREAT;
|
||||
var base: w.rights_t = w.RIGHT.FD_WRITE |
|
||||
w.RIGHT.FD_DATASYNC |
|
||||
w.RIGHT.FD_SEEK |
|
||||
w.RIGHT.FD_TELL |
|
||||
w.RIGHT.FD_FDSTAT_SET_FLAGS |
|
||||
w.RIGHT.FD_SYNC |
|
||||
w.RIGHT.FD_ALLOCATE |
|
||||
w.RIGHT.FD_ADVISE |
|
||||
w.RIGHT.FD_FILESTAT_SET_TIMES |
|
||||
w.RIGHT.FD_FILESTAT_SET_SIZE |
|
||||
w.RIGHT.FD_FILESTAT_GET;
|
||||
if (flags.read) {
|
||||
base |= w.RIGHT_FD_READ;
|
||||
base |= w.RIGHT.FD_READ;
|
||||
}
|
||||
if (flags.truncate) {
|
||||
oflags |= w.O_TRUNC;
|
||||
oflags |= w.O.TRUNC;
|
||||
}
|
||||
if (flags.exclusive) {
|
||||
oflags |= w.O_EXCL;
|
||||
oflags |= w.O.EXCL;
|
||||
}
|
||||
const fd = try os.openatWasi(self.fd, sub_path, 0x0, oflags, 0x0, base, 0x0);
|
||||
return File{ .handle = fd };
|
||||
@ -1070,26 +1071,26 @@ pub const Dir = struct {
|
||||
return self.createFileW(path_w.span(), flags);
|
||||
}
|
||||
|
||||
// Use the O_ locking flags if the os supports them to acquire the lock
|
||||
// Use the O locking flags if the os supports them to acquire the lock
|
||||
// atomically.
|
||||
const has_flock_open_flags = @hasDecl(os, "O_EXLOCK");
|
||||
// Note that the O_NONBLOCK flag is removed after the openat() call
|
||||
const has_flock_open_flags = @hasDecl(os.O, "EXLOCK");
|
||||
// Note that the O.NONBLOCK flag is removed after the openat() call
|
||||
// is successful.
|
||||
const nonblocking_lock_flag: u32 = if (has_flock_open_flags and flags.lock_nonblocking)
|
||||
os.O_NONBLOCK
|
||||
os.O.NONBLOCK
|
||||
else
|
||||
0;
|
||||
const lock_flag: u32 = if (has_flock_open_flags) switch (flags.lock) {
|
||||
.None => @as(u32, 0),
|
||||
.Shared => os.O_SHLOCK | nonblocking_lock_flag,
|
||||
.Exclusive => os.O_EXLOCK | nonblocking_lock_flag,
|
||||
.Shared => os.O.SHLOCK | nonblocking_lock_flag,
|
||||
.Exclusive => os.O.EXLOCK | nonblocking_lock_flag,
|
||||
} else 0;
|
||||
|
||||
const O_LARGEFILE = if (@hasDecl(os, "O_LARGEFILE")) os.O_LARGEFILE else 0;
|
||||
const os_flags = lock_flag | O_LARGEFILE | os.O_CREAT | os.O_CLOEXEC |
|
||||
(if (flags.truncate) @as(u32, os.O_TRUNC) else 0) |
|
||||
(if (flags.read) @as(u32, os.O_RDWR) else os.O_WRONLY) |
|
||||
(if (flags.exclusive) @as(u32, os.O_EXCL) else 0);
|
||||
const O_LARGEFILE = if (@hasDecl(os.O, "LARGEFILE")) os.O.LARGEFILE else 0;
|
||||
const os_flags = lock_flag | O_LARGEFILE | os.O.CREAT | os.O.CLOEXEC |
|
||||
(if (flags.truncate) @as(u32, os.O.TRUNC) else 0) |
|
||||
(if (flags.read) @as(u32, os.O.RDWR) else os.O.WRONLY) |
|
||||
(if (flags.exclusive) @as(u32, os.O.EXCL) else 0);
|
||||
const fd = if (flags.intended_io_mode != .blocking)
|
||||
try std.event.Loop.instance.?.openatZ(self.fd, sub_path_c, os_flags, flags.mode)
|
||||
else
|
||||
@ -1101,24 +1102,24 @@ pub const Dir = struct {
|
||||
if (builtin.target.os.tag != .wasi) {
|
||||
if (!has_flock_open_flags and flags.lock != .None) {
|
||||
// TODO: integrate async I/O
|
||||
const lock_nonblocking = if (flags.lock_nonblocking) os.LOCK_NB else @as(i32, 0);
|
||||
const lock_nonblocking = if (flags.lock_nonblocking) os.LOCK.NB else @as(i32, 0);
|
||||
try os.flock(fd, switch (flags.lock) {
|
||||
.None => unreachable,
|
||||
.Shared => os.LOCK_SH | lock_nonblocking,
|
||||
.Exclusive => os.LOCK_EX | lock_nonblocking,
|
||||
.Shared => os.LOCK.SH | lock_nonblocking,
|
||||
.Exclusive => os.LOCK.EX | lock_nonblocking,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (has_flock_open_flags and flags.lock_nonblocking) {
|
||||
var fl_flags = os.fcntl(fd, os.F_GETFL, 0) catch |err| switch (err) {
|
||||
var fl_flags = os.fcntl(fd, os.F.GETFL, 0) catch |err| switch (err) {
|
||||
error.FileBusy => unreachable,
|
||||
error.Locked => unreachable,
|
||||
error.PermissionDenied => unreachable,
|
||||
else => |e| return e,
|
||||
};
|
||||
fl_flags &= ~@as(usize, os.O_NONBLOCK);
|
||||
_ = os.fcntl(fd, os.F_SETFL, fl_flags) catch |err| switch (err) {
|
||||
fl_flags &= ~@as(usize, os.O.NONBLOCK);
|
||||
_ = os.fcntl(fd, os.F.SETFL, fl_flags) catch |err| switch (err) {
|
||||
error.FileBusy => unreachable,
|
||||
error.Locked => unreachable,
|
||||
error.PermissionDenied => unreachable,
|
||||
@ -1262,7 +1263,7 @@ pub const Dir = struct {
|
||||
return self.realpathW(pathname_w.span(), out_buffer);
|
||||
}
|
||||
|
||||
const flags = if (builtin.os.tag == .linux) os.O_PATH | os.O_NONBLOCK | os.O_CLOEXEC else os.O_NONBLOCK | os.O_CLOEXEC;
|
||||
const flags = if (builtin.os.tag == .linux) os.O.PATH | os.O.NONBLOCK | os.O.CLOEXEC else os.O.NONBLOCK | os.O.CLOEXEC;
|
||||
const fd = os.openatZ(self.fd, pathname, flags, 0) catch |err| switch (err) {
|
||||
error.FileLocksNotSupported => unreachable,
|
||||
else => |e| return e,
|
||||
@ -1401,34 +1402,34 @@ pub const Dir = struct {
|
||||
/// Same as `openDir` except only WASI.
|
||||
pub fn openDirWasi(self: Dir, sub_path: []const u8, args: OpenDirOptions) OpenError!Dir {
|
||||
const w = os.wasi;
|
||||
var base: w.rights_t = w.RIGHT_FD_FILESTAT_GET | w.RIGHT_FD_FDSTAT_SET_FLAGS | w.RIGHT_FD_FILESTAT_SET_TIMES;
|
||||
var base: w.rights_t = w.RIGHT.FD_FILESTAT_GET | w.RIGHT.FD_FDSTAT_SET_FLAGS | w.RIGHT.FD_FILESTAT_SET_TIMES;
|
||||
if (args.access_sub_paths) {
|
||||
base |= w.RIGHT_FD_READDIR |
|
||||
w.RIGHT_PATH_CREATE_DIRECTORY |
|
||||
w.RIGHT_PATH_CREATE_FILE |
|
||||
w.RIGHT_PATH_LINK_SOURCE |
|
||||
w.RIGHT_PATH_LINK_TARGET |
|
||||
w.RIGHT_PATH_OPEN |
|
||||
w.RIGHT_PATH_READLINK |
|
||||
w.RIGHT_PATH_RENAME_SOURCE |
|
||||
w.RIGHT_PATH_RENAME_TARGET |
|
||||
w.RIGHT_PATH_FILESTAT_GET |
|
||||
w.RIGHT_PATH_FILESTAT_SET_SIZE |
|
||||
w.RIGHT_PATH_FILESTAT_SET_TIMES |
|
||||
w.RIGHT_PATH_SYMLINK |
|
||||
w.RIGHT_PATH_REMOVE_DIRECTORY |
|
||||
w.RIGHT_PATH_UNLINK_FILE;
|
||||
base |= w.RIGHT.FD_READDIR |
|
||||
w.RIGHT.PATH_CREATE_DIRECTORY |
|
||||
w.RIGHT.PATH_CREATE_FILE |
|
||||
w.RIGHT.PATH_LINK_SOURCE |
|
||||
w.RIGHT.PATH_LINK_TARGET |
|
||||
w.RIGHT.PATH_OPEN |
|
||||
w.RIGHT.PATH_READLINK |
|
||||
w.RIGHT.PATH_RENAME_SOURCE |
|
||||
w.RIGHT.PATH_RENAME_TARGET |
|
||||
w.RIGHT.PATH_FILESTAT_GET |
|
||||
w.RIGHT.PATH_FILESTAT_SET_SIZE |
|
||||
w.RIGHT.PATH_FILESTAT_SET_TIMES |
|
||||
w.RIGHT.PATH_SYMLINK |
|
||||
w.RIGHT.PATH_REMOVE_DIRECTORY |
|
||||
w.RIGHT.PATH_UNLINK_FILE;
|
||||
}
|
||||
const symlink_flags: w.lookupflags_t = if (args.no_follow) 0x0 else w.LOOKUP_SYMLINK_FOLLOW;
|
||||
// TODO do we really need all the rights here?
|
||||
const inheriting: w.rights_t = w.RIGHT_ALL ^ w.RIGHT_SOCK_SHUTDOWN;
|
||||
const inheriting: w.rights_t = w.RIGHT.ALL ^ w.RIGHT.SOCK_SHUTDOWN;
|
||||
|
||||
const result = os.openatWasi(self.fd, sub_path, symlink_flags, w.O_DIRECTORY, 0x0, base, inheriting);
|
||||
const result = os.openatWasi(self.fd, sub_path, symlink_flags, w.O.DIRECTORY, 0x0, base, inheriting);
|
||||
const fd = result catch |err| switch (err) {
|
||||
error.FileTooBig => unreachable, // can't happen for directories
|
||||
error.IsDir => unreachable, // we're providing O_DIRECTORY
|
||||
error.NoSpaceLeft => unreachable, // not providing O_CREAT
|
||||
error.PathAlreadyExists => unreachable, // not providing O_CREAT
|
||||
error.IsDir => unreachable, // we're providing O.DIRECTORY
|
||||
error.NoSpaceLeft => unreachable, // not providing O.CREAT
|
||||
error.PathAlreadyExists => unreachable, // not providing O.CREAT
|
||||
error.FileLocksNotSupported => unreachable, // locking folders is not supported
|
||||
error.WouldBlock => unreachable, // can't happen for directories
|
||||
else => |e| return e,
|
||||
@ -1442,12 +1443,12 @@ pub const Dir = struct {
|
||||
const sub_path_w = try os.windows.cStrToPrefixedFileW(sub_path_c);
|
||||
return self.openDirW(sub_path_w.span().ptr, args);
|
||||
}
|
||||
const symlink_flags: u32 = if (args.no_follow) os.O_NOFOLLOW else 0x0;
|
||||
const symlink_flags: u32 = if (args.no_follow) os.O.NOFOLLOW else 0x0;
|
||||
if (!args.iterate) {
|
||||
const O_PATH = if (@hasDecl(os, "O_PATH")) os.O_PATH else 0;
|
||||
return self.openDirFlagsZ(sub_path_c, os.O_DIRECTORY | os.O_RDONLY | os.O_CLOEXEC | O_PATH | symlink_flags);
|
||||
const O_PATH = if (@hasDecl(os.O, "PATH")) os.O.PATH else 0;
|
||||
return self.openDirFlagsZ(sub_path_c, os.O.DIRECTORY | os.O.RDONLY | os.O.CLOEXEC | O_PATH | symlink_flags);
|
||||
} else {
|
||||
return self.openDirFlagsZ(sub_path_c, os.O_DIRECTORY | os.O_RDONLY | os.O_CLOEXEC | symlink_flags);
|
||||
return self.openDirFlagsZ(sub_path_c, os.O.DIRECTORY | os.O.RDONLY | os.O.CLOEXEC | symlink_flags);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1462,7 +1463,7 @@ pub const Dir = struct {
|
||||
return self.openDirAccessMaskW(sub_path_w, flags, args.no_follow);
|
||||
}
|
||||
|
||||
/// `flags` must contain `os.O_DIRECTORY`.
|
||||
/// `flags` must contain `os.O.DIRECTORY`.
|
||||
fn openDirFlagsZ(self: Dir, sub_path_c: [*:0]const u8, flags: u32) OpenError!Dir {
|
||||
const result = if (need_async_thread)
|
||||
std.event.Loop.instance.?.openatZ(self.fd, sub_path_c, flags, 0)
|
||||
@ -1470,9 +1471,9 @@ pub const Dir = struct {
|
||||
os.openatZ(self.fd, sub_path_c, flags, 0);
|
||||
const fd = result catch |err| switch (err) {
|
||||
error.FileTooBig => unreachable, // can't happen for directories
|
||||
error.IsDir => unreachable, // we're providing O_DIRECTORY
|
||||
error.NoSpaceLeft => unreachable, // not providing O_CREAT
|
||||
error.PathAlreadyExists => unreachable, // not providing O_CREAT
|
||||
error.IsDir => unreachable, // we're providing O.DIRECTORY
|
||||
error.NoSpaceLeft => unreachable, // not providing O.CREAT
|
||||
error.PathAlreadyExists => unreachable, // not providing O.CREAT
|
||||
error.FileLocksNotSupported => unreachable, // locking folders is not supported
|
||||
error.WouldBlock => unreachable, // can't happen for directories
|
||||
else => |e| return e,
|
||||
@ -1537,7 +1538,7 @@ pub const Dir = struct {
|
||||
return self.deleteFileW(sub_path_w.span());
|
||||
} else if (builtin.os.tag == .wasi and !builtin.link_libc) {
|
||||
os.unlinkatWasi(self.fd, sub_path, 0) catch |err| switch (err) {
|
||||
error.DirNotEmpty => unreachable, // not passing AT_REMOVEDIR
|
||||
error.DirNotEmpty => unreachable, // not passing AT.REMOVEDIR
|
||||
else => |e| return e,
|
||||
};
|
||||
} else {
|
||||
@ -1551,14 +1552,14 @@ pub const Dir = struct {
|
||||
/// Same as `deleteFile` except the parameter is null-terminated.
|
||||
pub fn deleteFileZ(self: Dir, sub_path_c: [*:0]const u8) DeleteFileError!void {
|
||||
os.unlinkatZ(self.fd, sub_path_c, 0) catch |err| switch (err) {
|
||||
error.DirNotEmpty => unreachable, // not passing AT_REMOVEDIR
|
||||
error.DirNotEmpty => unreachable, // not passing AT.REMOVEDIR
|
||||
error.AccessDenied => |e| switch (builtin.os.tag) {
|
||||
// non-Linux POSIX systems return EPERM when trying to delete a directory, so
|
||||
// we need to handle that case specifically and translate the error
|
||||
.macos, .ios, .freebsd, .netbsd, .dragonfly, .openbsd => {
|
||||
// Don't follow symlinks to match unlinkat (which acts on symlinks rather than follows them)
|
||||
const fstat = os.fstatatZ(self.fd, sub_path_c, os.AT_SYMLINK_NOFOLLOW) catch return e;
|
||||
const is_dir = fstat.mode & os.S_IFMT == os.S_IFDIR;
|
||||
const fstat = os.fstatatZ(self.fd, sub_path_c, os.AT.SYMLINK_NOFOLLOW) catch return e;
|
||||
const is_dir = fstat.mode & os.S.IFMT == os.S.IFDIR;
|
||||
return if (is_dir) error.IsDir else e;
|
||||
},
|
||||
else => return e,
|
||||
@ -1570,7 +1571,7 @@ pub const Dir = struct {
|
||||
/// Same as `deleteFile` except the parameter is WTF-16 encoded.
|
||||
pub fn deleteFileW(self: Dir, sub_path_w: []const u16) DeleteFileError!void {
|
||||
os.unlinkatW(self.fd, sub_path_w, 0) catch |err| switch (err) {
|
||||
error.DirNotEmpty => unreachable, // not passing AT_REMOVEDIR
|
||||
error.DirNotEmpty => unreachable, // not passing AT.REMOVEDIR
|
||||
else => |e| return e,
|
||||
};
|
||||
}
|
||||
@ -1599,8 +1600,8 @@ pub const Dir = struct {
|
||||
const sub_path_w = try os.windows.sliceToPrefixedFileW(sub_path);
|
||||
return self.deleteDirW(sub_path_w.span());
|
||||
} else if (builtin.os.tag == .wasi and !builtin.link_libc) {
|
||||
os.unlinkat(self.fd, sub_path, os.AT_REMOVEDIR) catch |err| switch (err) {
|
||||
error.IsDir => unreachable, // not possible since we pass AT_REMOVEDIR
|
||||
os.unlinkat(self.fd, sub_path, os.AT.REMOVEDIR) catch |err| switch (err) {
|
||||
error.IsDir => unreachable, // not possible since we pass AT.REMOVEDIR
|
||||
else => |e| return e,
|
||||
};
|
||||
} else {
|
||||
@ -1611,8 +1612,8 @@ pub const Dir = struct {
|
||||
|
||||
/// Same as `deleteDir` except the parameter is null-terminated.
|
||||
pub fn deleteDirZ(self: Dir, sub_path_c: [*:0]const u8) DeleteDirError!void {
|
||||
os.unlinkatZ(self.fd, sub_path_c, os.AT_REMOVEDIR) catch |err| switch (err) {
|
||||
error.IsDir => unreachable, // not possible since we pass AT_REMOVEDIR
|
||||
os.unlinkatZ(self.fd, sub_path_c, os.AT.REMOVEDIR) catch |err| switch (err) {
|
||||
error.IsDir => unreachable, // not possible since we pass AT.REMOVEDIR
|
||||
else => |e| return e,
|
||||
};
|
||||
}
|
||||
@ -1620,8 +1621,8 @@ pub const Dir = struct {
|
||||
/// Same as `deleteDir` except the parameter is UTF16LE, NT prefixed.
|
||||
/// This function is Windows-only.
|
||||
pub fn deleteDirW(self: Dir, sub_path_w: []const u16) DeleteDirError!void {
|
||||
os.unlinkatW(self.fd, sub_path_w, os.AT_REMOVEDIR) catch |err| switch (err) {
|
||||
error.IsDir => unreachable, // not possible since we pass AT_REMOVEDIR
|
||||
os.unlinkatW(self.fd, sub_path_w, os.AT.REMOVEDIR) catch |err| switch (err) {
|
||||
error.IsDir => unreachable, // not possible since we pass AT.REMOVEDIR
|
||||
else => |e| return e,
|
||||
};
|
||||
}
|
||||
@ -2132,7 +2133,7 @@ pub fn cwd() Dir {
|
||||
} else if (builtin.os.tag == .wasi and !builtin.link_libc) {
|
||||
@compileError("WASI doesn't have a concept of cwd(); use std.fs.wasi.PreopenList to get available Dir handles instead");
|
||||
} else {
|
||||
return Dir{ .fd = os.AT_FDCWD };
|
||||
return Dir{ .fd = os.AT.FDCWD };
|
||||
}
|
||||
}
|
||||
|
||||
@ -2441,14 +2442,14 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {
|
||||
switch (builtin.os.tag) {
|
||||
.linux => return os.readlinkZ("/proc/self/exe", out_buffer),
|
||||
.freebsd, .dragonfly => {
|
||||
var mib = [4]c_int{ os.CTL_KERN, os.KERN_PROC, os.KERN_PROC_PATHNAME, -1 };
|
||||
var mib = [4]c_int{ os.CTL.KERN, os.KERN.PROC, os.KERN.PROC_PATHNAME, -1 };
|
||||
var out_len: usize = out_buffer.len;
|
||||
try os.sysctl(&mib, out_buffer.ptr, &out_len, null, 0);
|
||||
// TODO could this slice from 0 to out_len instead?
|
||||
return mem.spanZ(std.meta.assumeSentinel(out_buffer.ptr, 0));
|
||||
},
|
||||
.netbsd => {
|
||||
var mib = [4]c_int{ os.CTL_KERN, os.KERN_PROC_ARGS, -1, os.KERN_PROC_PATHNAME };
|
||||
var mib = [4]c_int{ os.CTL.KERN, os.KERN.PROC_ARGS, -1, os.KERN.PROC_PATHNAME };
|
||||
var out_len: usize = out_buffer.len;
|
||||
try os.sysctl(&mib, out_buffer.ptr, &out_len, null, 0);
|
||||
// TODO could this slice from 0 to out_len instead?
|
||||
|
||||
@ -12,20 +12,23 @@ const is_windows = std.Target.current.os.tag == .windows;
|
||||
|
||||
pub const File = struct {
|
||||
/// The OS-specific file descriptor or file handle.
|
||||
handle: os.fd_t,
|
||||
handle: Handle,
|
||||
|
||||
/// On some systems, such as Linux, file system file descriptors are incapable of non-blocking I/O.
|
||||
/// This forces us to perform asynchronous I/O on a dedicated thread, to achieve non-blocking
|
||||
/// file-system I/O. To do this, `File` must be aware of whether it is a file system file descriptor,
|
||||
/// or, more specifically, whether the I/O is always blocking.
|
||||
/// On some systems, such as Linux, file system file descriptors are incapable
|
||||
/// of non-blocking I/O. This forces us to perform asynchronous I/O on a dedicated thread,
|
||||
/// to achieve non-blocking file-system I/O. To do this, `File` must be aware of whether
|
||||
/// it is a file system file descriptor, or, more specifically, whether the I/O is always
|
||||
/// blocking.
|
||||
capable_io_mode: io.ModeOverride = io.default_mode,
|
||||
|
||||
/// Furthermore, even when `std.io.mode` is async, it is still sometimes desirable to perform blocking I/O,
|
||||
/// although not by default. For example, when printing a stack trace to stderr.
|
||||
/// This field tracks both by acting as an overriding I/O mode. When not building in async I/O mode,
|
||||
/// the type only has the `.blocking` tag, making it a zero-bit type.
|
||||
/// Furthermore, even when `std.io.mode` is async, it is still sometimes desirable
|
||||
/// to perform blocking I/O, although not by default. For example, when printing a
|
||||
/// stack trace to stderr. This field tracks both by acting as an overriding I/O mode.
|
||||
/// When not building in async I/O mode, the type only has the `.blocking` tag, making
|
||||
/// it a zero-bit type.
|
||||
intended_io_mode: io.ModeOverride = io.default_mode,
|
||||
|
||||
pub const Handle = os.fd_t;
|
||||
pub const Mode = os.mode_t;
|
||||
pub const INode = os.ino_t;
|
||||
|
||||
@ -103,7 +106,7 @@ pub const File = struct {
|
||||
/// and `false` means `error.WouldBlock` is handled by the event loop.
|
||||
lock_nonblocking: bool = false,
|
||||
|
||||
/// Setting this to `.blocking` prevents `O_NONBLOCK` from being passed even
|
||||
/// Setting this to `.blocking` prevents `O.NONBLOCK` from being passed even
|
||||
/// if `std.io.is_async`. It allows the use of `nosuspend` when calling functions
|
||||
/// related to opening the file, reading, writing, and locking.
|
||||
intended_io_mode: io.ModeOverride = io.default_mode,
|
||||
@ -164,7 +167,7 @@ pub const File = struct {
|
||||
/// be created with.
|
||||
mode: Mode = default_mode,
|
||||
|
||||
/// Setting this to `.blocking` prevents `O_NONBLOCK` from being passed even
|
||||
/// Setting this to `.blocking` prevents `O.NONBLOCK` from being passed even
|
||||
/// if `std.io.is_async`. It allows the use of `nosuspend` when calling functions
|
||||
/// related to opening the file, reading, writing, and locking.
|
||||
intended_io_mode: io.ModeOverride = io.default_mode,
|
||||
@ -322,21 +325,21 @@ pub const File = struct {
|
||||
.size = @bitCast(u64, st.size),
|
||||
.mode = st.mode,
|
||||
.kind = if (builtin.os.tag == .wasi and !builtin.link_libc) switch (st.filetype) {
|
||||
os.FILETYPE_BLOCK_DEVICE => Kind.BlockDevice,
|
||||
os.FILETYPE_CHARACTER_DEVICE => Kind.CharacterDevice,
|
||||
os.FILETYPE_DIRECTORY => Kind.Directory,
|
||||
os.FILETYPE_SYMBOLIC_LINK => Kind.SymLink,
|
||||
os.FILETYPE_REGULAR_FILE => Kind.File,
|
||||
os.FILETYPE_SOCKET_STREAM, os.FILETYPE_SOCKET_DGRAM => Kind.UnixDomainSocket,
|
||||
.BLOCK_DEVICE => Kind.BlockDevice,
|
||||
.CHARACTER_DEVICE => Kind.CharacterDevice,
|
||||
.DIRECTORY => Kind.Directory,
|
||||
.SYMBOLIC_LINK => Kind.SymLink,
|
||||
.REGULAR_FILE => Kind.File,
|
||||
.SOCKET_STREAM, .SOCKET_DGRAM => Kind.UnixDomainSocket,
|
||||
else => Kind.Unknown,
|
||||
} else switch (st.mode & os.S_IFMT) {
|
||||
os.S_IFBLK => Kind.BlockDevice,
|
||||
os.S_IFCHR => Kind.CharacterDevice,
|
||||
os.S_IFDIR => Kind.Directory,
|
||||
os.S_IFIFO => Kind.NamedPipe,
|
||||
os.S_IFLNK => Kind.SymLink,
|
||||
os.S_IFREG => Kind.File,
|
||||
os.S_IFSOCK => Kind.UnixDomainSocket,
|
||||
} else switch (st.mode & os.S.IFMT) {
|
||||
os.S.IFBLK => Kind.BlockDevice,
|
||||
os.S.IFCHR => Kind.CharacterDevice,
|
||||
os.S.IFDIR => Kind.Directory,
|
||||
os.S.IFIFO => Kind.NamedPipe,
|
||||
os.S.IFLNK => Kind.SymLink,
|
||||
os.S.IFREG => Kind.File,
|
||||
os.S.IFSOCK => Kind.UnixDomainSocket,
|
||||
else => Kind.Unknown,
|
||||
},
|
||||
.atime = @as(i128, atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec,
|
||||
@ -883,9 +886,9 @@ pub const File = struct {
|
||||
};
|
||||
} else {
|
||||
return os.flock(file.handle, switch (l) {
|
||||
.None => os.LOCK_UN,
|
||||
.Shared => os.LOCK_SH,
|
||||
.Exclusive => os.LOCK_EX,
|
||||
.None => os.LOCK.UN,
|
||||
.Shared => os.LOCK.SH,
|
||||
.Exclusive => os.LOCK.EX,
|
||||
}) catch |err| switch (err) {
|
||||
error.WouldBlock => unreachable, // non-blocking=false
|
||||
else => |e| return e,
|
||||
@ -908,7 +911,7 @@ pub const File = struct {
|
||||
error.Unexpected => unreachable, // Resource deallocation must succeed.
|
||||
};
|
||||
} else {
|
||||
return os.flock(file.handle, os.LOCK_UN) catch |err| switch (err) {
|
||||
return os.flock(file.handle, os.LOCK.UN) catch |err| switch (err) {
|
||||
error.WouldBlock => unreachable, // unlocking can't block
|
||||
error.SystemResources => unreachable, // We are deallocating resources.
|
||||
error.Unexpected => unreachable, // Resource deallocation must succeed.
|
||||
@ -949,9 +952,9 @@ pub const File = struct {
|
||||
};
|
||||
} else {
|
||||
os.flock(file.handle, switch (l) {
|
||||
.None => os.LOCK_UN,
|
||||
.Shared => os.LOCK_SH | os.LOCK_NB,
|
||||
.Exclusive => os.LOCK_EX | os.LOCK_NB,
|
||||
.None => os.LOCK.UN,
|
||||
.Shared => os.LOCK.SH | os.LOCK.NB,
|
||||
.Exclusive => os.LOCK.EX | os.LOCK.NB,
|
||||
}) catch |err| switch (err) {
|
||||
error.WouldBlock => return false,
|
||||
else => |e| return e,
|
||||
@ -998,7 +1001,7 @@ pub const File = struct {
|
||||
error.Unexpected => unreachable, // Resource deallocation must succeed.
|
||||
};
|
||||
} else {
|
||||
return os.flock(file.handle, os.LOCK_SH | os.LOCK_NB) catch |err| switch (err) {
|
||||
return os.flock(file.handle, os.LOCK.SH | os.LOCK.NB) catch |err| switch (err) {
|
||||
error.WouldBlock => unreachable, // File was not locked in exclusive mode.
|
||||
else => |e| return e,
|
||||
};
|
||||
|
||||
@ -3,8 +3,9 @@ const os = std.os;
|
||||
const mem = std.mem;
|
||||
const math = std.math;
|
||||
const Allocator = mem.Allocator;
|
||||
|
||||
usingnamespace std.os.wasi;
|
||||
const wasi = std.os.wasi;
|
||||
const fd_t = wasi.fd_t;
|
||||
const prestat_t = wasi.prestat_t;
|
||||
|
||||
/// Type-tag of WASI preopen.
|
||||
///
|
||||
@ -115,7 +116,7 @@ pub const PreopenList = struct {
|
||||
|
||||
while (true) {
|
||||
var buf: prestat_t = undefined;
|
||||
switch (fd_prestat_get(fd, &buf)) {
|
||||
switch (wasi.fd_prestat_get(fd, &buf)) {
|
||||
.SUCCESS => {},
|
||||
.OPNOTSUPP => {
|
||||
// not a preopen, so keep going
|
||||
@ -131,7 +132,7 @@ pub const PreopenList = struct {
|
||||
const preopen_len = buf.u.dir.pr_name_len;
|
||||
const path_buf = try self.buffer.allocator.alloc(u8, preopen_len);
|
||||
mem.set(u8, path_buf, 0);
|
||||
switch (fd_prestat_dir_name(fd, path_buf.ptr, preopen_len)) {
|
||||
switch (wasi.fd_prestat_dir_name(fd, path_buf.ptr, preopen_len)) {
|
||||
.SUCCESS => {},
|
||||
else => |err| return os.unexpectedErrno(err),
|
||||
}
|
||||
@ -174,5 +175,5 @@ test "extracting WASI preopens" {
|
||||
try std.testing.expectEqual(@as(usize, 1), preopens.asSlice().len);
|
||||
const preopen = preopens.find(PreopenType{ .Dir = "." }) orelse unreachable;
|
||||
try std.testing.expect(preopen.@"type".eql(PreopenType{ .Dir = "." }));
|
||||
try std.testing.expectEqual(@as(usize, 3), preopen.fd);
|
||||
try std.testing.expectEqual(@as(i32, 3), preopen.fd);
|
||||
}
|
||||
|
||||
@ -250,7 +250,7 @@ pub fn Watch(comptime V: type) type {
|
||||
};
|
||||
|
||||
// @TODO Can I close this fd and get an error from bsdWaitKev?
|
||||
const flags = if (comptime std.Target.current.isDarwin()) os.O_SYMLINK | os.O_EVTONLY else 0;
|
||||
const flags = if (comptime std.Target.current.isDarwin()) os.O.SYMLINK | os.O.EVTONLY else 0;
|
||||
const fd = try os.open(realpath, flags, 0);
|
||||
gop.value_ptr.putter_frame = async self.kqPutEvents(fd, gop.key_ptr.*, gop.value_ptr.*);
|
||||
return null;
|
||||
|
||||
@ -92,6 +92,34 @@ pub fn hashString(s: []const u8) u64 {
|
||||
return std.hash.Wyhash.hash(0, s);
|
||||
}
|
||||
|
||||
pub const StringIndexContext = struct {
|
||||
bytes: *std.ArrayListUnmanaged(u8),
|
||||
|
||||
pub fn eql(self: @This(), a: u32, b: u32) bool {
|
||||
_ = self;
|
||||
return a == b;
|
||||
}
|
||||
|
||||
pub fn hash(self: @This(), x: u32) u64 {
|
||||
const x_slice = mem.spanZ(@ptrCast([*:0]const u8, self.bytes.items.ptr) + x);
|
||||
return hashString(x_slice);
|
||||
}
|
||||
};
|
||||
|
||||
pub const StringIndexAdapter = struct {
|
||||
bytes: *std.ArrayListUnmanaged(u8),
|
||||
|
||||
pub fn eql(self: @This(), a_slice: []const u8, b: u32) bool {
|
||||
const b_slice = mem.spanZ(@ptrCast([*:0]const u8, self.bytes.items.ptr) + b);
|
||||
return mem.eql(u8, a_slice, b_slice);
|
||||
}
|
||||
|
||||
pub fn hash(self: @This(), adapted_key: []const u8) u64 {
|
||||
_ = self;
|
||||
return hashString(adapted_key);
|
||||
}
|
||||
};
|
||||
|
||||
/// Deprecated use `default_max_load_percentage`
|
||||
pub const DefaultMaxLoadPercentage = default_max_load_percentage;
|
||||
|
||||
@ -622,8 +650,12 @@ pub fn HashMap(
|
||||
return other.promoteContext(self.allocator, new_ctx);
|
||||
}
|
||||
|
||||
/// Creates a copy of this map, using a specified allocator and context
|
||||
pub fn cloneWithAllocatorAndContext(new_allocator: *Allocator, new_ctx: anytype) !HashMap(K, V, @TypeOf(new_ctx), max_load_percentage) {
|
||||
/// Creates a copy of this map, using a specified allocator and context.
|
||||
pub fn cloneWithAllocatorAndContext(
|
||||
self: Self,
|
||||
new_allocator: *Allocator,
|
||||
new_ctx: anytype,
|
||||
) !HashMap(K, V, @TypeOf(new_ctx), max_load_percentage) {
|
||||
var other = try self.unmanaged.cloneContext(new_allocator, new_ctx);
|
||||
return other.promoteContext(new_allocator, new_ctx);
|
||||
}
|
||||
|
||||
@ -88,12 +88,12 @@ const CAllocator = struct {
|
||||
|
||||
fn alignedAllocSize(ptr: [*]u8) usize {
|
||||
if (supports_posix_memalign) {
|
||||
return malloc_size(ptr);
|
||||
return CAllocator.malloc_size(ptr);
|
||||
}
|
||||
|
||||
const unaligned_ptr = getHeader(ptr).*;
|
||||
const delta = @ptrToInt(ptr) - @ptrToInt(unaligned_ptr);
|
||||
return malloc_size(unaligned_ptr) - delta;
|
||||
return CAllocator.malloc_size(unaligned_ptr) - delta;
|
||||
}
|
||||
|
||||
fn alloc(
|
||||
@ -113,7 +113,7 @@ const CAllocator = struct {
|
||||
return ptr[0..len];
|
||||
}
|
||||
const full_len = init: {
|
||||
if (supports_malloc_size) {
|
||||
if (CAllocator.supports_malloc_size) {
|
||||
const s = alignedAllocSize(ptr);
|
||||
assert(s >= len);
|
||||
break :init s;
|
||||
@ -141,7 +141,7 @@ const CAllocator = struct {
|
||||
if (new_len <= buf.len) {
|
||||
return mem.alignAllocLen(buf.len, new_len, len_align);
|
||||
}
|
||||
if (supports_malloc_size) {
|
||||
if (CAllocator.supports_malloc_size) {
|
||||
const full_len = alignedAllocSize(buf.ptr);
|
||||
if (new_len <= full_len) {
|
||||
return mem.alignAllocLen(full_len, new_len, len_align);
|
||||
@ -304,8 +304,8 @@ const PageAllocator = struct {
|
||||
const slice = os.mmap(
|
||||
hint,
|
||||
alloc_len,
|
||||
os.PROT_READ | os.PROT_WRITE,
|
||||
os.MAP_PRIVATE | os.MAP_ANONYMOUS,
|
||||
os.PROT.READ | os.PROT.WRITE,
|
||||
os.MAP.PRIVATE | os.MAP.ANONYMOUS,
|
||||
-1,
|
||||
0,
|
||||
) catch return error.OutOfMemory;
|
||||
|
||||
@ -2,6 +2,7 @@ const std = @import("../std.zig");
|
||||
const builtin = std.builtin;
|
||||
const io = std.io;
|
||||
const testing = std.testing;
|
||||
const os = std.os;
|
||||
|
||||
pub const CWriter = io.Writer(*std.c.FILE, std.fs.File.WriteError, cWriterWrite);
|
||||
|
||||
|
||||
@ -1405,7 +1405,7 @@ fn parsedEqual(a: anytype, b: @TypeOf(a)) bool {
|
||||
if (a == null or b == null) return false;
|
||||
return parsedEqual(a.?, b.?);
|
||||
},
|
||||
.Union => {
|
||||
.Union => |info| {
|
||||
if (info.tag_type) |UnionTag| {
|
||||
const tag_a = std.meta.activeTag(a);
|
||||
const tag_b = std.meta.activeTag(b);
|
||||
@ -2657,7 +2657,7 @@ test "json.parser.dynamic" {
|
||||
try testing.expect(mem.eql(u8, large_int.NumberString, "18446744073709551615"));
|
||||
}
|
||||
|
||||
test "import more json tests" {
|
||||
test {
|
||||
_ = @import("json/test.zig");
|
||||
_ = @import("json/write_stream.zig");
|
||||
}
|
||||
|
||||
@ -601,35 +601,35 @@ pub const segment_command = extern struct {
|
||||
/// command and their size is reflected in cmdsize.
|
||||
pub const segment_command_64 = extern struct {
|
||||
/// LC_SEGMENT_64
|
||||
cmd: u32,
|
||||
cmd: u32 = LC_SEGMENT_64,
|
||||
|
||||
/// includes sizeof section_64 structs
|
||||
cmdsize: u32,
|
||||
cmdsize: u32 = @sizeOf(segment_command_64),
|
||||
|
||||
/// segment name
|
||||
segname: [16]u8,
|
||||
|
||||
/// memory address of this segment
|
||||
vmaddr: u64,
|
||||
vmaddr: u64 = 0,
|
||||
|
||||
/// memory size of this segment
|
||||
vmsize: u64,
|
||||
vmsize: u64 = 0,
|
||||
|
||||
/// file offset of this segment
|
||||
fileoff: u64,
|
||||
fileoff: u64 = 0,
|
||||
|
||||
/// amount to map from the file
|
||||
filesize: u64,
|
||||
filesize: u64 = 0,
|
||||
|
||||
/// maximum VM protection
|
||||
maxprot: vm_prot_t,
|
||||
maxprot: vm_prot_t = VM_PROT_NONE,
|
||||
|
||||
/// initial VM protection
|
||||
initprot: vm_prot_t,
|
||||
initprot: vm_prot_t = VM_PROT_NONE,
|
||||
|
||||
/// number of sections in segment
|
||||
nsects: u32,
|
||||
flags: u32,
|
||||
nsects: u32 = 0,
|
||||
flags: u32 = 0,
|
||||
};
|
||||
|
||||
/// A segment is made up of zero or more sections. Non-MH_OBJECT files have
|
||||
@ -700,34 +700,34 @@ pub const section_64 = extern struct {
|
||||
segname: [16]u8,
|
||||
|
||||
/// memory address of this section
|
||||
addr: u64,
|
||||
addr: u64 = 0,
|
||||
|
||||
/// size in bytes of this section
|
||||
size: u64,
|
||||
size: u64 = 0,
|
||||
|
||||
/// file offset of this section
|
||||
offset: u32,
|
||||
offset: u32 = 0,
|
||||
|
||||
/// section alignment (power of 2)
|
||||
@"align": u32,
|
||||
@"align": u32 = 0,
|
||||
|
||||
/// file offset of relocation entries
|
||||
reloff: u32,
|
||||
reloff: u32 = 0,
|
||||
|
||||
/// number of relocation entries
|
||||
nreloc: u32,
|
||||
nreloc: u32 = 0,
|
||||
|
||||
/// flags (section type and attributes
|
||||
flags: u32,
|
||||
flags: u32 = S_REGULAR,
|
||||
|
||||
/// reserved (for offset or index)
|
||||
reserved1: u32,
|
||||
reserved1: u32 = 0,
|
||||
|
||||
/// reserved (for count or sizeof)
|
||||
reserved2: u32,
|
||||
reserved2: u32 = 0,
|
||||
|
||||
/// reserved
|
||||
reserved3: u32,
|
||||
reserved3: u32 = 0,
|
||||
};
|
||||
|
||||
pub const nlist = extern struct {
|
||||
|
||||
@ -1415,3 +1415,8 @@ test "boolMask" {
|
||||
try runTest();
|
||||
comptime try runTest();
|
||||
}
|
||||
|
||||
/// Return the mod of `num` with the smallest integer type
|
||||
pub fn comptimeMod(num: anytype, denom: comptime_int) IntFittingRange(0, denom - 1) {
|
||||
return @intCast(IntFittingRange(0, denom - 1), @mod(num, denom));
|
||||
}
|
||||
|
||||
@ -672,10 +672,9 @@ pub const Mutable = struct {
|
||||
///
|
||||
/// `limbs_buffer` is used for temporary storage during the operation.
|
||||
pub fn gcdNoAlias(rma: *Mutable, x: Const, y: Const, limbs_buffer: *std.ArrayList(Limb)) !void {
|
||||
_ = limbs_buffer;
|
||||
assert(rma.limbs.ptr != x.limbs.ptr); // illegal aliasing
|
||||
assert(rma.limbs.ptr != y.limbs.ptr); // illegal aliasing
|
||||
return gcdLehmer(rma, x, y, allocator);
|
||||
return gcdLehmer(rma, x, y, limbs_buffer);
|
||||
}
|
||||
|
||||
fn gcdLehmer(result: *Mutable, xa: Const, ya: Const, limbs_buffer: *std.ArrayList(Limb)) !void {
|
||||
|
||||
194
lib/std/net.zig
194
lib/std/net.zig
@ -10,7 +10,7 @@ const native_endian = builtin.target.cpu.arch.endian();
|
||||
|
||||
// Windows 10 added support for unix sockets in build 17063, redstone 4 is the
|
||||
// first release to support them.
|
||||
pub const has_unix_sockets = @hasDecl(os, "sockaddr_un") and
|
||||
pub const has_unix_sockets = @hasDecl(os.sockaddr, "un") and
|
||||
(builtin.target.os.tag != .windows or
|
||||
std.Target.current.os.version_range.windows.isAtLeast(.win10_rs4) orelse false);
|
||||
|
||||
@ -18,7 +18,7 @@ pub const Address = extern union {
|
||||
any: os.sockaddr,
|
||||
in: Ip4Address,
|
||||
in6: Ip6Address,
|
||||
un: if (has_unix_sockets) os.sockaddr_un else void,
|
||||
un: if (has_unix_sockets) os.sockaddr.un else void,
|
||||
|
||||
/// Parse the given IP address string into an Address value.
|
||||
/// It is recommended to use `resolveIp` instead, to handle
|
||||
@ -70,9 +70,9 @@ pub const Address = extern union {
|
||||
|
||||
pub fn parseExpectingFamily(name: []const u8, family: os.sa_family_t, port: u16) !Address {
|
||||
switch (family) {
|
||||
os.AF_INET => return parseIp4(name, port),
|
||||
os.AF_INET6 => return parseIp6(name, port),
|
||||
os.AF_UNSPEC => return parseIp(name, port),
|
||||
os.AF.INET => return parseIp4(name, port),
|
||||
os.AF.INET6 => return parseIp6(name, port),
|
||||
os.AF.UNSPEC => return parseIp(name, port),
|
||||
else => unreachable,
|
||||
}
|
||||
}
|
||||
@ -98,8 +98,8 @@ pub const Address = extern union {
|
||||
}
|
||||
|
||||
pub fn initUnix(path: []const u8) !Address {
|
||||
var sock_addr = os.sockaddr_un{
|
||||
.family = os.AF_UNIX,
|
||||
var sock_addr = os.sockaddr.un{
|
||||
.family = os.AF.UNIX,
|
||||
.path = undefined,
|
||||
};
|
||||
|
||||
@ -116,8 +116,8 @@ pub const Address = extern union {
|
||||
/// Asserts that the address is ip4 or ip6.
|
||||
pub fn getPort(self: Address) u16 {
|
||||
return switch (self.any.family) {
|
||||
os.AF_INET => self.in.getPort(),
|
||||
os.AF_INET6 => self.in6.getPort(),
|
||||
os.AF.INET => self.in.getPort(),
|
||||
os.AF.INET6 => self.in6.getPort(),
|
||||
else => unreachable,
|
||||
};
|
||||
}
|
||||
@ -126,8 +126,8 @@ pub const Address = extern union {
|
||||
/// Asserts that the address is ip4 or ip6.
|
||||
pub fn setPort(self: *Address, port: u16) void {
|
||||
switch (self.any.family) {
|
||||
os.AF_INET => self.in.setPort(port),
|
||||
os.AF_INET6 => self.in6.setPort(port),
|
||||
os.AF.INET => self.in.setPort(port),
|
||||
os.AF.INET6 => self.in6.setPort(port),
|
||||
else => unreachable,
|
||||
}
|
||||
}
|
||||
@ -137,8 +137,8 @@ pub const Address = extern union {
|
||||
/// on the address family.
|
||||
pub fn initPosix(addr: *align(4) const os.sockaddr) Address {
|
||||
switch (addr.family) {
|
||||
os.AF_INET => return Address{ .in = Ip4Address{ .sa = @ptrCast(*const os.sockaddr_in, addr).* } },
|
||||
os.AF_INET6 => return Address{ .in6 = Ip6Address{ .sa = @ptrCast(*const os.sockaddr_in6, addr).* } },
|
||||
os.AF.INET => return Address{ .in = Ip4Address{ .sa = @ptrCast(*const os.sockaddr.in, addr).* } },
|
||||
os.AF.INET6 => return Address{ .in6 = Ip6Address{ .sa = @ptrCast(*const os.sockaddr.in6, addr).* } },
|
||||
else => unreachable,
|
||||
}
|
||||
}
|
||||
@ -150,9 +150,9 @@ pub const Address = extern union {
|
||||
out_stream: anytype,
|
||||
) !void {
|
||||
switch (self.any.family) {
|
||||
os.AF_INET => try self.in.format(fmt, options, out_stream),
|
||||
os.AF_INET6 => try self.in6.format(fmt, options, out_stream),
|
||||
os.AF_UNIX => {
|
||||
os.AF.INET => try self.in.format(fmt, options, out_stream),
|
||||
os.AF.INET6 => try self.in6.format(fmt, options, out_stream),
|
||||
os.AF.UNIX => {
|
||||
if (!has_unix_sockets) {
|
||||
unreachable;
|
||||
}
|
||||
@ -171,15 +171,15 @@ pub const Address = extern union {
|
||||
|
||||
pub fn getOsSockLen(self: Address) os.socklen_t {
|
||||
switch (self.any.family) {
|
||||
os.AF_INET => return self.in.getOsSockLen(),
|
||||
os.AF_INET6 => return self.in6.getOsSockLen(),
|
||||
os.AF_UNIX => {
|
||||
os.AF.INET => return self.in.getOsSockLen(),
|
||||
os.AF.INET6 => return self.in6.getOsSockLen(),
|
||||
os.AF.UNIX => {
|
||||
if (!has_unix_sockets) {
|
||||
unreachable;
|
||||
}
|
||||
|
||||
const path_len = std.mem.len(std.meta.assumeSentinel(&self.un.path, 0));
|
||||
return @intCast(os.socklen_t, @sizeOf(os.sockaddr_un) - self.un.path.len + path_len);
|
||||
return @intCast(os.socklen_t, @sizeOf(os.sockaddr.un) - self.un.path.len + path_len);
|
||||
},
|
||||
else => unreachable,
|
||||
}
|
||||
@ -187,7 +187,7 @@ pub const Address = extern union {
|
||||
};
|
||||
|
||||
pub const Ip4Address = extern struct {
|
||||
sa: os.sockaddr_in,
|
||||
sa: os.sockaddr.in,
|
||||
|
||||
pub fn parse(buf: []const u8, port: u16) !Ip4Address {
|
||||
var result = Ip4Address{
|
||||
@ -249,7 +249,7 @@ pub const Ip4Address = extern struct {
|
||||
|
||||
pub fn init(addr: [4]u8, port: u16) Ip4Address {
|
||||
return Ip4Address{
|
||||
.sa = os.sockaddr_in{
|
||||
.sa = os.sockaddr.in{
|
||||
.port = mem.nativeToBig(u16, port),
|
||||
.addr = @ptrCast(*align(1) const u32, &addr).*,
|
||||
},
|
||||
@ -288,19 +288,19 @@ pub const Ip4Address = extern struct {
|
||||
|
||||
pub fn getOsSockLen(self: Ip4Address) os.socklen_t {
|
||||
_ = self;
|
||||
return @sizeOf(os.sockaddr_in);
|
||||
return @sizeOf(os.sockaddr.in);
|
||||
}
|
||||
};
|
||||
|
||||
pub const Ip6Address = extern struct {
|
||||
sa: os.sockaddr_in6,
|
||||
sa: os.sockaddr.in6,
|
||||
|
||||
/// Parse a given IPv6 address string into an Address.
|
||||
/// Assumes the Scope ID of the address is fully numeric.
|
||||
/// For non-numeric addresses, see `resolveIp6`.
|
||||
pub fn parse(buf: []const u8, port: u16) !Ip6Address {
|
||||
var result = Ip6Address{
|
||||
.sa = os.sockaddr_in6{
|
||||
.sa = os.sockaddr.in6{
|
||||
.scope_id = 0,
|
||||
.port = mem.nativeToBig(u16, port),
|
||||
.flowinfo = 0,
|
||||
@ -407,7 +407,7 @@ pub const Ip6Address = extern struct {
|
||||
pub fn resolve(buf: []const u8, port: u16) !Ip6Address {
|
||||
// TODO: Unify the implementations of resolveIp6 and parseIp6.
|
||||
var result = Ip6Address{
|
||||
.sa = os.sockaddr_in6{
|
||||
.sa = os.sockaddr.in6{
|
||||
.scope_id = 0,
|
||||
.port = mem.nativeToBig(u16, port),
|
||||
.flowinfo = 0,
|
||||
@ -536,7 +536,7 @@ pub const Ip6Address = extern struct {
|
||||
|
||||
pub fn init(addr: [16]u8, port: u16, flowinfo: u32, scope_id: u32) Ip6Address {
|
||||
return Ip6Address{
|
||||
.sa = os.sockaddr_in6{
|
||||
.sa = os.sockaddr.in6{
|
||||
.addr = addr,
|
||||
.port = mem.nativeToBig(u16, port),
|
||||
.flowinfo = flowinfo,
|
||||
@ -608,15 +608,15 @@ pub const Ip6Address = extern struct {
|
||||
|
||||
pub fn getOsSockLen(self: Ip6Address) os.socklen_t {
|
||||
_ = self;
|
||||
return @sizeOf(os.sockaddr_in6);
|
||||
return @sizeOf(os.sockaddr.in6);
|
||||
}
|
||||
};
|
||||
|
||||
pub fn connectUnixSocket(path: []const u8) !Stream {
|
||||
const opt_non_block = if (std.io.is_async) os.SOCK_NONBLOCK else 0;
|
||||
const opt_non_block = if (std.io.is_async) os.SOCK.NONBLOCK else 0;
|
||||
const sockfd = try os.socket(
|
||||
os.AF_UNIX,
|
||||
os.SOCK_STREAM | os.SOCK_CLOEXEC | opt_non_block,
|
||||
os.AF.UNIX,
|
||||
os.SOCK.STREAM | os.SOCK.CLOEXEC | opt_non_block,
|
||||
0,
|
||||
);
|
||||
errdefer os.closeSocket(sockfd);
|
||||
@ -637,7 +637,7 @@ pub fn connectUnixSocket(path: []const u8) !Stream {
|
||||
|
||||
fn if_nametoindex(name: []const u8) !u32 {
|
||||
var ifr: os.ifreq = undefined;
|
||||
var sockfd = try os.socket(os.AF_UNIX, os.SOCK_DGRAM | os.SOCK_CLOEXEC, 0);
|
||||
var sockfd = try os.socket(os.AF.UNIX, os.SOCK.DGRAM | os.SOCK.CLOEXEC, 0);
|
||||
defer os.closeSocket(sockfd);
|
||||
|
||||
std.mem.copy(u8, &ifr.ifrn.name, name);
|
||||
@ -682,10 +682,10 @@ pub fn tcpConnectToHost(allocator: *mem.Allocator, name: []const u8, port: u16)
|
||||
}
|
||||
|
||||
pub fn tcpConnectToAddress(address: Address) !Stream {
|
||||
const nonblock = if (std.io.is_async) os.SOCK_NONBLOCK else 0;
|
||||
const sock_flags = os.SOCK_STREAM | nonblock |
|
||||
(if (builtin.target.os.tag == .windows) 0 else os.SOCK_CLOEXEC);
|
||||
const sockfd = try os.socket(address.any.family, sock_flags, os.IPPROTO_TCP);
|
||||
const nonblock = if (std.io.is_async) os.SOCK.NONBLOCK else 0;
|
||||
const sock_flags = os.SOCK.STREAM | nonblock |
|
||||
(if (builtin.target.os.tag == .windows) 0 else os.SOCK.CLOEXEC);
|
||||
const sockfd = try os.socket(address.any.family, sock_flags, os.IPPROTO.TCP);
|
||||
errdefer os.closeSocket(sockfd);
|
||||
|
||||
if (std.io.is_async) {
|
||||
@ -724,10 +724,10 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*
|
||||
|
||||
const sys = if (builtin.target.os.tag == .windows) os.windows.ws2_32 else os.system;
|
||||
const hints = os.addrinfo{
|
||||
.flags = sys.AI_NUMERICSERV,
|
||||
.family = os.AF_UNSPEC,
|
||||
.socktype = os.SOCK_STREAM,
|
||||
.protocol = os.IPPROTO_TCP,
|
||||
.flags = sys.AI.NUMERICSERV,
|
||||
.family = os.AF.UNSPEC,
|
||||
.socktype = os.SOCK.STREAM,
|
||||
.protocol = os.IPPROTO.TCP,
|
||||
.canonname = null,
|
||||
.addr = null,
|
||||
.addrlen = 0,
|
||||
@ -794,8 +794,8 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*
|
||||
return result;
|
||||
}
|
||||
if (builtin.target.os.tag == .linux) {
|
||||
const flags = std.c.AI_NUMERICSERV;
|
||||
const family = os.AF_UNSPEC;
|
||||
const flags = std.c.AI.NUMERICSERV;
|
||||
const family = os.AF.UNSPEC;
|
||||
var lookup_addrs = std.ArrayList(LookupAddr).init(allocator);
|
||||
defer lookup_addrs.deinit();
|
||||
|
||||
@ -846,7 +846,7 @@ fn linuxLookupName(
|
||||
try canon.appendSlice(name);
|
||||
if (Address.parseExpectingFamily(name, family, port)) |addr| {
|
||||
try addrs.append(LookupAddr{ .addr = addr });
|
||||
} else |name_err| if ((flags & std.c.AI_NUMERICHOST) != 0) {
|
||||
} else |name_err| if ((flags & std.c.AI.NUMERICHOST) != 0) {
|
||||
return name_err;
|
||||
} else {
|
||||
try linuxLookupNameFromHosts(addrs, canon, name, family, port);
|
||||
@ -876,9 +876,9 @@ fn linuxLookupName(
|
||||
|
||||
// No further processing is needed if there are fewer than 2
|
||||
// results or if there are only IPv4 results.
|
||||
if (addrs.items.len == 1 or family == os.AF_INET) return;
|
||||
if (addrs.items.len == 1 or family == os.AF.INET) return;
|
||||
const all_ip4 = for (addrs.items) |addr| {
|
||||
if (addr.addr.any.family != os.AF_INET) break false;
|
||||
if (addr.addr.any.family != os.AF.INET) break false;
|
||||
} else true;
|
||||
if (all_ip4) return;
|
||||
|
||||
@ -891,19 +891,19 @@ fn linuxLookupName(
|
||||
// A more idiomatic "ziggy" implementation would be welcome.
|
||||
for (addrs.items) |*addr, i| {
|
||||
var key: i32 = 0;
|
||||
var sa6: os.sockaddr_in6 = undefined;
|
||||
@memset(@ptrCast([*]u8, &sa6), 0, @sizeOf(os.sockaddr_in6));
|
||||
var da6 = os.sockaddr_in6{
|
||||
.family = os.AF_INET6,
|
||||
var sa6: os.sockaddr.in6 = undefined;
|
||||
@memset(@ptrCast([*]u8, &sa6), 0, @sizeOf(os.sockaddr.in6));
|
||||
var da6 = os.sockaddr.in6{
|
||||
.family = os.AF.INET6,
|
||||
.scope_id = addr.addr.in6.sa.scope_id,
|
||||
.port = 65535,
|
||||
.flowinfo = 0,
|
||||
.addr = [1]u8{0} ** 16,
|
||||
};
|
||||
var sa4: os.sockaddr_in = undefined;
|
||||
@memset(@ptrCast([*]u8, &sa4), 0, @sizeOf(os.sockaddr_in));
|
||||
var da4 = os.sockaddr_in{
|
||||
.family = os.AF_INET,
|
||||
var sa4: os.sockaddr.in = undefined;
|
||||
@memset(@ptrCast([*]u8, &sa4), 0, @sizeOf(os.sockaddr.in));
|
||||
var da4 = os.sockaddr.in{
|
||||
.family = os.AF.INET,
|
||||
.port = 65535,
|
||||
.addr = 0,
|
||||
.zero = [1]u8{0} ** 8,
|
||||
@ -912,21 +912,21 @@ fn linuxLookupName(
|
||||
var da: *align(4) os.sockaddr = undefined;
|
||||
var salen: os.socklen_t = undefined;
|
||||
var dalen: os.socklen_t = undefined;
|
||||
if (addr.addr.any.family == os.AF_INET6) {
|
||||
if (addr.addr.any.family == os.AF.INET6) {
|
||||
mem.copy(u8, &da6.addr, &addr.addr.in6.sa.addr);
|
||||
da = @ptrCast(*os.sockaddr, &da6);
|
||||
dalen = @sizeOf(os.sockaddr_in6);
|
||||
dalen = @sizeOf(os.sockaddr.in6);
|
||||
sa = @ptrCast(*os.sockaddr, &sa6);
|
||||
salen = @sizeOf(os.sockaddr_in6);
|
||||
salen = @sizeOf(os.sockaddr.in6);
|
||||
} else {
|
||||
mem.copy(u8, &sa6.addr, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff");
|
||||
mem.copy(u8, &da6.addr, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff");
|
||||
mem.writeIntNative(u32, da6.addr[12..], addr.addr.in.sa.addr);
|
||||
da4.addr = addr.addr.in.sa.addr;
|
||||
da = @ptrCast(*os.sockaddr, &da4);
|
||||
dalen = @sizeOf(os.sockaddr_in);
|
||||
dalen = @sizeOf(os.sockaddr.in);
|
||||
sa = @ptrCast(*os.sockaddr, &sa4);
|
||||
salen = @sizeOf(os.sockaddr_in);
|
||||
salen = @sizeOf(os.sockaddr.in);
|
||||
}
|
||||
const dpolicy = policyOf(da6.addr);
|
||||
const dscope: i32 = scopeOf(da6.addr);
|
||||
@ -934,13 +934,13 @@ fn linuxLookupName(
|
||||
const dprec: i32 = dpolicy.prec;
|
||||
const MAXADDRS = 3;
|
||||
var prefixlen: i32 = 0;
|
||||
const sock_flags = os.SOCK_DGRAM | os.SOCK_CLOEXEC;
|
||||
if (os.socket(addr.addr.any.family, sock_flags, os.IPPROTO_UDP)) |fd| syscalls: {
|
||||
const sock_flags = os.SOCK.DGRAM | os.SOCK.CLOEXEC;
|
||||
if (os.socket(addr.addr.any.family, sock_flags, os.IPPROTO.UDP)) |fd| syscalls: {
|
||||
defer os.closeSocket(fd);
|
||||
os.connect(fd, da, dalen) catch break :syscalls;
|
||||
key |= DAS_USABLE;
|
||||
os.getsockname(fd, sa, &salen) catch break :syscalls;
|
||||
if (addr.addr.any.family == os.AF_INET) {
|
||||
if (addr.addr.any.family == os.AF.INET) {
|
||||
// TODO sa6.addr[12..16] should return *[4]u8, making this cast unnecessary.
|
||||
mem.writeIntNative(u32, @ptrCast(*[4]u8, &sa6.addr[12]), sa4.addr);
|
||||
}
|
||||
@ -1082,24 +1082,24 @@ fn linuxLookupNameFromNull(
|
||||
flags: u32,
|
||||
port: u16,
|
||||
) !void {
|
||||
if ((flags & std.c.AI_PASSIVE) != 0) {
|
||||
if (family != os.AF_INET6) {
|
||||
if ((flags & std.c.AI.PASSIVE) != 0) {
|
||||
if (family != os.AF.INET6) {
|
||||
(try addrs.addOne()).* = LookupAddr{
|
||||
.addr = Address.initIp4([1]u8{0} ** 4, port),
|
||||
};
|
||||
}
|
||||
if (family != os.AF_INET) {
|
||||
if (family != os.AF.INET) {
|
||||
(try addrs.addOne()).* = LookupAddr{
|
||||
.addr = Address.initIp6([1]u8{0} ** 16, port, 0, 0),
|
||||
};
|
||||
}
|
||||
} else {
|
||||
if (family != os.AF_INET6) {
|
||||
if (family != os.AF.INET6) {
|
||||
(try addrs.addOne()).* = LookupAddr{
|
||||
.addr = Address.initIp4([4]u8{ 127, 0, 0, 1 }, port),
|
||||
};
|
||||
}
|
||||
if (family != os.AF_INET) {
|
||||
if (family != os.AF.INET) {
|
||||
(try addrs.addOne()).* = LookupAddr{
|
||||
.addr = Address.initIp6(([1]u8{0} ** 15) ++ [1]u8{1}, port, 0, 0),
|
||||
};
|
||||
@ -1252,8 +1252,8 @@ fn linuxLookupNameFromDns(
|
||||
rr: u8,
|
||||
};
|
||||
const afrrs = [_]AfRr{
|
||||
AfRr{ .af = os.AF_INET6, .rr = os.RR_A },
|
||||
AfRr{ .af = os.AF_INET, .rr = os.RR_AAAA },
|
||||
AfRr{ .af = os.AF.INET6, .rr = os.RR.A },
|
||||
AfRr{ .af = os.AF.INET, .rr = os.RR.AAAA },
|
||||
};
|
||||
var qbuf: [2][280]u8 = undefined;
|
||||
var abuf: [2][512]u8 = undefined;
|
||||
@ -1386,8 +1386,8 @@ fn resMSendRc(
|
||||
const timeout = 1000 * rc.timeout;
|
||||
const attempts = rc.attempts;
|
||||
|
||||
var sl: os.socklen_t = @sizeOf(os.sockaddr_in);
|
||||
var family: os.sa_family_t = os.AF_INET;
|
||||
var sl: os.socklen_t = @sizeOf(os.sockaddr.in);
|
||||
var family: os.sa_family_t = os.AF.INET;
|
||||
|
||||
var ns_list = std.ArrayList(Address).init(rc.ns.allocator);
|
||||
defer ns_list.deinit();
|
||||
@ -1398,9 +1398,9 @@ fn resMSendRc(
|
||||
for (rc.ns.items) |iplit, i| {
|
||||
ns[i] = iplit.addr;
|
||||
assert(ns[i].getPort() == 53);
|
||||
if (iplit.addr.any.family != os.AF_INET) {
|
||||
sl = @sizeOf(os.sockaddr_in6);
|
||||
family = os.AF_INET6;
|
||||
if (iplit.addr.any.family != os.AF.INET) {
|
||||
sl = @sizeOf(os.sockaddr.in6);
|
||||
family = os.AF.INET6;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1408,13 +1408,13 @@ fn resMSendRc(
|
||||
var sa: Address = undefined;
|
||||
@memset(@ptrCast([*]u8, &sa), 0, @sizeOf(Address));
|
||||
sa.any.family = family;
|
||||
const flags = os.SOCK_DGRAM | os.SOCK_CLOEXEC | os.SOCK_NONBLOCK;
|
||||
const flags = os.SOCK.DGRAM | os.SOCK.CLOEXEC | os.SOCK.NONBLOCK;
|
||||
const fd = os.socket(family, flags, 0) catch |err| switch (err) {
|
||||
error.AddressFamilyNotSupported => blk: {
|
||||
// Handle case where system lacks IPv6 support
|
||||
if (family == os.AF_INET6) {
|
||||
family = os.AF_INET;
|
||||
break :blk try os.socket(os.AF_INET, flags, 0);
|
||||
if (family == os.AF.INET6) {
|
||||
family = os.AF.INET;
|
||||
break :blk try os.socket(os.AF.INET, flags, 0);
|
||||
}
|
||||
return err;
|
||||
},
|
||||
@ -1429,15 +1429,15 @@ fn resMSendRc(
|
||||
|
||||
// Convert any IPv4 addresses in a mixed environment to v4-mapped
|
||||
// TODO
|
||||
//if (family == AF_INET6) {
|
||||
// setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &(int){0}, sizeof 0);
|
||||
//if (family == AF.INET6) {
|
||||
// setsockopt(fd, IPPROTO.IPV6, IPV6_V6ONLY, &(int){0}, sizeof 0);
|
||||
// for (i=0; i<nns; i++) {
|
||||
// if (ns[i].sin.sin_family != AF_INET) continue;
|
||||
// if (ns[i].sin.sin_family != AF.INET) continue;
|
||||
// memcpy(ns[i].sin6.sin6_addr.s6_addr+12,
|
||||
// &ns[i].sin.sin_addr, 4);
|
||||
// memcpy(ns[i].sin6.sin6_addr.s6_addr,
|
||||
// "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12);
|
||||
// ns[i].sin6.sin6_family = AF_INET6;
|
||||
// ns[i].sin6.sin6_family = AF.INET6;
|
||||
// ns[i].sin6.sin6_flowinfo = 0;
|
||||
// ns[i].sin6.sin6_scope_id = 0;
|
||||
// }
|
||||
@ -1445,7 +1445,7 @@ fn resMSendRc(
|
||||
|
||||
var pfd = [1]os.pollfd{os.pollfd{
|
||||
.fd = fd,
|
||||
.events = os.POLLIN,
|
||||
.events = os.POLL.IN,
|
||||
.revents = undefined,
|
||||
}};
|
||||
const retry_interval = timeout / attempts;
|
||||
@ -1465,9 +1465,9 @@ fn resMSendRc(
|
||||
var j: usize = 0;
|
||||
while (j < ns.len) : (j += 1) {
|
||||
if (std.io.is_async) {
|
||||
_ = std.event.Loop.instance.?.sendto(fd, queries[i], os.MSG_NOSIGNAL, &ns[j].any, sl) catch undefined;
|
||||
_ = std.event.Loop.instance.?.sendto(fd, queries[i], os.MSG.NOSIGNAL, &ns[j].any, sl) catch undefined;
|
||||
} else {
|
||||
_ = os.sendto(fd, queries[i], os.MSG_NOSIGNAL, &ns[j].any, sl) catch undefined;
|
||||
_ = os.sendto(fd, queries[i], os.MSG.NOSIGNAL, &ns[j].any, sl) catch undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1513,9 +1513,9 @@ fn resMSendRc(
|
||||
2 => if (servfail_retry != 0) {
|
||||
servfail_retry -= 1;
|
||||
if (std.io.is_async) {
|
||||
_ = std.event.Loop.instance.?.sendto(fd, queries[i], os.MSG_NOSIGNAL, &ns[j].any, sl) catch undefined;
|
||||
_ = std.event.Loop.instance.?.sendto(fd, queries[i], os.MSG.NOSIGNAL, &ns[j].any, sl) catch undefined;
|
||||
} else {
|
||||
_ = os.sendto(fd, queries[i], os.MSG_NOSIGNAL, &ns[j].any, sl) catch undefined;
|
||||
_ = os.sendto(fd, queries[i], os.MSG.NOSIGNAL, &ns[j].any, sl) catch undefined;
|
||||
}
|
||||
},
|
||||
else => continue,
|
||||
@ -1570,21 +1570,21 @@ fn dnsParse(
|
||||
|
||||
fn dnsParseCallback(ctx: dpc_ctx, rr: u8, data: []const u8, packet: []const u8) !void {
|
||||
switch (rr) {
|
||||
os.RR_A => {
|
||||
os.RR.A => {
|
||||
if (data.len != 4) return error.InvalidDnsARecord;
|
||||
const new_addr = try ctx.addrs.addOne();
|
||||
new_addr.* = LookupAddr{
|
||||
.addr = Address.initIp4(data[0..4].*, ctx.port),
|
||||
};
|
||||
},
|
||||
os.RR_AAAA => {
|
||||
os.RR.AAAA => {
|
||||
if (data.len != 16) return error.InvalidDnsAAAARecord;
|
||||
const new_addr = try ctx.addrs.addOne();
|
||||
new_addr.* = LookupAddr{
|
||||
.addr = Address.initIp6(data[0..16].*, ctx.port, 0, 0),
|
||||
};
|
||||
},
|
||||
os.RR_CNAME => {
|
||||
os.RR.CNAME => {
|
||||
var tmp: [256]u8 = undefined;
|
||||
// Returns len of compressed name. strlen to get canon name.
|
||||
_ = try os.dn_expand(packet, data, &tmp);
|
||||
@ -1700,7 +1700,7 @@ pub const StreamServer = struct {
|
||||
/// seeing "Connection refused".
|
||||
kernel_backlog: u31 = 128,
|
||||
|
||||
/// Enable SO_REUSEADDR on the socket.
|
||||
/// Enable SO.REUSEADDR on the socket.
|
||||
reuse_address: bool = false,
|
||||
};
|
||||
|
||||
@ -1722,9 +1722,9 @@ pub const StreamServer = struct {
|
||||
}
|
||||
|
||||
pub fn listen(self: *StreamServer, address: Address) !void {
|
||||
const nonblock = if (std.io.is_async) os.SOCK_NONBLOCK else 0;
|
||||
const sock_flags = os.SOCK_STREAM | os.SOCK_CLOEXEC | nonblock;
|
||||
const proto = if (address.any.family == os.AF_UNIX) @as(u32, 0) else os.IPPROTO_TCP;
|
||||
const nonblock = if (std.io.is_async) os.SOCK.NONBLOCK else 0;
|
||||
const sock_flags = os.SOCK.STREAM | os.SOCK.CLOEXEC | nonblock;
|
||||
const proto = if (address.any.family == os.AF.UNIX) @as(u32, 0) else os.IPPROTO.TCP;
|
||||
|
||||
const sockfd = try os.socket(address.any.family, sock_flags, proto);
|
||||
self.sockfd = sockfd;
|
||||
@ -1736,8 +1736,8 @@ pub const StreamServer = struct {
|
||||
if (self.reuse_address) {
|
||||
try os.setsockopt(
|
||||
sockfd,
|
||||
os.SOL_SOCKET,
|
||||
os.SO_REUSEADDR,
|
||||
os.SOL.SOCKET,
|
||||
os.SO.REUSEADDR,
|
||||
&mem.toBytes(@as(c_int, 1)),
|
||||
);
|
||||
}
|
||||
@ -1801,9 +1801,9 @@ pub const StreamServer = struct {
|
||||
const accept_result = blk: {
|
||||
if (std.io.is_async) {
|
||||
const loop = std.event.Loop.instance orelse return error.UnexpectedError;
|
||||
break :blk loop.accept(self.sockfd.?, &accepted_addr.any, &adr_len, os.SOCK_CLOEXEC);
|
||||
break :blk loop.accept(self.sockfd.?, &accepted_addr.any, &adr_len, os.SOCK.CLOEXEC);
|
||||
} else {
|
||||
break :blk os.accept(self.sockfd.?, &accepted_addr.any, &adr_len, os.SOCK_CLOEXEC);
|
||||
break :blk os.accept(self.sockfd.?, &accepted_addr.any, &adr_len, os.SOCK.CLOEXEC);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
357
lib/std/os.zig
357
lib/std/os.zig
@ -16,20 +16,21 @@
|
||||
|
||||
const root = @import("root");
|
||||
const std = @import("std.zig");
|
||||
const builtin = std.builtin;
|
||||
const builtin = @import("builtin");
|
||||
const assert = std.debug.assert;
|
||||
const math = std.math;
|
||||
const mem = std.mem;
|
||||
const elf = std.elf;
|
||||
const dl = @import("dynamic_library.zig");
|
||||
const MAX_PATH_BYTES = std.fs.MAX_PATH_BYTES;
|
||||
const is_windows = builtin.os.tag == .windows;
|
||||
|
||||
pub const darwin = @import("os/darwin.zig");
|
||||
pub const dragonfly = @import("os/dragonfly.zig");
|
||||
pub const freebsd = @import("os/freebsd.zig");
|
||||
pub const haiku = @import("os/haiku.zig");
|
||||
pub const netbsd = @import("os/netbsd.zig");
|
||||
pub const openbsd = @import("os/openbsd.zig");
|
||||
pub const darwin = std.c;
|
||||
pub const dragonfly = std.c;
|
||||
pub const freebsd = std.c;
|
||||
pub const haiku = std.c;
|
||||
pub const netbsd = std.c;
|
||||
pub const openbsd = std.c;
|
||||
pub const linux = @import("os/linux.zig");
|
||||
pub const uefi = @import("os/uefi.zig");
|
||||
pub const wasi = @import("os/wasi.zig");
|
||||
@ -40,15 +41,10 @@ comptime {
|
||||
}
|
||||
|
||||
test {
|
||||
_ = darwin;
|
||||
_ = freebsd;
|
||||
_ = linux;
|
||||
_ = netbsd;
|
||||
_ = openbsd;
|
||||
_ = uefi;
|
||||
_ = wasi;
|
||||
_ = windows;
|
||||
_ = haiku;
|
||||
|
||||
_ = @import("os/test.zig");
|
||||
}
|
||||
@ -58,22 +54,150 @@ test {
|
||||
/// When not linking libc, it is the OS-specific system interface.
|
||||
pub const system = if (@hasDecl(root, "os") and root.os != @This())
|
||||
root.os.system
|
||||
else if (builtin.link_libc)
|
||||
else if (builtin.link_libc or is_windows)
|
||||
std.c
|
||||
else switch (builtin.os.tag) {
|
||||
.macos, .ios, .watchos, .tvos => darwin,
|
||||
.freebsd => freebsd,
|
||||
.haiku => haiku,
|
||||
.linux => linux,
|
||||
.netbsd => netbsd,
|
||||
.openbsd => openbsd,
|
||||
.dragonfly => dragonfly,
|
||||
.wasi => wasi,
|
||||
.windows => windows,
|
||||
.uefi => uefi,
|
||||
else => struct {},
|
||||
};
|
||||
|
||||
pub usingnamespace @import("os/bits.zig");
|
||||
pub const AF = system.AF;
|
||||
pub const ARCH = system.ARCH;
|
||||
pub const AT = system.AT;
|
||||
pub const CLOCK = system.CLOCK;
|
||||
pub const CPU_COUNT = system.CPU_COUNT;
|
||||
pub const CTL = system.CTL;
|
||||
pub const DT = system.DT;
|
||||
pub const E = system.E;
|
||||
pub const Elf_Symndx = system.Elf_Symndx;
|
||||
pub const F = system.F;
|
||||
pub const FD_CLOEXEC = system.FD_CLOEXEC;
|
||||
pub const Flock = system.Flock;
|
||||
pub const HOST_NAME_MAX = system.HOST_NAME_MAX;
|
||||
pub const IFNAMESIZE = system.IFNAMESIZE;
|
||||
pub const IOV_MAX = system.IOV_MAX;
|
||||
pub const IPPROTO = system.IPPROTO;
|
||||
pub const KERN = system.KERN;
|
||||
pub const Kevent = system.Kevent;
|
||||
pub const LOCK = system.LOCK;
|
||||
pub const MADV = system.MADV;
|
||||
pub const MAP = system.MAP;
|
||||
pub const MAX_ADDR_LEN = system.MAX_ADDR_LEN;
|
||||
pub const MMAP2_UNIT = system.MMAP2_UNIT;
|
||||
pub const MSG = system.MSG;
|
||||
pub const NAME_MAX = system.NAME_MAX;
|
||||
pub const O = system.O;
|
||||
pub const PATH_MAX = system.PATH_MAX;
|
||||
pub const POLL = system.POLL;
|
||||
pub const POSIX_FADV = system.POSIX_FADV;
|
||||
pub const PR = system.PR;
|
||||
pub const PROT = system.PROT;
|
||||
pub const REG = system.REG;
|
||||
pub const RIGHT = system.RIGHT;
|
||||
pub const RLIM = system.RLIM;
|
||||
pub const RR = system.RR;
|
||||
pub const S = system.S;
|
||||
pub const SA = system.SA;
|
||||
pub const SC = system.SC;
|
||||
pub const SEEK = system.SEEK;
|
||||
pub const SHUT = system.SHUT;
|
||||
pub const SIG = system.SIG;
|
||||
pub const SIOCGIFINDEX = system.SIOCGIFINDEX;
|
||||
pub const SO = system.SO;
|
||||
pub const SOCK = system.SOCK;
|
||||
pub const SOL = system.SOL;
|
||||
pub const STDERR_FILENO = system.STDERR_FILENO;
|
||||
pub const STDIN_FILENO = system.STDIN_FILENO;
|
||||
pub const STDOUT_FILENO = system.STDOUT_FILENO;
|
||||
pub const SYS = system.SYS;
|
||||
pub const Sigaction = system.Sigaction;
|
||||
pub const Stat = system.Stat;
|
||||
pub const TCSA = system.TCSA;
|
||||
pub const TCP = system.TCP;
|
||||
pub const VDSO = system.VDSO;
|
||||
pub const W = system.W;
|
||||
pub const addrinfo = system.addrinfo;
|
||||
pub const blkcnt_t = system.blkcnt_t;
|
||||
pub const blksize_t = system.blksize_t;
|
||||
pub const clock_t = system.clock_t;
|
||||
pub const cpu_set_t = system.cpu_set_t;
|
||||
pub const dev_t = system.dev_t;
|
||||
pub const dl_phdr_info = system.dl_phdr_info;
|
||||
pub const empty_sigset = system.empty_sigset;
|
||||
pub const fd_t = system.fd_t;
|
||||
pub const fdflags_t = system.fdflags_t;
|
||||
pub const fdstat_t = system.fdstat_t;
|
||||
pub const gid_t = system.gid_t;
|
||||
pub const ifreq = system.ifreq;
|
||||
pub const ino_t = system.ino_t;
|
||||
pub const lookupflags_t = system.lookupflags_t;
|
||||
pub const mcontext_t = system.mcontext_t;
|
||||
pub const mode_t = system.mode_t;
|
||||
pub const msghdr = system.msghdr;
|
||||
pub const msghdr_const = system.msghdr_const;
|
||||
pub const nfds_t = system.nfds_t;
|
||||
pub const nlink_t = system.nlink_t;
|
||||
pub const off_t = system.off_t;
|
||||
pub const oflags_t = system.oflags_t;
|
||||
pub const pid_t = system.pid_t;
|
||||
pub const pollfd = system.pollfd;
|
||||
pub const rights_t = system.rights_t;
|
||||
pub const rlim_t = system.rlim_t;
|
||||
pub const rlimit = system.rlimit;
|
||||
pub const rlimit_resource = system.rlimit_resource;
|
||||
pub const rusage = system.rusage;
|
||||
pub const sa_family_t = system.sa_family_t;
|
||||
pub const siginfo_t = system.siginfo_t;
|
||||
pub const sigset_t = system.sigset_t;
|
||||
pub const sockaddr = system.sockaddr;
|
||||
pub const socklen_t = system.socklen_t;
|
||||
pub const stack_t = system.stack_t;
|
||||
pub const termios = system.termios;
|
||||
pub const time_t = system.time_t;
|
||||
pub const timespec = system.timespec;
|
||||
pub const timestamp_t = system.timestamp_t;
|
||||
pub const timeval = system.timeval;
|
||||
pub const timezone = system.timezone;
|
||||
pub const ucontext_t = system.ucontext_t;
|
||||
pub const uid_t = system.uid_t;
|
||||
pub const user_desc = system.user_desc;
|
||||
pub const utsname = system.utsname;
|
||||
|
||||
pub const F_OK = system.F_OK;
|
||||
pub const R_OK = system.R_OK;
|
||||
pub const W_OK = system.W_OK;
|
||||
pub const X_OK = system.X_OK;
|
||||
|
||||
pub const iovec = extern struct {
|
||||
iov_base: [*]u8,
|
||||
iov_len: usize,
|
||||
};
|
||||
|
||||
pub const iovec_const = extern struct {
|
||||
iov_base: [*]const u8,
|
||||
iov_len: usize,
|
||||
};
|
||||
|
||||
pub const LOG = struct {
|
||||
/// system is unusable
|
||||
pub const EMERG = 0;
|
||||
/// action must be taken immediately
|
||||
pub const ALERT = 1;
|
||||
/// critical conditions
|
||||
pub const CRIT = 2;
|
||||
/// error conditions
|
||||
pub const ERR = 3;
|
||||
/// warning conditions
|
||||
pub const WARNING = 4;
|
||||
/// normal but significant condition
|
||||
pub const NOTICE = 5;
|
||||
/// informational
|
||||
pub const INFO = 6;
|
||||
/// debug-level messages
|
||||
pub const DEBUG = 7;
|
||||
};
|
||||
|
||||
pub const socket_t = if (builtin.os.tag == .windows) windows.ws2_32.SOCKET else fd_t;
|
||||
|
||||
@ -136,7 +260,7 @@ pub fn getrandom(buffer: []u8) GetRandomError!void {
|
||||
if (builtin.os.tag == .linux or builtin.os.tag == .freebsd) {
|
||||
var buf = buffer;
|
||||
const use_c = builtin.os.tag != .linux or
|
||||
std.c.versionCheck(builtin.Version{ .major = 2, .minor = 25, .patch = 0 }).ok;
|
||||
std.c.versionCheck(std.builtin.Version{ .major = 2, .minor = 25, .patch = 0 }).ok;
|
||||
|
||||
while (buf.len != 0) {
|
||||
const res = if (use_c) blk: {
|
||||
@ -178,11 +302,11 @@ pub fn getrandom(buffer: []u8) GetRandomError!void {
|
||||
}
|
||||
|
||||
fn getRandomBytesDevURandom(buf: []u8) !void {
|
||||
const fd = try openZ("/dev/urandom", O_RDONLY | O_CLOEXEC, 0);
|
||||
const fd = try openZ("/dev/urandom", O.RDONLY | O.CLOEXEC, 0);
|
||||
defer close(fd);
|
||||
|
||||
const st = try fstat(fd);
|
||||
if (!S_ISCHR(st.mode)) {
|
||||
if (!S.ISCHR(st.mode)) {
|
||||
return error.NoDevice;
|
||||
}
|
||||
|
||||
@ -210,11 +334,11 @@ pub fn abort() noreturn {
|
||||
windows.kernel32.ExitProcess(3);
|
||||
}
|
||||
if (!builtin.link_libc and builtin.os.tag == .linux) {
|
||||
raise(SIGABRT) catch {};
|
||||
raise(SIG.ABRT) catch {};
|
||||
|
||||
// TODO the rest of the implementation of abort() from musl libc here
|
||||
|
||||
raise(SIGKILL) catch {};
|
||||
raise(SIG.KILL) catch {};
|
||||
exit(127);
|
||||
}
|
||||
if (builtin.os.tag == .uefi) {
|
||||
@ -239,15 +363,15 @@ pub fn raise(sig: u8) RaiseError!void {
|
||||
}
|
||||
|
||||
if (builtin.os.tag == .linux) {
|
||||
var set: linux.sigset_t = undefined;
|
||||
var set: sigset_t = undefined;
|
||||
// block application signals
|
||||
_ = linux.sigprocmask(SIG_BLOCK, &linux.app_mask, &set);
|
||||
_ = linux.sigprocmask(SIG.BLOCK, &linux.app_mask, &set);
|
||||
|
||||
const tid = linux.gettid();
|
||||
const rc = linux.tkill(tid, sig);
|
||||
|
||||
// restore signal mask
|
||||
_ = linux.sigprocmask(SIG_SETMASK, &set, null);
|
||||
_ = linux.sigprocmask(SIG.SETMASK, &set, null);
|
||||
|
||||
switch (errno(rc)) {
|
||||
.SUCCESS => return,
|
||||
@ -1040,18 +1164,18 @@ pub const OpenError = error{
|
||||
/// for 64-bit targets, as well as when opening directories.
|
||||
FileTooBig,
|
||||
|
||||
/// The path refers to directory but the `O_DIRECTORY` flag was not provided.
|
||||
/// The path refers to directory but the `O.DIRECTORY` flag was not provided.
|
||||
IsDir,
|
||||
|
||||
/// A new path cannot be created because the device has no room for the new file.
|
||||
/// This error is only reachable when the `O_CREAT` flag is provided.
|
||||
/// This error is only reachable when the `O.CREAT` flag is provided.
|
||||
NoSpaceLeft,
|
||||
|
||||
/// A component used as a directory in the path was not, in fact, a directory, or
|
||||
/// `O_DIRECTORY` was specified and the path was not a directory.
|
||||
/// `O.DIRECTORY` was specified and the path was not a directory.
|
||||
NotDir,
|
||||
|
||||
/// The path already exists and the `O_CREAT` and `O_EXCL` flags were provided.
|
||||
/// The path already exists and the `O.CREAT` and `O.EXCL` flags were provided.
|
||||
PathAlreadyExists,
|
||||
DeviceBusy,
|
||||
|
||||
@ -1123,20 +1247,20 @@ fn openOptionsFromFlags(flags: u32) windows.OpenFileOptions {
|
||||
const w = windows;
|
||||
|
||||
var access_mask: w.ULONG = w.READ_CONTROL | w.FILE_WRITE_ATTRIBUTES | w.SYNCHRONIZE;
|
||||
if (flags & O_RDWR != 0) {
|
||||
if (flags & O.RDWR != 0) {
|
||||
access_mask |= w.GENERIC_READ | w.GENERIC_WRITE;
|
||||
} else if (flags & O_WRONLY != 0) {
|
||||
} else if (flags & O.WRONLY != 0) {
|
||||
access_mask |= w.GENERIC_WRITE;
|
||||
} else {
|
||||
access_mask |= w.GENERIC_READ | w.GENERIC_WRITE;
|
||||
}
|
||||
|
||||
const open_dir: bool = flags & O_DIRECTORY != 0;
|
||||
const follow_symlinks: bool = flags & O_NOFOLLOW == 0;
|
||||
const open_dir: bool = flags & O.DIRECTORY != 0;
|
||||
const follow_symlinks: bool = flags & O.NOFOLLOW == 0;
|
||||
|
||||
const creation: w.ULONG = blk: {
|
||||
if (flags & O_CREAT != 0) {
|
||||
if (flags & O_EXCL != 0) {
|
||||
if (flags & O.CREAT != 0) {
|
||||
if (flags & O.EXCL != 0) {
|
||||
break :blk w.FILE_CREATE;
|
||||
}
|
||||
}
|
||||
@ -1842,7 +1966,7 @@ pub fn unlinkW(file_path_w: []const u16) UnlinkError!void {
|
||||
}
|
||||
|
||||
pub const UnlinkatError = UnlinkError || error{
|
||||
/// When passing `AT_REMOVEDIR`, this error occurs when the named directory is not empty.
|
||||
/// When passing `AT.REMOVEDIR`, this error occurs when the named directory is not empty.
|
||||
DirNotEmpty,
|
||||
};
|
||||
|
||||
@ -1865,7 +1989,7 @@ pub const unlinkatC = @compileError("deprecated: renamed to unlinkatZ");
|
||||
/// WASI-only. Same as `unlinkat` but targeting WASI.
|
||||
/// See also `unlinkat`.
|
||||
pub fn unlinkatWasi(dirfd: fd_t, file_path: []const u8, flags: u32) UnlinkatError!void {
|
||||
const remove_dir = (flags & AT_REMOVEDIR) != 0;
|
||||
const remove_dir = (flags & AT.REMOVEDIR) != 0;
|
||||
const res = if (remove_dir)
|
||||
wasi.path_remove_directory(dirfd, file_path.ptr, file_path.len)
|
||||
else
|
||||
@ -1925,7 +2049,7 @@ pub fn unlinkatZ(dirfd: fd_t, file_path_c: [*:0]const u8, flags: u32) UnlinkatEr
|
||||
|
||||
/// Same as `unlinkat` but `sub_path_w` is UTF16LE, NT prefixed. Windows only.
|
||||
pub fn unlinkatW(dirfd: fd_t, sub_path_w: []const u16, flags: u32) UnlinkatError!void {
|
||||
const remove_dir = (flags & AT_REMOVEDIR) != 0;
|
||||
const remove_dir = (flags & AT.REMOVEDIR) != 0;
|
||||
return windows.DeleteFile(sub_path_w, .{ .dir = dirfd, .remove_dir = remove_dir });
|
||||
}
|
||||
|
||||
@ -2663,8 +2787,8 @@ pub fn isatty(handle: fd_t) bool {
|
||||
}
|
||||
|
||||
// A tty is a character device that we can't seek or tell on.
|
||||
if (statbuf.fs_filetype != FILETYPE_CHARACTER_DEVICE or
|
||||
(statbuf.fs_rights_base & (RIGHT_FD_SEEK | RIGHT_FD_TELL)) != 0)
|
||||
if (statbuf.fs_filetype != .CHARACTER_DEVICE or
|
||||
(statbuf.fs_rights_base & (RIGHT.FD_SEEK | RIGHT.FD_TELL)) != 0)
|
||||
{
|
||||
// errno = ENOTTY;
|
||||
return false;
|
||||
@ -2676,7 +2800,7 @@ pub fn isatty(handle: fd_t) bool {
|
||||
while (true) {
|
||||
var wsz: linux.winsize = undefined;
|
||||
const fd = @bitCast(usize, @as(isize, handle));
|
||||
const rc = linux.syscall3(.ioctl, fd, linux.TIOCGWINSZ, @ptrToInt(&wsz));
|
||||
const rc = linux.syscall3(.ioctl, fd, linux.T.IOCGWINSZ, @ptrToInt(&wsz));
|
||||
switch (linux.getErrno(rc)) {
|
||||
.SUCCESS => return true,
|
||||
.INTR => continue,
|
||||
@ -2739,10 +2863,10 @@ pub const SocketError = error{
|
||||
|
||||
pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!socket_t {
|
||||
if (builtin.os.tag == .windows) {
|
||||
// NOTE: windows translates the SOCK_NONBLOCK/SOCK_CLOEXEC flags into
|
||||
// NOTE: windows translates the SOCK.NONBLOCK/SOCK.CLOEXEC flags into
|
||||
// windows-analagous operations
|
||||
const filtered_sock_type = socket_type & ~@as(u32, SOCK_NONBLOCK | SOCK_CLOEXEC);
|
||||
const flags: u32 = if ((socket_type & SOCK_CLOEXEC) != 0)
|
||||
const filtered_sock_type = socket_type & ~@as(u32, SOCK.NONBLOCK | SOCK.CLOEXEC);
|
||||
const flags: u32 = if ((socket_type & SOCK.CLOEXEC) != 0)
|
||||
windows.ws2_32.WSA_FLAG_NO_HANDLE_INHERIT
|
||||
else
|
||||
0;
|
||||
@ -2755,7 +2879,7 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!socket_t
|
||||
flags,
|
||||
);
|
||||
errdefer windows.closesocket(rc) catch unreachable;
|
||||
if ((socket_type & SOCK_NONBLOCK) != 0) {
|
||||
if ((socket_type & SOCK.NONBLOCK) != 0) {
|
||||
var mode: c_ulong = 1; // nonblocking
|
||||
if (windows.ws2_32.SOCKET_ERROR == windows.ws2_32.ioctlsocket(rc, windows.ws2_32.FIONBIO, &mode)) {
|
||||
switch (windows.ws2_32.WSAGetLastError()) {
|
||||
@ -2769,7 +2893,7 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!socket_t
|
||||
|
||||
const have_sock_flags = comptime !std.Target.current.isDarwin();
|
||||
const filtered_sock_type = if (!have_sock_flags)
|
||||
socket_type & ~@as(u32, SOCK_NONBLOCK | SOCK_CLOEXEC)
|
||||
socket_type & ~@as(u32, SOCK.NONBLOCK | SOCK.CLOEXEC)
|
||||
else
|
||||
socket_type;
|
||||
const rc = system.socket(domain, filtered_sock_type, protocol);
|
||||
@ -2832,9 +2956,9 @@ pub fn shutdown(sock: socket_t, how: ShutdownHow) ShutdownError!void {
|
||||
};
|
||||
} else {
|
||||
const rc = system.shutdown(sock, switch (how) {
|
||||
.recv => SHUT_RD,
|
||||
.send => SHUT_WR,
|
||||
.both => SHUT_RDWR,
|
||||
.recv => SHUT.RD,
|
||||
.send => SHUT.WR,
|
||||
.both => SHUT.RDWR,
|
||||
});
|
||||
switch (errno(rc)) {
|
||||
.SUCCESS => return,
|
||||
@ -3059,15 +3183,15 @@ pub fn accept(
|
||||
/// will return a value greater than was supplied to the call.
|
||||
addr_size: ?*socklen_t,
|
||||
/// The following values can be bitwise ORed in flags to obtain different behavior:
|
||||
/// * `SOCK_NONBLOCK` - Set the `O_NONBLOCK` file status flag on the open file description (see `open`)
|
||||
/// * `SOCK.NONBLOCK` - Set the `O.NONBLOCK` file status flag on the open file description (see `open`)
|
||||
/// referred to by the new file descriptor. Using this flag saves extra calls to `fcntl` to achieve
|
||||
/// the same result.
|
||||
/// * `SOCK_CLOEXEC` - Set the close-on-exec (`FD_CLOEXEC`) flag on the new file descriptor. See the
|
||||
/// description of the `O_CLOEXEC` flag in `open` for reasons why this may be useful.
|
||||
/// * `SOCK.CLOEXEC` - Set the close-on-exec (`FD_CLOEXEC`) flag on the new file descriptor. See the
|
||||
/// description of the `O.CLOEXEC` flag in `open` for reasons why this may be useful.
|
||||
flags: u32,
|
||||
) AcceptError!socket_t {
|
||||
const have_accept4 = comptime !(std.Target.current.isDarwin() or builtin.os.tag == .windows);
|
||||
assert(0 == (flags & ~@as(u32, SOCK_NONBLOCK | SOCK_CLOEXEC))); // Unsupported flag(s)
|
||||
assert(0 == (flags & ~@as(u32, SOCK.NONBLOCK | SOCK.CLOEXEC))); // Unsupported flag(s)
|
||||
|
||||
const accepted_sock = while (true) {
|
||||
const rc = if (have_accept4)
|
||||
@ -3177,7 +3301,7 @@ pub const EpollCtlError = error{
|
||||
FileDescriptorIncompatibleWithEpoll,
|
||||
} || UnexpectedError;
|
||||
|
||||
pub fn epoll_ctl(epfd: i32, op: u32, fd: i32, event: ?*epoll_event) EpollCtlError!void {
|
||||
pub fn epoll_ctl(epfd: i32, op: u32, fd: i32, event: ?*linux.epoll_event) EpollCtlError!void {
|
||||
const rc = system.epoll_ctl(epfd, op, fd, event);
|
||||
switch (errno(rc)) {
|
||||
.SUCCESS => return,
|
||||
@ -3197,7 +3321,7 @@ pub fn epoll_ctl(epfd: i32, op: u32, fd: i32, event: ?*epoll_event) EpollCtlErro
|
||||
/// Waits for an I/O event on an epoll file descriptor.
|
||||
/// Returns the number of file descriptors ready for the requested I/O,
|
||||
/// or zero if no file descriptor became ready during the requested timeout milliseconds.
|
||||
pub fn epoll_wait(epfd: i32, events: []epoll_event, timeout: i32) usize {
|
||||
pub fn epoll_wait(epfd: i32, events: []linux.epoll_event, timeout: i32) usize {
|
||||
while (true) {
|
||||
// TODO get rid of the @intCast
|
||||
const rc = system.epoll_wait(epfd, events.ptr, @intCast(u32, events.len), timeout);
|
||||
@ -3399,7 +3523,7 @@ pub fn connect(sock: socket_t, sock_addr: *const sockaddr, len: socklen_t) Conne
|
||||
.NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
|
||||
.PROTOTYPE => unreachable, // The socket type does not support the requested communications protocol.
|
||||
.TIMEDOUT => return error.ConnectionTimedOut,
|
||||
.NOENT => return error.FileNotFound, // Returned when socket is AF_UNIX and the given path does not exist.
|
||||
.NOENT => return error.FileNotFound, // Returned when socket is AF.UNIX and the given path does not exist.
|
||||
else => |err| return unexpectedErrno(err),
|
||||
}
|
||||
}
|
||||
@ -3408,7 +3532,7 @@ pub fn connect(sock: socket_t, sock_addr: *const sockaddr, len: socklen_t) Conne
|
||||
pub fn getsockoptError(sockfd: fd_t) ConnectError!void {
|
||||
var err_code: i32 = undefined;
|
||||
var size: u32 = @sizeOf(u32);
|
||||
const rc = system.getsockopt(sockfd, SOL_SOCKET, SO_ERROR, @ptrCast([*]u8, &err_code), &size);
|
||||
const rc = system.getsockopt(sockfd, SOL.SOCKET, SO.ERROR, @ptrCast([*]u8, &err_code), &size);
|
||||
assert(size == 4);
|
||||
switch (errno(rc)) {
|
||||
.SUCCESS => switch (@intToEnum(E, err_code)) {
|
||||
@ -3463,11 +3587,6 @@ pub fn waitpid(pid: pid_t, flags: u32) WaitPidResult {
|
||||
}
|
||||
}
|
||||
|
||||
pub const Stat = if (builtin.link_libc)
|
||||
system.libc_stat
|
||||
else
|
||||
system.kernel_stat;
|
||||
|
||||
pub const FStatError = error{
|
||||
SystemResources,
|
||||
|
||||
@ -3745,8 +3864,8 @@ pub const MMapError = error{
|
||||
MemoryMappingNotSupported,
|
||||
|
||||
/// A file descriptor refers to a non-regular file. Or a file mapping was requested,
|
||||
/// but the file descriptor is not open for reading. Or `MAP_SHARED` was requested
|
||||
/// and `PROT_WRITE` is set, but the file descriptor is not open in `O_RDWR` mode.
|
||||
/// but the file descriptor is not open for reading. Or `MAP.SHARED` was requested
|
||||
/// and `PROT_WRITE` is set, but the file descriptor is not open in `O.RDWR` mode.
|
||||
/// Or `PROT_WRITE` is set, but the file is append-only.
|
||||
AccessDenied,
|
||||
|
||||
@ -3778,7 +3897,7 @@ pub fn mmap(
|
||||
const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
|
||||
const rc = mmap_sym(ptr, length, prot, flags, fd, ioffset);
|
||||
const err = if (builtin.link_libc) blk: {
|
||||
if (rc != std.c.MAP_FAILED) return @ptrCast([*]align(mem.page_size) u8, @alignCast(mem.page_size, rc))[0..length];
|
||||
if (rc != std.c.MAP.FAILED) return @ptrCast([*]align(mem.page_size) u8, @alignCast(mem.page_size, rc))[0..length];
|
||||
break :blk @intToEnum(E, system._errno().*);
|
||||
} else blk: {
|
||||
const err = errno(rc);
|
||||
@ -3831,7 +3950,7 @@ pub const AccessError = error{
|
||||
} || UnexpectedError;
|
||||
|
||||
/// check user's permissions for a file
|
||||
/// TODO currently this assumes `mode` is `F_OK` on Windows.
|
||||
/// TODO currently this assumes `mode` is `F.OK` on Windows.
|
||||
pub fn access(path: []const u8, mode: u32) AccessError!void {
|
||||
if (builtin.os.tag == .windows) {
|
||||
const path_w = try windows.sliceToPrefixedFileW(path);
|
||||
@ -4001,11 +4120,11 @@ pub fn pipe2(flags: u32) PipeError![2]fd_t {
|
||||
if (flags == 0)
|
||||
return fds;
|
||||
|
||||
// O_CLOEXEC is special, it's a file descriptor flag and must be set using
|
||||
// F_SETFD.
|
||||
if (flags & O_CLOEXEC != 0) {
|
||||
// O.CLOEXEC is special, it's a file descriptor flag and must be set using
|
||||
// F.SETFD.
|
||||
if (flags & O.CLOEXEC != 0) {
|
||||
for (fds) |fd| {
|
||||
switch (errno(system.fcntl(fd, F_SETFD, @as(u32, FD_CLOEXEC)))) {
|
||||
switch (errno(system.fcntl(fd, F.SETFD, @as(u32, FD_CLOEXEC)))) {
|
||||
.SUCCESS => {},
|
||||
.INVAL => unreachable, // Invalid flags
|
||||
.BADF => unreachable, // Always a race condition
|
||||
@ -4014,11 +4133,11 @@ pub fn pipe2(flags: u32) PipeError![2]fd_t {
|
||||
}
|
||||
}
|
||||
|
||||
const new_flags = flags & ~@as(u32, O_CLOEXEC);
|
||||
// Set every other flag affecting the file status using F_SETFL.
|
||||
const new_flags = flags & ~@as(u32, O.CLOEXEC);
|
||||
// Set every other flag affecting the file status using F.SETFL.
|
||||
if (new_flags != 0) {
|
||||
for (fds) |fd| {
|
||||
switch (errno(system.fcntl(fd, F_SETFL, new_flags))) {
|
||||
switch (errno(system.fcntl(fd, F.SETFL, new_flags))) {
|
||||
.SUCCESS => {},
|
||||
.INVAL => unreachable, // Invalid flags
|
||||
.BADF => unreachable, // Always a race condition
|
||||
@ -4108,7 +4227,7 @@ pub const SeekError = error{
|
||||
pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {
|
||||
if (builtin.os.tag == .linux and !builtin.link_libc and @sizeOf(usize) == 4) {
|
||||
var result: u64 = undefined;
|
||||
switch (errno(system.llseek(fd, offset, &result, SEEK_SET))) {
|
||||
switch (errno(system.llseek(fd, offset, &result, SEEK.SET))) {
|
||||
.SUCCESS => return,
|
||||
.BADF => unreachable, // always a race condition
|
||||
.INVAL => return error.Unseekable,
|
||||
@ -4123,7 +4242,7 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {
|
||||
}
|
||||
if (builtin.os.tag == .wasi and !builtin.link_libc) {
|
||||
var new_offset: wasi.filesize_t = undefined;
|
||||
switch (wasi.fd_seek(fd, @bitCast(wasi.filedelta_t, offset), wasi.WHENCE_SET, &new_offset)) {
|
||||
switch (wasi.fd_seek(fd, @bitCast(wasi.filedelta_t, offset), .SET, &new_offset)) {
|
||||
.SUCCESS => return,
|
||||
.BADF => unreachable, // always a race condition
|
||||
.INVAL => return error.Unseekable,
|
||||
@ -4141,7 +4260,7 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {
|
||||
system.lseek;
|
||||
|
||||
const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
|
||||
switch (errno(lseek_sym(fd, ioffset, SEEK_SET))) {
|
||||
switch (errno(lseek_sym(fd, ioffset, SEEK.SET))) {
|
||||
.SUCCESS => return,
|
||||
.BADF => unreachable, // always a race condition
|
||||
.INVAL => return error.Unseekable,
|
||||
@ -4156,7 +4275,7 @@ pub fn lseek_SET(fd: fd_t, offset: u64) SeekError!void {
|
||||
pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void {
|
||||
if (builtin.os.tag == .linux and !builtin.link_libc and @sizeOf(usize) == 4) {
|
||||
var result: u64 = undefined;
|
||||
switch (errno(system.llseek(fd, @bitCast(u64, offset), &result, SEEK_CUR))) {
|
||||
switch (errno(system.llseek(fd, @bitCast(u64, offset), &result, SEEK.CUR))) {
|
||||
.SUCCESS => return,
|
||||
.BADF => unreachable, // always a race condition
|
||||
.INVAL => return error.Unseekable,
|
||||
@ -4171,7 +4290,7 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void {
|
||||
}
|
||||
if (builtin.os.tag == .wasi and !builtin.link_libc) {
|
||||
var new_offset: wasi.filesize_t = undefined;
|
||||
switch (wasi.fd_seek(fd, offset, wasi.WHENCE_CUR, &new_offset)) {
|
||||
switch (wasi.fd_seek(fd, offset, .CUR, &new_offset)) {
|
||||
.SUCCESS => return,
|
||||
.BADF => unreachable, // always a race condition
|
||||
.INVAL => return error.Unseekable,
|
||||
@ -4188,7 +4307,7 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void {
|
||||
system.lseek;
|
||||
|
||||
const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
|
||||
switch (errno(lseek_sym(fd, ioffset, SEEK_CUR))) {
|
||||
switch (errno(lseek_sym(fd, ioffset, SEEK.CUR))) {
|
||||
.SUCCESS => return,
|
||||
.BADF => unreachable, // always a race condition
|
||||
.INVAL => return error.Unseekable,
|
||||
@ -4203,7 +4322,7 @@ pub fn lseek_CUR(fd: fd_t, offset: i64) SeekError!void {
|
||||
pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void {
|
||||
if (builtin.os.tag == .linux and !builtin.link_libc and @sizeOf(usize) == 4) {
|
||||
var result: u64 = undefined;
|
||||
switch (errno(system.llseek(fd, @bitCast(u64, offset), &result, SEEK_END))) {
|
||||
switch (errno(system.llseek(fd, @bitCast(u64, offset), &result, SEEK.END))) {
|
||||
.SUCCESS => return,
|
||||
.BADF => unreachable, // always a race condition
|
||||
.INVAL => return error.Unseekable,
|
||||
@ -4218,7 +4337,7 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void {
|
||||
}
|
||||
if (builtin.os.tag == .wasi and !builtin.link_libc) {
|
||||
var new_offset: wasi.filesize_t = undefined;
|
||||
switch (wasi.fd_seek(fd, offset, wasi.WHENCE_END, &new_offset)) {
|
||||
switch (wasi.fd_seek(fd, offset, .END, &new_offset)) {
|
||||
.SUCCESS => return,
|
||||
.BADF => unreachable, // always a race condition
|
||||
.INVAL => return error.Unseekable,
|
||||
@ -4235,7 +4354,7 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void {
|
||||
system.lseek;
|
||||
|
||||
const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned
|
||||
switch (errno(lseek_sym(fd, ioffset, SEEK_END))) {
|
||||
switch (errno(lseek_sym(fd, ioffset, SEEK.END))) {
|
||||
.SUCCESS => return,
|
||||
.BADF => unreachable, // always a race condition
|
||||
.INVAL => return error.Unseekable,
|
||||
@ -4250,7 +4369,7 @@ pub fn lseek_END(fd: fd_t, offset: i64) SeekError!void {
|
||||
pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 {
|
||||
if (builtin.os.tag == .linux and !builtin.link_libc and @sizeOf(usize) == 4) {
|
||||
var result: u64 = undefined;
|
||||
switch (errno(system.llseek(fd, 0, &result, SEEK_CUR))) {
|
||||
switch (errno(system.llseek(fd, 0, &result, SEEK.CUR))) {
|
||||
.SUCCESS => return result,
|
||||
.BADF => unreachable, // always a race condition
|
||||
.INVAL => return error.Unseekable,
|
||||
@ -4265,7 +4384,7 @@ pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 {
|
||||
}
|
||||
if (builtin.os.tag == .wasi and !builtin.link_libc) {
|
||||
var new_offset: wasi.filesize_t = undefined;
|
||||
switch (wasi.fd_seek(fd, 0, wasi.WHENCE_CUR, &new_offset)) {
|
||||
switch (wasi.fd_seek(fd, 0, .CUR, &new_offset)) {
|
||||
.SUCCESS => return new_offset,
|
||||
.BADF => unreachable, // always a race condition
|
||||
.INVAL => return error.Unseekable,
|
||||
@ -4281,7 +4400,7 @@ pub fn lseek_CUR_get(fd: fd_t) SeekError!u64 {
|
||||
else
|
||||
system.lseek;
|
||||
|
||||
const rc = lseek_sym(fd, 0, SEEK_CUR);
|
||||
const rc = lseek_sym(fd, 0, SEEK.CUR);
|
||||
switch (errno(rc)) {
|
||||
.SUCCESS => return @bitCast(u64, rc),
|
||||
.BADF => unreachable, // always a race condition
|
||||
@ -4319,18 +4438,18 @@ pub fn fcntl(fd: fd_t, cmd: i32, arg: usize) FcntlError!usize {
|
||||
}
|
||||
|
||||
fn setSockFlags(sock: socket_t, flags: u32) !void {
|
||||
if ((flags & SOCK_CLOEXEC) != 0) {
|
||||
if ((flags & SOCK.CLOEXEC) != 0) {
|
||||
if (builtin.os.tag == .windows) {
|
||||
// TODO: Find out if this is supported for sockets
|
||||
} else {
|
||||
var fd_flags = fcntl(sock, F_GETFD, 0) catch |err| switch (err) {
|
||||
var fd_flags = fcntl(sock, F.GETFD, 0) catch |err| switch (err) {
|
||||
error.FileBusy => unreachable,
|
||||
error.Locked => unreachable,
|
||||
error.PermissionDenied => unreachable,
|
||||
else => |e| return e,
|
||||
};
|
||||
fd_flags |= FD_CLOEXEC;
|
||||
_ = fcntl(sock, F_SETFD, fd_flags) catch |err| switch (err) {
|
||||
_ = fcntl(sock, F.SETFD, fd_flags) catch |err| switch (err) {
|
||||
error.FileBusy => unreachable,
|
||||
error.Locked => unreachable,
|
||||
error.PermissionDenied => unreachable,
|
||||
@ -4338,7 +4457,7 @@ fn setSockFlags(sock: socket_t, flags: u32) !void {
|
||||
};
|
||||
}
|
||||
}
|
||||
if ((flags & SOCK_NONBLOCK) != 0) {
|
||||
if ((flags & SOCK.NONBLOCK) != 0) {
|
||||
if (builtin.os.tag == .windows) {
|
||||
var mode: c_ulong = 1;
|
||||
if (windows.ws2_32.ioctlsocket(sock, windows.ws2_32.FIONBIO, &mode) == windows.ws2_32.SOCKET_ERROR) {
|
||||
@ -4351,14 +4470,14 @@ fn setSockFlags(sock: socket_t, flags: u32) !void {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var fl_flags = fcntl(sock, F_GETFL, 0) catch |err| switch (err) {
|
||||
var fl_flags = fcntl(sock, F.GETFL, 0) catch |err| switch (err) {
|
||||
error.FileBusy => unreachable,
|
||||
error.Locked => unreachable,
|
||||
error.PermissionDenied => unreachable,
|
||||
else => |e| return e,
|
||||
};
|
||||
fl_flags |= O_NONBLOCK;
|
||||
_ = fcntl(sock, F_SETFL, fl_flags) catch |err| switch (err) {
|
||||
fl_flags |= O.NONBLOCK;
|
||||
_ = fcntl(sock, F.SETFL, fl_flags) catch |err| switch (err) {
|
||||
error.FileBusy => unreachable,
|
||||
error.Locked => unreachable,
|
||||
error.PermissionDenied => unreachable,
|
||||
@ -4444,7 +4563,7 @@ pub fn realpathZ(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealP
|
||||
return realpathW(pathname_w.span(), out_buffer);
|
||||
}
|
||||
if (!builtin.link_libc) {
|
||||
const flags = if (builtin.os.tag == .linux) O_PATH | O_NONBLOCK | O_CLOEXEC else O_NONBLOCK | O_CLOEXEC;
|
||||
const flags = if (builtin.os.tag == .linux) O.PATH | O.NONBLOCK | O.CLOEXEC else O.NONBLOCK | O.CLOEXEC;
|
||||
const fd = openZ(pathname, flags, 0) catch |err| switch (err) {
|
||||
error.FileLocksNotSupported => unreachable,
|
||||
error.WouldBlock => unreachable,
|
||||
@ -4523,14 +4642,14 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {
|
||||
return out_buffer[0..end_index];
|
||||
},
|
||||
.macos, .ios, .watchos, .tvos => {
|
||||
// On macOS, we can use F_GETPATH fcntl command to query the OS for
|
||||
// On macOS, we can use F.GETPATH fcntl command to query the OS for
|
||||
// the path to the file descriptor.
|
||||
@memset(out_buffer, 0, MAX_PATH_BYTES);
|
||||
switch (errno(system.fcntl(fd, F_GETPATH, out_buffer))) {
|
||||
switch (errno(system.fcntl(fd, F.GETPATH, out_buffer))) {
|
||||
.SUCCESS => {},
|
||||
.BADF => return error.FileNotFound,
|
||||
// TODO man pages for fcntl on macOS don't really tell you what
|
||||
// errno values to expect when command is F_GETPATH...
|
||||
// errno values to expect when command is F.GETPATH...
|
||||
else => |err| return unexpectedErrno(err),
|
||||
}
|
||||
const len = mem.indexOfScalar(u8, out_buffer[0..], @as(u8, 0)) orelse MAX_PATH_BYTES;
|
||||
@ -4679,7 +4798,7 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {
|
||||
return;
|
||||
}
|
||||
if (std.Target.current.os.tag == .windows) {
|
||||
if (clk_id == CLOCK_REALTIME) {
|
||||
if (clk_id == CLOCK.REALTIME) {
|
||||
var ft: windows.FILETIME = undefined;
|
||||
windows.kernel32.GetSystemTimeAsFileTime(&ft);
|
||||
// FileTime has a granularity of 100 nanoseconds and uses the NTFS/Windows epoch.
|
||||
@ -4691,7 +4810,7 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {
|
||||
};
|
||||
return;
|
||||
} else {
|
||||
// TODO POSIX implementation of CLOCK_MONOTONIC on Windows.
|
||||
// TODO POSIX implementation of CLOCK.MONOTONIC on Windows.
|
||||
return error.UnsupportedClock;
|
||||
}
|
||||
}
|
||||
@ -4929,7 +5048,7 @@ pub fn res_mkquery(
|
||||
|
||||
// Make a reasonably unpredictable id
|
||||
var ts: timespec = undefined;
|
||||
clock_gettime(CLOCK_REALTIME, &ts) catch {};
|
||||
clock_gettime(CLOCK.REALTIME, &ts) catch {};
|
||||
const UInt = std.meta.Int(.unsigned, std.meta.bitCount(@TypeOf(ts.tv_nsec)));
|
||||
const unsec = @bitCast(UInt, ts.tv_nsec);
|
||||
const id = @truncate(u32, unsec + unsec / 65536);
|
||||
@ -4975,7 +5094,7 @@ pub const SendError = error{
|
||||
SystemResources,
|
||||
|
||||
/// The local end has been shut down on a connection oriented socket. In this case, the
|
||||
/// process will also receive a SIGPIPE unless MSG_NOSIGNAL is set.
|
||||
/// process will also receive a SIGPIPE unless MSG.NOSIGNAL is set.
|
||||
BrokenPipe,
|
||||
|
||||
FileDescriptorNotASocket,
|
||||
@ -4991,13 +5110,13 @@ pub const SendMsgError = SendError || error{
|
||||
/// The passed address didn't have the correct address family in its sa_family field.
|
||||
AddressFamilyNotSupported,
|
||||
|
||||
/// Returned when socket is AF_UNIX and the given path has a symlink loop.
|
||||
/// Returned when socket is AF.UNIX and the given path has a symlink loop.
|
||||
SymLinkLoop,
|
||||
|
||||
/// Returned when socket is AF_UNIX and the given path length exceeds `MAX_PATH_BYTES` bytes.
|
||||
/// Returned when socket is AF.UNIX and the given path length exceeds `MAX_PATH_BYTES` bytes.
|
||||
NameTooLong,
|
||||
|
||||
/// Returned when socket is AF_UNIX and the given path does not point to an existing file.
|
||||
/// Returned when socket is AF.UNIX and the given path does not point to an existing file.
|
||||
FileNotFound,
|
||||
NotDir,
|
||||
|
||||
@ -5090,7 +5209,7 @@ pub const SendToError = SendMsgError;
|
||||
///
|
||||
/// sendto(sockfd, buf, len, flags, NULL, 0);
|
||||
///
|
||||
/// If sendto() is used on a connection-mode (`SOCK_STREAM`, `SOCK_SEQPACKET`) socket, the arguments
|
||||
/// If sendto() is used on a connection-mode (`SOCK.STREAM`, `SOCK.SEQPACKET`) socket, the arguments
|
||||
/// `dest_addr` and `addrlen` are asserted to be `null` and `0` respectively, and asserted
|
||||
/// that the socket was actually connected.
|
||||
/// Otherwise, the address of the target is given by `dest_addr` with `addrlen` specifying its size.
|
||||
@ -5330,7 +5449,7 @@ pub fn sendfile(
|
||||
// * Descriptor is not valid or locked
|
||||
// * an mmap(2)-like operation is not available for in_fd
|
||||
// * count is negative
|
||||
// * out_fd has the O_APPEND flag set
|
||||
// * out_fd has the O.APPEND flag set
|
||||
// Because of the "mmap(2)-like operation" possibility, we fall back to doing read/write
|
||||
// manually, the same as ENOSYS.
|
||||
break :sf;
|
||||
@ -5396,7 +5515,7 @@ pub fn sendfile(
|
||||
.INVAL, .OPNOTSUPP, .NOTSOCK, .NOSYS => {
|
||||
// EINVAL could be any of the following situations:
|
||||
// * The fd argument is not a regular file.
|
||||
// * The s argument is not a SOCK_STREAM type socket.
|
||||
// * The s argument is not a SOCK.STREAM type socket.
|
||||
// * The offset argument is negative.
|
||||
// Because of some of these possibilities, we fall back to doing read/write
|
||||
// manually, the same as ENOSYS.
|
||||
@ -5538,7 +5657,7 @@ pub const CopyFileRangeError = error{
|
||||
FileTooBig,
|
||||
InputOutput,
|
||||
/// `fd_in` is not open for reading; or `fd_out` is not open for writing;
|
||||
/// or the `O_APPEND` flag is set for `fd_out`.
|
||||
/// or the `O.APPEND` flag is set for `fd_out`.
|
||||
FilesOpenedWithWrongFlags,
|
||||
IsDir,
|
||||
OutOfMemory,
|
||||
@ -6154,27 +6273,27 @@ pub fn setrlimit(resource: rlimit_resource, limits: rlimit) SetrlimitError!void
|
||||
}
|
||||
|
||||
pub const MadviseError = error{
|
||||
/// advice is MADV_REMOVE, but the specified address range is not a shared writable mapping.
|
||||
/// advice is MADV.REMOVE, but the specified address range is not a shared writable mapping.
|
||||
AccessDenied,
|
||||
/// advice is MADV_HWPOISON, but the caller does not have the CAP_SYS_ADMIN capability.
|
||||
/// advice is MADV.HWPOISON, but the caller does not have the CAP_SYS_ADMIN capability.
|
||||
PermissionDenied,
|
||||
/// A kernel resource was temporarily unavailable.
|
||||
SystemResources,
|
||||
/// One of the following:
|
||||
/// * addr is not page-aligned or length is negative
|
||||
/// * advice is not valid
|
||||
/// * advice is MADV_DONTNEED or MADV_REMOVE and the specified address range
|
||||
/// * advice is MADV.DONTNEED or MADV.REMOVE and the specified address range
|
||||
/// includes locked, Huge TLB pages, or VM_PFNMAP pages.
|
||||
/// * advice is MADV_MERGEABLE or MADV_UNMERGEABLE, but the kernel was not
|
||||
/// * advice is MADV.MERGEABLE or MADV.UNMERGEABLE, but the kernel was not
|
||||
/// configured with CONFIG_KSM.
|
||||
/// * advice is MADV_FREE or MADV_WIPEONFORK but the specified address range
|
||||
/// includes file, Huge TLB, MAP_SHARED, or VM_PFNMAP ranges.
|
||||
/// * advice is MADV.FREE or MADV.WIPEONFORK but the specified address range
|
||||
/// includes file, Huge TLB, MAP.SHARED, or VM_PFNMAP ranges.
|
||||
InvalidSyscall,
|
||||
/// (for MADV_WILLNEED) Paging in this area would exceed the process's
|
||||
/// (for MADV.WILLNEED) Paging in this area would exceed the process's
|
||||
/// maximum resident set size.
|
||||
WouldExceedMaximumResidentSetSize,
|
||||
/// One of the following:
|
||||
/// * (for MADV_WILLNEED) Not enough memory: paging in failed.
|
||||
/// * (for MADV.WILLNEED) Not enough memory: paging in failed.
|
||||
/// * Addresses in the specified range are not currently mapped, or
|
||||
/// are outside the address space of the process.
|
||||
OutOfMemory,
|
||||
|
||||
@ -1,22 +0,0 @@
|
||||
//! Platform-dependent types and values that are used along with OS-specific APIs.
|
||||
//! These are imported into `std.c`, `std.os`, and `std.os.linux`.
|
||||
//! Root source files can define `os.bits` and these will additionally be added
|
||||
//! to the namespace.
|
||||
|
||||
const std = @import("std");
|
||||
const root = @import("root");
|
||||
|
||||
pub usingnamespace switch (std.Target.current.os.tag) {
|
||||
.macos, .ios, .tvos, .watchos => @import("bits/darwin.zig"),
|
||||
.dragonfly => @import("bits/dragonfly.zig"),
|
||||
.freebsd => @import("bits/freebsd.zig"),
|
||||
.haiku => @import("bits/haiku.zig"),
|
||||
.linux => @import("bits/linux.zig"),
|
||||
.netbsd => @import("bits/netbsd.zig"),
|
||||
.openbsd => @import("bits/openbsd.zig"),
|
||||
.wasi => @import("bits/wasi.zig"),
|
||||
.windows => @import("bits/windows.zig"),
|
||||
else => struct {},
|
||||
};
|
||||
|
||||
pub usingnamespace if (@hasDecl(root, "os") and @hasDecl(root.os, "bits")) root.os.bits else struct {};
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,636 +0,0 @@
|
||||
// arm-eabi-specific declarations that are intended to be imported into the POSIX namespace.
|
||||
const std = @import("../../../std.zig");
|
||||
const linux = std.os.linux;
|
||||
const socklen_t = linux.socklen_t;
|
||||
const iovec = linux.iovec;
|
||||
const iovec_const = linux.iovec_const;
|
||||
const stack_t = linux.stack_t;
|
||||
const sigset_t = linux.sigset_t;
|
||||
const uid_t = linux.uid_t;
|
||||
const gid_t = linux.gid_t;
|
||||
const pid_t = linux.pid_t;
|
||||
|
||||
pub const SYS = enum(usize) {
|
||||
restart_syscall = 0,
|
||||
exit = 1,
|
||||
fork = 2,
|
||||
read = 3,
|
||||
write = 4,
|
||||
open = 5,
|
||||
close = 6,
|
||||
creat = 8,
|
||||
link = 9,
|
||||
unlink = 10,
|
||||
execve = 11,
|
||||
chdir = 12,
|
||||
mknod = 14,
|
||||
chmod = 15,
|
||||
lchown = 16,
|
||||
lseek = 19,
|
||||
getpid = 20,
|
||||
mount = 21,
|
||||
setuid = 23,
|
||||
getuid = 24,
|
||||
ptrace = 26,
|
||||
pause = 29,
|
||||
access = 33,
|
||||
nice = 34,
|
||||
sync = 36,
|
||||
kill = 37,
|
||||
rename = 38,
|
||||
mkdir = 39,
|
||||
rmdir = 40,
|
||||
dup = 41,
|
||||
pipe = 42,
|
||||
times = 43,
|
||||
brk = 45,
|
||||
setgid = 46,
|
||||
getgid = 47,
|
||||
geteuid = 49,
|
||||
getegid = 50,
|
||||
acct = 51,
|
||||
umount2 = 52,
|
||||
ioctl = 54,
|
||||
fcntl = 55,
|
||||
setpgid = 57,
|
||||
umask = 60,
|
||||
chroot = 61,
|
||||
ustat = 62,
|
||||
dup2 = 63,
|
||||
getppid = 64,
|
||||
getpgrp = 65,
|
||||
setsid = 66,
|
||||
sigaction = 67,
|
||||
setreuid = 70,
|
||||
setregid = 71,
|
||||
sigsuspend = 72,
|
||||
sigpending = 73,
|
||||
sethostname = 74,
|
||||
setrlimit = 75,
|
||||
getrusage = 77,
|
||||
gettimeofday = 78,
|
||||
settimeofday = 79,
|
||||
getgroups = 80,
|
||||
setgroups = 81,
|
||||
symlink = 83,
|
||||
readlink = 85,
|
||||
uselib = 86,
|
||||
swapon = 87,
|
||||
reboot = 88,
|
||||
munmap = 91,
|
||||
truncate = 92,
|
||||
ftruncate = 93,
|
||||
fchmod = 94,
|
||||
fchown = 95,
|
||||
getpriority = 96,
|
||||
setpriority = 97,
|
||||
statfs = 99,
|
||||
fstatfs = 100,
|
||||
syslog = 103,
|
||||
setitimer = 104,
|
||||
getitimer = 105,
|
||||
stat = 106,
|
||||
lstat = 107,
|
||||
fstat = 108,
|
||||
vhangup = 111,
|
||||
wait4 = 114,
|
||||
swapoff = 115,
|
||||
sysinfo = 116,
|
||||
fsync = 118,
|
||||
sigreturn = 119,
|
||||
clone = 120,
|
||||
setdomainname = 121,
|
||||
uname = 122,
|
||||
adjtimex = 124,
|
||||
mprotect = 125,
|
||||
sigprocmask = 126,
|
||||
init_module = 128,
|
||||
delete_module = 129,
|
||||
quotactl = 131,
|
||||
getpgid = 132,
|
||||
fchdir = 133,
|
||||
bdflush = 134,
|
||||
sysfs = 135,
|
||||
personality = 136,
|
||||
setfsuid = 138,
|
||||
setfsgid = 139,
|
||||
_llseek = 140,
|
||||
getdents = 141,
|
||||
_newselect = 142,
|
||||
flock = 143,
|
||||
msync = 144,
|
||||
readv = 145,
|
||||
writev = 146,
|
||||
getsid = 147,
|
||||
fdatasync = 148,
|
||||
_sysctl = 149,
|
||||
mlock = 150,
|
||||
munlock = 151,
|
||||
mlockall = 152,
|
||||
munlockall = 153,
|
||||
sched_setparam = 154,
|
||||
sched_getparam = 155,
|
||||
sched_setscheduler = 156,
|
||||
sched_getscheduler = 157,
|
||||
sched_yield = 158,
|
||||
sched_get_priority_max = 159,
|
||||
sched_get_priority_min = 160,
|
||||
sched_rr_get_interval = 161,
|
||||
nanosleep = 162,
|
||||
mremap = 163,
|
||||
setresuid = 164,
|
||||
getresuid = 165,
|
||||
poll = 168,
|
||||
nfsservctl = 169,
|
||||
setresgid = 170,
|
||||
getresgid = 171,
|
||||
prctl = 172,
|
||||
rt_sigreturn = 173,
|
||||
rt_sigaction = 174,
|
||||
rt_sigprocmask = 175,
|
||||
rt_sigpending = 176,
|
||||
rt_sigtimedwait = 177,
|
||||
rt_sigqueueinfo = 178,
|
||||
rt_sigsuspend = 179,
|
||||
pread64 = 180,
|
||||
pwrite64 = 181,
|
||||
chown = 182,
|
||||
getcwd = 183,
|
||||
capget = 184,
|
||||
capset = 185,
|
||||
sigaltstack = 186,
|
||||
sendfile = 187,
|
||||
vfork = 190,
|
||||
ugetrlimit = 191,
|
||||
mmap2 = 192,
|
||||
truncate64 = 193,
|
||||
ftruncate64 = 194,
|
||||
stat64 = 195,
|
||||
lstat64 = 196,
|
||||
fstat64 = 197,
|
||||
lchown32 = 198,
|
||||
getuid32 = 199,
|
||||
getgid32 = 200,
|
||||
geteuid32 = 201,
|
||||
getegid32 = 202,
|
||||
setreuid32 = 203,
|
||||
setregid32 = 204,
|
||||
getgroups32 = 205,
|
||||
setgroups32 = 206,
|
||||
fchown32 = 207,
|
||||
setresuid32 = 208,
|
||||
getresuid32 = 209,
|
||||
setresgid32 = 210,
|
||||
getresgid32 = 211,
|
||||
chown32 = 212,
|
||||
setuid32 = 213,
|
||||
setgid32 = 214,
|
||||
setfsuid32 = 215,
|
||||
setfsgid32 = 216,
|
||||
getdents64 = 217,
|
||||
pivot_root = 218,
|
||||
mincore = 219,
|
||||
madvise = 220,
|
||||
fcntl64 = 221,
|
||||
gettid = 224,
|
||||
readahead = 225,
|
||||
setxattr = 226,
|
||||
lsetxattr = 227,
|
||||
fsetxattr = 228,
|
||||
getxattr = 229,
|
||||
lgetxattr = 230,
|
||||
fgetxattr = 231,
|
||||
listxattr = 232,
|
||||
llistxattr = 233,
|
||||
flistxattr = 234,
|
||||
removexattr = 235,
|
||||
lremovexattr = 236,
|
||||
fremovexattr = 237,
|
||||
tkill = 238,
|
||||
sendfile64 = 239,
|
||||
futex = 240,
|
||||
sched_setaffinity = 241,
|
||||
sched_getaffinity = 242,
|
||||
io_setup = 243,
|
||||
io_destroy = 244,
|
||||
io_getevents = 245,
|
||||
io_submit = 246,
|
||||
io_cancel = 247,
|
||||
exit_group = 248,
|
||||
lookup_dcookie = 249,
|
||||
epoll_create = 250,
|
||||
epoll_ctl = 251,
|
||||
epoll_wait = 252,
|
||||
remap_file_pages = 253,
|
||||
set_tid_address = 256,
|
||||
timer_create = 257,
|
||||
timer_settime = 258,
|
||||
timer_gettime = 259,
|
||||
timer_getoverrun = 260,
|
||||
timer_delete = 261,
|
||||
clock_settime = 262,
|
||||
clock_gettime = 263,
|
||||
clock_getres = 264,
|
||||
clock_nanosleep = 265,
|
||||
statfs64 = 266,
|
||||
fstatfs64 = 267,
|
||||
tgkill = 268,
|
||||
utimes = 269,
|
||||
fadvise64_64 = 270,
|
||||
pciconfig_iobase = 271,
|
||||
pciconfig_read = 272,
|
||||
pciconfig_write = 273,
|
||||
mq_open = 274,
|
||||
mq_unlink = 275,
|
||||
mq_timedsend = 276,
|
||||
mq_timedreceive = 277,
|
||||
mq_notify = 278,
|
||||
mq_getsetattr = 279,
|
||||
waitid = 280,
|
||||
socket = 281,
|
||||
bind = 282,
|
||||
connect = 283,
|
||||
listen = 284,
|
||||
accept = 285,
|
||||
getsockname = 286,
|
||||
getpeername = 287,
|
||||
socketpair = 288,
|
||||
send = 289,
|
||||
sendto = 290,
|
||||
recv = 291,
|
||||
recvfrom = 292,
|
||||
shutdown = 293,
|
||||
setsockopt = 294,
|
||||
getsockopt = 295,
|
||||
sendmsg = 296,
|
||||
recvmsg = 297,
|
||||
semop = 298,
|
||||
semget = 299,
|
||||
semctl = 300,
|
||||
msgsnd = 301,
|
||||
msgrcv = 302,
|
||||
msgget = 303,
|
||||
msgctl = 304,
|
||||
shmat = 305,
|
||||
shmdt = 306,
|
||||
shmget = 307,
|
||||
shmctl = 308,
|
||||
add_key = 309,
|
||||
request_key = 310,
|
||||
keyctl = 311,
|
||||
semtimedop = 312,
|
||||
vserver = 313,
|
||||
ioprio_set = 314,
|
||||
ioprio_get = 315,
|
||||
inotify_init = 316,
|
||||
inotify_add_watch = 317,
|
||||
inotify_rm_watch = 318,
|
||||
mbind = 319,
|
||||
get_mempolicy = 320,
|
||||
set_mempolicy = 321,
|
||||
openat = 322,
|
||||
mkdirat = 323,
|
||||
mknodat = 324,
|
||||
fchownat = 325,
|
||||
futimesat = 326,
|
||||
fstatat64 = 327,
|
||||
unlinkat = 328,
|
||||
renameat = 329,
|
||||
linkat = 330,
|
||||
symlinkat = 331,
|
||||
readlinkat = 332,
|
||||
fchmodat = 333,
|
||||
faccessat = 334,
|
||||
pselect6 = 335,
|
||||
ppoll = 336,
|
||||
unshare = 337,
|
||||
set_robust_list = 338,
|
||||
get_robust_list = 339,
|
||||
splice = 340,
|
||||
sync_file_range = 341,
|
||||
tee = 342,
|
||||
vmsplice = 343,
|
||||
move_pages = 344,
|
||||
getcpu = 345,
|
||||
epoll_pwait = 346,
|
||||
kexec_load = 347,
|
||||
utimensat = 348,
|
||||
signalfd = 349,
|
||||
timerfd_create = 350,
|
||||
eventfd = 351,
|
||||
fallocate = 352,
|
||||
timerfd_settime = 353,
|
||||
timerfd_gettime = 354,
|
||||
signalfd4 = 355,
|
||||
eventfd2 = 356,
|
||||
epoll_create1 = 357,
|
||||
dup3 = 358,
|
||||
pipe2 = 359,
|
||||
inotify_init1 = 360,
|
||||
preadv = 361,
|
||||
pwritev = 362,
|
||||
rt_tgsigqueueinfo = 363,
|
||||
perf_event_open = 364,
|
||||
recvmmsg = 365,
|
||||
accept4 = 366,
|
||||
fanotify_init = 367,
|
||||
fanotify_mark = 368,
|
||||
prlimit64 = 369,
|
||||
name_to_handle_at = 370,
|
||||
open_by_handle_at = 371,
|
||||
clock_adjtime = 372,
|
||||
syncfs = 373,
|
||||
sendmmsg = 374,
|
||||
setns = 375,
|
||||
process_vm_readv = 376,
|
||||
process_vm_writev = 377,
|
||||
kcmp = 378,
|
||||
finit_module = 379,
|
||||
sched_setattr = 380,
|
||||
sched_getattr = 381,
|
||||
renameat2 = 382,
|
||||
seccomp = 383,
|
||||
getrandom = 384,
|
||||
memfd_create = 385,
|
||||
bpf = 386,
|
||||
execveat = 387,
|
||||
userfaultfd = 388,
|
||||
membarrier = 389,
|
||||
mlock2 = 390,
|
||||
copy_file_range = 391,
|
||||
preadv2 = 392,
|
||||
pwritev2 = 393,
|
||||
pkey_mprotect = 394,
|
||||
pkey_alloc = 395,
|
||||
pkey_free = 396,
|
||||
statx = 397,
|
||||
rseq = 398,
|
||||
io_pgetevents = 399,
|
||||
migrate_pages = 400,
|
||||
kexec_file_load = 401,
|
||||
clock_gettime64 = 403,
|
||||
clock_settime64 = 404,
|
||||
clock_adjtime64 = 405,
|
||||
clock_getres_time64 = 406,
|
||||
clock_nanosleep_time64 = 407,
|
||||
timer_gettime64 = 408,
|
||||
timer_settime64 = 409,
|
||||
timerfd_gettime64 = 410,
|
||||
timerfd_settime64 = 411,
|
||||
utimensat_time64 = 412,
|
||||
pselect6_time64 = 413,
|
||||
ppoll_time64 = 414,
|
||||
io_pgetevents_time64 = 416,
|
||||
recvmmsg_time64 = 417,
|
||||
mq_timedsend_time64 = 418,
|
||||
mq_timedreceive_time64 = 419,
|
||||
semtimedop_time64 = 420,
|
||||
rt_sigtimedwait_time64 = 421,
|
||||
futex_time64 = 422,
|
||||
sched_rr_get_interval_time64 = 423,
|
||||
pidfd_send_signal = 424,
|
||||
io_uring_setup = 425,
|
||||
io_uring_enter = 426,
|
||||
io_uring_register = 427,
|
||||
open_tree = 428,
|
||||
move_mount = 429,
|
||||
fsopen = 430,
|
||||
fsconfig = 431,
|
||||
fsmount = 432,
|
||||
fspick = 433,
|
||||
pidfd_open = 434,
|
||||
clone3 = 435,
|
||||
close_range = 436,
|
||||
openat2 = 437,
|
||||
pidfd_getfd = 438,
|
||||
faccessat2 = 439,
|
||||
process_madvise = 440,
|
||||
epoll_pwait2 = 441,
|
||||
|
||||
breakpoint = 0x0f0001,
|
||||
cacheflush = 0x0f0002,
|
||||
usr26 = 0x0f0003,
|
||||
usr32 = 0x0f0004,
|
||||
set_tls = 0x0f0005,
|
||||
get_tls = 0x0f0006,
|
||||
|
||||
_,
|
||||
};
|
||||
|
||||
pub const MMAP2_UNIT = 4096;
|
||||
|
||||
pub const O_CREAT = 0o100;
|
||||
pub const O_EXCL = 0o200;
|
||||
pub const O_NOCTTY = 0o400;
|
||||
pub const O_TRUNC = 0o1000;
|
||||
pub const O_APPEND = 0o2000;
|
||||
pub const O_NONBLOCK = 0o4000;
|
||||
pub const O_DSYNC = 0o10000;
|
||||
pub const O_SYNC = 0o4010000;
|
||||
pub const O_RSYNC = 0o4010000;
|
||||
pub const O_DIRECTORY = 0o40000;
|
||||
pub const O_NOFOLLOW = 0o100000;
|
||||
pub const O_CLOEXEC = 0o2000000;
|
||||
|
||||
pub const O_ASYNC = 0o20000;
|
||||
pub const O_DIRECT = 0o200000;
|
||||
pub const O_LARGEFILE = 0o400000;
|
||||
pub const O_NOATIME = 0o1000000;
|
||||
pub const O_PATH = 0o10000000;
|
||||
pub const O_TMPFILE = 0o20040000;
|
||||
pub const O_NDELAY = O_NONBLOCK;
|
||||
|
||||
pub const F_DUPFD = 0;
|
||||
pub const F_GETFD = 1;
|
||||
pub const F_SETFD = 2;
|
||||
pub const F_GETFL = 3;
|
||||
pub const F_SETFL = 4;
|
||||
|
||||
pub const F_SETOWN = 8;
|
||||
pub const F_GETOWN = 9;
|
||||
pub const F_SETSIG = 10;
|
||||
pub const F_GETSIG = 11;
|
||||
|
||||
pub const F_GETLK = 12;
|
||||
pub const F_SETLK = 13;
|
||||
pub const F_SETLKW = 14;
|
||||
|
||||
pub const F_RDLCK = 0;
|
||||
pub const F_WRLCK = 1;
|
||||
pub const F_UNLCK = 2;
|
||||
|
||||
pub const F_SETOWN_EX = 15;
|
||||
pub const F_GETOWN_EX = 16;
|
||||
|
||||
pub const F_GETOWNER_UIDS = 17;
|
||||
|
||||
pub const LOCK_SH = 1;
|
||||
pub const LOCK_EX = 2;
|
||||
pub const LOCK_UN = 8;
|
||||
pub const LOCK_NB = 4;
|
||||
|
||||
/// stack-like segment
|
||||
pub const MAP_GROWSDOWN = 0x0100;
|
||||
|
||||
/// ETXTBSY
|
||||
pub const MAP_DENYWRITE = 0x0800;
|
||||
|
||||
/// mark it as an executable
|
||||
pub const MAP_EXECUTABLE = 0x1000;
|
||||
|
||||
/// pages are locked
|
||||
pub const MAP_LOCKED = 0x2000;
|
||||
|
||||
/// don't check for reservations
|
||||
pub const MAP_NORESERVE = 0x4000;
|
||||
|
||||
pub const VDSO_CGT_SYM = "__vdso_clock_gettime";
|
||||
pub const VDSO_CGT_VER = "LINUX_2.6";
|
||||
|
||||
pub const HWCAP_SWP = 1 << 0;
|
||||
pub const HWCAP_HALF = 1 << 1;
|
||||
pub const HWCAP_THUMB = 1 << 2;
|
||||
pub const HWCAP_26BIT = 1 << 3;
|
||||
pub const HWCAP_FAST_MULT = 1 << 4;
|
||||
pub const HWCAP_FPA = 1 << 5;
|
||||
pub const HWCAP_VFP = 1 << 6;
|
||||
pub const HWCAP_EDSP = 1 << 7;
|
||||
pub const HWCAP_JAVA = 1 << 8;
|
||||
pub const HWCAP_IWMMXT = 1 << 9;
|
||||
pub const HWCAP_CRUNCH = 1 << 10;
|
||||
pub const HWCAP_THUMBEE = 1 << 11;
|
||||
pub const HWCAP_NEON = 1 << 12;
|
||||
pub const HWCAP_VFPv3 = 1 << 13;
|
||||
pub const HWCAP_VFPv3D16 = 1 << 14;
|
||||
pub const HWCAP_TLS = 1 << 15;
|
||||
pub const HWCAP_VFPv4 = 1 << 16;
|
||||
pub const HWCAP_IDIVA = 1 << 17;
|
||||
pub const HWCAP_IDIVT = 1 << 18;
|
||||
pub const HWCAP_VFPD32 = 1 << 19;
|
||||
pub const HWCAP_IDIV = HWCAP_IDIVA | HWCAP_IDIVT;
|
||||
pub const HWCAP_LPAE = 1 << 20;
|
||||
pub const HWCAP_EVTSTRM = 1 << 21;
|
||||
|
||||
pub const Flock = extern struct {
|
||||
l_type: i16,
|
||||
l_whence: i16,
|
||||
__pad0: [4]u8,
|
||||
l_start: off_t,
|
||||
l_len: off_t,
|
||||
l_pid: pid_t,
|
||||
__unused: [4]u8,
|
||||
};
|
||||
|
||||
pub const msghdr = extern struct {
|
||||
msg_name: ?*sockaddr,
|
||||
msg_namelen: socklen_t,
|
||||
msg_iov: [*]iovec,
|
||||
msg_iovlen: i32,
|
||||
msg_control: ?*c_void,
|
||||
msg_controllen: socklen_t,
|
||||
msg_flags: i32,
|
||||
};
|
||||
|
||||
pub const msghdr_const = extern struct {
|
||||
msg_name: ?*const sockaddr,
|
||||
msg_namelen: socklen_t,
|
||||
msg_iov: [*]iovec_const,
|
||||
msg_iovlen: i32,
|
||||
msg_control: ?*c_void,
|
||||
msg_controllen: socklen_t,
|
||||
msg_flags: i32,
|
||||
};
|
||||
|
||||
pub const blksize_t = i32;
|
||||
pub const nlink_t = u32;
|
||||
pub const time_t = isize;
|
||||
pub const mode_t = u32;
|
||||
pub const off_t = i64;
|
||||
pub const ino_t = u64;
|
||||
pub const dev_t = u64;
|
||||
pub const blkcnt_t = i64;
|
||||
|
||||
// The `stat` definition used by the Linux kernel.
|
||||
pub const kernel_stat = extern struct {
|
||||
dev: dev_t,
|
||||
__dev_padding: u32,
|
||||
__ino_truncated: u32,
|
||||
mode: mode_t,
|
||||
nlink: nlink_t,
|
||||
uid: uid_t,
|
||||
gid: gid_t,
|
||||
rdev: dev_t,
|
||||
__rdev_padding: u32,
|
||||
size: off_t,
|
||||
blksize: blksize_t,
|
||||
blocks: blkcnt_t,
|
||||
atim: timespec,
|
||||
mtim: timespec,
|
||||
ctim: timespec,
|
||||
ino: ino_t,
|
||||
|
||||
pub fn atime(self: @This()) timespec {
|
||||
return self.atim;
|
||||
}
|
||||
|
||||
pub fn mtime(self: @This()) timespec {
|
||||
return self.mtim;
|
||||
}
|
||||
|
||||
pub fn ctime(self: @This()) timespec {
|
||||
return self.ctim;
|
||||
}
|
||||
};
|
||||
|
||||
// The `stat64` definition used by the libc.
|
||||
pub const libc_stat = kernel_stat;
|
||||
|
||||
pub const timespec = extern struct {
|
||||
tv_sec: i32,
|
||||
tv_nsec: i32,
|
||||
};
|
||||
|
||||
pub const timeval = extern struct {
|
||||
tv_sec: i32,
|
||||
tv_usec: i32,
|
||||
};
|
||||
|
||||
pub const timezone = extern struct {
|
||||
tz_minuteswest: i32,
|
||||
tz_dsttime: i32,
|
||||
};
|
||||
|
||||
pub const mcontext_t = extern struct {
|
||||
trap_no: usize,
|
||||
error_code: usize,
|
||||
oldmask: usize,
|
||||
arm_r0: usize,
|
||||
arm_r1: usize,
|
||||
arm_r2: usize,
|
||||
arm_r3: usize,
|
||||
arm_r4: usize,
|
||||
arm_r5: usize,
|
||||
arm_r6: usize,
|
||||
arm_r7: usize,
|
||||
arm_r8: usize,
|
||||
arm_r9: usize,
|
||||
arm_r10: usize,
|
||||
arm_fp: usize,
|
||||
arm_ip: usize,
|
||||
arm_sp: usize,
|
||||
arm_lr: usize,
|
||||
arm_pc: usize,
|
||||
arm_cpsr: usize,
|
||||
fault_address: usize,
|
||||
};
|
||||
|
||||
pub const ucontext_t = extern struct {
|
||||
flags: usize,
|
||||
link: *ucontext_t,
|
||||
stack: stack_t,
|
||||
mcontext: mcontext_t,
|
||||
sigmask: sigset_t,
|
||||
regspace: [64]u64,
|
||||
};
|
||||
|
||||
pub const Elf_Symndx = u32;
|
||||
@ -1,495 +0,0 @@
|
||||
// arm64-specific declarations that are intended to be imported into the POSIX namespace.
|
||||
// This does include Linux-only APIs.
|
||||
|
||||
const std = @import("../../../std.zig");
|
||||
const linux = std.os.linux;
|
||||
const socklen_t = linux.socklen_t;
|
||||
const sockaddr = linux.sockaddr;
|
||||
const iovec = linux.iovec;
|
||||
const iovec_const = linux.iovec_const;
|
||||
const uid_t = linux.uid_t;
|
||||
const gid_t = linux.gid_t;
|
||||
const pid_t = linux.pid_t;
|
||||
const stack_t = linux.stack_t;
|
||||
const sigset_t = linux.sigset_t;
|
||||
pub const SYS = enum(usize) {
|
||||
io_setup = 0,
|
||||
io_destroy = 1,
|
||||
io_submit = 2,
|
||||
io_cancel = 3,
|
||||
io_getevents = 4,
|
||||
setxattr = 5,
|
||||
lsetxattr = 6,
|
||||
fsetxattr = 7,
|
||||
getxattr = 8,
|
||||
lgetxattr = 9,
|
||||
fgetxattr = 10,
|
||||
listxattr = 11,
|
||||
llistxattr = 12,
|
||||
flistxattr = 13,
|
||||
removexattr = 14,
|
||||
lremovexattr = 15,
|
||||
fremovexattr = 16,
|
||||
getcwd = 17,
|
||||
lookup_dcookie = 18,
|
||||
eventfd2 = 19,
|
||||
epoll_create1 = 20,
|
||||
epoll_ctl = 21,
|
||||
epoll_pwait = 22,
|
||||
dup = 23,
|
||||
dup3 = 24,
|
||||
fcntl = 25,
|
||||
inotify_init1 = 26,
|
||||
inotify_add_watch = 27,
|
||||
inotify_rm_watch = 28,
|
||||
ioctl = 29,
|
||||
ioprio_set = 30,
|
||||
ioprio_get = 31,
|
||||
flock = 32,
|
||||
mknodat = 33,
|
||||
mkdirat = 34,
|
||||
unlinkat = 35,
|
||||
symlinkat = 36,
|
||||
linkat = 37,
|
||||
renameat = 38,
|
||||
umount2 = 39,
|
||||
mount = 40,
|
||||
pivot_root = 41,
|
||||
nfsservctl = 42,
|
||||
statfs = 43,
|
||||
fstatfs = 44,
|
||||
truncate = 45,
|
||||
ftruncate = 46,
|
||||
fallocate = 47,
|
||||
faccessat = 48,
|
||||
chdir = 49,
|
||||
fchdir = 50,
|
||||
chroot = 51,
|
||||
fchmod = 52,
|
||||
fchmodat = 53,
|
||||
fchownat = 54,
|
||||
fchown = 55,
|
||||
openat = 56,
|
||||
close = 57,
|
||||
vhangup = 58,
|
||||
pipe2 = 59,
|
||||
quotactl = 60,
|
||||
getdents64 = 61,
|
||||
lseek = 62,
|
||||
read = 63,
|
||||
write = 64,
|
||||
readv = 65,
|
||||
writev = 66,
|
||||
pread64 = 67,
|
||||
pwrite64 = 68,
|
||||
preadv = 69,
|
||||
pwritev = 70,
|
||||
sendfile = 71,
|
||||
pselect6 = 72,
|
||||
ppoll = 73,
|
||||
signalfd4 = 74,
|
||||
vmsplice = 75,
|
||||
splice = 76,
|
||||
tee = 77,
|
||||
readlinkat = 78,
|
||||
fstatat = 79,
|
||||
fstat = 80,
|
||||
sync = 81,
|
||||
fsync = 82,
|
||||
fdatasync = 83,
|
||||
sync_file_range = 84,
|
||||
timerfd_create = 85,
|
||||
timerfd_settime = 86,
|
||||
timerfd_gettime = 87,
|
||||
utimensat = 88,
|
||||
acct = 89,
|
||||
capget = 90,
|
||||
capset = 91,
|
||||
personality = 92,
|
||||
exit = 93,
|
||||
exit_group = 94,
|
||||
waitid = 95,
|
||||
set_tid_address = 96,
|
||||
unshare = 97,
|
||||
futex = 98,
|
||||
set_robust_list = 99,
|
||||
get_robust_list = 100,
|
||||
nanosleep = 101,
|
||||
getitimer = 102,
|
||||
setitimer = 103,
|
||||
kexec_load = 104,
|
||||
init_module = 105,
|
||||
delete_module = 106,
|
||||
timer_create = 107,
|
||||
timer_gettime = 108,
|
||||
timer_getoverrun = 109,
|
||||
timer_settime = 110,
|
||||
timer_delete = 111,
|
||||
clock_settime = 112,
|
||||
clock_gettime = 113,
|
||||
clock_getres = 114,
|
||||
clock_nanosleep = 115,
|
||||
syslog = 116,
|
||||
ptrace = 117,
|
||||
sched_setparam = 118,
|
||||
sched_setscheduler = 119,
|
||||
sched_getscheduler = 120,
|
||||
sched_getparam = 121,
|
||||
sched_setaffinity = 122,
|
||||
sched_getaffinity = 123,
|
||||
sched_yield = 124,
|
||||
sched_get_priority_max = 125,
|
||||
sched_get_priority_min = 126,
|
||||
sched_rr_get_interval = 127,
|
||||
restart_syscall = 128,
|
||||
kill = 129,
|
||||
tkill = 130,
|
||||
tgkill = 131,
|
||||
sigaltstack = 132,
|
||||
rt_sigsuspend = 133,
|
||||
rt_sigaction = 134,
|
||||
rt_sigprocmask = 135,
|
||||
rt_sigpending = 136,
|
||||
rt_sigtimedwait = 137,
|
||||
rt_sigqueueinfo = 138,
|
||||
rt_sigreturn = 139,
|
||||
setpriority = 140,
|
||||
getpriority = 141,
|
||||
reboot = 142,
|
||||
setregid = 143,
|
||||
setgid = 144,
|
||||
setreuid = 145,
|
||||
setuid = 146,
|
||||
setresuid = 147,
|
||||
getresuid = 148,
|
||||
setresgid = 149,
|
||||
getresgid = 150,
|
||||
setfsuid = 151,
|
||||
setfsgid = 152,
|
||||
times = 153,
|
||||
setpgid = 154,
|
||||
getpgid = 155,
|
||||
getsid = 156,
|
||||
setsid = 157,
|
||||
getgroups = 158,
|
||||
setgroups = 159,
|
||||
uname = 160,
|
||||
sethostname = 161,
|
||||
setdomainname = 162,
|
||||
getrlimit = 163,
|
||||
setrlimit = 164,
|
||||
getrusage = 165,
|
||||
umask = 166,
|
||||
prctl = 167,
|
||||
getcpu = 168,
|
||||
gettimeofday = 169,
|
||||
settimeofday = 170,
|
||||
adjtimex = 171,
|
||||
getpid = 172,
|
||||
getppid = 173,
|
||||
getuid = 174,
|
||||
geteuid = 175,
|
||||
getgid = 176,
|
||||
getegid = 177,
|
||||
gettid = 178,
|
||||
sysinfo = 179,
|
||||
mq_open = 180,
|
||||
mq_unlink = 181,
|
||||
mq_timedsend = 182,
|
||||
mq_timedreceive = 183,
|
||||
mq_notify = 184,
|
||||
mq_getsetattr = 185,
|
||||
msgget = 186,
|
||||
msgctl = 187,
|
||||
msgrcv = 188,
|
||||
msgsnd = 189,
|
||||
semget = 190,
|
||||
semctl = 191,
|
||||
semtimedop = 192,
|
||||
semop = 193,
|
||||
shmget = 194,
|
||||
shmctl = 195,
|
||||
shmat = 196,
|
||||
shmdt = 197,
|
||||
socket = 198,
|
||||
socketpair = 199,
|
||||
bind = 200,
|
||||
listen = 201,
|
||||
accept = 202,
|
||||
connect = 203,
|
||||
getsockname = 204,
|
||||
getpeername = 205,
|
||||
sendto = 206,
|
||||
recvfrom = 207,
|
||||
setsockopt = 208,
|
||||
getsockopt = 209,
|
||||
shutdown = 210,
|
||||
sendmsg = 211,
|
||||
recvmsg = 212,
|
||||
readahead = 213,
|
||||
brk = 214,
|
||||
munmap = 215,
|
||||
mremap = 216,
|
||||
add_key = 217,
|
||||
request_key = 218,
|
||||
keyctl = 219,
|
||||
clone = 220,
|
||||
execve = 221,
|
||||
mmap = 222,
|
||||
fadvise64 = 223,
|
||||
swapon = 224,
|
||||
swapoff = 225,
|
||||
mprotect = 226,
|
||||
msync = 227,
|
||||
mlock = 228,
|
||||
munlock = 229,
|
||||
mlockall = 230,
|
||||
munlockall = 231,
|
||||
mincore = 232,
|
||||
madvise = 233,
|
||||
remap_file_pages = 234,
|
||||
mbind = 235,
|
||||
get_mempolicy = 236,
|
||||
set_mempolicy = 237,
|
||||
migrate_pages = 238,
|
||||
move_pages = 239,
|
||||
rt_tgsigqueueinfo = 240,
|
||||
perf_event_open = 241,
|
||||
accept4 = 242,
|
||||
recvmmsg = 243,
|
||||
arch_specific_syscall = 244,
|
||||
wait4 = 260,
|
||||
prlimit64 = 261,
|
||||
fanotify_init = 262,
|
||||
fanotify_mark = 263,
|
||||
clock_adjtime = 266,
|
||||
syncfs = 267,
|
||||
setns = 268,
|
||||
sendmmsg = 269,
|
||||
process_vm_readv = 270,
|
||||
process_vm_writev = 271,
|
||||
kcmp = 272,
|
||||
finit_module = 273,
|
||||
sched_setattr = 274,
|
||||
sched_getattr = 275,
|
||||
renameat2 = 276,
|
||||
seccomp = 277,
|
||||
getrandom = 278,
|
||||
memfd_create = 279,
|
||||
bpf = 280,
|
||||
execveat = 281,
|
||||
userfaultfd = 282,
|
||||
membarrier = 283,
|
||||
mlock2 = 284,
|
||||
copy_file_range = 285,
|
||||
preadv2 = 286,
|
||||
pwritev2 = 287,
|
||||
pkey_mprotect = 288,
|
||||
pkey_alloc = 289,
|
||||
pkey_free = 290,
|
||||
statx = 291,
|
||||
io_pgetevents = 292,
|
||||
rseq = 293,
|
||||
kexec_file_load = 294,
|
||||
pidfd_send_signal = 424,
|
||||
io_uring_setup = 425,
|
||||
io_uring_enter = 426,
|
||||
io_uring_register = 427,
|
||||
open_tree = 428,
|
||||
move_mount = 429,
|
||||
fsopen = 430,
|
||||
fsconfig = 431,
|
||||
fsmount = 432,
|
||||
fspick = 433,
|
||||
pidfd_open = 434,
|
||||
clone3 = 435,
|
||||
close_range = 436,
|
||||
openat2 = 437,
|
||||
pidfd_getfd = 438,
|
||||
faccessat2 = 439,
|
||||
process_madvise = 440,
|
||||
epoll_pwait2 = 441,
|
||||
|
||||
_,
|
||||
};
|
||||
|
||||
pub const O_CREAT = 0o100;
|
||||
pub const O_EXCL = 0o200;
|
||||
pub const O_NOCTTY = 0o400;
|
||||
pub const O_TRUNC = 0o1000;
|
||||
pub const O_APPEND = 0o2000;
|
||||
pub const O_NONBLOCK = 0o4000;
|
||||
pub const O_DSYNC = 0o10000;
|
||||
pub const O_SYNC = 0o4010000;
|
||||
pub const O_RSYNC = 0o4010000;
|
||||
pub const O_DIRECTORY = 0o40000;
|
||||
pub const O_NOFOLLOW = 0o100000;
|
||||
pub const O_CLOEXEC = 0o2000000;
|
||||
|
||||
pub const O_ASYNC = 0o20000;
|
||||
pub const O_DIRECT = 0o200000;
|
||||
pub const O_LARGEFILE = 0o400000;
|
||||
pub const O_NOATIME = 0o1000000;
|
||||
pub const O_PATH = 0o10000000;
|
||||
pub const O_TMPFILE = 0o20040000;
|
||||
pub const O_NDELAY = O_NONBLOCK;
|
||||
|
||||
pub const F_DUPFD = 0;
|
||||
pub const F_GETFD = 1;
|
||||
pub const F_SETFD = 2;
|
||||
pub const F_GETFL = 3;
|
||||
pub const F_SETFL = 4;
|
||||
|
||||
pub const F_SETOWN = 8;
|
||||
pub const F_GETOWN = 9;
|
||||
pub const F_SETSIG = 10;
|
||||
pub const F_GETSIG = 11;
|
||||
|
||||
pub const F_GETLK = 5;
|
||||
pub const F_SETLK = 6;
|
||||
pub const F_SETLKW = 7;
|
||||
|
||||
pub const F_RDLCK = 0;
|
||||
pub const F_WRLCK = 1;
|
||||
pub const F_UNLCK = 2;
|
||||
|
||||
pub const LOCK_SH = 1;
|
||||
pub const LOCK_EX = 2;
|
||||
pub const LOCK_UN = 8;
|
||||
pub const LOCK_NB = 4;
|
||||
|
||||
pub const F_SETOWN_EX = 15;
|
||||
pub const F_GETOWN_EX = 16;
|
||||
|
||||
pub const F_GETOWNER_UIDS = 17;
|
||||
|
||||
/// stack-like segment
|
||||
pub const MAP_GROWSDOWN = 0x0100;
|
||||
|
||||
/// ETXTBSY
|
||||
pub const MAP_DENYWRITE = 0x0800;
|
||||
|
||||
/// mark it as an executable
|
||||
pub const MAP_EXECUTABLE = 0x1000;
|
||||
|
||||
/// pages are locked
|
||||
pub const MAP_LOCKED = 0x2000;
|
||||
|
||||
/// don't check for reservations
|
||||
pub const MAP_NORESERVE = 0x4000;
|
||||
|
||||
pub const VDSO_CGT_SYM = "__kernel_clock_gettime";
|
||||
pub const VDSO_CGT_VER = "LINUX_2.6.39";
|
||||
|
||||
pub const Flock = extern struct {
|
||||
l_type: i16,
|
||||
l_whence: i16,
|
||||
l_start: off_t,
|
||||
l_len: off_t,
|
||||
l_pid: pid_t,
|
||||
__unused: [4]u8,
|
||||
};
|
||||
|
||||
pub const msghdr = extern struct {
|
||||
msg_name: ?*sockaddr,
|
||||
msg_namelen: socklen_t,
|
||||
msg_iov: [*]iovec,
|
||||
msg_iovlen: i32,
|
||||
__pad1: i32 = 0,
|
||||
msg_control: ?*c_void,
|
||||
msg_controllen: socklen_t,
|
||||
__pad2: socklen_t = 0,
|
||||
msg_flags: i32,
|
||||
};
|
||||
|
||||
pub const msghdr_const = extern struct {
|
||||
msg_name: ?*const sockaddr,
|
||||
msg_namelen: socklen_t,
|
||||
msg_iov: [*]iovec_const,
|
||||
msg_iovlen: i32,
|
||||
__pad1: i32 = 0,
|
||||
msg_control: ?*c_void,
|
||||
msg_controllen: socklen_t,
|
||||
__pad2: socklen_t = 0,
|
||||
msg_flags: i32,
|
||||
};
|
||||
|
||||
pub const blksize_t = i32;
|
||||
pub const nlink_t = u32;
|
||||
pub const time_t = isize;
|
||||
pub const mode_t = u32;
|
||||
pub const off_t = isize;
|
||||
pub const ino_t = usize;
|
||||
pub const dev_t = usize;
|
||||
pub const blkcnt_t = isize;
|
||||
|
||||
// The `stat` definition used by the Linux kernel.
|
||||
pub const kernel_stat = extern struct {
|
||||
dev: dev_t,
|
||||
ino: ino_t,
|
||||
mode: mode_t,
|
||||
nlink: nlink_t,
|
||||
uid: uid_t,
|
||||
gid: gid_t,
|
||||
rdev: dev_t,
|
||||
__pad: usize,
|
||||
size: off_t,
|
||||
blksize: blksize_t,
|
||||
__pad2: i32,
|
||||
blocks: blkcnt_t,
|
||||
atim: timespec,
|
||||
mtim: timespec,
|
||||
ctim: timespec,
|
||||
__unused: [2]u32,
|
||||
|
||||
pub fn atime(self: @This()) timespec {
|
||||
return self.atim;
|
||||
}
|
||||
|
||||
pub fn mtime(self: @This()) timespec {
|
||||
return self.mtim;
|
||||
}
|
||||
|
||||
pub fn ctime(self: @This()) timespec {
|
||||
return self.ctim;
|
||||
}
|
||||
};
|
||||
|
||||
// The `stat64` definition used by the libc.
|
||||
pub const libc_stat = kernel_stat;
|
||||
|
||||
pub const timespec = extern struct {
|
||||
tv_sec: time_t,
|
||||
tv_nsec: isize,
|
||||
};
|
||||
|
||||
pub const timeval = extern struct {
|
||||
tv_sec: isize,
|
||||
tv_usec: isize,
|
||||
};
|
||||
|
||||
pub const timezone = extern struct {
|
||||
tz_minuteswest: i32,
|
||||
tz_dsttime: i32,
|
||||
};
|
||||
|
||||
pub const mcontext_t = extern struct {
|
||||
fault_address: usize,
|
||||
regs: [31]usize,
|
||||
sp: usize,
|
||||
pc: usize,
|
||||
pstate: usize,
|
||||
// Make sure the field is correctly aligned since this area
|
||||
// holds various FP/vector registers
|
||||
reserved1: [256 * 16]u8 align(16),
|
||||
};
|
||||
|
||||
pub const ucontext_t = extern struct {
|
||||
flags: usize,
|
||||
link: *ucontext_t,
|
||||
stack: stack_t,
|
||||
sigmask: sigset_t,
|
||||
mcontext: mcontext_t,
|
||||
};
|
||||
|
||||
pub const Elf_Symndx = u32;
|
||||
@ -1,670 +0,0 @@
|
||||
// i386-specific declarations that are intended to be imported into the POSIX namespace.
|
||||
// This does include Linux-only APIs.
|
||||
|
||||
const std = @import("../../../std.zig");
|
||||
const linux = std.os.linux;
|
||||
const socklen_t = linux.socklen_t;
|
||||
const iovec = linux.iovec;
|
||||
const iovec_const = linux.iovec_const;
|
||||
const uid_t = linux.uid_t;
|
||||
const gid_t = linux.gid_t;
|
||||
const pid_t = linux.pid_t;
|
||||
const stack_t = linux.stack_t;
|
||||
const sigset_t = linux.sigset_t;
|
||||
|
||||
pub const SYS = enum(usize) {
|
||||
restart_syscall = 0,
|
||||
exit = 1,
|
||||
fork = 2,
|
||||
read = 3,
|
||||
write = 4,
|
||||
open = 5,
|
||||
close = 6,
|
||||
waitpid = 7,
|
||||
creat = 8,
|
||||
link = 9,
|
||||
unlink = 10,
|
||||
execve = 11,
|
||||
chdir = 12,
|
||||
time = 13,
|
||||
mknod = 14,
|
||||
chmod = 15,
|
||||
lchown = 16,
|
||||
@"break" = 17,
|
||||
oldstat = 18,
|
||||
lseek = 19,
|
||||
getpid = 20,
|
||||
mount = 21,
|
||||
umount = 22,
|
||||
setuid = 23,
|
||||
getuid = 24,
|
||||
stime = 25,
|
||||
ptrace = 26,
|
||||
alarm = 27,
|
||||
oldfstat = 28,
|
||||
pause = 29,
|
||||
utime = 30,
|
||||
stty = 31,
|
||||
gtty = 32,
|
||||
access = 33,
|
||||
nice = 34,
|
||||
ftime = 35,
|
||||
sync = 36,
|
||||
kill = 37,
|
||||
rename = 38,
|
||||
mkdir = 39,
|
||||
rmdir = 40,
|
||||
dup = 41,
|
||||
pipe = 42,
|
||||
times = 43,
|
||||
prof = 44,
|
||||
brk = 45,
|
||||
setgid = 46,
|
||||
getgid = 47,
|
||||
signal = 48,
|
||||
geteuid = 49,
|
||||
getegid = 50,
|
||||
acct = 51,
|
||||
umount2 = 52,
|
||||
lock = 53,
|
||||
ioctl = 54,
|
||||
fcntl = 55,
|
||||
mpx = 56,
|
||||
setpgid = 57,
|
||||
ulimit = 58,
|
||||
oldolduname = 59,
|
||||
umask = 60,
|
||||
chroot = 61,
|
||||
ustat = 62,
|
||||
dup2 = 63,
|
||||
getppid = 64,
|
||||
getpgrp = 65,
|
||||
setsid = 66,
|
||||
sigaction = 67,
|
||||
sgetmask = 68,
|
||||
ssetmask = 69,
|
||||
setreuid = 70,
|
||||
setregid = 71,
|
||||
sigsuspend = 72,
|
||||
sigpending = 73,
|
||||
sethostname = 74,
|
||||
setrlimit = 75,
|
||||
getrlimit = 76,
|
||||
getrusage = 77,
|
||||
gettimeofday = 78,
|
||||
settimeofday = 79,
|
||||
getgroups = 80,
|
||||
setgroups = 81,
|
||||
select = 82,
|
||||
symlink = 83,
|
||||
oldlstat = 84,
|
||||
readlink = 85,
|
||||
uselib = 86,
|
||||
swapon = 87,
|
||||
reboot = 88,
|
||||
readdir = 89,
|
||||
mmap = 90,
|
||||
munmap = 91,
|
||||
truncate = 92,
|
||||
ftruncate = 93,
|
||||
fchmod = 94,
|
||||
fchown = 95,
|
||||
getpriority = 96,
|
||||
setpriority = 97,
|
||||
profil = 98,
|
||||
statfs = 99,
|
||||
fstatfs = 100,
|
||||
ioperm = 101,
|
||||
socketcall = 102,
|
||||
syslog = 103,
|
||||
setitimer = 104,
|
||||
getitimer = 105,
|
||||
stat = 106,
|
||||
lstat = 107,
|
||||
fstat = 108,
|
||||
olduname = 109,
|
||||
iopl = 110,
|
||||
vhangup = 111,
|
||||
idle = 112,
|
||||
vm86old = 113,
|
||||
wait4 = 114,
|
||||
swapoff = 115,
|
||||
sysinfo = 116,
|
||||
ipc = 117,
|
||||
fsync = 118,
|
||||
sigreturn = 119,
|
||||
clone = 120,
|
||||
setdomainname = 121,
|
||||
uname = 122,
|
||||
modify_ldt = 123,
|
||||
adjtimex = 124,
|
||||
mprotect = 125,
|
||||
sigprocmask = 126,
|
||||
create_module = 127,
|
||||
init_module = 128,
|
||||
delete_module = 129,
|
||||
get_kernel_syms = 130,
|
||||
quotactl = 131,
|
||||
getpgid = 132,
|
||||
fchdir = 133,
|
||||
bdflush = 134,
|
||||
sysfs = 135,
|
||||
personality = 136,
|
||||
afs_syscall = 137,
|
||||
setfsuid = 138,
|
||||
setfsgid = 139,
|
||||
_llseek = 140,
|
||||
getdents = 141,
|
||||
_newselect = 142,
|
||||
flock = 143,
|
||||
msync = 144,
|
||||
readv = 145,
|
||||
writev = 146,
|
||||
getsid = 147,
|
||||
fdatasync = 148,
|
||||
_sysctl = 149,
|
||||
mlock = 150,
|
||||
munlock = 151,
|
||||
mlockall = 152,
|
||||
munlockall = 153,
|
||||
sched_setparam = 154,
|
||||
sched_getparam = 155,
|
||||
sched_setscheduler = 156,
|
||||
sched_getscheduler = 157,
|
||||
sched_yield = 158,
|
||||
sched_get_priority_max = 159,
|
||||
sched_get_priority_min = 160,
|
||||
sched_rr_get_interval = 161,
|
||||
nanosleep = 162,
|
||||
mremap = 163,
|
||||
setresuid = 164,
|
||||
getresuid = 165,
|
||||
vm86 = 166,
|
||||
query_module = 167,
|
||||
poll = 168,
|
||||
nfsservctl = 169,
|
||||
setresgid = 170,
|
||||
getresgid = 171,
|
||||
prctl = 172,
|
||||
rt_sigreturn = 173,
|
||||
rt_sigaction = 174,
|
||||
rt_sigprocmask = 175,
|
||||
rt_sigpending = 176,
|
||||
rt_sigtimedwait = 177,
|
||||
rt_sigqueueinfo = 178,
|
||||
rt_sigsuspend = 179,
|
||||
pread64 = 180,
|
||||
pwrite64 = 181,
|
||||
chown = 182,
|
||||
getcwd = 183,
|
||||
capget = 184,
|
||||
capset = 185,
|
||||
sigaltstack = 186,
|
||||
sendfile = 187,
|
||||
getpmsg = 188,
|
||||
putpmsg = 189,
|
||||
vfork = 190,
|
||||
ugetrlimit = 191,
|
||||
mmap2 = 192,
|
||||
truncate64 = 193,
|
||||
ftruncate64 = 194,
|
||||
stat64 = 195,
|
||||
lstat64 = 196,
|
||||
fstat64 = 197,
|
||||
lchown32 = 198,
|
||||
getuid32 = 199,
|
||||
getgid32 = 200,
|
||||
geteuid32 = 201,
|
||||
getegid32 = 202,
|
||||
setreuid32 = 203,
|
||||
setregid32 = 204,
|
||||
getgroups32 = 205,
|
||||
setgroups32 = 206,
|
||||
fchown32 = 207,
|
||||
setresuid32 = 208,
|
||||
getresuid32 = 209,
|
||||
setresgid32 = 210,
|
||||
getresgid32 = 211,
|
||||
chown32 = 212,
|
||||
setuid32 = 213,
|
||||
setgid32 = 214,
|
||||
setfsuid32 = 215,
|
||||
setfsgid32 = 216,
|
||||
pivot_root = 217,
|
||||
mincore = 218,
|
||||
madvise = 219,
|
||||
getdents64 = 220,
|
||||
fcntl64 = 221,
|
||||
gettid = 224,
|
||||
readahead = 225,
|
||||
setxattr = 226,
|
||||
lsetxattr = 227,
|
||||
fsetxattr = 228,
|
||||
getxattr = 229,
|
||||
lgetxattr = 230,
|
||||
fgetxattr = 231,
|
||||
listxattr = 232,
|
||||
llistxattr = 233,
|
||||
flistxattr = 234,
|
||||
removexattr = 235,
|
||||
lremovexattr = 236,
|
||||
fremovexattr = 237,
|
||||
tkill = 238,
|
||||
sendfile64 = 239,
|
||||
futex = 240,
|
||||
sched_setaffinity = 241,
|
||||
sched_getaffinity = 242,
|
||||
set_thread_area = 243,
|
||||
get_thread_area = 244,
|
||||
io_setup = 245,
|
||||
io_destroy = 246,
|
||||
io_getevents = 247,
|
||||
io_submit = 248,
|
||||
io_cancel = 249,
|
||||
fadvise64 = 250,
|
||||
exit_group = 252,
|
||||
lookup_dcookie = 253,
|
||||
epoll_create = 254,
|
||||
epoll_ctl = 255,
|
||||
epoll_wait = 256,
|
||||
remap_file_pages = 257,
|
||||
set_tid_address = 258,
|
||||
timer_create = 259,
|
||||
timer_settime, // SYS_timer_create + 1
|
||||
timer_gettime, // SYS_timer_create + 2
|
||||
timer_getoverrun, // SYS_timer_create + 3
|
||||
timer_delete, // SYS_timer_create + 4
|
||||
clock_settime, // SYS_timer_create + 5
|
||||
clock_gettime, // SYS_timer_create + 6
|
||||
clock_getres, // SYS_timer_create + 7
|
||||
clock_nanosleep, // SYS_timer_create + 8
|
||||
statfs64 = 268,
|
||||
fstatfs64 = 269,
|
||||
tgkill = 270,
|
||||
utimes = 271,
|
||||
fadvise64_64 = 272,
|
||||
vserver = 273,
|
||||
mbind = 274,
|
||||
get_mempolicy = 275,
|
||||
set_mempolicy = 276,
|
||||
mq_open = 277,
|
||||
mq_unlink, // SYS_mq_open + 1
|
||||
mq_timedsend, // SYS_mq_open + 2
|
||||
mq_timedreceive, // SYS_mq_open + 3
|
||||
mq_notify, // SYS_mq_open + 4
|
||||
mq_getsetattr, // SYS_mq_open + 5
|
||||
kexec_load = 283,
|
||||
waitid = 284,
|
||||
add_key = 286,
|
||||
request_key = 287,
|
||||
keyctl = 288,
|
||||
ioprio_set = 289,
|
||||
ioprio_get = 290,
|
||||
inotify_init = 291,
|
||||
inotify_add_watch = 292,
|
||||
inotify_rm_watch = 293,
|
||||
migrate_pages = 294,
|
||||
openat = 295,
|
||||
mkdirat = 296,
|
||||
mknodat = 297,
|
||||
fchownat = 298,
|
||||
futimesat = 299,
|
||||
fstatat64 = 300,
|
||||
unlinkat = 301,
|
||||
renameat = 302,
|
||||
linkat = 303,
|
||||
symlinkat = 304,
|
||||
readlinkat = 305,
|
||||
fchmodat = 306,
|
||||
faccessat = 307,
|
||||
pselect6 = 308,
|
||||
ppoll = 309,
|
||||
unshare = 310,
|
||||
set_robust_list = 311,
|
||||
get_robust_list = 312,
|
||||
splice = 313,
|
||||
sync_file_range = 314,
|
||||
tee = 315,
|
||||
vmsplice = 316,
|
||||
move_pages = 317,
|
||||
getcpu = 318,
|
||||
epoll_pwait = 319,
|
||||
utimensat = 320,
|
||||
signalfd = 321,
|
||||
timerfd_create = 322,
|
||||
eventfd = 323,
|
||||
fallocate = 324,
|
||||
timerfd_settime = 325,
|
||||
timerfd_gettime = 326,
|
||||
signalfd4 = 327,
|
||||
eventfd2 = 328,
|
||||
epoll_create1 = 329,
|
||||
dup3 = 330,
|
||||
pipe2 = 331,
|
||||
inotify_init1 = 332,
|
||||
preadv = 333,
|
||||
pwritev = 334,
|
||||
rt_tgsigqueueinfo = 335,
|
||||
perf_event_open = 336,
|
||||
recvmmsg = 337,
|
||||
fanotify_init = 338,
|
||||
fanotify_mark = 339,
|
||||
prlimit64 = 340,
|
||||
name_to_handle_at = 341,
|
||||
open_by_handle_at = 342,
|
||||
clock_adjtime = 343,
|
||||
syncfs = 344,
|
||||
sendmmsg = 345,
|
||||
setns = 346,
|
||||
process_vm_readv = 347,
|
||||
process_vm_writev = 348,
|
||||
kcmp = 349,
|
||||
finit_module = 350,
|
||||
sched_setattr = 351,
|
||||
sched_getattr = 352,
|
||||
renameat2 = 353,
|
||||
seccomp = 354,
|
||||
getrandom = 355,
|
||||
memfd_create = 356,
|
||||
bpf = 357,
|
||||
execveat = 358,
|
||||
socket = 359,
|
||||
socketpair = 360,
|
||||
bind = 361,
|
||||
connect = 362,
|
||||
listen = 363,
|
||||
accept4 = 364,
|
||||
getsockopt = 365,
|
||||
setsockopt = 366,
|
||||
getsockname = 367,
|
||||
getpeername = 368,
|
||||
sendto = 369,
|
||||
sendmsg = 370,
|
||||
recvfrom = 371,
|
||||
recvmsg = 372,
|
||||
shutdown = 373,
|
||||
userfaultfd = 374,
|
||||
membarrier = 375,
|
||||
mlock2 = 376,
|
||||
copy_file_range = 377,
|
||||
preadv2 = 378,
|
||||
pwritev2 = 379,
|
||||
pkey_mprotect = 380,
|
||||
pkey_alloc = 381,
|
||||
pkey_free = 382,
|
||||
statx = 383,
|
||||
arch_prctl = 384,
|
||||
io_pgetevents = 385,
|
||||
rseq = 386,
|
||||
semget = 393,
|
||||
semctl = 394,
|
||||
shmget = 395,
|
||||
shmctl = 396,
|
||||
shmat = 397,
|
||||
shmdt = 398,
|
||||
msgget = 399,
|
||||
msgsnd = 400,
|
||||
msgrcv = 401,
|
||||
msgctl = 402,
|
||||
clock_gettime64 = 403,
|
||||
clock_settime64 = 404,
|
||||
clock_adjtime64 = 405,
|
||||
clock_getres_time64 = 406,
|
||||
clock_nanosleep_time64 = 407,
|
||||
timer_gettime64 = 408,
|
||||
timer_settime64 = 409,
|
||||
timerfd_gettime64 = 410,
|
||||
timerfd_settime64 = 411,
|
||||
utimensat_time64 = 412,
|
||||
pselect6_time64 = 413,
|
||||
ppoll_time64 = 414,
|
||||
io_pgetevents_time64 = 416,
|
||||
recvmmsg_time64 = 417,
|
||||
mq_timedsend_time64 = 418,
|
||||
mq_timedreceive_time64 = 419,
|
||||
semtimedop_time64 = 420,
|
||||
rt_sigtimedwait_time64 = 421,
|
||||
futex_time64 = 422,
|
||||
sched_rr_get_interval_time64 = 423,
|
||||
pidfd_send_signal = 424,
|
||||
io_uring_setup = 425,
|
||||
io_uring_enter = 426,
|
||||
io_uring_register = 427,
|
||||
open_tree = 428,
|
||||
move_mount = 429,
|
||||
fsopen = 430,
|
||||
fsconfig = 431,
|
||||
fsmount = 432,
|
||||
fspick = 433,
|
||||
pidfd_open = 434,
|
||||
clone3 = 435,
|
||||
close_range = 436,
|
||||
openat2 = 437,
|
||||
pidfd_getfd = 438,
|
||||
faccessat2 = 439,
|
||||
process_madvise = 440,
|
||||
epoll_pwait2 = 441,
|
||||
|
||||
_,
|
||||
};
|
||||
|
||||
pub const O_CREAT = 0o100;
|
||||
pub const O_EXCL = 0o200;
|
||||
pub const O_NOCTTY = 0o400;
|
||||
pub const O_TRUNC = 0o1000;
|
||||
pub const O_APPEND = 0o2000;
|
||||
pub const O_NONBLOCK = 0o4000;
|
||||
pub const O_DSYNC = 0o10000;
|
||||
pub const O_SYNC = 0o4010000;
|
||||
pub const O_RSYNC = 0o4010000;
|
||||
pub const O_DIRECTORY = 0o200000;
|
||||
pub const O_NOFOLLOW = 0o400000;
|
||||
pub const O_CLOEXEC = 0o2000000;
|
||||
|
||||
pub const O_ASYNC = 0o20000;
|
||||
pub const O_DIRECT = 0o40000;
|
||||
pub const O_LARGEFILE = 0o100000;
|
||||
pub const O_NOATIME = 0o1000000;
|
||||
pub const O_PATH = 0o10000000;
|
||||
pub const O_TMPFILE = 0o20200000;
|
||||
pub const O_NDELAY = O_NONBLOCK;
|
||||
|
||||
pub const F_DUPFD = 0;
|
||||
pub const F_GETFD = 1;
|
||||
pub const F_SETFD = 2;
|
||||
pub const F_GETFL = 3;
|
||||
pub const F_SETFL = 4;
|
||||
|
||||
pub const F_SETOWN = 8;
|
||||
pub const F_GETOWN = 9;
|
||||
pub const F_SETSIG = 10;
|
||||
pub const F_GETSIG = 11;
|
||||
|
||||
pub const F_GETLK = 12;
|
||||
pub const F_SETLK = 13;
|
||||
pub const F_SETLKW = 14;
|
||||
|
||||
pub const F_RDLCK = 0;
|
||||
pub const F_WRLCK = 1;
|
||||
pub const F_UNLCK = 2;
|
||||
|
||||
pub const LOCK_SH = 1;
|
||||
pub const LOCK_EX = 2;
|
||||
pub const LOCK_UN = 8;
|
||||
pub const LOCK_NB = 4;
|
||||
|
||||
pub const F_SETOWN_EX = 15;
|
||||
pub const F_GETOWN_EX = 16;
|
||||
|
||||
pub const F_GETOWNER_UIDS = 17;
|
||||
|
||||
pub const MAP_NORESERVE = 0x4000;
|
||||
pub const MAP_GROWSDOWN = 0x0100;
|
||||
pub const MAP_DENYWRITE = 0x0800;
|
||||
pub const MAP_EXECUTABLE = 0x1000;
|
||||
pub const MAP_LOCKED = 0x2000;
|
||||
pub const MAP_32BIT = 0x40;
|
||||
|
||||
pub const MMAP2_UNIT = 4096;
|
||||
|
||||
pub const VDSO_CGT_SYM = "__vdso_clock_gettime";
|
||||
pub const VDSO_CGT_VER = "LINUX_2.6";
|
||||
|
||||
pub const Flock = extern struct {
|
||||
l_type: i16,
|
||||
l_whence: i16,
|
||||
l_start: off_t,
|
||||
l_len: off_t,
|
||||
l_pid: pid_t,
|
||||
};
|
||||
|
||||
pub const msghdr = extern struct {
|
||||
msg_name: ?*sockaddr,
|
||||
msg_namelen: socklen_t,
|
||||
msg_iov: [*]iovec,
|
||||
msg_iovlen: i32,
|
||||
msg_control: ?*c_void,
|
||||
msg_controllen: socklen_t,
|
||||
msg_flags: i32,
|
||||
};
|
||||
|
||||
pub const msghdr_const = extern struct {
|
||||
msg_name: ?*const sockaddr,
|
||||
msg_namelen: socklen_t,
|
||||
msg_iov: [*]iovec_const,
|
||||
msg_iovlen: i32,
|
||||
msg_control: ?*c_void,
|
||||
msg_controllen: socklen_t,
|
||||
msg_flags: i32,
|
||||
};
|
||||
|
||||
pub const blksize_t = i32;
|
||||
pub const nlink_t = u32;
|
||||
pub const time_t = isize;
|
||||
pub const mode_t = u32;
|
||||
pub const off_t = i64;
|
||||
pub const ino_t = u64;
|
||||
pub const dev_t = u64;
|
||||
pub const blkcnt_t = i64;
|
||||
|
||||
// The `stat` definition used by the Linux kernel.
|
||||
pub const kernel_stat = extern struct {
|
||||
dev: dev_t,
|
||||
__dev_padding: u32,
|
||||
__ino_truncated: u32,
|
||||
mode: mode_t,
|
||||
nlink: nlink_t,
|
||||
uid: uid_t,
|
||||
gid: gid_t,
|
||||
rdev: dev_t,
|
||||
__rdev_padding: u32,
|
||||
size: off_t,
|
||||
blksize: blksize_t,
|
||||
blocks: blkcnt_t,
|
||||
atim: timespec,
|
||||
mtim: timespec,
|
||||
ctim: timespec,
|
||||
ino: ino_t,
|
||||
|
||||
pub fn atime(self: @This()) timespec {
|
||||
return self.atim;
|
||||
}
|
||||
|
||||
pub fn mtime(self: @This()) timespec {
|
||||
return self.mtim;
|
||||
}
|
||||
|
||||
pub fn ctime(self: @This()) timespec {
|
||||
return self.ctim;
|
||||
}
|
||||
};
|
||||
|
||||
// The `stat64` definition used by the libc.
|
||||
pub const libc_stat = kernel_stat;
|
||||
|
||||
pub const timespec = extern struct {
|
||||
tv_sec: i32,
|
||||
tv_nsec: i32,
|
||||
};
|
||||
|
||||
pub const timeval = extern struct {
|
||||
tv_sec: i32,
|
||||
tv_usec: i32,
|
||||
};
|
||||
|
||||
pub const timezone = extern struct {
|
||||
tz_minuteswest: i32,
|
||||
tz_dsttime: i32,
|
||||
};
|
||||
|
||||
pub const mcontext_t = extern struct {
|
||||
gregs: [19]usize,
|
||||
fpregs: [*]u8,
|
||||
oldmask: usize,
|
||||
cr2: usize,
|
||||
};
|
||||
|
||||
pub const REG_GS = 0;
|
||||
pub const REG_FS = 1;
|
||||
pub const REG_ES = 2;
|
||||
pub const REG_DS = 3;
|
||||
pub const REG_EDI = 4;
|
||||
pub const REG_ESI = 5;
|
||||
pub const REG_EBP = 6;
|
||||
pub const REG_ESP = 7;
|
||||
pub const REG_EBX = 8;
|
||||
pub const REG_EDX = 9;
|
||||
pub const REG_ECX = 10;
|
||||
pub const REG_EAX = 11;
|
||||
pub const REG_TRAPNO = 12;
|
||||
pub const REG_ERR = 13;
|
||||
pub const REG_EIP = 14;
|
||||
pub const REG_CS = 15;
|
||||
pub const REG_EFL = 16;
|
||||
pub const REG_UESP = 17;
|
||||
pub const REG_SS = 18;
|
||||
|
||||
pub const ucontext_t = extern struct {
|
||||
flags: usize,
|
||||
link: *ucontext_t,
|
||||
stack: stack_t,
|
||||
mcontext: mcontext_t,
|
||||
sigmask: sigset_t,
|
||||
regspace: [64]u64,
|
||||
};
|
||||
|
||||
pub const Elf_Symndx = u32;
|
||||
|
||||
pub const user_desc = packed struct {
|
||||
entry_number: u32,
|
||||
base_addr: u32,
|
||||
limit: u32,
|
||||
seg_32bit: u1,
|
||||
contents: u2,
|
||||
read_exec_only: u1,
|
||||
limit_in_pages: u1,
|
||||
seg_not_present: u1,
|
||||
useable: u1,
|
||||
};
|
||||
|
||||
// socketcall() call numbers
|
||||
pub const SC_socket = 1;
|
||||
pub const SC_bind = 2;
|
||||
pub const SC_connect = 3;
|
||||
pub const SC_listen = 4;
|
||||
pub const SC_accept = 5;
|
||||
pub const SC_getsockname = 6;
|
||||
pub const SC_getpeername = 7;
|
||||
pub const SC_socketpair = 8;
|
||||
pub const SC_send = 9;
|
||||
pub const SC_recv = 10;
|
||||
pub const SC_sendto = 11;
|
||||
pub const SC_recvfrom = 12;
|
||||
pub const SC_shutdown = 13;
|
||||
pub const SC_setsockopt = 14;
|
||||
pub const SC_getsockopt = 15;
|
||||
pub const SC_sendmsg = 16;
|
||||
pub const SC_recvmsg = 17;
|
||||
pub const SC_accept4 = 18;
|
||||
pub const SC_recvmmsg = 19;
|
||||
pub const SC_sendmmsg = 20;
|
||||
@ -1,622 +0,0 @@
|
||||
const std = @import("../../../std.zig");
|
||||
const linux = std.os.linux;
|
||||
const socklen_t = linux.socklen_t;
|
||||
const iovec = linux.iovec;
|
||||
const iovec_const = linux.iovec_const;
|
||||
const uid_t = linux.uid_t;
|
||||
const gid_t = linux.gid_t;
|
||||
const pid_t = linux.pid_t;
|
||||
|
||||
pub const SYS = enum(usize) {
|
||||
pub const Linux = 4000;
|
||||
|
||||
syscall = Linux + 0,
|
||||
exit = Linux + 1,
|
||||
fork = Linux + 2,
|
||||
read = Linux + 3,
|
||||
write = Linux + 4,
|
||||
open = Linux + 5,
|
||||
close = Linux + 6,
|
||||
waitpid = Linux + 7,
|
||||
creat = Linux + 8,
|
||||
link = Linux + 9,
|
||||
unlink = Linux + 10,
|
||||
execve = Linux + 11,
|
||||
chdir = Linux + 12,
|
||||
time = Linux + 13,
|
||||
mknod = Linux + 14,
|
||||
chmod = Linux + 15,
|
||||
lchown = Linux + 16,
|
||||
@"break" = Linux + 17,
|
||||
unused18 = Linux + 18,
|
||||
lseek = Linux + 19,
|
||||
getpid = Linux + 20,
|
||||
mount = Linux + 21,
|
||||
umount = Linux + 22,
|
||||
setuid = Linux + 23,
|
||||
getuid = Linux + 24,
|
||||
stime = Linux + 25,
|
||||
ptrace = Linux + 26,
|
||||
alarm = Linux + 27,
|
||||
unused28 = Linux + 28,
|
||||
pause = Linux + 29,
|
||||
utime = Linux + 30,
|
||||
stty = Linux + 31,
|
||||
gtty = Linux + 32,
|
||||
access = Linux + 33,
|
||||
nice = Linux + 34,
|
||||
ftime = Linux + 35,
|
||||
sync = Linux + 36,
|
||||
kill = Linux + 37,
|
||||
rename = Linux + 38,
|
||||
mkdir = Linux + 39,
|
||||
rmdir = Linux + 40,
|
||||
dup = Linux + 41,
|
||||
pipe = Linux + 42,
|
||||
times = Linux + 43,
|
||||
prof = Linux + 44,
|
||||
brk = Linux + 45,
|
||||
setgid = Linux + 46,
|
||||
getgid = Linux + 47,
|
||||
signal = Linux + 48,
|
||||
geteuid = Linux + 49,
|
||||
getegid = Linux + 50,
|
||||
acct = Linux + 51,
|
||||
umount2 = Linux + 52,
|
||||
lock = Linux + 53,
|
||||
ioctl = Linux + 54,
|
||||
fcntl = Linux + 55,
|
||||
mpx = Linux + 56,
|
||||
setpgid = Linux + 57,
|
||||
ulimit = Linux + 58,
|
||||
unused59 = Linux + 59,
|
||||
umask = Linux + 60,
|
||||
chroot = Linux + 61,
|
||||
ustat = Linux + 62,
|
||||
dup2 = Linux + 63,
|
||||
getppid = Linux + 64,
|
||||
getpgrp = Linux + 65,
|
||||
setsid = Linux + 66,
|
||||
sigaction = Linux + 67,
|
||||
sgetmask = Linux + 68,
|
||||
ssetmask = Linux + 69,
|
||||
setreuid = Linux + 70,
|
||||
setregid = Linux + 71,
|
||||
sigsuspend = Linux + 72,
|
||||
sigpending = Linux + 73,
|
||||
sethostname = Linux + 74,
|
||||
setrlimit = Linux + 75,
|
||||
getrlimit = Linux + 76,
|
||||
getrusage = Linux + 77,
|
||||
gettimeofday = Linux + 78,
|
||||
settimeofday = Linux + 79,
|
||||
getgroups = Linux + 80,
|
||||
setgroups = Linux + 81,
|
||||
reserved82 = Linux + 82,
|
||||
symlink = Linux + 83,
|
||||
unused84 = Linux + 84,
|
||||
readlink = Linux + 85,
|
||||
uselib = Linux + 86,
|
||||
swapon = Linux + 87,
|
||||
reboot = Linux + 88,
|
||||
readdir = Linux + 89,
|
||||
mmap = Linux + 90,
|
||||
munmap = Linux + 91,
|
||||
truncate = Linux + 92,
|
||||
ftruncate = Linux + 93,
|
||||
fchmod = Linux + 94,
|
||||
fchown = Linux + 95,
|
||||
getpriority = Linux + 96,
|
||||
setpriority = Linux + 97,
|
||||
profil = Linux + 98,
|
||||
statfs = Linux + 99,
|
||||
fstatfs = Linux + 100,
|
||||
ioperm = Linux + 101,
|
||||
socketcall = Linux + 102,
|
||||
syslog = Linux + 103,
|
||||
setitimer = Linux + 104,
|
||||
getitimer = Linux + 105,
|
||||
stat = Linux + 106,
|
||||
lstat = Linux + 107,
|
||||
fstat = Linux + 108,
|
||||
unused109 = Linux + 109,
|
||||
iopl = Linux + 110,
|
||||
vhangup = Linux + 111,
|
||||
idle = Linux + 112,
|
||||
vm86 = Linux + 113,
|
||||
wait4 = Linux + 114,
|
||||
swapoff = Linux + 115,
|
||||
sysinfo = Linux + 116,
|
||||
ipc = Linux + 117,
|
||||
fsync = Linux + 118,
|
||||
sigreturn = Linux + 119,
|
||||
clone = Linux + 120,
|
||||
setdomainname = Linux + 121,
|
||||
uname = Linux + 122,
|
||||
modify_ldt = Linux + 123,
|
||||
adjtimex = Linux + 124,
|
||||
mprotect = Linux + 125,
|
||||
sigprocmask = Linux + 126,
|
||||
create_module = Linux + 127,
|
||||
init_module = Linux + 128,
|
||||
delete_module = Linux + 129,
|
||||
get_kernel_syms = Linux + 130,
|
||||
quotactl = Linux + 131,
|
||||
getpgid = Linux + 132,
|
||||
fchdir = Linux + 133,
|
||||
bdflush = Linux + 134,
|
||||
sysfs = Linux + 135,
|
||||
personality = Linux + 136,
|
||||
afs_syscall = Linux + 137,
|
||||
setfsuid = Linux + 138,
|
||||
setfsgid = Linux + 139,
|
||||
_llseek = Linux + 140,
|
||||
getdents = Linux + 141,
|
||||
_newselect = Linux + 142,
|
||||
flock = Linux + 143,
|
||||
msync = Linux + 144,
|
||||
readv = Linux + 145,
|
||||
writev = Linux + 146,
|
||||
cacheflush = Linux + 147,
|
||||
cachectl = Linux + 148,
|
||||
sysmips = Linux + 149,
|
||||
unused150 = Linux + 150,
|
||||
getsid = Linux + 151,
|
||||
fdatasync = Linux + 152,
|
||||
_sysctl = Linux + 153,
|
||||
mlock = Linux + 154,
|
||||
munlock = Linux + 155,
|
||||
mlockall = Linux + 156,
|
||||
munlockall = Linux + 157,
|
||||
sched_setparam = Linux + 158,
|
||||
sched_getparam = Linux + 159,
|
||||
sched_setscheduler = Linux + 160,
|
||||
sched_getscheduler = Linux + 161,
|
||||
sched_yield = Linux + 162,
|
||||
sched_get_priority_max = Linux + 163,
|
||||
sched_get_priority_min = Linux + 164,
|
||||
sched_rr_get_interval = Linux + 165,
|
||||
nanosleep = Linux + 166,
|
||||
mremap = Linux + 167,
|
||||
accept = Linux + 168,
|
||||
bind = Linux + 169,
|
||||
connect = Linux + 170,
|
||||
getpeername = Linux + 171,
|
||||
getsockname = Linux + 172,
|
||||
getsockopt = Linux + 173,
|
||||
listen = Linux + 174,
|
||||
recv = Linux + 175,
|
||||
recvfrom = Linux + 176,
|
||||
recvmsg = Linux + 177,
|
||||
send = Linux + 178,
|
||||
sendmsg = Linux + 179,
|
||||
sendto = Linux + 180,
|
||||
setsockopt = Linux + 181,
|
||||
shutdown = Linux + 182,
|
||||
socket = Linux + 183,
|
||||
socketpair = Linux + 184,
|
||||
setresuid = Linux + 185,
|
||||
getresuid = Linux + 186,
|
||||
query_module = Linux + 187,
|
||||
poll = Linux + 188,
|
||||
nfsservctl = Linux + 189,
|
||||
setresgid = Linux + 190,
|
||||
getresgid = Linux + 191,
|
||||
prctl = Linux + 192,
|
||||
rt_sigreturn = Linux + 193,
|
||||
rt_sigaction = Linux + 194,
|
||||
rt_sigprocmask = Linux + 195,
|
||||
rt_sigpending = Linux + 196,
|
||||
rt_sigtimedwait = Linux + 197,
|
||||
rt_sigqueueinfo = Linux + 198,
|
||||
rt_sigsuspend = Linux + 199,
|
||||
pread64 = Linux + 200,
|
||||
pwrite64 = Linux + 201,
|
||||
chown = Linux + 202,
|
||||
getcwd = Linux + 203,
|
||||
capget = Linux + 204,
|
||||
capset = Linux + 205,
|
||||
sigaltstack = Linux + 206,
|
||||
sendfile = Linux + 207,
|
||||
getpmsg = Linux + 208,
|
||||
putpmsg = Linux + 209,
|
||||
mmap2 = Linux + 210,
|
||||
truncate64 = Linux + 211,
|
||||
ftruncate64 = Linux + 212,
|
||||
stat64 = Linux + 213,
|
||||
lstat64 = Linux + 214,
|
||||
fstat64 = Linux + 215,
|
||||
pivot_root = Linux + 216,
|
||||
mincore = Linux + 217,
|
||||
madvise = Linux + 218,
|
||||
getdents64 = Linux + 219,
|
||||
fcntl64 = Linux + 220,
|
||||
reserved221 = Linux + 221,
|
||||
gettid = Linux + 222,
|
||||
readahead = Linux + 223,
|
||||
setxattr = Linux + 224,
|
||||
lsetxattr = Linux + 225,
|
||||
fsetxattr = Linux + 226,
|
||||
getxattr = Linux + 227,
|
||||
lgetxattr = Linux + 228,
|
||||
fgetxattr = Linux + 229,
|
||||
listxattr = Linux + 230,
|
||||
llistxattr = Linux + 231,
|
||||
flistxattr = Linux + 232,
|
||||
removexattr = Linux + 233,
|
||||
lremovexattr = Linux + 234,
|
||||
fremovexattr = Linux + 235,
|
||||
tkill = Linux + 236,
|
||||
sendfile64 = Linux + 237,
|
||||
futex = Linux + 238,
|
||||
sched_setaffinity = Linux + 239,
|
||||
sched_getaffinity = Linux + 240,
|
||||
io_setup = Linux + 241,
|
||||
io_destroy = Linux + 242,
|
||||
io_getevents = Linux + 243,
|
||||
io_submit = Linux + 244,
|
||||
io_cancel = Linux + 245,
|
||||
exit_group = Linux + 246,
|
||||
lookup_dcookie = Linux + 247,
|
||||
epoll_create = Linux + 248,
|
||||
epoll_ctl = Linux + 249,
|
||||
epoll_wait = Linux + 250,
|
||||
remap_file_pages = Linux + 251,
|
||||
set_tid_address = Linux + 252,
|
||||
restart_syscall = Linux + 253,
|
||||
fadvise64 = Linux + 254,
|
||||
statfs64 = Linux + 255,
|
||||
fstatfs64 = Linux + 256,
|
||||
timer_create = Linux + 257,
|
||||
timer_settime = Linux + 258,
|
||||
timer_gettime = Linux + 259,
|
||||
timer_getoverrun = Linux + 260,
|
||||
timer_delete = Linux + 261,
|
||||
clock_settime = Linux + 262,
|
||||
clock_gettime = Linux + 263,
|
||||
clock_getres = Linux + 264,
|
||||
clock_nanosleep = Linux + 265,
|
||||
tgkill = Linux + 266,
|
||||
utimes = Linux + 267,
|
||||
mbind = Linux + 268,
|
||||
get_mempolicy = Linux + 269,
|
||||
set_mempolicy = Linux + 270,
|
||||
mq_open = Linux + 271,
|
||||
mq_unlink = Linux + 272,
|
||||
mq_timedsend = Linux + 273,
|
||||
mq_timedreceive = Linux + 274,
|
||||
mq_notify = Linux + 275,
|
||||
mq_getsetattr = Linux + 276,
|
||||
vserver = Linux + 277,
|
||||
waitid = Linux + 278,
|
||||
add_key = Linux + 280,
|
||||
request_key = Linux + 281,
|
||||
keyctl = Linux + 282,
|
||||
set_thread_area = Linux + 283,
|
||||
inotify_init = Linux + 284,
|
||||
inotify_add_watch = Linux + 285,
|
||||
inotify_rm_watch = Linux + 286,
|
||||
migrate_pages = Linux + 287,
|
||||
openat = Linux + 288,
|
||||
mkdirat = Linux + 289,
|
||||
mknodat = Linux + 290,
|
||||
fchownat = Linux + 291,
|
||||
futimesat = Linux + 292,
|
||||
fstatat64 = Linux + 293,
|
||||
unlinkat = Linux + 294,
|
||||
renameat = Linux + 295,
|
||||
linkat = Linux + 296,
|
||||
symlinkat = Linux + 297,
|
||||
readlinkat = Linux + 298,
|
||||
fchmodat = Linux + 299,
|
||||
faccessat = Linux + 300,
|
||||
pselect6 = Linux + 301,
|
||||
ppoll = Linux + 302,
|
||||
unshare = Linux + 303,
|
||||
splice = Linux + 304,
|
||||
sync_file_range = Linux + 305,
|
||||
tee = Linux + 306,
|
||||
vmsplice = Linux + 307,
|
||||
move_pages = Linux + 308,
|
||||
set_robust_list = Linux + 309,
|
||||
get_robust_list = Linux + 310,
|
||||
kexec_load = Linux + 311,
|
||||
getcpu = Linux + 312,
|
||||
epoll_pwait = Linux + 313,
|
||||
ioprio_set = Linux + 314,
|
||||
ioprio_get = Linux + 315,
|
||||
utimensat = Linux + 316,
|
||||
signalfd = Linux + 317,
|
||||
timerfd = Linux + 318,
|
||||
eventfd = Linux + 319,
|
||||
fallocate = Linux + 320,
|
||||
timerfd_create = Linux + 321,
|
||||
timerfd_gettime = Linux + 322,
|
||||
timerfd_settime = Linux + 323,
|
||||
signalfd4 = Linux + 324,
|
||||
eventfd2 = Linux + 325,
|
||||
epoll_create1 = Linux + 326,
|
||||
dup3 = Linux + 327,
|
||||
pipe2 = Linux + 328,
|
||||
inotify_init1 = Linux + 329,
|
||||
preadv = Linux + 330,
|
||||
pwritev = Linux + 331,
|
||||
rt_tgsigqueueinfo = Linux + 332,
|
||||
perf_event_open = Linux + 333,
|
||||
accept4 = Linux + 334,
|
||||
recvmmsg = Linux + 335,
|
||||
fanotify_init = Linux + 336,
|
||||
fanotify_mark = Linux + 337,
|
||||
prlimit64 = Linux + 338,
|
||||
name_to_handle_at = Linux + 339,
|
||||
open_by_handle_at = Linux + 340,
|
||||
clock_adjtime = Linux + 341,
|
||||
syncfs = Linux + 342,
|
||||
sendmmsg = Linux + 343,
|
||||
setns = Linux + 344,
|
||||
process_vm_readv = Linux + 345,
|
||||
process_vm_writev = Linux + 346,
|
||||
kcmp = Linux + 347,
|
||||
finit_module = Linux + 348,
|
||||
sched_setattr = Linux + 349,
|
||||
sched_getattr = Linux + 350,
|
||||
renameat2 = Linux + 351,
|
||||
seccomp = Linux + 352,
|
||||
getrandom = Linux + 353,
|
||||
memfd_create = Linux + 354,
|
||||
bpf = Linux + 355,
|
||||
execveat = Linux + 356,
|
||||
userfaultfd = Linux + 357,
|
||||
membarrier = Linux + 358,
|
||||
mlock2 = Linux + 359,
|
||||
copy_file_range = Linux + 360,
|
||||
preadv2 = Linux + 361,
|
||||
pwritev2 = Linux + 362,
|
||||
pkey_mprotect = Linux + 363,
|
||||
pkey_alloc = Linux + 364,
|
||||
pkey_free = Linux + 365,
|
||||
statx = Linux + 366,
|
||||
rseq = Linux + 367,
|
||||
io_pgetevents = Linux + 368,
|
||||
semget = Linux + 393,
|
||||
semctl = Linux + 394,
|
||||
shmget = Linux + 395,
|
||||
shmctl = Linux + 396,
|
||||
shmat = Linux + 397,
|
||||
shmdt = Linux + 398,
|
||||
msgget = Linux + 399,
|
||||
msgsnd = Linux + 400,
|
||||
msgrcv = Linux + 401,
|
||||
msgctl = Linux + 402,
|
||||
clock_gettime64 = Linux + 403,
|
||||
clock_settime64 = Linux + 404,
|
||||
clock_adjtime64 = Linux + 405,
|
||||
clock_getres_time64 = Linux + 406,
|
||||
clock_nanosleep_time64 = Linux + 407,
|
||||
timer_gettime64 = Linux + 408,
|
||||
timer_settime64 = Linux + 409,
|
||||
timerfd_gettime64 = Linux + 410,
|
||||
timerfd_settime64 = Linux + 411,
|
||||
utimensat_time64 = Linux + 412,
|
||||
pselect6_time64 = Linux + 413,
|
||||
ppoll_time64 = Linux + 414,
|
||||
io_pgetevents_time64 = Linux + 416,
|
||||
recvmmsg_time64 = Linux + 417,
|
||||
mq_timedsend_time64 = Linux + 418,
|
||||
mq_timedreceive_time64 = Linux + 419,
|
||||
semtimedop_time64 = Linux + 420,
|
||||
rt_sigtimedwait_time64 = Linux + 421,
|
||||
futex_time64 = Linux + 422,
|
||||
sched_rr_get_interval_time64 = Linux + 423,
|
||||
pidfd_send_signal = Linux + 424,
|
||||
io_uring_setup = Linux + 425,
|
||||
io_uring_enter = Linux + 426,
|
||||
io_uring_register = Linux + 427,
|
||||
open_tree = Linux + 428,
|
||||
move_mount = Linux + 429,
|
||||
fsopen = Linux + 430,
|
||||
fsconfig = Linux + 431,
|
||||
fsmount = Linux + 432,
|
||||
fspick = Linux + 433,
|
||||
pidfd_open = Linux + 434,
|
||||
clone3 = Linux + 435,
|
||||
close_range = Linux + 436,
|
||||
openat2 = Linux + 437,
|
||||
pidfd_getfd = Linux + 438,
|
||||
faccessat2 = Linux + 439,
|
||||
process_madvise = Linux + 440,
|
||||
epoll_pwait2 = Linux + 441,
|
||||
|
||||
_,
|
||||
};
|
||||
|
||||
pub const O_CREAT = 0o0400;
|
||||
pub const O_EXCL = 0o02000;
|
||||
pub const O_NOCTTY = 0o04000;
|
||||
pub const O_TRUNC = 0o01000;
|
||||
pub const O_APPEND = 0o0010;
|
||||
pub const O_NONBLOCK = 0o0200;
|
||||
pub const O_DSYNC = 0o0020;
|
||||
pub const O_SYNC = 0o040020;
|
||||
pub const O_RSYNC = 0o040020;
|
||||
pub const O_DIRECTORY = 0o0200000;
|
||||
pub const O_NOFOLLOW = 0o0400000;
|
||||
pub const O_CLOEXEC = 0o02000000;
|
||||
|
||||
pub const O_ASYNC = 0o010000;
|
||||
pub const O_DIRECT = 0o0100000;
|
||||
pub const O_LARGEFILE = 0o020000;
|
||||
pub const O_NOATIME = 0o01000000;
|
||||
pub const O_PATH = 0o010000000;
|
||||
pub const O_TMPFILE = 0o020200000;
|
||||
pub const O_NDELAY = O_NONBLOCK;
|
||||
|
||||
pub const F_DUPFD = 0;
|
||||
pub const F_GETFD = 1;
|
||||
pub const F_SETFD = 2;
|
||||
pub const F_GETFL = 3;
|
||||
pub const F_SETFL = 4;
|
||||
|
||||
pub const F_SETOWN = 24;
|
||||
pub const F_GETOWN = 23;
|
||||
pub const F_SETSIG = 10;
|
||||
pub const F_GETSIG = 11;
|
||||
|
||||
pub const F_GETLK = 33;
|
||||
pub const F_SETLK = 34;
|
||||
pub const F_SETLKW = 35;
|
||||
|
||||
pub const F_RDLCK = 0;
|
||||
pub const F_WRLCK = 1;
|
||||
pub const F_UNLCK = 2;
|
||||
|
||||
pub const LOCK_SH = 1;
|
||||
pub const LOCK_EX = 2;
|
||||
pub const LOCK_UN = 8;
|
||||
pub const LOCK_NB = 4;
|
||||
|
||||
pub const F_SETOWN_EX = 15;
|
||||
pub const F_GETOWN_EX = 16;
|
||||
|
||||
pub const F_GETOWNER_UIDS = 17;
|
||||
|
||||
pub const MMAP2_UNIT = 4096;
|
||||
|
||||
pub const MAP_NORESERVE = 0x0400;
|
||||
pub const MAP_GROWSDOWN = 0x1000;
|
||||
pub const MAP_DENYWRITE = 0x2000;
|
||||
pub const MAP_EXECUTABLE = 0x4000;
|
||||
pub const MAP_LOCKED = 0x8000;
|
||||
pub const MAP_32BIT = 0x40;
|
||||
|
||||
pub const SO_DEBUG = 1;
|
||||
pub const SO_REUSEADDR = 0x0004;
|
||||
pub const SO_KEEPALIVE = 0x0008;
|
||||
pub const SO_DONTROUTE = 0x0010;
|
||||
pub const SO_BROADCAST = 0x0020;
|
||||
pub const SO_LINGER = 0x0080;
|
||||
pub const SO_OOBINLINE = 0x0100;
|
||||
pub const SO_REUSEPORT = 0x0200;
|
||||
pub const SO_SNDBUF = 0x1001;
|
||||
pub const SO_RCVBUF = 0x1002;
|
||||
pub const SO_SNDLOWAT = 0x1003;
|
||||
pub const SO_RCVLOWAT = 0x1004;
|
||||
pub const SO_RCVTIMEO = 0x1006;
|
||||
pub const SO_SNDTIMEO = 0x1005;
|
||||
pub const SO_ERROR = 0x1007;
|
||||
pub const SO_TYPE = 0x1008;
|
||||
pub const SO_ACCEPTCONN = 0x1009;
|
||||
pub const SO_PROTOCOL = 0x1028;
|
||||
pub const SO_DOMAIN = 0x1029;
|
||||
pub const SO_NO_CHECK = 11;
|
||||
pub const SO_PRIORITY = 12;
|
||||
pub const SO_BSDCOMPAT = 14;
|
||||
pub const SO_PASSCRED = 17;
|
||||
pub const SO_PEERCRED = 18;
|
||||
pub const SO_PEERSEC = 30;
|
||||
pub const SO_SNDBUFFORCE = 31;
|
||||
pub const SO_RCVBUFFORCE = 33;
|
||||
|
||||
pub const VDSO_CGT_SYM = "__kernel_clock_gettime";
|
||||
pub const VDSO_CGT_VER = "LINUX_2.6.39";
|
||||
|
||||
pub const Flock = extern struct {
|
||||
l_type: i16,
|
||||
l_whence: i16,
|
||||
__pad0: [4]u8,
|
||||
l_start: off_t,
|
||||
l_len: off_t,
|
||||
l_pid: pid_t,
|
||||
__unused: [4]u8,
|
||||
};
|
||||
|
||||
pub const blksize_t = i32;
|
||||
pub const nlink_t = u32;
|
||||
pub const time_t = i32;
|
||||
pub const mode_t = u32;
|
||||
pub const off_t = i64;
|
||||
pub const ino_t = u64;
|
||||
pub const dev_t = u64;
|
||||
pub const blkcnt_t = i64;
|
||||
|
||||
// The `stat` definition used by the Linux kernel.
|
||||
pub const kernel_stat = extern struct {
|
||||
dev: u32,
|
||||
__pad0: [3]u32, // Reserved for st_dev expansion
|
||||
ino: ino_t,
|
||||
mode: mode_t,
|
||||
nlink: nlink_t,
|
||||
uid: uid_t,
|
||||
gid: gid_t,
|
||||
rdev: u32,
|
||||
__pad1: [3]u32,
|
||||
size: off_t,
|
||||
atim: timespec,
|
||||
mtim: timespec,
|
||||
ctim: timespec,
|
||||
blksize: blksize_t,
|
||||
__pad3: u32,
|
||||
blocks: blkcnt_t,
|
||||
__pad4: [14]usize,
|
||||
|
||||
pub fn atime(self: @This()) timespec {
|
||||
return self.atim;
|
||||
}
|
||||
|
||||
pub fn mtime(self: @This()) timespec {
|
||||
return self.mtim;
|
||||
}
|
||||
|
||||
pub fn ctime(self: @This()) timespec {
|
||||
return self.ctim;
|
||||
}
|
||||
};
|
||||
|
||||
pub const libc_stat = extern struct {
|
||||
dev: dev_t,
|
||||
__pad0: [2]u32,
|
||||
ino: ino_t,
|
||||
mode: mode_t,
|
||||
nlink: nlink_t,
|
||||
uid: uid_t,
|
||||
gid: gid_t,
|
||||
rdev: dev_t,
|
||||
__pad1: [2]u32,
|
||||
size: off_t,
|
||||
atim: timespec,
|
||||
mtim: timespec,
|
||||
ctim: timespec,
|
||||
blksize: blksize_t,
|
||||
__pad3: u32,
|
||||
blocks: blkcnt_t,
|
||||
__pad4: [14]u32,
|
||||
|
||||
pub fn atime(self: @This()) timespec {
|
||||
return self.atim;
|
||||
}
|
||||
|
||||
pub fn mtime(self: @This()) timespec {
|
||||
return self.mtim;
|
||||
}
|
||||
|
||||
pub fn ctime(self: @This()) timespec {
|
||||
return self.ctim;
|
||||
}
|
||||
};
|
||||
|
||||
pub const timespec = extern struct {
|
||||
tv_sec: isize,
|
||||
tv_nsec: isize,
|
||||
};
|
||||
|
||||
pub const timeval = extern struct {
|
||||
tv_sec: isize,
|
||||
tv_usec: isize,
|
||||
};
|
||||
|
||||
pub const timezone = extern struct {
|
||||
tz_minuteswest: i32,
|
||||
tz_dsttime: i32,
|
||||
};
|
||||
|
||||
pub const Elf_Symndx = u32;
|
||||
@ -1,498 +0,0 @@
|
||||
usingnamespace @import("../linux.zig");
|
||||
|
||||
/// Routing/device hook
|
||||
pub const NETLINK_ROUTE = 0;
|
||||
|
||||
/// Unused number
|
||||
pub const NETLINK_UNUSED = 1;
|
||||
|
||||
/// Reserved for user mode socket protocols
|
||||
pub const NETLINK_USERSOCK = 2;
|
||||
|
||||
/// Unused number, formerly ip_queue
|
||||
pub const NETLINK_FIREWALL = 3;
|
||||
|
||||
/// socket monitoring
|
||||
pub const NETLINK_SOCK_DIAG = 4;
|
||||
|
||||
/// netfilter/iptables ULOG
|
||||
pub const NETLINK_NFLOG = 5;
|
||||
|
||||
/// ipsec
|
||||
pub const NETLINK_XFRM = 6;
|
||||
|
||||
/// SELinux event notifications
|
||||
pub const NETLINK_SELINUX = 7;
|
||||
|
||||
/// Open-iSCSI
|
||||
pub const NETLINK_ISCSI = 8;
|
||||
|
||||
/// auditing
|
||||
pub const NETLINK_AUDIT = 9;
|
||||
|
||||
pub const NETLINK_FIB_LOOKUP = 10;
|
||||
|
||||
pub const NETLINK_CONNECTOR = 11;
|
||||
|
||||
/// netfilter subsystem
|
||||
pub const NETLINK_NETFILTER = 12;
|
||||
|
||||
pub const NETLINK_IP6_FW = 13;
|
||||
|
||||
/// DECnet routing messages
|
||||
pub const NETLINK_DNRTMSG = 14;
|
||||
|
||||
/// Kernel messages to userspace
|
||||
pub const NETLINK_KOBJECT_UEVENT = 15;
|
||||
|
||||
pub const NETLINK_GENERIC = 16;
|
||||
|
||||
// leave room for NETLINK_DM (DM Events)
|
||||
|
||||
/// SCSI Transports
|
||||
pub const NETLINK_SCSITRANSPORT = 18;
|
||||
|
||||
pub const NETLINK_ECRYPTFS = 19;
|
||||
|
||||
pub const NETLINK_RDMA = 20;
|
||||
|
||||
/// Crypto layer
|
||||
pub const NETLINK_CRYPTO = 21;
|
||||
|
||||
/// SMC monitoring
|
||||
pub const NETLINK_SMC = 22;
|
||||
|
||||
// Flags values
|
||||
|
||||
/// It is request message.
|
||||
pub const NLM_F_REQUEST = 0x01;
|
||||
|
||||
/// Multipart message, terminated by NLMSG_DONE
|
||||
pub const NLM_F_MULTI = 0x02;
|
||||
|
||||
/// Reply with ack, with zero or error code
|
||||
pub const NLM_F_ACK = 0x04;
|
||||
|
||||
/// Echo this request
|
||||
pub const NLM_F_ECHO = 0x08;
|
||||
|
||||
/// Dump was inconsistent due to sequence change
|
||||
pub const NLM_F_DUMP_INTR = 0x10;
|
||||
|
||||
/// Dump was filtered as requested
|
||||
pub const NLM_F_DUMP_FILTERED = 0x20;
|
||||
|
||||
// Modifiers to GET request
|
||||
|
||||
/// specify tree root
|
||||
pub const NLM_F_ROOT = 0x100;
|
||||
|
||||
/// return all matching
|
||||
pub const NLM_F_MATCH = 0x200;
|
||||
|
||||
/// atomic GET
|
||||
pub const NLM_F_ATOMIC = 0x400;
|
||||
pub const NLM_F_DUMP = NLM_F_ROOT | NLM_F_MATCH;
|
||||
|
||||
// Modifiers to NEW request
|
||||
|
||||
/// Override existing
|
||||
pub const NLM_F_REPLACE = 0x100;
|
||||
|
||||
/// Do not touch, if it exists
|
||||
pub const NLM_F_EXCL = 0x200;
|
||||
|
||||
/// Create, if it does not exist
|
||||
pub const NLM_F_CREATE = 0x400;
|
||||
|
||||
/// Add to end of list
|
||||
pub const NLM_F_APPEND = 0x800;
|
||||
|
||||
// Modifiers to DELETE request
|
||||
|
||||
/// Do not delete recursively
|
||||
pub const NLM_F_NONREC = 0x100;
|
||||
|
||||
// Flags for ACK message
|
||||
|
||||
/// request was capped
|
||||
pub const NLM_F_CAPPED = 0x100;
|
||||
|
||||
/// extended ACK TVLs were included
|
||||
pub const NLM_F_ACK_TLVS = 0x200;
|
||||
|
||||
pub const NetlinkMessageType = enum(u16) {
|
||||
/// < 0x10: reserved control messages
|
||||
pub const MIN_TYPE = 0x10;
|
||||
|
||||
/// Nothing.
|
||||
NOOP = 0x1,
|
||||
|
||||
/// Error
|
||||
ERROR = 0x2,
|
||||
|
||||
/// End of a dump
|
||||
DONE = 0x3,
|
||||
|
||||
/// Data lost
|
||||
OVERRUN = 0x4,
|
||||
|
||||
// rtlink types
|
||||
|
||||
RTM_NEWLINK = 16,
|
||||
RTM_DELLINK,
|
||||
RTM_GETLINK,
|
||||
RTM_SETLINK,
|
||||
|
||||
RTM_NEWADDR = 20,
|
||||
RTM_DELADDR,
|
||||
RTM_GETADDR,
|
||||
|
||||
RTM_NEWROUTE = 24,
|
||||
RTM_DELROUTE,
|
||||
RTM_GETROUTE,
|
||||
|
||||
RTM_NEWNEIGH = 28,
|
||||
RTM_DELNEIGH,
|
||||
RTM_GETNEIGH,
|
||||
|
||||
RTM_NEWRULE = 32,
|
||||
RTM_DELRULE,
|
||||
RTM_GETRULE,
|
||||
|
||||
RTM_NEWQDISC = 36,
|
||||
RTM_DELQDISC,
|
||||
RTM_GETQDISC,
|
||||
|
||||
RTM_NEWTCLASS = 40,
|
||||
RTM_DELTCLASS,
|
||||
RTM_GETTCLASS,
|
||||
|
||||
RTM_NEWTFILTER = 44,
|
||||
RTM_DELTFILTER,
|
||||
RTM_GETTFILTER,
|
||||
|
||||
RTM_NEWACTION = 48,
|
||||
RTM_DELACTION,
|
||||
RTM_GETACTION,
|
||||
|
||||
RTM_NEWPREFIX = 52,
|
||||
|
||||
RTM_GETMULTICAST = 58,
|
||||
|
||||
RTM_GETANYCAST = 62,
|
||||
|
||||
RTM_NEWNEIGHTBL = 64,
|
||||
RTM_GETNEIGHTBL = 66,
|
||||
RTM_SETNEIGHTBL,
|
||||
|
||||
RTM_NEWNDUSEROPT = 68,
|
||||
|
||||
RTM_NEWADDRLABEL = 72,
|
||||
RTM_DELADDRLABEL,
|
||||
RTM_GETADDRLABEL,
|
||||
|
||||
RTM_GETDCB = 78,
|
||||
RTM_SETDCB,
|
||||
|
||||
RTM_NEWNETCONF = 80,
|
||||
RTM_DELNETCONF,
|
||||
RTM_GETNETCONF = 82,
|
||||
|
||||
RTM_NEWMDB = 84,
|
||||
RTM_DELMDB = 85,
|
||||
RTM_GETMDB = 86,
|
||||
|
||||
RTM_NEWNSID = 88,
|
||||
RTM_DELNSID = 89,
|
||||
RTM_GETNSID = 90,
|
||||
|
||||
RTM_NEWSTATS = 92,
|
||||
RTM_GETSTATS = 94,
|
||||
|
||||
RTM_NEWCACHEREPORT = 96,
|
||||
|
||||
RTM_NEWCHAIN = 100,
|
||||
RTM_DELCHAIN,
|
||||
RTM_GETCHAIN,
|
||||
|
||||
RTM_NEWNEXTHOP = 104,
|
||||
RTM_DELNEXTHOP,
|
||||
RTM_GETNEXTHOP,
|
||||
|
||||
_,
|
||||
};
|
||||
|
||||
/// Netlink socket address
|
||||
pub const sockaddr_nl = extern struct {
|
||||
family: sa_family_t = AF_NETLINK,
|
||||
__pad1: c_ushort = 0,
|
||||
|
||||
/// port ID
|
||||
pid: u32,
|
||||
|
||||
/// multicast groups mask
|
||||
groups: u32,
|
||||
};
|
||||
|
||||
/// Netlink message header
|
||||
/// Specified in RFC 3549 Section 2.3.2
|
||||
pub const nlmsghdr = extern struct {
|
||||
/// Length of message including header
|
||||
len: u32,
|
||||
|
||||
/// Message content
|
||||
@"type": NetlinkMessageType,
|
||||
|
||||
/// Additional flags
|
||||
flags: u16,
|
||||
|
||||
/// Sequence number
|
||||
seq: u32,
|
||||
|
||||
/// Sending process port ID
|
||||
pid: u32,
|
||||
};
|
||||
|
||||
pub const ifinfomsg = extern struct {
|
||||
family: u8,
|
||||
__pad1: u8 = 0,
|
||||
|
||||
/// ARPHRD_*
|
||||
@"type": c_ushort,
|
||||
|
||||
/// Link index
|
||||
index: c_int,
|
||||
|
||||
/// IFF_* flags
|
||||
flags: c_uint,
|
||||
|
||||
/// IFF_* change mask
|
||||
change: c_uint,
|
||||
};
|
||||
|
||||
pub const rtattr = extern struct {
|
||||
/// Length of option
|
||||
len: c_ushort,
|
||||
|
||||
/// Type of option
|
||||
@"type": IFLA,
|
||||
|
||||
pub const ALIGNTO = 4;
|
||||
};
|
||||
|
||||
pub const IFLA = enum(c_ushort) {
|
||||
UNSPEC,
|
||||
ADDRESS,
|
||||
BROADCAST,
|
||||
IFNAME,
|
||||
MTU,
|
||||
LINK,
|
||||
QDISC,
|
||||
STATS,
|
||||
COST,
|
||||
PRIORITY,
|
||||
MASTER,
|
||||
|
||||
/// Wireless Extension event
|
||||
WIRELESS,
|
||||
|
||||
/// Protocol specific information for a link
|
||||
PROTINFO,
|
||||
|
||||
TXQLEN,
|
||||
MAP,
|
||||
WEIGHT,
|
||||
OPERSTATE,
|
||||
LINKMODE,
|
||||
LINKINFO,
|
||||
NET_NS_PID,
|
||||
IFALIAS,
|
||||
|
||||
/// Number of VFs if device is SR-IOV PF
|
||||
NUM_VF,
|
||||
|
||||
VFINFO_LIST,
|
||||
STATS64,
|
||||
VF_PORTS,
|
||||
PORT_SELF,
|
||||
AF_SPEC,
|
||||
|
||||
/// Group the device belongs to
|
||||
GROUP,
|
||||
|
||||
NET_NS_FD,
|
||||
|
||||
/// Extended info mask, VFs, etc
|
||||
EXT_MASK,
|
||||
|
||||
/// Promiscuity count: > 0 means acts PROMISC
|
||||
PROMISCUITY,
|
||||
|
||||
NUM_TX_QUEUES,
|
||||
NUM_RX_QUEUES,
|
||||
CARRIER,
|
||||
PHYS_PORT_ID,
|
||||
CARRIER_CHANGES,
|
||||
PHYS_SWITCH_ID,
|
||||
LINK_NETNSID,
|
||||
PHYS_PORT_NAME,
|
||||
PROTO_DOWN,
|
||||
GSO_MAX_SEGS,
|
||||
GSO_MAX_SIZE,
|
||||
PAD,
|
||||
XDP,
|
||||
EVENT,
|
||||
|
||||
NEW_NETNSID,
|
||||
IF_NETNSID,
|
||||
|
||||
CARRIER_UP_COUNT,
|
||||
CARRIER_DOWN_COUNT,
|
||||
NEW_IFINDEX,
|
||||
MIN_MTU,
|
||||
MAX_MTU,
|
||||
|
||||
_,
|
||||
|
||||
pub const TARGET_NETNSID: IFLA = .IF_NETNSID;
|
||||
};
|
||||
|
||||
pub const rtnl_link_ifmap = extern struct {
|
||||
mem_start: u64,
|
||||
mem_end: u64,
|
||||
base_addr: u64,
|
||||
irq: u16,
|
||||
dma: u8,
|
||||
port: u8,
|
||||
};
|
||||
|
||||
pub const rtnl_link_stats = extern struct {
|
||||
/// total packets received
|
||||
rx_packets: u32,
|
||||
|
||||
/// total packets transmitted
|
||||
tx_packets: u32,
|
||||
|
||||
/// total bytes received
|
||||
rx_bytes: u32,
|
||||
|
||||
/// total bytes transmitted
|
||||
tx_bytes: u32,
|
||||
|
||||
/// bad packets received
|
||||
rx_errors: u32,
|
||||
|
||||
/// packet transmit problems
|
||||
tx_errors: u32,
|
||||
|
||||
/// no space in linux buffers
|
||||
rx_dropped: u32,
|
||||
|
||||
/// no space available in linux
|
||||
tx_dropped: u32,
|
||||
|
||||
/// multicast packets received
|
||||
multicast: u32,
|
||||
|
||||
collisions: u32,
|
||||
|
||||
// detailed rx_errors
|
||||
|
||||
rx_length_errors: u32,
|
||||
|
||||
/// receiver ring buff overflow
|
||||
rx_over_errors: u32,
|
||||
|
||||
/// recved pkt with crc error
|
||||
rx_crc_errors: u32,
|
||||
|
||||
/// recv'd frame alignment error
|
||||
rx_frame_errors: u32,
|
||||
|
||||
/// recv'r fifo overrun
|
||||
rx_fifo_errors: u32,
|
||||
|
||||
/// receiver missed packet
|
||||
rx_missed_errors: u32,
|
||||
|
||||
// detailed tx_errors
|
||||
tx_aborted_errors: u32,
|
||||
tx_carrier_errors: u32,
|
||||
tx_fifo_errors: u32,
|
||||
tx_heartbeat_errors: u32,
|
||||
tx_window_errors: u32,
|
||||
|
||||
// for cslip etc
|
||||
|
||||
rx_compressed: u32,
|
||||
tx_compressed: u32,
|
||||
|
||||
/// dropped, no handler found
|
||||
rx_nohandler: u32,
|
||||
};
|
||||
|
||||
pub const rtnl_link_stats64 = extern struct {
|
||||
/// total packets received
|
||||
rx_packets: u64,
|
||||
|
||||
/// total packets transmitted
|
||||
tx_packets: u64,
|
||||
|
||||
/// total bytes received
|
||||
rx_bytes: u64,
|
||||
|
||||
/// total bytes transmitted
|
||||
tx_bytes: u64,
|
||||
|
||||
/// bad packets received
|
||||
rx_errors: u64,
|
||||
|
||||
/// packet transmit problems
|
||||
tx_errors: u64,
|
||||
|
||||
/// no space in linux buffers
|
||||
rx_dropped: u64,
|
||||
|
||||
/// no space available in linux
|
||||
tx_dropped: u64,
|
||||
|
||||
/// multicast packets received
|
||||
multicast: u64,
|
||||
|
||||
collisions: u64,
|
||||
|
||||
// detailed rx_errors
|
||||
|
||||
rx_length_errors: u64,
|
||||
|
||||
/// receiver ring buff overflow
|
||||
rx_over_errors: u64,
|
||||
|
||||
/// recved pkt with crc error
|
||||
rx_crc_errors: u64,
|
||||
|
||||
/// recv'd frame alignment error
|
||||
rx_frame_errors: u64,
|
||||
|
||||
/// recv'r fifo overrun
|
||||
rx_fifo_errors: u64,
|
||||
|
||||
/// receiver missed packet
|
||||
rx_missed_errors: u64,
|
||||
|
||||
// detailed tx_errors
|
||||
tx_aborted_errors: u64,
|
||||
tx_carrier_errors: u64,
|
||||
tx_fifo_errors: u64,
|
||||
tx_heartbeat_errors: u64,
|
||||
tx_window_errors: u64,
|
||||
|
||||
// for cslip etc
|
||||
|
||||
rx_compressed: u64,
|
||||
tx_compressed: u64,
|
||||
|
||||
/// dropped, no handler found
|
||||
rx_nohandler: u64,
|
||||
};
|
||||
@ -1,621 +0,0 @@
|
||||
const std = @import("../../../std.zig");
|
||||
const linux = std.os.linux;
|
||||
const socklen_t = linux.socklen_t;
|
||||
const iovec = linux.iovec;
|
||||
const iovec_const = linux.iovec_const;
|
||||
const uid_t = linux.uid_t;
|
||||
const gid_t = linux.gid_t;
|
||||
const pid_t = linux.pid_t;
|
||||
const stack_t = linux.stack_t;
|
||||
const sigset_t = linux.sigset_t;
|
||||
pub const SYS = enum(usize) {
|
||||
restart_syscall = 0,
|
||||
exit = 1,
|
||||
fork = 2,
|
||||
read = 3,
|
||||
write = 4,
|
||||
open = 5,
|
||||
close = 6,
|
||||
waitpid = 7,
|
||||
creat = 8,
|
||||
link = 9,
|
||||
unlink = 10,
|
||||
execve = 11,
|
||||
chdir = 12,
|
||||
time = 13,
|
||||
mknod = 14,
|
||||
chmod = 15,
|
||||
lchown = 16,
|
||||
@"break" = 17,
|
||||
oldstat = 18,
|
||||
lseek = 19,
|
||||
getpid = 20,
|
||||
mount = 21,
|
||||
umount = 22,
|
||||
setuid = 23,
|
||||
getuid = 24,
|
||||
stime = 25,
|
||||
ptrace = 26,
|
||||
alarm = 27,
|
||||
oldfstat = 28,
|
||||
pause = 29,
|
||||
utime = 30,
|
||||
stty = 31,
|
||||
gtty = 32,
|
||||
access = 33,
|
||||
nice = 34,
|
||||
ftime = 35,
|
||||
sync = 36,
|
||||
kill = 37,
|
||||
rename = 38,
|
||||
mkdir = 39,
|
||||
rmdir = 40,
|
||||
dup = 41,
|
||||
pipe = 42,
|
||||
times = 43,
|
||||
prof = 44,
|
||||
brk = 45,
|
||||
setgid = 46,
|
||||
getgid = 47,
|
||||
signal = 48,
|
||||
geteuid = 49,
|
||||
getegid = 50,
|
||||
acct = 51,
|
||||
umount2 = 52,
|
||||
lock = 53,
|
||||
ioctl = 54,
|
||||
fcntl = 55,
|
||||
mpx = 56,
|
||||
setpgid = 57,
|
||||
ulimit = 58,
|
||||
oldolduname = 59,
|
||||
umask = 60,
|
||||
chroot = 61,
|
||||
ustat = 62,
|
||||
dup2 = 63,
|
||||
getppid = 64,
|
||||
getpgrp = 65,
|
||||
setsid = 66,
|
||||
sigaction = 67,
|
||||
sgetmask = 68,
|
||||
ssetmask = 69,
|
||||
setreuid = 70,
|
||||
setregid = 71,
|
||||
sigsuspend = 72,
|
||||
sigpending = 73,
|
||||
sethostname = 74,
|
||||
setrlimit = 75,
|
||||
getrlimit = 76,
|
||||
getrusage = 77,
|
||||
gettimeofday = 78,
|
||||
settimeofday = 79,
|
||||
getgroups = 80,
|
||||
setgroups = 81,
|
||||
select = 82,
|
||||
symlink = 83,
|
||||
oldlstat = 84,
|
||||
readlink = 85,
|
||||
uselib = 86,
|
||||
swapon = 87,
|
||||
reboot = 88,
|
||||
readdir = 89,
|
||||
mmap = 90,
|
||||
munmap = 91,
|
||||
truncate = 92,
|
||||
ftruncate = 93,
|
||||
fchmod = 94,
|
||||
fchown = 95,
|
||||
getpriority = 96,
|
||||
setpriority = 97,
|
||||
profil = 98,
|
||||
statfs = 99,
|
||||
fstatfs = 100,
|
||||
ioperm = 101,
|
||||
socketcall = 102,
|
||||
syslog = 103,
|
||||
setitimer = 104,
|
||||
getitimer = 105,
|
||||
stat = 106,
|
||||
lstat = 107,
|
||||
fstat = 108,
|
||||
olduname = 109,
|
||||
iopl = 110,
|
||||
vhangup = 111,
|
||||
idle = 112,
|
||||
vm86 = 113,
|
||||
wait4 = 114,
|
||||
swapoff = 115,
|
||||
sysinfo = 116,
|
||||
ipc = 117,
|
||||
fsync = 118,
|
||||
sigreturn = 119,
|
||||
clone = 120,
|
||||
setdomainname = 121,
|
||||
uname = 122,
|
||||
modify_ldt = 123,
|
||||
adjtimex = 124,
|
||||
mprotect = 125,
|
||||
sigprocmask = 126,
|
||||
create_module = 127,
|
||||
init_module = 128,
|
||||
delete_module = 129,
|
||||
get_kernel_syms = 130,
|
||||
quotactl = 131,
|
||||
getpgid = 132,
|
||||
fchdir = 133,
|
||||
bdflush = 134,
|
||||
sysfs = 135,
|
||||
personality = 136,
|
||||
afs_syscall = 137,
|
||||
setfsuid = 138,
|
||||
setfsgid = 139,
|
||||
_llseek = 140,
|
||||
getdents = 141,
|
||||
_newselect = 142,
|
||||
flock = 143,
|
||||
msync = 144,
|
||||
readv = 145,
|
||||
writev = 146,
|
||||
getsid = 147,
|
||||
fdatasync = 148,
|
||||
_sysctl = 149,
|
||||
mlock = 150,
|
||||
munlock = 151,
|
||||
mlockall = 152,
|
||||
munlockall = 153,
|
||||
sched_setparam = 154,
|
||||
sched_getparam = 155,
|
||||
sched_setscheduler = 156,
|
||||
sched_getscheduler = 157,
|
||||
sched_yield = 158,
|
||||
sched_get_priority_max = 159,
|
||||
sched_get_priority_min = 160,
|
||||
sched_rr_get_interval = 161,
|
||||
nanosleep = 162,
|
||||
mremap = 163,
|
||||
setresuid = 164,
|
||||
getresuid = 165,
|
||||
query_module = 166,
|
||||
poll = 167,
|
||||
nfsservctl = 168,
|
||||
setresgid = 169,
|
||||
getresgid = 170,
|
||||
prctl = 171,
|
||||
rt_sigreturn = 172,
|
||||
rt_sigaction = 173,
|
||||
rt_sigprocmask = 174,
|
||||
rt_sigpending = 175,
|
||||
rt_sigtimedwait = 176,
|
||||
rt_sigqueueinfo = 177,
|
||||
rt_sigsuspend = 178,
|
||||
pread64 = 179,
|
||||
pwrite64 = 180,
|
||||
chown = 181,
|
||||
getcwd = 182,
|
||||
capget = 183,
|
||||
capset = 184,
|
||||
sigaltstack = 185,
|
||||
sendfile = 186,
|
||||
getpmsg = 187,
|
||||
putpmsg = 188,
|
||||
vfork = 189,
|
||||
ugetrlimit = 190,
|
||||
readahead = 191,
|
||||
mmap2 = 192,
|
||||
truncate64 = 193,
|
||||
ftruncate64 = 194,
|
||||
stat64 = 195,
|
||||
lstat64 = 196,
|
||||
fstat64 = 197,
|
||||
pciconfig_read = 198,
|
||||
pciconfig_write = 199,
|
||||
pciconfig_iobase = 200,
|
||||
multiplexer = 201,
|
||||
getdents64 = 202,
|
||||
pivot_root = 203,
|
||||
fcntl64 = 204,
|
||||
madvise = 205,
|
||||
mincore = 206,
|
||||
gettid = 207,
|
||||
tkill = 208,
|
||||
setxattr = 209,
|
||||
lsetxattr = 210,
|
||||
fsetxattr = 211,
|
||||
getxattr = 212,
|
||||
lgetxattr = 213,
|
||||
fgetxattr = 214,
|
||||
listxattr = 215,
|
||||
llistxattr = 216,
|
||||
flistxattr = 217,
|
||||
removexattr = 218,
|
||||
lremovexattr = 219,
|
||||
fremovexattr = 220,
|
||||
futex = 221,
|
||||
sched_setaffinity = 222,
|
||||
sched_getaffinity = 223,
|
||||
tuxcall = 225,
|
||||
sendfile64 = 226,
|
||||
io_setup = 227,
|
||||
io_destroy = 228,
|
||||
io_getevents = 229,
|
||||
io_submit = 230,
|
||||
io_cancel = 231,
|
||||
set_tid_address = 232,
|
||||
fadvise64 = 233,
|
||||
exit_group = 234,
|
||||
lookup_dcookie = 235,
|
||||
epoll_create = 236,
|
||||
epoll_ctl = 237,
|
||||
epoll_wait = 238,
|
||||
remap_file_pages = 239,
|
||||
timer_create = 240,
|
||||
timer_settime = 241,
|
||||
timer_gettime = 242,
|
||||
timer_getoverrun = 243,
|
||||
timer_delete = 244,
|
||||
clock_settime = 245,
|
||||
clock_gettime = 246,
|
||||
clock_getres = 247,
|
||||
clock_nanosleep = 248,
|
||||
swapcontext = 249,
|
||||
tgkill = 250,
|
||||
utimes = 251,
|
||||
statfs64 = 252,
|
||||
fstatfs64 = 253,
|
||||
fadvise64_64 = 254,
|
||||
rtas = 255,
|
||||
sys_debug_setcontext = 256,
|
||||
migrate_pages = 258,
|
||||
mbind = 259,
|
||||
get_mempolicy = 260,
|
||||
set_mempolicy = 261,
|
||||
mq_open = 262,
|
||||
mq_unlink = 263,
|
||||
mq_timedsend = 264,
|
||||
mq_timedreceive = 265,
|
||||
mq_notify = 266,
|
||||
mq_getsetattr = 267,
|
||||
kexec_load = 268,
|
||||
add_key = 269,
|
||||
request_key = 270,
|
||||
keyctl = 271,
|
||||
waitid = 272,
|
||||
ioprio_set = 273,
|
||||
ioprio_get = 274,
|
||||
inotify_init = 275,
|
||||
inotify_add_watch = 276,
|
||||
inotify_rm_watch = 277,
|
||||
spu_run = 278,
|
||||
spu_create = 279,
|
||||
pselect6 = 280,
|
||||
ppoll = 281,
|
||||
unshare = 282,
|
||||
splice = 283,
|
||||
tee = 284,
|
||||
vmsplice = 285,
|
||||
openat = 286,
|
||||
mkdirat = 287,
|
||||
mknodat = 288,
|
||||
fchownat = 289,
|
||||
futimesat = 290,
|
||||
fstatat64 = 291,
|
||||
unlinkat = 292,
|
||||
renameat = 293,
|
||||
linkat = 294,
|
||||
symlinkat = 295,
|
||||
readlinkat = 296,
|
||||
fchmodat = 297,
|
||||
faccessat = 298,
|
||||
get_robust_list = 299,
|
||||
set_robust_list = 300,
|
||||
move_pages = 301,
|
||||
getcpu = 302,
|
||||
epoll_pwait = 303,
|
||||
utimensat = 304,
|
||||
signalfd = 305,
|
||||
timerfd_create = 306,
|
||||
eventfd = 307,
|
||||
sync_file_range = 308,
|
||||
fallocate = 309,
|
||||
subpage_prot = 310,
|
||||
timerfd_settime = 311,
|
||||
timerfd_gettime = 312,
|
||||
signalfd4 = 313,
|
||||
eventfd2 = 314,
|
||||
epoll_create1 = 315,
|
||||
dup3 = 316,
|
||||
pipe2 = 317,
|
||||
inotify_init1 = 318,
|
||||
perf_event_open = 319,
|
||||
preadv = 320,
|
||||
pwritev = 321,
|
||||
rt_tgsigqueueinfo = 322,
|
||||
fanotify_init = 323,
|
||||
fanotify_mark = 324,
|
||||
prlimit64 = 325,
|
||||
socket = 326,
|
||||
bind = 327,
|
||||
connect = 328,
|
||||
listen = 329,
|
||||
accept = 330,
|
||||
getsockname = 331,
|
||||
getpeername = 332,
|
||||
socketpair = 333,
|
||||
send = 334,
|
||||
sendto = 335,
|
||||
recv = 336,
|
||||
recvfrom = 337,
|
||||
shutdown = 338,
|
||||
setsockopt = 339,
|
||||
getsockopt = 340,
|
||||
sendmsg = 341,
|
||||
recvmsg = 342,
|
||||
recvmmsg = 343,
|
||||
accept4 = 344,
|
||||
name_to_handle_at = 345,
|
||||
open_by_handle_at = 346,
|
||||
clock_adjtime = 347,
|
||||
syncfs = 348,
|
||||
sendmmsg = 349,
|
||||
setns = 350,
|
||||
process_vm_readv = 351,
|
||||
process_vm_writev = 352,
|
||||
finit_module = 353,
|
||||
kcmp = 354,
|
||||
sched_setattr = 355,
|
||||
sched_getattr = 356,
|
||||
renameat2 = 357,
|
||||
seccomp = 358,
|
||||
getrandom = 359,
|
||||
memfd_create = 360,
|
||||
bpf = 361,
|
||||
execveat = 362,
|
||||
switch_endian = 363,
|
||||
userfaultfd = 364,
|
||||
membarrier = 365,
|
||||
mlock2 = 378,
|
||||
copy_file_range = 379,
|
||||
preadv2 = 380,
|
||||
pwritev2 = 381,
|
||||
kexec_file_load = 382,
|
||||
statx = 383,
|
||||
pkey_alloc = 384,
|
||||
pkey_free = 385,
|
||||
pkey_mprotect = 386,
|
||||
rseq = 387,
|
||||
io_pgetevents = 388,
|
||||
semget = 393,
|
||||
semctl = 394,
|
||||
shmget = 395,
|
||||
shmctl = 396,
|
||||
shmat = 397,
|
||||
shmdt = 398,
|
||||
msgget = 399,
|
||||
msgsnd = 400,
|
||||
msgrcv = 401,
|
||||
msgctl = 402,
|
||||
clock_gettime64 = 403,
|
||||
clock_settime64 = 404,
|
||||
clock_adjtime64 = 405,
|
||||
clock_getres_time64 = 406,
|
||||
clock_nanosleep_time64 = 407,
|
||||
timer_gettime64 = 408,
|
||||
timer_settime64 = 409,
|
||||
timerfd_gettime64 = 410,
|
||||
timerfd_settime64 = 411,
|
||||
utimensat_time64 = 412,
|
||||
pselect6_time64 = 413,
|
||||
ppoll_time64 = 414,
|
||||
io_pgetevents_time64 = 416,
|
||||
recvmmsg_time64 = 417,
|
||||
mq_timedsend_time64 = 418,
|
||||
mq_timedreceive_time64 = 419,
|
||||
semtimedop_time64 = 420,
|
||||
rt_sigtimedwait_time64 = 421,
|
||||
futex_time64 = 422,
|
||||
sched_rr_get_interval_time64 = 423,
|
||||
pidfd_send_signal = 424,
|
||||
io_uring_setup = 425,
|
||||
io_uring_enter = 426,
|
||||
io_uring_register = 427,
|
||||
open_tree = 428,
|
||||
move_mount = 429,
|
||||
fsopen = 430,
|
||||
fsconfig = 431,
|
||||
fsmount = 432,
|
||||
fspick = 433,
|
||||
pidfd_open = 434,
|
||||
clone3 = 435,
|
||||
close_range = 436,
|
||||
openat2 = 437,
|
||||
pidfd_getfd = 438,
|
||||
faccessat2 = 439,
|
||||
process_madvise = 440,
|
||||
};
|
||||
|
||||
pub const O_CREAT = 0o100;
|
||||
pub const O_EXCL = 0o200;
|
||||
pub const O_NOCTTY = 0o400;
|
||||
pub const O_TRUNC = 0o1000;
|
||||
pub const O_APPEND = 0o2000;
|
||||
pub const O_NONBLOCK = 0o4000;
|
||||
pub const O_DSYNC = 0o10000;
|
||||
pub const O_SYNC = 0o4010000;
|
||||
pub const O_RSYNC = 0o4010000;
|
||||
pub const O_DIRECTORY = 0o40000;
|
||||
pub const O_NOFOLLOW = 0o100000;
|
||||
pub const O_CLOEXEC = 0o2000000;
|
||||
|
||||
pub const O_ASYNC = 0o20000;
|
||||
pub const O_DIRECT = 0o400000;
|
||||
pub const O_LARGEFILE = 0o200000;
|
||||
pub const O_NOATIME = 0o1000000;
|
||||
pub const O_PATH = 0o10000000;
|
||||
pub const O_TMPFILE = 0o20040000;
|
||||
pub const O_NDELAY = O_NONBLOCK;
|
||||
|
||||
pub const F_DUPFD = 0;
|
||||
pub const F_GETFD = 1;
|
||||
pub const F_SETFD = 2;
|
||||
pub const F_GETFL = 3;
|
||||
pub const F_SETFL = 4;
|
||||
|
||||
pub const F_SETOWN = 8;
|
||||
pub const F_GETOWN = 9;
|
||||
pub const F_SETSIG = 10;
|
||||
pub const F_GETSIG = 11;
|
||||
|
||||
pub const F_GETLK = 12;
|
||||
pub const F_SETLK = 13;
|
||||
pub const F_SETLKW = 14;
|
||||
|
||||
pub const F_SETOWN_EX = 15;
|
||||
pub const F_GETOWN_EX = 16;
|
||||
|
||||
pub const F_GETOWNER_UIDS = 17;
|
||||
|
||||
pub const F_RDLCK = 0;
|
||||
pub const F_WRLCK = 1;
|
||||
pub const F_UNLCK = 2;
|
||||
|
||||
pub const LOCK_SH = 1;
|
||||
pub const LOCK_EX = 2;
|
||||
pub const LOCK_UN = 8;
|
||||
pub const LOCK_NB = 4;
|
||||
|
||||
/// stack-like segment
|
||||
pub const MAP_GROWSDOWN = 0x0100;
|
||||
|
||||
/// ETXTBSY
|
||||
pub const MAP_DENYWRITE = 0x0800;
|
||||
|
||||
/// mark it as an executable
|
||||
pub const MAP_EXECUTABLE = 0x1000;
|
||||
|
||||
/// pages are locked
|
||||
pub const MAP_LOCKED = 0x0080;
|
||||
|
||||
/// don't check for reservations
|
||||
pub const MAP_NORESERVE = 0x0040;
|
||||
|
||||
pub const VDSO_CGT_SYM = "__kernel_clock_gettime";
|
||||
pub const VDSO_CGT_VER = "LINUX_2.6.15";
|
||||
|
||||
pub const Flock = extern struct {
|
||||
l_type: i16,
|
||||
l_whence: i16,
|
||||
l_start: off_t,
|
||||
l_len: off_t,
|
||||
l_pid: pid_t,
|
||||
};
|
||||
|
||||
pub const msghdr = extern struct {
|
||||
msg_name: ?*sockaddr,
|
||||
msg_namelen: socklen_t,
|
||||
msg_iov: [*]iovec,
|
||||
msg_iovlen: usize,
|
||||
msg_control: ?*c_void,
|
||||
msg_controllen: socklen_t,
|
||||
msg_flags: i32,
|
||||
};
|
||||
|
||||
pub const msghdr_const = extern struct {
|
||||
msg_name: ?*const sockaddr,
|
||||
msg_namelen: socklen_t,
|
||||
msg_iov: [*]iovec_const,
|
||||
msg_iovlen: usize,
|
||||
msg_control: ?*c_void,
|
||||
msg_controllen: socklen_t,
|
||||
msg_flags: i32,
|
||||
};
|
||||
|
||||
pub const blksize_t = i32;
|
||||
pub const nlink_t = u32;
|
||||
pub const time_t = isize;
|
||||
pub const mode_t = u32;
|
||||
pub const off_t = i64;
|
||||
pub const ino_t = u64;
|
||||
pub const dev_t = u64;
|
||||
pub const blkcnt_t = i64;
|
||||
|
||||
// The `stat` definition used by the Linux kernel.
|
||||
pub const kernel_stat = extern struct {
|
||||
dev: dev_t,
|
||||
ino: ino_t,
|
||||
mode: mode_t,
|
||||
nlink: nlink_t,
|
||||
uid: uid_t,
|
||||
gid: gid_t,
|
||||
rdev: dev_t,
|
||||
__rdev_padding: i16,
|
||||
size: off_t,
|
||||
blksize: blksize_t,
|
||||
blocks: blkcnt_t,
|
||||
atim: timespec,
|
||||
mtim: timespec,
|
||||
ctim: timespec,
|
||||
__unused: [2]u32,
|
||||
|
||||
pub fn atime(self: @This()) timespec {
|
||||
return self.atim;
|
||||
}
|
||||
|
||||
pub fn mtime(self: @This()) timespec {
|
||||
return self.mtim;
|
||||
}
|
||||
|
||||
pub fn ctime(self: @This()) timespec {
|
||||
return self.ctim;
|
||||
}
|
||||
};
|
||||
|
||||
// The `stat64` definition used by the libc.
|
||||
pub const libc_stat = kernel_stat;
|
||||
|
||||
pub const timespec = extern struct {
|
||||
tv_sec: time_t,
|
||||
tv_nsec: isize,
|
||||
};
|
||||
|
||||
pub const timeval = extern struct {
|
||||
tv_sec: time_t,
|
||||
tv_usec: isize,
|
||||
};
|
||||
|
||||
pub const timezone = extern struct {
|
||||
tz_minuteswest: i32,
|
||||
tz_dsttime: i32,
|
||||
};
|
||||
|
||||
pub const greg_t = u32;
|
||||
pub const gregset_t = [48]greg_t;
|
||||
pub const fpregset_t = [33]f64;
|
||||
|
||||
pub const vrregset = extern struct {
|
||||
vrregs: [32][4]u32,
|
||||
vrsave: u32,
|
||||
_pad: [2]u32,
|
||||
vscr: u32,
|
||||
};
|
||||
pub const vrregset_t = vrregset;
|
||||
|
||||
pub const mcontext_t = extern struct {
|
||||
gp_regs: gregset_t,
|
||||
fp_regs: fpregset_t,
|
||||
v_regs: vrregset_t align(16),
|
||||
};
|
||||
|
||||
pub const ucontext_t = extern struct {
|
||||
flags: u32,
|
||||
link: *ucontext_t,
|
||||
stack: stack_t,
|
||||
pad: [7]i32,
|
||||
regs: *mcontext_t,
|
||||
sigmask: sigset_t,
|
||||
pad2: [3]i32,
|
||||
mcontext: mcontext_t,
|
||||
};
|
||||
|
||||
pub const Elf_Symndx = u32;
|
||||
|
||||
pub const MMAP2_UNIT = 4096;
|
||||
@ -1,604 +0,0 @@
|
||||
const std = @import("../../../std.zig");
|
||||
const linux = std.os.linux;
|
||||
const socklen_t = linux.socklen_t;
|
||||
const iovec = linux.iovec;
|
||||
const iovec_const = linux.iovec_const;
|
||||
const uid_t = linux.uid_t;
|
||||
const gid_t = linux.gid_t;
|
||||
const pid_t = linux.pid_t;
|
||||
const stack_t = linux.stack_t;
|
||||
const sigset_t = linux.sigset_t;
|
||||
pub const SYS = enum(usize) {
|
||||
restart_syscall = 0,
|
||||
exit = 1,
|
||||
fork = 2,
|
||||
read = 3,
|
||||
write = 4,
|
||||
open = 5,
|
||||
close = 6,
|
||||
waitpid = 7,
|
||||
creat = 8,
|
||||
link = 9,
|
||||
unlink = 10,
|
||||
execve = 11,
|
||||
chdir = 12,
|
||||
time = 13,
|
||||
mknod = 14,
|
||||
chmod = 15,
|
||||
lchown = 16,
|
||||
@"break" = 17,
|
||||
oldstat = 18,
|
||||
lseek = 19,
|
||||
getpid = 20,
|
||||
mount = 21,
|
||||
umount = 22,
|
||||
setuid = 23,
|
||||
getuid = 24,
|
||||
stime = 25,
|
||||
ptrace = 26,
|
||||
alarm = 27,
|
||||
oldfstat = 28,
|
||||
pause = 29,
|
||||
utime = 30,
|
||||
stty = 31,
|
||||
gtty = 32,
|
||||
access = 33,
|
||||
nice = 34,
|
||||
ftime = 35,
|
||||
sync = 36,
|
||||
kill = 37,
|
||||
rename = 38,
|
||||
mkdir = 39,
|
||||
rmdir = 40,
|
||||
dup = 41,
|
||||
pipe = 42,
|
||||
times = 43,
|
||||
prof = 44,
|
||||
brk = 45,
|
||||
setgid = 46,
|
||||
getgid = 47,
|
||||
signal = 48,
|
||||
geteuid = 49,
|
||||
getegid = 50,
|
||||
acct = 51,
|
||||
umount2 = 52,
|
||||
lock = 53,
|
||||
ioctl = 54,
|
||||
fcntl = 55,
|
||||
mpx = 56,
|
||||
setpgid = 57,
|
||||
ulimit = 58,
|
||||
oldolduname = 59,
|
||||
umask = 60,
|
||||
chroot = 61,
|
||||
ustat = 62,
|
||||
dup2 = 63,
|
||||
getppid = 64,
|
||||
getpgrp = 65,
|
||||
setsid = 66,
|
||||
sigaction = 67,
|
||||
sgetmask = 68,
|
||||
ssetmask = 69,
|
||||
setreuid = 70,
|
||||
setregid = 71,
|
||||
sigsuspend = 72,
|
||||
sigpending = 73,
|
||||
sethostname = 74,
|
||||
setrlimit = 75,
|
||||
getrlimit = 76,
|
||||
getrusage = 77,
|
||||
gettimeofday = 78,
|
||||
settimeofday = 79,
|
||||
getgroups = 80,
|
||||
setgroups = 81,
|
||||
select = 82,
|
||||
symlink = 83,
|
||||
oldlstat = 84,
|
||||
readlink = 85,
|
||||
uselib = 86,
|
||||
swapon = 87,
|
||||
reboot = 88,
|
||||
readdir = 89,
|
||||
mmap = 90,
|
||||
munmap = 91,
|
||||
truncate = 92,
|
||||
ftruncate = 93,
|
||||
fchmod = 94,
|
||||
fchown = 95,
|
||||
getpriority = 96,
|
||||
setpriority = 97,
|
||||
profil = 98,
|
||||
statfs = 99,
|
||||
fstatfs = 100,
|
||||
ioperm = 101,
|
||||
socketcall = 102,
|
||||
syslog = 103,
|
||||
setitimer = 104,
|
||||
getitimer = 105,
|
||||
stat = 106,
|
||||
lstat = 107,
|
||||
fstat = 108,
|
||||
olduname = 109,
|
||||
iopl = 110,
|
||||
vhangup = 111,
|
||||
idle = 112,
|
||||
vm86 = 113,
|
||||
wait4 = 114,
|
||||
swapoff = 115,
|
||||
sysinfo = 116,
|
||||
ipc = 117,
|
||||
fsync = 118,
|
||||
sigreturn = 119,
|
||||
clone = 120,
|
||||
setdomainname = 121,
|
||||
uname = 122,
|
||||
modify_ldt = 123,
|
||||
adjtimex = 124,
|
||||
mprotect = 125,
|
||||
sigprocmask = 126,
|
||||
create_module = 127,
|
||||
init_module = 128,
|
||||
delete_module = 129,
|
||||
get_kernel_syms = 130,
|
||||
quotactl = 131,
|
||||
getpgid = 132,
|
||||
fchdir = 133,
|
||||
bdflush = 134,
|
||||
sysfs = 135,
|
||||
personality = 136,
|
||||
afs_syscall = 137,
|
||||
setfsuid = 138,
|
||||
setfsgid = 139,
|
||||
_llseek = 140,
|
||||
getdents = 141,
|
||||
_newselect = 142,
|
||||
flock = 143,
|
||||
msync = 144,
|
||||
readv = 145,
|
||||
writev = 146,
|
||||
getsid = 147,
|
||||
fdatasync = 148,
|
||||
_sysctl = 149,
|
||||
mlock = 150,
|
||||
munlock = 151,
|
||||
mlockall = 152,
|
||||
munlockall = 153,
|
||||
sched_setparam = 154,
|
||||
sched_getparam = 155,
|
||||
sched_setscheduler = 156,
|
||||
sched_getscheduler = 157,
|
||||
sched_yield = 158,
|
||||
sched_get_priority_max = 159,
|
||||
sched_get_priority_min = 160,
|
||||
sched_rr_get_interval = 161,
|
||||
nanosleep = 162,
|
||||
mremap = 163,
|
||||
setresuid = 164,
|
||||
getresuid = 165,
|
||||
query_module = 166,
|
||||
poll = 167,
|
||||
nfsservctl = 168,
|
||||
setresgid = 169,
|
||||
getresgid = 170,
|
||||
prctl = 171,
|
||||
rt_sigreturn = 172,
|
||||
rt_sigaction = 173,
|
||||
rt_sigprocmask = 174,
|
||||
rt_sigpending = 175,
|
||||
rt_sigtimedwait = 176,
|
||||
rt_sigqueueinfo = 177,
|
||||
rt_sigsuspend = 178,
|
||||
pread64 = 179,
|
||||
pwrite64 = 180,
|
||||
chown = 181,
|
||||
getcwd = 182,
|
||||
capget = 183,
|
||||
capset = 184,
|
||||
sigaltstack = 185,
|
||||
sendfile = 186,
|
||||
getpmsg = 187,
|
||||
putpmsg = 188,
|
||||
vfork = 189,
|
||||
ugetrlimit = 190,
|
||||
readahead = 191,
|
||||
pciconfig_read = 198,
|
||||
pciconfig_write = 199,
|
||||
pciconfig_iobase = 200,
|
||||
multiplexer = 201,
|
||||
getdents64 = 202,
|
||||
pivot_root = 203,
|
||||
madvise = 205,
|
||||
mincore = 206,
|
||||
gettid = 207,
|
||||
tkill = 208,
|
||||
setxattr = 209,
|
||||
lsetxattr = 210,
|
||||
fsetxattr = 211,
|
||||
getxattr = 212,
|
||||
lgetxattr = 213,
|
||||
fgetxattr = 214,
|
||||
listxattr = 215,
|
||||
llistxattr = 216,
|
||||
flistxattr = 217,
|
||||
removexattr = 218,
|
||||
lremovexattr = 219,
|
||||
fremovexattr = 220,
|
||||
futex = 221,
|
||||
sched_setaffinity = 222,
|
||||
sched_getaffinity = 223,
|
||||
tuxcall = 225,
|
||||
io_setup = 227,
|
||||
io_destroy = 228,
|
||||
io_getevents = 229,
|
||||
io_submit = 230,
|
||||
io_cancel = 231,
|
||||
set_tid_address = 232,
|
||||
fadvise64 = 233,
|
||||
exit_group = 234,
|
||||
lookup_dcookie = 235,
|
||||
epoll_create = 236,
|
||||
epoll_ctl = 237,
|
||||
epoll_wait = 238,
|
||||
remap_file_pages = 239,
|
||||
timer_create = 240,
|
||||
timer_settime = 241,
|
||||
timer_gettime = 242,
|
||||
timer_getoverrun = 243,
|
||||
timer_delete = 244,
|
||||
clock_settime = 245,
|
||||
clock_gettime = 246,
|
||||
clock_getres = 247,
|
||||
clock_nanosleep = 248,
|
||||
swapcontext = 249,
|
||||
tgkill = 250,
|
||||
utimes = 251,
|
||||
statfs64 = 252,
|
||||
fstatfs64 = 253,
|
||||
rtas = 255,
|
||||
sys_debug_setcontext = 256,
|
||||
migrate_pages = 258,
|
||||
mbind = 259,
|
||||
get_mempolicy = 260,
|
||||
set_mempolicy = 261,
|
||||
mq_open = 262,
|
||||
mq_unlink = 263,
|
||||
mq_timedsend = 264,
|
||||
mq_timedreceive = 265,
|
||||
mq_notify = 266,
|
||||
mq_getsetattr = 267,
|
||||
kexec_load = 268,
|
||||
add_key = 269,
|
||||
request_key = 270,
|
||||
keyctl = 271,
|
||||
waitid = 272,
|
||||
ioprio_set = 273,
|
||||
ioprio_get = 274,
|
||||
inotify_init = 275,
|
||||
inotify_add_watch = 276,
|
||||
inotify_rm_watch = 277,
|
||||
spu_run = 278,
|
||||
spu_create = 279,
|
||||
pselect6 = 280,
|
||||
ppoll = 281,
|
||||
unshare = 282,
|
||||
splice = 283,
|
||||
tee = 284,
|
||||
vmsplice = 285,
|
||||
openat = 286,
|
||||
mkdirat = 287,
|
||||
mknodat = 288,
|
||||
fchownat = 289,
|
||||
futimesat = 290,
|
||||
fstatat = 291,
|
||||
unlinkat = 292,
|
||||
renameat = 293,
|
||||
linkat = 294,
|
||||
symlinkat = 295,
|
||||
readlinkat = 296,
|
||||
fchmodat = 297,
|
||||
faccessat = 298,
|
||||
get_robust_list = 299,
|
||||
set_robust_list = 300,
|
||||
move_pages = 301,
|
||||
getcpu = 302,
|
||||
epoll_pwait = 303,
|
||||
utimensat = 304,
|
||||
signalfd = 305,
|
||||
timerfd_create = 306,
|
||||
eventfd = 307,
|
||||
sync_file_range = 308,
|
||||
fallocate = 309,
|
||||
subpage_prot = 310,
|
||||
timerfd_settime = 311,
|
||||
timerfd_gettime = 312,
|
||||
signalfd4 = 313,
|
||||
eventfd2 = 314,
|
||||
epoll_create1 = 315,
|
||||
dup3 = 316,
|
||||
pipe2 = 317,
|
||||
inotify_init1 = 318,
|
||||
perf_event_open = 319,
|
||||
preadv = 320,
|
||||
pwritev = 321,
|
||||
rt_tgsigqueueinfo = 322,
|
||||
fanotify_init = 323,
|
||||
fanotify_mark = 324,
|
||||
prlimit64 = 325,
|
||||
socket = 326,
|
||||
bind = 327,
|
||||
connect = 328,
|
||||
listen = 329,
|
||||
accept = 330,
|
||||
getsockname = 331,
|
||||
getpeername = 332,
|
||||
socketpair = 333,
|
||||
send = 334,
|
||||
sendto = 335,
|
||||
recv = 336,
|
||||
recvfrom = 337,
|
||||
shutdown = 338,
|
||||
setsockopt = 339,
|
||||
getsockopt = 340,
|
||||
sendmsg = 341,
|
||||
recvmsg = 342,
|
||||
recvmmsg = 343,
|
||||
accept4 = 344,
|
||||
name_to_handle_at = 345,
|
||||
open_by_handle_at = 346,
|
||||
clock_adjtime = 347,
|
||||
syncfs = 348,
|
||||
sendmmsg = 349,
|
||||
setns = 350,
|
||||
process_vm_readv = 351,
|
||||
process_vm_writev = 352,
|
||||
finit_module = 353,
|
||||
kcmp = 354,
|
||||
sched_setattr = 355,
|
||||
sched_getattr = 356,
|
||||
renameat2 = 357,
|
||||
seccomp = 358,
|
||||
getrandom = 359,
|
||||
memfd_create = 360,
|
||||
bpf = 361,
|
||||
execveat = 362,
|
||||
switch_endian = 363,
|
||||
userfaultfd = 364,
|
||||
membarrier = 365,
|
||||
mlock2 = 378,
|
||||
copy_file_range = 379,
|
||||
preadv2 = 380,
|
||||
pwritev2 = 381,
|
||||
kexec_file_load = 382,
|
||||
statx = 383,
|
||||
pkey_alloc = 384,
|
||||
pkey_free = 385,
|
||||
pkey_mprotect = 386,
|
||||
rseq = 387,
|
||||
io_pgetevents = 388,
|
||||
semtimedop = 392,
|
||||
semget = 393,
|
||||
semctl = 394,
|
||||
shmget = 395,
|
||||
shmctl = 396,
|
||||
shmat = 397,
|
||||
shmdt = 398,
|
||||
msgget = 399,
|
||||
msgsnd = 400,
|
||||
msgrcv = 401,
|
||||
msgctl = 402,
|
||||
pidfd_send_signal = 424,
|
||||
io_uring_setup = 425,
|
||||
io_uring_enter = 426,
|
||||
io_uring_register = 427,
|
||||
open_tree = 428,
|
||||
move_mount = 429,
|
||||
fsopen = 430,
|
||||
fsconfig = 431,
|
||||
fsmount = 432,
|
||||
fspick = 433,
|
||||
pidfd_open = 434,
|
||||
clone3 = 435,
|
||||
close_range = 436,
|
||||
openat2 = 437,
|
||||
pidfd_getfd = 438,
|
||||
faccessat2 = 439,
|
||||
process_madvise = 440,
|
||||
epoll_pwait2 = 441,
|
||||
|
||||
_,
|
||||
};
|
||||
|
||||
pub const O_CREAT = 0o100;
|
||||
pub const O_EXCL = 0o200;
|
||||
pub const O_NOCTTY = 0o400;
|
||||
pub const O_TRUNC = 0o1000;
|
||||
pub const O_APPEND = 0o2000;
|
||||
pub const O_NONBLOCK = 0o4000;
|
||||
pub const O_DSYNC = 0o10000;
|
||||
pub const O_SYNC = 0o4010000;
|
||||
pub const O_RSYNC = 0o4010000;
|
||||
pub const O_DIRECTORY = 0o40000;
|
||||
pub const O_NOFOLLOW = 0o100000;
|
||||
pub const O_CLOEXEC = 0o2000000;
|
||||
|
||||
pub const O_ASYNC = 0o20000;
|
||||
pub const O_DIRECT = 0o400000;
|
||||
pub const O_LARGEFILE = 0o200000;
|
||||
pub const O_NOATIME = 0o1000000;
|
||||
pub const O_PATH = 0o10000000;
|
||||
pub const O_TMPFILE = 0o20200000;
|
||||
pub const O_NDELAY = O_NONBLOCK;
|
||||
|
||||
pub const F_DUPFD = 0;
|
||||
pub const F_GETFD = 1;
|
||||
pub const F_SETFD = 2;
|
||||
pub const F_GETFL = 3;
|
||||
pub const F_SETFL = 4;
|
||||
|
||||
pub const F_SETOWN = 8;
|
||||
pub const F_GETOWN = 9;
|
||||
pub const F_SETSIG = 10;
|
||||
pub const F_GETSIG = 11;
|
||||
|
||||
pub const F_GETLK = 5;
|
||||
pub const F_SETLK = 6;
|
||||
pub const F_SETLKW = 7;
|
||||
|
||||
pub const F_RDLCK = 0;
|
||||
pub const F_WRLCK = 1;
|
||||
pub const F_UNLCK = 2;
|
||||
|
||||
pub const LOCK_SH = 1;
|
||||
pub const LOCK_EX = 2;
|
||||
pub const LOCK_UN = 8;
|
||||
pub const LOCK_NB = 4;
|
||||
|
||||
pub const F_SETOWN_EX = 15;
|
||||
pub const F_GETOWN_EX = 16;
|
||||
|
||||
pub const F_GETOWNER_UIDS = 17;
|
||||
|
||||
/// stack-like segment
|
||||
pub const MAP_GROWSDOWN = 0x0100;
|
||||
|
||||
/// ETXTBSY
|
||||
pub const MAP_DENYWRITE = 0x0800;
|
||||
|
||||
/// mark it as an executable
|
||||
pub const MAP_EXECUTABLE = 0x1000;
|
||||
|
||||
/// pages are locked
|
||||
pub const MAP_LOCKED = 0x0080;
|
||||
|
||||
/// don't check for reservations
|
||||
pub const MAP_NORESERVE = 0x0040;
|
||||
|
||||
pub const VDSO_CGT_SYM = "__kernel_clock_gettime";
|
||||
pub const VDSO_CGT_VER = "LINUX_2.6.15";
|
||||
|
||||
pub const Flock = extern struct {
|
||||
l_type: i16,
|
||||
l_whence: i16,
|
||||
l_start: off_t,
|
||||
l_len: off_t,
|
||||
l_pid: pid_t,
|
||||
__unused: [4]u8,
|
||||
};
|
||||
|
||||
pub const msghdr = extern struct {
|
||||
msg_name: ?*sockaddr,
|
||||
msg_namelen: socklen_t,
|
||||
msg_iov: [*]iovec,
|
||||
msg_iovlen: usize,
|
||||
msg_control: ?*c_void,
|
||||
msg_controllen: usize,
|
||||
msg_flags: i32,
|
||||
};
|
||||
|
||||
pub const msghdr_const = extern struct {
|
||||
msg_name: ?*const sockaddr,
|
||||
msg_namelen: socklen_t,
|
||||
msg_iov: [*]iovec_const,
|
||||
msg_iovlen: usize,
|
||||
msg_control: ?*c_void,
|
||||
msg_controllen: usize,
|
||||
msg_flags: i32,
|
||||
};
|
||||
|
||||
pub const blksize_t = i64;
|
||||
pub const nlink_t = u64;
|
||||
pub const time_t = i64;
|
||||
pub const mode_t = u32;
|
||||
pub const off_t = i64;
|
||||
pub const ino_t = u64;
|
||||
pub const dev_t = u64;
|
||||
pub const blkcnt_t = i64;
|
||||
|
||||
// The `stat` definition used by the Linux kernel.
|
||||
pub const kernel_stat = extern struct {
|
||||
dev: dev_t,
|
||||
ino: ino_t,
|
||||
nlink: nlink_t,
|
||||
mode: mode_t,
|
||||
uid: uid_t,
|
||||
gid: gid_t,
|
||||
rdev: dev_t,
|
||||
size: off_t,
|
||||
blksize: blksize_t,
|
||||
blocks: blkcnt_t,
|
||||
atim: timespec,
|
||||
mtim: timespec,
|
||||
ctim: timespec,
|
||||
__unused: [3]u64,
|
||||
|
||||
pub fn atime(self: @This()) timespec {
|
||||
return self.atim;
|
||||
}
|
||||
|
||||
pub fn mtime(self: @This()) timespec {
|
||||
return self.mtim;
|
||||
}
|
||||
|
||||
pub fn ctime(self: @This()) timespec {
|
||||
return self.ctim;
|
||||
}
|
||||
};
|
||||
|
||||
// The `stat64` definition used by the libc.
|
||||
pub const libc_stat = kernel_stat;
|
||||
|
||||
pub const timespec = extern struct {
|
||||
tv_sec: time_t,
|
||||
tv_nsec: isize,
|
||||
};
|
||||
|
||||
pub const timeval = extern struct {
|
||||
tv_sec: isize,
|
||||
tv_usec: isize,
|
||||
};
|
||||
|
||||
pub const timezone = extern struct {
|
||||
tz_minuteswest: i32,
|
||||
tz_dsttime: i32,
|
||||
};
|
||||
|
||||
pub const greg_t = u64;
|
||||
pub const gregset_t = [48]greg_t;
|
||||
pub const fpregset_t = [33]f64;
|
||||
|
||||
/// The position of the vscr register depends on endianness.
|
||||
/// On C, macros are used to change vscr_word's offset to
|
||||
/// account for this. Here we'll just define vscr_word_le
|
||||
/// and vscr_word_be. Code must take care to use the correct one.
|
||||
pub const vrregset = extern struct {
|
||||
vrregs: [32][4]u32 align(16),
|
||||
vscr_word_le: u32,
|
||||
_pad1: [2]u32,
|
||||
vscr_word_be: u32,
|
||||
vrsave: u32,
|
||||
_pad2: [3]u32,
|
||||
};
|
||||
pub const vrregset_t = vrregset;
|
||||
|
||||
pub const mcontext_t = extern struct {
|
||||
__unused: [4]u64,
|
||||
signal: i32,
|
||||
_pad0: i32,
|
||||
handler: u64,
|
||||
oldmask: u64,
|
||||
regs: ?*c_void,
|
||||
gp_regs: gregset_t,
|
||||
fp_regs: fpregset_t,
|
||||
v_regs: *vrregset_t,
|
||||
vmx_reserve: [34 + 34 + 32 + 1]i64,
|
||||
};
|
||||
|
||||
pub const ucontext_t = extern struct {
|
||||
flags: u32,
|
||||
link: *ucontext_t,
|
||||
stack: stack_t,
|
||||
sigmask: sigset_t,
|
||||
mcontext: mcontext_t,
|
||||
};
|
||||
|
||||
pub const Elf_Symndx = u32;
|
||||
@ -1,234 +0,0 @@
|
||||
pub const PR = enum(i32) {
|
||||
SET_PDEATHSIG = 1,
|
||||
GET_PDEATHSIG = 2,
|
||||
|
||||
GET_DUMPABLE = 3,
|
||||
SET_DUMPABLE = 4,
|
||||
|
||||
GET_UNALIGN = 5,
|
||||
SET_UNALIGN = 6,
|
||||
|
||||
GET_KEEPCAPS = 7,
|
||||
SET_KEEPCAPS = 8,
|
||||
|
||||
GET_FPEMU = 9,
|
||||
SET_FPEMU = 10,
|
||||
|
||||
GET_FPEXC = 11,
|
||||
SET_FPEXC = 12,
|
||||
|
||||
GET_TIMING = 13,
|
||||
SET_TIMING = 14,
|
||||
|
||||
SET_NAME = 15,
|
||||
GET_NAME = 16,
|
||||
|
||||
GET_ENDIAN = 19,
|
||||
SET_ENDIAN = 20,
|
||||
|
||||
GET_SECCOMP = 21,
|
||||
SET_SECCOMP = 22,
|
||||
|
||||
CAPBSET_READ = 23,
|
||||
CAPBSET_DROP = 24,
|
||||
|
||||
GET_TSC = 25,
|
||||
SET_TSC = 26,
|
||||
|
||||
GET_SECUREBITS = 27,
|
||||
SET_SECUREBITS = 28,
|
||||
|
||||
SET_TIMERSLACK = 29,
|
||||
GET_TIMERSLACK = 30,
|
||||
|
||||
TASK_PERF_EVENTS_DISABLE = 31,
|
||||
TASK_PERF_EVENTS_ENABLE = 32,
|
||||
|
||||
MCE_KILL = 33,
|
||||
|
||||
MCE_KILL_GET = 34,
|
||||
|
||||
SET_MM = 35,
|
||||
|
||||
SET_PTRACER = 0x59616d61,
|
||||
|
||||
SET_CHILD_SUBREAPER = 36,
|
||||
GET_CHILD_SUBREAPER = 37,
|
||||
|
||||
SET_NO_NEW_PRIVS = 38,
|
||||
GET_NO_NEW_PRIVS = 39,
|
||||
|
||||
GET_TID_ADDRESS = 40,
|
||||
|
||||
SET_THP_DISABLE = 41,
|
||||
GET_THP_DISABLE = 42,
|
||||
|
||||
MPX_ENABLE_MANAGEMENT = 43,
|
||||
MPX_DISABLE_MANAGEMENT = 44,
|
||||
|
||||
SET_FP_MODE = 45,
|
||||
GET_FP_MODE = 46,
|
||||
|
||||
CAP_AMBIENT = 47,
|
||||
|
||||
SVE_SET_VL = 50,
|
||||
SVE_GET_VL = 51,
|
||||
|
||||
GET_SPECULATION_CTRL = 52,
|
||||
SET_SPECULATION_CTRL = 53,
|
||||
|
||||
_,
|
||||
};
|
||||
|
||||
pub const PR_SET_PDEATHSIG = @enumToInt(PR.SET_PDEATHSIG);
|
||||
pub const PR_GET_PDEATHSIG = @enumToInt(PR.GET_PDEATHSIG);
|
||||
|
||||
pub const PR_GET_DUMPABLE = @enumToInt(PR.GET_DUMPABLE);
|
||||
pub const PR_SET_DUMPABLE = @enumToInt(PR.SET_DUMPABLE);
|
||||
|
||||
pub const PR_GET_UNALIGN = @enumToInt(PR.GET_UNALIGN);
|
||||
pub const PR_SET_UNALIGN = @enumToInt(PR.SET_UNALIGN);
|
||||
pub const PR_UNALIGN_NOPRINT = 1;
|
||||
pub const PR_UNALIGN_SIGBUS = 2;
|
||||
|
||||
pub const PR_GET_KEEPCAPS = @enumToInt(PR.GET_KEEPCAPS);
|
||||
pub const PR_SET_KEEPCAPS = @enumToInt(PR.SET_KEEPCAPS);
|
||||
|
||||
pub const PR_GET_FPEMU = @enumToInt(PR.GET_FPEMU);
|
||||
pub const PR_SET_FPEMU = @enumToInt(PR.SET_FPEMU);
|
||||
pub const PR_FPEMU_NOPRINT = 1;
|
||||
pub const PR_FPEMU_SIGFPE = 2;
|
||||
|
||||
pub const PR_GET_FPEXC = @enumToInt(PR.GET_FPEXC);
|
||||
pub const PR_SET_FPEXC = @enumToInt(PR.SET_FPEXC);
|
||||
pub const PR_FP_EXC_SW_ENABLE = 0x80;
|
||||
pub const PR_FP_EXC_DIV = 0x010000;
|
||||
pub const PR_FP_EXC_OVF = 0x020000;
|
||||
pub const PR_FP_EXC_UND = 0x040000;
|
||||
pub const PR_FP_EXC_RES = 0x080000;
|
||||
pub const PR_FP_EXC_INV = 0x100000;
|
||||
pub const PR_FP_EXC_DISABLED = 0;
|
||||
pub const PR_FP_EXC_NONRECOV = 1;
|
||||
pub const PR_FP_EXC_ASYNC = 2;
|
||||
pub const PR_FP_EXC_PRECISE = 3;
|
||||
|
||||
pub const PR_GET_TIMING = @enumToInt(PR.GET_TIMING);
|
||||
pub const PR_SET_TIMING = @enumToInt(PR.SET_TIMING);
|
||||
pub const PR_TIMING_STATISTICAL = 0;
|
||||
pub const PR_TIMING_TIMESTAMP = 1;
|
||||
|
||||
pub const PR_SET_NAME = @enumToInt(PR.SET_NAME);
|
||||
pub const PR_GET_NAME = @enumToInt(PR.GET_NAME);
|
||||
|
||||
pub const PR_GET_ENDIAN = @enumToInt(PR.GET_ENDIAN);
|
||||
pub const PR_SET_ENDIAN = @enumToInt(PR.SET_ENDIAN);
|
||||
pub const PR_ENDIAN_BIG = 0;
|
||||
pub const PR_ENDIAN_LITTLE = 1;
|
||||
pub const PR_ENDIAN_PPC_LITTLE = 2;
|
||||
|
||||
pub const PR_GET_SECCOMP = @enumToInt(PR.GET_SECCOMP);
|
||||
pub const PR_SET_SECCOMP = @enumToInt(PR.SET_SECCOMP);
|
||||
|
||||
pub const PR_CAPBSET_READ = @enumToInt(PR.CAPBSET_READ);
|
||||
pub const PR_CAPBSET_DROP = @enumToInt(PR.CAPBSET_DROP);
|
||||
|
||||
pub const PR_GET_TSC = @enumToInt(PR.GET_TSC);
|
||||
pub const PR_SET_TSC = @enumToInt(PR.SET_TSC);
|
||||
pub const PR_TSC_ENABLE = 1;
|
||||
pub const PR_TSC_SIGSEGV = 2;
|
||||
|
||||
pub const PR_GET_SECUREBITS = @enumToInt(PR.GET_SECUREBITS);
|
||||
pub const PR_SET_SECUREBITS = @enumToInt(PR.SET_SECUREBITS);
|
||||
|
||||
pub const PR_SET_TIMERSLACK = @enumToInt(PR.SET_TIMERSLACK);
|
||||
pub const PR_GET_TIMERSLACK = @enumToInt(PR.GET_TIMERSLACK);
|
||||
|
||||
pub const PR_TASK_PERF_EVENTS_DISABLE = @enumToInt(PR.TASK_PERF_EVENTS_DISABLE);
|
||||
pub const PR_TASK_PERF_EVENTS_ENABLE = @enumToInt(PR.TASK_PERF_EVENTS_ENABLE);
|
||||
|
||||
pub const PR_MCE_KILL = @enumToInt(PR.MCE_KILL);
|
||||
pub const PR_MCE_KILL_CLEAR = 0;
|
||||
pub const PR_MCE_KILL_SET = 1;
|
||||
|
||||
pub const PR_MCE_KILL_LATE = 0;
|
||||
pub const PR_MCE_KILL_EARLY = 1;
|
||||
pub const PR_MCE_KILL_DEFAULT = 2;
|
||||
|
||||
pub const PR_MCE_KILL_GET = @enumToInt(PR.MCE_KILL_GET);
|
||||
|
||||
pub const PR_SET_MM = @enumToInt(PR.SET_MM);
|
||||
pub const PR_SET_MM_START_CODE = 1;
|
||||
pub const PR_SET_MM_END_CODE = 2;
|
||||
pub const PR_SET_MM_START_DATA = 3;
|
||||
pub const PR_SET_MM_END_DATA = 4;
|
||||
pub const PR_SET_MM_START_STACK = 5;
|
||||
pub const PR_SET_MM_START_BRK = 6;
|
||||
pub const PR_SET_MM_BRK = 7;
|
||||
pub const PR_SET_MM_ARG_START = 8;
|
||||
pub const PR_SET_MM_ARG_END = 9;
|
||||
pub const PR_SET_MM_ENV_START = 10;
|
||||
pub const PR_SET_MM_ENV_END = 11;
|
||||
pub const PR_SET_MM_AUXV = 12;
|
||||
pub const PR_SET_MM_EXE_FILE = 13;
|
||||
pub const PR_SET_MM_MAP = 14;
|
||||
pub const PR_SET_MM_MAP_SIZE = 15;
|
||||
|
||||
pub const prctl_mm_map = extern struct {
|
||||
start_code: u64,
|
||||
end_code: u64,
|
||||
start_data: u64,
|
||||
end_data: u64,
|
||||
start_brk: u64,
|
||||
brk: u64,
|
||||
start_stack: u64,
|
||||
arg_start: u64,
|
||||
arg_end: u64,
|
||||
env_start: u64,
|
||||
env_end: u64,
|
||||
auxv: *u64,
|
||||
auxv_size: u32,
|
||||
exe_fd: u32,
|
||||
};
|
||||
|
||||
pub const PR_SET_PTRACER = @enumToInt(PR.SET_PTRACER);
|
||||
pub const PR_SET_PTRACER_ANY = std.math.maxInt(c_ulong);
|
||||
|
||||
pub const PR_SET_CHILD_SUBREAPER = @enumToInt(PR.SET_CHILD_SUBREAPER);
|
||||
pub const PR_GET_CHILD_SUBREAPER = @enumToInt(PR.GET_CHILD_SUBREAPER);
|
||||
|
||||
pub const PR_SET_NO_NEW_PRIVS = @enumToInt(PR.SET_NO_NEW_PRIVS);
|
||||
pub const PR_GET_NO_NEW_PRIVS = @enumToInt(PR.GET_NO_NEW_PRIVS);
|
||||
|
||||
pub const PR_GET_TID_ADDRESS = @enumToInt(PR.GET_TID_ADDRESS);
|
||||
|
||||
pub const PR_SET_THP_DISABLE = @enumToInt(PR.SET_THP_DISABLE);
|
||||
pub const PR_GET_THP_DISABLE = @enumToInt(PR.GET_THP_DISABLE);
|
||||
|
||||
pub const PR_MPX_ENABLE_MANAGEMENT = @enumToInt(PR.MPX_ENABLE_MANAGEMENT);
|
||||
pub const PR_MPX_DISABLE_MANAGEMENT = @enumToInt(PR.MPX_DISABLE_MANAGEMENT);
|
||||
|
||||
pub const PR_SET_FP_MODE = @enumToInt(PR.SET_FP_MODE);
|
||||
pub const PR_GET_FP_MODE = @enumToInt(PR.GET_FP_MODE);
|
||||
pub const PR_FP_MODE_FR = 1 << 0;
|
||||
pub const PR_FP_MODE_FRE = 1 << 1;
|
||||
|
||||
pub const PR_CAP_AMBIENT = @enumToInt(PR.CAP_AMBIENT);
|
||||
pub const PR_CAP_AMBIENT_IS_SET = 1;
|
||||
pub const PR_CAP_AMBIENT_RAISE = 2;
|
||||
pub const PR_CAP_AMBIENT_LOWER = 3;
|
||||
pub const PR_CAP_AMBIENT_CLEAR_ALL = 4;
|
||||
|
||||
pub const PR_SVE_SET_VL = @enumToInt(PR.SVE_SET_VL);
|
||||
pub const PR_SVE_SET_VL_ONEXEC = 1 << 18;
|
||||
pub const PR_SVE_GET_VL = @enumToInt(PR.SVE_GET_VL);
|
||||
pub const PR_SVE_VL_LEN_MASK = 0xffff;
|
||||
pub const PR_SVE_VL_INHERIT = 1 << 17;
|
||||
|
||||
pub const PR_GET_SPECULATION_CTRL = @enumToInt(PR.GET_SPECULATION_CTRL);
|
||||
pub const PR_SET_SPECULATION_CTRL = @enumToInt(PR.SET_SPECULATION_CTRL);
|
||||
pub const PR_SPEC_STORE_BYPASS = 0;
|
||||
pub const PR_SPEC_NOT_AFFECTED = 0;
|
||||
pub const PR_SPEC_PRCTL = 1 << 0;
|
||||
pub const PR_SPEC_ENABLE = 1 << 1;
|
||||
pub const PR_SPEC_DISABLE = 1 << 2;
|
||||
pub const PR_SPEC_FORCE_DISABLE = 1 << 3;
|
||||
@ -1,423 +0,0 @@
|
||||
// riscv64-specific declarations that are intended to be imported into the POSIX namespace.
|
||||
const std = @import("../../../std.zig");
|
||||
const uid_t = std.os.linux.uid_t;
|
||||
const gid_t = std.os.linux.gid_t;
|
||||
const pid_t = std.os.linux.pid_t;
|
||||
|
||||
pub const SYS = enum(usize) {
|
||||
pub const arch_specific_syscall = 244;
|
||||
|
||||
io_setup = 0,
|
||||
io_destroy = 1,
|
||||
io_submit = 2,
|
||||
io_cancel = 3,
|
||||
io_getevents = 4,
|
||||
setxattr = 5,
|
||||
lsetxattr = 6,
|
||||
fsetxattr = 7,
|
||||
getxattr = 8,
|
||||
lgetxattr = 9,
|
||||
fgetxattr = 10,
|
||||
listxattr = 11,
|
||||
llistxattr = 12,
|
||||
flistxattr = 13,
|
||||
removexattr = 14,
|
||||
lremovexattr = 15,
|
||||
fremovexattr = 16,
|
||||
getcwd = 17,
|
||||
lookup_dcookie = 18,
|
||||
eventfd2 = 19,
|
||||
epoll_create1 = 20,
|
||||
epoll_ctl = 21,
|
||||
epoll_pwait = 22,
|
||||
dup = 23,
|
||||
dup3 = 24,
|
||||
fcntl = 25,
|
||||
inotify_init1 = 26,
|
||||
inotify_add_watch = 27,
|
||||
inotify_rm_watch = 28,
|
||||
ioctl = 29,
|
||||
ioprio_set = 30,
|
||||
ioprio_get = 31,
|
||||
flock = 32,
|
||||
mknodat = 33,
|
||||
mkdirat = 34,
|
||||
unlinkat = 35,
|
||||
symlinkat = 36,
|
||||
linkat = 37,
|
||||
umount2 = 39,
|
||||
mount = 40,
|
||||
pivot_root = 41,
|
||||
nfsservctl = 42,
|
||||
statfs = 43,
|
||||
fstatfs = 44,
|
||||
truncate = 45,
|
||||
ftruncate = 46,
|
||||
fallocate = 47,
|
||||
faccessat = 48,
|
||||
chdir = 49,
|
||||
fchdir = 50,
|
||||
chroot = 51,
|
||||
fchmod = 52,
|
||||
fchmodat = 53,
|
||||
fchownat = 54,
|
||||
fchown = 55,
|
||||
openat = 56,
|
||||
close = 57,
|
||||
vhangup = 58,
|
||||
pipe2 = 59,
|
||||
quotactl = 60,
|
||||
getdents64 = 61,
|
||||
lseek = 62,
|
||||
read = 63,
|
||||
write = 64,
|
||||
readv = 65,
|
||||
writev = 66,
|
||||
pread64 = 67,
|
||||
pwrite64 = 68,
|
||||
preadv = 69,
|
||||
pwritev = 70,
|
||||
sendfile = 71,
|
||||
pselect6 = 72,
|
||||
ppoll = 73,
|
||||
signalfd4 = 74,
|
||||
vmsplice = 75,
|
||||
splice = 76,
|
||||
tee = 77,
|
||||
readlinkat = 78,
|
||||
fstatat = 79,
|
||||
fstat = 80,
|
||||
sync = 81,
|
||||
fsync = 82,
|
||||
fdatasync = 83,
|
||||
sync_file_range = 84,
|
||||
timerfd_create = 85,
|
||||
timerfd_settime = 86,
|
||||
timerfd_gettime = 87,
|
||||
utimensat = 88,
|
||||
acct = 89,
|
||||
capget = 90,
|
||||
capset = 91,
|
||||
personality = 92,
|
||||
exit = 93,
|
||||
exit_group = 94,
|
||||
waitid = 95,
|
||||
set_tid_address = 96,
|
||||
unshare = 97,
|
||||
futex = 98,
|
||||
set_robust_list = 99,
|
||||
get_robust_list = 100,
|
||||
nanosleep = 101,
|
||||
getitimer = 102,
|
||||
setitimer = 103,
|
||||
kexec_load = 104,
|
||||
init_module = 105,
|
||||
delete_module = 106,
|
||||
timer_create = 107,
|
||||
timer_gettime = 108,
|
||||
timer_getoverrun = 109,
|
||||
timer_settime = 110,
|
||||
timer_delete = 111,
|
||||
clock_settime = 112,
|
||||
clock_gettime = 113,
|
||||
clock_getres = 114,
|
||||
clock_nanosleep = 115,
|
||||
syslog = 116,
|
||||
ptrace = 117,
|
||||
sched_setparam = 118,
|
||||
sched_setscheduler = 119,
|
||||
sched_getscheduler = 120,
|
||||
sched_getparam = 121,
|
||||
sched_setaffinity = 122,
|
||||
sched_getaffinity = 123,
|
||||
sched_yield = 124,
|
||||
sched_get_priority_max = 125,
|
||||
sched_get_priority_min = 126,
|
||||
sched_rr_get_interval = 127,
|
||||
restart_syscall = 128,
|
||||
kill = 129,
|
||||
tkill = 130,
|
||||
tgkill = 131,
|
||||
sigaltstack = 132,
|
||||
rt_sigsuspend = 133,
|
||||
rt_sigaction = 134,
|
||||
rt_sigprocmask = 135,
|
||||
rt_sigpending = 136,
|
||||
rt_sigtimedwait = 137,
|
||||
rt_sigqueueinfo = 138,
|
||||
rt_sigreturn = 139,
|
||||
setpriority = 140,
|
||||
getpriority = 141,
|
||||
reboot = 142,
|
||||
setregid = 143,
|
||||
setgid = 144,
|
||||
setreuid = 145,
|
||||
setuid = 146,
|
||||
setresuid = 147,
|
||||
getresuid = 148,
|
||||
setresgid = 149,
|
||||
getresgid = 150,
|
||||
setfsuid = 151,
|
||||
setfsgid = 152,
|
||||
times = 153,
|
||||
setpgid = 154,
|
||||
getpgid = 155,
|
||||
getsid = 156,
|
||||
setsid = 157,
|
||||
getgroups = 158,
|
||||
setgroups = 159,
|
||||
uname = 160,
|
||||
sethostname = 161,
|
||||
setdomainname = 162,
|
||||
getrlimit = 163,
|
||||
setrlimit = 164,
|
||||
getrusage = 165,
|
||||
umask = 166,
|
||||
prctl = 167,
|
||||
getcpu = 168,
|
||||
gettimeofday = 169,
|
||||
settimeofday = 170,
|
||||
adjtimex = 171,
|
||||
getpid = 172,
|
||||
getppid = 173,
|
||||
getuid = 174,
|
||||
geteuid = 175,
|
||||
getgid = 176,
|
||||
getegid = 177,
|
||||
gettid = 178,
|
||||
sysinfo = 179,
|
||||
mq_open = 180,
|
||||
mq_unlink = 181,
|
||||
mq_timedsend = 182,
|
||||
mq_timedreceive = 183,
|
||||
mq_notify = 184,
|
||||
mq_getsetattr = 185,
|
||||
msgget = 186,
|
||||
msgctl = 187,
|
||||
msgrcv = 188,
|
||||
msgsnd = 189,
|
||||
semget = 190,
|
||||
semctl = 191,
|
||||
semtimedop = 192,
|
||||
semop = 193,
|
||||
shmget = 194,
|
||||
shmctl = 195,
|
||||
shmat = 196,
|
||||
shmdt = 197,
|
||||
socket = 198,
|
||||
socketpair = 199,
|
||||
bind = 200,
|
||||
listen = 201,
|
||||
accept = 202,
|
||||
connect = 203,
|
||||
getsockname = 204,
|
||||
getpeername = 205,
|
||||
sendto = 206,
|
||||
recvfrom = 207,
|
||||
setsockopt = 208,
|
||||
getsockopt = 209,
|
||||
shutdown = 210,
|
||||
sendmsg = 211,
|
||||
recvmsg = 212,
|
||||
readahead = 213,
|
||||
brk = 214,
|
||||
munmap = 215,
|
||||
mremap = 216,
|
||||
add_key = 217,
|
||||
request_key = 218,
|
||||
keyctl = 219,
|
||||
clone = 220,
|
||||
execve = 221,
|
||||
mmap = 222,
|
||||
fadvise64 = 223,
|
||||
swapon = 224,
|
||||
swapoff = 225,
|
||||
mprotect = 226,
|
||||
msync = 227,
|
||||
mlock = 228,
|
||||
munlock = 229,
|
||||
mlockall = 230,
|
||||
munlockall = 231,
|
||||
mincore = 232,
|
||||
madvise = 233,
|
||||
remap_file_pages = 234,
|
||||
mbind = 235,
|
||||
get_mempolicy = 236,
|
||||
set_mempolicy = 237,
|
||||
migrate_pages = 238,
|
||||
move_pages = 239,
|
||||
rt_tgsigqueueinfo = 240,
|
||||
perf_event_open = 241,
|
||||
accept4 = 242,
|
||||
recvmmsg = 243,
|
||||
|
||||
riscv_flush_icache = arch_specific_syscall + 15,
|
||||
|
||||
wait4 = 260,
|
||||
prlimit64 = 261,
|
||||
fanotify_init = 262,
|
||||
fanotify_mark = 263,
|
||||
name_to_handle_at = 264,
|
||||
open_by_handle_at = 265,
|
||||
clock_adjtime = 266,
|
||||
syncfs = 267,
|
||||
setns = 268,
|
||||
sendmmsg = 269,
|
||||
process_vm_readv = 270,
|
||||
process_vm_writev = 271,
|
||||
kcmp = 272,
|
||||
finit_module = 273,
|
||||
sched_setattr = 274,
|
||||
sched_getattr = 275,
|
||||
renameat2 = 276,
|
||||
seccomp = 277,
|
||||
getrandom = 278,
|
||||
memfd_create = 279,
|
||||
bpf = 280,
|
||||
execveat = 281,
|
||||
userfaultfd = 282,
|
||||
membarrier = 283,
|
||||
mlock2 = 284,
|
||||
copy_file_range = 285,
|
||||
preadv2 = 286,
|
||||
pwritev2 = 287,
|
||||
pkey_mprotect = 288,
|
||||
pkey_alloc = 289,
|
||||
pkey_free = 290,
|
||||
statx = 291,
|
||||
io_pgetevents = 292,
|
||||
rseq = 293,
|
||||
kexec_file_load = 294,
|
||||
pidfd_send_signal = 424,
|
||||
io_uring_setup = 425,
|
||||
io_uring_enter = 426,
|
||||
io_uring_register = 427,
|
||||
open_tree = 428,
|
||||
move_mount = 429,
|
||||
fsopen = 430,
|
||||
fsconfig = 431,
|
||||
fsmount = 432,
|
||||
fspick = 433,
|
||||
pidfd_open = 434,
|
||||
clone3 = 435,
|
||||
close_range = 436,
|
||||
openat2 = 437,
|
||||
pidfd_getfd = 438,
|
||||
faccessat2 = 439,
|
||||
process_madvise = 440,
|
||||
epoll_pwait2 = 441,
|
||||
|
||||
_,
|
||||
};
|
||||
|
||||
pub const O_CREAT = 0o100;
|
||||
pub const O_EXCL = 0o200;
|
||||
pub const O_NOCTTY = 0o400;
|
||||
pub const O_TRUNC = 0o1000;
|
||||
pub const O_APPEND = 0o2000;
|
||||
pub const O_NONBLOCK = 0o4000;
|
||||
pub const O_DSYNC = 0o10000;
|
||||
pub const O_SYNC = 0o4010000;
|
||||
pub const O_RSYNC = 0o4010000;
|
||||
pub const O_DIRECTORY = 0o200000;
|
||||
pub const O_NOFOLLOW = 0o400000;
|
||||
pub const O_CLOEXEC = 0o2000000;
|
||||
|
||||
pub const O_ASYNC = 0o20000;
|
||||
pub const O_DIRECT = 0o40000;
|
||||
pub const O_LARGEFILE = 0o100000;
|
||||
pub const O_NOATIME = 0o1000000;
|
||||
pub const O_PATH = 0o10000000;
|
||||
pub const O_TMPFILE = 0o20200000;
|
||||
pub const O_NDELAY = O_NONBLOCK;
|
||||
|
||||
pub const F_DUPFD = 0;
|
||||
pub const F_GETFD = 1;
|
||||
pub const F_SETFD = 2;
|
||||
pub const F_GETFL = 3;
|
||||
pub const F_SETFL = 4;
|
||||
pub const F_GETLK = 5;
|
||||
pub const F_SETLK = 6;
|
||||
pub const F_SETLKW = 7;
|
||||
pub const F_SETOWN = 8;
|
||||
pub const F_GETOWN = 9;
|
||||
pub const F_SETSIG = 10;
|
||||
pub const F_GETSIG = 11;
|
||||
|
||||
pub const F_RDLCK = 0;
|
||||
pub const F_WRLCK = 1;
|
||||
pub const F_UNLCK = 2;
|
||||
|
||||
pub const LOCK_SH = 1;
|
||||
pub const LOCK_EX = 2;
|
||||
pub const LOCK_UN = 8;
|
||||
pub const LOCK_NB = 4;
|
||||
|
||||
pub const F_SETOWN_EX = 15;
|
||||
pub const F_GETOWN_EX = 16;
|
||||
|
||||
pub const F_GETOWNER_UIDS = 17;
|
||||
|
||||
pub const blksize_t = i32;
|
||||
pub const nlink_t = u32;
|
||||
pub const time_t = isize;
|
||||
pub const mode_t = u32;
|
||||
pub const off_t = isize;
|
||||
pub const ino_t = usize;
|
||||
pub const dev_t = usize;
|
||||
pub const blkcnt_t = isize;
|
||||
pub const timespec = extern struct {
|
||||
tv_sec: time_t,
|
||||
tv_nsec: isize,
|
||||
};
|
||||
|
||||
pub const timeval = extern struct {
|
||||
tv_sec: time_t,
|
||||
tv_usec: i64,
|
||||
};
|
||||
|
||||
pub const Flock = extern struct {
|
||||
l_type: i16,
|
||||
l_whence: i16,
|
||||
l_start: off_t,
|
||||
l_len: off_t,
|
||||
l_pid: pid_t,
|
||||
__unused: [4]u8,
|
||||
};
|
||||
|
||||
// The `stat` definition used by the Linux kernel.
|
||||
pub const kernel_stat = extern struct {
|
||||
dev: dev_t,
|
||||
ino: ino_t,
|
||||
mode: mode_t,
|
||||
nlink: nlink_t,
|
||||
uid: uid_t,
|
||||
gid: gid_t,
|
||||
rdev: dev_t,
|
||||
__pad: usize,
|
||||
size: off_t,
|
||||
blksize: blksize_t,
|
||||
__pad2: i32,
|
||||
blocks: blkcnt_t,
|
||||
atim: timespec,
|
||||
mtim: timespec,
|
||||
ctim: timespec,
|
||||
__unused: [2]u32,
|
||||
|
||||
pub fn atime(self: @This()) timespec {
|
||||
return self.atim;
|
||||
}
|
||||
|
||||
pub fn mtime(self: @This()) timespec {
|
||||
return self.mtim;
|
||||
}
|
||||
|
||||
pub fn ctime(self: @This()) timespec {
|
||||
return self.ctim;
|
||||
}
|
||||
};
|
||||
|
||||
// The `stat64` definition used by the libc.
|
||||
pub const libc_stat = kernel_stat;
|
||||
|
||||
pub const Elf_Symndx = u32;
|
||||
@ -1,35 +0,0 @@
|
||||
fn issecure_mask(comptime x: comptime_int) comptime_int {
|
||||
return 1 << x;
|
||||
}
|
||||
|
||||
pub const SECUREBITS_DEFAULT = 0x00000000;
|
||||
|
||||
pub const SECURE_NOROOT = 0;
|
||||
pub const SECURE_NOROOT_LOCKED = 1;
|
||||
|
||||
pub const SECBIT_NOROOT = issecure_mask(SECURE_NOROOT);
|
||||
pub const SECBIT_NOROOT_LOCKED = issecure_mask(SECURE_NOROOT_LOCKED);
|
||||
|
||||
pub const SECURE_NO_SETUID_FIXUP = 2;
|
||||
pub const SECURE_NO_SETUID_FIXUP_LOCKED = 3;
|
||||
|
||||
pub const SECBIT_NO_SETUID_FIXUP = issecure_mask(SECURE_NO_SETUID_FIXUP);
|
||||
pub const SECBIT_NO_SETUID_FIXUP_LOCKED = issecure_mask(SECURE_NO_SETUID_FIXUP_LOCKED);
|
||||
|
||||
pub const SECURE_KEEP_CAPS = 4;
|
||||
pub const SECURE_KEEP_CAPS_LOCKED = 5;
|
||||
|
||||
pub const SECBIT_KEEP_CAPS = issecure_mask(SECURE_KEEP_CAPS);
|
||||
pub const SECBIT_KEEP_CAPS_LOCKED = issecure_mask(SECURE_KEEP_CAPS_LOCKED);
|
||||
|
||||
pub const SECURE_NO_CAP_AMBIENT_RAISE = 6;
|
||||
pub const SECURE_NO_CAP_AMBIENT_RAISE_LOCKED = 7;
|
||||
|
||||
pub const SECBIT_NO_CAP_AMBIENT_RAISE = issecure_mask(SECURE_NO_CAP_AMBIENT_RAISE);
|
||||
pub const SECBIT_NO_CAP_AMBIENT_RAISE_LOCKED = issecure_mask(SECURE_NO_CAP_AMBIENT_RAISE_LOCKED);
|
||||
|
||||
pub const SECURE_ALL_BITS = issecure_mask(SECURE_NOROOT) |
|
||||
issecure_mask(SECURE_NO_SETUID_FIXUP) |
|
||||
issecure_mask(SECURE_KEEP_CAPS) |
|
||||
issecure_mask(SECURE_NO_CAP_AMBIENT_RAISE);
|
||||
pub const SECURE_ALL_LOCKS = SECURE_ALL_BITS << 1;
|
||||
@ -1,675 +0,0 @@
|
||||
// sparc64-specific declarations that are intended to be imported into the POSIX namespace.
|
||||
const std = @import("../../../std.zig");
|
||||
const pid_t = linux.pid_t;
|
||||
const uid_t = linux.uid_t;
|
||||
const clock_t = linux.clock_t;
|
||||
const stack_t = linux.stack_t;
|
||||
const sigset_t = linux.sigset_t;
|
||||
|
||||
const linux = std.os.linux;
|
||||
const sockaddr = linux.sockaddr;
|
||||
const socklen_t = linux.socklen_t;
|
||||
const iovec = linux.iovec;
|
||||
const iovec_const = linux.iovec_const;
|
||||
|
||||
pub const SYS = enum(usize) {
|
||||
restart_syscall = 0,
|
||||
exit = 1,
|
||||
fork = 2,
|
||||
read = 3,
|
||||
write = 4,
|
||||
open = 5,
|
||||
close = 6,
|
||||
wait4 = 7,
|
||||
creat = 8,
|
||||
link = 9,
|
||||
unlink = 10,
|
||||
execv = 11,
|
||||
chdir = 12,
|
||||
chown = 13,
|
||||
mknod = 14,
|
||||
chmod = 15,
|
||||
lchown = 16,
|
||||
brk = 17,
|
||||
perfctr = 18,
|
||||
lseek = 19,
|
||||
getpid = 20,
|
||||
capget = 21,
|
||||
capset = 22,
|
||||
setuid = 23,
|
||||
getuid = 24,
|
||||
vmsplice = 25,
|
||||
ptrace = 26,
|
||||
alarm = 27,
|
||||
sigaltstack = 28,
|
||||
pause = 29,
|
||||
utime = 30,
|
||||
access = 33,
|
||||
nice = 34,
|
||||
sync = 36,
|
||||
kill = 37,
|
||||
stat = 38,
|
||||
sendfile = 39,
|
||||
lstat = 40,
|
||||
dup = 41,
|
||||
pipe = 42,
|
||||
times = 43,
|
||||
umount2 = 45,
|
||||
setgid = 46,
|
||||
getgid = 47,
|
||||
signal = 48,
|
||||
geteuid = 49,
|
||||
getegid = 50,
|
||||
acct = 51,
|
||||
memory_ordering = 52,
|
||||
ioctl = 54,
|
||||
reboot = 55,
|
||||
symlink = 57,
|
||||
readlink = 58,
|
||||
execve = 59,
|
||||
umask = 60,
|
||||
chroot = 61,
|
||||
fstat = 62,
|
||||
fstat64 = 63,
|
||||
getpagesize = 64,
|
||||
msync = 65,
|
||||
vfork = 66,
|
||||
pread64 = 67,
|
||||
pwrite64 = 68,
|
||||
mmap = 71,
|
||||
munmap = 73,
|
||||
mprotect = 74,
|
||||
madvise = 75,
|
||||
vhangup = 76,
|
||||
mincore = 78,
|
||||
getgroups = 79,
|
||||
setgroups = 80,
|
||||
getpgrp = 81,
|
||||
setitimer = 83,
|
||||
swapon = 85,
|
||||
getitimer = 86,
|
||||
sethostname = 88,
|
||||
dup2 = 90,
|
||||
fcntl = 92,
|
||||
select = 93,
|
||||
fsync = 95,
|
||||
setpriority = 96,
|
||||
socket = 97,
|
||||
connect = 98,
|
||||
accept = 99,
|
||||
getpriority = 100,
|
||||
rt_sigreturn = 101,
|
||||
rt_sigaction = 102,
|
||||
rt_sigprocmask = 103,
|
||||
rt_sigpending = 104,
|
||||
rt_sigtimedwait = 105,
|
||||
rt_sigqueueinfo = 106,
|
||||
rt_sigsuspend = 107,
|
||||
setresuid = 108,
|
||||
getresuid = 109,
|
||||
setresgid = 110,
|
||||
getresgid = 111,
|
||||
recvmsg = 113,
|
||||
sendmsg = 114,
|
||||
gettimeofday = 116,
|
||||
getrusage = 117,
|
||||
getsockopt = 118,
|
||||
getcwd = 119,
|
||||
readv = 120,
|
||||
writev = 121,
|
||||
settimeofday = 122,
|
||||
fchown = 123,
|
||||
fchmod = 124,
|
||||
recvfrom = 125,
|
||||
setreuid = 126,
|
||||
setregid = 127,
|
||||
rename = 128,
|
||||
truncate = 129,
|
||||
ftruncate = 130,
|
||||
flock = 131,
|
||||
lstat64 = 132,
|
||||
sendto = 133,
|
||||
shutdown = 134,
|
||||
socketpair = 135,
|
||||
mkdir = 136,
|
||||
rmdir = 137,
|
||||
utimes = 138,
|
||||
stat64 = 139,
|
||||
sendfile64 = 140,
|
||||
getpeername = 141,
|
||||
futex = 142,
|
||||
gettid = 143,
|
||||
getrlimit = 144,
|
||||
setrlimit = 145,
|
||||
pivot_root = 146,
|
||||
prctl = 147,
|
||||
pciconfig_read = 148,
|
||||
pciconfig_write = 149,
|
||||
getsockname = 150,
|
||||
inotify_init = 151,
|
||||
inotify_add_watch = 152,
|
||||
poll = 153,
|
||||
getdents64 = 154,
|
||||
inotify_rm_watch = 156,
|
||||
statfs = 157,
|
||||
fstatfs = 158,
|
||||
umount = 159,
|
||||
sched_set_affinity = 160,
|
||||
sched_get_affinity = 161,
|
||||
getdomainname = 162,
|
||||
setdomainname = 163,
|
||||
utrap_install = 164,
|
||||
quotactl = 165,
|
||||
set_tid_address = 166,
|
||||
mount = 167,
|
||||
ustat = 168,
|
||||
setxattr = 169,
|
||||
lsetxattr = 170,
|
||||
fsetxattr = 171,
|
||||
getxattr = 172,
|
||||
lgetxattr = 173,
|
||||
getdents = 174,
|
||||
setsid = 175,
|
||||
fchdir = 176,
|
||||
fgetxattr = 177,
|
||||
listxattr = 178,
|
||||
llistxattr = 179,
|
||||
flistxattr = 180,
|
||||
removexattr = 181,
|
||||
lremovexattr = 182,
|
||||
sigpending = 183,
|
||||
query_module = 184,
|
||||
setpgid = 185,
|
||||
fremovexattr = 186,
|
||||
tkill = 187,
|
||||
exit_group = 188,
|
||||
uname = 189,
|
||||
init_module = 190,
|
||||
personality = 191,
|
||||
remap_file_pages = 192,
|
||||
epoll_create = 193,
|
||||
epoll_ctl = 194,
|
||||
epoll_wait = 195,
|
||||
ioprio_set = 196,
|
||||
getppid = 197,
|
||||
sigaction = 198,
|
||||
sgetmask = 199,
|
||||
ssetmask = 200,
|
||||
sigsuspend = 201,
|
||||
oldlstat = 202,
|
||||
uselib = 203,
|
||||
readdir = 204,
|
||||
readahead = 205,
|
||||
socketcall = 206,
|
||||
syslog = 207,
|
||||
lookup_dcookie = 208,
|
||||
fadvise64 = 209,
|
||||
fadvise64_64 = 210,
|
||||
tgkill = 211,
|
||||
waitpid = 212,
|
||||
swapoff = 213,
|
||||
sysinfo = 214,
|
||||
ipc = 215,
|
||||
sigreturn = 216,
|
||||
clone = 217,
|
||||
ioprio_get = 218,
|
||||
adjtimex = 219,
|
||||
sigprocmask = 220,
|
||||
create_module = 221,
|
||||
delete_module = 222,
|
||||
get_kernel_syms = 223,
|
||||
getpgid = 224,
|
||||
bdflush = 225,
|
||||
sysfs = 226,
|
||||
afs_syscall = 227,
|
||||
setfsuid = 228,
|
||||
setfsgid = 229,
|
||||
_newselect = 230,
|
||||
splice = 232,
|
||||
stime = 233,
|
||||
statfs64 = 234,
|
||||
fstatfs64 = 235,
|
||||
_llseek = 236,
|
||||
mlock = 237,
|
||||
munlock = 238,
|
||||
mlockall = 239,
|
||||
munlockall = 240,
|
||||
sched_setparam = 241,
|
||||
sched_getparam = 242,
|
||||
sched_setscheduler = 243,
|
||||
sched_getscheduler = 244,
|
||||
sched_yield = 245,
|
||||
sched_get_priority_max = 246,
|
||||
sched_get_priority_min = 247,
|
||||
sched_rr_get_interval = 248,
|
||||
nanosleep = 249,
|
||||
mremap = 250,
|
||||
_sysctl = 251,
|
||||
getsid = 252,
|
||||
fdatasync = 253,
|
||||
nfsservctl = 254,
|
||||
sync_file_range = 255,
|
||||
clock_settime = 256,
|
||||
clock_gettime = 257,
|
||||
clock_getres = 258,
|
||||
clock_nanosleep = 259,
|
||||
sched_getaffinity = 260,
|
||||
sched_setaffinity = 261,
|
||||
timer_settime = 262,
|
||||
timer_gettime = 263,
|
||||
timer_getoverrun = 264,
|
||||
timer_delete = 265,
|
||||
timer_create = 266,
|
||||
vserver = 267,
|
||||
io_setup = 268,
|
||||
io_destroy = 269,
|
||||
io_submit = 270,
|
||||
io_cancel = 271,
|
||||
io_getevents = 272,
|
||||
mq_open = 273,
|
||||
mq_unlink = 274,
|
||||
mq_timedsend = 275,
|
||||
mq_timedreceive = 276,
|
||||
mq_notify = 277,
|
||||
mq_getsetattr = 278,
|
||||
waitid = 279,
|
||||
tee = 280,
|
||||
add_key = 281,
|
||||
request_key = 282,
|
||||
keyctl = 283,
|
||||
openat = 284,
|
||||
mkdirat = 285,
|
||||
mknodat = 286,
|
||||
fchownat = 287,
|
||||
futimesat = 288,
|
||||
fstatat64 = 289,
|
||||
unlinkat = 290,
|
||||
renameat = 291,
|
||||
linkat = 292,
|
||||
symlinkat = 293,
|
||||
readlinkat = 294,
|
||||
fchmodat = 295,
|
||||
faccessat = 296,
|
||||
pselect6 = 297,
|
||||
ppoll = 298,
|
||||
unshare = 299,
|
||||
set_robust_list = 300,
|
||||
get_robust_list = 301,
|
||||
migrate_pages = 302,
|
||||
mbind = 303,
|
||||
get_mempolicy = 304,
|
||||
set_mempolicy = 305,
|
||||
kexec_load = 306,
|
||||
move_pages = 307,
|
||||
getcpu = 308,
|
||||
epoll_pwait = 309,
|
||||
utimensat = 310,
|
||||
signalfd = 311,
|
||||
timerfd_create = 312,
|
||||
eventfd = 313,
|
||||
fallocate = 314,
|
||||
timerfd_settime = 315,
|
||||
timerfd_gettime = 316,
|
||||
signalfd4 = 317,
|
||||
eventfd2 = 318,
|
||||
epoll_create1 = 319,
|
||||
dup3 = 320,
|
||||
pipe2 = 321,
|
||||
inotify_init1 = 322,
|
||||
accept4 = 323,
|
||||
preadv = 324,
|
||||
pwritev = 325,
|
||||
rt_tgsigqueueinfo = 326,
|
||||
perf_event_open = 327,
|
||||
recvmmsg = 328,
|
||||
fanotify_init = 329,
|
||||
fanotify_mark = 330,
|
||||
prlimit64 = 331,
|
||||
name_to_handle_at = 332,
|
||||
open_by_handle_at = 333,
|
||||
clock_adjtime = 334,
|
||||
syncfs = 335,
|
||||
sendmmsg = 336,
|
||||
setns = 337,
|
||||
process_vm_readv = 338,
|
||||
process_vm_writev = 339,
|
||||
kern_features = 340,
|
||||
kcmp = 341,
|
||||
finit_module = 342,
|
||||
sched_setattr = 343,
|
||||
sched_getattr = 344,
|
||||
renameat2 = 345,
|
||||
seccomp = 346,
|
||||
getrandom = 347,
|
||||
memfd_create = 348,
|
||||
bpf = 349,
|
||||
execveat = 350,
|
||||
membarrier = 351,
|
||||
userfaultfd = 352,
|
||||
bind = 353,
|
||||
listen = 354,
|
||||
setsockopt = 355,
|
||||
mlock2 = 356,
|
||||
copy_file_range = 357,
|
||||
preadv2 = 358,
|
||||
pwritev2 = 359,
|
||||
statx = 360,
|
||||
io_pgetevents = 361,
|
||||
pkey_mprotect = 362,
|
||||
pkey_alloc = 363,
|
||||
pkey_free = 364,
|
||||
rseq = 365,
|
||||
semtimedop = 392,
|
||||
semget = 393,
|
||||
semctl = 394,
|
||||
shmget = 395,
|
||||
shmctl = 396,
|
||||
shmat = 397,
|
||||
shmdt = 398,
|
||||
msgget = 399,
|
||||
msgsnd = 400,
|
||||
msgrcv = 401,
|
||||
msgctl = 402,
|
||||
pidfd_send_signal = 424,
|
||||
io_uring_setup = 425,
|
||||
io_uring_enter = 426,
|
||||
io_uring_register = 427,
|
||||
open_tree = 428,
|
||||
move_mount = 429,
|
||||
fsopen = 430,
|
||||
fsconfig = 431,
|
||||
fsmount = 432,
|
||||
fspick = 433,
|
||||
pidfd_open = 434,
|
||||
clone3 = 435,
|
||||
close_range = 436,
|
||||
openat2 = 437,
|
||||
pidfd_getfd = 438,
|
||||
faccessat2 = 439,
|
||||
process_madvise = 440,
|
||||
epoll_pwait2 = 441,
|
||||
|
||||
_,
|
||||
};
|
||||
|
||||
pub const O_CREAT = 0x200;
|
||||
pub const O_EXCL = 0x800;
|
||||
pub const O_NOCTTY = 0x8000;
|
||||
pub const O_TRUNC = 0x400;
|
||||
pub const O_APPEND = 0x8;
|
||||
pub const O_NONBLOCK = 0x4000;
|
||||
pub const O_SYNC = 0x802000;
|
||||
pub const O_DSYNC = 0x2000;
|
||||
pub const O_RSYNC = O_SYNC;
|
||||
pub const O_DIRECTORY = 0x10000;
|
||||
pub const O_NOFOLLOW = 0x20000;
|
||||
pub const O_CLOEXEC = 0x400000;
|
||||
|
||||
pub const O_ASYNC = 0x40;
|
||||
pub const O_DIRECT = 0x100000;
|
||||
pub const O_LARGEFILE = 0;
|
||||
pub const O_NOATIME = 0x200000;
|
||||
pub const O_PATH = 0x1000000;
|
||||
pub const O_TMPFILE = 0x2010000;
|
||||
pub const O_NDELAY = O_NONBLOCK | 0x4;
|
||||
|
||||
pub const F_DUPFD = 0;
|
||||
pub const F_GETFD = 1;
|
||||
pub const F_SETFD = 2;
|
||||
pub const F_GETFL = 3;
|
||||
pub const F_SETFL = 4;
|
||||
|
||||
pub const F_SETOWN = 5;
|
||||
pub const F_GETOWN = 6;
|
||||
pub const F_GETLK = 7;
|
||||
pub const F_SETLK = 8;
|
||||
pub const F_SETLKW = 9;
|
||||
|
||||
pub const F_RDLCK = 1;
|
||||
pub const F_WRLCK = 2;
|
||||
pub const F_UNLCK = 3;
|
||||
|
||||
pub const F_SETOWN_EX = 15;
|
||||
pub const F_GETOWN_EX = 16;
|
||||
|
||||
pub const F_GETOWNER_UIDS = 17;
|
||||
|
||||
pub const LOCK_SH = 1;
|
||||
pub const LOCK_EX = 2;
|
||||
pub const LOCK_NB = 4;
|
||||
pub const LOCK_UN = 8;
|
||||
|
||||
/// stack-like segment
|
||||
pub const MAP_GROWSDOWN = 0x0200;
|
||||
|
||||
/// ETXTBSY
|
||||
pub const MAP_DENYWRITE = 0x0800;
|
||||
|
||||
/// mark it as an executable
|
||||
pub const MAP_EXECUTABLE = 0x1000;
|
||||
|
||||
/// pages are locked
|
||||
pub const MAP_LOCKED = 0x0100;
|
||||
|
||||
/// don't check for reservations
|
||||
pub const MAP_NORESERVE = 0x0040;
|
||||
|
||||
pub const VDSO_CGT_SYM = "__vdso_clock_gettime";
|
||||
pub const VDSO_CGT_VER = "LINUX_2.6";
|
||||
|
||||
pub const Flock = extern struct {
|
||||
l_type: i16,
|
||||
l_whence: i16,
|
||||
l_start: off_t,
|
||||
l_len: off_t,
|
||||
l_pid: pid_t,
|
||||
};
|
||||
|
||||
pub const msghdr = extern struct {
|
||||
msg_name: ?*sockaddr,
|
||||
msg_namelen: socklen_t,
|
||||
msg_iov: [*]iovec,
|
||||
msg_iovlen: u64,
|
||||
msg_control: ?*c_void,
|
||||
msg_controllen: u64,
|
||||
msg_flags: i32,
|
||||
};
|
||||
|
||||
pub const msghdr_const = extern struct {
|
||||
msg_name: ?*const sockaddr,
|
||||
msg_namelen: socklen_t,
|
||||
msg_iov: [*]iovec_const,
|
||||
msg_iovlen: u64,
|
||||
msg_control: ?*c_void,
|
||||
msg_controllen: u64,
|
||||
msg_flags: i32,
|
||||
};
|
||||
|
||||
pub const off_t = i64;
|
||||
pub const ino_t = u64;
|
||||
pub const mode_t = u32;
|
||||
|
||||
// The `stat64` definition used by the libc.
|
||||
pub const libc_stat = extern struct {
|
||||
dev: u64,
|
||||
ino: ino_t,
|
||||
mode: u32,
|
||||
nlink: usize,
|
||||
|
||||
uid: u32,
|
||||
gid: u32,
|
||||
rdev: u64,
|
||||
__pad0: u32,
|
||||
|
||||
size: off_t,
|
||||
blksize: isize,
|
||||
blocks: i64,
|
||||
|
||||
atim: timespec,
|
||||
mtim: timespec,
|
||||
ctim: timespec,
|
||||
__unused: [2]isize,
|
||||
|
||||
pub fn atime(self: libc_stat) timespec {
|
||||
return self.atim;
|
||||
}
|
||||
|
||||
pub fn mtime(self: libc_stat) timespec {
|
||||
return self.mtim;
|
||||
}
|
||||
|
||||
pub fn ctime(self: libc_stat) timespec {
|
||||
return self.ctim;
|
||||
}
|
||||
};
|
||||
|
||||
// The `stat64` definition used by the kernel.
|
||||
pub const kernel_stat = extern struct {
|
||||
dev: u64,
|
||||
ino: u64,
|
||||
nlink: u64,
|
||||
|
||||
mode: u32,
|
||||
uid: u32,
|
||||
gid: u32,
|
||||
__pad0: u32,
|
||||
|
||||
rdev: u64,
|
||||
size: i64,
|
||||
blksize: i64,
|
||||
blocks: i64,
|
||||
|
||||
atim: timespec,
|
||||
mtim: timespec,
|
||||
ctim: timespec,
|
||||
__unused: [3]u64,
|
||||
|
||||
pub fn atime(self: @This()) timespec {
|
||||
return self.atim;
|
||||
}
|
||||
|
||||
pub fn mtime(self: @This()) timespec {
|
||||
return self.mtim;
|
||||
}
|
||||
|
||||
pub fn ctime(self: @This()) timespec {
|
||||
return self.ctim;
|
||||
}
|
||||
};
|
||||
|
||||
pub const timespec = extern struct {
|
||||
tv_sec: isize,
|
||||
tv_nsec: isize,
|
||||
};
|
||||
|
||||
pub const timeval = extern struct {
|
||||
tv_sec: isize,
|
||||
tv_usec: isize,
|
||||
};
|
||||
|
||||
pub const timezone = extern struct {
|
||||
tz_minuteswest: i32,
|
||||
tz_dsttime: i32,
|
||||
};
|
||||
|
||||
// TODO I'm not sure if the code below is correct, need someone with more
|
||||
// knowledge about sparc64 linux internals to look into.
|
||||
|
||||
pub const Elf_Symndx = u32;
|
||||
|
||||
pub const fpstate = extern struct {
|
||||
regs: [32]u64,
|
||||
fsr: u64,
|
||||
gsr: u64,
|
||||
fprs: u64,
|
||||
};
|
||||
|
||||
pub const __fpq = extern struct {
|
||||
fpq_addr: *u32,
|
||||
fpq_instr: u32,
|
||||
};
|
||||
|
||||
pub const __fq = extern struct {
|
||||
FQu: extern union {
|
||||
whole: f64,
|
||||
fpq: __fpq,
|
||||
},
|
||||
};
|
||||
|
||||
pub const fpregset_t = extern struct {
|
||||
fpu_fr: extern union {
|
||||
fpu_regs: [32]u32,
|
||||
fpu_dregs: [32]f64,
|
||||
fpu_qregs: [16]c_longdouble,
|
||||
},
|
||||
fpu_q: *__fq,
|
||||
fpu_fsr: u64,
|
||||
fpu_qcnt: u8,
|
||||
fpu_q_entrysize: u8,
|
||||
fpu_en: u8,
|
||||
};
|
||||
|
||||
pub const siginfo_fpu_t = extern struct {
|
||||
float_regs: [64]u32,
|
||||
fsr: u64,
|
||||
gsr: u64,
|
||||
fprs: u64,
|
||||
};
|
||||
|
||||
pub const sigcontext = extern struct {
|
||||
info: [128]i8,
|
||||
regs: extern struct {
|
||||
u_regs: [16]u64,
|
||||
tstate: u64,
|
||||
tpc: u64,
|
||||
tnpc: u64,
|
||||
y: u64,
|
||||
fprs: u64,
|
||||
},
|
||||
fpu_save: *siginfo_fpu_t,
|
||||
stack: extern struct {
|
||||
sp: usize,
|
||||
flags: i32,
|
||||
size: u64,
|
||||
},
|
||||
mask: u64,
|
||||
};
|
||||
|
||||
pub const greg_t = u64;
|
||||
pub const gregset_t = [19]greg_t;
|
||||
|
||||
pub const fq = extern struct {
|
||||
addr: *u64,
|
||||
insn: u32,
|
||||
};
|
||||
|
||||
pub const fpu_t = extern struct {
|
||||
fregs: extern union {
|
||||
sregs: [32]u32,
|
||||
dregs: [32]u64,
|
||||
qregs: [16]c_longdouble,
|
||||
},
|
||||
fsr: u64,
|
||||
fprs: u64,
|
||||
gsr: u64,
|
||||
fq: *fq,
|
||||
qcnt: u8,
|
||||
qentsz: u8,
|
||||
enab: u8,
|
||||
};
|
||||
|
||||
pub const mcontext_t = extern struct {
|
||||
gregs: gregset_t,
|
||||
fp: greg_t,
|
||||
@"i7": greg_t,
|
||||
fpregs: fpu_t,
|
||||
};
|
||||
|
||||
pub const ucontext_t = extern struct {
|
||||
link: *ucontext_t,
|
||||
flags: u64,
|
||||
sigmask: u64,
|
||||
mcontext: mcontext_t,
|
||||
stack: stack_t,
|
||||
sigmask: sigset_t,
|
||||
};
|
||||
@ -1,638 +0,0 @@
|
||||
// x86-64-specific declarations that are intended to be imported into the POSIX namespace.
|
||||
const std = @import("../../../std.zig");
|
||||
const pid_t = linux.pid_t;
|
||||
const uid_t = linux.uid_t;
|
||||
const gid_t = linux.gid_t;
|
||||
const clock_t = linux.clock_t;
|
||||
const stack_t = linux.stack_t;
|
||||
const sigset_t = linux.sigset_t;
|
||||
|
||||
const linux = std.os.linux;
|
||||
const sockaddr = linux.sockaddr;
|
||||
const socklen_t = linux.socklen_t;
|
||||
const iovec = linux.iovec;
|
||||
const iovec_const = linux.iovec_const;
|
||||
|
||||
pub const mode_t = usize;
|
||||
pub const time_t = isize;
|
||||
|
||||
pub const SYS = enum(usize) {
|
||||
read = 0,
|
||||
write = 1,
|
||||
open = 2,
|
||||
close = 3,
|
||||
stat = 4,
|
||||
fstat = 5,
|
||||
lstat = 6,
|
||||
poll = 7,
|
||||
lseek = 8,
|
||||
mmap = 9,
|
||||
mprotect = 10,
|
||||
munmap = 11,
|
||||
brk = 12,
|
||||
rt_sigaction = 13,
|
||||
rt_sigprocmask = 14,
|
||||
rt_sigreturn = 15,
|
||||
ioctl = 16,
|
||||
pread = 17,
|
||||
pwrite = 18,
|
||||
readv = 19,
|
||||
writev = 20,
|
||||
access = 21,
|
||||
pipe = 22,
|
||||
select = 23,
|
||||
sched_yield = 24,
|
||||
mremap = 25,
|
||||
msync = 26,
|
||||
mincore = 27,
|
||||
madvise = 28,
|
||||
shmget = 29,
|
||||
shmat = 30,
|
||||
shmctl = 31,
|
||||
dup = 32,
|
||||
dup2 = 33,
|
||||
pause = 34,
|
||||
nanosleep = 35,
|
||||
getitimer = 36,
|
||||
alarm = 37,
|
||||
setitimer = 38,
|
||||
getpid = 39,
|
||||
sendfile = 40,
|
||||
socket = 41,
|
||||
connect = 42,
|
||||
accept = 43,
|
||||
sendto = 44,
|
||||
recvfrom = 45,
|
||||
sendmsg = 46,
|
||||
recvmsg = 47,
|
||||
shutdown = 48,
|
||||
bind = 49,
|
||||
listen = 50,
|
||||
getsockname = 51,
|
||||
getpeername = 52,
|
||||
socketpair = 53,
|
||||
setsockopt = 54,
|
||||
getsockopt = 55,
|
||||
clone = 56,
|
||||
fork = 57,
|
||||
vfork = 58,
|
||||
execve = 59,
|
||||
exit = 60,
|
||||
wait4 = 61,
|
||||
kill = 62,
|
||||
uname = 63,
|
||||
semget = 64,
|
||||
semop = 65,
|
||||
semctl = 66,
|
||||
shmdt = 67,
|
||||
msgget = 68,
|
||||
msgsnd = 69,
|
||||
msgrcv = 70,
|
||||
msgctl = 71,
|
||||
fcntl = 72,
|
||||
flock = 73,
|
||||
fsync = 74,
|
||||
fdatasync = 75,
|
||||
truncate = 76,
|
||||
ftruncate = 77,
|
||||
getdents = 78,
|
||||
getcwd = 79,
|
||||
chdir = 80,
|
||||
fchdir = 81,
|
||||
rename = 82,
|
||||
mkdir = 83,
|
||||
rmdir = 84,
|
||||
creat = 85,
|
||||
link = 86,
|
||||
unlink = 87,
|
||||
symlink = 88,
|
||||
readlink = 89,
|
||||
chmod = 90,
|
||||
fchmod = 91,
|
||||
chown = 92,
|
||||
fchown = 93,
|
||||
lchown = 94,
|
||||
umask = 95,
|
||||
gettimeofday = 96,
|
||||
getrlimit = 97,
|
||||
getrusage = 98,
|
||||
sysinfo = 99,
|
||||
times = 100,
|
||||
ptrace = 101,
|
||||
getuid = 102,
|
||||
syslog = 103,
|
||||
getgid = 104,
|
||||
setuid = 105,
|
||||
setgid = 106,
|
||||
geteuid = 107,
|
||||
getegid = 108,
|
||||
setpgid = 109,
|
||||
getppid = 110,
|
||||
getpgrp = 111,
|
||||
setsid = 112,
|
||||
setreuid = 113,
|
||||
setregid = 114,
|
||||
getgroups = 115,
|
||||
setgroups = 116,
|
||||
setresuid = 117,
|
||||
getresuid = 118,
|
||||
setresgid = 119,
|
||||
getresgid = 120,
|
||||
getpgid = 121,
|
||||
setfsuid = 122,
|
||||
setfsgid = 123,
|
||||
getsid = 124,
|
||||
capget = 125,
|
||||
capset = 126,
|
||||
rt_sigpending = 127,
|
||||
rt_sigtimedwait = 128,
|
||||
rt_sigqueueinfo = 129,
|
||||
rt_sigsuspend = 130,
|
||||
sigaltstack = 131,
|
||||
utime = 132,
|
||||
mknod = 133,
|
||||
uselib = 134,
|
||||
personality = 135,
|
||||
ustat = 136,
|
||||
statfs = 137,
|
||||
fstatfs = 138,
|
||||
sysfs = 139,
|
||||
getpriority = 140,
|
||||
setpriority = 141,
|
||||
sched_setparam = 142,
|
||||
sched_getparam = 143,
|
||||
sched_setscheduler = 144,
|
||||
sched_getscheduler = 145,
|
||||
sched_get_priority_max = 146,
|
||||
sched_get_priority_min = 147,
|
||||
sched_rr_get_interval = 148,
|
||||
mlock = 149,
|
||||
munlock = 150,
|
||||
mlockall = 151,
|
||||
munlockall = 152,
|
||||
vhangup = 153,
|
||||
modify_ldt = 154,
|
||||
pivot_root = 155,
|
||||
_sysctl = 156,
|
||||
prctl = 157,
|
||||
arch_prctl = 158,
|
||||
adjtimex = 159,
|
||||
setrlimit = 160,
|
||||
chroot = 161,
|
||||
sync = 162,
|
||||
acct = 163,
|
||||
settimeofday = 164,
|
||||
mount = 165,
|
||||
umount2 = 166,
|
||||
swapon = 167,
|
||||
swapoff = 168,
|
||||
reboot = 169,
|
||||
sethostname = 170,
|
||||
setdomainname = 171,
|
||||
iopl = 172,
|
||||
ioperm = 173,
|
||||
create_module = 174,
|
||||
init_module = 175,
|
||||
delete_module = 176,
|
||||
get_kernel_syms = 177,
|
||||
query_module = 178,
|
||||
quotactl = 179,
|
||||
nfsservctl = 180,
|
||||
getpmsg = 181,
|
||||
putpmsg = 182,
|
||||
afs_syscall = 183,
|
||||
tuxcall = 184,
|
||||
security = 185,
|
||||
gettid = 186,
|
||||
readahead = 187,
|
||||
setxattr = 188,
|
||||
lsetxattr = 189,
|
||||
fsetxattr = 190,
|
||||
getxattr = 191,
|
||||
lgetxattr = 192,
|
||||
fgetxattr = 193,
|
||||
listxattr = 194,
|
||||
llistxattr = 195,
|
||||
flistxattr = 196,
|
||||
removexattr = 197,
|
||||
lremovexattr = 198,
|
||||
fremovexattr = 199,
|
||||
tkill = 200,
|
||||
time = 201,
|
||||
futex = 202,
|
||||
sched_setaffinity = 203,
|
||||
sched_getaffinity = 204,
|
||||
set_thread_area = 205,
|
||||
io_setup = 206,
|
||||
io_destroy = 207,
|
||||
io_getevents = 208,
|
||||
io_submit = 209,
|
||||
io_cancel = 210,
|
||||
get_thread_area = 211,
|
||||
lookup_dcookie = 212,
|
||||
epoll_create = 213,
|
||||
epoll_ctl_old = 214,
|
||||
epoll_wait_old = 215,
|
||||
remap_file_pages = 216,
|
||||
getdents64 = 217,
|
||||
set_tid_address = 218,
|
||||
restart_syscall = 219,
|
||||
semtimedop = 220,
|
||||
fadvise64 = 221,
|
||||
timer_create = 222,
|
||||
timer_settime = 223,
|
||||
timer_gettime = 224,
|
||||
timer_getoverrun = 225,
|
||||
timer_delete = 226,
|
||||
clock_settime = 227,
|
||||
clock_gettime = 228,
|
||||
clock_getres = 229,
|
||||
clock_nanosleep = 230,
|
||||
exit_group = 231,
|
||||
epoll_wait = 232,
|
||||
epoll_ctl = 233,
|
||||
tgkill = 234,
|
||||
utimes = 235,
|
||||
vserver = 236,
|
||||
mbind = 237,
|
||||
set_mempolicy = 238,
|
||||
get_mempolicy = 239,
|
||||
mq_open = 240,
|
||||
mq_unlink = 241,
|
||||
mq_timedsend = 242,
|
||||
mq_timedreceive = 243,
|
||||
mq_notify = 244,
|
||||
mq_getsetattr = 245,
|
||||
kexec_load = 246,
|
||||
waitid = 247,
|
||||
add_key = 248,
|
||||
request_key = 249,
|
||||
keyctl = 250,
|
||||
ioprio_set = 251,
|
||||
ioprio_get = 252,
|
||||
inotify_init = 253,
|
||||
inotify_add_watch = 254,
|
||||
inotify_rm_watch = 255,
|
||||
migrate_pages = 256,
|
||||
openat = 257,
|
||||
mkdirat = 258,
|
||||
mknodat = 259,
|
||||
fchownat = 260,
|
||||
futimesat = 261,
|
||||
fstatat = 262,
|
||||
unlinkat = 263,
|
||||
renameat = 264,
|
||||
linkat = 265,
|
||||
symlinkat = 266,
|
||||
readlinkat = 267,
|
||||
fchmodat = 268,
|
||||
faccessat = 269,
|
||||
pselect6 = 270,
|
||||
ppoll = 271,
|
||||
unshare = 272,
|
||||
set_robust_list = 273,
|
||||
get_robust_list = 274,
|
||||
splice = 275,
|
||||
tee = 276,
|
||||
sync_file_range = 277,
|
||||
vmsplice = 278,
|
||||
move_pages = 279,
|
||||
utimensat = 280,
|
||||
epoll_pwait = 281,
|
||||
signalfd = 282,
|
||||
timerfd_create = 283,
|
||||
eventfd = 284,
|
||||
fallocate = 285,
|
||||
timerfd_settime = 286,
|
||||
timerfd_gettime = 287,
|
||||
accept4 = 288,
|
||||
signalfd4 = 289,
|
||||
eventfd2 = 290,
|
||||
epoll_create1 = 291,
|
||||
dup3 = 292,
|
||||
pipe2 = 293,
|
||||
inotify_init1 = 294,
|
||||
preadv = 295,
|
||||
pwritev = 296,
|
||||
rt_tgsigqueueinfo = 297,
|
||||
perf_event_open = 298,
|
||||
recvmmsg = 299,
|
||||
fanotify_init = 300,
|
||||
fanotify_mark = 301,
|
||||
prlimit64 = 302,
|
||||
name_to_handle_at = 303,
|
||||
open_by_handle_at = 304,
|
||||
clock_adjtime = 305,
|
||||
syncfs = 306,
|
||||
sendmmsg = 307,
|
||||
setns = 308,
|
||||
getcpu = 309,
|
||||
process_vm_readv = 310,
|
||||
process_vm_writev = 311,
|
||||
kcmp = 312,
|
||||
finit_module = 313,
|
||||
sched_setattr = 314,
|
||||
sched_getattr = 315,
|
||||
renameat2 = 316,
|
||||
seccomp = 317,
|
||||
getrandom = 318,
|
||||
memfd_create = 319,
|
||||
kexec_file_load = 320,
|
||||
bpf = 321,
|
||||
execveat = 322,
|
||||
userfaultfd = 323,
|
||||
membarrier = 324,
|
||||
mlock2 = 325,
|
||||
copy_file_range = 326,
|
||||
preadv2 = 327,
|
||||
pwritev2 = 328,
|
||||
pkey_mprotect = 329,
|
||||
pkey_alloc = 330,
|
||||
pkey_free = 331,
|
||||
statx = 332,
|
||||
io_pgetevents = 333,
|
||||
rseq = 334,
|
||||
pidfd_send_signal = 424,
|
||||
io_uring_setup = 425,
|
||||
io_uring_enter = 426,
|
||||
io_uring_register = 427,
|
||||
open_tree = 428,
|
||||
move_mount = 429,
|
||||
fsopen = 430,
|
||||
fsconfig = 431,
|
||||
fsmount = 432,
|
||||
fspick = 433,
|
||||
pidfd_open = 434,
|
||||
clone3 = 435,
|
||||
close_range = 436,
|
||||
openat2 = 437,
|
||||
pidfd_getfd = 438,
|
||||
faccessat2 = 439,
|
||||
process_madvise = 440,
|
||||
epoll_pwait2 = 441,
|
||||
|
||||
_,
|
||||
};
|
||||
|
||||
pub const O_CREAT = 0o100;
|
||||
pub const O_EXCL = 0o200;
|
||||
pub const O_NOCTTY = 0o400;
|
||||
pub const O_TRUNC = 0o1000;
|
||||
pub const O_APPEND = 0o2000;
|
||||
pub const O_NONBLOCK = 0o4000;
|
||||
pub const O_DSYNC = 0o10000;
|
||||
pub const O_SYNC = 0o4010000;
|
||||
pub const O_RSYNC = 0o4010000;
|
||||
pub const O_DIRECTORY = 0o200000;
|
||||
pub const O_NOFOLLOW = 0o400000;
|
||||
pub const O_CLOEXEC = 0o2000000;
|
||||
|
||||
pub const O_ASYNC = 0o20000;
|
||||
pub const O_DIRECT = 0o40000;
|
||||
pub const O_LARGEFILE = 0;
|
||||
pub const O_NOATIME = 0o1000000;
|
||||
pub const O_PATH = 0o10000000;
|
||||
pub const O_TMPFILE = 0o20200000;
|
||||
pub const O_NDELAY = O_NONBLOCK;
|
||||
|
||||
pub const F_DUPFD = 0;
|
||||
pub const F_GETFD = 1;
|
||||
pub const F_SETFD = 2;
|
||||
pub const F_GETFL = 3;
|
||||
pub const F_SETFL = 4;
|
||||
|
||||
pub const F_SETOWN = 8;
|
||||
pub const F_GETOWN = 9;
|
||||
pub const F_SETSIG = 10;
|
||||
pub const F_GETSIG = 11;
|
||||
|
||||
pub const F_GETLK = 5;
|
||||
pub const F_SETLK = 6;
|
||||
pub const F_SETLKW = 7;
|
||||
|
||||
pub const F_SETOWN_EX = 15;
|
||||
pub const F_GETOWN_EX = 16;
|
||||
|
||||
pub const F_GETOWNER_UIDS = 17;
|
||||
|
||||
/// only give out 32bit addresses
|
||||
pub const MAP_32BIT = 0x40;
|
||||
|
||||
/// stack-like segment
|
||||
pub const MAP_GROWSDOWN = 0x0100;
|
||||
|
||||
/// ETXTBSY
|
||||
pub const MAP_DENYWRITE = 0x0800;
|
||||
|
||||
/// mark it as an executable
|
||||
pub const MAP_EXECUTABLE = 0x1000;
|
||||
|
||||
/// pages are locked
|
||||
pub const MAP_LOCKED = 0x2000;
|
||||
|
||||
/// don't check for reservations
|
||||
pub const MAP_NORESERVE = 0x4000;
|
||||
|
||||
pub const VDSO_CGT_SYM = "__vdso_clock_gettime";
|
||||
pub const VDSO_CGT_VER = "LINUX_2.6";
|
||||
pub const VDSO_GETCPU_SYM = "__vdso_getcpu";
|
||||
pub const VDSO_GETCPU_VER = "LINUX_2.6";
|
||||
|
||||
pub const ARCH_SET_GS = 0x1001;
|
||||
pub const ARCH_SET_FS = 0x1002;
|
||||
pub const ARCH_GET_FS = 0x1003;
|
||||
pub const ARCH_GET_GS = 0x1004;
|
||||
|
||||
pub const REG_R8 = 0;
|
||||
pub const REG_R9 = 1;
|
||||
pub const REG_R10 = 2;
|
||||
pub const REG_R11 = 3;
|
||||
pub const REG_R12 = 4;
|
||||
pub const REG_R13 = 5;
|
||||
pub const REG_R14 = 6;
|
||||
pub const REG_R15 = 7;
|
||||
pub const REG_RDI = 8;
|
||||
pub const REG_RSI = 9;
|
||||
pub const REG_RBP = 10;
|
||||
pub const REG_RBX = 11;
|
||||
pub const REG_RDX = 12;
|
||||
pub const REG_RAX = 13;
|
||||
pub const REG_RCX = 14;
|
||||
pub const REG_RSP = 15;
|
||||
pub const REG_RIP = 16;
|
||||
pub const REG_EFL = 17;
|
||||
pub const REG_CSGSFS = 18;
|
||||
pub const REG_ERR = 19;
|
||||
pub const REG_TRAPNO = 20;
|
||||
pub const REG_OLDMASK = 21;
|
||||
pub const REG_CR2 = 22;
|
||||
|
||||
pub const LOCK_SH = 1;
|
||||
pub const LOCK_EX = 2;
|
||||
pub const LOCK_UN = 8;
|
||||
pub const LOCK_NB = 4;
|
||||
|
||||
pub const F_RDLCK = 0;
|
||||
pub const F_WRLCK = 1;
|
||||
pub const F_UNLCK = 2;
|
||||
|
||||
pub const Flock = extern struct {
|
||||
l_type: i16,
|
||||
l_whence: i16,
|
||||
l_start: off_t,
|
||||
l_len: off_t,
|
||||
l_pid: pid_t,
|
||||
};
|
||||
|
||||
pub const msghdr = extern struct {
|
||||
msg_name: ?*sockaddr,
|
||||
msg_namelen: socklen_t,
|
||||
msg_iov: [*]iovec,
|
||||
msg_iovlen: i32,
|
||||
__pad1: i32 = 0,
|
||||
msg_control: ?*c_void,
|
||||
msg_controllen: socklen_t,
|
||||
__pad2: socklen_t = 0,
|
||||
msg_flags: i32,
|
||||
};
|
||||
|
||||
pub const msghdr_const = extern struct {
|
||||
msg_name: ?*const sockaddr,
|
||||
msg_namelen: socklen_t,
|
||||
msg_iov: [*]iovec_const,
|
||||
msg_iovlen: i32,
|
||||
__pad1: i32 = 0,
|
||||
msg_control: ?*c_void,
|
||||
msg_controllen: socklen_t,
|
||||
__pad2: socklen_t = 0,
|
||||
msg_flags: i32,
|
||||
};
|
||||
|
||||
pub const off_t = i64;
|
||||
pub const ino_t = u64;
|
||||
pub const dev_t = u64;
|
||||
|
||||
// The `stat` definition used by the Linux kernel.
|
||||
pub const kernel_stat = extern struct {
|
||||
dev: dev_t,
|
||||
ino: ino_t,
|
||||
nlink: usize,
|
||||
|
||||
mode: u32,
|
||||
uid: uid_t,
|
||||
gid: gid_t,
|
||||
__pad0: u32,
|
||||
rdev: dev_t,
|
||||
size: off_t,
|
||||
blksize: isize,
|
||||
blocks: i64,
|
||||
|
||||
atim: timespec,
|
||||
mtim: timespec,
|
||||
ctim: timespec,
|
||||
__unused: [3]isize,
|
||||
|
||||
pub fn atime(self: @This()) timespec {
|
||||
return self.atim;
|
||||
}
|
||||
|
||||
pub fn mtime(self: @This()) timespec {
|
||||
return self.mtim;
|
||||
}
|
||||
|
||||
pub fn ctime(self: @This()) timespec {
|
||||
return self.ctim;
|
||||
}
|
||||
};
|
||||
|
||||
// The `stat64` definition used by the libc.
|
||||
pub const libc_stat = kernel_stat;
|
||||
|
||||
pub const timespec = extern struct {
|
||||
tv_sec: isize,
|
||||
tv_nsec: isize,
|
||||
};
|
||||
|
||||
pub const timeval = extern struct {
|
||||
tv_sec: isize,
|
||||
tv_usec: isize,
|
||||
};
|
||||
|
||||
pub const timezone = extern struct {
|
||||
tz_minuteswest: i32,
|
||||
tz_dsttime: i32,
|
||||
};
|
||||
|
||||
pub const Elf_Symndx = u32;
|
||||
|
||||
pub const greg_t = usize;
|
||||
pub const gregset_t = [23]greg_t;
|
||||
pub const fpstate = extern struct {
|
||||
cwd: u16,
|
||||
swd: u16,
|
||||
ftw: u16,
|
||||
fop: u16,
|
||||
rip: usize,
|
||||
rdp: usize,
|
||||
mxcsr: u32,
|
||||
mxcr_mask: u32,
|
||||
st: [8]extern struct {
|
||||
significand: [4]u16,
|
||||
exponent: u16,
|
||||
padding: [3]u16 = undefined,
|
||||
},
|
||||
xmm: [16]extern struct {
|
||||
element: [4]u32,
|
||||
},
|
||||
padding: [24]u32 = undefined,
|
||||
};
|
||||
pub const fpregset_t = *fpstate;
|
||||
pub const sigcontext = extern struct {
|
||||
r8: usize,
|
||||
r9: usize,
|
||||
r10: usize,
|
||||
r11: usize,
|
||||
r12: usize,
|
||||
r13: usize,
|
||||
r14: usize,
|
||||
r15: usize,
|
||||
|
||||
rdi: usize,
|
||||
rsi: usize,
|
||||
rbp: usize,
|
||||
rbx: usize,
|
||||
rdx: usize,
|
||||
rax: usize,
|
||||
rcx: usize,
|
||||
rsp: usize,
|
||||
rip: usize,
|
||||
eflags: usize,
|
||||
|
||||
cs: u16,
|
||||
gs: u16,
|
||||
fs: u16,
|
||||
pad0: u16 = undefined,
|
||||
|
||||
err: usize,
|
||||
trapno: usize,
|
||||
oldmask: usize,
|
||||
cr2: usize,
|
||||
|
||||
fpstate: *fpstate,
|
||||
reserved1: [8]usize = undefined,
|
||||
};
|
||||
|
||||
pub const mcontext_t = extern struct {
|
||||
gregs: gregset_t,
|
||||
fpregs: fpregset_t,
|
||||
reserved1: [8]usize = undefined,
|
||||
};
|
||||
|
||||
pub const ucontext_t = extern struct {
|
||||
flags: usize,
|
||||
link: *ucontext_t,
|
||||
stack: stack_t,
|
||||
mcontext: mcontext_t,
|
||||
sigmask: sigset_t,
|
||||
fpregs_mem: [64]usize,
|
||||
};
|
||||
@ -1,77 +0,0 @@
|
||||
usingnamespace @import("../linux.zig");
|
||||
|
||||
pub const XDP_SHARED_UMEM = (1 << 0);
|
||||
pub const XDP_COPY = (1 << 1);
|
||||
pub const XDP_ZEROCOPY = (1 << 2);
|
||||
|
||||
pub const XDP_UMEM_UNALIGNED_CHUNK_FLAG = (1 << 0);
|
||||
|
||||
pub const sockaddr_xdp = extern struct {
|
||||
family: u16 = AF_XDP,
|
||||
flags: u16,
|
||||
ifindex: u32,
|
||||
queue_id: u32,
|
||||
shared_umem_fd: u32,
|
||||
};
|
||||
|
||||
pub const XDP_USE_NEED_WAKEUP = (1 << 3);
|
||||
|
||||
pub const xdp_ring_offset = extern struct {
|
||||
producer: u64,
|
||||
consumer: u64,
|
||||
desc: u64,
|
||||
flags: u64,
|
||||
};
|
||||
|
||||
pub const xdp_mmap_offsets = extern struct {
|
||||
rx: xdp_ring_offset,
|
||||
tx: xdp_ring_offset,
|
||||
fr: xdp_ring_offset,
|
||||
cr: xdp_ring_offset,
|
||||
};
|
||||
|
||||
pub const XDP_MMAP_OFFSETS = 1;
|
||||
pub const XDP_RX_RING = 2;
|
||||
pub const XDP_TX_RING = 3;
|
||||
pub const XDP_UMEM_REG = 4;
|
||||
pub const XDP_UMEM_FILL_RING = 5;
|
||||
pub const XDP_UMEM_COMPLETION_RING = 6;
|
||||
pub const XDP_STATISTICS = 7;
|
||||
pub const XDP_OPTIONS = 8;
|
||||
|
||||
pub const xdp_umem_reg = extern struct {
|
||||
addr: u64,
|
||||
len: u64,
|
||||
chunk_size: u32,
|
||||
headroom: u32,
|
||||
flags: u32,
|
||||
};
|
||||
|
||||
pub const xdp_statistics = extern struct {
|
||||
rx_dropped: u64,
|
||||
rx_invalid_descs: u64,
|
||||
tx_invalid_descs: u64,
|
||||
rx_ring_full: u64,
|
||||
rx_fill_ring_empty_descs: u64,
|
||||
tx_ring_empty_descs: u64,
|
||||
};
|
||||
|
||||
pub const xdp_options = extern struct {
|
||||
flags: u32,
|
||||
};
|
||||
|
||||
pub const XDP_OPTIONS_ZEROCOPY = (1 << 0);
|
||||
|
||||
pub const XDP_PGOFF_RX_RING = 0;
|
||||
pub const XDP_PGOFF_TX_RING = 0x80000000;
|
||||
pub const XDP_UMEM_PGOFF_FILL_RING = 0x100000000;
|
||||
pub const XDP_UMEM_PGOFF_COMPLETION_RING = 0x180000000;
|
||||
|
||||
pub const XSK_UNALIGNED_BUF_OFFSET_SHIFT = 48;
|
||||
pub const XSK_UNALIGNED_BUF_ADDR_MASK = (1 << XSK_UNALIGNED_BUF_OFFSET_SHIFT) - 1;
|
||||
|
||||
pub const xdp_desc = extern struct {
|
||||
addr: u64,
|
||||
len: u32,
|
||||
options: u32,
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,28 +0,0 @@
|
||||
pub const iovec = extern struct {
|
||||
iov_base: [*]u8,
|
||||
iov_len: usize,
|
||||
};
|
||||
|
||||
pub const iovec_const = extern struct {
|
||||
iov_base: [*]const u8,
|
||||
iov_len: usize,
|
||||
};
|
||||
|
||||
// syslog
|
||||
|
||||
/// system is unusable
|
||||
pub const LOG_EMERG = 0;
|
||||
/// action must be taken immediately
|
||||
pub const LOG_ALERT = 1;
|
||||
/// critical conditions
|
||||
pub const LOG_CRIT = 2;
|
||||
/// error conditions
|
||||
pub const LOG_ERR = 3;
|
||||
/// warning conditions
|
||||
pub const LOG_WARNING = 4;
|
||||
/// normal but significant condition
|
||||
pub const LOG_NOTICE = 5;
|
||||
/// informational
|
||||
pub const LOG_INFO = 6;
|
||||
/// debug-level messages
|
||||
pub const LOG_DEBUG = 7;
|
||||
@ -1,490 +0,0 @@
|
||||
// Convenience types and consts used by std.os module
|
||||
const builtin = @import("builtin");
|
||||
const posix = @import("posix.zig");
|
||||
pub const iovec = posix.iovec;
|
||||
pub const iovec_const = posix.iovec_const;
|
||||
|
||||
pub const STDIN_FILENO = 0;
|
||||
pub const STDOUT_FILENO = 1;
|
||||
pub const STDERR_FILENO = 2;
|
||||
|
||||
pub const mode_t = u32;
|
||||
|
||||
pub const time_t = i64; // match https://github.com/CraneStation/wasi-libc
|
||||
|
||||
pub const timespec = struct {
|
||||
tv_sec: time_t,
|
||||
tv_nsec: isize,
|
||||
|
||||
pub fn fromTimestamp(tm: timestamp_t) timespec {
|
||||
const tv_sec: timestamp_t = tm / 1_000_000_000;
|
||||
const tv_nsec = tm - tv_sec * 1_000_000_000;
|
||||
return timespec{
|
||||
.tv_sec = @intCast(time_t, tv_sec),
|
||||
.tv_nsec = @intCast(isize, tv_nsec),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn toTimestamp(ts: timespec) timestamp_t {
|
||||
const tm = @intCast(timestamp_t, ts.tv_sec * 1_000_000_000) + @intCast(timestamp_t, ts.tv_nsec);
|
||||
return tm;
|
||||
}
|
||||
};
|
||||
|
||||
pub const kernel_stat = struct {
|
||||
dev: device_t,
|
||||
ino: inode_t,
|
||||
mode: mode_t,
|
||||
filetype: filetype_t,
|
||||
nlink: linkcount_t,
|
||||
size: filesize_t,
|
||||
atim: timespec,
|
||||
mtim: timespec,
|
||||
ctim: timespec,
|
||||
|
||||
const Self = @This();
|
||||
|
||||
pub fn fromFilestat(stat: filestat_t) Self {
|
||||
return Self{
|
||||
.dev = stat.dev,
|
||||
.ino = stat.ino,
|
||||
.mode = 0,
|
||||
.filetype = stat.filetype,
|
||||
.nlink = stat.nlink,
|
||||
.size = stat.size,
|
||||
.atim = stat.atime(),
|
||||
.mtim = stat.mtime(),
|
||||
.ctim = stat.ctime(),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn atime(self: Self) timespec {
|
||||
return self.atim;
|
||||
}
|
||||
|
||||
pub fn mtime(self: Self) timespec {
|
||||
return self.mtim;
|
||||
}
|
||||
|
||||
pub fn ctime(self: Self) timespec {
|
||||
return self.ctim;
|
||||
}
|
||||
};
|
||||
|
||||
pub const IOV_MAX = 1024;
|
||||
|
||||
pub const AT_REMOVEDIR: u32 = 0x4;
|
||||
pub const AT_FDCWD: fd_t = -2;
|
||||
|
||||
// As defined in the wasi_snapshot_preview1 spec file:
|
||||
// https://github.com/WebAssembly/WASI/blob/master/phases/snapshot/witx/typenames.witx
|
||||
pub const advice_t = u8;
|
||||
pub const ADVICE_NORMAL: advice_t = 0;
|
||||
pub const ADVICE_SEQUENTIAL: advice_t = 1;
|
||||
pub const ADVICE_RANDOM: advice_t = 2;
|
||||
pub const ADVICE_WILLNEED: advice_t = 3;
|
||||
pub const ADVICE_DONTNEED: advice_t = 4;
|
||||
pub const ADVICE_NOREUSE: advice_t = 5;
|
||||
|
||||
pub const clockid_t = u32;
|
||||
pub const CLOCK_REALTIME: clockid_t = 0;
|
||||
pub const CLOCK_MONOTONIC: clockid_t = 1;
|
||||
pub const CLOCK_PROCESS_CPUTIME_ID: clockid_t = 2;
|
||||
pub const CLOCK_THREAD_CPUTIME_ID: clockid_t = 3;
|
||||
|
||||
pub const device_t = u64;
|
||||
|
||||
pub const dircookie_t = u64;
|
||||
pub const DIRCOOKIE_START: dircookie_t = 0;
|
||||
|
||||
pub const dirnamlen_t = u32;
|
||||
|
||||
pub const dirent_t = extern struct {
|
||||
d_next: dircookie_t,
|
||||
d_ino: inode_t,
|
||||
d_namlen: dirnamlen_t,
|
||||
d_type: filetype_t,
|
||||
};
|
||||
|
||||
pub const errno_t = enum(u16) {
|
||||
SUCCESS = 0,
|
||||
@"2BIG" = 1,
|
||||
ACCES = 2,
|
||||
ADDRINUSE = 3,
|
||||
ADDRNOTAVAIL = 4,
|
||||
AFNOSUPPORT = 5,
|
||||
/// This is also the error code used for `WOULDBLOCK`.
|
||||
AGAIN = 6,
|
||||
ALREADY = 7,
|
||||
BADF = 8,
|
||||
BADMSG = 9,
|
||||
BUSY = 10,
|
||||
CANCELED = 11,
|
||||
CHILD = 12,
|
||||
CONNABORTED = 13,
|
||||
CONNREFUSED = 14,
|
||||
CONNRESET = 15,
|
||||
DEADLK = 16,
|
||||
DESTADDRREQ = 17,
|
||||
DOM = 18,
|
||||
DQUOT = 19,
|
||||
EXIST = 20,
|
||||
FAULT = 21,
|
||||
FBIG = 22,
|
||||
HOSTUNREACH = 23,
|
||||
IDRM = 24,
|
||||
ILSEQ = 25,
|
||||
INPROGRESS = 26,
|
||||
INTR = 27,
|
||||
INVAL = 28,
|
||||
IO = 29,
|
||||
ISCONN = 30,
|
||||
ISDIR = 31,
|
||||
LOOP = 32,
|
||||
MFILE = 33,
|
||||
MLINK = 34,
|
||||
MSGSIZE = 35,
|
||||
MULTIHOP = 36,
|
||||
NAMETOOLONG = 37,
|
||||
NETDOWN = 38,
|
||||
NETRESET = 39,
|
||||
NETUNREACH = 40,
|
||||
NFILE = 41,
|
||||
NOBUFS = 42,
|
||||
NODEV = 43,
|
||||
NOENT = 44,
|
||||
NOEXEC = 45,
|
||||
NOLCK = 46,
|
||||
NOLINK = 47,
|
||||
NOMEM = 48,
|
||||
NOMSG = 49,
|
||||
NOPROTOOPT = 50,
|
||||
NOSPC = 51,
|
||||
NOSYS = 52,
|
||||
NOTCONN = 53,
|
||||
NOTDIR = 54,
|
||||
NOTEMPTY = 55,
|
||||
NOTRECOVERABLE = 56,
|
||||
NOTSOCK = 57,
|
||||
/// This is also the code used for `NOTSUP`.
|
||||
OPNOTSUPP = 58,
|
||||
NOTTY = 59,
|
||||
NXIO = 60,
|
||||
OVERFLOW = 61,
|
||||
OWNERDEAD = 62,
|
||||
PERM = 63,
|
||||
PIPE = 64,
|
||||
PROTO = 65,
|
||||
PROTONOSUPPORT = 66,
|
||||
PROTOTYPE = 67,
|
||||
RANGE = 68,
|
||||
ROFS = 69,
|
||||
SPIPE = 70,
|
||||
SRCH = 71,
|
||||
STALE = 72,
|
||||
TIMEDOUT = 73,
|
||||
TXTBSY = 74,
|
||||
XDEV = 75,
|
||||
NOTCAPABLE = 76,
|
||||
_,
|
||||
};
|
||||
pub const E = errno_t;
|
||||
|
||||
pub const event_t = extern struct {
|
||||
userdata: userdata_t,
|
||||
@"error": errno_t,
|
||||
@"type": eventtype_t,
|
||||
fd_readwrite: eventfdreadwrite_t,
|
||||
};
|
||||
|
||||
pub const eventfdreadwrite_t = extern struct {
|
||||
nbytes: filesize_t,
|
||||
flags: eventrwflags_t,
|
||||
};
|
||||
|
||||
pub const eventrwflags_t = u16;
|
||||
pub const EVENT_FD_READWRITE_HANGUP: eventrwflags_t = 0x0001;
|
||||
|
||||
pub const eventtype_t = u8;
|
||||
pub const EVENTTYPE_CLOCK: eventtype_t = 0;
|
||||
pub const EVENTTYPE_FD_READ: eventtype_t = 1;
|
||||
pub const EVENTTYPE_FD_WRITE: eventtype_t = 2;
|
||||
|
||||
pub const exitcode_t = u32;
|
||||
|
||||
pub const fd_t = if (builtin.link_libc) c_int else u32;
|
||||
|
||||
pub const fdflags_t = u16;
|
||||
pub const FDFLAG_APPEND: fdflags_t = 0x0001;
|
||||
pub const FDFLAG_DSYNC: fdflags_t = 0x0002;
|
||||
pub const FDFLAG_NONBLOCK: fdflags_t = 0x0004;
|
||||
pub const FDFLAG_RSYNC: fdflags_t = 0x0008;
|
||||
pub const FDFLAG_SYNC: fdflags_t = 0x0010;
|
||||
|
||||
pub const fdstat_t = extern struct {
|
||||
fs_filetype: filetype_t,
|
||||
fs_flags: fdflags_t,
|
||||
fs_rights_base: rights_t,
|
||||
fs_rights_inheriting: rights_t,
|
||||
};
|
||||
|
||||
pub const filedelta_t = i64;
|
||||
|
||||
pub const filesize_t = u64;
|
||||
|
||||
pub const filestat_t = extern struct {
|
||||
dev: device_t,
|
||||
ino: inode_t,
|
||||
filetype: filetype_t,
|
||||
nlink: linkcount_t,
|
||||
size: filesize_t,
|
||||
atim: timestamp_t,
|
||||
mtim: timestamp_t,
|
||||
ctim: timestamp_t,
|
||||
|
||||
pub fn atime(self: filestat_t) timespec {
|
||||
return timespec.fromTimestamp(self.atim);
|
||||
}
|
||||
|
||||
pub fn mtime(self: filestat_t) timespec {
|
||||
return timespec.fromTimestamp(self.mtim);
|
||||
}
|
||||
|
||||
pub fn ctime(self: filestat_t) timespec {
|
||||
return timespec.fromTimestamp(self.ctim);
|
||||
}
|
||||
};
|
||||
|
||||
pub const filetype_t = u8;
|
||||
pub const FILETYPE_UNKNOWN: filetype_t = 0;
|
||||
pub const FILETYPE_BLOCK_DEVICE: filetype_t = 1;
|
||||
pub const FILETYPE_CHARACTER_DEVICE: filetype_t = 2;
|
||||
pub const FILETYPE_DIRECTORY: filetype_t = 3;
|
||||
pub const FILETYPE_REGULAR_FILE: filetype_t = 4;
|
||||
pub const FILETYPE_SOCKET_DGRAM: filetype_t = 5;
|
||||
pub const FILETYPE_SOCKET_STREAM: filetype_t = 6;
|
||||
pub const FILETYPE_SYMBOLIC_LINK: filetype_t = 7;
|
||||
|
||||
pub const fstflags_t = u16;
|
||||
pub const FILESTAT_SET_ATIM: fstflags_t = 0x0001;
|
||||
pub const FILESTAT_SET_ATIM_NOW: fstflags_t = 0x0002;
|
||||
pub const FILESTAT_SET_MTIM: fstflags_t = 0x0004;
|
||||
pub const FILESTAT_SET_MTIM_NOW: fstflags_t = 0x0008;
|
||||
|
||||
pub const inode_t = u64;
|
||||
pub const ino_t = inode_t;
|
||||
|
||||
pub const linkcount_t = u64;
|
||||
|
||||
pub const lookupflags_t = u32;
|
||||
pub const LOOKUP_SYMLINK_FOLLOW: lookupflags_t = 0x00000001;
|
||||
|
||||
pub usingnamespace if (builtin.link_libc) struct {
|
||||
// Derived from https://github.com/WebAssembly/wasi-libc/blob/main/expected/wasm32-wasi/predefined-macros.txt
|
||||
pub const O_ACCMODE = (O_EXEC | O_RDWR | O_SEARCH);
|
||||
pub const O_APPEND = FDFLAG_APPEND;
|
||||
pub const O_CLOEXEC = (0);
|
||||
pub const O_CREAT = ((1 << 0) << 12); // = __WASI_OFLAGS_CREAT << 12
|
||||
pub const O_DIRECTORY = ((1 << 1) << 12); // = __WASI_OFLAGS_DIRECTORY << 12
|
||||
pub const O_DSYNC = FDFLAG_DSYNC;
|
||||
pub const O_EXCL = ((1 << 2) << 12); // = __WASI_OFLAGS_EXCL << 12
|
||||
pub const O_EXEC = (0x02000000);
|
||||
pub const O_NOCTTY = (0);
|
||||
pub const O_NOFOLLOW = (0x01000000);
|
||||
pub const O_NONBLOCK = (1 << FDFLAG_NONBLOCK);
|
||||
pub const O_RDONLY = (0x04000000);
|
||||
pub const O_RDWR = (O_RDONLY | O_WRONLY);
|
||||
pub const O_RSYNC = (1 << FDFLAG_RSYNC);
|
||||
pub const O_SEARCH = (0x08000000);
|
||||
pub const O_SYNC = (1 << FDFLAG_SYNC);
|
||||
pub const O_TRUNC = ((1 << 3) << 12); // = __WASI_OFLAGS_TRUNC << 12
|
||||
pub const O_TTY_INIT = (0);
|
||||
pub const O_WRONLY = (0x10000000);
|
||||
} else struct {
|
||||
pub const oflags_t = u16;
|
||||
pub const O_CREAT: oflags_t = 0x0001;
|
||||
pub const O_DIRECTORY: oflags_t = 0x0002;
|
||||
pub const O_EXCL: oflags_t = 0x0004;
|
||||
pub const O_TRUNC: oflags_t = 0x0008;
|
||||
};
|
||||
|
||||
pub const preopentype_t = u8;
|
||||
pub const PREOPENTYPE_DIR: preopentype_t = 0;
|
||||
|
||||
pub const prestat_t = extern struct {
|
||||
pr_type: preopentype_t,
|
||||
u: prestat_u_t,
|
||||
};
|
||||
|
||||
pub const prestat_dir_t = extern struct {
|
||||
pr_name_len: usize,
|
||||
};
|
||||
|
||||
pub const prestat_u_t = extern union {
|
||||
dir: prestat_dir_t,
|
||||
};
|
||||
|
||||
pub const riflags_t = u16;
|
||||
pub const SOCK_RECV_PEEK: riflags_t = 0x0001;
|
||||
pub const SOCK_RECV_WAITALL: riflags_t = 0x0002;
|
||||
|
||||
pub const rights_t = u64;
|
||||
pub const RIGHT_FD_DATASYNC: rights_t = 0x0000000000000001;
|
||||
pub const RIGHT_FD_READ: rights_t = 0x0000000000000002;
|
||||
pub const RIGHT_FD_SEEK: rights_t = 0x0000000000000004;
|
||||
pub const RIGHT_FD_FDSTAT_SET_FLAGS: rights_t = 0x0000000000000008;
|
||||
pub const RIGHT_FD_SYNC: rights_t = 0x0000000000000010;
|
||||
pub const RIGHT_FD_TELL: rights_t = 0x0000000000000020;
|
||||
pub const RIGHT_FD_WRITE: rights_t = 0x0000000000000040;
|
||||
pub const RIGHT_FD_ADVISE: rights_t = 0x0000000000000080;
|
||||
pub const RIGHT_FD_ALLOCATE: rights_t = 0x0000000000000100;
|
||||
pub const RIGHT_PATH_CREATE_DIRECTORY: rights_t = 0x0000000000000200;
|
||||
pub const RIGHT_PATH_CREATE_FILE: rights_t = 0x0000000000000400;
|
||||
pub const RIGHT_PATH_LINK_SOURCE: rights_t = 0x0000000000000800;
|
||||
pub const RIGHT_PATH_LINK_TARGET: rights_t = 0x0000000000001000;
|
||||
pub const RIGHT_PATH_OPEN: rights_t = 0x0000000000002000;
|
||||
pub const RIGHT_FD_READDIR: rights_t = 0x0000000000004000;
|
||||
pub const RIGHT_PATH_READLINK: rights_t = 0x0000000000008000;
|
||||
pub const RIGHT_PATH_RENAME_SOURCE: rights_t = 0x0000000000010000;
|
||||
pub const RIGHT_PATH_RENAME_TARGET: rights_t = 0x0000000000020000;
|
||||
pub const RIGHT_PATH_FILESTAT_GET: rights_t = 0x0000000000040000;
|
||||
pub const RIGHT_PATH_FILESTAT_SET_SIZE: rights_t = 0x0000000000080000;
|
||||
pub const RIGHT_PATH_FILESTAT_SET_TIMES: rights_t = 0x0000000000100000;
|
||||
pub const RIGHT_FD_FILESTAT_GET: rights_t = 0x0000000000200000;
|
||||
pub const RIGHT_FD_FILESTAT_SET_SIZE: rights_t = 0x0000000000400000;
|
||||
pub const RIGHT_FD_FILESTAT_SET_TIMES: rights_t = 0x0000000000800000;
|
||||
pub const RIGHT_PATH_SYMLINK: rights_t = 0x0000000001000000;
|
||||
pub const RIGHT_PATH_REMOVE_DIRECTORY: rights_t = 0x0000000002000000;
|
||||
pub const RIGHT_PATH_UNLINK_FILE: rights_t = 0x0000000004000000;
|
||||
pub const RIGHT_POLL_FD_READWRITE: rights_t = 0x0000000008000000;
|
||||
pub const RIGHT_SOCK_SHUTDOWN: rights_t = 0x0000000010000000;
|
||||
pub const RIGHT_ALL: rights_t = RIGHT_FD_DATASYNC |
|
||||
RIGHT_FD_READ |
|
||||
RIGHT_FD_SEEK |
|
||||
RIGHT_FD_FDSTAT_SET_FLAGS |
|
||||
RIGHT_FD_SYNC |
|
||||
RIGHT_FD_TELL |
|
||||
RIGHT_FD_WRITE |
|
||||
RIGHT_FD_ADVISE |
|
||||
RIGHT_FD_ALLOCATE |
|
||||
RIGHT_PATH_CREATE_DIRECTORY |
|
||||
RIGHT_PATH_CREATE_FILE |
|
||||
RIGHT_PATH_LINK_SOURCE |
|
||||
RIGHT_PATH_LINK_TARGET |
|
||||
RIGHT_PATH_OPEN |
|
||||
RIGHT_FD_READDIR |
|
||||
RIGHT_PATH_READLINK |
|
||||
RIGHT_PATH_RENAME_SOURCE |
|
||||
RIGHT_PATH_RENAME_TARGET |
|
||||
RIGHT_PATH_FILESTAT_GET |
|
||||
RIGHT_PATH_FILESTAT_SET_SIZE |
|
||||
RIGHT_PATH_FILESTAT_SET_TIMES |
|
||||
RIGHT_FD_FILESTAT_GET |
|
||||
RIGHT_FD_FILESTAT_SET_SIZE |
|
||||
RIGHT_FD_FILESTAT_SET_TIMES |
|
||||
RIGHT_PATH_SYMLINK |
|
||||
RIGHT_PATH_REMOVE_DIRECTORY |
|
||||
RIGHT_PATH_UNLINK_FILE |
|
||||
RIGHT_POLL_FD_READWRITE |
|
||||
RIGHT_SOCK_SHUTDOWN;
|
||||
|
||||
pub const roflags_t = u16;
|
||||
pub const SOCK_RECV_DATA_TRUNCATED: roflags_t = 0x0001;
|
||||
|
||||
pub const sdflags_t = u8;
|
||||
pub const SHUT_RD: sdflags_t = 0x01;
|
||||
pub const SHUT_WR: sdflags_t = 0x02;
|
||||
|
||||
pub const siflags_t = u16;
|
||||
|
||||
pub const signal_t = u8;
|
||||
pub const SIGNONE: signal_t = 0;
|
||||
pub const SIGHUP: signal_t = 1;
|
||||
pub const SIGINT: signal_t = 2;
|
||||
pub const SIGQUIT: signal_t = 3;
|
||||
pub const SIGILL: signal_t = 4;
|
||||
pub const SIGTRAP: signal_t = 5;
|
||||
pub const SIGABRT: signal_t = 6;
|
||||
pub const SIGBUS: signal_t = 7;
|
||||
pub const SIGFPE: signal_t = 8;
|
||||
pub const SIGKILL: signal_t = 9;
|
||||
pub const SIGUSR1: signal_t = 10;
|
||||
pub const SIGSEGV: signal_t = 11;
|
||||
pub const SIGUSR2: signal_t = 12;
|
||||
pub const SIGPIPE: signal_t = 13;
|
||||
pub const SIGALRM: signal_t = 14;
|
||||
pub const SIGTERM: signal_t = 15;
|
||||
pub const SIGCHLD: signal_t = 16;
|
||||
pub const SIGCONT: signal_t = 17;
|
||||
pub const SIGSTOP: signal_t = 18;
|
||||
pub const SIGTSTP: signal_t = 19;
|
||||
pub const SIGTTIN: signal_t = 20;
|
||||
pub const SIGTTOU: signal_t = 21;
|
||||
pub const SIGURG: signal_t = 22;
|
||||
pub const SIGXCPU: signal_t = 23;
|
||||
pub const SIGXFSZ: signal_t = 24;
|
||||
pub const SIGVTALRM: signal_t = 25;
|
||||
pub const SIGPROF: signal_t = 26;
|
||||
pub const SIGWINCH: signal_t = 27;
|
||||
pub const SIGPOLL: signal_t = 28;
|
||||
pub const SIGPWR: signal_t = 29;
|
||||
pub const SIGSYS: signal_t = 30;
|
||||
|
||||
pub const subclockflags_t = u16;
|
||||
pub const SUBSCRIPTION_CLOCK_ABSTIME: subclockflags_t = 0x0001;
|
||||
|
||||
pub const subscription_t = extern struct {
|
||||
userdata: userdata_t,
|
||||
u: subscription_u_t,
|
||||
};
|
||||
|
||||
pub const subscription_clock_t = extern struct {
|
||||
id: clockid_t,
|
||||
timeout: timestamp_t,
|
||||
precision: timestamp_t,
|
||||
flags: subclockflags_t,
|
||||
};
|
||||
|
||||
pub const subscription_fd_readwrite_t = extern struct {
|
||||
fd: fd_t,
|
||||
};
|
||||
|
||||
pub const subscription_u_t = extern struct {
|
||||
tag: eventtype_t,
|
||||
u: subscription_u_u_t,
|
||||
};
|
||||
|
||||
pub const subscription_u_u_t = extern union {
|
||||
clock: subscription_clock_t,
|
||||
fd_read: subscription_fd_readwrite_t,
|
||||
fd_write: subscription_fd_readwrite_t,
|
||||
};
|
||||
|
||||
pub const timestamp_t = u64;
|
||||
|
||||
pub const userdata_t = u64;
|
||||
|
||||
pub const whence_t = u8;
|
||||
pub const WHENCE_SET: whence_t = 0;
|
||||
pub const WHENCE_CUR: whence_t = 1;
|
||||
pub const WHENCE_END: whence_t = 2;
|
||||
|
||||
pub const S_IEXEC = S_IXUSR;
|
||||
pub const S_IFBLK = 0x6000;
|
||||
pub const S_IFCHR = 0x2000;
|
||||
pub const S_IFDIR = 0x4000;
|
||||
pub const S_IFIFO = 0xc000;
|
||||
pub const S_IFLNK = 0xa000;
|
||||
pub const S_IFMT = S_IFBLK | S_IFCHR | S_IFDIR | S_IFIFO | S_IFLNK | S_IFREG | S_IFSOCK;
|
||||
pub const S_IFREG = 0x8000;
|
||||
// There's no concept of UNIX domain socket but we define this value here in order to line with other OSes.
|
||||
pub const S_IFSOCK = 0x1;
|
||||
|
||||
pub const SEEK_SET = WHENCE_SET;
|
||||
pub const SEEK_CUR = WHENCE_CUR;
|
||||
pub const SEEK_END = WHENCE_END;
|
||||
|
||||
pub const LOCK_SH = 0x1;
|
||||
pub const LOCK_EX = 0x2;
|
||||
pub const LOCK_NB = 0x4;
|
||||
pub const LOCK_UN = 0x8;
|
||||
@ -1,329 +0,0 @@
|
||||
// The reference for these types and values is Microsoft Windows's ucrt (Universal C RunTime).
|
||||
|
||||
usingnamespace @import("../windows/bits.zig");
|
||||
const ws2_32 = @import("../windows/ws2_32.zig");
|
||||
|
||||
// TODO: Stop using os.iovec in std.fs et al on Windows in the future
|
||||
const posix = @import("posix.zig");
|
||||
pub const iovec = posix.iovec;
|
||||
pub const iovec_const = posix.iovec_const;
|
||||
|
||||
pub const fd_t = HANDLE;
|
||||
pub const ino_t = LARGE_INTEGER;
|
||||
pub const pid_t = HANDLE;
|
||||
pub const mode_t = u0;
|
||||
|
||||
pub const PATH_MAX = 260;
|
||||
|
||||
pub const time_t = c_longlong;
|
||||
|
||||
pub const timespec = extern struct {
|
||||
tv_sec: time_t,
|
||||
tv_nsec: c_long,
|
||||
};
|
||||
|
||||
pub const timeval = extern struct {
|
||||
tv_sec: c_long,
|
||||
tv_usec: c_long,
|
||||
};
|
||||
|
||||
pub const sig_atomic_t = c_int;
|
||||
|
||||
/// maximum signal number + 1
|
||||
pub const NSIG = 23;
|
||||
|
||||
// Signal types
|
||||
|
||||
/// interrupt
|
||||
pub const SIGINT = 2;
|
||||
|
||||
/// illegal instruction - invalid function image
|
||||
pub const SIGILL = 4;
|
||||
|
||||
/// floating point exception
|
||||
pub const SIGFPE = 8;
|
||||
|
||||
/// segment violation
|
||||
pub const SIGSEGV = 11;
|
||||
|
||||
/// Software termination signal from kill
|
||||
pub const SIGTERM = 15;
|
||||
|
||||
/// Ctrl-Break sequence
|
||||
pub const SIGBREAK = 21;
|
||||
|
||||
/// abnormal termination triggered by abort call
|
||||
pub const SIGABRT = 22;
|
||||
|
||||
/// SIGABRT compatible with other platforms, same as SIGABRT
|
||||
pub const SIGABRT_COMPAT = 6;
|
||||
|
||||
// Signal action codes
|
||||
|
||||
/// default signal action
|
||||
pub const SIG_DFL = 0;
|
||||
|
||||
/// ignore signal
|
||||
pub const SIG_IGN = 1;
|
||||
|
||||
/// return current value
|
||||
pub const SIG_GET = 2;
|
||||
|
||||
/// signal gets error
|
||||
pub const SIG_SGE = 3;
|
||||
|
||||
/// acknowledge
|
||||
pub const SIG_ACK = 4;
|
||||
|
||||
/// Signal error value (returned by signal call on error)
|
||||
pub const SIG_ERR = -1;
|
||||
|
||||
pub const SEEK_SET = 0;
|
||||
pub const SEEK_CUR = 1;
|
||||
pub const SEEK_END = 2;
|
||||
|
||||
pub const E = enum(u16) {
|
||||
/// No error occurred.
|
||||
SUCCESS = 0,
|
||||
PERM = 1,
|
||||
NOENT = 2,
|
||||
SRCH = 3,
|
||||
INTR = 4,
|
||||
IO = 5,
|
||||
NXIO = 6,
|
||||
@"2BIG" = 7,
|
||||
NOEXEC = 8,
|
||||
BADF = 9,
|
||||
CHILD = 10,
|
||||
AGAIN = 11,
|
||||
NOMEM = 12,
|
||||
ACCES = 13,
|
||||
FAULT = 14,
|
||||
BUSY = 16,
|
||||
EXIST = 17,
|
||||
XDEV = 18,
|
||||
NODEV = 19,
|
||||
NOTDIR = 20,
|
||||
ISDIR = 21,
|
||||
NFILE = 23,
|
||||
MFILE = 24,
|
||||
NOTTY = 25,
|
||||
FBIG = 27,
|
||||
NOSPC = 28,
|
||||
SPIPE = 29,
|
||||
ROFS = 30,
|
||||
MLINK = 31,
|
||||
PIPE = 32,
|
||||
DOM = 33,
|
||||
/// Also means `DEADLOCK`.
|
||||
DEADLK = 36,
|
||||
NAMETOOLONG = 38,
|
||||
NOLCK = 39,
|
||||
NOSYS = 40,
|
||||
NOTEMPTY = 41,
|
||||
|
||||
INVAL = 22,
|
||||
RANGE = 34,
|
||||
ILSEQ = 42,
|
||||
|
||||
// POSIX Supplement
|
||||
ADDRINUSE = 100,
|
||||
ADDRNOTAVAIL = 101,
|
||||
AFNOSUPPORT = 102,
|
||||
ALREADY = 103,
|
||||
BADMSG = 104,
|
||||
CANCELED = 105,
|
||||
CONNABORTED = 106,
|
||||
CONNREFUSED = 107,
|
||||
CONNRESET = 108,
|
||||
DESTADDRREQ = 109,
|
||||
HOSTUNREACH = 110,
|
||||
IDRM = 111,
|
||||
INPROGRESS = 112,
|
||||
ISCONN = 113,
|
||||
LOOP = 114,
|
||||
MSGSIZE = 115,
|
||||
NETDOWN = 116,
|
||||
NETRESET = 117,
|
||||
NETUNREACH = 118,
|
||||
NOBUFS = 119,
|
||||
NODATA = 120,
|
||||
NOLINK = 121,
|
||||
NOMSG = 122,
|
||||
NOPROTOOPT = 123,
|
||||
NOSR = 124,
|
||||
NOSTR = 125,
|
||||
NOTCONN = 126,
|
||||
NOTRECOVERABLE = 127,
|
||||
NOTSOCK = 128,
|
||||
NOTSUP = 129,
|
||||
OPNOTSUPP = 130,
|
||||
OTHER = 131,
|
||||
OVERFLOW = 132,
|
||||
OWNERDEAD = 133,
|
||||
PROTO = 134,
|
||||
PROTONOSUPPORT = 135,
|
||||
PROTOTYPE = 136,
|
||||
TIME = 137,
|
||||
TIMEDOUT = 138,
|
||||
TXTBSY = 139,
|
||||
WOULDBLOCK = 140,
|
||||
DQUOT = 10069,
|
||||
_,
|
||||
};
|
||||
|
||||
pub const STRUNCATE = 80;
|
||||
|
||||
pub const F_OK = 0;
|
||||
|
||||
/// Remove directory instead of unlinking file
|
||||
pub const AT_REMOVEDIR = 0x200;
|
||||
|
||||
pub const in_port_t = u16;
|
||||
pub const sa_family_t = ws2_32.ADDRESS_FAMILY;
|
||||
pub const socklen_t = ws2_32.socklen_t;
|
||||
|
||||
pub const sockaddr = ws2_32.sockaddr;
|
||||
pub const sockaddr_in = ws2_32.sockaddr_in;
|
||||
pub const sockaddr_in6 = ws2_32.sockaddr_in6;
|
||||
pub const sockaddr_un = ws2_32.sockaddr_un;
|
||||
|
||||
pub const in6_addr = [16]u8;
|
||||
pub const in_addr = u32;
|
||||
|
||||
pub const addrinfo = ws2_32.addrinfo;
|
||||
|
||||
pub const AF_UNSPEC = ws2_32.AF_UNSPEC;
|
||||
pub const AF_UNIX = ws2_32.AF_UNIX;
|
||||
pub const AF_INET = ws2_32.AF_INET;
|
||||
pub const AF_IMPLINK = ws2_32.AF_IMPLINK;
|
||||
pub const AF_PUP = ws2_32.AF_PUP;
|
||||
pub const AF_CHAOS = ws2_32.AF_CHAOS;
|
||||
pub const AF_NS = ws2_32.AF_NS;
|
||||
pub const AF_IPX = ws2_32.AF_IPX;
|
||||
pub const AF_ISO = ws2_32.AF_ISO;
|
||||
pub const AF_OSI = ws2_32.AF_OSI;
|
||||
pub const AF_ECMA = ws2_32.AF_ECMA;
|
||||
pub const AF_DATAKIT = ws2_32.AF_DATAKIT;
|
||||
pub const AF_CCITT = ws2_32.AF_CCITT;
|
||||
pub const AF_SNA = ws2_32.AF_SNA;
|
||||
pub const AF_DECnet = ws2_32.AF_DECnet;
|
||||
pub const AF_DLI = ws2_32.AF_DLI;
|
||||
pub const AF_LAT = ws2_32.AF_LAT;
|
||||
pub const AF_HYLINK = ws2_32.AF_HYLINK;
|
||||
pub const AF_APPLETALK = ws2_32.AF_APPLETALK;
|
||||
pub const AF_NETBIOS = ws2_32.AF_NETBIOS;
|
||||
pub const AF_VOICEVIEW = ws2_32.AF_VOICEVIEW;
|
||||
pub const AF_FIREFOX = ws2_32.AF_FIREFOX;
|
||||
pub const AF_UNKNOWN1 = ws2_32.AF_UNKNOWN1;
|
||||
pub const AF_BAN = ws2_32.AF_BAN;
|
||||
pub const AF_ATM = ws2_32.AF_ATM;
|
||||
pub const AF_INET6 = ws2_32.AF_INET6;
|
||||
pub const AF_CLUSTER = ws2_32.AF_CLUSTER;
|
||||
pub const AF_12844 = ws2_32.AF_12844;
|
||||
pub const AF_IRDA = ws2_32.AF_IRDA;
|
||||
pub const AF_NETDES = ws2_32.AF_NETDES;
|
||||
pub const AF_TCNPROCESS = ws2_32.AF_TCNPROCESS;
|
||||
pub const AF_TCNMESSAGE = ws2_32.AF_TCNMESSAGE;
|
||||
pub const AF_ICLFXBM = ws2_32.AF_ICLFXBM;
|
||||
pub const AF_BTH = ws2_32.AF_BTH;
|
||||
pub const AF_MAX = ws2_32.AF_MAX;
|
||||
|
||||
pub const SOCK_STREAM = ws2_32.SOCK_STREAM;
|
||||
pub const SOCK_DGRAM = ws2_32.SOCK_DGRAM;
|
||||
pub const SOCK_RAW = ws2_32.SOCK_RAW;
|
||||
pub const SOCK_RDM = ws2_32.SOCK_RDM;
|
||||
pub const SOCK_SEQPACKET = ws2_32.SOCK_SEQPACKET;
|
||||
|
||||
/// WARNING: this flag is not supported by windows socket functions directly,
|
||||
/// it is only supported by std.os.socket. Be sure that this value does
|
||||
/// not share any bits with any of the SOCK_* values.
|
||||
pub const SOCK_CLOEXEC = 0x10000;
|
||||
/// WARNING: this flag is not supported by windows socket functions directly,
|
||||
/// it is only supported by std.os.socket. Be sure that this value does
|
||||
/// not share any bits with any of the SOCK_* values.
|
||||
pub const SOCK_NONBLOCK = 0x20000;
|
||||
|
||||
pub const IPPROTO_ICMP = ws2_32.IPPROTO_ICMP;
|
||||
pub const IPPROTO_IGMP = ws2_32.IPPROTO_IGMP;
|
||||
pub const BTHPROTO_RFCOMM = ws2_32.BTHPROTO_RFCOMM;
|
||||
pub const IPPROTO_TCP = ws2_32.IPPROTO_TCP;
|
||||
pub const IPPROTO_UDP = ws2_32.IPPROTO_UDP;
|
||||
pub const IPPROTO_ICMPV6 = ws2_32.IPPROTO_ICMPV6;
|
||||
pub const IPPROTO_RM = ws2_32.IPPROTO_RM;
|
||||
|
||||
pub const nfds_t = c_ulong;
|
||||
pub const pollfd = ws2_32.pollfd;
|
||||
|
||||
pub const POLLRDNORM = ws2_32.POLLRDNORM;
|
||||
pub const POLLRDBAND = ws2_32.POLLRDBAND;
|
||||
pub const POLLIN = ws2_32.POLLIN;
|
||||
pub const POLLPRI = ws2_32.POLLPRI;
|
||||
pub const POLLWRNORM = ws2_32.POLLWRNORM;
|
||||
pub const POLLOUT = ws2_32.POLLOUT;
|
||||
pub const POLLWRBAND = ws2_32.POLLWRBAND;
|
||||
pub const POLLERR = ws2_32.POLLERR;
|
||||
pub const POLLHUP = ws2_32.POLLHUP;
|
||||
pub const POLLNVAL = ws2_32.POLLNVAL;
|
||||
|
||||
pub const SOL_SOCKET = ws2_32.SOL_SOCKET;
|
||||
|
||||
pub const SO_DEBUG = ws2_32.SO_DEBUG;
|
||||
pub const SO_ACCEPTCONN = ws2_32.SO_ACCEPTCONN;
|
||||
pub const SO_REUSEADDR = ws2_32.SO_REUSEADDR;
|
||||
pub const SO_KEEPALIVE = ws2_32.SO_KEEPALIVE;
|
||||
pub const SO_DONTROUTE = ws2_32.SO_DONTROUTE;
|
||||
pub const SO_BROADCAST = ws2_32.SO_BROADCAST;
|
||||
pub const SO_USELOOPBACK = ws2_32.SO_USELOOPBACK;
|
||||
pub const SO_LINGER = ws2_32.SO_LINGER;
|
||||
pub const SO_OOBINLINE = ws2_32.SO_OOBINLINE;
|
||||
|
||||
pub const SO_DONTLINGER = ws2_32.SO_DONTLINGER;
|
||||
pub const SO_EXCLUSIVEADDRUSE = ws2_32.SO_EXCLUSIVEADDRUSE;
|
||||
|
||||
pub const SO_SNDBUF = ws2_32.SO_SNDBUF;
|
||||
pub const SO_RCVBUF = ws2_32.SO_RCVBUF;
|
||||
pub const SO_SNDLOWAT = ws2_32.SO_SNDLOWAT;
|
||||
pub const SO_RCVLOWAT = ws2_32.SO_RCVLOWAT;
|
||||
pub const SO_SNDTIMEO = ws2_32.SO_SNDTIMEO;
|
||||
pub const SO_RCVTIMEO = ws2_32.SO_RCVTIMEO;
|
||||
pub const SO_ERROR = ws2_32.SO_ERROR;
|
||||
pub const SO_TYPE = ws2_32.SO_TYPE;
|
||||
|
||||
pub const SO_GROUP_ID = ws2_32.SO_GROUP_ID;
|
||||
pub const SO_GROUP_PRIORITY = ws2_32.SO_GROUP_PRIORITY;
|
||||
pub const SO_MAX_MSG_SIZE = ws2_32.SO_MAX_MSG_SIZE;
|
||||
pub const SO_PROTOCOL_INFOA = ws2_32.SO_PROTOCOL_INFOA;
|
||||
pub const SO_PROTOCOL_INFOW = ws2_32.SO_PROTOCOL_INFOW;
|
||||
|
||||
pub const PVD_CONFIG = ws2_32.PVD_CONFIG;
|
||||
pub const SO_CONDITIONAL_ACCEPT = ws2_32.SO_CONDITIONAL_ACCEPT;
|
||||
|
||||
pub const TCP_NODELAY = ws2_32.TCP_NODELAY;
|
||||
|
||||
pub const O_RDONLY = 0o0;
|
||||
pub const O_WRONLY = 0o1;
|
||||
pub const O_RDWR = 0o2;
|
||||
|
||||
pub const O_CREAT = 0o100;
|
||||
pub const O_EXCL = 0o200;
|
||||
pub const O_NOCTTY = 0o400;
|
||||
pub const O_TRUNC = 0o1000;
|
||||
pub const O_APPEND = 0o2000;
|
||||
pub const O_NONBLOCK = 0o4000;
|
||||
pub const O_DSYNC = 0o10000;
|
||||
pub const O_SYNC = 0o4010000;
|
||||
pub const O_RSYNC = 0o4010000;
|
||||
pub const O_DIRECTORY = 0o200000;
|
||||
pub const O_NOFOLLOW = 0o400000;
|
||||
pub const O_CLOEXEC = 0o2000000;
|
||||
|
||||
pub const O_ASYNC = 0o20000;
|
||||
pub const O_DIRECT = 0o40000;
|
||||
pub const O_LARGEFILE = 0;
|
||||
pub const O_NOATIME = 0o1000000;
|
||||
pub const O_PATH = 0o10000000;
|
||||
pub const O_TMPFILE = 0o20200000;
|
||||
pub const O_NDELAY = O_NONBLOCK;
|
||||
|
||||
pub const IFNAMESIZE = 30;
|
||||
@ -1,3 +0,0 @@
|
||||
const std = @import("../std.zig");
|
||||
pub usingnamespace std.c;
|
||||
pub usingnamespace @import("bits.zig");
|
||||
@ -1,3 +0,0 @@
|
||||
const std = @import("../std.zig");
|
||||
pub usingnamespace std.c;
|
||||
pub usingnamespace @import("bits.zig");
|
||||
@ -1,3 +0,0 @@
|
||||
const std = @import("../std.zig");
|
||||
pub usingnamespace std.c;
|
||||
pub usingnamespace @import("bits.zig");
|
||||
@ -1,3 +0,0 @@
|
||||
const std = @import("../std.zig");
|
||||
pub usingnamespace std.c;
|
||||
pub usingnamespace @import("bits.zig");
|
||||
3510
lib/std/os/linux.zig
3510
lib/std/os/linux.zig
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,16 @@
|
||||
usingnamespace @import("../bits/linux.zig");
|
||||
const std = @import("../../std.zig");
|
||||
const maxInt = std.math.maxInt;
|
||||
const linux = std.os.linux;
|
||||
const iovec = std.os.iovec;
|
||||
const iovec_const = std.os.iovec_const;
|
||||
const socklen_t = linux.socklen_t;
|
||||
const stack_t = linux.stack_t;
|
||||
const sigset_t = linux.sigset_t;
|
||||
const uid_t = linux.uid_t;
|
||||
const gid_t = linux.gid_t;
|
||||
const pid_t = linux.pid_t;
|
||||
const sockaddr = linux.sockaddr;
|
||||
const timespec = linux.timespec;
|
||||
|
||||
pub fn syscall0(number: SYS) usize {
|
||||
return asm volatile ("svc #0"
|
||||
@ -86,7 +98,15 @@ pub fn syscall6(
|
||||
}
|
||||
|
||||
/// This matches the libc clone function.
|
||||
pub extern fn clone(func: fn (arg: usize) callconv(.C) u8, stack: usize, flags: u32, arg: usize, ptid: *i32, tls: usize, ctid: *i32) usize;
|
||||
pub extern fn clone(
|
||||
func: fn (arg: usize) callconv(.C) u8,
|
||||
stack: usize,
|
||||
flags: u32,
|
||||
arg: usize,
|
||||
ptid: *i32,
|
||||
tls: usize,
|
||||
ctid: *i32,
|
||||
) usize;
|
||||
|
||||
pub fn restore() callconv(.Naked) void {
|
||||
return asm volatile ("svc #0"
|
||||
@ -103,3 +123,628 @@ pub fn restore_rt() callconv(.Naked) void {
|
||||
: "memory"
|
||||
);
|
||||
}
|
||||
|
||||
pub const SYS = enum(usize) {
|
||||
restart_syscall = 0,
|
||||
exit = 1,
|
||||
fork = 2,
|
||||
read = 3,
|
||||
write = 4,
|
||||
open = 5,
|
||||
close = 6,
|
||||
creat = 8,
|
||||
link = 9,
|
||||
unlink = 10,
|
||||
execve = 11,
|
||||
chdir = 12,
|
||||
mknod = 14,
|
||||
chmod = 15,
|
||||
lchown = 16,
|
||||
lseek = 19,
|
||||
getpid = 20,
|
||||
mount = 21,
|
||||
setuid = 23,
|
||||
getuid = 24,
|
||||
ptrace = 26,
|
||||
pause = 29,
|
||||
access = 33,
|
||||
nice = 34,
|
||||
sync = 36,
|
||||
kill = 37,
|
||||
rename = 38,
|
||||
mkdir = 39,
|
||||
rmdir = 40,
|
||||
dup = 41,
|
||||
pipe = 42,
|
||||
times = 43,
|
||||
brk = 45,
|
||||
setgid = 46,
|
||||
getgid = 47,
|
||||
geteuid = 49,
|
||||
getegid = 50,
|
||||
acct = 51,
|
||||
umount2 = 52,
|
||||
ioctl = 54,
|
||||
fcntl = 55,
|
||||
setpgid = 57,
|
||||
umask = 60,
|
||||
chroot = 61,
|
||||
ustat = 62,
|
||||
dup2 = 63,
|
||||
getppid = 64,
|
||||
getpgrp = 65,
|
||||
setsid = 66,
|
||||
sigaction = 67,
|
||||
setreuid = 70,
|
||||
setregid = 71,
|
||||
sigsuspend = 72,
|
||||
sigpending = 73,
|
||||
sethostname = 74,
|
||||
setrlimit = 75,
|
||||
getrusage = 77,
|
||||
gettimeofday = 78,
|
||||
settimeofday = 79,
|
||||
getgroups = 80,
|
||||
setgroups = 81,
|
||||
symlink = 83,
|
||||
readlink = 85,
|
||||
uselib = 86,
|
||||
swapon = 87,
|
||||
reboot = 88,
|
||||
munmap = 91,
|
||||
truncate = 92,
|
||||
ftruncate = 93,
|
||||
fchmod = 94,
|
||||
fchown = 95,
|
||||
getpriority = 96,
|
||||
setpriority = 97,
|
||||
statfs = 99,
|
||||
fstatfs = 100,
|
||||
syslog = 103,
|
||||
setitimer = 104,
|
||||
getitimer = 105,
|
||||
stat = 106,
|
||||
lstat = 107,
|
||||
fstat = 108,
|
||||
vhangup = 111,
|
||||
wait4 = 114,
|
||||
swapoff = 115,
|
||||
sysinfo = 116,
|
||||
fsync = 118,
|
||||
sigreturn = 119,
|
||||
clone = 120,
|
||||
setdomainname = 121,
|
||||
uname = 122,
|
||||
adjtimex = 124,
|
||||
mprotect = 125,
|
||||
sigprocmask = 126,
|
||||
init_module = 128,
|
||||
delete_module = 129,
|
||||
quotactl = 131,
|
||||
getpgid = 132,
|
||||
fchdir = 133,
|
||||
bdflush = 134,
|
||||
sysfs = 135,
|
||||
personality = 136,
|
||||
setfsuid = 138,
|
||||
setfsgid = 139,
|
||||
_llseek = 140,
|
||||
getdents = 141,
|
||||
_newselect = 142,
|
||||
flock = 143,
|
||||
msync = 144,
|
||||
readv = 145,
|
||||
writev = 146,
|
||||
getsid = 147,
|
||||
fdatasync = 148,
|
||||
_sysctl = 149,
|
||||
mlock = 150,
|
||||
munlock = 151,
|
||||
mlockall = 152,
|
||||
munlockall = 153,
|
||||
sched_setparam = 154,
|
||||
sched_getparam = 155,
|
||||
sched_setscheduler = 156,
|
||||
sched_getscheduler = 157,
|
||||
sched_yield = 158,
|
||||
sched_get_priority_max = 159,
|
||||
sched_get_priority_min = 160,
|
||||
sched_rr_get_interval = 161,
|
||||
nanosleep = 162,
|
||||
mremap = 163,
|
||||
setresuid = 164,
|
||||
getresuid = 165,
|
||||
poll = 168,
|
||||
nfsservctl = 169,
|
||||
setresgid = 170,
|
||||
getresgid = 171,
|
||||
prctl = 172,
|
||||
rt_sigreturn = 173,
|
||||
rt_sigaction = 174,
|
||||
rt_sigprocmask = 175,
|
||||
rt_sigpending = 176,
|
||||
rt_sigtimedwait = 177,
|
||||
rt_sigqueueinfo = 178,
|
||||
rt_sigsuspend = 179,
|
||||
pread64 = 180,
|
||||
pwrite64 = 181,
|
||||
chown = 182,
|
||||
getcwd = 183,
|
||||
capget = 184,
|
||||
capset = 185,
|
||||
sigaltstack = 186,
|
||||
sendfile = 187,
|
||||
vfork = 190,
|
||||
ugetrlimit = 191,
|
||||
mmap2 = 192,
|
||||
truncate64 = 193,
|
||||
ftruncate64 = 194,
|
||||
stat64 = 195,
|
||||
lstat64 = 196,
|
||||
fstat64 = 197,
|
||||
lchown32 = 198,
|
||||
getuid32 = 199,
|
||||
getgid32 = 200,
|
||||
geteuid32 = 201,
|
||||
getegid32 = 202,
|
||||
setreuid32 = 203,
|
||||
setregid32 = 204,
|
||||
getgroups32 = 205,
|
||||
setgroups32 = 206,
|
||||
fchown32 = 207,
|
||||
setresuid32 = 208,
|
||||
getresuid32 = 209,
|
||||
setresgid32 = 210,
|
||||
getresgid32 = 211,
|
||||
chown32 = 212,
|
||||
setuid32 = 213,
|
||||
setgid32 = 214,
|
||||
setfsuid32 = 215,
|
||||
setfsgid32 = 216,
|
||||
getdents64 = 217,
|
||||
pivot_root = 218,
|
||||
mincore = 219,
|
||||
madvise = 220,
|
||||
fcntl64 = 221,
|
||||
gettid = 224,
|
||||
readahead = 225,
|
||||
setxattr = 226,
|
||||
lsetxattr = 227,
|
||||
fsetxattr = 228,
|
||||
getxattr = 229,
|
||||
lgetxattr = 230,
|
||||
fgetxattr = 231,
|
||||
listxattr = 232,
|
||||
llistxattr = 233,
|
||||
flistxattr = 234,
|
||||
removexattr = 235,
|
||||
lremovexattr = 236,
|
||||
fremovexattr = 237,
|
||||
tkill = 238,
|
||||
sendfile64 = 239,
|
||||
futex = 240,
|
||||
sched_setaffinity = 241,
|
||||
sched_getaffinity = 242,
|
||||
io_setup = 243,
|
||||
io_destroy = 244,
|
||||
io_getevents = 245,
|
||||
io_submit = 246,
|
||||
io_cancel = 247,
|
||||
exit_group = 248,
|
||||
lookup_dcookie = 249,
|
||||
epoll_create = 250,
|
||||
epoll_ctl = 251,
|
||||
epoll_wait = 252,
|
||||
remap_file_pages = 253,
|
||||
set_tid_address = 256,
|
||||
timer_create = 257,
|
||||
timer_settime = 258,
|
||||
timer_gettime = 259,
|
||||
timer_getoverrun = 260,
|
||||
timer_delete = 261,
|
||||
clock_settime = 262,
|
||||
clock_gettime = 263,
|
||||
clock_getres = 264,
|
||||
clock_nanosleep = 265,
|
||||
statfs64 = 266,
|
||||
fstatfs64 = 267,
|
||||
tgkill = 268,
|
||||
utimes = 269,
|
||||
fadvise64_64 = 270,
|
||||
pciconfig_iobase = 271,
|
||||
pciconfig_read = 272,
|
||||
pciconfig_write = 273,
|
||||
mq_open = 274,
|
||||
mq_unlink = 275,
|
||||
mq_timedsend = 276,
|
||||
mq_timedreceive = 277,
|
||||
mq_notify = 278,
|
||||
mq_getsetattr = 279,
|
||||
waitid = 280,
|
||||
socket = 281,
|
||||
bind = 282,
|
||||
connect = 283,
|
||||
listen = 284,
|
||||
accept = 285,
|
||||
getsockname = 286,
|
||||
getpeername = 287,
|
||||
socketpair = 288,
|
||||
send = 289,
|
||||
sendto = 290,
|
||||
recv = 291,
|
||||
recvfrom = 292,
|
||||
shutdown = 293,
|
||||
setsockopt = 294,
|
||||
getsockopt = 295,
|
||||
sendmsg = 296,
|
||||
recvmsg = 297,
|
||||
semop = 298,
|
||||
semget = 299,
|
||||
semctl = 300,
|
||||
msgsnd = 301,
|
||||
msgrcv = 302,
|
||||
msgget = 303,
|
||||
msgctl = 304,
|
||||
shmat = 305,
|
||||
shmdt = 306,
|
||||
shmget = 307,
|
||||
shmctl = 308,
|
||||
add_key = 309,
|
||||
request_key = 310,
|
||||
keyctl = 311,
|
||||
semtimedop = 312,
|
||||
vserver = 313,
|
||||
ioprio_set = 314,
|
||||
ioprio_get = 315,
|
||||
inotify_init = 316,
|
||||
inotify_add_watch = 317,
|
||||
inotify_rm_watch = 318,
|
||||
mbind = 319,
|
||||
get_mempolicy = 320,
|
||||
set_mempolicy = 321,
|
||||
openat = 322,
|
||||
mkdirat = 323,
|
||||
mknodat = 324,
|
||||
fchownat = 325,
|
||||
futimesat = 326,
|
||||
fstatat64 = 327,
|
||||
unlinkat = 328,
|
||||
renameat = 329,
|
||||
linkat = 330,
|
||||
symlinkat = 331,
|
||||
readlinkat = 332,
|
||||
fchmodat = 333,
|
||||
faccessat = 334,
|
||||
pselect6 = 335,
|
||||
ppoll = 336,
|
||||
unshare = 337,
|
||||
set_robust_list = 338,
|
||||
get_robust_list = 339,
|
||||
splice = 340,
|
||||
sync_file_range = 341,
|
||||
tee = 342,
|
||||
vmsplice = 343,
|
||||
move_pages = 344,
|
||||
getcpu = 345,
|
||||
epoll_pwait = 346,
|
||||
kexec_load = 347,
|
||||
utimensat = 348,
|
||||
signalfd = 349,
|
||||
timerfd_create = 350,
|
||||
eventfd = 351,
|
||||
fallocate = 352,
|
||||
timerfd_settime = 353,
|
||||
timerfd_gettime = 354,
|
||||
signalfd4 = 355,
|
||||
eventfd2 = 356,
|
||||
epoll_create1 = 357,
|
||||
dup3 = 358,
|
||||
pipe2 = 359,
|
||||
inotify_init1 = 360,
|
||||
preadv = 361,
|
||||
pwritev = 362,
|
||||
rt_tgsigqueueinfo = 363,
|
||||
perf_event_open = 364,
|
||||
recvmmsg = 365,
|
||||
accept4 = 366,
|
||||
fanotify_init = 367,
|
||||
fanotify_mark = 368,
|
||||
prlimit64 = 369,
|
||||
name_to_handle_at = 370,
|
||||
open_by_handle_at = 371,
|
||||
clock_adjtime = 372,
|
||||
syncfs = 373,
|
||||
sendmmsg = 374,
|
||||
setns = 375,
|
||||
process_vm_readv = 376,
|
||||
process_vm_writev = 377,
|
||||
kcmp = 378,
|
||||
finit_module = 379,
|
||||
sched_setattr = 380,
|
||||
sched_getattr = 381,
|
||||
renameat2 = 382,
|
||||
seccomp = 383,
|
||||
getrandom = 384,
|
||||
memfd_create = 385,
|
||||
bpf = 386,
|
||||
execveat = 387,
|
||||
userfaultfd = 388,
|
||||
membarrier = 389,
|
||||
mlock2 = 390,
|
||||
copy_file_range = 391,
|
||||
preadv2 = 392,
|
||||
pwritev2 = 393,
|
||||
pkey_mprotect = 394,
|
||||
pkey_alloc = 395,
|
||||
pkey_free = 396,
|
||||
statx = 397,
|
||||
rseq = 398,
|
||||
io_pgetevents = 399,
|
||||
migrate_pages = 400,
|
||||
kexec_file_load = 401,
|
||||
clock_gettime64 = 403,
|
||||
clock_settime64 = 404,
|
||||
clock_adjtime64 = 405,
|
||||
clock_getres_time64 = 406,
|
||||
clock_nanosleep_time64 = 407,
|
||||
timer_gettime64 = 408,
|
||||
timer_settime64 = 409,
|
||||
timerfd_gettime64 = 410,
|
||||
timerfd_settime64 = 411,
|
||||
utimensat_time64 = 412,
|
||||
pselect6_time64 = 413,
|
||||
ppoll_time64 = 414,
|
||||
io_pgetevents_time64 = 416,
|
||||
recvmmsg_time64 = 417,
|
||||
mq_timedsend_time64 = 418,
|
||||
mq_timedreceive_time64 = 419,
|
||||
semtimedop_time64 = 420,
|
||||
rt_sigtimedwait_time64 = 421,
|
||||
futex_time64 = 422,
|
||||
sched_rr_get_interval_time64 = 423,
|
||||
pidfd_send_signal = 424,
|
||||
io_uring_setup = 425,
|
||||
io_uring_enter = 426,
|
||||
io_uring_register = 427,
|
||||
open_tree = 428,
|
||||
move_mount = 429,
|
||||
fsopen = 430,
|
||||
fsconfig = 431,
|
||||
fsmount = 432,
|
||||
fspick = 433,
|
||||
pidfd_open = 434,
|
||||
clone3 = 435,
|
||||
close_range = 436,
|
||||
openat2 = 437,
|
||||
pidfd_getfd = 438,
|
||||
faccessat2 = 439,
|
||||
process_madvise = 440,
|
||||
epoll_pwait2 = 441,
|
||||
|
||||
breakpoint = 0x0f0001,
|
||||
cacheflush = 0x0f0002,
|
||||
usr26 = 0x0f0003,
|
||||
usr32 = 0x0f0004,
|
||||
set_tls = 0x0f0005,
|
||||
get_tls = 0x0f0006,
|
||||
|
||||
_,
|
||||
};
|
||||
|
||||
pub const MMAP2_UNIT = 4096;
|
||||
|
||||
pub const O = struct {
|
||||
pub const CREAT = 0o100;
|
||||
pub const EXCL = 0o200;
|
||||
pub const NOCTTY = 0o400;
|
||||
pub const TRUNC = 0o1000;
|
||||
pub const APPEND = 0o2000;
|
||||
pub const NONBLOCK = 0o4000;
|
||||
pub const DSYNC = 0o10000;
|
||||
pub const SYNC = 0o4010000;
|
||||
pub const RSYNC = 0o4010000;
|
||||
pub const DIRECTORY = 0o40000;
|
||||
pub const NOFOLLOW = 0o100000;
|
||||
pub const CLOEXEC = 0o2000000;
|
||||
|
||||
pub const ASYNC = 0o20000;
|
||||
pub const DIRECT = 0o200000;
|
||||
pub const LARGEFILE = 0o400000;
|
||||
pub const NOATIME = 0o1000000;
|
||||
pub const PATH = 0o10000000;
|
||||
pub const TMPFILE = 0o20040000;
|
||||
pub const NDELAY = NONBLOCK;
|
||||
};
|
||||
|
||||
pub const F = struct {
|
||||
pub const DUPFD = 0;
|
||||
pub const GETFD = 1;
|
||||
pub const SETFD = 2;
|
||||
pub const GETFL = 3;
|
||||
pub const SETFL = 4;
|
||||
|
||||
pub const SETOWN = 8;
|
||||
pub const GETOWN = 9;
|
||||
pub const SETSIG = 10;
|
||||
pub const GETSIG = 11;
|
||||
|
||||
pub const GETLK = 12;
|
||||
pub const SETLK = 13;
|
||||
pub const SETLKW = 14;
|
||||
|
||||
pub const RDLCK = 0;
|
||||
pub const WRLCK = 1;
|
||||
pub const UNLCK = 2;
|
||||
|
||||
pub const SETOWN_EX = 15;
|
||||
pub const GETOWN_EX = 16;
|
||||
|
||||
pub const GETOWNER_UIDS = 17;
|
||||
};
|
||||
|
||||
pub const LOCK = struct {
|
||||
pub const SH = 1;
|
||||
pub const EX = 2;
|
||||
pub const UN = 8;
|
||||
pub const NB = 4;
|
||||
};
|
||||
|
||||
pub const MAP = struct {
|
||||
/// stack-like segment
|
||||
pub const GROWSDOWN = 0x0100;
|
||||
/// ETXTBSY
|
||||
pub const DENYWRITE = 0x0800;
|
||||
/// mark it as an executable
|
||||
pub const EXECUTABLE = 0x1000;
|
||||
/// pages are locked
|
||||
pub const LOCKED = 0x2000;
|
||||
/// don't check for reservations
|
||||
pub const NORESERVE = 0x4000;
|
||||
};
|
||||
|
||||
pub const VDSO = struct {
|
||||
pub const CGT_SYM = "__vdso_clock_gettime";
|
||||
pub const CGT_VER = "LINUX_2.6";
|
||||
};
|
||||
|
||||
pub const HWCAP = struct {
|
||||
pub const SWP = 1 << 0;
|
||||
pub const HALF = 1 << 1;
|
||||
pub const THUMB = 1 << 2;
|
||||
pub const @"26BIT" = 1 << 3;
|
||||
pub const FAST_MULT = 1 << 4;
|
||||
pub const FPA = 1 << 5;
|
||||
pub const VFP = 1 << 6;
|
||||
pub const EDSP = 1 << 7;
|
||||
pub const JAVA = 1 << 8;
|
||||
pub const IWMMXT = 1 << 9;
|
||||
pub const CRUNCH = 1 << 10;
|
||||
pub const THUMBEE = 1 << 11;
|
||||
pub const NEON = 1 << 12;
|
||||
pub const VFPv3 = 1 << 13;
|
||||
pub const VFPv3D16 = 1 << 14;
|
||||
pub const TLS = 1 << 15;
|
||||
pub const VFPv4 = 1 << 16;
|
||||
pub const IDIVA = 1 << 17;
|
||||
pub const IDIVT = 1 << 18;
|
||||
pub const VFPD32 = 1 << 19;
|
||||
pub const IDIV = IDIVA | IDIVT;
|
||||
pub const LPAE = 1 << 20;
|
||||
pub const EVTSTRM = 1 << 21;
|
||||
};
|
||||
|
||||
pub const Flock = extern struct {
|
||||
l_type: i16,
|
||||
l_whence: i16,
|
||||
__pad0: [4]u8,
|
||||
l_start: off_t,
|
||||
l_len: off_t,
|
||||
l_pid: pid_t,
|
||||
__unused: [4]u8,
|
||||
};
|
||||
|
||||
pub const msghdr = extern struct {
|
||||
msg_name: ?*sockaddr,
|
||||
msg_namelen: socklen_t,
|
||||
msg_iov: [*]iovec,
|
||||
msg_iovlen: i32,
|
||||
msg_control: ?*c_void,
|
||||
msg_controllen: socklen_t,
|
||||
msg_flags: i32,
|
||||
};
|
||||
|
||||
pub const msghdr_const = extern struct {
|
||||
msg_name: ?*const sockaddr,
|
||||
msg_namelen: socklen_t,
|
||||
msg_iov: [*]iovec_const,
|
||||
msg_iovlen: i32,
|
||||
msg_control: ?*c_void,
|
||||
msg_controllen: socklen_t,
|
||||
msg_flags: i32,
|
||||
};
|
||||
|
||||
pub const blksize_t = i32;
|
||||
pub const nlink_t = u32;
|
||||
pub const time_t = isize;
|
||||
pub const mode_t = u32;
|
||||
pub const off_t = i64;
|
||||
pub const ino_t = u64;
|
||||
pub const dev_t = u64;
|
||||
pub const blkcnt_t = i64;
|
||||
|
||||
// The `stat` definition used by the Linux kernel.
|
||||
pub const Stat = extern struct {
|
||||
dev: dev_t,
|
||||
__dev_padding: u32,
|
||||
__ino_truncated: u32,
|
||||
mode: mode_t,
|
||||
nlink: nlink_t,
|
||||
uid: uid_t,
|
||||
gid: gid_t,
|
||||
rdev: dev_t,
|
||||
__rdev_padding: u32,
|
||||
size: off_t,
|
||||
blksize: blksize_t,
|
||||
blocks: blkcnt_t,
|
||||
atim: timespec,
|
||||
mtim: timespec,
|
||||
ctim: timespec,
|
||||
ino: ino_t,
|
||||
|
||||
pub fn atime(self: @This()) timespec {
|
||||
return self.atim;
|
||||
}
|
||||
|
||||
pub fn mtime(self: @This()) timespec {
|
||||
return self.mtim;
|
||||
}
|
||||
|
||||
pub fn ctime(self: @This()) timespec {
|
||||
return self.ctim;
|
||||
}
|
||||
};
|
||||
|
||||
pub const timeval = extern struct {
|
||||
tv_sec: i32,
|
||||
tv_usec: i32,
|
||||
};
|
||||
|
||||
pub const timezone = extern struct {
|
||||
tz_minuteswest: i32,
|
||||
tz_dsttime: i32,
|
||||
};
|
||||
|
||||
pub const mcontext_t = extern struct {
|
||||
trap_no: usize,
|
||||
error_code: usize,
|
||||
oldmask: usize,
|
||||
arm_r0: usize,
|
||||
arm_r1: usize,
|
||||
arm_r2: usize,
|
||||
arm_r3: usize,
|
||||
arm_r4: usize,
|
||||
arm_r5: usize,
|
||||
arm_r6: usize,
|
||||
arm_r7: usize,
|
||||
arm_r8: usize,
|
||||
arm_r9: usize,
|
||||
arm_r10: usize,
|
||||
arm_fp: usize,
|
||||
arm_ip: usize,
|
||||
arm_sp: usize,
|
||||
arm_lr: usize,
|
||||
arm_pc: usize,
|
||||
arm_cpsr: usize,
|
||||
fault_address: usize,
|
||||
};
|
||||
|
||||
pub const ucontext_t = extern struct {
|
||||
flags: usize,
|
||||
link: *ucontext_t,
|
||||
stack: stack_t,
|
||||
mcontext: mcontext_t,
|
||||
sigmask: sigset_t,
|
||||
regspace: [64]u64,
|
||||
};
|
||||
|
||||
pub const Elf_Symndx = u32;
|
||||
|
||||
@ -1,4 +1,16 @@
|
||||
usingnamespace @import("../bits/linux.zig");
|
||||
const std = @import("../../std.zig");
|
||||
const maxInt = std.math.maxInt;
|
||||
const linux = std.os.linux;
|
||||
const socklen_t = linux.socklen_t;
|
||||
const sockaddr = linux.sockaddr;
|
||||
const iovec = linux.iovec;
|
||||
const iovec_const = linux.iovec_const;
|
||||
const uid_t = linux.uid_t;
|
||||
const gid_t = linux.gid_t;
|
||||
const pid_t = linux.pid_t;
|
||||
const stack_t = linux.stack_t;
|
||||
const sigset_t = linux.sigset_t;
|
||||
const timespec = std.os.linux.timespec;
|
||||
|
||||
pub fn syscall0(number: SYS) usize {
|
||||
return asm volatile ("svc #0"
|
||||
@ -97,3 +109,483 @@ pub fn restore_rt() callconv(.Naked) void {
|
||||
: "memory", "cc"
|
||||
);
|
||||
}
|
||||
|
||||
pub const SYS = enum(usize) {
|
||||
io_setup = 0,
|
||||
io_destroy = 1,
|
||||
io_submit = 2,
|
||||
io_cancel = 3,
|
||||
io_getevents = 4,
|
||||
setxattr = 5,
|
||||
lsetxattr = 6,
|
||||
fsetxattr = 7,
|
||||
getxattr = 8,
|
||||
lgetxattr = 9,
|
||||
fgetxattr = 10,
|
||||
listxattr = 11,
|
||||
llistxattr = 12,
|
||||
flistxattr = 13,
|
||||
removexattr = 14,
|
||||
lremovexattr = 15,
|
||||
fremovexattr = 16,
|
||||
getcwd = 17,
|
||||
lookup_dcookie = 18,
|
||||
eventfd2 = 19,
|
||||
epoll_create1 = 20,
|
||||
epoll_ctl = 21,
|
||||
epoll_pwait = 22,
|
||||
dup = 23,
|
||||
dup3 = 24,
|
||||
fcntl = 25,
|
||||
inotify_init1 = 26,
|
||||
inotify_add_watch = 27,
|
||||
inotify_rm_watch = 28,
|
||||
ioctl = 29,
|
||||
ioprio_set = 30,
|
||||
ioprio_get = 31,
|
||||
flock = 32,
|
||||
mknodat = 33,
|
||||
mkdirat = 34,
|
||||
unlinkat = 35,
|
||||
symlinkat = 36,
|
||||
linkat = 37,
|
||||
renameat = 38,
|
||||
umount2 = 39,
|
||||
mount = 40,
|
||||
pivot_root = 41,
|
||||
nfsservctl = 42,
|
||||
statfs = 43,
|
||||
fstatfs = 44,
|
||||
truncate = 45,
|
||||
ftruncate = 46,
|
||||
fallocate = 47,
|
||||
faccessat = 48,
|
||||
chdir = 49,
|
||||
fchdir = 50,
|
||||
chroot = 51,
|
||||
fchmod = 52,
|
||||
fchmodat = 53,
|
||||
fchownat = 54,
|
||||
fchown = 55,
|
||||
openat = 56,
|
||||
close = 57,
|
||||
vhangup = 58,
|
||||
pipe2 = 59,
|
||||
quotactl = 60,
|
||||
getdents64 = 61,
|
||||
lseek = 62,
|
||||
read = 63,
|
||||
write = 64,
|
||||
readv = 65,
|
||||
writev = 66,
|
||||
pread64 = 67,
|
||||
pwrite64 = 68,
|
||||
preadv = 69,
|
||||
pwritev = 70,
|
||||
sendfile = 71,
|
||||
pselect6 = 72,
|
||||
ppoll = 73,
|
||||
signalfd4 = 74,
|
||||
vmsplice = 75,
|
||||
splice = 76,
|
||||
tee = 77,
|
||||
readlinkat = 78,
|
||||
fstatat = 79,
|
||||
fstat = 80,
|
||||
sync = 81,
|
||||
fsync = 82,
|
||||
fdatasync = 83,
|
||||
sync_file_range = 84,
|
||||
timerfd_create = 85,
|
||||
timerfd_settime = 86,
|
||||
timerfd_gettime = 87,
|
||||
utimensat = 88,
|
||||
acct = 89,
|
||||
capget = 90,
|
||||
capset = 91,
|
||||
personality = 92,
|
||||
exit = 93,
|
||||
exit_group = 94,
|
||||
waitid = 95,
|
||||
set_tid_address = 96,
|
||||
unshare = 97,
|
||||
futex = 98,
|
||||
set_robust_list = 99,
|
||||
get_robust_list = 100,
|
||||
nanosleep = 101,
|
||||
getitimer = 102,
|
||||
setitimer = 103,
|
||||
kexec_load = 104,
|
||||
init_module = 105,
|
||||
delete_module = 106,
|
||||
timer_create = 107,
|
||||
timer_gettime = 108,
|
||||
timer_getoverrun = 109,
|
||||
timer_settime = 110,
|
||||
timer_delete = 111,
|
||||
clock_settime = 112,
|
||||
clock_gettime = 113,
|
||||
clock_getres = 114,
|
||||
clock_nanosleep = 115,
|
||||
syslog = 116,
|
||||
ptrace = 117,
|
||||
sched_setparam = 118,
|
||||
sched_setscheduler = 119,
|
||||
sched_getscheduler = 120,
|
||||
sched_getparam = 121,
|
||||
sched_setaffinity = 122,
|
||||
sched_getaffinity = 123,
|
||||
sched_yield = 124,
|
||||
sched_get_priority_max = 125,
|
||||
sched_get_priority_min = 126,
|
||||
sched_rr_get_interval = 127,
|
||||
restart_syscall = 128,
|
||||
kill = 129,
|
||||
tkill = 130,
|
||||
tgkill = 131,
|
||||
sigaltstack = 132,
|
||||
rt_sigsuspend = 133,
|
||||
rt_sigaction = 134,
|
||||
rt_sigprocmask = 135,
|
||||
rt_sigpending = 136,
|
||||
rt_sigtimedwait = 137,
|
||||
rt_sigqueueinfo = 138,
|
||||
rt_sigreturn = 139,
|
||||
setpriority = 140,
|
||||
getpriority = 141,
|
||||
reboot = 142,
|
||||
setregid = 143,
|
||||
setgid = 144,
|
||||
setreuid = 145,
|
||||
setuid = 146,
|
||||
setresuid = 147,
|
||||
getresuid = 148,
|
||||
setresgid = 149,
|
||||
getresgid = 150,
|
||||
setfsuid = 151,
|
||||
setfsgid = 152,
|
||||
times = 153,
|
||||
setpgid = 154,
|
||||
getpgid = 155,
|
||||
getsid = 156,
|
||||
setsid = 157,
|
||||
getgroups = 158,
|
||||
setgroups = 159,
|
||||
uname = 160,
|
||||
sethostname = 161,
|
||||
setdomainname = 162,
|
||||
getrlimit = 163,
|
||||
setrlimit = 164,
|
||||
getrusage = 165,
|
||||
umask = 166,
|
||||
prctl = 167,
|
||||
getcpu = 168,
|
||||
gettimeofday = 169,
|
||||
settimeofday = 170,
|
||||
adjtimex = 171,
|
||||
getpid = 172,
|
||||
getppid = 173,
|
||||
getuid = 174,
|
||||
geteuid = 175,
|
||||
getgid = 176,
|
||||
getegid = 177,
|
||||
gettid = 178,
|
||||
sysinfo = 179,
|
||||
mq_open = 180,
|
||||
mq_unlink = 181,
|
||||
mq_timedsend = 182,
|
||||
mq_timedreceive = 183,
|
||||
mq_notify = 184,
|
||||
mq_getsetattr = 185,
|
||||
msgget = 186,
|
||||
msgctl = 187,
|
||||
msgrcv = 188,
|
||||
msgsnd = 189,
|
||||
semget = 190,
|
||||
semctl = 191,
|
||||
semtimedop = 192,
|
||||
semop = 193,
|
||||
shmget = 194,
|
||||
shmctl = 195,
|
||||
shmat = 196,
|
||||
shmdt = 197,
|
||||
socket = 198,
|
||||
socketpair = 199,
|
||||
bind = 200,
|
||||
listen = 201,
|
||||
accept = 202,
|
||||
connect = 203,
|
||||
getsockname = 204,
|
||||
getpeername = 205,
|
||||
sendto = 206,
|
||||
recvfrom = 207,
|
||||
setsockopt = 208,
|
||||
getsockopt = 209,
|
||||
shutdown = 210,
|
||||
sendmsg = 211,
|
||||
recvmsg = 212,
|
||||
readahead = 213,
|
||||
brk = 214,
|
||||
munmap = 215,
|
||||
mremap = 216,
|
||||
add_key = 217,
|
||||
request_key = 218,
|
||||
keyctl = 219,
|
||||
clone = 220,
|
||||
execve = 221,
|
||||
mmap = 222,
|
||||
fadvise64 = 223,
|
||||
swapon = 224,
|
||||
swapoff = 225,
|
||||
mprotect = 226,
|
||||
msync = 227,
|
||||
mlock = 228,
|
||||
munlock = 229,
|
||||
mlockall = 230,
|
||||
munlockall = 231,
|
||||
mincore = 232,
|
||||
madvise = 233,
|
||||
remap_file_pages = 234,
|
||||
mbind = 235,
|
||||
get_mempolicy = 236,
|
||||
set_mempolicy = 237,
|
||||
migrate_pages = 238,
|
||||
move_pages = 239,
|
||||
rt_tgsigqueueinfo = 240,
|
||||
perf_event_open = 241,
|
||||
accept4 = 242,
|
||||
recvmmsg = 243,
|
||||
arch_specific_syscall = 244,
|
||||
wait4 = 260,
|
||||
prlimit64 = 261,
|
||||
fanotify_init = 262,
|
||||
fanotify_mark = 263,
|
||||
clock_adjtime = 266,
|
||||
syncfs = 267,
|
||||
setns = 268,
|
||||
sendmmsg = 269,
|
||||
process_vm_readv = 270,
|
||||
process_vm_writev = 271,
|
||||
kcmp = 272,
|
||||
finit_module = 273,
|
||||
sched_setattr = 274,
|
||||
sched_getattr = 275,
|
||||
renameat2 = 276,
|
||||
seccomp = 277,
|
||||
getrandom = 278,
|
||||
memfd_create = 279,
|
||||
bpf = 280,
|
||||
execveat = 281,
|
||||
userfaultfd = 282,
|
||||
membarrier = 283,
|
||||
mlock2 = 284,
|
||||
copy_file_range = 285,
|
||||
preadv2 = 286,
|
||||
pwritev2 = 287,
|
||||
pkey_mprotect = 288,
|
||||
pkey_alloc = 289,
|
||||
pkey_free = 290,
|
||||
statx = 291,
|
||||
io_pgetevents = 292,
|
||||
rseq = 293,
|
||||
kexec_file_load = 294,
|
||||
pidfd_send_signal = 424,
|
||||
io_uring_setup = 425,
|
||||
io_uring_enter = 426,
|
||||
io_uring_register = 427,
|
||||
open_tree = 428,
|
||||
move_mount = 429,
|
||||
fsopen = 430,
|
||||
fsconfig = 431,
|
||||
fsmount = 432,
|
||||
fspick = 433,
|
||||
pidfd_open = 434,
|
||||
clone3 = 435,
|
||||
close_range = 436,
|
||||
openat2 = 437,
|
||||
pidfd_getfd = 438,
|
||||
faccessat2 = 439,
|
||||
process_madvise = 440,
|
||||
epoll_pwait2 = 441,
|
||||
|
||||
_,
|
||||
};
|
||||
|
||||
pub const O = struct {
|
||||
pub const CREAT = 0o100;
|
||||
pub const EXCL = 0o200;
|
||||
pub const NOCTTY = 0o400;
|
||||
pub const TRUNC = 0o1000;
|
||||
pub const APPEND = 0o2000;
|
||||
pub const NONBLOCK = 0o4000;
|
||||
pub const DSYNC = 0o10000;
|
||||
pub const SYNC = 0o4010000;
|
||||
pub const RSYNC = 0o4010000;
|
||||
pub const DIRECTORY = 0o40000;
|
||||
pub const NOFOLLOW = 0o100000;
|
||||
pub const CLOEXEC = 0o2000000;
|
||||
|
||||
pub const ASYNC = 0o20000;
|
||||
pub const DIRECT = 0o200000;
|
||||
pub const LARGEFILE = 0o400000;
|
||||
pub const NOATIME = 0o1000000;
|
||||
pub const PATH = 0o10000000;
|
||||
pub const TMPFILE = 0o20040000;
|
||||
pub const NDELAY = NONBLOCK;
|
||||
};
|
||||
|
||||
pub const F = struct {
|
||||
pub const DUPFD = 0;
|
||||
pub const GETFD = 1;
|
||||
pub const SETFD = 2;
|
||||
pub const GETFL = 3;
|
||||
pub const SETFL = 4;
|
||||
|
||||
pub const SETOWN = 8;
|
||||
pub const GETOWN = 9;
|
||||
pub const SETSIG = 10;
|
||||
pub const GETSIG = 11;
|
||||
|
||||
pub const GETLK = 5;
|
||||
pub const SETLK = 6;
|
||||
pub const SETLKW = 7;
|
||||
|
||||
pub const RDLCK = 0;
|
||||
pub const WRLCK = 1;
|
||||
pub const UNLCK = 2;
|
||||
|
||||
pub const SETOWN_EX = 15;
|
||||
pub const GETOWN_EX = 16;
|
||||
|
||||
pub const GETOWNER_UIDS = 17;
|
||||
};
|
||||
|
||||
pub const LOCK = struct {
|
||||
pub const SH = 1;
|
||||
pub const EX = 2;
|
||||
pub const UN = 8;
|
||||
pub const NB = 4;
|
||||
};
|
||||
|
||||
pub const MAP = struct {
|
||||
/// stack-like segment
|
||||
pub const GROWSDOWN = 0x0100;
|
||||
/// ETXTBSY
|
||||
pub const DENYWRITE = 0x0800;
|
||||
/// mark it as an executable
|
||||
pub const EXECUTABLE = 0x1000;
|
||||
/// pages are locked
|
||||
pub const LOCKED = 0x2000;
|
||||
/// don't check for reservations
|
||||
pub const NORESERVE = 0x4000;
|
||||
};
|
||||
|
||||
pub const VDSO = struct {
|
||||
pub const CGT_SYM = "__kernel_clock_gettime";
|
||||
pub const CGT_VER = "LINUX_2.6.39";
|
||||
};
|
||||
|
||||
pub const Flock = extern struct {
|
||||
l_type: i16,
|
||||
l_whence: i16,
|
||||
l_start: off_t,
|
||||
l_len: off_t,
|
||||
l_pid: pid_t,
|
||||
__unused: [4]u8,
|
||||
};
|
||||
|
||||
pub const msghdr = extern struct {
|
||||
msg_name: ?*sockaddr,
|
||||
msg_namelen: socklen_t,
|
||||
msg_iov: [*]iovec,
|
||||
msg_iovlen: i32,
|
||||
__pad1: i32 = 0,
|
||||
msg_control: ?*c_void,
|
||||
msg_controllen: socklen_t,
|
||||
__pad2: socklen_t = 0,
|
||||
msg_flags: i32,
|
||||
};
|
||||
|
||||
pub const msghdr_const = extern struct {
|
||||
msg_name: ?*const sockaddr,
|
||||
msg_namelen: socklen_t,
|
||||
msg_iov: [*]iovec_const,
|
||||
msg_iovlen: i32,
|
||||
__pad1: i32 = 0,
|
||||
msg_control: ?*c_void,
|
||||
msg_controllen: socklen_t,
|
||||
__pad2: socklen_t = 0,
|
||||
msg_flags: i32,
|
||||
};
|
||||
|
||||
pub const blksize_t = i32;
|
||||
pub const nlink_t = u32;
|
||||
pub const time_t = isize;
|
||||
pub const mode_t = u32;
|
||||
pub const off_t = isize;
|
||||
pub const ino_t = usize;
|
||||
pub const dev_t = usize;
|
||||
pub const blkcnt_t = isize;
|
||||
|
||||
// The `stat` definition used by the Linux kernel.
|
||||
pub const Stat = extern struct {
|
||||
dev: dev_t,
|
||||
ino: ino_t,
|
||||
mode: mode_t,
|
||||
nlink: nlink_t,
|
||||
uid: uid_t,
|
||||
gid: gid_t,
|
||||
rdev: dev_t,
|
||||
__pad: usize,
|
||||
size: off_t,
|
||||
blksize: blksize_t,
|
||||
__pad2: i32,
|
||||
blocks: blkcnt_t,
|
||||
atim: timespec,
|
||||
mtim: timespec,
|
||||
ctim: timespec,
|
||||
__unused: [2]u32,
|
||||
|
||||
pub fn atime(self: @This()) timespec {
|
||||
return self.atim;
|
||||
}
|
||||
|
||||
pub fn mtime(self: @This()) timespec {
|
||||
return self.mtim;
|
||||
}
|
||||
|
||||
pub fn ctime(self: @This()) timespec {
|
||||
return self.ctim;
|
||||
}
|
||||
};
|
||||
|
||||
pub const timeval = extern struct {
|
||||
tv_sec: isize,
|
||||
tv_usec: isize,
|
||||
};
|
||||
|
||||
pub const timezone = extern struct {
|
||||
tz_minuteswest: i32,
|
||||
tz_dsttime: i32,
|
||||
};
|
||||
|
||||
pub const mcontext_t = extern struct {
|
||||
fault_address: usize,
|
||||
regs: [31]usize,
|
||||
sp: usize,
|
||||
pc: usize,
|
||||
pstate: usize,
|
||||
// Make sure the field is correctly aligned since this area
|
||||
// holds various FP/vector registers
|
||||
reserved1: [256 * 16]u8 align(16),
|
||||
};
|
||||
|
||||
pub const ucontext_t = extern struct {
|
||||
flags: usize,
|
||||
link: *ucontext_t,
|
||||
stack: stack_t,
|
||||
sigmask: sigset_t,
|
||||
mcontext: mcontext_t,
|
||||
};
|
||||
|
||||
pub const Elf_Symndx = u32;
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
usingnamespace std.os.linux;
|
||||
const std = @import("../../std.zig");
|
||||
const errno = getErrno;
|
||||
const unexpectedErrno = std.os.unexpectedErrno;
|
||||
@ -6,6 +5,11 @@ const expectEqual = std.testing.expectEqual;
|
||||
const expectError = std.testing.expectError;
|
||||
const expect = std.testing.expect;
|
||||
|
||||
const linux = std.os.linux;
|
||||
const fd_t = linux.fd_t;
|
||||
const pid_t = linux.pid_t;
|
||||
const getErrno = linux.getErrno;
|
||||
|
||||
pub const btf = @import("bpf/btf.zig");
|
||||
pub const kern = @import("bpf/kern.zig");
|
||||
|
||||
@ -1502,7 +1506,7 @@ pub fn map_create(map_type: MapType, key_size: u32, value_size: u32, max_entries
|
||||
attr.map_create.value_size = value_size;
|
||||
attr.map_create.max_entries = max_entries;
|
||||
|
||||
const rc = bpf(.map_create, &attr, @sizeOf(MapCreateAttr));
|
||||
const rc = linux.bpf(.map_create, &attr, @sizeOf(MapCreateAttr));
|
||||
switch (errno(rc)) {
|
||||
.SUCCESS => return @intCast(fd_t, rc),
|
||||
.INVAL => return error.MapTypeOrAttrInvalid,
|
||||
@ -1526,7 +1530,7 @@ pub fn map_lookup_elem(fd: fd_t, key: []const u8, value: []u8) !void {
|
||||
attr.map_elem.key = @ptrToInt(key.ptr);
|
||||
attr.map_elem.result.value = @ptrToInt(value.ptr);
|
||||
|
||||
const rc = bpf(.map_lookup_elem, &attr, @sizeOf(MapElemAttr));
|
||||
const rc = linux.bpf(.map_lookup_elem, &attr, @sizeOf(MapElemAttr));
|
||||
switch (errno(rc)) {
|
||||
.SUCCESS => return,
|
||||
.BADF => return error.BadFd,
|
||||
@ -1548,7 +1552,7 @@ pub fn map_update_elem(fd: fd_t, key: []const u8, value: []const u8, flags: u64)
|
||||
attr.map_elem.result = .{ .value = @ptrToInt(value.ptr) };
|
||||
attr.map_elem.flags = flags;
|
||||
|
||||
const rc = bpf(.map_update_elem, &attr, @sizeOf(MapElemAttr));
|
||||
const rc = linux.bpf(.map_update_elem, &attr, @sizeOf(MapElemAttr));
|
||||
switch (errno(rc)) {
|
||||
.SUCCESS => return,
|
||||
.@"2BIG" => return error.ReachedMaxEntries,
|
||||
@ -1569,7 +1573,7 @@ pub fn map_delete_elem(fd: fd_t, key: []const u8) !void {
|
||||
attr.map_elem.map_fd = fd;
|
||||
attr.map_elem.key = @ptrToInt(key.ptr);
|
||||
|
||||
const rc = bpf(.map_delete_elem, &attr, @sizeOf(MapElemAttr));
|
||||
const rc = linux.bpf(.map_delete_elem, &attr, @sizeOf(MapElemAttr));
|
||||
switch (errno(rc)) {
|
||||
.SUCCESS => return,
|
||||
.BADF => return error.BadFd,
|
||||
@ -1632,7 +1636,7 @@ pub fn prog_load(
|
||||
attr.prog_load.log_level = l.level;
|
||||
}
|
||||
|
||||
const rc = bpf(.prog_load, &attr, @sizeOf(ProgLoadAttr));
|
||||
const rc = linux.bpf(.prog_load, &attr, @sizeOf(ProgLoadAttr));
|
||||
return switch (errno(rc)) {
|
||||
.SUCCESS => @intCast(fd_t, rc),
|
||||
.ACCES => error.UnsafeProgram,
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
const std = @import("../../../std.zig");
|
||||
|
||||
const magic = 0xeb9f;
|
||||
const version = 1;
|
||||
|
||||
|
||||
@ -1,5 +1,10 @@
|
||||
const std = @import("../../../std.zig");
|
||||
const kern = @import("kern.zig");
|
||||
|
||||
const PtRegs = @compileError("TODO missing os bits: PtRegs");
|
||||
const TcpHdr = @compileError("TODO missing os bits: TcpHdr");
|
||||
const SkFullSock = @compileError("TODO missing os bits: SkFullSock");
|
||||
|
||||
// in BPF, all the helper calls
|
||||
// TODO: when https://github.com/ziglang/zig/issues/1717 is here, make a nice
|
||||
// function that uses the Helper enum
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user