| author | |
| committer | |
| log | 35c462caf0c0763c14d0f1303197c86a63c51f03 |
| tree | 46591490be3dcf41f664c411385b62de9b1326d2 |
| parent | 457f557c37947af6ce90a82a70e08e59526af0dc |
| parent | e7f555ca550cc73288adbdf4ec8d0e4abbc7a987 |
151 files changed, 5715 insertions(+), 4377 deletions(-)
CMakeLists.txt+13-4| ... | ... | @@ -224,7 +224,7 @@ set(EMBEDDED_SOFTFLOAT_SOURCES |
| 224 | 224 | add_library(embedded_softfloat STATIC ${EMBEDDED_SOFTFLOAT_SOURCES}) |
| 225 | 225 | if(MSVC) |
| 226 | 226 | set_target_properties(embedded_softfloat PROPERTIES |
| 227 | COMPILE_FLAGS "-std=c99 /w" | |
| 227 | COMPILE_FLAGS "/w /O2" | |
| 228 | 228 | ) |
| 229 | 229 | else() |
| 230 | 230 | set_target_properties(embedded_softfloat PROPERTIES |
| ... | ... | @@ -315,12 +315,17 @@ include_directories( |
| 315 | 315 | ) |
| 316 | 316 | |
| 317 | 317 | # These have to go before the -Wno- flags |
| 318 | set(EXE_CFLAGS "-std=c++14") | |
| 318 | if(MSVC) | |
| 319 | set(EXE_CFLAGS "/std:c++14") | |
| 320 | else(MSVC) | |
| 321 | set(EXE_CFLAGS "-std=c++14") | |
| 322 | endif(MSVC) | |
| 323 | ||
| 319 | 324 | if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") |
| 320 | 325 | if(MSVC) |
| 321 | 326 | set(EXE_CFLAGS "${EXE_CFLAGS} /w") |
| 322 | 327 | else() |
| 323 | set(EXE_CFLAGS "${EXE_CFLAGS} -Werror -Wall") | |
| 328 | set(EXE_CFLAGS "${EXE_CFLAGS} -Werror -Wall -Werror=implicit-fallthrough") | |
| 324 | 329 | endif() |
| 325 | 330 | endif() |
| 326 | 331 | |
| ... | ... | @@ -333,7 +338,11 @@ else() |
| 333 | 338 | endif() |
| 334 | 339 | endif() |
| 335 | 340 | |
| 336 | set(OPTIMIZED_C_FLAGS "-std=c99 -O3") | |
| 341 | if(MSVC) | |
| 342 | set(OPTIMIZED_C_FLAGS "/O2") | |
| 343 | else(MSVC) | |
| 344 | set(OPTIMIZED_C_FLAGS "-std=c99 -O3") | |
| 345 | endif(MSVC) | |
| 337 | 346 | |
| 338 | 347 | set(EXE_LDFLAGS " ") |
| 339 | 348 | if(MSVC) |
README.md+2-2| ... | ... | @@ -54,8 +54,8 @@ make install |
| 54 | 54 | ##### MacOS |
| 55 | 55 | |
| 56 | 56 | ``` |
| 57 | brew install cmake llvm@10 | |
| 58 | brew outdated llvm@10 || brew upgrade llvm@10 | |
| 57 | brew install cmake llvm | |
| 58 | brew outdated llvm || brew upgrade llvm | |
| 59 | 59 | mkdir build |
| 60 | 60 | cd build |
| 61 | 61 | cmake .. -DCMAKE_PREFIX_PATH=$(brew --prefix llvm) |
ci/azure/linux_script+5-1| ... | ... | @@ -12,7 +12,11 @@ sudo apt-get update -q |
| 12 | 12 | |
| 13 | 13 | sudo apt-get remove -y llvm-* |
| 14 | 14 | sudo rm -rf /usr/local/* |
| 15 | sudo apt-get install -y libxml2-dev libclang-10-dev llvm-10 llvm-10-dev liblld-10-dev cmake s3cmd gcc-7 g++-7 qemu | |
| 15 | sudo apt-get install -y libxml2-dev libclang-10-dev llvm-10 llvm-10-dev liblld-10-dev cmake s3cmd gcc-7 g++-7 | |
| 16 | ||
| 17 | wget https://ziglang.org/deps/qemu-5.0.0-rc1-x86_64-alpinelinux.tar.xz | |
| 18 | tar xf qemu-5.0.0-rc1-x86_64-alpinelinux.tar.xz | |
| 19 | PATH=$PWD/qemu-5.0.0-rc1/bin:$PATH | |
| 16 | 20 | |
| 17 | 21 | # Make the `zig version` number consistent. |
| 18 | 22 | # This will affect the cmake command below. |
ci/srht/update_download_page+1| ... | ... | @@ -71,6 +71,7 @@ export X86_64_FREEBSD_SHASUM="$(echo "$X86_64_FREEBSD_JSON" | jq .shasum -r)" |
| 71 | 71 | git clone https://github.com/ziglang/www.ziglang.org --depth 1 |
| 72 | 72 | cd www.ziglang.org |
| 73 | 73 | export MASTER_DATE="$(date +%Y-%m-%d)" |
| 74 | export MASTER_VERSION="$VERSION" | |
| 74 | 75 | "../$ZIG" run update-download-page.zig |
| 75 | 76 | |
| 76 | 77 | $S3CMD put -P --no-mime-magic --add-header="cache-control: public, max-age=31536000, immutable" "../$SRC_TARBALL" s3://ziglang.org/builds/ |
cmake/Findlld.cmake+1| ... | ... | @@ -24,6 +24,7 @@ else() |
| 24 | 24 | string(TOUPPER ${_libname_} _prettylibname_) |
| 25 | 25 | find_library(LLD_${_prettylibname_}_LIB NAMES ${_libname_} |
| 26 | 26 | PATHS |
| 27 | ${LLD_LIBDIRS} | |
| 27 | 28 | /usr/lib/llvm-10/lib |
| 28 | 29 | /usr/local/llvm100/lib |
| 29 | 30 | /mingw64/lib |
doc/docgen.zig+48-29| ... | ... | @@ -321,7 +321,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc { |
| 321 | 321 | var last_action = Action.Open; |
| 322 | 322 | var last_columns: ?u8 = null; |
| 323 | 323 | |
| 324 | var toc_buf = try std.Buffer.initSize(allocator, 0); | |
| 324 | var toc_buf = std.ArrayList(u8).init(allocator); | |
| 325 | 325 | defer toc_buf.deinit(); |
| 326 | 326 | |
| 327 | 327 | var toc = toc_buf.outStream(); |
| ... | ... | @@ -607,7 +607,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc { |
| 607 | 607 | } |
| 608 | 608 | |
| 609 | 609 | fn urlize(allocator: *mem.Allocator, input: []const u8) ![]u8 { |
| 610 | var buf = try std.Buffer.initSize(allocator, 0); | |
| 610 | var buf = std.ArrayList(u8).init(allocator); | |
| 611 | 611 | defer buf.deinit(); |
| 612 | 612 | |
| 613 | 613 | const out = buf.outStream(); |
| ... | ... | @@ -626,7 +626,7 @@ fn urlize(allocator: *mem.Allocator, input: []const u8) ![]u8 { |
| 626 | 626 | } |
| 627 | 627 | |
| 628 | 628 | fn escapeHtml(allocator: *mem.Allocator, input: []const u8) ![]u8 { |
| 629 | var buf = try std.Buffer.initSize(allocator, 0); | |
| 629 | var buf = std.ArrayList(u8).init(allocator); | |
| 630 | 630 | defer buf.deinit(); |
| 631 | 631 | |
| 632 | 632 | const out = buf.outStream(); |
| ... | ... | @@ -672,7 +672,7 @@ test "term color" { |
| 672 | 672 | } |
| 673 | 673 | |
| 674 | 674 | fn termColor(allocator: *mem.Allocator, input: []const u8) ![]u8 { |
| 675 | var buf = try std.Buffer.initSize(allocator, 0); | |
| 675 | var buf = std.ArrayList(u8).init(allocator); | |
| 676 | 676 | defer buf.deinit(); |
| 677 | 677 | |
| 678 | 678 | var out = buf.outStream(); |
| ... | ... | @@ -1048,7 +1048,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1048 | 1048 | allocator, |
| 1049 | 1049 | &[_][]const u8{ tmp_dir_name, name_plus_ext }, |
| 1050 | 1050 | ); |
| 1051 | try io.writeFile(tmp_source_file_name, trimmed_raw_source); | |
| 1051 | try fs.cwd().writeFile(tmp_source_file_name, trimmed_raw_source); | |
| 1052 | 1052 | |
| 1053 | 1053 | switch (code.id) { |
| 1054 | 1054 | Code.Id.Exe => |expected_outcome| code_block: { |
| ... | ... | @@ -1106,18 +1106,17 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1106 | 1106 | } |
| 1107 | 1107 | } |
| 1108 | 1108 | if (expected_outcome == .BuildFail) { |
| 1109 | const result = try ChildProcess.exec( | |
| 1110 | allocator, | |
| 1111 | build_args.toSliceConst(), | |
| 1112 | null, | |
| 1113 | &env_map, | |
| 1114 | max_doc_file_size, | |
| 1115 | ); | |
| 1109 | const result = try ChildProcess.exec(.{ | |
| 1110 | .allocator = allocator, | |
| 1111 | .argv = build_args.span(), | |
| 1112 | .env_map = &env_map, | |
| 1113 | .max_output_bytes = max_doc_file_size, | |
| 1114 | }); | |
| 1116 | 1115 | switch (result.term) { |
| 1117 | 1116 | .Exited => |exit_code| { |
| 1118 | 1117 | if (exit_code == 0) { |
| 1119 | 1118 | warn("{}\nThe following command incorrectly succeeded:\n", .{result.stderr}); |
| 1120 | for (build_args.toSliceConst()) |arg| | |
| 1119 | for (build_args.span()) |arg| | |
| 1121 | 1120 | warn("{} ", .{arg}) |
| 1122 | 1121 | else |
| 1123 | 1122 | warn("\n", .{}); |
| ... | ... | @@ -1126,7 +1125,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1126 | 1125 | }, |
| 1127 | 1126 | else => { |
| 1128 | 1127 | warn("{}\nThe following command crashed:\n", .{result.stderr}); |
| 1129 | for (build_args.toSliceConst()) |arg| | |
| 1128 | for (build_args.span()) |arg| | |
| 1130 | 1129 | warn("{} ", .{arg}) |
| 1131 | 1130 | else |
| 1132 | 1131 | warn("\n", .{}); |
| ... | ... | @@ -1138,7 +1137,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1138 | 1137 | try out.print("\n{}</code></pre>\n", .{colored_stderr}); |
| 1139 | 1138 | break :code_block; |
| 1140 | 1139 | } |
| 1141 | const exec_result = exec(allocator, &env_map, build_args.toSliceConst()) catch | |
| 1140 | const exec_result = exec(allocator, &env_map, build_args.span()) catch | |
| 1142 | 1141 | return parseError(tokenizer, code.source_token, "example failed to compile", .{}); |
| 1143 | 1142 | |
| 1144 | 1143 | if (code.target_str) |triple| { |
| ... | ... | @@ -1167,7 +1166,12 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1167 | 1166 | var exited_with_signal = false; |
| 1168 | 1167 | |
| 1169 | 1168 | const result = if (expected_outcome == ExpectedOutcome.Fail) blk: { |
| 1170 | const result = try ChildProcess.exec(allocator, run_args, null, &env_map, max_doc_file_size); | |
| 1169 | const result = try ChildProcess.exec(.{ | |
| 1170 | .allocator = allocator, | |
| 1171 | .argv = run_args, | |
| 1172 | .env_map = &env_map, | |
| 1173 | .max_output_bytes = max_doc_file_size, | |
| 1174 | }); | |
| 1171 | 1175 | switch (result.term) { |
| 1172 | 1176 | .Exited => |exit_code| { |
| 1173 | 1177 | if (exit_code == 0) { |
| ... | ... | @@ -1234,7 +1238,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1234 | 1238 | try test_args.appendSlice(&[_][]const u8{ "-target", triple }); |
| 1235 | 1239 | try out.print(" -target {}", .{triple}); |
| 1236 | 1240 | } |
| 1237 | const result = exec(allocator, &env_map, test_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "test failed", .{}); | |
| 1241 | const result = exec(allocator, &env_map, test_args.span()) catch return parseError(tokenizer, code.source_token, "test failed", .{}); | |
| 1238 | 1242 | const escaped_stderr = try escapeHtml(allocator, result.stderr); |
| 1239 | 1243 | const escaped_stdout = try escapeHtml(allocator, result.stdout); |
| 1240 | 1244 | try out.print("\n{}{}</code></pre>\n", .{ escaped_stderr, escaped_stdout }); |
| ... | ... | @@ -1268,12 +1272,17 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1268 | 1272 | try out.print(" --release-small", .{}); |
| 1269 | 1273 | }, |
| 1270 | 1274 | } |
| 1271 | const result = try ChildProcess.exec(allocator, test_args.toSliceConst(), null, &env_map, max_doc_file_size); | |
| 1275 | const result = try ChildProcess.exec(.{ | |
| 1276 | .allocator = allocator, | |
| 1277 | .argv = test_args.span(), | |
| 1278 | .env_map = &env_map, | |
| 1279 | .max_output_bytes = max_doc_file_size, | |
| 1280 | }); | |
| 1272 | 1281 | switch (result.term) { |
| 1273 | 1282 | .Exited => |exit_code| { |
| 1274 | 1283 | if (exit_code == 0) { |
| 1275 | 1284 | warn("{}\nThe following command incorrectly succeeded:\n", .{result.stderr}); |
| 1276 | for (test_args.toSliceConst()) |arg| | |
| 1285 | for (test_args.span()) |arg| | |
| 1277 | 1286 | warn("{} ", .{arg}) |
| 1278 | 1287 | else |
| 1279 | 1288 | warn("\n", .{}); |
| ... | ... | @@ -1282,7 +1291,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1282 | 1291 | }, |
| 1283 | 1292 | else => { |
| 1284 | 1293 | warn("{}\nThe following command crashed:\n", .{result.stderr}); |
| 1285 | for (test_args.toSliceConst()) |arg| | |
| 1294 | for (test_args.span()) |arg| | |
| 1286 | 1295 | warn("{} ", .{arg}) |
| 1287 | 1296 | else |
| 1288 | 1297 | warn("\n", .{}); |
| ... | ... | @@ -1326,12 +1335,17 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1326 | 1335 | }, |
| 1327 | 1336 | } |
| 1328 | 1337 | |
| 1329 | const result = try ChildProcess.exec(allocator, test_args.toSliceConst(), null, &env_map, max_doc_file_size); | |
| 1338 | const result = try ChildProcess.exec(.{ | |
| 1339 | .allocator = allocator, | |
| 1340 | .argv = test_args.span(), | |
| 1341 | .env_map = &env_map, | |
| 1342 | .max_output_bytes = max_doc_file_size, | |
| 1343 | }); | |
| 1330 | 1344 | switch (result.term) { |
| 1331 | 1345 | .Exited => |exit_code| { |
| 1332 | 1346 | if (exit_code == 0) { |
| 1333 | 1347 | warn("{}\nThe following command incorrectly succeeded:\n", .{result.stderr}); |
| 1334 | for (test_args.toSliceConst()) |arg| | |
| 1348 | for (test_args.span()) |arg| | |
| 1335 | 1349 | warn("{} ", .{arg}) |
| 1336 | 1350 | else |
| 1337 | 1351 | warn("\n", .{}); |
| ... | ... | @@ -1340,7 +1354,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1340 | 1354 | }, |
| 1341 | 1355 | else => { |
| 1342 | 1356 | warn("{}\nThe following command crashed:\n", .{result.stderr}); |
| 1343 | for (test_args.toSliceConst()) |arg| | |
| 1357 | for (test_args.span()) |arg| | |
| 1344 | 1358 | warn("{} ", .{arg}) |
| 1345 | 1359 | else |
| 1346 | 1360 | warn("\n", .{}); |
| ... | ... | @@ -1418,12 +1432,17 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1418 | 1432 | } |
| 1419 | 1433 | |
| 1420 | 1434 | if (maybe_error_match) |error_match| { |
| 1421 | const result = try ChildProcess.exec(allocator, build_args.toSliceConst(), null, &env_map, max_doc_file_size); | |
| 1435 | const result = try ChildProcess.exec(.{ | |
| 1436 | .allocator = allocator, | |
| 1437 | .argv = build_args.span(), | |
| 1438 | .env_map = &env_map, | |
| 1439 | .max_output_bytes = max_doc_file_size, | |
| 1440 | }); | |
| 1422 | 1441 | switch (result.term) { |
| 1423 | 1442 | .Exited => |exit_code| { |
| 1424 | 1443 | if (exit_code == 0) { |
| 1425 | 1444 | warn("{}\nThe following command incorrectly succeeded:\n", .{result.stderr}); |
| 1426 | for (build_args.toSliceConst()) |arg| | |
| 1445 | for (build_args.span()) |arg| | |
| 1427 | 1446 | warn("{} ", .{arg}) |
| 1428 | 1447 | else |
| 1429 | 1448 | warn("\n", .{}); |
| ... | ... | @@ -1432,7 +1451,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1432 | 1451 | }, |
| 1433 | 1452 | else => { |
| 1434 | 1453 | warn("{}\nThe following command crashed:\n", .{result.stderr}); |
| 1435 | for (build_args.toSliceConst()) |arg| | |
| 1454 | for (build_args.span()) |arg| | |
| 1436 | 1455 | warn("{} ", .{arg}) |
| 1437 | 1456 | else |
| 1438 | 1457 | warn("\n", .{}); |
| ... | ... | @@ -1447,7 +1466,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1447 | 1466 | const colored_stderr = try termColor(allocator, escaped_stderr); |
| 1448 | 1467 | try out.print("\n{}", .{colored_stderr}); |
| 1449 | 1468 | } else { |
| 1450 | _ = exec(allocator, &env_map, build_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "example failed to compile", .{}); | |
| 1469 | _ = exec(allocator, &env_map, build_args.span()) catch return parseError(tokenizer, code.source_token, "example failed to compile", .{}); | |
| 1451 | 1470 | } |
| 1452 | 1471 | if (!code.is_inline) { |
| 1453 | 1472 | try out.print("</code></pre>\n", .{}); |
| ... | ... | @@ -1484,7 +1503,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1484 | 1503 | try test_args.appendSlice(&[_][]const u8{ "-target", triple }); |
| 1485 | 1504 | try out.print(" -target {}", .{triple}); |
| 1486 | 1505 | } |
| 1487 | const result = exec(allocator, &env_map, test_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "test failed", .{}); | |
| 1506 | const result = exec(allocator, &env_map, test_args.span()) catch return parseError(tokenizer, code.source_token, "test failed", .{}); | |
| 1488 | 1507 | const escaped_stderr = try escapeHtml(allocator, result.stderr); |
| 1489 | 1508 | const escaped_stdout = try escapeHtml(allocator, result.stdout); |
| 1490 | 1509 | try out.print("\n{}{}</code></pre>\n", .{ escaped_stderr, escaped_stdout }); |
| ... | ... | @@ -1497,7 +1516,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1497 | 1516 | } |
| 1498 | 1517 | |
| 1499 | 1518 | fn exec(allocator: *mem.Allocator, env_map: *std.BufMap, args: []const []const u8) !ChildProcess.ExecResult { |
| 1500 | const result = try ChildProcess.exec2(.{ | |
| 1519 | const result = try ChildProcess.exec(.{ | |
| 1501 | 1520 | .allocator = allocator, |
| 1502 | 1521 | .argv = args, |
| 1503 | 1522 | .env_map = env_map, |
doc/langref.html.in+2-2| ... | ... | @@ -4953,7 +4953,7 @@ const mem = std.mem; |
| 4953 | 4953 | test "cast *[1][*]const u8 to [*]const ?[*]const u8" { |
| 4954 | 4954 | const window_name = [1][*]const u8{"window name"}; |
| 4955 | 4955 | const x: [*]const ?[*]const u8 = &window_name; |
| 4956 | assert(mem.eql(u8, std.mem.toSliceConst(u8, @ptrCast([*:0]const u8, x[0].?)), "window name")); | |
| 4956 | assert(mem.eql(u8, std.mem.spanZ(@ptrCast([*:0]const u8, x[0].?)), "window name")); | |
| 4957 | 4957 | } |
| 4958 | 4958 | {#code_end#} |
| 4959 | 4959 | {#header_close#} |
| ... | ... | @@ -9310,7 +9310,7 @@ test "string literal to constant slice" { |
| 9310 | 9310 | </p> |
| 9311 | 9311 | <p> |
| 9312 | 9312 | Sometimes the lifetime of a pointer may be more complicated. For example, when using |
| 9313 | {#syntax#}std.ArrayList(T).toSlice(){#endsyntax#}, the returned slice has a lifetime that remains | |
| 9313 | {#syntax#}std.ArrayList(T).span(){#endsyntax#}, the returned slice has a lifetime that remains | |
| 9314 | 9314 | valid until the next time the list is resized, such as by appending new elements. |
| 9315 | 9315 | </p> |
| 9316 | 9316 | <p> |
lib/std/array_list.zig+29-4| ... | ... | @@ -189,16 +189,30 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type { |
| 189 | 189 | self.len += items.len; |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | /// Append a value to the list `n` times. Allocates more memory | |
| 193 | /// as necessary. | |
| 192 | /// Same as `append` except it returns the number of bytes written, which is always the same | |
| 193 | /// as `m.len`. The purpose of this function existing is to match `std.io.OutStream` API. | |
| 194 | /// This function may be called only when `T` is `u8`. | |
| 195 | fn appendWrite(self: *Self, m: []const u8) !usize { | |
| 196 | try self.appendSlice(m); | |
| 197 | return m.len; | |
| 198 | } | |
| 199 | ||
| 200 | /// Initializes an OutStream which will append to the list. | |
| 201 | /// This function may be called only when `T` is `u8`. | |
| 202 | pub fn outStream(self: *Self) std.io.OutStream(*Self, error{OutOfMemory}, appendWrite) { | |
| 203 | return .{ .context = self }; | |
| 204 | } | |
| 205 | ||
| 206 | /// Append a value to the list `n` times. | |
| 207 | /// Allocates more memory as necessary. | |
| 194 | 208 | pub fn appendNTimes(self: *Self, value: T, n: usize) !void { |
| 195 | 209 | const old_len = self.len; |
| 196 | 210 | try self.resize(self.len + n); |
| 197 | 211 | mem.set(T, self.items[old_len..self.len], value); |
| 198 | 212 | } |
| 199 | 213 | |
| 200 | /// Adjust the list's length to `new_len`. Doesn't initialize | |
| 201 | /// added items if any. | |
| 214 | /// Adjust the list's length to `new_len`. | |
| 215 | /// Does not initialize added items if any. | |
| 202 | 216 | pub fn resize(self: *Self, new_len: usize) !void { |
| 203 | 217 | try self.ensureCapacity(new_len); |
| 204 | 218 | self.len = new_len; |
| ... | ... | @@ -479,3 +493,14 @@ test "std.ArrayList: ArrayList(T) of struct T" { |
| 479 | 493 | try root.sub_items.append(Item{ .integer = 42, .sub_items = ArrayList(Item).init(testing.allocator) }); |
| 480 | 494 | testing.expect(root.sub_items.items[0].integer == 42); |
| 481 | 495 | } |
| 496 | ||
| 497 | test "std.ArrayList(u8) implements outStream" { | |
| 498 | var buffer = ArrayList(u8).init(std.testing.allocator); | |
| 499 | defer buffer.deinit(); | |
| 500 | ||
| 501 | const x: i32 = 42; | |
| 502 | const y: i32 = 1234; | |
| 503 | try buffer.outStream().print("x: {}\ny: {}\n", .{ x, y }); | |
| 504 | ||
| 505 | testing.expectEqualSlices(u8, "x: 42\ny: 1234\n", buffer.span()); | |
| 506 | } |
lib/std/array_list_sentineled.zig created+224| ... | ... | @@ -0,0 +1,224 @@ |
| 1 | const std = @import("std.zig"); | |
| 2 | const debug = std.debug; | |
| 3 | const mem = std.mem; | |
| 4 | const Allocator = mem.Allocator; | |
| 5 | const assert = debug.assert; | |
| 6 | const testing = std.testing; | |
| 7 | const ArrayList = std.ArrayList; | |
| 8 | ||
| 9 | /// A contiguous, growable list of items in memory, with a sentinel after them. | |
| 10 | /// The sentinel is maintained when appending, resizing, etc. | |
| 11 | /// If you do not need a sentinel, consider using `ArrayList` instead. | |
| 12 | pub fn ArrayListSentineled(comptime T: type, comptime sentinel: T) type { | |
| 13 | return struct { | |
| 14 | list: ArrayList(T), | |
| 15 | ||
| 16 | const Self = @This(); | |
| 17 | ||
| 18 | /// Must deinitialize with deinit. | |
| 19 | pub fn init(allocator: *Allocator, m: []const T) !Self { | |
| 20 | var self = try initSize(allocator, m.len); | |
| 21 | mem.copy(T, self.list.items, m); | |
| 22 | return self; | |
| 23 | } | |
| 24 | ||
| 25 | /// Initialize memory to size bytes of undefined values. | |
| 26 | /// Must deinitialize with deinit. | |
| 27 | pub fn initSize(allocator: *Allocator, size: usize) !Self { | |
| 28 | var self = initNull(allocator); | |
| 29 | try self.resize(size); | |
| 30 | return self; | |
| 31 | } | |
| 32 | ||
| 33 | /// Initialize with capacity to hold at least num bytes. | |
| 34 | /// Must deinitialize with deinit. | |
| 35 | pub fn initCapacity(allocator: *Allocator, num: usize) !Self { | |
| 36 | var self = Self{ .list = try ArrayList(T).initCapacity(allocator, num + 1) }; | |
| 37 | self.list.appendAssumeCapacity(sentinel); | |
| 38 | return self; | |
| 39 | } | |
| 40 | ||
| 41 | /// Must deinitialize with deinit. | |
| 42 | /// None of the other operations are valid until you do one of these: | |
| 43 | /// * `replaceContents` | |
| 44 | /// * `resize` | |
| 45 | pub fn initNull(allocator: *Allocator) Self { | |
| 46 | return Self{ .list = ArrayList(T).init(allocator) }; | |
| 47 | } | |
| 48 | ||
| 49 | /// Must deinitialize with deinit. | |
| 50 | pub fn initFromBuffer(buffer: Self) !Self { | |
| 51 | return Self.init(buffer.list.allocator, buffer.span()); | |
| 52 | } | |
| 53 | ||
| 54 | /// Takes ownership of the passed in slice. The slice must have been | |
| 55 | /// allocated with `allocator`. | |
| 56 | /// Must deinitialize with deinit. | |
| 57 | pub fn fromOwnedSlice(allocator: *Allocator, slice: []T) !Self { | |
| 58 | var self = Self{ .list = ArrayList(T).fromOwnedSlice(allocator, slice) }; | |
| 59 | try self.list.append(sentinel); | |
| 60 | return self; | |
| 61 | } | |
| 62 | ||
| 63 | /// The caller owns the returned memory. The list becomes null and is safe to `deinit`. | |
| 64 | pub fn toOwnedSlice(self: *Self) [:sentinel]T { | |
| 65 | const allocator = self.list.allocator; | |
| 66 | const result = self.list.toOwnedSlice(); | |
| 67 | self.* = initNull(allocator); | |
| 68 | return result[0 .. result.len - 1 :sentinel]; | |
| 69 | } | |
| 70 | ||
| 71 | /// Only works when `T` is `u8`. | |
| 72 | pub fn allocPrint(allocator: *Allocator, comptime format: []const u8, args: var) !Self { | |
| 73 | const size = std.math.cast(usize, std.fmt.count(format, args)) catch |err| switch (err) { | |
| 74 | error.Overflow => return error.OutOfMemory, | |
| 75 | }; | |
| 76 | var self = try Self.initSize(allocator, size); | |
| 77 | assert((std.fmt.bufPrint(self.list.items, format, args) catch unreachable).len == size); | |
| 78 | return self; | |
| 79 | } | |
| 80 | ||
| 81 | pub fn deinit(self: *Self) void { | |
| 82 | self.list.deinit(); | |
| 83 | } | |
| 84 | ||
| 85 | pub fn span(self: var) @TypeOf(self.list.items[0 .. self.list.len - 1 :sentinel]) { | |
| 86 | return self.list.span()[0..self.len() :sentinel]; | |
| 87 | } | |
| 88 | ||
| 89 | pub fn shrink(self: *Self, new_len: usize) void { | |
| 90 | assert(new_len <= self.len()); | |
| 91 | self.list.shrink(new_len + 1); | |
| 92 | self.list.items[self.len()] = sentinel; | |
| 93 | } | |
| 94 | ||
| 95 | pub fn resize(self: *Self, new_len: usize) !void { | |
| 96 | try self.list.resize(new_len + 1); | |
| 97 | self.list.items[self.len()] = sentinel; | |
| 98 | } | |
| 99 | ||
| 100 | pub fn isNull(self: Self) bool { | |
| 101 | return self.list.len == 0; | |
| 102 | } | |
| 103 | ||
| 104 | pub fn len(self: Self) usize { | |
| 105 | return self.list.len - 1; | |
| 106 | } | |
| 107 | ||
| 108 | pub fn capacity(self: Self) usize { | |
| 109 | return if (self.list.items.len > 0) | |
| 110 | self.list.items.len - 1 | |
| 111 | else | |
| 112 | 0; | |
| 113 | } | |
| 114 | ||
| 115 | pub fn appendSlice(self: *Self, m: []const T) !void { | |
| 116 | const old_len = self.len(); | |
| 117 | try self.resize(old_len + m.len); | |
| 118 | mem.copy(T, self.list.span()[old_len..], m); | |
| 119 | } | |
| 120 | ||
| 121 | pub fn append(self: *Self, byte: T) !void { | |
| 122 | const old_len = self.len(); | |
| 123 | try self.resize(old_len + 1); | |
| 124 | self.list.span()[old_len] = byte; | |
| 125 | } | |
| 126 | ||
| 127 | pub fn eql(self: Self, m: []const T) bool { | |
| 128 | return mem.eql(T, self.span(), m); | |
| 129 | } | |
| 130 | ||
| 131 | pub fn startsWith(self: Self, m: []const T) bool { | |
| 132 | if (self.len() < m.len) return false; | |
| 133 | return mem.eql(T, self.list.items[0..m.len], m); | |
| 134 | } | |
| 135 | ||
| 136 | pub fn endsWith(self: Self, m: []const T) bool { | |
| 137 | const l = self.len(); | |
| 138 | if (l < m.len) return false; | |
| 139 | const start = l - m.len; | |
| 140 | return mem.eql(T, self.list.items[start..l], m); | |
| 141 | } | |
| 142 | ||
| 143 | pub fn replaceContents(self: *Self, m: []const T) !void { | |
| 144 | try self.resize(m.len); | |
| 145 | mem.copy(T, self.list.span(), m); | |
| 146 | } | |
| 147 | ||
| 148 | /// Initializes an OutStream which will append to the list. | |
| 149 | /// This function may be called only when `T` is `u8`. | |
| 150 | pub fn outStream(self: *Self) std.io.OutStream(*Self, error{OutOfMemory}, appendWrite) { | |
| 151 | return .{ .context = self }; | |
| 152 | } | |
| 153 | ||
| 154 | /// Same as `append` except it returns the number of bytes written, which is always the same | |
| 155 | /// as `m.len`. The purpose of this function existing is to match `std.io.OutStream` API. | |
| 156 | /// This function may be called only when `T` is `u8`. | |
| 157 | pub fn appendWrite(self: *Self, m: []const u8) !usize { | |
| 158 | try self.appendSlice(m); | |
| 159 | return m.len; | |
| 160 | } | |
| 161 | }; | |
| 162 | } | |
| 163 | ||
| 164 | test "simple" { | |
| 165 | var buf = try ArrayListSentineled(u8, 0).init(testing.allocator, ""); | |
| 166 | defer buf.deinit(); | |
| 167 | ||
| 168 | testing.expect(buf.len() == 0); | |
| 169 | try buf.appendSlice("hello"); | |
| 170 | try buf.appendSlice(" "); | |
| 171 | try buf.appendSlice("world"); | |
| 172 | testing.expect(buf.eql("hello world")); | |
| 173 | testing.expect(mem.eql(u8, mem.spanZ(buf.span().ptr), buf.span())); | |
| 174 | ||
| 175 | var buf2 = try ArrayListSentineled(u8, 0).initFromBuffer(buf); | |
| 176 | defer buf2.deinit(); | |
| 177 | testing.expect(buf.eql(buf2.span())); | |
| 178 | ||
| 179 | testing.expect(buf.startsWith("hell")); | |
| 180 | testing.expect(buf.endsWith("orld")); | |
| 181 | ||
| 182 | try buf2.resize(4); | |
| 183 | testing.expect(buf.startsWith(buf2.span())); | |
| 184 | } | |
| 185 | ||
| 186 | test "initSize" { | |
| 187 | var buf = try ArrayListSentineled(u8, 0).initSize(testing.allocator, 3); | |
| 188 | defer buf.deinit(); | |
| 189 | testing.expect(buf.len() == 3); | |
| 190 | try buf.appendSlice("hello"); | |
| 191 | testing.expect(mem.eql(u8, buf.span()[3..], "hello")); | |
| 192 | } | |
| 193 | ||
| 194 | test "initCapacity" { | |
| 195 | var buf = try ArrayListSentineled(u8, 0).initCapacity(testing.allocator, 10); | |
| 196 | defer buf.deinit(); | |
| 197 | testing.expect(buf.len() == 0); | |
| 198 | testing.expect(buf.capacity() >= 10); | |
| 199 | const old_cap = buf.capacity(); | |
| 200 | try buf.appendSlice("hello"); | |
| 201 | testing.expect(buf.len() == 5); | |
| 202 | testing.expect(buf.capacity() == old_cap); | |
| 203 | testing.expect(mem.eql(u8, buf.span(), "hello")); | |
| 204 | } | |
| 205 | ||
| 206 | test "print" { | |
| 207 | var buf = try ArrayListSentineled(u8, 0).init(testing.allocator, ""); | |
| 208 | defer buf.deinit(); | |
| 209 | ||
| 210 | try buf.outStream().print("Hello {} the {}", .{ 2, "world" }); | |
| 211 | testing.expect(buf.eql("Hello 2 the world")); | |
| 212 | } | |
| 213 | ||
| 214 | test "outStream" { | |
| 215 | var buffer = try ArrayListSentineled(u8, 0).initSize(testing.allocator, 0); | |
| 216 | defer buffer.deinit(); | |
| 217 | const buf_stream = buffer.outStream(); | |
| 218 | ||
| 219 | const x: i32 = 42; | |
| 220 | const y: i32 = 1234; | |
| 221 | try buf_stream.print("x: {}\ny: {}\n", .{ x, y }); | |
| 222 | ||
| 223 | testing.expect(mem.eql(u8, buffer.span(), "x: 42\ny: 1234\n")); | |
| 224 | } |
lib/std/atomic/queue.zig+1-1| ... | ... | @@ -227,7 +227,7 @@ fn startPuts(ctx: *Context) u8 { |
| 227 | 227 | var r = std.rand.DefaultPrng.init(0xdeadbeef); |
| 228 | 228 | while (put_count != 0) : (put_count -= 1) { |
| 229 | 229 | std.time.sleep(1); // let the os scheduler be our fuzz |
| 230 | const x = @bitCast(i32, r.random.scalar(u32)); | |
| 230 | const x = @bitCast(i32, r.random.int(u32)); | |
| 231 | 231 | const node = ctx.allocator.create(Queue(i32).Node) catch unreachable; |
| 232 | 232 | node.* = .{ |
| 233 | 233 | .prev = undefined, |
lib/std/atomic/stack.zig+1-1| ... | ... | @@ -150,7 +150,7 @@ fn startPuts(ctx: *Context) u8 { |
| 150 | 150 | var r = std.rand.DefaultPrng.init(0xdeadbeef); |
| 151 | 151 | while (put_count != 0) : (put_count -= 1) { |
| 152 | 152 | std.time.sleep(1); // let the os scheduler be our fuzz |
| 153 | const x = @bitCast(i32, r.random.scalar(u32)); | |
| 153 | const x = @bitCast(i32, r.random.int(u32)); | |
| 154 | 154 | const node = ctx.allocator.create(Stack(i32).Node) catch unreachable; |
| 155 | 155 | node.* = Stack(i32).Node{ |
| 156 | 156 | .next = undefined, |
lib/std/buffer.zig deleted-225| ... | ... | @@ -1,225 +0,0 @@ |
| 1 | const std = @import("std.zig"); | |
| 2 | const debug = std.debug; | |
| 3 | const mem = std.mem; | |
| 4 | const Allocator = mem.Allocator; | |
| 5 | const assert = debug.assert; | |
| 6 | const testing = std.testing; | |
| 7 | const ArrayList = std.ArrayList; | |
| 8 | ||
| 9 | /// A buffer that allocates memory and maintains a null byte at the end. | |
| 10 | pub const Buffer = struct { | |
| 11 | list: ArrayList(u8), | |
| 12 | ||
| 13 | /// Must deinitialize with deinit. | |
| 14 | pub fn init(allocator: *Allocator, m: []const u8) !Buffer { | |
| 15 | var self = try initSize(allocator, m.len); | |
| 16 | mem.copy(u8, self.list.items, m); | |
| 17 | return self; | |
| 18 | } | |
| 19 | ||
| 20 | /// Initialize memory to size bytes of undefined values. | |
| 21 | /// Must deinitialize with deinit. | |
| 22 | pub fn initSize(allocator: *Allocator, size: usize) !Buffer { | |
| 23 | var self = initNull(allocator); | |
| 24 | try self.resize(size); | |
| 25 | return self; | |
| 26 | } | |
| 27 | ||
| 28 | /// Initialize with capacity to hold at least num bytes. | |
| 29 | /// Must deinitialize with deinit. | |
| 30 | pub fn initCapacity(allocator: *Allocator, num: usize) !Buffer { | |
| 31 | var self = Buffer{ .list = try ArrayList(u8).initCapacity(allocator, num + 1) }; | |
| 32 | self.list.appendAssumeCapacity(0); | |
| 33 | return self; | |
| 34 | } | |
| 35 | ||
| 36 | /// Must deinitialize with deinit. | |
| 37 | /// None of the other operations are valid until you do one of these: | |
| 38 | /// * ::replaceContents | |
| 39 | /// * ::resize | |
| 40 | pub fn initNull(allocator: *Allocator) Buffer { | |
| 41 | return Buffer{ .list = ArrayList(u8).init(allocator) }; | |
| 42 | } | |
| 43 | ||
| 44 | /// Must deinitialize with deinit. | |
| 45 | pub fn initFromBuffer(buffer: Buffer) !Buffer { | |
| 46 | return Buffer.init(buffer.list.allocator, buffer.toSliceConst()); | |
| 47 | } | |
| 48 | ||
| 49 | /// Buffer takes ownership of the passed in slice. The slice must have been | |
| 50 | /// allocated with `allocator`. | |
| 51 | /// Must deinitialize with deinit. | |
| 52 | pub fn fromOwnedSlice(allocator: *Allocator, slice: []u8) !Buffer { | |
| 53 | var self = Buffer{ .list = ArrayList(u8).fromOwnedSlice(allocator, slice) }; | |
| 54 | try self.list.append(0); | |
| 55 | return self; | |
| 56 | } | |
| 57 | ||
| 58 | /// The caller owns the returned memory. The Buffer becomes null and | |
| 59 | /// is safe to `deinit`. | |
| 60 | pub fn toOwnedSlice(self: *Buffer) [:0]u8 { | |
| 61 | const allocator = self.list.allocator; | |
| 62 | const result = self.list.toOwnedSlice(); | |
| 63 | self.* = initNull(allocator); | |
| 64 | return result[0 .. result.len - 1 :0]; | |
| 65 | } | |
| 66 | ||
| 67 | pub fn allocPrint(allocator: *Allocator, comptime format: []const u8, args: var) !Buffer { | |
| 68 | const size = std.math.cast(usize, std.fmt.count(format, args)) catch |err| switch (err) { | |
| 69 | error.Overflow => return error.OutOfMemory, | |
| 70 | }; | |
| 71 | var self = try Buffer.initSize(allocator, size); | |
| 72 | assert((std.fmt.bufPrint(self.list.items, format, args) catch unreachable).len == size); | |
| 73 | return self; | |
| 74 | } | |
| 75 | ||
| 76 | pub fn deinit(self: *Buffer) void { | |
| 77 | self.list.deinit(); | |
| 78 | } | |
| 79 | ||
| 80 | pub fn span(self: var) @TypeOf(self.list.items[0 .. self.list.len - 1 :0]) { | |
| 81 | return self.list.span()[0..self.len() :0]; | |
| 82 | } | |
| 83 | ||
| 84 | /// Deprecated: use `span` | |
| 85 | pub fn toSlice(self: Buffer) [:0]u8 { | |
| 86 | return self.span(); | |
| 87 | } | |
| 88 | ||
| 89 | /// Deprecated: use `span` | |
| 90 | pub fn toSliceConst(self: Buffer) [:0]const u8 { | |
| 91 | return self.span(); | |
| 92 | } | |
| 93 | ||
| 94 | pub fn shrink(self: *Buffer, new_len: usize) void { | |
| 95 | assert(new_len <= self.len()); | |
| 96 | self.list.shrink(new_len + 1); | |
| 97 | self.list.items[self.len()] = 0; | |
| 98 | } | |
| 99 | ||
| 100 | pub fn resize(self: *Buffer, new_len: usize) !void { | |
| 101 | try self.list.resize(new_len + 1); | |
| 102 | self.list.items[self.len()] = 0; | |
| 103 | } | |
| 104 | ||
| 105 | pub fn isNull(self: Buffer) bool { | |
| 106 | return self.list.len == 0; | |
| 107 | } | |
| 108 | ||
| 109 | pub fn len(self: Buffer) usize { | |
| 110 | return self.list.len - 1; | |
| 111 | } | |
| 112 | ||
| 113 | pub fn capacity(self: Buffer) usize { | |
| 114 | return if (self.list.items.len > 0) | |
| 115 | self.list.items.len - 1 | |
| 116 | else | |
| 117 | 0; | |
| 118 | } | |
| 119 | ||
| 120 | pub fn append(self: *Buffer, m: []const u8) !void { | |
| 121 | const old_len = self.len(); | |
| 122 | try self.resize(old_len + m.len); | |
| 123 | mem.copy(u8, self.list.toSlice()[old_len..], m); | |
| 124 | } | |
| 125 | ||
| 126 | pub fn appendByte(self: *Buffer, byte: u8) !void { | |
| 127 | const old_len = self.len(); | |
| 128 | try self.resize(old_len + 1); | |
| 129 | self.list.toSlice()[old_len] = byte; | |
| 130 | } | |
| 131 | ||
| 132 | pub fn eql(self: Buffer, m: []const u8) bool { | |
| 133 | return mem.eql(u8, self.toSliceConst(), m); | |
| 134 | } | |
| 135 | ||
| 136 | pub fn startsWith(self: Buffer, m: []const u8) bool { | |
| 137 | if (self.len() < m.len) return false; | |
| 138 | return mem.eql(u8, self.list.items[0..m.len], m); | |
| 139 | } | |
| 140 | ||
| 141 | pub fn endsWith(self: Buffer, m: []const u8) bool { | |
| 142 | const l = self.len(); | |
| 143 | if (l < m.len) return false; | |
| 144 | const start = l - m.len; | |
| 145 | return mem.eql(u8, self.list.items[start..l], m); | |
| 146 | } | |
| 147 | ||
| 148 | pub fn replaceContents(self: *Buffer, m: []const u8) !void { | |
| 149 | try self.resize(m.len); | |
| 150 | mem.copy(u8, self.list.toSlice(), m); | |
| 151 | } | |
| 152 | ||
| 153 | pub fn outStream(self: *Buffer) std.io.OutStream(*Buffer, error{OutOfMemory}, appendWrite) { | |
| 154 | return .{ .context = self }; | |
| 155 | } | |
| 156 | ||
| 157 | /// Same as `append` except it returns the number of bytes written, which is always the same | |
| 158 | /// as `m.len`. The purpose of this function existing is to match `std.io.OutStream` API. | |
| 159 | pub fn appendWrite(self: *Buffer, m: []const u8) !usize { | |
| 160 | try self.append(m); | |
| 161 | return m.len; | |
| 162 | } | |
| 163 | }; | |
| 164 | ||
| 165 | test "simple Buffer" { | |
| 166 | var buf = try Buffer.init(testing.allocator, ""); | |
| 167 | defer buf.deinit(); | |
| 168 | ||
| 169 | testing.expect(buf.len() == 0); | |
| 170 | try buf.append("hello"); | |
| 171 | try buf.append(" "); | |
| 172 | try buf.append("world"); | |
| 173 | testing.expect(buf.eql("hello world")); | |
| 174 | testing.expect(mem.eql(u8, mem.toSliceConst(u8, buf.toSliceConst().ptr), buf.toSliceConst())); | |
| 175 | ||
| 176 | var buf2 = try Buffer.initFromBuffer(buf); | |
| 177 | defer buf2.deinit(); | |
| 178 | testing.expect(buf.eql(buf2.toSliceConst())); | |
| 179 | ||
| 180 | testing.expect(buf.startsWith("hell")); | |
| 181 | testing.expect(buf.endsWith("orld")); | |
| 182 | ||
| 183 | try buf2.resize(4); | |
| 184 | testing.expect(buf.startsWith(buf2.toSlice())); | |
| 185 | } | |
| 186 | ||
| 187 | test "Buffer.initSize" { | |
| 188 | var buf = try Buffer.initSize(testing.allocator, 3); | |
| 189 | defer buf.deinit(); | |
| 190 | testing.expect(buf.len() == 3); | |
| 191 | try buf.append("hello"); | |
| 192 | testing.expect(mem.eql(u8, buf.toSliceConst()[3..], "hello")); | |
| 193 | } | |
| 194 | ||
| 195 | test "Buffer.initCapacity" { | |
| 196 | var buf = try Buffer.initCapacity(testing.allocator, 10); | |
| 197 | defer buf.deinit(); | |
| 198 | testing.expect(buf.len() == 0); | |
| 199 | testing.expect(buf.capacity() >= 10); | |
| 200 | const old_cap = buf.capacity(); | |
| 201 | try buf.append("hello"); | |
| 202 | testing.expect(buf.len() == 5); | |
| 203 | testing.expect(buf.capacity() == old_cap); | |
| 204 | testing.expect(mem.eql(u8, buf.toSliceConst(), "hello")); | |
| 205 | } | |
| 206 | ||
| 207 | test "Buffer.print" { | |
| 208 | var buf = try Buffer.init(testing.allocator, ""); | |
| 209 | defer buf.deinit(); | |
| 210 | ||
| 211 | try buf.outStream().print("Hello {} the {}", .{ 2, "world" }); | |
| 212 | testing.expect(buf.eql("Hello 2 the world")); | |
| 213 | } | |
| 214 | ||
| 215 | test "Buffer.outStream" { | |
| 216 | var buffer = try Buffer.initSize(testing.allocator, 0); | |
| 217 | defer buffer.deinit(); | |
| 218 | const buf_stream = buffer.outStream(); | |
| 219 | ||
| 220 | const x: i32 = 42; | |
| 221 | const y: i32 = 1234; | |
| 222 | try buf_stream.print("x: {}\ny: {}\n", .{ x, y }); | |
| 223 | ||
| 224 | testing.expect(mem.eql(u8, buffer.toSlice(), "x: 42\ny: 1234\n")); | |
| 225 | } |
lib/std/build.zig+29-32| ... | ... | @@ -355,7 +355,7 @@ pub const Builder = struct { |
| 355 | 355 | } |
| 356 | 356 | } |
| 357 | 357 | |
| 358 | for (wanted_steps.toSliceConst()) |s| { | |
| 358 | for (wanted_steps.span()) |s| { | |
| 359 | 359 | try self.makeOneStep(s); |
| 360 | 360 | } |
| 361 | 361 | } |
| ... | ... | @@ -372,7 +372,7 @@ pub const Builder = struct { |
| 372 | 372 | const uninstall_tls = @fieldParentPtr(TopLevelStep, "step", uninstall_step); |
| 373 | 373 | const self = @fieldParentPtr(Builder, "uninstall_tls", uninstall_tls); |
| 374 | 374 | |
| 375 | for (self.installed_files.toSliceConst()) |installed_file| { | |
| 375 | for (self.installed_files.span()) |installed_file| { | |
| 376 | 376 | const full_path = self.getInstallPath(installed_file.dir, installed_file.path); |
| 377 | 377 | if (self.verbose) { |
| 378 | 378 | warn("rm {}\n", .{full_path}); |
| ... | ... | @@ -390,7 +390,7 @@ pub const Builder = struct { |
| 390 | 390 | } |
| 391 | 391 | s.loop_flag = true; |
| 392 | 392 | |
| 393 | for (s.dependencies.toSlice()) |dep| { | |
| 393 | for (s.dependencies.span()) |dep| { | |
| 394 | 394 | self.makeOneStep(dep) catch |err| { |
| 395 | 395 | if (err == error.DependencyLoopDetected) { |
| 396 | 396 | warn(" {}\n", .{s.name}); |
| ... | ... | @@ -405,7 +405,7 @@ pub const Builder = struct { |
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | fn getTopLevelStepByName(self: *Builder, name: []const u8) !*Step { |
| 408 | for (self.top_level_steps.toSliceConst()) |top_level_step| { | |
| 408 | for (self.top_level_steps.span()) |top_level_step| { | |
| 409 | 409 | if (mem.eql(u8, top_level_step.step.name, name)) { |
| 410 | 410 | return &top_level_step.step; |
| 411 | 411 | } |
| ... | ... | @@ -470,7 +470,7 @@ pub const Builder = struct { |
| 470 | 470 | return null; |
| 471 | 471 | }, |
| 472 | 472 | UserValue.Scalar => |s| return &[_][]const u8{s}, |
| 473 | UserValue.List => |lst| return lst.toSliceConst(), | |
| 473 | UserValue.List => |lst| return lst.span(), | |
| 474 | 474 | }, |
| 475 | 475 | } |
| 476 | 476 | } |
| ... | ... | @@ -866,7 +866,7 @@ pub const Builder = struct { |
| 866 | 866 | pub fn findProgram(self: *Builder, names: []const []const u8, paths: []const []const u8) ![]const u8 { |
| 867 | 867 | // TODO report error for ambiguous situations |
| 868 | 868 | const exe_extension = @as(CrossTarget, .{}).exeFileExt(); |
| 869 | for (self.search_prefixes.toSliceConst()) |search_prefix| { | |
| 869 | for (self.search_prefixes.span()) |search_prefix| { | |
| 870 | 870 | for (names) |name| { |
| 871 | 871 | if (fs.path.isAbsolute(name)) { |
| 872 | 872 | return name; |
| ... | ... | @@ -1010,7 +1010,7 @@ pub const Builder = struct { |
| 1010 | 1010 | .desc = tok_it.rest(), |
| 1011 | 1011 | }); |
| 1012 | 1012 | } |
| 1013 | return list.toSliceConst(); | |
| 1013 | return list.span(); | |
| 1014 | 1014 | } |
| 1015 | 1015 | |
| 1016 | 1016 | fn getPkgConfigList(self: *Builder) ![]const PkgConfigPkg { |
| ... | ... | @@ -1139,7 +1139,7 @@ pub const LibExeObjStep = struct { |
| 1139 | 1139 | out_lib_filename: []const u8, |
| 1140 | 1140 | out_pdb_filename: []const u8, |
| 1141 | 1141 | packages: ArrayList(Pkg), |
| 1142 | build_options_contents: std.Buffer, | |
| 1142 | build_options_contents: std.ArrayList(u8), | |
| 1143 | 1143 | system_linker_hack: bool = false, |
| 1144 | 1144 | |
| 1145 | 1145 | object_src: []const u8, |
| ... | ... | @@ -1274,7 +1274,7 @@ pub const LibExeObjStep = struct { |
| 1274 | 1274 | .lib_paths = ArrayList([]const u8).init(builder.allocator), |
| 1275 | 1275 | .framework_dirs = ArrayList([]const u8).init(builder.allocator), |
| 1276 | 1276 | .object_src = undefined, |
| 1277 | .build_options_contents = std.Buffer.initSize(builder.allocator, 0) catch unreachable, | |
| 1277 | .build_options_contents = std.ArrayList(u8).init(builder.allocator), | |
| 1278 | 1278 | .c_std = Builder.CStd.C99, |
| 1279 | 1279 | .override_lib_dir = null, |
| 1280 | 1280 | .main_pkg_path = null, |
| ... | ... | @@ -1395,7 +1395,7 @@ pub const LibExeObjStep = struct { |
| 1395 | 1395 | if (isLibCLibrary(name)) { |
| 1396 | 1396 | return self.is_linking_libc; |
| 1397 | 1397 | } |
| 1398 | for (self.link_objects.toSliceConst()) |link_object| { | |
| 1398 | for (self.link_objects.span()) |link_object| { | |
| 1399 | 1399 | switch (link_object) { |
| 1400 | 1400 | LinkObject.SystemLib => |n| if (mem.eql(u8, n, name)) return true, |
| 1401 | 1401 | else => continue, |
| ... | ... | @@ -1599,10 +1599,7 @@ pub const LibExeObjStep = struct { |
| 1599 | 1599 | self.main_pkg_path = dir_path; |
| 1600 | 1600 | } |
| 1601 | 1601 | |
| 1602 | /// Deprecated; just set the field directly. | |
| 1603 | pub fn setDisableGenH(self: *LibExeObjStep, is_disabled: bool) void { | |
| 1604 | self.emit_h = !is_disabled; | |
| 1605 | } | |
| 1602 | pub const setDisableGenH = @compileError("deprecated; set the emit_h field directly"); | |
| 1606 | 1603 | |
| 1607 | 1604 | pub fn setLibCFile(self: *LibExeObjStep, libc_file: ?[]const u8) void { |
| 1608 | 1605 | self.libc_file = libc_file; |
| ... | ... | @@ -1762,7 +1759,7 @@ pub const LibExeObjStep = struct { |
| 1762 | 1759 | self.include_dirs.append(IncludeDir{ .OtherStep = other }) catch unreachable; |
| 1763 | 1760 | |
| 1764 | 1761 | // Inherit dependency on system libraries |
| 1765 | for (other.link_objects.toSliceConst()) |link_object| { | |
| 1762 | for (other.link_objects.span()) |link_object| { | |
| 1766 | 1763 | switch (link_object) { |
| 1767 | 1764 | .SystemLib => |name| self.linkSystemLibrary(name), |
| 1768 | 1765 | else => continue, |
| ... | ... | @@ -1802,7 +1799,7 @@ pub const LibExeObjStep = struct { |
| 1802 | 1799 | |
| 1803 | 1800 | if (self.root_src) |root_src| try zig_args.append(root_src.getPath(builder)); |
| 1804 | 1801 | |
| 1805 | for (self.link_objects.toSlice()) |link_object| { | |
| 1802 | for (self.link_objects.span()) |link_object| { | |
| 1806 | 1803 | switch (link_object) { |
| 1807 | 1804 | .StaticPath => |static_path| { |
| 1808 | 1805 | try zig_args.append("--object"); |
| ... | ... | @@ -1850,12 +1847,12 @@ pub const LibExeObjStep = struct { |
| 1850 | 1847 | } |
| 1851 | 1848 | } |
| 1852 | 1849 | |
| 1853 | if (self.build_options_contents.len() > 0) { | |
| 1850 | if (self.build_options_contents.len > 0) { | |
| 1854 | 1851 | const build_options_file = try fs.path.join( |
| 1855 | 1852 | builder.allocator, |
| 1856 | 1853 | &[_][]const u8{ builder.cache_root, builder.fmt("{}_build_options.zig", .{self.name}) }, |
| 1857 | 1854 | ); |
| 1858 | try std.io.writeFile(build_options_file, self.build_options_contents.toSliceConst()); | |
| 1855 | try fs.cwd().writeFile(build_options_file, self.build_options_contents.span()); | |
| 1859 | 1856 | try zig_args.append("--pkg-begin"); |
| 1860 | 1857 | try zig_args.append("build_options"); |
| 1861 | 1858 | try zig_args.append(builder.pathFromRoot(build_options_file)); |
| ... | ... | @@ -1963,22 +1960,22 @@ pub const LibExeObjStep = struct { |
| 1963 | 1960 | try zig_args.append(cross.cpu.model.name); |
| 1964 | 1961 | } |
| 1965 | 1962 | } else { |
| 1966 | var mcpu_buffer = try std.Buffer.init(builder.allocator, "-mcpu="); | |
| 1967 | try mcpu_buffer.append(cross.cpu.model.name); | |
| 1963 | var mcpu_buffer = std.ArrayList(u8).init(builder.allocator); | |
| 1964 | ||
| 1965 | try mcpu_buffer.outStream().print("-mcpu={}", .{cross.cpu.model.name}); | |
| 1968 | 1966 | |
| 1969 | 1967 | for (all_features) |feature, i_usize| { |
| 1970 | 1968 | const i = @intCast(std.Target.Cpu.Feature.Set.Index, i_usize); |
| 1971 | 1969 | const in_cpu_set = populated_cpu_features.isEnabled(i); |
| 1972 | 1970 | const in_actual_set = cross.cpu.features.isEnabled(i); |
| 1973 | 1971 | if (in_cpu_set and !in_actual_set) { |
| 1974 | try mcpu_buffer.appendByte('-'); | |
| 1975 | try mcpu_buffer.append(feature.name); | |
| 1972 | try mcpu_buffer.outStream().print("-{}", .{feature.name}); | |
| 1976 | 1973 | } else if (!in_cpu_set and in_actual_set) { |
| 1977 | try mcpu_buffer.appendByte('+'); | |
| 1978 | try mcpu_buffer.append(feature.name); | |
| 1974 | try mcpu_buffer.outStream().print("+{}", .{feature.name}); | |
| 1979 | 1975 | } |
| 1980 | 1976 | } |
| 1981 | try zig_args.append(mcpu_buffer.toSliceConst()); | |
| 1977 | ||
| 1978 | try zig_args.append(mcpu_buffer.toOwnedSlice()); | |
| 1982 | 1979 | } |
| 1983 | 1980 | |
| 1984 | 1981 | if (self.target.dynamic_linker.get()) |dynamic_linker| { |
| ... | ... | @@ -2040,7 +2037,7 @@ pub const LibExeObjStep = struct { |
| 2040 | 2037 | try zig_args.append("--test-cmd-bin"); |
| 2041 | 2038 | }, |
| 2042 | 2039 | } |
| 2043 | for (self.packages.toSliceConst()) |pkg| { | |
| 2040 | for (self.packages.span()) |pkg| { | |
| 2044 | 2041 | try zig_args.append("--pkg-begin"); |
| 2045 | 2042 | try zig_args.append(pkg.name); |
| 2046 | 2043 | try zig_args.append(builder.pathFromRoot(pkg.path)); |
| ... | ... | @@ -2057,7 +2054,7 @@ pub const LibExeObjStep = struct { |
| 2057 | 2054 | try zig_args.append("--pkg-end"); |
| 2058 | 2055 | } |
| 2059 | 2056 | |
| 2060 | for (self.include_dirs.toSliceConst()) |include_dir| { | |
| 2057 | for (self.include_dirs.span()) |include_dir| { | |
| 2061 | 2058 | switch (include_dir) { |
| 2062 | 2059 | .RawPath => |include_path| { |
| 2063 | 2060 | try zig_args.append("-I"); |
| ... | ... | @@ -2075,18 +2072,18 @@ pub const LibExeObjStep = struct { |
| 2075 | 2072 | } |
| 2076 | 2073 | } |
| 2077 | 2074 | |
| 2078 | for (self.lib_paths.toSliceConst()) |lib_path| { | |
| 2075 | for (self.lib_paths.span()) |lib_path| { | |
| 2079 | 2076 | try zig_args.append("-L"); |
| 2080 | 2077 | try zig_args.append(lib_path); |
| 2081 | 2078 | } |
| 2082 | 2079 | |
| 2083 | for (self.c_macros.toSliceConst()) |c_macro| { | |
| 2080 | for (self.c_macros.span()) |c_macro| { | |
| 2084 | 2081 | try zig_args.append("-D"); |
| 2085 | 2082 | try zig_args.append(c_macro); |
| 2086 | 2083 | } |
| 2087 | 2084 | |
| 2088 | 2085 | if (self.target.isDarwin()) { |
| 2089 | for (self.framework_dirs.toSliceConst()) |dir| { | |
| 2086 | for (self.framework_dirs.span()) |dir| { | |
| 2090 | 2087 | try zig_args.append("-F"); |
| 2091 | 2088 | try zig_args.append(dir); |
| 2092 | 2089 | } |
| ... | ... | @@ -2146,12 +2143,12 @@ pub const LibExeObjStep = struct { |
| 2146 | 2143 | } |
| 2147 | 2144 | |
| 2148 | 2145 | if (self.kind == Kind.Test) { |
| 2149 | try builder.spawnChild(zig_args.toSliceConst()); | |
| 2146 | try builder.spawnChild(zig_args.span()); | |
| 2150 | 2147 | } else { |
| 2151 | 2148 | try zig_args.append("--cache"); |
| 2152 | 2149 | try zig_args.append("on"); |
| 2153 | 2150 | |
| 2154 | const output_dir_nl = try builder.execFromStep(zig_args.toSliceConst(), &self.step); | |
| 2151 | const output_dir_nl = try builder.execFromStep(zig_args.span(), &self.step); | |
| 2155 | 2152 | const build_output_dir = mem.trimRight(u8, output_dir_nl, "\r\n"); |
| 2156 | 2153 | |
| 2157 | 2154 | if (self.output_dir) |output_dir| { |
lib/std/build/emit_raw.zig+6-6| ... | ... | @@ -72,7 +72,7 @@ const BinaryElfOutput = struct { |
| 72 | 72 | newSegment.binaryOffset = 0; |
| 73 | 73 | newSegment.firstSection = null; |
| 74 | 74 | |
| 75 | for (self.sections.toSlice()) |section| { | |
| 75 | for (self.sections.span()) |section| { | |
| 76 | 76 | if (sectionWithinSegment(section, phdr)) { |
| 77 | 77 | if (section.segment) |sectionSegment| { |
| 78 | 78 | if (sectionSegment.elfOffset > newSegment.elfOffset) { |
| ... | ... | @@ -92,7 +92,7 @@ const BinaryElfOutput = struct { |
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | sort.sort(*BinaryElfSegment, self.segments.toSlice(), segmentSortCompare); | |
| 95 | sort.sort(*BinaryElfSegment, self.segments.span(), segmentSortCompare); | |
| 96 | 96 | |
| 97 | 97 | if (self.segments.len > 0) { |
| 98 | 98 | const firstSegment = self.segments.at(0); |
| ... | ... | @@ -105,19 +105,19 @@ const BinaryElfOutput = struct { |
| 105 | 105 | |
| 106 | 106 | const basePhysicalAddress = firstSegment.physicalAddress; |
| 107 | 107 | |
| 108 | for (self.segments.toSlice()) |segment| { | |
| 108 | for (self.segments.span()) |segment| { | |
| 109 | 109 | segment.binaryOffset = segment.physicalAddress - basePhysicalAddress; |
| 110 | 110 | } |
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | for (self.sections.toSlice()) |section| { | |
| 114 | for (self.sections.span()) |section| { | |
| 115 | 115 | if (section.segment) |segment| { |
| 116 | 116 | section.binaryOffset = segment.binaryOffset + (section.elfOffset - segment.elfOffset); |
| 117 | 117 | } |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | sort.sort(*BinaryElfSection, self.sections.toSlice(), sectionSortCompare); | |
| 120 | sort.sort(*BinaryElfSection, self.sections.span(), sectionSortCompare); | |
| 121 | 121 | |
| 122 | 122 | return self; |
| 123 | 123 | } |
| ... | ... | @@ -165,7 +165,7 @@ fn emitRaw(allocator: *Allocator, elf_path: []const u8, raw_path: []const u8) !v |
| 165 | 165 | var binary_elf_output = try BinaryElfOutput.parse(allocator, elf_file); |
| 166 | 166 | defer binary_elf_output.deinit(); |
| 167 | 167 | |
| 168 | for (binary_elf_output.sections.toSlice()) |section| { | |
| 168 | for (binary_elf_output.sections.span()) |section| { | |
| 169 | 169 | try writeBinaryElfSection(elf_file, out_file, section); |
| 170 | 170 | } |
| 171 | 171 | } |
lib/std/build/run.zig+3-3| ... | ... | @@ -139,7 +139,7 @@ pub const RunStep = struct { |
| 139 | 139 | const cwd = if (self.cwd) |cwd| self.builder.pathFromRoot(cwd) else self.builder.build_root; |
| 140 | 140 | |
| 141 | 141 | var argv_list = ArrayList([]const u8).init(self.builder.allocator); |
| 142 | for (self.argv.toSlice()) |arg| { | |
| 142 | for (self.argv.span()) |arg| { | |
| 143 | 143 | switch (arg) { |
| 144 | 144 | Arg.Bytes => |bytes| try argv_list.append(bytes), |
| 145 | 145 | Arg.Artifact => |artifact| { |
| ... | ... | @@ -153,7 +153,7 @@ pub const RunStep = struct { |
| 153 | 153 | } |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | const argv = argv_list.toSliceConst(); | |
| 156 | const argv = argv_list.span(); | |
| 157 | 157 | |
| 158 | 158 | const child = std.ChildProcess.init(argv, self.builder.allocator) catch unreachable; |
| 159 | 159 | defer child.deinit(); |
| ... | ... | @@ -289,7 +289,7 @@ pub const RunStep = struct { |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | fn addPathForDynLibs(self: *RunStep, artifact: *LibExeObjStep) void { |
| 292 | for (artifact.link_objects.toSliceConst()) |link_object| { | |
| 292 | for (artifact.link_objects.span()) |link_object| { | |
| 293 | 293 | switch (link_object) { |
| 294 | 294 | .OtherStep => |other| { |
| 295 | 295 | if (other.target.isWindows() and other.isDynamicLibrary()) { |
lib/std/build/translate_c.zig+1-1| ... | ... | @@ -71,7 +71,7 @@ pub const TranslateCStep = struct { |
| 71 | 71 | |
| 72 | 72 | try argv_list.append(self.source.getPath(self.builder)); |
| 73 | 73 | |
| 74 | const output_path_nl = try self.builder.execFromStep(argv_list.toSliceConst(), &self.step); | |
| 74 | const output_path_nl = try self.builder.execFromStep(argv_list.span(), &self.step); | |
| 75 | 75 | const output_path = mem.trimRight(u8, output_path_nl, "\r\n"); |
| 76 | 76 | |
| 77 | 77 | self.out_basename = fs.path.basename(output_path); |
lib/std/build/write_file.zig+2-2| ... | ... | @@ -59,7 +59,7 @@ pub const WriteFileStep = struct { |
| 59 | 59 | // new random bytes when WriteFileStep implementation is modified |
| 60 | 60 | // in a non-backwards-compatible way. |
| 61 | 61 | hash.update("eagVR1dYXoE7ARDP"); |
| 62 | for (self.files.toSliceConst()) |file| { | |
| 62 | for (self.files.span()) |file| { | |
| 63 | 63 | hash.update(file.basename); |
| 64 | 64 | hash.update(file.bytes); |
| 65 | 65 | hash.update("|"); |
| ... | ... | @@ -80,7 +80,7 @@ pub const WriteFileStep = struct { |
| 80 | 80 | }; |
| 81 | 81 | var dir = try fs.cwd().openDir(self.output_dir, .{}); |
| 82 | 82 | defer dir.close(); |
| 83 | for (self.files.toSliceConst()) |file| { | |
| 83 | for (self.files.span()) |file| { | |
| 84 | 84 | dir.writeFile(file.basename, file.bytes) catch |err| { |
| 85 | 85 | warn("unable to write {} into {}: {}\n", .{ |
| 86 | 86 | file.basename, |
lib/std/c.zig+45-13| ... | ... | @@ -73,7 +73,6 @@ pub extern "c" fn abort() noreturn; |
| 73 | 73 | pub extern "c" fn exit(code: c_int) noreturn; |
| 74 | 74 | pub extern "c" fn isatty(fd: fd_t) c_int; |
| 75 | 75 | pub extern "c" fn close(fd: fd_t) c_int; |
| 76 | pub extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int; | |
| 77 | 76 | pub extern "c" fn fstatat(dirfd: fd_t, path: [*:0]const u8, stat_buf: *Stat, flags: u32) c_int; |
| 78 | 77 | pub extern "c" fn lseek(fd: fd_t, offset: off_t, whence: c_int) off_t; |
| 79 | 78 | pub extern "c" fn open(path: [*:0]const u8, oflag: c_uint, ...) c_int; |
| ... | ... | @@ -86,7 +85,6 @@ pub extern "c" fn pread(fd: fd_t, buf: [*]u8, nbyte: usize, offset: u64) isize; |
| 86 | 85 | pub extern "c" fn preadv(fd: c_int, iov: [*]const iovec, iovcnt: c_uint, offset: u64) isize; |
| 87 | 86 | pub extern "c" fn writev(fd: c_int, iov: [*]const iovec_const, iovcnt: c_uint) isize; |
| 88 | 87 | pub extern "c" fn pwritev(fd: c_int, iov: [*]const iovec_const, iovcnt: c_uint, offset: u64) isize; |
| 89 | pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *Stat) c_int; | |
| 90 | 88 | pub extern "c" fn write(fd: fd_t, buf: [*]const u8, nbyte: usize) isize; |
| 91 | 89 | pub extern "c" fn pwrite(fd: fd_t, buf: [*]const u8, nbyte: usize, offset: u64) isize; |
| 92 | 90 | pub extern "c" fn mmap(addr: ?*align(page_size) c_void, len: usize, prot: c_uint, flags: c_uint, fd: fd_t, offset: u64) *c_void; |
| ... | ... | @@ -114,15 +112,10 @@ pub extern "c" fn dup2(old_fd: fd_t, new_fd: fd_t) c_int; |
| 114 | 112 | pub extern "c" fn readlink(noalias path: [*:0]const u8, noalias buf: [*]u8, bufsize: usize) isize; |
| 115 | 113 | pub extern "c" fn readlinkat(dirfd: fd_t, noalias path: [*:0]const u8, noalias buf: [*]u8, bufsize: usize) isize; |
| 116 | 114 | pub extern "c" fn realpath(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8; |
| 117 | pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int; | |
| 118 | pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int; | |
| 119 | pub extern "c" fn sigaction(sig: c_int, noalias act: *const Sigaction, noalias oact: ?*Sigaction) c_int; | |
| 120 | pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int; | |
| 121 | 115 | pub extern "c" fn setreuid(ruid: c_uint, euid: c_uint) c_int; |
| 122 | 116 | pub extern "c" fn setregid(rgid: c_uint, egid: c_uint) c_int; |
| 123 | 117 | pub extern "c" fn rmdir(path: [*:0]const u8) c_int; |
| 124 | 118 | pub extern "c" fn getenv(name: [*:0]const u8) ?[*:0]u8; |
| 125 | pub extern "c" fn getrusage(who: c_int, usage: *rusage) c_int; | |
| 126 | 119 | pub extern "c" fn sysctl(name: [*]const c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int; |
| 127 | 120 | pub extern "c" fn sysctlbyname(name: [*:0]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int; |
| 128 | 121 | pub extern "c" fn sysctlnametomib(name: [*:0]const u8, mibp: ?*c_int, sizep: ?*usize) c_int; |
| ... | ... | @@ -133,7 +126,6 @@ pub extern "c" fn uname(buf: *utsname) c_int; |
| 133 | 126 | |
| 134 | 127 | pub extern "c" fn gethostname(name: [*]u8, len: usize) c_int; |
| 135 | 128 | pub extern "c" fn bind(socket: fd_t, address: ?*const sockaddr, address_len: socklen_t) c_int; |
| 136 | pub extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int; | |
| 137 | 129 | pub extern "c" fn socketpair(domain: c_uint, sock_type: c_uint, protocol: c_uint, sv: *[2]fd_t) c_int; |
| 138 | 130 | pub extern "c" fn listen(sockfd: fd_t, backlog: c_uint) c_int; |
| 139 | 131 | pub extern "c" fn getsockname(sockfd: fd_t, noalias addr: *sockaddr, noalias addrlen: *socklen_t) c_int; |
| ... | ... | @@ -161,12 +153,55 @@ pub extern fn recvfrom( |
| 161 | 153 | noalias addrlen: ?*socklen_t, |
| 162 | 154 | ) isize; |
| 163 | 155 | |
| 156 | pub usingnamespace switch (builtin.os.tag) { | |
| 157 | .netbsd => struct { | |
| 158 | pub const clock_getres = __clock_getres50; | |
| 159 | pub const clock_gettime = __clock_gettime50; | |
| 160 | pub const fstat = __fstat50; | |
| 161 | pub const getdents = __getdents30; | |
| 162 | pub const getrusage = __getrusage50; | |
| 163 | pub const gettimeofday = __gettimeofday50; | |
| 164 | pub const nanosleep = __nanosleep50; | |
| 165 | pub const sched_yield = __libc_thr_yield; | |
| 166 | pub const sigaction = __sigaction14; | |
| 167 | pub const sigaltstack = __sigaltstack14; | |
| 168 | pub const sigprocmask = __sigprocmask14; | |
| 169 | pub const stat = __stat50; | |
| 170 | }, | |
| 171 | .macosx, .ios, .watchos, .tvos => struct { | |
| 172 | // XXX: close -> close$NOCANCEL | |
| 173 | // XXX: getdirentries -> _getdirentries64 | |
| 174 | pub extern "c" fn clock_getres(clk_id: c_int, tp: *timespec) c_int; | |
| 175 | pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int; | |
| 176 | pub const fstat = @"fstat$INODE64"; | |
| 177 | pub extern "c" fn getrusage(who: c_int, usage: *rusage) c_int; | |
| 178 | pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int; | |
| 179 | pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int; | |
| 180 | pub extern "c" fn sched_yield() c_int; | |
| 181 | pub extern "c" fn sigaction(sig: c_int, noalias act: *const Sigaction, noalias oact: ?*Sigaction) c_int; | |
| 182 | pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int; | |
| 183 | pub extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int; | |
| 184 | pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *Stat) c_int; | |
| 185 | }, | |
| 186 | else => struct { | |
| 187 | pub extern "c" fn clock_getres(clk_id: c_int, tp: *timespec) c_int; | |
| 188 | pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int; | |
| 189 | pub extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int; | |
| 190 | pub extern "c" fn getrusage(who: c_int, usage: *rusage) c_int; | |
| 191 | pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int; | |
| 192 | pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int; | |
| 193 | pub extern "c" fn sched_yield() c_int; | |
| 194 | pub extern "c" fn sigaction(sig: c_int, noalias act: *const Sigaction, noalias oact: ?*Sigaction) c_int; | |
| 195 | pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int; | |
| 196 | pub extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int; | |
| 197 | pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *Stat) c_int; | |
| 198 | }, | |
| 199 | }; | |
| 200 | ||
| 164 | 201 | pub extern "c" fn kill(pid: pid_t, sig: c_int) c_int; |
| 165 | 202 | pub extern "c" fn getdirentries(fd: fd_t, buf_ptr: [*]u8, nbytes: usize, basep: *i64) isize; |
| 166 | 203 | pub extern "c" fn setgid(ruid: c_uint, euid: c_uint) c_int; |
| 167 | 204 | pub extern "c" fn setuid(uid: c_uint) c_int; |
| 168 | pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int; | |
| 169 | pub extern "c" fn clock_getres(clk_id: c_int, tp: *timespec) c_int; | |
| 170 | 205 | |
| 171 | 206 | pub extern "c" fn aligned_alloc(alignment: usize, size: usize) ?*c_void; |
| 172 | 207 | pub extern "c" fn malloc(usize) ?*c_void; |
| ... | ... | @@ -174,7 +209,6 @@ pub extern "c" fn realloc(?*c_void, usize) ?*c_void; |
| 174 | 209 | pub extern "c" fn free(*c_void) void; |
| 175 | 210 | pub extern "c" fn posix_memalign(memptr: **c_void, alignment: usize, size: usize) c_int; |
| 176 | 211 | |
| 177 | // Deprecated | |
| 178 | 212 | pub extern "c" fn futimes(fd: fd_t, times: *[2]timeval) c_int; |
| 179 | 213 | pub extern "c" fn utimes(path: [*:0]const u8, times: *[2]timeval) c_int; |
| 180 | 214 | |
| ... | ... | @@ -230,8 +264,6 @@ pub extern "c" fn dn_expand( |
| 230 | 264 | length: c_int, |
| 231 | 265 | ) c_int; |
| 232 | 266 | |
| 233 | pub extern "c" fn sched_yield() c_int; | |
| 234 | ||
| 235 | 267 | pub const PTHREAD_MUTEX_INITIALIZER = pthread_mutex_t{}; |
| 236 | 268 | pub extern "c" fn pthread_mutex_lock(mutex: *pthread_mutex_t) c_int; |
| 237 | 269 | pub extern "c" fn pthread_mutex_unlock(mutex: *pthread_mutex_t) c_int; |
lib/std/c/netbsd.zig+33-11| ... | ... | @@ -10,36 +10,58 @@ pub const dl_iterate_phdr_callback = extern fn (info: *dl_phdr_info, size: usize |
| 10 | 10 | pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*c_void) c_int; |
| 11 | 11 | |
| 12 | 12 | pub extern "c" fn __fstat50(fd: fd_t, buf: *Stat) c_int; |
| 13 | pub extern "c" fn __stat50(path: [*:0]const u8, buf: *Stat) c_int; | |
| 13 | 14 | pub extern "c" fn __clock_gettime50(clk_id: c_int, tp: *timespec) c_int; |
| 14 | 15 | pub extern "c" fn __clock_getres50(clk_id: c_int, tp: *timespec) c_int; |
| 15 | 16 | pub extern "c" fn __getdents30(fd: c_int, buf_ptr: [*]u8, nbytes: usize) c_int; |
| 16 | 17 | pub extern "c" fn __sigaltstack14(ss: ?*stack_t, old_ss: ?*stack_t) c_int; |
| 18 | pub extern "c" fn __nanosleep50(rqtp: *const timespec, rmtp: ?*timespec) c_int; | |
| 19 | pub extern "c" fn __sigaction14(sig: c_int, noalias act: *const Sigaction, noalias oact: ?*Sigaction) c_int; | |
| 20 | pub extern "c" fn __sigprocmask14(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int; | |
| 21 | pub extern "c" fn __socket30(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int; | |
| 22 | pub extern "c" fn __gettimeofday50(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int; | |
| 23 | pub extern "c" fn __getrusage50(who: c_int, usage: *rusage) c_int; | |
| 24 | // libc aliases this as sched_yield | |
| 25 | pub extern "c" fn __libc_thr_yield() c_int; | |
| 17 | 26 | |
| 18 | 27 | pub const pthread_mutex_t = extern struct { |
| 19 | ptm_magic: c_uint = 0x33330003, | |
| 20 | ptm_errorcheck: padded_spin_t = 0, | |
| 21 | ptm_unused: padded_spin_t = 0, | |
| 28 | ptm_magic: u32 = 0x33330003, | |
| 29 | ptm_errorcheck: padded_pthread_spin_t = 0, | |
| 30 | ptm_ceiling: padded_pthread_spin_t = 0, | |
| 22 | 31 | ptm_owner: usize = 0, |
| 23 | 32 | ptm_waiters: ?*u8 = null, |
| 24 | ptm_recursed: c_uint = 0, | |
| 33 | ptm_recursed: u32 = 0, | |
| 25 | 34 | ptm_spare2: ?*c_void = null, |
| 26 | 35 | }; |
| 36 | ||
| 27 | 37 | pub const pthread_cond_t = extern struct { |
| 28 | ptc_magic: c_uint = 0x55550005, | |
| 38 | ptc_magic: u32 = 0x55550005, | |
| 29 | 39 | ptc_lock: pthread_spin_t = 0, |
| 30 | 40 | ptc_waiters_first: ?*u8 = null, |
| 31 | 41 | ptc_waiters_last: ?*u8 = null, |
| 32 | 42 | ptc_mutex: ?*pthread_mutex_t = null, |
| 33 | 43 | ptc_private: ?*c_void = null, |
| 34 | 44 | }; |
| 35 | const pthread_spin_t = if (builtin.arch == .arm or .arch == .powerpc) c_int else u8; | |
| 36 | const padded_spin_t = switch (builtin.arch) { | |
| 37 | .sparc, .sparcel, .sparcv9, .i386, .x86_64, .le64 => u32, | |
| 38 | else => spin_t, | |
| 45 | ||
| 46 | const pthread_spin_t = switch (builtin.arch) { | |
| 47 | .aarch64, .aarch64_be, .aarch64_32 => u8, | |
| 48 | .mips, .mipsel, .mips64, .mips64el => u32, | |
| 49 | .powerpc, .powerpc64, .powerpc64le => i32, | |
| 50 | .i386, .x86_64 => u8, | |
| 51 | .arm, .armeb, .thumb, .thumbeb => i32, | |
| 52 | .sparc, .sparcel, .sparcv9 => u8, | |
| 53 | .riscv32, .riscv64 => u32, | |
| 54 | else => @compileError("undefined pthread_spin_t for this arch"), | |
| 55 | }; | |
| 56 | ||
| 57 | const padded_pthread_spin_t = switch (builtin.arch) { | |
| 58 | .i386, .x86_64 => u32, | |
| 59 | .sparc, .sparcel, .sparcv9 => u32, | |
| 60 | else => pthread_spin_t, | |
| 39 | 61 | }; |
| 40 | 62 | |
| 41 | 63 | pub const pthread_attr_t = extern struct { |
| 42 | 64 | pta_magic: u32, |
| 43 | pta_flags: c_int, | |
| 44 | pta_private: *c_void, | |
| 65 | pta_flags: i32, | |
| 66 | pta_private: ?*c_void, | |
| 45 | 67 | }; |
lib/std/child_process.zig+13-33| ... | ... | @@ -10,7 +10,7 @@ const windows = os.windows; |
| 10 | 10 | const mem = std.mem; |
| 11 | 11 | const debug = std.debug; |
| 12 | 12 | const BufMap = std.BufMap; |
| 13 | const Buffer = std.Buffer; | |
| 13 | const ArrayListSentineled = std.ArrayListSentineled; | |
| 14 | 14 | const builtin = @import("builtin"); |
| 15 | 15 | const Os = builtin.Os; |
| 16 | 16 | const TailQueue = std.TailQueue; |
| ... | ... | @@ -175,29 +175,11 @@ pub const ChildProcess = struct { |
| 175 | 175 | stderr: []u8, |
| 176 | 176 | }; |
| 177 | 177 | |
| 178 | /// Spawns a child process, waits for it, collecting stdout and stderr, and then returns. | |
| 179 | /// If it succeeds, the caller owns result.stdout and result.stderr memory. | |
| 180 | /// TODO deprecate in favor of exec2 | |
| 181 | pub fn exec( | |
| 182 | allocator: *mem.Allocator, | |
| 183 | argv: []const []const u8, | |
| 184 | cwd: ?[]const u8, | |
| 185 | env_map: ?*const BufMap, | |
| 186 | max_output_bytes: usize, | |
| 187 | ) !ExecResult { | |
| 188 | return exec2(.{ | |
| 189 | .allocator = allocator, | |
| 190 | .argv = argv, | |
| 191 | .cwd = cwd, | |
| 192 | .env_map = env_map, | |
| 193 | .max_output_bytes = max_output_bytes, | |
| 194 | }); | |
| 195 | } | |
| 178 | pub const exec2 = @compileError("deprecated: exec2 is renamed to exec"); | |
| 196 | 179 | |
| 197 | 180 | /// Spawns a child process, waits for it, collecting stdout and stderr, and then returns. |
| 198 | 181 | /// If it succeeds, the caller owns result.stdout and result.stderr memory. |
| 199 | /// TODO rename to exec | |
| 200 | pub fn exec2(args: struct { | |
| 182 | pub fn exec(args: struct { | |
| 201 | 183 | allocator: *mem.Allocator, |
| 202 | 184 | argv: []const []const u8, |
| 203 | 185 | cwd: ?[]const u8 = null, |
| ... | ... | @@ -370,7 +352,7 @@ pub const ChildProcess = struct { |
| 370 | 352 | |
| 371 | 353 | const any_ignore = (self.stdin_behavior == StdIo.Ignore or self.stdout_behavior == StdIo.Ignore or self.stderr_behavior == StdIo.Ignore); |
| 372 | 354 | const dev_null_fd = if (any_ignore) |
| 373 | os.openC("/dev/null", os.O_RDWR, 0) catch |err| switch (err) { | |
| 355 | os.openZ("/dev/null", os.O_RDWR, 0) catch |err| switch (err) { | |
| 374 | 356 | error.PathAlreadyExists => unreachable, |
| 375 | 357 | error.NoSpaceLeft => unreachable, |
| 376 | 358 | error.FileTooBig => unreachable, |
| ... | ... | @@ -775,38 +757,36 @@ fn windowsCreateProcess(app_name: [*:0]u16, cmd_line: [*:0]u16, envp_ptr: ?[*]u1 |
| 775 | 757 | } |
| 776 | 758 | |
| 777 | 759 | /// Caller must dealloc. |
| 778 | /// Guarantees a null byte at result[result.len]. | |
| 779 | fn windowsCreateCommandLine(allocator: *mem.Allocator, argv: []const []const u8) ![]u8 { | |
| 780 | var buf = try Buffer.initSize(allocator, 0); | |
| 760 | fn windowsCreateCommandLine(allocator: *mem.Allocator, argv: []const []const u8) ![:0]u8 { | |
| 761 | var buf = try ArrayListSentineled(u8, 0).initSize(allocator, 0); | |
| 781 | 762 | defer buf.deinit(); |
| 782 | ||
| 783 | var buf_stream = buf.outStream(); | |
| 763 | const buf_stream = buf.outStream(); | |
| 784 | 764 | |
| 785 | 765 | for (argv) |arg, arg_i| { |
| 786 | if (arg_i != 0) try buf.appendByte(' '); | |
| 766 | if (arg_i != 0) try buf_stream.writeByte(' '); | |
| 787 | 767 | if (mem.indexOfAny(u8, arg, " \t\n\"") == null) { |
| 788 | try buf.append(arg); | |
| 768 | try buf_stream.writeAll(arg); | |
| 789 | 769 | continue; |
| 790 | 770 | } |
| 791 | try buf.appendByte('"'); | |
| 771 | try buf_stream.writeByte('"'); | |
| 792 | 772 | var backslash_count: usize = 0; |
| 793 | 773 | for (arg) |byte| { |
| 794 | 774 | switch (byte) { |
| 795 | 775 | '\\' => backslash_count += 1, |
| 796 | 776 | '"' => { |
| 797 | 777 | try buf_stream.writeByteNTimes('\\', backslash_count * 2 + 1); |
| 798 | try buf.appendByte('"'); | |
| 778 | try buf_stream.writeByte('"'); | |
| 799 | 779 | backslash_count = 0; |
| 800 | 780 | }, |
| 801 | 781 | else => { |
| 802 | 782 | try buf_stream.writeByteNTimes('\\', backslash_count); |
| 803 | try buf.appendByte(byte); | |
| 783 | try buf_stream.writeByte(byte); | |
| 804 | 784 | backslash_count = 0; |
| 805 | 785 | }, |
| 806 | 786 | } |
| 807 | 787 | } |
| 808 | 788 | try buf_stream.writeByteNTimes('\\', backslash_count * 2); |
| 809 | try buf.appendByte('"'); | |
| 789 | try buf_stream.writeByte('"'); | |
| 810 | 790 | } |
| 811 | 791 | |
| 812 | 792 | return buf.toOwnedSlice(); |
lib/std/coff.zig+2-2| ... | ... | @@ -145,7 +145,7 @@ pub const Coff = struct { |
| 145 | 145 | blk: while (i < debug_dir_entry_count) : (i += 1) { |
| 146 | 146 | const debug_dir_entry = try in.readStruct(DebugDirectoryEntry); |
| 147 | 147 | if (debug_dir_entry.type == IMAGE_DEBUG_TYPE_CODEVIEW) { |
| 148 | for (self.sections.toSlice()) |*section| { | |
| 148 | for (self.sections.span()) |*section| { | |
| 149 | 149 | const section_start = section.header.virtual_address; |
| 150 | 150 | const section_size = section.header.misc.virtual_size; |
| 151 | 151 | const rva = debug_dir_entry.address_of_raw_data; |
| ... | ... | @@ -211,7 +211,7 @@ pub const Coff = struct { |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | pub fn getSection(self: *Coff, comptime name: []const u8) ?*Section { |
| 214 | for (self.sections.toSlice()) |*sec| { | |
| 214 | for (self.sections.span()) |*sec| { | |
| 215 | 215 | if (mem.eql(u8, sec.header.name[0..name.len], name)) { |
| 216 | 216 | return sec; |
| 217 | 217 | } |
lib/std/crypto/gimli.zig+2| ... | ... | @@ -23,10 +23,12 @@ pub const State = struct { |
| 23 | 23 | |
| 24 | 24 | const Self = @This(); |
| 25 | 25 | |
| 26 | /// TODO follow the span() convention instead of having this and `toSliceConst` | |
| 26 | 27 | pub fn toSlice(self: *Self) []u8 { |
| 27 | 28 | return mem.sliceAsBytes(self.data[0..]); |
| 28 | 29 | } |
| 29 | 30 | |
| 31 | /// TODO follow the span() convention instead of having this and `toSlice` | |
| 30 | 32 | pub fn toSliceConst(self: *Self) []const u8 { |
| 31 | 33 | return mem.sliceAsBytes(self.data[0..]); |
| 32 | 34 | } |
lib/std/debug.zig+17-12| ... | ... | @@ -735,7 +735,7 @@ fn openCoffDebugInfo(allocator: *mem.Allocator, coff_file_path: [:0]const u16) ! |
| 735 | 735 | for (present) |_| { |
| 736 | 736 | const name_offset = try pdb_stream.inStream().readIntLittle(u32); |
| 737 | 737 | const name_index = try pdb_stream.inStream().readIntLittle(u32); |
| 738 | const name = mem.toSlice(u8, @ptrCast([*:0]u8, name_bytes.ptr + name_offset)); | |
| 738 | const name = mem.spanZ(@ptrCast([*:0]u8, name_bytes.ptr + name_offset)); | |
| 739 | 739 | if (mem.eql(u8, name, "/names")) { |
| 740 | 740 | break :str_tab_index name_index; |
| 741 | 741 | } |
| ... | ... | @@ -1131,7 +1131,7 @@ pub const DebugInfo = struct { |
| 1131 | 1131 | const obj_di = try self.allocator.create(ModuleDebugInfo); |
| 1132 | 1132 | errdefer self.allocator.destroy(obj_di); |
| 1133 | 1133 | |
| 1134 | const macho_path = mem.toSliceConst(u8, std.c._dyld_get_image_name(i)); | |
| 1134 | const macho_path = mem.spanZ(std.c._dyld_get_image_name(i)); | |
| 1135 | 1135 | obj_di.* = openMachODebugInfo(self.allocator, macho_path) catch |err| switch (err) { |
| 1136 | 1136 | error.FileNotFound => return error.MissingDebugInfo, |
| 1137 | 1137 | else => return err, |
| ... | ... | @@ -1254,10 +1254,7 @@ pub const DebugInfo = struct { |
| 1254 | 1254 | if (context.address >= seg_start and context.address < seg_end) { |
| 1255 | 1255 | // Android libc uses NULL instead of an empty string to mark the |
| 1256 | 1256 | // main program |
| 1257 | context.name = if (info.dlpi_name) |dlpi_name| | |
| 1258 | mem.toSliceConst(u8, dlpi_name) | |
| 1259 | else | |
| 1260 | ""; | |
| 1257 | context.name = mem.spanZ(info.dlpi_name) orelse ""; | |
| 1261 | 1258 | context.base_address = info.dlpi_addr; |
| 1262 | 1259 | // Stop the iteration |
| 1263 | 1260 | return error.Found; |
| ... | ... | @@ -1426,7 +1423,7 @@ pub const ModuleDebugInfo = switch (builtin.os.tag) { |
| 1426 | 1423 | return SymbolInfo{}; |
| 1427 | 1424 | |
| 1428 | 1425 | assert(symbol.ofile.?.n_strx < self.strings.len); |
| 1429 | const o_file_path = mem.toSliceConst(u8, self.strings.ptr + symbol.ofile.?.n_strx); | |
| 1426 | const o_file_path = mem.spanZ(self.strings.ptr + symbol.ofile.?.n_strx); | |
| 1430 | 1427 | |
| 1431 | 1428 | // Check if its debug infos are already in the cache |
| 1432 | 1429 | var o_file_di = self.ofiles.getValue(o_file_path) orelse |
| ... | ... | @@ -1483,7 +1480,7 @@ pub const ModuleDebugInfo = switch (builtin.os.tag) { |
| 1483 | 1480 | const mod_index = for (self.sect_contribs) |sect_contrib| { |
| 1484 | 1481 | if (sect_contrib.Section > self.coff.sections.len) continue; |
| 1485 | 1482 | // Remember that SectionContribEntry.Section is 1-based. |
| 1486 | coff_section = &self.coff.sections.toSlice()[sect_contrib.Section - 1]; | |
| 1483 | coff_section = &self.coff.sections.span()[sect_contrib.Section - 1]; | |
| 1487 | 1484 | |
| 1488 | 1485 | const vaddr_start = coff_section.header.virtual_address + sect_contrib.Offset; |
| 1489 | 1486 | const vaddr_end = vaddr_start + sect_contrib.Size; |
| ... | ... | @@ -1510,7 +1507,7 @@ pub const ModuleDebugInfo = switch (builtin.os.tag) { |
| 1510 | 1507 | const vaddr_start = coff_section.header.virtual_address + proc_sym.CodeOffset; |
| 1511 | 1508 | const vaddr_end = vaddr_start + proc_sym.CodeSize; |
| 1512 | 1509 | if (relocated_address >= vaddr_start and relocated_address < vaddr_end) { |
| 1513 | break mem.toSliceConst(u8, @ptrCast([*:0]u8, proc_sym) + @sizeOf(pdb.ProcSym)); | |
| 1510 | break mem.spanZ(@ptrCast([*:0]u8, proc_sym) + @sizeOf(pdb.ProcSym)); | |
| 1514 | 1511 | } |
| 1515 | 1512 | }, |
| 1516 | 1513 | else => {}, |
| ... | ... | @@ -1669,7 +1666,11 @@ fn getDebugInfoAllocator() *mem.Allocator { |
| 1669 | 1666 | } |
| 1670 | 1667 | |
| 1671 | 1668 | /// Whether or not the current target can print useful debug information when a segfault occurs. |
| 1672 | pub const have_segfault_handling_support = builtin.os.tag == .linux or builtin.os.tag == .windows; | |
| 1669 | pub const have_segfault_handling_support = switch (builtin.os.tag) { | |
| 1670 | .linux, .netbsd => true, | |
| 1671 | .windows => true, | |
| 1672 | else => false, | |
| 1673 | }; | |
| 1673 | 1674 | pub const enable_segfault_handler: bool = if (@hasDecl(root, "enable_segfault_handler")) |
| 1674 | 1675 | root.enable_segfault_handler |
| 1675 | 1676 | else |
| ... | ... | @@ -1721,13 +1722,17 @@ fn resetSegfaultHandler() void { |
| 1721 | 1722 | os.sigaction(os.SIGBUS, &act, null); |
| 1722 | 1723 | } |
| 1723 | 1724 | |
| 1724 | fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: *const c_void) callconv(.C) noreturn { | |
| 1725 | fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const c_void) callconv(.C) noreturn { | |
| 1725 | 1726 | // Reset to the default handler so that if a segfault happens in this handler it will crash |
| 1726 | 1727 | // the process. Also when this handler returns, the original instruction will be repeated |
| 1727 | 1728 | // and the resulting segfault will crash the process rather than continually dump stack traces. |
| 1728 | 1729 | resetSegfaultHandler(); |
| 1729 | 1730 | |
| 1730 | const addr = @ptrToInt(info.fields.sigfault.addr); | |
| 1731 | const addr = switch (builtin.os.tag) { | |
| 1732 | .linux => @ptrToInt(info.fields.sigfault.addr), | |
| 1733 | .netbsd => @ptrToInt(info.info.reason.fault.addr), | |
| 1734 | else => unreachable, | |
| 1735 | }; | |
| 1731 | 1736 | switch (sig) { |
| 1732 | 1737 | os.SIGSEGV => std.debug.warn("Segmentation fault at address 0x{x}\n", .{addr}), |
| 1733 | 1738 | os.SIGILL => std.debug.warn("Illegal instruction at address 0x{x}\n", .{addr}), |
lib/std/dwarf.zig+7-7| ... | ... | @@ -82,7 +82,7 @@ const Die = struct { |
| 82 | 82 | }; |
| 83 | 83 | |
| 84 | 84 | fn getAttr(self: *const Die, id: u64) ?*const FormValue { |
| 85 | for (self.attrs.toSliceConst()) |*attr| { | |
| 85 | for (self.attrs.span()) |*attr| { | |
| 86 | 86 | if (attr.id == id) return &attr.value; |
| 87 | 87 | } |
| 88 | 88 | return null; |
| ... | ... | @@ -375,7 +375,7 @@ fn parseFormValue(allocator: *mem.Allocator, in_stream: var, form_id: u64, is_64 |
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | fn getAbbrevTableEntry(abbrev_table: *const AbbrevTable, abbrev_code: u64) ?*const AbbrevTableEntry { |
| 378 | for (abbrev_table.toSliceConst()) |*table_entry| { | |
| 378 | for (abbrev_table.span()) |*table_entry| { | |
| 379 | 379 | if (table_entry.abbrev_code == abbrev_code) return table_entry; |
| 380 | 380 | } |
| 381 | 381 | return null; |
| ... | ... | @@ -399,7 +399,7 @@ pub const DwarfInfo = struct { |
| 399 | 399 | } |
| 400 | 400 | |
| 401 | 401 | fn getSymbolName(di: *DwarfInfo, address: u64) ?[]const u8 { |
| 402 | for (di.func_list.toSliceConst()) |*func| { | |
| 402 | for (di.func_list.span()) |*func| { | |
| 403 | 403 | if (func.pc_range) |range| { |
| 404 | 404 | if (address >= range.start and address < range.end) { |
| 405 | 405 | return func.name; |
| ... | ... | @@ -588,7 +588,7 @@ pub const DwarfInfo = struct { |
| 588 | 588 | } |
| 589 | 589 | |
| 590 | 590 | fn findCompileUnit(di: *DwarfInfo, target_address: u64) !*const CompileUnit { |
| 591 | for (di.compile_unit_list.toSlice()) |*compile_unit| { | |
| 591 | for (di.compile_unit_list.span()) |*compile_unit| { | |
| 592 | 592 | if (compile_unit.pc_range) |range| { |
| 593 | 593 | if (target_address >= range.start and target_address < range.end) return compile_unit; |
| 594 | 594 | } |
| ... | ... | @@ -636,7 +636,7 @@ pub const DwarfInfo = struct { |
| 636 | 636 | /// Gets an already existing AbbrevTable given the abbrev_offset, or if not found, |
| 637 | 637 | /// seeks in the stream and parses it. |
| 638 | 638 | fn getAbbrevTable(di: *DwarfInfo, abbrev_offset: u64) !*const AbbrevTable { |
| 639 | for (di.abbrev_table_list.toSlice()) |*header| { | |
| 639 | for (di.abbrev_table_list.span()) |*header| { | |
| 640 | 640 | if (header.offset == abbrev_offset) { |
| 641 | 641 | return &header.table; |
| 642 | 642 | } |
| ... | ... | @@ -690,7 +690,7 @@ pub const DwarfInfo = struct { |
| 690 | 690 | .attrs = ArrayList(Die.Attr).init(di.allocator()), |
| 691 | 691 | }; |
| 692 | 692 | try result.attrs.resize(table_entry.attrs.len); |
| 693 | for (table_entry.attrs.toSliceConst()) |attr, i| { | |
| 693 | for (table_entry.attrs.span()) |attr, i| { | |
| 694 | 694 | result.attrs.items[i] = Die.Attr{ |
| 695 | 695 | .id = attr.attr_id, |
| 696 | 696 | .value = try parseFormValue(di.allocator(), in_stream, attr.form_id, is_64), |
| ... | ... | @@ -757,7 +757,7 @@ pub const DwarfInfo = struct { |
| 757 | 757 | } |
| 758 | 758 | |
| 759 | 759 | var file_entries = ArrayList(FileEntry).init(di.allocator()); |
| 760 | var prog = LineNumberProgram.init(default_is_stmt, include_directories.toSliceConst(), &file_entries, target_address); | |
| 760 | var prog = LineNumberProgram.init(default_is_stmt, include_directories.span(), &file_entries, target_address); | |
| 761 | 761 | |
| 762 | 762 | while (true) { |
| 763 | 763 | const file_name = try in.readUntilDelimiterAlloc(di.allocator(), 0, math.maxInt(usize)); |
lib/std/dynamic_library.zig+13-7| ... | ... | @@ -254,9 +254,11 @@ pub const ElfDynLib = struct { |
| 254 | 254 | }; |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | pub const openC = @compileError("deprecated: renamed to openZ"); | |
| 258 | ||
| 257 | 259 | /// Trusts the file. Malicious file will be able to execute arbitrary code. |
| 258 | pub fn openC(path_c: [*:0]const u8) !ElfDynLib { | |
| 259 | return open(mem.toSlice(u8, path_c)); | |
| 260 | pub fn openZ(path_c: [*:0]const u8) !ElfDynLib { | |
| 261 | return open(mem.spanZ(path_c)); | |
| 260 | 262 | } |
| 261 | 263 | |
| 262 | 264 | /// Trusts the file |
| ... | ... | @@ -285,7 +287,7 @@ pub const ElfDynLib = struct { |
| 285 | 287 | if (0 == (@as(u32, 1) << @intCast(u5, self.syms[i].st_info & 0xf) & OK_TYPES)) continue; |
| 286 | 288 | if (0 == (@as(u32, 1) << @intCast(u5, self.syms[i].st_info >> 4) & OK_BINDS)) continue; |
| 287 | 289 | if (0 == self.syms[i].st_shndx) continue; |
| 288 | if (!mem.eql(u8, name, mem.toSliceConst(u8, self.strings + self.syms[i].st_name))) continue; | |
| 290 | if (!mem.eql(u8, name, mem.spanZ(self.strings + self.syms[i].st_name))) continue; | |
| 289 | 291 | if (maybe_versym) |versym| { |
| 290 | 292 | if (!checkver(self.verdef.?, versym[i], vername, self.strings)) |
| 291 | 293 | continue; |
| ... | ... | @@ -316,7 +318,7 @@ fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [ |
| 316 | 318 | def = @intToPtr(*elf.Verdef, @ptrToInt(def) + def.vd_next); |
| 317 | 319 | } |
| 318 | 320 | const aux = @intToPtr(*elf.Verdaux, @ptrToInt(def) + def.vd_aux); |
| 319 | return mem.eql(u8, vername, mem.toSliceConst(u8, strings + aux.vda_name)); | |
| 321 | return mem.eql(u8, vername, mem.spanZ(strings + aux.vda_name)); | |
| 320 | 322 | } |
| 321 | 323 | |
| 322 | 324 | pub const WindowsDynLib = struct { |
| ... | ... | @@ -329,7 +331,9 @@ pub const WindowsDynLib = struct { |
| 329 | 331 | return openW(&path_w); |
| 330 | 332 | } |
| 331 | 333 | |
| 332 | pub fn openC(path_c: [*:0]const u8) !WindowsDynLib { | |
| 334 | pub const openC = @compileError("deprecated: renamed to openZ"); | |
| 335 | ||
| 336 | pub fn openZ(path_c: [*:0]const u8) !WindowsDynLib { | |
| 333 | 337 | const path_w = try windows.cStrToPrefixedFileW(path_c); |
| 334 | 338 | return openW(&path_w); |
| 335 | 339 | } |
| ... | ... | @@ -362,10 +366,12 @@ pub const DlDynlib = struct { |
| 362 | 366 | |
| 363 | 367 | pub fn open(path: []const u8) !DlDynlib { |
| 364 | 368 | const path_c = try os.toPosixPath(path); |
| 365 | return openC(&path_c); | |
| 369 | return openZ(&path_c); | |
| 366 | 370 | } |
| 367 | 371 | |
| 368 | pub fn openC(path_c: [*:0]const u8) !DlDynlib { | |
| 372 | pub const openC = @compileError("deprecated: renamed to openZ"); | |
| 373 | ||
| 374 | pub fn openZ(path_c: [*:0]const u8) !DlDynlib { | |
| 369 | 375 | return DlDynlib{ |
| 370 | 376 | .handle = system.dlopen(path_c, system.RTLD_LAZY) orelse { |
| 371 | 377 | return error.FileNotFound; |
lib/std/event/loop.zig+2-2| ... | ... | @@ -1096,10 +1096,10 @@ pub const Loop = struct { |
| 1096 | 1096 | msg.result = noasync os.preadv(msg.fd, msg.iov, msg.offset); |
| 1097 | 1097 | }, |
| 1098 | 1098 | .open => |*msg| { |
| 1099 | msg.result = noasync os.openC(msg.path, msg.flags, msg.mode); | |
| 1099 | msg.result = noasync os.openZ(msg.path, msg.flags, msg.mode); | |
| 1100 | 1100 | }, |
| 1101 | 1101 | .openat => |*msg| { |
| 1102 | msg.result = noasync os.openatC(msg.fd, msg.path, msg.flags, msg.mode); | |
| 1102 | msg.result = noasync os.openatZ(msg.fd, msg.path, msg.flags, msg.mode); | |
| 1103 | 1103 | }, |
| 1104 | 1104 | .faccessat => |*msg| { |
| 1105 | 1105 | msg.result = noasync os.faccessatZ(msg.dirfd, msg.path, msg.mode, msg.flags); |
lib/std/fifo.zig+50-25| ... | ... | @@ -160,7 +160,7 @@ pub fn LinearFifo( |
| 160 | 160 | return self.readableSliceMut(offset); |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | /// Discard first `count` bytes of readable data | |
| 163 | /// Discard first `count` items in the fifo | |
| 164 | 164 | pub fn discard(self: *Self, count: usize) void { |
| 165 | 165 | assert(count <= self.count); |
| 166 | 166 | { // set old range to undefined. Note: may be wrapped around |
| ... | ... | @@ -199,7 +199,7 @@ pub fn LinearFifo( |
| 199 | 199 | return c; |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | /// Read data from the fifo into `dst`, returns number of bytes copied. | |
| 202 | /// Read data from the fifo into `dst`, returns number of items copied. | |
| 203 | 203 | pub fn read(self: *Self, dst: []T) usize { |
| 204 | 204 | var dst_left = dst; |
| 205 | 205 | |
| ... | ... | @@ -215,7 +215,17 @@ pub fn LinearFifo( |
| 215 | 215 | return dst.len - dst_left.len; |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | /// Returns number of bytes available in fifo | |
| 218 | /// Same as `read` except it returns an error union | |
| 219 | /// The purpose of this function existing is to match `std.io.InStream` API. | |
| 220 | fn readFn(self: *Self, dest: []u8) error{}!usize { | |
| 221 | return self.read(dest); | |
| 222 | } | |
| 223 | ||
| 224 | pub fn inStream(self: *Self) std.io.InStream(*Self, error{}, readFn) { | |
| 225 | return .{ .context = self }; | |
| 226 | } | |
| 227 | ||
| 228 | /// Returns number of items available in fifo | |
| 219 | 229 | pub fn writableLength(self: Self) usize { |
| 220 | 230 | return self.buf.len - self.count; |
| 221 | 231 | } |
| ... | ... | @@ -233,9 +243,9 @@ pub fn LinearFifo( |
| 233 | 243 | } |
| 234 | 244 | } |
| 235 | 245 | |
| 236 | /// Returns a writable buffer of at least `size` bytes, allocating memory as needed. | |
| 246 | /// Returns a writable buffer of at least `size` items, allocating memory as needed. | |
| 237 | 247 | /// Use `fifo.update` once you've written data to it. |
| 238 | pub fn writeableWithSize(self: *Self, size: usize) ![]T { | |
| 248 | pub fn writableWithSize(self: *Self, size: usize) ![]T { | |
| 239 | 249 | try self.ensureUnusedCapacity(size); |
| 240 | 250 | |
| 241 | 251 | // try to avoid realigning buffer |
| ... | ... | @@ -247,7 +257,7 @@ pub fn LinearFifo( |
| 247 | 257 | return slice; |
| 248 | 258 | } |
| 249 | 259 | |
| 250 | /// Update the tail location of the buffer (usually follows use of writable/writeableWithSize) | |
| 260 | /// Update the tail location of the buffer (usually follows use of writable/writableWithSize) | |
| 251 | 261 | pub fn update(self: *Self, count: usize) void { |
| 252 | 262 | assert(self.count + count <= self.buf.len); |
| 253 | 263 | self.count += count; |
| ... | ... | @@ -279,7 +289,7 @@ pub fn LinearFifo( |
| 279 | 289 | } else { |
| 280 | 290 | tail %= self.buf.len; |
| 281 | 291 | } |
| 282 | self.buf[tail] = byte; | |
| 292 | self.buf[tail] = item; | |
| 283 | 293 | self.update(1); |
| 284 | 294 | } |
| 285 | 295 | |
| ... | ... | @@ -291,24 +301,16 @@ pub fn LinearFifo( |
| 291 | 301 | return self.writeAssumeCapacity(src); |
| 292 | 302 | } |
| 293 | 303 | |
| 294 | pub usingnamespace if (T == u8) | |
| 295 | struct { | |
| 296 | const OutStream = std.io.OutStream(*Self, Error, appendWrite); | |
| 297 | const Error = error{OutOfMemory}; | |
| 298 | ||
| 299 | /// Same as `write` except it returns the number of bytes written, which is always the same | |
| 300 | /// as `bytes.len`. The purpose of this function existing is to match `std.io.OutStream` API. | |
| 301 | pub fn appendWrite(fifo: *Self, bytes: []const u8) Error!usize { | |
| 302 | try fifo.write(bytes); | |
| 303 | return bytes.len; | |
| 304 | } | |
| 304 | /// Same as `write` except it returns the number of bytes written, which is always the same | |
| 305 | /// as `bytes.len`. The purpose of this function existing is to match `std.io.OutStream` API. | |
| 306 | fn appendWrite(self: *Self, bytes: []const u8) error{OutOfMemory}!usize { | |
| 307 | try self.write(bytes); | |
| 308 | return bytes.len; | |
| 309 | } | |
| 305 | 310 | |
| 306 | pub fn outStream(self: *Self) OutStream { | |
| 307 | return .{ .context = self }; | |
| 308 | } | |
| 309 | } | |
| 310 | else | |
| 311 | struct {}; | |
| 311 | pub fn outStream(self: *Self) std.io.OutStream(*Self, error{OutOfMemory}, appendWrite) { | |
| 312 | return .{ .context = self }; | |
| 313 | } | |
| 312 | 314 | |
| 313 | 315 | /// Make `count` items available before the current read location |
| 314 | 316 | fn rewind(self: *Self, count: usize) void { |
| ... | ... | @@ -395,7 +397,7 @@ test "LinearFifo(u8, .Dynamic)" { |
| 395 | 397 | } |
| 396 | 398 | |
| 397 | 399 | { |
| 398 | const buf = try fifo.writeableWithSize(12); | |
| 400 | const buf = try fifo.writableWithSize(12); | |
| 399 | 401 | testing.expectEqual(@as(usize, 12), buf.len); |
| 400 | 402 | var i: u8 = 0; |
| 401 | 403 | while (i < 10) : (i += 1) { |
| ... | ... | @@ -422,6 +424,15 @@ test "LinearFifo(u8, .Dynamic)" { |
| 422 | 424 | testing.expectEqualSlices(u8, "Hello, World!", result[0..fifo.read(&result)]); |
| 423 | 425 | testing.expectEqual(@as(usize, 0), fifo.readableLength()); |
| 424 | 426 | } |
| 427 | ||
| 428 | { | |
| 429 | try fifo.outStream().writeAll("This is a test"); | |
| 430 | var result: [30]u8 = undefined; | |
| 431 | testing.expectEqualSlices(u8, "This", (try fifo.inStream().readUntilDelimiterOrEof(&result, ' ')).?); | |
| 432 | testing.expectEqualSlices(u8, "is", (try fifo.inStream().readUntilDelimiterOrEof(&result, ' ')).?); | |
| 433 | testing.expectEqualSlices(u8, "a", (try fifo.inStream().readUntilDelimiterOrEof(&result, ' ')).?); | |
| 434 | testing.expectEqualSlices(u8, "test", (try fifo.inStream().readUntilDelimiterOrEof(&result, ' ')).?); | |
| 435 | } | |
| 425 | 436 | } |
| 426 | 437 | |
| 427 | 438 | test "LinearFifo" { |
| ... | ... | @@ -445,6 +456,20 @@ test "LinearFifo" { |
| 445 | 456 | testing.expectEqual(@as(T, 1), try fifo.readItem()); |
| 446 | 457 | testing.expectEqual(@as(T, 0), try fifo.readItem()); |
| 447 | 458 | testing.expectEqual(@as(T, 1), try fifo.readItem()); |
| 459 | testing.expectEqual(@as(usize, 0), fifo.readableLength()); | |
| 460 | } | |
| 461 | ||
| 462 | { | |
| 463 | try fifo.writeItem(1); | |
| 464 | try fifo.writeItem(1); | |
| 465 | try fifo.writeItem(1); | |
| 466 | testing.expectEqual(@as(usize, 3), fifo.readableLength()); | |
| 467 | } | |
| 468 | ||
| 469 | { | |
| 470 | var readBuf: [3]T = undefined; | |
| 471 | const n = fifo.read(&readBuf); | |
| 472 | testing.expectEqual(@as(usize, 3), n); // NOTE: It should be the number of items. | |
| 448 | 473 | } |
| 449 | 474 | } |
| 450 | 475 | } |
lib/std/fmt/parse_float.zig+51-71| ... | ... | @@ -30,6 +30,7 @@ |
| 30 | 30 | // - Does not handle denormals |
| 31 | 31 | |
| 32 | 32 | const std = @import("../std.zig"); |
| 33 | const ascii = std.ascii; | |
| 33 | 34 | |
| 34 | 35 | const max_digits = 25; |
| 35 | 36 | |
| ... | ... | @@ -190,14 +191,6 @@ const ParseResult = enum { |
| 190 | 191 | MinusInf, |
| 191 | 192 | }; |
| 192 | 193 | |
| 193 | inline fn isDigit(c: u8) bool { | |
| 194 | return c >= '0' and c <= '9'; | |
| 195 | } | |
| 196 | ||
| 197 | inline fn isSpace(c: u8) bool { | |
| 198 | return (c >= 0x09 and c <= 0x13) or c == 0x20; | |
| 199 | } | |
| 200 | ||
| 201 | 194 | fn parseRepr(s: []const u8, n: *FloatRepr) !ParseResult { |
| 202 | 195 | var digit_index: usize = 0; |
| 203 | 196 | var negative = false; |
| ... | ... | @@ -207,52 +200,49 @@ fn parseRepr(s: []const u8, n: *FloatRepr) !ParseResult { |
| 207 | 200 | var state = State.MaybeSign; |
| 208 | 201 | |
| 209 | 202 | var i: usize = 0; |
| 210 | loop: while (i < s.len) { | |
| 203 | while (i < s.len) { | |
| 211 | 204 | const c = s[i]; |
| 212 | 205 | |
| 213 | 206 | switch (state) { |
| 214 | State.MaybeSign => { | |
| 215 | state = State.LeadingMantissaZeros; | |
| 207 | .MaybeSign => { | |
| 208 | state = .LeadingMantissaZeros; | |
| 216 | 209 | |
| 217 | 210 | if (c == '+') { |
| 218 | 211 | i += 1; |
| 219 | 212 | } else if (c == '-') { |
| 220 | 213 | n.negative = true; |
| 221 | 214 | i += 1; |
| 222 | } else if (isDigit(c) or c == '.') { | |
| 215 | } else if (ascii.isDigit(c) or c == '.') { | |
| 223 | 216 | // continue |
| 224 | 217 | } else { |
| 225 | 218 | return error.InvalidCharacter; |
| 226 | 219 | } |
| 227 | 220 | }, |
| 228 | ||
| 229 | State.LeadingMantissaZeros => { | |
| 221 | .LeadingMantissaZeros => { | |
| 230 | 222 | if (c == '0') { |
| 231 | 223 | i += 1; |
| 232 | 224 | } else if (c == '.') { |
| 233 | 225 | i += 1; |
| 234 | state = State.LeadingFractionalZeros; | |
| 226 | state = .LeadingFractionalZeros; | |
| 235 | 227 | } else { |
| 236 | state = State.MantissaIntegral; | |
| 228 | state = .MantissaIntegral; | |
| 237 | 229 | } |
| 238 | 230 | }, |
| 239 | ||
| 240 | State.LeadingFractionalZeros => { | |
| 231 | .LeadingFractionalZeros => { | |
| 241 | 232 | if (c == '0') { |
| 242 | 233 | i += 1; |
| 243 | 234 | if (n.exponent > std.math.minInt(i32)) { |
| 244 | 235 | n.exponent -= 1; |
| 245 | 236 | } |
| 246 | 237 | } else { |
| 247 | state = State.MantissaFractional; | |
| 238 | state = .MantissaFractional; | |
| 248 | 239 | } |
| 249 | 240 | }, |
| 250 | ||
| 251 | State.MantissaIntegral => { | |
| 252 | if (isDigit(c)) { | |
| 241 | .MantissaIntegral => { | |
| 242 | if (ascii.isDigit(c)) { | |
| 253 | 243 | if (digit_index < max_digits) { |
| 254 | 244 | n.mantissa *%= 10; |
| 255 | n.mantissa += s[i] - '0'; | |
| 245 | n.mantissa += c - '0'; | |
| 256 | 246 | digit_index += 1; |
| 257 | 247 | } else if (n.exponent < std.math.maxInt(i32)) { |
| 258 | 248 | n.exponent += 1; |
| ... | ... | @@ -261,14 +251,13 @@ fn parseRepr(s: []const u8, n: *FloatRepr) !ParseResult { |
| 261 | 251 | i += 1; |
| 262 | 252 | } else if (c == '.') { |
| 263 | 253 | i += 1; |
| 264 | state = State.MantissaFractional; | |
| 254 | state = .MantissaFractional; | |
| 265 | 255 | } else { |
| 266 | state = State.MantissaFractional; | |
| 256 | state = .MantissaFractional; | |
| 267 | 257 | } |
| 268 | 258 | }, |
| 269 | ||
| 270 | State.MantissaFractional => { | |
| 271 | if (isDigit(c)) { | |
| 259 | .MantissaFractional => { | |
| 260 | if (ascii.isDigit(c)) { | |
| 272 | 261 | if (digit_index < max_digits) { |
| 273 | 262 | n.mantissa *%= 10; |
| 274 | 263 | n.mantissa += c - '0'; |
| ... | ... | @@ -279,13 +268,12 @@ fn parseRepr(s: []const u8, n: *FloatRepr) !ParseResult { |
| 279 | 268 | i += 1; |
| 280 | 269 | } else if (c == 'e' or c == 'E') { |
| 281 | 270 | i += 1; |
| 282 | state = State.ExponentSign; | |
| 271 | state = .ExponentSign; | |
| 283 | 272 | } else { |
| 284 | state = State.ExponentSign; | |
| 273 | state = .ExponentSign; | |
| 285 | 274 | } |
| 286 | 275 | }, |
| 287 | ||
| 288 | State.ExponentSign => { | |
| 276 | .ExponentSign => { | |
| 289 | 277 | if (c == '+') { |
| 290 | 278 | i += 1; |
| 291 | 279 | } else if (c == '-') { |
| ... | ... | @@ -293,20 +281,18 @@ fn parseRepr(s: []const u8, n: *FloatRepr) !ParseResult { |
| 293 | 281 | i += 1; |
| 294 | 282 | } |
| 295 | 283 | |
| 296 | state = State.LeadingExponentZeros; | |
| 284 | state = .LeadingExponentZeros; | |
| 297 | 285 | }, |
| 298 | ||
| 299 | State.LeadingExponentZeros => { | |
| 286 | .LeadingExponentZeros => { | |
| 300 | 287 | if (c == '0') { |
| 301 | 288 | i += 1; |
| 302 | 289 | } else { |
| 303 | state = State.Exponent; | |
| 290 | state = .Exponent; | |
| 304 | 291 | } |
| 305 | 292 | }, |
| 306 | ||
| 307 | State.Exponent => { | |
| 308 | if (isDigit(c)) { | |
| 309 | if (exponent < std.math.maxInt(i32)) { | |
| 293 | .Exponent => { | |
| 294 | if (ascii.isDigit(c)) { | |
| 295 | if (exponent < std.math.maxInt(i32) / 10) { | |
| 310 | 296 | exponent *= 10; |
| 311 | 297 | exponent += @intCast(i32, c - '0'); |
| 312 | 298 | } |
| ... | ... | @@ -323,29 +309,21 @@ fn parseRepr(s: []const u8, n: *FloatRepr) !ParseResult { |
| 323 | 309 | n.exponent += exponent; |
| 324 | 310 | |
| 325 | 311 | if (n.mantissa == 0) { |
| 326 | return if (n.negative) ParseResult.MinusZero else ParseResult.PlusZero; | |
| 312 | return if (n.negative) .MinusZero else .PlusZero; | |
| 327 | 313 | } else if (n.exponent > 309) { |
| 328 | return if (n.negative) ParseResult.MinusInf else ParseResult.PlusInf; | |
| 314 | return if (n.negative) .MinusInf else .PlusInf; | |
| 329 | 315 | } else if (n.exponent < -328) { |
| 330 | return if (n.negative) ParseResult.MinusZero else ParseResult.PlusZero; | |
| 316 | return if (n.negative) .MinusZero else .PlusZero; | |
| 331 | 317 | } |
| 332 | 318 | |
| 333 | return ParseResult.Ok; | |
| 334 | } | |
| 335 | ||
| 336 | inline fn isLower(c: u8) bool { | |
| 337 | return c -% 'a' < 26; | |
| 338 | } | |
| 339 | ||
| 340 | inline fn toUpper(c: u8) u8 { | |
| 341 | return if (isLower(c)) (c & 0x5f) else c; | |
| 319 | return .Ok; | |
| 342 | 320 | } |
| 343 | 321 | |
| 344 | 322 | fn caseInEql(a: []const u8, b: []const u8) bool { |
| 345 | 323 | if (a.len != b.len) return false; |
| 346 | 324 | |
| 347 | 325 | for (a) |_, i| { |
| 348 | if (toUpper(a[i]) != toUpper(b[i])) { | |
| 326 | if (ascii.toUpper(a[i]) != ascii.toUpper(b[i])) { | |
| 349 | 327 | return false; |
| 350 | 328 | } |
| 351 | 329 | } |
| ... | ... | @@ -373,11 +351,11 @@ pub fn parseFloat(comptime T: type, s: []const u8) !T { |
| 373 | 351 | }; |
| 374 | 352 | |
| 375 | 353 | return switch (try parseRepr(s, &r)) { |
| 376 | ParseResult.Ok => convertRepr(T, r), | |
| 377 | ParseResult.PlusZero => 0.0, | |
| 378 | ParseResult.MinusZero => -@as(T, 0.0), | |
| 379 | ParseResult.PlusInf => std.math.inf(T), | |
| 380 | ParseResult.MinusInf => -std.math.inf(T), | |
| 354 | .Ok => convertRepr(T, r), | |
| 355 | .PlusZero => 0.0, | |
| 356 | .MinusZero => -@as(T, 0.0), | |
| 357 | .PlusInf => std.math.inf(T), | |
| 358 | .MinusInf => -std.math.inf(T), | |
| 381 | 359 | }; |
| 382 | 360 | } |
| 383 | 361 | |
| ... | ... | @@ -396,26 +374,28 @@ test "fmt.parseFloat" { |
| 396 | 374 | testing.expectError(error.InvalidCharacter, parseFloat(T, "1abc")); |
| 397 | 375 | |
| 398 | 376 | expectEqual(try parseFloat(T, "0"), 0.0); |
| 399 | expectEqual((try parseFloat(T, "0")), 0.0); | |
| 400 | expectEqual((try parseFloat(T, "+0")), 0.0); | |
| 401 | expectEqual((try parseFloat(T, "-0")), 0.0); | |
| 377 | expectEqual(try parseFloat(T, "0"), 0.0); | |
| 378 | expectEqual(try parseFloat(T, "+0"), 0.0); | |
| 379 | expectEqual(try parseFloat(T, "-0"), 0.0); | |
| 402 | 380 | |
| 403 | expectEqual((try parseFloat(T, "0e0")), 0); | |
| 404 | expectEqual((try parseFloat(T, "2e3")), 2000.0); | |
| 405 | expectEqual((try parseFloat(T, "1e0")), 1.0); | |
| 406 | expectEqual((try parseFloat(T, "-2e3")), -2000.0); | |
| 407 | expectEqual((try parseFloat(T, "-1e0")), -1.0); | |
| 408 | expectEqual((try parseFloat(T, "1.234e3")), 1234); | |
| 381 | expectEqual(try parseFloat(T, "0e0"), 0); | |
| 382 | expectEqual(try parseFloat(T, "2e3"), 2000.0); | |
| 383 | expectEqual(try parseFloat(T, "1e0"), 1.0); | |
| 384 | expectEqual(try parseFloat(T, "-2e3"), -2000.0); | |
| 385 | expectEqual(try parseFloat(T, "-1e0"), -1.0); | |
| 386 | expectEqual(try parseFloat(T, "1.234e3"), 1234); | |
| 409 | 387 | |
| 410 | 388 | expect(approxEq(T, try parseFloat(T, "3.141"), 3.141, epsilon)); |
| 411 | 389 | expect(approxEq(T, try parseFloat(T, "-3.141"), -3.141, epsilon)); |
| 412 | 390 | |
| 413 | expectEqual((try parseFloat(T, "1e-700")), 0); | |
| 414 | expectEqual((try parseFloat(T, "1e+700")), std.math.inf(T)); | |
| 391 | expectEqual(try parseFloat(T, "1e-700"), 0); | |
| 392 | expectEqual(try parseFloat(T, "1e+700"), std.math.inf(T)); | |
| 415 | 393 | |
| 416 | 394 | expectEqual(@bitCast(Z, try parseFloat(T, "nAn")), @bitCast(Z, std.math.nan(T))); |
| 417 | expectEqual((try parseFloat(T, "inF")), std.math.inf(T)); | |
| 418 | expectEqual((try parseFloat(T, "-INF")), -std.math.inf(T)); | |
| 395 | expectEqual(try parseFloat(T, "inF"), std.math.inf(T)); | |
| 396 | expectEqual(try parseFloat(T, "-INF"), -std.math.inf(T)); | |
| 397 | ||
| 398 | expectEqual(try parseFloat(T, "0.4e0066999999999999999999999999999999999999999999999999999"), std.math.inf(T)); | |
| 419 | 399 | |
| 420 | 400 | if (T != f16) { |
| 421 | 401 | expect(approxEq(T, try parseFloat(T, "1e-2"), 0.01, epsilon)); |
lib/std/fs.zig+121-98| ... | ... | @@ -11,13 +11,18 @@ const math = std.math; |
| 11 | 11 | pub const path = @import("fs/path.zig"); |
| 12 | 12 | pub const File = @import("fs/file.zig").File; |
| 13 | 13 | |
| 14 | // TODO audit these APIs with respect to Dir and absolute paths | |
| 15 | ||
| 14 | 16 | pub const symLink = os.symlink; |
| 15 | pub const symLinkC = os.symlinkC; | |
| 17 | pub const symLinkZ = os.symlinkZ; | |
| 18 | pub const symLinkC = @compileError("deprecated: renamed to symlinkZ"); | |
| 16 | 19 | pub const rename = os.rename; |
| 17 | pub const renameC = os.renameC; | |
| 20 | pub const renameZ = os.renameZ; | |
| 21 | pub const renameC = @compileError("deprecated: renamed to renameZ"); | |
| 18 | 22 | pub const renameW = os.renameW; |
| 19 | 23 | pub const realpath = os.realpath; |
| 20 | pub const realpathC = os.realpathC; | |
| 24 | pub const realpathZ = os.realpathZ; | |
| 25 | pub const realpathC = @compileError("deprecated: renamed to realpathZ"); | |
| 21 | 26 | pub const realpathW = os.realpathW; |
| 22 | 27 | |
| 23 | 28 | pub const getAppDataDir = @import("fs/get_app_data_dir.zig").getAppDataDir; |
| ... | ... | @@ -120,7 +125,7 @@ pub const AtomicFile = struct { |
| 120 | 125 | file: File, |
| 121 | 126 | // TODO either replace this with rand_buf or use []u16 on Windows |
| 122 | 127 | tmp_path_buf: [TMP_PATH_LEN:0]u8, |
| 123 | dest_path: []const u8, | |
| 128 | dest_basename: []const u8, | |
| 124 | 129 | file_open: bool, |
| 125 | 130 | file_exists: bool, |
| 126 | 131 | close_dir_on_deinit: bool, |
| ... | ... | @@ -131,17 +136,23 @@ pub const AtomicFile = struct { |
| 131 | 136 | const RANDOM_BYTES = 12; |
| 132 | 137 | const TMP_PATH_LEN = base64.Base64Encoder.calcSize(RANDOM_BYTES); |
| 133 | 138 | |
| 134 | /// TODO rename this. Callers should go through Dir API | |
| 135 | pub fn init2(dest_path: []const u8, mode: File.Mode, dir: Dir, close_dir_on_deinit: bool) InitError!AtomicFile { | |
| 139 | /// Note that the `Dir.atomicFile` API may be more handy than this lower-level function. | |
| 140 | pub fn init( | |
| 141 | dest_basename: []const u8, | |
| 142 | mode: File.Mode, | |
| 143 | dir: Dir, | |
| 144 | close_dir_on_deinit: bool, | |
| 145 | ) InitError!AtomicFile { | |
| 136 | 146 | var rand_buf: [RANDOM_BYTES]u8 = undefined; |
| 137 | 147 | var tmp_path_buf: [TMP_PATH_LEN:0]u8 = undefined; |
| 148 | // TODO: should be able to use TMP_PATH_LEN here. | |
| 138 | 149 | tmp_path_buf[base64.Base64Encoder.calcSize(RANDOM_BYTES)] = 0; |
| 139 | 150 | |
| 140 | 151 | while (true) { |
| 141 | 152 | try crypto.randomBytes(rand_buf[0..]); |
| 142 | 153 | base64_encoder.encode(&tmp_path_buf, &rand_buf); |
| 143 | 154 | |
| 144 | const file = dir.createFileC( | |
| 155 | const file = dir.createFileZ( | |
| 145 | 156 | &tmp_path_buf, |
| 146 | 157 | .{ .mode = mode, .exclusive = true }, |
| 147 | 158 | ) catch |err| switch (err) { |
| ... | ... | @@ -152,7 +163,7 @@ pub const AtomicFile = struct { |
| 152 | 163 | return AtomicFile{ |
| 153 | 164 | .file = file, |
| 154 | 165 | .tmp_path_buf = tmp_path_buf, |
| 155 | .dest_path = dest_path, | |
| 166 | .dest_basename = dest_basename, | |
| 156 | 167 | .file_open = true, |
| 157 | 168 | .file_exists = true, |
| 158 | 169 | .close_dir_on_deinit = close_dir_on_deinit, |
| ... | ... | @@ -161,11 +172,6 @@ pub const AtomicFile = struct { |
| 161 | 172 | } |
| 162 | 173 | } |
| 163 | 174 | |
| 164 | /// Deprecated. Use `Dir.atomicFile`. | |
| 165 | pub fn init(dest_path: []const u8, mode: File.Mode) InitError!AtomicFile { | |
| 166 | return cwd().atomicFile(dest_path, .{ .mode = mode }); | |
| 167 | } | |
| 168 | ||
| 169 | 175 | /// always call deinit, even after successful finish() |
| 170 | 176 | pub fn deinit(self: *AtomicFile) void { |
| 171 | 177 | if (self.file_open) { |
| ... | ... | @@ -173,7 +179,7 @@ pub const AtomicFile = struct { |
| 173 | 179 | self.file_open = false; |
| 174 | 180 | } |
| 175 | 181 | if (self.file_exists) { |
| 176 | self.dir.deleteFileC(&self.tmp_path_buf) catch {}; | |
| 182 | self.dir.deleteFileZ(&self.tmp_path_buf) catch {}; | |
| 177 | 183 | self.file_exists = false; |
| 178 | 184 | } |
| 179 | 185 | if (self.close_dir_on_deinit) { |
| ... | ... | @@ -189,12 +195,12 @@ pub const AtomicFile = struct { |
| 189 | 195 | self.file_open = false; |
| 190 | 196 | } |
| 191 | 197 | if (std.Target.current.os.tag == .windows) { |
| 192 | const dest_path_w = try os.windows.sliceToPrefixedFileW(self.dest_path); | |
| 198 | const dest_path_w = try os.windows.sliceToPrefixedFileW(self.dest_basename); | |
| 193 | 199 | const tmp_path_w = try os.windows.cStrToPrefixedFileW(&self.tmp_path_buf); |
| 194 | 200 | try os.renameatW(self.dir.fd, &tmp_path_w, self.dir.fd, &dest_path_w, os.windows.TRUE); |
| 195 | 201 | self.file_exists = false; |
| 196 | 202 | } else { |
| 197 | const dest_path_c = try os.toPosixPath(self.dest_path); | |
| 203 | const dest_path_c = try os.toPosixPath(self.dest_basename); | |
| 198 | 204 | try os.renameatZ(self.dir.fd, &self.tmp_path_buf, self.dir.fd, &dest_path_c); |
| 199 | 205 | self.file_exists = false; |
| 200 | 206 | } |
| ... | ... | @@ -213,7 +219,7 @@ pub fn makeDirAbsolute(absolute_path: []const u8) !void { |
| 213 | 219 | |
| 214 | 220 | /// Same as `makeDirAbsolute` except the parameter is a null-terminated UTF8-encoded string. |
| 215 | 221 | pub fn makeDirAbsoluteZ(absolute_path_z: [*:0]const u8) !void { |
| 216 | assert(path.isAbsoluteC(absolute_path_z)); | |
| 222 | assert(path.isAbsoluteZ(absolute_path_z)); | |
| 217 | 223 | return os.mkdirZ(absolute_path_z, default_new_dir_mode); |
| 218 | 224 | } |
| 219 | 225 | |
| ... | ... | @@ -224,18 +230,25 @@ pub fn makeDirAbsoluteW(absolute_path_w: [*:0]const u16) !void { |
| 224 | 230 | os.windows.CloseHandle(handle); |
| 225 | 231 | } |
| 226 | 232 | |
| 227 | /// Deprecated; use `Dir.deleteDir`. | |
| 228 | pub fn deleteDir(dir_path: []const u8) !void { | |
| 233 | pub const deleteDir = @compileError("deprecated; use dir.deleteDir or deleteDirAbsolute"); | |
| 234 | pub const deleteDirC = @compileError("deprecated; use dir.deleteDirZ or deleteDirAbsoluteZ"); | |
| 235 | pub const deleteDirW = @compileError("deprecated; use dir.deleteDirW or deleteDirAbsoluteW"); | |
| 236 | ||
| 237 | /// Same as `Dir.deleteDir` except the path is absolute. | |
| 238 | pub fn deleteDirAbsolute(dir_path: []const u8) !void { | |
| 239 | assert(path.isAbsolute(dir_path)); | |
| 229 | 240 | return os.rmdir(dir_path); |
| 230 | 241 | } |
| 231 | 242 | |
| 232 | /// Deprecated; use `Dir.deleteDirC`. | |
| 233 | pub fn deleteDirC(dir_path: [*:0]const u8) !void { | |
| 234 | return os.rmdirC(dir_path); | |
| 243 | /// Same as `deleteDirAbsolute` except the path parameter is null-terminated. | |
| 244 | pub fn deleteDirAbsoluteZ(dir_path: [*:0]const u8) !void { | |
| 245 | assert(path.isAbsoluteZ(dir_path)); | |
| 246 | return os.rmdirZ(dir_path); | |
| 235 | 247 | } |
| 236 | 248 | |
| 237 | /// Deprecated; use `Dir.deleteDirW`. | |
| 238 | pub fn deleteDirW(dir_path: [*:0]const u16) !void { | |
| 249 | /// Same as `deleteDirAbsolute` except the path parameter is WTF-16 and target OS is assumed Windows. | |
| 250 | pub fn deleteDirAbsoluteW(dir_path: [*:0]const u16) !void { | |
| 251 | assert(path.isAbsoluteWindowsW(dir_path)); | |
| 239 | 252 | return os.rmdirW(dir_path); |
| 240 | 253 | } |
| 241 | 254 | |
| ... | ... | @@ -412,7 +425,7 @@ pub const Dir = struct { |
| 412 | 425 | const next_index = self.index + linux_entry.reclen(); |
| 413 | 426 | self.index = next_index; |
| 414 | 427 | |
| 415 | const name = mem.toSlice(u8, @ptrCast([*:0]u8, &linux_entry.d_name)); | |
| 428 | const name = mem.spanZ(@ptrCast([*:0]u8, &linux_entry.d_name)); | |
| 416 | 429 | |
| 417 | 430 | // skip . and .. entries |
| 418 | 431 | if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..")) { |
| ... | ... | @@ -573,8 +586,7 @@ pub const Dir = struct { |
| 573 | 586 | return self.openFileZ(&path_c, flags); |
| 574 | 587 | } |
| 575 | 588 | |
| 576 | /// Deprecated; use `openFileZ`. | |
| 577 | pub const openFileC = openFileZ; | |
| 589 | pub const openFileC = @compileError("deprecated: renamed to openFileZ"); | |
| 578 | 590 | |
| 579 | 591 | /// Same as `openFile` but the path parameter is null-terminated. |
| 580 | 592 | pub fn openFileZ(self: Dir, sub_path: [*:0]const u8, flags: File.OpenFlags) File.OpenError!File { |
| ... | ... | @@ -603,7 +615,7 @@ pub const Dir = struct { |
| 603 | 615 | const fd = if (need_async_thread and !flags.always_blocking) |
| 604 | 616 | try std.event.Loop.instance.?.openatZ(self.fd, sub_path, os_flags, 0) |
| 605 | 617 | else |
| 606 | try os.openatC(self.fd, sub_path, os_flags, 0); | |
| 618 | try os.openatZ(self.fd, sub_path, os_flags, 0); | |
| 607 | 619 | |
| 608 | 620 | // use fcntl file locking if no lock flag was given |
| 609 | 621 | if (flags.lock and lock_flag == 0) { |
| ... | ... | @@ -652,11 +664,13 @@ pub const Dir = struct { |
| 652 | 664 | return self.createFileW(&path_w, flags); |
| 653 | 665 | } |
| 654 | 666 | const path_c = try os.toPosixPath(sub_path); |
| 655 | return self.createFileC(&path_c, flags); | |
| 667 | return self.createFileZ(&path_c, flags); | |
| 656 | 668 | } |
| 657 | 669 | |
| 670 | pub const createFileC = @compileError("deprecated: renamed to createFileZ"); | |
| 671 | ||
| 658 | 672 | /// Same as `createFile` but the path parameter is null-terminated. |
| 659 | pub fn createFileC(self: Dir, sub_path_c: [*:0]const u8, flags: File.CreateFlags) File.OpenError!File { | |
| 673 | pub fn createFileZ(self: Dir, sub_path_c: [*:0]const u8, flags: File.CreateFlags) File.OpenError!File { | |
| 660 | 674 | if (builtin.os.tag == .windows) { |
| 661 | 675 | const path_w = try os.windows.cStrToPrefixedFileW(sub_path_c); |
| 662 | 676 | return self.createFileW(&path_w, flags); |
| ... | ... | @@ -676,7 +690,7 @@ pub const Dir = struct { |
| 676 | 690 | const fd = if (need_async_thread) |
| 677 | 691 | try std.event.Loop.instance.?.openatZ(self.fd, sub_path_c, os_flags, flags.mode) |
| 678 | 692 | else |
| 679 | try os.openatC(self.fd, sub_path_c, os_flags, flags.mode); | |
| 693 | try os.openatZ(self.fd, sub_path_c, os_flags, flags.mode); | |
| 680 | 694 | |
| 681 | 695 | if (flags.lock and lock_flag == 0) { |
| 682 | 696 | // TODO: integrate async I/O |
| ... | ... | @@ -713,27 +727,16 @@ pub const Dir = struct { |
| 713 | 727 | }); |
| 714 | 728 | } |
| 715 | 729 | |
| 716 | /// Deprecated; call `openFile` directly. | |
| 717 | pub fn openRead(self: Dir, sub_path: []const u8) File.OpenError!File { | |
| 718 | return self.openFile(sub_path, .{}); | |
| 719 | } | |
| 720 | ||
| 721 | /// Deprecated; call `openFileZ` directly. | |
| 722 | pub fn openReadC(self: Dir, sub_path: [*:0]const u8) File.OpenError!File { | |
| 723 | return self.openFileZ(sub_path, .{}); | |
| 724 | } | |
| 725 | ||
| 726 | /// Deprecated; call `openFileW` directly. | |
| 727 | pub fn openReadW(self: Dir, sub_path: [*:0]const u16) File.OpenError!File { | |
| 728 | return self.openFileW(sub_path, .{}); | |
| 729 | } | |
| 730 | pub const openRead = @compileError("deprecated in favor of openFile"); | |
| 731 | pub const openReadC = @compileError("deprecated in favor of openFileZ"); | |
| 732 | pub const openReadW = @compileError("deprecated in favor of openFileW"); | |
| 730 | 733 | |
| 731 | 734 | pub fn makeDir(self: Dir, sub_path: []const u8) !void { |
| 732 | 735 | try os.mkdirat(self.fd, sub_path, default_new_dir_mode); |
| 733 | 736 | } |
| 734 | 737 | |
| 735 | 738 | pub fn makeDirZ(self: Dir, sub_path: [*:0]const u8) !void { |
| 736 | try os.mkdiratC(self.fd, sub_path, default_new_dir_mode); | |
| 739 | try os.mkdiratZ(self.fd, sub_path, default_new_dir_mode); | |
| 737 | 740 | } |
| 738 | 741 | |
| 739 | 742 | pub fn makeDirW(self: Dir, sub_path: [*:0]const u16) !void { |
| ... | ... | @@ -807,20 +810,22 @@ pub const Dir = struct { |
| 807 | 810 | return self.openDirW(&sub_path_w, args); |
| 808 | 811 | } else { |
| 809 | 812 | const sub_path_c = try os.toPosixPath(sub_path); |
| 810 | return self.openDirC(&sub_path_c, args); | |
| 813 | return self.openDirZ(&sub_path_c, args); | |
| 811 | 814 | } |
| 812 | 815 | } |
| 813 | 816 | |
| 817 | pub const openDirC = @compileError("deprecated: renamed to openDirZ"); | |
| 818 | ||
| 814 | 819 | /// Same as `openDir` except the parameter is null-terminated. |
| 815 | pub fn openDirC(self: Dir, sub_path_c: [*:0]const u8, args: OpenDirOptions) OpenError!Dir { | |
| 820 | pub fn openDirZ(self: Dir, sub_path_c: [*:0]const u8, args: OpenDirOptions) OpenError!Dir { | |
| 816 | 821 | if (builtin.os.tag == .windows) { |
| 817 | 822 | const sub_path_w = try os.windows.cStrToPrefixedFileW(sub_path_c); |
| 818 | 823 | return self.openDirW(&sub_path_w, args); |
| 819 | 824 | } else if (!args.iterate) { |
| 820 | 825 | const O_PATH = if (@hasDecl(os, "O_PATH")) os.O_PATH else 0; |
| 821 | return self.openDirFlagsC(sub_path_c, os.O_DIRECTORY | os.O_RDONLY | os.O_CLOEXEC | O_PATH); | |
| 826 | return self.openDirFlagsZ(sub_path_c, os.O_DIRECTORY | os.O_RDONLY | os.O_CLOEXEC | O_PATH); | |
| 822 | 827 | } else { |
| 823 | return self.openDirFlagsC(sub_path_c, os.O_DIRECTORY | os.O_RDONLY | os.O_CLOEXEC); | |
| 828 | return self.openDirFlagsZ(sub_path_c, os.O_DIRECTORY | os.O_RDONLY | os.O_CLOEXEC); | |
| 824 | 829 | } |
| 825 | 830 | } |
| 826 | 831 | |
| ... | ... | @@ -836,11 +841,11 @@ pub const Dir = struct { |
| 836 | 841 | } |
| 837 | 842 | |
| 838 | 843 | /// `flags` must contain `os.O_DIRECTORY`. |
| 839 | fn openDirFlagsC(self: Dir, sub_path_c: [*:0]const u8, flags: u32) OpenError!Dir { | |
| 844 | fn openDirFlagsZ(self: Dir, sub_path_c: [*:0]const u8, flags: u32) OpenError!Dir { | |
| 840 | 845 | const result = if (need_async_thread) |
| 841 | 846 | std.event.Loop.instance.?.openatZ(self.fd, sub_path_c, flags, 0) |
| 842 | 847 | else |
| 843 | os.openatC(self.fd, sub_path_c, flags, 0); | |
| 848 | os.openatZ(self.fd, sub_path_c, flags, 0); | |
| 844 | 849 | const fd = result catch |err| switch (err) { |
| 845 | 850 | error.FileTooBig => unreachable, // can't happen for directories |
| 846 | 851 | error.IsDir => unreachable, // we're providing O_DIRECTORY |
| ... | ... | @@ -858,7 +863,7 @@ pub const Dir = struct { |
| 858 | 863 | .fd = undefined, |
| 859 | 864 | }; |
| 860 | 865 | |
| 861 | const path_len_bytes = @intCast(u16, mem.toSliceConst(u16, sub_path_w).len * 2); | |
| 866 | const path_len_bytes = @intCast(u16, mem.lenZ(sub_path_w) * 2); | |
| 862 | 867 | var nt_name = w.UNICODE_STRING{ |
| 863 | 868 | .Length = path_len_bytes, |
| 864 | 869 | .MaximumLength = path_len_bytes, |
| ... | ... | @@ -916,9 +921,11 @@ pub const Dir = struct { |
| 916 | 921 | }; |
| 917 | 922 | } |
| 918 | 923 | |
| 924 | pub const deleteFileC = @compileError("deprecated: renamed to deleteFileZ"); | |
| 925 | ||
| 919 | 926 | /// Same as `deleteFile` except the parameter is null-terminated. |
| 920 | pub fn deleteFileC(self: Dir, sub_path_c: [*:0]const u8) DeleteFileError!void { | |
| 921 | os.unlinkatC(self.fd, sub_path_c, 0) catch |err| switch (err) { | |
| 927 | pub fn deleteFileZ(self: Dir, sub_path_c: [*:0]const u8) DeleteFileError!void { | |
| 928 | os.unlinkatZ(self.fd, sub_path_c, 0) catch |err| switch (err) { | |
| 922 | 929 | error.DirNotEmpty => unreachable, // not passing AT_REMOVEDIR |
| 923 | 930 | else => |e| return e, |
| 924 | 931 | }; |
| ... | ... | @@ -957,12 +964,12 @@ pub const Dir = struct { |
| 957 | 964 | return self.deleteDirW(&sub_path_w); |
| 958 | 965 | } |
| 959 | 966 | const sub_path_c = try os.toPosixPath(sub_path); |
| 960 | return self.deleteDirC(&sub_path_c); | |
| 967 | return self.deleteDirZ(&sub_path_c); | |
| 961 | 968 | } |
| 962 | 969 | |
| 963 | 970 | /// Same as `deleteDir` except the parameter is null-terminated. |
| 964 | pub fn deleteDirC(self: Dir, sub_path_c: [*:0]const u8) DeleteDirError!void { | |
| 965 | os.unlinkatC(self.fd, sub_path_c, os.AT_REMOVEDIR) catch |err| switch (err) { | |
| 971 | pub fn deleteDirZ(self: Dir, sub_path_c: [*:0]const u8) DeleteDirError!void { | |
| 972 | os.unlinkatZ(self.fd, sub_path_c, os.AT_REMOVEDIR) catch |err| switch (err) { | |
| 966 | 973 | error.IsDir => unreachable, // not possible since we pass AT_REMOVEDIR |
| 967 | 974 | else => |e| return e, |
| 968 | 975 | }; |
| ... | ... | @@ -982,12 +989,14 @@ pub const Dir = struct { |
| 982 | 989 | /// Asserts that the path parameter has no null bytes. |
| 983 | 990 | pub fn readLink(self: Dir, sub_path: []const u8, buffer: *[MAX_PATH_BYTES]u8) ![]u8 { |
| 984 | 991 | const sub_path_c = try os.toPosixPath(sub_path); |
| 985 | return self.readLinkC(&sub_path_c, buffer); | |
| 992 | return self.readLinkZ(&sub_path_c, buffer); | |
| 986 | 993 | } |
| 987 | 994 | |
| 995 | pub const readLinkC = @compileError("deprecated: renamed to readLinkZ"); | |
| 996 | ||
| 988 | 997 | /// Same as `readLink`, except the `pathname` parameter is null-terminated. |
| 989 | pub fn readLinkC(self: Dir, sub_path_c: [*:0]const u8, buffer: *[MAX_PATH_BYTES]u8) ![]u8 { | |
| 990 | return os.readlinkatC(self.fd, sub_path_c, buffer); | |
| 998 | pub fn readLinkZ(self: Dir, sub_path_c: [*:0]const u8, buffer: *[MAX_PATH_BYTES]u8) ![]u8 { | |
| 999 | return os.readlinkatZ(self.fd, sub_path_c, buffer); | |
| 991 | 1000 | } |
| 992 | 1001 | |
| 993 | 1002 | /// On success, caller owns returned buffer. |
| ... | ... | @@ -1005,7 +1014,7 @@ pub const Dir = struct { |
| 1005 | 1014 | max_bytes: usize, |
| 1006 | 1015 | comptime A: u29, |
| 1007 | 1016 | ) ![]align(A) u8 { |
| 1008 | var file = try self.openRead(file_path); | |
| 1017 | var file = try self.openFile(file_path, .{}); | |
| 1009 | 1018 | defer file.close(); |
| 1010 | 1019 | |
| 1011 | 1020 | const size = math.cast(usize, try file.getEndPos()) catch math.maxInt(usize); |
| ... | ... | @@ -1329,9 +1338,9 @@ pub const Dir = struct { |
| 1329 | 1338 | pub fn atomicFile(self: Dir, dest_path: []const u8, options: AtomicFileOptions) !AtomicFile { |
| 1330 | 1339 | if (path.dirname(dest_path)) |dirname| { |
| 1331 | 1340 | const dir = try self.openDir(dirname, .{}); |
| 1332 | return AtomicFile.init2(path.basename(dest_path), options.mode, dir, true); | |
| 1341 | return AtomicFile.init(path.basename(dest_path), options.mode, dir, true); | |
| 1333 | 1342 | } else { |
| 1334 | return AtomicFile.init2(dest_path, options.mode, self, false); | |
| 1343 | return AtomicFile.init(dest_path, options.mode, self, false); | |
| 1335 | 1344 | } |
| 1336 | 1345 | } |
| 1337 | 1346 | }; |
| ... | ... | @@ -1358,9 +1367,11 @@ pub fn openFileAbsolute(absolute_path: []const u8, flags: File.OpenFlags) File.O |
| 1358 | 1367 | return cwd().openFile(absolute_path, flags); |
| 1359 | 1368 | } |
| 1360 | 1369 | |
| 1370 | pub const openFileAbsoluteC = @compileError("deprecated: renamed to openFileAbsoluteZ"); | |
| 1371 | ||
| 1361 | 1372 | /// Same as `openFileAbsolute` but the path parameter is null-terminated. |
| 1362 | pub fn openFileAbsoluteC(absolute_path_c: [*:0]const u8, flags: File.OpenFlags) File.OpenError!File { | |
| 1363 | assert(path.isAbsoluteC(absolute_path_c)); | |
| 1373 | pub fn openFileAbsoluteZ(absolute_path_c: [*:0]const u8, flags: File.OpenFlags) File.OpenError!File { | |
| 1374 | assert(path.isAbsoluteZ(absolute_path_c)); | |
| 1364 | 1375 | return cwd().openFileZ(absolute_path_c, flags); |
| 1365 | 1376 | } |
| 1366 | 1377 | |
| ... | ... | @@ -1381,10 +1392,12 @@ pub fn createFileAbsolute(absolute_path: []const u8, flags: File.CreateFlags) Fi |
| 1381 | 1392 | return cwd().createFile(absolute_path, flags); |
| 1382 | 1393 | } |
| 1383 | 1394 | |
| 1395 | pub const createFileAbsoluteC = @compileError("deprecated: renamed to createFileAbsoluteZ"); | |
| 1396 | ||
| 1384 | 1397 | /// Same as `createFileAbsolute` but the path parameter is null-terminated. |
| 1385 | pub fn createFileAbsoluteC(absolute_path_c: [*:0]const u8, flags: File.CreateFlags) File.OpenError!File { | |
| 1386 | assert(path.isAbsoluteC(absolute_path_c)); | |
| 1387 | return cwd().createFileC(absolute_path_c, flags); | |
| 1398 | pub fn createFileAbsoluteZ(absolute_path_c: [*:0]const u8, flags: File.CreateFlags) File.OpenError!File { | |
| 1399 | assert(path.isAbsoluteZ(absolute_path_c)); | |
| 1400 | return cwd().createFileZ(absolute_path_c, flags); | |
| 1388 | 1401 | } |
| 1389 | 1402 | |
| 1390 | 1403 | /// Same as `createFileAbsolute` but the path parameter is WTF-16 encoded. |
| ... | ... | @@ -1402,10 +1415,12 @@ pub fn deleteFileAbsolute(absolute_path: []const u8) DeleteFileError!void { |
| 1402 | 1415 | return cwd().deleteFile(absolute_path); |
| 1403 | 1416 | } |
| 1404 | 1417 | |
| 1418 | pub const deleteFileAbsoluteC = @compileError("deprecated: renamed to deleteFileAbsoluteZ"); | |
| 1419 | ||
| 1405 | 1420 | /// Same as `deleteFileAbsolute` except the parameter is null-terminated. |
| 1406 | pub fn deleteFileAbsoluteC(absolute_path_c: [*:0]const u8) DeleteFileError!void { | |
| 1407 | assert(path.isAbsoluteC(absolute_path_c)); | |
| 1408 | return cwd().deleteFileC(absolute_path_c); | |
| 1421 | pub fn deleteFileAbsoluteZ(absolute_path_c: [*:0]const u8) DeleteFileError!void { | |
| 1422 | assert(path.isAbsoluteZ(absolute_path_c)); | |
| 1423 | return cwd().deleteFileZ(absolute_path_c); | |
| 1409 | 1424 | } |
| 1410 | 1425 | |
| 1411 | 1426 | /// Same as `deleteFileAbsolute` except the parameter is WTF-16 encoded. |
| ... | ... | @@ -1433,15 +1448,31 @@ pub fn deleteTreeAbsolute(absolute_path: []const u8) !void { |
| 1433 | 1448 | return dir.deleteTree(path.basename(absolute_path)); |
| 1434 | 1449 | } |
| 1435 | 1450 | |
| 1451 | /// Same as `Dir.readLink`, except it asserts the path is absolute. | |
| 1452 | pub fn readLinkAbsolute(pathname: []const u8, buffer: *[MAX_PATH_BYTES]u8) ![]u8 { | |
| 1453 | assert(path.isAbsolute(pathname)); | |
| 1454 | return os.readlink(pathname, buffer); | |
| 1455 | } | |
| 1456 | ||
| 1457 | /// Same as `readLink`, except the path parameter is null-terminated. | |
| 1458 | pub fn readLinkAbsoluteZ(pathname_c: [*]const u8, buffer: *[MAX_PATH_BYTES]u8) ![]u8 { | |
| 1459 | assert(path.isAbsoluteZ(pathname_c)); | |
| 1460 | return os.readlinkZ(pathname_c, buffer); | |
| 1461 | } | |
| 1462 | ||
| 1463 | pub const readLink = @compileError("deprecated; use Dir.readLink or readLinkAbsolute"); | |
| 1464 | pub const readLinkC = @compileError("deprecated; use Dir.readLinkZ or readLinkAbsoluteZ"); | |
| 1465 | ||
| 1436 | 1466 | pub const Walker = struct { |
| 1437 | 1467 | stack: std.ArrayList(StackItem), |
| 1438 | name_buffer: std.Buffer, | |
| 1468 | name_buffer: std.ArrayList(u8), | |
| 1439 | 1469 | |
| 1440 | 1470 | pub const Entry = struct { |
| 1441 | 1471 | /// The containing directory. This can be used to operate directly on `basename` |
| 1442 | 1472 | /// rather than `path`, avoiding `error.NameTooLong` for deeply nested paths. |
| 1443 | 1473 | /// The directory remains open until `next` or `deinit` is called. |
| 1444 | 1474 | dir: Dir, |
| 1475 | /// TODO make this null terminated for API convenience | |
| 1445 | 1476 | basename: []const u8, |
| 1446 | 1477 | |
| 1447 | 1478 | path: []const u8, |
| ... | ... | @@ -1460,12 +1491,12 @@ pub const Walker = struct { |
| 1460 | 1491 | while (true) { |
| 1461 | 1492 | if (self.stack.len == 0) return null; |
| 1462 | 1493 | // `top` becomes invalid after appending to `self.stack`. |
| 1463 | const top = &self.stack.toSlice()[self.stack.len - 1]; | |
| 1494 | const top = &self.stack.span()[self.stack.len - 1]; | |
| 1464 | 1495 | const dirname_len = top.dirname_len; |
| 1465 | 1496 | if (try top.dir_it.next()) |base| { |
| 1466 | 1497 | self.name_buffer.shrink(dirname_len); |
| 1467 | try self.name_buffer.appendByte(path.sep); | |
| 1468 | try self.name_buffer.append(base.name); | |
| 1498 | try self.name_buffer.append(path.sep); | |
| 1499 | try self.name_buffer.appendSlice(base.name); | |
| 1469 | 1500 | if (base.kind == .Directory) { |
| 1470 | 1501 | var new_dir = top.dir_it.dir.openDir(base.name, .{ .iterate = true }) catch |err| switch (err) { |
| 1471 | 1502 | error.NameTooLong => unreachable, // no path sep in base.name |
| ... | ... | @@ -1475,14 +1506,14 @@ pub const Walker = struct { |
| 1475 | 1506 | errdefer new_dir.close(); |
| 1476 | 1507 | try self.stack.append(StackItem{ |
| 1477 | 1508 | .dir_it = new_dir.iterate(), |
| 1478 | .dirname_len = self.name_buffer.len(), | |
| 1509 | .dirname_len = self.name_buffer.len, | |
| 1479 | 1510 | }); |
| 1480 | 1511 | } |
| 1481 | 1512 | } |
| 1482 | 1513 | return Entry{ |
| 1483 | 1514 | .dir = top.dir_it.dir, |
| 1484 | .basename = self.name_buffer.toSliceConst()[dirname_len + 1 ..], | |
| 1485 | .path = self.name_buffer.toSliceConst(), | |
| 1515 | .basename = self.name_buffer.span()[dirname_len + 1 ..], | |
| 1516 | .path = self.name_buffer.span(), | |
| 1486 | 1517 | .kind = base.kind, |
| 1487 | 1518 | }; |
| 1488 | 1519 | } else { |
| ... | ... | @@ -1508,9 +1539,11 @@ pub fn walkPath(allocator: *Allocator, dir_path: []const u8) !Walker { |
| 1508 | 1539 | var dir = try cwd().openDir(dir_path, .{ .iterate = true }); |
| 1509 | 1540 | errdefer dir.close(); |
| 1510 | 1541 | |
| 1511 | var name_buffer = try std.Buffer.init(allocator, dir_path); | |
| 1542 | var name_buffer = std.ArrayList(u8).init(allocator); | |
| 1512 | 1543 | errdefer name_buffer.deinit(); |
| 1513 | 1544 | |
| 1545 | try name_buffer.appendSlice(dir_path); | |
| 1546 | ||
| 1514 | 1547 | var walker = Walker{ |
| 1515 | 1548 | .stack = std.ArrayList(Walker.StackItem).init(allocator), |
| 1516 | 1549 | .name_buffer = name_buffer, |
| ... | ... | @@ -1524,31 +1557,21 @@ pub fn walkPath(allocator: *Allocator, dir_path: []const u8) !Walker { |
| 1524 | 1557 | return walker; |
| 1525 | 1558 | } |
| 1526 | 1559 | |
| 1527 | /// Deprecated; use `Dir.readLink`. | |
| 1528 | pub fn readLink(pathname: []const u8, buffer: *[MAX_PATH_BYTES]u8) ![]u8 { | |
| 1529 | return os.readlink(pathname, buffer); | |
| 1530 | } | |
| 1531 | ||
| 1532 | /// Deprecated; use `Dir.readLinkC`. | |
| 1533 | pub fn readLinkC(pathname_c: [*]const u8, buffer: *[MAX_PATH_BYTES]u8) ![]u8 { | |
| 1534 | return os.readlinkC(pathname_c, buffer); | |
| 1535 | } | |
| 1536 | ||
| 1537 | 1560 | pub const OpenSelfExeError = os.OpenError || os.windows.CreateFileError || SelfExePathError || os.FcntlError; |
| 1538 | 1561 | |
| 1539 | 1562 | pub fn openSelfExe() OpenSelfExeError!File { |
| 1540 | 1563 | if (builtin.os.tag == .linux) { |
| 1541 | return openFileAbsoluteC("/proc/self/exe", .{}); | |
| 1564 | return openFileAbsoluteZ("/proc/self/exe", .{}); | |
| 1542 | 1565 | } |
| 1543 | 1566 | if (builtin.os.tag == .windows) { |
| 1544 | 1567 | const wide_slice = selfExePathW(); |
| 1545 | 1568 | const prefixed_path_w = try os.windows.wToPrefixedFileW(wide_slice); |
| 1546 | return cwd().openReadW(&prefixed_path_w); | |
| 1569 | return cwd().openFileW(&prefixed_path_w, .{}); | |
| 1547 | 1570 | } |
| 1548 | 1571 | var buf: [MAX_PATH_BYTES]u8 = undefined; |
| 1549 | 1572 | const self_exe_path = try selfExePath(&buf); |
| 1550 | 1573 | buf[self_exe_path.len] = 0; |
| 1551 | return openFileAbsoluteC(self_exe_path[0..self_exe_path.len :0].ptr, .{}); | |
| 1574 | return openFileAbsoluteZ(self_exe_path[0..self_exe_path.len :0].ptr, .{}); | |
| 1552 | 1575 | } |
| 1553 | 1576 | |
| 1554 | 1577 | test "openSelfExe" { |
| ... | ... | @@ -1582,23 +1605,23 @@ pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) SelfExePathError![]u8 { |
| 1582 | 1605 | var u32_len: u32 = out_buffer.len; |
| 1583 | 1606 | const rc = std.c._NSGetExecutablePath(out_buffer, &u32_len); |
| 1584 | 1607 | if (rc != 0) return error.NameTooLong; |
| 1585 | return mem.toSlice(u8, @ptrCast([*:0]u8, out_buffer)); | |
| 1608 | return mem.spanZ(@ptrCast([*:0]u8, out_buffer)); | |
| 1586 | 1609 | } |
| 1587 | 1610 | switch (builtin.os.tag) { |
| 1588 | .linux => return os.readlinkC("/proc/self/exe", out_buffer), | |
| 1611 | .linux => return os.readlinkZ("/proc/self/exe", out_buffer), | |
| 1589 | 1612 | .freebsd, .dragonfly => { |
| 1590 | 1613 | var mib = [4]c_int{ os.CTL_KERN, os.KERN_PROC, os.KERN_PROC_PATHNAME, -1 }; |
| 1591 | 1614 | var out_len: usize = out_buffer.len; |
| 1592 | 1615 | try os.sysctl(&mib, out_buffer, &out_len, null, 0); |
| 1593 | 1616 | // TODO could this slice from 0 to out_len instead? |
| 1594 | return mem.toSlice(u8, @ptrCast([*:0]u8, out_buffer)); | |
| 1617 | return mem.spanZ(@ptrCast([*:0]u8, out_buffer)); | |
| 1595 | 1618 | }, |
| 1596 | 1619 | .netbsd => { |
| 1597 | 1620 | var mib = [4]c_int{ os.CTL_KERN, os.KERN_PROC_ARGS, -1, os.KERN_PROC_PATHNAME }; |
| 1598 | 1621 | var out_len: usize = out_buffer.len; |
| 1599 | 1622 | try os.sysctl(&mib, out_buffer, &out_len, null, 0); |
| 1600 | 1623 | // TODO could this slice from 0 to out_len instead? |
| 1601 | return mem.toSlice(u8, @ptrCast([*:0]u8, out_buffer)); | |
| 1624 | return mem.spanZ(@ptrCast([*:0]u8, out_buffer)); | |
| 1602 | 1625 | }, |
| 1603 | 1626 | .windows => { |
| 1604 | 1627 | const utf16le_slice = selfExePathW(); |
| ... | ... | @@ -1613,7 +1636,7 @@ pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) SelfExePathError![]u8 { |
| 1613 | 1636 | /// The result is UTF16LE-encoded. |
| 1614 | 1637 | pub fn selfExePathW() [:0]const u16 { |
| 1615 | 1638 | const image_path_name = &os.windows.peb().ProcessParameters.ImagePathName; |
| 1616 | return mem.toSliceConst(u16, @ptrCast([*:0]const u16, image_path_name.Buffer)); | |
| 1639 | return mem.spanZ(@ptrCast([*:0]const u16, image_path_name.Buffer)); | |
| 1617 | 1640 | } |
| 1618 | 1641 | |
| 1619 | 1642 | /// `selfExeDirPath` except allocates the result on the heap. |
lib/std/fs/file.zig+1-1| ... | ... | @@ -110,7 +110,7 @@ pub const File = struct { |
| 110 | 110 | if (self.isTty()) { |
| 111 | 111 | if (self.handle == os.STDOUT_FILENO or self.handle == os.STDERR_FILENO) { |
| 112 | 112 | // Use getenvC to workaround https://github.com/ziglang/zig/issues/3511 |
| 113 | if (os.getenvC("TERM")) |term| { | |
| 113 | if (os.getenvZ("TERM")) |term| { | |
| 114 | 114 | if (std.mem.eql(u8, term, "dumb")) |
| 115 | 115 | return false; |
| 116 | 116 | } |
lib/std/fs/get_app_data_dir.zig+1-1| ... | ... | @@ -24,7 +24,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD |
| 24 | 24 | )) { |
| 25 | 25 | os.windows.S_OK => { |
| 26 | 26 | defer os.windows.ole32.CoTaskMemFree(@ptrCast(*c_void, dir_path_ptr)); |
| 27 | const global_dir = unicode.utf16leToUtf8Alloc(allocator, mem.toSliceConst(u16, dir_path_ptr)) catch |err| switch (err) { | |
| 27 | const global_dir = unicode.utf16leToUtf8Alloc(allocator, mem.spanZ(dir_path_ptr)) catch |err| switch (err) { | |
| 28 | 28 | error.UnexpectedSecondSurrogateHalf => return error.AppDataDirUnavailable, |
| 29 | 29 | error.ExpectedSecondSurrogateHalf => return error.AppDataDirUnavailable, |
| 30 | 30 | error.DanglingSurrogateHalf => return error.AppDataDirUnavailable, |
lib/std/fs/path.zig+14-8| ... | ... | @@ -128,11 +128,13 @@ test "join" { |
| 128 | 128 | testJoinPosix(&[_][]const u8{ "a/", "/c" }, "a/c"); |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | pub fn isAbsoluteC(path_c: [*:0]const u8) bool { | |
| 131 | pub const isAbsoluteC = @compileError("deprecated: renamed to isAbsoluteZ"); | |
| 132 | ||
| 133 | pub fn isAbsoluteZ(path_c: [*:0]const u8) bool { | |
| 132 | 134 | if (builtin.os.tag == .windows) { |
| 133 | return isAbsoluteWindowsC(path_c); | |
| 135 | return isAbsoluteWindowsZ(path_c); | |
| 134 | 136 | } else { |
| 135 | return isAbsolutePosixC(path_c); | |
| 137 | return isAbsolutePosixZ(path_c); | |
| 136 | 138 | } |
| 137 | 139 | } |
| 138 | 140 | |
| ... | ... | @@ -172,19 +174,23 @@ pub fn isAbsoluteWindows(path: []const u8) bool { |
| 172 | 174 | } |
| 173 | 175 | |
| 174 | 176 | pub fn isAbsoluteWindowsW(path_w: [*:0]const u16) bool { |
| 175 | return isAbsoluteWindowsImpl(u16, mem.toSliceConst(u16, path_w)); | |
| 177 | return isAbsoluteWindowsImpl(u16, mem.spanZ(path_w)); | |
| 176 | 178 | } |
| 177 | 179 | |
| 178 | pub fn isAbsoluteWindowsC(path_c: [*:0]const u8) bool { | |
| 179 | return isAbsoluteWindowsImpl(u8, mem.toSliceConst(u8, path_c)); | |
| 180 | pub const isAbsoluteWindowsC = @compileError("deprecated: renamed to isAbsoluteWindowsZ"); | |
| 181 | ||
| 182 | pub fn isAbsoluteWindowsZ(path_c: [*:0]const u8) bool { | |
| 183 | return isAbsoluteWindowsImpl(u8, mem.spanZ(path_c)); | |
| 180 | 184 | } |
| 181 | 185 | |
| 182 | 186 | pub fn isAbsolutePosix(path: []const u8) bool { |
| 183 | 187 | return path.len > 0 and path[0] == sep_posix; |
| 184 | 188 | } |
| 185 | 189 | |
| 186 | pub fn isAbsolutePosixC(path_c: [*:0]const u8) bool { | |
| 187 | return isAbsolutePosix(mem.toSliceConst(u8, path_c)); | |
| 190 | pub const isAbsolutePosixC = @compileError("deprecated: renamed to isAbsolutePosixZ"); | |
| 191 | ||
| 192 | pub fn isAbsolutePosixZ(path_c: [*:0]const u8) bool { | |
| 193 | return isAbsolutePosix(mem.spanZ(path_c)); | |
| 188 | 194 | } |
| 189 | 195 | |
| 190 | 196 | test "isAbsoluteWindows" { |
lib/std/fs/watch.zig+1-1| ... | ... | @@ -326,7 +326,7 @@ pub fn Watch(comptime V: type) type { |
| 326 | 326 | var basename_with_null_consumed = false; |
| 327 | 327 | defer if (!basename_with_null_consumed) self.allocator.free(basename_with_null); |
| 328 | 328 | |
| 329 | const wd = try os.inotify_add_watchC( | |
| 329 | const wd = try os.inotify_add_watchZ( | |
| 330 | 330 | self.os_data.inotify_fd, |
| 331 | 331 | dirname_with_null.ptr, |
| 332 | 332 | os.linux.IN_CLOSE_WRITE | os.linux.IN_ONLYDIR | os.linux.IN_EXCL_UNLINK, |
lib/std/hash/adler.zig+29-8| ... | ... | @@ -42,18 +42,23 @@ pub const Adler32 = struct { |
| 42 | 42 | |
| 43 | 43 | s2 %= base; |
| 44 | 44 | } else { |
| 45 | const n = nmax / 16; // note: 16 | nmax | |
| 46 | ||
| 45 | 47 | var i: usize = 0; |
| 46 | while (i + nmax <= input.len) : (i += nmax) { | |
| 47 | const n = nmax / 16; // note: 16 | nmax | |
| 48 | 48 | |
| 49 | while (i + nmax <= input.len) { | |
| 49 | 50 | var rounds: usize = 0; |
| 50 | 51 | while (rounds < n) : (rounds += 1) { |
| 51 | 52 | comptime var j: usize = 0; |
| 52 | 53 | inline while (j < 16) : (j += 1) { |
| 53 | s1 +%= input[i + n * j]; | |
| 54 | s1 +%= input[i + j]; | |
| 54 | 55 | s2 +%= s1; |
| 55 | 56 | } |
| 57 | i += 16; | |
| 56 | 58 | } |
| 59 | ||
| 60 | s1 %= base; | |
| 61 | s2 %= base; | |
| 57 | 62 | } |
| 58 | 63 | |
| 59 | 64 | if (i < input.len) { |
| ... | ... | @@ -89,19 +94,35 @@ pub const Adler32 = struct { |
| 89 | 94 | }; |
| 90 | 95 | |
| 91 | 96 | test "adler32 sanity" { |
| 92 | testing.expect(Adler32.hash("a") == 0x620062); | |
| 93 | testing.expect(Adler32.hash("example") == 0xbc002ed); | |
| 97 | testing.expectEqual(@as(u32, 0x620062), Adler32.hash("a")); | |
| 98 | testing.expectEqual(@as(u32, 0xbc002ed), Adler32.hash("example")); | |
| 94 | 99 | } |
| 95 | 100 | |
| 96 | 101 | test "adler32 long" { |
| 97 | 102 | const long1 = [_]u8{1} ** 1024; |
| 98 | testing.expect(Adler32.hash(long1[0..]) == 0x06780401); | |
| 103 | testing.expectEqual(@as(u32, 0x06780401), Adler32.hash(long1[0..])); | |
| 99 | 104 | |
| 100 | 105 | const long2 = [_]u8{1} ** 1025; |
| 101 | testing.expect(Adler32.hash(long2[0..]) == 0x0a7a0402); | |
| 106 | testing.expectEqual(@as(u32, 0x0a7a0402), Adler32.hash(long2[0..])); | |
| 102 | 107 | } |
| 103 | 108 | |
| 104 | 109 | test "adler32 very long" { |
| 105 | 110 | const long = [_]u8{1} ** 5553; |
| 106 | testing.expect(Adler32.hash(long[0..]) == 0x707f15b2); | |
| 111 | testing.expectEqual(@as(u32, 0x707f15b2), Adler32.hash(long[0..])); | |
| 112 | } | |
| 113 | ||
| 114 | test "adler32 very long with variation" { | |
| 115 | const long = comptime blk: { | |
| 116 | @setEvalBranchQuota(7000); | |
| 117 | var result: [6000]u8 = undefined; | |
| 118 | ||
| 119 | var i: usize = 0; | |
| 120 | while (i < result.len) : (i += 1) { | |
| 121 | result[i] = @truncate(u8, i); | |
| 122 | } | |
| 123 | ||
| 124 | break :blk result; | |
| 125 | }; | |
| 126 | ||
| 127 | testing.expectEqual(@as(u32, 0x5af38d6e), std.hash.Adler32.hash(long[0..])); | |
| 107 | 128 | } |
lib/std/heap.zig+1-2| ... | ... | @@ -51,8 +51,7 @@ var wasm_page_allocator_state = Allocator{ |
| 51 | 51 | .shrinkFn = WasmPageAllocator.shrink, |
| 52 | 52 | }; |
| 53 | 53 | |
| 54 | /// Deprecated. Use `page_allocator`. | |
| 55 | pub const direct_allocator = page_allocator; | |
| 54 | pub const direct_allocator = @compileError("deprecated; use std.heap.page_allocator"); | |
| 56 | 55 | |
| 57 | 56 | const PageAllocator = struct { |
| 58 | 57 | fn alloc(allocator: *Allocator, n: usize, alignment: u29) error{OutOfMemory}![]u8 { |
lib/std/http/headers.zig+8-8| ... | ... | @@ -129,7 +129,7 @@ pub const Headers = struct { |
| 129 | 129 | self.index.deinit(); |
| 130 | 130 | } |
| 131 | 131 | { |
| 132 | for (self.data.toSliceConst()) |entry| { | |
| 132 | for (self.data.span()) |entry| { | |
| 133 | 133 | entry.deinit(); |
| 134 | 134 | } |
| 135 | 135 | self.data.deinit(); |
| ... | ... | @@ -141,14 +141,14 @@ pub const Headers = struct { |
| 141 | 141 | errdefer other.deinit(); |
| 142 | 142 | try other.data.ensureCapacity(self.data.len); |
| 143 | 143 | try other.index.initCapacity(self.index.entries.len); |
| 144 | for (self.data.toSliceConst()) |entry| { | |
| 144 | for (self.data.span()) |entry| { | |
| 145 | 145 | try other.append(entry.name, entry.value, entry.never_index); |
| 146 | 146 | } |
| 147 | 147 | return other; |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | pub fn toSlice(self: Self) []const HeaderEntry { |
| 151 | return self.data.toSliceConst(); | |
| 151 | return self.data.span(); | |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | pub fn append(self: *Self, name: []const u8, value: []const u8, never_index: ?bool) !void { |
| ... | ... | @@ -279,7 +279,7 @@ pub const Headers = struct { |
| 279 | 279 | |
| 280 | 280 | const buf = try allocator.alloc(HeaderEntry, dex.len); |
| 281 | 281 | var n: usize = 0; |
| 282 | for (dex.toSliceConst()) |idx| { | |
| 282 | for (dex.span()) |idx| { | |
| 283 | 283 | buf[n] = self.data.at(idx); |
| 284 | 284 | n += 1; |
| 285 | 285 | } |
| ... | ... | @@ -302,7 +302,7 @@ pub const Headers = struct { |
| 302 | 302 | // adapted from mem.join |
| 303 | 303 | const total_len = blk: { |
| 304 | 304 | var sum: usize = dex.len - 1; // space for separator(s) |
| 305 | for (dex.toSliceConst()) |idx| | |
| 305 | for (dex.span()) |idx| | |
| 306 | 306 | sum += self.data.at(idx).value.len; |
| 307 | 307 | break :blk sum; |
| 308 | 308 | }; |
| ... | ... | @@ -334,7 +334,7 @@ pub const Headers = struct { |
| 334 | 334 | } |
| 335 | 335 | } |
| 336 | 336 | { // fill up indexes again; we know capacity is fine from before |
| 337 | for (self.data.toSliceConst()) |entry, i| { | |
| 337 | for (self.data.span()) |entry, i| { | |
| 338 | 338 | var dex = &self.index.get(entry.name).?.value; |
| 339 | 339 | dex.appendAssumeCapacity(i); |
| 340 | 340 | } |
| ... | ... | @@ -495,8 +495,8 @@ test "Headers.getIndices" { |
| 495 | 495 | try h.append("set-cookie", "y=2", null); |
| 496 | 496 | |
| 497 | 497 | testing.expect(null == h.getIndices("not-present")); |
| 498 | testing.expectEqualSlices(usize, &[_]usize{0}, h.getIndices("foo").?.toSliceConst()); | |
| 499 | testing.expectEqualSlices(usize, &[_]usize{ 1, 2 }, h.getIndices("set-cookie").?.toSliceConst()); | |
| 498 | testing.expectEqualSlices(usize, &[_]usize{0}, h.getIndices("foo").?.span()); | |
| 499 | testing.expectEqualSlices(usize, &[_]usize{ 1, 2 }, h.getIndices("set-cookie").?.span()); | |
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | test "Headers.get" { |
lib/std/io.zig+17-10| ... | ... | @@ -128,16 +128,6 @@ pub const BufferedAtomicFile = @import("io/buffered_atomic_file.zig").BufferedAt |
| 128 | 128 | |
| 129 | 129 | pub const StreamSource = @import("io/stream_source.zig").StreamSource; |
| 130 | 130 | |
| 131 | /// Deprecated; use `std.fs.Dir.writeFile`. | |
| 132 | pub fn writeFile(path: []const u8, data: []const u8) !void { | |
| 133 | return fs.cwd().writeFile(path, data); | |
| 134 | } | |
| 135 | ||
| 136 | /// Deprecated; use `std.fs.Dir.readFileAlloc`. | |
| 137 | pub fn readFileAlloc(allocator: *mem.Allocator, path: []const u8) ![]u8 { | |
| 138 | return fs.cwd().readFileAlloc(allocator, path, math.maxInt(usize)); | |
| 139 | } | |
| 140 | ||
| 141 | 131 | /// An OutStream that doesn't write to anything. |
| 142 | 132 | pub const null_out_stream = @as(NullOutStream, .{ .context = {} }); |
| 143 | 133 | |
| ... | ... | @@ -151,5 +141,22 @@ test "null_out_stream" { |
| 151 | 141 | } |
| 152 | 142 | |
| 153 | 143 | test "" { |
| 144 | _ = @import("io/bit_in_stream.zig"); | |
| 145 | _ = @import("io/bit_out_stream.zig"); | |
| 146 | _ = @import("io/buffered_atomic_file.zig"); | |
| 147 | _ = @import("io/buffered_in_stream.zig"); | |
| 148 | _ = @import("io/buffered_out_stream.zig"); | |
| 149 | _ = @import("io/c_out_stream.zig"); | |
| 150 | _ = @import("io/counting_out_stream.zig"); | |
| 151 | _ = @import("io/fixed_buffer_stream.zig"); | |
| 152 | _ = @import("io/in_stream.zig"); | |
| 153 | _ = @import("io/out_stream.zig"); | |
| 154 | _ = @import("io/peek_stream.zig"); | |
| 155 | _ = @import("io/seekable_stream.zig"); | |
| 156 | _ = @import("io/serialization.zig"); | |
| 157 | _ = @import("io/stream_source.zig"); | |
| 154 | 158 | _ = @import("io/test.zig"); |
| 155 | 159 | } |
| 160 | ||
| 161 | pub const writeFile = @compileError("deprecated: use std.fs.Dir.writeFile with math.maxInt(usize)"); | |
| 162 | pub const readFileAlloc = @compileError("deprecated: use std.fs.Dir.readFileAlloc"); |
lib/std/io/buffered_atomic_file.zig+2-1| ... | ... | @@ -15,6 +15,7 @@ pub const BufferedAtomicFile = struct { |
| 15 | 15 | |
| 16 | 16 | /// TODO when https://github.com/ziglang/zig/issues/2761 is solved |
| 17 | 17 | /// this API will not need an allocator |
| 18 | /// TODO integrate this with Dir API | |
| 18 | 19 | pub fn create(allocator: *mem.Allocator, dest_path: []const u8) !*BufferedAtomicFile { |
| 19 | 20 | var self = try allocator.create(BufferedAtomicFile); |
| 20 | 21 | self.* = BufferedAtomicFile{ |
| ... | ... | @@ -25,7 +26,7 @@ pub const BufferedAtomicFile = struct { |
| 25 | 26 | }; |
| 26 | 27 | errdefer allocator.destroy(self); |
| 27 | 28 | |
| 28 | self.atomic_file = try fs.AtomicFile.init(dest_path, File.default_mode); | |
| 29 | self.atomic_file = try fs.cwd().atomicFile(dest_path, .{}); | |
| 29 | 30 | errdefer self.atomic_file.deinit(); |
| 30 | 31 | |
| 31 | 32 | self.file_stream = self.atomic_file.file.outStream(); |
lib/std/io/c_out_stream.zig+2-2| ... | ... | @@ -36,9 +36,9 @@ test "" { |
| 36 | 36 | const out_file = std.c.fopen(filename, "w") orelse return error.UnableToOpenTestFile; |
| 37 | 37 | defer { |
| 38 | 38 | _ = std.c.fclose(out_file); |
| 39 | fs.cwd().deleteFileC(filename) catch {}; | |
| 39 | std.fs.cwd().deleteFileZ(filename) catch {}; | |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | const out_stream = &io.COutStream.init(out_file).stream; | |
| 42 | const out_stream = cOutStream(out_file); | |
| 43 | 43 | try out_stream.print("hi: {}\n", .{@as(i32, 123)}); |
| 44 | 44 | } |
lib/std/io/in_stream.zig+1-8| ... | ... | @@ -3,7 +3,6 @@ const builtin = std.builtin; |
| 3 | 3 | const math = std.math; |
| 4 | 4 | const assert = std.debug.assert; |
| 5 | 5 | const mem = std.mem; |
| 6 | const Buffer = std.Buffer; | |
| 7 | 6 | const testing = std.testing; |
| 8 | 7 | |
| 9 | 8 | pub fn InStream( |
| ... | ... | @@ -48,13 +47,7 @@ pub fn InStream( |
| 48 | 47 | if (amt_read < buf.len) return error.EndOfStream; |
| 49 | 48 | } |
| 50 | 49 | |
| 51 | /// Deprecated: use `readAllArrayList`. | |
| 52 | pub fn readAllBuffer(self: Self, buffer: *Buffer, max_size: usize) !void { | |
| 53 | buffer.list.shrink(0); | |
| 54 | try self.readAllArrayList(&buffer.list, max_size); | |
| 55 | errdefer buffer.shrink(0); | |
| 56 | try buffer.list.append(0); | |
| 57 | } | |
| 50 | pub const readAllBuffer = @compileError("deprecated; use readAllArrayList()"); | |
| 58 | 51 | |
| 59 | 52 | /// Appends to the `std.ArrayList` contents by reading from the stream until end of stream is found. |
| 60 | 53 | /// If the number of bytes appended would exceed `max_append_size`, `error.StreamTooLong` is returned |
lib/std/io/peek_stream.zig+4-4| ... | ... | @@ -24,7 +24,7 @@ pub fn PeekStream( |
| 24 | 24 | .Static => struct { |
| 25 | 25 | pub fn init(base: InStreamType) Self { |
| 26 | 26 | return .{ |
| 27 | .base = base, | |
| 27 | .unbuffered_in_stream = base, | |
| 28 | 28 | .fifo = FifoType.init(), |
| 29 | 29 | }; |
| 30 | 30 | } |
| ... | ... | @@ -32,7 +32,7 @@ pub fn PeekStream( |
| 32 | 32 | .Slice => struct { |
| 33 | 33 | pub fn init(base: InStreamType, buf: []u8) Self { |
| 34 | 34 | return .{ |
| 35 | .base = base, | |
| 35 | .unbuffered_in_stream = base, | |
| 36 | 36 | .fifo = FifoType.init(buf), |
| 37 | 37 | }; |
| 38 | 38 | } |
| ... | ... | @@ -40,7 +40,7 @@ pub fn PeekStream( |
| 40 | 40 | .Dynamic => struct { |
| 41 | 41 | pub fn init(base: InStreamType, allocator: *mem.Allocator) Self { |
| 42 | 42 | return .{ |
| 43 | .base = base, | |
| 43 | .unbuffered_in_stream = base, | |
| 44 | 44 | .fifo = FifoType.init(allocator), |
| 45 | 45 | }; |
| 46 | 46 | } |
| ... | ... | @@ -61,7 +61,7 @@ pub fn PeekStream( |
| 61 | 61 | if (dest_index == dest.len) return dest_index; |
| 62 | 62 | |
| 63 | 63 | // ask the backing stream for more |
| 64 | dest_index += try self.base.read(dest[dest_index..]); | |
| 64 | dest_index += try self.unbuffered_in_stream.read(dest[dest_index..]); | |
| 65 | 65 | return dest_index; |
| 66 | 66 | } |
| 67 | 67 |
lib/std/io/serialization.zig+50-49| ... | ... | @@ -5,6 +5,7 @@ const assert = std.debug.assert; |
| 5 | 5 | const math = std.math; |
| 6 | 6 | const meta = std.meta; |
| 7 | 7 | const trait = meta.trait; |
| 8 | const testing = std.testing; | |
| 8 | 9 | |
| 9 | 10 | pub const Packing = enum { |
| 10 | 11 | /// Pack data to byte alignment |
| ... | ... | @@ -273,7 +274,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co |
| 273 | 274 | if (comptime trait.hasFn("serialize")(T)) return T.serialize(value, self); |
| 274 | 275 | |
| 275 | 276 | if (comptime trait.isPacked(T) and packing != .Bit) { |
| 276 | var packed_serializer = Serializer(endian, .Bit, Error).init(self.out_stream); | |
| 277 | var packed_serializer = Serializer(endian, .Bit, OutStreamType).init(self.out_stream); | |
| 277 | 278 | try packed_serializer.serialize(value); |
| 278 | 279 | try packed_serializer.flush(); |
| 279 | 280 | return; |
| ... | ... | @@ -364,28 +365,28 @@ fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime packi |
| 364 | 365 | |
| 365 | 366 | var data_mem: [total_bytes]u8 = undefined; |
| 366 | 367 | var out = io.fixedBufferStream(&data_mem); |
| 367 | var serializer = serializer(endian, packing, out.outStream()); | |
| 368 | var _serializer = serializer(endian, packing, out.outStream()); | |
| 368 | 369 | |
| 369 | 370 | var in = io.fixedBufferStream(&data_mem); |
| 370 | var deserializer = Deserializer(endian, packing, in.inStream()); | |
| 371 | var _deserializer = deserializer(endian, packing, in.inStream()); | |
| 371 | 372 | |
| 372 | 373 | comptime var i = 0; |
| 373 | 374 | inline while (i <= max_test_bitsize) : (i += 1) { |
| 374 | 375 | const U = std.meta.IntType(false, i); |
| 375 | 376 | const S = std.meta.IntType(true, i); |
| 376 | try serializer.serializeInt(@as(U, i)); | |
| 377 | if (i != 0) try serializer.serializeInt(@as(S, -1)) else try serializer.serialize(@as(S, 0)); | |
| 377 | try _serializer.serializeInt(@as(U, i)); | |
| 378 | if (i != 0) try _serializer.serializeInt(@as(S, -1)) else try _serializer.serialize(@as(S, 0)); | |
| 378 | 379 | } |
| 379 | try serializer.flush(); | |
| 380 | try _serializer.flush(); | |
| 380 | 381 | |
| 381 | 382 | i = 0; |
| 382 | 383 | inline while (i <= max_test_bitsize) : (i += 1) { |
| 383 | 384 | const U = std.meta.IntType(false, i); |
| 384 | 385 | const S = std.meta.IntType(true, i); |
| 385 | const x = try deserializer.deserializeInt(U); | |
| 386 | const y = try deserializer.deserializeInt(S); | |
| 387 | expect(x == @as(U, i)); | |
| 388 | if (i != 0) expect(y == @as(S, -1)) else expect(y == 0); | |
| 386 | const x = try _deserializer.deserializeInt(U); | |
| 387 | const y = try _deserializer.deserializeInt(S); | |
| 388 | testing.expect(x == @as(U, i)); | |
| 389 | if (i != 0) testing.expect(y == @as(S, -1)) else testing.expect(y == 0); | |
| 389 | 390 | } |
| 390 | 391 | |
| 391 | 392 | const u8_bit_count = comptime meta.bitCount(u8); |
| ... | ... | @@ -395,7 +396,7 @@ fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime packi |
| 395 | 396 | const extra_packed_byte = @boolToInt(total_bits % u8_bit_count > 0); |
| 396 | 397 | const total_packed_bytes = (total_bits / u8_bit_count) + extra_packed_byte; |
| 397 | 398 | |
| 398 | expect(in.pos == if (packing == .Bit) total_packed_bytes else total_bytes); | |
| 399 | testing.expect(in.pos == if (packing == .Bit) total_packed_bytes else total_bytes); | |
| 399 | 400 | |
| 400 | 401 | //Verify that empty error set works with serializer. |
| 401 | 402 | //deserializer is covered by FixedBufferStream |
| ... | ... | @@ -421,35 +422,35 @@ fn testIntSerializerDeserializerInfNaN( |
| 421 | 422 | var data_mem: [mem_size]u8 = undefined; |
| 422 | 423 | |
| 423 | 424 | var out = io.fixedBufferStream(&data_mem); |
| 424 | var serializer = serializer(endian, packing, out.outStream()); | |
| 425 | var _serializer = serializer(endian, packing, out.outStream()); | |
| 425 | 426 | |
| 426 | 427 | var in = io.fixedBufferStream(&data_mem); |
| 427 | var deserializer = deserializer(endian, packing, in.inStream()); | |
| 428 | var _deserializer = deserializer(endian, packing, in.inStream()); | |
| 428 | 429 | |
| 429 | 430 | //@TODO: isInf/isNan not currently implemented for f128. |
| 430 | try serializer.serialize(std.math.nan(f16)); | |
| 431 | try serializer.serialize(std.math.inf(f16)); | |
| 432 | try serializer.serialize(std.math.nan(f32)); | |
| 433 | try serializer.serialize(std.math.inf(f32)); | |
| 434 | try serializer.serialize(std.math.nan(f64)); | |
| 435 | try serializer.serialize(std.math.inf(f64)); | |
| 431 | try _serializer.serialize(std.math.nan(f16)); | |
| 432 | try _serializer.serialize(std.math.inf(f16)); | |
| 433 | try _serializer.serialize(std.math.nan(f32)); | |
| 434 | try _serializer.serialize(std.math.inf(f32)); | |
| 435 | try _serializer.serialize(std.math.nan(f64)); | |
| 436 | try _serializer.serialize(std.math.inf(f64)); | |
| 436 | 437 | //try serializer.serialize(std.math.nan(f128)); |
| 437 | 438 | //try serializer.serialize(std.math.inf(f128)); |
| 438 | const nan_check_f16 = try deserializer.deserialize(f16); | |
| 439 | const inf_check_f16 = try deserializer.deserialize(f16); | |
| 440 | const nan_check_f32 = try deserializer.deserialize(f32); | |
| 441 | deserializer.alignToByte(); | |
| 442 | const inf_check_f32 = try deserializer.deserialize(f32); | |
| 443 | const nan_check_f64 = try deserializer.deserialize(f64); | |
| 444 | const inf_check_f64 = try deserializer.deserialize(f64); | |
| 439 | const nan_check_f16 = try _deserializer.deserialize(f16); | |
| 440 | const inf_check_f16 = try _deserializer.deserialize(f16); | |
| 441 | const nan_check_f32 = try _deserializer.deserialize(f32); | |
| 442 | _deserializer.alignToByte(); | |
| 443 | const inf_check_f32 = try _deserializer.deserialize(f32); | |
| 444 | const nan_check_f64 = try _deserializer.deserialize(f64); | |
| 445 | const inf_check_f64 = try _deserializer.deserialize(f64); | |
| 445 | 446 | //const nan_check_f128 = try deserializer.deserialize(f128); |
| 446 | 447 | //const inf_check_f128 = try deserializer.deserialize(f128); |
| 447 | expect(std.math.isNan(nan_check_f16)); | |
| 448 | expect(std.math.isInf(inf_check_f16)); | |
| 449 | expect(std.math.isNan(nan_check_f32)); | |
| 450 | expect(std.math.isInf(inf_check_f32)); | |
| 451 | expect(std.math.isNan(nan_check_f64)); | |
| 452 | expect(std.math.isInf(inf_check_f64)); | |
| 448 | testing.expect(std.math.isNan(nan_check_f16)); | |
| 449 | testing.expect(std.math.isInf(inf_check_f16)); | |
| 450 | testing.expect(std.math.isNan(nan_check_f32)); | |
| 451 | testing.expect(std.math.isInf(inf_check_f32)); | |
| 452 | testing.expect(std.math.isNan(nan_check_f64)); | |
| 453 | testing.expect(std.math.isInf(inf_check_f64)); | |
| 453 | 454 | //expect(std.math.isNan(nan_check_f128)); |
| 454 | 455 | //expect(std.math.isInf(inf_check_f128)); |
| 455 | 456 | } |
| ... | ... | @@ -461,8 +462,8 @@ test "Serializer/Deserializer Int: Inf/NaN" { |
| 461 | 462 | try testIntSerializerDeserializerInfNaN(.Little, .Bit); |
| 462 | 463 | } |
| 463 | 464 | |
| 464 | fn testAlternateSerializer(self: var, serializer: var) !void { | |
| 465 | try serializer.serialize(self.f_f16); | |
| 465 | fn testAlternateSerializer(self: var, _serializer: var) !void { | |
| 466 | try _serializer.serialize(self.f_f16); | |
| 466 | 467 | } |
| 467 | 468 | |
| 468 | 469 | fn testSerializerDeserializer(comptime endian: builtin.Endian, comptime packing: io.Packing) !void { |
| ... | ... | @@ -502,8 +503,8 @@ fn testSerializerDeserializer(comptime endian: builtin.Endian, comptime packing: |
| 502 | 503 | f_f16: f16, |
| 503 | 504 | f_unused_u32: u32, |
| 504 | 505 | |
| 505 | pub fn deserialize(self: *@This(), deserializer: var) !void { | |
| 506 | try deserializer.deserializeInto(&self.f_f16); | |
| 506 | pub fn deserialize(self: *@This(), _deserializer: var) !void { | |
| 507 | try _deserializer.deserializeInto(&self.f_f16); | |
| 507 | 508 | self.f_unused_u32 = 47; |
| 508 | 509 | } |
| 509 | 510 | |
| ... | ... | @@ -550,15 +551,15 @@ fn testSerializerDeserializer(comptime endian: builtin.Endian, comptime packing: |
| 550 | 551 | |
| 551 | 552 | var data_mem: [@sizeOf(MyStruct)]u8 = undefined; |
| 552 | 553 | var out = io.fixedBufferStream(&data_mem); |
| 553 | var serializer = serializer(endian, packing, out.outStream()); | |
| 554 | var _serializer = serializer(endian, packing, out.outStream()); | |
| 554 | 555 | |
| 555 | 556 | var in = io.fixedBufferStream(&data_mem); |
| 556 | var deserializer = deserializer(endian, packing, in.inStream()); | |
| 557 | var _deserializer = deserializer(endian, packing, in.inStream()); | |
| 557 | 558 | |
| 558 | try serializer.serialize(my_inst); | |
| 559 | try _serializer.serialize(my_inst); | |
| 559 | 560 | |
| 560 | const my_copy = try deserializer.deserialize(MyStruct); | |
| 561 | expect(meta.eql(my_copy, my_inst)); | |
| 561 | const my_copy = try _deserializer.deserialize(MyStruct); | |
| 562 | testing.expect(meta.eql(my_copy, my_inst)); | |
| 562 | 563 | } |
| 563 | 564 | |
| 564 | 565 | test "Serializer/Deserializer generic" { |
| ... | ... | @@ -584,18 +585,18 @@ fn testBadData(comptime endian: builtin.Endian, comptime packing: io.Packing) !v |
| 584 | 585 | }; |
| 585 | 586 | |
| 586 | 587 | var data_mem: [4]u8 = undefined; |
| 587 | var out = io.fixedBufferStream.init(&data_mem); | |
| 588 | var serializer = serializer(endian, packing, out.outStream()); | |
| 588 | var out = io.fixedBufferStream(&data_mem); | |
| 589 | var _serializer = serializer(endian, packing, out.outStream()); | |
| 589 | 590 | |
| 590 | 591 | var in = io.fixedBufferStream(&data_mem); |
| 591 | var deserializer = deserializer(endian, packing, in.inStream()); | |
| 592 | var _deserializer = deserializer(endian, packing, in.inStream()); | |
| 592 | 593 | |
| 593 | try serializer.serialize(@as(u14, 3)); | |
| 594 | expectError(error.InvalidEnumTag, deserializer.deserialize(A)); | |
| 594 | try _serializer.serialize(@as(u14, 3)); | |
| 595 | testing.expectError(error.InvalidEnumTag, _deserializer.deserialize(A)); | |
| 595 | 596 | out.pos = 0; |
| 596 | try serializer.serialize(@as(u14, 3)); | |
| 597 | try serializer.serialize(@as(u14, 88)); | |
| 598 | expectError(error.InvalidEnumTag, deserializer.deserialize(C)); | |
| 597 | try _serializer.serialize(@as(u14, 3)); | |
| 598 | try _serializer.serialize(@as(u14, 88)); | |
| 599 | testing.expectError(error.InvalidEnumTag, _deserializer.deserialize(C)); | |
| 599 | 600 | } |
| 600 | 601 | |
| 601 | 602 | test "Deserializer bad data" { |
lib/std/json.zig+328-95| ... | ... | @@ -1233,42 +1233,119 @@ pub const Value = union(enum) { |
| 1233 | 1233 | Array: Array, |
| 1234 | 1234 | Object: ObjectMap, |
| 1235 | 1235 | |
| 1236 | pub fn jsonStringify( | |
| 1237 | value: @This(), | |
| 1238 | options: StringifyOptions, | |
| 1239 | out_stream: var, | |
| 1240 | ) @TypeOf(out_stream).Error!void { | |
| 1241 | switch (value) { | |
| 1242 | .Null => try stringify(null, options, out_stream), | |
| 1243 | .Bool => |inner| try stringify(inner, options, out_stream), | |
| 1244 | .Integer => |inner| try stringify(inner, options, out_stream), | |
| 1245 | .Float => |inner| try stringify(inner, options, out_stream), | |
| 1246 | .String => |inner| try stringify(inner, options, out_stream), | |
| 1247 | .Array => |inner| try stringify(inner.span(), options, out_stream), | |
| 1248 | .Object => |inner| { | |
| 1249 | try out_stream.writeByte('{'); | |
| 1250 | var field_output = false; | |
| 1251 | var child_options = options; | |
| 1252 | if (child_options.whitespace) |*child_whitespace| { | |
| 1253 | child_whitespace.indent_level += 1; | |
| 1254 | } | |
| 1255 | var it = inner.iterator(); | |
| 1256 | while (it.next()) |entry| { | |
| 1257 | if (!field_output) { | |
| 1258 | field_output = true; | |
| 1259 | } else { | |
| 1260 | try out_stream.writeByte(','); | |
| 1261 | } | |
| 1262 | if (child_options.whitespace) |child_whitespace| { | |
| 1263 | try out_stream.writeByte('\n'); | |
| 1264 | try child_whitespace.outputIndent(out_stream); | |
| 1265 | } | |
| 1266 | ||
| 1267 | try stringify(entry.key, options, out_stream); | |
| 1268 | try out_stream.writeByte(':'); | |
| 1269 | if (child_options.whitespace) |child_whitespace| { | |
| 1270 | if (child_whitespace.separator) { | |
| 1271 | try out_stream.writeByte(' '); | |
| 1272 | } | |
| 1273 | } | |
| 1274 | try stringify(entry.value, child_options, out_stream); | |
| 1275 | } | |
| 1276 | if (field_output) { | |
| 1277 | if (options.whitespace) |whitespace| { | |
| 1278 | try out_stream.writeByte('\n'); | |
| 1279 | try whitespace.outputIndent(out_stream); | |
| 1280 | } | |
| 1281 | } | |
| 1282 | try out_stream.writeByte('}'); | |
| 1283 | }, | |
| 1284 | } | |
| 1285 | } | |
| 1286 | ||
| 1236 | 1287 | pub fn dump(self: Value) void { |
| 1237 | 1288 | var held = std.debug.getStderrMutex().acquire(); |
| 1238 | 1289 | defer held.release(); |
| 1239 | 1290 | |
| 1240 | 1291 | const stderr = std.debug.getStderrStream(); |
| 1241 | self.dumpStream(stderr, 1024) catch return; | |
| 1292 | std.json.stringify(self, std.json.StringifyOptions{ .whitespace = null }, stderr) catch return; | |
| 1242 | 1293 | } |
| 1294 | }; | |
| 1243 | 1295 | |
| 1244 | pub fn dumpIndent(self: Value, comptime indent: usize) void { | |
| 1245 | if (indent == 0) { | |
| 1246 | self.dump(); | |
| 1247 | } else { | |
| 1248 | var held = std.debug.getStderrMutex().acquire(); | |
| 1249 | defer held.release(); | |
| 1250 | ||
| 1251 | const stderr = std.debug.getStderrStream(); | |
| 1252 | self.dumpStreamIndent(indent, stderr, 1024) catch return; | |
| 1253 | } | |
| 1296 | test "Value.jsonStringify" { | |
| 1297 | { | |
| 1298 | var buffer: [10]u8 = undefined; | |
| 1299 | var fbs = std.io.fixedBufferStream(&buffer); | |
| 1300 | try @as(Value, .Null).jsonStringify(.{}, fbs.outStream()); | |
| 1301 | testing.expectEqualSlices(u8, fbs.getWritten(), "null"); | |
| 1254 | 1302 | } |
| 1255 | ||
| 1256 | pub fn dumpStream(self: @This(), stream: var, comptime max_depth: usize) !void { | |
| 1257 | var w = std.json.WriteStream(@TypeOf(stream).Child, max_depth).init(stream); | |
| 1258 | w.newline = ""; | |
| 1259 | w.one_indent = ""; | |
| 1260 | w.space = ""; | |
| 1261 | try w.emitJson(self); | |
| 1303 | { | |
| 1304 | var buffer: [10]u8 = undefined; | |
| 1305 | var fbs = std.io.fixedBufferStream(&buffer); | |
| 1306 | try (Value{ .Bool = true }).jsonStringify(.{}, fbs.outStream()); | |
| 1307 | testing.expectEqualSlices(u8, fbs.getWritten(), "true"); | |
| 1262 | 1308 | } |
| 1263 | ||
| 1264 | pub fn dumpStreamIndent(self: @This(), comptime indent: usize, stream: var, comptime max_depth: usize) !void { | |
| 1265 | var one_indent = " " ** indent; | |
| 1266 | ||
| 1267 | var w = std.json.WriteStream(@TypeOf(stream).Child, max_depth).init(stream); | |
| 1268 | w.one_indent = one_indent; | |
| 1269 | try w.emitJson(self); | |
| 1309 | { | |
| 1310 | var buffer: [10]u8 = undefined; | |
| 1311 | var fbs = std.io.fixedBufferStream(&buffer); | |
| 1312 | try (Value{ .Integer = 42 }).jsonStringify(.{}, fbs.outStream()); | |
| 1313 | testing.expectEqualSlices(u8, fbs.getWritten(), "42"); | |
| 1270 | 1314 | } |
| 1271 | }; | |
| 1315 | { | |
| 1316 | var buffer: [10]u8 = undefined; | |
| 1317 | var fbs = std.io.fixedBufferStream(&buffer); | |
| 1318 | try (Value{ .Float = 42 }).jsonStringify(.{}, fbs.outStream()); | |
| 1319 | testing.expectEqualSlices(u8, fbs.getWritten(), "4.2e+01"); | |
| 1320 | } | |
| 1321 | { | |
| 1322 | var buffer: [10]u8 = undefined; | |
| 1323 | var fbs = std.io.fixedBufferStream(&buffer); | |
| 1324 | try (Value{ .String = "weeee" }).jsonStringify(.{}, fbs.outStream()); | |
| 1325 | testing.expectEqualSlices(u8, fbs.getWritten(), "\"weeee\""); | |
| 1326 | } | |
| 1327 | { | |
| 1328 | var buffer: [10]u8 = undefined; | |
| 1329 | var fbs = std.io.fixedBufferStream(&buffer); | |
| 1330 | try (Value{ | |
| 1331 | .Array = Array.fromOwnedSlice(undefined, &[_]Value{ | |
| 1332 | .{ .Integer = 1 }, | |
| 1333 | .{ .Integer = 2 }, | |
| 1334 | .{ .Integer = 3 }, | |
| 1335 | }), | |
| 1336 | }).jsonStringify(.{}, fbs.outStream()); | |
| 1337 | testing.expectEqualSlices(u8, fbs.getWritten(), "[1,2,3]"); | |
| 1338 | } | |
| 1339 | { | |
| 1340 | var buffer: [10]u8 = undefined; | |
| 1341 | var fbs = std.io.fixedBufferStream(&buffer); | |
| 1342 | var obj = ObjectMap.init(testing.allocator); | |
| 1343 | defer obj.deinit(); | |
| 1344 | try obj.putNoClobber("a", .{ .String = "b" }); | |
| 1345 | try (Value{ .Object = obj }).jsonStringify(.{}, fbs.outStream()); | |
| 1346 | testing.expectEqualSlices(u8, fbs.getWritten(), "{\"a\":\"b\"}"); | |
| 1347 | } | |
| 1348 | } | |
| 1272 | 1349 | |
| 1273 | 1350 | pub const ParseOptions = struct { |
| 1274 | 1351 | allocator: ?*Allocator = null, |
| ... | ... | @@ -1658,9 +1735,6 @@ test "parse into tagged union" { |
| 1658 | 1735 | } |
| 1659 | 1736 | |
| 1660 | 1737 | test "parseFree descends into tagged union" { |
| 1661 | // tagged unions are broken on arm64: https://github.com/ziglang/zig/issues/4492 | |
| 1662 | if (std.builtin.arch == .aarch64) return error.SkipZigTest; | |
| 1663 | ||
| 1664 | 1738 | var fail_alloc = testing.FailingAllocator.init(testing.allocator, 1); |
| 1665 | 1739 | const options = ParseOptions{ .allocator = &fail_alloc.allocator }; |
| 1666 | 1740 | const T = union(enum) { |
| ... | ... | @@ -1947,7 +2021,7 @@ pub const Parser = struct { |
| 1947 | 2021 | } |
| 1948 | 2022 | |
| 1949 | 2023 | fn pushToParent(p: *Parser, value: *const Value) !void { |
| 1950 | switch (p.stack.toSlice()[p.stack.len - 1]) { | |
| 2024 | switch (p.stack.span()[p.stack.len - 1]) { | |
| 1951 | 2025 | // Object Parent -> [ ..., object, <key>, value ] |
| 1952 | 2026 | Value.String => |key| { |
| 1953 | 2027 | _ = p.stack.pop(); |
| ... | ... | @@ -2244,11 +2318,86 @@ test "string copy option" { |
| 2244 | 2318 | } |
| 2245 | 2319 | |
| 2246 | 2320 | pub const StringifyOptions = struct { |
| 2247 | // TODO: indentation options? | |
| 2248 | // TODO: make escaping '/' in strings optional? | |
| 2249 | // TODO: allow picking if []u8 is string or array? | |
| 2321 | pub const Whitespace = struct { | |
| 2322 | /// How many indentation levels deep are we? | |
| 2323 | indent_level: usize = 0, | |
| 2324 | ||
| 2325 | pub const Indentation = union(enum) { | |
| 2326 | Space: u8, | |
| 2327 | Tab: void, | |
| 2328 | }; | |
| 2329 | ||
| 2330 | /// What character(s) should be used for indentation? | |
| 2331 | indent: Indentation = Indentation{ .Space = 4 }, | |
| 2332 | ||
| 2333 | fn outputIndent( | |
| 2334 | whitespace: @This(), | |
| 2335 | out_stream: var, | |
| 2336 | ) @TypeOf(out_stream).Error!void { | |
| 2337 | var char: u8 = undefined; | |
| 2338 | var n_chars: usize = undefined; | |
| 2339 | switch (whitespace.indent) { | |
| 2340 | .Space => |n_spaces| { | |
| 2341 | char = ' '; | |
| 2342 | n_chars = n_spaces; | |
| 2343 | }, | |
| 2344 | .Tab => { | |
| 2345 | char = '\t'; | |
| 2346 | n_chars = 1; | |
| 2347 | }, | |
| 2348 | } | |
| 2349 | n_chars *= whitespace.indent_level; | |
| 2350 | try out_stream.writeByteNTimes(char, n_chars); | |
| 2351 | } | |
| 2352 | ||
| 2353 | /// After a colon, should whitespace be inserted? | |
| 2354 | separator: bool = true, | |
| 2355 | }; | |
| 2356 | ||
| 2357 | /// Controls the whitespace emitted | |
| 2358 | whitespace: ?Whitespace = null, | |
| 2359 | ||
| 2360 | /// Should []u8 be serialised as a string? or an array? | |
| 2361 | pub const StringOptions = union(enum) { | |
| 2362 | Array, | |
| 2363 | ||
| 2364 | /// String output options | |
| 2365 | const StringOutputOptions = struct { | |
| 2366 | /// Should '/' be escaped in strings? | |
| 2367 | escape_solidus: bool = false, | |
| 2368 | ||
| 2369 | /// Should unicode characters be escaped in strings? | |
| 2370 | escape_unicode: bool = false, | |
| 2371 | }; | |
| 2372 | String: StringOutputOptions, | |
| 2373 | }; | |
| 2374 | ||
| 2375 | string: StringOptions = StringOptions{ .String = .{} }, | |
| 2250 | 2376 | }; |
| 2251 | 2377 | |
| 2378 | fn outputUnicodeEscape( | |
| 2379 | codepoint: u21, | |
| 2380 | out_stream: var, | |
| 2381 | ) !void { | |
| 2382 | if (codepoint <= 0xFFFF) { | |
| 2383 | // If the character is in the Basic Multilingual Plane (U+0000 through U+FFFF), | |
| 2384 | // then it may be represented as a six-character sequence: a reverse solidus, followed | |
| 2385 | // by the lowercase letter u, followed by four hexadecimal digits that encode the character's code point. | |
| 2386 | try out_stream.writeAll("\\u"); | |
| 2387 | try std.fmt.formatIntValue(codepoint, "x", std.fmt.FormatOptions{ .width = 4, .fill = '0' }, out_stream); | |
| 2388 | } else { | |
| 2389 | assert(codepoint <= 0x10FFFF); | |
| 2390 | // To escape an extended character that is not in the Basic Multilingual Plane, | |
| 2391 | // the character is represented as a 12-character sequence, encoding the UTF-16 surrogate pair. | |
| 2392 | const high = @intCast(u16, (codepoint - 0x10000) >> 10) + 0xD800; | |
| 2393 | const low = @intCast(u16, codepoint & 0x3FF) + 0xDC00; | |
| 2394 | try out_stream.writeAll("\\u"); | |
| 2395 | try std.fmt.formatIntValue(high, "x", std.fmt.FormatOptions{ .width = 4, .fill = '0' }, out_stream); | |
| 2396 | try out_stream.writeAll("\\u"); | |
| 2397 | try std.fmt.formatIntValue(low, "x", std.fmt.FormatOptions{ .width = 4, .fill = '0' }, out_stream); | |
| 2398 | } | |
| 2399 | } | |
| 2400 | ||
| 2252 | 2401 | pub fn stringify( |
| 2253 | 2402 | value: var, |
| 2254 | 2403 | options: StringifyOptions, |
| ... | ... | @@ -2265,11 +2414,14 @@ pub fn stringify( |
| 2265 | 2414 | .Bool => { |
| 2266 | 2415 | return out_stream.writeAll(if (value) "true" else "false"); |
| 2267 | 2416 | }, |
| 2417 | .Null => { | |
| 2418 | return out_stream.writeAll("null"); | |
| 2419 | }, | |
| 2268 | 2420 | .Optional => { |
| 2269 | 2421 | if (value) |payload| { |
| 2270 | 2422 | return try stringify(payload, options, out_stream); |
| 2271 | 2423 | } else { |
| 2272 | return out_stream.writeAll("null"); | |
| 2424 | return try stringify(null, options, out_stream); | |
| 2273 | 2425 | } |
| 2274 | 2426 | }, |
| 2275 | 2427 | .Enum => { |
| ... | ... | @@ -2300,8 +2452,12 @@ pub fn stringify( |
| 2300 | 2452 | return value.jsonStringify(options, out_stream); |
| 2301 | 2453 | } |
| 2302 | 2454 | |
| 2303 | try out_stream.writeAll("{"); | |
| 2455 | try out_stream.writeByte('{'); | |
| 2304 | 2456 | comptime var field_output = false; |
| 2457 | var child_options = options; | |
| 2458 | if (child_options.whitespace) |*child_whitespace| { | |
| 2459 | child_whitespace.indent_level += 1; | |
| 2460 | } | |
| 2305 | 2461 | inline for (S.fields) |Field, field_i| { |
| 2306 | 2462 | // don't include void fields |
| 2307 | 2463 | if (Field.field_type == void) continue; |
| ... | ... | @@ -2309,14 +2465,28 @@ pub fn stringify( |
| 2309 | 2465 | if (!field_output) { |
| 2310 | 2466 | field_output = true; |
| 2311 | 2467 | } else { |
| 2312 | try out_stream.writeAll(","); | |
| 2468 | try out_stream.writeByte(','); | |
| 2469 | } | |
| 2470 | if (child_options.whitespace) |child_whitespace| { | |
| 2471 | try out_stream.writeByte('\n'); | |
| 2472 | try child_whitespace.outputIndent(out_stream); | |
| 2313 | 2473 | } |
| 2314 | ||
| 2315 | 2474 | try stringify(Field.name, options, out_stream); |
| 2316 | try out_stream.writeAll(":"); | |
| 2317 | try stringify(@field(value, Field.name), options, out_stream); | |
| 2475 | try out_stream.writeByte(':'); | |
| 2476 | if (child_options.whitespace) |child_whitespace| { | |
| 2477 | if (child_whitespace.separator) { | |
| 2478 | try out_stream.writeByte(' '); | |
| 2479 | } | |
| 2480 | } | |
| 2481 | try stringify(@field(value, Field.name), child_options, out_stream); | |
| 2482 | } | |
| 2483 | if (field_output) { | |
| 2484 | if (options.whitespace) |whitespace| { | |
| 2485 | try out_stream.writeByte('\n'); | |
| 2486 | try whitespace.outputIndent(out_stream); | |
| 2487 | } | |
| 2318 | 2488 | } |
| 2319 | try out_stream.writeAll("}"); | |
| 2489 | try out_stream.writeByte('}'); | |
| 2320 | 2490 | return; |
| 2321 | 2491 | }, |
| 2322 | 2492 | .Pointer => |ptr_info| switch (ptr_info.size) { |
| ... | ... | @@ -2332,17 +2502,26 @@ pub fn stringify( |
| 2332 | 2502 | }, |
| 2333 | 2503 | // TODO: .Many when there is a sentinel (waiting for https://github.com/ziglang/zig/pull/3972) |
| 2334 | 2504 | .Slice => { |
| 2335 | if (ptr_info.child == u8 and std.unicode.utf8ValidateSlice(value)) { | |
| 2336 | try out_stream.writeAll("\""); | |
| 2505 | if (ptr_info.child == u8 and options.string == .String and std.unicode.utf8ValidateSlice(value)) { | |
| 2506 | try out_stream.writeByte('\"'); | |
| 2337 | 2507 | var i: usize = 0; |
| 2338 | 2508 | while (i < value.len) : (i += 1) { |
| 2339 | 2509 | switch (value[i]) { |
| 2340 | // normal ascii characters | |
| 2341 | 0x20...0x21, 0x23...0x2E, 0x30...0x5B, 0x5D...0x7F => try out_stream.writeAll(value[i .. i + 1]), | |
| 2342 | // control characters with short escapes | |
| 2510 | // normal ascii character | |
| 2511 | 0x20...0x21, 0x23...0x2E, 0x30...0x5B, 0x5D...0x7F => |c| try out_stream.writeByte(c), | |
| 2512 | // only 2 characters that *must* be escaped | |
| 2343 | 2513 | '\\' => try out_stream.writeAll("\\\\"), |
| 2344 | 2514 | '\"' => try out_stream.writeAll("\\\""), |
| 2345 | '/' => try out_stream.writeAll("\\/"), | |
| 2515 | // solidus is optional to escape | |
| 2516 | '/' => { | |
| 2517 | if (options.string.String.escape_solidus) { | |
| 2518 | try out_stream.writeAll("\\/"); | |
| 2519 | } else { | |
| 2520 | try out_stream.writeByte('\\'); | |
| 2521 | } | |
| 2522 | }, | |
| 2523 | // control characters with short escapes | |
| 2524 | // TODO: option to switch between unicode and 'short' forms? | |
| 2346 | 2525 | 0x8 => try out_stream.writeAll("\\b"), |
| 2347 | 2526 | 0xC => try out_stream.writeAll("\\f"), |
| 2348 | 2527 | '\n' => try out_stream.writeAll("\\n"), |
| ... | ... | @@ -2350,39 +2529,43 @@ pub fn stringify( |
| 2350 | 2529 | '\t' => try out_stream.writeAll("\\t"), |
| 2351 | 2530 | else => { |
| 2352 | 2531 | const ulen = std.unicode.utf8ByteSequenceLength(value[i]) catch unreachable; |
| 2353 | const codepoint = std.unicode.utf8Decode(value[i .. i + ulen]) catch unreachable; | |
| 2354 | if (codepoint <= 0xFFFF) { | |
| 2355 | // If the character is in the Basic Multilingual Plane (U+0000 through U+FFFF), | |
| 2356 | // then it may be represented as a six-character sequence: a reverse solidus, followed | |
| 2357 | // by the lowercase letter u, followed by four hexadecimal digits that encode the character's code point. | |
| 2358 | try out_stream.writeAll("\\u"); | |
| 2359 | try std.fmt.formatIntValue(codepoint, "x", std.fmt.FormatOptions{ .width = 4, .fill = '0' }, out_stream); | |
| 2532 | // control characters (only things left with 1 byte length) should always be printed as unicode escapes | |
| 2533 | if (ulen == 1 or options.string.String.escape_unicode) { | |
| 2534 | const codepoint = std.unicode.utf8Decode(value[i .. i + ulen]) catch unreachable; | |
| 2535 | try outputUnicodeEscape(codepoint, out_stream); | |
| 2360 | 2536 | } else { |
| 2361 | // To escape an extended character that is not in the Basic Multilingual Plane, | |
| 2362 | // the character is represented as a 12-character sequence, encoding the UTF-16 surrogate pair. | |
| 2363 | const high = @intCast(u16, (codepoint - 0x10000) >> 10) + 0xD800; | |
| 2364 | const low = @intCast(u16, codepoint & 0x3FF) + 0xDC00; | |
| 2365 | try out_stream.writeAll("\\u"); | |
| 2366 | try std.fmt.formatIntValue(high, "x", std.fmt.FormatOptions{ .width = 4, .fill = '0' }, out_stream); | |
| 2367 | try out_stream.writeAll("\\u"); | |
| 2368 | try std.fmt.formatIntValue(low, "x", std.fmt.FormatOptions{ .width = 4, .fill = '0' }, out_stream); | |
| 2537 | try out_stream.writeAll(value[i .. i + ulen]); | |
| 2369 | 2538 | } |
| 2370 | 2539 | i += ulen - 1; |
| 2371 | 2540 | }, |
| 2372 | 2541 | } |
| 2373 | 2542 | } |
| 2374 | try out_stream.writeAll("\""); | |
| 2543 | try out_stream.writeByte('\"'); | |
| 2375 | 2544 | return; |
| 2376 | 2545 | } |
| 2377 | 2546 | |
| 2378 | try out_stream.writeAll("["); | |
| 2547 | try out_stream.writeByte('['); | |
| 2548 | var child_options = options; | |
| 2549 | if (child_options.whitespace) |*whitespace| { | |
| 2550 | whitespace.indent_level += 1; | |
| 2551 | } | |
| 2379 | 2552 | for (value) |x, i| { |
| 2380 | 2553 | if (i != 0) { |
| 2381 | try out_stream.writeAll(","); | |
| 2554 | try out_stream.writeByte(','); | |
| 2555 | } | |
| 2556 | if (child_options.whitespace) |child_whitespace| { | |
| 2557 | try out_stream.writeByte('\n'); | |
| 2558 | try child_whitespace.outputIndent(out_stream); | |
| 2382 | 2559 | } |
| 2383 | try stringify(x, options, out_stream); | |
| 2560 | try stringify(x, child_options, out_stream); | |
| 2384 | 2561 | } |
| 2385 | try out_stream.writeAll("]"); | |
| 2562 | if (value.len != 0) { | |
| 2563 | if (options.whitespace) |whitespace| { | |
| 2564 | try out_stream.writeByte('\n'); | |
| 2565 | try whitespace.outputIndent(out_stream); | |
| 2566 | } | |
| 2567 | } | |
| 2568 | try out_stream.writeByte(']'); | |
| 2386 | 2569 | return; |
| 2387 | 2570 | }, |
| 2388 | 2571 | else => @compileError("Unable to stringify type '" ++ @typeName(T) ++ "'"), |
| ... | ... | @@ -2393,7 +2576,7 @@ pub fn stringify( |
| 2393 | 2576 | unreachable; |
| 2394 | 2577 | } |
| 2395 | 2578 | |
| 2396 | fn teststringify(expected: []const u8, value: var) !void { | |
| 2579 | fn teststringify(expected: []const u8, value: var, options: StringifyOptions) !void { | |
| 2397 | 2580 | const ValidationOutStream = struct { |
| 2398 | 2581 | const Self = @This(); |
| 2399 | 2582 | pub const OutStream = std.io.OutStream(*Self, Error, write); |
| ... | ... | @@ -2445,55 +2628,105 @@ fn teststringify(expected: []const u8, value: var) !void { |
| 2445 | 2628 | }; |
| 2446 | 2629 | |
| 2447 | 2630 | var vos = ValidationOutStream.init(expected); |
| 2448 | try stringify(value, StringifyOptions{}, vos.outStream()); | |
| 2631 | try stringify(value, options, vos.outStream()); | |
| 2449 | 2632 | if (vos.expected_remaining.len > 0) return error.NotEnoughData; |
| 2450 | 2633 | } |
| 2451 | 2634 | |
| 2452 | 2635 | test "stringify basic types" { |
| 2453 | try teststringify("false", false); | |
| 2454 | try teststringify("true", true); | |
| 2455 | try teststringify("null", @as(?u8, null)); | |
| 2456 | try teststringify("null", @as(?*u32, null)); | |
| 2457 | try teststringify("42", 42); | |
| 2458 | try teststringify("4.2e+01", 42.0); | |
| 2459 | try teststringify("42", @as(u8, 42)); | |
| 2460 | try teststringify("42", @as(u128, 42)); | |
| 2461 | try teststringify("4.2e+01", @as(f32, 42)); | |
| 2462 | try teststringify("4.2e+01", @as(f64, 42)); | |
| 2636 | try teststringify("false", false, StringifyOptions{}); | |
| 2637 | try teststringify("true", true, StringifyOptions{}); | |
| 2638 | try teststringify("null", @as(?u8, null), StringifyOptions{}); | |
| 2639 | try teststringify("null", @as(?*u32, null), StringifyOptions{}); | |
| 2640 | try teststringify("42", 42, StringifyOptions{}); | |
| 2641 | try teststringify("4.2e+01", 42.0, StringifyOptions{}); | |
| 2642 | try teststringify("42", @as(u8, 42), StringifyOptions{}); | |
| 2643 | try teststringify("42", @as(u128, 42), StringifyOptions{}); | |
| 2644 | try teststringify("4.2e+01", @as(f32, 42), StringifyOptions{}); | |
| 2645 | try teststringify("4.2e+01", @as(f64, 42), StringifyOptions{}); | |
| 2463 | 2646 | } |
| 2464 | 2647 | |
| 2465 | 2648 | test "stringify string" { |
| 2466 | try teststringify("\"hello\"", "hello"); | |
| 2467 | try teststringify("\"with\\nescapes\\r\"", "with\nescapes\r"); | |
| 2468 | try teststringify("\"with unicode\\u0001\"", "with unicode\u{1}"); | |
| 2469 | try teststringify("\"with unicode\\u0080\"", "with unicode\u{80}"); | |
| 2470 | try teststringify("\"with unicode\\u00ff\"", "with unicode\u{FF}"); | |
| 2471 | try teststringify("\"with unicode\\u0100\"", "with unicode\u{100}"); | |
| 2472 | try teststringify("\"with unicode\\u0800\"", "with unicode\u{800}"); | |
| 2473 | try teststringify("\"with unicode\\u8000\"", "with unicode\u{8000}"); | |
| 2474 | try teststringify("\"with unicode\\ud799\"", "with unicode\u{D799}"); | |
| 2475 | try teststringify("\"with unicode\\ud800\\udc00\"", "with unicode\u{10000}"); | |
| 2476 | try teststringify("\"with unicode\\udbff\\udfff\"", "with unicode\u{10FFFF}"); | |
| 2649 | try teststringify("\"hello\"", "hello", StringifyOptions{}); | |
| 2650 | try teststringify("\"with\\nescapes\\r\"", "with\nescapes\r", StringifyOptions{}); | |
| 2651 | try teststringify("\"with\\nescapes\\r\"", "with\nescapes\r", StringifyOptions{ .string = .{ .String = .{ .escape_unicode = true } } }); | |
| 2652 | try teststringify("\"with unicode\\u0001\"", "with unicode\u{1}", StringifyOptions{}); | |
| 2653 | try teststringify("\"with unicode\\u0001\"", "with unicode\u{1}", StringifyOptions{ .string = .{ .String = .{ .escape_unicode = true } } }); | |
| 2654 | try teststringify("\"with unicode\u{80}\"", "with unicode\u{80}", StringifyOptions{}); | |
| 2655 | try teststringify("\"with unicode\\u0080\"", "with unicode\u{80}", StringifyOptions{ .string = .{ .String = .{ .escape_unicode = true } } }); | |
| 2656 | try teststringify("\"with unicode\u{FF}\"", "with unicode\u{FF}", StringifyOptions{}); | |
| 2657 | try teststringify("\"with unicode\\u00ff\"", "with unicode\u{FF}", StringifyOptions{ .string = .{ .String = .{ .escape_unicode = true } } }); | |
| 2658 | try teststringify("\"with unicode\u{100}\"", "with unicode\u{100}", StringifyOptions{}); | |
| 2659 | try teststringify("\"with unicode\\u0100\"", "with unicode\u{100}", StringifyOptions{ .string = .{ .String = .{ .escape_unicode = true } } }); | |
| 2660 | try teststringify("\"with unicode\u{800}\"", "with unicode\u{800}", StringifyOptions{}); | |
| 2661 | try teststringify("\"with unicode\\u0800\"", "with unicode\u{800}", StringifyOptions{ .string = .{ .String = .{ .escape_unicode = true } } }); | |
| 2662 | try teststringify("\"with unicode\u{8000}\"", "with unicode\u{8000}", StringifyOptions{}); | |
| 2663 | try teststringify("\"with unicode\\u8000\"", "with unicode\u{8000}", StringifyOptions{ .string = .{ .String = .{ .escape_unicode = true } } }); | |
| 2664 | try teststringify("\"with unicode\u{D799}\"", "with unicode\u{D799}", StringifyOptions{}); | |
| 2665 | try teststringify("\"with unicode\\ud799\"", "with unicode\u{D799}", StringifyOptions{ .string = .{ .String = .{ .escape_unicode = true } } }); | |
| 2666 | try teststringify("\"with unicode\u{10000}\"", "with unicode\u{10000}", StringifyOptions{}); | |
| 2667 | try teststringify("\"with unicode\\ud800\\udc00\"", "with unicode\u{10000}", StringifyOptions{ .string = .{ .String = .{ .escape_unicode = true } } }); | |
| 2668 | try teststringify("\"with unicode\u{10FFFF}\"", "with unicode\u{10FFFF}", StringifyOptions{}); | |
| 2669 | try teststringify("\"with unicode\\udbff\\udfff\"", "with unicode\u{10FFFF}", StringifyOptions{ .string = .{ .String = .{ .escape_unicode = true } } }); | |
| 2477 | 2670 | } |
| 2478 | 2671 | |
| 2479 | 2672 | test "stringify tagged unions" { |
| 2480 | 2673 | try teststringify("42", union(enum) { |
| 2481 | 2674 | Foo: u32, |
| 2482 | 2675 | Bar: bool, |
| 2483 | }{ .Foo = 42 }); | |
| 2676 | }{ .Foo = 42 }, StringifyOptions{}); | |
| 2484 | 2677 | } |
| 2485 | 2678 | |
| 2486 | 2679 | test "stringify struct" { |
| 2487 | 2680 | try teststringify("{\"foo\":42}", struct { |
| 2488 | 2681 | foo: u32, |
| 2489 | }{ .foo = 42 }); | |
| 2682 | }{ .foo = 42 }, StringifyOptions{}); | |
| 2683 | } | |
| 2684 | ||
| 2685 | test "stringify struct with indentation" { | |
| 2686 | try teststringify( | |
| 2687 | \\{ | |
| 2688 | \\ "foo": 42, | |
| 2689 | \\ "bar": [ | |
| 2690 | \\ 1, | |
| 2691 | \\ 2, | |
| 2692 | \\ 3 | |
| 2693 | \\ ] | |
| 2694 | \\} | |
| 2695 | , | |
| 2696 | struct { | |
| 2697 | foo: u32, | |
| 2698 | bar: [3]u32, | |
| 2699 | }{ | |
| 2700 | .foo = 42, | |
| 2701 | .bar = .{ 1, 2, 3 }, | |
| 2702 | }, | |
| 2703 | StringifyOptions{ | |
| 2704 | .whitespace = .{}, | |
| 2705 | }, | |
| 2706 | ); | |
| 2707 | try teststringify( | |
| 2708 | "{\n\t\"foo\":42,\n\t\"bar\":[\n\t\t1,\n\t\t2,\n\t\t3\n\t]\n}", | |
| 2709 | struct { | |
| 2710 | foo: u32, | |
| 2711 | bar: [3]u32, | |
| 2712 | }{ | |
| 2713 | .foo = 42, | |
| 2714 | .bar = .{ 1, 2, 3 }, | |
| 2715 | }, | |
| 2716 | StringifyOptions{ | |
| 2717 | .whitespace = .{ | |
| 2718 | .indent = .Tab, | |
| 2719 | .separator = false, | |
| 2720 | }, | |
| 2721 | }, | |
| 2722 | ); | |
| 2490 | 2723 | } |
| 2491 | 2724 | |
| 2492 | 2725 | test "stringify struct with void field" { |
| 2493 | 2726 | try teststringify("{\"foo\":42}", struct { |
| 2494 | 2727 | foo: u32, |
| 2495 | 2728 | bar: void = {}, |
| 2496 | }{ .foo = 42 }); | |
| 2729 | }{ .foo = 42 }, StringifyOptions{}); | |
| 2497 | 2730 | } |
| 2498 | 2731 | |
| 2499 | 2732 | test "stringify array of structs" { |
| ... | ... | @@ -2504,7 +2737,7 @@ test "stringify array of structs" { |
| 2504 | 2737 | MyStruct{ .foo = 42 }, |
| 2505 | 2738 | MyStruct{ .foo = 100 }, |
| 2506 | 2739 | MyStruct{ .foo = 1000 }, |
| 2507 | }); | |
| 2740 | }, StringifyOptions{}); | |
| 2508 | 2741 | } |
| 2509 | 2742 | |
| 2510 | 2743 | test "stringify struct with custom stringifier" { |
| ... | ... | @@ -2518,7 +2751,7 @@ test "stringify struct with custom stringifier" { |
| 2518 | 2751 | ) !void { |
| 2519 | 2752 | try out_stream.writeAll("[\"something special\","); |
| 2520 | 2753 | try stringify(42, options, out_stream); |
| 2521 | try out_stream.writeAll("]"); | |
| 2754 | try out_stream.writeByte(']'); | |
| 2522 | 2755 | } |
| 2523 | }{ .foo = 42 }); | |
| 2756 | }{ .foo = 42 }, StringifyOptions{}); | |
| 2524 | 2757 | } |
lib/std/json/test.zig+3-5| ... | ... | @@ -1751,11 +1751,9 @@ test "i_number_double_huge_neg_exp" { |
| 1751 | 1751 | } |
| 1752 | 1752 | |
| 1753 | 1753 | test "i_number_huge_exp" { |
| 1754 | return error.SkipZigTest; | |
| 1755 | // FIXME Integer overflow in parseFloat | |
| 1756 | // any( | |
| 1757 | // \\[0.4e00669999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999969999999006] | |
| 1758 | // ); | |
| 1754 | any( | |
| 1755 | \\[0.4e00669999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999969999999006] | |
| 1756 | ); | |
| 1759 | 1757 | } |
| 1760 | 1758 | |
| 1761 | 1759 | test "i_number_neg_int_huge_exp" { |
lib/std/json/write_stream.zig+27-59| ... | ... | @@ -21,14 +21,10 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type { |
| 21 | 21 | |
| 22 | 22 | pub const Stream = OutStream; |
| 23 | 23 | |
| 24 | /// The string used for indenting. | |
| 25 | one_indent: []const u8 = " ", | |
| 26 | ||
| 27 | /// The string used as a newline character. | |
| 28 | newline: []const u8 = "\n", | |
| 29 | ||
| 30 | /// The string used as spacing. | |
| 31 | space: []const u8 = " ", | |
| 24 | whitespace: std.json.StringifyOptions.Whitespace = std.json.StringifyOptions.Whitespace{ | |
| 25 | .indent_level = 0, | |
| 26 | .indent = .{ .Space = 1 }, | |
| 27 | }, | |
| 32 | 28 | |
| 33 | 29 | stream: OutStream, |
| 34 | 30 | state_index: usize, |
| ... | ... | @@ -49,12 +45,14 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type { |
| 49 | 45 | assert(self.state[self.state_index] == State.Value); // need to call arrayElem or objectField |
| 50 | 46 | try self.stream.writeByte('['); |
| 51 | 47 | self.state[self.state_index] = State.ArrayStart; |
| 48 | self.whitespace.indent_level += 1; | |
| 52 | 49 | } |
| 53 | 50 | |
| 54 | 51 | pub fn beginObject(self: *Self) !void { |
| 55 | 52 | assert(self.state[self.state_index] == State.Value); // need to call arrayElem or objectField |
| 56 | 53 | try self.stream.writeByte('{'); |
| 57 | 54 | self.state[self.state_index] = State.ObjectStart; |
| 55 | self.whitespace.indent_level += 1; | |
| 58 | 56 | } |
| 59 | 57 | |
| 60 | 58 | pub fn arrayElem(self: *Self) !void { |
| ... | ... | @@ -90,8 +88,10 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type { |
| 90 | 88 | self.pushState(.Value); |
| 91 | 89 | try self.indent(); |
| 92 | 90 | try self.writeEscapedString(name); |
| 93 | try self.stream.writeAll(":"); | |
| 94 | try self.stream.writeAll(self.space); | |
| 91 | try self.stream.writeByte(':'); | |
| 92 | if (self.whitespace.separator) { | |
| 93 | try self.stream.writeByte(' '); | |
| 94 | } | |
| 95 | 95 | }, |
| 96 | 96 | } |
| 97 | 97 | } |
| ... | ... | @@ -103,10 +103,12 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type { |
| 103 | 103 | .ObjectStart => unreachable, |
| 104 | 104 | .Object => unreachable, |
| 105 | 105 | .ArrayStart => { |
| 106 | self.whitespace.indent_level -= 1; | |
| 106 | 107 | try self.stream.writeByte(']'); |
| 107 | 108 | self.popState(); |
| 108 | 109 | }, |
| 109 | 110 | .Array => { |
| 111 | self.whitespace.indent_level -= 1; | |
| 110 | 112 | try self.indent(); |
| 111 | 113 | self.popState(); |
| 112 | 114 | try self.stream.writeByte(']'); |
| ... | ... | @@ -121,10 +123,12 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type { |
| 121 | 123 | .ArrayStart => unreachable, |
| 122 | 124 | .Array => unreachable, |
| 123 | 125 | .ObjectStart => { |
| 126 | self.whitespace.indent_level -= 1; | |
| 124 | 127 | try self.stream.writeByte('}'); |
| 125 | 128 | self.popState(); |
| 126 | 129 | }, |
| 127 | 130 | .Object => { |
| 131 | self.whitespace.indent_level -= 1; | |
| 128 | 132 | try self.indent(); |
| 129 | 133 | self.popState(); |
| 130 | 134 | try self.stream.writeByte('}'); |
| ... | ... | @@ -134,17 +138,13 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type { |
| 134 | 138 | |
| 135 | 139 | pub fn emitNull(self: *Self) !void { |
| 136 | 140 | assert(self.state[self.state_index] == State.Value); |
| 137 | try self.stream.writeAll("null"); | |
| 141 | try self.stringify(null); | |
| 138 | 142 | self.popState(); |
| 139 | 143 | } |
| 140 | 144 | |
| 141 | 145 | pub fn emitBool(self: *Self, value: bool) !void { |
| 142 | 146 | assert(self.state[self.state_index] == State.Value); |
| 143 | if (value) { | |
| 144 | try self.stream.writeAll("true"); | |
| 145 | } else { | |
| 146 | try self.stream.writeAll("false"); | |
| 147 | } | |
| 147 | try self.stringify(value); | |
| 148 | 148 | self.popState(); |
| 149 | 149 | } |
| 150 | 150 | |
| ... | ... | @@ -185,57 +185,19 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type { |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | fn writeEscapedString(self: *Self, string: []const u8) !void { |
| 188 | try self.stream.writeByte('"'); | |
| 189 | for (string) |s| { | |
| 190 | switch (s) { | |
| 191 | '"' => try self.stream.writeAll("\\\""), | |
| 192 | '\t' => try self.stream.writeAll("\\t"), | |
| 193 | '\r' => try self.stream.writeAll("\\r"), | |
| 194 | '\n' => try self.stream.writeAll("\\n"), | |
| 195 | 8 => try self.stream.writeAll("\\b"), | |
| 196 | 12 => try self.stream.writeAll("\\f"), | |
| 197 | '\\' => try self.stream.writeAll("\\\\"), | |
| 198 | else => try self.stream.writeByte(s), | |
| 199 | } | |
| 200 | } | |
| 201 | try self.stream.writeByte('"'); | |
| 188 | assert(std.unicode.utf8ValidateSlice(string)); | |
| 189 | try self.stringify(string); | |
| 202 | 190 | } |
| 203 | 191 | |
| 204 | 192 | /// Writes the complete json into the output stream |
| 205 | 193 | pub fn emitJson(self: *Self, json: std.json.Value) Stream.Error!void { |
| 206 | switch (json) { | |
| 207 | .Null => try self.emitNull(), | |
| 208 | .Bool => |inner| try self.emitBool(inner), | |
| 209 | .Integer => |inner| try self.emitNumber(inner), | |
| 210 | .Float => |inner| try self.emitNumber(inner), | |
| 211 | .String => |inner| try self.emitString(inner), | |
| 212 | .Array => |inner| { | |
| 213 | try self.beginArray(); | |
| 214 | for (inner.toSliceConst()) |elem| { | |
| 215 | try self.arrayElem(); | |
| 216 | try self.emitJson(elem); | |
| 217 | } | |
| 218 | try self.endArray(); | |
| 219 | }, | |
| 220 | .Object => |inner| { | |
| 221 | try self.beginObject(); | |
| 222 | var it = inner.iterator(); | |
| 223 | while (it.next()) |entry| { | |
| 224 | try self.objectField(entry.key); | |
| 225 | try self.emitJson(entry.value); | |
| 226 | } | |
| 227 | try self.endObject(); | |
| 228 | }, | |
| 229 | } | |
| 194 | try self.stringify(json); | |
| 230 | 195 | } |
| 231 | 196 | |
| 232 | 197 | fn indent(self: *Self) !void { |
| 233 | 198 | assert(self.state_index >= 1); |
| 234 | try self.stream.writeAll(self.newline); | |
| 235 | var i: usize = 0; | |
| 236 | while (i < self.state_index - 1) : (i += 1) { | |
| 237 | try self.stream.writeAll(self.one_indent); | |
| 238 | } | |
| 199 | try self.stream.writeByte('\n'); | |
| 200 | try self.whitespace.outputIndent(self.stream); | |
| 239 | 201 | } |
| 240 | 202 | |
| 241 | 203 | fn pushState(self: *Self, state: State) void { |
| ... | ... | @@ -246,6 +208,12 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type { |
| 246 | 208 | fn popState(self: *Self) void { |
| 247 | 209 | self.state_index -= 1; |
| 248 | 210 | } |
| 211 | ||
| 212 | fn stringify(self: *Self, value: var) !void { | |
| 213 | try std.json.stringify(value, std.json.StringifyOptions{ | |
| 214 | .whitespace = self.whitespace, | |
| 215 | }, self.stream); | |
| 216 | } | |
| 249 | 217 | }; |
| 250 | 218 | } |
| 251 | 219 |
lib/std/mem.zig+51-28| ... | ... | @@ -341,11 +341,7 @@ pub fn zeroes(comptime T: type) T { |
| 341 | 341 | } |
| 342 | 342 | }, |
| 343 | 343 | .Array => |info| { |
| 344 | var array: T = undefined; | |
| 345 | for (array) |*element| { | |
| 346 | element.* = zeroes(info.child); | |
| 347 | } | |
| 348 | return array; | |
| 344 | return [_]info.child{zeroes(info.child)} ** info.len; | |
| 349 | 345 | }, |
| 350 | 346 | .Vector, |
| 351 | 347 | .ErrorUnion, |
| ... | ... | @@ -496,15 +492,8 @@ pub fn eql(comptime T: type, a: []const T, b: []const T) bool { |
| 496 | 492 | return true; |
| 497 | 493 | } |
| 498 | 494 | |
| 499 | /// Deprecated. Use `spanZ`. | |
| 500 | pub fn toSliceConst(comptime T: type, ptr: [*:0]const T) [:0]const T { | |
| 501 | return ptr[0..lenZ(ptr) :0]; | |
| 502 | } | |
| 503 | ||
| 504 | /// Deprecated. Use `spanZ`. | |
| 505 | pub fn toSlice(comptime T: type, ptr: [*:0]T) [:0]T { | |
| 506 | return ptr[0..lenZ(ptr) :0]; | |
| 507 | } | |
| 495 | pub const toSliceConst = @compileError("deprecated; use std.mem.spanZ"); | |
| 496 | pub const toSlice = @compileError("deprecated; use std.mem.spanZ"); | |
| 508 | 497 | |
| 509 | 498 | /// Takes a pointer to an array, a sentinel-terminated pointer, or a slice, and |
| 510 | 499 | /// returns a slice. If there is a sentinel on the input type, there will be a |
| ... | ... | @@ -512,36 +501,54 @@ pub fn toSlice(comptime T: type, ptr: [*:0]T) [:0]T { |
| 512 | 501 | /// the constness of the input type. `[*c]` pointers are assumed to be 0-terminated, |
| 513 | 502 | /// and assumed to not allow null. |
| 514 | 503 | pub fn Span(comptime T: type) type { |
| 515 | var ptr_info = @typeInfo(T).Pointer; | |
| 516 | switch (ptr_info.size) { | |
| 517 | .One => switch (@typeInfo(ptr_info.child)) { | |
| 518 | .Array => |info| { | |
| 519 | ptr_info.child = info.child; | |
| 520 | ptr_info.sentinel = info.sentinel; | |
| 521 | }, | |
| 522 | else => @compileError("invalid type given to std.mem.Span"), | |
| 504 | switch(@typeInfo(T)) { | |
| 505 | .Optional => |optional_info| { | |
| 506 | return ?Span(optional_info.child); | |
| 523 | 507 | }, |
| 524 | .C => { | |
| 525 | ptr_info.sentinel = 0; | |
| 526 | ptr_info.is_allowzero = false; | |
| 508 | .Pointer => |ptr_info| { | |
| 509 | var new_ptr_info = ptr_info; | |
| 510 | switch (ptr_info.size) { | |
| 511 | .One => switch (@typeInfo(ptr_info.child)) { | |
| 512 | .Array => |info| { | |
| 513 | new_ptr_info.child = info.child; | |
| 514 | new_ptr_info.sentinel = info.sentinel; | |
| 515 | }, | |
| 516 | else => @compileError("invalid type given to std.mem.Span"), | |
| 517 | }, | |
| 518 | .C => { | |
| 519 | new_ptr_info.sentinel = 0; | |
| 520 | new_ptr_info.is_allowzero = false; | |
| 521 | }, | |
| 522 | .Many, .Slice => {}, | |
| 523 | } | |
| 524 | new_ptr_info.size = .Slice; | |
| 525 | return @Type(std.builtin.TypeInfo{ .Pointer = new_ptr_info }); | |
| 527 | 526 | }, |
| 528 | .Many, .Slice => {}, | |
| 527 | else => @compileError("invalid type given to std.mem.Span"), | |
| 529 | 528 | } |
| 530 | ptr_info.size = .Slice; | |
| 531 | return @Type(std.builtin.TypeInfo{ .Pointer = ptr_info }); | |
| 532 | 529 | } |
| 533 | 530 | |
| 534 | 531 | test "Span" { |
| 535 | 532 | testing.expect(Span(*[5]u16) == []u16); |
| 533 | testing.expect(Span(?*[5]u16) == ?[]u16); | |
| 536 | 534 | testing.expect(Span(*const [5]u16) == []const u16); |
| 535 | testing.expect(Span(?*const [5]u16) == ?[]const u16); | |
| 537 | 536 | testing.expect(Span([]u16) == []u16); |
| 537 | testing.expect(Span(?[]u16) == ?[]u16); | |
| 538 | 538 | testing.expect(Span([]const u8) == []const u8); |
| 539 | testing.expect(Span(?[]const u8) == ?[]const u8); | |
| 539 | 540 | testing.expect(Span([:1]u16) == [:1]u16); |
| 541 | testing.expect(Span(?[:1]u16) == ?[:1]u16); | |
| 540 | 542 | testing.expect(Span([:1]const u8) == [:1]const u8); |
| 543 | testing.expect(Span(?[:1]const u8) == ?[:1]const u8); | |
| 541 | 544 | testing.expect(Span([*:1]u16) == [:1]u16); |
| 545 | testing.expect(Span(?[*:1]u16) == ?[:1]u16); | |
| 542 | 546 | testing.expect(Span([*:1]const u8) == [:1]const u8); |
| 547 | testing.expect(Span(?[*:1]const u8) == ?[:1]const u8); | |
| 543 | 548 | testing.expect(Span([*c]u16) == [:0]u16); |
| 549 | testing.expect(Span(?[*c]u16) == ?[:0]u16); | |
| 544 | 550 | testing.expect(Span([*c]const u8) == [:0]const u8); |
| 551 | testing.expect(Span(?[*c]const u8) == ?[:0]const u8); | |
| 545 | 552 | } |
| 546 | 553 | |
| 547 | 554 | /// Takes a pointer to an array, a sentinel-terminated pointer, or a slice, and |
| ... | ... | @@ -552,6 +559,13 @@ test "Span" { |
| 552 | 559 | /// When there is both a sentinel and an array length or slice length, the |
| 553 | 560 | /// length value is used instead of the sentinel. |
| 554 | 561 | pub fn span(ptr: var) Span(@TypeOf(ptr)) { |
| 562 | if (@typeInfo(@TypeOf(ptr)) == .Optional) { | |
| 563 | if (ptr) |non_null| { | |
| 564 | return span(non_null); | |
| 565 | } else { | |
| 566 | return null; | |
| 567 | } | |
| 568 | } | |
| 555 | 569 | const Result = Span(@TypeOf(ptr)); |
| 556 | 570 | const l = len(ptr); |
| 557 | 571 | if (@typeInfo(Result).Pointer.sentinel) |s| { |
| ... | ... | @@ -566,12 +580,20 @@ test "span" { |
| 566 | 580 | const ptr = @as([*:3]u16, array[0..2 :3]); |
| 567 | 581 | testing.expect(eql(u16, span(ptr), &[_]u16{ 1, 2 })); |
| 568 | 582 | testing.expect(eql(u16, span(&array), &[_]u16{ 1, 2, 3, 4, 5 })); |
| 583 | testing.expectEqual(@as(?[:0]u16, null), span(@as(?[*:0]u16, null))); | |
| 569 | 584 | } |
| 570 | 585 | |
| 571 | 586 | /// Same as `span`, except when there is both a sentinel and an array |
| 572 | 587 | /// length or slice length, scans the memory for the sentinel value |
| 573 | 588 | /// rather than using the length. |
| 574 | 589 | pub fn spanZ(ptr: var) Span(@TypeOf(ptr)) { |
| 590 | if (@typeInfo(@TypeOf(ptr)) == .Optional) { | |
| 591 | if (ptr) |non_null| { | |
| 592 | return spanZ(non_null); | |
| 593 | } else { | |
| 594 | return null; | |
| 595 | } | |
| 596 | } | |
| 575 | 597 | const Result = Span(@TypeOf(ptr)); |
| 576 | 598 | const l = lenZ(ptr); |
| 577 | 599 | if (@typeInfo(Result).Pointer.sentinel) |s| { |
| ... | ... | @@ -586,6 +608,7 @@ test "spanZ" { |
| 586 | 608 | const ptr = @as([*:3]u16, array[0..2 :3]); |
| 587 | 609 | testing.expect(eql(u16, spanZ(ptr), &[_]u16{ 1, 2 })); |
| 588 | 610 | testing.expect(eql(u16, spanZ(&array), &[_]u16{ 1, 2, 3, 4, 5 })); |
| 611 | testing.expectEqual(@as(?[:0]u16, null), spanZ(@as(?[*:0]u16, null))); | |
| 589 | 612 | } |
| 590 | 613 | |
| 591 | 614 | /// Takes a pointer to an array, an array, a sentinel-terminated pointer, |
lib/std/net.zig+26-27| ... | ... | @@ -397,13 +397,12 @@ pub const AddressList = struct { |
| 397 | 397 | |
| 398 | 398 | /// All memory allocated with `allocator` will be freed before this function returns. |
| 399 | 399 | pub fn tcpConnectToHost(allocator: *mem.Allocator, name: []const u8, port: u16) !fs.File { |
| 400 | const list = getAddressList(allocator, name, port); | |
| 400 | const list = try getAddressList(allocator, name, port); | |
| 401 | 401 | defer list.deinit(); |
| 402 | 402 | |
| 403 | const addrs = list.addrs.toSliceConst(); | |
| 404 | if (addrs.len == 0) return error.UnknownHostName; | |
| 403 | if (list.addrs.len == 0) return error.UnknownHostName; | |
| 405 | 404 | |
| 406 | return tcpConnectToAddress(addrs[0], port); | |
| 405 | return tcpConnectToAddress(list.addrs[0]); | |
| 407 | 406 | } |
| 408 | 407 | |
| 409 | 408 | pub fn tcpConnectToAddress(address: Address) !fs.File { |
| ... | ... | @@ -491,7 +490,7 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !* |
| 491 | 490 | |
| 492 | 491 | if (info.canonname) |n| { |
| 493 | 492 | if (result.canon_name == null) { |
| 494 | result.canon_name = try mem.dupe(arena, u8, mem.toSliceConst(u8, n)); | |
| 493 | result.canon_name = try mem.dupe(arena, u8, mem.spanZ(n)); | |
| 495 | 494 | } |
| 496 | 495 | } |
| 497 | 496 | i += 1; |
| ... | ... | @@ -505,7 +504,7 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !* |
| 505 | 504 | var lookup_addrs = std.ArrayList(LookupAddr).init(allocator); |
| 506 | 505 | defer lookup_addrs.deinit(); |
| 507 | 506 | |
| 508 | var canon = std.Buffer.initNull(arena); | |
| 507 | var canon = std.ArrayListSentineled(u8, 0).initNull(arena); | |
| 509 | 508 | defer canon.deinit(); |
| 510 | 509 | |
| 511 | 510 | try linuxLookupName(&lookup_addrs, &canon, name, family, flags, port); |
| ... | ... | @@ -515,7 +514,7 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !* |
| 515 | 514 | result.canon_name = canon.toOwnedSlice(); |
| 516 | 515 | } |
| 517 | 516 | |
| 518 | for (lookup_addrs.toSliceConst()) |lookup_addr, i| { | |
| 517 | for (lookup_addrs.span()) |lookup_addr, i| { | |
| 519 | 518 | result.addrs[i] = lookup_addr.addr; |
| 520 | 519 | assert(result.addrs[i].getPort() == port); |
| 521 | 520 | } |
| ... | ... | @@ -540,7 +539,7 @@ const DAS_ORDER_SHIFT = 0; |
| 540 | 539 | |
| 541 | 540 | fn linuxLookupName( |
| 542 | 541 | addrs: *std.ArrayList(LookupAddr), |
| 543 | canon: *std.Buffer, | |
| 542 | canon: *std.ArrayListSentineled(u8, 0), | |
| 544 | 543 | opt_name: ?[]const u8, |
| 545 | 544 | family: os.sa_family_t, |
| 546 | 545 | flags: u32, |
| ... | ... | @@ -568,7 +567,7 @@ fn linuxLookupName( |
| 568 | 567 | // No further processing is needed if there are fewer than 2 |
| 569 | 568 | // results or if there are only IPv4 results. |
| 570 | 569 | if (addrs.len == 1 or family == os.AF_INET) return; |
| 571 | const all_ip4 = for (addrs.toSliceConst()) |addr| { | |
| 570 | const all_ip4 = for (addrs.span()) |addr| { | |
| 572 | 571 | if (addr.addr.any.family != os.AF_INET) break false; |
| 573 | 572 | } else true; |
| 574 | 573 | if (all_ip4) return; |
| ... | ... | @@ -580,7 +579,7 @@ fn linuxLookupName( |
| 580 | 579 | // So far the label/precedence table cannot be customized. |
| 581 | 580 | // This implementation is ported from musl libc. |
| 582 | 581 | // A more idiomatic "ziggy" implementation would be welcome. |
| 583 | for (addrs.toSlice()) |*addr, i| { | |
| 582 | for (addrs.span()) |*addr, i| { | |
| 584 | 583 | var key: i32 = 0; |
| 585 | 584 | var sa6: os.sockaddr_in6 = undefined; |
| 586 | 585 | @memset(@ptrCast([*]u8, &sa6), 0, @sizeOf(os.sockaddr_in6)); |
| ... | ... | @@ -645,7 +644,7 @@ fn linuxLookupName( |
| 645 | 644 | key |= (MAXADDRS - @intCast(i32, i)) << DAS_ORDER_SHIFT; |
| 646 | 645 | addr.sortkey = key; |
| 647 | 646 | } |
| 648 | std.sort.sort(LookupAddr, addrs.toSlice(), addrCmpLessThan); | |
| 647 | std.sort.sort(LookupAddr, addrs.span(), addrCmpLessThan); | |
| 649 | 648 | } |
| 650 | 649 | |
| 651 | 650 | const Policy = struct { |
| ... | ... | @@ -799,12 +798,12 @@ fn linuxLookupNameFromNull( |
| 799 | 798 | |
| 800 | 799 | fn linuxLookupNameFromHosts( |
| 801 | 800 | addrs: *std.ArrayList(LookupAddr), |
| 802 | canon: *std.Buffer, | |
| 801 | canon: *std.ArrayListSentineled(u8, 0), | |
| 803 | 802 | name: []const u8, |
| 804 | 803 | family: os.sa_family_t, |
| 805 | 804 | port: u16, |
| 806 | 805 | ) !void { |
| 807 | const file = fs.openFileAbsoluteC("/etc/hosts", .{}) catch |err| switch (err) { | |
| 806 | const file = fs.openFileAbsoluteZ("/etc/hosts", .{}) catch |err| switch (err) { | |
| 808 | 807 | error.FileNotFound, |
| 809 | 808 | error.NotDir, |
| 810 | 809 | error.AccessDenied, |
| ... | ... | @@ -869,7 +868,7 @@ pub fn isValidHostName(hostname: []const u8) bool { |
| 869 | 868 | |
| 870 | 869 | fn linuxLookupNameFromDnsSearch( |
| 871 | 870 | addrs: *std.ArrayList(LookupAddr), |
| 872 | canon: *std.Buffer, | |
| 871 | canon: *std.ArrayListSentineled(u8, 0), | |
| 873 | 872 | name: []const u8, |
| 874 | 873 | family: os.sa_family_t, |
| 875 | 874 | port: u16, |
| ... | ... | @@ -888,7 +887,7 @@ fn linuxLookupNameFromDnsSearch( |
| 888 | 887 | const search = if (rc.search.isNull() or dots >= rc.ndots or mem.endsWith(u8, name, ".")) |
| 889 | 888 | &[_]u8{} |
| 890 | 889 | else |
| 891 | rc.search.toSliceConst(); | |
| 890 | rc.search.span(); | |
| 892 | 891 | |
| 893 | 892 | var canon_name = name; |
| 894 | 893 | |
| ... | ... | @@ -901,14 +900,14 @@ fn linuxLookupNameFromDnsSearch( |
| 901 | 900 | // name is not a CNAME record) and serves as a buffer for passing |
| 902 | 901 | // the full requested name to name_from_dns. |
| 903 | 902 | try canon.resize(canon_name.len); |
| 904 | mem.copy(u8, canon.toSlice(), canon_name); | |
| 905 | try canon.appendByte('.'); | |
| 903 | mem.copy(u8, canon.span(), canon_name); | |
| 904 | try canon.append('.'); | |
| 906 | 905 | |
| 907 | 906 | var tok_it = mem.tokenize(search, " \t"); |
| 908 | 907 | while (tok_it.next()) |tok| { |
| 909 | 908 | canon.shrink(canon_name.len + 1); |
| 910 | try canon.append(tok); | |
| 911 | try linuxLookupNameFromDns(addrs, canon, canon.toSliceConst(), family, rc, port); | |
| 909 | try canon.appendSlice(tok); | |
| 910 | try linuxLookupNameFromDns(addrs, canon, canon.span(), family, rc, port); | |
| 912 | 911 | if (addrs.len != 0) return; |
| 913 | 912 | } |
| 914 | 913 | |
| ... | ... | @@ -918,13 +917,13 @@ fn linuxLookupNameFromDnsSearch( |
| 918 | 917 | |
| 919 | 918 | const dpc_ctx = struct { |
| 920 | 919 | addrs: *std.ArrayList(LookupAddr), |
| 921 | canon: *std.Buffer, | |
| 920 | canon: *std.ArrayListSentineled(u8, 0), | |
| 922 | 921 | port: u16, |
| 923 | 922 | }; |
| 924 | 923 | |
| 925 | 924 | fn linuxLookupNameFromDns( |
| 926 | 925 | addrs: *std.ArrayList(LookupAddr), |
| 927 | canon: *std.Buffer, | |
| 926 | canon: *std.ArrayListSentineled(u8, 0), | |
| 928 | 927 | name: []const u8, |
| 929 | 928 | family: os.sa_family_t, |
| 930 | 929 | rc: ResolvConf, |
| ... | ... | @@ -979,7 +978,7 @@ const ResolvConf = struct { |
| 979 | 978 | attempts: u32, |
| 980 | 979 | ndots: u32, |
| 981 | 980 | timeout: u32, |
| 982 | search: std.Buffer, | |
| 981 | search: std.ArrayListSentineled(u8, 0), | |
| 983 | 982 | ns: std.ArrayList(LookupAddr), |
| 984 | 983 | |
| 985 | 984 | fn deinit(rc: *ResolvConf) void { |
| ... | ... | @@ -994,14 +993,14 @@ const ResolvConf = struct { |
| 994 | 993 | fn getResolvConf(allocator: *mem.Allocator, rc: *ResolvConf) !void { |
| 995 | 994 | rc.* = ResolvConf{ |
| 996 | 995 | .ns = std.ArrayList(LookupAddr).init(allocator), |
| 997 | .search = std.Buffer.initNull(allocator), | |
| 996 | .search = std.ArrayListSentineled(u8, 0).initNull(allocator), | |
| 998 | 997 | .ndots = 1, |
| 999 | 998 | .timeout = 5, |
| 1000 | 999 | .attempts = 2, |
| 1001 | 1000 | }; |
| 1002 | 1001 | errdefer rc.deinit(); |
| 1003 | 1002 | |
| 1004 | const file = fs.openFileAbsoluteC("/etc/resolv.conf", .{}) catch |err| switch (err) { | |
| 1003 | const file = fs.openFileAbsoluteZ("/etc/resolv.conf", .{}) catch |err| switch (err) { | |
| 1005 | 1004 | error.FileNotFound, |
| 1006 | 1005 | error.NotDir, |
| 1007 | 1006 | error.AccessDenied, |
| ... | ... | @@ -1080,9 +1079,9 @@ fn resMSendRc( |
| 1080 | 1079 | defer ns_list.deinit(); |
| 1081 | 1080 | |
| 1082 | 1081 | try ns_list.resize(rc.ns.len); |
| 1083 | const ns = ns_list.toSlice(); | |
| 1082 | const ns = ns_list.span(); | |
| 1084 | 1083 | |
| 1085 | for (rc.ns.toSliceConst()) |iplit, i| { | |
| 1084 | for (rc.ns.span()) |iplit, i| { | |
| 1086 | 1085 | ns[i] = iplit.addr; |
| 1087 | 1086 | assert(ns[i].getPort() == 53); |
| 1088 | 1087 | if (iplit.addr.any.family != os.AF_INET) { |
| ... | ... | @@ -1266,7 +1265,7 @@ fn dnsParseCallback(ctx: dpc_ctx, rr: u8, data: []const u8, packet: []const u8) |
| 1266 | 1265 | var tmp: [256]u8 = undefined; |
| 1267 | 1266 | // Returns len of compressed name. strlen to get canon name. |
| 1268 | 1267 | _ = try os.dn_expand(packet, data, &tmp); |
| 1269 | const canon_name = mem.toSliceConst(u8, @ptrCast([*:0]const u8, &tmp)); | |
| 1268 | const canon_name = mem.spanZ(@ptrCast([*:0]const u8, &tmp)); | |
| 1270 | 1269 | if (isValidHostName(canon_name)) { |
| 1271 | 1270 | try ctx.canon.replaceContents(canon_name); |
| 1272 | 1271 | } |
lib/std/os.zig+105-83| ... | ... | @@ -163,7 +163,7 @@ pub fn getrandom(buffer: []u8) GetRandomError!void { |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | fn getRandomBytesDevURandom(buf: []u8) !void { |
| 166 | const fd = try openC("/dev/urandom", O_RDONLY | O_CLOEXEC, 0); | |
| 166 | const fd = try openZ("/dev/urandom", O_RDONLY | O_CLOEXEC, 0); | |
| 167 | 167 | defer close(fd); |
| 168 | 168 | |
| 169 | 169 | const st = try fstat(fd); |
| ... | ... | @@ -853,13 +853,15 @@ pub const OpenError = error{ |
| 853 | 853 | /// TODO support windows |
| 854 | 854 | pub fn open(file_path: []const u8, flags: u32, perm: usize) OpenError!fd_t { |
| 855 | 855 | const file_path_c = try toPosixPath(file_path); |
| 856 | return openC(&file_path_c, flags, perm); | |
| 856 | return openZ(&file_path_c, flags, perm); | |
| 857 | 857 | } |
| 858 | 858 | |
| 859 | pub const openC = @compileError("deprecated: renamed to openZ"); | |
| 860 | ||
| 859 | 861 | /// Open and possibly create a file. Keeps trying if it gets interrupted. |
| 860 | 862 | /// See also `open`. |
| 861 | 863 | /// TODO support windows |
| 862 | pub fn openC(file_path: [*:0]const u8, flags: u32, perm: usize) OpenError!fd_t { | |
| 864 | pub fn openZ(file_path: [*:0]const u8, flags: u32, perm: usize) OpenError!fd_t { | |
| 863 | 865 | while (true) { |
| 864 | 866 | const rc = system.open(file_path, flags, perm); |
| 865 | 867 | switch (errno(rc)) { |
| ... | ... | @@ -895,14 +897,16 @@ pub fn openC(file_path: [*:0]const u8, flags: u32, perm: usize) OpenError!fd_t { |
| 895 | 897 | /// TODO support windows |
| 896 | 898 | pub fn openat(dir_fd: fd_t, file_path: []const u8, flags: u32, mode: mode_t) OpenError!fd_t { |
| 897 | 899 | const file_path_c = try toPosixPath(file_path); |
| 898 | return openatC(dir_fd, &file_path_c, flags, mode); | |
| 900 | return openatZ(dir_fd, &file_path_c, flags, mode); | |
| 899 | 901 | } |
| 900 | 902 | |
| 903 | pub const openatC = @compileError("deprecated: renamed to openatZ"); | |
| 904 | ||
| 901 | 905 | /// Open and possibly create a file. Keeps trying if it gets interrupted. |
| 902 | 906 | /// `file_path` is relative to the open directory handle `dir_fd`. |
| 903 | 907 | /// See also `openat`. |
| 904 | 908 | /// TODO support windows |
| 905 | pub fn openatC(dir_fd: fd_t, file_path: [*:0]const u8, flags: u32, mode: mode_t) OpenError!fd_t { | |
| 909 | pub fn openatZ(dir_fd: fd_t, file_path: [*:0]const u8, flags: u32, mode: mode_t) OpenError!fd_t { | |
| 906 | 910 | while (true) { |
| 907 | 911 | const rc = system.openat(dir_fd, file_path, flags, mode); |
| 908 | 912 | switch (errno(rc)) { |
| ... | ... | @@ -959,8 +963,7 @@ pub const ExecveError = error{ |
| 959 | 963 | NameTooLong, |
| 960 | 964 | } || UnexpectedError; |
| 961 | 965 | |
| 962 | /// Deprecated in favor of `execveZ`. | |
| 963 | pub const execveC = execveZ; | |
| 966 | pub const execveC = @compileError("deprecated: use execveZ"); | |
| 964 | 967 | |
| 965 | 968 | /// Like `execve` except the parameters are null-terminated, |
| 966 | 969 | /// matching the syscall API on all targets. This removes the need for an allocator. |
| ... | ... | @@ -992,8 +995,7 @@ pub fn execveZ( |
| 992 | 995 | } |
| 993 | 996 | } |
| 994 | 997 | |
| 995 | /// Deprecated in favor of `execvpeZ`. | |
| 996 | pub const execvpeC = execvpeZ; | |
| 998 | pub const execvpeC = @compileError("deprecated in favor of execvpeZ"); | |
| 997 | 999 | |
| 998 | 1000 | pub const Arg0Expand = enum { |
| 999 | 1001 | expand, |
| ... | ... | @@ -1012,7 +1014,7 @@ pub fn execvpeZ_expandArg0( |
| 1012 | 1014 | }, |
| 1013 | 1015 | envp: [*:null]const ?[*:0]const u8, |
| 1014 | 1016 | ) ExecveError { |
| 1015 | const file_slice = mem.toSliceConst(u8, file); | |
| 1017 | const file_slice = mem.spanZ(file); | |
| 1016 | 1018 | if (mem.indexOfScalar(u8, file_slice, '/') != null) return execveZ(file, child_argv, envp); |
| 1017 | 1019 | |
| 1018 | 1020 | const PATH = getenvZ("PATH") orelse "/usr/local/bin:/bin/:/usr/bin"; |
| ... | ... | @@ -1076,7 +1078,7 @@ pub fn execvpe_expandArg0( |
| 1076 | 1078 | mem.set(?[*:0]u8, argv_buf, null); |
| 1077 | 1079 | defer { |
| 1078 | 1080 | for (argv_buf) |arg| { |
| 1079 | const arg_buf = if (arg) |ptr| mem.toSlice(u8, ptr) else break; | |
| 1081 | const arg_buf = mem.spanZ(arg) orelse break; | |
| 1080 | 1082 | allocator.free(arg_buf); |
| 1081 | 1083 | } |
| 1082 | 1084 | allocator.free(argv_buf); |
| ... | ... | @@ -1189,30 +1191,32 @@ pub fn getenv(key: []const u8) ?[]const u8 { |
| 1189 | 1191 | return null; |
| 1190 | 1192 | } |
| 1191 | 1193 | |
| 1192 | /// Deprecated in favor of `getenvZ`. | |
| 1193 | pub const getenvC = getenvZ; | |
| 1194 | pub const getenvC = @compileError("Deprecated in favor of `getenvZ`"); | |
| 1194 | 1195 | |
| 1195 | 1196 | /// Get an environment variable with a null-terminated name. |
| 1196 | 1197 | /// See also `getenv`. |
| 1197 | 1198 | pub fn getenvZ(key: [*:0]const u8) ?[]const u8 { |
| 1198 | 1199 | if (builtin.link_libc) { |
| 1199 | 1200 | const value = system.getenv(key) orelse return null; |
| 1200 | return mem.toSliceConst(u8, value); | |
| 1201 | return mem.spanZ(value); | |
| 1201 | 1202 | } |
| 1202 | 1203 | if (builtin.os.tag == .windows) { |
| 1203 | 1204 | @compileError("std.os.getenvZ is unavailable for Windows because environment string is in WTF-16 format. See std.process.getEnvVarOwned for cross-platform API or std.os.getenvW for Windows-specific API."); |
| 1204 | 1205 | } |
| 1205 | return getenv(mem.toSliceConst(u8, key)); | |
| 1206 | return getenv(mem.spanZ(key)); | |
| 1206 | 1207 | } |
| 1207 | 1208 | |
| 1208 | 1209 | /// Windows-only. Get an environment variable with a null-terminated, WTF-16 encoded name. |
| 1209 | 1210 | /// See also `getenv`. |
| 1211 | /// This function first attempts a case-sensitive lookup. If no match is found, and `key` | |
| 1212 | /// is ASCII, then it attempts a second case-insensitive lookup. | |
| 1210 | 1213 | pub fn getenvW(key: [*:0]const u16) ?[:0]const u16 { |
| 1211 | 1214 | if (builtin.os.tag != .windows) { |
| 1212 | 1215 | @compileError("std.os.getenvW is a Windows-only API"); |
| 1213 | 1216 | } |
| 1214 | const key_slice = mem.toSliceConst(u16, key); | |
| 1217 | const key_slice = mem.spanZ(key); | |
| 1215 | 1218 | const ptr = windows.peb().ProcessParameters.Environment; |
| 1219 | var ascii_match: ?[:0]const u16 = null; | |
| 1216 | 1220 | var i: usize = 0; |
| 1217 | 1221 | while (ptr[i] != 0) { |
| 1218 | 1222 | const key_start = i; |
| ... | ... | @@ -1228,9 +1232,20 @@ pub fn getenvW(key: [*:0]const u16) ?[:0]const u16 { |
| 1228 | 1232 | |
| 1229 | 1233 | if (mem.eql(u16, key_slice, this_key)) return this_value; |
| 1230 | 1234 | |
| 1235 | ascii_check: { | |
| 1236 | if (ascii_match != null) break :ascii_check; | |
| 1237 | if (key_slice.len != this_key.len) break :ascii_check; | |
| 1238 | for (key_slice) |a_c, key_index| { | |
| 1239 | const a = math.cast(u8, a_c) catch break :ascii_check; | |
| 1240 | const b = math.cast(u8, this_key[key_index]) catch break :ascii_check; | |
| 1241 | if (std.ascii.toLower(a) != std.ascii.toLower(b)) break :ascii_check; | |
| 1242 | } | |
| 1243 | ascii_match = this_value; | |
| 1244 | } | |
| 1245 | ||
| 1231 | 1246 | i += 1; // skip over null byte |
| 1232 | 1247 | } |
| 1233 | return null; | |
| 1248 | return ascii_match; | |
| 1234 | 1249 | } |
| 1235 | 1250 | |
| 1236 | 1251 | pub const GetCwdError = error{ |
| ... | ... | @@ -1250,7 +1265,7 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 { |
| 1250 | 1265 | break :blk errno(system.getcwd(out_buffer.ptr, out_buffer.len)); |
| 1251 | 1266 | }; |
| 1252 | 1267 | switch (err) { |
| 1253 | 0 => return mem.toSlice(u8, @ptrCast([*:0]u8, out_buffer.ptr)), | |
| 1268 | 0 => return mem.spanZ(@ptrCast([*:0]u8, out_buffer.ptr)), | |
| 1254 | 1269 | EFAULT => unreachable, |
| 1255 | 1270 | EINVAL => unreachable, |
| 1256 | 1271 | ENOENT => return error.CurrentWorkingDirectoryUnlinked, |
| ... | ... | @@ -1288,13 +1303,15 @@ pub fn symlink(target_path: []const u8, sym_link_path: []const u8) SymLinkError! |
| 1288 | 1303 | } else { |
| 1289 | 1304 | const target_path_c = try toPosixPath(target_path); |
| 1290 | 1305 | const sym_link_path_c = try toPosixPath(sym_link_path); |
| 1291 | return symlinkC(&target_path_c, &sym_link_path_c); | |
| 1306 | return symlinkZ(&target_path_c, &sym_link_path_c); | |
| 1292 | 1307 | } |
| 1293 | 1308 | } |
| 1294 | 1309 | |
| 1310 | pub const symlinkC = @compileError("deprecated: renamed to symlinkZ"); | |
| 1311 | ||
| 1295 | 1312 | /// This is the same as `symlink` except the parameters are null-terminated pointers. |
| 1296 | 1313 | /// See also `symlink`. |
| 1297 | pub fn symlinkC(target_path: [*:0]const u8, sym_link_path: [*:0]const u8) SymLinkError!void { | |
| 1314 | pub fn symlinkZ(target_path: [*:0]const u8, sym_link_path: [*:0]const u8) SymLinkError!void { | |
| 1298 | 1315 | if (builtin.os.tag == .windows) { |
| 1299 | 1316 | const target_path_w = try windows.cStrToPrefixedFileW(target_path); |
| 1300 | 1317 | const sym_link_path_w = try windows.cStrToPrefixedFileW(sym_link_path); |
| ... | ... | @@ -1323,10 +1340,12 @@ pub fn symlinkC(target_path: [*:0]const u8, sym_link_path: [*:0]const u8) SymLin |
| 1323 | 1340 | pub fn symlinkat(target_path: []const u8, newdirfd: fd_t, sym_link_path: []const u8) SymLinkError!void { |
| 1324 | 1341 | const target_path_c = try toPosixPath(target_path); |
| 1325 | 1342 | const sym_link_path_c = try toPosixPath(sym_link_path); |
| 1326 | return symlinkatC(target_path_c, newdirfd, sym_link_path_c); | |
| 1343 | return symlinkatZ(target_path_c, newdirfd, sym_link_path_c); | |
| 1327 | 1344 | } |
| 1328 | 1345 | |
| 1329 | pub fn symlinkatC(target_path: [*:0]const u8, newdirfd: fd_t, sym_link_path: [*:0]const u8) SymLinkError!void { | |
| 1346 | pub const symlinkatC = @compileError("deprecated: renamed to symlinkatZ"); | |
| 1347 | ||
| 1348 | pub fn symlinkatZ(target_path: [*:0]const u8, newdirfd: fd_t, sym_link_path: [*:0]const u8) SymLinkError!void { | |
| 1330 | 1349 | switch (errno(system.symlinkat(target_path, newdirfd, sym_link_path))) { |
| 1331 | 1350 | 0 => return, |
| 1332 | 1351 | EFAULT => unreachable, |
| ... | ... | @@ -1375,12 +1394,14 @@ pub fn unlink(file_path: []const u8) UnlinkError!void { |
| 1375 | 1394 | return windows.DeleteFileW(&file_path_w); |
| 1376 | 1395 | } else { |
| 1377 | 1396 | const file_path_c = try toPosixPath(file_path); |
| 1378 | return unlinkC(&file_path_c); | |
| 1397 | return unlinkZ(&file_path_c); | |
| 1379 | 1398 | } |
| 1380 | 1399 | } |
| 1381 | 1400 | |
| 1401 | pub const unlinkC = @compileError("deprecated: renamed to unlinkZ"); | |
| 1402 | ||
| 1382 | 1403 | /// Same as `unlink` except the parameter is a null terminated UTF8-encoded string. |
| 1383 | pub fn unlinkC(file_path: [*:0]const u8) UnlinkError!void { | |
| 1404 | pub fn unlinkZ(file_path: [*:0]const u8) UnlinkError!void { | |
| 1384 | 1405 | if (builtin.os.tag == .windows) { |
| 1385 | 1406 | const file_path_w = try windows.cStrToPrefixedFileW(file_path); |
| 1386 | 1407 | return windows.DeleteFileW(&file_path_w); |
| ... | ... | @@ -1417,11 +1438,13 @@ pub fn unlinkat(dirfd: fd_t, file_path: []const u8, flags: u32) UnlinkatError!vo |
| 1417 | 1438 | return unlinkatW(dirfd, &file_path_w, flags); |
| 1418 | 1439 | } |
| 1419 | 1440 | const file_path_c = try toPosixPath(file_path); |
| 1420 | return unlinkatC(dirfd, &file_path_c, flags); | |
| 1441 | return unlinkatZ(dirfd, &file_path_c, flags); | |
| 1421 | 1442 | } |
| 1422 | 1443 | |
| 1444 | pub const unlinkatC = @compileError("deprecated: renamed to unlinkatZ"); | |
| 1445 | ||
| 1423 | 1446 | /// Same as `unlinkat` but `file_path` is a null-terminated string. |
| 1424 | pub fn unlinkatC(dirfd: fd_t, file_path_c: [*:0]const u8, flags: u32) UnlinkatError!void { | |
| 1447 | pub fn unlinkatZ(dirfd: fd_t, file_path_c: [*:0]const u8, flags: u32) UnlinkatError!void { | |
| 1425 | 1448 | if (builtin.os.tag == .windows) { |
| 1426 | 1449 | const file_path_w = try windows.cStrToPrefixedFileW(file_path_c); |
| 1427 | 1450 | return unlinkatW(dirfd, &file_path_w, flags); |
| ... | ... | @@ -1459,7 +1482,7 @@ pub fn unlinkatW(dirfd: fd_t, sub_path_w: [*:0]const u16, flags: u32) UnlinkatEr |
| 1459 | 1482 | else |
| 1460 | 1483 | @as(w.ULONG, w.FILE_DELETE_ON_CLOSE | w.FILE_NON_DIRECTORY_FILE); |
| 1461 | 1484 | |
| 1462 | const path_len_bytes = @intCast(u16, mem.toSliceConst(u16, sub_path_w).len * 2); | |
| 1485 | const path_len_bytes = @intCast(u16, mem.lenZ(sub_path_w) * 2); | |
| 1463 | 1486 | var nt_name = w.UNICODE_STRING{ |
| 1464 | 1487 | .Length = path_len_bytes, |
| 1465 | 1488 | .MaximumLength = path_len_bytes, |
| ... | ... | @@ -1543,12 +1566,14 @@ pub fn rename(old_path: []const u8, new_path: []const u8) RenameError!void { |
| 1543 | 1566 | } else { |
| 1544 | 1567 | const old_path_c = try toPosixPath(old_path); |
| 1545 | 1568 | const new_path_c = try toPosixPath(new_path); |
| 1546 | return renameC(&old_path_c, &new_path_c); | |
| 1569 | return renameZ(&old_path_c, &new_path_c); | |
| 1547 | 1570 | } |
| 1548 | 1571 | } |
| 1549 | 1572 | |
| 1573 | pub const renameC = @compileError("deprecated: renamed to renameZ"); | |
| 1574 | ||
| 1550 | 1575 | /// Same as `rename` except the parameters are null-terminated byte arrays. |
| 1551 | pub fn renameC(old_path: [*:0]const u8, new_path: [*:0]const u8) RenameError!void { | |
| 1576 | pub fn renameZ(old_path: [*:0]const u8, new_path: [*:0]const u8) RenameError!void { | |
| 1552 | 1577 | if (builtin.os.tag == .windows) { |
| 1553 | 1578 | const old_path_w = try windows.cStrToPrefixedFileW(old_path); |
| 1554 | 1579 | const new_path_w = try windows.cStrToPrefixedFileW(new_path); |
| ... | ... | @@ -1715,11 +1740,13 @@ pub fn mkdirat(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirError!v |
| 1715 | 1740 | return mkdiratW(dir_fd, &sub_dir_path_w, mode); |
| 1716 | 1741 | } else { |
| 1717 | 1742 | const sub_dir_path_c = try toPosixPath(sub_dir_path); |
| 1718 | return mkdiratC(dir_fd, &sub_dir_path_c, mode); | |
| 1743 | return mkdiratZ(dir_fd, &sub_dir_path_c, mode); | |
| 1719 | 1744 | } |
| 1720 | 1745 | } |
| 1721 | 1746 | |
| 1722 | pub fn mkdiratC(dir_fd: fd_t, sub_dir_path: [*:0]const u8, mode: u32) MakeDirError!void { | |
| 1747 | pub const mkdiratC = @compileError("deprecated: renamed to mkdiratZ"); | |
| 1748 | ||
| 1749 | pub fn mkdiratZ(dir_fd: fd_t, sub_dir_path: [*:0]const u8, mode: u32) MakeDirError!void { | |
| 1723 | 1750 | if (builtin.os.tag == .windows) { |
| 1724 | 1751 | const sub_dir_path_w = try windows.cStrToPrefixedFileW(sub_dir_path); |
| 1725 | 1752 | return mkdiratW(dir_fd, &sub_dir_path_w, mode); |
| ... | ... | @@ -1810,12 +1837,14 @@ pub fn rmdir(dir_path: []const u8) DeleteDirError!void { |
| 1810 | 1837 | return windows.RemoveDirectoryW(&dir_path_w); |
| 1811 | 1838 | } else { |
| 1812 | 1839 | const dir_path_c = try toPosixPath(dir_path); |
| 1813 | return rmdirC(&dir_path_c); | |
| 1840 | return rmdirZ(&dir_path_c); | |
| 1814 | 1841 | } |
| 1815 | 1842 | } |
| 1816 | 1843 | |
| 1844 | pub const rmdirC = @compileError("deprecated: renamed to rmdirZ"); | |
| 1845 | ||
| 1817 | 1846 | /// Same as `rmdir` except the parameter is null-terminated. |
| 1818 | pub fn rmdirC(dir_path: [*:0]const u8) DeleteDirError!void { | |
| 1847 | pub fn rmdirZ(dir_path: [*:0]const u8) DeleteDirError!void { | |
| 1819 | 1848 | if (builtin.os.tag == .windows) { |
| 1820 | 1849 | const dir_path_w = try windows.cStrToPrefixedFileW(dir_path); |
| 1821 | 1850 | return windows.RemoveDirectoryW(&dir_path_w); |
| ... | ... | @@ -1857,12 +1886,14 @@ pub fn chdir(dir_path: []const u8) ChangeCurDirError!void { |
| 1857 | 1886 | @compileError("TODO implement chdir for Windows"); |
| 1858 | 1887 | } else { |
| 1859 | 1888 | const dir_path_c = try toPosixPath(dir_path); |
| 1860 | return chdirC(&dir_path_c); | |
| 1889 | return chdirZ(&dir_path_c); | |
| 1861 | 1890 | } |
| 1862 | 1891 | } |
| 1863 | 1892 | |
| 1893 | pub const chdirC = @compileError("deprecated: renamed to chdirZ"); | |
| 1894 | ||
| 1864 | 1895 | /// Same as `chdir` except the parameter is null-terminated. |
| 1865 | pub fn chdirC(dir_path: [*:0]const u8) ChangeCurDirError!void { | |
| 1896 | pub fn chdirZ(dir_path: [*:0]const u8) ChangeCurDirError!void { | |
| 1866 | 1897 | if (builtin.os.tag == .windows) { |
| 1867 | 1898 | const dir_path_w = try windows.cStrToPrefixedFileW(dir_path); |
| 1868 | 1899 | @compileError("TODO implement chdir for Windows"); |
| ... | ... | @@ -1919,12 +1950,14 @@ pub fn readlink(file_path: []const u8, out_buffer: []u8) ReadLinkError![]u8 { |
| 1919 | 1950 | @compileError("TODO implement readlink for Windows"); |
| 1920 | 1951 | } else { |
| 1921 | 1952 | const file_path_c = try toPosixPath(file_path); |
| 1922 | return readlinkC(&file_path_c, out_buffer); | |
| 1953 | return readlinkZ(&file_path_c, out_buffer); | |
| 1923 | 1954 | } |
| 1924 | 1955 | } |
| 1925 | 1956 | |
| 1957 | pub const readlinkC = @compileError("deprecated: renamed to readlinkZ"); | |
| 1958 | ||
| 1926 | 1959 | /// Same as `readlink` except `file_path` is null-terminated. |
| 1927 | pub fn readlinkC(file_path: [*:0]const u8, out_buffer: []u8) ReadLinkError![]u8 { | |
| 1960 | pub fn readlinkZ(file_path: [*:0]const u8, out_buffer: []u8) ReadLinkError![]u8 { | |
| 1928 | 1961 | if (builtin.os.tag == .windows) { |
| 1929 | 1962 | const file_path_w = try windows.cStrToPrefixedFileW(file_path); |
| 1930 | 1963 | @compileError("TODO implement readlink for Windows"); |
| ... | ... | @@ -1945,7 +1978,9 @@ pub fn readlinkC(file_path: [*:0]const u8, out_buffer: []u8) ReadLinkError![]u8 |
| 1945 | 1978 | } |
| 1946 | 1979 | } |
| 1947 | 1980 | |
| 1948 | pub fn readlinkatC(dirfd: fd_t, file_path: [*:0]const u8, out_buffer: []u8) ReadLinkError![]u8 { | |
| 1981 | pub const readlinkatC = @compileError("deprecated: renamed to readlinkatZ"); | |
| 1982 | ||
| 1983 | pub fn readlinkatZ(dirfd: fd_t, file_path: [*:0]const u8, out_buffer: []u8) ReadLinkError![]u8 { | |
| 1949 | 1984 | if (builtin.os.tag == .windows) { |
| 1950 | 1985 | const file_path_w = try windows.cStrToPrefixedFileW(file_path); |
| 1951 | 1986 | @compileError("TODO implement readlink for Windows"); |
| ... | ... | @@ -2044,7 +2079,7 @@ pub fn isatty(handle: fd_t) bool { |
| 2044 | 2079 | } |
| 2045 | 2080 | if (builtin.os.tag == .linux) { |
| 2046 | 2081 | var wsz: linux.winsize = undefined; |
| 2047 | return linux.syscall3(linux.SYS_ioctl, @bitCast(usize, @as(isize, handle)), linux.TIOCGWINSZ, @ptrToInt(&wsz)) == 0; | |
| 2082 | return linux.syscall3(.ioctl, @bitCast(usize, @as(isize, handle)), linux.TIOCGWINSZ, @ptrToInt(&wsz)) == 0; | |
| 2048 | 2083 | } |
| 2049 | 2084 | unreachable; |
| 2050 | 2085 | } |
| ... | ... | @@ -2532,14 +2567,7 @@ pub const FStatError = error{ |
| 2532 | 2567 | pub fn fstat(fd: fd_t) FStatError!Stat { |
| 2533 | 2568 | var stat: Stat = undefined; |
| 2534 | 2569 | |
| 2535 | const symbol_name = if (comptime std.Target.current.isDarwin()) | |
| 2536 | "fstat$INODE64" | |
| 2537 | else if (std.Target.current.os.tag == .netbsd) | |
| 2538 | "__fstat50" | |
| 2539 | else | |
| 2540 | "fstat"; | |
| 2541 | ||
| 2542 | switch (errno(@field(system, symbol_name)(fd, &stat))) { | |
| 2570 | switch (errno(system.fstat(fd, &stat))) { | |
| 2543 | 2571 | 0 => return stat, |
| 2544 | 2572 | EINVAL => unreachable, |
| 2545 | 2573 | EBADF => unreachable, // Always a race condition. |
| ... | ... | @@ -2553,10 +2581,12 @@ const FStatAtError = FStatError || error{NameTooLong}; |
| 2553 | 2581 | |
| 2554 | 2582 | pub fn fstatat(dirfd: fd_t, pathname: []const u8, flags: u32) FStatAtError![]Stat { |
| 2555 | 2583 | const pathname_c = try toPosixPath(pathname); |
| 2556 | return fstatatC(dirfd, &pathname_c, flags); | |
| 2584 | return fstatatZ(dirfd, &pathname_c, flags); | |
| 2557 | 2585 | } |
| 2558 | 2586 | |
| 2559 | pub fn fstatatC(dirfd: fd_t, pathname: [*:0]const u8, flags: u32) FStatAtError!Stat { | |
| 2587 | pub const fstatatC = @compileError("deprecated: renamed to fstatatZ"); | |
| 2588 | ||
| 2589 | pub fn fstatatZ(dirfd: fd_t, pathname: [*:0]const u8, flags: u32) FStatAtError!Stat { | |
| 2560 | 2590 | var stat: Stat = undefined; |
| 2561 | 2591 | switch (errno(system.fstatat(dirfd, pathname, &stat, flags))) { |
| 2562 | 2592 | 0 => return stat, |
| ... | ... | @@ -2668,11 +2698,13 @@ pub const INotifyAddWatchError = error{ |
| 2668 | 2698 | /// add a watch to an initialized inotify instance |
| 2669 | 2699 | pub fn inotify_add_watch(inotify_fd: i32, pathname: []const u8, mask: u32) INotifyAddWatchError!i32 { |
| 2670 | 2700 | const pathname_c = try toPosixPath(pathname); |
| 2671 | return inotify_add_watchC(inotify_fd, &pathname_c, mask); | |
| 2701 | return inotify_add_watchZ(inotify_fd, &pathname_c, mask); | |
| 2672 | 2702 | } |
| 2673 | 2703 | |
| 2704 | pub const inotify_add_watchC = @compileError("deprecated: renamed to inotify_add_watchZ"); | |
| 2705 | ||
| 2674 | 2706 | /// Same as `inotify_add_watch` except pathname is null-terminated. |
| 2675 | pub fn inotify_add_watchC(inotify_fd: i32, pathname: [*:0]const u8, mask: u32) INotifyAddWatchError!i32 { | |
| 2707 | pub fn inotify_add_watchZ(inotify_fd: i32, pathname: [*:0]const u8, mask: u32) INotifyAddWatchError!i32 { | |
| 2676 | 2708 | const rc = system.inotify_add_watch(inotify_fd, pathname, mask); |
| 2677 | 2709 | switch (errno(rc)) { |
| 2678 | 2710 | 0 => return @intCast(i32, rc), |
| ... | ... | @@ -2829,11 +2861,10 @@ pub fn access(path: []const u8, mode: u32) AccessError!void { |
| 2829 | 2861 | return; |
| 2830 | 2862 | } |
| 2831 | 2863 | const path_c = try toPosixPath(path); |
| 2832 | return accessC(&path_c, mode); | |
| 2864 | return accessZ(&path_c, mode); | |
| 2833 | 2865 | } |
| 2834 | 2866 | |
| 2835 | /// Deprecated in favor of `accessZ`. | |
| 2836 | pub const accessC = accessZ; | |
| 2867 | pub const accessC = @compileError("Deprecated in favor of `accessZ`"); | |
| 2837 | 2868 | |
| 2838 | 2869 | /// Same as `access` except `path` is null-terminated. |
| 2839 | 2870 | pub fn accessZ(path: [*:0]const u8, mode: u32) AccessError!void { |
| ... | ... | @@ -2920,7 +2951,7 @@ pub fn faccessatW(dirfd: fd_t, sub_path_w: [*:0]const u16, mode: u32, flags: u32 |
| 2920 | 2951 | return; |
| 2921 | 2952 | } |
| 2922 | 2953 | |
| 2923 | const path_len_bytes = math.cast(u16, mem.toSliceConst(u16, sub_path_w).len * 2) catch |err| switch (err) { | |
| 2954 | const path_len_bytes = math.cast(u16, mem.lenZ(sub_path_w) * 2) catch |err| switch (err) { | |
| 2924 | 2955 | error.Overflow => return error.NameTooLong, |
| 2925 | 2956 | }; |
| 2926 | 2957 | var nt_name = windows.UNICODE_STRING{ |
| ... | ... | @@ -3019,7 +3050,9 @@ pub fn sysctl( |
| 3019 | 3050 | } |
| 3020 | 3051 | } |
| 3021 | 3052 | |
| 3022 | pub fn sysctlbynameC( | |
| 3053 | pub const sysctlbynameC = @compileError("deprecated: renamed to sysctlbynameZ"); | |
| 3054 | ||
| 3055 | pub fn sysctlbynameZ( | |
| 3023 | 3056 | name: [*:0]const u8, |
| 3024 | 3057 | oldp: ?*c_void, |
| 3025 | 3058 | oldlenp: ?*usize, |
| ... | ... | @@ -3224,23 +3257,25 @@ pub fn realpath(pathname: []const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealPathE |
| 3224 | 3257 | return realpathW(&pathname_w, out_buffer); |
| 3225 | 3258 | } |
| 3226 | 3259 | const pathname_c = try toPosixPath(pathname); |
| 3227 | return realpathC(&pathname_c, out_buffer); | |
| 3260 | return realpathZ(&pathname_c, out_buffer); | |
| 3228 | 3261 | } |
| 3229 | 3262 | |
| 3263 | pub const realpathC = @compileError("deprecated: renamed realpathZ"); | |
| 3264 | ||
| 3230 | 3265 | /// Same as `realpath` except `pathname` is null-terminated. |
| 3231 | pub fn realpathC(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 { | |
| 3266 | pub fn realpathZ(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 { | |
| 3232 | 3267 | if (builtin.os.tag == .windows) { |
| 3233 | 3268 | const pathname_w = try windows.cStrToPrefixedFileW(pathname); |
| 3234 | 3269 | return realpathW(&pathname_w, out_buffer); |
| 3235 | 3270 | } |
| 3236 | 3271 | if (builtin.os.tag == .linux and !builtin.link_libc) { |
| 3237 | const fd = try openC(pathname, linux.O_PATH | linux.O_NONBLOCK | linux.O_CLOEXEC, 0); | |
| 3272 | const fd = try openZ(pathname, linux.O_PATH | linux.O_NONBLOCK | linux.O_CLOEXEC, 0); | |
| 3238 | 3273 | defer close(fd); |
| 3239 | 3274 | |
| 3240 | 3275 | var procfs_buf: ["/proc/self/fd/-2147483648".len:0]u8 = undefined; |
| 3241 | 3276 | const proc_path = std.fmt.bufPrint(procfs_buf[0..], "/proc/self/fd/{}\x00", .{fd}) catch unreachable; |
| 3242 | 3277 | |
| 3243 | return readlinkC(@ptrCast([*:0]const u8, proc_path.ptr), out_buffer); | |
| 3278 | return readlinkZ(@ptrCast([*:0]const u8, proc_path.ptr), out_buffer); | |
| 3244 | 3279 | } |
| 3245 | 3280 | const result_path = std.c.realpath(pathname, out_buffer) orelse switch (std.c._errno().*) { |
| 3246 | 3281 | EINVAL => unreachable, |
| ... | ... | @@ -3255,7 +3290,7 @@ pub fn realpathC(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealP |
| 3255 | 3290 | EIO => return error.InputOutput, |
| 3256 | 3291 | else => |err| return unexpectedErrno(@intCast(usize, err)), |
| 3257 | 3292 | }; |
| 3258 | return mem.toSlice(u8, result_path); | |
| 3293 | return mem.spanZ(result_path); | |
| 3259 | 3294 | } |
| 3260 | 3295 | |
| 3261 | 3296 | /// Same as `realpath` except `pathname` is null-terminated and UTF16LE-encoded. |
| ... | ... | @@ -3399,12 +3434,7 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void { |
| 3399 | 3434 | return; |
| 3400 | 3435 | } |
| 3401 | 3436 | |
| 3402 | const symbol_name = if (std.Target.current.os.tag == .netbsd) | |
| 3403 | "__clock_gettime50" | |
| 3404 | else | |
| 3405 | "clock_gettime"; | |
| 3406 | ||
| 3407 | switch (errno(@field(system, symbol_name)(clk_id, tp))) { | |
| 3437 | switch (errno(system.clock_gettime(clk_id, tp))) { | |
| 3408 | 3438 | 0 => return, |
| 3409 | 3439 | EFAULT => unreachable, |
| 3410 | 3440 | EINVAL => return error.UnsupportedClock, |
| ... | ... | @@ -3426,12 +3456,7 @@ pub fn clock_getres(clk_id: i32, res: *timespec) ClockGetTimeError!void { |
| 3426 | 3456 | return; |
| 3427 | 3457 | } |
| 3428 | 3458 | |
| 3429 | const symbol_name = if (std.Target.current.os.tag == .netbsd) | |
| 3430 | "__clock_getres50" | |
| 3431 | else | |
| 3432 | "clock_getres"; | |
| 3433 | ||
| 3434 | switch (errno(@field(system, symbol_name)(clk_id, res))) { | |
| 3459 | switch (errno(system.clock_getres(clk_id, res))) { | |
| 3435 | 3460 | 0 => return, |
| 3436 | 3461 | EFAULT => unreachable, |
| 3437 | 3462 | EINVAL => return error.UnsupportedClock, |
| ... | ... | @@ -3497,12 +3522,7 @@ pub const SigaltstackError = error{ |
| 3497 | 3522 | } || UnexpectedError; |
| 3498 | 3523 | |
| 3499 | 3524 | pub fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) SigaltstackError!void { |
| 3500 | const symbol_name = if (std.Target.current.os.tag == .netbsd) | |
| 3501 | "__sigaltstack14" | |
| 3502 | else | |
| 3503 | "sigaltstack"; | |
| 3504 | ||
| 3505 | switch (errno(@field(system, symbol_name)(ss, old_ss))) { | |
| 3525 | switch (errno(system.sigaltstack(ss, old_ss))) { | |
| 3506 | 3526 | 0 => return, |
| 3507 | 3527 | EFAULT => unreachable, |
| 3508 | 3528 | EINVAL => unreachable, |
| ... | ... | @@ -3564,7 +3584,7 @@ pub const GetHostNameError = error{PermissionDenied} || UnexpectedError; |
| 3564 | 3584 | pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 { |
| 3565 | 3585 | if (builtin.link_libc) { |
| 3566 | 3586 | switch (errno(system.gethostname(name_buffer, name_buffer.len))) { |
| 3567 | 0 => return mem.toSlice(u8, @ptrCast([*:0]u8, name_buffer)), | |
| 3587 | 0 => return mem.spanZ(@ptrCast([*:0]u8, name_buffer)), | |
| 3568 | 3588 | EFAULT => unreachable, |
| 3569 | 3589 | ENAMETOOLONG => unreachable, // HOST_NAME_MAX prevents this |
| 3570 | 3590 | EPERM => return error.PermissionDenied, |
| ... | ... | @@ -3573,7 +3593,7 @@ pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 { |
| 3573 | 3593 | } |
| 3574 | 3594 | if (builtin.os.tag == .linux) { |
| 3575 | 3595 | const uts = uname(); |
| 3576 | const hostname = mem.toSliceConst(u8, @ptrCast([*:0]const u8, &uts.nodename)); | |
| 3596 | const hostname = mem.spanZ(@ptrCast([*:0]const u8, &uts.nodename)); | |
| 3577 | 3597 | mem.copy(u8, name_buffer, hostname); |
| 3578 | 3598 | return name_buffer[0..hostname.len]; |
| 3579 | 3599 | } |
| ... | ... | @@ -4260,7 +4280,9 @@ pub const MemFdCreateError = error{ |
| 4260 | 4280 | SystemOutdated, |
| 4261 | 4281 | } || UnexpectedError; |
| 4262 | 4282 | |
| 4263 | pub fn memfd_createC(name: [*:0]const u8, flags: u32) MemFdCreateError!fd_t { | |
| 4283 | pub const memfd_createC = @compileError("deprecated: renamed to memfd_createZ"); | |
| 4284 | ||
| 4285 | pub fn memfd_createZ(name: [*:0]const u8, flags: u32) MemFdCreateError!fd_t { | |
| 4264 | 4286 | // memfd_create is available only in glibc versions starting with 2.27. |
| 4265 | 4287 | const use_c = std.c.versionCheck(.{ .major = 2, .minor = 27, .patch = 0 }).ok; |
| 4266 | 4288 | const sys = if (use_c) std.c else linux; |
| ... | ... | @@ -4291,7 +4313,7 @@ fn toMemFdPath(name: []const u8) ![MFD_MAX_NAME_LEN:0]u8 { |
| 4291 | 4313 | |
| 4292 | 4314 | pub fn memfd_create(name: []const u8, flags: u32) !fd_t { |
| 4293 | 4315 | const name_t = try toMemFdPath(name); |
| 4294 | return memfd_createC(&name_t, flags); | |
| 4316 | return memfd_createZ(&name_t, flags); | |
| 4295 | 4317 | } |
| 4296 | 4318 | |
| 4297 | 4319 | pub fn getrusage(who: i32) rusage { |
lib/std/os/bits/linux.zig+128-25| ... | ... | @@ -88,11 +88,29 @@ pub const FUTEX_PRIVATE_FLAG = 128; |
| 88 | 88 | |
| 89 | 89 | pub const FUTEX_CLOCK_REALTIME = 256; |
| 90 | 90 | |
| 91 | pub const PROT_NONE = 0; | |
| 92 | pub const PROT_READ = 1; | |
| 93 | pub const PROT_WRITE = 2; | |
| 94 | pub const PROT_EXEC = 4; | |
| 91 | /// page can not be accessed | |
| 92 | pub const PROT_NONE = 0x0; | |
| 93 | ||
| 94 | /// page can be read | |
| 95 | pub const PROT_READ = 0x1; | |
| 96 | ||
| 97 | /// page can be written | |
| 98 | pub const PROT_WRITE = 0x2; | |
| 99 | ||
| 100 | /// page can be executed | |
| 101 | pub const PROT_EXEC = 0x4; | |
| 102 | ||
| 103 | /// page may be used for atomic ops | |
| 104 | pub const PROT_SEM = switch (builtin.arch) { | |
| 105 | // TODO: also xtensa | |
| 106 | .mips, .mipsel, .mips64, .mips64el => 0x10, | |
| 107 | else => 0x8, | |
| 108 | }; | |
| 109 | ||
| 110 | /// mprotect flag: extend change to start of growsdown vma | |
| 95 | 111 | pub const PROT_GROWSDOWN = 0x01000000; |
| 112 | ||
| 113 | /// mprotect flag: extend change to end of growsup vma | |
| 96 | 114 | pub const PROT_GROWSUP = 0x02000000; |
| 97 | 115 | |
| 98 | 116 | /// Share changes |
| ... | ... | @@ -617,6 +635,11 @@ pub const CLONE_IO = 0x80000000; |
| 617 | 635 | /// Clear any signal handler and reset to SIG_DFL. |
| 618 | 636 | pub const CLONE_CLEAR_SIGHAND = 0x100000000; |
| 619 | 637 | |
| 638 | // cloning flags intersect with CSIGNAL so can be used with unshare and clone3 syscalls only. | |
| 639 | ||
| 640 | /// New time namespace | |
| 641 | pub const CLONE_NEWTIME = 0x00000080; | |
| 642 | ||
| 620 | 643 | pub const EFD_SEMAPHORE = 1; |
| 621 | 644 | pub const EFD_CLOEXEC = O_CLOEXEC; |
| 622 | 645 | pub const EFD_NONBLOCK = O_NONBLOCK; |
| ... | ... | @@ -790,13 +813,13 @@ pub const app_mask: sigset_t = [2]u32{ 0xfffffffc, 0x7fffffff } ++ [_]u32{0xffff |
| 790 | 813 | pub const k_sigaction = if (is_mips) |
| 791 | 814 | extern struct { |
| 792 | 815 | flags: usize, |
| 793 | sigaction: ?extern fn (i32, *siginfo_t, *c_void) void, | |
| 816 | sigaction: ?extern fn (i32, *siginfo_t, ?*c_void) void, | |
| 794 | 817 | mask: [4]u32, |
| 795 | 818 | restorer: extern fn () void, |
| 796 | 819 | } |
| 797 | 820 | else |
| 798 | 821 | extern struct { |
| 799 | sigaction: ?extern fn (i32, *siginfo_t, *c_void) void, | |
| 822 | sigaction: ?extern fn (i32, *siginfo_t, ?*c_void) void, | |
| 800 | 823 | flags: usize, |
| 801 | 824 | restorer: extern fn () void, |
| 802 | 825 | mask: [2]u32, |
| ... | ... | @@ -804,15 +827,17 @@ else |
| 804 | 827 | |
| 805 | 828 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. |
| 806 | 829 | pub const Sigaction = extern struct { |
| 807 | sigaction: ?extern fn (i32, *siginfo_t, *c_void) void, | |
| 830 | pub const sigaction_fn = fn (i32, *siginfo_t, ?*c_void) callconv(.C) void; | |
| 831 | sigaction: ?sigaction_fn, | |
| 808 | 832 | mask: sigset_t, |
| 809 | 833 | flags: u32, |
| 810 | 834 | restorer: ?extern fn () void = null, |
| 811 | 835 | }; |
| 812 | 836 | |
| 813 | pub const SIG_ERR = @intToPtr(extern fn (i32, *siginfo_t, *c_void) void, maxInt(usize)); | |
| 814 | pub const SIG_DFL = @intToPtr(?extern fn (i32, *siginfo_t, *c_void) void, 0); | |
| 815 | pub const SIG_IGN = @intToPtr(extern fn (i32, *siginfo_t, *c_void) void, 1); | |
| 837 | pub const SIG_ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize)); | |
| 838 | pub const SIG_DFL = @intToPtr(?Sigaction.sigaction_fn, 0); | |
| 839 | pub const SIG_IGN = @intToPtr(?Sigaction.sigaction_fn, 1); | |
| 840 | ||
| 816 | 841 | pub const empty_sigset = [_]u32{0} ** sigset_t.len; |
| 817 | 842 | |
| 818 | 843 | pub const in_port_t = u16; |
| ... | ... | @@ -1125,7 +1150,8 @@ pub const io_uring_params = extern struct { |
| 1125 | 1150 | sq_thread_cpu: u32, |
| 1126 | 1151 | sq_thread_idle: u32, |
| 1127 | 1152 | features: u32, |
| 1128 | resv: [4]u32, | |
| 1153 | wq_fd: u32, | |
| 1154 | resv: [3]u32, | |
| 1129 | 1155 | sq_off: io_sqring_offsets, |
| 1130 | 1156 | cq_off: io_cqring_offsets, |
| 1131 | 1157 | }; |
| ... | ... | @@ -1135,6 +1161,8 @@ pub const io_uring_params = extern struct { |
| 1135 | 1161 | pub const IORING_FEAT_SINGLE_MMAP = 1 << 0; |
| 1136 | 1162 | pub const IORING_FEAT_NODROP = 1 << 1; |
| 1137 | 1163 | pub const IORING_FEAT_SUBMIT_STABLE = 1 << 2; |
| 1164 | pub const IORING_FEAT_RW_CUR_POS = 1 << 3; | |
| 1165 | pub const IORING_FEAT_CUR_PERSONALITY = 1 << 4; | |
| 1138 | 1166 | |
| 1139 | 1167 | // io_uring_params.flags |
| 1140 | 1168 | |
| ... | ... | @@ -1150,6 +1178,12 @@ pub const IORING_SETUP_SQ_AFF = 1 << 2; |
| 1150 | 1178 | /// app defines CQ size |
| 1151 | 1179 | pub const IORING_SETUP_CQSIZE = 1 << 3; |
| 1152 | 1180 | |
| 1181 | /// clamp SQ/CQ ring sizes | |
| 1182 | pub const IORING_SETUP_CLAMP = 1 << 4; | |
| 1183 | ||
| 1184 | /// attach to existing wq | |
| 1185 | pub const IORING_SETUP_ATTACH_WQ = 1 << 5; | |
| 1186 | ||
| 1153 | 1187 | pub const io_sqring_offsets = extern struct { |
| 1154 | 1188 | /// offset of ring head |
| 1155 | 1189 | head: u32, |
| ... | ... | @@ -1192,7 +1226,7 @@ pub const io_cqring_offsets = extern struct { |
| 1192 | 1226 | }; |
| 1193 | 1227 | |
| 1194 | 1228 | pub const io_uring_sqe = extern struct { |
| 1195 | opcode: u8, | |
| 1229 | opcode: IORING_OP, | |
| 1196 | 1230 | flags: u8, |
| 1197 | 1231 | ioprio: u16, |
| 1198 | 1232 | fd: i32, |
| ... | ... | @@ -1212,31 +1246,53 @@ pub const io_uring_sqe = extern struct { |
| 1212 | 1246 | timeout_flags: u32, |
| 1213 | 1247 | accept_flags: u32, |
| 1214 | 1248 | cancel_flags: u32, |
| 1249 | open_flags: u32, | |
| 1250 | statx_flags: u32, | |
| 1251 | fadvise_flags: u32, | |
| 1215 | 1252 | }; |
| 1216 | 1253 | union2: union2, |
| 1217 | 1254 | user_data: u64, |
| 1218 | 1255 | pub const union3 = extern union { |
| 1219 | buf_index: u16, | |
| 1256 | struct1: extern struct { | |
| 1257 | /// index into fixed buffers, if used | |
| 1258 | buf_index: u16, | |
| 1259 | ||
| 1260 | /// personality to use, if used | |
| 1261 | personality: u16, | |
| 1262 | }, | |
| 1220 | 1263 | __pad2: [3]u64, |
| 1221 | 1264 | }; |
| 1222 | 1265 | union3: union3, |
| 1223 | 1266 | }; |
| 1224 | 1267 | |
| 1268 | pub const IOSQE_BIT = extern enum { | |
| 1269 | FIXED_FILE, | |
| 1270 | IO_DRAIN, | |
| 1271 | IO_LINK, | |
| 1272 | IO_HARDLINK, | |
| 1273 | ASYNC, | |
| 1274 | ||
| 1275 | _, | |
| 1276 | }; | |
| 1277 | ||
| 1225 | 1278 | // io_uring_sqe.flags |
| 1226 | 1279 | |
| 1227 | 1280 | /// use fixed fileset |
| 1228 | pub const IOSQE_FIXED_FILE = 1 << 0; | |
| 1281 | pub const IOSQE_FIXED_FILE = 1 << IOSQE_BIT.FIXED_FILE; | |
| 1229 | 1282 | |
| 1230 | 1283 | /// issue after inflight IO |
| 1231 | pub const IOSQE_IO_DRAIN = 1 << 1; | |
| 1284 | pub const IOSQE_IO_DRAIN = 1 << IOSQE_BIT.IO_DRAIN; | |
| 1232 | 1285 | |
| 1233 | 1286 | /// links next sqe |
| 1234 | pub const IOSQE_IO_LINK = 1 << 2; | |
| 1287 | pub const IOSQE_IO_LINK = 1 << IOSQE_BIT.IO_LINK; | |
| 1235 | 1288 | |
| 1236 | 1289 | /// like LINK, but stronger |
| 1237 | pub const IOSQE_IO_HARDLINK = 1 << 3; | |
| 1290 | pub const IOSQE_IO_HARDLINK = 1 << IOSQE_BIT.IO_HARDLINK; | |
| 1291 | ||
| 1292 | /// always go async | |
| 1293 | pub const IOSQE_ASYNC = 1 << IOSQE_BIT.ASYNC; | |
| 1238 | 1294 | |
| 1239 | pub const IORING_OP = extern enum { | |
| 1295 | pub const IORING_OP = extern enum(u8) { | |
| 1240 | 1296 | NOP, |
| 1241 | 1297 | READV, |
| 1242 | 1298 | WRITEV, |
| ... | ... | @@ -1254,6 +1310,19 @@ pub const IORING_OP = extern enum { |
| 1254 | 1310 | ASYNC_CANCEL, |
| 1255 | 1311 | LINK_TIMEOUT, |
| 1256 | 1312 | CONNECT, |
| 1313 | FALLOCATE, | |
| 1314 | OPENAT, | |
| 1315 | CLOSE, | |
| 1316 | FILES_UPDATE, | |
| 1317 | STATX, | |
| 1318 | READ, | |
| 1319 | WRITE, | |
| 1320 | FADVISE, | |
| 1321 | MADVISE, | |
| 1322 | SEND, | |
| 1323 | RECV, | |
| 1324 | OPENAT2, | |
| 1325 | EPOLL_CTL, | |
| 1257 | 1326 | |
| 1258 | 1327 | _, |
| 1259 | 1328 | }; |
| ... | ... | @@ -1283,13 +1352,21 @@ pub const IORING_ENTER_GETEVENTS = 1 << 0; |
| 1283 | 1352 | pub const IORING_ENTER_SQ_WAKEUP = 1 << 1; |
| 1284 | 1353 | |
| 1285 | 1354 | // io_uring_register opcodes and arguments |
| 1286 | pub const IORING_REGISTER_BUFFERS = 0; | |
| 1287 | pub const IORING_UNREGISTER_BUFFERS = 1; | |
| 1288 | pub const IORING_REGISTER_FILES = 2; | |
| 1289 | pub const IORING_UNREGISTER_FILES = 3; | |
| 1290 | pub const IORING_REGISTER_EVENTFD = 4; | |
| 1291 | pub const IORING_UNREGISTER_EVENTFD = 5; | |
| 1292 | pub const IORING_REGISTER_FILES_UPDATE = 6; | |
| 1355 | pub const IORING_REGISTER = extern enum(u32) { | |
| 1356 | REGISTER_BUFFERS, | |
| 1357 | UNREGISTER_BUFFERS, | |
| 1358 | REGISTER_FILES, | |
| 1359 | UNREGISTER_FILES, | |
| 1360 | REGISTER_EVENTFD, | |
| 1361 | UNREGISTER_EVENTFD, | |
| 1362 | REGISTER_FILES_UPDATE, | |
| 1363 | REGISTER_EVENTFD_ASYNC, | |
| 1364 | REGISTER_PROBE, | |
| 1365 | REGISTER_PERSONALITY, | |
| 1366 | UNREGISTER_PERSONALITY, | |
| 1367 | ||
| 1368 | _, | |
| 1369 | }; | |
| 1293 | 1370 | |
| 1294 | 1371 | pub const io_uring_files_update = struct { |
| 1295 | 1372 | offset: u32, |
| ... | ... | @@ -1297,6 +1374,32 @@ pub const io_uring_files_update = struct { |
| 1297 | 1374 | fds: u64, |
| 1298 | 1375 | }; |
| 1299 | 1376 | |
| 1377 | pub const IO_URING_OP_SUPPORTED = 1 << 0; | |
| 1378 | ||
| 1379 | pub const io_uring_probe_op = struct { | |
| 1380 | op: IORING_OP, | |
| 1381 | ||
| 1382 | resv: u8, | |
| 1383 | ||
| 1384 | /// IO_URING_OP_* flags | |
| 1385 | flags: u16, | |
| 1386 | ||
| 1387 | resv2: u32, | |
| 1388 | }; | |
| 1389 | ||
| 1390 | pub const io_uring_probe = struct { | |
| 1391 | /// last opcode supported | |
| 1392 | last_op: IORING_OP, | |
| 1393 | ||
| 1394 | /// Number of io_uring_probe_op following | |
| 1395 | ops_len: u8, | |
| 1396 | ||
| 1397 | resv: u16, | |
| 1398 | resv2: u32[3], | |
| 1399 | ||
| 1400 | // Followed by up to `ops_len` io_uring_probe_op structures | |
| 1401 | }; | |
| 1402 | ||
| 1300 | 1403 | pub const utsname = extern struct { |
| 1301 | 1404 | sysname: [64:0]u8, |
| 1302 | 1405 | nodename: [64:0]u8, |
lib/std/os/bits/linux/arm-eabi.zig+404-398| ... | ... | @@ -10,404 +10,410 @@ const uid_t = linux.uid_t; |
| 10 | 10 | const gid_t = linux.gid_t; |
| 11 | 11 | const pid_t = linux.pid_t; |
| 12 | 12 | |
| 13 | pub const SYS_restart_syscall = 0; | |
| 14 | pub const SYS_exit = 1; | |
| 15 | pub const SYS_fork = 2; | |
| 16 | pub const SYS_read = 3; | |
| 17 | pub const SYS_write = 4; | |
| 18 | pub const SYS_open = 5; | |
| 19 | pub const SYS_close = 6; | |
| 20 | pub const SYS_creat = 8; | |
| 21 | pub const SYS_link = 9; | |
| 22 | pub const SYS_unlink = 10; | |
| 23 | pub const SYS_execve = 11; | |
| 24 | pub const SYS_chdir = 12; | |
| 25 | pub const SYS_mknod = 14; | |
| 26 | pub const SYS_chmod = 15; | |
| 27 | pub const SYS_lchown = 16; | |
| 28 | pub const SYS_lseek = 19; | |
| 29 | pub const SYS_getpid = 20; | |
| 30 | pub const SYS_mount = 21; | |
| 31 | pub const SYS_setuid = 23; | |
| 32 | pub const SYS_getuid = 24; | |
| 33 | pub const SYS_ptrace = 26; | |
| 34 | pub const SYS_pause = 29; | |
| 35 | pub const SYS_access = 33; | |
| 36 | pub const SYS_nice = 34; | |
| 37 | pub const SYS_sync = 36; | |
| 38 | pub const SYS_kill = 37; | |
| 39 | pub const SYS_rename = 38; | |
| 40 | pub const SYS_mkdir = 39; | |
| 41 | pub const SYS_rmdir = 40; | |
| 42 | pub const SYS_dup = 41; | |
| 43 | pub const SYS_pipe = 42; | |
| 44 | pub const SYS_times = 43; | |
| 45 | pub const SYS_brk = 45; | |
| 46 | pub const SYS_setgid = 46; | |
| 47 | pub const SYS_getgid = 47; | |
| 48 | pub const SYS_geteuid = 49; | |
| 49 | pub const SYS_getegid = 50; | |
| 50 | pub const SYS_acct = 51; | |
| 51 | pub const SYS_umount2 = 52; | |
| 52 | pub const SYS_ioctl = 54; | |
| 53 | pub const SYS_fcntl = 55; | |
| 54 | pub const SYS_setpgid = 57; | |
| 55 | pub const SYS_umask = 60; | |
| 56 | pub const SYS_chroot = 61; | |
| 57 | pub const SYS_ustat = 62; | |
| 58 | pub const SYS_dup2 = 63; | |
| 59 | pub const SYS_getppid = 64; | |
| 60 | pub const SYS_getpgrp = 65; | |
| 61 | pub const SYS_setsid = 66; | |
| 62 | pub const SYS_sigaction = 67; | |
| 63 | pub const SYS_setreuid = 70; | |
| 64 | pub const SYS_setregid = 71; | |
| 65 | pub const SYS_sigsuspend = 72; | |
| 66 | pub const SYS_sigpending = 73; | |
| 67 | pub const SYS_sethostname = 74; | |
| 68 | pub const SYS_setrlimit = 75; | |
| 69 | pub const SYS_getrusage = 77; | |
| 70 | pub const SYS_gettimeofday = 78; | |
| 71 | pub const SYS_settimeofday = 79; | |
| 72 | pub const SYS_getgroups = 80; | |
| 73 | pub const SYS_setgroups = 81; | |
| 74 | pub const SYS_symlink = 83; | |
| 75 | pub const SYS_readlink = 85; | |
| 76 | pub const SYS_uselib = 86; | |
| 77 | pub const SYS_swapon = 87; | |
| 78 | pub const SYS_reboot = 88; | |
| 79 | pub const SYS_munmap = 91; | |
| 80 | pub const SYS_truncate = 92; | |
| 81 | pub const SYS_ftruncate = 93; | |
| 82 | pub const SYS_fchmod = 94; | |
| 83 | pub const SYS_fchown = 95; | |
| 84 | pub const SYS_getpriority = 96; | |
| 85 | pub const SYS_setpriority = 97; | |
| 86 | pub const SYS_statfs = 99; | |
| 87 | pub const SYS_fstatfs = 100; | |
| 88 | pub const SYS_syslog = 103; | |
| 89 | pub const SYS_setitimer = 104; | |
| 90 | pub const SYS_getitimer = 105; | |
| 91 | pub const SYS_stat = 106; | |
| 92 | pub const SYS_lstat = 107; | |
| 93 | pub const SYS_fstat = 108; | |
| 94 | pub const SYS_vhangup = 111; | |
| 95 | pub const SYS_wait4 = 114; | |
| 96 | pub const SYS_swapoff = 115; | |
| 97 | pub const SYS_sysinfo = 116; | |
| 98 | pub const SYS_fsync = 118; | |
| 99 | pub const SYS_sigreturn = 119; | |
| 100 | pub const SYS_clone = 120; | |
| 101 | pub const SYS_setdomainname = 121; | |
| 102 | pub const SYS_uname = 122; | |
| 103 | pub const SYS_adjtimex = 124; | |
| 104 | pub const SYS_mprotect = 125; | |
| 105 | pub const SYS_sigprocmask = 126; | |
| 106 | pub const SYS_init_module = 128; | |
| 107 | pub const SYS_delete_module = 129; | |
| 108 | pub const SYS_quotactl = 131; | |
| 109 | pub const SYS_getpgid = 132; | |
| 110 | pub const SYS_fchdir = 133; | |
| 111 | pub const SYS_bdflush = 134; | |
| 112 | pub const SYS_sysfs = 135; | |
| 113 | pub const SYS_personality = 136; | |
| 114 | pub const SYS_setfsuid = 138; | |
| 115 | pub const SYS_setfsgid = 139; | |
| 116 | pub const SYS__llseek = 140; | |
| 117 | pub const SYS_getdents = 141; | |
| 118 | pub const SYS__newselect = 142; | |
| 119 | pub const SYS_flock = 143; | |
| 120 | pub const SYS_msync = 144; | |
| 121 | pub const SYS_readv = 145; | |
| 122 | pub const SYS_writev = 146; | |
| 123 | pub const SYS_getsid = 147; | |
| 124 | pub const SYS_fdatasync = 148; | |
| 125 | pub const SYS__sysctl = 149; | |
| 126 | pub const SYS_mlock = 150; | |
| 127 | pub const SYS_munlock = 151; | |
| 128 | pub const SYS_mlockall = 152; | |
| 129 | pub const SYS_munlockall = 153; | |
| 130 | pub const SYS_sched_setparam = 154; | |
| 131 | pub const SYS_sched_getparam = 155; | |
| 132 | pub const SYS_sched_setscheduler = 156; | |
| 133 | pub const SYS_sched_getscheduler = 157; | |
| 134 | pub const SYS_sched_yield = 158; | |
| 135 | pub const SYS_sched_get_priority_max = 159; | |
| 136 | pub const SYS_sched_get_priority_min = 160; | |
| 137 | pub const SYS_sched_rr_get_interval = 161; | |
| 138 | pub const SYS_nanosleep = 162; | |
| 139 | pub const SYS_mremap = 163; | |
| 140 | pub const SYS_setresuid = 164; | |
| 141 | pub const SYS_getresuid = 165; | |
| 142 | pub const SYS_poll = 168; | |
| 143 | pub const SYS_nfsservctl = 169; | |
| 144 | pub const SYS_setresgid = 170; | |
| 145 | pub const SYS_getresgid = 171; | |
| 146 | pub const SYS_prctl = 172; | |
| 147 | pub const SYS_rt_sigreturn = 173; | |
| 148 | pub const SYS_rt_sigaction = 174; | |
| 149 | pub const SYS_rt_sigprocmask = 175; | |
| 150 | pub const SYS_rt_sigpending = 176; | |
| 151 | pub const SYS_rt_sigtimedwait = 177; | |
| 152 | pub const SYS_rt_sigqueueinfo = 178; | |
| 153 | pub const SYS_rt_sigsuspend = 179; | |
| 154 | pub const SYS_pread64 = 180; | |
| 155 | pub const SYS_pwrite64 = 181; | |
| 156 | pub const SYS_chown = 182; | |
| 157 | pub const SYS_getcwd = 183; | |
| 158 | pub const SYS_capget = 184; | |
| 159 | pub const SYS_capset = 185; | |
| 160 | pub const SYS_sigaltstack = 186; | |
| 161 | pub const SYS_sendfile = 187; | |
| 162 | pub const SYS_vfork = 190; | |
| 163 | pub const SYS_ugetrlimit = 191; | |
| 164 | pub const SYS_mmap2 = 192; | |
| 165 | pub const SYS_truncate64 = 193; | |
| 166 | pub const SYS_ftruncate64 = 194; | |
| 167 | pub const SYS_stat64 = 195; | |
| 168 | pub const SYS_lstat64 = 196; | |
| 169 | pub const SYS_fstat64 = 197; | |
| 170 | pub const SYS_lchown32 = 198; | |
| 171 | pub const SYS_getuid32 = 199; | |
| 172 | pub const SYS_getgid32 = 200; | |
| 173 | pub const SYS_geteuid32 = 201; | |
| 174 | pub const SYS_getegid32 = 202; | |
| 175 | pub const SYS_setreuid32 = 203; | |
| 176 | pub const SYS_setregid32 = 204; | |
| 177 | pub const SYS_getgroups32 = 205; | |
| 178 | pub const SYS_setgroups32 = 206; | |
| 179 | pub const SYS_fchown32 = 207; | |
| 180 | pub const SYS_setresuid32 = 208; | |
| 181 | pub const SYS_getresuid32 = 209; | |
| 182 | pub const SYS_setresgid32 = 210; | |
| 183 | pub const SYS_getresgid32 = 211; | |
| 184 | pub const SYS_chown32 = 212; | |
| 185 | pub const SYS_setuid32 = 213; | |
| 186 | pub const SYS_setgid32 = 214; | |
| 187 | pub const SYS_setfsuid32 = 215; | |
| 188 | pub const SYS_setfsgid32 = 216; | |
| 189 | pub const SYS_getdents64 = 217; | |
| 190 | pub const SYS_pivot_root = 218; | |
| 191 | pub const SYS_mincore = 219; | |
| 192 | pub const SYS_madvise = 220; | |
| 193 | pub const SYS_fcntl64 = 221; | |
| 194 | pub const SYS_gettid = 224; | |
| 195 | pub const SYS_readahead = 225; | |
| 196 | pub const SYS_setxattr = 226; | |
| 197 | pub const SYS_lsetxattr = 227; | |
| 198 | pub const SYS_fsetxattr = 228; | |
| 199 | pub const SYS_getxattr = 229; | |
| 200 | pub const SYS_lgetxattr = 230; | |
| 201 | pub const SYS_fgetxattr = 231; | |
| 202 | pub const SYS_listxattr = 232; | |
| 203 | pub const SYS_llistxattr = 233; | |
| 204 | pub const SYS_flistxattr = 234; | |
| 205 | pub const SYS_removexattr = 235; | |
| 206 | pub const SYS_lremovexattr = 236; | |
| 207 | pub const SYS_fremovexattr = 237; | |
| 208 | pub const SYS_tkill = 238; | |
| 209 | pub const SYS_sendfile64 = 239; | |
| 210 | pub const SYS_futex = 240; | |
| 211 | pub const SYS_sched_setaffinity = 241; | |
| 212 | pub const SYS_sched_getaffinity = 242; | |
| 213 | pub const SYS_io_setup = 243; | |
| 214 | pub const SYS_io_destroy = 244; | |
| 215 | pub const SYS_io_getevents = 245; | |
| 216 | pub const SYS_io_submit = 246; | |
| 217 | pub const SYS_io_cancel = 247; | |
| 218 | pub const SYS_exit_group = 248; | |
| 219 | pub const SYS_lookup_dcookie = 249; | |
| 220 | pub const SYS_epoll_create = 250; | |
| 221 | pub const SYS_epoll_ctl = 251; | |
| 222 | pub const SYS_epoll_wait = 252; | |
| 223 | pub const SYS_remap_file_pages = 253; | |
| 224 | pub const SYS_set_tid_address = 256; | |
| 225 | pub const SYS_timer_create = 257; | |
| 226 | pub const SYS_timer_settime = 258; | |
| 227 | pub const SYS_timer_gettime = 259; | |
| 228 | pub const SYS_timer_getoverrun = 260; | |
| 229 | pub const SYS_timer_delete = 261; | |
| 230 | pub const SYS_clock_settime = 262; | |
| 231 | pub const SYS_clock_gettime = 263; | |
| 232 | pub const SYS_clock_getres = 264; | |
| 233 | pub const SYS_clock_nanosleep = 265; | |
| 234 | pub const SYS_statfs64 = 266; | |
| 235 | pub const SYS_fstatfs64 = 267; | |
| 236 | pub const SYS_tgkill = 268; | |
| 237 | pub const SYS_utimes = 269; | |
| 238 | pub const SYS_fadvise64_64 = 270; | |
| 239 | pub const SYS_arm_fadvise64_64 = 270; | |
| 240 | pub const SYS_pciconfig_iobase = 271; | |
| 241 | pub const SYS_pciconfig_read = 272; | |
| 242 | pub const SYS_pciconfig_write = 273; | |
| 243 | pub const SYS_mq_open = 274; | |
| 244 | pub const SYS_mq_unlink = 275; | |
| 245 | pub const SYS_mq_timedsend = 276; | |
| 246 | pub const SYS_mq_timedreceive = 277; | |
| 247 | pub const SYS_mq_notify = 278; | |
| 248 | pub const SYS_mq_getsetattr = 279; | |
| 249 | pub const SYS_waitid = 280; | |
| 250 | pub const SYS_socket = 281; | |
| 251 | pub const SYS_bind = 282; | |
| 252 | pub const SYS_connect = 283; | |
| 253 | pub const SYS_listen = 284; | |
| 254 | pub const SYS_accept = 285; | |
| 255 | pub const SYS_getsockname = 286; | |
| 256 | pub const SYS_getpeername = 287; | |
| 257 | pub const SYS_socketpair = 288; | |
| 258 | pub const SYS_send = 289; | |
| 259 | pub const SYS_sendto = 290; | |
| 260 | pub const SYS_recv = 291; | |
| 261 | pub const SYS_recvfrom = 292; | |
| 262 | pub const SYS_shutdown = 293; | |
| 263 | pub const SYS_setsockopt = 294; | |
| 264 | pub const SYS_getsockopt = 295; | |
| 265 | pub const SYS_sendmsg = 296; | |
| 266 | pub const SYS_recvmsg = 297; | |
| 267 | pub const SYS_semop = 298; | |
| 268 | pub const SYS_semget = 299; | |
| 269 | pub const SYS_semctl = 300; | |
| 270 | pub const SYS_msgsnd = 301; | |
| 271 | pub const SYS_msgrcv = 302; | |
| 272 | pub const SYS_msgget = 303; | |
| 273 | pub const SYS_msgctl = 304; | |
| 274 | pub const SYS_shmat = 305; | |
| 275 | pub const SYS_shmdt = 306; | |
| 276 | pub const SYS_shmget = 307; | |
| 277 | pub const SYS_shmctl = 308; | |
| 278 | pub const SYS_add_key = 309; | |
| 279 | pub const SYS_request_key = 310; | |
| 280 | pub const SYS_keyctl = 311; | |
| 281 | pub const SYS_semtimedop = 312; | |
| 282 | pub const SYS_vserver = 313; | |
| 283 | pub const SYS_ioprio_set = 314; | |
| 284 | pub const SYS_ioprio_get = 315; | |
| 285 | pub const SYS_inotify_init = 316; | |
| 286 | pub const SYS_inotify_add_watch = 317; | |
| 287 | pub const SYS_inotify_rm_watch = 318; | |
| 288 | pub const SYS_mbind = 319; | |
| 289 | pub const SYS_get_mempolicy = 320; | |
| 290 | pub const SYS_set_mempolicy = 321; | |
| 291 | pub const SYS_openat = 322; | |
| 292 | pub const SYS_mkdirat = 323; | |
| 293 | pub const SYS_mknodat = 324; | |
| 294 | pub const SYS_fchownat = 325; | |
| 295 | pub const SYS_futimesat = 326; | |
| 296 | pub const SYS_fstatat64 = 327; | |
| 297 | pub const SYS_unlinkat = 328; | |
| 298 | pub const SYS_renameat = 329; | |
| 299 | pub const SYS_linkat = 330; | |
| 300 | pub const SYS_symlinkat = 331; | |
| 301 | pub const SYS_readlinkat = 332; | |
| 302 | pub const SYS_fchmodat = 333; | |
| 303 | pub const SYS_faccessat = 334; | |
| 304 | pub const SYS_pselect6 = 335; | |
| 305 | pub const SYS_ppoll = 336; | |
| 306 | pub const SYS_unshare = 337; | |
| 307 | pub const SYS_set_robust_list = 338; | |
| 308 | pub const SYS_get_robust_list = 339; | |
| 309 | pub const SYS_splice = 340; | |
| 310 | pub const SYS_sync_file_range2 = 341; | |
| 311 | pub const SYS_arm_sync_file_range = 341; | |
| 312 | pub const SYS_tee = 342; | |
| 313 | pub const SYS_vmsplice = 343; | |
| 314 | pub const SYS_move_pages = 344; | |
| 315 | pub const SYS_getcpu = 345; | |
| 316 | pub const SYS_epoll_pwait = 346; | |
| 317 | pub const SYS_kexec_load = 347; | |
| 318 | pub const SYS_utimensat = 348; | |
| 319 | pub const SYS_signalfd = 349; | |
| 320 | pub const SYS_timerfd_create = 350; | |
| 321 | pub const SYS_eventfd = 351; | |
| 322 | pub const SYS_fallocate = 352; | |
| 323 | pub const SYS_timerfd_settime = 353; | |
| 324 | pub const SYS_timerfd_gettime = 354; | |
| 325 | pub const SYS_signalfd4 = 355; | |
| 326 | pub const SYS_eventfd2 = 356; | |
| 327 | pub const SYS_epoll_create1 = 357; | |
| 328 | pub const SYS_dup3 = 358; | |
| 329 | pub const SYS_pipe2 = 359; | |
| 330 | pub const SYS_inotify_init1 = 360; | |
| 331 | pub const SYS_preadv = 361; | |
| 332 | pub const SYS_pwritev = 362; | |
| 333 | pub const SYS_rt_tgsigqueueinfo = 363; | |
| 334 | pub const SYS_perf_event_open = 364; | |
| 335 | pub const SYS_recvmmsg = 365; | |
| 336 | pub const SYS_accept4 = 366; | |
| 337 | pub const SYS_fanotify_init = 367; | |
| 338 | pub const SYS_fanotify_mark = 368; | |
| 339 | pub const SYS_prlimit64 = 369; | |
| 340 | pub const SYS_name_to_handle_at = 370; | |
| 341 | pub const SYS_open_by_handle_at = 371; | |
| 342 | pub const SYS_clock_adjtime = 372; | |
| 343 | pub const SYS_syncfs = 373; | |
| 344 | pub const SYS_sendmmsg = 374; | |
| 345 | pub const SYS_setns = 375; | |
| 346 | pub const SYS_process_vm_readv = 376; | |
| 347 | pub const SYS_process_vm_writev = 377; | |
| 348 | pub const SYS_kcmp = 378; | |
| 349 | pub const SYS_finit_module = 379; | |
| 350 | pub const SYS_sched_setattr = 380; | |
| 351 | pub const SYS_sched_getattr = 381; | |
| 352 | pub const SYS_renameat2 = 382; | |
| 353 | pub const SYS_seccomp = 383; | |
| 354 | pub const SYS_getrandom = 384; | |
| 355 | pub const SYS_memfd_create = 385; | |
| 356 | pub const SYS_bpf = 386; | |
| 357 | pub const SYS_execveat = 387; | |
| 358 | pub const SYS_userfaultfd = 388; | |
| 359 | pub const SYS_membarrier = 389; | |
| 360 | pub const SYS_mlock2 = 390; | |
| 361 | pub const SYS_copy_file_range = 391; | |
| 362 | pub const SYS_preadv2 = 392; | |
| 363 | pub const SYS_pwritev2 = 393; | |
| 364 | pub const SYS_pkey_mprotect = 394; | |
| 365 | pub const SYS_pkey_alloc = 395; | |
| 366 | pub const SYS_pkey_free = 396; | |
| 367 | pub const SYS_statx = 397; | |
| 368 | pub const SYS_rseq = 398; | |
| 369 | pub const SYS_io_pgetevents = 399; | |
| 370 | pub const SYS_migrate_pages = 400; | |
| 371 | pub const SYS_kexec_file_load = 401; | |
| 372 | pub const SYS_clock_gettime64 = 403; | |
| 373 | pub const SYS_clock_settime64 = 404; | |
| 374 | pub const SYS_clock_adjtime64 = 405; | |
| 375 | pub const SYS_clock_getres_time64 = 406; | |
| 376 | pub const SYS_clock_nanosleep_time64 = 407; | |
| 377 | pub const SYS_timer_gettime64 = 408; | |
| 378 | pub const SYS_timer_settime64 = 409; | |
| 379 | pub const SYS_timerfd_gettime64 = 410; | |
| 380 | pub const SYS_timerfd_settime64 = 411; | |
| 381 | pub const SYS_utimensat_time64 = 412; | |
| 382 | pub const SYS_pselect6_time64 = 413; | |
| 383 | pub const SYS_ppoll_time64 = 414; | |
| 384 | pub const SYS_io_pgetevents_time64 = 416; | |
| 385 | pub const SYS_recvmmsg_time64 = 417; | |
| 386 | pub const SYS_mq_timedsend_time64 = 418; | |
| 387 | pub const SYS_mq_timedreceive_time64 = 419; | |
| 388 | pub const SYS_semtimedop_time64 = 420; | |
| 389 | pub const SYS_rt_sigtimedwait_time64 = 421; | |
| 390 | pub const SYS_futex_time64 = 422; | |
| 391 | pub const SYS_sched_rr_get_interval_time64 = 423; | |
| 392 | pub const SYS_pidfd_send_signal = 424; | |
| 393 | pub const SYS_io_uring_setup = 425; | |
| 394 | pub const SYS_io_uring_enter = 426; | |
| 395 | pub const SYS_io_uring_register = 427; | |
| 396 | pub const SYS_open_tree = 428; | |
| 397 | pub const SYS_move_mount = 429; | |
| 398 | pub const SYS_fsopen = 430; | |
| 399 | pub const SYS_fsconfig = 431; | |
| 400 | pub const SYS_fsmount = 432; | |
| 401 | pub const SYS_fspick = 433; | |
| 402 | pub const SYS_pidfd_open = 434; | |
| 403 | pub const SYS_clone3 = 435; | |
| 404 | ||
| 405 | pub const SYS_breakpoint = 0x0f0001; | |
| 406 | pub const SYS_cacheflush = 0x0f0002; | |
| 407 | pub const SYS_usr26 = 0x0f0003; | |
| 408 | pub const SYS_usr32 = 0x0f0004; | |
| 409 | pub const SYS_set_tls = 0x0f0005; | |
| 410 | pub const SYS_get_tls = 0x0f0006; | |
| 13 | pub const SYS = extern enum(usize) { | |
| 14 | restart_syscall = 0, | |
| 15 | exit = 1, | |
| 16 | fork = 2, | |
| 17 | read = 3, | |
| 18 | write = 4, | |
| 19 | open = 5, | |
| 20 | close = 6, | |
| 21 | creat = 8, | |
| 22 | link = 9, | |
| 23 | unlink = 10, | |
| 24 | execve = 11, | |
| 25 | chdir = 12, | |
| 26 | mknod = 14, | |
| 27 | chmod = 15, | |
| 28 | lchown = 16, | |
| 29 | lseek = 19, | |
| 30 | getpid = 20, | |
| 31 | mount = 21, | |
| 32 | setuid = 23, | |
| 33 | getuid = 24, | |
| 34 | ptrace = 26, | |
| 35 | pause = 29, | |
| 36 | access = 33, | |
| 37 | nice = 34, | |
| 38 | sync = 36, | |
| 39 | kill = 37, | |
| 40 | rename = 38, | |
| 41 | mkdir = 39, | |
| 42 | rmdir = 40, | |
| 43 | dup = 41, | |
| 44 | pipe = 42, | |
| 45 | times = 43, | |
| 46 | brk = 45, | |
| 47 | setgid = 46, | |
| 48 | getgid = 47, | |
| 49 | geteuid = 49, | |
| 50 | getegid = 50, | |
| 51 | acct = 51, | |
| 52 | umount2 = 52, | |
| 53 | ioctl = 54, | |
| 54 | fcntl = 55, | |
| 55 | setpgid = 57, | |
| 56 | umask = 60, | |
| 57 | chroot = 61, | |
| 58 | ustat = 62, | |
| 59 | dup2 = 63, | |
| 60 | getppid = 64, | |
| 61 | getpgrp = 65, | |
| 62 | setsid = 66, | |
| 63 | sigaction = 67, | |
| 64 | setreuid = 70, | |
| 65 | setregid = 71, | |
| 66 | sigsuspend = 72, | |
| 67 | sigpending = 73, | |
| 68 | sethostname = 74, | |
| 69 | setrlimit = 75, | |
| 70 | getrusage = 77, | |
| 71 | gettimeofday = 78, | |
| 72 | settimeofday = 79, | |
| 73 | getgroups = 80, | |
| 74 | setgroups = 81, | |
| 75 | symlink = 83, | |
| 76 | readlink = 85, | |
| 77 | uselib = 86, | |
| 78 | swapon = 87, | |
| 79 | reboot = 88, | |
| 80 | munmap = 91, | |
| 81 | truncate = 92, | |
| 82 | ftruncate = 93, | |
| 83 | fchmod = 94, | |
| 84 | fchown = 95, | |
| 85 | getpriority = 96, | |
| 86 | setpriority = 97, | |
| 87 | statfs = 99, | |
| 88 | fstatfs = 100, | |
| 89 | syslog = 103, | |
| 90 | setitimer = 104, | |
| 91 | getitimer = 105, | |
| 92 | stat = 106, | |
| 93 | lstat = 107, | |
| 94 | fstat = 108, | |
| 95 | vhangup = 111, | |
| 96 | wait4 = 114, | |
| 97 | swapoff = 115, | |
| 98 | sysinfo = 116, | |
| 99 | fsync = 118, | |
| 100 | sigreturn = 119, | |
| 101 | clone = 120, | |
| 102 | setdomainname = 121, | |
| 103 | uname = 122, | |
| 104 | adjtimex = 124, | |
| 105 | mprotect = 125, | |
| 106 | sigprocmask = 126, | |
| 107 | init_module = 128, | |
| 108 | delete_module = 129, | |
| 109 | quotactl = 131, | |
| 110 | getpgid = 132, | |
| 111 | fchdir = 133, | |
| 112 | bdflush = 134, | |
| 113 | sysfs = 135, | |
| 114 | personality = 136, | |
| 115 | setfsuid = 138, | |
| 116 | setfsgid = 139, | |
| 117 | _llseek = 140, | |
| 118 | getdents = 141, | |
| 119 | _newselect = 142, | |
| 120 | flock = 143, | |
| 121 | msync = 144, | |
| 122 | readv = 145, | |
| 123 | writev = 146, | |
| 124 | getsid = 147, | |
| 125 | fdatasync = 148, | |
| 126 | _sysctl = 149, | |
| 127 | mlock = 150, | |
| 128 | munlock = 151, | |
| 129 | mlockall = 152, | |
| 130 | munlockall = 153, | |
| 131 | sched_setparam = 154, | |
| 132 | sched_getparam = 155, | |
| 133 | sched_setscheduler = 156, | |
| 134 | sched_getscheduler = 157, | |
| 135 | sched_yield = 158, | |
| 136 | sched_get_priority_max = 159, | |
| 137 | sched_get_priority_min = 160, | |
| 138 | sched_rr_get_interval = 161, | |
| 139 | nanosleep = 162, | |
| 140 | mremap = 163, | |
| 141 | setresuid = 164, | |
| 142 | getresuid = 165, | |
| 143 | poll = 168, | |
| 144 | nfsservctl = 169, | |
| 145 | setresgid = 170, | |
| 146 | getresgid = 171, | |
| 147 | prctl = 172, | |
| 148 | rt_sigreturn = 173, | |
| 149 | rt_sigaction = 174, | |
| 150 | rt_sigprocmask = 175, | |
| 151 | rt_sigpending = 176, | |
| 152 | rt_sigtimedwait = 177, | |
| 153 | rt_sigqueueinfo = 178, | |
| 154 | rt_sigsuspend = 179, | |
| 155 | pread64 = 180, | |
| 156 | pwrite64 = 181, | |
| 157 | chown = 182, | |
| 158 | getcwd = 183, | |
| 159 | capget = 184, | |
| 160 | capset = 185, | |
| 161 | sigaltstack = 186, | |
| 162 | sendfile = 187, | |
| 163 | vfork = 190, | |
| 164 | ugetrlimit = 191, | |
| 165 | mmap2 = 192, | |
| 166 | truncate64 = 193, | |
| 167 | ftruncate64 = 194, | |
| 168 | stat64 = 195, | |
| 169 | lstat64 = 196, | |
| 170 | fstat64 = 197, | |
| 171 | lchown32 = 198, | |
| 172 | getuid32 = 199, | |
| 173 | getgid32 = 200, | |
| 174 | geteuid32 = 201, | |
| 175 | getegid32 = 202, | |
| 176 | setreuid32 = 203, | |
| 177 | setregid32 = 204, | |
| 178 | getgroups32 = 205, | |
| 179 | setgroups32 = 206, | |
| 180 | fchown32 = 207, | |
| 181 | setresuid32 = 208, | |
| 182 | getresuid32 = 209, | |
| 183 | setresgid32 = 210, | |
| 184 | getresgid32 = 211, | |
| 185 | chown32 = 212, | |
| 186 | setuid32 = 213, | |
| 187 | setgid32 = 214, | |
| 188 | setfsuid32 = 215, | |
| 189 | setfsgid32 = 216, | |
| 190 | getdents64 = 217, | |
| 191 | pivot_root = 218, | |
| 192 | mincore = 219, | |
| 193 | madvise = 220, | |
| 194 | fcntl64 = 221, | |
| 195 | gettid = 224, | |
| 196 | readahead = 225, | |
| 197 | setxattr = 226, | |
| 198 | lsetxattr = 227, | |
| 199 | fsetxattr = 228, | |
| 200 | getxattr = 229, | |
| 201 | lgetxattr = 230, | |
| 202 | fgetxattr = 231, | |
| 203 | listxattr = 232, | |
| 204 | llistxattr = 233, | |
| 205 | flistxattr = 234, | |
| 206 | removexattr = 235, | |
| 207 | lremovexattr = 236, | |
| 208 | fremovexattr = 237, | |
| 209 | tkill = 238, | |
| 210 | sendfile64 = 239, | |
| 211 | futex = 240, | |
| 212 | sched_setaffinity = 241, | |
| 213 | sched_getaffinity = 242, | |
| 214 | io_setup = 243, | |
| 215 | io_destroy = 244, | |
| 216 | io_getevents = 245, | |
| 217 | io_submit = 246, | |
| 218 | io_cancel = 247, | |
| 219 | exit_group = 248, | |
| 220 | lookup_dcookie = 249, | |
| 221 | epoll_create = 250, | |
| 222 | epoll_ctl = 251, | |
| 223 | epoll_wait = 252, | |
| 224 | remap_file_pages = 253, | |
| 225 | set_tid_address = 256, | |
| 226 | timer_create = 257, | |
| 227 | timer_settime = 258, | |
| 228 | timer_gettime = 259, | |
| 229 | timer_getoverrun = 260, | |
| 230 | timer_delete = 261, | |
| 231 | clock_settime = 262, | |
| 232 | clock_gettime = 263, | |
| 233 | clock_getres = 264, | |
| 234 | clock_nanosleep = 265, | |
| 235 | statfs64 = 266, | |
| 236 | fstatfs64 = 267, | |
| 237 | tgkill = 268, | |
| 238 | utimes = 269, | |
| 239 | fadvise64_64 = 270, | |
| 240 | arm_fadvise64_64 = 270, | |
| 241 | pciconfig_iobase = 271, | |
| 242 | pciconfig_read = 272, | |
| 243 | pciconfig_write = 273, | |
| 244 | mq_open = 274, | |
| 245 | mq_unlink = 275, | |
| 246 | mq_timedsend = 276, | |
| 247 | mq_timedreceive = 277, | |
| 248 | mq_notify = 278, | |
| 249 | mq_getsetattr = 279, | |
| 250 | waitid = 280, | |
| 251 | socket = 281, | |
| 252 | bind = 282, | |
| 253 | connect = 283, | |
| 254 | listen = 284, | |
| 255 | accept = 285, | |
| 256 | getsockname = 286, | |
| 257 | getpeername = 287, | |
| 258 | socketpair = 288, | |
| 259 | send = 289, | |
| 260 | sendto = 290, | |
| 261 | recv = 291, | |
| 262 | recvfrom = 292, | |
| 263 | shutdown = 293, | |
| 264 | setsockopt = 294, | |
| 265 | getsockopt = 295, | |
| 266 | sendmsg = 296, | |
| 267 | recvmsg = 297, | |
| 268 | semop = 298, | |
| 269 | semget = 299, | |
| 270 | semctl = 300, | |
| 271 | msgsnd = 301, | |
| 272 | msgrcv = 302, | |
| 273 | msgget = 303, | |
| 274 | msgctl = 304, | |
| 275 | shmat = 305, | |
| 276 | shmdt = 306, | |
| 277 | shmget = 307, | |
| 278 | shmctl = 308, | |
| 279 | add_key = 309, | |
| 280 | request_key = 310, | |
| 281 | keyctl = 311, | |
| 282 | semtimedop = 312, | |
| 283 | vserver = 313, | |
| 284 | ioprio_set = 314, | |
| 285 | ioprio_get = 315, | |
| 286 | inotify_init = 316, | |
| 287 | inotify_add_watch = 317, | |
| 288 | inotify_rm_watch = 318, | |
| 289 | mbind = 319, | |
| 290 | get_mempolicy = 320, | |
| 291 | set_mempolicy = 321, | |
| 292 | openat = 322, | |
| 293 | mkdirat = 323, | |
| 294 | mknodat = 324, | |
| 295 | fchownat = 325, | |
| 296 | futimesat = 326, | |
| 297 | fstatat64 = 327, | |
| 298 | unlinkat = 328, | |
| 299 | renameat = 329, | |
| 300 | linkat = 330, | |
| 301 | symlinkat = 331, | |
| 302 | readlinkat = 332, | |
| 303 | fchmodat = 333, | |
| 304 | faccessat = 334, | |
| 305 | pselect6 = 335, | |
| 306 | ppoll = 336, | |
| 307 | unshare = 337, | |
| 308 | set_robust_list = 338, | |
| 309 | get_robust_list = 339, | |
| 310 | splice = 340, | |
| 311 | sync_file_range2 = 341, | |
| 312 | arm_sync_file_range = 341, | |
| 313 | tee = 342, | |
| 314 | vmsplice = 343, | |
| 315 | move_pages = 344, | |
| 316 | getcpu = 345, | |
| 317 | epoll_pwait = 346, | |
| 318 | kexec_load = 347, | |
| 319 | utimensat = 348, | |
| 320 | signalfd = 349, | |
| 321 | timerfd_create = 350, | |
| 322 | eventfd = 351, | |
| 323 | fallocate = 352, | |
| 324 | timerfd_settime = 353, | |
| 325 | timerfd_gettime = 354, | |
| 326 | signalfd4 = 355, | |
| 327 | eventfd2 = 356, | |
| 328 | epoll_create1 = 357, | |
| 329 | dup3 = 358, | |
| 330 | pipe2 = 359, | |
| 331 | inotify_init1 = 360, | |
| 332 | preadv = 361, | |
| 333 | pwritev = 362, | |
| 334 | rt_tgsigqueueinfo = 363, | |
| 335 | perf_event_open = 364, | |
| 336 | recvmmsg = 365, | |
| 337 | accept4 = 366, | |
| 338 | fanotify_init = 367, | |
| 339 | fanotify_mark = 368, | |
| 340 | prlimit64 = 369, | |
| 341 | name_to_handle_at = 370, | |
| 342 | open_by_handle_at = 371, | |
| 343 | clock_adjtime = 372, | |
| 344 | syncfs = 373, | |
| 345 | sendmmsg = 374, | |
| 346 | setns = 375, | |
| 347 | process_vm_readv = 376, | |
| 348 | process_vm_writev = 377, | |
| 349 | kcmp = 378, | |
| 350 | finit_module = 379, | |
| 351 | sched_setattr = 380, | |
| 352 | sched_getattr = 381, | |
| 353 | renameat2 = 382, | |
| 354 | seccomp = 383, | |
| 355 | getrandom = 384, | |
| 356 | memfd_create = 385, | |
| 357 | bpf = 386, | |
| 358 | execveat = 387, | |
| 359 | userfaultfd = 388, | |
| 360 | membarrier = 389, | |
| 361 | mlock2 = 390, | |
| 362 | copy_file_range = 391, | |
| 363 | preadv2 = 392, | |
| 364 | pwritev2 = 393, | |
| 365 | pkey_mprotect = 394, | |
| 366 | pkey_alloc = 395, | |
| 367 | pkey_free = 396, | |
| 368 | statx = 397, | |
| 369 | rseq = 398, | |
| 370 | io_pgetevents = 399, | |
| 371 | migrate_pages = 400, | |
| 372 | kexec_file_load = 401, | |
| 373 | clock_gettime64 = 403, | |
| 374 | clock_settime64 = 404, | |
| 375 | clock_adjtime64 = 405, | |
| 376 | clock_getres_time64 = 406, | |
| 377 | clock_nanosleep_time64 = 407, | |
| 378 | timer_gettime64 = 408, | |
| 379 | timer_settime64 = 409, | |
| 380 | timerfd_gettime64 = 410, | |
| 381 | timerfd_settime64 = 411, | |
| 382 | utimensat_time64 = 412, | |
| 383 | pselect6_time64 = 413, | |
| 384 | ppoll_time64 = 414, | |
| 385 | io_pgetevents_time64 = 416, | |
| 386 | recvmmsg_time64 = 417, | |
| 387 | mq_timedsend_time64 = 418, | |
| 388 | mq_timedreceive_time64 = 419, | |
| 389 | semtimedop_time64 = 420, | |
| 390 | rt_sigtimedwait_time64 = 421, | |
| 391 | futex_time64 = 422, | |
| 392 | sched_rr_get_interval_time64 = 423, | |
| 393 | pidfd_send_signal = 424, | |
| 394 | io_uring_setup = 425, | |
| 395 | io_uring_enter = 426, | |
| 396 | io_uring_register = 427, | |
| 397 | open_tree = 428, | |
| 398 | move_mount = 429, | |
| 399 | fsopen = 430, | |
| 400 | fsconfig = 431, | |
| 401 | fsmount = 432, | |
| 402 | fspick = 433, | |
| 403 | pidfd_open = 434, | |
| 404 | clone3 = 435, | |
| 405 | openat2 = 437, | |
| 406 | pidfd_getfd = 438, | |
| 407 | ||
| 408 | breakpoint = 0x0f0001, | |
| 409 | cacheflush = 0x0f0002, | |
| 410 | usr26 = 0x0f0003, | |
| 411 | usr32 = 0x0f0004, | |
| 412 | set_tls = 0x0f0005, | |
| 413 | get_tls = 0x0f0006, | |
| 414 | ||
| 415 | _, | |
| 416 | }; | |
| 411 | 417 | |
| 412 | 418 | pub const MMAP2_UNIT = 4096; |
| 413 | 419 |
lib/std/os/bits/linux/arm64.zig+296-291| ... | ... | @@ -11,298 +11,303 @@ const gid_t = linux.gid_t; |
| 11 | 11 | const pid_t = linux.pid_t; |
| 12 | 12 | const stack_t = linux.stack_t; |
| 13 | 13 | const sigset_t = linux.sigset_t; |
| 14 | pub const SYS = extern enum(usize) { | |
| 15 | io_setup = 0, | |
| 16 | io_destroy = 1, | |
| 17 | io_submit = 2, | |
| 18 | io_cancel = 3, | |
| 19 | io_getevents = 4, | |
| 20 | setxattr = 5, | |
| 21 | lsetxattr = 6, | |
| 22 | fsetxattr = 7, | |
| 23 | getxattr = 8, | |
| 24 | lgetxattr = 9, | |
| 25 | fgetxattr = 10, | |
| 26 | listxattr = 11, | |
| 27 | llistxattr = 12, | |
| 28 | flistxattr = 13, | |
| 29 | removexattr = 14, | |
| 30 | lremovexattr = 15, | |
| 31 | fremovexattr = 16, | |
| 32 | getcwd = 17, | |
| 33 | lookup_dcookie = 18, | |
| 34 | eventfd2 = 19, | |
| 35 | epoll_create1 = 20, | |
| 36 | epoll_ctl = 21, | |
| 37 | epoll_pwait = 22, | |
| 38 | dup = 23, | |
| 39 | dup3 = 24, | |
| 40 | fcntl = 25, | |
| 41 | inotify_init1 = 26, | |
| 42 | inotify_add_watch = 27, | |
| 43 | inotify_rm_watch = 28, | |
| 44 | ioctl = 29, | |
| 45 | ioprio_set = 30, | |
| 46 | ioprio_get = 31, | |
| 47 | flock = 32, | |
| 48 | mknodat = 33, | |
| 49 | mkdirat = 34, | |
| 50 | unlinkat = 35, | |
| 51 | symlinkat = 36, | |
| 52 | linkat = 37, | |
| 53 | renameat = 38, | |
| 54 | umount2 = 39, | |
| 55 | mount = 40, | |
| 56 | pivot_root = 41, | |
| 57 | nfsservctl = 42, | |
| 58 | statfs = 43, | |
| 59 | fstatfs = 44, | |
| 60 | truncate = 45, | |
| 61 | ftruncate = 46, | |
| 62 | fallocate = 47, | |
| 63 | faccessat = 48, | |
| 64 | chdir = 49, | |
| 65 | fchdir = 50, | |
| 66 | chroot = 51, | |
| 67 | fchmod = 52, | |
| 68 | fchmodat = 53, | |
| 69 | fchownat = 54, | |
| 70 | fchown = 55, | |
| 71 | openat = 56, | |
| 72 | close = 57, | |
| 73 | vhangup = 58, | |
| 74 | pipe2 = 59, | |
| 75 | quotactl = 60, | |
| 76 | getdents64 = 61, | |
| 77 | lseek = 62, | |
| 78 | read = 63, | |
| 79 | write = 64, | |
| 80 | readv = 65, | |
| 81 | writev = 66, | |
| 82 | pread64 = 67, | |
| 83 | pwrite64 = 68, | |
| 84 | preadv = 69, | |
| 85 | pwritev = 70, | |
| 86 | sendfile = 71, | |
| 87 | pselect6 = 72, | |
| 88 | ppoll = 73, | |
| 89 | signalfd4 = 74, | |
| 90 | vmsplice = 75, | |
| 91 | splice = 76, | |
| 92 | tee = 77, | |
| 93 | readlinkat = 78, | |
| 94 | fstatat = 79, | |
| 95 | fstat = 80, | |
| 96 | sync = 81, | |
| 97 | fsync = 82, | |
| 98 | fdatasync = 83, | |
| 99 | sync_file_range2 = 84, | |
| 100 | sync_file_range = 84, | |
| 101 | timerfd_create = 85, | |
| 102 | timerfd_settime = 86, | |
| 103 | timerfd_gettime = 87, | |
| 104 | utimensat = 88, | |
| 105 | acct = 89, | |
| 106 | capget = 90, | |
| 107 | capset = 91, | |
| 108 | personality = 92, | |
| 109 | exit = 93, | |
| 110 | exit_group = 94, | |
| 111 | waitid = 95, | |
| 112 | set_tid_address = 96, | |
| 113 | unshare = 97, | |
| 114 | futex = 98, | |
| 115 | set_robust_list = 99, | |
| 116 | get_robust_list = 100, | |
| 117 | nanosleep = 101, | |
| 118 | getitimer = 102, | |
| 119 | setitimer = 103, | |
| 120 | kexec_load = 104, | |
| 121 | init_module = 105, | |
| 122 | delete_module = 106, | |
| 123 | timer_create = 107, | |
| 124 | timer_gettime = 108, | |
| 125 | timer_getoverrun = 109, | |
| 126 | timer_settime = 110, | |
| 127 | timer_delete = 111, | |
| 128 | clock_settime = 112, | |
| 129 | clock_gettime = 113, | |
| 130 | clock_getres = 114, | |
| 131 | clock_nanosleep = 115, | |
| 132 | syslog = 116, | |
| 133 | ptrace = 117, | |
| 134 | sched_setparam = 118, | |
| 135 | sched_setscheduler = 119, | |
| 136 | sched_getscheduler = 120, | |
| 137 | sched_getparam = 121, | |
| 138 | sched_setaffinity = 122, | |
| 139 | sched_getaffinity = 123, | |
| 140 | sched_yield = 124, | |
| 141 | sched_get_priority_max = 125, | |
| 142 | sched_get_priority_min = 126, | |
| 143 | sched_rr_get_interval = 127, | |
| 144 | restart_syscall = 128, | |
| 145 | kill = 129, | |
| 146 | tkill = 130, | |
| 147 | tgkill = 131, | |
| 148 | sigaltstack = 132, | |
| 149 | rt_sigsuspend = 133, | |
| 150 | rt_sigaction = 134, | |
| 151 | rt_sigprocmask = 135, | |
| 152 | rt_sigpending = 136, | |
| 153 | rt_sigtimedwait = 137, | |
| 154 | rt_sigqueueinfo = 138, | |
| 155 | rt_sigreturn = 139, | |
| 156 | setpriority = 140, | |
| 157 | getpriority = 141, | |
| 158 | reboot = 142, | |
| 159 | setregid = 143, | |
| 160 | setgid = 144, | |
| 161 | setreuid = 145, | |
| 162 | setuid = 146, | |
| 163 | setresuid = 147, | |
| 164 | getresuid = 148, | |
| 165 | setresgid = 149, | |
| 166 | getresgid = 150, | |
| 167 | setfsuid = 151, | |
| 168 | setfsgid = 152, | |
| 169 | times = 153, | |
| 170 | setpgid = 154, | |
| 171 | getpgid = 155, | |
| 172 | getsid = 156, | |
| 173 | setsid = 157, | |
| 174 | getgroups = 158, | |
| 175 | setgroups = 159, | |
| 176 | uname = 160, | |
| 177 | sethostname = 161, | |
| 178 | setdomainname = 162, | |
| 179 | getrlimit = 163, | |
| 180 | setrlimit = 164, | |
| 181 | getrusage = 165, | |
| 182 | umask = 166, | |
| 183 | prctl = 167, | |
| 184 | getcpu = 168, | |
| 185 | gettimeofday = 169, | |
| 186 | settimeofday = 170, | |
| 187 | adjtimex = 171, | |
| 188 | getpid = 172, | |
| 189 | getppid = 173, | |
| 190 | getuid = 174, | |
| 191 | geteuid = 175, | |
| 192 | getgid = 176, | |
| 193 | getegid = 177, | |
| 194 | gettid = 178, | |
| 195 | sysinfo = 179, | |
| 196 | mq_open = 180, | |
| 197 | mq_unlink = 181, | |
| 198 | mq_timedsend = 182, | |
| 199 | mq_timedreceive = 183, | |
| 200 | mq_notify = 184, | |
| 201 | mq_getsetattr = 185, | |
| 202 | msgget = 186, | |
| 203 | msgctl = 187, | |
| 204 | msgrcv = 188, | |
| 205 | msgsnd = 189, | |
| 206 | semget = 190, | |
| 207 | semctl = 191, | |
| 208 | semtimedop = 192, | |
| 209 | semop = 193, | |
| 210 | shmget = 194, | |
| 211 | shmctl = 195, | |
| 212 | shmat = 196, | |
| 213 | shmdt = 197, | |
| 214 | socket = 198, | |
| 215 | socketpair = 199, | |
| 216 | bind = 200, | |
| 217 | listen = 201, | |
| 218 | accept = 202, | |
| 219 | connect = 203, | |
| 220 | getsockname = 204, | |
| 221 | getpeername = 205, | |
| 222 | sendto = 206, | |
| 223 | recvfrom = 207, | |
| 224 | setsockopt = 208, | |
| 225 | getsockopt = 209, | |
| 226 | shutdown = 210, | |
| 227 | sendmsg = 211, | |
| 228 | recvmsg = 212, | |
| 229 | readahead = 213, | |
| 230 | brk = 214, | |
| 231 | munmap = 215, | |
| 232 | mremap = 216, | |
| 233 | add_key = 217, | |
| 234 | request_key = 218, | |
| 235 | keyctl = 219, | |
| 236 | clone = 220, | |
| 237 | execve = 221, | |
| 238 | mmap = 222, | |
| 239 | fadvise64 = 223, | |
| 240 | swapon = 224, | |
| 241 | swapoff = 225, | |
| 242 | mprotect = 226, | |
| 243 | msync = 227, | |
| 244 | mlock = 228, | |
| 245 | munlock = 229, | |
| 246 | mlockall = 230, | |
| 247 | munlockall = 231, | |
| 248 | mincore = 232, | |
| 249 | madvise = 233, | |
| 250 | remap_file_pages = 234, | |
| 251 | mbind = 235, | |
| 252 | get_mempolicy = 236, | |
| 253 | set_mempolicy = 237, | |
| 254 | migrate_pages = 238, | |
| 255 | move_pages = 239, | |
| 256 | rt_tgsigqueueinfo = 240, | |
| 257 | perf_event_open = 241, | |
| 258 | accept4 = 242, | |
| 259 | recvmmsg = 243, | |
| 260 | arch_specific_syscall = 244, | |
| 261 | wait4 = 260, | |
| 262 | prlimit64 = 261, | |
| 263 | fanotify_init = 262, | |
| 264 | fanotify_mark = 263, | |
| 265 | clock_adjtime = 266, | |
| 266 | syncfs = 267, | |
| 267 | setns = 268, | |
| 268 | sendmmsg = 269, | |
| 269 | process_vm_readv = 270, | |
| 270 | process_vm_writev = 271, | |
| 271 | kcmp = 272, | |
| 272 | finit_module = 273, | |
| 273 | sched_setattr = 274, | |
| 274 | sched_getattr = 275, | |
| 275 | renameat2 = 276, | |
| 276 | seccomp = 277, | |
| 277 | getrandom = 278, | |
| 278 | memfd_create = 279, | |
| 279 | bpf = 280, | |
| 280 | execveat = 281, | |
| 281 | userfaultfd = 282, | |
| 282 | membarrier = 283, | |
| 283 | mlock2 = 284, | |
| 284 | copy_file_range = 285, | |
| 285 | preadv2 = 286, | |
| 286 | pwritev2 = 287, | |
| 287 | pkey_mprotect = 288, | |
| 288 | pkey_alloc = 289, | |
| 289 | pkey_free = 290, | |
| 290 | statx = 291, | |
| 291 | io_pgetevents = 292, | |
| 292 | rseq = 293, | |
| 293 | kexec_file_load = 294, | |
| 294 | pidfd_send_signal = 424, | |
| 295 | io_uring_setup = 425, | |
| 296 | io_uring_enter = 426, | |
| 297 | io_uring_register = 427, | |
| 298 | open_tree = 428, | |
| 299 | move_mount = 429, | |
| 300 | fsopen = 430, | |
| 301 | fsconfig = 431, | |
| 302 | fsmount = 432, | |
| 303 | fspick = 433, | |
| 304 | pidfd_open = 434, | |
| 305 | clone3 = 435, | |
| 306 | openat2 = 437, | |
| 307 | pidfd_getfd = 438, | |
| 14 | 308 | |
| 15 | pub const SYS_io_setup = 0; | |
| 16 | pub const SYS_io_destroy = 1; | |
| 17 | pub const SYS_io_submit = 2; | |
| 18 | pub const SYS_io_cancel = 3; | |
| 19 | pub const SYS_io_getevents = 4; | |
| 20 | pub const SYS_setxattr = 5; | |
| 21 | pub const SYS_lsetxattr = 6; | |
| 22 | pub const SYS_fsetxattr = 7; | |
| 23 | pub const SYS_getxattr = 8; | |
| 24 | pub const SYS_lgetxattr = 9; | |
| 25 | pub const SYS_fgetxattr = 10; | |
| 26 | pub const SYS_listxattr = 11; | |
| 27 | pub const SYS_llistxattr = 12; | |
| 28 | pub const SYS_flistxattr = 13; | |
| 29 | pub const SYS_removexattr = 14; | |
| 30 | pub const SYS_lremovexattr = 15; | |
| 31 | pub const SYS_fremovexattr = 16; | |
| 32 | pub const SYS_getcwd = 17; | |
| 33 | pub const SYS_lookup_dcookie = 18; | |
| 34 | pub const SYS_eventfd2 = 19; | |
| 35 | pub const SYS_epoll_create1 = 20; | |
| 36 | pub const SYS_epoll_ctl = 21; | |
| 37 | pub const SYS_epoll_pwait = 22; | |
| 38 | pub const SYS_dup = 23; | |
| 39 | pub const SYS_dup3 = 24; | |
| 40 | pub const SYS_fcntl = 25; | |
| 41 | pub const SYS_inotify_init1 = 26; | |
| 42 | pub const SYS_inotify_add_watch = 27; | |
| 43 | pub const SYS_inotify_rm_watch = 28; | |
| 44 | pub const SYS_ioctl = 29; | |
| 45 | pub const SYS_ioprio_set = 30; | |
| 46 | pub const SYS_ioprio_get = 31; | |
| 47 | pub const SYS_flock = 32; | |
| 48 | pub const SYS_mknodat = 33; | |
| 49 | pub const SYS_mkdirat = 34; | |
| 50 | pub const SYS_unlinkat = 35; | |
| 51 | pub const SYS_symlinkat = 36; | |
| 52 | pub const SYS_linkat = 37; | |
| 53 | pub const SYS_renameat = 38; | |
| 54 | pub const SYS_umount2 = 39; | |
| 55 | pub const SYS_mount = 40; | |
| 56 | pub const SYS_pivot_root = 41; | |
| 57 | pub const SYS_nfsservctl = 42; | |
| 58 | pub const SYS_statfs = 43; | |
| 59 | pub const SYS_fstatfs = 44; | |
| 60 | pub const SYS_truncate = 45; | |
| 61 | pub const SYS_ftruncate = 46; | |
| 62 | pub const SYS_fallocate = 47; | |
| 63 | pub const SYS_faccessat = 48; | |
| 64 | pub const SYS_chdir = 49; | |
| 65 | pub const SYS_fchdir = 50; | |
| 66 | pub const SYS_chroot = 51; | |
| 67 | pub const SYS_fchmod = 52; | |
| 68 | pub const SYS_fchmodat = 53; | |
| 69 | pub const SYS_fchownat = 54; | |
| 70 | pub const SYS_fchown = 55; | |
| 71 | pub const SYS_openat = 56; | |
| 72 | pub const SYS_close = 57; | |
| 73 | pub const SYS_vhangup = 58; | |
| 74 | pub const SYS_pipe2 = 59; | |
| 75 | pub const SYS_quotactl = 60; | |
| 76 | pub const SYS_getdents64 = 61; | |
| 77 | pub const SYS_lseek = 62; | |
| 78 | pub const SYS_read = 63; | |
| 79 | pub const SYS_write = 64; | |
| 80 | pub const SYS_readv = 65; | |
| 81 | pub const SYS_writev = 66; | |
| 82 | pub const SYS_pread64 = 67; | |
| 83 | pub const SYS_pwrite64 = 68; | |
| 84 | pub const SYS_preadv = 69; | |
| 85 | pub const SYS_pwritev = 70; | |
| 86 | pub const SYS_sendfile = 71; | |
| 87 | pub const SYS_pselect6 = 72; | |
| 88 | pub const SYS_ppoll = 73; | |
| 89 | pub const SYS_signalfd4 = 74; | |
| 90 | pub const SYS_vmsplice = 75; | |
| 91 | pub const SYS_splice = 76; | |
| 92 | pub const SYS_tee = 77; | |
| 93 | pub const SYS_readlinkat = 78; | |
| 94 | pub const SYS_fstatat = 79; | |
| 95 | pub const SYS_fstat = 80; | |
| 96 | pub const SYS_sync = 81; | |
| 97 | pub const SYS_fsync = 82; | |
| 98 | pub const SYS_fdatasync = 83; | |
| 99 | pub const SYS_sync_file_range2 = 84; | |
| 100 | pub const SYS_sync_file_range = 84; | |
| 101 | pub const SYS_timerfd_create = 85; | |
| 102 | pub const SYS_timerfd_settime = 86; | |
| 103 | pub const SYS_timerfd_gettime = 87; | |
| 104 | pub const SYS_utimensat = 88; | |
| 105 | pub const SYS_acct = 89; | |
| 106 | pub const SYS_capget = 90; | |
| 107 | pub const SYS_capset = 91; | |
| 108 | pub const SYS_personality = 92; | |
| 109 | pub const SYS_exit = 93; | |
| 110 | pub const SYS_exit_group = 94; | |
| 111 | pub const SYS_waitid = 95; | |
| 112 | pub const SYS_set_tid_address = 96; | |
| 113 | pub const SYS_unshare = 97; | |
| 114 | pub const SYS_futex = 98; | |
| 115 | pub const SYS_set_robust_list = 99; | |
| 116 | pub const SYS_get_robust_list = 100; | |
| 117 | pub const SYS_nanosleep = 101; | |
| 118 | pub const SYS_getitimer = 102; | |
| 119 | pub const SYS_setitimer = 103; | |
| 120 | pub const SYS_kexec_load = 104; | |
| 121 | pub const SYS_init_module = 105; | |
| 122 | pub const SYS_delete_module = 106; | |
| 123 | pub const SYS_timer_create = 107; | |
| 124 | pub const SYS_timer_gettime = 108; | |
| 125 | pub const SYS_timer_getoverrun = 109; | |
| 126 | pub const SYS_timer_settime = 110; | |
| 127 | pub const SYS_timer_delete = 111; | |
| 128 | pub const SYS_clock_settime = 112; | |
| 129 | pub const SYS_clock_gettime = 113; | |
| 130 | pub const SYS_clock_getres = 114; | |
| 131 | pub const SYS_clock_nanosleep = 115; | |
| 132 | pub const SYS_syslog = 116; | |
| 133 | pub const SYS_ptrace = 117; | |
| 134 | pub const SYS_sched_setparam = 118; | |
| 135 | pub const SYS_sched_setscheduler = 119; | |
| 136 | pub const SYS_sched_getscheduler = 120; | |
| 137 | pub const SYS_sched_getparam = 121; | |
| 138 | pub const SYS_sched_setaffinity = 122; | |
| 139 | pub const SYS_sched_getaffinity = 123; | |
| 140 | pub const SYS_sched_yield = 124; | |
| 141 | pub const SYS_sched_get_priority_max = 125; | |
| 142 | pub const SYS_sched_get_priority_min = 126; | |
| 143 | pub const SYS_sched_rr_get_interval = 127; | |
| 144 | pub const SYS_restart_syscall = 128; | |
| 145 | pub const SYS_kill = 129; | |
| 146 | pub const SYS_tkill = 130; | |
| 147 | pub const SYS_tgkill = 131; | |
| 148 | pub const SYS_sigaltstack = 132; | |
| 149 | pub const SYS_rt_sigsuspend = 133; | |
| 150 | pub const SYS_rt_sigaction = 134; | |
| 151 | pub const SYS_rt_sigprocmask = 135; | |
| 152 | pub const SYS_rt_sigpending = 136; | |
| 153 | pub const SYS_rt_sigtimedwait = 137; | |
| 154 | pub const SYS_rt_sigqueueinfo = 138; | |
| 155 | pub const SYS_rt_sigreturn = 139; | |
| 156 | pub const SYS_setpriority = 140; | |
| 157 | pub const SYS_getpriority = 141; | |
| 158 | pub const SYS_reboot = 142; | |
| 159 | pub const SYS_setregid = 143; | |
| 160 | pub const SYS_setgid = 144; | |
| 161 | pub const SYS_setreuid = 145; | |
| 162 | pub const SYS_setuid = 146; | |
| 163 | pub const SYS_setresuid = 147; | |
| 164 | pub const SYS_getresuid = 148; | |
| 165 | pub const SYS_setresgid = 149; | |
| 166 | pub const SYS_getresgid = 150; | |
| 167 | pub const SYS_setfsuid = 151; | |
| 168 | pub const SYS_setfsgid = 152; | |
| 169 | pub const SYS_times = 153; | |
| 170 | pub const SYS_setpgid = 154; | |
| 171 | pub const SYS_getpgid = 155; | |
| 172 | pub const SYS_getsid = 156; | |
| 173 | pub const SYS_setsid = 157; | |
| 174 | pub const SYS_getgroups = 158; | |
| 175 | pub const SYS_setgroups = 159; | |
| 176 | pub const SYS_uname = 160; | |
| 177 | pub const SYS_sethostname = 161; | |
| 178 | pub const SYS_setdomainname = 162; | |
| 179 | pub const SYS_getrlimit = 163; | |
| 180 | pub const SYS_setrlimit = 164; | |
| 181 | pub const SYS_getrusage = 165; | |
| 182 | pub const SYS_umask = 166; | |
| 183 | pub const SYS_prctl = 167; | |
| 184 | pub const SYS_getcpu = 168; | |
| 185 | pub const SYS_gettimeofday = 169; | |
| 186 | pub const SYS_settimeofday = 170; | |
| 187 | pub const SYS_adjtimex = 171; | |
| 188 | pub const SYS_getpid = 172; | |
| 189 | pub const SYS_getppid = 173; | |
| 190 | pub const SYS_getuid = 174; | |
| 191 | pub const SYS_geteuid = 175; | |
| 192 | pub const SYS_getgid = 176; | |
| 193 | pub const SYS_getegid = 177; | |
| 194 | pub const SYS_gettid = 178; | |
| 195 | pub const SYS_sysinfo = 179; | |
| 196 | pub const SYS_mq_open = 180; | |
| 197 | pub const SYS_mq_unlink = 181; | |
| 198 | pub const SYS_mq_timedsend = 182; | |
| 199 | pub const SYS_mq_timedreceive = 183; | |
| 200 | pub const SYS_mq_notify = 184; | |
| 201 | pub const SYS_mq_getsetattr = 185; | |
| 202 | pub const SYS_msgget = 186; | |
| 203 | pub const SYS_msgctl = 187; | |
| 204 | pub const SYS_msgrcv = 188; | |
| 205 | pub const SYS_msgsnd = 189; | |
| 206 | pub const SYS_semget = 190; | |
| 207 | pub const SYS_semctl = 191; | |
| 208 | pub const SYS_semtimedop = 192; | |
| 209 | pub const SYS_semop = 193; | |
| 210 | pub const SYS_shmget = 194; | |
| 211 | pub const SYS_shmctl = 195; | |
| 212 | pub const SYS_shmat = 196; | |
| 213 | pub const SYS_shmdt = 197; | |
| 214 | pub const SYS_socket = 198; | |
| 215 | pub const SYS_socketpair = 199; | |
| 216 | pub const SYS_bind = 200; | |
| 217 | pub const SYS_listen = 201; | |
| 218 | pub const SYS_accept = 202; | |
| 219 | pub const SYS_connect = 203; | |
| 220 | pub const SYS_getsockname = 204; | |
| 221 | pub const SYS_getpeername = 205; | |
| 222 | pub const SYS_sendto = 206; | |
| 223 | pub const SYS_recvfrom = 207; | |
| 224 | pub const SYS_setsockopt = 208; | |
| 225 | pub const SYS_getsockopt = 209; | |
| 226 | pub const SYS_shutdown = 210; | |
| 227 | pub const SYS_sendmsg = 211; | |
| 228 | pub const SYS_recvmsg = 212; | |
| 229 | pub const SYS_readahead = 213; | |
| 230 | pub const SYS_brk = 214; | |
| 231 | pub const SYS_munmap = 215; | |
| 232 | pub const SYS_mremap = 216; | |
| 233 | pub const SYS_add_key = 217; | |
| 234 | pub const SYS_request_key = 218; | |
| 235 | pub const SYS_keyctl = 219; | |
| 236 | pub const SYS_clone = 220; | |
| 237 | pub const SYS_execve = 221; | |
| 238 | pub const SYS_mmap = 222; | |
| 239 | pub const SYS_fadvise64 = 223; | |
| 240 | pub const SYS_swapon = 224; | |
| 241 | pub const SYS_swapoff = 225; | |
| 242 | pub const SYS_mprotect = 226; | |
| 243 | pub const SYS_msync = 227; | |
| 244 | pub const SYS_mlock = 228; | |
| 245 | pub const SYS_munlock = 229; | |
| 246 | pub const SYS_mlockall = 230; | |
| 247 | pub const SYS_munlockall = 231; | |
| 248 | pub const SYS_mincore = 232; | |
| 249 | pub const SYS_madvise = 233; | |
| 250 | pub const SYS_remap_file_pages = 234; | |
| 251 | pub const SYS_mbind = 235; | |
| 252 | pub const SYS_get_mempolicy = 236; | |
| 253 | pub const SYS_set_mempolicy = 237; | |
| 254 | pub const SYS_migrate_pages = 238; | |
| 255 | pub const SYS_move_pages = 239; | |
| 256 | pub const SYS_rt_tgsigqueueinfo = 240; | |
| 257 | pub const SYS_perf_event_open = 241; | |
| 258 | pub const SYS_accept4 = 242; | |
| 259 | pub const SYS_recvmmsg = 243; | |
| 260 | pub const SYS_arch_specific_syscall = 244; | |
| 261 | pub const SYS_wait4 = 260; | |
| 262 | pub const SYS_prlimit64 = 261; | |
| 263 | pub const SYS_fanotify_init = 262; | |
| 264 | pub const SYS_fanotify_mark = 263; | |
| 265 | pub const SYS_clock_adjtime = 266; | |
| 266 | pub const SYS_syncfs = 267; | |
| 267 | pub const SYS_setns = 268; | |
| 268 | pub const SYS_sendmmsg = 269; | |
| 269 | pub const SYS_process_vm_readv = 270; | |
| 270 | pub const SYS_process_vm_writev = 271; | |
| 271 | pub const SYS_kcmp = 272; | |
| 272 | pub const SYS_finit_module = 273; | |
| 273 | pub const SYS_sched_setattr = 274; | |
| 274 | pub const SYS_sched_getattr = 275; | |
| 275 | pub const SYS_renameat2 = 276; | |
| 276 | pub const SYS_seccomp = 277; | |
| 277 | pub const SYS_getrandom = 278; | |
| 278 | pub const SYS_memfd_create = 279; | |
| 279 | pub const SYS_bpf = 280; | |
| 280 | pub const SYS_execveat = 281; | |
| 281 | pub const SYS_userfaultfd = 282; | |
| 282 | pub const SYS_membarrier = 283; | |
| 283 | pub const SYS_mlock2 = 284; | |
| 284 | pub const SYS_copy_file_range = 285; | |
| 285 | pub const SYS_preadv2 = 286; | |
| 286 | pub const SYS_pwritev2 = 287; | |
| 287 | pub const SYS_pkey_mprotect = 288; | |
| 288 | pub const SYS_pkey_alloc = 289; | |
| 289 | pub const SYS_pkey_free = 290; | |
| 290 | pub const SYS_statx = 291; | |
| 291 | pub const SYS_io_pgetevents = 292; | |
| 292 | pub const SYS_rseq = 293; | |
| 293 | pub const SYS_kexec_file_load = 294; | |
| 294 | pub const SYS_pidfd_send_signal = 424; | |
| 295 | pub const SYS_io_uring_setup = 425; | |
| 296 | pub const SYS_io_uring_enter = 426; | |
| 297 | pub const SYS_io_uring_register = 427; | |
| 298 | pub const SYS_open_tree = 428; | |
| 299 | pub const SYS_move_mount = 429; | |
| 300 | pub const SYS_fsopen = 430; | |
| 301 | pub const SYS_fsconfig = 431; | |
| 302 | pub const SYS_fsmount = 432; | |
| 303 | pub const SYS_fspick = 433; | |
| 304 | pub const SYS_pidfd_open = 434; | |
| 305 | pub const SYS_clone3 = 435; | |
| 309 | _, | |
| 310 | }; | |
| 306 | 311 | |
| 307 | 312 | pub const O_CREAT = 0o100; |
| 308 | 313 | pub const O_EXCL = 0o200; |
lib/std/os/bits/linux/errno-generic.zig+27| ... | ... | @@ -368,6 +368,33 @@ pub const ENOMEDIUM = 123; |
| 368 | 368 | /// Wrong medium type |
| 369 | 369 | pub const EMEDIUMTYPE = 124; |
| 370 | 370 | |
| 371 | /// Operation canceled | |
| 372 | pub const ECANCELED = 125; | |
| 373 | ||
| 374 | /// Required key not available | |
| 375 | pub const ENOKEY = 126; | |
| 376 | ||
| 377 | /// Key has expired | |
| 378 | pub const EKEYEXPIRED = 127; | |
| 379 | ||
| 380 | /// Key has been revoked | |
| 381 | pub const EKEYREVOKED = 128; | |
| 382 | ||
| 383 | /// Key was rejected by service | |
| 384 | pub const EKEYREJECTED = 129; | |
| 385 | ||
| 386 | // for robust mutexes | |
| 387 | /// Owner died | |
| 388 | pub const EOWNERDEAD = 130; | |
| 389 | /// State not recoverable | |
| 390 | pub const ENOTRECOVERABLE = 131; | |
| 391 | ||
| 392 | /// Operation not possible due to RF-kill | |
| 393 | pub const ERFKILL = 132; | |
| 394 | ||
| 395 | /// Memory page has hardware error | |
| 396 | pub const EHWPOISON = 133; | |
| 397 | ||
| 371 | 398 | // nameserver query return codes |
| 372 | 399 | |
| 373 | 400 | /// DNS server returned answer with no data |
lib/std/os/bits/linux/i386.zig+429-423| ... | ... | @@ -12,429 +12,435 @@ const pid_t = linux.pid_t; |
| 12 | 12 | const stack_t = linux.stack_t; |
| 13 | 13 | const sigset_t = linux.sigset_t; |
| 14 | 14 | |
| 15 | pub const SYS_restart_syscall = 0; | |
| 16 | pub const SYS_exit = 1; | |
| 17 | pub const SYS_fork = 2; | |
| 18 | pub const SYS_read = 3; | |
| 19 | pub const SYS_write = 4; | |
| 20 | pub const SYS_open = 5; | |
| 21 | pub const SYS_close = 6; | |
| 22 | pub const SYS_waitpid = 7; | |
| 23 | pub const SYS_creat = 8; | |
| 24 | pub const SYS_link = 9; | |
| 25 | pub const SYS_unlink = 10; | |
| 26 | pub const SYS_execve = 11; | |
| 27 | pub const SYS_chdir = 12; | |
| 28 | pub const SYS_time = 13; | |
| 29 | pub const SYS_mknod = 14; | |
| 30 | pub const SYS_chmod = 15; | |
| 31 | pub const SYS_lchown = 16; | |
| 32 | pub const SYS_break = 17; | |
| 33 | pub const SYS_oldstat = 18; | |
| 34 | pub const SYS_lseek = 19; | |
| 35 | pub const SYS_getpid = 20; | |
| 36 | pub const SYS_mount = 21; | |
| 37 | pub const SYS_umount = 22; | |
| 38 | pub const SYS_setuid = 23; | |
| 39 | pub const SYS_getuid = 24; | |
| 40 | pub const SYS_stime = 25; | |
| 41 | pub const SYS_ptrace = 26; | |
| 42 | pub const SYS_alarm = 27; | |
| 43 | pub const SYS_oldfstat = 28; | |
| 44 | pub const SYS_pause = 29; | |
| 45 | pub const SYS_utime = 30; | |
| 46 | pub const SYS_stty = 31; | |
| 47 | pub const SYS_gtty = 32; | |
| 48 | pub const SYS_access = 33; | |
| 49 | pub const SYS_nice = 34; | |
| 50 | pub const SYS_ftime = 35; | |
| 51 | pub const SYS_sync = 36; | |
| 52 | pub const SYS_kill = 37; | |
| 53 | pub const SYS_rename = 38; | |
| 54 | pub const SYS_mkdir = 39; | |
| 55 | pub const SYS_rmdir = 40; | |
| 56 | pub const SYS_dup = 41; | |
| 57 | pub const SYS_pipe = 42; | |
| 58 | pub const SYS_times = 43; | |
| 59 | pub const SYS_prof = 44; | |
| 60 | pub const SYS_brk = 45; | |
| 61 | pub const SYS_setgid = 46; | |
| 62 | pub const SYS_getgid = 47; | |
| 63 | pub const SYS_signal = 48; | |
| 64 | pub const SYS_geteuid = 49; | |
| 65 | pub const SYS_getegid = 50; | |
| 66 | pub const SYS_acct = 51; | |
| 67 | pub const SYS_umount2 = 52; | |
| 68 | pub const SYS_lock = 53; | |
| 69 | pub const SYS_ioctl = 54; | |
| 70 | pub const SYS_fcntl = 55; | |
| 71 | pub const SYS_mpx = 56; | |
| 72 | pub const SYS_setpgid = 57; | |
| 73 | pub const SYS_ulimit = 58; | |
| 74 | pub const SYS_oldolduname = 59; | |
| 75 | pub const SYS_umask = 60; | |
| 76 | pub const SYS_chroot = 61; | |
| 77 | pub const SYS_ustat = 62; | |
| 78 | pub const SYS_dup2 = 63; | |
| 79 | pub const SYS_getppid = 64; | |
| 80 | pub const SYS_getpgrp = 65; | |
| 81 | pub const SYS_setsid = 66; | |
| 82 | pub const SYS_sigaction = 67; | |
| 83 | pub const SYS_sgetmask = 68; | |
| 84 | pub const SYS_ssetmask = 69; | |
| 85 | pub const SYS_setreuid = 70; | |
| 86 | pub const SYS_setregid = 71; | |
| 87 | pub const SYS_sigsuspend = 72; | |
| 88 | pub const SYS_sigpending = 73; | |
| 89 | pub const SYS_sethostname = 74; | |
| 90 | pub const SYS_setrlimit = 75; | |
| 91 | pub const SYS_getrlimit = 76; | |
| 92 | pub const SYS_getrusage = 77; | |
| 93 | pub const SYS_gettimeofday = 78; | |
| 94 | pub const SYS_settimeofday = 79; | |
| 95 | pub const SYS_getgroups = 80; | |
| 96 | pub const SYS_setgroups = 81; | |
| 97 | pub const SYS_select = 82; | |
| 98 | pub const SYS_symlink = 83; | |
| 99 | pub const SYS_oldlstat = 84; | |
| 100 | pub const SYS_readlink = 85; | |
| 101 | pub const SYS_uselib = 86; | |
| 102 | pub const SYS_swapon = 87; | |
| 103 | pub const SYS_reboot = 88; | |
| 104 | pub const SYS_readdir = 89; | |
| 105 | pub const SYS_mmap = 90; | |
| 106 | pub const SYS_munmap = 91; | |
| 107 | pub const SYS_truncate = 92; | |
| 108 | pub const SYS_ftruncate = 93; | |
| 109 | pub const SYS_fchmod = 94; | |
| 110 | pub const SYS_fchown = 95; | |
| 111 | pub const SYS_getpriority = 96; | |
| 112 | pub const SYS_setpriority = 97; | |
| 113 | pub const SYS_profil = 98; | |
| 114 | pub const SYS_statfs = 99; | |
| 115 | pub const SYS_fstatfs = 100; | |
| 116 | pub const SYS_ioperm = 101; | |
| 117 | pub const SYS_socketcall = 102; | |
| 118 | pub const SYS_syslog = 103; | |
| 119 | pub const SYS_setitimer = 104; | |
| 120 | pub const SYS_getitimer = 105; | |
| 121 | pub const SYS_stat = 106; | |
| 122 | pub const SYS_lstat = 107; | |
| 123 | pub const SYS_fstat = 108; | |
| 124 | pub const SYS_olduname = 109; | |
| 125 | pub const SYS_iopl = 110; | |
| 126 | pub const SYS_vhangup = 111; | |
| 127 | pub const SYS_idle = 112; | |
| 128 | pub const SYS_vm86old = 113; | |
| 129 | pub const SYS_wait4 = 114; | |
| 130 | pub const SYS_swapoff = 115; | |
| 131 | pub const SYS_sysinfo = 116; | |
| 132 | pub const SYS_ipc = 117; | |
| 133 | pub const SYS_fsync = 118; | |
| 134 | pub const SYS_sigreturn = 119; | |
| 135 | pub const SYS_clone = 120; | |
| 136 | pub const SYS_setdomainname = 121; | |
| 137 | pub const SYS_uname = 122; | |
| 138 | pub const SYS_modify_ldt = 123; | |
| 139 | pub const SYS_adjtimex = 124; | |
| 140 | pub const SYS_mprotect = 125; | |
| 141 | pub const SYS_sigprocmask = 126; | |
| 142 | pub const SYS_create_module = 127; | |
| 143 | pub const SYS_init_module = 128; | |
| 144 | pub const SYS_delete_module = 129; | |
| 145 | pub const SYS_get_kernel_syms = 130; | |
| 146 | pub const SYS_quotactl = 131; | |
| 147 | pub const SYS_getpgid = 132; | |
| 148 | pub const SYS_fchdir = 133; | |
| 149 | pub const SYS_bdflush = 134; | |
| 150 | pub const SYS_sysfs = 135; | |
| 151 | pub const SYS_personality = 136; | |
| 152 | pub const SYS_afs_syscall = 137; | |
| 153 | pub const SYS_setfsuid = 138; | |
| 154 | pub const SYS_setfsgid = 139; | |
| 155 | pub const SYS__llseek = 140; | |
| 156 | pub const SYS_getdents = 141; | |
| 157 | pub const SYS__newselect = 142; | |
| 158 | pub const SYS_flock = 143; | |
| 159 | pub const SYS_msync = 144; | |
| 160 | pub const SYS_readv = 145; | |
| 161 | pub const SYS_writev = 146; | |
| 162 | pub const SYS_getsid = 147; | |
| 163 | pub const SYS_fdatasync = 148; | |
| 164 | pub const SYS__sysctl = 149; | |
| 165 | pub const SYS_mlock = 150; | |
| 166 | pub const SYS_munlock = 151; | |
| 167 | pub const SYS_mlockall = 152; | |
| 168 | pub const SYS_munlockall = 153; | |
| 169 | pub const SYS_sched_setparam = 154; | |
| 170 | pub const SYS_sched_getparam = 155; | |
| 171 | pub const SYS_sched_setscheduler = 156; | |
| 172 | pub const SYS_sched_getscheduler = 157; | |
| 173 | pub const SYS_sched_yield = 158; | |
| 174 | pub const SYS_sched_get_priority_max = 159; | |
| 175 | pub const SYS_sched_get_priority_min = 160; | |
| 176 | pub const SYS_sched_rr_get_interval = 161; | |
| 177 | pub const SYS_nanosleep = 162; | |
| 178 | pub const SYS_mremap = 163; | |
| 179 | pub const SYS_setresuid = 164; | |
| 180 | pub const SYS_getresuid = 165; | |
| 181 | pub const SYS_vm86 = 166; | |
| 182 | pub const SYS_query_module = 167; | |
| 183 | pub const SYS_poll = 168; | |
| 184 | pub const SYS_nfsservctl = 169; | |
| 185 | pub const SYS_setresgid = 170; | |
| 186 | pub const SYS_getresgid = 171; | |
| 187 | pub const SYS_prctl = 172; | |
| 188 | pub const SYS_rt_sigreturn = 173; | |
| 189 | pub const SYS_rt_sigaction = 174; | |
| 190 | pub const SYS_rt_sigprocmask = 175; | |
| 191 | pub const SYS_rt_sigpending = 176; | |
| 192 | pub const SYS_rt_sigtimedwait = 177; | |
| 193 | pub const SYS_rt_sigqueueinfo = 178; | |
| 194 | pub const SYS_rt_sigsuspend = 179; | |
| 195 | pub const SYS_pread64 = 180; | |
| 196 | pub const SYS_pwrite64 = 181; | |
| 197 | pub const SYS_chown = 182; | |
| 198 | pub const SYS_getcwd = 183; | |
| 199 | pub const SYS_capget = 184; | |
| 200 | pub const SYS_capset = 185; | |
| 201 | pub const SYS_sigaltstack = 186; | |
| 202 | pub const SYS_sendfile = 187; | |
| 203 | pub const SYS_getpmsg = 188; | |
| 204 | pub const SYS_putpmsg = 189; | |
| 205 | pub const SYS_vfork = 190; | |
| 206 | pub const SYS_ugetrlimit = 191; | |
| 207 | pub const SYS_mmap2 = 192; | |
| 208 | pub const SYS_truncate64 = 193; | |
| 209 | pub const SYS_ftruncate64 = 194; | |
| 210 | pub const SYS_stat64 = 195; | |
| 211 | pub const SYS_lstat64 = 196; | |
| 212 | pub const SYS_fstat64 = 197; | |
| 213 | pub const SYS_lchown32 = 198; | |
| 214 | pub const SYS_getuid32 = 199; | |
| 215 | pub const SYS_getgid32 = 200; | |
| 216 | pub const SYS_geteuid32 = 201; | |
| 217 | pub const SYS_getegid32 = 202; | |
| 218 | pub const SYS_setreuid32 = 203; | |
| 219 | pub const SYS_setregid32 = 204; | |
| 220 | pub const SYS_getgroups32 = 205; | |
| 221 | pub const SYS_setgroups32 = 206; | |
| 222 | pub const SYS_fchown32 = 207; | |
| 223 | pub const SYS_setresuid32 = 208; | |
| 224 | pub const SYS_getresuid32 = 209; | |
| 225 | pub const SYS_setresgid32 = 210; | |
| 226 | pub const SYS_getresgid32 = 211; | |
| 227 | pub const SYS_chown32 = 212; | |
| 228 | pub const SYS_setuid32 = 213; | |
| 229 | pub const SYS_setgid32 = 214; | |
| 230 | pub const SYS_setfsuid32 = 215; | |
| 231 | pub const SYS_setfsgid32 = 216; | |
| 232 | pub const SYS_pivot_root = 217; | |
| 233 | pub const SYS_mincore = 218; | |
| 234 | pub const SYS_madvise = 219; | |
| 235 | pub const SYS_getdents64 = 220; | |
| 236 | pub const SYS_fcntl64 = 221; | |
| 237 | pub const SYS_gettid = 224; | |
| 238 | pub const SYS_readahead = 225; | |
| 239 | pub const SYS_setxattr = 226; | |
| 240 | pub const SYS_lsetxattr = 227; | |
| 241 | pub const SYS_fsetxattr = 228; | |
| 242 | pub const SYS_getxattr = 229; | |
| 243 | pub const SYS_lgetxattr = 230; | |
| 244 | pub const SYS_fgetxattr = 231; | |
| 245 | pub const SYS_listxattr = 232; | |
| 246 | pub const SYS_llistxattr = 233; | |
| 247 | pub const SYS_flistxattr = 234; | |
| 248 | pub const SYS_removexattr = 235; | |
| 249 | pub const SYS_lremovexattr = 236; | |
| 250 | pub const SYS_fremovexattr = 237; | |
| 251 | pub const SYS_tkill = 238; | |
| 252 | pub const SYS_sendfile64 = 239; | |
| 253 | pub const SYS_futex = 240; | |
| 254 | pub const SYS_sched_setaffinity = 241; | |
| 255 | pub const SYS_sched_getaffinity = 242; | |
| 256 | pub const SYS_set_thread_area = 243; | |
| 257 | pub const SYS_get_thread_area = 244; | |
| 258 | pub const SYS_io_setup = 245; | |
| 259 | pub const SYS_io_destroy = 246; | |
| 260 | pub const SYS_io_getevents = 247; | |
| 261 | pub const SYS_io_submit = 248; | |
| 262 | pub const SYS_io_cancel = 249; | |
| 263 | pub const SYS_fadvise64 = 250; | |
| 264 | pub const SYS_exit_group = 252; | |
| 265 | pub const SYS_lookup_dcookie = 253; | |
| 266 | pub const SYS_epoll_create = 254; | |
| 267 | pub const SYS_epoll_ctl = 255; | |
| 268 | pub const SYS_epoll_wait = 256; | |
| 269 | pub const SYS_remap_file_pages = 257; | |
| 270 | pub const SYS_set_tid_address = 258; | |
| 271 | pub const SYS_timer_create = 259; | |
| 272 | pub const SYS_timer_settime = SYS_timer_create + 1; | |
| 273 | pub const SYS_timer_gettime = SYS_timer_create + 2; | |
| 274 | pub const SYS_timer_getoverrun = SYS_timer_create + 3; | |
| 275 | pub const SYS_timer_delete = SYS_timer_create + 4; | |
| 276 | pub const SYS_clock_settime = SYS_timer_create + 5; | |
| 277 | pub const SYS_clock_gettime = SYS_timer_create + 6; | |
| 278 | pub const SYS_clock_getres = SYS_timer_create + 7; | |
| 279 | pub const SYS_clock_nanosleep = SYS_timer_create + 8; | |
| 280 | pub const SYS_statfs64 = 268; | |
| 281 | pub const SYS_fstatfs64 = 269; | |
| 282 | pub const SYS_tgkill = 270; | |
| 283 | pub const SYS_utimes = 271; | |
| 284 | pub const SYS_fadvise64_64 = 272; | |
| 285 | pub const SYS_vserver = 273; | |
| 286 | pub const SYS_mbind = 274; | |
| 287 | pub const SYS_get_mempolicy = 275; | |
| 288 | pub const SYS_set_mempolicy = 276; | |
| 289 | pub const SYS_mq_open = 277; | |
| 290 | pub const SYS_mq_unlink = SYS_mq_open + 1; | |
| 291 | pub const SYS_mq_timedsend = SYS_mq_open + 2; | |
| 292 | pub const SYS_mq_timedreceive = SYS_mq_open + 3; | |
| 293 | pub const SYS_mq_notify = SYS_mq_open + 4; | |
| 294 | pub const SYS_mq_getsetattr = SYS_mq_open + 5; | |
| 295 | pub const SYS_kexec_load = 283; | |
| 296 | pub const SYS_waitid = 284; | |
| 297 | pub const SYS_add_key = 286; | |
| 298 | pub const SYS_request_key = 287; | |
| 299 | pub const SYS_keyctl = 288; | |
| 300 | pub const SYS_ioprio_set = 289; | |
| 301 | pub const SYS_ioprio_get = 290; | |
| 302 | pub const SYS_inotify_init = 291; | |
| 303 | pub const SYS_inotify_add_watch = 292; | |
| 304 | pub const SYS_inotify_rm_watch = 293; | |
| 305 | pub const SYS_migrate_pages = 294; | |
| 306 | pub const SYS_openat = 295; | |
| 307 | pub const SYS_mkdirat = 296; | |
| 308 | pub const SYS_mknodat = 297; | |
| 309 | pub const SYS_fchownat = 298; | |
| 310 | pub const SYS_futimesat = 299; | |
| 311 | pub const SYS_fstatat64 = 300; | |
| 312 | pub const SYS_unlinkat = 301; | |
| 313 | pub const SYS_renameat = 302; | |
| 314 | pub const SYS_linkat = 303; | |
| 315 | pub const SYS_symlinkat = 304; | |
| 316 | pub const SYS_readlinkat = 305; | |
| 317 | pub const SYS_fchmodat = 306; | |
| 318 | pub const SYS_faccessat = 307; | |
| 319 | pub const SYS_pselect6 = 308; | |
| 320 | pub const SYS_ppoll = 309; | |
| 321 | pub const SYS_unshare = 310; | |
| 322 | pub const SYS_set_robust_list = 311; | |
| 323 | pub const SYS_get_robust_list = 312; | |
| 324 | pub const SYS_splice = 313; | |
| 325 | pub const SYS_sync_file_range = 314; | |
| 326 | pub const SYS_tee = 315; | |
| 327 | pub const SYS_vmsplice = 316; | |
| 328 | pub const SYS_move_pages = 317; | |
| 329 | pub const SYS_getcpu = 318; | |
| 330 | pub const SYS_epoll_pwait = 319; | |
| 331 | pub const SYS_utimensat = 320; | |
| 332 | pub const SYS_signalfd = 321; | |
| 333 | pub const SYS_timerfd_create = 322; | |
| 334 | pub const SYS_eventfd = 323; | |
| 335 | pub const SYS_fallocate = 324; | |
| 336 | pub const SYS_timerfd_settime = 325; | |
| 337 | pub const SYS_timerfd_gettime = 326; | |
| 338 | pub const SYS_signalfd4 = 327; | |
| 339 | pub const SYS_eventfd2 = 328; | |
| 340 | pub const SYS_epoll_create1 = 329; | |
| 341 | pub const SYS_dup3 = 330; | |
| 342 | pub const SYS_pipe2 = 331; | |
| 343 | pub const SYS_inotify_init1 = 332; | |
| 344 | pub const SYS_preadv = 333; | |
| 345 | pub const SYS_pwritev = 334; | |
| 346 | pub const SYS_rt_tgsigqueueinfo = 335; | |
| 347 | pub const SYS_perf_event_open = 336; | |
| 348 | pub const SYS_recvmmsg = 337; | |
| 349 | pub const SYS_fanotify_init = 338; | |
| 350 | pub const SYS_fanotify_mark = 339; | |
| 351 | pub const SYS_prlimit64 = 340; | |
| 352 | pub const SYS_name_to_handle_at = 341; | |
| 353 | pub const SYS_open_by_handle_at = 342; | |
| 354 | pub const SYS_clock_adjtime = 343; | |
| 355 | pub const SYS_syncfs = 344; | |
| 356 | pub const SYS_sendmmsg = 345; | |
| 357 | pub const SYS_setns = 346; | |
| 358 | pub const SYS_process_vm_readv = 347; | |
| 359 | pub const SYS_process_vm_writev = 348; | |
| 360 | pub const SYS_kcmp = 349; | |
| 361 | pub const SYS_finit_module = 350; | |
| 362 | pub const SYS_sched_setattr = 351; | |
| 363 | pub const SYS_sched_getattr = 352; | |
| 364 | pub const SYS_renameat2 = 353; | |
| 365 | pub const SYS_seccomp = 354; | |
| 366 | pub const SYS_getrandom = 355; | |
| 367 | pub const SYS_memfd_create = 356; | |
| 368 | pub const SYS_bpf = 357; | |
| 369 | pub const SYS_execveat = 358; | |
| 370 | pub const SYS_socket = 359; | |
| 371 | pub const SYS_socketpair = 360; | |
| 372 | pub const SYS_bind = 361; | |
| 373 | pub const SYS_connect = 362; | |
| 374 | pub const SYS_listen = 363; | |
| 375 | pub const SYS_accept4 = 364; | |
| 376 | pub const SYS_getsockopt = 365; | |
| 377 | pub const SYS_setsockopt = 366; | |
| 378 | pub const SYS_getsockname = 367; | |
| 379 | pub const SYS_getpeername = 368; | |
| 380 | pub const SYS_sendto = 369; | |
| 381 | pub const SYS_sendmsg = 370; | |
| 382 | pub const SYS_recvfrom = 371; | |
| 383 | pub const SYS_recvmsg = 372; | |
| 384 | pub const SYS_shutdown = 373; | |
| 385 | pub const SYS_userfaultfd = 374; | |
| 386 | pub const SYS_membarrier = 375; | |
| 387 | pub const SYS_mlock2 = 376; | |
| 388 | pub const SYS_copy_file_range = 377; | |
| 389 | pub const SYS_preadv2 = 378; | |
| 390 | pub const SYS_pwritev2 = 379; | |
| 391 | pub const SYS_pkey_mprotect = 380; | |
| 392 | pub const SYS_pkey_alloc = 381; | |
| 393 | pub const SYS_pkey_free = 382; | |
| 394 | pub const SYS_statx = 383; | |
| 395 | pub const SYS_arch_prctl = 384; | |
| 396 | pub const SYS_io_pgetevents = 385; | |
| 397 | pub const SYS_rseq = 386; | |
| 398 | pub const SYS_semget = 393; | |
| 399 | pub const SYS_semctl = 394; | |
| 400 | pub const SYS_shmget = 395; | |
| 401 | pub const SYS_shmctl = 396; | |
| 402 | pub const SYS_shmat = 397; | |
| 403 | pub const SYS_shmdt = 398; | |
| 404 | pub const SYS_msgget = 399; | |
| 405 | pub const SYS_msgsnd = 400; | |
| 406 | pub const SYS_msgrcv = 401; | |
| 407 | pub const SYS_msgctl = 402; | |
| 408 | pub const SYS_clock_gettime64 = 403; | |
| 409 | pub const SYS_clock_settime64 = 404; | |
| 410 | pub const SYS_clock_adjtime64 = 405; | |
| 411 | pub const SYS_clock_getres_time64 = 406; | |
| 412 | pub const SYS_clock_nanosleep_time64 = 407; | |
| 413 | pub const SYS_timer_gettime64 = 408; | |
| 414 | pub const SYS_timer_settime64 = 409; | |
| 415 | pub const SYS_timerfd_gettime64 = 410; | |
| 416 | pub const SYS_timerfd_settime64 = 411; | |
| 417 | pub const SYS_utimensat_time64 = 412; | |
| 418 | pub const SYS_pselect6_time64 = 413; | |
| 419 | pub const SYS_ppoll_time64 = 414; | |
| 420 | pub const SYS_io_pgetevents_time64 = 416; | |
| 421 | pub const SYS_recvmmsg_time64 = 417; | |
| 422 | pub const SYS_mq_timedsend_time64 = 418; | |
| 423 | pub const SYS_mq_timedreceive_time64 = 419; | |
| 424 | pub const SYS_semtimedop_time64 = 420; | |
| 425 | pub const SYS_rt_sigtimedwait_time64 = 421; | |
| 426 | pub const SYS_futex_time64 = 422; | |
| 427 | pub const SYS_sched_rr_get_interval_time64 = 423; | |
| 428 | pub const SYS_pidfd_send_signal = 424; | |
| 429 | pub const SYS_io_uring_setup = 425; | |
| 430 | pub const SYS_io_uring_enter = 426; | |
| 431 | pub const SYS_io_uring_register = 427; | |
| 432 | pub const SYS_open_tree = 428; | |
| 433 | pub const SYS_move_mount = 429; | |
| 434 | pub const SYS_fsopen = 430; | |
| 435 | pub const SYS_fsconfig = 431; | |
| 436 | pub const SYS_fsmount = 432; | |
| 437 | pub const SYS_fspick = 433; | |
| 15 | pub const SYS = extern enum(usize) { | |
| 16 | restart_syscall = 0, | |
| 17 | exit = 1, | |
| 18 | fork = 2, | |
| 19 | read = 3, | |
| 20 | write = 4, | |
| 21 | open = 5, | |
| 22 | close = 6, | |
| 23 | waitpid = 7, | |
| 24 | creat = 8, | |
| 25 | link = 9, | |
| 26 | unlink = 10, | |
| 27 | execve = 11, | |
| 28 | chdir = 12, | |
| 29 | time = 13, | |
| 30 | mknod = 14, | |
| 31 | chmod = 15, | |
| 32 | lchown = 16, | |
| 33 | @"break" = 17, | |
| 34 | oldstat = 18, | |
| 35 | lseek = 19, | |
| 36 | getpid = 20, | |
| 37 | mount = 21, | |
| 38 | umount = 22, | |
| 39 | setuid = 23, | |
| 40 | getuid = 24, | |
| 41 | stime = 25, | |
| 42 | ptrace = 26, | |
| 43 | alarm = 27, | |
| 44 | oldfstat = 28, | |
| 45 | pause = 29, | |
| 46 | utime = 30, | |
| 47 | stty = 31, | |
| 48 | gtty = 32, | |
| 49 | access = 33, | |
| 50 | nice = 34, | |
| 51 | ftime = 35, | |
| 52 | sync = 36, | |
| 53 | kill = 37, | |
| 54 | rename = 38, | |
| 55 | mkdir = 39, | |
| 56 | rmdir = 40, | |
| 57 | dup = 41, | |
| 58 | pipe = 42, | |
| 59 | times = 43, | |
| 60 | prof = 44, | |
| 61 | brk = 45, | |
| 62 | setgid = 46, | |
| 63 | getgid = 47, | |
| 64 | signal = 48, | |
| 65 | geteuid = 49, | |
| 66 | getegid = 50, | |
| 67 | acct = 51, | |
| 68 | umount2 = 52, | |
| 69 | lock = 53, | |
| 70 | ioctl = 54, | |
| 71 | fcntl = 55, | |
| 72 | mpx = 56, | |
| 73 | setpgid = 57, | |
| 74 | ulimit = 58, | |
| 75 | oldolduname = 59, | |
| 76 | umask = 60, | |
| 77 | chroot = 61, | |
| 78 | ustat = 62, | |
| 79 | dup2 = 63, | |
| 80 | getppid = 64, | |
| 81 | getpgrp = 65, | |
| 82 | setsid = 66, | |
| 83 | sigaction = 67, | |
| 84 | sgetmask = 68, | |
| 85 | ssetmask = 69, | |
| 86 | setreuid = 70, | |
| 87 | setregid = 71, | |
| 88 | sigsuspend = 72, | |
| 89 | sigpending = 73, | |
| 90 | sethostname = 74, | |
| 91 | setrlimit = 75, | |
| 92 | getrlimit = 76, | |
| 93 | getrusage = 77, | |
| 94 | gettimeofday = 78, | |
| 95 | settimeofday = 79, | |
| 96 | getgroups = 80, | |
| 97 | setgroups = 81, | |
| 98 | select = 82, | |
| 99 | symlink = 83, | |
| 100 | oldlstat = 84, | |
| 101 | readlink = 85, | |
| 102 | uselib = 86, | |
| 103 | swapon = 87, | |
| 104 | reboot = 88, | |
| 105 | readdir = 89, | |
| 106 | mmap = 90, | |
| 107 | munmap = 91, | |
| 108 | truncate = 92, | |
| 109 | ftruncate = 93, | |
| 110 | fchmod = 94, | |
| 111 | fchown = 95, | |
| 112 | getpriority = 96, | |
| 113 | setpriority = 97, | |
| 114 | profil = 98, | |
| 115 | statfs = 99, | |
| 116 | fstatfs = 100, | |
| 117 | ioperm = 101, | |
| 118 | socketcall = 102, | |
| 119 | syslog = 103, | |
| 120 | setitimer = 104, | |
| 121 | getitimer = 105, | |
| 122 | stat = 106, | |
| 123 | lstat = 107, | |
| 124 | fstat = 108, | |
| 125 | olduname = 109, | |
| 126 | iopl = 110, | |
| 127 | vhangup = 111, | |
| 128 | idle = 112, | |
| 129 | vm86old = 113, | |
| 130 | wait4 = 114, | |
| 131 | swapoff = 115, | |
| 132 | sysinfo = 116, | |
| 133 | ipc = 117, | |
| 134 | fsync = 118, | |
| 135 | sigreturn = 119, | |
| 136 | clone = 120, | |
| 137 | setdomainname = 121, | |
| 138 | uname = 122, | |
| 139 | modify_ldt = 123, | |
| 140 | adjtimex = 124, | |
| 141 | mprotect = 125, | |
| 142 | sigprocmask = 126, | |
| 143 | create_module = 127, | |
| 144 | init_module = 128, | |
| 145 | delete_module = 129, | |
| 146 | get_kernel_syms = 130, | |
| 147 | quotactl = 131, | |
| 148 | getpgid = 132, | |
| 149 | fchdir = 133, | |
| 150 | bdflush = 134, | |
| 151 | sysfs = 135, | |
| 152 | personality = 136, | |
| 153 | afs_syscall = 137, | |
| 154 | setfsuid = 138, | |
| 155 | setfsgid = 139, | |
| 156 | _llseek = 140, | |
| 157 | getdents = 141, | |
| 158 | _newselect = 142, | |
| 159 | flock = 143, | |
| 160 | msync = 144, | |
| 161 | readv = 145, | |
| 162 | writev = 146, | |
| 163 | getsid = 147, | |
| 164 | fdatasync = 148, | |
| 165 | _sysctl = 149, | |
| 166 | mlock = 150, | |
| 167 | munlock = 151, | |
| 168 | mlockall = 152, | |
| 169 | munlockall = 153, | |
| 170 | sched_setparam = 154, | |
| 171 | sched_getparam = 155, | |
| 172 | sched_setscheduler = 156, | |
| 173 | sched_getscheduler = 157, | |
| 174 | sched_yield = 158, | |
| 175 | sched_get_priority_max = 159, | |
| 176 | sched_get_priority_min = 160, | |
| 177 | sched_rr_get_interval = 161, | |
| 178 | nanosleep = 162, | |
| 179 | mremap = 163, | |
| 180 | setresuid = 164, | |
| 181 | getresuid = 165, | |
| 182 | vm86 = 166, | |
| 183 | query_module = 167, | |
| 184 | poll = 168, | |
| 185 | nfsservctl = 169, | |
| 186 | setresgid = 170, | |
| 187 | getresgid = 171, | |
| 188 | prctl = 172, | |
| 189 | rt_sigreturn = 173, | |
| 190 | rt_sigaction = 174, | |
| 191 | rt_sigprocmask = 175, | |
| 192 | rt_sigpending = 176, | |
| 193 | rt_sigtimedwait = 177, | |
| 194 | rt_sigqueueinfo = 178, | |
| 195 | rt_sigsuspend = 179, | |
| 196 | pread64 = 180, | |
| 197 | pwrite64 = 181, | |
| 198 | chown = 182, | |
| 199 | getcwd = 183, | |
| 200 | capget = 184, | |
| 201 | capset = 185, | |
| 202 | sigaltstack = 186, | |
| 203 | sendfile = 187, | |
| 204 | getpmsg = 188, | |
| 205 | putpmsg = 189, | |
| 206 | vfork = 190, | |
| 207 | ugetrlimit = 191, | |
| 208 | mmap2 = 192, | |
| 209 | truncate64 = 193, | |
| 210 | ftruncate64 = 194, | |
| 211 | stat64 = 195, | |
| 212 | lstat64 = 196, | |
| 213 | fstat64 = 197, | |
| 214 | lchown32 = 198, | |
| 215 | getuid32 = 199, | |
| 216 | getgid32 = 200, | |
| 217 | geteuid32 = 201, | |
| 218 | getegid32 = 202, | |
| 219 | setreuid32 = 203, | |
| 220 | setregid32 = 204, | |
| 221 | getgroups32 = 205, | |
| 222 | setgroups32 = 206, | |
| 223 | fchown32 = 207, | |
| 224 | setresuid32 = 208, | |
| 225 | getresuid32 = 209, | |
| 226 | setresgid32 = 210, | |
| 227 | getresgid32 = 211, | |
| 228 | chown32 = 212, | |
| 229 | setuid32 = 213, | |
| 230 | setgid32 = 214, | |
| 231 | setfsuid32 = 215, | |
| 232 | setfsgid32 = 216, | |
| 233 | pivot_root = 217, | |
| 234 | mincore = 218, | |
| 235 | madvise = 219, | |
| 236 | getdents64 = 220, | |
| 237 | fcntl64 = 221, | |
| 238 | gettid = 224, | |
| 239 | readahead = 225, | |
| 240 | setxattr = 226, | |
| 241 | lsetxattr = 227, | |
| 242 | fsetxattr = 228, | |
| 243 | getxattr = 229, | |
| 244 | lgetxattr = 230, | |
| 245 | fgetxattr = 231, | |
| 246 | listxattr = 232, | |
| 247 | llistxattr = 233, | |
| 248 | flistxattr = 234, | |
| 249 | removexattr = 235, | |
| 250 | lremovexattr = 236, | |
| 251 | fremovexattr = 237, | |
| 252 | tkill = 238, | |
| 253 | sendfile64 = 239, | |
| 254 | futex = 240, | |
| 255 | sched_setaffinity = 241, | |
| 256 | sched_getaffinity = 242, | |
| 257 | set_thread_area = 243, | |
| 258 | get_thread_area = 244, | |
| 259 | io_setup = 245, | |
| 260 | io_destroy = 246, | |
| 261 | io_getevents = 247, | |
| 262 | io_submit = 248, | |
| 263 | io_cancel = 249, | |
| 264 | fadvise64 = 250, | |
| 265 | exit_group = 252, | |
| 266 | lookup_dcookie = 253, | |
| 267 | epoll_create = 254, | |
| 268 | epoll_ctl = 255, | |
| 269 | epoll_wait = 256, | |
| 270 | remap_file_pages = 257, | |
| 271 | set_tid_address = 258, | |
| 272 | timer_create = 259, | |
| 273 | timer_settime, // SYS_timer_create + 1 | |
| 274 | timer_gettime, // SYS_timer_create + 2 | |
| 275 | timer_getoverrun, // SYS_timer_create + 3 | |
| 276 | timer_delete, // SYS_timer_create + 4 | |
| 277 | clock_settime, // SYS_timer_create + 5 | |
| 278 | clock_gettime, // SYS_timer_create + 6 | |
| 279 | clock_getres, // SYS_timer_create + 7 | |
| 280 | clock_nanosleep, // SYS_timer_create + 8 | |
| 281 | statfs64 = 268, | |
| 282 | fstatfs64 = 269, | |
| 283 | tgkill = 270, | |
| 284 | utimes = 271, | |
| 285 | fadvise64_64 = 272, | |
| 286 | vserver = 273, | |
| 287 | mbind = 274, | |
| 288 | get_mempolicy = 275, | |
| 289 | set_mempolicy = 276, | |
| 290 | mq_open = 277, | |
| 291 | mq_unlink, // SYS_mq_open + 1 | |
| 292 | mq_timedsend, // SYS_mq_open + 2 | |
| 293 | mq_timedreceive, // SYS_mq_open + 3 | |
| 294 | mq_notify, // SYS_mq_open + 4 | |
| 295 | mq_getsetattr, // SYS_mq_open + 5 | |
| 296 | kexec_load = 283, | |
| 297 | waitid = 284, | |
| 298 | add_key = 286, | |
| 299 | request_key = 287, | |
| 300 | keyctl = 288, | |
| 301 | ioprio_set = 289, | |
| 302 | ioprio_get = 290, | |
| 303 | inotify_init = 291, | |
| 304 | inotify_add_watch = 292, | |
| 305 | inotify_rm_watch = 293, | |
| 306 | migrate_pages = 294, | |
| 307 | openat = 295, | |
| 308 | mkdirat = 296, | |
| 309 | mknodat = 297, | |
| 310 | fchownat = 298, | |
| 311 | futimesat = 299, | |
| 312 | fstatat64 = 300, | |
| 313 | unlinkat = 301, | |
| 314 | renameat = 302, | |
| 315 | linkat = 303, | |
| 316 | symlinkat = 304, | |
| 317 | readlinkat = 305, | |
| 318 | fchmodat = 306, | |
| 319 | faccessat = 307, | |
| 320 | pselect6 = 308, | |
| 321 | ppoll = 309, | |
| 322 | unshare = 310, | |
| 323 | set_robust_list = 311, | |
| 324 | get_robust_list = 312, | |
| 325 | splice = 313, | |
| 326 | sync_file_range = 314, | |
| 327 | tee = 315, | |
| 328 | vmsplice = 316, | |
| 329 | move_pages = 317, | |
| 330 | getcpu = 318, | |
| 331 | epoll_pwait = 319, | |
| 332 | utimensat = 320, | |
| 333 | signalfd = 321, | |
| 334 | timerfd_create = 322, | |
| 335 | eventfd = 323, | |
| 336 | fallocate = 324, | |
| 337 | timerfd_settime = 325, | |
| 338 | timerfd_gettime = 326, | |
| 339 | signalfd4 = 327, | |
| 340 | eventfd2 = 328, | |
| 341 | epoll_create1 = 329, | |
| 342 | dup3 = 330, | |
| 343 | pipe2 = 331, | |
| 344 | inotify_init1 = 332, | |
| 345 | preadv = 333, | |
| 346 | pwritev = 334, | |
| 347 | rt_tgsigqueueinfo = 335, | |
| 348 | perf_event_open = 336, | |
| 349 | recvmmsg = 337, | |
| 350 | fanotify_init = 338, | |
| 351 | fanotify_mark = 339, | |
| 352 | prlimit64 = 340, | |
| 353 | name_to_handle_at = 341, | |
| 354 | open_by_handle_at = 342, | |
| 355 | clock_adjtime = 343, | |
| 356 | syncfs = 344, | |
| 357 | sendmmsg = 345, | |
| 358 | setns = 346, | |
| 359 | process_vm_readv = 347, | |
| 360 | process_vm_writev = 348, | |
| 361 | kcmp = 349, | |
| 362 | finit_module = 350, | |
| 363 | sched_setattr = 351, | |
| 364 | sched_getattr = 352, | |
| 365 | renameat2 = 353, | |
| 366 | seccomp = 354, | |
| 367 | getrandom = 355, | |
| 368 | memfd_create = 356, | |
| 369 | bpf = 357, | |
| 370 | execveat = 358, | |
| 371 | socket = 359, | |
| 372 | socketpair = 360, | |
| 373 | bind = 361, | |
| 374 | connect = 362, | |
| 375 | listen = 363, | |
| 376 | accept4 = 364, | |
| 377 | getsockopt = 365, | |
| 378 | setsockopt = 366, | |
| 379 | getsockname = 367, | |
| 380 | getpeername = 368, | |
| 381 | sendto = 369, | |
| 382 | sendmsg = 370, | |
| 383 | recvfrom = 371, | |
| 384 | recvmsg = 372, | |
| 385 | shutdown = 373, | |
| 386 | userfaultfd = 374, | |
| 387 | membarrier = 375, | |
| 388 | mlock2 = 376, | |
| 389 | copy_file_range = 377, | |
| 390 | preadv2 = 378, | |
| 391 | pwritev2 = 379, | |
| 392 | pkey_mprotect = 380, | |
| 393 | pkey_alloc = 381, | |
| 394 | pkey_free = 382, | |
| 395 | statx = 383, | |
| 396 | arch_prctl = 384, | |
| 397 | io_pgetevents = 385, | |
| 398 | rseq = 386, | |
| 399 | semget = 393, | |
| 400 | semctl = 394, | |
| 401 | shmget = 395, | |
| 402 | shmctl = 396, | |
| 403 | shmat = 397, | |
| 404 | shmdt = 398, | |
| 405 | msgget = 399, | |
| 406 | msgsnd = 400, | |
| 407 | msgrcv = 401, | |
| 408 | msgctl = 402, | |
| 409 | clock_gettime64 = 403, | |
| 410 | clock_settime64 = 404, | |
| 411 | clock_adjtime64 = 405, | |
| 412 | clock_getres_time64 = 406, | |
| 413 | clock_nanosleep_time64 = 407, | |
| 414 | timer_gettime64 = 408, | |
| 415 | timer_settime64 = 409, | |
| 416 | timerfd_gettime64 = 410, | |
| 417 | timerfd_settime64 = 411, | |
| 418 | utimensat_time64 = 412, | |
| 419 | pselect6_time64 = 413, | |
| 420 | ppoll_time64 = 414, | |
| 421 | io_pgetevents_time64 = 416, | |
| 422 | recvmmsg_time64 = 417, | |
| 423 | mq_timedsend_time64 = 418, | |
| 424 | mq_timedreceive_time64 = 419, | |
| 425 | semtimedop_time64 = 420, | |
| 426 | rt_sigtimedwait_time64 = 421, | |
| 427 | futex_time64 = 422, | |
| 428 | sched_rr_get_interval_time64 = 423, | |
| 429 | pidfd_send_signal = 424, | |
| 430 | io_uring_setup = 425, | |
| 431 | io_uring_enter = 426, | |
| 432 | io_uring_register = 427, | |
| 433 | open_tree = 428, | |
| 434 | move_mount = 429, | |
| 435 | fsopen = 430, | |
| 436 | fsconfig = 431, | |
| 437 | fsmount = 432, | |
| 438 | fspick = 433, | |
| 439 | openat2 = 437, | |
| 440 | pidfd_getfd = 438, | |
| 441 | ||
| 442 | _, | |
| 443 | }; | |
| 438 | 444 | |
| 439 | 445 | pub const O_CREAT = 0o100; |
| 440 | 446 | pub const O_EXCL = 0o200; |
lib/std/os/bits/linux/mipsel.zig+376-369| ... | ... | @@ -7,375 +7,382 @@ const uid_t = linux.uid_t; |
| 7 | 7 | const gid_t = linux.gid_t; |
| 8 | 8 | const pid_t = linux.pid_t; |
| 9 | 9 | |
| 10 | pub const SYS_Linux = 4000; | |
| 11 | pub const SYS_syscall = (SYS_Linux + 0); | |
| 12 | pub const SYS_exit = (SYS_Linux + 1); | |
| 13 | pub const SYS_fork = (SYS_Linux + 2); | |
| 14 | pub const SYS_read = (SYS_Linux + 3); | |
| 15 | pub const SYS_write = (SYS_Linux + 4); | |
| 16 | pub const SYS_open = (SYS_Linux + 5); | |
| 17 | pub const SYS_close = (SYS_Linux + 6); | |
| 18 | pub const SYS_waitpid = (SYS_Linux + 7); | |
| 19 | pub const SYS_creat = (SYS_Linux + 8); | |
| 20 | pub const SYS_link = (SYS_Linux + 9); | |
| 21 | pub const SYS_unlink = (SYS_Linux + 10); | |
| 22 | pub const SYS_execve = (SYS_Linux + 11); | |
| 23 | pub const SYS_chdir = (SYS_Linux + 12); | |
| 24 | pub const SYS_time = (SYS_Linux + 13); | |
| 25 | pub const SYS_mknod = (SYS_Linux + 14); | |
| 26 | pub const SYS_chmod = (SYS_Linux + 15); | |
| 27 | pub const SYS_lchown = (SYS_Linux + 16); | |
| 28 | pub const SYS_break = (SYS_Linux + 17); | |
| 29 | pub const SYS_unused18 = (SYS_Linux + 18); | |
| 30 | pub const SYS_lseek = (SYS_Linux + 19); | |
| 31 | pub const SYS_getpid = (SYS_Linux + 20); | |
| 32 | pub const SYS_mount = (SYS_Linux + 21); | |
| 33 | pub const SYS_umount = (SYS_Linux + 22); | |
| 34 | pub const SYS_setuid = (SYS_Linux + 23); | |
| 35 | pub const SYS_getuid = (SYS_Linux + 24); | |
| 36 | pub const SYS_stime = (SYS_Linux + 25); | |
| 37 | pub const SYS_ptrace = (SYS_Linux + 26); | |
| 38 | pub const SYS_alarm = (SYS_Linux + 27); | |
| 39 | pub const SYS_unused28 = (SYS_Linux + 28); | |
| 40 | pub const SYS_pause = (SYS_Linux + 29); | |
| 41 | pub const SYS_utime = (SYS_Linux + 30); | |
| 42 | pub const SYS_stty = (SYS_Linux + 31); | |
| 43 | pub const SYS_gtty = (SYS_Linux + 32); | |
| 44 | pub const SYS_access = (SYS_Linux + 33); | |
| 45 | pub const SYS_nice = (SYS_Linux + 34); | |
| 46 | pub const SYS_ftime = (SYS_Linux + 35); | |
| 47 | pub const SYS_sync = (SYS_Linux + 36); | |
| 48 | pub const SYS_kill = (SYS_Linux + 37); | |
| 49 | pub const SYS_rename = (SYS_Linux + 38); | |
| 50 | pub const SYS_mkdir = (SYS_Linux + 39); | |
| 51 | pub const SYS_rmdir = (SYS_Linux + 40); | |
| 52 | pub const SYS_dup = (SYS_Linux + 41); | |
| 53 | pub const SYS_pipe = (SYS_Linux + 42); | |
| 54 | pub const SYS_times = (SYS_Linux + 43); | |
| 55 | pub const SYS_prof = (SYS_Linux + 44); | |
| 56 | pub const SYS_brk = (SYS_Linux + 45); | |
| 57 | pub const SYS_setgid = (SYS_Linux + 46); | |
| 58 | pub const SYS_getgid = (SYS_Linux + 47); | |
| 59 | pub const SYS_signal = (SYS_Linux + 48); | |
| 60 | pub const SYS_geteuid = (SYS_Linux + 49); | |
| 61 | pub const SYS_getegid = (SYS_Linux + 50); | |
| 62 | pub const SYS_acct = (SYS_Linux + 51); | |
| 63 | pub const SYS_umount2 = (SYS_Linux + 52); | |
| 64 | pub const SYS_lock = (SYS_Linux + 53); | |
| 65 | pub const SYS_ioctl = (SYS_Linux + 54); | |
| 66 | pub const SYS_fcntl = (SYS_Linux + 55); | |
| 67 | pub const SYS_mpx = (SYS_Linux + 56); | |
| 68 | pub const SYS_setpgid = (SYS_Linux + 57); | |
| 69 | pub const SYS_ulimit = (SYS_Linux + 58); | |
| 70 | pub const SYS_unused59 = (SYS_Linux + 59); | |
| 71 | pub const SYS_umask = (SYS_Linux + 60); | |
| 72 | pub const SYS_chroot = (SYS_Linux + 61); | |
| 73 | pub const SYS_ustat = (SYS_Linux + 62); | |
| 74 | pub const SYS_dup2 = (SYS_Linux + 63); | |
| 75 | pub const SYS_getppid = (SYS_Linux + 64); | |
| 76 | pub const SYS_getpgrp = (SYS_Linux + 65); | |
| 77 | pub const SYS_setsid = (SYS_Linux + 66); | |
| 78 | pub const SYS_sigaction = (SYS_Linux + 67); | |
| 79 | pub const SYS_sgetmask = (SYS_Linux + 68); | |
| 80 | pub const SYS_ssetmask = (SYS_Linux + 69); | |
| 81 | pub const SYS_setreuid = (SYS_Linux + 70); | |
| 82 | pub const SYS_setregid = (SYS_Linux + 71); | |
| 83 | pub const SYS_sigsuspend = (SYS_Linux + 72); | |
| 84 | pub const SYS_sigpending = (SYS_Linux + 73); | |
| 85 | pub const SYS_sethostname = (SYS_Linux + 74); | |
| 86 | pub const SYS_setrlimit = (SYS_Linux + 75); | |
| 87 | pub const SYS_getrlimit = (SYS_Linux + 76); | |
| 88 | pub const SYS_getrusage = (SYS_Linux + 77); | |
| 89 | pub const SYS_gettimeofday = (SYS_Linux + 78); | |
| 90 | pub const SYS_settimeofday = (SYS_Linux + 79); | |
| 91 | pub const SYS_getgroups = (SYS_Linux + 80); | |
| 92 | pub const SYS_setgroups = (SYS_Linux + 81); | |
| 93 | pub const SYS_reserved82 = (SYS_Linux + 82); | |
| 94 | pub const SYS_symlink = (SYS_Linux + 83); | |
| 95 | pub const SYS_unused84 = (SYS_Linux + 84); | |
| 96 | pub const SYS_readlink = (SYS_Linux + 85); | |
| 97 | pub const SYS_uselib = (SYS_Linux + 86); | |
| 98 | pub const SYS_swapon = (SYS_Linux + 87); | |
| 99 | pub const SYS_reboot = (SYS_Linux + 88); | |
| 100 | pub const SYS_readdir = (SYS_Linux + 89); | |
| 101 | pub const SYS_mmap = (SYS_Linux + 90); | |
| 102 | pub const SYS_munmap = (SYS_Linux + 91); | |
| 103 | pub const SYS_truncate = (SYS_Linux + 92); | |
| 104 | pub const SYS_ftruncate = (SYS_Linux + 93); | |
| 105 | pub const SYS_fchmod = (SYS_Linux + 94); | |
| 106 | pub const SYS_fchown = (SYS_Linux + 95); | |
| 107 | pub const SYS_getpriority = (SYS_Linux + 96); | |
| 108 | pub const SYS_setpriority = (SYS_Linux + 97); | |
| 109 | pub const SYS_profil = (SYS_Linux + 98); | |
| 110 | pub const SYS_statfs = (SYS_Linux + 99); | |
| 111 | pub const SYS_fstatfs = (SYS_Linux + 100); | |
| 112 | pub const SYS_ioperm = (SYS_Linux + 101); | |
| 113 | pub const SYS_socketcall = (SYS_Linux + 102); | |
| 114 | pub const SYS_syslog = (SYS_Linux + 103); | |
| 115 | pub const SYS_setitimer = (SYS_Linux + 104); | |
| 116 | pub const SYS_getitimer = (SYS_Linux + 105); | |
| 117 | pub const SYS_stat = (SYS_Linux + 106); | |
| 118 | pub const SYS_lstat = (SYS_Linux + 107); | |
| 119 | pub const SYS_fstat = (SYS_Linux + 108); | |
| 120 | pub const SYS_unused109 = (SYS_Linux + 109); | |
| 121 | pub const SYS_iopl = (SYS_Linux + 110); | |
| 122 | pub const SYS_vhangup = (SYS_Linux + 111); | |
| 123 | pub const SYS_idle = (SYS_Linux + 112); | |
| 124 | pub const SYS_vm86 = (SYS_Linux + 113); | |
| 125 | pub const SYS_wait4 = (SYS_Linux + 114); | |
| 126 | pub const SYS_swapoff = (SYS_Linux + 115); | |
| 127 | pub const SYS_sysinfo = (SYS_Linux + 116); | |
| 128 | pub const SYS_ipc = (SYS_Linux + 117); | |
| 129 | pub const SYS_fsync = (SYS_Linux + 118); | |
| 130 | pub const SYS_sigreturn = (SYS_Linux + 119); | |
| 131 | pub const SYS_clone = (SYS_Linux + 120); | |
| 132 | pub const SYS_setdomainname = (SYS_Linux + 121); | |
| 133 | pub const SYS_uname = (SYS_Linux + 122); | |
| 134 | pub const SYS_modify_ldt = (SYS_Linux + 123); | |
| 135 | pub const SYS_adjtimex = (SYS_Linux + 124); | |
| 136 | pub const SYS_mprotect = (SYS_Linux + 125); | |
| 137 | pub const SYS_sigprocmask = (SYS_Linux + 126); | |
| 138 | pub const SYS_create_module = (SYS_Linux + 127); | |
| 139 | pub const SYS_init_module = (SYS_Linux + 128); | |
| 140 | pub const SYS_delete_module = (SYS_Linux + 129); | |
| 141 | pub const SYS_get_kernel_syms = (SYS_Linux + 130); | |
| 142 | pub const SYS_quotactl = (SYS_Linux + 131); | |
| 143 | pub const SYS_getpgid = (SYS_Linux + 132); | |
| 144 | pub const SYS_fchdir = (SYS_Linux + 133); | |
| 145 | pub const SYS_bdflush = (SYS_Linux + 134); | |
| 146 | pub const SYS_sysfs = (SYS_Linux + 135); | |
| 147 | pub const SYS_personality = (SYS_Linux + 136); | |
| 148 | pub const SYS_afs_syscall = (SYS_Linux + 137); | |
| 149 | pub const SYS_setfsuid = (SYS_Linux + 138); | |
| 150 | pub const SYS_setfsgid = (SYS_Linux + 139); | |
| 151 | pub const SYS__llseek = (SYS_Linux + 140); | |
| 152 | pub const SYS_getdents = (SYS_Linux + 141); | |
| 153 | pub const SYS__newselect = (SYS_Linux + 142); | |
| 154 | pub const SYS_flock = (SYS_Linux + 143); | |
| 155 | pub const SYS_msync = (SYS_Linux + 144); | |
| 156 | pub const SYS_readv = (SYS_Linux + 145); | |
| 157 | pub const SYS_writev = (SYS_Linux + 146); | |
| 158 | pub const SYS_cacheflush = (SYS_Linux + 147); | |
| 159 | pub const SYS_cachectl = (SYS_Linux + 148); | |
| 160 | pub const SYS_sysmips = (SYS_Linux + 149); | |
| 161 | pub const SYS_unused150 = (SYS_Linux + 150); | |
| 162 | pub const SYS_getsid = (SYS_Linux + 151); | |
| 163 | pub const SYS_fdatasync = (SYS_Linux + 152); | |
| 164 | pub const SYS__sysctl = (SYS_Linux + 153); | |
| 165 | pub const SYS_mlock = (SYS_Linux + 154); | |
| 166 | pub const SYS_munlock = (SYS_Linux + 155); | |
| 167 | pub const SYS_mlockall = (SYS_Linux + 156); | |
| 168 | pub const SYS_munlockall = (SYS_Linux + 157); | |
| 169 | pub const SYS_sched_setparam = (SYS_Linux + 158); | |
| 170 | pub const SYS_sched_getparam = (SYS_Linux + 159); | |
| 171 | pub const SYS_sched_setscheduler = (SYS_Linux + 160); | |
| 172 | pub const SYS_sched_getscheduler = (SYS_Linux + 161); | |
| 173 | pub const SYS_sched_yield = (SYS_Linux + 162); | |
| 174 | pub const SYS_sched_get_priority_max = (SYS_Linux + 163); | |
| 175 | pub const SYS_sched_get_priority_min = (SYS_Linux + 164); | |
| 176 | pub const SYS_sched_rr_get_interval = (SYS_Linux + 165); | |
| 177 | pub const SYS_nanosleep = (SYS_Linux + 166); | |
| 178 | pub const SYS_mremap = (SYS_Linux + 167); | |
| 179 | pub const SYS_accept = (SYS_Linux + 168); | |
| 180 | pub const SYS_bind = (SYS_Linux + 169); | |
| 181 | pub const SYS_connect = (SYS_Linux + 170); | |
| 182 | pub const SYS_getpeername = (SYS_Linux + 171); | |
| 183 | pub const SYS_getsockname = (SYS_Linux + 172); | |
| 184 | pub const SYS_getsockopt = (SYS_Linux + 173); | |
| 185 | pub const SYS_listen = (SYS_Linux + 174); | |
| 186 | pub const SYS_recv = (SYS_Linux + 175); | |
| 187 | pub const SYS_recvfrom = (SYS_Linux + 176); | |
| 188 | pub const SYS_recvmsg = (SYS_Linux + 177); | |
| 189 | pub const SYS_send = (SYS_Linux + 178); | |
| 190 | pub const SYS_sendmsg = (SYS_Linux + 179); | |
| 191 | pub const SYS_sendto = (SYS_Linux + 180); | |
| 192 | pub const SYS_setsockopt = (SYS_Linux + 181); | |
| 193 | pub const SYS_shutdown = (SYS_Linux + 182); | |
| 194 | pub const SYS_socket = (SYS_Linux + 183); | |
| 195 | pub const SYS_socketpair = (SYS_Linux + 184); | |
| 196 | pub const SYS_setresuid = (SYS_Linux + 185); | |
| 197 | pub const SYS_getresuid = (SYS_Linux + 186); | |
| 198 | pub const SYS_query_module = (SYS_Linux + 187); | |
| 199 | pub const SYS_poll = (SYS_Linux + 188); | |
| 200 | pub const SYS_nfsservctl = (SYS_Linux + 189); | |
| 201 | pub const SYS_setresgid = (SYS_Linux + 190); | |
| 202 | pub const SYS_getresgid = (SYS_Linux + 191); | |
| 203 | pub const SYS_prctl = (SYS_Linux + 192); | |
| 204 | pub const SYS_rt_sigreturn = (SYS_Linux + 193); | |
| 205 | pub const SYS_rt_sigaction = (SYS_Linux + 194); | |
| 206 | pub const SYS_rt_sigprocmask = (SYS_Linux + 195); | |
| 207 | pub const SYS_rt_sigpending = (SYS_Linux + 196); | |
| 208 | pub const SYS_rt_sigtimedwait = (SYS_Linux + 197); | |
| 209 | pub const SYS_rt_sigqueueinfo = (SYS_Linux + 198); | |
| 210 | pub const SYS_rt_sigsuspend = (SYS_Linux + 199); | |
| 211 | pub const SYS_pread64 = (SYS_Linux + 200); | |
| 212 | pub const SYS_pwrite64 = (SYS_Linux + 201); | |
| 213 | pub const SYS_chown = (SYS_Linux + 202); | |
| 214 | pub const SYS_getcwd = (SYS_Linux + 203); | |
| 215 | pub const SYS_capget = (SYS_Linux + 204); | |
| 216 | pub const SYS_capset = (SYS_Linux + 205); | |
| 217 | pub const SYS_sigaltstack = (SYS_Linux + 206); | |
| 218 | pub const SYS_sendfile = (SYS_Linux + 207); | |
| 219 | pub const SYS_getpmsg = (SYS_Linux + 208); | |
| 220 | pub const SYS_putpmsg = (SYS_Linux + 209); | |
| 221 | pub const SYS_mmap2 = (SYS_Linux + 210); | |
| 222 | pub const SYS_truncate64 = (SYS_Linux + 211); | |
| 223 | pub const SYS_ftruncate64 = (SYS_Linux + 212); | |
| 224 | pub const SYS_stat64 = (SYS_Linux + 213); | |
| 225 | pub const SYS_lstat64 = (SYS_Linux + 214); | |
| 226 | pub const SYS_fstat64 = (SYS_Linux + 215); | |
| 227 | pub const SYS_pivot_root = (SYS_Linux + 216); | |
| 228 | pub const SYS_mincore = (SYS_Linux + 217); | |
| 229 | pub const SYS_madvise = (SYS_Linux + 218); | |
| 230 | pub const SYS_getdents64 = (SYS_Linux + 219); | |
| 231 | pub const SYS_fcntl64 = (SYS_Linux + 220); | |
| 232 | pub const SYS_reserved221 = (SYS_Linux + 221); | |
| 233 | pub const SYS_gettid = (SYS_Linux + 222); | |
| 234 | pub const SYS_readahead = (SYS_Linux + 223); | |
| 235 | pub const SYS_setxattr = (SYS_Linux + 224); | |
| 236 | pub const SYS_lsetxattr = (SYS_Linux + 225); | |
| 237 | pub const SYS_fsetxattr = (SYS_Linux + 226); | |
| 238 | pub const SYS_getxattr = (SYS_Linux + 227); | |
| 239 | pub const SYS_lgetxattr = (SYS_Linux + 228); | |
| 240 | pub const SYS_fgetxattr = (SYS_Linux + 229); | |
| 241 | pub const SYS_listxattr = (SYS_Linux + 230); | |
| 242 | pub const SYS_llistxattr = (SYS_Linux + 231); | |
| 243 | pub const SYS_flistxattr = (SYS_Linux + 232); | |
| 244 | pub const SYS_removexattr = (SYS_Linux + 233); | |
| 245 | pub const SYS_lremovexattr = (SYS_Linux + 234); | |
| 246 | pub const SYS_fremovexattr = (SYS_Linux + 235); | |
| 247 | pub const SYS_tkill = (SYS_Linux + 236); | |
| 248 | pub const SYS_sendfile64 = (SYS_Linux + 237); | |
| 249 | pub const SYS_futex = (SYS_Linux + 238); | |
| 250 | pub const SYS_sched_setaffinity = (SYS_Linux + 239); | |
| 251 | pub const SYS_sched_getaffinity = (SYS_Linux + 240); | |
| 252 | pub const SYS_io_setup = (SYS_Linux + 241); | |
| 253 | pub const SYS_io_destroy = (SYS_Linux + 242); | |
| 254 | pub const SYS_io_getevents = (SYS_Linux + 243); | |
| 255 | pub const SYS_io_submit = (SYS_Linux + 244); | |
| 256 | pub const SYS_io_cancel = (SYS_Linux + 245); | |
| 257 | pub const SYS_exit_group = (SYS_Linux + 246); | |
| 258 | pub const SYS_lookup_dcookie = (SYS_Linux + 247); | |
| 259 | pub const SYS_epoll_create = (SYS_Linux + 248); | |
| 260 | pub const SYS_epoll_ctl = (SYS_Linux + 249); | |
| 261 | pub const SYS_epoll_wait = (SYS_Linux + 250); | |
| 262 | pub const SYS_remap_file_pages = (SYS_Linux + 251); | |
| 263 | pub const SYS_set_tid_address = (SYS_Linux + 252); | |
| 264 | pub const SYS_restart_syscall = (SYS_Linux + 253); | |
| 265 | pub const SYS_fadvise64 = (SYS_Linux + 254); | |
| 266 | pub const SYS_statfs64 = (SYS_Linux + 255); | |
| 267 | pub const SYS_fstatfs64 = (SYS_Linux + 256); | |
| 268 | pub const SYS_timer_create = (SYS_Linux + 257); | |
| 269 | pub const SYS_timer_settime = (SYS_Linux + 258); | |
| 270 | pub const SYS_timer_gettime = (SYS_Linux + 259); | |
| 271 | pub const SYS_timer_getoverrun = (SYS_Linux + 260); | |
| 272 | pub const SYS_timer_delete = (SYS_Linux + 261); | |
| 273 | pub const SYS_clock_settime = (SYS_Linux + 262); | |
| 274 | pub const SYS_clock_gettime = (SYS_Linux + 263); | |
| 275 | pub const SYS_clock_getres = (SYS_Linux + 264); | |
| 276 | pub const SYS_clock_nanosleep = (SYS_Linux + 265); | |
| 277 | pub const SYS_tgkill = (SYS_Linux + 266); | |
| 278 | pub const SYS_utimes = (SYS_Linux + 267); | |
| 279 | pub const SYS_mbind = (SYS_Linux + 268); | |
| 280 | pub const SYS_get_mempolicy = (SYS_Linux + 269); | |
| 281 | pub const SYS_set_mempolicy = (SYS_Linux + 270); | |
| 282 | pub const SYS_mq_open = (SYS_Linux + 271); | |
| 283 | pub const SYS_mq_unlink = (SYS_Linux + 272); | |
| 284 | pub const SYS_mq_timedsend = (SYS_Linux + 273); | |
| 285 | pub const SYS_mq_timedreceive = (SYS_Linux + 274); | |
| 286 | pub const SYS_mq_notify = (SYS_Linux + 275); | |
| 287 | pub const SYS_mq_getsetattr = (SYS_Linux + 276); | |
| 288 | pub const SYS_vserver = (SYS_Linux + 277); | |
| 289 | pub const SYS_waitid = (SYS_Linux + 278); | |
| 290 | pub const SYS_add_key = (SYS_Linux + 280); | |
| 291 | pub const SYS_request_key = (SYS_Linux + 281); | |
| 292 | pub const SYS_keyctl = (SYS_Linux + 282); | |
| 293 | pub const SYS_set_thread_area = (SYS_Linux + 283); | |
| 294 | pub const SYS_inotify_init = (SYS_Linux + 284); | |
| 295 | pub const SYS_inotify_add_watch = (SYS_Linux + 285); | |
| 296 | pub const SYS_inotify_rm_watch = (SYS_Linux + 286); | |
| 297 | pub const SYS_migrate_pages = (SYS_Linux + 287); | |
| 298 | pub const SYS_openat = (SYS_Linux + 288); | |
| 299 | pub const SYS_mkdirat = (SYS_Linux + 289); | |
| 300 | pub const SYS_mknodat = (SYS_Linux + 290); | |
| 301 | pub const SYS_fchownat = (SYS_Linux + 291); | |
| 302 | pub const SYS_futimesat = (SYS_Linux + 292); | |
| 303 | pub const SYS_fstatat64 = (SYS_Linux + 293); | |
| 304 | pub const SYS_unlinkat = (SYS_Linux + 294); | |
| 305 | pub const SYS_renameat = (SYS_Linux + 295); | |
| 306 | pub const SYS_linkat = (SYS_Linux + 296); | |
| 307 | pub const SYS_symlinkat = (SYS_Linux + 297); | |
| 308 | pub const SYS_readlinkat = (SYS_Linux + 298); | |
| 309 | pub const SYS_fchmodat = (SYS_Linux + 299); | |
| 310 | pub const SYS_faccessat = (SYS_Linux + 300); | |
| 311 | pub const SYS_pselect6 = (SYS_Linux + 301); | |
| 312 | pub const SYS_ppoll = (SYS_Linux + 302); | |
| 313 | pub const SYS_unshare = (SYS_Linux + 303); | |
| 314 | pub const SYS_splice = (SYS_Linux + 304); | |
| 315 | pub const SYS_sync_file_range = (SYS_Linux + 305); | |
| 316 | pub const SYS_tee = (SYS_Linux + 306); | |
| 317 | pub const SYS_vmsplice = (SYS_Linux + 307); | |
| 318 | pub const SYS_move_pages = (SYS_Linux + 308); | |
| 319 | pub const SYS_set_robust_list = (SYS_Linux + 309); | |
| 320 | pub const SYS_get_robust_list = (SYS_Linux + 310); | |
| 321 | pub const SYS_kexec_load = (SYS_Linux + 311); | |
| 322 | pub const SYS_getcpu = (SYS_Linux + 312); | |
| 323 | pub const SYS_epoll_pwait = (SYS_Linux + 313); | |
| 324 | pub const SYS_ioprio_set = (SYS_Linux + 314); | |
| 325 | pub const SYS_ioprio_get = (SYS_Linux + 315); | |
| 326 | pub const SYS_utimensat = (SYS_Linux + 316); | |
| 327 | pub const SYS_signalfd = (SYS_Linux + 317); | |
| 328 | pub const SYS_timerfd = (SYS_Linux + 318); | |
| 329 | pub const SYS_eventfd = (SYS_Linux + 319); | |
| 330 | pub const SYS_fallocate = (SYS_Linux + 320); | |
| 331 | pub const SYS_timerfd_create = (SYS_Linux + 321); | |
| 332 | pub const SYS_timerfd_gettime = (SYS_Linux + 322); | |
| 333 | pub const SYS_timerfd_settime = (SYS_Linux + 323); | |
| 334 | pub const SYS_signalfd4 = (SYS_Linux + 324); | |
| 335 | pub const SYS_eventfd2 = (SYS_Linux + 325); | |
| 336 | pub const SYS_epoll_create1 = (SYS_Linux + 326); | |
| 337 | pub const SYS_dup3 = (SYS_Linux + 327); | |
| 338 | pub const SYS_pipe2 = (SYS_Linux + 328); | |
| 339 | pub const SYS_inotify_init1 = (SYS_Linux + 329); | |
| 340 | pub const SYS_preadv = (SYS_Linux + 330); | |
| 341 | pub const SYS_pwritev = (SYS_Linux + 331); | |
| 342 | pub const SYS_rt_tgsigqueueinfo = (SYS_Linux + 332); | |
| 343 | pub const SYS_perf_event_open = (SYS_Linux + 333); | |
| 344 | pub const SYS_accept4 = (SYS_Linux + 334); | |
| 345 | pub const SYS_recvmmsg = (SYS_Linux + 335); | |
| 346 | pub const SYS_fanotify_init = (SYS_Linux + 336); | |
| 347 | pub const SYS_fanotify_mark = (SYS_Linux + 337); | |
| 348 | pub const SYS_prlimit64 = (SYS_Linux + 338); | |
| 349 | pub const SYS_name_to_handle_at = (SYS_Linux + 339); | |
| 350 | pub const SYS_open_by_handle_at = (SYS_Linux + 340); | |
| 351 | pub const SYS_clock_adjtime = (SYS_Linux + 341); | |
| 352 | pub const SYS_syncfs = (SYS_Linux + 342); | |
| 353 | pub const SYS_sendmmsg = (SYS_Linux + 343); | |
| 354 | pub const SYS_setns = (SYS_Linux + 344); | |
| 355 | pub const SYS_process_vm_readv = (SYS_Linux + 345); | |
| 356 | pub const SYS_process_vm_writev = (SYS_Linux + 346); | |
| 357 | pub const SYS_kcmp = (SYS_Linux + 347); | |
| 358 | pub const SYS_finit_module = (SYS_Linux + 348); | |
| 359 | pub const SYS_sched_setattr = (SYS_Linux + 349); | |
| 360 | pub const SYS_sched_getattr = (SYS_Linux + 350); | |
| 361 | pub const SYS_renameat2 = (SYS_Linux + 351); | |
| 362 | pub const SYS_seccomp = (SYS_Linux + 352); | |
| 363 | pub const SYS_getrandom = (SYS_Linux + 353); | |
| 364 | pub const SYS_memfd_create = (SYS_Linux + 354); | |
| 365 | pub const SYS_bpf = (SYS_Linux + 355); | |
| 366 | pub const SYS_execveat = (SYS_Linux + 356); | |
| 367 | pub const SYS_userfaultfd = (SYS_Linux + 357); | |
| 368 | pub const SYS_membarrier = (SYS_Linux + 358); | |
| 369 | pub const SYS_mlock2 = (SYS_Linux + 359); | |
| 370 | pub const SYS_copy_file_range = (SYS_Linux + 360); | |
| 371 | pub const SYS_preadv2 = (SYS_Linux + 361); | |
| 372 | pub const SYS_pwritev2 = (SYS_Linux + 362); | |
| 373 | pub const SYS_pkey_mprotect = (SYS_Linux + 363); | |
| 374 | pub const SYS_pkey_alloc = (SYS_Linux + 364); | |
| 375 | pub const SYS_pkey_free = (SYS_Linux + 365); | |
| 376 | pub const SYS_statx = (SYS_Linux + 366); | |
| 377 | pub const SYS_rseq = (SYS_Linux + 367); | |
| 378 | pub const SYS_io_pgetevents = (SYS_Linux + 368); | |
| 10 | pub const SYS = extern enum(usize) { | |
| 11 | pub const Linux = 4000; | |
| 12 | ||
| 13 | syscall = Linux + 0, | |
| 14 | exit = Linux + 1, | |
| 15 | fork = Linux + 2, | |
| 16 | read = Linux + 3, | |
| 17 | write = Linux + 4, | |
| 18 | open = Linux + 5, | |
| 19 | close = Linux + 6, | |
| 20 | waitpid = Linux + 7, | |
| 21 | creat = Linux + 8, | |
| 22 | link = Linux + 9, | |
| 23 | unlink = Linux + 10, | |
| 24 | execve = Linux + 11, | |
| 25 | chdir = Linux + 12, | |
| 26 | time = Linux + 13, | |
| 27 | mknod = Linux + 14, | |
| 28 | chmod = Linux + 15, | |
| 29 | lchown = Linux + 16, | |
| 30 | @"break" = Linux + 17, | |
| 31 | unused18 = Linux + 18, | |
| 32 | lseek = Linux + 19, | |
| 33 | getpid = Linux + 20, | |
| 34 | mount = Linux + 21, | |
| 35 | umount = Linux + 22, | |
| 36 | setuid = Linux + 23, | |
| 37 | getuid = Linux + 24, | |
| 38 | stime = Linux + 25, | |
| 39 | ptrace = Linux + 26, | |
| 40 | alarm = Linux + 27, | |
| 41 | unused28 = Linux + 28, | |
| 42 | pause = Linux + 29, | |
| 43 | utime = Linux + 30, | |
| 44 | stty = Linux + 31, | |
| 45 | gtty = Linux + 32, | |
| 46 | access = Linux + 33, | |
| 47 | nice = Linux + 34, | |
| 48 | ftime = Linux + 35, | |
| 49 | sync = Linux + 36, | |
| 50 | kill = Linux + 37, | |
| 51 | rename = Linux + 38, | |
| 52 | mkdir = Linux + 39, | |
| 53 | rmdir = Linux + 40, | |
| 54 | dup = Linux + 41, | |
| 55 | pipe = Linux + 42, | |
| 56 | times = Linux + 43, | |
| 57 | prof = Linux + 44, | |
| 58 | brk = Linux + 45, | |
| 59 | setgid = Linux + 46, | |
| 60 | getgid = Linux + 47, | |
| 61 | signal = Linux + 48, | |
| 62 | geteuid = Linux + 49, | |
| 63 | getegid = Linux + 50, | |
| 64 | acct = Linux + 51, | |
| 65 | umount2 = Linux + 52, | |
| 66 | lock = Linux + 53, | |
| 67 | ioctl = Linux + 54, | |
| 68 | fcntl = Linux + 55, | |
| 69 | mpx = Linux + 56, | |
| 70 | setpgid = Linux + 57, | |
| 71 | ulimit = Linux + 58, | |
| 72 | unused59 = Linux + 59, | |
| 73 | umask = Linux + 60, | |
| 74 | chroot = Linux + 61, | |
| 75 | ustat = Linux + 62, | |
| 76 | dup2 = Linux + 63, | |
| 77 | getppid = Linux + 64, | |
| 78 | getpgrp = Linux + 65, | |
| 79 | setsid = Linux + 66, | |
| 80 | sigaction = Linux + 67, | |
| 81 | sgetmask = Linux + 68, | |
| 82 | ssetmask = Linux + 69, | |
| 83 | setreuid = Linux + 70, | |
| 84 | setregid = Linux + 71, | |
| 85 | sigsuspend = Linux + 72, | |
| 86 | sigpending = Linux + 73, | |
| 87 | sethostname = Linux + 74, | |
| 88 | setrlimit = Linux + 75, | |
| 89 | getrlimit = Linux + 76, | |
| 90 | getrusage = Linux + 77, | |
| 91 | gettimeofday = Linux + 78, | |
| 92 | settimeofday = Linux + 79, | |
| 93 | getgroups = Linux + 80, | |
| 94 | setgroups = Linux + 81, | |
| 95 | reserved82 = Linux + 82, | |
| 96 | symlink = Linux + 83, | |
| 97 | unused84 = Linux + 84, | |
| 98 | readlink = Linux + 85, | |
| 99 | uselib = Linux + 86, | |
| 100 | swapon = Linux + 87, | |
| 101 | reboot = Linux + 88, | |
| 102 | readdir = Linux + 89, | |
| 103 | mmap = Linux + 90, | |
| 104 | munmap = Linux + 91, | |
| 105 | truncate = Linux + 92, | |
| 106 | ftruncate = Linux + 93, | |
| 107 | fchmod = Linux + 94, | |
| 108 | fchown = Linux + 95, | |
| 109 | getpriority = Linux + 96, | |
| 110 | setpriority = Linux + 97, | |
| 111 | profil = Linux + 98, | |
| 112 | statfs = Linux + 99, | |
| 113 | fstatfs = Linux + 100, | |
| 114 | ioperm = Linux + 101, | |
| 115 | socketcall = Linux + 102, | |
| 116 | syslog = Linux + 103, | |
| 117 | setitimer = Linux + 104, | |
| 118 | getitimer = Linux + 105, | |
| 119 | stat = Linux + 106, | |
| 120 | lstat = Linux + 107, | |
| 121 | fstat = Linux + 108, | |
| 122 | unused109 = Linux + 109, | |
| 123 | iopl = Linux + 110, | |
| 124 | vhangup = Linux + 111, | |
| 125 | idle = Linux + 112, | |
| 126 | vm86 = Linux + 113, | |
| 127 | wait4 = Linux + 114, | |
| 128 | swapoff = Linux + 115, | |
| 129 | sysinfo = Linux + 116, | |
| 130 | ipc = Linux + 117, | |
| 131 | fsync = Linux + 118, | |
| 132 | sigreturn = Linux + 119, | |
| 133 | clone = Linux + 120, | |
| 134 | setdomainname = Linux + 121, | |
| 135 | uname = Linux + 122, | |
| 136 | modify_ldt = Linux + 123, | |
| 137 | adjtimex = Linux + 124, | |
| 138 | mprotect = Linux + 125, | |
| 139 | sigprocmask = Linux + 126, | |
| 140 | create_module = Linux + 127, | |
| 141 | init_module = Linux + 128, | |
| 142 | delete_module = Linux + 129, | |
| 143 | get_kernel_syms = Linux + 130, | |
| 144 | quotactl = Linux + 131, | |
| 145 | getpgid = Linux + 132, | |
| 146 | fchdir = Linux + 133, | |
| 147 | bdflush = Linux + 134, | |
| 148 | sysfs = Linux + 135, | |
| 149 | personality = Linux + 136, | |
| 150 | afs_syscall = Linux + 137, | |
| 151 | setfsuid = Linux + 138, | |
| 152 | setfsgid = Linux + 139, | |
| 153 | _llseek = Linux + 140, | |
| 154 | getdents = Linux + 141, | |
| 155 | _newselect = Linux + 142, | |
| 156 | flock = Linux + 143, | |
| 157 | msync = Linux + 144, | |
| 158 | readv = Linux + 145, | |
| 159 | writev = Linux + 146, | |
| 160 | cacheflush = Linux + 147, | |
| 161 | cachectl = Linux + 148, | |
| 162 | sysmips = Linux + 149, | |
| 163 | unused150 = Linux + 150, | |
| 164 | getsid = Linux + 151, | |
| 165 | fdatasync = Linux + 152, | |
| 166 | _sysctl = Linux + 153, | |
| 167 | mlock = Linux + 154, | |
| 168 | munlock = Linux + 155, | |
| 169 | mlockall = Linux + 156, | |
| 170 | munlockall = Linux + 157, | |
| 171 | sched_setparam = Linux + 158, | |
| 172 | sched_getparam = Linux + 159, | |
| 173 | sched_setscheduler = Linux + 160, | |
| 174 | sched_getscheduler = Linux + 161, | |
| 175 | sched_yield = Linux + 162, | |
| 176 | sched_get_priority_max = Linux + 163, | |
| 177 | sched_get_priority_min = Linux + 164, | |
| 178 | sched_rr_get_interval = Linux + 165, | |
| 179 | nanosleep = Linux + 166, | |
| 180 | mremap = Linux + 167, | |
| 181 | accept = Linux + 168, | |
| 182 | bind = Linux + 169, | |
| 183 | connect = Linux + 170, | |
| 184 | getpeername = Linux + 171, | |
| 185 | getsockname = Linux + 172, | |
| 186 | getsockopt = Linux + 173, | |
| 187 | listen = Linux + 174, | |
| 188 | recv = Linux + 175, | |
| 189 | recvfrom = Linux + 176, | |
| 190 | recvmsg = Linux + 177, | |
| 191 | send = Linux + 178, | |
| 192 | sendmsg = Linux + 179, | |
| 193 | sendto = Linux + 180, | |
| 194 | setsockopt = Linux + 181, | |
| 195 | shutdown = Linux + 182, | |
| 196 | socket = Linux + 183, | |
| 197 | socketpair = Linux + 184, | |
| 198 | setresuid = Linux + 185, | |
| 199 | getresuid = Linux + 186, | |
| 200 | query_module = Linux + 187, | |
| 201 | poll = Linux + 188, | |
| 202 | nfsservctl = Linux + 189, | |
| 203 | setresgid = Linux + 190, | |
| 204 | getresgid = Linux + 191, | |
| 205 | prctl = Linux + 192, | |
| 206 | rt_sigreturn = Linux + 193, | |
| 207 | rt_sigaction = Linux + 194, | |
| 208 | rt_sigprocmask = Linux + 195, | |
| 209 | rt_sigpending = Linux + 196, | |
| 210 | rt_sigtimedwait = Linux + 197, | |
| 211 | rt_sigqueueinfo = Linux + 198, | |
| 212 | rt_sigsuspend = Linux + 199, | |
| 213 | pread64 = Linux + 200, | |
| 214 | pwrite64 = Linux + 201, | |
| 215 | chown = Linux + 202, | |
| 216 | getcwd = Linux + 203, | |
| 217 | capget = Linux + 204, | |
| 218 | capset = Linux + 205, | |
| 219 | sigaltstack = Linux + 206, | |
| 220 | sendfile = Linux + 207, | |
| 221 | getpmsg = Linux + 208, | |
| 222 | putpmsg = Linux + 209, | |
| 223 | mmap2 = Linux + 210, | |
| 224 | truncate64 = Linux + 211, | |
| 225 | ftruncate64 = Linux + 212, | |
| 226 | stat64 = Linux + 213, | |
| 227 | lstat64 = Linux + 214, | |
| 228 | fstat64 = Linux + 215, | |
| 229 | pivot_root = Linux + 216, | |
| 230 | mincore = Linux + 217, | |
| 231 | madvise = Linux + 218, | |
| 232 | getdents64 = Linux + 219, | |
| 233 | fcntl64 = Linux + 220, | |
| 234 | reserved221 = Linux + 221, | |
| 235 | gettid = Linux + 222, | |
| 236 | readahead = Linux + 223, | |
| 237 | setxattr = Linux + 224, | |
| 238 | lsetxattr = Linux + 225, | |
| 239 | fsetxattr = Linux + 226, | |
| 240 | getxattr = Linux + 227, | |
| 241 | lgetxattr = Linux + 228, | |
| 242 | fgetxattr = Linux + 229, | |
| 243 | listxattr = Linux + 230, | |
| 244 | llistxattr = Linux + 231, | |
| 245 | flistxattr = Linux + 232, | |
| 246 | removexattr = Linux + 233, | |
| 247 | lremovexattr = Linux + 234, | |
| 248 | fremovexattr = Linux + 235, | |
| 249 | tkill = Linux + 236, | |
| 250 | sendfile64 = Linux + 237, | |
| 251 | futex = Linux + 238, | |
| 252 | sched_setaffinity = Linux + 239, | |
| 253 | sched_getaffinity = Linux + 240, | |
| 254 | io_setup = Linux + 241, | |
| 255 | io_destroy = Linux + 242, | |
| 256 | io_getevents = Linux + 243, | |
| 257 | io_submit = Linux + 244, | |
| 258 | io_cancel = Linux + 245, | |
| 259 | exit_group = Linux + 246, | |
| 260 | lookup_dcookie = Linux + 247, | |
| 261 | epoll_create = Linux + 248, | |
| 262 | epoll_ctl = Linux + 249, | |
| 263 | epoll_wait = Linux + 250, | |
| 264 | remap_file_pages = Linux + 251, | |
| 265 | set_tid_address = Linux + 252, | |
| 266 | restart_syscall = Linux + 253, | |
| 267 | fadvise64 = Linux + 254, | |
| 268 | statfs64 = Linux + 255, | |
| 269 | fstatfs64 = Linux + 256, | |
| 270 | timer_create = Linux + 257, | |
| 271 | timer_settime = Linux + 258, | |
| 272 | timer_gettime = Linux + 259, | |
| 273 | timer_getoverrun = Linux + 260, | |
| 274 | timer_delete = Linux + 261, | |
| 275 | clock_settime = Linux + 262, | |
| 276 | clock_gettime = Linux + 263, | |
| 277 | clock_getres = Linux + 264, | |
| 278 | clock_nanosleep = Linux + 265, | |
| 279 | tgkill = Linux + 266, | |
| 280 | utimes = Linux + 267, | |
| 281 | mbind = Linux + 268, | |
| 282 | get_mempolicy = Linux + 269, | |
| 283 | set_mempolicy = Linux + 270, | |
| 284 | mq_open = Linux + 271, | |
| 285 | mq_unlink = Linux + 272, | |
| 286 | mq_timedsend = Linux + 273, | |
| 287 | mq_timedreceive = Linux + 274, | |
| 288 | mq_notify = Linux + 275, | |
| 289 | mq_getsetattr = Linux + 276, | |
| 290 | vserver = Linux + 277, | |
| 291 | waitid = Linux + 278, | |
| 292 | add_key = Linux + 280, | |
| 293 | request_key = Linux + 281, | |
| 294 | keyctl = Linux + 282, | |
| 295 | set_thread_area = Linux + 283, | |
| 296 | inotify_init = Linux + 284, | |
| 297 | inotify_add_watch = Linux + 285, | |
| 298 | inotify_rm_watch = Linux + 286, | |
| 299 | migrate_pages = Linux + 287, | |
| 300 | openat = Linux + 288, | |
| 301 | mkdirat = Linux + 289, | |
| 302 | mknodat = Linux + 290, | |
| 303 | fchownat = Linux + 291, | |
| 304 | futimesat = Linux + 292, | |
| 305 | fstatat64 = Linux + 293, | |
| 306 | unlinkat = Linux + 294, | |
| 307 | renameat = Linux + 295, | |
| 308 | linkat = Linux + 296, | |
| 309 | symlinkat = Linux + 297, | |
| 310 | readlinkat = Linux + 298, | |
| 311 | fchmodat = Linux + 299, | |
| 312 | faccessat = Linux + 300, | |
| 313 | pselect6 = Linux + 301, | |
| 314 | ppoll = Linux + 302, | |
| 315 | unshare = Linux + 303, | |
| 316 | splice = Linux + 304, | |
| 317 | sync_file_range = Linux + 305, | |
| 318 | tee = Linux + 306, | |
| 319 | vmsplice = Linux + 307, | |
| 320 | move_pages = Linux + 308, | |
| 321 | set_robust_list = Linux + 309, | |
| 322 | get_robust_list = Linux + 310, | |
| 323 | kexec_load = Linux + 311, | |
| 324 | getcpu = Linux + 312, | |
| 325 | epoll_pwait = Linux + 313, | |
| 326 | ioprio_set = Linux + 314, | |
| 327 | ioprio_get = Linux + 315, | |
| 328 | utimensat = Linux + 316, | |
| 329 | signalfd = Linux + 317, | |
| 330 | timerfd = Linux + 318, | |
| 331 | eventfd = Linux + 319, | |
| 332 | fallocate = Linux + 320, | |
| 333 | timerfd_create = Linux + 321, | |
| 334 | timerfd_gettime = Linux + 322, | |
| 335 | timerfd_settime = Linux + 323, | |
| 336 | signalfd4 = Linux + 324, | |
| 337 | eventfd2 = Linux + 325, | |
| 338 | epoll_create1 = Linux + 326, | |
| 339 | dup3 = Linux + 327, | |
| 340 | pipe2 = Linux + 328, | |
| 341 | inotify_init1 = Linux + 329, | |
| 342 | preadv = Linux + 330, | |
| 343 | pwritev = Linux + 331, | |
| 344 | rt_tgsigqueueinfo = Linux + 332, | |
| 345 | perf_event_open = Linux + 333, | |
| 346 | accept4 = Linux + 334, | |
| 347 | recvmmsg = Linux + 335, | |
| 348 | fanotify_init = Linux + 336, | |
| 349 | fanotify_mark = Linux + 337, | |
| 350 | prlimit64 = Linux + 338, | |
| 351 | name_to_handle_at = Linux + 339, | |
| 352 | open_by_handle_at = Linux + 340, | |
| 353 | clock_adjtime = Linux + 341, | |
| 354 | syncfs = Linux + 342, | |
| 355 | sendmmsg = Linux + 343, | |
| 356 | setns = Linux + 344, | |
| 357 | process_vm_readv = Linux + 345, | |
| 358 | process_vm_writev = Linux + 346, | |
| 359 | kcmp = Linux + 347, | |
| 360 | finit_module = Linux + 348, | |
| 361 | sched_setattr = Linux + 349, | |
| 362 | sched_getattr = Linux + 350, | |
| 363 | renameat2 = Linux + 351, | |
| 364 | seccomp = Linux + 352, | |
| 365 | getrandom = Linux + 353, | |
| 366 | memfd_create = Linux + 354, | |
| 367 | bpf = Linux + 355, | |
| 368 | execveat = Linux + 356, | |
| 369 | userfaultfd = Linux + 357, | |
| 370 | membarrier = Linux + 358, | |
| 371 | mlock2 = Linux + 359, | |
| 372 | copy_file_range = Linux + 360, | |
| 373 | preadv2 = Linux + 361, | |
| 374 | pwritev2 = Linux + 362, | |
| 375 | pkey_mprotect = Linux + 363, | |
| 376 | pkey_alloc = Linux + 364, | |
| 377 | pkey_free = Linux + 365, | |
| 378 | statx = Linux + 366, | |
| 379 | rseq = Linux + 367, | |
| 380 | io_pgetevents = Linux + 368, | |
| 381 | openat2 = Linux + 437, | |
| 382 | pidfd_getfd = Linux + 438, | |
| 383 | ||
| 384 | _, | |
| 385 | }; | |
| 379 | 386 | |
| 380 | 387 | pub const O_CREAT = 0o0400; |
| 381 | 388 | pub const O_EXCL = 0o02000; |
lib/std/os/bits/linux/riscv64.zig+298-292| ... | ... | @@ -4,300 +4,306 @@ const uid_t = std.os.linux.uid_t; |
| 4 | 4 | const gid_t = std.os.linux.gid_t; |
| 5 | 5 | const pid_t = std.os.linux.pid_t; |
| 6 | 6 | |
| 7 | pub const SYS_io_setup = 0; | |
| 8 | pub const SYS_io_destroy = 1; | |
| 9 | pub const SYS_io_submit = 2; | |
| 10 | pub const SYS_io_cancel = 3; | |
| 11 | pub const SYS_io_getevents = 4; | |
| 12 | pub const SYS_setxattr = 5; | |
| 13 | pub const SYS_lsetxattr = 6; | |
| 14 | pub const SYS_fsetxattr = 7; | |
| 15 | pub const SYS_getxattr = 8; | |
| 16 | pub const SYS_lgetxattr = 9; | |
| 17 | pub const SYS_fgetxattr = 10; | |
| 18 | pub const SYS_listxattr = 11; | |
| 19 | pub const SYS_llistxattr = 12; | |
| 20 | pub const SYS_flistxattr = 13; | |
| 21 | pub const SYS_removexattr = 14; | |
| 22 | pub const SYS_lremovexattr = 15; | |
| 23 | pub const SYS_fremovexattr = 16; | |
| 24 | pub const SYS_getcwd = 17; | |
| 25 | pub const SYS_lookup_dcookie = 18; | |
| 26 | pub const SYS_eventfd2 = 19; | |
| 27 | pub const SYS_epoll_create1 = 20; | |
| 28 | pub const SYS_epoll_ctl = 21; | |
| 29 | pub const SYS_epoll_pwait = 22; | |
| 30 | pub const SYS_dup = 23; | |
| 31 | pub const SYS_dup3 = 24; | |
| 32 | pub const SYS_fcntl = 25; | |
| 33 | pub const SYS_inotify_init1 = 26; | |
| 34 | pub const SYS_inotify_add_watch = 27; | |
| 35 | pub const SYS_inotify_rm_watch = 28; | |
| 36 | pub const SYS_ioctl = 29; | |
| 37 | pub const SYS_ioprio_set = 30; | |
| 38 | pub const SYS_ioprio_get = 31; | |
| 39 | pub const SYS_flock = 32; | |
| 40 | pub const SYS_mknodat = 33; | |
| 41 | pub const SYS_mkdirat = 34; | |
| 42 | pub const SYS_unlinkat = 35; | |
| 43 | pub const SYS_symlinkat = 36; | |
| 44 | pub const SYS_linkat = 37; | |
| 45 | pub const SYS_umount2 = 39; | |
| 46 | pub const SYS_mount = 40; | |
| 47 | pub const SYS_pivot_root = 41; | |
| 48 | pub const SYS_nfsservctl = 42; | |
| 49 | pub const SYS_statfs = 43; | |
| 50 | pub const SYS_fstatfs = 44; | |
| 51 | pub const SYS_truncate = 45; | |
| 52 | pub const SYS_ftruncate = 46; | |
| 53 | pub const SYS_fallocate = 47; | |
| 54 | pub const SYS_faccessat = 48; | |
| 55 | pub const SYS_chdir = 49; | |
| 56 | pub const SYS_fchdir = 50; | |
| 57 | pub const SYS_chroot = 51; | |
| 58 | pub const SYS_fchmod = 52; | |
| 59 | pub const SYS_fchmodat = 53; | |
| 60 | pub const SYS_fchownat = 54; | |
| 61 | pub const SYS_fchown = 55; | |
| 62 | pub const SYS_openat = 56; | |
| 63 | pub const SYS_close = 57; | |
| 64 | pub const SYS_vhangup = 58; | |
| 65 | pub const SYS_pipe2 = 59; | |
| 66 | pub const SYS_quotactl = 60; | |
| 67 | pub const SYS_getdents64 = 61; | |
| 68 | pub const SYS_lseek = 62; | |
| 69 | pub const SYS_read = 63; | |
| 70 | pub const SYS_write = 64; | |
| 71 | pub const SYS_readv = 65; | |
| 72 | pub const SYS_writev = 66; | |
| 73 | pub const SYS_pread64 = 67; | |
| 74 | pub const SYS_pwrite64 = 68; | |
| 75 | pub const SYS_preadv = 69; | |
| 76 | pub const SYS_pwritev = 70; | |
| 77 | pub const SYS_sendfile = 71; | |
| 78 | pub const SYS_pselect6 = 72; | |
| 79 | pub const SYS_ppoll = 73; | |
| 80 | pub const SYS_signalfd4 = 74; | |
| 81 | pub const SYS_vmsplice = 75; | |
| 82 | pub const SYS_splice = 76; | |
| 83 | pub const SYS_tee = 77; | |
| 84 | pub const SYS_readlinkat = 78; | |
| 85 | pub const SYS_fstatat = 79; | |
| 86 | pub const SYS_fstat = 80; | |
| 87 | pub const SYS_sync = 81; | |
| 88 | pub const SYS_fsync = 82; | |
| 89 | pub const SYS_fdatasync = 83; | |
| 90 | pub const SYS_sync_file_range = 84; | |
| 91 | pub const SYS_timerfd_create = 85; | |
| 92 | pub const SYS_timerfd_settime = 86; | |
| 93 | pub const SYS_timerfd_gettime = 87; | |
| 94 | pub const SYS_utimensat = 88; | |
| 95 | pub const SYS_acct = 89; | |
| 96 | pub const SYS_capget = 90; | |
| 97 | pub const SYS_capset = 91; | |
| 98 | pub const SYS_personality = 92; | |
| 99 | pub const SYS_exit = 93; | |
| 100 | pub const SYS_exit_group = 94; | |
| 101 | pub const SYS_waitid = 95; | |
| 102 | pub const SYS_set_tid_address = 96; | |
| 103 | pub const SYS_unshare = 97; | |
| 104 | pub const SYS_futex = 98; | |
| 105 | pub const SYS_set_robust_list = 99; | |
| 106 | pub const SYS_get_robust_list = 100; | |
| 107 | pub const SYS_nanosleep = 101; | |
| 108 | pub const SYS_getitimer = 102; | |
| 109 | pub const SYS_setitimer = 103; | |
| 110 | pub const SYS_kexec_load = 104; | |
| 111 | pub const SYS_init_module = 105; | |
| 112 | pub const SYS_delete_module = 106; | |
| 113 | pub const SYS_timer_create = 107; | |
| 114 | pub const SYS_timer_gettime = 108; | |
| 115 | pub const SYS_timer_getoverrun = 109; | |
| 116 | pub const SYS_timer_settime = 110; | |
| 117 | pub const SYS_timer_delete = 111; | |
| 118 | pub const SYS_clock_settime = 112; | |
| 119 | pub const SYS_clock_gettime = 113; | |
| 120 | pub const SYS_clock_getres = 114; | |
| 121 | pub const SYS_clock_nanosleep = 115; | |
| 122 | pub const SYS_syslog = 116; | |
| 123 | pub const SYS_ptrace = 117; | |
| 124 | pub const SYS_sched_setparam = 118; | |
| 125 | pub const SYS_sched_setscheduler = 119; | |
| 126 | pub const SYS_sched_getscheduler = 120; | |
| 127 | pub const SYS_sched_getparam = 121; | |
| 128 | pub const SYS_sched_setaffinity = 122; | |
| 129 | pub const SYS_sched_getaffinity = 123; | |
| 130 | pub const SYS_sched_yield = 124; | |
| 131 | pub const SYS_sched_get_priority_max = 125; | |
| 132 | pub const SYS_sched_get_priority_min = 126; | |
| 133 | pub const SYS_sched_rr_get_interval = 127; | |
| 134 | pub const SYS_restart_syscall = 128; | |
| 135 | pub const SYS_kill = 129; | |
| 136 | pub const SYS_tkill = 130; | |
| 137 | pub const SYS_tgkill = 131; | |
| 138 | pub const SYS_sigaltstack = 132; | |
| 139 | pub const SYS_rt_sigsuspend = 133; | |
| 140 | pub const SYS_rt_sigaction = 134; | |
| 141 | pub const SYS_rt_sigprocmask = 135; | |
| 142 | pub const SYS_rt_sigpending = 136; | |
| 143 | pub const SYS_rt_sigtimedwait = 137; | |
| 144 | pub const SYS_rt_sigqueueinfo = 138; | |
| 145 | pub const SYS_rt_sigreturn = 139; | |
| 146 | pub const SYS_setpriority = 140; | |
| 147 | pub const SYS_getpriority = 141; | |
| 148 | pub const SYS_reboot = 142; | |
| 149 | pub const SYS_setregid = 143; | |
| 150 | pub const SYS_setgid = 144; | |
| 151 | pub const SYS_setreuid = 145; | |
| 152 | pub const SYS_setuid = 146; | |
| 153 | pub const SYS_setresuid = 147; | |
| 154 | pub const SYS_getresuid = 148; | |
| 155 | pub const SYS_setresgid = 149; | |
| 156 | pub const SYS_getresgid = 150; | |
| 157 | pub const SYS_setfsuid = 151; | |
| 158 | pub const SYS_setfsgid = 152; | |
| 159 | pub const SYS_times = 153; | |
| 160 | pub const SYS_setpgid = 154; | |
| 161 | pub const SYS_getpgid = 155; | |
| 162 | pub const SYS_getsid = 156; | |
| 163 | pub const SYS_setsid = 157; | |
| 164 | pub const SYS_getgroups = 158; | |
| 165 | pub const SYS_setgroups = 159; | |
| 166 | pub const SYS_uname = 160; | |
| 167 | pub const SYS_sethostname = 161; | |
| 168 | pub const SYS_setdomainname = 162; | |
| 169 | pub const SYS_getrlimit = 163; | |
| 170 | pub const SYS_setrlimit = 164; | |
| 171 | pub const SYS_getrusage = 165; | |
| 172 | pub const SYS_umask = 166; | |
| 173 | pub const SYS_prctl = 167; | |
| 174 | pub const SYS_getcpu = 168; | |
| 175 | pub const SYS_gettimeofday = 169; | |
| 176 | pub const SYS_settimeofday = 170; | |
| 177 | pub const SYS_adjtimex = 171; | |
| 178 | pub const SYS_getpid = 172; | |
| 179 | pub const SYS_getppid = 173; | |
| 180 | pub const SYS_getuid = 174; | |
| 181 | pub const SYS_geteuid = 175; | |
| 182 | pub const SYS_getgid = 176; | |
| 183 | pub const SYS_getegid = 177; | |
| 184 | pub const SYS_gettid = 178; | |
| 185 | pub const SYS_sysinfo = 179; | |
| 186 | pub const SYS_mq_open = 180; | |
| 187 | pub const SYS_mq_unlink = 181; | |
| 188 | pub const SYS_mq_timedsend = 182; | |
| 189 | pub const SYS_mq_timedreceive = 183; | |
| 190 | pub const SYS_mq_notify = 184; | |
| 191 | pub const SYS_mq_getsetattr = 185; | |
| 192 | pub const SYS_msgget = 186; | |
| 193 | pub const SYS_msgctl = 187; | |
| 194 | pub const SYS_msgrcv = 188; | |
| 195 | pub const SYS_msgsnd = 189; | |
| 196 | pub const SYS_semget = 190; | |
| 197 | pub const SYS_semctl = 191; | |
| 198 | pub const SYS_semtimedop = 192; | |
| 199 | pub const SYS_semop = 193; | |
| 200 | pub const SYS_shmget = 194; | |
| 201 | pub const SYS_shmctl = 195; | |
| 202 | pub const SYS_shmat = 196; | |
| 203 | pub const SYS_shmdt = 197; | |
| 204 | pub const SYS_socket = 198; | |
| 205 | pub const SYS_socketpair = 199; | |
| 206 | pub const SYS_bind = 200; | |
| 207 | pub const SYS_listen = 201; | |
| 208 | pub const SYS_accept = 202; | |
| 209 | pub const SYS_connect = 203; | |
| 210 | pub const SYS_getsockname = 204; | |
| 211 | pub const SYS_getpeername = 205; | |
| 212 | pub const SYS_sendto = 206; | |
| 213 | pub const SYS_recvfrom = 207; | |
| 214 | pub const SYS_setsockopt = 208; | |
| 215 | pub const SYS_getsockopt = 209; | |
| 216 | pub const SYS_shutdown = 210; | |
| 217 | pub const SYS_sendmsg = 211; | |
| 218 | pub const SYS_recvmsg = 212; | |
| 219 | pub const SYS_readahead = 213; | |
| 220 | pub const SYS_brk = 214; | |
| 221 | pub const SYS_munmap = 215; | |
| 222 | pub const SYS_mremap = 216; | |
| 223 | pub const SYS_add_key = 217; | |
| 224 | pub const SYS_request_key = 218; | |
| 225 | pub const SYS_keyctl = 219; | |
| 226 | pub const SYS_clone = 220; | |
| 227 | pub const SYS_execve = 221; | |
| 228 | pub const SYS_mmap = 222; | |
| 229 | pub const SYS_fadvise64 = 223; | |
| 230 | pub const SYS_swapon = 224; | |
| 231 | pub const SYS_swapoff = 225; | |
| 232 | pub const SYS_mprotect = 226; | |
| 233 | pub const SYS_msync = 227; | |
| 234 | pub const SYS_mlock = 228; | |
| 235 | pub const SYS_munlock = 229; | |
| 236 | pub const SYS_mlockall = 230; | |
| 237 | pub const SYS_munlockall = 231; | |
| 238 | pub const SYS_mincore = 232; | |
| 239 | pub const SYS_madvise = 233; | |
| 240 | pub const SYS_remap_file_pages = 234; | |
| 241 | pub const SYS_mbind = 235; | |
| 242 | pub const SYS_get_mempolicy = 236; | |
| 243 | pub const SYS_set_mempolicy = 237; | |
| 244 | pub const SYS_migrate_pages = 238; | |
| 245 | pub const SYS_move_pages = 239; | |
| 246 | pub const SYS_rt_tgsigqueueinfo = 240; | |
| 247 | pub const SYS_perf_event_open = 241; | |
| 248 | pub const SYS_accept4 = 242; | |
| 249 | pub const SYS_recvmmsg = 243; | |
| 7 | pub const SYS = extern enum(usize) { | |
| 8 | io_setup = 0, | |
| 9 | io_destroy = 1, | |
| 10 | io_submit = 2, | |
| 11 | io_cancel = 3, | |
| 12 | io_getevents = 4, | |
| 13 | setxattr = 5, | |
| 14 | lsetxattr = 6, | |
| 15 | fsetxattr = 7, | |
| 16 | getxattr = 8, | |
| 17 | lgetxattr = 9, | |
| 18 | fgetxattr = 10, | |
| 19 | listxattr = 11, | |
| 20 | llistxattr = 12, | |
| 21 | flistxattr = 13, | |
| 22 | removexattr = 14, | |
| 23 | lremovexattr = 15, | |
| 24 | fremovexattr = 16, | |
| 25 | getcwd = 17, | |
| 26 | lookup_dcookie = 18, | |
| 27 | eventfd2 = 19, | |
| 28 | epoll_create1 = 20, | |
| 29 | epoll_ctl = 21, | |
| 30 | epoll_pwait = 22, | |
| 31 | dup = 23, | |
| 32 | dup3 = 24, | |
| 33 | fcntl = 25, | |
| 34 | inotify_init1 = 26, | |
| 35 | inotify_add_watch = 27, | |
| 36 | inotify_rm_watch = 28, | |
| 37 | ioctl = 29, | |
| 38 | ioprio_set = 30, | |
| 39 | ioprio_get = 31, | |
| 40 | flock = 32, | |
| 41 | mknodat = 33, | |
| 42 | mkdirat = 34, | |
| 43 | unlinkat = 35, | |
| 44 | symlinkat = 36, | |
| 45 | linkat = 37, | |
| 46 | umount2 = 39, | |
| 47 | mount = 40, | |
| 48 | pivot_root = 41, | |
| 49 | nfsservctl = 42, | |
| 50 | statfs = 43, | |
| 51 | fstatfs = 44, | |
| 52 | truncate = 45, | |
| 53 | ftruncate = 46, | |
| 54 | fallocate = 47, | |
| 55 | faccessat = 48, | |
| 56 | chdir = 49, | |
| 57 | fchdir = 50, | |
| 58 | chroot = 51, | |
| 59 | fchmod = 52, | |
| 60 | fchmodat = 53, | |
| 61 | fchownat = 54, | |
| 62 | fchown = 55, | |
| 63 | openat = 56, | |
| 64 | close = 57, | |
| 65 | vhangup = 58, | |
| 66 | pipe2 = 59, | |
| 67 | quotactl = 60, | |
| 68 | getdents64 = 61, | |
| 69 | lseek = 62, | |
| 70 | read = 63, | |
| 71 | write = 64, | |
| 72 | readv = 65, | |
| 73 | writev = 66, | |
| 74 | pread64 = 67, | |
| 75 | pwrite64 = 68, | |
| 76 | preadv = 69, | |
| 77 | pwritev = 70, | |
| 78 | sendfile = 71, | |
| 79 | pselect6 = 72, | |
| 80 | ppoll = 73, | |
| 81 | signalfd4 = 74, | |
| 82 | vmsplice = 75, | |
| 83 | splice = 76, | |
| 84 | tee = 77, | |
| 85 | readlinkat = 78, | |
| 86 | fstatat = 79, | |
| 87 | fstat = 80, | |
| 88 | sync = 81, | |
| 89 | fsync = 82, | |
| 90 | fdatasync = 83, | |
| 91 | sync_file_range = 84, | |
| 92 | timerfd_create = 85, | |
| 93 | timerfd_settime = 86, | |
| 94 | timerfd_gettime = 87, | |
| 95 | utimensat = 88, | |
| 96 | acct = 89, | |
| 97 | capget = 90, | |
| 98 | capset = 91, | |
| 99 | personality = 92, | |
| 100 | exit = 93, | |
| 101 | exit_group = 94, | |
| 102 | waitid = 95, | |
| 103 | set_tid_address = 96, | |
| 104 | unshare = 97, | |
| 105 | futex = 98, | |
| 106 | set_robust_list = 99, | |
| 107 | get_robust_list = 100, | |
| 108 | nanosleep = 101, | |
| 109 | getitimer = 102, | |
| 110 | setitimer = 103, | |
| 111 | kexec_load = 104, | |
| 112 | init_module = 105, | |
| 113 | delete_module = 106, | |
| 114 | timer_create = 107, | |
| 115 | timer_gettime = 108, | |
| 116 | timer_getoverrun = 109, | |
| 117 | timer_settime = 110, | |
| 118 | timer_delete = 111, | |
| 119 | clock_settime = 112, | |
| 120 | clock_gettime = 113, | |
| 121 | clock_getres = 114, | |
| 122 | clock_nanosleep = 115, | |
| 123 | syslog = 116, | |
| 124 | ptrace = 117, | |
| 125 | sched_setparam = 118, | |
| 126 | sched_setscheduler = 119, | |
| 127 | sched_getscheduler = 120, | |
| 128 | sched_getparam = 121, | |
| 129 | sched_setaffinity = 122, | |
| 130 | sched_getaffinity = 123, | |
| 131 | sched_yield = 124, | |
| 132 | sched_get_priority_max = 125, | |
| 133 | sched_get_priority_min = 126, | |
| 134 | sched_rr_get_interval = 127, | |
| 135 | restart_syscall = 128, | |
| 136 | kill = 129, | |
| 137 | tkill = 130, | |
| 138 | tgkill = 131, | |
| 139 | sigaltstack = 132, | |
| 140 | rt_sigsuspend = 133, | |
| 141 | rt_sigaction = 134, | |
| 142 | rt_sigprocmask = 135, | |
| 143 | rt_sigpending = 136, | |
| 144 | rt_sigtimedwait = 137, | |
| 145 | rt_sigqueueinfo = 138, | |
| 146 | rt_sigreturn = 139, | |
| 147 | setpriority = 140, | |
| 148 | getpriority = 141, | |
| 149 | reboot = 142, | |
| 150 | setregid = 143, | |
| 151 | setgid = 144, | |
| 152 | setreuid = 145, | |
| 153 | setuid = 146, | |
| 154 | setresuid = 147, | |
| 155 | getresuid = 148, | |
| 156 | setresgid = 149, | |
| 157 | getresgid = 150, | |
| 158 | setfsuid = 151, | |
| 159 | setfsgid = 152, | |
| 160 | times = 153, | |
| 161 | setpgid = 154, | |
| 162 | getpgid = 155, | |
| 163 | getsid = 156, | |
| 164 | setsid = 157, | |
| 165 | getgroups = 158, | |
| 166 | setgroups = 159, | |
| 167 | uname = 160, | |
| 168 | sethostname = 161, | |
| 169 | setdomainname = 162, | |
| 170 | getrlimit = 163, | |
| 171 | setrlimit = 164, | |
| 172 | getrusage = 165, | |
| 173 | umask = 166, | |
| 174 | prctl = 167, | |
| 175 | getcpu = 168, | |
| 176 | gettimeofday = 169, | |
| 177 | settimeofday = 170, | |
| 178 | adjtimex = 171, | |
| 179 | getpid = 172, | |
| 180 | getppid = 173, | |
| 181 | getuid = 174, | |
| 182 | geteuid = 175, | |
| 183 | getgid = 176, | |
| 184 | getegid = 177, | |
| 185 | gettid = 178, | |
| 186 | sysinfo = 179, | |
| 187 | mq_open = 180, | |
| 188 | mq_unlink = 181, | |
| 189 | mq_timedsend = 182, | |
| 190 | mq_timedreceive = 183, | |
| 191 | mq_notify = 184, | |
| 192 | mq_getsetattr = 185, | |
| 193 | msgget = 186, | |
| 194 | msgctl = 187, | |
| 195 | msgrcv = 188, | |
| 196 | msgsnd = 189, | |
| 197 | semget = 190, | |
| 198 | semctl = 191, | |
| 199 | semtimedop = 192, | |
| 200 | semop = 193, | |
| 201 | shmget = 194, | |
| 202 | shmctl = 195, | |
| 203 | shmat = 196, | |
| 204 | shmdt = 197, | |
| 205 | socket = 198, | |
| 206 | socketpair = 199, | |
| 207 | bind = 200, | |
| 208 | listen = 201, | |
| 209 | accept = 202, | |
| 210 | connect = 203, | |
| 211 | getsockname = 204, | |
| 212 | getpeername = 205, | |
| 213 | sendto = 206, | |
| 214 | recvfrom = 207, | |
| 215 | setsockopt = 208, | |
| 216 | getsockopt = 209, | |
| 217 | shutdown = 210, | |
| 218 | sendmsg = 211, | |
| 219 | recvmsg = 212, | |
| 220 | readahead = 213, | |
| 221 | brk = 214, | |
| 222 | munmap = 215, | |
| 223 | mremap = 216, | |
| 224 | add_key = 217, | |
| 225 | request_key = 218, | |
| 226 | keyctl = 219, | |
| 227 | clone = 220, | |
| 228 | execve = 221, | |
| 229 | mmap = 222, | |
| 230 | fadvise64 = 223, | |
| 231 | swapon = 224, | |
| 232 | swapoff = 225, | |
| 233 | mprotect = 226, | |
| 234 | msync = 227, | |
| 235 | mlock = 228, | |
| 236 | munlock = 229, | |
| 237 | mlockall = 230, | |
| 238 | munlockall = 231, | |
| 239 | mincore = 232, | |
| 240 | madvise = 233, | |
| 241 | remap_file_pages = 234, | |
| 242 | mbind = 235, | |
| 243 | get_mempolicy = 236, | |
| 244 | set_mempolicy = 237, | |
| 245 | migrate_pages = 238, | |
| 246 | move_pages = 239, | |
| 247 | rt_tgsigqueueinfo = 240, | |
| 248 | perf_event_open = 241, | |
| 249 | accept4 = 242, | |
| 250 | recvmmsg = 243, | |
| 250 | 251 | |
| 251 | pub const SYS_arch_specific_syscall = 244; | |
| 252 | pub const SYS_riscv_flush_icache = SYS_arch_specific_syscall + 15; | |
| 252 | pub const arch_specific_syscall = 244; | |
| 253 | riscv_flush_icache = arch_specific_syscall + 15, | |
| 253 | 254 | |
| 254 | pub const SYS_wait4 = 260; | |
| 255 | pub const SYS_prlimit64 = 261; | |
| 256 | pub const SYS_fanotify_init = 262; | |
| 257 | pub const SYS_fanotify_mark = 263; | |
| 258 | pub const SYS_name_to_handle_at = 264; | |
| 259 | pub const SYS_open_by_handle_at = 265; | |
| 260 | pub const SYS_clock_adjtime = 266; | |
| 261 | pub const SYS_syncfs = 267; | |
| 262 | pub const SYS_setns = 268; | |
| 263 | pub const SYS_sendmmsg = 269; | |
| 264 | pub const SYS_process_vm_readv = 270; | |
| 265 | pub const SYS_process_vm_writev = 271; | |
| 266 | pub const SYS_kcmp = 272; | |
| 267 | pub const SYS_finit_module = 273; | |
| 268 | pub const SYS_sched_setattr = 274; | |
| 269 | pub const SYS_sched_getattr = 275; | |
| 270 | pub const SYS_renameat2 = 276; | |
| 271 | pub const SYS_seccomp = 277; | |
| 272 | pub const SYS_getrandom = 278; | |
| 273 | pub const SYS_memfd_create = 279; | |
| 274 | pub const SYS_bpf = 280; | |
| 275 | pub const SYS_execveat = 281; | |
| 276 | pub const SYS_userfaultfd = 282; | |
| 277 | pub const SYS_membarrier = 283; | |
| 278 | pub const SYS_mlock2 = 284; | |
| 279 | pub const SYS_copy_file_range = 285; | |
| 280 | pub const SYS_preadv2 = 286; | |
| 281 | pub const SYS_pwritev2 = 287; | |
| 282 | pub const SYS_pkey_mprotect = 288; | |
| 283 | pub const SYS_pkey_alloc = 289; | |
| 284 | pub const SYS_pkey_free = 290; | |
| 285 | pub const SYS_statx = 291; | |
| 286 | pub const SYS_io_pgetevents = 292; | |
| 287 | pub const SYS_rseq = 293; | |
| 288 | pub const SYS_kexec_file_load = 294; | |
| 289 | pub const SYS_pidfd_send_signal = 424; | |
| 290 | pub const SYS_io_uring_setup = 425; | |
| 291 | pub const SYS_io_uring_enter = 426; | |
| 292 | pub const SYS_io_uring_register = 427; | |
| 293 | pub const SYS_open_tree = 428; | |
| 294 | pub const SYS_move_mount = 429; | |
| 295 | pub const SYS_fsopen = 430; | |
| 296 | pub const SYS_fsconfig = 431; | |
| 297 | pub const SYS_fsmount = 432; | |
| 298 | pub const SYS_fspick = 433; | |
| 299 | pub const SYS_pidfd_open = 434; | |
| 300 | pub const SYS_clone3 = 435; | |
| 255 | wait4 = 260, | |
| 256 | prlimit64 = 261, | |
| 257 | fanotify_init = 262, | |
| 258 | fanotify_mark = 263, | |
| 259 | name_to_handle_at = 264, | |
| 260 | open_by_handle_at = 265, | |
| 261 | clock_adjtime = 266, | |
| 262 | syncfs = 267, | |
| 263 | setns = 268, | |
| 264 | sendmmsg = 269, | |
| 265 | process_vm_readv = 270, | |
| 266 | process_vm_writev = 271, | |
| 267 | kcmp = 272, | |
| 268 | finit_module = 273, | |
| 269 | sched_setattr = 274, | |
| 270 | sched_getattr = 275, | |
| 271 | renameat2 = 276, | |
| 272 | seccomp = 277, | |
| 273 | getrandom = 278, | |
| 274 | memfd_create = 279, | |
| 275 | bpf = 280, | |
| 276 | execveat = 281, | |
| 277 | userfaultfd = 282, | |
| 278 | membarrier = 283, | |
| 279 | mlock2 = 284, | |
| 280 | copy_file_range = 285, | |
| 281 | preadv2 = 286, | |
| 282 | pwritev2 = 287, | |
| 283 | pkey_mprotect = 288, | |
| 284 | pkey_alloc = 289, | |
| 285 | pkey_free = 290, | |
| 286 | statx = 291, | |
| 287 | io_pgetevents = 292, | |
| 288 | rseq = 293, | |
| 289 | kexec_file_load = 294, | |
| 290 | pidfd_send_signal = 424, | |
| 291 | io_uring_setup = 425, | |
| 292 | io_uring_enter = 426, | |
| 293 | io_uring_register = 427, | |
| 294 | open_tree = 428, | |
| 295 | move_mount = 429, | |
| 296 | fsopen = 430, | |
| 297 | fsconfig = 431, | |
| 298 | fsmount = 432, | |
| 299 | fspick = 433, | |
| 300 | pidfd_open = 434, | |
| 301 | clone3 = 435, | |
| 302 | openat2 = 437, | |
| 303 | pidfd_getfd = 438, | |
| 304 | ||
| 305 | _, | |
| 306 | }; | |
| 301 | 307 | |
| 302 | 308 | pub const O_CREAT = 0o100; |
| 303 | 309 | pub const O_EXCL = 0o200; |
lib/std/os/bits/linux/x86_64.zig+354-348| ... | ... | @@ -14,354 +14,360 @@ const iovec_const = linux.iovec_const; |
| 14 | 14 | |
| 15 | 15 | pub const mode_t = usize; |
| 16 | 16 | |
| 17 | pub const SYS_read = 0; | |
| 18 | pub const SYS_write = 1; | |
| 19 | pub const SYS_open = 2; | |
| 20 | pub const SYS_close = 3; | |
| 21 | pub const SYS_stat = 4; | |
| 22 | pub const SYS_fstat = 5; | |
| 23 | pub const SYS_lstat = 6; | |
| 24 | pub const SYS_poll = 7; | |
| 25 | pub const SYS_lseek = 8; | |
| 26 | pub const SYS_mmap = 9; | |
| 27 | pub const SYS_mprotect = 10; | |
| 28 | pub const SYS_munmap = 11; | |
| 29 | pub const SYS_brk = 12; | |
| 30 | pub const SYS_rt_sigaction = 13; | |
| 31 | pub const SYS_rt_sigprocmask = 14; | |
| 32 | pub const SYS_rt_sigreturn = 15; | |
| 33 | pub const SYS_ioctl = 16; | |
| 34 | pub const SYS_pread = 17; | |
| 35 | pub const SYS_pwrite = 18; | |
| 36 | pub const SYS_readv = 19; | |
| 37 | pub const SYS_writev = 20; | |
| 38 | pub const SYS_access = 21; | |
| 39 | pub const SYS_pipe = 22; | |
| 40 | pub const SYS_select = 23; | |
| 41 | pub const SYS_sched_yield = 24; | |
| 42 | pub const SYS_mremap = 25; | |
| 43 | pub const SYS_msync = 26; | |
| 44 | pub const SYS_mincore = 27; | |
| 45 | pub const SYS_madvise = 28; | |
| 46 | pub const SYS_shmget = 29; | |
| 47 | pub const SYS_shmat = 30; | |
| 48 | pub const SYS_shmctl = 31; | |
| 49 | pub const SYS_dup = 32; | |
| 50 | pub const SYS_dup2 = 33; | |
| 51 | pub const SYS_pause = 34; | |
| 52 | pub const SYS_nanosleep = 35; | |
| 53 | pub const SYS_getitimer = 36; | |
| 54 | pub const SYS_alarm = 37; | |
| 55 | pub const SYS_setitimer = 38; | |
| 56 | pub const SYS_getpid = 39; | |
| 57 | pub const SYS_sendfile = 40; | |
| 58 | pub const SYS_socket = 41; | |
| 59 | pub const SYS_connect = 42; | |
| 60 | pub const SYS_accept = 43; | |
| 61 | pub const SYS_sendto = 44; | |
| 62 | pub const SYS_recvfrom = 45; | |
| 63 | pub const SYS_sendmsg = 46; | |
| 64 | pub const SYS_recvmsg = 47; | |
| 65 | pub const SYS_shutdown = 48; | |
| 66 | pub const SYS_bind = 49; | |
| 67 | pub const SYS_listen = 50; | |
| 68 | pub const SYS_getsockname = 51; | |
| 69 | pub const SYS_getpeername = 52; | |
| 70 | pub const SYS_socketpair = 53; | |
| 71 | pub const SYS_setsockopt = 54; | |
| 72 | pub const SYS_getsockopt = 55; | |
| 73 | pub const SYS_clone = 56; | |
| 74 | pub const SYS_fork = 57; | |
| 75 | pub const SYS_vfork = 58; | |
| 76 | pub const SYS_execve = 59; | |
| 77 | pub const SYS_exit = 60; | |
| 78 | pub const SYS_wait4 = 61; | |
| 79 | pub const SYS_kill = 62; | |
| 80 | pub const SYS_uname = 63; | |
| 81 | pub const SYS_semget = 64; | |
| 82 | pub const SYS_semop = 65; | |
| 83 | pub const SYS_semctl = 66; | |
| 84 | pub const SYS_shmdt = 67; | |
| 85 | pub const SYS_msgget = 68; | |
| 86 | pub const SYS_msgsnd = 69; | |
| 87 | pub const SYS_msgrcv = 70; | |
| 88 | pub const SYS_msgctl = 71; | |
| 89 | pub const SYS_fcntl = 72; | |
| 90 | pub const SYS_flock = 73; | |
| 91 | pub const SYS_fsync = 74; | |
| 92 | pub const SYS_fdatasync = 75; | |
| 93 | pub const SYS_truncate = 76; | |
| 94 | pub const SYS_ftruncate = 77; | |
| 95 | pub const SYS_getdents = 78; | |
| 96 | pub const SYS_getcwd = 79; | |
| 97 | pub const SYS_chdir = 80; | |
| 98 | pub const SYS_fchdir = 81; | |
| 99 | pub const SYS_rename = 82; | |
| 100 | pub const SYS_mkdir = 83; | |
| 101 | pub const SYS_rmdir = 84; | |
| 102 | pub const SYS_creat = 85; | |
| 103 | pub const SYS_link = 86; | |
| 104 | pub const SYS_unlink = 87; | |
| 105 | pub const SYS_symlink = 88; | |
| 106 | pub const SYS_readlink = 89; | |
| 107 | pub const SYS_chmod = 90; | |
| 108 | pub const SYS_fchmod = 91; | |
| 109 | pub const SYS_chown = 92; | |
| 110 | pub const SYS_fchown = 93; | |
| 111 | pub const SYS_lchown = 94; | |
| 112 | pub const SYS_umask = 95; | |
| 113 | pub const SYS_gettimeofday = 96; | |
| 114 | pub const SYS_getrlimit = 97; | |
| 115 | pub const SYS_getrusage = 98; | |
| 116 | pub const SYS_sysinfo = 99; | |
| 117 | pub const SYS_times = 100; | |
| 118 | pub const SYS_ptrace = 101; | |
| 119 | pub const SYS_getuid = 102; | |
| 120 | pub const SYS_syslog = 103; | |
| 121 | pub const SYS_getgid = 104; | |
| 122 | pub const SYS_setuid = 105; | |
| 123 | pub const SYS_setgid = 106; | |
| 124 | pub const SYS_geteuid = 107; | |
| 125 | pub const SYS_getegid = 108; | |
| 126 | pub const SYS_setpgid = 109; | |
| 127 | pub const SYS_getppid = 110; | |
| 128 | pub const SYS_getpgrp = 111; | |
| 129 | pub const SYS_setsid = 112; | |
| 130 | pub const SYS_setreuid = 113; | |
| 131 | pub const SYS_setregid = 114; | |
| 132 | pub const SYS_getgroups = 115; | |
| 133 | pub const SYS_setgroups = 116; | |
| 134 | pub const SYS_setresuid = 117; | |
| 135 | pub const SYS_getresuid = 118; | |
| 136 | pub const SYS_setresgid = 119; | |
| 137 | pub const SYS_getresgid = 120; | |
| 138 | pub const SYS_getpgid = 121; | |
| 139 | pub const SYS_setfsuid = 122; | |
| 140 | pub const SYS_setfsgid = 123; | |
| 141 | pub const SYS_getsid = 124; | |
| 142 | pub const SYS_capget = 125; | |
| 143 | pub const SYS_capset = 126; | |
| 144 | pub const SYS_rt_sigpending = 127; | |
| 145 | pub const SYS_rt_sigtimedwait = 128; | |
| 146 | pub const SYS_rt_sigqueueinfo = 129; | |
| 147 | pub const SYS_rt_sigsuspend = 130; | |
| 148 | pub const SYS_sigaltstack = 131; | |
| 149 | pub const SYS_utime = 132; | |
| 150 | pub const SYS_mknod = 133; | |
| 151 | pub const SYS_uselib = 134; | |
| 152 | pub const SYS_personality = 135; | |
| 153 | pub const SYS_ustat = 136; | |
| 154 | pub const SYS_statfs = 137; | |
| 155 | pub const SYS_fstatfs = 138; | |
| 156 | pub const SYS_sysfs = 139; | |
| 157 | pub const SYS_getpriority = 140; | |
| 158 | pub const SYS_setpriority = 141; | |
| 159 | pub const SYS_sched_setparam = 142; | |
| 160 | pub const SYS_sched_getparam = 143; | |
| 161 | pub const SYS_sched_setscheduler = 144; | |
| 162 | pub const SYS_sched_getscheduler = 145; | |
| 163 | pub const SYS_sched_get_priority_max = 146; | |
| 164 | pub const SYS_sched_get_priority_min = 147; | |
| 165 | pub const SYS_sched_rr_get_interval = 148; | |
| 166 | pub const SYS_mlock = 149; | |
| 167 | pub const SYS_munlock = 150; | |
| 168 | pub const SYS_mlockall = 151; | |
| 169 | pub const SYS_munlockall = 152; | |
| 170 | pub const SYS_vhangup = 153; | |
| 171 | pub const SYS_modify_ldt = 154; | |
| 172 | pub const SYS_pivot_root = 155; | |
| 173 | pub const SYS__sysctl = 156; | |
| 174 | pub const SYS_prctl = 157; | |
| 175 | pub const SYS_arch_prctl = 158; | |
| 176 | pub const SYS_adjtimex = 159; | |
| 177 | pub const SYS_setrlimit = 160; | |
| 178 | pub const SYS_chroot = 161; | |
| 179 | pub const SYS_sync = 162; | |
| 180 | pub const SYS_acct = 163; | |
| 181 | pub const SYS_settimeofday = 164; | |
| 182 | pub const SYS_mount = 165; | |
| 183 | pub const SYS_umount2 = 166; | |
| 184 | pub const SYS_swapon = 167; | |
| 185 | pub const SYS_swapoff = 168; | |
| 186 | pub const SYS_reboot = 169; | |
| 187 | pub const SYS_sethostname = 170; | |
| 188 | pub const SYS_setdomainname = 171; | |
| 189 | pub const SYS_iopl = 172; | |
| 190 | pub const SYS_ioperm = 173; | |
| 191 | pub const SYS_create_module = 174; | |
| 192 | pub const SYS_init_module = 175; | |
| 193 | pub const SYS_delete_module = 176; | |
| 194 | pub const SYS_get_kernel_syms = 177; | |
| 195 | pub const SYS_query_module = 178; | |
| 196 | pub const SYS_quotactl = 179; | |
| 197 | pub const SYS_nfsservctl = 180; | |
| 198 | pub const SYS_getpmsg = 181; | |
| 199 | pub const SYS_putpmsg = 182; | |
| 200 | pub const SYS_afs_syscall = 183; | |
| 201 | pub const SYS_tuxcall = 184; | |
| 202 | pub const SYS_security = 185; | |
| 203 | pub const SYS_gettid = 186; | |
| 204 | pub const SYS_readahead = 187; | |
| 205 | pub const SYS_setxattr = 188; | |
| 206 | pub const SYS_lsetxattr = 189; | |
| 207 | pub const SYS_fsetxattr = 190; | |
| 208 | pub const SYS_getxattr = 191; | |
| 209 | pub const SYS_lgetxattr = 192; | |
| 210 | pub const SYS_fgetxattr = 193; | |
| 211 | pub const SYS_listxattr = 194; | |
| 212 | pub const SYS_llistxattr = 195; | |
| 213 | pub const SYS_flistxattr = 196; | |
| 214 | pub const SYS_removexattr = 197; | |
| 215 | pub const SYS_lremovexattr = 198; | |
| 216 | pub const SYS_fremovexattr = 199; | |
| 217 | pub const SYS_tkill = 200; | |
| 218 | pub const SYS_time = 201; | |
| 219 | pub const SYS_futex = 202; | |
| 220 | pub const SYS_sched_setaffinity = 203; | |
| 221 | pub const SYS_sched_getaffinity = 204; | |
| 222 | pub const SYS_set_thread_area = 205; | |
| 223 | pub const SYS_io_setup = 206; | |
| 224 | pub const SYS_io_destroy = 207; | |
| 225 | pub const SYS_io_getevents = 208; | |
| 226 | pub const SYS_io_submit = 209; | |
| 227 | pub const SYS_io_cancel = 210; | |
| 228 | pub const SYS_get_thread_area = 211; | |
| 229 | pub const SYS_lookup_dcookie = 212; | |
| 230 | pub const SYS_epoll_create = 213; | |
| 231 | pub const SYS_epoll_ctl_old = 214; | |
| 232 | pub const SYS_epoll_wait_old = 215; | |
| 233 | pub const SYS_remap_file_pages = 216; | |
| 234 | pub const SYS_getdents64 = 217; | |
| 235 | pub const SYS_set_tid_address = 218; | |
| 236 | pub const SYS_restart_syscall = 219; | |
| 237 | pub const SYS_semtimedop = 220; | |
| 238 | pub const SYS_fadvise64 = 221; | |
| 239 | pub const SYS_timer_create = 222; | |
| 240 | pub const SYS_timer_settime = 223; | |
| 241 | pub const SYS_timer_gettime = 224; | |
| 242 | pub const SYS_timer_getoverrun = 225; | |
| 243 | pub const SYS_timer_delete = 226; | |
| 244 | pub const SYS_clock_settime = 227; | |
| 245 | pub const SYS_clock_gettime = 228; | |
| 246 | pub const SYS_clock_getres = 229; | |
| 247 | pub const SYS_clock_nanosleep = 230; | |
| 248 | pub const SYS_exit_group = 231; | |
| 249 | pub const SYS_epoll_wait = 232; | |
| 250 | pub const SYS_epoll_ctl = 233; | |
| 251 | pub const SYS_tgkill = 234; | |
| 252 | pub const SYS_utimes = 235; | |
| 253 | pub const SYS_vserver = 236; | |
| 254 | pub const SYS_mbind = 237; | |
| 255 | pub const SYS_set_mempolicy = 238; | |
| 256 | pub const SYS_get_mempolicy = 239; | |
| 257 | pub const SYS_mq_open = 240; | |
| 258 | pub const SYS_mq_unlink = 241; | |
| 259 | pub const SYS_mq_timedsend = 242; | |
| 260 | pub const SYS_mq_timedreceive = 243; | |
| 261 | pub const SYS_mq_notify = 244; | |
| 262 | pub const SYS_mq_getsetattr = 245; | |
| 263 | pub const SYS_kexec_load = 246; | |
| 264 | pub const SYS_waitid = 247; | |
| 265 | pub const SYS_add_key = 248; | |
| 266 | pub const SYS_request_key = 249; | |
| 267 | pub const SYS_keyctl = 250; | |
| 268 | pub const SYS_ioprio_set = 251; | |
| 269 | pub const SYS_ioprio_get = 252; | |
| 270 | pub const SYS_inotify_init = 253; | |
| 271 | pub const SYS_inotify_add_watch = 254; | |
| 272 | pub const SYS_inotify_rm_watch = 255; | |
| 273 | pub const SYS_migrate_pages = 256; | |
| 274 | pub const SYS_openat = 257; | |
| 275 | pub const SYS_mkdirat = 258; | |
| 276 | pub const SYS_mknodat = 259; | |
| 277 | pub const SYS_fchownat = 260; | |
| 278 | pub const SYS_futimesat = 261; | |
| 279 | pub const SYS_newfstatat = 262; | |
| 280 | pub const SYS_fstatat = 262; | |
| 281 | pub const SYS_unlinkat = 263; | |
| 282 | pub const SYS_renameat = 264; | |
| 283 | pub const SYS_linkat = 265; | |
| 284 | pub const SYS_symlinkat = 266; | |
| 285 | pub const SYS_readlinkat = 267; | |
| 286 | pub const SYS_fchmodat = 268; | |
| 287 | pub const SYS_faccessat = 269; | |
| 288 | pub const SYS_pselect6 = 270; | |
| 289 | pub const SYS_ppoll = 271; | |
| 290 | pub const SYS_unshare = 272; | |
| 291 | pub const SYS_set_robust_list = 273; | |
| 292 | pub const SYS_get_robust_list = 274; | |
| 293 | pub const SYS_splice = 275; | |
| 294 | pub const SYS_tee = 276; | |
| 295 | pub const SYS_sync_file_range = 277; | |
| 296 | pub const SYS_vmsplice = 278; | |
| 297 | pub const SYS_move_pages = 279; | |
| 298 | pub const SYS_utimensat = 280; | |
| 299 | pub const SYS_epoll_pwait = 281; | |
| 300 | pub const SYS_signalfd = 282; | |
| 301 | pub const SYS_timerfd_create = 283; | |
| 302 | pub const SYS_eventfd = 284; | |
| 303 | pub const SYS_fallocate = 285; | |
| 304 | pub const SYS_timerfd_settime = 286; | |
| 305 | pub const SYS_timerfd_gettime = 287; | |
| 306 | pub const SYS_accept4 = 288; | |
| 307 | pub const SYS_signalfd4 = 289; | |
| 308 | pub const SYS_eventfd2 = 290; | |
| 309 | pub const SYS_epoll_create1 = 291; | |
| 310 | pub const SYS_dup3 = 292; | |
| 311 | pub const SYS_pipe2 = 293; | |
| 312 | pub const SYS_inotify_init1 = 294; | |
| 313 | pub const SYS_preadv = 295; | |
| 314 | pub const SYS_pwritev = 296; | |
| 315 | pub const SYS_rt_tgsigqueueinfo = 297; | |
| 316 | pub const SYS_perf_event_open = 298; | |
| 317 | pub const SYS_recvmmsg = 299; | |
| 318 | pub const SYS_fanotify_init = 300; | |
| 319 | pub const SYS_fanotify_mark = 301; | |
| 320 | pub const SYS_prlimit64 = 302; | |
| 321 | pub const SYS_name_to_handle_at = 303; | |
| 322 | pub const SYS_open_by_handle_at = 304; | |
| 323 | pub const SYS_clock_adjtime = 305; | |
| 324 | pub const SYS_syncfs = 306; | |
| 325 | pub const SYS_sendmmsg = 307; | |
| 326 | pub const SYS_setns = 308; | |
| 327 | pub const SYS_getcpu = 309; | |
| 328 | pub const SYS_process_vm_readv = 310; | |
| 329 | pub const SYS_process_vm_writev = 311; | |
| 330 | pub const SYS_kcmp = 312; | |
| 331 | pub const SYS_finit_module = 313; | |
| 332 | pub const SYS_sched_setattr = 314; | |
| 333 | pub const SYS_sched_getattr = 315; | |
| 334 | pub const SYS_renameat2 = 316; | |
| 335 | pub const SYS_seccomp = 317; | |
| 336 | pub const SYS_getrandom = 318; | |
| 337 | pub const SYS_memfd_create = 319; | |
| 338 | pub const SYS_kexec_file_load = 320; | |
| 339 | pub const SYS_bpf = 321; | |
| 340 | pub const SYS_execveat = 322; | |
| 341 | pub const SYS_userfaultfd = 323; | |
| 342 | pub const SYS_membarrier = 324; | |
| 343 | pub const SYS_mlock2 = 325; | |
| 344 | pub const SYS_copy_file_range = 326; | |
| 345 | pub const SYS_preadv2 = 327; | |
| 346 | pub const SYS_pwritev2 = 328; | |
| 347 | pub const SYS_pkey_mprotect = 329; | |
| 348 | pub const SYS_pkey_alloc = 330; | |
| 349 | pub const SYS_pkey_free = 331; | |
| 350 | pub const SYS_statx = 332; | |
| 351 | pub const SYS_io_pgetevents = 333; | |
| 352 | pub const SYS_rseq = 334; | |
| 353 | pub const SYS_pidfd_send_signal = 424; | |
| 354 | pub const SYS_io_uring_setup = 425; | |
| 355 | pub const SYS_io_uring_enter = 426; | |
| 356 | pub const SYS_io_uring_register = 427; | |
| 357 | pub const SYS_open_tree = 428; | |
| 358 | pub const SYS_move_mount = 429; | |
| 359 | pub const SYS_fsopen = 430; | |
| 360 | pub const SYS_fsconfig = 431; | |
| 361 | pub const SYS_fsmount = 432; | |
| 362 | pub const SYS_fspick = 433; | |
| 363 | pub const SYS_pidfd_open = 434; | |
| 364 | pub const SYS_clone3 = 435; | |
| 17 | pub const SYS = extern enum(usize) { | |
| 18 | read = 0, | |
| 19 | write = 1, | |
| 20 | open = 2, | |
| 21 | close = 3, | |
| 22 | stat = 4, | |
| 23 | fstat = 5, | |
| 24 | lstat = 6, | |
| 25 | poll = 7, | |
| 26 | lseek = 8, | |
| 27 | mmap = 9, | |
| 28 | mprotect = 10, | |
| 29 | munmap = 11, | |
| 30 | brk = 12, | |
| 31 | rt_sigaction = 13, | |
| 32 | rt_sigprocmask = 14, | |
| 33 | rt_sigreturn = 15, | |
| 34 | ioctl = 16, | |
| 35 | pread = 17, | |
| 36 | pwrite = 18, | |
| 37 | readv = 19, | |
| 38 | writev = 20, | |
| 39 | access = 21, | |
| 40 | pipe = 22, | |
| 41 | select = 23, | |
| 42 | sched_yield = 24, | |
| 43 | mremap = 25, | |
| 44 | msync = 26, | |
| 45 | mincore = 27, | |
| 46 | madvise = 28, | |
| 47 | shmget = 29, | |
| 48 | shmat = 30, | |
| 49 | shmctl = 31, | |
| 50 | dup = 32, | |
| 51 | dup2 = 33, | |
| 52 | pause = 34, | |
| 53 | nanosleep = 35, | |
| 54 | getitimer = 36, | |
| 55 | alarm = 37, | |
| 56 | setitimer = 38, | |
| 57 | getpid = 39, | |
| 58 | sendfile = 40, | |
| 59 | socket = 41, | |
| 60 | connect = 42, | |
| 61 | accept = 43, | |
| 62 | sendto = 44, | |
| 63 | recvfrom = 45, | |
| 64 | sendmsg = 46, | |
| 65 | recvmsg = 47, | |
| 66 | shutdown = 48, | |
| 67 | bind = 49, | |
| 68 | listen = 50, | |
| 69 | getsockname = 51, | |
| 70 | getpeername = 52, | |
| 71 | socketpair = 53, | |
| 72 | setsockopt = 54, | |
| 73 | getsockopt = 55, | |
| 74 | clone = 56, | |
| 75 | fork = 57, | |
| 76 | vfork = 58, | |
| 77 | execve = 59, | |
| 78 | exit = 60, | |
| 79 | wait4 = 61, | |
| 80 | kill = 62, | |
| 81 | uname = 63, | |
| 82 | semget = 64, | |
| 83 | semop = 65, | |
| 84 | semctl = 66, | |
| 85 | shmdt = 67, | |
| 86 | msgget = 68, | |
| 87 | msgsnd = 69, | |
| 88 | msgrcv = 70, | |
| 89 | msgctl = 71, | |
| 90 | fcntl = 72, | |
| 91 | flock = 73, | |
| 92 | fsync = 74, | |
| 93 | fdatasync = 75, | |
| 94 | truncate = 76, | |
| 95 | ftruncate = 77, | |
| 96 | getdents = 78, | |
| 97 | getcwd = 79, | |
| 98 | chdir = 80, | |
| 99 | fchdir = 81, | |
| 100 | rename = 82, | |
| 101 | mkdir = 83, | |
| 102 | rmdir = 84, | |
| 103 | creat = 85, | |
| 104 | link = 86, | |
| 105 | unlink = 87, | |
| 106 | symlink = 88, | |
| 107 | readlink = 89, | |
| 108 | chmod = 90, | |
| 109 | fchmod = 91, | |
| 110 | chown = 92, | |
| 111 | fchown = 93, | |
| 112 | lchown = 94, | |
| 113 | umask = 95, | |
| 114 | gettimeofday = 96, | |
| 115 | getrlimit = 97, | |
| 116 | getrusage = 98, | |
| 117 | sysinfo = 99, | |
| 118 | times = 100, | |
| 119 | ptrace = 101, | |
| 120 | getuid = 102, | |
| 121 | syslog = 103, | |
| 122 | getgid = 104, | |
| 123 | setuid = 105, | |
| 124 | setgid = 106, | |
| 125 | geteuid = 107, | |
| 126 | getegid = 108, | |
| 127 | setpgid = 109, | |
| 128 | getppid = 110, | |
| 129 | getpgrp = 111, | |
| 130 | setsid = 112, | |
| 131 | setreuid = 113, | |
| 132 | setregid = 114, | |
| 133 | getgroups = 115, | |
| 134 | setgroups = 116, | |
| 135 | setresuid = 117, | |
| 136 | getresuid = 118, | |
| 137 | setresgid = 119, | |
| 138 | getresgid = 120, | |
| 139 | getpgid = 121, | |
| 140 | setfsuid = 122, | |
| 141 | setfsgid = 123, | |
| 142 | getsid = 124, | |
| 143 | capget = 125, | |
| 144 | capset = 126, | |
| 145 | rt_sigpending = 127, | |
| 146 | rt_sigtimedwait = 128, | |
| 147 | rt_sigqueueinfo = 129, | |
| 148 | rt_sigsuspend = 130, | |
| 149 | sigaltstack = 131, | |
| 150 | utime = 132, | |
| 151 | mknod = 133, | |
| 152 | uselib = 134, | |
| 153 | personality = 135, | |
| 154 | ustat = 136, | |
| 155 | statfs = 137, | |
| 156 | fstatfs = 138, | |
| 157 | sysfs = 139, | |
| 158 | getpriority = 140, | |
| 159 | setpriority = 141, | |
| 160 | sched_setparam = 142, | |
| 161 | sched_getparam = 143, | |
| 162 | sched_setscheduler = 144, | |
| 163 | sched_getscheduler = 145, | |
| 164 | sched_get_priority_max = 146, | |
| 165 | sched_get_priority_min = 147, | |
| 166 | sched_rr_get_interval = 148, | |
| 167 | mlock = 149, | |
| 168 | munlock = 150, | |
| 169 | mlockall = 151, | |
| 170 | munlockall = 152, | |
| 171 | vhangup = 153, | |
| 172 | modify_ldt = 154, | |
| 173 | pivot_root = 155, | |
| 174 | _sysctl = 156, | |
| 175 | prctl = 157, | |
| 176 | arch_prctl = 158, | |
| 177 | adjtimex = 159, | |
| 178 | setrlimit = 160, | |
| 179 | chroot = 161, | |
| 180 | sync = 162, | |
| 181 | acct = 163, | |
| 182 | settimeofday = 164, | |
| 183 | mount = 165, | |
| 184 | umount2 = 166, | |
| 185 | swapon = 167, | |
| 186 | swapoff = 168, | |
| 187 | reboot = 169, | |
| 188 | sethostname = 170, | |
| 189 | setdomainname = 171, | |
| 190 | iopl = 172, | |
| 191 | ioperm = 173, | |
| 192 | create_module = 174, | |
| 193 | init_module = 175, | |
| 194 | delete_module = 176, | |
| 195 | get_kernel_syms = 177, | |
| 196 | query_module = 178, | |
| 197 | quotactl = 179, | |
| 198 | nfsservctl = 180, | |
| 199 | getpmsg = 181, | |
| 200 | putpmsg = 182, | |
| 201 | afs_syscall = 183, | |
| 202 | tuxcall = 184, | |
| 203 | security = 185, | |
| 204 | gettid = 186, | |
| 205 | readahead = 187, | |
| 206 | setxattr = 188, | |
| 207 | lsetxattr = 189, | |
| 208 | fsetxattr = 190, | |
| 209 | getxattr = 191, | |
| 210 | lgetxattr = 192, | |
| 211 | fgetxattr = 193, | |
| 212 | listxattr = 194, | |
| 213 | llistxattr = 195, | |
| 214 | flistxattr = 196, | |
| 215 | removexattr = 197, | |
| 216 | lremovexattr = 198, | |
| 217 | fremovexattr = 199, | |
| 218 | tkill = 200, | |
| 219 | time = 201, | |
| 220 | futex = 202, | |
| 221 | sched_setaffinity = 203, | |
| 222 | sched_getaffinity = 204, | |
| 223 | set_thread_area = 205, | |
| 224 | io_setup = 206, | |
| 225 | io_destroy = 207, | |
| 226 | io_getevents = 208, | |
| 227 | io_submit = 209, | |
| 228 | io_cancel = 210, | |
| 229 | get_thread_area = 211, | |
| 230 | lookup_dcookie = 212, | |
| 231 | epoll_create = 213, | |
| 232 | epoll_ctl_old = 214, | |
| 233 | epoll_wait_old = 215, | |
| 234 | remap_file_pages = 216, | |
| 235 | getdents64 = 217, | |
| 236 | set_tid_address = 218, | |
| 237 | restart_syscall = 219, | |
| 238 | semtimedop = 220, | |
| 239 | fadvise64 = 221, | |
| 240 | timer_create = 222, | |
| 241 | timer_settime = 223, | |
| 242 | timer_gettime = 224, | |
| 243 | timer_getoverrun = 225, | |
| 244 | timer_delete = 226, | |
| 245 | clock_settime = 227, | |
| 246 | clock_gettime = 228, | |
| 247 | clock_getres = 229, | |
| 248 | clock_nanosleep = 230, | |
| 249 | exit_group = 231, | |
| 250 | epoll_wait = 232, | |
| 251 | epoll_ctl = 233, | |
| 252 | tgkill = 234, | |
| 253 | utimes = 235, | |
| 254 | vserver = 236, | |
| 255 | mbind = 237, | |
| 256 | set_mempolicy = 238, | |
| 257 | get_mempolicy = 239, | |
| 258 | mq_open = 240, | |
| 259 | mq_unlink = 241, | |
| 260 | mq_timedsend = 242, | |
| 261 | mq_timedreceive = 243, | |
| 262 | mq_notify = 244, | |
| 263 | mq_getsetattr = 245, | |
| 264 | kexec_load = 246, | |
| 265 | waitid = 247, | |
| 266 | add_key = 248, | |
| 267 | request_key = 249, | |
| 268 | keyctl = 250, | |
| 269 | ioprio_set = 251, | |
| 270 | ioprio_get = 252, | |
| 271 | inotify_init = 253, | |
| 272 | inotify_add_watch = 254, | |
| 273 | inotify_rm_watch = 255, | |
| 274 | migrate_pages = 256, | |
| 275 | openat = 257, | |
| 276 | mkdirat = 258, | |
| 277 | mknodat = 259, | |
| 278 | fchownat = 260, | |
| 279 | futimesat = 261, | |
| 280 | newfstatat = 262, | |
| 281 | fstatat = 262, | |
| 282 | unlinkat = 263, | |
| 283 | renameat = 264, | |
| 284 | linkat = 265, | |
| 285 | symlinkat = 266, | |
| 286 | readlinkat = 267, | |
| 287 | fchmodat = 268, | |
| 288 | faccessat = 269, | |
| 289 | pselect6 = 270, | |
| 290 | ppoll = 271, | |
| 291 | unshare = 272, | |
| 292 | set_robust_list = 273, | |
| 293 | get_robust_list = 274, | |
| 294 | splice = 275, | |
| 295 | tee = 276, | |
| 296 | sync_file_range = 277, | |
| 297 | vmsplice = 278, | |
| 298 | move_pages = 279, | |
| 299 | utimensat = 280, | |
| 300 | epoll_pwait = 281, | |
| 301 | signalfd = 282, | |
| 302 | timerfd_create = 283, | |
| 303 | eventfd = 284, | |
| 304 | fallocate = 285, | |
| 305 | timerfd_settime = 286, | |
| 306 | timerfd_gettime = 287, | |
| 307 | accept4 = 288, | |
| 308 | signalfd4 = 289, | |
| 309 | eventfd2 = 290, | |
| 310 | epoll_create1 = 291, | |
| 311 | dup3 = 292, | |
| 312 | pipe2 = 293, | |
| 313 | inotify_init1 = 294, | |
| 314 | preadv = 295, | |
| 315 | pwritev = 296, | |
| 316 | rt_tgsigqueueinfo = 297, | |
| 317 | perf_event_open = 298, | |
| 318 | recvmmsg = 299, | |
| 319 | fanotify_init = 300, | |
| 320 | fanotify_mark = 301, | |
| 321 | prlimit64 = 302, | |
| 322 | name_to_handle_at = 303, | |
| 323 | open_by_handle_at = 304, | |
| 324 | clock_adjtime = 305, | |
| 325 | syncfs = 306, | |
| 326 | sendmmsg = 307, | |
| 327 | setns = 308, | |
| 328 | getcpu = 309, | |
| 329 | process_vm_readv = 310, | |
| 330 | process_vm_writev = 311, | |
| 331 | kcmp = 312, | |
| 332 | finit_module = 313, | |
| 333 | sched_setattr = 314, | |
| 334 | sched_getattr = 315, | |
| 335 | renameat2 = 316, | |
| 336 | seccomp = 317, | |
| 337 | getrandom = 318, | |
| 338 | memfd_create = 319, | |
| 339 | kexec_file_load = 320, | |
| 340 | bpf = 321, | |
| 341 | execveat = 322, | |
| 342 | userfaultfd = 323, | |
| 343 | membarrier = 324, | |
| 344 | mlock2 = 325, | |
| 345 | copy_file_range = 326, | |
| 346 | preadv2 = 327, | |
| 347 | pwritev2 = 328, | |
| 348 | pkey_mprotect = 329, | |
| 349 | pkey_alloc = 330, | |
| 350 | pkey_free = 331, | |
| 351 | statx = 332, | |
| 352 | io_pgetevents = 333, | |
| 353 | rseq = 334, | |
| 354 | pidfd_send_signal = 424, | |
| 355 | io_uring_setup = 425, | |
| 356 | io_uring_enter = 426, | |
| 357 | io_uring_register = 427, | |
| 358 | open_tree = 428, | |
| 359 | move_mount = 429, | |
| 360 | fsopen = 430, | |
| 361 | fsconfig = 431, | |
| 362 | fsmount = 432, | |
| 363 | fspick = 433, | |
| 364 | pidfd_open = 434, | |
| 365 | clone3 = 435, | |
| 366 | openat2 = 437, | |
| 367 | pidfd_getfd = 438, | |
| 368 | ||
| 369 | _, | |
| 370 | }; | |
| 365 | 371 | |
| 366 | 372 | pub const O_CREAT = 0o100; |
| 367 | 373 | pub const O_EXCL = 0o200; |
lib/std/os/bits/netbsd.zig+114-26| ... | ... | @@ -1,12 +1,22 @@ |
| 1 | 1 | const std = @import("../../std.zig"); |
| 2 | const builtin = std.builtin; | |
| 2 | 3 | const maxInt = std.math.maxInt; |
| 3 | 4 | |
| 5 | pub const blkcnt_t = i64; | |
| 6 | pub const blksize_t = i32; | |
| 7 | pub const clock_t = u32; | |
| 8 | pub const dev_t = u64; | |
| 4 | 9 | pub const fd_t = i32; |
| 5 | pub const pid_t = i32; | |
| 6 | pub const mode_t = u32; | |
| 10 | pub const gid_t = u32; | |
| 7 | 11 | pub const ino_t = u64; |
| 12 | pub const mode_t = u32; | |
| 13 | pub const nlink_t = u32; | |
| 8 | 14 | pub const off_t = i64; |
| 15 | pub const pid_t = i32; | |
| 9 | 16 | pub const socklen_t = u32; |
| 17 | pub const time_t = i64; | |
| 18 | pub const uid_t = u32; | |
| 19 | pub const lwpid_t = i32; | |
| 10 | 20 | |
| 11 | 21 | /// Renamed from `kevent` to `Kevent` to avoid conflict with function name. |
| 12 | 22 | pub const Kevent = extern struct { |
| ... | ... | @@ -145,23 +155,20 @@ pub const msghdr_const = extern struct { |
| 145 | 155 | /// in C, macros are used to hide the differences. Here we use |
| 146 | 156 | /// methods to accomplish this. |
| 147 | 157 | pub const Stat = extern struct { |
| 148 | dev: u64, | |
| 149 | mode: u32, | |
| 158 | dev: dev_t, | |
| 159 | mode: mode_t, | |
| 150 | 160 | ino: ino_t, |
| 151 | nlink: usize, | |
| 152 | ||
| 153 | uid: u32, | |
| 154 | gid: u32, | |
| 155 | rdev: u64, | |
| 156 | ||
| 161 | nlink: nlink_t, | |
| 162 | uid: uid_t, | |
| 163 | gid: gid_t, | |
| 164 | rdev: dev_t, | |
| 157 | 165 | atim: timespec, |
| 158 | 166 | mtim: timespec, |
| 159 | 167 | ctim: timespec, |
| 160 | 168 | birthtim: timespec, |
| 161 | ||
| 162 | 169 | size: off_t, |
| 163 | blocks: i64, | |
| 164 | blksize: isize, | |
| 170 | blocks: blkcnt_t, | |
| 171 | blksize: blksize_t, | |
| 165 | 172 | flags: u32, |
| 166 | 173 | gen: u32, |
| 167 | 174 | __spare: [2]u32, |
| ... | ... | @@ -184,12 +191,14 @@ pub const timespec = extern struct { |
| 184 | 191 | tv_nsec: isize, |
| 185 | 192 | }; |
| 186 | 193 | |
| 194 | pub const MAXNAMLEN = 511; | |
| 195 | ||
| 187 | 196 | pub const dirent = extern struct { |
| 188 | d_fileno: u64, | |
| 197 | d_fileno: ino_t, | |
| 189 | 198 | d_reclen: u16, |
| 190 | 199 | d_namlen: u16, |
| 191 | 200 | d_type: u8, |
| 192 | d_name: [512]u8, | |
| 201 | d_name: [MAXNAMLEN:0]u8, | |
| 193 | 202 | |
| 194 | 203 | pub fn reclen(self: dirent) u16 { |
| 195 | 204 | return self.d_reclen; |
| ... | ... | @@ -697,23 +706,74 @@ pub const winsize = extern struct { |
| 697 | 706 | |
| 698 | 707 | const NSIG = 32; |
| 699 | 708 | |
| 700 | pub const SIG_ERR = @intToPtr(extern fn (i32) void, maxInt(usize)); | |
| 701 | pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0); | |
| 702 | pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1); | |
| 709 | pub const SIG_ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize)); | |
| 710 | pub const SIG_DFL = @intToPtr(?Sigaction.sigaction_fn, 0); | |
| 711 | pub const SIG_IGN = @intToPtr(?Sigaction.sigaction_fn, 1); | |
| 703 | 712 | |
| 704 | 713 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. |
| 705 | 714 | pub const Sigaction = extern struct { |
| 715 | pub const sigaction_fn = fn (i32, *siginfo_t, ?*c_void) callconv(.C) void; | |
| 706 | 716 | /// signal handler |
| 707 | __sigaction_u: extern union { | |
| 708 | __sa_handler: extern fn (i32) void, | |
| 709 | __sa_sigaction: extern fn (i32, *__siginfo, usize) void, | |
| 710 | }, | |
| 717 | sigaction: ?sigaction_fn, | |
| 718 | /// signal mask to apply | |
| 719 | mask: sigset_t, | |
| 720 | /// signal options | |
| 721 | flags: u32, | |
| 722 | }; | |
| 711 | 723 | |
| 712 | /// see signal options | |
| 713 | sa_flags: u32, | |
| 724 | pub const sigval_t = extern union { | |
| 725 | int: i32, | |
| 726 | ptr: ?*c_void, | |
| 727 | }; | |
| 714 | 728 | |
| 715 | /// signal mask to apply | |
| 716 | sa_mask: sigset_t, | |
| 729 | pub const siginfo_t = extern union { | |
| 730 | pad: [128]u8, | |
| 731 | info: _ksiginfo, | |
| 732 | }; | |
| 733 | ||
| 734 | pub const _ksiginfo = extern struct { | |
| 735 | signo: i32, | |
| 736 | code: i32, | |
| 737 | errno: i32, | |
| 738 | // 64bit architectures insert 4bytes of padding here, this is done by | |
| 739 | // correctly aligning the reason field | |
| 740 | reason: extern union { | |
| 741 | rt: extern struct { | |
| 742 | pid: pid_t, | |
| 743 | uid: uid_t, | |
| 744 | value: sigval_t, | |
| 745 | }, | |
| 746 | child: extern struct { | |
| 747 | pid: pid_t, | |
| 748 | uid: uid_t, | |
| 749 | status: i32, | |
| 750 | utime: clock_t, | |
| 751 | stime: clock_t, | |
| 752 | }, | |
| 753 | fault: extern struct { | |
| 754 | addr: ?*c_void, | |
| 755 | trap: i32, | |
| 756 | trap2: i32, | |
| 757 | trap3: i32, | |
| 758 | }, | |
| 759 | poll: extern struct { | |
| 760 | band: i32, | |
| 761 | fd: i32, | |
| 762 | }, | |
| 763 | syscall: extern struct { | |
| 764 | sysnum: i32, | |
| 765 | retval: [2]i32, | |
| 766 | @"error": i32, | |
| 767 | args: [8]u64, | |
| 768 | }, | |
| 769 | ptrace_state: extern struct { | |
| 770 | pe_report_event: i32, | |
| 771 | option: extern union { | |
| 772 | pe_other_pid: pid_t, | |
| 773 | pe_lwp: lwpid_t, | |
| 774 | }, | |
| 775 | }, | |
| 776 | } align(@sizeOf(usize)), | |
| 717 | 777 | }; |
| 718 | 778 | |
| 719 | 779 | pub const _SIG_WORDS = 4; |
| ... | ... | @@ -736,6 +796,34 @@ pub const sigset_t = extern struct { |
| 736 | 796 | __bits: [_SIG_WORDS]u32, |
| 737 | 797 | }; |
| 738 | 798 | |
| 799 | pub const empty_sigset = sigset_t{ .__bits = [_]u32{0} ** _SIG_WORDS }; | |
| 800 | ||
| 801 | // XXX x86_64 specific | |
| 802 | pub const mcontext_t = extern struct { | |
| 803 | gregs: [26]u64, | |
| 804 | mc_tlsbase: u64, | |
| 805 | fpregs: [512]u8 align(8), | |
| 806 | }; | |
| 807 | ||
| 808 | pub const REG_RBP = 12; | |
| 809 | pub const REG_RIP = 21; | |
| 810 | pub const REG_RSP = 24; | |
| 811 | ||
| 812 | pub const ucontext_t = extern struct { | |
| 813 | flags: u32, | |
| 814 | link: ?*ucontext_t, | |
| 815 | sigmask: sigset_t, | |
| 816 | stack: stack_t, | |
| 817 | mcontext: mcontext_t, | |
| 818 | __pad: [switch (builtin.arch) { | |
| 819 | .i386 => 4, | |
| 820 | .mips, .mipsel, .mips64, .mips64el => 14, | |
| 821 | .arm, .armeb, .thumb, .thumbeb => 1, | |
| 822 | .sparc, .sparcel, .sparcv9 => if (@sizeOf(usize) == 4) 43 else 8, | |
| 823 | else => 0, | |
| 824 | }]u32, | |
| 825 | }; | |
| 826 | ||
| 739 | 827 | pub const EPERM = 1; // Operation not permitted |
| 740 | 828 | pub const ENOENT = 2; // No such file or directory |
| 741 | 829 | pub const ESRCH = 3; // No such process |
lib/std/os/linux.zig+228-228| ... | ... | @@ -53,46 +53,46 @@ pub fn getErrno(r: usize) u12 { |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | pub fn dup2(old: i32, new: i32) usize { |
| 56 | if (@hasDecl(@This(), "SYS_dup2")) { | |
| 57 | return syscall2(SYS_dup2, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new))); | |
| 56 | if (@hasField(SYS, "dup2")) { | |
| 57 | return syscall2(.dup2, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new))); | |
| 58 | 58 | } else { |
| 59 | 59 | if (old == new) { |
| 60 | 60 | if (std.debug.runtime_safety) { |
| 61 | const rc = syscall2(SYS_fcntl, @bitCast(usize, @as(isize, old)), F_GETFD); | |
| 61 | const rc = syscall2(.fcntl, @bitCast(usize, @as(isize, old)), F_GETFD); | |
| 62 | 62 | if (@bitCast(isize, rc) < 0) return rc; |
| 63 | 63 | } |
| 64 | 64 | return @intCast(usize, old); |
| 65 | 65 | } else { |
| 66 | return syscall3(SYS_dup3, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new)), 0); | |
| 66 | return syscall3(.dup3, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new)), 0); | |
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | pub fn dup3(old: i32, new: i32, flags: u32) usize { |
| 72 | return syscall3(SYS_dup3, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new)), flags); | |
| 72 | return syscall3(.dup3, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new)), flags); | |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | pub fn chdir(path: [*:0]const u8) usize { |
| 76 | return syscall1(SYS_chdir, @ptrToInt(path)); | |
| 76 | return syscall1(.chdir, @ptrToInt(path)); | |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | pub fn fchdir(fd: fd_t) usize { |
| 80 | return syscall1(SYS_fchdir, @bitCast(usize, @as(isize, fd))); | |
| 80 | return syscall1(.fchdir, @bitCast(usize, @as(isize, fd))); | |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | pub fn chroot(path: [*:0]const u8) usize { |
| 84 | return syscall1(SYS_chroot, @ptrToInt(path)); | |
| 84 | return syscall1(.chroot, @ptrToInt(path)); | |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | pub fn execve(path: [*:0]const u8, argv: [*:null]const ?[*:0]const u8, envp: [*:null]const ?[*:0]const u8) usize { |
| 88 | return syscall3(SYS_execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp)); | |
| 88 | return syscall3(.execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp)); | |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | pub fn fork() usize { |
| 92 | if (@hasDecl(@This(), "SYS_fork")) { | |
| 93 | return syscall0(SYS_fork); | |
| 92 | if (@hasField(SYS, "fork")) { | |
| 93 | return syscall0(.fork); | |
| 94 | 94 | } else { |
| 95 | return syscall2(SYS_clone, SIGCHLD, 0); | |
| 95 | return syscall2(.clone, SIGCHLD, 0); | |
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | 98 | |
| ... | ... | @@ -102,7 +102,7 @@ pub fn fork() usize { |
| 102 | 102 | /// the compiler is not aware of how vfork affects control flow and you may |
| 103 | 103 | /// see different results in optimized builds. |
| 104 | 104 | pub inline fn vfork() usize { |
| 105 | return @call(.{ .modifier = .always_inline }, syscall0, .{SYS_vfork}); | |
| 105 | return @call(.{ .modifier = .always_inline }, syscall0, .{.vfork}); | |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | pub fn futimens(fd: i32, times: *const [2]timespec) usize { |
| ... | ... | @@ -110,24 +110,24 @@ pub fn futimens(fd: i32, times: *const [2]timespec) usize { |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | pub fn utimensat(dirfd: i32, path: ?[*:0]const u8, times: *const [2]timespec, flags: u32) usize { |
| 113 | return syscall4(SYS_utimensat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(times), flags); | |
| 113 | return syscall4(.utimensat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(times), flags); | |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | pub fn futex_wait(uaddr: *const i32, futex_op: u32, val: i32, timeout: ?*timespec) usize { |
| 117 | return syscall4(SYS_futex, @ptrToInt(uaddr), futex_op, @bitCast(u32, val), @ptrToInt(timeout)); | |
| 117 | return syscall4(.futex, @ptrToInt(uaddr), futex_op, @bitCast(u32, val), @ptrToInt(timeout)); | |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | pub fn futex_wake(uaddr: *const i32, futex_op: u32, val: i32) usize { |
| 121 | return syscall3(SYS_futex, @ptrToInt(uaddr), futex_op, @bitCast(u32, val)); | |
| 121 | return syscall3(.futex, @ptrToInt(uaddr), futex_op, @bitCast(u32, val)); | |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | pub fn getcwd(buf: [*]u8, size: usize) usize { |
| 125 | return syscall2(SYS_getcwd, @ptrToInt(buf), size); | |
| 125 | return syscall2(.getcwd, @ptrToInt(buf), size); | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | pub fn getdents(fd: i32, dirp: [*]u8, len: usize) usize { |
| 129 | 129 | return syscall3( |
| 130 | SYS_getdents, | |
| 130 | .getdents, | |
| 131 | 131 | @bitCast(usize, @as(isize, fd)), |
| 132 | 132 | @ptrToInt(dirp), |
| 133 | 133 | std.math.min(len, maxInt(c_int)), |
| ... | ... | @@ -136,7 +136,7 @@ pub fn getdents(fd: i32, dirp: [*]u8, len: usize) usize { |
| 136 | 136 | |
| 137 | 137 | pub fn getdents64(fd: i32, dirp: [*]u8, len: usize) usize { |
| 138 | 138 | return syscall3( |
| 139 | SYS_getdents64, | |
| 139 | .getdents64, | |
| 140 | 140 | @bitCast(usize, @as(isize, fd)), |
| 141 | 141 | @ptrToInt(dirp), |
| 142 | 142 | std.math.min(len, maxInt(c_int)), |
| ... | ... | @@ -144,61 +144,61 @@ pub fn getdents64(fd: i32, dirp: [*]u8, len: usize) usize { |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | pub fn inotify_init1(flags: u32) usize { |
| 147 | return syscall1(SYS_inotify_init1, flags); | |
| 147 | return syscall1(.inotify_init1, flags); | |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | pub fn inotify_add_watch(fd: i32, pathname: [*:0]const u8, mask: u32) usize { |
| 151 | return syscall3(SYS_inotify_add_watch, @bitCast(usize, @as(isize, fd)), @ptrToInt(pathname), mask); | |
| 151 | return syscall3(.inotify_add_watch, @bitCast(usize, @as(isize, fd)), @ptrToInt(pathname), mask); | |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | pub fn inotify_rm_watch(fd: i32, wd: i32) usize { |
| 155 | return syscall2(SYS_inotify_rm_watch, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, wd))); | |
| 155 | return syscall2(.inotify_rm_watch, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, wd))); | |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | pub fn readlink(noalias path: [*:0]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize { |
| 159 | if (@hasDecl(@This(), "SYS_readlink")) { | |
| 160 | return syscall3(SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); | |
| 159 | if (@hasField(SYS, "readlink")) { | |
| 160 | return syscall3(.readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); | |
| 161 | 161 | } else { |
| 162 | return syscall4(SYS_readlinkat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); | |
| 162 | return syscall4(.readlinkat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); | |
| 163 | 163 | } |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | pub fn readlinkat(dirfd: i32, noalias path: [*:0]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize { |
| 167 | return syscall4(SYS_readlinkat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); | |
| 167 | return syscall4(.readlinkat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); | |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | pub fn mkdir(path: [*:0]const u8, mode: u32) usize { |
| 171 | if (@hasDecl(@This(), "SYS_mkdir")) { | |
| 172 | return syscall2(SYS_mkdir, @ptrToInt(path), mode); | |
| 171 | if (@hasField(SYS, "mkdir")) { | |
| 172 | return syscall2(.mkdir, @ptrToInt(path), mode); | |
| 173 | 173 | } else { |
| 174 | return syscall3(SYS_mkdirat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), mode); | |
| 174 | return syscall3(.mkdirat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), mode); | |
| 175 | 175 | } |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | pub fn mkdirat(dirfd: i32, path: [*:0]const u8, mode: u32) usize { |
| 179 | return syscall3(SYS_mkdirat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), mode); | |
| 179 | return syscall3(.mkdirat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), mode); | |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | pub fn mount(special: [*:0]const u8, dir: [*:0]const u8, fstype: [*:0]const u8, flags: u32, data: usize) usize { |
| 183 | return syscall5(SYS_mount, @ptrToInt(special), @ptrToInt(dir), @ptrToInt(fstype), flags, data); | |
| 183 | return syscall5(.mount, @ptrToInt(special), @ptrToInt(dir), @ptrToInt(fstype), flags, data); | |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | pub fn umount(special: [*:0]const u8) usize { |
| 187 | return syscall2(SYS_umount2, @ptrToInt(special), 0); | |
| 187 | return syscall2(.umount2, @ptrToInt(special), 0); | |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | pub fn umount2(special: [*:0]const u8, flags: u32) usize { |
| 191 | return syscall2(SYS_umount2, @ptrToInt(special), flags); | |
| 191 | return syscall2(.umount2, @ptrToInt(special), flags); | |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, offset: u64) usize { |
| 195 | if (@hasDecl(@This(), "SYS_mmap2")) { | |
| 195 | if (@hasField(SYS, "mmap2")) { | |
| 196 | 196 | // Make sure the offset is also specified in multiples of page size |
| 197 | 197 | if ((offset & (MMAP2_UNIT - 1)) != 0) |
| 198 | 198 | return @bitCast(usize, @as(isize, -EINVAL)); |
| 199 | 199 | |
| 200 | 200 | return syscall6( |
| 201 | SYS_mmap2, | |
| 201 | .mmap2, | |
| 202 | 202 | @ptrToInt(address), |
| 203 | 203 | length, |
| 204 | 204 | prot, |
| ... | ... | @@ -208,7 +208,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of |
| 208 | 208 | ); |
| 209 | 209 | } else { |
| 210 | 210 | return syscall6( |
| 211 | SYS_mmap, | |
| 211 | .mmap, | |
| 212 | 212 | @ptrToInt(address), |
| 213 | 213 | length, |
| 214 | 214 | prot, |
| ... | ... | @@ -220,19 +220,19 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | pub fn mprotect(address: [*]const u8, length: usize, protection: usize) usize { |
| 223 | return syscall3(SYS_mprotect, @ptrToInt(address), length, protection); | |
| 223 | return syscall3(.mprotect, @ptrToInt(address), length, protection); | |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | pub fn munmap(address: [*]const u8, length: usize) usize { |
| 227 | return syscall2(SYS_munmap, @ptrToInt(address), length); | |
| 227 | return syscall2(.munmap, @ptrToInt(address), length); | |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | pub fn poll(fds: [*]pollfd, n: nfds_t, timeout: i32) usize { |
| 231 | if (@hasDecl(@This(), "SYS_poll")) { | |
| 232 | return syscall3(SYS_poll, @ptrToInt(fds), n, @bitCast(u32, timeout)); | |
| 231 | if (@hasField(SYS, "poll")) { | |
| 232 | return syscall3(.poll, @ptrToInt(fds), n, @bitCast(u32, timeout)); | |
| 233 | 233 | } else { |
| 234 | 234 | return syscall6( |
| 235 | SYS_ppoll, | |
| 235 | .ppoll, | |
| 236 | 236 | @ptrToInt(fds), |
| 237 | 237 | n, |
| 238 | 238 | @ptrToInt(if (timeout >= 0) |
| ... | ... | @@ -250,12 +250,12 @@ pub fn poll(fds: [*]pollfd, n: nfds_t, timeout: i32) usize { |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | pub fn read(fd: i32, buf: [*]u8, count: usize) usize { |
| 253 | return syscall3(SYS_read, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count); | |
| 253 | return syscall3(.read, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count); | |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: u64) usize { |
| 257 | 257 | return syscall5( |
| 258 | SYS_preadv, | |
| 258 | .preadv, | |
| 259 | 259 | @bitCast(usize, @as(isize, fd)), |
| 260 | 260 | @ptrToInt(iov), |
| 261 | 261 | count, |
| ... | ... | @@ -266,7 +266,7 @@ pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: u64) usize { |
| 266 | 266 | |
| 267 | 267 | pub fn preadv2(fd: i32, iov: [*]const iovec, count: usize, offset: u64, flags: kernel_rwf) usize { |
| 268 | 268 | return syscall6( |
| 269 | SYS_preadv2, | |
| 269 | .preadv2, | |
| 270 | 270 | @bitCast(usize, @as(isize, fd)), |
| 271 | 271 | @ptrToInt(iov), |
| 272 | 272 | count, |
| ... | ... | @@ -277,16 +277,16 @@ pub fn preadv2(fd: i32, iov: [*]const iovec, count: usize, offset: u64, flags: k |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | pub fn readv(fd: i32, iov: [*]const iovec, count: usize) usize { |
| 280 | return syscall3(SYS_readv, @bitCast(usize, @as(isize, fd)), @ptrToInt(iov), count); | |
| 280 | return syscall3(.readv, @bitCast(usize, @as(isize, fd)), @ptrToInt(iov), count); | |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | pub fn writev(fd: i32, iov: [*]const iovec_const, count: usize) usize { |
| 284 | return syscall3(SYS_writev, @bitCast(usize, @as(isize, fd)), @ptrToInt(iov), count); | |
| 284 | return syscall3(.writev, @bitCast(usize, @as(isize, fd)), @ptrToInt(iov), count); | |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64) usize { |
| 288 | 288 | return syscall5( |
| 289 | SYS_pwritev, | |
| 289 | .pwritev, | |
| 290 | 290 | @bitCast(usize, @as(isize, fd)), |
| 291 | 291 | @ptrToInt(iov), |
| 292 | 292 | count, |
| ... | ... | @@ -297,7 +297,7 @@ pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64) us |
| 297 | 297 | |
| 298 | 298 | pub fn pwritev2(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64, flags: kernel_rwf) usize { |
| 299 | 299 | return syscall6( |
| 300 | SYS_pwritev2, | |
| 300 | .pwritev2, | |
| 301 | 301 | @bitCast(usize, @as(isize, fd)), |
| 302 | 302 | @ptrToInt(iov), |
| 303 | 303 | count, |
| ... | ... | @@ -308,30 +308,30 @@ pub fn pwritev2(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64, f |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | pub fn rmdir(path: [*:0]const u8) usize { |
| 311 | if (@hasDecl(@This(), "SYS_rmdir")) { | |
| 312 | return syscall1(SYS_rmdir, @ptrToInt(path)); | |
| 311 | if (@hasField(SYS, "rmdir")) { | |
| 312 | return syscall1(.rmdir, @ptrToInt(path)); | |
| 313 | 313 | } else { |
| 314 | return syscall3(SYS_unlinkat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), AT_REMOVEDIR); | |
| 314 | return syscall3(.unlinkat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), AT_REMOVEDIR); | |
| 315 | 315 | } |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | pub fn symlink(existing: [*:0]const u8, new: [*:0]const u8) usize { |
| 319 | if (@hasDecl(@This(), "SYS_symlink")) { | |
| 320 | return syscall2(SYS_symlink, @ptrToInt(existing), @ptrToInt(new)); | |
| 319 | if (@hasField(SYS, "symlink")) { | |
| 320 | return syscall2(.symlink, @ptrToInt(existing), @ptrToInt(new)); | |
| 321 | 321 | } else { |
| 322 | return syscall3(SYS_symlinkat, @ptrToInt(existing), @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(new)); | |
| 322 | return syscall3(.symlinkat, @ptrToInt(existing), @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(new)); | |
| 323 | 323 | } |
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | pub fn symlinkat(existing: [*:0]const u8, newfd: i32, newpath: [*:0]const u8) usize { |
| 327 | return syscall3(SYS_symlinkat, @ptrToInt(existing), @bitCast(usize, @as(isize, newfd)), @ptrToInt(newpath)); | |
| 327 | return syscall3(.symlinkat, @ptrToInt(existing), @bitCast(usize, @as(isize, newfd)), @ptrToInt(newpath)); | |
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: u64) usize { |
| 331 | if (@hasDecl(@This(), "SYS_pread64")) { | |
| 331 | if (@hasField(SYS, "pread64")) { | |
| 332 | 332 | if (require_aligned_register_pair) { |
| 333 | 333 | return syscall6( |
| 334 | SYS_pread64, | |
| 334 | .pread64, | |
| 335 | 335 | @bitCast(usize, @as(isize, fd)), |
| 336 | 336 | @ptrToInt(buf), |
| 337 | 337 | count, |
| ... | ... | @@ -341,7 +341,7 @@ pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: u64) usize { |
| 341 | 341 | ); |
| 342 | 342 | } else { |
| 343 | 343 | return syscall5( |
| 344 | SYS_pread64, | |
| 344 | .pread64, | |
| 345 | 345 | @bitCast(usize, @as(isize, fd)), |
| 346 | 346 | @ptrToInt(buf), |
| 347 | 347 | count, |
| ... | ... | @@ -351,7 +351,7 @@ pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: u64) usize { |
| 351 | 351 | } |
| 352 | 352 | } else { |
| 353 | 353 | return syscall4( |
| 354 | SYS_pread, | |
| 354 | .pread, | |
| 355 | 355 | @bitCast(usize, @as(isize, fd)), |
| 356 | 356 | @ptrToInt(buf), |
| 357 | 357 | count, |
| ... | ... | @@ -361,40 +361,40 @@ pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: u64) usize { |
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | pub fn access(path: [*:0]const u8, mode: u32) usize { |
| 364 | if (@hasDecl(@This(), "SYS_access")) { | |
| 365 | return syscall2(SYS_access, @ptrToInt(path), mode); | |
| 364 | if (@hasField(SYS, "access")) { | |
| 365 | return syscall2(.access, @ptrToInt(path), mode); | |
| 366 | 366 | } else { |
| 367 | return syscall4(SYS_faccessat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), mode, 0); | |
| 367 | return syscall4(.faccessat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), mode, 0); | |
| 368 | 368 | } |
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | pub fn faccessat(dirfd: i32, path: [*:0]const u8, mode: u32, flags: u32) usize { |
| 372 | return syscall4(SYS_faccessat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), mode, flags); | |
| 372 | return syscall4(.faccessat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), mode, flags); | |
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | pub fn pipe(fd: *[2]i32) usize { |
| 376 | 376 | if (comptime builtin.arch.isMIPS()) { |
| 377 | 377 | return syscall_pipe(fd); |
| 378 | } else if (@hasDecl(@This(), "SYS_pipe")) { | |
| 379 | return syscall1(SYS_pipe, @ptrToInt(fd)); | |
| 378 | } else if (@hasField(SYS, "pipe")) { | |
| 379 | return syscall1(.pipe, @ptrToInt(fd)); | |
| 380 | 380 | } else { |
| 381 | return syscall2(SYS_pipe2, @ptrToInt(fd), 0); | |
| 381 | return syscall2(.pipe2, @ptrToInt(fd), 0); | |
| 382 | 382 | } |
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | pub fn pipe2(fd: *[2]i32, flags: u32) usize { |
| 386 | return syscall2(SYS_pipe2, @ptrToInt(fd), flags); | |
| 386 | return syscall2(.pipe2, @ptrToInt(fd), flags); | |
| 387 | 387 | } |
| 388 | 388 | |
| 389 | 389 | pub fn write(fd: i32, buf: [*]const u8, count: usize) usize { |
| 390 | return syscall3(SYS_write, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count); | |
| 390 | return syscall3(.write, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count); | |
| 391 | 391 | } |
| 392 | 392 | |
| 393 | 393 | pub fn ftruncate(fd: i32, length: u64) usize { |
| 394 | if (@hasDecl(@This(), "SYS_ftruncate64")) { | |
| 394 | if (@hasField(SYS, "ftruncate64")) { | |
| 395 | 395 | if (require_aligned_register_pair) { |
| 396 | 396 | return syscall4( |
| 397 | SYS_ftruncate64, | |
| 397 | .ftruncate64, | |
| 398 | 398 | @bitCast(usize, @as(isize, fd)), |
| 399 | 399 | 0, |
| 400 | 400 | @truncate(usize, length), |
| ... | ... | @@ -402,7 +402,7 @@ pub fn ftruncate(fd: i32, length: u64) usize { |
| 402 | 402 | ); |
| 403 | 403 | } else { |
| 404 | 404 | return syscall3( |
| 405 | SYS_ftruncate64, | |
| 405 | .ftruncate64, | |
| 406 | 406 | @bitCast(usize, @as(isize, fd)), |
| 407 | 407 | @truncate(usize, length), |
| 408 | 408 | @truncate(usize, length >> 32), |
| ... | ... | @@ -410,7 +410,7 @@ pub fn ftruncate(fd: i32, length: u64) usize { |
| 410 | 410 | } |
| 411 | 411 | } else { |
| 412 | 412 | return syscall2( |
| 413 | SYS_ftruncate, | |
| 413 | .ftruncate, | |
| 414 | 414 | @bitCast(usize, @as(isize, fd)), |
| 415 | 415 | @truncate(usize, length), |
| 416 | 416 | ); |
| ... | ... | @@ -418,10 +418,10 @@ pub fn ftruncate(fd: i32, length: u64) usize { |
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize { |
| 421 | if (@hasDecl(@This(), "SYS_pwrite64")) { | |
| 421 | if (@hasField(SYS, "pwrite64")) { | |
| 422 | 422 | if (require_aligned_register_pair) { |
| 423 | 423 | return syscall6( |
| 424 | SYS_pwrite64, | |
| 424 | .pwrite64, | |
| 425 | 425 | @bitCast(usize, @as(isize, fd)), |
| 426 | 426 | @ptrToInt(buf), |
| 427 | 427 | count, |
| ... | ... | @@ -431,7 +431,7 @@ pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize { |
| 431 | 431 | ); |
| 432 | 432 | } else { |
| 433 | 433 | return syscall5( |
| 434 | SYS_pwrite64, | |
| 434 | .pwrite64, | |
| 435 | 435 | @bitCast(usize, @as(isize, fd)), |
| 436 | 436 | @ptrToInt(buf), |
| 437 | 437 | count, |
| ... | ... | @@ -441,7 +441,7 @@ pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize { |
| 441 | 441 | } |
| 442 | 442 | } else { |
| 443 | 443 | return syscall4( |
| 444 | SYS_pwrite, | |
| 444 | .pwrite, | |
| 445 | 445 | @bitCast(usize, @as(isize, fd)), |
| 446 | 446 | @ptrToInt(buf), |
| 447 | 447 | count, |
| ... | ... | @@ -451,19 +451,19 @@ pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize { |
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | pub fn rename(old: [*:0]const u8, new: [*:0]const u8) usize { |
| 454 | if (@hasDecl(@This(), "SYS_rename")) { | |
| 455 | return syscall2(SYS_rename, @ptrToInt(old), @ptrToInt(new)); | |
| 456 | } else if (@hasDecl(@This(), "SYS_renameat")) { | |
| 457 | return syscall4(SYS_renameat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(old), @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(new)); | |
| 454 | if (@hasField(SYS, "rename")) { | |
| 455 | return syscall2(.rename, @ptrToInt(old), @ptrToInt(new)); | |
| 456 | } else if (@hasField(SYS, "renameat")) { | |
| 457 | return syscall4(.renameat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(old), @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(new)); | |
| 458 | 458 | } else { |
| 459 | return syscall5(SYS_renameat2, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(old), @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(new), 0); | |
| 459 | return syscall5(.renameat2, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(old), @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(new), 0); | |
| 460 | 460 | } |
| 461 | 461 | } |
| 462 | 462 | |
| 463 | 463 | pub fn renameat(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const u8) usize { |
| 464 | if (@hasDecl(@This(), "SYS_renameat")) { | |
| 464 | if (@hasField(SYS, "renameat")) { | |
| 465 | 465 | return syscall4( |
| 466 | SYS_renameat, | |
| 466 | .renameat, | |
| 467 | 467 | @bitCast(usize, @as(isize, oldfd)), |
| 468 | 468 | @ptrToInt(oldpath), |
| 469 | 469 | @bitCast(usize, @as(isize, newfd)), |
| ... | ... | @@ -471,7 +471,7 @@ pub fn renameat(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const |
| 471 | 471 | ); |
| 472 | 472 | } else { |
| 473 | 473 | return syscall5( |
| 474 | SYS_renameat2, | |
| 474 | .renameat2, | |
| 475 | 475 | @bitCast(usize, @as(isize, oldfd)), |
| 476 | 476 | @ptrToInt(oldpath), |
| 477 | 477 | @bitCast(usize, @as(isize, newfd)), |
| ... | ... | @@ -483,7 +483,7 @@ pub fn renameat(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const |
| 483 | 483 | |
| 484 | 484 | pub fn renameat2(oldfd: i32, oldpath: [*:0]const u8, newfd: i32, newpath: [*:0]const u8, flags: u32) usize { |
| 485 | 485 | return syscall5( |
| 486 | SYS_renameat2, | |
| 486 | .renameat2, | |
| 487 | 487 | @bitCast(usize, @as(isize, oldfd)), |
| 488 | 488 | @ptrToInt(oldpath), |
| 489 | 489 | @bitCast(usize, @as(isize, newfd)), |
| ... | ... | @@ -493,11 +493,11 @@ pub fn renameat2(oldfd: i32, oldpath: [*:0]const u8, newfd: i32, newpath: [*:0]c |
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | pub fn open(path: [*:0]const u8, flags: u32, perm: usize) usize { |
| 496 | if (@hasDecl(@This(), "SYS_open")) { | |
| 497 | return syscall3(SYS_open, @ptrToInt(path), flags, perm); | |
| 496 | if (@hasField(SYS, "open")) { | |
| 497 | return syscall3(.open, @ptrToInt(path), flags, perm); | |
| 498 | 498 | } else { |
| 499 | 499 | return syscall4( |
| 500 | SYS_openat, | |
| 500 | .openat, | |
| 501 | 501 | @bitCast(usize, @as(isize, AT_FDCWD)), |
| 502 | 502 | @ptrToInt(path), |
| 503 | 503 | flags, |
| ... | ... | @@ -507,32 +507,32 @@ pub fn open(path: [*:0]const u8, flags: u32, perm: usize) usize { |
| 507 | 507 | } |
| 508 | 508 | |
| 509 | 509 | pub fn create(path: [*:0]const u8, perm: usize) usize { |
| 510 | return syscall2(SYS_creat, @ptrToInt(path), perm); | |
| 510 | return syscall2(.creat, @ptrToInt(path), perm); | |
| 511 | 511 | } |
| 512 | 512 | |
| 513 | 513 | pub fn openat(dirfd: i32, path: [*:0]const u8, flags: u32, mode: usize) usize { |
| 514 | 514 | // dirfd could be negative, for example AT_FDCWD is -100 |
| 515 | return syscall4(SYS_openat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), flags, mode); | |
| 515 | return syscall4(.openat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), flags, mode); | |
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | /// See also `clone` (from the arch-specific include) |
| 519 | 519 | pub fn clone5(flags: usize, child_stack_ptr: usize, parent_tid: *i32, child_tid: *i32, newtls: usize) usize { |
| 520 | return syscall5(SYS_clone, flags, child_stack_ptr, @ptrToInt(parent_tid), @ptrToInt(child_tid), newtls); | |
| 520 | return syscall5(.clone, flags, child_stack_ptr, @ptrToInt(parent_tid), @ptrToInt(child_tid), newtls); | |
| 521 | 521 | } |
| 522 | 522 | |
| 523 | 523 | /// See also `clone` (from the arch-specific include) |
| 524 | 524 | pub fn clone2(flags: u32, child_stack_ptr: usize) usize { |
| 525 | return syscall2(SYS_clone, flags, child_stack_ptr); | |
| 525 | return syscall2(.clone, flags, child_stack_ptr); | |
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | pub fn close(fd: i32) usize { |
| 529 | return syscall1(SYS_close, @bitCast(usize, @as(isize, fd))); | |
| 529 | return syscall1(.close, @bitCast(usize, @as(isize, fd))); | |
| 530 | 530 | } |
| 531 | 531 | |
| 532 | 532 | /// Can only be called on 32 bit systems. For 64 bit see `lseek`. |
| 533 | 533 | pub fn llseek(fd: i32, offset: u64, result: ?*u64, whence: usize) usize { |
| 534 | 534 | return syscall5( |
| 535 | SYS__llseek, | |
| 535 | ._llseek, | |
| 536 | 536 | @bitCast(usize, @as(isize, fd)), |
| 537 | 537 | @truncate(usize, offset >> 32), |
| 538 | 538 | @truncate(usize, offset), |
| ... | ... | @@ -543,53 +543,53 @@ pub fn llseek(fd: i32, offset: u64, result: ?*u64, whence: usize) usize { |
| 543 | 543 | |
| 544 | 544 | /// Can only be called on 64 bit systems. For 32 bit see `llseek`. |
| 545 | 545 | pub fn lseek(fd: i32, offset: i64, whence: usize) usize { |
| 546 | return syscall3(SYS_lseek, @bitCast(usize, @as(isize, fd)), @bitCast(usize, offset), whence); | |
| 546 | return syscall3(.lseek, @bitCast(usize, @as(isize, fd)), @bitCast(usize, offset), whence); | |
| 547 | 547 | } |
| 548 | 548 | |
| 549 | 549 | pub fn exit(status: i32) noreturn { |
| 550 | _ = syscall1(SYS_exit, @bitCast(usize, @as(isize, status))); | |
| 550 | _ = syscall1(.exit, @bitCast(usize, @as(isize, status))); | |
| 551 | 551 | unreachable; |
| 552 | 552 | } |
| 553 | 553 | |
| 554 | 554 | pub fn exit_group(status: i32) noreturn { |
| 555 | _ = syscall1(SYS_exit_group, @bitCast(usize, @as(isize, status))); | |
| 555 | _ = syscall1(.exit_group, @bitCast(usize, @as(isize, status))); | |
| 556 | 556 | unreachable; |
| 557 | 557 | } |
| 558 | 558 | |
| 559 | 559 | pub fn getrandom(buf: [*]u8, count: usize, flags: u32) usize { |
| 560 | return syscall3(SYS_getrandom, @ptrToInt(buf), count, flags); | |
| 560 | return syscall3(.getrandom, @ptrToInt(buf), count, flags); | |
| 561 | 561 | } |
| 562 | 562 | |
| 563 | 563 | pub fn kill(pid: pid_t, sig: i32) usize { |
| 564 | return syscall2(SYS_kill, @bitCast(usize, @as(isize, pid)), @bitCast(usize, @as(isize, sig))); | |
| 564 | return syscall2(.kill, @bitCast(usize, @as(isize, pid)), @bitCast(usize, @as(isize, sig))); | |
| 565 | 565 | } |
| 566 | 566 | |
| 567 | 567 | pub fn tkill(tid: pid_t, sig: i32) usize { |
| 568 | return syscall2(SYS_tkill, @bitCast(usize, @as(isize, tid)), @bitCast(usize, @as(isize, sig))); | |
| 568 | return syscall2(.tkill, @bitCast(usize, @as(isize, tid)), @bitCast(usize, @as(isize, sig))); | |
| 569 | 569 | } |
| 570 | 570 | |
| 571 | 571 | pub fn tgkill(tgid: pid_t, tid: pid_t, sig: i32) usize { |
| 572 | return syscall2(SYS_tgkill, @bitCast(usize, @as(isize, tgid)), @bitCast(usize, @as(isize, tid)), @bitCast(usize, @as(isize, sig))); | |
| 572 | return syscall2(.tgkill, @bitCast(usize, @as(isize, tgid)), @bitCast(usize, @as(isize, tid)), @bitCast(usize, @as(isize, sig))); | |
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | pub fn unlink(path: [*:0]const u8) usize { |
| 576 | if (@hasDecl(@This(), "SYS_unlink")) { | |
| 577 | return syscall1(SYS_unlink, @ptrToInt(path)); | |
| 576 | if (@hasField(SYS, "unlink")) { | |
| 577 | return syscall1(.unlink, @ptrToInt(path)); | |
| 578 | 578 | } else { |
| 579 | return syscall3(SYS_unlinkat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), 0); | |
| 579 | return syscall3(.unlinkat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), 0); | |
| 580 | 580 | } |
| 581 | 581 | } |
| 582 | 582 | |
| 583 | 583 | pub fn unlinkat(dirfd: i32, path: [*:0]const u8, flags: u32) usize { |
| 584 | return syscall3(SYS_unlinkat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), flags); | |
| 584 | return syscall3(.unlinkat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), flags); | |
| 585 | 585 | } |
| 586 | 586 | |
| 587 | 587 | pub fn waitpid(pid: pid_t, status: *u32, flags: u32) usize { |
| 588 | return syscall4(SYS_wait4, @bitCast(usize, @as(isize, pid)), @ptrToInt(status), flags, 0); | |
| 588 | return syscall4(.wait4, @bitCast(usize, @as(isize, pid)), @ptrToInt(status), flags, 0); | |
| 589 | 589 | } |
| 590 | 590 | |
| 591 | 591 | pub fn fcntl(fd: fd_t, cmd: i32, arg: usize) usize { |
| 592 | return syscall3(SYS_fcntl, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, cmd)), arg); | |
| 592 | return syscall3(.fcntl, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, cmd)), arg); | |
| 593 | 593 | } |
| 594 | 594 | |
| 595 | 595 | var vdso_clock_gettime = @ptrCast(?*const c_void, init_vdso_clock_gettime); |
| ... | ... | @@ -609,7 +609,7 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) usize { |
| 609 | 609 | } |
| 610 | 610 | } |
| 611 | 611 | } |
| 612 | return syscall2(SYS_clock_gettime, @bitCast(usize, @as(isize, clk_id)), @ptrToInt(tp)); | |
| 612 | return syscall2(.clock_gettime, @bitCast(usize, @as(isize, clk_id)), @ptrToInt(tp)); | |
| 613 | 613 | } |
| 614 | 614 | |
| 615 | 615 | fn init_vdso_clock_gettime(clk: i32, ts: *timespec) callconv(.C) usize { |
| ... | ... | @@ -626,86 +626,86 @@ fn init_vdso_clock_gettime(clk: i32, ts: *timespec) callconv(.C) usize { |
| 626 | 626 | } |
| 627 | 627 | |
| 628 | 628 | pub fn clock_getres(clk_id: i32, tp: *timespec) usize { |
| 629 | return syscall2(SYS_clock_getres, @bitCast(usize, @as(isize, clk_id)), @ptrToInt(tp)); | |
| 629 | return syscall2(.clock_getres, @bitCast(usize, @as(isize, clk_id)), @ptrToInt(tp)); | |
| 630 | 630 | } |
| 631 | 631 | |
| 632 | 632 | pub fn clock_settime(clk_id: i32, tp: *const timespec) usize { |
| 633 | return syscall2(SYS_clock_settime, @bitCast(usize, @as(isize, clk_id)), @ptrToInt(tp)); | |
| 633 | return syscall2(.clock_settime, @bitCast(usize, @as(isize, clk_id)), @ptrToInt(tp)); | |
| 634 | 634 | } |
| 635 | 635 | |
| 636 | 636 | pub fn gettimeofday(tv: *timeval, tz: *timezone) usize { |
| 637 | return syscall2(SYS_gettimeofday, @ptrToInt(tv), @ptrToInt(tz)); | |
| 637 | return syscall2(.gettimeofday, @ptrToInt(tv), @ptrToInt(tz)); | |
| 638 | 638 | } |
| 639 | 639 | |
| 640 | 640 | pub fn settimeofday(tv: *const timeval, tz: *const timezone) usize { |
| 641 | return syscall2(SYS_settimeofday, @ptrToInt(tv), @ptrToInt(tz)); | |
| 641 | return syscall2(.settimeofday, @ptrToInt(tv), @ptrToInt(tz)); | |
| 642 | 642 | } |
| 643 | 643 | |
| 644 | 644 | pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize { |
| 645 | return syscall2(SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem)); | |
| 645 | return syscall2(.nanosleep, @ptrToInt(req), @ptrToInt(rem)); | |
| 646 | 646 | } |
| 647 | 647 | |
| 648 | 648 | pub fn setuid(uid: u32) usize { |
| 649 | if (@hasDecl(@This(), "SYS_setuid32")) { | |
| 650 | return syscall1(SYS_setuid32, uid); | |
| 649 | if (@hasField(SYS, "setuid32")) { | |
| 650 | return syscall1(.setuid32, uid); | |
| 651 | 651 | } else { |
| 652 | return syscall1(SYS_setuid, uid); | |
| 652 | return syscall1(.setuid, uid); | |
| 653 | 653 | } |
| 654 | 654 | } |
| 655 | 655 | |
| 656 | 656 | pub fn setgid(gid: u32) usize { |
| 657 | if (@hasDecl(@This(), "SYS_setgid32")) { | |
| 658 | return syscall1(SYS_setgid32, gid); | |
| 657 | if (@hasField(SYS, "setgid32")) { | |
| 658 | return syscall1(.setgid32, gid); | |
| 659 | 659 | } else { |
| 660 | return syscall1(SYS_setgid, gid); | |
| 660 | return syscall1(.setgid, gid); | |
| 661 | 661 | } |
| 662 | 662 | } |
| 663 | 663 | |
| 664 | 664 | pub fn setreuid(ruid: u32, euid: u32) usize { |
| 665 | if (@hasDecl(@This(), "SYS_setreuid32")) { | |
| 666 | return syscall2(SYS_setreuid32, ruid, euid); | |
| 665 | if (@hasField(SYS, "setreuid32")) { | |
| 666 | return syscall2(.setreuid32, ruid, euid); | |
| 667 | 667 | } else { |
| 668 | return syscall2(SYS_setreuid, ruid, euid); | |
| 668 | return syscall2(.setreuid, ruid, euid); | |
| 669 | 669 | } |
| 670 | 670 | } |
| 671 | 671 | |
| 672 | 672 | pub fn setregid(rgid: u32, egid: u32) usize { |
| 673 | if (@hasDecl(@This(), "SYS_setregid32")) { | |
| 674 | return syscall2(SYS_setregid32, rgid, egid); | |
| 673 | if (@hasField(SYS, "setregid32")) { | |
| 674 | return syscall2(.setregid32, rgid, egid); | |
| 675 | 675 | } else { |
| 676 | return syscall2(SYS_setregid, rgid, egid); | |
| 676 | return syscall2(.setregid, rgid, egid); | |
| 677 | 677 | } |
| 678 | 678 | } |
| 679 | 679 | |
| 680 | 680 | pub fn getuid() u32 { |
| 681 | if (@hasDecl(@This(), "SYS_getuid32")) { | |
| 682 | return @as(u32, syscall0(SYS_getuid32)); | |
| 681 | if (@hasField(SYS, "getuid32")) { | |
| 682 | return @as(u32, syscall0(.getuid32)); | |
| 683 | 683 | } else { |
| 684 | return @as(u32, syscall0(SYS_getuid)); | |
| 684 | return @as(u32, syscall0(.getuid)); | |
| 685 | 685 | } |
| 686 | 686 | } |
| 687 | 687 | |
| 688 | 688 | pub fn getgid() u32 { |
| 689 | if (@hasDecl(@This(), "SYS_getgid32")) { | |
| 690 | return @as(u32, syscall0(SYS_getgid32)); | |
| 689 | if (@hasField(SYS, "getgid32")) { | |
| 690 | return @as(u32, syscall0(.getgid32)); | |
| 691 | 691 | } else { |
| 692 | return @as(u32, syscall0(SYS_getgid)); | |
| 692 | return @as(u32, syscall0(.getgid)); | |
| 693 | 693 | } |
| 694 | 694 | } |
| 695 | 695 | |
| 696 | 696 | pub fn geteuid() u32 { |
| 697 | if (@hasDecl(@This(), "SYS_geteuid32")) { | |
| 698 | return @as(u32, syscall0(SYS_geteuid32)); | |
| 697 | if (@hasField(SYS, "geteuid32")) { | |
| 698 | return @as(u32, syscall0(.geteuid32)); | |
| 699 | 699 | } else { |
| 700 | return @as(u32, syscall0(SYS_geteuid)); | |
| 700 | return @as(u32, syscall0(.geteuid)); | |
| 701 | 701 | } |
| 702 | 702 | } |
| 703 | 703 | |
| 704 | 704 | pub fn getegid() u32 { |
| 705 | if (@hasDecl(@This(), "SYS_getegid32")) { | |
| 706 | return @as(u32, syscall0(SYS_getegid32)); | |
| 705 | if (@hasField(SYS, "getegid32")) { | |
| 706 | return @as(u32, syscall0(.getegid32)); | |
| 707 | 707 | } else { |
| 708 | return @as(u32, syscall0(SYS_getegid)); | |
| 708 | return @as(u32, syscall0(.getegid)); | |
| 709 | 709 | } |
| 710 | 710 | } |
| 711 | 711 | |
| ... | ... | @@ -718,63 +718,63 @@ pub fn setegid(egid: u32) usize { |
| 718 | 718 | } |
| 719 | 719 | |
| 720 | 720 | pub fn getresuid(ruid: *u32, euid: *u32, suid: *u32) usize { |
| 721 | if (@hasDecl(@This(), "SYS_getresuid32")) { | |
| 722 | return syscall3(SYS_getresuid32, @ptrToInt(ruid), @ptrToInt(euid), @ptrToInt(suid)); | |
| 721 | if (@hasField(SYS, "getresuid32")) { | |
| 722 | return syscall3(.getresuid32, @ptrToInt(ruid), @ptrToInt(euid), @ptrToInt(suid)); | |
| 723 | 723 | } else { |
| 724 | return syscall3(SYS_getresuid, @ptrToInt(ruid), @ptrToInt(euid), @ptrToInt(suid)); | |
| 724 | return syscall3(.getresuid, @ptrToInt(ruid), @ptrToInt(euid), @ptrToInt(suid)); | |
| 725 | 725 | } |
| 726 | 726 | } |
| 727 | 727 | |
| 728 | 728 | pub fn getresgid(rgid: *u32, egid: *u32, sgid: *u32) usize { |
| 729 | if (@hasDecl(@This(), "SYS_getresgid32")) { | |
| 730 | return syscall3(SYS_getresgid32, @ptrToInt(rgid), @ptrToInt(egid), @ptrToInt(sgid)); | |
| 729 | if (@hasField(SYS, "getresgid32")) { | |
| 730 | return syscall3(.getresgid32, @ptrToInt(rgid), @ptrToInt(egid), @ptrToInt(sgid)); | |
| 731 | 731 | } else { |
| 732 | return syscall3(SYS_getresgid, @ptrToInt(rgid), @ptrToInt(egid), @ptrToInt(sgid)); | |
| 732 | return syscall3(.getresgid, @ptrToInt(rgid), @ptrToInt(egid), @ptrToInt(sgid)); | |
| 733 | 733 | } |
| 734 | 734 | } |
| 735 | 735 | |
| 736 | 736 | pub fn setresuid(ruid: u32, euid: u32, suid: u32) usize { |
| 737 | if (@hasDecl(@This(), "SYS_setresuid32")) { | |
| 738 | return syscall3(SYS_setresuid32, ruid, euid, suid); | |
| 737 | if (@hasField(SYS, "setresuid32")) { | |
| 738 | return syscall3(.setresuid32, ruid, euid, suid); | |
| 739 | 739 | } else { |
| 740 | return syscall3(SYS_setresuid, ruid, euid, suid); | |
| 740 | return syscall3(.setresuid, ruid, euid, suid); | |
| 741 | 741 | } |
| 742 | 742 | } |
| 743 | 743 | |
| 744 | 744 | pub fn setresgid(rgid: u32, egid: u32, sgid: u32) usize { |
| 745 | if (@hasDecl(@This(), "SYS_setresgid32")) { | |
| 746 | return syscall3(SYS_setresgid32, rgid, egid, sgid); | |
| 745 | if (@hasField(SYS, "setresgid32")) { | |
| 746 | return syscall3(.setresgid32, rgid, egid, sgid); | |
| 747 | 747 | } else { |
| 748 | return syscall3(SYS_setresgid, rgid, egid, sgid); | |
| 748 | return syscall3(.setresgid, rgid, egid, sgid); | |
| 749 | 749 | } |
| 750 | 750 | } |
| 751 | 751 | |
| 752 | 752 | pub fn getgroups(size: usize, list: *u32) usize { |
| 753 | if (@hasDecl(@This(), "SYS_getgroups32")) { | |
| 754 | return syscall2(SYS_getgroups32, size, @ptrToInt(list)); | |
| 753 | if (@hasField(SYS, "getgroups32")) { | |
| 754 | return syscall2(.getgroups32, size, @ptrToInt(list)); | |
| 755 | 755 | } else { |
| 756 | return syscall2(SYS_getgroups, size, @ptrToInt(list)); | |
| 756 | return syscall2(.getgroups, size, @ptrToInt(list)); | |
| 757 | 757 | } |
| 758 | 758 | } |
| 759 | 759 | |
| 760 | 760 | pub fn setgroups(size: usize, list: *const u32) usize { |
| 761 | if (@hasDecl(@This(), "SYS_setgroups32")) { | |
| 762 | return syscall2(SYS_setgroups32, size, @ptrToInt(list)); | |
| 761 | if (@hasField(SYS, "setgroups32")) { | |
| 762 | return syscall2(.setgroups32, size, @ptrToInt(list)); | |
| 763 | 763 | } else { |
| 764 | return syscall2(SYS_setgroups, size, @ptrToInt(list)); | |
| 764 | return syscall2(.setgroups, size, @ptrToInt(list)); | |
| 765 | 765 | } |
| 766 | 766 | } |
| 767 | 767 | |
| 768 | 768 | pub fn getpid() pid_t { |
| 769 | return @bitCast(pid_t, @truncate(u32, syscall0(SYS_getpid))); | |
| 769 | return @bitCast(pid_t, @truncate(u32, syscall0(.getpid))); | |
| 770 | 770 | } |
| 771 | 771 | |
| 772 | 772 | pub fn gettid() pid_t { |
| 773 | return @bitCast(pid_t, @truncate(u32, syscall0(SYS_gettid))); | |
| 773 | return @bitCast(pid_t, @truncate(u32, syscall0(.gettid))); | |
| 774 | 774 | } |
| 775 | 775 | |
| 776 | 776 | pub fn sigprocmask(flags: u32, noalias set: ?*const sigset_t, noalias oldset: ?*sigset_t) usize { |
| 777 | return syscall4(SYS_rt_sigprocmask, flags, @ptrToInt(set), @ptrToInt(oldset), NSIG / 8); | |
| 777 | return syscall4(.rt_sigprocmask, flags, @ptrToInt(set), @ptrToInt(oldset), NSIG / 8); | |
| 778 | 778 | } |
| 779 | 779 | |
| 780 | 780 | pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigaction) usize { |
| ... | ... | @@ -792,7 +792,7 @@ pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigacti |
| 792 | 792 | var ksa_old: k_sigaction = undefined; |
| 793 | 793 | const ksa_mask_size = @sizeOf(@TypeOf(ksa_old.mask)); |
| 794 | 794 | @memcpy(@ptrCast([*]u8, &ksa.mask), @ptrCast([*]const u8, &act.mask), ksa_mask_size); |
| 795 | const result = syscall4(SYS_rt_sigaction, sig, @ptrToInt(&ksa), @ptrToInt(&ksa_old), ksa_mask_size); | |
| 795 | const result = syscall4(.rt_sigaction, sig, @ptrToInt(&ksa), @ptrToInt(&ksa_old), ksa_mask_size); | |
| 796 | 796 | const err = getErrno(result); |
| 797 | 797 | if (err != 0) { |
| 798 | 798 | return result; |
| ... | ... | @@ -819,42 +819,42 @@ pub fn getsockname(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) us |
| 819 | 819 | if (builtin.arch == .i386) { |
| 820 | 820 | return socketcall(SC_getsockname, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len) }); |
| 821 | 821 | } |
| 822 | return syscall3(SYS_getsockname, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len)); | |
| 822 | return syscall3(.getsockname, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len)); | |
| 823 | 823 | } |
| 824 | 824 | |
| 825 | 825 | pub fn getpeername(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize { |
| 826 | 826 | if (builtin.arch == .i386) { |
| 827 | 827 | return socketcall(SC_getpeername, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len) }); |
| 828 | 828 | } |
| 829 | return syscall3(SYS_getpeername, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len)); | |
| 829 | return syscall3(.getpeername, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len)); | |
| 830 | 830 | } |
| 831 | 831 | |
| 832 | 832 | pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize { |
| 833 | 833 | if (builtin.arch == .i386) { |
| 834 | 834 | return socketcall(SC_socket, &[3]usize{ domain, socket_type, protocol }); |
| 835 | 835 | } |
| 836 | return syscall3(SYS_socket, domain, socket_type, protocol); | |
| 836 | return syscall3(.socket, domain, socket_type, protocol); | |
| 837 | 837 | } |
| 838 | 838 | |
| 839 | 839 | pub fn setsockopt(fd: i32, level: u32, optname: u32, optval: [*]const u8, optlen: socklen_t) usize { |
| 840 | 840 | if (builtin.arch == .i386) { |
| 841 | 841 | return socketcall(SC_setsockopt, &[5]usize{ @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @intCast(usize, optlen) }); |
| 842 | 842 | } |
| 843 | return syscall5(SYS_setsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @intCast(usize, optlen)); | |
| 843 | return syscall5(.setsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @intCast(usize, optlen)); | |
| 844 | 844 | } |
| 845 | 845 | |
| 846 | 846 | pub fn getsockopt(fd: i32, level: u32, optname: u32, noalias optval: [*]u8, noalias optlen: *socklen_t) usize { |
| 847 | 847 | if (builtin.arch == .i386) { |
| 848 | 848 | return socketcall(SC_getsockopt, &[5]usize{ @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen) }); |
| 849 | 849 | } |
| 850 | return syscall5(SYS_getsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen)); | |
| 850 | return syscall5(.getsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen)); | |
| 851 | 851 | } |
| 852 | 852 | |
| 853 | 853 | pub fn sendmsg(fd: i32, msg: *msghdr_const, flags: u32) usize { |
| 854 | 854 | if (builtin.arch == .i386) { |
| 855 | 855 | return socketcall(SC_sendmsg, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags }); |
| 856 | 856 | } |
| 857 | return syscall3(SYS_sendmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags); | |
| 857 | return syscall3(.sendmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags); | |
| 858 | 858 | } |
| 859 | 859 | |
| 860 | 860 | pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize { |
| ... | ... | @@ -872,7 +872,7 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize |
| 872 | 872 | // batch-send all messages up to the current message |
| 873 | 873 | if (next_unsent < i) { |
| 874 | 874 | const batch_size = i - next_unsent; |
| 875 | const r = syscall4(SYS_sendmmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(&msgvec[next_unsent]), batch_size, flags); | |
| 875 | const r = syscall4(.sendmmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(&msgvec[next_unsent]), batch_size, flags); | |
| 876 | 876 | if (getErrno(r) != 0) return next_unsent; |
| 877 | 877 | if (r < batch_size) return next_unsent + r; |
| 878 | 878 | } |
| ... | ... | @@ -888,68 +888,68 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize |
| 888 | 888 | } |
| 889 | 889 | if (next_unsent < kvlen or next_unsent == 0) { // want to make sure at least one syscall occurs (e.g. to trigger MSG_EOR) |
| 890 | 890 | const batch_size = kvlen - next_unsent; |
| 891 | const r = syscall4(SYS_sendmmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(&msgvec[next_unsent]), batch_size, flags); | |
| 891 | const r = syscall4(.sendmmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(&msgvec[next_unsent]), batch_size, flags); | |
| 892 | 892 | if (getErrno(r) != 0) return r; |
| 893 | 893 | return next_unsent + r; |
| 894 | 894 | } |
| 895 | 895 | return kvlen; |
| 896 | 896 | } |
| 897 | return syscall4(SYS_sendmmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msgvec), vlen, flags); | |
| 897 | return syscall4(.sendmmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msgvec), vlen, flags); | |
| 898 | 898 | } |
| 899 | 899 | |
| 900 | 900 | pub fn connect(fd: i32, addr: *const c_void, len: socklen_t) usize { |
| 901 | 901 | if (builtin.arch == .i386) { |
| 902 | 902 | return socketcall(SC_connect, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), len }); |
| 903 | 903 | } |
| 904 | return syscall3(SYS_connect, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), len); | |
| 904 | return syscall3(.connect, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), len); | |
| 905 | 905 | } |
| 906 | 906 | |
| 907 | 907 | pub fn recvmsg(fd: i32, msg: *msghdr, flags: u32) usize { |
| 908 | 908 | if (builtin.arch == .i386) { |
| 909 | 909 | return socketcall(SC_recvmsg, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags }); |
| 910 | 910 | } |
| 911 | return syscall3(SYS_recvmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags); | |
| 911 | return syscall3(.recvmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags); | |
| 912 | 912 | } |
| 913 | 913 | |
| 914 | 914 | pub fn recvfrom(fd: i32, noalias buf: [*]u8, len: usize, flags: u32, noalias addr: ?*sockaddr, noalias alen: ?*socklen_t) usize { |
| 915 | 915 | if (builtin.arch == .i386) { |
| 916 | 916 | return socketcall(SC_recvfrom, &[6]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen) }); |
| 917 | 917 | } |
| 918 | return syscall6(SYS_recvfrom, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen)); | |
| 918 | return syscall6(.recvfrom, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen)); | |
| 919 | 919 | } |
| 920 | 920 | |
| 921 | 921 | pub fn shutdown(fd: i32, how: i32) usize { |
| 922 | 922 | if (builtin.arch == .i386) { |
| 923 | 923 | return socketcall(SC_shutdown, &[2]usize{ @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, how)) }); |
| 924 | 924 | } |
| 925 | return syscall2(SYS_shutdown, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, how))); | |
| 925 | return syscall2(.shutdown, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, how))); | |
| 926 | 926 | } |
| 927 | 927 | |
| 928 | 928 | pub fn bind(fd: i32, addr: *const sockaddr, len: socklen_t) usize { |
| 929 | 929 | if (builtin.arch == .i386) { |
| 930 | 930 | return socketcall(SC_bind, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @intCast(usize, len) }); |
| 931 | 931 | } |
| 932 | return syscall3(SYS_bind, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @intCast(usize, len)); | |
| 932 | return syscall3(.bind, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @intCast(usize, len)); | |
| 933 | 933 | } |
| 934 | 934 | |
| 935 | 935 | pub fn listen(fd: i32, backlog: u32) usize { |
| 936 | 936 | if (builtin.arch == .i386) { |
| 937 | 937 | return socketcall(SC_listen, &[2]usize{ @bitCast(usize, @as(isize, fd)), backlog }); |
| 938 | 938 | } |
| 939 | return syscall2(SYS_listen, @bitCast(usize, @as(isize, fd)), backlog); | |
| 939 | return syscall2(.listen, @bitCast(usize, @as(isize, fd)), backlog); | |
| 940 | 940 | } |
| 941 | 941 | |
| 942 | 942 | pub fn sendto(fd: i32, buf: [*]const u8, len: usize, flags: u32, addr: ?*const sockaddr, alen: socklen_t) usize { |
| 943 | 943 | if (builtin.arch == .i386) { |
| 944 | 944 | return socketcall(SC_sendto, &[6]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @intCast(usize, alen) }); |
| 945 | 945 | } |
| 946 | return syscall6(SYS_sendto, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @intCast(usize, alen)); | |
| 946 | return syscall6(.sendto, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @intCast(usize, alen)); | |
| 947 | 947 | } |
| 948 | 948 | |
| 949 | 949 | pub fn sendfile(outfd: i32, infd: i32, offset: ?*i64, count: usize) usize { |
| 950 | if (@hasDecl(@This(), "SYS_sendfile64")) { | |
| 950 | if (@hasField(SYS, "sendfile64")) { | |
| 951 | 951 | return syscall4( |
| 952 | SYS_sendfile64, | |
| 952 | .sendfile64, | |
| 953 | 953 | @bitCast(usize, @as(isize, outfd)), |
| 954 | 954 | @bitCast(usize, @as(isize, infd)), |
| 955 | 955 | @ptrToInt(offset), |
| ... | ... | @@ -957,7 +957,7 @@ pub fn sendfile(outfd: i32, infd: i32, offset: ?*i64, count: usize) usize { |
| 957 | 957 | ); |
| 958 | 958 | } else { |
| 959 | 959 | return syscall4( |
| 960 | SYS_sendfile, | |
| 960 | .sendfile, | |
| 961 | 961 | @bitCast(usize, @as(isize, outfd)), |
| 962 | 962 | @bitCast(usize, @as(isize, infd)), |
| 963 | 963 | @ptrToInt(offset), |
| ... | ... | @@ -970,7 +970,7 @@ pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) usiz |
| 970 | 970 | if (builtin.arch == .i386) { |
| 971 | 971 | return socketcall(SC_socketpair, &[4]usize{ @intCast(usize, domain), @intCast(usize, socket_type), @intCast(usize, protocol), @ptrToInt(&fd[0]) }); |
| 972 | 972 | } |
| 973 | return syscall4(SYS_socketpair, @intCast(usize, domain), @intCast(usize, socket_type), @intCast(usize, protocol), @ptrToInt(&fd[0])); | |
| 973 | return syscall4(.socketpair, @intCast(usize, domain), @intCast(usize, socket_type), @intCast(usize, protocol), @ptrToInt(&fd[0])); | |
| 974 | 974 | } |
| 975 | 975 | |
| 976 | 976 | pub fn accept(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize { |
| ... | ... | @@ -984,45 +984,45 @@ pub fn accept4(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t, flags: |
| 984 | 984 | if (builtin.arch == .i386) { |
| 985 | 985 | return socketcall(SC_accept4, &[4]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len), flags }); |
| 986 | 986 | } |
| 987 | return syscall4(SYS_accept4, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len), flags); | |
| 987 | return syscall4(.accept4, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len), flags); | |
| 988 | 988 | } |
| 989 | 989 | |
| 990 | 990 | pub fn fstat(fd: i32, stat_buf: *Stat) usize { |
| 991 | if (@hasDecl(@This(), "SYS_fstat64")) { | |
| 992 | return syscall2(SYS_fstat64, @bitCast(usize, @as(isize, fd)), @ptrToInt(stat_buf)); | |
| 991 | if (@hasField(SYS, "fstat64")) { | |
| 992 | return syscall2(.fstat64, @bitCast(usize, @as(isize, fd)), @ptrToInt(stat_buf)); | |
| 993 | 993 | } else { |
| 994 | return syscall2(SYS_fstat, @bitCast(usize, @as(isize, fd)), @ptrToInt(stat_buf)); | |
| 994 | return syscall2(.fstat, @bitCast(usize, @as(isize, fd)), @ptrToInt(stat_buf)); | |
| 995 | 995 | } |
| 996 | 996 | } |
| 997 | 997 | |
| 998 | 998 | pub fn stat(pathname: [*:0]const u8, statbuf: *Stat) usize { |
| 999 | if (@hasDecl(@This(), "SYS_stat64")) { | |
| 1000 | return syscall2(SYS_stat64, @ptrToInt(pathname), @ptrToInt(statbuf)); | |
| 999 | if (@hasField(SYS, "stat64")) { | |
| 1000 | return syscall2(.stat64, @ptrToInt(pathname), @ptrToInt(statbuf)); | |
| 1001 | 1001 | } else { |
| 1002 | return syscall2(SYS_stat, @ptrToInt(pathname), @ptrToInt(statbuf)); | |
| 1002 | return syscall2(.stat, @ptrToInt(pathname), @ptrToInt(statbuf)); | |
| 1003 | 1003 | } |
| 1004 | 1004 | } |
| 1005 | 1005 | |
| 1006 | 1006 | pub fn lstat(pathname: [*:0]const u8, statbuf: *Stat) usize { |
| 1007 | if (@hasDecl(@This(), "SYS_lstat64")) { | |
| 1008 | return syscall2(SYS_lstat64, @ptrToInt(pathname), @ptrToInt(statbuf)); | |
| 1007 | if (@hasField(SYS, "lstat64")) { | |
| 1008 | return syscall2(.lstat64, @ptrToInt(pathname), @ptrToInt(statbuf)); | |
| 1009 | 1009 | } else { |
| 1010 | return syscall2(SYS_lstat, @ptrToInt(pathname), @ptrToInt(statbuf)); | |
| 1010 | return syscall2(.lstat, @ptrToInt(pathname), @ptrToInt(statbuf)); | |
| 1011 | 1011 | } |
| 1012 | 1012 | } |
| 1013 | 1013 | |
| 1014 | 1014 | pub fn fstatat(dirfd: i32, path: [*:0]const u8, stat_buf: *Stat, flags: u32) usize { |
| 1015 | if (@hasDecl(@This(), "SYS_fstatat64")) { | |
| 1016 | return syscall4(SYS_fstatat64, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags); | |
| 1015 | if (@hasField(SYS, "fstatat64")) { | |
| 1016 | return syscall4(.fstatat64, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags); | |
| 1017 | 1017 | } else { |
| 1018 | return syscall4(SYS_fstatat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags); | |
| 1018 | return syscall4(.fstatat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags); | |
| 1019 | 1019 | } |
| 1020 | 1020 | } |
| 1021 | 1021 | |
| 1022 | 1022 | pub fn statx(dirfd: i32, path: [*]const u8, flags: u32, mask: u32, statx_buf: *Statx) usize { |
| 1023 | if (@hasDecl(@This(), "SYS_statx")) { | |
| 1023 | if (@hasField(SYS, "statx")) { | |
| 1024 | 1024 | return syscall5( |
| 1025 | SYS_statx, | |
| 1025 | .statx, | |
| 1026 | 1026 | @bitCast(usize, @as(isize, dirfd)), |
| 1027 | 1027 | @ptrToInt(path), |
| 1028 | 1028 | flags, |
| ... | ... | @@ -1034,59 +1034,59 @@ pub fn statx(dirfd: i32, path: [*]const u8, flags: u32, mask: u32, statx_buf: *S |
| 1034 | 1034 | } |
| 1035 | 1035 | |
| 1036 | 1036 | pub fn listxattr(path: [*:0]const u8, list: [*]u8, size: usize) usize { |
| 1037 | return syscall3(SYS_listxattr, @ptrToInt(path), @ptrToInt(list), size); | |
| 1037 | return syscall3(.listxattr, @ptrToInt(path), @ptrToInt(list), size); | |
| 1038 | 1038 | } |
| 1039 | 1039 | |
| 1040 | 1040 | pub fn llistxattr(path: [*:0]const u8, list: [*]u8, size: usize) usize { |
| 1041 | return syscall3(SYS_llistxattr, @ptrToInt(path), @ptrToInt(list), size); | |
| 1041 | return syscall3(.llistxattr, @ptrToInt(path), @ptrToInt(list), size); | |
| 1042 | 1042 | } |
| 1043 | 1043 | |
| 1044 | 1044 | pub fn flistxattr(fd: usize, list: [*]u8, size: usize) usize { |
| 1045 | return syscall3(SYS_flistxattr, fd, @ptrToInt(list), size); | |
| 1045 | return syscall3(.flistxattr, fd, @ptrToInt(list), size); | |
| 1046 | 1046 | } |
| 1047 | 1047 | |
| 1048 | 1048 | pub fn getxattr(path: [*:0]const u8, name: [*:0]const u8, value: [*]u8, size: usize) usize { |
| 1049 | return syscall4(SYS_getxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size); | |
| 1049 | return syscall4(.getxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size); | |
| 1050 | 1050 | } |
| 1051 | 1051 | |
| 1052 | 1052 | pub fn lgetxattr(path: [*:0]const u8, name: [*:0]const u8, value: [*]u8, size: usize) usize { |
| 1053 | return syscall4(SYS_lgetxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size); | |
| 1053 | return syscall4(.lgetxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size); | |
| 1054 | 1054 | } |
| 1055 | 1055 | |
| 1056 | 1056 | pub fn fgetxattr(fd: usize, name: [*:0]const u8, value: [*]u8, size: usize) usize { |
| 1057 | return syscall4(SYS_lgetxattr, fd, @ptrToInt(name), @ptrToInt(value), size); | |
| 1057 | return syscall4(.lgetxattr, fd, @ptrToInt(name), @ptrToInt(value), size); | |
| 1058 | 1058 | } |
| 1059 | 1059 | |
| 1060 | 1060 | pub fn setxattr(path: [*:0]const u8, name: [*:0]const u8, value: *const void, size: usize, flags: usize) usize { |
| 1061 | return syscall5(SYS_setxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size, flags); | |
| 1061 | return syscall5(.setxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size, flags); | |
| 1062 | 1062 | } |
| 1063 | 1063 | |
| 1064 | 1064 | pub fn lsetxattr(path: [*:0]const u8, name: [*:0]const u8, value: *const void, size: usize, flags: usize) usize { |
| 1065 | return syscall5(SYS_lsetxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size, flags); | |
| 1065 | return syscall5(.lsetxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size, flags); | |
| 1066 | 1066 | } |
| 1067 | 1067 | |
| 1068 | 1068 | pub fn fsetxattr(fd: usize, name: [*:0]const u8, value: *const void, size: usize, flags: usize) usize { |
| 1069 | return syscall5(SYS_fsetxattr, fd, @ptrToInt(name), @ptrToInt(value), size, flags); | |
| 1069 | return syscall5(.fsetxattr, fd, @ptrToInt(name), @ptrToInt(value), size, flags); | |
| 1070 | 1070 | } |
| 1071 | 1071 | |
| 1072 | 1072 | pub fn removexattr(path: [*:0]const u8, name: [*:0]const u8) usize { |
| 1073 | return syscall2(SYS_removexattr, @ptrToInt(path), @ptrToInt(name)); | |
| 1073 | return syscall2(.removexattr, @ptrToInt(path), @ptrToInt(name)); | |
| 1074 | 1074 | } |
| 1075 | 1075 | |
| 1076 | 1076 | pub fn lremovexattr(path: [*:0]const u8, name: [*:0]const u8) usize { |
| 1077 | return syscall2(SYS_lremovexattr, @ptrToInt(path), @ptrToInt(name)); | |
| 1077 | return syscall2(.lremovexattr, @ptrToInt(path), @ptrToInt(name)); | |
| 1078 | 1078 | } |
| 1079 | 1079 | |
| 1080 | 1080 | pub fn fremovexattr(fd: usize, name: [*:0]const u8) usize { |
| 1081 | return syscall2(SYS_fremovexattr, fd, @ptrToInt(name)); | |
| 1081 | return syscall2(.fremovexattr, fd, @ptrToInt(name)); | |
| 1082 | 1082 | } |
| 1083 | 1083 | |
| 1084 | 1084 | pub fn sched_yield() usize { |
| 1085 | return syscall0(SYS_sched_yield); | |
| 1085 | return syscall0(.sched_yield); | |
| 1086 | 1086 | } |
| 1087 | 1087 | |
| 1088 | 1088 | pub fn sched_getaffinity(pid: pid_t, size: usize, set: *cpu_set_t) usize { |
| 1089 | const rc = syscall3(SYS_sched_getaffinity, @bitCast(usize, @as(isize, pid)), size, @ptrToInt(set)); | |
| 1089 | const rc = syscall3(.sched_getaffinity, @bitCast(usize, @as(isize, pid)), size, @ptrToInt(set)); | |
| 1090 | 1090 | if (@bitCast(isize, rc) < 0) return rc; |
| 1091 | 1091 | if (rc < size) @memset(@ptrCast([*]u8, set) + rc, 0, size - rc); |
| 1092 | 1092 | return 0; |
| ... | ... | @@ -1097,11 +1097,11 @@ pub fn epoll_create() usize { |
| 1097 | 1097 | } |
| 1098 | 1098 | |
| 1099 | 1099 | pub fn epoll_create1(flags: usize) usize { |
| 1100 | return syscall1(SYS_epoll_create1, flags); | |
| 1100 | return syscall1(.epoll_create1, flags); | |
| 1101 | 1101 | } |
| 1102 | 1102 | |
| 1103 | 1103 | pub fn epoll_ctl(epoll_fd: i32, op: u32, fd: i32, ev: ?*epoll_event) usize { |
| 1104 | return syscall4(SYS_epoll_ctl, @bitCast(usize, @as(isize, epoll_fd)), @intCast(usize, op), @bitCast(usize, @as(isize, fd)), @ptrToInt(ev)); | |
| 1104 | return syscall4(.epoll_ctl, @bitCast(usize, @as(isize, epoll_fd)), @intCast(usize, op), @bitCast(usize, @as(isize, fd)), @ptrToInt(ev)); | |
| 1105 | 1105 | } |
| 1106 | 1106 | |
| 1107 | 1107 | pub fn epoll_wait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32) usize { |
| ... | ... | @@ -1110,7 +1110,7 @@ pub fn epoll_wait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout |
| 1110 | 1110 | |
| 1111 | 1111 | pub fn epoll_pwait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32, sigmask: ?*sigset_t) usize { |
| 1112 | 1112 | return syscall6( |
| 1113 | SYS_epoll_pwait, | |
| 1113 | .epoll_pwait, | |
| 1114 | 1114 | @bitCast(usize, @as(isize, epoll_fd)), |
| 1115 | 1115 | @ptrToInt(events), |
| 1116 | 1116 | @intCast(usize, maxevents), |
| ... | ... | @@ -1121,11 +1121,11 @@ pub fn epoll_pwait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeou |
| 1121 | 1121 | } |
| 1122 | 1122 | |
| 1123 | 1123 | pub fn eventfd(count: u32, flags: u32) usize { |
| 1124 | return syscall2(SYS_eventfd2, count, flags); | |
| 1124 | return syscall2(.eventfd2, count, flags); | |
| 1125 | 1125 | } |
| 1126 | 1126 | |
| 1127 | 1127 | pub fn timerfd_create(clockid: i32, flags: u32) usize { |
| 1128 | return syscall2(SYS_timerfd_create, @bitCast(usize, @as(isize, clockid)), flags); | |
| 1128 | return syscall2(.timerfd_create, @bitCast(usize, @as(isize, clockid)), flags); | |
| 1129 | 1129 | } |
| 1130 | 1130 | |
| 1131 | 1131 | pub const itimerspec = extern struct { |
| ... | ... | @@ -1134,59 +1134,59 @@ pub const itimerspec = extern struct { |
| 1134 | 1134 | }; |
| 1135 | 1135 | |
| 1136 | 1136 | pub fn timerfd_gettime(fd: i32, curr_value: *itimerspec) usize { |
| 1137 | return syscall2(SYS_timerfd_gettime, @bitCast(usize, @as(isize, fd)), @ptrToInt(curr_value)); | |
| 1137 | return syscall2(.timerfd_gettime, @bitCast(usize, @as(isize, fd)), @ptrToInt(curr_value)); | |
| 1138 | 1138 | } |
| 1139 | 1139 | |
| 1140 | 1140 | pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const itimerspec, old_value: ?*itimerspec) usize { |
| 1141 | return syscall4(SYS_timerfd_settime, @bitCast(usize, @as(isize, fd)), flags, @ptrToInt(new_value), @ptrToInt(old_value)); | |
| 1141 | return syscall4(.timerfd_settime, @bitCast(usize, @as(isize, fd)), flags, @ptrToInt(new_value), @ptrToInt(old_value)); | |
| 1142 | 1142 | } |
| 1143 | 1143 | |
| 1144 | 1144 | pub fn unshare(flags: usize) usize { |
| 1145 | return syscall1(SYS_unshare, flags); | |
| 1145 | return syscall1(.unshare, flags); | |
| 1146 | 1146 | } |
| 1147 | 1147 | |
| 1148 | 1148 | pub fn capget(hdrp: *cap_user_header_t, datap: *cap_user_data_t) usize { |
| 1149 | return syscall2(SYS_capget, @ptrToInt(hdrp), @ptrToInt(datap)); | |
| 1149 | return syscall2(.capget, @ptrToInt(hdrp), @ptrToInt(datap)); | |
| 1150 | 1150 | } |
| 1151 | 1151 | |
| 1152 | 1152 | pub fn capset(hdrp: *cap_user_header_t, datap: *const cap_user_data_t) usize { |
| 1153 | return syscall2(SYS_capset, @ptrToInt(hdrp), @ptrToInt(datap)); | |
| 1153 | return syscall2(.capset, @ptrToInt(hdrp), @ptrToInt(datap)); | |
| 1154 | 1154 | } |
| 1155 | 1155 | |
| 1156 | 1156 | pub fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) usize { |
| 1157 | return syscall2(SYS_sigaltstack, @ptrToInt(ss), @ptrToInt(old_ss)); | |
| 1157 | return syscall2(.sigaltstack, @ptrToInt(ss), @ptrToInt(old_ss)); | |
| 1158 | 1158 | } |
| 1159 | 1159 | |
| 1160 | 1160 | pub fn uname(uts: *utsname) usize { |
| 1161 | return syscall1(SYS_uname, @ptrToInt(uts)); | |
| 1161 | return syscall1(.uname, @ptrToInt(uts)); | |
| 1162 | 1162 | } |
| 1163 | 1163 | |
| 1164 | 1164 | pub fn io_uring_setup(entries: u32, p: *io_uring_params) usize { |
| 1165 | return syscall2(SYS_io_uring_setup, entries, @ptrToInt(p)); | |
| 1165 | return syscall2(.io_uring_setup, entries, @ptrToInt(p)); | |
| 1166 | 1166 | } |
| 1167 | 1167 | |
| 1168 | 1168 | pub fn io_uring_enter(fd: i32, to_submit: u32, min_complete: u32, flags: u32, sig: ?*sigset_t) usize { |
| 1169 | return syscall6(SYS_io_uring_enter, @bitCast(usize, @as(isize, fd)), to_submit, min_complete, flags, @ptrToInt(sig), NSIG / 8); | |
| 1169 | return syscall6(.io_uring_enter, @bitCast(usize, @as(isize, fd)), to_submit, min_complete, flags, @ptrToInt(sig), NSIG / 8); | |
| 1170 | 1170 | } |
| 1171 | 1171 | |
| 1172 | pub fn io_uring_register(fd: i32, opcode: u32, arg: ?*const c_void, nr_args: u32) usize { | |
| 1173 | return syscall4(SYS_io_uring_register, @bitCast(usize, @as(isize, fd)), opcode, @ptrToInt(arg), nr_args); | |
| 1172 | pub fn io_uring_register(fd: i32, opcode: IORING_REGISTER, arg: ?*const c_void, nr_args: u32) usize { | |
| 1173 | return syscall4(.io_uring_register, @bitCast(usize, @as(isize, fd)), @enumToInt(opcode), @ptrToInt(arg), nr_args); | |
| 1174 | 1174 | } |
| 1175 | 1175 | |
| 1176 | 1176 | pub fn memfd_create(name: [*:0]const u8, flags: u32) usize { |
| 1177 | return syscall2(SYS_memfd_create, @ptrToInt(name), flags); | |
| 1177 | return syscall2(.memfd_create, @ptrToInt(name), flags); | |
| 1178 | 1178 | } |
| 1179 | 1179 | |
| 1180 | 1180 | pub fn getrusage(who: i32, usage: *rusage) usize { |
| 1181 | return syscall2(SYS_getrusage, @bitCast(usize, @as(isize, who)), @ptrToInt(usage)); | |
| 1181 | return syscall2(.getrusage, @bitCast(usize, @as(isize, who)), @ptrToInt(usage)); | |
| 1182 | 1182 | } |
| 1183 | 1183 | |
| 1184 | 1184 | pub fn tcgetattr(fd: fd_t, termios_p: *termios) usize { |
| 1185 | return syscall3(SYS_ioctl, @bitCast(usize, @as(isize, fd)), TCGETS, @ptrToInt(termios_p)); | |
| 1185 | return syscall3(.ioctl, @bitCast(usize, @as(isize, fd)), TCGETS, @ptrToInt(termios_p)); | |
| 1186 | 1186 | } |
| 1187 | 1187 | |
| 1188 | 1188 | pub fn tcsetattr(fd: fd_t, optional_action: TCSA, termios_p: *const termios) usize { |
| 1189 | return syscall3(SYS_ioctl, @bitCast(usize, @as(isize, fd)), TCSETS + @enumToInt(optional_action), @ptrToInt(termios_p)); | |
| 1189 | return syscall3(.ioctl, @bitCast(usize, @as(isize, fd)), TCSETS + @enumToInt(optional_action), @ptrToInt(termios_p)); | |
| 1190 | 1190 | } |
| 1191 | 1191 | |
| 1192 | 1192 | test "" { |
lib/std/os/linux/arm-eabi.zig+16-16| ... | ... | @@ -1,36 +1,36 @@ |
| 1 | 1 | usingnamespace @import("../bits.zig"); |
| 2 | 2 | |
| 3 | pub fn syscall0(number: usize) usize { | |
| 3 | pub fn syscall0(number: SYS) usize { | |
| 4 | 4 | return asm volatile ("svc #0" |
| 5 | 5 | : [ret] "={r0}" (-> usize) |
| 6 | : [number] "{r7}" (number) | |
| 6 | : [number] "{r7}" (@enumToInt(number)) | |
| 7 | 7 | : "memory" |
| 8 | 8 | ); |
| 9 | 9 | } |
| 10 | 10 | |
| 11 | pub fn syscall1(number: usize, arg1: usize) usize { | |
| 11 | pub fn syscall1(number: SYS, arg1: usize) usize { | |
| 12 | 12 | return asm volatile ("svc #0" |
| 13 | 13 | : [ret] "={r0}" (-> usize) |
| 14 | : [number] "{r7}" (number), | |
| 14 | : [number] "{r7}" (@enumToInt(number)), | |
| 15 | 15 | [arg1] "{r0}" (arg1) |
| 16 | 16 | : "memory" |
| 17 | 17 | ); |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize { | |
| 20 | pub fn syscall2(number: SYS, arg1: usize, arg2: usize) usize { | |
| 21 | 21 | return asm volatile ("svc #0" |
| 22 | 22 | : [ret] "={r0}" (-> usize) |
| 23 | : [number] "{r7}" (number), | |
| 23 | : [number] "{r7}" (@enumToInt(number)), | |
| 24 | 24 | [arg1] "{r0}" (arg1), |
| 25 | 25 | [arg2] "{r1}" (arg2) |
| 26 | 26 | : "memory" |
| 27 | 27 | ); |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize { | |
| 30 | pub fn syscall3(number: SYS, arg1: usize, arg2: usize, arg3: usize) usize { | |
| 31 | 31 | return asm volatile ("svc #0" |
| 32 | 32 | : [ret] "={r0}" (-> usize) |
| 33 | : [number] "{r7}" (number), | |
| 33 | : [number] "{r7}" (@enumToInt(number)), | |
| 34 | 34 | [arg1] "{r0}" (arg1), |
| 35 | 35 | [arg2] "{r1}" (arg2), |
| 36 | 36 | [arg3] "{r2}" (arg3) |
| ... | ... | @@ -38,10 +38,10 @@ pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize { |
| 38 | 38 | ); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize { | |
| 41 | pub fn syscall4(number: SYS, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize { | |
| 42 | 42 | return asm volatile ("svc #0" |
| 43 | 43 | : [ret] "={r0}" (-> usize) |
| 44 | : [number] "{r7}" (number), | |
| 44 | : [number] "{r7}" (@enumToInt(number)), | |
| 45 | 45 | [arg1] "{r0}" (arg1), |
| 46 | 46 | [arg2] "{r1}" (arg2), |
| 47 | 47 | [arg3] "{r2}" (arg3), |
| ... | ... | @@ -50,10 +50,10 @@ pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz |
| 50 | 50 | ); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize { | |
| 53 | pub fn syscall5(number: SYS, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize { | |
| 54 | 54 | return asm volatile ("svc #0" |
| 55 | 55 | : [ret] "={r0}" (-> usize) |
| 56 | : [number] "{r7}" (number), | |
| 56 | : [number] "{r7}" (@enumToInt(number)), | |
| 57 | 57 | [arg1] "{r0}" (arg1), |
| 58 | 58 | [arg2] "{r1}" (arg2), |
| 59 | 59 | [arg3] "{r2}" (arg3), |
| ... | ... | @@ -64,7 +64,7 @@ pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | pub fn syscall6( |
| 67 | number: usize, | |
| 67 | number: SYS, | |
| 68 | 68 | arg1: usize, |
| 69 | 69 | arg2: usize, |
| 70 | 70 | arg3: usize, |
| ... | ... | @@ -74,7 +74,7 @@ pub fn syscall6( |
| 74 | 74 | ) usize { |
| 75 | 75 | return asm volatile ("svc #0" |
| 76 | 76 | : [ret] "={r0}" (-> usize) |
| 77 | : [number] "{r7}" (number), | |
| 77 | : [number] "{r7}" (@enumToInt(number)), | |
| 78 | 78 | [arg1] "{r0}" (arg1), |
| 79 | 79 | [arg2] "{r1}" (arg2), |
| 80 | 80 | [arg3] "{r2}" (arg3), |
| ... | ... | @@ -91,7 +91,7 @@ pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, a |
| 91 | 91 | pub fn restore() callconv(.Naked) void { |
| 92 | 92 | return asm volatile ("svc #0" |
| 93 | 93 | : |
| 94 | : [number] "{r7}" (@as(usize, SYS_sigreturn)) | |
| 94 | : [number] "{r7}" (@enumToInt(SYS.sigreturn)) | |
| 95 | 95 | : "memory" |
| 96 | 96 | ); |
| 97 | 97 | } |
| ... | ... | @@ -99,7 +99,7 @@ pub fn restore() callconv(.Naked) void { |
| 99 | 99 | pub fn restore_rt() callconv(.Naked) void { |
| 100 | 100 | return asm volatile ("svc #0" |
| 101 | 101 | : |
| 102 | : [number] "{r7}" (@as(usize, SYS_rt_sigreturn)) | |
| 102 | : [number] "{r7}" (@enumToInt(SYS.rt_sigreturn)) | |
| 103 | 103 | : "memory" |
| 104 | 104 | ); |
| 105 | 105 | } |
lib/std/os/linux/arm64.zig+15-15| ... | ... | @@ -1,36 +1,36 @@ |
| 1 | 1 | usingnamespace @import("../bits.zig"); |
| 2 | 2 | |
| 3 | pub fn syscall0(number: usize) usize { | |
| 3 | pub fn syscall0(number: SYS) usize { | |
| 4 | 4 | return asm volatile ("svc #0" |
| 5 | 5 | : [ret] "={x0}" (-> usize) |
| 6 | : [number] "{x8}" (number) | |
| 6 | : [number] "{x8}" (@enumToInt(number)) | |
| 7 | 7 | : "memory", "cc" |
| 8 | 8 | ); |
| 9 | 9 | } |
| 10 | 10 | |
| 11 | pub fn syscall1(number: usize, arg1: usize) usize { | |
| 11 | pub fn syscall1(number: SYS, arg1: usize) usize { | |
| 12 | 12 | return asm volatile ("svc #0" |
| 13 | 13 | : [ret] "={x0}" (-> usize) |
| 14 | : [number] "{x8}" (number), | |
| 14 | : [number] "{x8}" (@enumToInt(number)), | |
| 15 | 15 | [arg1] "{x0}" (arg1) |
| 16 | 16 | : "memory", "cc" |
| 17 | 17 | ); |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize { | |
| 20 | pub fn syscall2(number: SYS, arg1: usize, arg2: usize) usize { | |
| 21 | 21 | return asm volatile ("svc #0" |
| 22 | 22 | : [ret] "={x0}" (-> usize) |
| 23 | : [number] "{x8}" (number), | |
| 23 | : [number] "{x8}" (@enumToInt(number)), | |
| 24 | 24 | [arg1] "{x0}" (arg1), |
| 25 | 25 | [arg2] "{x1}" (arg2) |
| 26 | 26 | : "memory", "cc" |
| 27 | 27 | ); |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize { | |
| 30 | pub fn syscall3(number: SYS, arg1: usize, arg2: usize, arg3: usize) usize { | |
| 31 | 31 | return asm volatile ("svc #0" |
| 32 | 32 | : [ret] "={x0}" (-> usize) |
| 33 | : [number] "{x8}" (number), | |
| 33 | : [number] "{x8}" (@enumToInt(number)), | |
| 34 | 34 | [arg1] "{x0}" (arg1), |
| 35 | 35 | [arg2] "{x1}" (arg2), |
| 36 | 36 | [arg3] "{x2}" (arg3) |
| ... | ... | @@ -38,10 +38,10 @@ pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize { |
| 38 | 38 | ); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize { | |
| 41 | pub fn syscall4(number: SYS, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize { | |
| 42 | 42 | return asm volatile ("svc #0" |
| 43 | 43 | : [ret] "={x0}" (-> usize) |
| 44 | : [number] "{x8}" (number), | |
| 44 | : [number] "{x8}" (@enumToInt(number)), | |
| 45 | 45 | [arg1] "{x0}" (arg1), |
| 46 | 46 | [arg2] "{x1}" (arg2), |
| 47 | 47 | [arg3] "{x2}" (arg3), |
| ... | ... | @@ -50,10 +50,10 @@ pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz |
| 50 | 50 | ); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize { | |
| 53 | pub fn syscall5(number: SYS, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize { | |
| 54 | 54 | return asm volatile ("svc #0" |
| 55 | 55 | : [ret] "={x0}" (-> usize) |
| 56 | : [number] "{x8}" (number), | |
| 56 | : [number] "{x8}" (@enumToInt(number)), | |
| 57 | 57 | [arg1] "{x0}" (arg1), |
| 58 | 58 | [arg2] "{x1}" (arg2), |
| 59 | 59 | [arg3] "{x2}" (arg3), |
| ... | ... | @@ -64,7 +64,7 @@ pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | pub fn syscall6( |
| 67 | number: usize, | |
| 67 | number: SYS, | |
| 68 | 68 | arg1: usize, |
| 69 | 69 | arg2: usize, |
| 70 | 70 | arg3: usize, |
| ... | ... | @@ -74,7 +74,7 @@ pub fn syscall6( |
| 74 | 74 | ) usize { |
| 75 | 75 | return asm volatile ("svc #0" |
| 76 | 76 | : [ret] "={x0}" (-> usize) |
| 77 | : [number] "{x8}" (number), | |
| 77 | : [number] "{x8}" (@enumToInt(number)), | |
| 78 | 78 | [arg1] "{x0}" (arg1), |
| 79 | 79 | [arg2] "{x1}" (arg2), |
| 80 | 80 | [arg3] "{x2}" (arg3), |
| ... | ... | @@ -93,7 +93,7 @@ pub const restore = restore_rt; |
| 93 | 93 | pub fn restore_rt() callconv(.Naked) void { |
| 94 | 94 | return asm volatile ("svc #0" |
| 95 | 95 | : |
| 96 | : [number] "{x8}" (@as(usize, SYS_rt_sigreturn)) | |
| 96 | : [number] "{x8}" (@enumToInt(SYS.rt_sigreturn)) | |
| 97 | 97 | : "memory", "cc" |
| 98 | 98 | ); |
| 99 | 99 | } |
lib/std/os/linux/i386.zig+17-17| ... | ... | @@ -1,36 +1,36 @@ |
| 1 | 1 | usingnamespace @import("../bits.zig"); |
| 2 | 2 | |
| 3 | pub fn syscall0(number: usize) usize { | |
| 3 | pub fn syscall0(number: SYS) usize { | |
| 4 | 4 | return asm volatile ("int $0x80" |
| 5 | 5 | : [ret] "={eax}" (-> usize) |
| 6 | : [number] "{eax}" (number) | |
| 6 | : [number] "{eax}" (@enumToInt(number)) | |
| 7 | 7 | : "memory" |
| 8 | 8 | ); |
| 9 | 9 | } |
| 10 | 10 | |
| 11 | pub fn syscall1(number: usize, arg1: usize) usize { | |
| 11 | pub fn syscall1(number: SYS, arg1: usize) usize { | |
| 12 | 12 | return asm volatile ("int $0x80" |
| 13 | 13 | : [ret] "={eax}" (-> usize) |
| 14 | : [number] "{eax}" (number), | |
| 14 | : [number] "{eax}" (@enumToInt(number)), | |
| 15 | 15 | [arg1] "{ebx}" (arg1) |
| 16 | 16 | : "memory" |
| 17 | 17 | ); |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize { | |
| 20 | pub fn syscall2(number: SYS, arg1: usize, arg2: usize) usize { | |
| 21 | 21 | return asm volatile ("int $0x80" |
| 22 | 22 | : [ret] "={eax}" (-> usize) |
| 23 | : [number] "{eax}" (number), | |
| 23 | : [number] "{eax}" (@enumToInt(number)), | |
| 24 | 24 | [arg1] "{ebx}" (arg1), |
| 25 | 25 | [arg2] "{ecx}" (arg2) |
| 26 | 26 | : "memory" |
| 27 | 27 | ); |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize { | |
| 30 | pub fn syscall3(number: SYS, arg1: usize, arg2: usize, arg3: usize) usize { | |
| 31 | 31 | return asm volatile ("int $0x80" |
| 32 | 32 | : [ret] "={eax}" (-> usize) |
| 33 | : [number] "{eax}" (number), | |
| 33 | : [number] "{eax}" (@enumToInt(number)), | |
| 34 | 34 | [arg1] "{ebx}" (arg1), |
| 35 | 35 | [arg2] "{ecx}" (arg2), |
| 36 | 36 | [arg3] "{edx}" (arg3) |
| ... | ... | @@ -38,10 +38,10 @@ pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize { |
| 38 | 38 | ); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize { | |
| 41 | pub fn syscall4(number: SYS, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize { | |
| 42 | 42 | return asm volatile ("int $0x80" |
| 43 | 43 | : [ret] "={eax}" (-> usize) |
| 44 | : [number] "{eax}" (number), | |
| 44 | : [number] "{eax}" (@enumToInt(number)), | |
| 45 | 45 | [arg1] "{ebx}" (arg1), |
| 46 | 46 | [arg2] "{ecx}" (arg2), |
| 47 | 47 | [arg3] "{edx}" (arg3), |
| ... | ... | @@ -50,10 +50,10 @@ pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz |
| 50 | 50 | ); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize { | |
| 53 | pub fn syscall5(number: SYS, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize { | |
| 54 | 54 | return asm volatile ("int $0x80" |
| 55 | 55 | : [ret] "={eax}" (-> usize) |
| 56 | : [number] "{eax}" (number), | |
| 56 | : [number] "{eax}" (@enumToInt(number)), | |
| 57 | 57 | [arg1] "{ebx}" (arg1), |
| 58 | 58 | [arg2] "{ecx}" (arg2), |
| 59 | 59 | [arg3] "{edx}" (arg3), |
| ... | ... | @@ -64,7 +64,7 @@ pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | pub fn syscall6( |
| 67 | number: usize, | |
| 67 | number: SYS, | |
| 68 | 68 | arg1: usize, |
| 69 | 69 | arg2: usize, |
| 70 | 70 | arg3: usize, |
| ... | ... | @@ -84,7 +84,7 @@ pub fn syscall6( |
| 84 | 84 | \\ pop %%ebp |
| 85 | 85 | \\ add $4, %%esp |
| 86 | 86 | : [ret] "={eax}" (-> usize) |
| 87 | : [number] "{eax}" (number), | |
| 87 | : [number] "{eax}" (@enumToInt(number)), | |
| 88 | 88 | [arg1] "{ebx}" (arg1), |
| 89 | 89 | [arg2] "{ecx}" (arg2), |
| 90 | 90 | [arg3] "{edx}" (arg3), |
| ... | ... | @@ -98,7 +98,7 @@ pub fn syscall6( |
| 98 | 98 | pub fn socketcall(call: usize, args: [*]usize) usize { |
| 99 | 99 | return asm volatile ("int $0x80" |
| 100 | 100 | : [ret] "={eax}" (-> usize) |
| 101 | : [number] "{eax}" (@as(usize, SYS_socketcall)), | |
| 101 | : [number] "{eax}" (@enumToInt(SYS.socketcall)), | |
| 102 | 102 | [arg1] "{ebx}" (call), |
| 103 | 103 | [arg2] "{ecx}" (@ptrToInt(args)) |
| 104 | 104 | : "memory" |
| ... | ... | @@ -111,7 +111,7 @@ pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, a |
| 111 | 111 | pub fn restore() callconv(.Naked) void { |
| 112 | 112 | return asm volatile ("int $0x80" |
| 113 | 113 | : |
| 114 | : [number] "{eax}" (@as(usize, SYS_sigreturn)) | |
| 114 | : [number] "{eax}" (@enumToInt(SYS.sigreturn)) | |
| 115 | 115 | : "memory" |
| 116 | 116 | ); |
| 117 | 117 | } |
| ... | ... | @@ -119,7 +119,7 @@ pub fn restore() callconv(.Naked) void { |
| 119 | 119 | pub fn restore_rt() callconv(.Naked) void { |
| 120 | 120 | return asm volatile ("int $0x80" |
| 121 | 121 | : |
| 122 | : [number] "{eax}" (@as(usize, SYS_rt_sigreturn)) | |
| 122 | : [number] "{eax}" (@enumToInt(SYS.rt_sigreturn)) | |
| 123 | 123 | : "memory" |
| 124 | 124 | ); |
| 125 | 125 | } |
lib/std/os/linux/mipsel.zig+17-17| ... | ... | @@ -1,13 +1,13 @@ |
| 1 | 1 | usingnamespace @import("../bits.zig"); |
| 2 | 2 | |
| 3 | pub fn syscall0(number: usize) usize { | |
| 3 | pub fn syscall0(number: SYS) usize { | |
| 4 | 4 | return asm volatile ( |
| 5 | 5 | \\ syscall |
| 6 | 6 | \\ blez $7, 1f |
| 7 | 7 | \\ subu $2, $0, $2 |
| 8 | 8 | \\ 1: |
| 9 | 9 | : [ret] "={$2}" (-> usize) |
| 10 | : [number] "{$2}" (number) | |
| 10 | : [number] "{$2}" (@enumToInt(number)) | |
| 11 | 11 | : "memory", "cc", "$7" |
| 12 | 12 | ); |
| 13 | 13 | } |
| ... | ... | @@ -26,46 +26,46 @@ pub fn syscall_pipe(fd: *[2]i32) usize { |
| 26 | 26 | \\ sw $3, 4($4) |
| 27 | 27 | \\ 2: |
| 28 | 28 | : [ret] "={$2}" (-> usize) |
| 29 | : [number] "{$2}" (@as(usize, SYS_pipe)) | |
| 29 | : [number] "{$2}" (@enumToInt(SYS.pipe)) | |
| 30 | 30 | : "memory", "cc", "$7" |
| 31 | 31 | ); |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | pub fn syscall1(number: usize, arg1: usize) usize { | |
| 34 | pub fn syscall1(number: SYS, arg1: usize) usize { | |
| 35 | 35 | return asm volatile ( |
| 36 | 36 | \\ syscall |
| 37 | 37 | \\ blez $7, 1f |
| 38 | 38 | \\ subu $2, $0, $2 |
| 39 | 39 | \\ 1: |
| 40 | 40 | : [ret] "={$2}" (-> usize) |
| 41 | : [number] "{$2}" (number), | |
| 41 | : [number] "{$2}" (@enumToInt(number)), | |
| 42 | 42 | [arg1] "{$4}" (arg1) |
| 43 | 43 | : "memory", "cc", "$7" |
| 44 | 44 | ); |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize { | |
| 47 | pub fn syscall2(number: SYS, arg1: usize, arg2: usize) usize { | |
| 48 | 48 | return asm volatile ( |
| 49 | 49 | \\ syscall |
| 50 | 50 | \\ blez $7, 1f |
| 51 | 51 | \\ subu $2, $0, $2 |
| 52 | 52 | \\ 1: |
| 53 | 53 | : [ret] "={$2}" (-> usize) |
| 54 | : [number] "{$2}" (number), | |
| 54 | : [number] "{$2}" (@enumToInt(number)), | |
| 55 | 55 | [arg1] "{$4}" (arg1), |
| 56 | 56 | [arg2] "{$5}" (arg2) |
| 57 | 57 | : "memory", "cc", "$7" |
| 58 | 58 | ); |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize { | |
| 61 | pub fn syscall3(number: SYS, arg1: usize, arg2: usize, arg3: usize) usize { | |
| 62 | 62 | return asm volatile ( |
| 63 | 63 | \\ syscall |
| 64 | 64 | \\ blez $7, 1f |
| 65 | 65 | \\ subu $2, $0, $2 |
| 66 | 66 | \\ 1: |
| 67 | 67 | : [ret] "={$2}" (-> usize) |
| 68 | : [number] "{$2}" (number), | |
| 68 | : [number] "{$2}" (@enumToInt(number)), | |
| 69 | 69 | [arg1] "{$4}" (arg1), |
| 70 | 70 | [arg2] "{$5}" (arg2), |
| 71 | 71 | [arg3] "{$6}" (arg3) |
| ... | ... | @@ -73,14 +73,14 @@ pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize { |
| 73 | 73 | ); |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize { | |
| 76 | pub fn syscall4(number: SYS, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize { | |
| 77 | 77 | return asm volatile ( |
| 78 | 78 | \\ syscall |
| 79 | 79 | \\ blez $7, 1f |
| 80 | 80 | \\ subu $2, $0, $2 |
| 81 | 81 | \\ 1: |
| 82 | 82 | : [ret] "={$2}" (-> usize) |
| 83 | : [number] "{$2}" (number), | |
| 83 | : [number] "{$2}" (@enumToInt(number)), | |
| 84 | 84 | [arg1] "{$4}" (arg1), |
| 85 | 85 | [arg2] "{$5}" (arg2), |
| 86 | 86 | [arg3] "{$6}" (arg3), |
| ... | ... | @@ -89,7 +89,7 @@ pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz |
| 89 | 89 | ); |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize { | |
| 92 | pub fn syscall5(number: SYS, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize { | |
| 93 | 93 | return asm volatile ( |
| 94 | 94 | \\ .set noat |
| 95 | 95 | \\ subu $sp, $sp, 24 |
| ... | ... | @@ -100,7 +100,7 @@ pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz |
| 100 | 100 | \\ subu $2, $0, $2 |
| 101 | 101 | \\ 1: |
| 102 | 102 | : [ret] "={$2}" (-> usize) |
| 103 | : [number] "{$2}" (number), | |
| 103 | : [number] "{$2}" (@enumToInt(number)), | |
| 104 | 104 | [arg1] "{$4}" (arg1), |
| 105 | 105 | [arg2] "{$5}" (arg2), |
| 106 | 106 | [arg3] "{$6}" (arg3), |
| ... | ... | @@ -111,7 +111,7 @@ pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | pub fn syscall6( |
| 114 | number: usize, | |
| 114 | number: SYS, | |
| 115 | 115 | arg1: usize, |
| 116 | 116 | arg2: usize, |
| 117 | 117 | arg3: usize, |
| ... | ... | @@ -130,7 +130,7 @@ pub fn syscall6( |
| 130 | 130 | \\ subu $2, $0, $2 |
| 131 | 131 | \\ 1: |
| 132 | 132 | : [ret] "={$2}" (-> usize) |
| 133 | : [number] "{$2}" (number), | |
| 133 | : [number] "{$2}" (@enumToInt(number)), | |
| 134 | 134 | [arg1] "{$4}" (arg1), |
| 135 | 135 | [arg2] "{$5}" (arg2), |
| 136 | 136 | [arg3] "{$6}" (arg3), |
| ... | ... | @@ -147,7 +147,7 @@ pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, a |
| 147 | 147 | pub fn restore() callconv(.Naked) void { |
| 148 | 148 | return asm volatile ("syscall" |
| 149 | 149 | : |
| 150 | : [number] "{$2}" (@as(usize, SYS_sigreturn)) | |
| 150 | : [number] "{$2}" (@enumToInt(SYS.sigreturn)) | |
| 151 | 151 | : "memory", "cc", "$7" |
| 152 | 152 | ); |
| 153 | 153 | } |
| ... | ... | @@ -155,7 +155,7 @@ pub fn restore() callconv(.Naked) void { |
| 155 | 155 | pub fn restore_rt() callconv(.Naked) void { |
| 156 | 156 | return asm volatile ("syscall" |
| 157 | 157 | : |
| 158 | : [number] "{$2}" (@as(usize, SYS_rt_sigreturn)) | |
| 158 | : [number] "{$2}" (@enumToInt(SYS.rt_sigreturn)) | |
| 159 | 159 | : "memory", "cc", "$7" |
| 160 | 160 | ); |
| 161 | 161 | } |
lib/std/os/linux/riscv64.zig+15-15| ... | ... | @@ -1,36 +1,36 @@ |
| 1 | 1 | usingnamespace @import("../bits.zig"); |
| 2 | 2 | |
| 3 | pub fn syscall0(number: usize) usize { | |
| 3 | pub fn syscall0(number: SYS) usize { | |
| 4 | 4 | return asm volatile ("ecall" |
| 5 | 5 | : [ret] "={x10}" (-> usize) |
| 6 | : [number] "{x17}" (number) | |
| 6 | : [number] "{x17}" (@enumToInt(number)) | |
| 7 | 7 | : "memory" |
| 8 | 8 | ); |
| 9 | 9 | } |
| 10 | 10 | |
| 11 | pub fn syscall1(number: usize, arg1: usize) usize { | |
| 11 | pub fn syscall1(number: SYS, arg1: usize) usize { | |
| 12 | 12 | return asm volatile ("ecall" |
| 13 | 13 | : [ret] "={x10}" (-> usize) |
| 14 | : [number] "{x17}" (number), | |
| 14 | : [number] "{x17}" (@enumToInt(number)), | |
| 15 | 15 | [arg1] "{x10}" (arg1) |
| 16 | 16 | : "memory" |
| 17 | 17 | ); |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize { | |
| 20 | pub fn syscall2(number: SYS, arg1: usize, arg2: usize) usize { | |
| 21 | 21 | return asm volatile ("ecall" |
| 22 | 22 | : [ret] "={x10}" (-> usize) |
| 23 | : [number] "{x17}" (number), | |
| 23 | : [number] "{x17}" (@enumToInt(number)), | |
| 24 | 24 | [arg1] "{x10}" (arg1), |
| 25 | 25 | [arg2] "{x11}" (arg2) |
| 26 | 26 | : "memory" |
| 27 | 27 | ); |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize { | |
| 30 | pub fn syscall3(number: SYS, arg1: usize, arg2: usize, arg3: usize) usize { | |
| 31 | 31 | return asm volatile ("ecall" |
| 32 | 32 | : [ret] "={x10}" (-> usize) |
| 33 | : [number] "{x17}" (number), | |
| 33 | : [number] "{x17}" (@enumToInt(number)), | |
| 34 | 34 | [arg1] "{x10}" (arg1), |
| 35 | 35 | [arg2] "{x11}" (arg2), |
| 36 | 36 | [arg3] "{x12}" (arg3) |
| ... | ... | @@ -38,10 +38,10 @@ pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize { |
| 38 | 38 | ); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize { | |
| 41 | pub fn syscall4(number: SYS, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize { | |
| 42 | 42 | return asm volatile ("ecall" |
| 43 | 43 | : [ret] "={x10}" (-> usize) |
| 44 | : [number] "{x17}" (number), | |
| 44 | : [number] "{x17}" (@enumToInt(number)), | |
| 45 | 45 | [arg1] "{x10}" (arg1), |
| 46 | 46 | [arg2] "{x11}" (arg2), |
| 47 | 47 | [arg3] "{x12}" (arg3), |
| ... | ... | @@ -50,10 +50,10 @@ pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz |
| 50 | 50 | ); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize { | |
| 53 | pub fn syscall5(number: SYS, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize { | |
| 54 | 54 | return asm volatile ("ecall" |
| 55 | 55 | : [ret] "={x10}" (-> usize) |
| 56 | : [number] "{x17}" (number), | |
| 56 | : [number] "{x17}" (@enumToInt(number)), | |
| 57 | 57 | [arg1] "{x10}" (arg1), |
| 58 | 58 | [arg2] "{x11}" (arg2), |
| 59 | 59 | [arg3] "{x12}" (arg3), |
| ... | ... | @@ -64,7 +64,7 @@ pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | pub fn syscall6( |
| 67 | number: usize, | |
| 67 | number: SYS, | |
| 68 | 68 | arg1: usize, |
| 69 | 69 | arg2: usize, |
| 70 | 70 | arg3: usize, |
| ... | ... | @@ -74,7 +74,7 @@ pub fn syscall6( |
| 74 | 74 | ) usize { |
| 75 | 75 | return asm volatile ("ecall" |
| 76 | 76 | : [ret] "={x10}" (-> usize) |
| 77 | : [number] "{x17}" (number), | |
| 77 | : [number] "{x17}" (@enumToInt(number)), | |
| 78 | 78 | [arg1] "{x10}" (arg1), |
| 79 | 79 | [arg2] "{x11}" (arg2), |
| 80 | 80 | [arg3] "{x12}" (arg3), |
| ... | ... | @@ -92,7 +92,7 @@ pub const restore = restore_rt; |
| 92 | 92 | pub fn restore_rt() callconv(.Naked) void { |
| 93 | 93 | return asm volatile ("ecall" |
| 94 | 94 | : |
| 95 | : [number] "{x17}" (@as(usize, SYS_rt_sigreturn)) | |
| 95 | : [number] "{x17}" (@enumToInt(SYS.rt_sigreturn)) | |
| 96 | 96 | : "memory" |
| 97 | 97 | ); |
| 98 | 98 | } |
lib/std/os/linux/tls.zig+4-4| ... | ... | @@ -122,7 +122,7 @@ pub fn setThreadPointer(addr: usize) void { |
| 122 | 122 | .seg_not_present = 0, |
| 123 | 123 | .useable = 1, |
| 124 | 124 | }; |
| 125 | const rc = std.os.linux.syscall1(std.os.linux.SYS_set_thread_area, @ptrToInt(&user_desc)); | |
| 125 | const rc = std.os.linux.syscall1(.set_thread_area, @ptrToInt(&user_desc)); | |
| 126 | 126 | assert(rc == 0); |
| 127 | 127 | |
| 128 | 128 | const gdt_entry_number = user_desc.entry_number; |
| ... | ... | @@ -135,7 +135,7 @@ pub fn setThreadPointer(addr: usize) void { |
| 135 | 135 | ); |
| 136 | 136 | }, |
| 137 | 137 | .x86_64 => { |
| 138 | const rc = std.os.linux.syscall2(std.os.linux.SYS_arch_prctl, std.os.linux.ARCH_SET_FS, addr); | |
| 138 | const rc = std.os.linux.syscall2(.arch_prctl, std.os.linux.ARCH_SET_FS, addr); | |
| 139 | 139 | assert(rc == 0); |
| 140 | 140 | }, |
| 141 | 141 | .aarch64 => { |
| ... | ... | @@ -146,7 +146,7 @@ pub fn setThreadPointer(addr: usize) void { |
| 146 | 146 | ); |
| 147 | 147 | }, |
| 148 | 148 | .arm => { |
| 149 | const rc = std.os.linux.syscall1(std.os.linux.SYS_set_tls, addr); | |
| 149 | const rc = std.os.linux.syscall1(.set_tls, addr); | |
| 150 | 150 | assert(rc == 0); |
| 151 | 151 | }, |
| 152 | 152 | .riscv64 => { |
| ... | ... | @@ -157,7 +157,7 @@ pub fn setThreadPointer(addr: usize) void { |
| 157 | 157 | ); |
| 158 | 158 | }, |
| 159 | 159 | .mipsel => { |
| 160 | const rc = std.os.linux.syscall1(std.os.linux.SYS_set_thread_area, addr); | |
| 160 | const rc = std.os.linux.syscall1(.set_thread_area, addr); | |
| 161 | 161 | assert(rc == 0); |
| 162 | 162 | }, |
| 163 | 163 | else => @compileError("Unsupported architecture"), |
lib/std/os/linux/vdso.zig+3-3| ... | ... | @@ -22,7 +22,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize { |
| 22 | 22 | }) { |
| 23 | 23 | const this_ph = @intToPtr(*elf.Phdr, ph_addr); |
| 24 | 24 | switch (this_ph.p_type) { |
| 25 | // On WSL1 as well as older kernels, the VDSO ELF image is pre-linked in the upper half | |
| 25 | // On WSL1 as well as older kernels, the VDSO ELF image is pre-linked in the upper half | |
| 26 | 26 | // of the memory space (e.g. p_vaddr = 0xffffffffff700000 on WSL1). |
| 27 | 27 | // Wrapping operations are used on this line as well as subsequent calculations relative to base |
| 28 | 28 | // (lines 47, 78) to ensure no overflow check is tripped. |
| ... | ... | @@ -70,7 +70,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize { |
| 70 | 70 | if (0 == (@as(u32, 1) << @intCast(u5, syms[i].st_info >> 4) & OK_BINDS)) continue; |
| 71 | 71 | if (0 == syms[i].st_shndx) continue; |
| 72 | 72 | const sym_name = @ptrCast([*:0]const u8, strings + syms[i].st_name); |
| 73 | if (!mem.eql(u8, name, mem.toSliceConst(u8, sym_name))) continue; | |
| 73 | if (!mem.eql(u8, name, mem.spanZ(sym_name))) continue; | |
| 74 | 74 | if (maybe_versym) |versym| { |
| 75 | 75 | if (!checkver(maybe_verdef.?, versym[i], vername, strings)) |
| 76 | 76 | continue; |
| ... | ... | @@ -93,5 +93,5 @@ fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [ |
| 93 | 93 | } |
| 94 | 94 | const aux = @intToPtr(*elf.Verdaux, @ptrToInt(def) + def.vd_aux); |
| 95 | 95 | const vda_name = @ptrCast([*:0]const u8, strings + aux.vda_name); |
| 96 | return mem.eql(u8, vername, mem.toSliceConst(u8, vda_name)); | |
| 96 | return mem.eql(u8, vername, mem.spanZ(vda_name)); | |
| 97 | 97 | } |
lib/std/os/linux/x86_64.zig+15-15| ... | ... | @@ -1,36 +1,36 @@ |
| 1 | 1 | usingnamespace @import("../bits.zig"); |
| 2 | 2 | |
| 3 | pub fn syscall0(number: usize) usize { | |
| 3 | pub fn syscall0(number: SYS) usize { | |
| 4 | 4 | return asm volatile ("syscall" |
| 5 | 5 | : [ret] "={rax}" (-> usize) |
| 6 | : [number] "{rax}" (number) | |
| 6 | : [number] "{rax}" (@enumToInt(number)) | |
| 7 | 7 | : "rcx", "r11", "memory" |
| 8 | 8 | ); |
| 9 | 9 | } |
| 10 | 10 | |
| 11 | pub fn syscall1(number: usize, arg1: usize) usize { | |
| 11 | pub fn syscall1(number: SYS, arg1: usize) usize { | |
| 12 | 12 | return asm volatile ("syscall" |
| 13 | 13 | : [ret] "={rax}" (-> usize) |
| 14 | : [number] "{rax}" (number), | |
| 14 | : [number] "{rax}" (@enumToInt(number)), | |
| 15 | 15 | [arg1] "{rdi}" (arg1) |
| 16 | 16 | : "rcx", "r11", "memory" |
| 17 | 17 | ); |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize { | |
| 20 | pub fn syscall2(number: SYS, arg1: usize, arg2: usize) usize { | |
| 21 | 21 | return asm volatile ("syscall" |
| 22 | 22 | : [ret] "={rax}" (-> usize) |
| 23 | : [number] "{rax}" (number), | |
| 23 | : [number] "{rax}" (@enumToInt(number)), | |
| 24 | 24 | [arg1] "{rdi}" (arg1), |
| 25 | 25 | [arg2] "{rsi}" (arg2) |
| 26 | 26 | : "rcx", "r11", "memory" |
| 27 | 27 | ); |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize { | |
| 30 | pub fn syscall3(number: SYS, arg1: usize, arg2: usize, arg3: usize) usize { | |
| 31 | 31 | return asm volatile ("syscall" |
| 32 | 32 | : [ret] "={rax}" (-> usize) |
| 33 | : [number] "{rax}" (number), | |
| 33 | : [number] "{rax}" (@enumToInt(number)), | |
| 34 | 34 | [arg1] "{rdi}" (arg1), |
| 35 | 35 | [arg2] "{rsi}" (arg2), |
| 36 | 36 | [arg3] "{rdx}" (arg3) |
| ... | ... | @@ -38,10 +38,10 @@ pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize { |
| 38 | 38 | ); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize { | |
| 41 | pub fn syscall4(number: SYS, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize { | |
| 42 | 42 | return asm volatile ("syscall" |
| 43 | 43 | : [ret] "={rax}" (-> usize) |
| 44 | : [number] "{rax}" (number), | |
| 44 | : [number] "{rax}" (@enumToInt(number)), | |
| 45 | 45 | [arg1] "{rdi}" (arg1), |
| 46 | 46 | [arg2] "{rsi}" (arg2), |
| 47 | 47 | [arg3] "{rdx}" (arg3), |
| ... | ... | @@ -50,10 +50,10 @@ pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz |
| 50 | 50 | ); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize { | |
| 53 | pub fn syscall5(number: SYS, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize { | |
| 54 | 54 | return asm volatile ("syscall" |
| 55 | 55 | : [ret] "={rax}" (-> usize) |
| 56 | : [number] "{rax}" (number), | |
| 56 | : [number] "{rax}" (@enumToInt(number)), | |
| 57 | 57 | [arg1] "{rdi}" (arg1), |
| 58 | 58 | [arg2] "{rsi}" (arg2), |
| 59 | 59 | [arg3] "{rdx}" (arg3), |
| ... | ... | @@ -64,7 +64,7 @@ pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | pub fn syscall6( |
| 67 | number: usize, | |
| 67 | number: SYS, | |
| 68 | 68 | arg1: usize, |
| 69 | 69 | arg2: usize, |
| 70 | 70 | arg3: usize, |
| ... | ... | @@ -74,7 +74,7 @@ pub fn syscall6( |
| 74 | 74 | ) usize { |
| 75 | 75 | return asm volatile ("syscall" |
| 76 | 76 | : [ret] "={rax}" (-> usize) |
| 77 | : [number] "{rax}" (number), | |
| 77 | : [number] "{rax}" (@enumToInt(number)), | |
| 78 | 78 | [arg1] "{rdi}" (arg1), |
| 79 | 79 | [arg2] "{rsi}" (arg2), |
| 80 | 80 | [arg3] "{rdx}" (arg3), |
| ... | ... | @@ -93,7 +93,7 @@ pub const restore = restore_rt; |
| 93 | 93 | pub fn restore_rt() callconv(.Naked) void { |
| 94 | 94 | return asm volatile ("syscall" |
| 95 | 95 | : |
| 96 | : [number] "{rax}" (@as(usize, SYS_rt_sigreturn)) | |
| 96 | : [number] "{rax}" (@enumToInt(SYS.rt_sigreturn)) | |
| 97 | 97 | : "rcx", "r11", "memory" |
| 98 | 98 | ); |
| 99 | 99 | } |
lib/std/os/test.zig+8-8| ... | ... | @@ -18,8 +18,8 @@ const AtomicOrder = builtin.AtomicOrder; |
| 18 | 18 | |
| 19 | 19 | test "makePath, put some files in it, deleteTree" { |
| 20 | 20 | try fs.cwd().makePath("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "c"); |
| 21 | try io.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "c" ++ fs.path.sep_str ++ "file.txt", "nonsense"); | |
| 22 | try io.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "file2.txt", "blah"); | |
| 21 | try fs.cwd().writeFile("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "c" ++ fs.path.sep_str ++ "file.txt", "nonsense"); | |
| 22 | try fs.cwd().writeFile("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "file2.txt", "blah"); | |
| 23 | 23 | try fs.cwd().deleteTree("os_test_tmp"); |
| 24 | 24 | if (fs.cwd().openDir("os_test_tmp", .{})) |dir| { |
| 25 | 25 | @panic("expected error"); |
| ... | ... | @@ -36,8 +36,8 @@ test "access file" { |
| 36 | 36 | expect(err == error.FileNotFound); |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | try io.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", ""); | |
| 40 | try os.access("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", os.F_OK); | |
| 39 | try fs.cwd().writeFile("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", ""); | |
| 40 | try fs.cwd().access("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", .{}); | |
| 41 | 41 | try fs.cwd().deleteTree("os_test_tmp"); |
| 42 | 42 | } |
| 43 | 43 | |
| ... | ... | @@ -65,12 +65,12 @@ test "sendfile" { |
| 65 | 65 | }, |
| 66 | 66 | }; |
| 67 | 67 | |
| 68 | var src_file = try dir.createFileC("sendfile1.txt", .{ .read = true }); | |
| 68 | var src_file = try dir.createFileZ("sendfile1.txt", .{ .read = true }); | |
| 69 | 69 | defer src_file.close(); |
| 70 | 70 | |
| 71 | 71 | try src_file.writevAll(&vecs); |
| 72 | 72 | |
| 73 | var dest_file = try dir.createFileC("sendfile2.txt", .{ .read = true }); | |
| 73 | var dest_file = try dir.createFileZ("sendfile2.txt", .{ .read = true }); | |
| 74 | 74 | defer dest_file.close(); |
| 75 | 75 | |
| 76 | 76 | const header1 = "header1\n"; |
| ... | ... | @@ -192,12 +192,12 @@ test "AtomicFile" { |
| 192 | 192 | \\ this is a test file |
| 193 | 193 | ; |
| 194 | 194 | { |
| 195 | var af = try fs.AtomicFile.init(test_out_file, File.default_mode); | |
| 195 | var af = try fs.cwd().atomicFile(test_out_file, .{}); | |
| 196 | 196 | defer af.deinit(); |
| 197 | 197 | try af.file.writeAll(test_content); |
| 198 | 198 | try af.finish(); |
| 199 | 199 | } |
| 200 | const content = try io.readFileAlloc(testing.allocator, test_out_file); | |
| 200 | const content = try fs.cwd().readFileAlloc(testing.allocator, test_out_file, 9999); | |
| 201 | 201 | defer testing.allocator.free(content); |
| 202 | 202 | expect(mem.eql(u8, content, test_content)); |
| 203 | 203 |
lib/std/os/windows.zig+5-5| ... | ... | @@ -119,7 +119,7 @@ pub fn OpenFileW( |
| 119 | 119 | |
| 120 | 120 | var result: HANDLE = undefined; |
| 121 | 121 | |
| 122 | const path_len_bytes = math.cast(u16, mem.toSliceConst(u16, sub_path_w).len * 2) catch |err| switch (err) { | |
| 122 | const path_len_bytes = math.cast(u16, mem.lenZ(sub_path_w) * 2) catch |err| switch (err) { | |
| 123 | 123 | error.Overflow => return error.NameTooLong, |
| 124 | 124 | }; |
| 125 | 125 | var nt_name = UNICODE_STRING{ |
| ... | ... | @@ -697,7 +697,7 @@ pub fn CreateDirectoryW( |
| 697 | 697 | sub_path_w: [*:0]const u16, |
| 698 | 698 | sa: ?*SECURITY_ATTRIBUTES, |
| 699 | 699 | ) CreateDirectoryError!HANDLE { |
| 700 | const path_len_bytes = math.cast(u16, mem.toSliceConst(u16, sub_path_w).len * 2) catch |err| switch (err) { | |
| 700 | const path_len_bytes = math.cast(u16, mem.lenZ(sub_path_w) * 2) catch |err| switch (err) { | |
| 701 | 701 | error.Overflow => return error.NameTooLong, |
| 702 | 702 | }; |
| 703 | 703 | var nt_name = UNICODE_STRING{ |
| ... | ... | @@ -905,7 +905,7 @@ pub fn WSAStartup(majorVersion: u8, minorVersion: u8) !ws2_32.WSADATA { |
| 905 | 905 | var wsadata: ws2_32.WSADATA = undefined; |
| 906 | 906 | return switch (ws2_32.WSAStartup((@as(WORD, minorVersion) << 8) | majorVersion, &wsadata)) { |
| 907 | 907 | 0 => wsadata, |
| 908 | else => |err| unexpectedWSAError(@intToEnum(WinsockError, err)), | |
| 908 | else => |err| unexpectedWSAError(@intToEnum(ws2_32.WinsockError, @intCast(u16, err))), | |
| 909 | 909 | }; |
| 910 | 910 | } |
| 911 | 911 | |
| ... | ... | @@ -1226,7 +1226,7 @@ pub fn nanoSecondsToFileTime(ns: i64) FILETIME { |
| 1226 | 1226 | } |
| 1227 | 1227 | |
| 1228 | 1228 | pub fn cStrToPrefixedFileW(s: [*:0]const u8) ![PATH_MAX_WIDE:0]u16 { |
| 1229 | return sliceToPrefixedFileW(mem.toSliceConst(u8, s)); | |
| 1229 | return sliceToPrefixedFileW(mem.spanZ(s)); | |
| 1230 | 1230 | } |
| 1231 | 1231 | |
| 1232 | 1232 | pub fn sliceToPrefixedFileW(s: []const u8) ![PATH_MAX_WIDE:0]u16 { |
| ... | ... | @@ -1304,7 +1304,7 @@ pub fn unexpectedError(err: Win32Error) std.os.UnexpectedError { |
| 1304 | 1304 | return error.Unexpected; |
| 1305 | 1305 | } |
| 1306 | 1306 | |
| 1307 | pub fn unexpectedWSAError(err: WinsockError) std.os.UnexpectedError { | |
| 1307 | pub fn unexpectedWSAError(err: ws2_32.WinsockError) std.os.UnexpectedError { | |
| 1308 | 1308 | return unexpectedError(@intToEnum(Win32Error, @enumToInt(err))); |
| 1309 | 1309 | } |
| 1310 | 1310 |
lib/std/pdb.zig+1-1| ... | ... | @@ -649,7 +649,7 @@ const MsfStream = struct { |
| 649 | 649 | while (true) { |
| 650 | 650 | const byte = try self.inStream().readByte(); |
| 651 | 651 | if (byte == 0) { |
| 652 | return list.toSlice(); | |
| 652 | return list.span(); | |
| 653 | 653 | } |
| 654 | 654 | try list.append(byte); |
| 655 | 655 | } |
lib/std/process.zig+7-7| ... | ... | @@ -83,7 +83,7 @@ pub fn getEnvMap(allocator: *Allocator) !BufMap { |
| 83 | 83 | |
| 84 | 84 | for (environ) |env| { |
| 85 | 85 | if (env) |ptr| { |
| 86 | const pair = mem.toSlice(u8, ptr); | |
| 86 | const pair = mem.spanZ(ptr); | |
| 87 | 87 | var parts = mem.separate(pair, "="); |
| 88 | 88 | const key = parts.next().?; |
| 89 | 89 | const value = parts.next().?; |
| ... | ... | @@ -176,7 +176,7 @@ pub const ArgIteratorPosix = struct { |
| 176 | 176 | |
| 177 | 177 | const s = os.argv[self.index]; |
| 178 | 178 | self.index += 1; |
| 179 | return mem.toSlice(u8, s); | |
| 179 | return mem.spanZ(s); | |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | pub fn skip(self: *ArgIteratorPosix) bool { |
| ... | ... | @@ -401,7 +401,7 @@ pub fn argsAlloc(allocator: *mem.Allocator) ![][]u8 { |
| 401 | 401 | |
| 402 | 402 | var i: usize = 0; |
| 403 | 403 | while (i < count) : (i += 1) { |
| 404 | result_slice[i] = mem.toSlice(u8, argv[i]); | |
| 404 | result_slice[i] = mem.spanZ(argv[i]); | |
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | return result_slice; |
| ... | ... | @@ -422,8 +422,8 @@ pub fn argsAlloc(allocator: *mem.Allocator) ![][]u8 { |
| 422 | 422 | try slice_list.append(arg.len); |
| 423 | 423 | } |
| 424 | 424 | |
| 425 | const contents_slice = contents.toSliceConst(); | |
| 426 | const slice_sizes = slice_list.toSliceConst(); | |
| 425 | const contents_slice = contents.span(); | |
| 426 | const slice_sizes = slice_list.span(); | |
| 427 | 427 | const slice_list_bytes = try math.mul(usize, @sizeOf([]u8), slice_sizes.len); |
| 428 | 428 | const total_bytes = try math.add(usize, slice_list_bytes, contents_slice.len); |
| 429 | 429 | const buf = try allocator.alignedAlloc(u8, @alignOf([]u8), total_bytes); |
| ... | ... | @@ -636,7 +636,7 @@ pub fn getSelfExeSharedLibPaths(allocator: *Allocator) error{OutOfMemory}![][:0] |
| 636 | 636 | fn callback(info: *os.dl_phdr_info, size: usize, list: *List) !void { |
| 637 | 637 | const name = info.dlpi_name orelse return; |
| 638 | 638 | if (name[0] == '/') { |
| 639 | const item = try mem.dupeZ(list.allocator, u8, mem.toSliceConst(u8, name)); | |
| 639 | const item = try mem.dupeZ(list.allocator, u8, mem.spanZ(name)); | |
| 640 | 640 | errdefer list.allocator.free(item); |
| 641 | 641 | try list.append(item); |
| 642 | 642 | } |
| ... | ... | @@ -657,7 +657,7 @@ pub fn getSelfExeSharedLibPaths(allocator: *Allocator) error{OutOfMemory}![][:0] |
| 657 | 657 | var i: u32 = 0; |
| 658 | 658 | while (i < img_count) : (i += 1) { |
| 659 | 659 | const name = std.c._dyld_get_image_name(i); |
| 660 | const item = try mem.dupeZ(allocator, u8, mem.toSliceConst(u8, name)); | |
| 660 | const item = try mem.dupeZ(allocator, u8, mem.spanZ(name)); | |
| 661 | 661 | errdefer allocator.free(item); |
| 662 | 662 | try paths.append(item); |
| 663 | 663 | } |
lib/std/rand.zig+13-19| ... | ... | @@ -59,7 +59,7 @@ pub const Random = struct { |
| 59 | 59 | return @bitCast(T, unsigned_result); |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | /// Constant-time implementation off ::uintLessThan. | |
| 62 | /// Constant-time implementation off `uintLessThan`. | |
| 63 | 63 | /// The results of this function may be biased. |
| 64 | 64 | pub fn uintLessThanBiased(r: *Random, comptime T: type, less_than: T) T { |
| 65 | 65 | comptime assert(T.is_signed == false); |
| ... | ... | @@ -73,13 +73,13 @@ pub const Random = struct { |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /// Returns an evenly distributed random unsigned integer `0 <= i < less_than`. |
| 76 | /// This function assumes that the underlying ::fillFn produces evenly distributed values. | |
| 76 | /// This function assumes that the underlying `fillFn` produces evenly distributed values. | |
| 77 | 77 | /// Within this assumption, the runtime of this function is exponentially distributed. |
| 78 | /// If ::fillFn were backed by a true random generator, | |
| 78 | /// If `fillFn` were backed by a true random generator, | |
| 79 | 79 | /// the runtime of this function would technically be unbounded. |
| 80 | /// However, if ::fillFn is backed by any evenly distributed pseudo random number generator, | |
| 80 | /// However, if `fillFn` is backed by any evenly distributed pseudo random number generator, | |
| 81 | 81 | /// this function is guaranteed to return. |
| 82 | /// If you need deterministic runtime bounds, use `::uintLessThanBiased`. | |
| 82 | /// If you need deterministic runtime bounds, use `uintLessThanBiased`. | |
| 83 | 83 | pub fn uintLessThan(r: *Random, comptime T: type, less_than: T) T { |
| 84 | 84 | comptime assert(T.is_signed == false); |
| 85 | 85 | comptime assert(T.bit_count <= 64); // TODO: workaround: LLVM ERROR: Unsupported library call operation! |
| ... | ... | @@ -116,7 +116,7 @@ pub const Random = struct { |
| 116 | 116 | return @intCast(T, m >> Small.bit_count); |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | /// Constant-time implementation off ::uintAtMost. | |
| 119 | /// Constant-time implementation off `uintAtMost`. | |
| 120 | 120 | /// The results of this function may be biased. |
| 121 | 121 | pub fn uintAtMostBiased(r: *Random, comptime T: type, at_most: T) T { |
| 122 | 122 | assert(T.is_signed == false); |
| ... | ... | @@ -128,7 +128,7 @@ pub const Random = struct { |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | /// Returns an evenly distributed random unsigned integer `0 <= i <= at_most`. |
| 131 | /// See ::uintLessThan, which this function uses in most cases, | |
| 131 | /// See `uintLessThan`, which this function uses in most cases, | |
| 132 | 132 | /// for commentary on the runtime of this function. |
| 133 | 133 | pub fn uintAtMost(r: *Random, comptime T: type, at_most: T) T { |
| 134 | 134 | assert(T.is_signed == false); |
| ... | ... | @@ -139,7 +139,7 @@ pub const Random = struct { |
| 139 | 139 | return r.uintLessThan(T, at_most + 1); |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | /// Constant-time implementation off ::intRangeLessThan. | |
| 142 | /// Constant-time implementation off `intRangeLessThan`. | |
| 143 | 143 | /// The results of this function may be biased. |
| 144 | 144 | pub fn intRangeLessThanBiased(r: *Random, comptime T: type, at_least: T, less_than: T) T { |
| 145 | 145 | assert(at_least < less_than); |
| ... | ... | @@ -157,7 +157,7 @@ pub const Random = struct { |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /// Returns an evenly distributed random integer `at_least <= i < less_than`. |
| 160 | /// See ::uintLessThan, which this function uses in most cases, | |
| 160 | /// See `uintLessThan`, which this function uses in most cases, | |
| 161 | 161 | /// for commentary on the runtime of this function. |
| 162 | 162 | pub fn intRangeLessThan(r: *Random, comptime T: type, at_least: T, less_than: T) T { |
| 163 | 163 | assert(at_least < less_than); |
| ... | ... | @@ -174,7 +174,7 @@ pub const Random = struct { |
| 174 | 174 | } |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | /// Constant-time implementation off ::intRangeAtMostBiased. | |
| 177 | /// Constant-time implementation off `intRangeAtMostBiased`. | |
| 178 | 178 | /// The results of this function may be biased. |
| 179 | 179 | pub fn intRangeAtMostBiased(r: *Random, comptime T: type, at_least: T, at_most: T) T { |
| 180 | 180 | assert(at_least <= at_most); |
| ... | ... | @@ -192,7 +192,7 @@ pub const Random = struct { |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /// Returns an evenly distributed random integer `at_least <= i <= at_most`. |
| 195 | /// See ::uintLessThan, which this function uses in most cases, | |
| 195 | /// See `uintLessThan`, which this function uses in most cases, | |
| 196 | 196 | /// for commentary on the runtime of this function. |
| 197 | 197 | pub fn intRangeAtMost(r: *Random, comptime T: type, at_least: T, at_most: T) T { |
| 198 | 198 | assert(at_least <= at_most); |
| ... | ... | @@ -209,15 +209,9 @@ pub const Random = struct { |
| 209 | 209 | } |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | /// TODO: deprecated. use ::boolean or ::int instead. | |
| 213 | pub fn scalar(r: *Random, comptime T: type) T { | |
| 214 | return if (T == bool) r.boolean() else r.int(T); | |
| 215 | } | |
| 212 | pub const scalar = @compileError("deprecated; use boolean() or int() instead"); | |
| 216 | 213 | |
| 217 | /// TODO: deprecated. renamed to ::intRangeLessThan | |
| 218 | pub fn range(r: *Random, comptime T: type, start: T, end: T) T { | |
| 219 | return r.intRangeLessThan(T, start, end); | |
| 220 | } | |
| 214 | pub const range = @compileError("deprecated; use intRangeLessThan()"); | |
| 221 | 215 | |
| 222 | 216 | /// Return a floating point value evenly distributed in the range [0, 1). |
| 223 | 217 | pub fn float(r: *Random, comptime T: type) T { |
lib/std/sort.zig+2-2| ... | ... | @@ -1227,13 +1227,13 @@ test "sort fuzz testing" { |
| 1227 | 1227 | var fixed_buffer_mem: [100 * 1024]u8 = undefined; |
| 1228 | 1228 | |
| 1229 | 1229 | fn fuzzTest(rng: *std.rand.Random) !void { |
| 1230 | const array_size = rng.range(usize, 0, 1000); | |
| 1230 | const array_size = rng.intRangeLessThan(usize, 0, 1000); | |
| 1231 | 1231 | var array = try testing.allocator.alloc(IdAndValue, array_size); |
| 1232 | 1232 | defer testing.allocator.free(array); |
| 1233 | 1233 | // populate with random data |
| 1234 | 1234 | for (array) |*item, index| { |
| 1235 | 1235 | item.id = index; |
| 1236 | item.value = rng.range(i32, 0, 100); | |
| 1236 | item.value = rng.intRangeLessThan(i32, 0, 100); | |
| 1237 | 1237 | } |
| 1238 | 1238 | sort(IdAndValue, array, cmpByValue); |
| 1239 | 1239 |
lib/std/special/build_runner.zig+3-3| ... | ... | @@ -116,7 +116,7 @@ pub fn main() !void { |
| 116 | 116 | if (builder.validateUserInputDidItFail()) |
| 117 | 117 | return usageAndErr(builder, true, stderr_stream); |
| 118 | 118 | |
| 119 | builder.make(targets.toSliceConst()) catch |err| { | |
| 119 | builder.make(targets.span()) catch |err| { | |
| 120 | 120 | switch (err) { |
| 121 | 121 | error.InvalidStepName => { |
| 122 | 122 | return usageAndErr(builder, true, stderr_stream); |
| ... | ... | @@ -151,7 +151,7 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: var) !void { |
| 151 | 151 | , .{builder.zig_exe}); |
| 152 | 152 | |
| 153 | 153 | const allocator = builder.allocator; |
| 154 | for (builder.top_level_steps.toSliceConst()) |top_level_step| { | |
| 154 | for (builder.top_level_steps.span()) |top_level_step| { | |
| 155 | 155 | const name = if (&top_level_step.step == builder.default_step) |
| 156 | 156 | try fmt.allocPrint(allocator, "{} (default)", .{top_level_step.step.name}) |
| 157 | 157 | else |
| ... | ... | @@ -174,7 +174,7 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: var) !void { |
| 174 | 174 | if (builder.available_options_list.len == 0) { |
| 175 | 175 | try out_stream.print(" (none)\n", .{}); |
| 176 | 176 | } else { |
| 177 | for (builder.available_options_list.toSliceConst()) |option| { | |
| 177 | for (builder.available_options_list.span()) |option| { | |
| 178 | 178 | const name = try fmt.allocPrint(allocator, " -D{}=[{}]", .{ |
| 179 | 179 | option.name, |
| 180 | 180 | Builder.typeIdName(option.type_id), |
lib/std/special/compiler_rt.zig+20-7| ... | ... | @@ -10,13 +10,19 @@ comptime { |
| 10 | 10 | const strong_linkage = if (is_test) builtin.GlobalLinkage.Internal else builtin.GlobalLinkage.Strong; |
| 11 | 11 | |
| 12 | 12 | switch (builtin.arch) { |
| 13 | .i386, .x86_64 => @export(@import("compiler_rt/stack_probe.zig").zig_probe_stack, .{ .name = "__zig_probe_stack", .linkage = linkage }), | |
| 14 | .aarch64, .aarch64_be, .aarch64_32 => { | |
| 15 | @export(@import("compiler_rt/clear_cache.zig").clear_cache, .{ .name = "__clear_cache", .linkage = linkage }); | |
| 16 | }, | |
| 13 | .i386, | |
| 14 | .x86_64, | |
| 15 | => @export(@import("compiler_rt/stack_probe.zig").zig_probe_stack, .{ | |
| 16 | .name = "__zig_probe_stack", | |
| 17 | .linkage = linkage, | |
| 18 | }), | |
| 19 | ||
| 17 | 20 | else => {}, |
| 18 | 21 | } |
| 19 | 22 | |
| 23 | // __clear_cache manages its own logic about whether to be exported or not. | |
| 24 | _ = @import("compiler_rt/clear_cache.zig").clear_cache; | |
| 25 | ||
| 20 | 26 | @export(@import("compiler_rt/compareXf2.zig").__lesf2, .{ .name = "__lesf2", .linkage = linkage }); |
| 21 | 27 | @export(@import("compiler_rt/compareXf2.zig").__ledf2, .{ .name = "__ledf2", .linkage = linkage }); |
| 22 | 28 | @export(@import("compiler_rt/compareXf2.zig").__letf2, .{ .name = "__letf2", .linkage = linkage }); |
| ... | ... | @@ -69,9 +75,12 @@ comptime { |
| 69 | 75 | @export(@import("compiler_rt/divdf3.zig").__divdf3, .{ .name = "__divdf3", .linkage = linkage }); |
| 70 | 76 | @export(@import("compiler_rt/divtf3.zig").__divtf3, .{ .name = "__divtf3", .linkage = linkage }); |
| 71 | 77 | |
| 72 | @export(@import("compiler_rt/ashlti3.zig").__ashlti3, .{ .name = "__ashlti3", .linkage = linkage }); | |
| 73 | @export(@import("compiler_rt/lshrti3.zig").__lshrti3, .{ .name = "__lshrti3", .linkage = linkage }); | |
| 74 | @export(@import("compiler_rt/ashrti3.zig").__ashrti3, .{ .name = "__ashrti3", .linkage = linkage }); | |
| 78 | @export(@import("compiler_rt/shift.zig").__ashldi3, .{ .name = "__ashldi3", .linkage = linkage }); | |
| 79 | @export(@import("compiler_rt/shift.zig").__ashlti3, .{ .name = "__ashlti3", .linkage = linkage }); | |
| 80 | @export(@import("compiler_rt/shift.zig").__ashrdi3, .{ .name = "__ashrdi3", .linkage = linkage }); | |
| 81 | @export(@import("compiler_rt/shift.zig").__ashrti3, .{ .name = "__ashrti3", .linkage = linkage }); | |
| 82 | @export(@import("compiler_rt/shift.zig").__lshrdi3, .{ .name = "__lshrdi3", .linkage = linkage }); | |
| 83 | @export(@import("compiler_rt/shift.zig").__lshrti3, .{ .name = "__lshrti3", .linkage = linkage }); | |
| 75 | 84 | |
| 76 | 85 | @export(@import("compiler_rt/floatsiXf.zig").__floatsidf, .{ .name = "__floatsidf", .linkage = linkage }); |
| 77 | 86 | @export(@import("compiler_rt/floatsiXf.zig").__floatsisf, .{ .name = "__floatsisf", .linkage = linkage }); |
| ... | ... | @@ -229,6 +238,10 @@ comptime { |
| 229 | 238 | @export(@import("compiler_rt/divsf3.zig").__aeabi_fdiv, .{ .name = "__aeabi_fdiv", .linkage = linkage }); |
| 230 | 239 | @export(@import("compiler_rt/divdf3.zig").__aeabi_ddiv, .{ .name = "__aeabi_ddiv", .linkage = linkage }); |
| 231 | 240 | |
| 241 | @export(@import("compiler_rt/shift.zig").__aeabi_llsl, .{ .name = "__aeabi_llsl", .linkage = linkage }); | |
| 242 | @export(@import("compiler_rt/shift.zig").__aeabi_lasr, .{ .name = "__aeabi_lasr", .linkage = linkage }); | |
| 243 | @export(@import("compiler_rt/shift.zig").__aeabi_llsr, .{ .name = "__aeabi_llsr", .linkage = linkage }); | |
| 244 | ||
| 232 | 245 | @export(@import("compiler_rt/compareXf2.zig").__aeabi_fcmpeq, .{ .name = "__aeabi_fcmpeq", .linkage = linkage }); |
| 233 | 246 | @export(@import("compiler_rt/compareXf2.zig").__aeabi_fcmplt, .{ .name = "__aeabi_fcmplt", .linkage = linkage }); |
| 234 | 247 | @export(@import("compiler_rt/compareXf2.zig").__aeabi_fcmple, .{ .name = "__aeabi_fcmple", .linkage = linkage }); |
lib/std/special/compiler_rt/ashldi3_test.zig created+32| ... | ... | @@ -0,0 +1,32 @@ |
| 1 | const __ashldi3 = @import("shift.zig").__ashldi3; | |
| 2 | const testing = @import("std").testing; | |
| 3 | ||
| 4 | fn test__ashldi3(a: i64, b: i32, expected: u64) void { | |
| 5 | const x = __ashldi3(a, b); | |
| 6 | testing.expectEqual(@bitCast(i64, expected), x); | |
| 7 | } | |
| 8 | ||
| 9 | test "ashldi3" { | |
| 10 | test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF); | |
| 11 | test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x2468ACF13579BDE); | |
| 12 | test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37BC); | |
| 13 | test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x91A2B3C4D5E6F78); | |
| 14 | test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDEF0); | |
| 15 | ||
| 16 | test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x789ABCDEF0000000); | |
| 17 | test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0xF13579BDE0000000); | |
| 18 | test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0xE26AF37BC0000000); | |
| 19 | test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0xC4D5E6F780000000); | |
| 20 | ||
| 21 | test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x89ABCDEF00000000); | |
| 22 | ||
| 23 | test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x13579BDE00000000); | |
| 24 | test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x26AF37BC00000000); | |
| 25 | test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x4D5E6F7800000000); | |
| 26 | test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x9ABCDEF000000000); | |
| 27 | ||
| 28 | test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0xF000000000000000); | |
| 29 | test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0xE000000000000000); | |
| 30 | test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0xC000000000000000); | |
| 31 | test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0x8000000000000000); | |
| 32 | } |
lib/std/special/compiler_rt/ashlti3.zig deleted-41| ... | ... | @@ -1,41 +0,0 @@ |
| 1 | const builtin = @import("builtin"); | |
| 2 | const compiler_rt = @import("../compiler_rt.zig"); | |
| 3 | ||
| 4 | pub fn __ashlti3(a: i128, b: i32) callconv(.C) i128 { | |
| 5 | var input = twords{ .all = a }; | |
| 6 | var result: twords = undefined; | |
| 7 | ||
| 8 | if (b > 63) { | |
| 9 | // 64 <= b < 128 | |
| 10 | result.s.low = 0; | |
| 11 | result.s.high = input.s.low << @intCast(u6, b - 64); | |
| 12 | } else { | |
| 13 | // 0 <= b < 64 | |
| 14 | if (b == 0) return a; | |
| 15 | result.s.low = input.s.low << @intCast(u6, b); | |
| 16 | result.s.high = input.s.low >> @intCast(u6, 64 - b); | |
| 17 | result.s.high |= input.s.high << @intCast(u6, b); | |
| 18 | } | |
| 19 | ||
| 20 | return result.all; | |
| 21 | } | |
| 22 | ||
| 23 | const twords = extern union { | |
| 24 | all: i128, | |
| 25 | s: S, | |
| 26 | ||
| 27 | const S = if (builtin.endian == .Little) | |
| 28 | struct { | |
| 29 | low: u64, | |
| 30 | high: u64, | |
| 31 | } | |
| 32 | else | |
| 33 | struct { | |
| 34 | high: u64, | |
| 35 | low: u64, | |
| 36 | }; | |
| 37 | }; | |
| 38 | ||
| 39 | test "import ashlti3" { | |
| 40 | _ = @import("ashlti3_test.zig"); | |
| 41 | } |
lib/std/special/compiler_rt/ashlti3_test.zig+2-2| ... | ... | @@ -1,9 +1,9 @@ |
| 1 | const __ashlti3 = @import("ashlti3.zig").__ashlti3; | |
| 1 | const __ashlti3 = @import("shift.zig").__ashlti3; | |
| 2 | 2 | const testing = @import("std").testing; |
| 3 | 3 | |
| 4 | 4 | fn test__ashlti3(a: i128, b: i32, expected: i128) void { |
| 5 | 5 | const x = __ashlti3(a, b); |
| 6 | testing.expect(x == expected); | |
| 6 | testing.expectEqual(expected, x); | |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | test "ashlti3" { |
lib/std/special/compiler_rt/ashrdi3_test.zig created+55| ... | ... | @@ -0,0 +1,55 @@ |
| 1 | const __ashrdi3 = @import("shift.zig").__ashrdi3; | |
| 2 | const testing = @import("std").testing; | |
| 3 | ||
| 4 | fn test__ashrdi3(a: i64, b: i32, expected: u64) void { | |
| 5 | const x = __ashrdi3(a, b); | |
| 6 | testing.expectEqual(@bitCast(i64, expected), x); | |
| 7 | } | |
| 8 | ||
| 9 | test "ashrdi3" { | |
| 10 | test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF); | |
| 11 | test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x91A2B3C4D5E6F7); | |
| 12 | test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37B); | |
| 13 | test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x2468ACF13579BD); | |
| 14 | test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDE); | |
| 15 | ||
| 16 | test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x12345678); | |
| 17 | test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0x91A2B3C); | |
| 18 | test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0x48D159E); | |
| 19 | test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0x2468ACF); | |
| 20 | ||
| 21 | test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x1234567); | |
| 22 | ||
| 23 | test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x91A2B3); | |
| 24 | test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x48D159); | |
| 25 | test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x2468AC); | |
| 26 | test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x123456); | |
| 27 | ||
| 28 | test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0); | |
| 29 | test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0); | |
| 30 | test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0); | |
| 31 | test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0); | |
| 32 | ||
| 33 | test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 0, 0xFEDCBA9876543210); | |
| 34 | test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 1, 0xFF6E5D4C3B2A1908); | |
| 35 | test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 2, 0xFFB72EA61D950C84); | |
| 36 | test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 3, 0xFFDB97530ECA8642); | |
| 37 | test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 4, 0xFFEDCBA987654321); | |
| 38 | ||
| 39 | test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 28, 0xFFFFFFFFEDCBA987); | |
| 40 | test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 29, 0xFFFFFFFFF6E5D4C3); | |
| 41 | test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 30, 0xFFFFFFFFFB72EA61); | |
| 42 | test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 31, 0xFFFFFFFFFDB97530); | |
| 43 | ||
| 44 | test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 32, 0xFFFFFFFFFEDCBA98); | |
| 45 | ||
| 46 | test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 33, 0xFFFFFFFFFF6E5D4C); | |
| 47 | test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 34, 0xFFFFFFFFFFB72EA6); | |
| 48 | test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 35, 0xFFFFFFFFFFDB9753); | |
| 49 | test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 36, 0xFFFFFFFFFFEDCBA9); | |
| 50 | ||
| 51 | test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 60, 0xFFFFFFFFFFFFFFFA); | |
| 52 | test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 61, 0xFFFFFFFFFFFFFFFD); | |
| 53 | test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 62, 0xFFFFFFFFFFFFFFFE); | |
| 54 | test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 63, 0xFFFFFFFFFFFFFFFF); | |
| 55 | } |
lib/std/special/compiler_rt/ashrti3.zig deleted-42| ... | ... | @@ -1,42 +0,0 @@ |
| 1 | const builtin = @import("builtin"); | |
| 2 | const compiler_rt = @import("../compiler_rt.zig"); | |
| 3 | ||
| 4 | pub fn __ashrti3(a: i128, b: i32) callconv(.C) i128 { | |
| 5 | var input = twords{ .all = a }; | |
| 6 | var result: twords = undefined; | |
| 7 | ||
| 8 | if (b > 63) { | |
| 9 | // 64 <= b < 128 | |
| 10 | result.s.low = input.s.high >> @intCast(u6, b - 64); | |
| 11 | result.s.high = input.s.high >> 63; | |
| 12 | } else { | |
| 13 | // 0 <= b < 64 | |
| 14 | if (b == 0) return a; | |
| 15 | result.s.low = input.s.high << @intCast(u6, 64 - b); | |
| 16 | // Avoid sign-extension here | |
| 17 | result.s.low |= @bitCast(i64, @bitCast(u64, input.s.low) >> @intCast(u6, b)); | |
| 18 | result.s.high = input.s.high >> @intCast(u6, b); | |
| 19 | } | |
| 20 | ||
| 21 | return result.all; | |
| 22 | } | |
| 23 | ||
| 24 | const twords = extern union { | |
| 25 | all: i128, | |
| 26 | s: S, | |
| 27 | ||
| 28 | const S = if (builtin.endian == .Little) | |
| 29 | struct { | |
| 30 | low: i64, | |
| 31 | high: i64, | |
| 32 | } | |
| 33 | else | |
| 34 | struct { | |
| 35 | high: i64, | |
| 36 | low: i64, | |
| 37 | }; | |
| 38 | }; | |
| 39 | ||
| 40 | test "import ashrti3" { | |
| 41 | _ = @import("ashrti3_test.zig"); | |
| 42 | } |
lib/std/special/compiler_rt/ashrti3_test.zig+2-4| ... | ... | @@ -1,11 +1,9 @@ |
| 1 | const __ashrti3 = @import("ashrti3.zig").__ashrti3; | |
| 1 | const __ashrti3 = @import("shift.zig").__ashrti3; | |
| 2 | 2 | const testing = @import("std").testing; |
| 3 | 3 | |
| 4 | 4 | fn test__ashrti3(a: i128, b: i32, expected: i128) void { |
| 5 | 5 | const x = __ashrti3(a, b); |
| 6 | // @import("std").debug.warn("got 0x{x}\nexp 0x{x}\n", .{@truncate(u64, | |
| 7 | // @bitCast(u128, x) >> 64), @truncate(u64, @bitCast(u128, expected)) >> 64}); | |
| 8 | testing.expect(x == expected); | |
| 6 | testing.expectEqual(expected, x); | |
| 9 | 7 | } |
| 10 | 8 | |
| 11 | 9 | test "ashrti3" { |
lib/std/special/compiler_rt/clear_cache.zig+53-37| ... | ... | @@ -26,6 +26,10 @@ pub fn clear_cache(start: usize, end: usize) callconv(.C) void { |
| 26 | 26 | .mips, .mipsel, .mips64, .mips64el => true, |
| 27 | 27 | else => false, |
| 28 | 28 | }; |
| 29 | const riscv = switch (arch) { | |
| 30 | .riscv32, .riscv64 => true, | |
| 31 | else => false, | |
| 32 | }; | |
| 29 | 33 | const powerpc64 = switch (arch) { |
| 30 | 34 | .powerpc64, .powerpc64le => true, |
| 31 | 35 | else => false, |
| ... | ... | @@ -41,45 +45,42 @@ pub fn clear_cache(start: usize, end: usize) callconv(.C) void { |
| 41 | 45 | if (x86) { |
| 42 | 46 | // Intel processors have a unified instruction and data cache |
| 43 | 47 | // so there is nothing to do |
| 48 | exportIt(); | |
| 44 | 49 | } else if (os == .windows and (arm32 or arm64)) { |
| 45 | @compileError("TODO"); | |
| 50 | // TODO | |
| 46 | 51 | // FlushInstructionCache(GetCurrentProcess(), start, end - start); |
| 52 | // exportIt(); | |
| 47 | 53 | } else if (arm32 and !apple) { |
| 48 | @compileError("TODO"); | |
| 49 | //#if defined(__FreeBSD__) || defined(__NetBSD__) | |
| 50 | // struct arm_sync_icache_args arg; | |
| 51 | // | |
| 52 | // arg.addr = (uintptr_t)start; | |
| 53 | // arg.len = (uintptr_t)end - (uintptr_t)start; | |
| 54 | // | |
| 55 | // sysarch(ARM_SYNC_ICACHE, &arg); | |
| 56 | //#elif defined(__linux__) | |
| 57 | //// We used to include asm/unistd.h for the __ARM_NR_cacheflush define, but | |
| 58 | //// it also brought many other unused defines, as well as a dependency on | |
| 59 | //// kernel headers to be installed. | |
| 60 | //// | |
| 61 | //// This value is stable at least since Linux 3.13 and should remain so for | |
| 62 | //// compatibility reasons, warranting it's re-definition here. | |
| 63 | //#define __ARM_NR_cacheflush 0x0f0002 | |
| 64 | // register int start_reg __asm("r0") = (int)(intptr_t)start; | |
| 65 | // const register int end_reg __asm("r1") = (int)(intptr_t)end; | |
| 66 | // const register int flags __asm("r2") = 0; | |
| 67 | // const register int syscall_nr __asm("r7") = __ARM_NR_cacheflush; | |
| 68 | // __asm __volatile("svc 0x0" | |
| 69 | // : "=r"(start_reg) | |
| 70 | // : "r"(syscall_nr), "r"(start_reg), "r"(end_reg), "r"(flags)); | |
| 71 | // assert(start_reg == 0 && "Cache flush syscall failed."); | |
| 72 | //#else | |
| 73 | // compilerrt_abort(); | |
| 74 | //#endif | |
| 54 | switch (os) { | |
| 55 | .freebsd, .netbsd => { | |
| 56 | var arg = arm_sync_icache_args{ | |
| 57 | .addr = start, | |
| 58 | .len = end - start, | |
| 59 | }; | |
| 60 | const result = sysarch(ARM_SYNC_ICACHE, @ptrToInt(&arg)); | |
| 61 | std.debug.assert(result == 0); | |
| 62 | exportIt(); | |
| 63 | }, | |
| 64 | .linux => { | |
| 65 | const result = std.os.linux.syscall3(.cacheflush, start, end, 0); | |
| 66 | std.debug.assert(result == 0); | |
| 67 | exportIt(); | |
| 68 | }, | |
| 69 | else => {}, | |
| 70 | } | |
| 75 | 71 | } else if (os == .linux and mips) { |
| 76 | @compileError("TODO"); | |
| 77 | //const uintptr_t start_int = (uintptr_t)start; | |
| 78 | //const uintptr_t end_int = (uintptr_t)end; | |
| 79 | //syscall(__NR_cacheflush, start, (end_int - start_int), BCACHE); | |
| 72 | const flags = 3; // ICACHE | DCACHE | |
| 73 | const result = std.os.linux.syscall3(.cacheflush, start, end - start, flags); | |
| 74 | std.debug.assert(result == 0); | |
| 75 | exportIt(); | |
| 80 | 76 | } else if (mips and os == .openbsd) { |
| 81 | @compileError("TODO"); | |
| 77 | // TODO | |
| 82 | 78 | //cacheflush(start, (uintptr_t)end - (uintptr_t)start, BCACHE); |
| 79 | // exportIt(); | |
| 80 | } else if (os == .linux and riscv) { | |
| 81 | const result = std.os.linux.syscall3(.riscv_flush_icache, start, end - start, 0); | |
| 82 | std.debug.assert(result == 0); | |
| 83 | exportIt(); | |
| 83 | 84 | } else if (arm64 and !apple) { |
| 84 | 85 | // Get Cache Type Info. |
| 85 | 86 | // TODO memoize this? |
| ... | ... | @@ -118,8 +119,9 @@ pub fn clear_cache(start: usize, end: usize) callconv(.C) void { |
| 118 | 119 | } |
| 119 | 120 | } |
| 120 | 121 | asm volatile ("isb sy"); |
| 122 | exportIt(); | |
| 121 | 123 | } else if (powerpc64) { |
| 122 | @compileError("TODO"); | |
| 124 | // TODO | |
| 123 | 125 | //const size_t line_size = 32; |
| 124 | 126 | //const size_t len = (uintptr_t)end - (uintptr_t)start; |
| 125 | 127 | // |
| ... | ... | @@ -134,8 +136,9 @@ pub fn clear_cache(start: usize, end: usize) callconv(.C) void { |
| 134 | 136 | //for (uintptr_t line = start_line; line < end_line; line += line_size) |
| 135 | 137 | // __asm__ volatile("icbi 0, %0" : : "r"(line)); |
| 136 | 138 | //__asm__ volatile("isync"); |
| 139 | // exportIt(); | |
| 137 | 140 | } else if (sparc) { |
| 138 | @compileError("TODO"); | |
| 141 | // TODO | |
| 139 | 142 | //const size_t dword_size = 8; |
| 140 | 143 | //const size_t len = (uintptr_t)end - (uintptr_t)start; |
| 141 | 144 | // |
| ... | ... | @@ -145,13 +148,26 @@ pub fn clear_cache(start: usize, end: usize) callconv(.C) void { |
| 145 | 148 | // |
| 146 | 149 | //for (uintptr_t dword = start_dword; dword < end_dword; dword += dword_size) |
| 147 | 150 | // __asm__ volatile("flush %0" : : "r"(dword)); |
| 151 | // exportIt(); | |
| 148 | 152 | } else if (apple) { |
| 149 | 153 | // On Darwin, sys_icache_invalidate() provides this functionality |
| 150 | 154 | sys_icache_invalidate(start, end - start); |
| 151 | } else { | |
| 152 | @compileError("no __clear_cache implementation available for this target"); | |
| 155 | exportIt(); | |
| 153 | 156 | } |
| 154 | 157 | } |
| 155 | 158 | |
| 159 | const linkage = if (std.builtin.is_test) std.builtin.GlobalLinkage.Internal else std.builtin.GlobalLinkage.Weak; | |
| 160 | ||
| 161 | fn exportIt() void { | |
| 162 | @export(clear_cache, .{ .name = "__clear_cache", .linkage = linkage }); | |
| 163 | } | |
| 164 | ||
| 156 | 165 | // Darwin-only |
| 157 | 166 | extern fn sys_icache_invalidate(start: usize, len: usize) void; |
| 167 | // BSD-only | |
| 168 | const arm_sync_icache_args = extern struct { | |
| 169 | addr: usize, // Virtual start address | |
| 170 | len: usize, // Region size | |
| 171 | }; | |
| 172 | const ARM_SYNC_ICACHE = 0; | |
| 173 | extern "c" fn sysarch(number: i32, args: usize) i32; |
lib/std/special/compiler_rt/lshrdi3_test.zig created+55| ... | ... | @@ -0,0 +1,55 @@ |
| 1 | const __lshrdi3 = @import("shift.zig").__lshrdi3; | |
| 2 | const testing = @import("std").testing; | |
| 3 | ||
| 4 | fn test__lshrdi3(a: i64, b: i32, expected: u64) void { | |
| 5 | const x = __lshrdi3(a, b); | |
| 6 | testing.expectEqual(@bitCast(i64, expected), x); | |
| 7 | } | |
| 8 | ||
| 9 | test "lshrdi3" { | |
| 10 | test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF); | |
| 11 | test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x91A2B3C4D5E6F7); | |
| 12 | test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37B); | |
| 13 | test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x2468ACF13579BD); | |
| 14 | test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDE); | |
| 15 | ||
| 16 | test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x12345678); | |
| 17 | test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0x91A2B3C); | |
| 18 | test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0x48D159E); | |
| 19 | test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0x2468ACF); | |
| 20 | ||
| 21 | test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x1234567); | |
| 22 | ||
| 23 | test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x91A2B3); | |
| 24 | test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x48D159); | |
| 25 | test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x2468AC); | |
| 26 | test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x123456); | |
| 27 | ||
| 28 | test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0); | |
| 29 | test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0); | |
| 30 | test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0); | |
| 31 | test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0); | |
| 32 | ||
| 33 | test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 0, 0xFEDCBA9876543210); | |
| 34 | test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 1, 0x7F6E5D4C3B2A1908); | |
| 35 | test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 2, 0x3FB72EA61D950C84); | |
| 36 | test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 3, 0x1FDB97530ECA8642); | |
| 37 | test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 4, 0xFEDCBA987654321); | |
| 38 | ||
| 39 | test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 28, 0xFEDCBA987); | |
| 40 | test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 29, 0x7F6E5D4C3); | |
| 41 | test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 30, 0x3FB72EA61); | |
| 42 | test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 31, 0x1FDB97530); | |
| 43 | ||
| 44 | test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 32, 0xFEDCBA98); | |
| 45 | ||
| 46 | test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 33, 0x7F6E5D4C); | |
| 47 | test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 34, 0x3FB72EA6); | |
| 48 | test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 35, 0x1FDB9753); | |
| 49 | test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 36, 0xFEDCBA9); | |
| 50 | ||
| 51 | test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 60, 0xA); | |
| 52 | test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 61, 0x5); | |
| 53 | test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 62, 0x2); | |
| 54 | test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 63, 0x1); | |
| 55 | } |
lib/std/special/compiler_rt/lshrti3.zig deleted-41| ... | ... | @@ -1,41 +0,0 @@ |
| 1 | const builtin = @import("builtin"); | |
| 2 | const compiler_rt = @import("../compiler_rt.zig"); | |
| 3 | ||
| 4 | pub fn __lshrti3(a: i128, b: i32) callconv(.C) i128 { | |
| 5 | var input = twords{ .all = a }; | |
| 6 | var result: twords = undefined; | |
| 7 | ||
| 8 | if (b > 63) { | |
| 9 | // 64 <= b < 128 | |
| 10 | result.s.low = input.s.high >> @intCast(u6, b - 64); | |
| 11 | result.s.high = 0; | |
| 12 | } else { | |
| 13 | // 0 <= b < 64 | |
| 14 | if (b == 0) return a; | |
| 15 | result.s.low = input.s.high << @intCast(u6, 64 - b); | |
| 16 | result.s.low |= input.s.low >> @intCast(u6, b); | |
| 17 | result.s.high = input.s.high >> @intCast(u6, b); | |
| 18 | } | |
| 19 | ||
| 20 | return result.all; | |
| 21 | } | |
| 22 | ||
| 23 | const twords = extern union { | |
| 24 | all: i128, | |
| 25 | s: S, | |
| 26 | ||
| 27 | const S = if (builtin.endian == .Little) | |
| 28 | struct { | |
| 29 | low: u64, | |
| 30 | high: u64, | |
| 31 | } | |
| 32 | else | |
| 33 | struct { | |
| 34 | high: u64, | |
| 35 | low: u64, | |
| 36 | }; | |
| 37 | }; | |
| 38 | ||
| 39 | test "import lshrti3" { | |
| 40 | _ = @import("lshrti3_test.zig"); | |
| 41 | } |
lib/std/special/compiler_rt/lshrti3_test.zig+2-2| ... | ... | @@ -1,9 +1,9 @@ |
| 1 | const __lshrti3 = @import("lshrti3.zig").__lshrti3; | |
| 1 | const __lshrti3 = @import("shift.zig").__lshrti3; | |
| 2 | 2 | const testing = @import("std").testing; |
| 3 | 3 | |
| 4 | 4 | fn test__lshrti3(a: i128, b: i32, expected: i128) void { |
| 5 | 5 | const x = __lshrti3(a, b); |
| 6 | testing.expect(x == expected); | |
| 6 | testing.expectEqual(expected, x); | |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | test "lshrti3" { |
lib/std/special/compiler_rt/shift.zig created+130| ... | ... | @@ -0,0 +1,130 @@ |
| 1 | const std = @import("std"); | |
| 2 | const builtin = std.builtin; | |
| 3 | const Log2Int = std.math.Log2Int; | |
| 4 | ||
| 5 | fn Dwords(comptime T: type, comptime signed_half: bool) type { | |
| 6 | return extern union { | |
| 7 | pub const HalfTU = std.meta.IntType(false, @divExact(T.bit_count, 2)); | |
| 8 | pub const HalfTS = std.meta.IntType(true, @divExact(T.bit_count, 2)); | |
| 9 | pub const HalfT = if (signed_half) HalfTS else HalfTU; | |
| 10 | ||
| 11 | all: T, | |
| 12 | s: if (builtin.endian == .Little) | |
| 13 | struct { low: HalfT, high: HalfT } | |
| 14 | else | |
| 15 | struct { high: HalfT, low: HalfT }, | |
| 16 | }; | |
| 17 | } | |
| 18 | ||
| 19 | // Arithmetic shift left | |
| 20 | // Precondition: 0 <= b < bits_in_dword | |
| 21 | pub fn ashlXi3(comptime T: type, a: T, b: i32) T { | |
| 22 | const dwords = Dwords(T, false); | |
| 23 | const S = Log2Int(dwords.HalfT); | |
| 24 | ||
| 25 | const input = dwords{ .all = a }; | |
| 26 | var output: dwords = undefined; | |
| 27 | ||
| 28 | if (b >= dwords.HalfT.bit_count) { | |
| 29 | output.s.low = 0; | |
| 30 | output.s.high = input.s.low << @intCast(S, b - dwords.HalfT.bit_count); | |
| 31 | } else if (b == 0) { | |
| 32 | return a; | |
| 33 | } else { | |
| 34 | output.s.low = input.s.low << @intCast(S, b); | |
| 35 | output.s.high = input.s.high << @intCast(S, b); | |
| 36 | output.s.high |= input.s.low >> @intCast(S, dwords.HalfT.bit_count - b); | |
| 37 | } | |
| 38 | ||
| 39 | return output.all; | |
| 40 | } | |
| 41 | ||
| 42 | // Arithmetic shift right | |
| 43 | // Precondition: 0 <= b < T.bit_count | |
| 44 | pub fn ashrXi3(comptime T: type, a: T, b: i32) T { | |
| 45 | const dwords = Dwords(T, true); | |
| 46 | const S = Log2Int(dwords.HalfT); | |
| 47 | ||
| 48 | const input = dwords{ .all = a }; | |
| 49 | var output: dwords = undefined; | |
| 50 | ||
| 51 | if (b >= dwords.HalfT.bit_count) { | |
| 52 | output.s.high = input.s.high >> (dwords.HalfT.bit_count - 1); | |
| 53 | output.s.low = input.s.high >> @intCast(S, b - dwords.HalfT.bit_count); | |
| 54 | } else if (b == 0) { | |
| 55 | return a; | |
| 56 | } else { | |
| 57 | output.s.high = input.s.high >> @intCast(S, b); | |
| 58 | output.s.low = input.s.high << @intCast(S, dwords.HalfT.bit_count - b); | |
| 59 | // Avoid sign-extension here | |
| 60 | output.s.low |= @bitCast( | |
| 61 | dwords.HalfT, | |
| 62 | @bitCast(dwords.HalfTU, input.s.low) >> @intCast(S, b), | |
| 63 | ); | |
| 64 | } | |
| 65 | ||
| 66 | return output.all; | |
| 67 | } | |
| 68 | ||
| 69 | // Logical shift right | |
| 70 | // Precondition: 0 <= b < T.bit_count | |
| 71 | pub fn lshrXi3(comptime T: type, a: T, b: i32) T { | |
| 72 | const dwords = Dwords(T, false); | |
| 73 | const S = Log2Int(dwords.HalfT); | |
| 74 | ||
| 75 | const input = dwords{ .all = a }; | |
| 76 | var output: dwords = undefined; | |
| 77 | ||
| 78 | if (b >= dwords.HalfT.bit_count) { | |
| 79 | output.s.high = 0; | |
| 80 | output.s.low = input.s.high >> @intCast(S, b - dwords.HalfT.bit_count); | |
| 81 | } else if (b == 0) { | |
| 82 | return a; | |
| 83 | } else { | |
| 84 | output.s.high = input.s.high >> @intCast(S, b); | |
| 85 | output.s.low = input.s.high << @intCast(S, dwords.HalfT.bit_count - b); | |
| 86 | output.s.low |= input.s.low >> @intCast(S, b); | |
| 87 | } | |
| 88 | ||
| 89 | return output.all; | |
| 90 | } | |
| 91 | ||
| 92 | pub fn __ashldi3(a: i64, b: i32) callconv(.C) i64 { | |
| 93 | return @call(.{ .modifier = .always_inline }, ashlXi3, .{ i64, a, b }); | |
| 94 | } | |
| 95 | pub fn __ashlti3(a: i128, b: i32) callconv(.C) i128 { | |
| 96 | return @call(.{ .modifier = .always_inline }, ashlXi3, .{ i128, a, b }); | |
| 97 | } | |
| 98 | pub fn __ashrdi3(a: i64, b: i32) callconv(.C) i64 { | |
| 99 | return @call(.{ .modifier = .always_inline }, ashrXi3, .{ i64, a, b }); | |
| 100 | } | |
| 101 | pub fn __ashrti3(a: i128, b: i32) callconv(.C) i128 { | |
| 102 | return @call(.{ .modifier = .always_inline }, ashrXi3, .{ i128, a, b }); | |
| 103 | } | |
| 104 | pub fn __lshrdi3(a: i64, b: i32) callconv(.C) i64 { | |
| 105 | return @call(.{ .modifier = .always_inline }, lshrXi3, .{ i64, a, b }); | |
| 106 | } | |
| 107 | pub fn __lshrti3(a: i128, b: i32) callconv(.C) i128 { | |
| 108 | return @call(.{ .modifier = .always_inline }, lshrXi3, .{ i128, a, b }); | |
| 109 | } | |
| 110 | ||
| 111 | pub fn __aeabi_llsl(a: i64, b: i32) callconv(.AAPCS) i64 { | |
| 112 | return __ashldi3(a, b); | |
| 113 | } | |
| 114 | pub fn __aeabi_lasr(a: i64, b: i32) callconv(.AAPCS) i64 { | |
| 115 | return __ashrdi3(a, b); | |
| 116 | } | |
| 117 | pub fn __aeabi_llsr(a: i64, b: i32) callconv(.AAPCS) i64 { | |
| 118 | return __lshrdi3(a, b); | |
| 119 | } | |
| 120 | ||
| 121 | test "" { | |
| 122 | _ = @import("ashrdi3_test.zig"); | |
| 123 | _ = @import("ashrti3_test.zig"); | |
| 124 | ||
| 125 | _ = @import("ashldi3_test.zig"); | |
| 126 | _ = @import("ashlti3_test.zig"); | |
| 127 | ||
| 128 | _ = @import("lshrdi3_test.zig"); | |
| 129 | _ = @import("lshrti3_test.zig"); | |
| 130 | } |
lib/std/std.zig+1-1| ... | ... | @@ -1,10 +1,10 @@ |
| 1 | 1 | pub const AlignedArrayList = @import("array_list.zig").AlignedArrayList; |
| 2 | 2 | pub const ArrayList = @import("array_list.zig").ArrayList; |
| 3 | pub const ArrayListSentineled = @import("array_list_sentineled.zig").ArrayListSentineled; | |
| 3 | 4 | pub const AutoHashMap = @import("hash_map.zig").AutoHashMap; |
| 4 | 5 | pub const BloomFilter = @import("bloom_filter.zig").BloomFilter; |
| 5 | 6 | pub const BufMap = @import("buf_map.zig").BufMap; |
| 6 | 7 | pub const BufSet = @import("buf_set.zig").BufSet; |
| 7 | pub const Buffer = @import("buffer.zig").Buffer; | |
| 8 | 8 | pub const ChildProcess = @import("child_process.zig").ChildProcess; |
| 9 | 9 | pub const DynLib = @import("dynamic_library.zig").DynLib; |
| 10 | 10 | pub const HashMap = @import("hash_map.zig").HashMap; |
lib/std/target.zig+4-4| ... | ... | @@ -967,15 +967,15 @@ pub const Target = struct { |
| 967 | 967 | |
| 968 | 968 | pub const stack_align = 16; |
| 969 | 969 | |
| 970 | pub fn zigTriple(self: Target, allocator: *mem.Allocator) ![:0]u8 { | |
| 970 | pub fn zigTriple(self: Target, allocator: *mem.Allocator) ![]u8 { | |
| 971 | 971 | return std.zig.CrossTarget.fromTarget(self).zigTriple(allocator); |
| 972 | 972 | } |
| 973 | 973 | |
| 974 | pub fn linuxTripleSimple(allocator: *mem.Allocator, cpu_arch: Cpu.Arch, os_tag: Os.Tag, abi: Abi) ![:0]u8 { | |
| 975 | return std.fmt.allocPrint0(allocator, "{}-{}-{}", .{ @tagName(cpu_arch), @tagName(os_tag), @tagName(abi) }); | |
| 974 | pub fn linuxTripleSimple(allocator: *mem.Allocator, cpu_arch: Cpu.Arch, os_tag: Os.Tag, abi: Abi) ![]u8 { | |
| 975 | return std.fmt.allocPrint(allocator, "{}-{}-{}", .{ @tagName(cpu_arch), @tagName(os_tag), @tagName(abi) }); | |
| 976 | 976 | } |
| 977 | 977 | |
| 978 | pub fn linuxTriple(self: Target, allocator: *mem.Allocator) ![:0]u8 { | |
| 978 | pub fn linuxTriple(self: Target, allocator: *mem.Allocator) ![]u8 { | |
| 979 | 979 | return linuxTripleSimple(allocator, self.cpu.arch, self.os.tag, self.abi); |
| 980 | 980 | } |
| 981 | 981 |
lib/std/thread.zig+1-1| ... | ... | @@ -464,7 +464,7 @@ pub const Thread = struct { |
| 464 | 464 | var count: c_int = undefined; |
| 465 | 465 | var count_len: usize = @sizeOf(c_int); |
| 466 | 466 | const name = if (comptime std.Target.current.isDarwin()) "hw.logicalcpu" else "hw.ncpu"; |
| 467 | os.sysctlbynameC(name, &count, &count_len, null, 0) catch |err| switch (err) { | |
| 467 | os.sysctlbynameZ(name, &count, &count_len, null, 0) catch |err| switch (err) { | |
| 468 | 468 | error.NameTooLong, error.UnknownName => unreachable, |
| 469 | 469 | else => |e| return e, |
| 470 | 470 | }; |
lib/std/zig/cross_target.zig+18-8| ... | ... | @@ -495,17 +495,19 @@ pub const CrossTarget = struct { |
| 495 | 495 | return self.isNativeCpu() and self.isNativeOs() and self.abi == null; |
| 496 | 496 | } |
| 497 | 497 | |
| 498 | pub fn zigTriple(self: CrossTarget, allocator: *mem.Allocator) error{OutOfMemory}![:0]u8 { | |
| 498 | pub fn zigTriple(self: CrossTarget, allocator: *mem.Allocator) error{OutOfMemory}![]u8 { | |
| 499 | 499 | if (self.isNative()) { |
| 500 | return mem.dupeZ(allocator, u8, "native"); | |
| 500 | return mem.dupe(allocator, u8, "native"); | |
| 501 | 501 | } |
| 502 | 502 | |
| 503 | 503 | const arch_name = if (self.cpu_arch) |arch| @tagName(arch) else "native"; |
| 504 | 504 | const os_name = if (self.os_tag) |os_tag| @tagName(os_tag) else "native"; |
| 505 | 505 | |
| 506 | var result = try std.Buffer.allocPrint(allocator, "{}-{}", .{ arch_name, os_name }); | |
| 506 | var result = std.ArrayList(u8).init(allocator); | |
| 507 | 507 | defer result.deinit(); |
| 508 | 508 | |
| 509 | try result.outStream().print("{}-{}", .{ arch_name, os_name }); | |
| 510 | ||
| 509 | 511 | // The zig target syntax does not allow specifying a max os version with no min, so |
| 510 | 512 | // if either are present, we need the min. |
| 511 | 513 | if (self.os_version_min != null or self.os_version_max != null) { |
| ... | ... | @@ -532,13 +534,13 @@ pub const CrossTarget = struct { |
| 532 | 534 | return result.toOwnedSlice(); |
| 533 | 535 | } |
| 534 | 536 | |
| 535 | pub fn allocDescription(self: CrossTarget, allocator: *mem.Allocator) ![:0]u8 { | |
| 537 | pub fn allocDescription(self: CrossTarget, allocator: *mem.Allocator) ![]u8 { | |
| 536 | 538 | // TODO is there anything else worthy of the description that is not |
| 537 | 539 | // already captured in the triple? |
| 538 | 540 | return self.zigTriple(allocator); |
| 539 | 541 | } |
| 540 | 542 | |
| 541 | pub fn linuxTriple(self: CrossTarget, allocator: *mem.Allocator) ![:0]u8 { | |
| 543 | pub fn linuxTriple(self: CrossTarget, allocator: *mem.Allocator) ![]u8 { | |
| 542 | 544 | return Target.linuxTripleSimple(allocator, self.getCpuArch(), self.getOsTag(), self.getAbi()); |
| 543 | 545 | } |
| 544 | 546 | |
| ... | ... | @@ -549,7 +551,7 @@ pub const CrossTarget = struct { |
| 549 | 551 | pub const VcpkgLinkage = std.builtin.LinkMode; |
| 550 | 552 | |
| 551 | 553 | /// Returned slice must be freed by the caller. |
| 552 | pub fn vcpkgTriplet(self: CrossTarget, allocator: *mem.Allocator, linkage: VcpkgLinkage) ![:0]u8 { | |
| 554 | pub fn vcpkgTriplet(self: CrossTarget, allocator: *mem.Allocator, linkage: VcpkgLinkage) ![]u8 { | |
| 553 | 555 | const arch = switch (self.getCpuArch()) { |
| 554 | 556 | .i386 => "x86", |
| 555 | 557 | .x86_64 => "x64", |
| ... | ... | @@ -580,7 +582,7 @@ pub const CrossTarget = struct { |
| 580 | 582 | .Dynamic => "", |
| 581 | 583 | }; |
| 582 | 584 | |
| 583 | return std.fmt.allocPrint0(allocator, "{}-{}{}", .{ arch, os, static_suffix }); | |
| 585 | return std.fmt.allocPrint(allocator, "{}-{}{}", .{ arch, os, static_suffix }); | |
| 584 | 586 | } |
| 585 | 587 | |
| 586 | 588 | pub const Executor = union(enum) { |
| ... | ... | @@ -763,7 +765,15 @@ test "CrossTarget.parse" { |
| 763 | 765 | |
| 764 | 766 | const text = try cross_target.zigTriple(std.testing.allocator); |
| 765 | 767 | defer std.testing.allocator.free(text); |
| 766 | std.testing.expectEqualSlices(u8, "native-native-gnu.2.1.1", text); | |
| 768 | ||
| 769 | var buf: [256]u8 = undefined; | |
| 770 | const triple = std.fmt.bufPrint( | |
| 771 | buf[0..], | |
| 772 | "native-native-{}.2.1.1", | |
| 773 | .{@tagName(std.Target.current.abi)}, | |
| 774 | ) catch unreachable; | |
| 775 | ||
| 776 | std.testing.expectEqualSlices(u8, triple, text); | |
| 767 | 777 | } |
| 768 | 778 | { |
| 769 | 779 | const cross_target = try CrossTarget.parse(.{ |
lib/std/zig/parser_test.zig+30-1| ... | ... | @@ -373,6 +373,35 @@ test "zig fmt: correctly move doc comments on struct fields" { |
| 373 | 373 | ); |
| 374 | 374 | } |
| 375 | 375 | |
| 376 | test "zig fmt: correctly space struct fields with doc comments" { | |
| 377 | try testTransform( | |
| 378 | \\pub const S = struct { | |
| 379 | \\ /// A | |
| 380 | \\ a: u8, | |
| 381 | \\ /// B | |
| 382 | \\ /// B (cont) | |
| 383 | \\ b: u8, | |
| 384 | \\ | |
| 385 | \\ | |
| 386 | \\ /// C | |
| 387 | \\ c: u8, | |
| 388 | \\}; | |
| 389 | \\ | |
| 390 | , | |
| 391 | \\pub const S = struct { | |
| 392 | \\ /// A | |
| 393 | \\ a: u8, | |
| 394 | \\ /// B | |
| 395 | \\ /// B (cont) | |
| 396 | \\ b: u8, | |
| 397 | \\ | |
| 398 | \\ /// C | |
| 399 | \\ c: u8, | |
| 400 | \\}; | |
| 401 | \\ | |
| 402 | ); | |
| 403 | } | |
| 404 | ||
| 376 | 405 | test "zig fmt: doc comments on param decl" { |
| 377 | 406 | try testCanonical( |
| 378 | 407 | \\pub const Allocator = struct { |
| ... | ... | @@ -2924,7 +2953,7 @@ fn testParse(source: []const u8, allocator: *mem.Allocator, anything_changed: *b |
| 2924 | 2953 | return error.ParseError; |
| 2925 | 2954 | } |
| 2926 | 2955 | |
| 2927 | var buffer = try std.Buffer.initSize(allocator, 0); | |
| 2956 | var buffer = std.ArrayList(u8).init(allocator); | |
| 2928 | 2957 | errdefer buffer.deinit(); |
| 2929 | 2958 | |
| 2930 | 2959 | anything_changed.* = try std.zig.render(allocator, buffer.outStream(), tree); |
lib/std/zig/render.zig+6-2| ... | ... | @@ -187,12 +187,16 @@ fn renderExtraNewline(tree: *ast.Tree, stream: var, start_col: *usize, node: *as |
| 187 | 187 | const first_token = node.firstToken(); |
| 188 | 188 | var prev_token = first_token; |
| 189 | 189 | if (prev_token == 0) return; |
| 190 | var newline_threshold: usize = 2; | |
| 190 | 191 | while (tree.tokens.at(prev_token - 1).id == .DocComment) { |
| 192 | if (tree.tokenLocation(tree.tokens.at(prev_token - 1).end, prev_token).line == 1) { | |
| 193 | newline_threshold += 1; | |
| 194 | } | |
| 191 | 195 | prev_token -= 1; |
| 192 | 196 | } |
| 193 | 197 | const prev_token_end = tree.tokens.at(prev_token - 1).end; |
| 194 | 198 | const loc = tree.tokenLocation(prev_token_end, first_token); |
| 195 | if (loc.line >= 2) { | |
| 199 | if (loc.line >= newline_threshold) { | |
| 196 | 200 | try stream.writeByte('\n'); |
| 197 | 201 | start_col.* = 0; |
| 198 | 202 | } |
| ... | ... | @@ -1527,7 +1531,7 @@ fn renderExpression( |
| 1527 | 1531 | try renderToken(tree, stream, callconv_rparen, indent, start_col, Space.Space); // ) |
| 1528 | 1532 | } else if (cc_rewrite_str) |str| { |
| 1529 | 1533 | try stream.writeAll("callconv("); |
| 1530 | try stream.writeAll(mem.toSliceConst(u8, str)); | |
| 1534 | try stream.writeAll(mem.spanZ(str)); | |
| 1531 | 1535 | try stream.writeAll(") "); |
| 1532 | 1536 | } |
| 1533 | 1537 |
lib/std/zig/system.zig+17-13| ... | ... | @@ -119,7 +119,7 @@ pub const NativePaths = struct { |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | fn deinitArray(array: *ArrayList([:0]u8)) void { |
| 122 | for (array.toSlice()) |item| { | |
| 122 | for (array.span()) |item| { | |
| 123 | 123 | array.allocator.free(item); |
| 124 | 124 | } |
| 125 | 125 | array.deinit(); |
| ... | ... | @@ -201,7 +201,7 @@ pub const NativeTargetInfo = struct { |
| 201 | 201 | switch (Target.current.os.tag) { |
| 202 | 202 | .linux => { |
| 203 | 203 | const uts = std.os.uname(); |
| 204 | const release = mem.toSliceConst(u8, &uts.release); | |
| 204 | const release = mem.spanZ(&uts.release); | |
| 205 | 205 | // The release field may have several other fields after the |
| 206 | 206 | // kernel version |
| 207 | 207 | const kernel_version = if (mem.indexOfScalar(u8, release, '-')) |pos| |
| ... | ... | @@ -265,7 +265,7 @@ pub const NativeTargetInfo = struct { |
| 265 | 265 | // The osproductversion sysctl was introduced first with |
| 266 | 266 | // High Sierra, thankfully that's also the baseline that Zig |
| 267 | 267 | // supports |
| 268 | std.os.sysctlbynameC( | |
| 268 | std.os.sysctlbynameZ( | |
| 269 | 269 | "kern.osproductversion", |
| 270 | 270 | &product_version, |
| 271 | 271 | &size, |
| ... | ... | @@ -460,7 +460,7 @@ pub const NativeTargetInfo = struct { |
| 460 | 460 | return result; |
| 461 | 461 | } |
| 462 | 462 | |
| 463 | const env_file = std.fs.openFileAbsoluteC("/usr/bin/env", .{}) catch |err| switch (err) { | |
| 463 | const env_file = std.fs.openFileAbsoluteZ("/usr/bin/env", .{}) catch |err| switch (err) { | |
| 464 | 464 | error.NoSpaceLeft => unreachable, |
| 465 | 465 | error.NameTooLong => unreachable, |
| 466 | 466 | error.PathAlreadyExists => unreachable, |
| ... | ... | @@ -515,7 +515,7 @@ pub const NativeTargetInfo = struct { |
| 515 | 515 | |
| 516 | 516 | fn glibcVerFromSO(so_path: [:0]const u8) !std.builtin.Version { |
| 517 | 517 | var link_buf: [std.os.PATH_MAX]u8 = undefined; |
| 518 | const link_name = std.os.readlinkC(so_path.ptr, &link_buf) catch |err| switch (err) { | |
| 518 | const link_name = std.os.readlinkZ(so_path.ptr, &link_buf) catch |err| switch (err) { | |
| 519 | 519 | error.AccessDenied => return error.GnuLibCVersionUnavailable, |
| 520 | 520 | error.FileSystem => return error.FileSystem, |
| 521 | 521 | error.SymLinkLoop => return error.SymLinkLoop, |
| ... | ... | @@ -625,9 +625,10 @@ pub const NativeTargetInfo = struct { |
| 625 | 625 | const p_offset = elfInt(is_64, need_bswap, ph32.p_offset, ph64.p_offset); |
| 626 | 626 | const p_filesz = elfInt(is_64, need_bswap, ph32.p_filesz, ph64.p_filesz); |
| 627 | 627 | if (p_filesz > result.dynamic_linker.buffer.len) return error.NameTooLong; |
| 628 | _ = try preadMin(file, result.dynamic_linker.buffer[0..p_filesz], p_offset, p_filesz); | |
| 629 | // PT_INTERP includes a null byte in p_filesz. | |
| 630 | const len = p_filesz - 1; | |
| 628 | const filesz = @intCast(usize, p_filesz); | |
| 629 | _ = try preadMin(file, result.dynamic_linker.buffer[0..filesz], p_offset, filesz); | |
| 630 | // PT_INTERP includes a null byte in filesz. | |
| 631 | const len = filesz - 1; | |
| 631 | 632 | // dynamic_linker.max_byte is "max", not "len". |
| 632 | 633 | // We know it will fit in u8 because we check against dynamic_linker.buffer.len above. |
| 633 | 634 | result.dynamic_linker.max_byte = @intCast(u8, len - 1); |
| ... | ... | @@ -648,7 +649,7 @@ pub const NativeTargetInfo = struct { |
| 648 | 649 | { |
| 649 | 650 | var dyn_off = elfInt(is_64, need_bswap, ph32.p_offset, ph64.p_offset); |
| 650 | 651 | const p_filesz = elfInt(is_64, need_bswap, ph32.p_filesz, ph64.p_filesz); |
| 651 | const dyn_size: u64 = if (is_64) @sizeOf(elf.Elf64_Dyn) else @sizeOf(elf.Elf32_Dyn); | |
| 652 | const dyn_size: usize = if (is_64) @sizeOf(elf.Elf64_Dyn) else @sizeOf(elf.Elf32_Dyn); | |
| 652 | 653 | const dyn_num = p_filesz / dyn_size; |
| 653 | 654 | var dyn_buf: [16 * @sizeOf(elf.Elf64_Dyn)]u8 align(@alignOf(elf.Elf64_Dyn)) = undefined; |
| 654 | 655 | var dyn_i: usize = 0; |
| ... | ... | @@ -739,7 +740,7 @@ pub const NativeTargetInfo = struct { |
| 739 | 740 | ); |
| 740 | 741 | const sh_name_off = elfInt(is_64, need_bswap, sh32.sh_name, sh64.sh_name); |
| 741 | 742 | // TODO this pointer cast should not be necessary |
| 742 | const sh_name = mem.toSliceConst(u8, @ptrCast([*:0]u8, shstrtab[sh_name_off..].ptr)); | |
| 743 | const sh_name = mem.spanZ(@ptrCast([*:0]u8, shstrtab[sh_name_off..].ptr)); | |
| 743 | 744 | if (mem.eql(u8, sh_name, ".dynstr")) { |
| 744 | 745 | break :find_dyn_str .{ |
| 745 | 746 | .offset = elfInt(is_64, need_bswap, sh32.sh_offset, sh64.sh_offset), |
| ... | ... | @@ -754,7 +755,10 @@ pub const NativeTargetInfo = struct { |
| 754 | 755 | const strtab_read_len = try preadMin(file, &strtab_buf, ds.offset, shstrtab_len); |
| 755 | 756 | const strtab = strtab_buf[0..strtab_read_len]; |
| 756 | 757 | // TODO this pointer cast should not be necessary |
| 757 | const rpath_list = mem.toSliceConst(u8, @ptrCast([*:0]u8, strtab[rpoff..].ptr)); | |
| 758 | const rpoff_usize = std.math.cast(usize, rpoff) catch |err| switch (err) { | |
| 759 | error.Overflow => return error.InvalidElfFile, | |
| 760 | }; | |
| 761 | const rpath_list = mem.spanZ(@ptrCast([*:0]u8, strtab[rpoff_usize..].ptr)); | |
| 758 | 762 | var it = mem.tokenize(rpath_list, ":"); |
| 759 | 763 | while (it.next()) |rpath| { |
| 760 | 764 | var dir = fs.cwd().openDir(rpath, .{}) catch |err| switch (err) { |
| ... | ... | @@ -779,7 +783,7 @@ pub const NativeTargetInfo = struct { |
| 779 | 783 | defer dir.close(); |
| 780 | 784 | |
| 781 | 785 | var link_buf: [std.os.PATH_MAX]u8 = undefined; |
| 782 | const link_name = std.os.readlinkatC( | |
| 786 | const link_name = std.os.readlinkatZ( | |
| 783 | 787 | dir.fd, |
| 784 | 788 | glibc_so_basename, |
| 785 | 789 | &link_buf, |
| ... | ... | @@ -814,7 +818,7 @@ pub const NativeTargetInfo = struct { |
| 814 | 818 | } |
| 815 | 819 | |
| 816 | 820 | fn preadMin(file: fs.File, buf: []u8, offset: u64, min_read_len: usize) !usize { |
| 817 | var i: u64 = 0; | |
| 821 | var i: usize = 0; | |
| 818 | 822 | while (i < min_read_len) { |
| 819 | 823 | const len = file.pread(buf[i .. buf.len - i], offset + i) catch |err| switch (err) { |
| 820 | 824 | error.OperationAborted => unreachable, // Windows-only |
src-self-hosted/clang_options_data.zig+85-50| ... | ... | @@ -7,7 +7,7 @@ flagpd1("CC"), |
| 7 | 7 | .{ |
| 8 | 8 | .name = "E", |
| 9 | 9 | .syntax = .flag, |
| 10 | .zig_equivalent = .preprocess, | |
| 10 | .zig_equivalent = .pp_or_asm, | |
| 11 | 11 | .pd1 = true, |
| 12 | 12 | .pd2 = false, |
| 13 | 13 | .psl = false, |
| ... | ... | @@ -26,12 +26,26 @@ flagpd1("H"), |
| 26 | 26 | }, |
| 27 | 27 | flagpd1("I-"), |
| 28 | 28 | flagpd1("M"), |
| 29 | flagpd1("MD"), | |
| 29 | .{ | |
| 30 | .name = "MD", | |
| 31 | .syntax = .flag, | |
| 32 | .zig_equivalent = .dep_file, | |
| 33 | .pd1 = true, | |
| 34 | .pd2 = false, | |
| 35 | .psl = false, | |
| 36 | }, | |
| 30 | 37 | flagpd1("MG"), |
| 31 | 38 | flagpd1("MM"), |
| 32 | 39 | flagpd1("MMD"), |
| 33 | 40 | flagpd1("MP"), |
| 34 | flagpd1("MV"), | |
| 41 | .{ | |
| 42 | .name = "MV", | |
| 43 | .syntax = .flag, | |
| 44 | .zig_equivalent = .dep_file, | |
| 45 | .pd1 = true, | |
| 46 | .pd2 = false, | |
| 47 | .psl = false, | |
| 48 | }, | |
| 35 | 49 | flagpd1("Mach"), |
| 36 | 50 | flagpd1("O0"), |
| 37 | 51 | flagpd1("O4"), |
| ... | ... | @@ -53,7 +67,7 @@ flagpd1("Qy"), |
| 53 | 67 | .{ |
| 54 | 68 | .name = "S", |
| 55 | 69 | .syntax = .flag, |
| 56 | .zig_equivalent = .driver_punt, | |
| 70 | .zig_equivalent = .pp_or_asm, | |
| 57 | 71 | .pd1 = true, |
| 58 | 72 | .pd2 = false, |
| 59 | 73 | .psl = false, |
| ... | ... | @@ -154,7 +168,7 @@ sepd1("Zlinker-input"), |
| 154 | 168 | .{ |
| 155 | 169 | .name = "E", |
| 156 | 170 | .syntax = .flag, |
| 157 | .zig_equivalent = .preprocess, | |
| 171 | .zig_equivalent = .pp_or_asm, | |
| 158 | 172 | .pd1 = true, |
| 159 | 173 | .pd2 = false, |
| 160 | 174 | .psl = true, |
| ... | ... | @@ -490,7 +504,7 @@ sepd1("Zlinker-input"), |
| 490 | 504 | .{ |
| 491 | 505 | .name = "MD", |
| 492 | 506 | .syntax = .flag, |
| 493 | .zig_equivalent = .other, | |
| 507 | .zig_equivalent = .dep_file, | |
| 494 | 508 | .pd1 = true, |
| 495 | 509 | .pd2 = false, |
| 496 | 510 | .psl = true, |
| ... | ... | @@ -1442,7 +1456,7 @@ sepd1("Zlinker-input"), |
| 1442 | 1456 | .{ |
| 1443 | 1457 | .name = "assemble", |
| 1444 | 1458 | .syntax = .flag, |
| 1445 | .zig_equivalent = .driver_punt, | |
| 1459 | .zig_equivalent = .pp_or_asm, | |
| 1446 | 1460 | .pd1 = false, |
| 1447 | 1461 | .pd2 = true, |
| 1448 | 1462 | .psl = false, |
| ... | ... | @@ -1658,7 +1672,7 @@ sepd1("Zlinker-input"), |
| 1658 | 1672 | .{ |
| 1659 | 1673 | .name = "library-directory", |
| 1660 | 1674 | .syntax = .separate, |
| 1661 | .zig_equivalent = .other, | |
| 1675 | .zig_equivalent = .lib_dir, | |
| 1662 | 1676 | .pd1 = false, |
| 1663 | 1677 | .pd2 = true, |
| 1664 | 1678 | .psl = false, |
| ... | ... | @@ -1770,7 +1784,7 @@ sepd1("Zlinker-input"), |
| 1770 | 1784 | .{ |
| 1771 | 1785 | .name = "preprocess", |
| 1772 | 1786 | .syntax = .flag, |
| 1773 | .zig_equivalent = .preprocess, | |
| 1787 | .zig_equivalent = .pp_or_asm, | |
| 1774 | 1788 | .pd1 = false, |
| 1775 | 1789 | .pd2 = true, |
| 1776 | 1790 | .psl = false, |
| ... | ... | @@ -2554,14 +2568,7 @@ flagpd1("femulated-tls"), |
| 2554 | 2568 | flagpd1("fencode-extended-block-signature"), |
| 2555 | 2569 | sepd1("ferror-limit"), |
| 2556 | 2570 | flagpd1("fescaping-block-tail-calls"), |
| 2557 | .{ | |
| 2558 | .name = "fexceptions", | |
| 2559 | .syntax = .flag, | |
| 2560 | .zig_equivalent = .exceptions, | |
| 2561 | .pd1 = true, | |
| 2562 | .pd2 = false, | |
| 2563 | .psl = false, | |
| 2564 | }, | |
| 2571 | flagpd1("fexceptions"), | |
| 2565 | 2572 | flagpd1("fexperimental-isel"), |
| 2566 | 2573 | flagpd1("fexperimental-new-constant-interpreter"), |
| 2567 | 2574 | flagpd1("fexperimental-new-pass-manager"), |
| ... | ... | @@ -2765,14 +2772,7 @@ flagpd1("fno-elide-type"), |
| 2765 | 2772 | flagpd1("fno-eliminate-unused-debug-symbols"), |
| 2766 | 2773 | flagpd1("fno-emulated-tls"), |
| 2767 | 2774 | flagpd1("fno-escaping-block-tail-calls"), |
| 2768 | .{ | |
| 2769 | .name = "fno-exceptions", | |
| 2770 | .syntax = .flag, | |
| 2771 | .zig_equivalent = .no_exceptions, | |
| 2772 | .pd1 = true, | |
| 2773 | .pd2 = false, | |
| 2774 | .psl = false, | |
| 2775 | }, | |
| 2775 | flagpd1("fno-exceptions"), | |
| 2776 | 2776 | flagpd1("fno-experimental-isel"), |
| 2777 | 2777 | flagpd1("fno-experimental-new-pass-manager"), |
| 2778 | 2778 | flagpd1("fno-fast-math"), |
| ... | ... | @@ -2861,14 +2861,7 @@ flagpd1("fno-rewrite-includes"), |
| 2861 | 2861 | flagpd1("fno-ropi"), |
| 2862 | 2862 | flagpd1("fno-rounding-math"), |
| 2863 | 2863 | flagpd1("fno-rtlib-add-rpath"), |
| 2864 | .{ | |
| 2865 | .name = "fno-rtti", | |
| 2866 | .syntax = .flag, | |
| 2867 | .zig_equivalent = .no_rtti, | |
| 2868 | .pd1 = true, | |
| 2869 | .pd2 = false, | |
| 2870 | .psl = false, | |
| 2871 | }, | |
| 2864 | flagpd1("fno-rtti"), | |
| 2872 | 2865 | flagpd1("fno-rtti-data"), |
| 2873 | 2866 | flagpd1("fno-rwpi"), |
| 2874 | 2867 | flagpd1("fno-sanitize-address-poison-custom-array-cookie"), |
| ... | ... | @@ -2996,7 +2989,14 @@ sepd1("fprofile-remapping-file"), |
| 2996 | 2989 | flagpd1("fprofile-sample-accurate"), |
| 2997 | 2990 | flagpd1("fprofile-sample-use"), |
| 2998 | 2991 | flagpd1("fprofile-use"), |
| 2999 | sepd1("framework"), | |
| 2992 | .{ | |
| 2993 | .name = "framework", | |
| 2994 | .syntax = .separate, | |
| 2995 | .zig_equivalent = .framework, | |
| 2996 | .pd1 = true, | |
| 2997 | .pd2 = false, | |
| 2998 | .psl = false, | |
| 2999 | }, | |
| 3000 | 3000 | flagpd1("freciprocal-math"), |
| 3001 | 3001 | flagpd1("frecord-command-line"), |
| 3002 | 3002 | flagpd1("ffree-form"), |
| ... | ... | @@ -3016,14 +3016,7 @@ flagpd1("fno-frontend-optimize"), |
| 3016 | 3016 | flagpd1("fropi"), |
| 3017 | 3017 | flagpd1("frounding-math"), |
| 3018 | 3018 | flagpd1("frtlib-add-rpath"), |
| 3019 | .{ | |
| 3020 | .name = "frtti", | |
| 3021 | .syntax = .flag, | |
| 3022 | .zig_equivalent = .rtti, | |
| 3023 | .pd1 = true, | |
| 3024 | .pd2 = false, | |
| 3025 | .psl = false, | |
| 3026 | }, | |
| 3019 | flagpd1("frtti"), | |
| 3027 | 3020 | flagpd1("frwpi"), |
| 3028 | 3021 | flagpd1("fsanitize-address-globals-dead-stripping"), |
| 3029 | 3022 | flagpd1("fsanitize-address-poison-custom-array-cookie"), |
| ... | ... | @@ -4562,7 +4555,7 @@ joinpd1("target-sdk-version="), |
| 4562 | 4555 | .{ |
| 4563 | 4556 | .name = "library-directory=", |
| 4564 | 4557 | .syntax = .joined, |
| 4565 | .zig_equivalent = .other, | |
| 4558 | .zig_equivalent = .lib_dir, | |
| 4566 | 4559 | .pd1 = false, |
| 4567 | 4560 | .pd2 = true, |
| 4568 | 4561 | .psl = false, |
| ... | ... | @@ -5282,8 +5275,22 @@ joinpd1("fixit="), |
| 5282 | 5275 | joinpd1("gstabs"), |
| 5283 | 5276 | joinpd1("gxcoff"), |
| 5284 | 5277 | jspd1("iquote"), |
| 5285 | joinpd1("march="), | |
| 5286 | joinpd1("mtune="), | |
| 5278 | .{ | |
| 5279 | .name = "march=", | |
| 5280 | .syntax = .joined, | |
| 5281 | .zig_equivalent = .mcpu, | |
| 5282 | .pd1 = true, | |
| 5283 | .pd2 = false, | |
| 5284 | .psl = false, | |
| 5285 | }, | |
| 5286 | .{ | |
| 5287 | .name = "mtune=", | |
| 5288 | .syntax = .joined, | |
| 5289 | .zig_equivalent = .mcpu, | |
| 5290 | .pd1 = true, | |
| 5291 | .pd2 = false, | |
| 5292 | .psl = false, | |
| 5293 | }, | |
| 5287 | 5294 | .{ |
| 5288 | 5295 | .name = "rtlib=", |
| 5289 | 5296 | .syntax = .joined, |
| ... | ... | @@ -5348,7 +5355,14 @@ joinpd1("gcoff"), |
| 5348 | 5355 | joinpd1("mabi="), |
| 5349 | 5356 | joinpd1("mabs="), |
| 5350 | 5357 | joinpd1("masm="), |
| 5351 | joinpd1("mcpu="), | |
| 5358 | .{ | |
| 5359 | .name = "mcpu=", | |
| 5360 | .syntax = .joined, | |
| 5361 | .zig_equivalent = .mcpu, | |
| 5362 | .pd1 = true, | |
| 5363 | .pd2 = false, | |
| 5364 | .psl = false, | |
| 5365 | }, | |
| 5352 | 5366 | joinpd1("mfpu="), |
| 5353 | 5367 | joinpd1("mhvx="), |
| 5354 | 5368 | joinpd1("mmcu="), |
| ... | ... | @@ -5441,7 +5455,14 @@ joinpd1("mtp="), |
| 5441 | 5455 | joinpd1("gz="), |
| 5442 | 5456 | joinpd1("A-"), |
| 5443 | 5457 | joinpd1("G="), |
| 5444 | jspd1("MF"), | |
| 5458 | .{ | |
| 5459 | .name = "MF", | |
| 5460 | .syntax = .joined_or_separate, | |
| 5461 | .zig_equivalent = .dep_file, | |
| 5462 | .pd1 = true, | |
| 5463 | .pd2 = false, | |
| 5464 | .psl = false, | |
| 5465 | }, | |
| 5445 | 5466 | jspd1("MJ"), |
| 5446 | 5467 | jspd1("MQ"), |
| 5447 | 5468 | jspd1("MT"), |
| ... | ... | @@ -5656,11 +5677,25 @@ jspd1("MT"), |
| 5656 | 5677 | jspd1("A"), |
| 5657 | 5678 | jspd1("B"), |
| 5658 | 5679 | jspd1("D"), |
| 5659 | jspd1("F"), | |
| 5680 | .{ | |
| 5681 | .name = "F", | |
| 5682 | .syntax = .joined_or_separate, | |
| 5683 | .zig_equivalent = .framework_dir, | |
| 5684 | .pd1 = true, | |
| 5685 | .pd2 = false, | |
| 5686 | .psl = false, | |
| 5687 | }, | |
| 5660 | 5688 | jspd1("G"), |
| 5661 | 5689 | jspd1("I"), |
| 5662 | 5690 | jspd1("J"), |
| 5663 | jspd1("L"), | |
| 5691 | .{ | |
| 5692 | .name = "L", | |
| 5693 | .syntax = .joined_or_separate, | |
| 5694 | .zig_equivalent = .lib_dir, | |
| 5695 | .pd1 = true, | |
| 5696 | .pd2 = false, | |
| 5697 | .psl = false, | |
| 5698 | }, | |
| 5664 | 5699 | .{ |
| 5665 | 5700 | .name = "O", |
| 5666 | 5701 | .syntax = .joined, |
| ... | ... | @@ -5694,7 +5729,7 @@ joinpd1("Z"), |
| 5694 | 5729 | .{ |
| 5695 | 5730 | .name = "F", |
| 5696 | 5731 | .syntax = .joined_or_separate, |
| 5697 | .zig_equivalent = .other, | |
| 5732 | .zig_equivalent = .framework_dir, | |
| 5698 | 5733 | .pd1 = true, |
| 5699 | 5734 | .pd2 = false, |
| 5700 | 5735 | .psl = true, |
src-self-hosted/codegen.zig+14-14| ... | ... | @@ -25,10 +25,10 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code) |
| 25 | 25 | |
| 26 | 26 | const context = llvm_handle.node.data; |
| 27 | 27 | |
| 28 | const module = llvm.ModuleCreateWithNameInContext(comp.name.toSliceConst(), context) orelse return error.OutOfMemory; | |
| 28 | const module = llvm.ModuleCreateWithNameInContext(comp.name.span(), context) orelse return error.OutOfMemory; | |
| 29 | 29 | defer llvm.DisposeModule(module); |
| 30 | 30 | |
| 31 | llvm.SetTarget(module, comp.llvm_triple.toSliceConst()); | |
| 31 | llvm.SetTarget(module, comp.llvm_triple.span()); | |
| 32 | 32 | llvm.SetDataLayout(module, comp.target_layout_str); |
| 33 | 33 | |
| 34 | 34 | if (comp.target.getObjectFormat() == .coff) { |
| ... | ... | @@ -45,7 +45,7 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code) |
| 45 | 45 | |
| 46 | 46 | // Don't use ZIG_VERSION_STRING here. LLVM misparses it when it includes |
| 47 | 47 | // the git revision. |
| 48 | const producer = try std.Buffer.allocPrint(&code.arena.allocator, "zig {}.{}.{}", .{ | |
| 48 | const producer = try std.fmt.allocPrintZ(&code.arena.allocator, "zig {}.{}.{}", .{ | |
| 49 | 49 | @as(u32, c.ZIG_VERSION_MAJOR), |
| 50 | 50 | @as(u32, c.ZIG_VERSION_MINOR), |
| 51 | 51 | @as(u32, c.ZIG_VERSION_PATCH), |
| ... | ... | @@ -54,15 +54,15 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code) |
| 54 | 54 | const runtime_version = 0; |
| 55 | 55 | const compile_unit_file = llvm.CreateFile( |
| 56 | 56 | dibuilder, |
| 57 | comp.name.toSliceConst(), | |
| 58 | comp.root_package.root_src_dir.toSliceConst(), | |
| 57 | comp.name.span(), | |
| 58 | comp.root_package.root_src_dir.span(), | |
| 59 | 59 | ) orelse return error.OutOfMemory; |
| 60 | 60 | const is_optimized = comp.build_mode != .Debug; |
| 61 | 61 | const compile_unit = llvm.CreateCompileUnit( |
| 62 | 62 | dibuilder, |
| 63 | 63 | DW.LANG_C99, |
| 64 | 64 | compile_unit_file, |
| 65 | producer.toSliceConst(), | |
| 65 | producer, | |
| 66 | 66 | is_optimized, |
| 67 | 67 | flags, |
| 68 | 68 | runtime_version, |
| ... | ... | @@ -109,14 +109,14 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code) |
| 109 | 109 | if (llvm.TargetMachineEmitToFile( |
| 110 | 110 | comp.target_machine, |
| 111 | 111 | module, |
| 112 | output_path.toSliceConst(), | |
| 112 | output_path.span(), | |
| 113 | 113 | llvm.EmitBinary, |
| 114 | 114 | &err_msg, |
| 115 | 115 | is_debug, |
| 116 | 116 | is_small, |
| 117 | 117 | )) { |
| 118 | 118 | if (std.debug.runtime_safety) { |
| 119 | std.debug.panic("unable to write object file {}: {s}\n", .{ output_path.toSliceConst(), err_msg }); | |
| 119 | std.debug.panic("unable to write object file {}: {s}\n", .{ output_path.span(), err_msg }); | |
| 120 | 120 | } |
| 121 | 121 | return error.WritingObjectFileFailed; |
| 122 | 122 | } |
| ... | ... | @@ -127,7 +127,7 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code) |
| 127 | 127 | llvm.DumpModule(ofile.module); |
| 128 | 128 | } |
| 129 | 129 | if (comp.verbose_link) { |
| 130 | std.debug.warn("created {}\n", .{output_path.toSliceConst()}); | |
| 130 | std.debug.warn("created {}\n", .{output_path.span()}); | |
| 131 | 131 | } |
| 132 | 132 | } |
| 133 | 133 | |
| ... | ... | @@ -150,7 +150,7 @@ pub fn renderToLlvmModule(ofile: *ObjectFile, fn_val: *Value.Fn, code: *ir.Code) |
| 150 | 150 | const llvm_fn_type = try fn_val.base.typ.getLlvmType(ofile.arena, ofile.context); |
| 151 | 151 | const llvm_fn = llvm.AddFunction( |
| 152 | 152 | ofile.module, |
| 153 | fn_val.symbol_name.toSliceConst(), | |
| 153 | fn_val.symbol_name.span(), | |
| 154 | 154 | llvm_fn_type, |
| 155 | 155 | ) orelse return error.OutOfMemory; |
| 156 | 156 | |
| ... | ... | @@ -211,7 +211,7 @@ pub fn renderToLlvmModule(ofile: *ObjectFile, fn_val: *Value.Fn, code: *ir.Code) |
| 211 | 211 | const cur_ret_ptr = if (fn_type_normal.return_type.handleIsPtr()) llvm.GetParam(llvm_fn, 0) else null; |
| 212 | 212 | |
| 213 | 213 | // build all basic blocks |
| 214 | for (code.basic_block_list.toSlice()) |bb| { | |
| 214 | for (code.basic_block_list.span()) |bb| { | |
| 215 | 215 | bb.llvm_block = llvm.AppendBasicBlockInContext( |
| 216 | 216 | ofile.context, |
| 217 | 217 | llvm_fn, |
| ... | ... | @@ -226,7 +226,7 @@ pub fn renderToLlvmModule(ofile: *ObjectFile, fn_val: *Value.Fn, code: *ir.Code) |
| 226 | 226 | // TODO set up error return tracing |
| 227 | 227 | // TODO allocate temporary stack values |
| 228 | 228 | |
| 229 | const var_list = fn_type.non_key.Normal.variable_list.toSliceConst(); | |
| 229 | const var_list = fn_type.non_key.Normal.variable_list.span(); | |
| 230 | 230 | // create debug variable declarations for variables and allocate all local variables |
| 231 | 231 | for (var_list) |var_scope, i| { |
| 232 | 232 | const var_type = switch (var_scope.data) { |
| ... | ... | @@ -306,9 +306,9 @@ pub fn renderToLlvmModule(ofile: *ObjectFile, fn_val: *Value.Fn, code: *ir.Code) |
| 306 | 306 | //} |
| 307 | 307 | } |
| 308 | 308 | |
| 309 | for (code.basic_block_list.toSlice()) |current_block| { | |
| 309 | for (code.basic_block_list.span()) |current_block| { | |
| 310 | 310 | llvm.PositionBuilderAtEnd(ofile.builder, current_block.llvm_block); |
| 311 | for (current_block.instruction_list.toSlice()) |instruction| { | |
| 311 | for (current_block.instruction_list.span()) |instruction| { | |
| 312 | 312 | if (instruction.ref_count == 0 and !instruction.hasSideEffects()) continue; |
| 313 | 313 | |
| 314 | 314 | instruction.llvm_value = try instruction.render(ofile, fn_val); |
src-self-hosted/compilation.zig+11-11| ... | ... | @@ -2,7 +2,7 @@ const std = @import("std"); |
| 2 | 2 | const io = std.io; |
| 3 | 3 | const mem = std.mem; |
| 4 | 4 | const Allocator = mem.Allocator; |
| 5 | const Buffer = std.Buffer; | |
| 5 | const ArrayListSentineled = std.ArrayListSentineled; | |
| 6 | 6 | const llvm = @import("llvm.zig"); |
| 7 | 7 | const c = @import("c.zig"); |
| 8 | 8 | const builtin = std.builtin; |
| ... | ... | @@ -123,8 +123,8 @@ pub const LlvmHandle = struct { |
| 123 | 123 | |
| 124 | 124 | pub const Compilation = struct { |
| 125 | 125 | zig_compiler: *ZigCompiler, |
| 126 | name: Buffer, | |
| 127 | llvm_triple: Buffer, | |
| 126 | name: ArrayListSentineled(u8, 0), | |
| 127 | llvm_triple: ArrayListSentineled(u8, 0), | |
| 128 | 128 | root_src_path: ?[]const u8, |
| 129 | 129 | target: std.Target, |
| 130 | 130 | llvm_target: *llvm.Target, |
| ... | ... | @@ -444,7 +444,7 @@ pub const Compilation = struct { |
| 444 | 444 | comp.arena_allocator.deinit(); |
| 445 | 445 | } |
| 446 | 446 | |
| 447 | comp.name = try Buffer.init(comp.arena(), name); | |
| 447 | comp.name = try ArrayListSentineled(u8, 0).init(comp.arena(), name); | |
| 448 | 448 | comp.llvm_triple = try util.getLLVMTriple(comp.arena(), target); |
| 449 | 449 | comp.llvm_target = try util.llvmTargetFromTriple(comp.llvm_triple); |
| 450 | 450 | comp.zig_std_dir = try fs.path.join(comp.arena(), &[_][]const u8{ zig_lib_dir, "std" }); |
| ... | ... | @@ -465,7 +465,7 @@ pub const Compilation = struct { |
| 465 | 465 | |
| 466 | 466 | comp.target_machine = llvm.CreateTargetMachine( |
| 467 | 467 | comp.llvm_target, |
| 468 | comp.llvm_triple.toSliceConst(), | |
| 468 | comp.llvm_triple.span(), | |
| 469 | 469 | target_specific_cpu_args orelse "", |
| 470 | 470 | target_specific_cpu_features orelse "", |
| 471 | 471 | opt_level, |
| ... | ... | @@ -1106,7 +1106,7 @@ pub const Compilation = struct { |
| 1106 | 1106 | } |
| 1107 | 1107 | } |
| 1108 | 1108 | |
| 1109 | for (self.link_libs_list.toSliceConst()) |existing_lib| { | |
| 1109 | for (self.link_libs_list.span()) |existing_lib| { | |
| 1110 | 1110 | if (mem.eql(u8, name, existing_lib.name)) { |
| 1111 | 1111 | return existing_lib; |
| 1112 | 1112 | } |
| ... | ... | @@ -1151,7 +1151,7 @@ pub const Compilation = struct { |
| 1151 | 1151 | |
| 1152 | 1152 | /// If the temporary directory for this compilation has not been created, it creates it. |
| 1153 | 1153 | /// Then it creates a random file name in that dir and returns it. |
| 1154 | pub fn createRandomOutputPath(self: *Compilation, suffix: []const u8) !Buffer { | |
| 1154 | pub fn createRandomOutputPath(self: *Compilation, suffix: []const u8) !ArrayListSentineled(u8, 0) { | |
| 1155 | 1155 | const tmp_dir = try self.getTmpDir(); |
| 1156 | 1156 | const file_prefix = self.getRandomFileName(); |
| 1157 | 1157 | |
| ... | ... | @@ -1161,7 +1161,7 @@ pub const Compilation = struct { |
| 1161 | 1161 | const full_path = try fs.path.join(self.gpa(), &[_][]const u8{ tmp_dir, file_name[0..] }); |
| 1162 | 1162 | errdefer self.gpa().free(full_path); |
| 1163 | 1163 | |
| 1164 | return Buffer.fromOwnedSlice(self.gpa(), full_path); | |
| 1164 | return ArrayListSentineled(u8, 0).fromOwnedSlice(self.gpa(), full_path); | |
| 1165 | 1165 | } |
| 1166 | 1166 | |
| 1167 | 1167 | /// If the temporary directory for this Compilation has not been created, creates it. |
| ... | ... | @@ -1279,7 +1279,7 @@ fn generateDeclFn(comp: *Compilation, fn_decl: *Decl.Fn) !void { |
| 1279 | 1279 | const fn_type = try analyzeFnType(comp, tree_scope, fn_decl.base.parent_scope, fn_decl.fn_proto); |
| 1280 | 1280 | defer fn_type.base.base.deref(comp); |
| 1281 | 1281 | |
| 1282 | var symbol_name = try std.Buffer.init(comp.gpa(), fn_decl.base.name); | |
| 1282 | var symbol_name = try std.ArrayListSentineled(u8, 0).init(comp.gpa(), fn_decl.base.name); | |
| 1283 | 1283 | var symbol_name_consumed = false; |
| 1284 | 1284 | errdefer if (!symbol_name_consumed) symbol_name.deinit(); |
| 1285 | 1285 | |
| ... | ... | @@ -1371,7 +1371,7 @@ fn analyzeFnType( |
| 1371 | 1371 | var params = ArrayList(Type.Fn.Param).init(comp.gpa()); |
| 1372 | 1372 | var params_consumed = false; |
| 1373 | 1373 | defer if (!params_consumed) { |
| 1374 | for (params.toSliceConst()) |param| { | |
| 1374 | for (params.span()) |param| { | |
| 1375 | 1375 | param.typ.base.deref(comp); |
| 1376 | 1376 | } |
| 1377 | 1377 | params.deinit(); |
| ... | ... | @@ -1426,7 +1426,7 @@ fn generateDeclFnProto(comp: *Compilation, fn_decl: *Decl.Fn) !void { |
| 1426 | 1426 | ); |
| 1427 | 1427 | defer fn_type.base.base.deref(comp); |
| 1428 | 1428 | |
| 1429 | var symbol_name = try std.Buffer.init(comp.gpa(), fn_decl.base.name); | |
| 1429 | var symbol_name = try std.ArrayListSentineled(u8, 0).init(comp.gpa(), fn_decl.base.name); | |
| 1430 | 1430 | var symbol_name_consumed = false; |
| 1431 | 1431 | defer if (!symbol_name_consumed) symbol_name.deinit(); |
| 1432 | 1432 |
src-self-hosted/dep_tokenizer.zig+59-59| ... | ... | @@ -33,7 +33,7 @@ pub const Tokenizer = struct { |
| 33 | 33 | break; // advance |
| 34 | 34 | }, |
| 35 | 35 | else => { |
| 36 | self.state = State{ .target = try std.Buffer.initSize(&self.arena.allocator, 0) }; | |
| 36 | self.state = State{ .target = try std.ArrayListSentineled(u8, 0).initSize(&self.arena.allocator, 0) }; | |
| 37 | 37 | }, |
| 38 | 38 | }, |
| 39 | 39 | .target => |*target| switch (char) { |
| ... | ... | @@ -53,7 +53,7 @@ pub const Tokenizer = struct { |
| 53 | 53 | break; // advance |
| 54 | 54 | }, |
| 55 | 55 | else => { |
| 56 | try target.appendByte(char); | |
| 56 | try target.append(char); | |
| 57 | 57 | break; // advance |
| 58 | 58 | }, |
| 59 | 59 | }, |
| ... | ... | @@ -62,24 +62,24 @@ pub const Tokenizer = struct { |
| 62 | 62 | return self.errorIllegalChar(self.index, char, "bad target escape", .{}); |
| 63 | 63 | }, |
| 64 | 64 | ' ', '#', '\\' => { |
| 65 | try target.appendByte(char); | |
| 65 | try target.append(char); | |
| 66 | 66 | self.state = State{ .target = target.* }; |
| 67 | 67 | break; // advance |
| 68 | 68 | }, |
| 69 | 69 | '$' => { |
| 70 | try target.append(self.bytes[self.index - 1 .. self.index]); | |
| 70 | try target.appendSlice(self.bytes[self.index - 1 .. self.index]); | |
| 71 | 71 | self.state = State{ .target_dollar_sign = target.* }; |
| 72 | 72 | break; // advance |
| 73 | 73 | }, |
| 74 | 74 | else => { |
| 75 | try target.append(self.bytes[self.index - 1 .. self.index + 1]); | |
| 75 | try target.appendSlice(self.bytes[self.index - 1 .. self.index + 1]); | |
| 76 | 76 | self.state = State{ .target = target.* }; |
| 77 | 77 | break; // advance |
| 78 | 78 | }, |
| 79 | 79 | }, |
| 80 | 80 | .target_dollar_sign => |*target| switch (char) { |
| 81 | 81 | '$' => { |
| 82 | try target.appendByte(char); | |
| 82 | try target.append(char); | |
| 83 | 83 | self.state = State{ .target = target.* }; |
| 84 | 84 | break; // advance |
| 85 | 85 | }, |
| ... | ... | @@ -89,7 +89,7 @@ pub const Tokenizer = struct { |
| 89 | 89 | }, |
| 90 | 90 | .target_colon => |*target| switch (char) { |
| 91 | 91 | '\n', '\r' => { |
| 92 | const bytes = target.toSlice(); | |
| 92 | const bytes = target.span(); | |
| 93 | 93 | if (bytes.len != 0) { |
| 94 | 94 | self.state = State{ .lhs = {} }; |
| 95 | 95 | return Token{ .id = .target, .bytes = bytes }; |
| ... | ... | @@ -103,7 +103,7 @@ pub const Tokenizer = struct { |
| 103 | 103 | break; // advance |
| 104 | 104 | }, |
| 105 | 105 | else => { |
| 106 | const bytes = target.toSlice(); | |
| 106 | const bytes = target.span(); | |
| 107 | 107 | if (bytes.len != 0) { |
| 108 | 108 | self.state = State{ .rhs = {} }; |
| 109 | 109 | return Token{ .id = .target, .bytes = bytes }; |
| ... | ... | @@ -115,7 +115,7 @@ pub const Tokenizer = struct { |
| 115 | 115 | }, |
| 116 | 116 | .target_colon_reverse_solidus => |*target| switch (char) { |
| 117 | 117 | '\n', '\r' => { |
| 118 | const bytes = target.toSlice(); | |
| 118 | const bytes = target.span(); | |
| 119 | 119 | if (bytes.len != 0) { |
| 120 | 120 | self.state = State{ .lhs = {} }; |
| 121 | 121 | return Token{ .id = .target, .bytes = bytes }; |
| ... | ... | @@ -125,7 +125,7 @@ pub const Tokenizer = struct { |
| 125 | 125 | continue; |
| 126 | 126 | }, |
| 127 | 127 | else => { |
| 128 | try target.append(self.bytes[self.index - 2 .. self.index + 1]); | |
| 128 | try target.appendSlice(self.bytes[self.index - 2 .. self.index + 1]); | |
| 129 | 129 | self.state = State{ .target = target.* }; |
| 130 | 130 | break; |
| 131 | 131 | }, |
| ... | ... | @@ -144,11 +144,11 @@ pub const Tokenizer = struct { |
| 144 | 144 | break; // advance |
| 145 | 145 | }, |
| 146 | 146 | '"' => { |
| 147 | self.state = State{ .prereq_quote = try std.Buffer.initSize(&self.arena.allocator, 0) }; | |
| 147 | self.state = State{ .prereq_quote = try std.ArrayListSentineled(u8, 0).initSize(&self.arena.allocator, 0) }; | |
| 148 | 148 | break; // advance |
| 149 | 149 | }, |
| 150 | 150 | else => { |
| 151 | self.state = State{ .prereq = try std.Buffer.initSize(&self.arena.allocator, 0) }; | |
| 151 | self.state = State{ .prereq = try std.ArrayListSentineled(u8, 0).initSize(&self.arena.allocator, 0) }; | |
| 152 | 152 | }, |
| 153 | 153 | }, |
| 154 | 154 | .rhs_continuation => switch (char) { |
| ... | ... | @@ -175,24 +175,24 @@ pub const Tokenizer = struct { |
| 175 | 175 | }, |
| 176 | 176 | .prereq_quote => |*prereq| switch (char) { |
| 177 | 177 | '"' => { |
| 178 | const bytes = prereq.toSlice(); | |
| 178 | const bytes = prereq.span(); | |
| 179 | 179 | self.index += 1; |
| 180 | 180 | self.state = State{ .rhs = {} }; |
| 181 | 181 | return Token{ .id = .prereq, .bytes = bytes }; |
| 182 | 182 | }, |
| 183 | 183 | else => { |
| 184 | try prereq.appendByte(char); | |
| 184 | try prereq.append(char); | |
| 185 | 185 | break; // advance |
| 186 | 186 | }, |
| 187 | 187 | }, |
| 188 | 188 | .prereq => |*prereq| switch (char) { |
| 189 | 189 | '\t', ' ' => { |
| 190 | const bytes = prereq.toSlice(); | |
| 190 | const bytes = prereq.span(); | |
| 191 | 191 | self.state = State{ .rhs = {} }; |
| 192 | 192 | return Token{ .id = .prereq, .bytes = bytes }; |
| 193 | 193 | }, |
| 194 | 194 | '\n', '\r' => { |
| 195 | const bytes = prereq.toSlice(); | |
| 195 | const bytes = prereq.span(); | |
| 196 | 196 | self.state = State{ .lhs = {} }; |
| 197 | 197 | return Token{ .id = .prereq, .bytes = bytes }; |
| 198 | 198 | }, |
| ... | ... | @@ -201,13 +201,13 @@ pub const Tokenizer = struct { |
| 201 | 201 | break; // advance |
| 202 | 202 | }, |
| 203 | 203 | else => { |
| 204 | try prereq.appendByte(char); | |
| 204 | try prereq.append(char); | |
| 205 | 205 | break; // advance |
| 206 | 206 | }, |
| 207 | 207 | }, |
| 208 | 208 | .prereq_continuation => |*prereq| switch (char) { |
| 209 | 209 | '\n' => { |
| 210 | const bytes = prereq.toSlice(); | |
| 210 | const bytes = prereq.span(); | |
| 211 | 211 | self.index += 1; |
| 212 | 212 | self.state = State{ .rhs = {} }; |
| 213 | 213 | return Token{ .id = .prereq, .bytes = bytes }; |
| ... | ... | @@ -218,14 +218,14 @@ pub const Tokenizer = struct { |
| 218 | 218 | }, |
| 219 | 219 | else => { |
| 220 | 220 | // not continuation |
| 221 | try prereq.append(self.bytes[self.index - 1 .. self.index + 1]); | |
| 221 | try prereq.appendSlice(self.bytes[self.index - 1 .. self.index + 1]); | |
| 222 | 222 | self.state = State{ .prereq = prereq.* }; |
| 223 | 223 | break; // advance |
| 224 | 224 | }, |
| 225 | 225 | }, |
| 226 | 226 | .prereq_continuation_linefeed => |prereq| switch (char) { |
| 227 | 227 | '\n' => { |
| 228 | const bytes = prereq.toSlice(); | |
| 228 | const bytes = prereq.span(); | |
| 229 | 229 | self.index += 1; |
| 230 | 230 | self.state = State{ .rhs = {} }; |
| 231 | 231 | return Token{ .id = .prereq, .bytes = bytes }; |
| ... | ... | @@ -249,7 +249,7 @@ pub const Tokenizer = struct { |
| 249 | 249 | .rhs_continuation_linefeed, |
| 250 | 250 | => {}, |
| 251 | 251 | .target => |target| { |
| 252 | return self.errorPosition(idx, target.toSlice(), "incomplete target", .{}); | |
| 252 | return self.errorPosition(idx, target.span(), "incomplete target", .{}); | |
| 253 | 253 | }, |
| 254 | 254 | .target_reverse_solidus, |
| 255 | 255 | .target_dollar_sign, |
| ... | ... | @@ -258,7 +258,7 @@ pub const Tokenizer = struct { |
| 258 | 258 | return self.errorIllegalChar(idx, self.bytes[idx], "incomplete escape", .{}); |
| 259 | 259 | }, |
| 260 | 260 | .target_colon => |target| { |
| 261 | const bytes = target.toSlice(); | |
| 261 | const bytes = target.span(); | |
| 262 | 262 | if (bytes.len != 0) { |
| 263 | 263 | self.index += 1; |
| 264 | 264 | self.state = State{ .rhs = {} }; |
| ... | ... | @@ -268,7 +268,7 @@ pub const Tokenizer = struct { |
| 268 | 268 | self.state = State{ .lhs = {} }; |
| 269 | 269 | }, |
| 270 | 270 | .target_colon_reverse_solidus => |target| { |
| 271 | const bytes = target.toSlice(); | |
| 271 | const bytes = target.span(); | |
| 272 | 272 | if (bytes.len != 0) { |
| 273 | 273 | self.index += 1; |
| 274 | 274 | self.state = State{ .rhs = {} }; |
| ... | ... | @@ -278,20 +278,20 @@ pub const Tokenizer = struct { |
| 278 | 278 | self.state = State{ .lhs = {} }; |
| 279 | 279 | }, |
| 280 | 280 | .prereq_quote => |prereq| { |
| 281 | return self.errorPosition(idx, prereq.toSlice(), "incomplete quoted prerequisite", .{}); | |
| 281 | return self.errorPosition(idx, prereq.span(), "incomplete quoted prerequisite", .{}); | |
| 282 | 282 | }, |
| 283 | 283 | .prereq => |prereq| { |
| 284 | const bytes = prereq.toSlice(); | |
| 284 | const bytes = prereq.span(); | |
| 285 | 285 | self.state = State{ .lhs = {} }; |
| 286 | 286 | return Token{ .id = .prereq, .bytes = bytes }; |
| 287 | 287 | }, |
| 288 | 288 | .prereq_continuation => |prereq| { |
| 289 | const bytes = prereq.toSlice(); | |
| 289 | const bytes = prereq.span(); | |
| 290 | 290 | self.state = State{ .lhs = {} }; |
| 291 | 291 | return Token{ .id = .prereq, .bytes = bytes }; |
| 292 | 292 | }, |
| 293 | 293 | .prereq_continuation_linefeed => |prereq| { |
| 294 | const bytes = prereq.toSlice(); | |
| 294 | const bytes = prereq.span(); | |
| 295 | 295 | self.state = State{ .lhs = {} }; |
| 296 | 296 | return Token{ .id = .prereq, .bytes = bytes }; |
| 297 | 297 | }, |
| ... | ... | @@ -300,29 +300,29 @@ pub const Tokenizer = struct { |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | fn errorf(self: *Tokenizer, comptime fmt: []const u8, args: var) Error { |
| 303 | self.error_text = (try std.Buffer.allocPrint(&self.arena.allocator, fmt, args)).toSlice(); | |
| 303 | self.error_text = try std.fmt.allocPrintZ(&self.arena.allocator, fmt, args); | |
| 304 | 304 | return Error.InvalidInput; |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | fn errorPosition(self: *Tokenizer, position: usize, bytes: []const u8, comptime fmt: []const u8, args: var) Error { |
| 308 | var buffer = try std.Buffer.initSize(&self.arena.allocator, 0); | |
| 308 | var buffer = try std.ArrayListSentineled(u8, 0).initSize(&self.arena.allocator, 0); | |
| 309 | 309 | try buffer.outStream().print(fmt, args); |
| 310 | try buffer.append(" '"); | |
| 311 | var out = makeOutput(std.Buffer.append, &buffer); | |
| 310 | try buffer.appendSlice(" '"); | |
| 311 | var out = makeOutput(std.ArrayListSentineled(u8, 0).appendSlice, &buffer); | |
| 312 | 312 | try printCharValues(&out, bytes); |
| 313 | try buffer.append("'"); | |
| 313 | try buffer.appendSlice("'"); | |
| 314 | 314 | try buffer.outStream().print(" at position {}", .{position - (bytes.len - 1)}); |
| 315 | self.error_text = buffer.toSlice(); | |
| 315 | self.error_text = buffer.span(); | |
| 316 | 316 | return Error.InvalidInput; |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | fn errorIllegalChar(self: *Tokenizer, position: usize, char: u8, comptime fmt: []const u8, args: var) Error { |
| 320 | var buffer = try std.Buffer.initSize(&self.arena.allocator, 0); | |
| 321 | try buffer.append("illegal char "); | |
| 320 | var buffer = try std.ArrayListSentineled(u8, 0).initSize(&self.arena.allocator, 0); | |
| 321 | try buffer.appendSlice("illegal char "); | |
| 322 | 322 | try printUnderstandableChar(&buffer, char); |
| 323 | 323 | try buffer.outStream().print(" at position {}", .{position}); |
| 324 | 324 | if (fmt.len != 0) try buffer.outStream().print(": " ++ fmt, args); |
| 325 | self.error_text = buffer.toSlice(); | |
| 325 | self.error_text = buffer.span(); | |
| 326 | 326 | return Error.InvalidInput; |
| 327 | 327 | } |
| 328 | 328 | |
| ... | ... | @@ -333,18 +333,18 @@ pub const Tokenizer = struct { |
| 333 | 333 | |
| 334 | 334 | const State = union(enum) { |
| 335 | 335 | lhs: void, |
| 336 | target: std.Buffer, | |
| 337 | target_reverse_solidus: std.Buffer, | |
| 338 | target_dollar_sign: std.Buffer, | |
| 339 | target_colon: std.Buffer, | |
| 340 | target_colon_reverse_solidus: std.Buffer, | |
| 336 | target: std.ArrayListSentineled(u8, 0), | |
| 337 | target_reverse_solidus: std.ArrayListSentineled(u8, 0), | |
| 338 | target_dollar_sign: std.ArrayListSentineled(u8, 0), | |
| 339 | target_colon: std.ArrayListSentineled(u8, 0), | |
| 340 | target_colon_reverse_solidus: std.ArrayListSentineled(u8, 0), | |
| 341 | 341 | rhs: void, |
| 342 | 342 | rhs_continuation: void, |
| 343 | 343 | rhs_continuation_linefeed: void, |
| 344 | prereq_quote: std.Buffer, | |
| 345 | prereq: std.Buffer, | |
| 346 | prereq_continuation: std.Buffer, | |
| 347 | prereq_continuation_linefeed: std.Buffer, | |
| 344 | prereq_quote: std.ArrayListSentineled(u8, 0), | |
| 345 | prereq: std.ArrayListSentineled(u8, 0), | |
| 346 | prereq_continuation: std.ArrayListSentineled(u8, 0), | |
| 347 | prereq_continuation_linefeed: std.ArrayListSentineled(u8, 0), | |
| 348 | 348 | }; |
| 349 | 349 | |
| 350 | 350 | const Token = struct { |
| ... | ... | @@ -841,31 +841,31 @@ fn depTokenizer(input: []const u8, expect: []const u8) !void { |
| 841 | 841 | defer arena_allocator.deinit(); |
| 842 | 842 | |
| 843 | 843 | var it = Tokenizer.init(arena, input); |
| 844 | var buffer = try std.Buffer.initSize(arena, 0); | |
| 844 | var buffer = try std.ArrayListSentineled(u8, 0).initSize(arena, 0); | |
| 845 | 845 | var i: usize = 0; |
| 846 | 846 | while (true) { |
| 847 | 847 | const r = it.next() catch |err| { |
| 848 | 848 | switch (err) { |
| 849 | 849 | Tokenizer.Error.InvalidInput => { |
| 850 | if (i != 0) try buffer.append("\n"); | |
| 851 | try buffer.append("ERROR: "); | |
| 852 | try buffer.append(it.error_text); | |
| 850 | if (i != 0) try buffer.appendSlice("\n"); | |
| 851 | try buffer.appendSlice("ERROR: "); | |
| 852 | try buffer.appendSlice(it.error_text); | |
| 853 | 853 | }, |
| 854 | 854 | else => return err, |
| 855 | 855 | } |
| 856 | 856 | break; |
| 857 | 857 | }; |
| 858 | 858 | const token = r orelse break; |
| 859 | if (i != 0) try buffer.append("\n"); | |
| 860 | try buffer.append(@tagName(token.id)); | |
| 861 | try buffer.append(" = {"); | |
| 859 | if (i != 0) try buffer.appendSlice("\n"); | |
| 860 | try buffer.appendSlice(@tagName(token.id)); | |
| 861 | try buffer.appendSlice(" = {"); | |
| 862 | 862 | for (token.bytes) |b| { |
| 863 | try buffer.appendByte(printable_char_tab[b]); | |
| 863 | try buffer.append(printable_char_tab[b]); | |
| 864 | 864 | } |
| 865 | try buffer.append("}"); | |
| 865 | try buffer.appendSlice("}"); | |
| 866 | 866 | i += 1; |
| 867 | 867 | } |
| 868 | const got: []const u8 = buffer.toSlice(); | |
| 868 | const got: []const u8 = buffer.span(); | |
| 869 | 869 | |
| 870 | 870 | if (std.mem.eql(u8, expect, got)) { |
| 871 | 871 | testing.expect(true); |
| ... | ... | @@ -995,13 +995,13 @@ fn printCharValues(out: var, bytes: []const u8) !void { |
| 995 | 995 | } |
| 996 | 996 | } |
| 997 | 997 | |
| 998 | fn printUnderstandableChar(buffer: *std.Buffer, char: u8) !void { | |
| 998 | fn printUnderstandableChar(buffer: *std.ArrayListSentineled(u8, 0), char: u8) !void { | |
| 999 | 999 | if (!std.ascii.isPrint(char) or char == ' ') { |
| 1000 | 1000 | try buffer.outStream().print("\\x{X:2}", .{char}); |
| 1001 | 1001 | } else { |
| 1002 | try buffer.append("'"); | |
| 1003 | try buffer.appendByte(printable_char_tab[char]); | |
| 1004 | try buffer.append("'"); | |
| 1002 | try buffer.appendSlice("'"); | |
| 1003 | try buffer.append(printable_char_tab[char]); | |
| 1004 | try buffer.appendSlice("'"); | |
| 1005 | 1005 | } |
| 1006 | 1006 | } |
| 1007 | 1007 |
src-self-hosted/errmsg.zig+2-2| ... | ... | @@ -158,7 +158,7 @@ pub const Msg = struct { |
| 158 | 158 | parse_error: *const ast.Error, |
| 159 | 159 | ) !*Msg { |
| 160 | 160 | const loc_token = parse_error.loc(); |
| 161 | var text_buf = try std.Buffer.initSize(comp.gpa(), 0); | |
| 161 | var text_buf = std.ArrayList(u8).init(comp.gpa()); | |
| 162 | 162 | defer text_buf.deinit(); |
| 163 | 163 | |
| 164 | 164 | const realpath_copy = try mem.dupe(comp.gpa(), u8, tree_scope.root().realpath); |
| ... | ... | @@ -197,7 +197,7 @@ pub const Msg = struct { |
| 197 | 197 | realpath: []const u8, |
| 198 | 198 | ) !*Msg { |
| 199 | 199 | const loc_token = parse_error.loc(); |
| 200 | var text_buf = try std.Buffer.initSize(allocator, 0); | |
| 200 | var text_buf = std.ArrayList(u8).init(allocator); | |
| 201 | 201 | defer text_buf.deinit(); |
| 202 | 202 | |
| 203 | 203 | const realpath_copy = try mem.dupe(allocator, u8, realpath); |
src-self-hosted/ir.zig+4-4| ... | ... | @@ -965,9 +965,9 @@ pub const Code = struct { |
| 965 | 965 | |
| 966 | 966 | pub fn dump(self: *Code) void { |
| 967 | 967 | var bb_i: usize = 0; |
| 968 | for (self.basic_block_list.toSliceConst()) |bb| { | |
| 968 | for (self.basic_block_list.span()) |bb| { | |
| 969 | 969 | std.debug.warn("{s}_{}:\n", .{ bb.name_hint, bb.debug_id }); |
| 970 | for (bb.instruction_list.toSliceConst()) |instr| { | |
| 970 | for (bb.instruction_list.span()) |instr| { | |
| 971 | 971 | std.debug.warn(" ", .{}); |
| 972 | 972 | instr.dump(); |
| 973 | 973 | std.debug.warn("\n", .{}); |
| ... | ... | @@ -978,7 +978,7 @@ pub const Code = struct { |
| 978 | 978 | /// returns a ref-incremented value, or adds a compile error |
| 979 | 979 | pub fn getCompTimeResult(self: *Code, comp: *Compilation) !*Value { |
| 980 | 980 | const bb = self.basic_block_list.at(0); |
| 981 | for (bb.instruction_list.toSliceConst()) |inst| { | |
| 981 | for (bb.instruction_list.span()) |inst| { | |
| 982 | 982 | if (inst.cast(Inst.Return)) |ret_inst| { |
| 983 | 983 | const ret_value = ret_inst.params.return_value; |
| 984 | 984 | if (ret_value.isCompTime()) { |
| ... | ... | @@ -2585,6 +2585,6 @@ pub fn analyze(comp: *Compilation, old_code: *Code, expected_type: ?*Type) !*Cod |
| 2585 | 2585 | return ira.irb.finish(); |
| 2586 | 2586 | } |
| 2587 | 2587 | |
| 2588 | ira.irb.code.return_type = try ira.resolvePeerTypes(expected_type, ira.src_implicit_return_type_list.toSliceConst()); | |
| 2588 | ira.irb.code.return_type = try ira.resolvePeerTypes(expected_type, ira.src_implicit_return_type_list.span()); | |
| 2589 | 2589 | return ira.irb.finish(); |
| 2590 | 2590 | } |
src-self-hosted/libc_installation.zig+20-24| ... | ... | @@ -14,11 +14,11 @@ usingnamespace @import("windows_sdk.zig"); |
| 14 | 14 | |
| 15 | 15 | /// See the render function implementation for documentation of the fields. |
| 16 | 16 | pub const LibCInstallation = struct { |
| 17 | include_dir: ?[:0]const u8 = null, | |
| 18 | sys_include_dir: ?[:0]const u8 = null, | |
| 19 | crt_dir: ?[:0]const u8 = null, | |
| 20 | msvc_lib_dir: ?[:0]const u8 = null, | |
| 21 | kernel32_lib_dir: ?[:0]const u8 = null, | |
| 17 | include_dir: ?[]const u8 = null, | |
| 18 | sys_include_dir: ?[]const u8 = null, | |
| 19 | crt_dir: ?[]const u8 = null, | |
| 20 | msvc_lib_dir: ?[]const u8 = null, | |
| 21 | kernel32_lib_dir: ?[]const u8 = null, | |
| 22 | 22 | |
| 23 | 23 | pub const FindError = error{ |
| 24 | 24 | OutOfMemory, |
| ... | ... | @@ -54,7 +54,7 @@ pub const LibCInstallation = struct { |
| 54 | 54 | } |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | const contents = try std.io.readFileAlloc(allocator, libc_file); | |
| 57 | const contents = try std.fs.cwd().readFileAlloc(allocator, libc_file, std.math.maxInt(usize)); | |
| 58 | 58 | defer allocator.free(contents); |
| 59 | 59 | |
| 60 | 60 | var it = std.mem.tokenize(contents, "\n"); |
| ... | ... | @@ -229,7 +229,7 @@ pub const LibCInstallation = struct { |
| 229 | 229 | "-xc", |
| 230 | 230 | dev_null, |
| 231 | 231 | }; |
| 232 | const exec_res = std.ChildProcess.exec2(.{ | |
| 232 | const exec_res = std.ChildProcess.exec(.{ | |
| 233 | 233 | .allocator = allocator, |
| 234 | 234 | .argv = &argv, |
| 235 | 235 | .max_output_bytes = 1024 * 1024, |
| ... | ... | @@ -327,15 +327,14 @@ pub const LibCInstallation = struct { |
| 327 | 327 | var search_buf: [2]Search = undefined; |
| 328 | 328 | const searches = fillSearch(&search_buf, sdk); |
| 329 | 329 | |
| 330 | var result_buf = try std.Buffer.initSize(allocator, 0); | |
| 330 | var result_buf = std.ArrayList(u8).init(allocator); | |
| 331 | 331 | defer result_buf.deinit(); |
| 332 | 332 | |
| 333 | 333 | for (searches) |search| { |
| 334 | 334 | result_buf.shrink(0); |
| 335 | const stream = result_buf.outStream(); | |
| 336 | try stream.print("{}\\Include\\{}\\ucrt", .{ search.path, search.version }); | |
| 335 | try result_buf.outStream().print("{}\\Include\\{}\\ucrt", .{ search.path, search.version }); | |
| 337 | 336 | |
| 338 | var dir = fs.cwd().openDir(result_buf.toSliceConst(), .{}) catch |err| switch (err) { | |
| 337 | var dir = fs.cwd().openDir(result_buf.span(), .{}) catch |err| switch (err) { | |
| 339 | 338 | error.FileNotFound, |
| 340 | 339 | error.NotDir, |
| 341 | 340 | error.NoDevice, |
| ... | ... | @@ -367,7 +366,7 @@ pub const LibCInstallation = struct { |
| 367 | 366 | var search_buf: [2]Search = undefined; |
| 368 | 367 | const searches = fillSearch(&search_buf, sdk); |
| 369 | 368 | |
| 370 | var result_buf = try std.Buffer.initSize(allocator, 0); | |
| 369 | var result_buf = std.ArrayList(u8).init(allocator); | |
| 371 | 370 | defer result_buf.deinit(); |
| 372 | 371 | |
| 373 | 372 | const arch_sub_dir = switch (builtin.arch) { |
| ... | ... | @@ -379,10 +378,9 @@ pub const LibCInstallation = struct { |
| 379 | 378 | |
| 380 | 379 | for (searches) |search| { |
| 381 | 380 | result_buf.shrink(0); |
| 382 | const stream = result_buf.outStream(); | |
| 383 | try stream.print("{}\\Lib\\{}\\ucrt\\{}", .{ search.path, search.version, arch_sub_dir }); | |
| 381 | try result_buf.outStream().print("{}\\Lib\\{}\\ucrt\\{}", .{ search.path, search.version, arch_sub_dir }); | |
| 384 | 382 | |
| 385 | var dir = fs.cwd().openDir(result_buf.toSliceConst(), .{}) catch |err| switch (err) { | |
| 383 | var dir = fs.cwd().openDir(result_buf.span(), .{}) catch |err| switch (err) { | |
| 386 | 384 | error.FileNotFound, |
| 387 | 385 | error.NotDir, |
| 388 | 386 | error.NoDevice, |
| ... | ... | @@ -422,7 +420,7 @@ pub const LibCInstallation = struct { |
| 422 | 420 | var search_buf: [2]Search = undefined; |
| 423 | 421 | const searches = fillSearch(&search_buf, sdk); |
| 424 | 422 | |
| 425 | var result_buf = try std.Buffer.initSize(allocator, 0); | |
| 423 | var result_buf = std.ArrayList(u8).init(allocator); | |
| 426 | 424 | defer result_buf.deinit(); |
| 427 | 425 | |
| 428 | 426 | const arch_sub_dir = switch (builtin.arch) { |
| ... | ... | @@ -437,7 +435,7 @@ pub const LibCInstallation = struct { |
| 437 | 435 | const stream = result_buf.outStream(); |
| 438 | 436 | try stream.print("{}\\Lib\\{}\\um\\{}", .{ search.path, search.version, arch_sub_dir }); |
| 439 | 437 | |
| 440 | var dir = fs.cwd().openDir(result_buf.toSliceConst(), .{}) catch |err| switch (err) { | |
| 438 | var dir = fs.cwd().openDir(result_buf.span(), .{}) catch |err| switch (err) { | |
| 441 | 439 | error.FileNotFound, |
| 442 | 440 | error.NotDir, |
| 443 | 441 | error.NoDevice, |
| ... | ... | @@ -470,12 +468,10 @@ pub const LibCInstallation = struct { |
| 470 | 468 | const up1 = fs.path.dirname(msvc_lib_dir) orelse return error.LibCStdLibHeaderNotFound; |
| 471 | 469 | const up2 = fs.path.dirname(up1) orelse return error.LibCStdLibHeaderNotFound; |
| 472 | 470 | |
| 473 | var result_buf = try std.Buffer.init(allocator, up2); | |
| 474 | defer result_buf.deinit(); | |
| 475 | ||
| 476 | try result_buf.append("\\include"); | |
| 471 | const dir_path = try fs.path.join(allocator, &[_][]const u8{ up2, "include" }); | |
| 472 | errdefer allocator.free(dir_path); | |
| 477 | 473 | |
| 478 | var dir = fs.cwd().openDir(result_buf.toSliceConst(), .{}) catch |err| switch (err) { | |
| 474 | var dir = fs.cwd().openDir(dir_path, .{}) catch |err| switch (err) { | |
| 479 | 475 | error.FileNotFound, |
| 480 | 476 | error.NotDir, |
| 481 | 477 | error.NoDevice, |
| ... | ... | @@ -490,7 +486,7 @@ pub const LibCInstallation = struct { |
| 490 | 486 | else => return error.FileSystem, |
| 491 | 487 | }; |
| 492 | 488 | |
| 493 | self.sys_include_dir = result_buf.toOwnedSlice(); | |
| 489 | self.sys_include_dir = dir_path; | |
| 494 | 490 | } |
| 495 | 491 | |
| 496 | 492 | fn findNativeMsvcLibDir( |
| ... | ... | @@ -522,7 +518,7 @@ fn ccPrintFileName(args: CCPrintFileNameOptions) ![:0]u8 { |
| 522 | 518 | defer allocator.free(arg1); |
| 523 | 519 | const argv = [_][]const u8{ cc_exe, arg1 }; |
| 524 | 520 | |
| 525 | const exec_res = std.ChildProcess.exec2(.{ | |
| 521 | const exec_res = std.ChildProcess.exec(.{ | |
| 526 | 522 | .allocator = allocator, |
| 527 | 523 | .argv = &argv, |
| 528 | 524 | .max_output_bytes = 1024 * 1024, |
src-self-hosted/link.zig+12-12| ... | ... | @@ -15,10 +15,10 @@ const Context = struct { |
| 15 | 15 | link_in_crt: bool, |
| 16 | 16 | |
| 17 | 17 | link_err: error{OutOfMemory}!void, |
| 18 | link_msg: std.Buffer, | |
| 18 | link_msg: std.ArrayListSentineled(u8, 0), | |
| 19 | 19 | |
| 20 | 20 | libc: *LibCInstallation, |
| 21 | out_file_path: std.Buffer, | |
| 21 | out_file_path: std.ArrayListSentineled(u8, 0), | |
| 22 | 22 | }; |
| 23 | 23 | |
| 24 | 24 | pub fn link(comp: *Compilation) !void { |
| ... | ... | @@ -34,9 +34,9 @@ pub fn link(comp: *Compilation) !void { |
| 34 | 34 | }; |
| 35 | 35 | defer ctx.arena.deinit(); |
| 36 | 36 | ctx.args = std.ArrayList([*:0]const u8).init(&ctx.arena.allocator); |
| 37 | ctx.link_msg = std.Buffer.initNull(&ctx.arena.allocator); | |
| 37 | ctx.link_msg = std.ArrayListSentineled(u8, 0).initNull(&ctx.arena.allocator); | |
| 38 | 38 | |
| 39 | ctx.out_file_path = try std.Buffer.init(&ctx.arena.allocator, comp.name.toSliceConst()); | |
| 39 | ctx.out_file_path = try std.ArrayListSentineled(u8, 0).init(&ctx.arena.allocator, comp.name.span()); | |
| 40 | 40 | switch (comp.kind) { |
| 41 | 41 | .Exe => { |
| 42 | 42 | try ctx.out_file_path.append(comp.target.exeFileExt()); |
| ... | ... | @@ -70,7 +70,7 @@ pub fn link(comp: *Compilation) !void { |
| 70 | 70 | try constructLinkerArgs(&ctx); |
| 71 | 71 | |
| 72 | 72 | if (comp.verbose_link) { |
| 73 | for (ctx.args.toSliceConst()) |arg, i| { | |
| 73 | for (ctx.args.span()) |arg, i| { | |
| 74 | 74 | const space = if (i == 0) "" else " "; |
| 75 | 75 | std.debug.warn("{}{s}", .{ space, arg }); |
| 76 | 76 | } |
| ... | ... | @@ -78,7 +78,7 @@ pub fn link(comp: *Compilation) !void { |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | const extern_ofmt = toExternObjectFormatType(comp.target.getObjectFormat()); |
| 81 | const args_slice = ctx.args.toSlice(); | |
| 81 | const args_slice = ctx.args.span(); | |
| 82 | 82 | |
| 83 | 83 | { |
| 84 | 84 | // LLD is not thread-safe, so we grab a global lock. |
| ... | ... | @@ -91,7 +91,7 @@ pub fn link(comp: *Compilation) !void { |
| 91 | 91 | // TODO capture these messages and pass them through the system, reporting them through the |
| 92 | 92 | // event system instead of printing them directly here. |
| 93 | 93 | // perhaps try to parse and understand them. |
| 94 | std.debug.warn("{}\n", .{ctx.link_msg.toSliceConst()}); | |
| 94 | std.debug.warn("{}\n", .{ctx.link_msg.span()}); | |
| 95 | 95 | } |
| 96 | 96 | return error.LinkFailed; |
| 97 | 97 | } |
| ... | ... | @@ -173,7 +173,7 @@ fn constructLinkerArgsElf(ctx: *Context) !void { |
| 173 | 173 | //} |
| 174 | 174 | |
| 175 | 175 | try ctx.args.append("-o"); |
| 176 | try ctx.args.append(ctx.out_file_path.toSliceConst()); | |
| 176 | try ctx.args.append(ctx.out_file_path.span()); | |
| 177 | 177 | |
| 178 | 178 | if (ctx.link_in_crt) { |
| 179 | 179 | const crt1o = if (ctx.comp.is_static) "crt1.o" else "Scrt1.o"; |
| ... | ... | @@ -291,7 +291,7 @@ fn constructLinkerArgsCoff(ctx: *Context) !void { |
| 291 | 291 | |
| 292 | 292 | const is_library = ctx.comp.kind == .Lib; |
| 293 | 293 | |
| 294 | const out_arg = try std.fmt.allocPrint(&ctx.arena.allocator, "-OUT:{}\x00", .{ctx.out_file_path.toSliceConst()}); | |
| 294 | const out_arg = try std.fmt.allocPrint(&ctx.arena.allocator, "-OUT:{}\x00", .{ctx.out_file_path.span()}); | |
| 295 | 295 | try ctx.args.append(@ptrCast([*:0]const u8, out_arg.ptr)); |
| 296 | 296 | |
| 297 | 297 | if (ctx.comp.haveLibC()) { |
| ... | ... | @@ -394,7 +394,7 @@ fn constructLinkerArgsMachO(ctx: *Context) !void { |
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | try ctx.args.append("-o"); |
| 397 | try ctx.args.append(ctx.out_file_path.toSliceConst()); | |
| 397 | try ctx.args.append(ctx.out_file_path.span()); | |
| 398 | 398 | |
| 399 | 399 | if (shared) { |
| 400 | 400 | try ctx.args.append("-headerpad_max_install_names"); |
| ... | ... | @@ -432,7 +432,7 @@ fn constructLinkerArgsMachO(ctx: *Context) !void { |
| 432 | 432 | |
| 433 | 433 | // TODO |
| 434 | 434 | //if (ctx.comp.target == Target.Native) { |
| 435 | // for (ctx.comp.link_libs_list.toSliceConst()) |lib| { | |
| 435 | // for (ctx.comp.link_libs_list.span()) |lib| { | |
| 436 | 436 | // if (mem.eql(u8, lib.name, "c")) { |
| 437 | 437 | // // on Darwin, libSystem has libc in it, but also you have to use it |
| 438 | 438 | // // to make syscalls because the syscall numbers are not documented |
| ... | ... | @@ -482,7 +482,7 @@ fn addFnObjects(ctx: *Context) !void { |
| 482 | 482 | ctx.comp.gpa().destroy(node); |
| 483 | 483 | continue; |
| 484 | 484 | }; |
| 485 | try ctx.args.append(fn_val.containing_object.toSliceConst()); | |
| 485 | try ctx.args.append(fn_val.containing_object.span()); | |
| 486 | 486 | it = node.next; |
| 487 | 487 | } |
| 488 | 488 | } |
src-self-hosted/main.zig+7-7| ... | ... | @@ -421,7 +421,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co |
| 421 | 421 | process.exit(1); |
| 422 | 422 | } |
| 423 | 423 | |
| 424 | try ZigCompiler.setLlvmArgv(allocator, mllvm_flags.toSliceConst()); | |
| 424 | try ZigCompiler.setLlvmArgv(allocator, mllvm_flags.span()); | |
| 425 | 425 | |
| 426 | 426 | const zig_lib_dir = introspect.resolveZigLibDir(allocator) catch process.exit(1); |
| 427 | 427 | defer allocator.free(zig_lib_dir); |
| ... | ... | @@ -448,14 +448,14 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co |
| 448 | 448 | comp.override_libc = &override_libc; |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | for (system_libs.toSliceConst()) |lib| { | |
| 451 | for (system_libs.span()) |lib| { | |
| 452 | 452 | _ = try comp.addLinkLib(lib, true); |
| 453 | 453 | } |
| 454 | 454 | |
| 455 | 455 | comp.version = version; |
| 456 | 456 | comp.is_test = false; |
| 457 | 457 | comp.linker_script = linker_script; |
| 458 | comp.clang_argv = clang_argv_buf.toSliceConst(); | |
| 458 | comp.clang_argv = clang_argv_buf.span(); | |
| 459 | 459 | comp.strip = strip; |
| 460 | 460 | |
| 461 | 461 | comp.verbose_tokenize = verbose_tokenize; |
| ... | ... | @@ -488,8 +488,8 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co |
| 488 | 488 | comp.emit_asm = emit_asm; |
| 489 | 489 | comp.emit_llvm_ir = emit_llvm_ir; |
| 490 | 490 | comp.emit_h = emit_h; |
| 491 | comp.assembly_files = assembly_files.toSliceConst(); | |
| 492 | comp.link_objects = link_objects.toSliceConst(); | |
| 491 | comp.assembly_files = assembly_files.span(); | |
| 492 | comp.link_objects = link_objects.span(); | |
| 493 | 493 | |
| 494 | 494 | comp.start(); |
| 495 | 495 | processBuildEvents(comp, color); |
| ... | ... | @@ -683,7 +683,7 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void { |
| 683 | 683 | }; |
| 684 | 684 | |
| 685 | 685 | var group = event.Group(FmtError!void).init(allocator); |
| 686 | for (input_files.toSliceConst()) |file_path| { | |
| 686 | for (input_files.span()) |file_path| { | |
| 687 | 687 | try group.call(fmtPath, .{ &fmt, file_path, check_flag }); |
| 688 | 688 | } |
| 689 | 689 | try group.wait(); |
| ... | ... | @@ -898,7 +898,7 @@ const CliPkg = struct { |
| 898 | 898 | } |
| 899 | 899 | |
| 900 | 900 | pub fn deinit(self: *CliPkg) void { |
| 901 | for (self.children.toSliceConst()) |child| { | |
| 901 | for (self.children.span()) |child| { | |
| 902 | 902 | child.deinit(); |
| 903 | 903 | } |
| 904 | 904 | self.children.deinit(); |
src-self-hosted/package.zig+5-5| ... | ... | @@ -1,11 +1,11 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const mem = std.mem; |
| 3 | 3 | const assert = std.debug.assert; |
| 4 | const Buffer = std.Buffer; | |
| 4 | const ArrayListSentineled = std.ArrayListSentineled; | |
| 5 | 5 | |
| 6 | 6 | pub const Package = struct { |
| 7 | root_src_dir: Buffer, | |
| 8 | root_src_path: Buffer, | |
| 7 | root_src_dir: ArrayListSentineled(u8, 0), | |
| 8 | root_src_path: ArrayListSentineled(u8, 0), | |
| 9 | 9 | |
| 10 | 10 | /// relative to root_src_dir |
| 11 | 11 | table: Table, |
| ... | ... | @@ -17,8 +17,8 @@ pub const Package = struct { |
| 17 | 17 | pub fn create(allocator: *mem.Allocator, root_src_dir: []const u8, root_src_path: []const u8) !*Package { |
| 18 | 18 | const ptr = try allocator.create(Package); |
| 19 | 19 | ptr.* = Package{ |
| 20 | .root_src_dir = try Buffer.init(allocator, root_src_dir), | |
| 21 | .root_src_path = try Buffer.init(allocator, root_src_path), | |
| 20 | .root_src_dir = try ArrayListSentineled(u8, 0).init(allocator, root_src_dir), | |
| 21 | .root_src_path = try ArrayListSentineled(u8, 0).init(allocator, root_src_path), | |
| 22 | 22 | .table = Table.init(allocator), |
| 23 | 23 | }; |
| 24 | 24 | return ptr; |
src-self-hosted/stage2.zig+57-55| ... | ... | @@ -8,7 +8,7 @@ const fs = std.fs; |
| 8 | 8 | const process = std.process; |
| 9 | 9 | const Allocator = mem.Allocator; |
| 10 | 10 | const ArrayList = std.ArrayList; |
| 11 | const Buffer = std.Buffer; | |
| 11 | const ArrayListSentineled = std.ArrayListSentineled; | |
| 12 | 12 | const Target = std.Target; |
| 13 | 13 | const CrossTarget = std.zig.CrossTarget; |
| 14 | 14 | const self_hosted_main = @import("main.zig"); |
| ... | ... | @@ -188,14 +188,14 @@ fn fmtMain(argc: c_int, argv: [*]const [*:0]const u8) !void { |
| 188 | 188 | const argc_usize = @intCast(usize, argc); |
| 189 | 189 | var arg_i: usize = 0; |
| 190 | 190 | while (arg_i < argc_usize) : (arg_i += 1) { |
| 191 | try args_list.append(mem.toSliceConst(u8, argv[arg_i])); | |
| 191 | try args_list.append(mem.spanZ(argv[arg_i])); | |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | stdout = std.io.getStdOut().outStream(); |
| 195 | 195 | stderr_file = std.io.getStdErr(); |
| 196 | 196 | stderr = stderr_file.outStream(); |
| 197 | 197 | |
| 198 | const args = args_list.toSliceConst()[2..]; | |
| 198 | const args = args_list.span()[2..]; | |
| 199 | 199 | |
| 200 | 200 | var color: errmsg.Color = .Auto; |
| 201 | 201 | var stdin_flag: bool = false; |
| ... | ... | @@ -288,7 +288,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*:0]const u8) !void { |
| 288 | 288 | .allocator = allocator, |
| 289 | 289 | }; |
| 290 | 290 | |
| 291 | for (input_files.toSliceConst()) |file_path| { | |
| 291 | for (input_files.span()) |file_path| { | |
| 292 | 292 | try fmtPath(&fmt, file_path, check_flag); |
| 293 | 293 | } |
| 294 | 294 | if (fmt.any_error) { |
| ... | ... | @@ -321,7 +321,8 @@ fn fmtPath(fmt: *Fmt, file_path: []const u8, check_mode: bool) FmtError!void { |
| 321 | 321 | if (fmt.seen.exists(file_path)) return; |
| 322 | 322 | try fmt.seen.put(file_path); |
| 323 | 323 | |
| 324 | const source_code = io.readFileAlloc(fmt.allocator, file_path) catch |err| switch (err) { | |
| 324 | const max = std.math.maxInt(usize); | |
| 325 | const source_code = fs.cwd().readFileAlloc(fmt.allocator, file_path, max) catch |err| switch (err) { | |
| 325 | 326 | error.IsDir, error.AccessDenied => { |
| 326 | 327 | // TODO make event based (and dir.next()) |
| 327 | 328 | var dir = try fs.cwd().openDir(file_path, .{ .iterate = true }); |
| ... | ... | @@ -413,12 +414,13 @@ fn printErrMsgToFile( |
| 413 | 414 | const start_loc = tree.tokenLocationPtr(0, first_token); |
| 414 | 415 | const end_loc = tree.tokenLocationPtr(first_token.end, last_token); |
| 415 | 416 | |
| 416 | var text_buf = try std.Buffer.initSize(allocator, 0); | |
| 417 | const out_stream = &text_buf.outStream(); | |
| 417 | var text_buf = std.ArrayList(u8).init(allocator); | |
| 418 | defer text_buf.deinit(); | |
| 419 | const out_stream = text_buf.outStream(); | |
| 418 | 420 | try parse_error.render(&tree.tokens, out_stream); |
| 419 | const text = text_buf.toOwnedSlice(); | |
| 421 | const text = text_buf.span(); | |
| 420 | 422 | |
| 421 | const stream = &file.outStream(); | |
| 423 | const stream = file.outStream(); | |
| 422 | 424 | try stream.print("{}:{}:{}: error: {}\n", .{ path, start_loc.line + 1, start_loc.column + 1, text }); |
| 423 | 425 | |
| 424 | 426 | if (!color_on) return; |
| ... | ... | @@ -450,10 +452,10 @@ export fn stage2_DepTokenizer_deinit(self: *stage2_DepTokenizer) void { |
| 450 | 452 | |
| 451 | 453 | export fn stage2_DepTokenizer_next(self: *stage2_DepTokenizer) stage2_DepNextResult { |
| 452 | 454 | const otoken = self.handle.next() catch { |
| 453 | const textz = std.Buffer.init(&self.handle.arena.allocator, self.handle.error_text) catch @panic("failed to create .d tokenizer error text"); | |
| 455 | const textz = std.ArrayListSentineled(u8, 0).init(&self.handle.arena.allocator, self.handle.error_text) catch @panic("failed to create .d tokenizer error text"); | |
| 454 | 456 | return stage2_DepNextResult{ |
| 455 | 457 | .type_id = .error_, |
| 456 | .textz = textz.toSlice().ptr, | |
| 458 | .textz = textz.span().ptr, | |
| 457 | 459 | }; |
| 458 | 460 | }; |
| 459 | 461 | const token = otoken orelse { |
| ... | ... | @@ -462,13 +464,13 @@ export fn stage2_DepTokenizer_next(self: *stage2_DepTokenizer) stage2_DepNextRes |
| 462 | 464 | .textz = undefined, |
| 463 | 465 | }; |
| 464 | 466 | }; |
| 465 | const textz = std.Buffer.init(&self.handle.arena.allocator, token.bytes) catch @panic("failed to create .d tokenizer token text"); | |
| 467 | const textz = std.ArrayListSentineled(u8, 0).init(&self.handle.arena.allocator, token.bytes) catch @panic("failed to create .d tokenizer token text"); | |
| 466 | 468 | return stage2_DepNextResult{ |
| 467 | 469 | .type_id = switch (token.id) { |
| 468 | 470 | .target => .target, |
| 469 | 471 | .prereq => .prereq, |
| 470 | 472 | }, |
| 471 | .textz = textz.toSlice().ptr, | |
| 473 | .textz = textz.span().ptr, | |
| 472 | 474 | }; |
| 473 | 475 | } |
| 474 | 476 | |
| ... | ... | @@ -575,7 +577,7 @@ fn detectNativeCpuWithLLVM( |
| 575 | 577 | var result = Target.Cpu.baseline(arch); |
| 576 | 578 | |
| 577 | 579 | if (llvm_cpu_name_z) |cpu_name_z| { |
| 578 | const llvm_cpu_name = mem.toSliceConst(u8, cpu_name_z); | |
| 580 | const llvm_cpu_name = mem.spanZ(cpu_name_z); | |
| 579 | 581 | |
| 580 | 582 | for (arch.allCpuModels()) |model| { |
| 581 | 583 | const this_llvm_name = model.llvm_name orelse continue; |
| ... | ... | @@ -596,7 +598,7 @@ fn detectNativeCpuWithLLVM( |
| 596 | 598 | const all_features = arch.allFeaturesList(); |
| 597 | 599 | |
| 598 | 600 | if (llvm_cpu_features_opt) |llvm_cpu_features| { |
| 599 | var it = mem.tokenize(mem.toSliceConst(u8, llvm_cpu_features), ","); | |
| 601 | var it = mem.tokenize(mem.spanZ(llvm_cpu_features), ","); | |
| 600 | 602 | while (it.next()) |decorated_llvm_feat| { |
| 601 | 603 | var op: enum { |
| 602 | 604 | add, |
| ... | ... | @@ -691,12 +693,11 @@ fn stage2CrossTarget( |
| 691 | 693 | mcpu_oz: ?[*:0]const u8, |
| 692 | 694 | dynamic_linker_oz: ?[*:0]const u8, |
| 693 | 695 | ) !CrossTarget { |
| 694 | const zig_triple = if (zig_triple_oz) |zig_triple_z| mem.toSliceConst(u8, zig_triple_z) else "native"; | |
| 695 | const mcpu = if (mcpu_oz) |mcpu_z| mem.toSliceConst(u8, mcpu_z) else null; | |
| 696 | const dynamic_linker = if (dynamic_linker_oz) |dl_z| mem.toSliceConst(u8, dl_z) else null; | |
| 696 | const mcpu = mem.spanZ(mcpu_oz); | |
| 697 | const dynamic_linker = mem.spanZ(dynamic_linker_oz); | |
| 697 | 698 | var diags: CrossTarget.ParseOptions.Diagnostics = .{}; |
| 698 | 699 | const target: CrossTarget = CrossTarget.parse(.{ |
| 699 | .arch_os_abi = zig_triple, | |
| 700 | .arch_os_abi = mem.spanZ(zig_triple_oz) orelse "native", | |
| 700 | 701 | .cpu_features = mcpu, |
| 701 | 702 | .dynamic_linker = dynamic_linker, |
| 702 | 703 | .diagnostics = &diags, |
| ... | ... | @@ -743,15 +744,15 @@ fn stage2TargetParse( |
| 743 | 744 | |
| 744 | 745 | // ABI warning |
| 745 | 746 | const Stage2LibCInstallation = extern struct { |
| 746 | include_dir: [*:0]const u8, | |
| 747 | include_dir: [*]const u8, | |
| 747 | 748 | include_dir_len: usize, |
| 748 | sys_include_dir: [*:0]const u8, | |
| 749 | sys_include_dir: [*]const u8, | |
| 749 | 750 | sys_include_dir_len: usize, |
| 750 | crt_dir: [*:0]const u8, | |
| 751 | crt_dir: [*]const u8, | |
| 751 | 752 | crt_dir_len: usize, |
| 752 | msvc_lib_dir: [*:0]const u8, | |
| 753 | msvc_lib_dir: [*]const u8, | |
| 753 | 754 | msvc_lib_dir_len: usize, |
| 754 | kernel32_lib_dir: [*:0]const u8, | |
| 755 | kernel32_lib_dir: [*]const u8, | |
| 755 | 756 | kernel32_lib_dir_len: usize, |
| 756 | 757 | |
| 757 | 758 | fn initFromStage2(self: *Stage2LibCInstallation, libc: LibCInstallation) void { |
| ... | ... | @@ -795,19 +796,19 @@ const Stage2LibCInstallation = extern struct { |
| 795 | 796 | fn toStage2(self: Stage2LibCInstallation) LibCInstallation { |
| 796 | 797 | var libc: LibCInstallation = .{}; |
| 797 | 798 | if (self.include_dir_len != 0) { |
| 798 | libc.include_dir = self.include_dir[0..self.include_dir_len :0]; | |
| 799 | libc.include_dir = self.include_dir[0..self.include_dir_len]; | |
| 799 | 800 | } |
| 800 | 801 | if (self.sys_include_dir_len != 0) { |
| 801 | libc.sys_include_dir = self.sys_include_dir[0..self.sys_include_dir_len :0]; | |
| 802 | libc.sys_include_dir = self.sys_include_dir[0..self.sys_include_dir_len]; | |
| 802 | 803 | } |
| 803 | 804 | if (self.crt_dir_len != 0) { |
| 804 | libc.crt_dir = self.crt_dir[0..self.crt_dir_len :0]; | |
| 805 | libc.crt_dir = self.crt_dir[0..self.crt_dir_len]; | |
| 805 | 806 | } |
| 806 | 807 | if (self.msvc_lib_dir_len != 0) { |
| 807 | libc.msvc_lib_dir = self.msvc_lib_dir[0..self.msvc_lib_dir_len :0]; | |
| 808 | libc.msvc_lib_dir = self.msvc_lib_dir[0..self.msvc_lib_dir_len]; | |
| 808 | 809 | } |
| 809 | 810 | if (self.kernel32_lib_dir_len != 0) { |
| 810 | libc.kernel32_lib_dir = self.kernel32_lib_dir[0..self.kernel32_lib_dir_len :0]; | |
| 811 | libc.kernel32_lib_dir = self.kernel32_lib_dir[0..self.kernel32_lib_dir_len]; | |
| 811 | 812 | } |
| 812 | 813 | return libc; |
| 813 | 814 | } |
| ... | ... | @@ -817,7 +818,7 @@ const Stage2LibCInstallation = extern struct { |
| 817 | 818 | export fn stage2_libc_parse(stage1_libc: *Stage2LibCInstallation, libc_file_z: [*:0]const u8) Error { |
| 818 | 819 | stderr_file = std.io.getStdErr(); |
| 819 | 820 | stderr = stderr_file.outStream(); |
| 820 | const libc_file = mem.toSliceConst(u8, libc_file_z); | |
| 821 | const libc_file = mem.spanZ(libc_file_z); | |
| 821 | 822 | var libc = LibCInstallation.parse(std.heap.c_allocator, libc_file, stderr) catch |err| switch (err) { |
| 822 | 823 | error.ParseError => return .SemanticAnalyzeFail, |
| 823 | 824 | error.DiskQuota => return .DiskQuota, |
| ... | ... | @@ -929,14 +930,14 @@ const Stage2Target = extern struct { |
| 929 | 930 | var dynamic_linker: ?[*:0]u8 = null; |
| 930 | 931 | const target = try crossTargetToTarget(cross_target, &dynamic_linker); |
| 931 | 932 | |
| 932 | var cache_hash = try std.Buffer.allocPrint(allocator, "{}\n{}\n", .{ | |
| 933 | var cache_hash = try std.ArrayListSentineled(u8, 0).allocPrint(allocator, "{}\n{}\n", .{ | |
| 933 | 934 | target.cpu.model.name, |
| 934 | 935 | target.cpu.features.asBytes(), |
| 935 | 936 | }); |
| 936 | 937 | defer cache_hash.deinit(); |
| 937 | 938 | |
| 938 | 939 | const generic_arch_name = target.cpu.arch.genericName(); |
| 939 | var cpu_builtin_str_buffer = try std.Buffer.allocPrint(allocator, | |
| 940 | var cpu_builtin_str_buffer = try std.ArrayListSentineled(u8, 0).allocPrint(allocator, | |
| 940 | 941 | \\Cpu{{ |
| 941 | 942 | \\ .arch = .{}, |
| 942 | 943 | \\ .model = &Target.{}.cpu.{}, |
| ... | ... | @@ -951,7 +952,7 @@ const Stage2Target = extern struct { |
| 951 | 952 | }); |
| 952 | 953 | defer cpu_builtin_str_buffer.deinit(); |
| 953 | 954 | |
| 954 | var llvm_features_buffer = try std.Buffer.initSize(allocator, 0); | |
| 955 | var llvm_features_buffer = try std.ArrayListSentineled(u8, 0).initSize(allocator, 0); | |
| 955 | 956 | defer llvm_features_buffer.deinit(); |
| 956 | 957 | |
| 957 | 958 | // Unfortunately we have to do the work twice, because Clang does not support |
| ... | ... | @@ -966,17 +967,17 @@ const Stage2Target = extern struct { |
| 966 | 967 | |
| 967 | 968 | if (feature.llvm_name) |llvm_name| { |
| 968 | 969 | const plus_or_minus = "-+"[@boolToInt(is_enabled)]; |
| 969 | try llvm_features_buffer.appendByte(plus_or_minus); | |
| 970 | try llvm_features_buffer.append(llvm_name); | |
| 971 | try llvm_features_buffer.append(","); | |
| 970 | try llvm_features_buffer.append(plus_or_minus); | |
| 971 | try llvm_features_buffer.appendSlice(llvm_name); | |
| 972 | try llvm_features_buffer.appendSlice(","); | |
| 972 | 973 | } |
| 973 | 974 | |
| 974 | 975 | if (is_enabled) { |
| 975 | 976 | // TODO some kind of "zig identifier escape" function rather than |
| 976 | 977 | // unconditionally using @"" syntax |
| 977 | try cpu_builtin_str_buffer.append(" .@\""); | |
| 978 | try cpu_builtin_str_buffer.append(feature.name); | |
| 979 | try cpu_builtin_str_buffer.append("\",\n"); | |
| 978 | try cpu_builtin_str_buffer.appendSlice(" .@\""); | |
| 979 | try cpu_builtin_str_buffer.appendSlice(feature.name); | |
| 980 | try cpu_builtin_str_buffer.appendSlice("\",\n"); | |
| 980 | 981 | } |
| 981 | 982 | } |
| 982 | 983 | |
| ... | ... | @@ -995,16 +996,16 @@ const Stage2Target = extern struct { |
| 995 | 996 | }, |
| 996 | 997 | } |
| 997 | 998 | |
| 998 | try cpu_builtin_str_buffer.append( | |
| 999 | try cpu_builtin_str_buffer.appendSlice( | |
| 999 | 1000 | \\ }), |
| 1000 | 1001 | \\}; |
| 1001 | 1002 | \\ |
| 1002 | 1003 | ); |
| 1003 | 1004 | |
| 1004 | assert(mem.endsWith(u8, llvm_features_buffer.toSliceConst(), ",")); | |
| 1005 | assert(mem.endsWith(u8, llvm_features_buffer.span(), ",")); | |
| 1005 | 1006 | llvm_features_buffer.shrink(llvm_features_buffer.len() - 1); |
| 1006 | 1007 | |
| 1007 | var os_builtin_str_buffer = try std.Buffer.allocPrint(allocator, | |
| 1008 | var os_builtin_str_buffer = try std.ArrayListSentineled(u8, 0).allocPrint(allocator, | |
| 1008 | 1009 | \\Os{{ |
| 1009 | 1010 | \\ .tag = .{}, |
| 1010 | 1011 | \\ .version_range = .{{ |
| ... | ... | @@ -1047,7 +1048,7 @@ const Stage2Target = extern struct { |
| 1047 | 1048 | .emscripten, |
| 1048 | 1049 | .uefi, |
| 1049 | 1050 | .other, |
| 1050 | => try os_builtin_str_buffer.append(" .none = {} }\n"), | |
| 1051 | => try os_builtin_str_buffer.appendSlice(" .none = {} }\n"), | |
| 1051 | 1052 | |
| 1052 | 1053 | .freebsd, |
| 1053 | 1054 | .macosx, |
| ... | ... | @@ -1123,10 +1124,10 @@ const Stage2Target = extern struct { |
| 1123 | 1124 | @tagName(target.os.version_range.windows.max), |
| 1124 | 1125 | }), |
| 1125 | 1126 | } |
| 1126 | try os_builtin_str_buffer.append("};\n"); | |
| 1127 | try os_builtin_str_buffer.appendSlice("};\n"); | |
| 1127 | 1128 | |
| 1128 | try cache_hash.append( | |
| 1129 | os_builtin_str_buffer.toSlice()[os_builtin_str_ver_start_index..os_builtin_str_buffer.len()], | |
| 1129 | try cache_hash.appendSlice( | |
| 1130 | os_builtin_str_buffer.span()[os_builtin_str_ver_start_index..os_builtin_str_buffer.len()], | |
| 1130 | 1131 | ); |
| 1131 | 1132 | |
| 1132 | 1133 | const glibc_or_darwin_version = blk: { |
| ... | ... | @@ -1238,10 +1239,10 @@ fn stage2DetectNativePaths(stage1_paths: *Stage2NativePaths) !void { |
| 1238 | 1239 | var paths = try std.zig.system.NativePaths.detect(std.heap.c_allocator); |
| 1239 | 1240 | errdefer paths.deinit(); |
| 1240 | 1241 | |
| 1241 | try convertSlice(paths.include_dirs.toSlice(), &stage1_paths.include_dirs_ptr, &stage1_paths.include_dirs_len); | |
| 1242 | try convertSlice(paths.lib_dirs.toSlice(), &stage1_paths.lib_dirs_ptr, &stage1_paths.lib_dirs_len); | |
| 1243 | try convertSlice(paths.rpaths.toSlice(), &stage1_paths.rpaths_ptr, &stage1_paths.rpaths_len); | |
| 1244 | try convertSlice(paths.warnings.toSlice(), &stage1_paths.warnings_ptr, &stage1_paths.warnings_len); | |
| 1242 | try convertSlice(paths.include_dirs.span(), &stage1_paths.include_dirs_ptr, &stage1_paths.include_dirs_len); | |
| 1243 | try convertSlice(paths.lib_dirs.span(), &stage1_paths.lib_dirs_ptr, &stage1_paths.lib_dirs_len); | |
| 1244 | try convertSlice(paths.rpaths.span(), &stage1_paths.rpaths_ptr, &stage1_paths.rpaths_len); | |
| 1245 | try convertSlice(paths.warnings.span(), &stage1_paths.warnings_ptr, &stage1_paths.warnings_len); | |
| 1245 | 1246 | } |
| 1246 | 1247 | |
| 1247 | 1248 | fn convertSlice(slice: [][:0]u8, ptr: *[*][*:0]u8, len: *usize) !void { |
| ... | ... | @@ -1285,18 +1286,19 @@ pub const ClangArgIterator = extern struct { |
| 1285 | 1286 | shared, |
| 1286 | 1287 | rdynamic, |
| 1287 | 1288 | wl, |
| 1288 | preprocess, | |
| 1289 | pp_or_asm, | |
| 1289 | 1290 | optimize, |
| 1290 | 1291 | debug, |
| 1291 | 1292 | sanitize, |
| 1292 | 1293 | linker_script, |
| 1293 | 1294 | verbose_cmds, |
| 1294 | exceptions, | |
| 1295 | no_exceptions, | |
| 1296 | rtti, | |
| 1297 | no_rtti, | |
| 1298 | 1295 | for_linker, |
| 1299 | 1296 | linker_input_z, |
| 1297 | lib_dir, | |
| 1298 | mcpu, | |
| 1299 | dep_file, | |
| 1300 | framework_dir, | |
| 1301 | framework, | |
| 1300 | 1302 | }; |
| 1301 | 1303 | |
| 1302 | 1304 | const Args = struct { |
src-self-hosted/test.zig+7-5| ... | ... | @@ -88,8 +88,7 @@ pub const TestContext = struct { |
| 88 | 88 | try std.fs.cwd().makePath(dirname); |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | // TODO async I/O | |
| 92 | try std.io.writeFile(file1_path, source); | |
| 91 | try std.fs.cwd().writeFile(file1_path, source); | |
| 93 | 92 | |
| 94 | 93 | var comp = try Compilation.create( |
| 95 | 94 | &self.zig_compiler, |
| ... | ... | @@ -122,8 +121,7 @@ pub const TestContext = struct { |
| 122 | 121 | try std.fs.cwd().makePath(dirname); |
| 123 | 122 | } |
| 124 | 123 | |
| 125 | // TODO async I/O | |
| 126 | try std.io.writeFile(file1_path, source); | |
| 124 | try std.fs.cwd().writeFile(file1_path, source); | |
| 127 | 125 | |
| 128 | 126 | var comp = try Compilation.create( |
| 129 | 127 | &self.zig_compiler, |
| ... | ... | @@ -156,7 +154,11 @@ pub const TestContext = struct { |
| 156 | 154 | .Ok => { |
| 157 | 155 | const argv = [_][]const u8{exe_file}; |
| 158 | 156 | // TODO use event loop |
| 159 | const child = try std.ChildProcess.exec(allocator, argv, null, null, 1024 * 1024); | |
| 157 | const child = try std.ChildProcess.exec(.{ | |
| 158 | .allocator = allocator, | |
| 159 | .argv = argv, | |
| 160 | .max_output_bytes = 1024 * 1024, | |
| 161 | }); | |
| 160 | 162 | switch (child.term) { |
| 161 | 163 | .Exited => |code| { |
| 162 | 164 | if (code != 0) { |
src-self-hosted/translate_c.zig+44-12| ... | ... | @@ -209,7 +209,7 @@ const Scope = struct { |
| 209 | 209 | |
| 210 | 210 | pub const Context = struct { |
| 211 | 211 | tree: *ast.Tree, |
| 212 | source_buffer: *std.Buffer, | |
| 212 | source_buffer: *std.ArrayList(u8), | |
| 213 | 213 | err: Error, |
| 214 | 214 | source_manager: *ZigClangSourceManager, |
| 215 | 215 | decl_table: DeclTable, |
| ... | ... | @@ -235,7 +235,7 @@ pub const Context = struct { |
| 235 | 235 | |
| 236 | 236 | /// Convert a null-terminated C string to a slice allocated in the arena |
| 237 | 237 | fn str(c: *Context, s: [*:0]const u8) ![]u8 { |
| 238 | return mem.dupe(c.a(), u8, mem.toSliceConst(u8, s)); | |
| 238 | return mem.dupe(c.a(), u8, mem.spanZ(s)); | |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | /// Convert a clang source location to a file:line:column string |
| ... | ... | @@ -275,7 +275,7 @@ pub fn translate( |
| 275 | 275 | |
| 276 | 276 | const tree = try tree_arena.allocator.create(ast.Tree); |
| 277 | 277 | tree.* = ast.Tree{ |
| 278 | .source = undefined, // need to use Buffer.toOwnedSlice later | |
| 278 | .source = undefined, // need to use toOwnedSlice later | |
| 279 | 279 | .root_node = undefined, |
| 280 | 280 | .arena_allocator = tree_arena, |
| 281 | 281 | .tokens = undefined, // can't reference the allocator yet |
| ... | ... | @@ -296,7 +296,7 @@ pub fn translate( |
| 296 | 296 | .eof_token = undefined, |
| 297 | 297 | }; |
| 298 | 298 | |
| 299 | var source_buffer = try std.Buffer.initSize(arena, 0); | |
| 299 | var source_buffer = std.ArrayList(u8).init(arena); | |
| 300 | 300 | |
| 301 | 301 | var context = Context{ |
| 302 | 302 | .tree = tree, |
| ... | ... | @@ -3845,7 +3845,9 @@ fn transCreateNodePtrType( |
| 3845 | 3845 | } |
| 3846 | 3846 | |
| 3847 | 3847 | fn transCreateNodeAPInt(c: *Context, int: *const ZigClangAPSInt) !*ast.Node { |
| 3848 | const num_limbs = ZigClangAPSInt_getNumWords(int); | |
| 3848 | const num_limbs = math.cast(usize, ZigClangAPSInt_getNumWords(int)) catch |err| switch (err) { | |
| 3849 | error.Overflow => return error.OutOfMemory, | |
| 3850 | }; | |
| 3849 | 3851 | var aps_int = int; |
| 3850 | 3852 | const is_negative = ZigClangAPSInt_isSigned(int) and ZigClangAPSInt_isNegative(int); |
| 3851 | 3853 | if (is_negative) |
| ... | ... | @@ -3855,8 +3857,26 @@ fn transCreateNodeAPInt(c: *Context, int: *const ZigClangAPSInt) !*ast.Node { |
| 3855 | 3857 | big.negate(); |
| 3856 | 3858 | defer big.deinit(); |
| 3857 | 3859 | const data = ZigClangAPSInt_getRawData(aps_int); |
| 3858 | var i: @TypeOf(num_limbs) = 0; | |
| 3859 | while (i < num_limbs) : (i += 1) big.limbs[i] = data[i]; | |
| 3860 | switch (@sizeOf(std.math.big.Limb)) { | |
| 3861 | 8 => { | |
| 3862 | var i: usize = 0; | |
| 3863 | while (i < num_limbs) : (i += 1) { | |
| 3864 | big.limbs[i] = data[i]; | |
| 3865 | } | |
| 3866 | }, | |
| 3867 | 4 => { | |
| 3868 | var limb_i: usize = 0; | |
| 3869 | var data_i: usize = 0; | |
| 3870 | while (limb_i < num_limbs) : ({ | |
| 3871 | limb_i += 2; | |
| 3872 | data_i += 1; | |
| 3873 | }) { | |
| 3874 | big.limbs[limb_i] = @truncate(u32, data[data_i]); | |
| 3875 | big.limbs[limb_i + 1] = @truncate(u32, data[data_i] >> 32); | |
| 3876 | } | |
| 3877 | }, | |
| 3878 | else => @compileError("unimplemented"), | |
| 3879 | } | |
| 3860 | 3880 | const str = big.toString(c.a(), 10) catch |err| switch (err) { |
| 3861 | 3881 | error.OutOfMemory => return error.OutOfMemory, |
| 3862 | 3882 | else => unreachable, |
| ... | ... | @@ -4289,7 +4309,7 @@ fn makeRestorePoint(c: *Context) RestorePoint { |
| 4289 | 4309 | return RestorePoint{ |
| 4290 | 4310 | .c = c, |
| 4291 | 4311 | .token_index = c.tree.tokens.len, |
| 4292 | .src_buf_index = c.source_buffer.len(), | |
| 4312 | .src_buf_index = c.source_buffer.len, | |
| 4293 | 4313 | }; |
| 4294 | 4314 | } |
| 4295 | 4315 | |
| ... | ... | @@ -4751,11 +4771,11 @@ fn appendToken(c: *Context, token_id: Token.Id, bytes: []const u8) !ast.TokenInd |
| 4751 | 4771 | |
| 4752 | 4772 | fn appendTokenFmt(c: *Context, token_id: Token.Id, comptime format: []const u8, args: var) !ast.TokenIndex { |
| 4753 | 4773 | assert(token_id != .Invalid); |
| 4754 | const start_index = c.source_buffer.len(); | |
| 4774 | const start_index = c.source_buffer.len; | |
| 4755 | 4775 | errdefer c.source_buffer.shrink(start_index); |
| 4756 | 4776 | |
| 4757 | 4777 | try c.source_buffer.outStream().print(format, args); |
| 4758 | const end_index = c.source_buffer.len(); | |
| 4778 | const end_index = c.source_buffer.len; | |
| 4759 | 4779 | const token_index = c.tree.tokens.len; |
| 4760 | 4780 | const new_token = try c.tree.tokens.addOne(); |
| 4761 | 4781 | errdefer c.tree.tokens.shrink(token_index); |
| ... | ... | @@ -4765,7 +4785,7 @@ fn appendTokenFmt(c: *Context, token_id: Token.Id, comptime format: []const u8, |
| 4765 | 4785 | .start = start_index, |
| 4766 | 4786 | .end = end_index, |
| 4767 | 4787 | }; |
| 4768 | try c.source_buffer.appendByte(' '); | |
| 4788 | try c.source_buffer.append(' '); | |
| 4769 | 4789 | |
| 4770 | 4790 | return token_index; |
| 4771 | 4791 | } |
| ... | ... | @@ -5782,6 +5802,18 @@ fn parseCSuffixOpExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8, |
| 5782 | 5802 | op_id = .Mod; |
| 5783 | 5803 | op_token = try appendToken(c, .Percent, "%"); |
| 5784 | 5804 | }, |
| 5805 | .StringLiteral => { | |
| 5806 | op_id = .ArrayCat; | |
| 5807 | op_token = try appendToken(c, .PlusPlus, "++"); | |
| 5808 | ||
| 5809 | _ = it.prev(); | |
| 5810 | }, | |
| 5811 | .Identifier => { | |
| 5812 | op_id = .ArrayCat; | |
| 5813 | op_token = try appendToken(c, .PlusPlus, "++"); | |
| 5814 | ||
| 5815 | _ = it.prev(); | |
| 5816 | }, | |
| 5785 | 5817 | else => { |
| 5786 | 5818 | _ = it.prev(); |
| 5787 | 5819 | return node; |
| ... | ... | @@ -5839,7 +5871,7 @@ fn parseCPrefixOpExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8, |
| 5839 | 5871 | |
| 5840 | 5872 | fn tokenSlice(c: *Context, token: ast.TokenIndex) []u8 { |
| 5841 | 5873 | const tok = c.tree.tokens.at(token); |
| 5842 | const slice = c.source_buffer.toSlice()[tok.start..tok.end]; | |
| 5874 | const slice = c.source_buffer.span()[tok.start..tok.end]; | |
| 5843 | 5875 | return if (mem.startsWith(u8, slice, "@\"")) |
| 5844 | 5876 | slice[2 .. slice.len - 1] |
| 5845 | 5877 | else |
src-self-hosted/type.zig+2-2| ... | ... | @@ -387,10 +387,10 @@ pub const Type = struct { |
| 387 | 387 | }; |
| 388 | 388 | errdefer comp.gpa().destroy(self); |
| 389 | 389 | |
| 390 | var name_buf = try std.Buffer.initSize(comp.gpa(), 0); | |
| 390 | var name_buf = std.ArrayList(u8).init(comp.gpa()); | |
| 391 | 391 | defer name_buf.deinit(); |
| 392 | 392 | |
| 393 | const name_stream = &std.io.BufferOutStream.init(&name_buf).stream; | |
| 393 | const name_stream = name_buf.outStream(); | |
| 394 | 394 | |
| 395 | 395 | switch (key.data) { |
| 396 | 396 | .Generic => |generic| { |
src-self-hosted/util.zig+7-7| ... | ... | @@ -16,11 +16,11 @@ pub fn getDarwinArchString(self: Target) [:0]const u8 { |
| 16 | 16 | } |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | pub fn llvmTargetFromTriple(triple: std.Buffer) !*llvm.Target { | |
| 19 | pub fn llvmTargetFromTriple(triple: [:0]const u8) !*llvm.Target { | |
| 20 | 20 | var result: *llvm.Target = undefined; |
| 21 | 21 | var err_msg: [*:0]u8 = undefined; |
| 22 | if (llvm.GetTargetFromTriple(triple.toSlice(), &result, &err_msg) != 0) { | |
| 23 | std.debug.warn("triple: {s} error: {s}\n", .{ triple.toSlice(), err_msg }); | |
| 22 | if (llvm.GetTargetFromTriple(triple, &result, &err_msg) != 0) { | |
| 23 | std.debug.warn("triple: {s} error: {s}\n", .{ triple, err_msg }); | |
| 24 | 24 | return error.UnsupportedTarget; |
| 25 | 25 | } |
| 26 | 26 | return result; |
| ... | ... | @@ -34,14 +34,14 @@ pub fn initializeAllTargets() void { |
| 34 | 34 | llvm.InitializeAllAsmParsers(); |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | pub fn getLLVMTriple(allocator: *std.mem.Allocator, target: std.Target) !std.Buffer { | |
| 38 | var result = try std.Buffer.initSize(allocator, 0); | |
| 39 | errdefer result.deinit(); | |
| 37 | pub fn getLLVMTriple(allocator: *std.mem.Allocator, target: std.Target) ![:0]u8 { | |
| 38 | var result = try std.ArrayListSentineled(u8, 0).initSize(allocator, 0); | |
| 39 | defer result.deinit(); | |
| 40 | 40 | |
| 41 | 41 | try result.outStream().print( |
| 42 | 42 | "{}-unknown-{}-{}", |
| 43 | 43 | .{ @tagName(target.cpu.arch), @tagName(target.os.tag), @tagName(target.abi) }, |
| 44 | 44 | ); |
| 45 | 45 | |
| 46 | return result; | |
| 46 | return result.toOwnedSlice(); | |
| 47 | 47 | } |
src-self-hosted/value.zig+9-9| ... | ... | @@ -3,7 +3,7 @@ const Scope = @import("scope.zig").Scope; |
| 3 | 3 | const Compilation = @import("compilation.zig").Compilation; |
| 4 | 4 | const ObjectFile = @import("codegen.zig").ObjectFile; |
| 5 | 5 | const llvm = @import("llvm.zig"); |
| 6 | const Buffer = std.Buffer; | |
| 6 | const ArrayListSentineled = std.ArrayListSentineled; | |
| 7 | 7 | const assert = std.debug.assert; |
| 8 | 8 | |
| 9 | 9 | /// Values are ref-counted, heap-allocated, and copy-on-write |
| ... | ... | @@ -131,9 +131,9 @@ pub const Value = struct { |
| 131 | 131 | |
| 132 | 132 | /// The main external name that is used in the .o file. |
| 133 | 133 | /// TODO https://github.com/ziglang/zig/issues/265 |
| 134 | symbol_name: Buffer, | |
| 134 | symbol_name: ArrayListSentineled(u8, 0), | |
| 135 | 135 | |
| 136 | pub fn create(comp: *Compilation, fn_type: *Type.Fn, symbol_name: Buffer) !*FnProto { | |
| 136 | pub fn create(comp: *Compilation, fn_type: *Type.Fn, symbol_name: ArrayListSentineled(u8, 0)) !*FnProto { | |
| 137 | 137 | const self = try comp.gpa().create(FnProto); |
| 138 | 138 | self.* = FnProto{ |
| 139 | 139 | .base = Value{ |
| ... | ... | @@ -156,7 +156,7 @@ pub const Value = struct { |
| 156 | 156 | const llvm_fn_type = try self.base.typ.getLlvmType(ofile.arena, ofile.context); |
| 157 | 157 | const llvm_fn = llvm.AddFunction( |
| 158 | 158 | ofile.module, |
| 159 | self.symbol_name.toSliceConst(), | |
| 159 | self.symbol_name.span(), | |
| 160 | 160 | llvm_fn_type, |
| 161 | 161 | ) orelse return error.OutOfMemory; |
| 162 | 162 | |
| ... | ... | @@ -171,7 +171,7 @@ pub const Value = struct { |
| 171 | 171 | |
| 172 | 172 | /// The main external name that is used in the .o file. |
| 173 | 173 | /// TODO https://github.com/ziglang/zig/issues/265 |
| 174 | symbol_name: Buffer, | |
| 174 | symbol_name: ArrayListSentineled(u8, 0), | |
| 175 | 175 | |
| 176 | 176 | /// parent should be the top level decls or container decls |
| 177 | 177 | fndef_scope: *Scope.FnDef, |
| ... | ... | @@ -183,13 +183,13 @@ pub const Value = struct { |
| 183 | 183 | block_scope: ?*Scope.Block, |
| 184 | 184 | |
| 185 | 185 | /// Path to the object file that contains this function |
| 186 | containing_object: Buffer, | |
| 186 | containing_object: ArrayListSentineled(u8, 0), | |
| 187 | 187 | |
| 188 | 188 | link_set_node: *std.TailQueue(?*Value.Fn).Node, |
| 189 | 189 | |
| 190 | 190 | /// Creates a Fn value with 1 ref |
| 191 | 191 | /// Takes ownership of symbol_name |
| 192 | pub fn create(comp: *Compilation, fn_type: *Type.Fn, fndef_scope: *Scope.FnDef, symbol_name: Buffer) !*Fn { | |
| 192 | pub fn create(comp: *Compilation, fn_type: *Type.Fn, fndef_scope: *Scope.FnDef, symbol_name: ArrayListSentineled(u8, 0)) !*Fn { | |
| 193 | 193 | const link_set_node = try comp.gpa().create(Compilation.FnLinkSet.Node); |
| 194 | 194 | link_set_node.* = Compilation.FnLinkSet.Node{ |
| 195 | 195 | .data = null, |
| ... | ... | @@ -209,7 +209,7 @@ pub const Value = struct { |
| 209 | 209 | .child_scope = &fndef_scope.base, |
| 210 | 210 | .block_scope = null, |
| 211 | 211 | .symbol_name = symbol_name, |
| 212 | .containing_object = Buffer.initNull(comp.gpa()), | |
| 212 | .containing_object = ArrayListSentineled(u8, 0).initNull(comp.gpa()), | |
| 213 | 213 | .link_set_node = link_set_node, |
| 214 | 214 | }; |
| 215 | 215 | fn_type.base.base.ref(); |
| ... | ... | @@ -241,7 +241,7 @@ pub const Value = struct { |
| 241 | 241 | const llvm_fn_type = try self.base.typ.getLlvmType(ofile.arena, ofile.context); |
| 242 | 242 | const llvm_fn = llvm.AddFunction( |
| 243 | 243 | ofile.module, |
| 244 | self.symbol_name.toSliceConst(), | |
| 244 | self.symbol_name.span(), | |
| 245 | 245 | llvm_fn_type, |
| 246 | 246 | ) orelse return error.OutOfMemory; |
| 247 | 247 |
src/all_types.hpp+30-4| ... | ... | @@ -54,6 +54,16 @@ struct ResultLocCast; |
| 54 | 54 | struct ResultLocReturn; |
| 55 | 55 | struct IrExecutableGen; |
| 56 | 56 | |
| 57 | enum FileExt { | |
| 58 | FileExtUnknown, | |
| 59 | FileExtAsm, | |
| 60 | FileExtC, | |
| 61 | FileExtCpp, | |
| 62 | FileExtHeader, | |
| 63 | FileExtLLVMIr, | |
| 64 | FileExtLLVMBitCode, | |
| 65 | }; | |
| 66 | ||
| 57 | 67 | enum PtrLen { |
| 58 | 68 | PtrLenUnknown, |
| 59 | 69 | PtrLenSingle, |
| ... | ... | @@ -1324,6 +1334,7 @@ struct ZigTypeFloat { |
| 1324 | 1334 | size_t bit_count; |
| 1325 | 1335 | }; |
| 1326 | 1336 | |
| 1337 | // Needs to have the same memory layout as ZigTypeVector | |
| 1327 | 1338 | struct ZigTypeArray { |
| 1328 | 1339 | ZigType *child_type; |
| 1329 | 1340 | uint64_t len; |
| ... | ... | @@ -1512,12 +1523,17 @@ struct ZigTypeBoundFn { |
| 1512 | 1523 | ZigType *fn_type; |
| 1513 | 1524 | }; |
| 1514 | 1525 | |
| 1526 | // Needs to have the same memory layout as ZigTypeArray | |
| 1515 | 1527 | struct ZigTypeVector { |
| 1516 | 1528 | // The type must be a pointer, integer, bool, or float |
| 1517 | 1529 | ZigType *elem_type; |
| 1518 | uint32_t len; | |
| 1530 | uint64_t len; | |
| 1531 | size_t padding; | |
| 1519 | 1532 | }; |
| 1520 | 1533 | |
| 1534 | // A lot of code is relying on ZigTypeArray and ZigTypeVector having the same layout/size | |
| 1535 | static_assert(sizeof(ZigTypeVector) == sizeof(ZigTypeArray), "Size of ZigTypeVector and ZigTypeArray do not match!"); | |
| 1536 | ||
| 1521 | 1537 | enum ZigTypeId { |
| 1522 | 1538 | ZigTypeIdInvalid, |
| 1523 | 1539 | ZigTypeIdMetaType, |
| ... | ... | @@ -1999,6 +2015,12 @@ enum WantCSanitize { |
| 1999 | 2015 | WantCSanitizeEnabled, |
| 2000 | 2016 | }; |
| 2001 | 2017 | |
| 2018 | enum OptionalBool { | |
| 2019 | OptionalBoolNull, | |
| 2020 | OptionalBoolFalse, | |
| 2021 | OptionalBoolTrue, | |
| 2022 | }; | |
| 2023 | ||
| 2002 | 2024 | struct CFile { |
| 2003 | 2025 | ZigList<const char *> args; |
| 2004 | 2026 | const char *source_path; |
| ... | ... | @@ -2214,6 +2236,7 @@ struct CodeGen { |
| 2214 | 2236 | bool reported_bad_link_libc_error; |
| 2215 | 2237 | bool is_dynamic; // shared library rather than static library. dynamic musl rather than static musl. |
| 2216 | 2238 | bool need_frame_size_prefix_data; |
| 2239 | bool disable_c_depfile; | |
| 2217 | 2240 | |
| 2218 | 2241 | //////////////////////////// Participates in Input Parameter Cache Hash |
| 2219 | 2242 | /////// Note: there is a separate cache hash for builtin.zig, when adding fields, |
| ... | ... | @@ -2242,6 +2265,9 @@ struct CodeGen { |
| 2242 | 2265 | const ZigTarget *zig_target; |
| 2243 | 2266 | TargetSubsystem subsystem; // careful using this directly; see detect_subsystem |
| 2244 | 2267 | ValgrindSupport valgrind_support; |
| 2268 | CodeModel code_model; | |
| 2269 | OptionalBool linker_gc_sections; | |
| 2270 | OptionalBool linker_allow_shlib_undefined; | |
| 2245 | 2271 | bool strip_debug_symbols; |
| 2246 | 2272 | bool is_test_build; |
| 2247 | 2273 | bool is_single_threaded; |
| ... | ... | @@ -2262,9 +2288,8 @@ struct CodeGen { |
| 2262 | 2288 | bool emit_asm; |
| 2263 | 2289 | bool emit_llvm_ir; |
| 2264 | 2290 | bool test_is_evented; |
| 2265 | bool cpp_rtti; | |
| 2266 | bool cpp_exceptions; | |
| 2267 | CodeModel code_model; | |
| 2291 | bool linker_z_nodelete; | |
| 2292 | bool linker_z_defs; | |
| 2268 | 2293 | |
| 2269 | 2294 | Buf *root_out_name; |
| 2270 | 2295 | Buf *test_filter; |
| ... | ... | @@ -2273,6 +2298,7 @@ struct CodeGen { |
| 2273 | 2298 | Buf *zig_std_dir; |
| 2274 | 2299 | Buf *version_script_path; |
| 2275 | 2300 | Buf *override_soname; |
| 2301 | Buf *linker_optimization; | |
| 2276 | 2302 | |
| 2277 | 2303 | const char **llvm_argv; |
| 2278 | 2304 | size_t llvm_argv_len; |
src/analyze.cpp+7-4| ... | ... | @@ -363,6 +363,7 @@ bool type_is_resolved(ZigType *type_entry, ResolveStatus status) { |
| 363 | 363 | case ResolveStatusLLVMFull: |
| 364 | 364 | return type_entry->llvm_type != nullptr; |
| 365 | 365 | } |
| 366 | zig_unreachable(); | |
| 366 | 367 | case ZigTypeIdOpaque: |
| 367 | 368 | return status < ResolveStatusSizeKnown; |
| 368 | 369 | case ZigTypeIdPointer: |
| ... | ... | @@ -381,6 +382,7 @@ bool type_is_resolved(ZigType *type_entry, ResolveStatus status) { |
| 381 | 382 | case ResolveStatusLLVMFull: |
| 382 | 383 | return type_entry->llvm_type != nullptr; |
| 383 | 384 | } |
| 385 | zig_unreachable(); | |
| 384 | 386 | case ZigTypeIdMetaType: |
| 385 | 387 | case ZigTypeIdVoid: |
| 386 | 388 | case ZigTypeIdBool: |
| ... | ... | @@ -5156,6 +5158,7 @@ ZigType *get_vector_type(CodeGen *g, uint32_t len, ZigType *elem_type) { |
| 5156 | 5158 | } |
| 5157 | 5159 | entry->data.vector.len = len; |
| 5158 | 5160 | entry->data.vector.elem_type = elem_type; |
| 5161 | entry->data.vector.padding = 0; | |
| 5159 | 5162 | |
| 5160 | 5163 | buf_resize(&entry->name, 0); |
| 5161 | 5164 | buf_appendf(&entry->name, "@Vector(%u, %s)", len, buf_ptr(&elem_type->name)); |
| ... | ... | @@ -5358,7 +5361,7 @@ static uint32_t hash_const_val(ZigValue *const_val) { |
| 5358 | 5361 | return result; |
| 5359 | 5362 | } |
| 5360 | 5363 | case ZigTypeIdEnumLiteral: |
| 5361 | return buf_hash(const_val->data.x_enum_literal) * 2691276464; | |
| 5364 | return buf_hash(const_val->data.x_enum_literal) * (uint32_t)2691276464; | |
| 5362 | 5365 | case ZigTypeIdEnum: |
| 5363 | 5366 | { |
| 5364 | 5367 | uint32_t result = 31643936; |
| ... | ... | @@ -5426,12 +5429,12 @@ static uint32_t hash_const_val(ZigValue *const_val) { |
| 5426 | 5429 | return 2709806591; |
| 5427 | 5430 | case ZigTypeIdOptional: |
| 5428 | 5431 | if (get_src_ptr_type(const_val->type) != nullptr) { |
| 5429 | return hash_const_val_ptr(const_val) * 1992916303; | |
| 5432 | return hash_const_val_ptr(const_val) * (uint32_t)1992916303; | |
| 5430 | 5433 | } else if (const_val->type->data.maybe.child_type->id == ZigTypeIdErrorSet) { |
| 5431 | return hash_const_val_error_set(const_val) * 3147031929; | |
| 5434 | return hash_const_val_error_set(const_val) * (uint32_t)3147031929; | |
| 5432 | 5435 | } else { |
| 5433 | 5436 | if (const_val->data.x_optional) { |
| 5434 | return hash_const_val(const_val->data.x_optional) * 1992916303; | |
| 5437 | return hash_const_val(const_val->data.x_optional) * (uint32_t)1992916303; | |
| 5435 | 5438 | } else { |
| 5436 | 5439 | return 4016830364; |
| 5437 | 5440 | } |
src/analyze.hpp+1-7| ... | ... | @@ -257,14 +257,8 @@ Error create_c_object_cache(CodeGen *g, CacheHash **out_cache_hash, bool verbose |
| 257 | 257 | LLVMTypeRef get_llvm_type(CodeGen *g, ZigType *type); |
| 258 | 258 | ZigLLVMDIType *get_llvm_di_type(CodeGen *g, ZigType *type); |
| 259 | 259 | |
| 260 | enum CSourceKind { | |
| 261 | CSourceKindAsm, | |
| 262 | CSourceKindC, | |
| 263 | CSourceKindCpp, | |
| 264 | }; | |
| 265 | ||
| 266 | 260 | void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_path, bool translate_c, |
| 267 | CSourceKind source_kind); | |
| 261 | FileExt source_kind); | |
| 268 | 262 | |
| 269 | 263 | void src_assert(bool ok, AstNode *source_node); |
| 270 | 264 | bool is_container(ZigType *type_entry); |
src/bigint.cpp+1-1| ... | ... | @@ -1430,7 +1430,7 @@ void bigint_shr(BigInt *dest, const BigInt *op1, const BigInt *op2) { |
| 1430 | 1430 | uint64_t digit = op1_digits[op_digit_index]; |
| 1431 | 1431 | size_t dest_digit_index = op_digit_index - digit_shift_count; |
| 1432 | 1432 | digits[dest_digit_index] = carry | (digit >> leftover_shift_count); |
| 1433 | carry = digit << (64 - leftover_shift_count); | |
| 1433 | carry = (leftover_shift_count != 0) ? (digit << (64 - leftover_shift_count)) : 0; | |
| 1434 | 1434 | |
| 1435 | 1435 | if (dest_digit_index == 0) { break; } |
| 1436 | 1436 | op_digit_index -= 1; |
src/buffer.hpp+1-4| ... | ... | @@ -178,10 +178,7 @@ static inline bool buf_starts_with_str(Buf *buf, const char *str) { |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | static inline bool buf_ends_with_mem(Buf *buf, const char *mem, size_t mem_len) { |
| 181 | if (buf_len(buf) < mem_len) { | |
| 182 | return false; | |
| 183 | } | |
| 184 | return memcmp(buf_ptr(buf) + buf_len(buf) - mem_len, mem, mem_len) == 0; | |
| 181 | return mem_ends_with_mem(buf_ptr(buf), buf_len(buf), mem, mem_len); | |
| 185 | 182 | } |
| 186 | 183 | |
| 187 | 184 | static inline bool buf_ends_with_str(Buf *buf, const char *str) { |
src/cache_hash.cpp+7-1| ... | ... | @@ -27,11 +27,17 @@ void cache_init(CacheHash *ch, Buf *manifest_dir) { |
| 27 | 27 | void cache_mem(CacheHash *ch, const char *ptr, size_t len) { |
| 28 | 28 | assert(ch->manifest_file_path == nullptr); |
| 29 | 29 | assert(ptr != nullptr); |
| 30 | // + 1 to include the null byte | |
| 31 | 30 | blake2b_update(&ch->blake, ptr, len); |
| 32 | 31 | } |
| 33 | 32 | |
| 33 | void cache_slice(CacheHash *ch, Slice<const char> slice) { | |
| 34 | // mix the length into the hash so that two juxtaposed cached slices can't collide | |
| 35 | cache_usize(ch, slice.len); | |
| 36 | cache_mem(ch, slice.ptr, slice.len); | |
| 37 | } | |
| 38 | ||
| 34 | 39 | void cache_str(CacheHash *ch, const char *ptr) { |
| 40 | // + 1 to include the null byte | |
| 35 | 41 | cache_mem(ch, ptr, strlen(ptr) + 1); |
| 36 | 42 | } |
| 37 | 43 |
src/cache_hash.hpp+1| ... | ... | @@ -36,6 +36,7 @@ void cache_init(CacheHash *ch, Buf *manifest_dir); |
| 36 | 36 | |
| 37 | 37 | // Next, use the hash population functions to add the initial parameters. |
| 38 | 38 | void cache_mem(CacheHash *ch, const char *ptr, size_t len); |
| 39 | void cache_slice(CacheHash *ch, Slice<const char> slice); | |
| 39 | 40 | void cache_str(CacheHash *ch, const char *ptr); |
| 40 | 41 | void cache_int(CacheHash *ch, int x); |
| 41 | 42 | void cache_bool(CacheHash *ch, bool x); |
src/codegen.cpp+82-89| ... | ... | @@ -714,7 +714,7 @@ static LLVMValueRef get_arithmetic_overflow_fn(CodeGen *g, ZigType *operand_type |
| 714 | 714 | }; |
| 715 | 715 | |
| 716 | 716 | if (operand_type->id == ZigTypeIdVector) { |
| 717 | sprintf(fn_name, "llvm.%s.with.overflow.v%" PRIu32 "i%" PRIu32, signed_str, | |
| 717 | sprintf(fn_name, "llvm.%s.with.overflow.v%" PRIu64 "i%" PRIu32, signed_str, | |
| 718 | 718 | operand_type->data.vector.len, int_type->data.integral.bit_count); |
| 719 | 719 | |
| 720 | 720 | LLVMTypeRef return_elem_types[] = { |
| ... | ... | @@ -3954,8 +3954,9 @@ static void render_async_var_decls(CodeGen *g, Scope *scope) { |
| 3954 | 3954 | if (var->did_the_decl_codegen) { |
| 3955 | 3955 | render_decl_var(g, var); |
| 3956 | 3956 | } |
| 3957 | // fallthrough | |
| 3958 | 3957 | } |
| 3958 | ZIG_FALLTHROUGH; | |
| 3959 | ||
| 3959 | 3960 | case ScopeIdDecls: |
| 3960 | 3961 | case ScopeIdBlock: |
| 3961 | 3962 | case ScopeIdDefer: |
| ... | ... | @@ -8784,8 +8785,6 @@ static Error define_builtin_compile_vars(CodeGen *g) { |
| 8784 | 8785 | cache_bool(&cache_hash, g->is_test_build); |
| 8785 | 8786 | cache_bool(&cache_hash, g->is_single_threaded); |
| 8786 | 8787 | cache_bool(&cache_hash, g->test_is_evented); |
| 8787 | cache_bool(&cache_hash, g->cpp_rtti); | |
| 8788 | cache_bool(&cache_hash, g->cpp_exceptions); | |
| 8789 | 8788 | cache_int(&cache_hash, g->code_model); |
| 8790 | 8789 | cache_int(&cache_hash, g->zig_target->is_native_os); |
| 8791 | 8790 | cache_int(&cache_hash, g->zig_target->is_native_cpu); |
| ... | ... | @@ -9125,21 +9124,29 @@ static void detect_libc(CodeGen *g) { |
| 9125 | 9124 | g->libc_include_dir_len = 0; |
| 9126 | 9125 | g->libc_include_dir_list = heap::c_allocator.allocate<const char *>(dir_count); |
| 9127 | 9126 | |
| 9128 | g->libc_include_dir_list[g->libc_include_dir_len] = g->libc->include_dir; | |
| 9127 | g->libc_include_dir_list[g->libc_include_dir_len] = buf_ptr(buf_create_from_mem( | |
| 9128 | g->libc->include_dir, g->libc->include_dir_len)); | |
| 9129 | 9129 | g->libc_include_dir_len += 1; |
| 9130 | 9130 | |
| 9131 | 9131 | if (want_sys_dir) { |
| 9132 | g->libc_include_dir_list[g->libc_include_dir_len] = g->libc->sys_include_dir; | |
| 9132 | g->libc_include_dir_list[g->libc_include_dir_len] = buf_ptr(buf_create_from_mem( | |
| 9133 | g->libc->sys_include_dir, g->libc->sys_include_dir_len)); | |
| 9133 | 9134 | g->libc_include_dir_len += 1; |
| 9134 | 9135 | } |
| 9135 | 9136 | |
| 9136 | 9137 | if (want_um_and_shared_dirs != 0) { |
| 9137 | g->libc_include_dir_list[g->libc_include_dir_len] = buf_ptr(buf_sprintf( | |
| 9138 | "%s" OS_SEP ".." OS_SEP "um", g->libc->include_dir)); | |
| 9138 | Buf *include_dir_parent = buf_alloc(); | |
| 9139 | os_path_join(buf_create_from_mem(g->libc->include_dir, g->libc->include_dir_len), | |
| 9140 | buf_create_from_str(".."), include_dir_parent); | |
| 9141 | ||
| 9142 | Buf *buff1 = buf_alloc(); | |
| 9143 | os_path_join(include_dir_parent, buf_create_from_str("um"), buff1); | |
| 9144 | g->libc_include_dir_list[g->libc_include_dir_len] = buf_ptr(buff1); | |
| 9139 | 9145 | g->libc_include_dir_len += 1; |
| 9140 | 9146 | |
| 9141 | g->libc_include_dir_list[g->libc_include_dir_len] = buf_ptr(buf_sprintf( | |
| 9142 | "%s" OS_SEP ".." OS_SEP "shared", g->libc->include_dir)); | |
| 9147 | Buf *buff2 = buf_alloc(); | |
| 9148 | os_path_join(include_dir_parent, buf_create_from_str("shared"), buff2); | |
| 9149 | g->libc_include_dir_list[g->libc_include_dir_len] = buf_ptr(buff2); | |
| 9143 | 9150 | g->libc_include_dir_len += 1; |
| 9144 | 9151 | } |
| 9145 | 9152 | assert(g->libc_include_dir_len == dir_count); |
| ... | ... | @@ -9163,20 +9170,13 @@ static void detect_libc(CodeGen *g) { |
| 9163 | 9170 | |
| 9164 | 9171 | // does not add the "cc" arg |
| 9165 | 9172 | void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_path, |
| 9166 | bool translate_c, CSourceKind source_kind) | |
| 9173 | bool translate_c, FileExt source_kind) | |
| 9167 | 9174 | { |
| 9168 | 9175 | if (translate_c) { |
| 9169 | 9176 | args.append("-x"); |
| 9170 | 9177 | args.append("c"); |
| 9171 | 9178 | } |
| 9172 | 9179 | |
| 9173 | if (source_kind != CSourceKindAsm && out_dep_path != nullptr) { | |
| 9174 | args.append("-MD"); | |
| 9175 | args.append("-MV"); | |
| 9176 | args.append("-MF"); | |
| 9177 | args.append(out_dep_path); | |
| 9178 | } | |
| 9179 | ||
| 9180 | 9180 | args.append("-nostdinc"); |
| 9181 | 9181 | args.append("-fno-spell-checking"); |
| 9182 | 9182 | |
| ... | ... | @@ -9184,14 +9184,7 @@ void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_pa |
| 9184 | 9184 | args.append("-ffunction-sections"); |
| 9185 | 9185 | } |
| 9186 | 9186 | |
| 9187 | if (translate_c) { | |
| 9188 | if (source_kind != CSourceKindAsm) { | |
| 9189 | // this gives us access to preprocessing entities, presumably at | |
| 9190 | // the cost of performance | |
| 9191 | args.append("-Xclang"); | |
| 9192 | args.append("-detailed-preprocessing-record"); | |
| 9193 | } | |
| 9194 | } else { | |
| 9187 | if (!translate_c) { | |
| 9195 | 9188 | switch (g->err_color) { |
| 9196 | 9189 | case ErrColorAuto: |
| 9197 | 9190 | break; |
| ... | ... | @@ -9225,24 +9218,25 @@ void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_pa |
| 9225 | 9218 | args.append("-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS"); |
| 9226 | 9219 | } |
| 9227 | 9220 | |
| 9228 | // According to Rich Felker libc headers are supposed to go before C language headers. | |
| 9229 | // However as noted by @dimenus, appending libc headers before c_headers breaks intrinsics | |
| 9230 | // and other compiler specific items. | |
| 9231 | args.append("-isystem"); | |
| 9232 | args.append(buf_ptr(g->zig_c_headers_dir)); | |
| 9233 | ||
| 9234 | for (size_t i = 0; i < g->libc_include_dir_len; i += 1) { | |
| 9235 | const char *include_dir = g->libc_include_dir_list[i]; | |
| 9236 | args.append("-isystem"); | |
| 9237 | args.append(include_dir); | |
| 9238 | } | |
| 9239 | ||
| 9240 | 9221 | args.append("-target"); |
| 9241 | 9222 | args.append(buf_ptr(&g->llvm_triple_str)); |
| 9242 | 9223 | |
| 9243 | 9224 | switch (source_kind) { |
| 9244 | case CSourceKindC: | |
| 9245 | case CSourceKindCpp: | |
| 9225 | case FileExtC: | |
| 9226 | case FileExtCpp: | |
| 9227 | case FileExtHeader: | |
| 9228 | // According to Rich Felker libc headers are supposed to go before C language headers. | |
| 9229 | // However as noted by @dimenus, appending libc headers before c_headers breaks intrinsics | |
| 9230 | // and other compiler specific items. | |
| 9231 | args.append("-isystem"); | |
| 9232 | args.append(buf_ptr(g->zig_c_headers_dir)); | |
| 9233 | ||
| 9234 | for (size_t i = 0; i < g->libc_include_dir_len; i += 1) { | |
| 9235 | const char *include_dir = g->libc_include_dir_list[i]; | |
| 9236 | args.append("-isystem"); | |
| 9237 | args.append(include_dir); | |
| 9238 | } | |
| 9239 | ||
| 9246 | 9240 | if (g->zig_target->llvm_cpu_name != nullptr) { |
| 9247 | 9241 | args.append("-Xclang"); |
| 9248 | 9242 | args.append("-target-cpu"); |
| ... | ... | @@ -9255,18 +9249,25 @@ void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_pa |
| 9255 | 9249 | args.append("-Xclang"); |
| 9256 | 9250 | args.append(g->zig_target->llvm_cpu_features); |
| 9257 | 9251 | } |
| 9252 | if (translate_c) { | |
| 9253 | // this gives us access to preprocessing entities, presumably at | |
| 9254 | // the cost of performance | |
| 9255 | args.append("-Xclang"); | |
| 9256 | args.append("-detailed-preprocessing-record"); | |
| 9257 | } | |
| 9258 | if (out_dep_path != nullptr) { | |
| 9259 | args.append("-MD"); | |
| 9260 | args.append("-MV"); | |
| 9261 | args.append("-MF"); | |
| 9262 | args.append(out_dep_path); | |
| 9263 | } | |
| 9258 | 9264 | break; |
| 9259 | case CSourceKindAsm: | |
| 9265 | case FileExtAsm: | |
| 9266 | case FileExtLLVMIr: | |
| 9267 | case FileExtLLVMBitCode: | |
| 9268 | case FileExtUnknown: | |
| 9260 | 9269 | break; |
| 9261 | 9270 | } |
| 9262 | if (source_kind == CSourceKindCpp) { | |
| 9263 | if (!g->cpp_rtti) { | |
| 9264 | args.append("-fno-rtti"); | |
| 9265 | } | |
| 9266 | if (!g->cpp_exceptions) { | |
| 9267 | args.append("-fno-exceptions"); | |
| 9268 | } | |
| 9269 | } | |
| 9270 | 9271 | for (size_t i = 0; i < g->zig_target->llvm_cpu_features_asm_len; i += 1) { |
| 9271 | 9272 | args.append(g->zig_target->llvm_cpu_features_asm_ptr[i]); |
| 9272 | 9273 | } |
| ... | ... | @@ -9414,7 +9415,7 @@ void codegen_translate_c(CodeGen *g, Buf *full_path) { |
| 9414 | 9415 | } |
| 9415 | 9416 | |
| 9416 | 9417 | ZigList<const char *> clang_argv = {0}; |
| 9417 | add_cc_args(g, clang_argv, out_dep_path_cstr, true, CSourceKindC); | |
| 9418 | add_cc_args(g, clang_argv, out_dep_path_cstr, true, FileExtC); | |
| 9418 | 9419 | |
| 9419 | 9420 | clang_argv.append(buf_ptr(full_path)); |
| 9420 | 9421 | |
| ... | ... | @@ -9714,8 +9715,6 @@ Error create_c_object_cache(CodeGen *g, CacheHash **out_cache_hash, bool verbose |
| 9714 | 9715 | cache_bool(cache_hash, g->have_sanitize_c); |
| 9715 | 9716 | cache_bool(cache_hash, want_valgrind_support(g)); |
| 9716 | 9717 | cache_bool(cache_hash, g->function_sections); |
| 9717 | cache_bool(cache_hash, g->cpp_rtti); | |
| 9718 | cache_bool(cache_hash, g->cpp_exceptions); | |
| 9719 | 9718 | cache_int(cache_hash, g->code_model); |
| 9720 | 9719 | |
| 9721 | 9720 | for (size_t arg_i = 0; arg_i < g->clang_argv_len; arg_i += 1) { |
| ... | ... | @@ -9754,15 +9753,6 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) { |
| 9754 | 9753 | Buf *c_source_basename = buf_alloc(); |
| 9755 | 9754 | os_path_split(c_source_file, nullptr, c_source_basename); |
| 9756 | 9755 | |
| 9757 | CSourceKind c_source_kind; | |
| 9758 | if (buf_ends_with_str(c_source_basename, ".s") || | |
| 9759 | buf_ends_with_str(c_source_basename, ".S")) | |
| 9760 | { | |
| 9761 | c_source_kind = CSourceKindAsm; | |
| 9762 | } else { | |
| 9763 | c_source_kind = CSourceKindC; | |
| 9764 | } | |
| 9765 | ||
| 9766 | 9756 | Stage2ProgressNode *child_prog_node = stage2_progress_start(g->sub_progress_node, buf_ptr(c_source_basename), |
| 9767 | 9757 | buf_len(c_source_basename), 0); |
| 9768 | 9758 | |
| ... | ... | @@ -9813,7 +9803,7 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) { |
| 9813 | 9803 | exit(1); |
| 9814 | 9804 | } |
| 9815 | 9805 | } |
| 9816 | bool is_cache_miss = (buf_len(&digest) == 0); | |
| 9806 | bool is_cache_miss = g->disable_c_depfile || (buf_len(&digest) == 0); | |
| 9817 | 9807 | if (is_cache_miss) { |
| 9818 | 9808 | // we can't know the digest until we do the C compiler invocation, so we |
| 9819 | 9809 | // need a tmp filename. |
| ... | ... | @@ -9828,14 +9818,14 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) { |
| 9828 | 9818 | args.append(buf_ptr(self_exe_path)); |
| 9829 | 9819 | args.append("clang"); |
| 9830 | 9820 | |
| 9831 | if (c_file->preprocessor_only_basename != nullptr) { | |
| 9832 | args.append("-E"); | |
| 9833 | } else { | |
| 9821 | if (c_file->preprocessor_only_basename == nullptr) { | |
| 9834 | 9822 | args.append("-c"); |
| 9835 | 9823 | } |
| 9836 | 9824 | |
| 9837 | Buf *out_dep_path = buf_sprintf("%s.d", buf_ptr(out_obj_path)); | |
| 9838 | add_cc_args(g, args, buf_ptr(out_dep_path), false, c_source_kind); | |
| 9825 | Buf *out_dep_path = g->disable_c_depfile ? nullptr : buf_sprintf("%s.d", buf_ptr(out_obj_path)); | |
| 9826 | const char *out_dep_path_cstr = (out_dep_path == nullptr) ? nullptr : buf_ptr(out_dep_path); | |
| 9827 | FileExt ext = classify_file_ext(buf_ptr(c_source_basename), buf_len(c_source_basename)); | |
| 9828 | add_cc_args(g, args, out_dep_path_cstr, false, ext); | |
| 9839 | 9829 | |
| 9840 | 9830 | args.append("-o"); |
| 9841 | 9831 | args.append(buf_ptr(out_obj_path)); |
| ... | ... | @@ -9856,22 +9846,24 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) { |
| 9856 | 9846 | exit(1); |
| 9857 | 9847 | } |
| 9858 | 9848 | |
| 9859 | // add the files depended on to the cache system | |
| 9860 | if ((err = cache_add_dep_file(cache_hash, out_dep_path, true))) { | |
| 9861 | // Don't treat the absence of the .d file as a fatal error, the | |
| 9862 | // compiler may not produce one eg. when compiling .s files | |
| 9849 | if (out_dep_path != nullptr) { | |
| 9850 | // add the files depended on to the cache system | |
| 9851 | if ((err = cache_add_dep_file(cache_hash, out_dep_path, true))) { | |
| 9852 | // Don't treat the absence of the .d file as a fatal error, the | |
| 9853 | // compiler may not produce one eg. when compiling .s files | |
| 9854 | if (err != ErrorFileNotFound) { | |
| 9855 | fprintf(stderr, "Failed to add C source dependencies to cache: %s\n", err_str(err)); | |
| 9856 | exit(1); | |
| 9857 | } | |
| 9858 | } | |
| 9863 | 9859 | if (err != ErrorFileNotFound) { |
| 9864 | fprintf(stderr, "Failed to add C source dependencies to cache: %s\n", err_str(err)); | |
| 9865 | exit(1); | |
| 9860 | os_delete_file(out_dep_path); | |
| 9866 | 9861 | } |
| 9867 | } | |
| 9868 | if (err != ErrorFileNotFound) { | |
| 9869 | os_delete_file(out_dep_path); | |
| 9870 | } | |
| 9871 | 9862 | |
| 9872 | if ((err = cache_final(cache_hash, &digest))) { | |
| 9873 | fprintf(stderr, "Unable to finalize cache hash: %s\n", err_str(err)); | |
| 9874 | exit(1); | |
| 9863 | if ((err = cache_final(cache_hash, &digest))) { | |
| 9864 | fprintf(stderr, "Unable to finalize cache hash: %s\n", err_str(err)); | |
| 9865 | exit(1); | |
| 9866 | } | |
| 9875 | 9867 | } |
| 9876 | 9868 | artifact_dir = buf_alloc(); |
| 9877 | 9869 | os_path_join(o_dir, &digest, artifact_dir); |
| ... | ... | @@ -10550,8 +10542,6 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) { |
| 10550 | 10542 | cache_bool(ch, g->emit_bin); |
| 10551 | 10543 | cache_bool(ch, g->emit_llvm_ir); |
| 10552 | 10544 | cache_bool(ch, g->emit_asm); |
| 10553 | cache_bool(ch, g->cpp_rtti); | |
| 10554 | cache_bool(ch, g->cpp_exceptions); | |
| 10555 | 10545 | cache_usize(ch, g->version_major); |
| 10556 | 10546 | cache_usize(ch, g->version_minor); |
| 10557 | 10547 | cache_usize(ch, g->version_patch); |
| ... | ... | @@ -10560,14 +10550,19 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) { |
| 10560 | 10550 | cache_list_of_str(ch, g->lib_dirs.items, g->lib_dirs.length); |
| 10561 | 10551 | cache_list_of_str(ch, g->framework_dirs.items, g->framework_dirs.length); |
| 10562 | 10552 | if (g->libc) { |
| 10563 | cache_str(ch, g->libc->include_dir); | |
| 10564 | cache_str(ch, g->libc->sys_include_dir); | |
| 10565 | cache_str(ch, g->libc->crt_dir); | |
| 10566 | cache_str(ch, g->libc->msvc_lib_dir); | |
| 10567 | cache_str(ch, g->libc->kernel32_lib_dir); | |
| 10553 | cache_slice(ch, Slice<const char>{g->libc->include_dir, g->libc->include_dir_len}); | |
| 10554 | cache_slice(ch, Slice<const char>{g->libc->sys_include_dir, g->libc->sys_include_dir_len}); | |
| 10555 | cache_slice(ch, Slice<const char>{g->libc->crt_dir, g->libc->crt_dir_len}); | |
| 10556 | cache_slice(ch, Slice<const char>{g->libc->msvc_lib_dir, g->libc->msvc_lib_dir_len}); | |
| 10557 | cache_slice(ch, Slice<const char>{g->libc->kernel32_lib_dir, g->libc->kernel32_lib_dir_len}); | |
| 10568 | 10558 | } |
| 10569 | 10559 | cache_buf_opt(ch, g->version_script_path); |
| 10570 | 10560 | cache_buf_opt(ch, g->override_soname); |
| 10561 | cache_buf_opt(ch, g->linker_optimization); | |
| 10562 | cache_int(ch, g->linker_gc_sections); | |
| 10563 | cache_int(ch, g->linker_allow_shlib_undefined); | |
| 10564 | cache_bool(ch, g->linker_z_nodelete); | |
| 10565 | cache_bool(ch, g->linker_z_defs); | |
| 10571 | 10566 | |
| 10572 | 10567 | // gen_c_objects appends objects to g->link_objects which we want to include in the hash |
| 10573 | 10568 | gen_c_objects(g); |
| ... | ... | @@ -10856,8 +10851,6 @@ CodeGen *create_child_codegen(CodeGen *parent_gen, Buf *root_src_path, OutType o |
| 10856 | 10851 | parent_gen->build_mode, parent_gen->zig_lib_dir, libc, get_global_cache_dir(), false, child_progress_node); |
| 10857 | 10852 | child_gen->root_out_name = buf_create_from_str(name); |
| 10858 | 10853 | child_gen->disable_gen_h = true; |
| 10859 | child_gen->cpp_rtti = parent_gen->cpp_rtti; | |
| 10860 | child_gen->cpp_exceptions = parent_gen->cpp_exceptions; | |
| 10861 | 10854 | child_gen->want_stack_check = WantStackCheckDisabled; |
| 10862 | 10855 | child_gen->want_sanitize_c = WantCSanitizeDisabled; |
| 10863 | 10856 | child_gen->verbose_tokenize = parent_gen->verbose_tokenize; |
src/compiler.cpp+22| ... | ... | @@ -164,3 +164,25 @@ Buf *get_global_cache_dir(void) { |
| 164 | 164 | buf_deinit(&app_data_dir); |
| 165 | 165 | return &saved_global_cache_dir; |
| 166 | 166 | } |
| 167 | ||
| 168 | FileExt classify_file_ext(const char *filename_ptr, size_t filename_len) { | |
| 169 | if (mem_ends_with_str(filename_ptr, filename_len, ".c")) { | |
| 170 | return FileExtC; | |
| 171 | } else if (mem_ends_with_str(filename_ptr, filename_len, ".C") || | |
| 172 | mem_ends_with_str(filename_ptr, filename_len, ".cc") || | |
| 173 | mem_ends_with_str(filename_ptr, filename_len, ".cpp") || | |
| 174 | mem_ends_with_str(filename_ptr, filename_len, ".cxx")) | |
| 175 | { | |
| 176 | return FileExtCpp; | |
| 177 | } else if (mem_ends_with_str(filename_ptr, filename_len, ".ll")) { | |
| 178 | return FileExtLLVMIr; | |
| 179 | } else if (mem_ends_with_str(filename_ptr, filename_len, ".bc")) { | |
| 180 | return FileExtLLVMBitCode; | |
| 181 | } else if (mem_ends_with_str(filename_ptr, filename_len, ".s") || | |
| 182 | mem_ends_with_str(filename_ptr, filename_len, ".S")) | |
| 183 | { | |
| 184 | return FileExtAsm; | |
| 185 | } | |
| 186 | // TODO look for .so, .so.X, .so.X.Y, .so.X.Y.Z | |
| 187 | return FileExtUnknown; | |
| 188 | } |
src/compiler.hpp+4-2| ... | ... | @@ -8,8 +8,7 @@ |
| 8 | 8 | #ifndef ZIG_COMPILER_HPP |
| 9 | 9 | #define ZIG_COMPILER_HPP |
| 10 | 10 | |
| 11 | #include "buffer.hpp" | |
| 12 | #include "error.hpp" | |
| 11 | #include "all_types.hpp" | |
| 13 | 12 | |
| 14 | 13 | Error get_compiler_id(Buf **result); |
| 15 | 14 | |
| ... | ... | @@ -19,4 +18,7 @@ Buf *get_zig_std_dir(Buf *zig_lib_dir); |
| 19 | 18 | |
| 20 | 19 | Buf *get_global_cache_dir(void); |
| 21 | 20 | |
| 21 | ||
| 22 | FileExt classify_file_ext(const char *filename_ptr, size_t filename_len); | |
| 23 | ||
| 22 | 24 | #endif |
src/dump_analysis.cpp+2-2| ... | ... | @@ -80,7 +80,7 @@ static void jw_array_elem(JsonWriter *jw) { |
| 80 | 80 | zig_unreachable(); |
| 81 | 81 | case JsonWriterStateArray: |
| 82 | 82 | fprintf(jw->f, ","); |
| 83 | // fallthrough | |
| 83 | ZIG_FALLTHROUGH; | |
| 84 | 84 | case JsonWriterStateArrayStart: |
| 85 | 85 | jw->state[jw->state_index] = JsonWriterStateArray; |
| 86 | 86 | jw_push_state(jw, JsonWriterStateValue); |
| ... | ... | @@ -134,7 +134,7 @@ static void jw_object_field(JsonWriter *jw, const char *name) { |
| 134 | 134 | zig_unreachable(); |
| 135 | 135 | case JsonWriterStateObject: |
| 136 | 136 | fprintf(jw->f, ","); |
| 137 | // fallthrough | |
| 137 | ZIG_FALLTHROUGH; | |
| 138 | 138 | case JsonWriterStateObjectStart: |
| 139 | 139 | jw->state[jw->state_index] = JsonWriterStateObject; |
| 140 | 140 | jw_push_state(jw, JsonWriterStateValue); |
src/ir.cpp+73-32| ... | ... | @@ -231,6 +231,7 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op); |
| 231 | 231 | static IrInstSrc *ir_lval_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *value, LVal lval, ResultLoc *result_loc); |
| 232 | 232 | static IrInstSrc *ir_expr_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *inst, ResultLoc *result_loc); |
| 233 | 233 | static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align); |
| 234 | static ZigType *adjust_ptr_const(CodeGen *g, ZigType *ptr_type, bool is_const); | |
| 234 | 235 | static ZigType *adjust_slice_align(CodeGen *g, ZigType *slice_type, uint32_t new_align); |
| 235 | 236 | static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, uint8_t *buf, ZigValue *val); |
| 236 | 237 | static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ZigValue *val); |
| ... | ... | @@ -11453,10 +11454,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted |
| 11453 | 11454 | bool actual_allows_zero = ptr_allows_addr_zero(actual_type); |
| 11454 | 11455 | bool wanted_is_c_ptr = wanted_type->id == ZigTypeIdPointer && wanted_type->data.pointer.ptr_len == PtrLenC; |
| 11455 | 11456 | bool actual_is_c_ptr = actual_type->id == ZigTypeIdPointer && actual_type->data.pointer.ptr_len == PtrLenC; |
| 11456 | bool wanted_opt_or_ptr = wanted_ptr_type != nullptr && | |
| 11457 | (wanted_type->id == ZigTypeIdPointer || wanted_type->id == ZigTypeIdOptional); | |
| 11458 | bool actual_opt_or_ptr = actual_ptr_type != nullptr && | |
| 11459 | (actual_type->id == ZigTypeIdPointer || actual_type->id == ZigTypeIdOptional); | |
| 11457 | bool wanted_opt_or_ptr = wanted_ptr_type != nullptr && wanted_ptr_type->id == ZigTypeIdPointer; | |
| 11458 | bool actual_opt_or_ptr = actual_ptr_type != nullptr && actual_ptr_type->id == ZigTypeIdPointer; | |
| 11460 | 11459 | if (wanted_opt_or_ptr && actual_opt_or_ptr) { |
| 11461 | 11460 | bool ok_null_term_ptrs = |
| 11462 | 11461 | wanted_ptr_type->data.pointer.sentinel == nullptr || |
| ... | ... | @@ -11844,6 +11843,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 11844 | 11843 | |
| 11845 | 11844 | bool any_are_null = (prev_inst->value->type->id == ZigTypeIdNull); |
| 11846 | 11845 | bool convert_to_const_slice = false; |
| 11846 | bool make_the_slice_const = false; | |
| 11847 | 11847 | for (; i < instruction_count; i += 1) { |
| 11848 | 11848 | IrInstGen *cur_inst = instructions[i]; |
| 11849 | 11849 | ZigType *cur_type = cur_inst->value->type; |
| ... | ... | @@ -12357,12 +12357,12 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 12357 | 12357 | ZigType *slice_type = (prev_type->id == ZigTypeIdErrorUnion) ? |
| 12358 | 12358 | prev_type->data.error_union.payload_type : prev_type; |
| 12359 | 12359 | ZigType *slice_ptr_type = slice_type->data.structure.fields[slice_ptr_index]->type_entry; |
| 12360 | if ((slice_ptr_type->data.pointer.is_const || array_type->data.array.len == 0 || | |
| 12361 | !cur_type->data.pointer.is_const) && | |
| 12362 | types_match_const_cast_only(ira, | |
| 12363 | slice_ptr_type->data.pointer.child_type, | |
| 12360 | if (types_match_const_cast_only(ira, slice_ptr_type->data.pointer.child_type, | |
| 12364 | 12361 | array_type->data.array.child_type, source_node, false).id == ConstCastResultIdOk) |
| 12365 | 12362 | { |
| 12363 | bool const_ok = (slice_ptr_type->data.pointer.is_const || array_type->data.array.len == 0 || | |
| 12364 | !cur_type->data.pointer.is_const); | |
| 12365 | if (!const_ok) make_the_slice_const = true; | |
| 12366 | 12366 | convert_to_const_slice = false; |
| 12367 | 12367 | continue; |
| 12368 | 12368 | } |
| ... | ... | @@ -12391,12 +12391,12 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 12391 | 12391 | break; |
| 12392 | 12392 | } |
| 12393 | 12393 | ZigType *slice_ptr_type = slice_type->data.structure.fields[slice_ptr_index]->type_entry; |
| 12394 | if ((slice_ptr_type->data.pointer.is_const || array_type->data.array.len == 0 || | |
| 12395 | !prev_type->data.pointer.is_const) && | |
| 12396 | types_match_const_cast_only(ira, | |
| 12397 | slice_ptr_type->data.pointer.child_type, | |
| 12394 | if (types_match_const_cast_only(ira, slice_ptr_type->data.pointer.child_type, | |
| 12398 | 12395 | array_type->data.array.child_type, source_node, false).id == ConstCastResultIdOk) |
| 12399 | 12396 | { |
| 12397 | bool const_ok = (slice_ptr_type->data.pointer.is_const || array_type->data.array.len == 0 || | |
| 12398 | !prev_type->data.pointer.is_const); | |
| 12399 | if (!const_ok) make_the_slice_const = true; | |
| 12400 | 12400 | prev_inst = cur_inst; |
| 12401 | 12401 | convert_to_const_slice = false; |
| 12402 | 12402 | continue; |
| ... | ... | @@ -12408,8 +12408,6 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 12408 | 12408 | cur_type->data.pointer.child_type->id == ZigTypeIdArray && |
| 12409 | 12409 | prev_type->id == ZigTypeIdPointer && prev_type->data.pointer.ptr_len == PtrLenSingle && |
| 12410 | 12410 | prev_type->data.pointer.child_type->id == ZigTypeIdArray && |
| 12411 | (cur_type->data.pointer.is_const || !prev_type->data.pointer.is_const || | |
| 12412 | prev_type->data.pointer.child_type->data.array.len == 0) && | |
| 12413 | 12411 | ( |
| 12414 | 12412 | prev_type->data.pointer.child_type->data.array.sentinel == nullptr || |
| 12415 | 12413 | (cur_type->data.pointer.child_type->data.array.sentinel != nullptr && |
| ... | ... | @@ -12421,6 +12419,9 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 12421 | 12419 | prev_type->data.pointer.child_type->data.array.child_type, |
| 12422 | 12420 | source_node, !cur_type->data.pointer.is_const).id == ConstCastResultIdOk) |
| 12423 | 12421 | { |
| 12422 | bool const_ok = (cur_type->data.pointer.is_const || !prev_type->data.pointer.is_const || | |
| 12423 | prev_type->data.pointer.child_type->data.array.len == 0); | |
| 12424 | if (!const_ok) make_the_slice_const = true; | |
| 12424 | 12425 | prev_inst = cur_inst; |
| 12425 | 12426 | convert_to_const_slice = true; |
| 12426 | 12427 | continue; |
| ... | ... | @@ -12429,8 +12430,6 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 12429 | 12430 | prev_type->data.pointer.child_type->id == ZigTypeIdArray && |
| 12430 | 12431 | cur_type->id == ZigTypeIdPointer && cur_type->data.pointer.ptr_len == PtrLenSingle && |
| 12431 | 12432 | cur_type->data.pointer.child_type->id == ZigTypeIdArray && |
| 12432 | (prev_type->data.pointer.is_const || !cur_type->data.pointer.is_const || | |
| 12433 | cur_type->data.pointer.child_type->data.array.len == 0) && | |
| 12434 | 12433 | ( |
| 12435 | 12434 | cur_type->data.pointer.child_type->data.array.sentinel == nullptr || |
| 12436 | 12435 | (prev_type->data.pointer.child_type->data.array.sentinel != nullptr && |
| ... | ... | @@ -12442,6 +12441,9 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 12442 | 12441 | cur_type->data.pointer.child_type->data.array.child_type, |
| 12443 | 12442 | source_node, !prev_type->data.pointer.is_const).id == ConstCastResultIdOk) |
| 12444 | 12443 | { |
| 12444 | bool const_ok = (prev_type->data.pointer.is_const || !cur_type->data.pointer.is_const || | |
| 12445 | cur_type->data.pointer.child_type->data.array.len == 0); | |
| 12446 | if (!const_ok) make_the_slice_const = true; | |
| 12445 | 12447 | convert_to_const_slice = true; |
| 12446 | 12448 | continue; |
| 12447 | 12449 | } |
| ... | ... | @@ -12486,7 +12488,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 12486 | 12488 | src_assert(array_type->id == ZigTypeIdArray, source_node); |
| 12487 | 12489 | ZigType *ptr_type = get_pointer_to_type_extra2( |
| 12488 | 12490 | ira->codegen, array_type->data.array.child_type, |
| 12489 | prev_inst->value->type->data.pointer.is_const, false, | |
| 12491 | prev_inst->value->type->data.pointer.is_const || make_the_slice_const, false, | |
| 12490 | 12492 | PtrLenUnknown, |
| 12491 | 12493 | 0, 0, 0, false, |
| 12492 | 12494 | VECTOR_INDEX_NONE, nullptr, array_type->data.array.sentinel); |
| ... | ... | @@ -12537,6 +12539,26 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 12537 | 12539 | return ira->codegen->builtin_types.entry_invalid; |
| 12538 | 12540 | return get_optional_type(ira->codegen, prev_inst->value->type); |
| 12539 | 12541 | } |
| 12542 | } else if (make_the_slice_const) { | |
| 12543 | ZigType *slice_type; | |
| 12544 | if (prev_inst->value->type->id == ZigTypeIdErrorUnion) { | |
| 12545 | slice_type = prev_inst->value->type->data.error_union.payload_type; | |
| 12546 | } else if (is_slice(prev_inst->value->type)) { | |
| 12547 | slice_type = prev_inst->value->type; | |
| 12548 | } else { | |
| 12549 | zig_unreachable(); | |
| 12550 | } | |
| 12551 | ZigType *slice_ptr_type = slice_type->data.structure.fields[slice_ptr_index]->type_entry; | |
| 12552 | ZigType *adjusted_ptr_type = adjust_ptr_const(ira->codegen, slice_ptr_type, make_the_slice_const); | |
| 12553 | ZigType *adjusted_slice_type = get_slice_type(ira->codegen, adjusted_ptr_type); | |
| 12554 | if (prev_inst->value->type->id == ZigTypeIdErrorUnion) { | |
| 12555 | return get_error_union_type(ira->codegen, prev_inst->value->type->data.error_union.err_set_type, | |
| 12556 | adjusted_slice_type); | |
| 12557 | } else if (is_slice(prev_inst->value->type)) { | |
| 12558 | return adjusted_slice_type; | |
| 12559 | } else { | |
| 12560 | zig_unreachable(); | |
| 12561 | } | |
| 12540 | 12562 | } else { |
| 12541 | 12563 | return prev_inst->value->type; |
| 12542 | 12564 | } |
| ... | ... | @@ -15929,7 +15951,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i |
| 15929 | 15951 | if (op1->value->type->id == ZigTypeIdVector && op2->value->type->id == ZigTypeIdVector) { |
| 15930 | 15952 | if (op1->value->type->data.vector.len != op2->value->type->data.vector.len) { |
| 15931 | 15953 | ir_add_error(ira, source_instr, |
| 15932 | buf_sprintf("vector length mismatch: %" PRIu32 " and %" PRIu32, | |
| 15954 | buf_sprintf("vector length mismatch: %" PRIu64 " and %" PRIu64, | |
| 15933 | 15955 | op1->value->type->data.vector.len, op2->value->type->data.vector.len)); |
| 15934 | 15956 | return ira->codegen->invalid_inst_gen; |
| 15935 | 15957 | } |
| ... | ... | @@ -18958,7 +18980,7 @@ static IrInstGen *ir_analyze_async_call(IrAnalyze *ira, IrInst* source_instr, Zi |
| 18958 | 18980 | if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) { |
| 18959 | 18981 | return result_loc; |
| 18960 | 18982 | } |
| 18961 | result_loc = ir_implicit_cast2(ira, &call_result_loc->source_instruction->base, result_loc, | |
| 18983 | result_loc = ir_implicit_cast2(ira, source_instr, result_loc, | |
| 18962 | 18984 | get_pointer_to_type(ira->codegen, frame_type, false)); |
| 18963 | 18985 | if (type_is_invalid(result_loc->value->type)) |
| 18964 | 18986 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -19925,6 +19947,7 @@ static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr, |
| 19925 | 19947 | buf_sprintf("the specified modifier requires a comptime-known function")); |
| 19926 | 19948 | return ira->codegen->invalid_inst_gen; |
| 19927 | 19949 | } |
| 19950 | ZIG_FALLTHROUGH; | |
| 19928 | 19951 | default: |
| 19929 | 19952 | break; |
| 19930 | 19953 | } |
| ... | ... | @@ -19943,14 +19966,16 @@ static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr, |
| 19943 | 19966 | return ira->codegen->invalid_inst_gen; |
| 19944 | 19967 | |
| 19945 | 19968 | IrInstGen *stack = nullptr; |
| 19969 | IrInst *stack_src = nullptr; | |
| 19946 | 19970 | if (stack_is_non_null) { |
| 19947 | 19971 | stack = ir_analyze_optional_value_payload_value(ira, source_instr, opt_stack, false); |
| 19948 | 19972 | if (type_is_invalid(stack->value->type)) |
| 19949 | 19973 | return ira->codegen->invalid_inst_gen; |
| 19974 | stack_src = &stack->base; | |
| 19950 | 19975 | } |
| 19951 | 19976 | |
| 19952 | 19977 | return ir_analyze_fn_call(ira, source_instr, fn, fn_type, fn_ref, first_arg_ptr, first_arg_ptr_src, |
| 19953 | modifier, stack, &stack->base, false, args_ptr, args_len, nullptr, result_loc); | |
| 19978 | modifier, stack, stack_src, false, args_ptr, args_len, nullptr, result_loc); | |
| 19954 | 19979 | } |
| 19955 | 19980 | |
| 19956 | 19981 | static IrInstGen *ir_analyze_instruction_call_extra(IrAnalyze *ira, IrInstSrcCallExtra *instruction) { |
| ... | ... | @@ -20708,24 +20733,44 @@ static ZigType *adjust_slice_align(CodeGen *g, ZigType *slice_type, uint32_t new |
| 20708 | 20733 | |
| 20709 | 20734 | static ZigType *adjust_ptr_len(CodeGen *g, ZigType *ptr_type, PtrLen ptr_len) { |
| 20710 | 20735 | assert(ptr_type->id == ZigTypeIdPointer); |
| 20711 | return get_pointer_to_type_extra(g, | |
| 20736 | return get_pointer_to_type_extra2(g, | |
| 20712 | 20737 | ptr_type->data.pointer.child_type, |
| 20713 | 20738 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, |
| 20714 | 20739 | ptr_len, |
| 20715 | 20740 | ptr_type->data.pointer.explicit_alignment, |
| 20716 | 20741 | ptr_type->data.pointer.bit_offset_in_host, ptr_type->data.pointer.host_int_bytes, |
| 20717 | ptr_type->data.pointer.allow_zero); | |
| 20742 | ptr_type->data.pointer.allow_zero, | |
| 20743 | ptr_type->data.pointer.vector_index, | |
| 20744 | ptr_type->data.pointer.inferred_struct_field, | |
| 20745 | ptr_type->data.pointer.sentinel); | |
| 20718 | 20746 | } |
| 20719 | 20747 | |
| 20720 | 20748 | static ZigType *adjust_ptr_allow_zero(CodeGen *g, ZigType *ptr_type, bool allow_zero) { |
| 20721 | 20749 | assert(ptr_type->id == ZigTypeIdPointer); |
| 20722 | return get_pointer_to_type_extra(g, | |
| 20750 | return get_pointer_to_type_extra2(g, | |
| 20723 | 20751 | ptr_type->data.pointer.child_type, |
| 20724 | 20752 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, |
| 20725 | 20753 | ptr_type->data.pointer.ptr_len, |
| 20726 | 20754 | ptr_type->data.pointer.explicit_alignment, |
| 20727 | 20755 | ptr_type->data.pointer.bit_offset_in_host, ptr_type->data.pointer.host_int_bytes, |
| 20728 | allow_zero); | |
| 20756 | allow_zero, | |
| 20757 | ptr_type->data.pointer.vector_index, | |
| 20758 | ptr_type->data.pointer.inferred_struct_field, | |
| 20759 | ptr_type->data.pointer.sentinel); | |
| 20760 | } | |
| 20761 | ||
| 20762 | static ZigType *adjust_ptr_const(CodeGen *g, ZigType *ptr_type, bool is_const) { | |
| 20763 | assert(ptr_type->id == ZigTypeIdPointer); | |
| 20764 | return get_pointer_to_type_extra2(g, | |
| 20765 | ptr_type->data.pointer.child_type, | |
| 20766 | is_const, ptr_type->data.pointer.is_volatile, | |
| 20767 | ptr_type->data.pointer.ptr_len, | |
| 20768 | ptr_type->data.pointer.explicit_alignment, | |
| 20769 | ptr_type->data.pointer.bit_offset_in_host, ptr_type->data.pointer.host_int_bytes, | |
| 20770 | ptr_type->data.pointer.allow_zero, | |
| 20771 | ptr_type->data.pointer.vector_index, | |
| 20772 | ptr_type->data.pointer.inferred_struct_field, | |
| 20773 | ptr_type->data.pointer.sentinel); | |
| 20729 | 20774 | } |
| 20730 | 20775 | |
| 20731 | 20776 | static Error compute_elem_align(IrAnalyze *ira, ZigType *elem_type, uint32_t base_ptr_align, |
| ... | ... | @@ -20880,13 +20925,8 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP |
| 20880 | 20925 | if (instr_is_comptime(casted_elem_index)) { |
| 20881 | 20926 | uint64_t index = bigint_as_u64(&casted_elem_index->value->data.x_bigint); |
| 20882 | 20927 | if (array_type->id == ZigTypeIdArray) { |
| 20883 | uint64_t array_len = array_type->data.array.len; | |
| 20884 | if (index == array_len && array_type->data.array.sentinel != nullptr) { | |
| 20885 | ZigType *elem_type = array_type->data.array.child_type; | |
| 20886 | IrInstGen *sentinel_elem = ir_const(ira, &elem_ptr_instruction->base.base, elem_type); | |
| 20887 | copy_const_val(ira->codegen, sentinel_elem->value, array_type->data.array.sentinel); | |
| 20888 | return ir_get_ref(ira, &elem_ptr_instruction->base.base, sentinel_elem, true, false); | |
| 20889 | } | |
| 20928 | uint64_t array_len = array_type->data.array.len + | |
| 20929 | (array_type->data.array.sentinel != nullptr); | |
| 20890 | 20930 | if (index >= array_len) { |
| 20891 | 20931 | ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node, |
| 20892 | 20932 | buf_sprintf("index %" ZIG_PRI_u64 " outside array of size %" ZIG_PRI_u64, |
| ... | ... | @@ -25131,7 +25171,7 @@ static IrInstGen *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstSrcCImpo |
| 25131 | 25171 | |
| 25132 | 25172 | ZigList<const char *> clang_argv = {0}; |
| 25133 | 25173 | |
| 25134 | add_cc_args(ira->codegen, clang_argv, buf_ptr(tmp_dep_file), true, CSourceKindC); | |
| 25174 | add_cc_args(ira->codegen, clang_argv, buf_ptr(tmp_dep_file), true, FileExtC); | |
| 25135 | 25175 | |
| 25136 | 25176 | clang_argv.append(buf_ptr(&tmp_c_file_path)); |
| 25137 | 25177 | |
| ... | ... | @@ -28128,6 +28168,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ZigValue *val) |
| 28128 | 28168 | return; |
| 28129 | 28169 | } |
| 28130 | 28170 | } |
| 28171 | zig_unreachable(); | |
| 28131 | 28172 | case ZigTypeIdOptional: |
| 28132 | 28173 | zig_panic("TODO buf_write_value_bytes maybe type"); |
| 28133 | 28174 | case ZigTypeIdFn: |
src/link.cpp+103-22| ... | ... | @@ -651,6 +651,7 @@ static const char *build_libunwind(CodeGen *parent, Stage2ProgressNode *progress |
| 651 | 651 | if (parent->is_single_threaded) { |
| 652 | 652 | c_file->args.append("-D_LIBUNWIND_HAS_NO_THREADS"); |
| 653 | 653 | } |
| 654 | c_file->args.append("-Wno-bitwise-conditional-parentheses"); | |
| 654 | 655 | c_source_files.append(c_file); |
| 655 | 656 | } |
| 656 | 657 | child_gen->c_source_files = c_source_files; |
| ... | ... | @@ -1594,7 +1595,8 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2Pr |
| 1594 | 1595 | } else { |
| 1595 | 1596 | assert(parent->libc != nullptr); |
| 1596 | 1597 | Buf *out_buf = buf_alloc(); |
| 1597 | os_path_join(buf_create_from_str(parent->libc->crt_dir), buf_create_from_str(file), out_buf); | |
| 1598 | os_path_join(buf_create_from_mem(parent->libc->crt_dir, parent->libc->crt_dir_len), | |
| 1599 | buf_create_from_str(file), out_buf); | |
| 1598 | 1600 | return buf_ptr(out_buf); |
| 1599 | 1601 | } |
| 1600 | 1602 | } |
| ... | ... | @@ -1767,8 +1769,17 @@ static void construct_linker_job_elf(LinkJob *lj) { |
| 1767 | 1769 | lj->args.append(g->linker_script); |
| 1768 | 1770 | } |
| 1769 | 1771 | |
| 1770 | if (g->out_type != OutTypeObj) { | |
| 1771 | lj->args.append("--gc-sections"); | |
| 1772 | switch (g->linker_gc_sections) { | |
| 1773 | case OptionalBoolNull: | |
| 1774 | if (g->out_type != OutTypeObj) { | |
| 1775 | lj->args.append("--gc-sections"); | |
| 1776 | } | |
| 1777 | break; | |
| 1778 | case OptionalBoolTrue: | |
| 1779 | lj->args.append("--gc-sections"); | |
| 1780 | break; | |
| 1781 | case OptionalBoolFalse: | |
| 1782 | break; | |
| 1772 | 1783 | } |
| 1773 | 1784 | |
| 1774 | 1785 | if (g->link_eh_frame_hdr) { |
| ... | ... | @@ -1779,6 +1790,19 @@ static void construct_linker_job_elf(LinkJob *lj) { |
| 1779 | 1790 | lj->args.append("--export-dynamic"); |
| 1780 | 1791 | } |
| 1781 | 1792 | |
| 1793 | if (g->linker_optimization != nullptr) { | |
| 1794 | lj->args.append(buf_ptr(g->linker_optimization)); | |
| 1795 | } | |
| 1796 | ||
| 1797 | if (g->linker_z_nodelete) { | |
| 1798 | lj->args.append("-z"); | |
| 1799 | lj->args.append("nodelete"); | |
| 1800 | } | |
| 1801 | if (g->linker_z_defs) { | |
| 1802 | lj->args.append("-z"); | |
| 1803 | lj->args.append("defs"); | |
| 1804 | } | |
| 1805 | ||
| 1782 | 1806 | lj->args.append("-m"); |
| 1783 | 1807 | lj->args.append(getLDMOption(g->zig_target)); |
| 1784 | 1808 | |
| ... | ... | @@ -1859,7 +1883,7 @@ static void construct_linker_job_elf(LinkJob *lj) { |
| 1859 | 1883 | if (g->libc_link_lib != nullptr) { |
| 1860 | 1884 | if (g->libc != nullptr) { |
| 1861 | 1885 | lj->args.append("-L"); |
| 1862 | lj->args.append(g->libc->crt_dir); | |
| 1886 | lj->args.append(buf_ptr(buf_create_from_mem(g->libc->crt_dir, g->libc->crt_dir_len))); | |
| 1863 | 1887 | } |
| 1864 | 1888 | |
| 1865 | 1889 | if (g->have_dynamic_link && (is_dyn_lib || g->out_type == OutTypeExe)) { |
| ... | ... | @@ -1903,7 +1927,7 @@ static void construct_linker_job_elf(LinkJob *lj) { |
| 1903 | 1927 | // libc is linked specially |
| 1904 | 1928 | continue; |
| 1905 | 1929 | } |
| 1906 | if (buf_eql_str(link_lib->name, "c++") || buf_eql_str(link_lib->name, "c++abi")) { | |
| 1930 | if (target_is_libcpp_lib_name(g->zig_target, buf_ptr(link_lib->name))) { | |
| 1907 | 1931 | // libc++ is linked specially |
| 1908 | 1932 | continue; |
| 1909 | 1933 | } |
| ... | ... | @@ -1947,15 +1971,11 @@ static void construct_linker_job_elf(LinkJob *lj) { |
| 1947 | 1971 | lj->args.append("-lpthread"); |
| 1948 | 1972 | } |
| 1949 | 1973 | } else if (target_is_glibc(g->zig_target)) { |
| 1950 | if (target_supports_libunwind(g->zig_target)) { | |
| 1951 | lj->args.append(build_libunwind(g, lj->build_dep_prog_node)); | |
| 1952 | } | |
| 1974 | lj->args.append(build_libunwind(g, lj->build_dep_prog_node)); | |
| 1953 | 1975 | add_glibc_libs(lj); |
| 1954 | 1976 | lj->args.append(get_libc_crt_file(g, "libc_nonshared.a", lj->build_dep_prog_node)); |
| 1955 | 1977 | } else if (target_is_musl(g->zig_target)) { |
| 1956 | if (target_supports_libunwind(g->zig_target)) { | |
| 1957 | lj->args.append(build_libunwind(g, lj->build_dep_prog_node)); | |
| 1958 | } | |
| 1978 | lj->args.append(build_libunwind(g, lj->build_dep_prog_node)); | |
| 1959 | 1979 | lj->args.append(build_musl(g, lj->build_dep_prog_node)); |
| 1960 | 1980 | } else if (g->libcpp_link_lib != nullptr) { |
| 1961 | 1981 | lj->args.append(build_libunwind(g, lj->build_dep_prog_node)); |
| ... | ... | @@ -1973,8 +1993,17 @@ static void construct_linker_job_elf(LinkJob *lj) { |
| 1973 | 1993 | } |
| 1974 | 1994 | } |
| 1975 | 1995 | |
| 1976 | if (!g->zig_target->is_native_os) { | |
| 1977 | lj->args.append("--allow-shlib-undefined"); | |
| 1996 | switch (g->linker_allow_shlib_undefined) { | |
| 1997 | case OptionalBoolNull: | |
| 1998 | if (!g->zig_target->is_native_os) { | |
| 1999 | lj->args.append("--allow-shlib-undefined"); | |
| 2000 | } | |
| 2001 | break; | |
| 2002 | case OptionalBoolFalse: | |
| 2003 | break; | |
| 2004 | case OptionalBoolTrue: | |
| 2005 | lj->args.append("--allow-shlib-undefined"); | |
| 2006 | break; | |
| 1978 | 2007 | } |
| 1979 | 2008 | } |
| 1980 | 2009 | |
| ... | ... | @@ -2384,14 +2413,26 @@ static void construct_linker_job_coff(LinkJob *lj) { |
| 2384 | 2413 | lj->args.append(buf_ptr(buf_sprintf("-OUT:%s", buf_ptr(&g->bin_file_output_path)))); |
| 2385 | 2414 | |
| 2386 | 2415 | if (g->libc_link_lib != nullptr && g->libc != nullptr) { |
| 2387 | lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", g->libc->crt_dir))); | |
| 2416 | Buf *buff0 = buf_create_from_str("-LIBPATH:"); | |
| 2417 | buf_append_mem(buff0, g->libc->crt_dir, g->libc->crt_dir_len); | |
| 2418 | lj->args.append(buf_ptr(buff0)); | |
| 2388 | 2419 | |
| 2389 | 2420 | if (target_abi_is_gnu(g->zig_target->abi)) { |
| 2390 | lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", g->libc->sys_include_dir))); | |
| 2391 | lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", g->libc->include_dir))); | |
| 2421 | Buf *buff1 = buf_create_from_str("-LIBPATH:"); | |
| 2422 | buf_append_mem(buff1, g->libc->sys_include_dir, g->libc->sys_include_dir_len); | |
| 2423 | lj->args.append(buf_ptr(buff1)); | |
| 2424 | ||
| 2425 | Buf *buff2 = buf_create_from_str("-LIBPATH:"); | |
| 2426 | buf_append_mem(buff2, g->libc->include_dir, g->libc->include_dir_len); | |
| 2427 | lj->args.append(buf_ptr(buff2)); | |
| 2392 | 2428 | } else { |
| 2393 | lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", g->libc->msvc_lib_dir))); | |
| 2394 | lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", g->libc->kernel32_lib_dir))); | |
| 2429 | Buf *buff1 = buf_create_from_str("-LIBPATH:"); | |
| 2430 | buf_append_mem(buff1, g->libc->msvc_lib_dir, g->libc->msvc_lib_dir_len); | |
| 2431 | lj->args.append(buf_ptr(buff1)); | |
| 2432 | ||
| 2433 | Buf *buff2 = buf_create_from_str("-LIBPATH:"); | |
| 2434 | buf_append_mem(buff2, g->libc->kernel32_lib_dir, g->libc->kernel32_lib_dir_len); | |
| 2435 | lj->args.append(buf_ptr(buff2)); | |
| 2395 | 2436 | } |
| 2396 | 2437 | } |
| 2397 | 2438 | |
| ... | ... | @@ -2470,7 +2511,12 @@ static void construct_linker_job_coff(LinkJob *lj) { |
| 2470 | 2511 | if (buf_eql_str(link_lib->name, "c")) { |
| 2471 | 2512 | continue; |
| 2472 | 2513 | } |
| 2473 | if (buf_eql_str(link_lib->name, "c++") || buf_eql_str(link_lib->name, "c++abi")) { | |
| 2514 | if (target_is_libcpp_lib_name(g->zig_target, buf_ptr(link_lib->name))) { | |
| 2515 | // libc++ is linked specially | |
| 2516 | continue; | |
| 2517 | } | |
| 2518 | if (g->libc == nullptr && target_is_libc_lib_name(g->zig_target, buf_ptr(link_lib->name))) { | |
| 2519 | // these libraries are always linked below when targeting glibc | |
| 2474 | 2520 | continue; |
| 2475 | 2521 | } |
| 2476 | 2522 | bool is_sys_lib = is_mingw_link_lib(link_lib->name); |
| ... | ... | @@ -2521,10 +2567,34 @@ static void construct_linker_job_macho(LinkJob *lj) { |
| 2521 | 2567 | //lj->args.append("-error-limit=0"); |
| 2522 | 2568 | lj->args.append("-demangle"); |
| 2523 | 2569 | |
| 2570 | switch (g->linker_gc_sections) { | |
| 2571 | case OptionalBoolNull: | |
| 2572 | // TODO why do we not follow the same logic of elf here? | |
| 2573 | break; | |
| 2574 | case OptionalBoolTrue: | |
| 2575 | lj->args.append("--gc-sections"); | |
| 2576 | break; | |
| 2577 | case OptionalBoolFalse: | |
| 2578 | break; | |
| 2579 | } | |
| 2580 | ||
| 2524 | 2581 | if (g->linker_rdynamic) { |
| 2525 | 2582 | lj->args.append("-export_dynamic"); |
| 2526 | 2583 | } |
| 2527 | 2584 | |
| 2585 | if (g->linker_optimization != nullptr) { | |
| 2586 | lj->args.append(buf_ptr(g->linker_optimization)); | |
| 2587 | } | |
| 2588 | ||
| 2589 | if (g->linker_z_nodelete) { | |
| 2590 | lj->args.append("-z"); | |
| 2591 | lj->args.append("nodelete"); | |
| 2592 | } | |
| 2593 | if (g->linker_z_defs) { | |
| 2594 | lj->args.append("-z"); | |
| 2595 | lj->args.append("defs"); | |
| 2596 | } | |
| 2597 | ||
| 2528 | 2598 | bool is_lib = g->out_type == OutTypeLib; |
| 2529 | 2599 | bool is_dyn_lib = g->is_dynamic && is_lib; |
| 2530 | 2600 | if (is_lib && !g->is_dynamic) { |
| ... | ... | @@ -2639,9 +2709,20 @@ static void construct_linker_job_macho(LinkJob *lj) { |
| 2639 | 2709 | // and change between versions. |
| 2640 | 2710 | // so we always link against libSystem |
| 2641 | 2711 | lj->args.append("-lSystem"); |
| 2642 | } else { | |
| 2643 | lj->args.append("-undefined"); | |
| 2644 | lj->args.append("dynamic_lookup"); | |
| 2712 | } | |
| 2713 | switch (g->linker_allow_shlib_undefined) { | |
| 2714 | case OptionalBoolNull: | |
| 2715 | if (!g->zig_target->is_native_os) { | |
| 2716 | lj->args.append("-undefined"); | |
| 2717 | lj->args.append("dynamic_lookup"); | |
| 2718 | } | |
| 2719 | break; | |
| 2720 | case OptionalBoolFalse: | |
| 2721 | break; | |
| 2722 | case OptionalBoolTrue: | |
| 2723 | lj->args.append("-undefined"); | |
| 2724 | lj->args.append("dynamic_lookup"); | |
| 2725 | break; | |
| 2645 | 2726 | } |
| 2646 | 2727 | |
| 2647 | 2728 | for (size_t i = 0; i < g->framework_dirs.length; i += 1) { |
src/main.cpp+97-43| ... | ... | @@ -455,11 +455,15 @@ static int main0(int argc, char **argv) { |
| 455 | 455 | const char *mcpu = nullptr; |
| 456 | 456 | CodeModel code_model = CodeModelDefault; |
| 457 | 457 | const char *override_soname = nullptr; |
| 458 | bool only_preprocess = false; | |
| 458 | bool only_pp_or_asm = false; | |
| 459 | 459 | bool ensure_libc_on_non_freestanding = false; |
| 460 | 460 | bool ensure_libcpp_on_non_freestanding = false; |
| 461 | bool cpp_rtti = true; | |
| 462 | bool cpp_exceptions = true; | |
| 461 | bool disable_c_depfile = false; | |
| 462 | Buf *linker_optimization = nullptr; | |
| 463 | OptionalBool linker_gc_sections = OptionalBoolNull; | |
| 464 | OptionalBool linker_allow_shlib_undefined = OptionalBoolNull; | |
| 465 | bool linker_z_nodelete = false; | |
| 466 | bool linker_z_defs = false; | |
| 463 | 467 | |
| 464 | 468 | ZigList<const char *> llvm_argv = {0}; |
| 465 | 469 | llvm_argv.append("zig (LLVM option parsing)"); |
| ... | ... | @@ -617,20 +621,22 @@ static int main0(int argc, char **argv) { |
| 617 | 621 | } |
| 618 | 622 | break; |
| 619 | 623 | case Stage2ClangArgPositional: { |
| 620 | Buf *arg_buf = buf_create_from_str(it.only_arg); | |
| 621 | if (buf_ends_with_str(arg_buf, ".c") || | |
| 622 | buf_ends_with_str(arg_buf, ".C") || | |
| 623 | buf_ends_with_str(arg_buf, ".cc") || | |
| 624 | buf_ends_with_str(arg_buf, ".cpp") || | |
| 625 | buf_ends_with_str(arg_buf, ".cxx") || | |
| 626 | buf_ends_with_str(arg_buf, ".s") || | |
| 627 | buf_ends_with_str(arg_buf, ".S")) | |
| 628 | { | |
| 629 | CFile *c_file = heap::c_allocator.create<CFile>(); | |
| 630 | c_file->source_path = it.only_arg; | |
| 631 | c_source_files.append(c_file); | |
| 632 | } else { | |
| 633 | objects.append(it.only_arg); | |
| 624 | FileExt file_ext = classify_file_ext(it.only_arg, strlen(it.only_arg)); | |
| 625 | switch (file_ext) { | |
| 626 | case FileExtAsm: | |
| 627 | case FileExtC: | |
| 628 | case FileExtCpp: | |
| 629 | case FileExtLLVMIr: | |
| 630 | case FileExtLLVMBitCode: | |
| 631 | case FileExtHeader: { | |
| 632 | CFile *c_file = heap::c_allocator.create<CFile>(); | |
| 633 | c_file->source_path = it.only_arg; | |
| 634 | c_source_files.append(c_file); | |
| 635 | break; | |
| 636 | } | |
| 637 | case FileExtUnknown: | |
| 638 | objects.append(it.only_arg); | |
| 639 | break; | |
| 634 | 640 | } |
| 635 | 641 | break; |
| 636 | 642 | } |
| ... | ... | @@ -676,8 +682,12 @@ static int main0(int argc, char **argv) { |
| 676 | 682 | } |
| 677 | 683 | break; |
| 678 | 684 | } |
| 679 | case Stage2ClangArgPreprocess: | |
| 680 | only_preprocess = true; | |
| 685 | case Stage2ClangArgPreprocessOrAsm: | |
| 686 | // this handles both -E and -S | |
| 687 | only_pp_or_asm = true; | |
| 688 | for (size_t i = 0; i < it.other_args_len; i += 1) { | |
| 689 | clang_argv.append(it.other_args_ptr[i]); | |
| 690 | } | |
| 681 | 691 | break; |
| 682 | 692 | case Stage2ClangArgOptimize: |
| 683 | 693 | // alright what release mode do they want? |
| ... | ... | @@ -688,7 +698,9 @@ static int main0(int argc, char **argv) { |
| 688 | 698 | strcmp(it.only_arg, "O4") == 0) |
| 689 | 699 | { |
| 690 | 700 | build_mode = BuildModeFastRelease; |
| 691 | } else if (strcmp(it.only_arg, "Og") == 0) { | |
| 701 | } else if (strcmp(it.only_arg, "Og") == 0 || | |
| 702 | strcmp(it.only_arg, "O0") == 0) | |
| 703 | { | |
| 692 | 704 | build_mode = BuildModeDebug; |
| 693 | 705 | } else { |
| 694 | 706 | for (size_t i = 0; i < it.other_args_len; i += 1) { |
| ... | ... | @@ -722,18 +734,6 @@ static int main0(int argc, char **argv) { |
| 722 | 734 | verbose_cc = true; |
| 723 | 735 | verbose_link = true; |
| 724 | 736 | break; |
| 725 | case Stage2ClangArgExceptions: | |
| 726 | cpp_exceptions = true; | |
| 727 | break; | |
| 728 | case Stage2ClangArgNoExceptions: | |
| 729 | cpp_exceptions = false; | |
| 730 | break; | |
| 731 | case Stage2ClangArgRtti: | |
| 732 | cpp_rtti = true; | |
| 733 | break; | |
| 734 | case Stage2ClangArgNoRtti: | |
| 735 | cpp_rtti = false; | |
| 736 | break; | |
| 737 | 737 | case Stage2ClangArgForLinker: |
| 738 | 738 | linker_args.append(buf_create_from_str(it.only_arg)); |
| 739 | 739 | break; |
| ... | ... | @@ -741,6 +741,24 @@ static int main0(int argc, char **argv) { |
| 741 | 741 | linker_args.append(buf_create_from_str("-z")); |
| 742 | 742 | linker_args.append(buf_create_from_str(it.only_arg)); |
| 743 | 743 | break; |
| 744 | case Stage2ClangArgLibDir: | |
| 745 | lib_dirs.append(it.only_arg); | |
| 746 | break; | |
| 747 | case Stage2ClangArgMCpu: | |
| 748 | mcpu = it.only_arg; | |
| 749 | break; | |
| 750 | case Stage2ClangArgDepFile: | |
| 751 | disable_c_depfile = true; | |
| 752 | for (size_t i = 0; i < it.other_args_len; i += 1) { | |
| 753 | clang_argv.append(it.other_args_ptr[i]); | |
| 754 | } | |
| 755 | break; | |
| 756 | case Stage2ClangArgFrameworkDir: | |
| 757 | framework_dirs.append(it.only_arg); | |
| 758 | break; | |
| 759 | case Stage2ClangArgFramework: | |
| 760 | frameworks.append(it.only_arg); | |
| 761 | break; | |
| 744 | 762 | } |
| 745 | 763 | } |
| 746 | 764 | // Parse linker args |
| ... | ... | @@ -802,6 +820,37 @@ static int main0(int argc, char **argv) { |
| 802 | 820 | buf_eql_str(arg, "-export-dynamic")) |
| 803 | 821 | { |
| 804 | 822 | rdynamic = true; |
| 823 | } else if (buf_eql_str(arg, "--version-script")) { | |
| 824 | i += 1; | |
| 825 | if (i >= linker_args.length) { | |
| 826 | fprintf(stderr, "expected linker arg after '%s'\n", buf_ptr(arg)); | |
| 827 | return EXIT_FAILURE; | |
| 828 | } | |
| 829 | version_script = linker_args.at(i); | |
| 830 | } else if (buf_starts_with_str(arg, "-O")) { | |
| 831 | linker_optimization = arg; | |
| 832 | } else if (buf_eql_str(arg, "--gc-sections")) { | |
| 833 | linker_gc_sections = OptionalBoolTrue; | |
| 834 | } else if (buf_eql_str(arg, "--no-gc-sections")) { | |
| 835 | linker_gc_sections = OptionalBoolFalse; | |
| 836 | } else if (buf_eql_str(arg, "--allow-shlib-undefined")) { | |
| 837 | linker_allow_shlib_undefined = OptionalBoolTrue; | |
| 838 | } else if (buf_eql_str(arg, "--no-allow-shlib-undefined")) { | |
| 839 | linker_allow_shlib_undefined = OptionalBoolFalse; | |
| 840 | } else if (buf_eql_str(arg, "-z")) { | |
| 841 | i += 1; | |
| 842 | if (i >= linker_args.length) { | |
| 843 | fprintf(stderr, "expected linker arg after '%s'\n", buf_ptr(arg)); | |
| 844 | return EXIT_FAILURE; | |
| 845 | } | |
| 846 | Buf *z_arg = linker_args.at(i); | |
| 847 | if (buf_eql_str(z_arg, "nodelete")) { | |
| 848 | linker_z_nodelete = true; | |
| 849 | } else if (buf_eql_str(z_arg, "defs")) { | |
| 850 | linker_z_defs = true; | |
| 851 | } else { | |
| 852 | fprintf(stderr, "warning: unsupported linker arg: -z %s\n", buf_ptr(z_arg)); | |
| 853 | } | |
| 805 | 854 | } else { |
| 806 | 855 | fprintf(stderr, "warning: unsupported linker arg: %s\n", buf_ptr(arg)); |
| 807 | 856 | } |
| ... | ... | @@ -811,7 +860,7 @@ static int main0(int argc, char **argv) { |
| 811 | 860 | build_mode = BuildModeSafeRelease; |
| 812 | 861 | } |
| 813 | 862 | |
| 814 | if (only_preprocess) { | |
| 863 | if (only_pp_or_asm) { | |
| 815 | 864 | cmd = CmdBuild; |
| 816 | 865 | out_type = OutTypeObj; |
| 817 | 866 | emit_bin = false; |
| ... | ... | @@ -1329,8 +1378,6 @@ static int main0(int argc, char **argv) { |
| 1329 | 1378 | LinkLib *link_lib = codegen_add_link_lib(g, buf_create_from_str(link_libs.at(i))); |
| 1330 | 1379 | link_lib->provided_explicitly = true; |
| 1331 | 1380 | } |
| 1332 | g->cpp_rtti = cpp_rtti; | |
| 1333 | g->cpp_exceptions = cpp_exceptions; | |
| 1334 | 1381 | g->subsystem = subsystem; |
| 1335 | 1382 | g->valgrind_support = valgrind_support; |
| 1336 | 1383 | g->want_pic = want_pic; |
| ... | ... | @@ -1369,15 +1416,17 @@ static int main0(int argc, char **argv) { |
| 1369 | 1416 | return print_error_usage(arg0); |
| 1370 | 1417 | } |
| 1371 | 1418 | |
| 1372 | bool any_non_c_link_libs = false; | |
| 1419 | bool any_system_lib_dependencies = false; | |
| 1373 | 1420 | for (size_t i = 0; i < link_libs.length; i += 1) { |
| 1374 | if (!target_is_libc_lib_name(&target, link_libs.at(i))) { | |
| 1375 | any_non_c_link_libs = true; | |
| 1421 | if (!target_is_libc_lib_name(&target, link_libs.at(i)) && | |
| 1422 | !target_is_libcpp_lib_name(&target, link_libs.at(i))) | |
| 1423 | { | |
| 1424 | any_system_lib_dependencies = true; | |
| 1376 | 1425 | break; |
| 1377 | 1426 | } |
| 1378 | 1427 | } |
| 1379 | 1428 | |
| 1380 | if (target.is_native_os && any_non_c_link_libs) { | |
| 1429 | if (target.is_native_os && any_system_lib_dependencies) { | |
| 1381 | 1430 | Error err; |
| 1382 | 1431 | Stage2NativePaths paths; |
| 1383 | 1432 | if ((err = stage2_detect_native_paths(&paths))) { |
| ... | ... | @@ -1477,8 +1526,6 @@ static int main0(int argc, char **argv) { |
| 1477 | 1526 | } |
| 1478 | 1527 | CodeGen *g = codegen_create(main_pkg_path, zig_root_source_file, &target, out_type, build_mode, |
| 1479 | 1528 | override_lib_dir, libc, cache_dir_buf, cmd == CmdTest, root_progress_node); |
| 1480 | g->cpp_rtti = cpp_rtti; | |
| 1481 | g->cpp_exceptions = cpp_exceptions; | |
| 1482 | 1529 | if (llvm_argv.length >= 2) codegen_set_llvm_argv(g, llvm_argv.items + 1, llvm_argv.length - 2); |
| 1483 | 1530 | g->valgrind_support = valgrind_support; |
| 1484 | 1531 | g->link_eh_frame_hdr = link_eh_frame_hdr; |
| ... | ... | @@ -1522,6 +1569,13 @@ static int main0(int argc, char **argv) { |
| 1522 | 1569 | g->system_linker_hack = system_linker_hack; |
| 1523 | 1570 | g->function_sections = function_sections; |
| 1524 | 1571 | g->code_model = code_model; |
| 1572 | g->disable_c_depfile = disable_c_depfile; | |
| 1573 | ||
| 1574 | g->linker_optimization = linker_optimization; | |
| 1575 | g->linker_gc_sections = linker_gc_sections; | |
| 1576 | g->linker_allow_shlib_undefined = linker_allow_shlib_undefined; | |
| 1577 | g->linker_z_nodelete = linker_z_nodelete; | |
| 1578 | g->linker_z_defs = linker_z_defs; | |
| 1525 | 1579 | |
| 1526 | 1580 | if (override_soname) { |
| 1527 | 1581 | g->override_soname = buf_create_from_str(override_soname); |
| ... | ... | @@ -1611,7 +1665,7 @@ static int main0(int argc, char **argv) { |
| 1611 | 1665 | #endif |
| 1612 | 1666 | Buf *dest_path = buf_create_from_str(emit_bin_override_path); |
| 1613 | 1667 | Buf *source_path; |
| 1614 | if (only_preprocess) { | |
| 1668 | if (only_pp_or_asm) { | |
| 1615 | 1669 | source_path = buf_alloc(); |
| 1616 | 1670 | Buf *pp_only_basename = buf_create_from_str( |
| 1617 | 1671 | c_source_files.at(0)->preprocessor_only_basename); |
| ... | ... | @@ -1625,7 +1679,7 @@ static int main0(int argc, char **argv) { |
| 1625 | 1679 | buf_ptr(dest_path), err_str(err)); |
| 1626 | 1680 | return main_exit(root_progress_node, EXIT_FAILURE); |
| 1627 | 1681 | } |
| 1628 | } else if (only_preprocess) { | |
| 1682 | } else if (only_pp_or_asm) { | |
| 1629 | 1683 | #if defined(ZIG_OS_WINDOWS) |
| 1630 | 1684 | buf_replace(g->c_artifact_dir, '/', '\\'); |
| 1631 | 1685 | #endif |
src/os.cpp+6-3| ... | ... | @@ -1097,8 +1097,8 @@ static Error set_file_times(OsFile file, OsTimeStamp ts) { |
| 1097 | 1097 | return ErrorNone; |
| 1098 | 1098 | #else |
| 1099 | 1099 | struct timespec times[2] = { |
| 1100 | { (time_t)ts.sec, (time_t)ts.nsec }, | |
| 1101 | { (time_t)ts.sec, (time_t)ts.nsec }, | |
| 1100 | { (time_t)ts.sec, (long)ts.nsec }, | |
| 1101 | { (time_t)ts.sec, (long)ts.nsec }, | |
| 1102 | 1102 | }; |
| 1103 | 1103 | if (futimens(file, times) == -1) { |
| 1104 | 1104 | switch (errno) { |
| ... | ... | @@ -1456,7 +1456,10 @@ static void init_rand() { |
| 1456 | 1456 | memcpy(&seed, bytes, sizeof(unsigned)); |
| 1457 | 1457 | srand(seed); |
| 1458 | 1458 | #elif defined(ZIG_OS_LINUX) |
| 1459 | srand(*((unsigned*)getauxval(AT_RANDOM))); | |
| 1459 | unsigned char *ptr_random = (unsigned char*)getauxval(AT_RANDOM); | |
| 1460 | unsigned seed; | |
| 1461 | memcpy(&seed, ptr_random, sizeof(seed)); | |
| 1462 | srand(seed); | |
| 1460 | 1463 | #else |
| 1461 | 1464 | int fd = open("/dev/urandom", O_RDONLY|O_CLOEXEC); |
| 1462 | 1465 | if (fd == -1) { |
src/stage2.h+6-5| ... | ... | @@ -342,18 +342,19 @@ enum Stage2ClangArg { |
| 342 | 342 | Stage2ClangArgShared, |
| 343 | 343 | Stage2ClangArgRDynamic, |
| 344 | 344 | Stage2ClangArgWL, |
| 345 | Stage2ClangArgPreprocess, | |
| 345 | Stage2ClangArgPreprocessOrAsm, | |
| 346 | 346 | Stage2ClangArgOptimize, |
| 347 | 347 | Stage2ClangArgDebug, |
| 348 | 348 | Stage2ClangArgSanitize, |
| 349 | 349 | Stage2ClangArgLinkerScript, |
| 350 | 350 | Stage2ClangArgVerboseCmds, |
| 351 | Stage2ClangArgExceptions, | |
| 352 | Stage2ClangArgNoExceptions, | |
| 353 | Stage2ClangArgRtti, | |
| 354 | Stage2ClangArgNoRtti, | |
| 355 | 351 | Stage2ClangArgForLinker, |
| 356 | 352 | Stage2ClangArgLinkerInputZ, |
| 353 | Stage2ClangArgLibDir, | |
| 354 | Stage2ClangArgMCpu, | |
| 355 | Stage2ClangArgDepFile, | |
| 356 | Stage2ClangArgFrameworkDir, | |
| 357 | Stage2ClangArgFramework, | |
| 357 | 358 | }; |
| 358 | 359 | |
| 359 | 360 | // ABI warning |
src/target.cpp+14-13| ... | ... | @@ -624,6 +624,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) { |
| 624 | 624 | case CIntTypeCount: |
| 625 | 625 | zig_unreachable(); |
| 626 | 626 | } |
| 627 | zig_unreachable(); | |
| 627 | 628 | default: |
| 628 | 629 | switch (id) { |
| 629 | 630 | case CIntTypeShort: |
| ... | ... | @@ -642,6 +643,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) { |
| 642 | 643 | zig_unreachable(); |
| 643 | 644 | } |
| 644 | 645 | } |
| 646 | zig_unreachable(); | |
| 645 | 647 | case OsLinux: |
| 646 | 648 | case OsMacOSX: |
| 647 | 649 | case OsFreeBSD: |
| ... | ... | @@ -666,6 +668,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) { |
| 666 | 668 | case CIntTypeCount: |
| 667 | 669 | zig_unreachable(); |
| 668 | 670 | } |
| 671 | zig_unreachable(); | |
| 669 | 672 | case OsUefi: |
| 670 | 673 | case OsWindows: |
| 671 | 674 | switch (id) { |
| ... | ... | @@ -683,6 +686,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) { |
| 683 | 686 | case CIntTypeCount: |
| 684 | 687 | zig_unreachable(); |
| 685 | 688 | } |
| 689 | zig_unreachable(); | |
| 686 | 690 | case OsIOS: |
| 687 | 691 | switch (id) { |
| 688 | 692 | case CIntTypeShort: |
| ... | ... | @@ -699,6 +703,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) { |
| 699 | 703 | case CIntTypeCount: |
| 700 | 704 | zig_unreachable(); |
| 701 | 705 | } |
| 706 | zig_unreachable(); | |
| 702 | 707 | case OsAnanas: |
| 703 | 708 | case OsCloudABI: |
| 704 | 709 | case OsKFreeBSD: |
| ... | ... | @@ -1207,6 +1212,15 @@ bool target_is_libc_lib_name(const ZigTarget *target, const char *name) { |
| 1207 | 1212 | if (strcmp(name, "c") == 0) |
| 1208 | 1213 | return true; |
| 1209 | 1214 | |
| 1215 | if (target_abi_is_gnu(target->abi) && target->os == OsWindows) { | |
| 1216 | // mingw-w64 | |
| 1217 | ||
| 1218 | if (strcmp(name, "m") == 0) | |
| 1219 | return true; | |
| 1220 | ||
| 1221 | return false; | |
| 1222 | } | |
| 1223 | ||
| 1210 | 1224 | if (target_abi_is_gnu(target->abi) || target_abi_is_musl(target->abi) || target_os_is_darwin(target->os)) { |
| 1211 | 1225 | if (strcmp(name, "m") == 0) |
| 1212 | 1226 | return true; |
| ... | ... | @@ -1286,19 +1300,6 @@ const char *target_arch_musl_name(ZigLLVM_ArchType arch) { |
| 1286 | 1300 | } |
| 1287 | 1301 | } |
| 1288 | 1302 | |
| 1289 | bool target_supports_libunwind(const ZigTarget *target) { | |
| 1290 | switch (target->arch) { | |
| 1291 | case ZigLLVM_arm: | |
| 1292 | case ZigLLVM_armeb: | |
| 1293 | case ZigLLVM_riscv32: | |
| 1294 | case ZigLLVM_riscv64: | |
| 1295 | return false; | |
| 1296 | default: | |
| 1297 | return true; | |
| 1298 | } | |
| 1299 | return true; | |
| 1300 | } | |
| 1301 | ||
| 1302 | 1303 | bool target_libc_needs_crti_crtn(const ZigTarget *target) { |
| 1303 | 1304 | if (target->arch == ZigLLVM_riscv32 || target->arch == ZigLLVM_riscv64 || target_is_android(target)) { |
| 1304 | 1305 | return false; |
src/target.hpp-1| ... | ... | @@ -119,7 +119,6 @@ bool target_supports_stack_probing(const ZigTarget *target); |
| 119 | 119 | bool target_supports_sanitize_c(const ZigTarget *target); |
| 120 | 120 | bool target_has_debug_info(const ZigTarget *target); |
| 121 | 121 | const char *target_arch_musl_name(ZigLLVM_ArchType arch); |
| 122 | bool target_supports_libunwind(const ZigTarget *target); | |
| 123 | 122 | |
| 124 | 123 | uint32_t target_arch_pointer_bit_width(ZigLLVM_ArchType arch); |
| 125 | 124 | uint32_t target_arch_largest_atomic_bits(ZigLLVM_ArchType arch); |
src/tokenizer.cpp+12-3| ... | ... | @@ -840,6 +840,7 @@ void tokenize(Buf *buf, Tokenization *out) { |
| 840 | 840 | t.state = TokenizeStateStart; |
| 841 | 841 | continue; |
| 842 | 842 | } |
| 843 | break; | |
| 843 | 844 | case TokenizeStateSawSlash: |
| 844 | 845 | switch (c) { |
| 845 | 846 | case '/': |
| ... | ... | @@ -1209,7 +1210,7 @@ void tokenize(Buf *buf, Tokenization *out) { |
| 1209 | 1210 | t.is_trailing_underscore = false; |
| 1210 | 1211 | t.state = TokenizeStateNumber; |
| 1211 | 1212 | } |
| 1212 | // fall through | |
| 1213 | ZIG_FALLTHROUGH; | |
| 1213 | 1214 | case TokenizeStateNumber: |
| 1214 | 1215 | { |
| 1215 | 1216 | if (c == '_') { |
| ... | ... | @@ -1291,7 +1292,7 @@ void tokenize(Buf *buf, Tokenization *out) { |
| 1291 | 1292 | t.is_trailing_underscore = false; |
| 1292 | 1293 | t.state = TokenizeStateFloatFraction; |
| 1293 | 1294 | } |
| 1294 | // fall through | |
| 1295 | ZIG_FALLTHROUGH; | |
| 1295 | 1296 | case TokenizeStateFloatFraction: |
| 1296 | 1297 | { |
| 1297 | 1298 | if (c == '_') { |
| ... | ... | @@ -1350,7 +1351,7 @@ void tokenize(Buf *buf, Tokenization *out) { |
| 1350 | 1351 | t.is_trailing_underscore = false; |
| 1351 | 1352 | t.state = TokenizeStateFloatExponentNumber; |
| 1352 | 1353 | } |
| 1353 | // fall through | |
| 1354 | ZIG_FALLTHROUGH; | |
| 1354 | 1355 | case TokenizeStateFloatExponentNumber: |
| 1355 | 1356 | { |
| 1356 | 1357 | if (c == '_') { |
| ... | ... | @@ -1494,9 +1495,17 @@ void tokenize(Buf *buf, Tokenization *out) { |
| 1494 | 1495 | tokenize_error(&t, "unexpected EOF"); |
| 1495 | 1496 | break; |
| 1496 | 1497 | case TokenizeStateLineComment: |
| 1498 | break; | |
| 1497 | 1499 | case TokenizeStateSawSlash2: |
| 1500 | cancel_token(&t); | |
| 1501 | break; | |
| 1498 | 1502 | case TokenizeStateSawSlash3: |
| 1503 | set_token_id(&t, t.cur_tok, TokenIdDocComment); | |
| 1504 | end_token(&t); | |
| 1505 | break; | |
| 1499 | 1506 | case TokenizeStateSawSlashBang: |
| 1507 | set_token_id(&t, t.cur_tok, TokenIdContainerDocComment); | |
| 1508 | end_token(&t); | |
| 1500 | 1509 | break; |
| 1501 | 1510 | } |
| 1502 | 1511 | if (t.state != TokenizeStateError) { |
src/util.hpp+9| ... | ... | @@ -100,6 +100,15 @@ static inline bool is_power_of_2(uint64_t x) { |
| 100 | 100 | return x != 0 && ((x & (~x + 1)) == x); |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | static inline bool mem_ends_with_mem(const char *mem, size_t mem_len, const char *end, size_t end_len) { | |
| 104 | if (mem_len < end_len) return false; | |
| 105 | return memcmp(mem + mem_len - end_len, end, end_len) == 0; | |
| 106 | } | |
| 107 | ||
| 108 | static inline bool mem_ends_with_str(const char *mem, size_t mem_len, const char *str) { | |
| 109 | return mem_ends_with_mem(mem, mem_len, str, strlen(str)); | |
| 110 | } | |
| 111 | ||
| 103 | 112 | static inline uint64_t round_to_next_power_of_2(uint64_t x) { |
| 104 | 113 | --x; |
| 105 | 114 | x |= x >> 1; |
src/util_base.hpp+10| ... | ... | @@ -64,4 +64,14 @@ static inline void zig_assert(bool ok, const char *file, int line, const char *f |
| 64 | 64 | #undef assert |
| 65 | 65 | #define assert(ok) zig_assert(ok, __FILE__, __LINE__, __func__) |
| 66 | 66 | |
| 67 | #if defined(_MSC_VER) | |
| 68 | #define ZIG_FALLTHROUGH | |
| 69 | #elif defined(__clang__) | |
| 70 | #define ZIG_FALLTHROUGH [[clang::fallthrough]] | |
| 71 | #elif defined(__GNUC__) | |
| 72 | #define ZIG_FALLTHROUGH __attribute__((fallthrough)) | |
| 73 | #else | |
| 74 | #define ZIG_FALLTHROUGH | |
| 75 | #endif | |
| 76 | ||
| 67 | 77 | #endif |
src/zig_clang.h+2| ... | ... | @@ -52,6 +52,8 @@ struct ZigClangAPValue { |
| 52 | 52 | // experimentally-derived size of clang::APValue::DataType |
| 53 | 53 | #if defined(_WIN32) && defined(_MSC_VER) |
| 54 | 54 | char Data[52]; |
| 55 | #elif defined(__i386__) | |
| 56 | char Data[48]; | |
| 55 | 57 | #else |
| 56 | 58 | char Data[68]; |
| 57 | 59 | #endif |
test/cli.zig+8-3| ... | ... | @@ -59,7 +59,12 @@ fn printCmd(cwd: []const u8, argv: []const []const u8) void { |
| 59 | 59 | |
| 60 | 60 | fn exec(cwd: []const u8, argv: []const []const u8) !ChildProcess.ExecResult { |
| 61 | 61 | const max_output_size = 100 * 1024; |
| 62 | const result = ChildProcess.exec(a, argv, cwd, null, max_output_size) catch |err| { | |
| 62 | const result = ChildProcess.exec(.{ | |
| 63 | .allocator = a, | |
| 64 | .argv = argv, | |
| 65 | .cwd = cwd, | |
| 66 | .max_output_bytes = max_output_size, | |
| 67 | }) catch |err| { | |
| 63 | 68 | std.debug.warn("The following command failed:\n", .{}); |
| 64 | 69 | printCmd(cwd, argv); |
| 65 | 70 | return err; |
| ... | ... | @@ -101,7 +106,7 @@ fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void { |
| 101 | 106 | const example_zig_path = try fs.path.join(a, &[_][]const u8{ dir_path, "example.zig" }); |
| 102 | 107 | const example_s_path = try fs.path.join(a, &[_][]const u8{ dir_path, "example.s" }); |
| 103 | 108 | |
| 104 | try std.io.writeFile(example_zig_path, | |
| 109 | try fs.cwd().writeFile(example_zig_path, | |
| 105 | 110 | \\// Type your code here, or load an example. |
| 106 | 111 | \\export fn square(num: i32) i32 { |
| 107 | 112 | \\ return num * num; |
| ... | ... | @@ -124,7 +129,7 @@ fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void { |
| 124 | 129 | }; |
| 125 | 130 | _ = try exec(dir_path, &args); |
| 126 | 131 | |
| 127 | const out_asm = try std.io.readFileAlloc(a, example_s_path); | |
| 132 | const out_asm = try std.fs.cwd().readFileAlloc(a, example_s_path, std.math.maxInt(usize)); | |
| 128 | 133 | testing.expect(std.mem.indexOf(u8, out_asm, "square:") != null); |
| 129 | 134 | testing.expect(std.mem.indexOf(u8, out_asm, "mov\teax, edi") != null); |
| 130 | 135 | testing.expect(std.mem.indexOf(u8, out_asm, "imul\teax, edi") != null); |
test/compile_errors.zig+52-1| ... | ... | @@ -2,6 +2,19 @@ const tests = @import("tests.zig"); |
| 2 | 2 | const std = @import("std"); |
| 3 | 3 | |
| 4 | 4 | pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5 | cases.addTest("cast between ?T where T is not a pointer", | |
| 6 | \\pub const fnty1 = ?fn (i8) void; | |
| 7 | \\pub const fnty2 = ?fn (u64) void; | |
| 8 | \\export fn entry() void { | |
| 9 | \\ var a: fnty1 = undefined; | |
| 10 | \\ var b: fnty2 = undefined; | |
| 11 | \\ a = b; | |
| 12 | \\} | |
| 13 | , &[_][]const u8{ | |
| 14 | "tmp.zig:6:9: error: expected type '?fn(i8) void', found '?fn(u64) void'", | |
| 15 | "tmp.zig:6:9: note: optional type child 'fn(u64) void' cannot cast into optional type child 'fn(i8) void'", | |
| 16 | }); | |
| 17 | ||
| 5 | 18 | cases.addTest("unused variable error on errdefer", |
| 6 | 19 | \\fn foo() !void { |
| 7 | 20 | \\ errdefer |a| unreachable; |
| ... | ... | @@ -1188,7 +1201,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1188 | 1201 | \\ suspend; |
| 1189 | 1202 | \\} |
| 1190 | 1203 | , &[_][]const u8{ |
| 1191 | "tmp.zig:3:5: error: expected type '*@Frame(bar)', found '*@Frame(foo)'", | |
| 1204 | "tmp.zig:3:13: error: expected type '*@Frame(bar)', found '*@Frame(foo)'", | |
| 1192 | 1205 | }); |
| 1193 | 1206 | |
| 1194 | 1207 | cases.add("@Frame() of generic function", |
| ... | ... | @@ -6806,4 +6819,42 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6806 | 6819 | , &[_][]const u8{ |
| 6807 | 6820 | "tmp.zig:2:27: error: type 'u32' does not support array initialization", |
| 6808 | 6821 | }); |
| 6822 | ||
| 6823 | cases.add("issue #2687: coerce from undefined array pointer to slice", | |
| 6824 | \\export fn foo1() void { | |
| 6825 | \\ const a: *[1]u8 = undefined; | |
| 6826 | \\ var b: []u8 = a; | |
| 6827 | \\} | |
| 6828 | \\export fn foo2() void { | |
| 6829 | \\ comptime { | |
| 6830 | \\ var a: *[1]u8 = undefined; | |
| 6831 | \\ var b: []u8 = a; | |
| 6832 | \\ } | |
| 6833 | \\} | |
| 6834 | \\export fn foo3() void { | |
| 6835 | \\ comptime { | |
| 6836 | \\ const a: *[1]u8 = undefined; | |
| 6837 | \\ var b: []u8 = a; | |
| 6838 | \\ } | |
| 6839 | \\} | |
| 6840 | , &[_][]const u8{ | |
| 6841 | "tmp.zig:3:19: error: use of undefined value here causes undefined behavior", | |
| 6842 | "tmp.zig:8:23: error: use of undefined value here causes undefined behavior", | |
| 6843 | "tmp.zig:14:23: error: use of undefined value here causes undefined behavior", | |
| 6844 | }); | |
| 6845 | ||
| 6846 | cases.add("issue #3818: bitcast from parray/slice to u16", | |
| 6847 | \\export fn foo1() void { | |
| 6848 | \\ var bytes = [_]u8{1, 2}; | |
| 6849 | \\ const word: u16 = @bitCast(u16, bytes[0..]); | |
| 6850 | \\} | |
| 6851 | \\export fn foo2() void { | |
| 6852 | \\ var bytes: []u8 = &[_]u8{1, 2}; | |
| 6853 | \\ const word: u16 = @bitCast(u16, bytes); | |
| 6854 | \\} | |
| 6855 | , &[_][]const u8{ | |
| 6856 | "tmp.zig:3:42: error: unable to @bitCast from pointer type '*[2]u8'", | |
| 6857 | "tmp.zig:7:32: error: destination type 'u16' has size 2 but source type '[]u8' has size 16", | |
| 6858 | "tmp.zig:7:37: note: referenced here", | |
| 6859 | }); | |
| 6809 | 6860 | } |
test/src/compare_output.zig+4-4| ... | ... | @@ -91,7 +91,7 @@ pub const CompareOutputContext = struct { |
| 91 | 91 | const b = self.b; |
| 92 | 92 | |
| 93 | 93 | const write_src = b.addWriteFiles(); |
| 94 | for (case.sources.toSliceConst()) |src_file| { | |
| 94 | for (case.sources.span()) |src_file| { | |
| 95 | 95 | write_src.add(src_file.filename, src_file.source); |
| 96 | 96 | } |
| 97 | 97 | |
| ... | ... | @@ -105,7 +105,7 @@ pub const CompareOutputContext = struct { |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | const exe = b.addExecutable("test", null); |
| 108 | exe.addAssemblyFileFromWriteFileStep(write_src, case.sources.toSliceConst()[0].filename); | |
| 108 | exe.addAssemblyFileFromWriteFileStep(write_src, case.sources.span()[0].filename); | |
| 109 | 109 | |
| 110 | 110 | const run = exe.run(); |
| 111 | 111 | run.addArgs(case.cli_args); |
| ... | ... | @@ -125,7 +125,7 @@ pub const CompareOutputContext = struct { |
| 125 | 125 | if (mem.indexOf(u8, annotated_case_name, filter) == null) continue; |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | const basename = case.sources.toSliceConst()[0].filename; | |
| 128 | const basename = case.sources.span()[0].filename; | |
| 129 | 129 | const exe = b.addExecutableFromWriteFileStep("test", write_src, basename); |
| 130 | 130 | exe.setBuildMode(mode); |
| 131 | 131 | if (case.link_libc) { |
| ... | ... | @@ -146,7 +146,7 @@ pub const CompareOutputContext = struct { |
| 146 | 146 | if (mem.indexOf(u8, annotated_case_name, filter) == null) return; |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | const basename = case.sources.toSliceConst()[0].filename; | |
| 149 | const basename = case.sources.span()[0].filename; | |
| 150 | 150 | const exe = b.addExecutableFromWriteFileStep("test", write_src, basename); |
| 151 | 151 | if (case.link_libc) { |
| 152 | 152 | exe.linkSystemLibrary("c"); |
test/src/run_translated_c.zig+2-2| ... | ... | @@ -82,13 +82,13 @@ pub const RunTranslatedCContext = struct { |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | const write_src = b.addWriteFiles(); |
| 85 | for (case.sources.toSliceConst()) |src_file| { | |
| 85 | for (case.sources.span()) |src_file| { | |
| 86 | 86 | write_src.add(src_file.filename, src_file.source); |
| 87 | 87 | } |
| 88 | 88 | const translate_c = b.addTranslateC(.{ |
| 89 | 89 | .write_file = .{ |
| 90 | 90 | .step = write_src, |
| 91 | .basename = case.sources.toSliceConst()[0].filename, | |
| 91 | .basename = case.sources.span()[0].filename, | |
| 92 | 92 | }, |
| 93 | 93 | }); |
| 94 | 94 | translate_c.step.name = b.fmt("{} translate-c", .{annotated_case_name}); |
test/src/translate_c.zig+3-3| ... | ... | @@ -105,20 +105,20 @@ pub const TranslateCContext = struct { |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | const write_src = b.addWriteFiles(); |
| 108 | for (case.sources.toSliceConst()) |src_file| { | |
| 108 | for (case.sources.span()) |src_file| { | |
| 109 | 109 | write_src.add(src_file.filename, src_file.source); |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | const translate_c = b.addTranslateC(.{ |
| 113 | 113 | .write_file = .{ |
| 114 | 114 | .step = write_src, |
| 115 | .basename = case.sources.toSliceConst()[0].filename, | |
| 115 | .basename = case.sources.span()[0].filename, | |
| 116 | 116 | }, |
| 117 | 117 | }); |
| 118 | 118 | translate_c.step.name = annotated_case_name; |
| 119 | 119 | translate_c.setTarget(case.target); |
| 120 | 120 | |
| 121 | const check_file = translate_c.addCheckFile(case.expected_lines.toSliceConst()); | |
| 121 | const check_file = translate_c.addCheckFile(case.expected_lines.span()); | |
| 122 | 122 | |
| 123 | 123 | self.step.dependOn(&check_file.step); |
| 124 | 124 | } |
test/stage1/behavior.zig+3| ... | ... | @@ -41,6 +41,9 @@ comptime { |
| 41 | 41 | _ = @import("behavior/bugs/3586.zig"); |
| 42 | 42 | _ = @import("behavior/bugs/3742.zig"); |
| 43 | 43 | _ = @import("behavior/bugs/4560.zig"); |
| 44 | _ = @import("behavior/bugs/4769_a.zig"); | |
| 45 | _ = @import("behavior/bugs/4769_b.zig"); | |
| 46 | _ = @import("behavior/bugs/4769_c.zig"); | |
| 44 | 47 | _ = @import("behavior/bugs/394.zig"); |
| 45 | 48 | _ = @import("behavior/bugs/421.zig"); |
| 46 | 49 | _ = @import("behavior/bugs/529.zig"); |
test/stage1/behavior/array.zig+14-5| ... | ... | @@ -31,14 +31,23 @@ fn getArrayLen(a: []const u32) usize { |
| 31 | 31 | test "array with sentinels" { |
| 32 | 32 | const S = struct { |
| 33 | 33 | fn doTheTest(is_ct: bool) void { |
| 34 | var zero_sized: [0:0xde]u8 = [_:0xde]u8{}; | |
| 35 | expectEqual(@as(u8, 0xde), zero_sized[0]); | |
| 36 | // Disabled at runtime because of | |
| 37 | // https://github.com/ziglang/zig/issues/4372 | |
| 38 | 34 | if (is_ct) { |
| 35 | var zero_sized: [0:0xde]u8 = [_:0xde]u8{}; | |
| 36 | // Disabled at runtime because of | |
| 37 | // https://github.com/ziglang/zig/issues/4372 | |
| 38 | expectEqual(@as(u8, 0xde), zero_sized[0]); | |
| 39 | 39 | var reinterpreted = @ptrCast(*[1]u8, &zero_sized); |
| 40 | 40 | expectEqual(@as(u8, 0xde), reinterpreted[0]); |
| 41 | 41 | } |
| 42 | var arr: [3:0x55]u8 = undefined; | |
| 43 | // Make sure the sentinel pointer is pointing after the last element | |
| 44 | if (!is_ct) { | |
| 45 | const sentinel_ptr = @ptrToInt(&arr[3]); | |
| 46 | const last_elem_ptr = @ptrToInt(&arr[2]); | |
| 47 | expectEqual(@as(usize, 1), sentinel_ptr - last_elem_ptr); | |
| 48 | } | |
| 49 | // Make sure the sentinel is writeable | |
| 50 | arr[3] = 0x55; | |
| 42 | 51 | } |
| 43 | 52 | }; |
| 44 | 53 | |
| ... | ... | @@ -372,7 +381,7 @@ test "access the null element of a null terminated array" { |
| 372 | 381 | const S = struct { |
| 373 | 382 | fn doTheTest() void { |
| 374 | 383 | var array: [4:0]u8 = .{ 'a', 'o', 'e', 'u' }; |
| 375 | comptime expect(array[4] == 0); | |
| 384 | expect(array[4] == 0); | |
| 376 | 385 | var len: usize = 4; |
| 377 | 386 | expect(array[len] == 0); |
| 378 | 387 | } |
test/stage1/behavior/atomics.zig-2| ... | ... | @@ -190,8 +190,6 @@ fn testAtomicRmwInt() void { |
| 190 | 190 | _ = @atomicRmw(u8, &x, .Xor, 2, .SeqCst); |
| 191 | 191 | expect(x == 0xfd); |
| 192 | 192 | |
| 193 | // TODO https://github.com/ziglang/zig/issues/4724 | |
| 194 | if (builtin.arch == .mipsel) return; | |
| 195 | 193 | _ = @atomicRmw(u8, &x, .Max, 1, .SeqCst); |
| 196 | 194 | expect(x == 0xfd); |
| 197 | 195 | _ = @atomicRmw(u8, &x, .Min, 1, .SeqCst); |
test/stage1/behavior/bugs/4769_a.zig created+1| ... | ... | @@ -0,0 +1 @@ |
| 1 | // | |
| \ No newline at end of file |
test/stage1/behavior/bugs/4769_b.zig created+1| ... | ... | @@ -0,0 +1 @@ |
| 1 | //! | |
| \ No newline at end of file |
test/stage1/behavior/bugs/4769_c.zig created+1| ... | ... | @@ -0,0 +1 @@ |
| 1 | /// | |
| \ No newline at end of file |
test/stage1/behavior/cast.zig+16-1| ... | ... | @@ -329,7 +329,7 @@ fn testCastPtrOfArrayToSliceAndPtr() void { |
| 329 | 329 | test "cast *[1][*]const u8 to [*]const ?[*]const u8" { |
| 330 | 330 | const window_name = [1][*]const u8{"window name"}; |
| 331 | 331 | const x: [*]const ?[*]const u8 = &window_name; |
| 332 | expect(mem.eql(u8, std.mem.toSliceConst(u8, @ptrCast([*:0]const u8, x[0].?)), "window name")); | |
| 332 | expect(mem.eql(u8, std.mem.spanZ(@ptrCast([*:0]const u8, x[0].?)), "window name")); | |
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | test "@intCast comptime_int" { |
| ... | ... | @@ -790,3 +790,18 @@ test "assignment to optional pointer result loc" { |
| 790 | 790 | var foo: struct { ptr: ?*c_void } = .{ .ptr = &global_struct }; |
| 791 | 791 | expect(foo.ptr.? == @ptrCast(*c_void, &global_struct)); |
| 792 | 792 | } |
| 793 | ||
| 794 | test "peer type resolve string lit with sentinel-terminated mutable slice" { | |
| 795 | var array: [4:0]u8 = undefined; | |
| 796 | array[4] = 0; // TODO remove this when #4372 is solved | |
| 797 | var slice: [:0]u8 = array[0..4 :0]; | |
| 798 | comptime expect(@TypeOf(slice, "hi") == [:0]const u8); | |
| 799 | comptime expect(@TypeOf("hi", slice) == [:0]const u8); | |
| 800 | } | |
| 801 | ||
| 802 | test "peer type resolve array pointers, one of them const" { | |
| 803 | var array1: [4]u8 = undefined; | |
| 804 | const array2: [5]u8 = undefined; | |
| 805 | comptime expect(@TypeOf(&array1, &array2) == []const u8); | |
| 806 | comptime expect(@TypeOf(&array2, &array1) == []const u8); | |
| 807 | } |
test/stage1/behavior/pointers.zig+1-1| ... | ... | @@ -225,7 +225,7 @@ test "null terminated pointer" { |
| 225 | 225 | var zero_ptr: [*:0]const u8 = @ptrCast([*:0]const u8, &array_with_zero); |
| 226 | 226 | var no_zero_ptr: [*]const u8 = zero_ptr; |
| 227 | 227 | var zero_ptr_again = @ptrCast([*:0]const u8, no_zero_ptr); |
| 228 | expect(std.mem.eql(u8, std.mem.toSliceConst(u8, zero_ptr_again), "hello")); | |
| 228 | expect(std.mem.eql(u8, std.mem.spanZ(zero_ptr_again), "hello")); | |
| 229 | 229 | } |
| 230 | 230 | }; |
| 231 | 231 | S.doTheTest(); |
test/standalone/brace_expansion/main.zig+24-24| ... | ... | @@ -4,7 +4,7 @@ const mem = std.mem; |
| 4 | 4 | const debug = std.debug; |
| 5 | 5 | const assert = debug.assert; |
| 6 | 6 | const testing = std.testing; |
| 7 | const Buffer = std.Buffer; | |
| 7 | const ArrayListSentineled = std.ArrayListSentineled; | |
| 8 | 8 | const ArrayList = std.ArrayList; |
| 9 | 9 | const maxInt = std.math.maxInt; |
| 10 | 10 | |
| ... | ... | @@ -111,7 +111,7 @@ fn parse(tokens: *const ArrayList(Token), token_index: *usize) ParseError!Node { |
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | fn expandString(input: []const u8, output: *Buffer) !void { | |
| 114 | fn expandString(input: []const u8, output: *ArrayListSentineled(u8, 0)) !void { | |
| 115 | 115 | const tokens = try tokenize(input); |
| 116 | 116 | if (tokens.len == 1) { |
| 117 | 117 | return output.resize(0); |
| ... | ... | @@ -125,52 +125,52 @@ fn expandString(input: []const u8, output: *Buffer) !void { |
| 125 | 125 | else => return error.InvalidInput, |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | var result_list = ArrayList(Buffer).init(global_allocator); | |
| 128 | var result_list = ArrayList(ArrayListSentineled(u8, 0)).init(global_allocator); | |
| 129 | 129 | defer result_list.deinit(); |
| 130 | 130 | |
| 131 | 131 | try expandNode(root, &result_list); |
| 132 | 132 | |
| 133 | 133 | try output.resize(0); |
| 134 | for (result_list.toSliceConst()) |buf, i| { | |
| 134 | for (result_list.span()) |buf, i| { | |
| 135 | 135 | if (i != 0) { |
| 136 | try output.appendByte(' '); | |
| 136 | try output.append(' '); | |
| 137 | 137 | } |
| 138 | try output.append(buf.toSliceConst()); | |
| 138 | try output.appendSlice(buf.span()); | |
| 139 | 139 | } |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | const ExpandNodeError = error{OutOfMemory}; |
| 143 | 143 | |
| 144 | fn expandNode(node: Node, output: *ArrayList(Buffer)) ExpandNodeError!void { | |
| 144 | fn expandNode(node: Node, output: *ArrayList(ArrayListSentineled(u8, 0))) ExpandNodeError!void { | |
| 145 | 145 | assert(output.len == 0); |
| 146 | 146 | switch (node) { |
| 147 | 147 | Node.Scalar => |scalar| { |
| 148 | try output.append(try Buffer.init(global_allocator, scalar)); | |
| 148 | try output.append(try ArrayListSentineled(u8, 0).init(global_allocator, scalar)); | |
| 149 | 149 | }, |
| 150 | 150 | Node.Combine => |pair| { |
| 151 | 151 | const a_node = pair[0]; |
| 152 | 152 | const b_node = pair[1]; |
| 153 | 153 | |
| 154 | var child_list_a = ArrayList(Buffer).init(global_allocator); | |
| 154 | var child_list_a = ArrayList(ArrayListSentineled(u8, 0)).init(global_allocator); | |
| 155 | 155 | try expandNode(a_node, &child_list_a); |
| 156 | 156 | |
| 157 | var child_list_b = ArrayList(Buffer).init(global_allocator); | |
| 157 | var child_list_b = ArrayList(ArrayListSentineled(u8, 0)).init(global_allocator); | |
| 158 | 158 | try expandNode(b_node, &child_list_b); |
| 159 | 159 | |
| 160 | for (child_list_a.toSliceConst()) |buf_a| { | |
| 161 | for (child_list_b.toSliceConst()) |buf_b| { | |
| 162 | var combined_buf = try Buffer.initFromBuffer(buf_a); | |
| 163 | try combined_buf.append(buf_b.toSliceConst()); | |
| 160 | for (child_list_a.span()) |buf_a| { | |
| 161 | for (child_list_b.span()) |buf_b| { | |
| 162 | var combined_buf = try ArrayListSentineled(u8, 0).initFromBuffer(buf_a); | |
| 163 | try combined_buf.appendSlice(buf_b.span()); | |
| 164 | 164 | try output.append(combined_buf); |
| 165 | 165 | } |
| 166 | 166 | } |
| 167 | 167 | }, |
| 168 | 168 | Node.List => |list| { |
| 169 | for (list.toSliceConst()) |child_node| { | |
| 170 | var child_list = ArrayList(Buffer).init(global_allocator); | |
| 169 | for (list.span()) |child_node| { | |
| 170 | var child_list = ArrayList(ArrayListSentineled(u8, 0)).init(global_allocator); | |
| 171 | 171 | try expandNode(child_node, &child_list); |
| 172 | 172 | |
| 173 | for (child_list.toSliceConst()) |buf| { | |
| 173 | for (child_list.span()) |buf| { | |
| 174 | 174 | try output.append(buf); |
| 175 | 175 | } |
| 176 | 176 | } |
| ... | ... | @@ -187,17 +187,17 @@ pub fn main() !void { |
| 187 | 187 | |
| 188 | 188 | global_allocator = &arena.allocator; |
| 189 | 189 | |
| 190 | var stdin_buf = try Buffer.initSize(global_allocator, 0); | |
| 190 | var stdin_buf = try ArrayListSentineled(u8, 0).initSize(global_allocator, 0); | |
| 191 | 191 | defer stdin_buf.deinit(); |
| 192 | 192 | |
| 193 | 193 | var stdin_adapter = stdin_file.inStream(); |
| 194 | 194 | try stdin_adapter.stream.readAllBuffer(&stdin_buf, maxInt(usize)); |
| 195 | 195 | |
| 196 | var result_buf = try Buffer.initSize(global_allocator, 0); | |
| 196 | var result_buf = try ArrayListSentineled(u8, 0).initSize(global_allocator, 0); | |
| 197 | 197 | defer result_buf.deinit(); |
| 198 | 198 | |
| 199 | try expandString(stdin_buf.toSlice(), &result_buf); | |
| 200 | try stdout_file.write(result_buf.toSliceConst()); | |
| 199 | try expandString(stdin_buf.span(), &result_buf); | |
| 200 | try stdout_file.write(result_buf.span()); | |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | test "invalid inputs" { |
| ... | ... | @@ -218,7 +218,7 @@ test "invalid inputs" { |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | fn expectError(test_input: []const u8, expected_err: anyerror) void { |
| 221 | var output_buf = Buffer.initSize(global_allocator, 0) catch unreachable; | |
| 221 | var output_buf = ArrayListSentineled(u8, 0).initSize(global_allocator, 0) catch unreachable; | |
| 222 | 222 | defer output_buf.deinit(); |
| 223 | 223 | |
| 224 | 224 | testing.expectError(expected_err, expandString(test_input, &output_buf)); |
| ... | ... | @@ -251,10 +251,10 @@ test "valid inputs" { |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | fn expectExpansion(test_input: []const u8, expected_result: []const u8) void { |
| 254 | var result = Buffer.initSize(global_allocator, 0) catch unreachable; | |
| 254 | var result = ArrayListSentineled(u8, 0).initSize(global_allocator, 0) catch unreachable; | |
| 255 | 255 | defer result.deinit(); |
| 256 | 256 | |
| 257 | 257 | expandString(test_input, &result) catch unreachable; |
| 258 | 258 | |
| 259 | testing.expectEqualSlices(u8, expected_result, result.toSlice()); | |
| 259 | testing.expectEqualSlices(u8, expected_result, result.span()); | |
| 260 | 260 | } |
test/standalone/guess_number/main.zig+1-1| ... | ... | @@ -17,7 +17,7 @@ pub fn main() !void { |
| 17 | 17 | const seed = std.mem.readIntNative(u64, &seed_bytes); |
| 18 | 18 | var prng = std.rand.DefaultPrng.init(seed); |
| 19 | 19 | |
| 20 | const answer = prng.random.range(u8, 0, 100) + 1; | |
| 20 | const answer = prng.random.intRangeLessThan(u8, 0, 100) + 1; | |
| 21 | 21 | |
| 22 | 22 | while (true) { |
| 23 | 23 | try stdout.print("\nGuess a number between 1 and 100: ", .{}); |
test/tests.zig+32-33| ... | ... | @@ -4,7 +4,6 @@ const debug = std.debug; |
| 4 | 4 | const warn = debug.warn; |
| 5 | 5 | const build = std.build; |
| 6 | 6 | const CrossTarget = std.zig.CrossTarget; |
| 7 | const Buffer = std.Buffer; | |
| 8 | 7 | const io = std.io; |
| 9 | 8 | const fs = std.fs; |
| 10 | 9 | const mem = std.mem; |
| ... | ... | @@ -583,7 +582,7 @@ pub const StackTracesContext = struct { |
| 583 | 582 | |
| 584 | 583 | warn("Test {}/{} {}...", .{ self.test_index + 1, self.context.test_index, self.name }); |
| 585 | 584 | |
| 586 | const child = std.ChildProcess.init(args.toSliceConst(), b.allocator) catch unreachable; | |
| 585 | const child = std.ChildProcess.init(args.span(), b.allocator) catch unreachable; | |
| 587 | 586 | defer child.deinit(); |
| 588 | 587 | |
| 589 | 588 | child.stdin_behavior = .Ignore; |
| ... | ... | @@ -592,7 +591,7 @@ pub const StackTracesContext = struct { |
| 592 | 591 | child.env_map = b.env_map; |
| 593 | 592 | |
| 594 | 593 | if (b.verbose) { |
| 595 | printInvocation(args.toSliceConst()); | |
| 594 | printInvocation(args.span()); | |
| 596 | 595 | } |
| 597 | 596 | child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", .{ full_exe_path, @errorName(err) }); |
| 598 | 597 | |
| ... | ... | @@ -614,23 +613,23 @@ pub const StackTracesContext = struct { |
| 614 | 613 | code, |
| 615 | 614 | expect_code, |
| 616 | 615 | }); |
| 617 | printInvocation(args.toSliceConst()); | |
| 616 | printInvocation(args.span()); | |
| 618 | 617 | return error.TestFailed; |
| 619 | 618 | } |
| 620 | 619 | }, |
| 621 | 620 | .Signal => |signum| { |
| 622 | 621 | warn("Process {} terminated on signal {}\n", .{ full_exe_path, signum }); |
| 623 | printInvocation(args.toSliceConst()); | |
| 622 | printInvocation(args.span()); | |
| 624 | 623 | return error.TestFailed; |
| 625 | 624 | }, |
| 626 | 625 | .Stopped => |signum| { |
| 627 | 626 | warn("Process {} stopped on signal {}\n", .{ full_exe_path, signum }); |
| 628 | printInvocation(args.toSliceConst()); | |
| 627 | printInvocation(args.span()); | |
| 629 | 628 | return error.TestFailed; |
| 630 | 629 | }, |
| 631 | 630 | .Unknown => |code| { |
| 632 | 631 | warn("Process {} terminated unexpectedly with error code {}\n", .{ full_exe_path, code }); |
| 633 | printInvocation(args.toSliceConst()); | |
| 632 | printInvocation(args.span()); | |
| 634 | 633 | return error.TestFailed; |
| 635 | 634 | }, |
| 636 | 635 | } |
| ... | ... | @@ -640,7 +639,7 @@ pub const StackTracesContext = struct { |
| 640 | 639 | // - replace address with symbolic string |
| 641 | 640 | // - skip empty lines |
| 642 | 641 | const got: []const u8 = got_result: { |
| 643 | var buf = try Buffer.initSize(b.allocator, 0); | |
| 642 | var buf = ArrayList(u8).init(b.allocator); | |
| 644 | 643 | defer buf.deinit(); |
| 645 | 644 | if (stderr.len != 0 and stderr[stderr.len - 1] == '\n') stderr = stderr[0 .. stderr.len - 1]; |
| 646 | 645 | var it = mem.separate(stderr, "\n"); |
| ... | ... | @@ -652,21 +651,21 @@ pub const StackTracesContext = struct { |
| 652 | 651 | var pos: usize = if (std.Target.current.os.tag == .windows) 2 else 0; |
| 653 | 652 | for (delims) |delim, i| { |
| 654 | 653 | marks[i] = mem.indexOfPos(u8, line, pos, delim) orelse { |
| 655 | try buf.append(line); | |
| 656 | try buf.append("\n"); | |
| 654 | try buf.appendSlice(line); | |
| 655 | try buf.appendSlice("\n"); | |
| 657 | 656 | continue :process_lines; |
| 658 | 657 | }; |
| 659 | 658 | pos = marks[i] + delim.len; |
| 660 | 659 | } |
| 661 | 660 | pos = mem.lastIndexOfScalar(u8, line[0..marks[0]], fs.path.sep) orelse { |
| 662 | try buf.append(line); | |
| 663 | try buf.append("\n"); | |
| 661 | try buf.appendSlice(line); | |
| 662 | try buf.appendSlice("\n"); | |
| 664 | 663 | continue :process_lines; |
| 665 | 664 | }; |
| 666 | try buf.append(line[pos + 1 .. marks[2] + delims[2].len]); | |
| 667 | try buf.append(" [address]"); | |
| 668 | try buf.append(line[marks[3]..]); | |
| 669 | try buf.append("\n"); | |
| 665 | try buf.appendSlice(line[pos + 1 .. marks[2] + delims[2].len]); | |
| 666 | try buf.appendSlice(" [address]"); | |
| 667 | try buf.appendSlice(line[marks[3]..]); | |
| 668 | try buf.appendSlice("\n"); | |
| 670 | 669 | } |
| 671 | 670 | break :got_result buf.toOwnedSlice(); |
| 672 | 671 | }; |
| ... | ... | @@ -785,7 +784,7 @@ pub const CompileErrorContext = struct { |
| 785 | 784 | } else { |
| 786 | 785 | try zig_args.append("build-obj"); |
| 787 | 786 | } |
| 788 | const root_src_basename = self.case.sources.toSliceConst()[0].filename; | |
| 787 | const root_src_basename = self.case.sources.span()[0].filename; | |
| 789 | 788 | try zig_args.append(self.write_src.getOutputPath(root_src_basename)); |
| 790 | 789 | |
| 791 | 790 | zig_args.append("--name") catch unreachable; |
| ... | ... | @@ -809,10 +808,10 @@ pub const CompileErrorContext = struct { |
| 809 | 808 | warn("Test {}/{} {}...", .{ self.test_index + 1, self.context.test_index, self.name }); |
| 810 | 809 | |
| 811 | 810 | if (b.verbose) { |
| 812 | printInvocation(zig_args.toSliceConst()); | |
| 811 | printInvocation(zig_args.span()); | |
| 813 | 812 | } |
| 814 | 813 | |
| 815 | const child = std.ChildProcess.init(zig_args.toSliceConst(), b.allocator) catch unreachable; | |
| 814 | const child = std.ChildProcess.init(zig_args.span(), b.allocator) catch unreachable; | |
| 816 | 815 | defer child.deinit(); |
| 817 | 816 | |
| 818 | 817 | child.env_map = b.env_map; |
| ... | ... | @@ -822,11 +821,11 @@ pub const CompileErrorContext = struct { |
| 822 | 821 | |
| 823 | 822 | child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", .{ zig_args.items[0], @errorName(err) }); |
| 824 | 823 | |
| 825 | var stdout_buf = Buffer.initNull(b.allocator); | |
| 826 | var stderr_buf = Buffer.initNull(b.allocator); | |
| 824 | var stdout_buf = ArrayList(u8).init(b.allocator); | |
| 825 | var stderr_buf = ArrayList(u8).init(b.allocator); | |
| 827 | 826 | |
| 828 | child.stdout.?.inStream().readAllBuffer(&stdout_buf, max_stdout_size) catch unreachable; | |
| 829 | child.stderr.?.inStream().readAllBuffer(&stderr_buf, max_stdout_size) catch unreachable; | |
| 827 | child.stdout.?.inStream().readAllArrayList(&stdout_buf, max_stdout_size) catch unreachable; | |
| 828 | child.stderr.?.inStream().readAllArrayList(&stderr_buf, max_stdout_size) catch unreachable; | |
| 830 | 829 | |
| 831 | 830 | const term = child.wait() catch |err| { |
| 832 | 831 | debug.panic("Unable to spawn {}: {}\n", .{ zig_args.items[0], @errorName(err) }); |
| ... | ... | @@ -834,19 +833,19 @@ pub const CompileErrorContext = struct { |
| 834 | 833 | switch (term) { |
| 835 | 834 | .Exited => |code| { |
| 836 | 835 | if (code == 0) { |
| 837 | printInvocation(zig_args.toSliceConst()); | |
| 836 | printInvocation(zig_args.span()); | |
| 838 | 837 | return error.CompilationIncorrectlySucceeded; |
| 839 | 838 | } |
| 840 | 839 | }, |
| 841 | 840 | else => { |
| 842 | 841 | warn("Process {} terminated unexpectedly\n", .{b.zig_exe}); |
| 843 | printInvocation(zig_args.toSliceConst()); | |
| 842 | printInvocation(zig_args.span()); | |
| 844 | 843 | return error.TestFailed; |
| 845 | 844 | }, |
| 846 | 845 | } |
| 847 | 846 | |
| 848 | const stdout = stdout_buf.toSliceConst(); | |
| 849 | const stderr = stderr_buf.toSliceConst(); | |
| 847 | const stdout = stdout_buf.span(); | |
| 848 | const stderr = stderr_buf.span(); | |
| 850 | 849 | |
| 851 | 850 | if (stdout.len != 0) { |
| 852 | 851 | warn( |
| ... | ... | @@ -875,12 +874,12 @@ pub const CompileErrorContext = struct { |
| 875 | 874 | |
| 876 | 875 | if (!ok) { |
| 877 | 876 | warn("\n======== Expected these compile errors: ========\n", .{}); |
| 878 | for (self.case.expected_errors.toSliceConst()) |expected| { | |
| 877 | for (self.case.expected_errors.span()) |expected| { | |
| 879 | 878 | warn("{}\n", .{expected}); |
| 880 | 879 | } |
| 881 | 880 | } |
| 882 | 881 | } else { |
| 883 | for (self.case.expected_errors.toSliceConst()) |expected| { | |
| 882 | for (self.case.expected_errors.span()) |expected| { | |
| 884 | 883 | if (mem.indexOf(u8, stderr, expected) == null) { |
| 885 | 884 | warn( |
| 886 | 885 | \\ |
| ... | ... | @@ -980,7 +979,7 @@ pub const CompileErrorContext = struct { |
| 980 | 979 | if (mem.indexOf(u8, annotated_case_name, filter) == null) return; |
| 981 | 980 | } |
| 982 | 981 | const write_src = b.addWriteFiles(); |
| 983 | for (case.sources.toSliceConst()) |src_file| { | |
| 982 | for (case.sources.span()) |src_file| { | |
| 984 | 983 | write_src.add(src_file.filename, src_file.source); |
| 985 | 984 | } |
| 986 | 985 | |
| ... | ... | @@ -1027,7 +1026,7 @@ pub const StandaloneContext = struct { |
| 1027 | 1026 | zig_args.append("--verbose") catch unreachable; |
| 1028 | 1027 | } |
| 1029 | 1028 | |
| 1030 | const run_cmd = b.addSystemCommand(zig_args.toSliceConst()); | |
| 1029 | const run_cmd = b.addSystemCommand(zig_args.span()); | |
| 1031 | 1030 | |
| 1032 | 1031 | const log_step = b.addLog("PASS {}\n", .{annotated_case_name}); |
| 1033 | 1032 | log_step.step.dependOn(&run_cmd.step); |
| ... | ... | @@ -1127,7 +1126,7 @@ pub const GenHContext = struct { |
| 1127 | 1126 | const full_h_path = self.obj.getOutputHPath(); |
| 1128 | 1127 | const actual_h = try io.readFileAlloc(b.allocator, full_h_path); |
| 1129 | 1128 | |
| 1130 | for (self.case.expected_lines.toSliceConst()) |expected_line| { | |
| 1129 | for (self.case.expected_lines.span()) |expected_line| { | |
| 1131 | 1130 | if (mem.indexOf(u8, actual_h, expected_line) == null) { |
| 1132 | 1131 | warn( |
| 1133 | 1132 | \\ |
| ... | ... | @@ -1188,7 +1187,7 @@ pub const GenHContext = struct { |
| 1188 | 1187 | } |
| 1189 | 1188 | |
| 1190 | 1189 | const write_src = b.addWriteFiles(); |
| 1191 | for (case.sources.toSliceConst()) |src_file| { | |
| 1190 | for (case.sources.span()) |src_file| { | |
| 1192 | 1191 | write_src.add(src_file.filename, src_file.source); |
| 1193 | 1192 | } |
| 1194 | 1193 |
test/translate_c.zig+39| ... | ... | @@ -2808,4 +2808,43 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2808 | 2808 | \\ return if (x > y) x else y; |
| 2809 | 2809 | \\} |
| 2810 | 2810 | }); |
| 2811 | ||
| 2812 | cases.add("string concatenation in macros", | |
| 2813 | \\#define FOO "hello" | |
| 2814 | \\#define BAR FOO " world" | |
| 2815 | \\#define BAZ "oh, " FOO | |
| 2816 | , &[_][]const u8{ | |
| 2817 | \\pub const FOO = "hello"; | |
| 2818 | , | |
| 2819 | \\pub const BAR = FOO ++ " world"; | |
| 2820 | , | |
| 2821 | \\pub const BAZ = "oh, " ++ FOO; | |
| 2822 | }); | |
| 2823 | ||
| 2824 | cases.add("string concatenation in macros: two defines", | |
| 2825 | \\#define FOO "hello" | |
| 2826 | \\#define BAZ " world" | |
| 2827 | \\#define BAR FOO BAZ | |
| 2828 | , &[_][]const u8{ | |
| 2829 | \\pub const FOO = "hello"; | |
| 2830 | , | |
| 2831 | \\pub const BAZ = " world"; | |
| 2832 | , | |
| 2833 | \\pub const BAR = FOO ++ BAZ; | |
| 2834 | }); | |
| 2835 | ||
| 2836 | cases.add("string concatenation in macros: two strings", | |
| 2837 | \\#define FOO "a" "b" | |
| 2838 | \\#define BAR FOO "c" | |
| 2839 | , &[_][]const u8{ | |
| 2840 | \\pub const FOO = "a" ++ "b"; | |
| 2841 | , | |
| 2842 | \\pub const BAR = FOO ++ "c"; | |
| 2843 | }); | |
| 2844 | ||
| 2845 | cases.add("string concatenation in macros: three strings", | |
| 2846 | \\#define FOO "a" "b" "c" | |
| 2847 | , &[_][]const u8{ | |
| 2848 | \\pub const FOO = "a" ++ ("b" ++ "c"); | |
| 2849 | }); | |
| 2811 | 2850 | } |
tools/merge_anal_dumps.zig+12-12| ... | ... | @@ -183,13 +183,13 @@ const Dump = struct { |
| 183 | 183 | try mergeSameStrings(&self.zig_version, zig_version); |
| 184 | 184 | try mergeSameStrings(&self.root_name, root_name); |
| 185 | 185 | |
| 186 | for (params.get("builds").?.value.Array.toSliceConst()) |json_build| { | |
| 186 | for (params.get("builds").?.value.Array.span()) |json_build| { | |
| 187 | 187 | const target = json_build.Object.get("target").?.value.String; |
| 188 | 188 | try self.targets.append(target); |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | // Merge files. If the string matches, it's the same file. |
| 192 | const other_files = root.Object.get("files").?.value.Array.toSliceConst(); | |
| 192 | const other_files = root.Object.get("files").?.value.Array.span(); | |
| 193 | 193 | var other_file_to_mine = std.AutoHashMap(usize, usize).init(self.a()); |
| 194 | 194 | for (other_files) |other_file, i| { |
| 195 | 195 | const gop = try self.file_map.getOrPut(other_file.String); |
| ... | ... | @@ -201,7 +201,7 @@ const Dump = struct { |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | // Merge AST nodes. If the file id, line, and column all match, it's the same AST node. |
| 204 | const other_ast_nodes = root.Object.get("astNodes").?.value.Array.toSliceConst(); | |
| 204 | const other_ast_nodes = root.Object.get("astNodes").?.value.Array.span(); | |
| 205 | 205 | var other_ast_node_to_mine = std.AutoHashMap(usize, usize).init(self.a()); |
| 206 | 206 | for (other_ast_nodes) |other_ast_node_json, i| { |
| 207 | 207 | const other_file_id = jsonObjInt(other_ast_node_json, "file"); |
| ... | ... | @@ -221,9 +221,9 @@ const Dump = struct { |
| 221 | 221 | // convert fields lists |
| 222 | 222 | for (other_ast_nodes) |other_ast_node_json, i| { |
| 223 | 223 | const my_node_index = other_ast_node_to_mine.get(i).?.value; |
| 224 | const my_node = &self.node_list.toSlice()[my_node_index]; | |
| 224 | const my_node = &self.node_list.span()[my_node_index]; | |
| 225 | 225 | if (other_ast_node_json.Object.get("fields")) |fields_json_kv| { |
| 226 | const other_fields = fields_json_kv.value.Array.toSliceConst(); | |
| 226 | const other_fields = fields_json_kv.value.Array.span(); | |
| 227 | 227 | my_node.fields = try self.a().alloc(usize, other_fields.len); |
| 228 | 228 | for (other_fields) |other_field_index, field_i| { |
| 229 | 229 | const other_index = @intCast(usize, other_field_index.Integer); |
| ... | ... | @@ -233,7 +233,7 @@ const Dump = struct { |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | // Merge errors. If the AST Node matches, it's the same error value. |
| 236 | const other_errors = root.Object.get("errors").?.value.Array.toSliceConst(); | |
| 236 | const other_errors = root.Object.get("errors").?.value.Array.span(); | |
| 237 | 237 | var other_error_to_mine = std.AutoHashMap(usize, usize).init(self.a()); |
| 238 | 238 | for (other_errors) |other_error_json, i| { |
| 239 | 239 | const other_src_id = jsonObjInt(other_error_json, "src"); |
| ... | ... | @@ -253,7 +253,7 @@ const Dump = struct { |
| 253 | 253 | // First we identify all the simple types and merge those. |
| 254 | 254 | // Example: void, type, noreturn |
| 255 | 255 | // We can also do integers and floats. |
| 256 | const other_types = root.Object.get("types").?.value.Array.toSliceConst(); | |
| 256 | const other_types = root.Object.get("types").?.value.Array.span(); | |
| 257 | 257 | var other_types_to_mine = std.AutoHashMap(usize, usize).init(self.a()); |
| 258 | 258 | for (other_types) |other_type_json, i| { |
| 259 | 259 | const type_kind = jsonObjInt(other_type_json, "kind"); |
| ... | ... | @@ -336,7 +336,7 @@ const Dump = struct { |
| 336 | 336 | |
| 337 | 337 | try jw.objectField("builds"); |
| 338 | 338 | try jw.beginArray(); |
| 339 | for (self.targets.toSliceConst()) |target| { | |
| 339 | for (self.targets.span()) |target| { | |
| 340 | 340 | try jw.arrayElem(); |
| 341 | 341 | try jw.beginObject(); |
| 342 | 342 | try jw.objectField("target"); |
| ... | ... | @@ -349,7 +349,7 @@ const Dump = struct { |
| 349 | 349 | |
| 350 | 350 | try jw.objectField("types"); |
| 351 | 351 | try jw.beginArray(); |
| 352 | for (self.type_list.toSliceConst()) |t| { | |
| 352 | for (self.type_list.span()) |t| { | |
| 353 | 353 | try jw.arrayElem(); |
| 354 | 354 | try jw.beginObject(); |
| 355 | 355 | |
| ... | ... | @@ -379,7 +379,7 @@ const Dump = struct { |
| 379 | 379 | |
| 380 | 380 | try jw.objectField("errors"); |
| 381 | 381 | try jw.beginArray(); |
| 382 | for (self.error_list.toSliceConst()) |zig_error| { | |
| 382 | for (self.error_list.span()) |zig_error| { | |
| 383 | 383 | try jw.arrayElem(); |
| 384 | 384 | try jw.beginObject(); |
| 385 | 385 | |
| ... | ... | @@ -395,7 +395,7 @@ const Dump = struct { |
| 395 | 395 | |
| 396 | 396 | try jw.objectField("astNodes"); |
| 397 | 397 | try jw.beginArray(); |
| 398 | for (self.node_list.toSliceConst()) |node| { | |
| 398 | for (self.node_list.span()) |node| { | |
| 399 | 399 | try jw.arrayElem(); |
| 400 | 400 | try jw.beginObject(); |
| 401 | 401 | |
| ... | ... | @@ -425,7 +425,7 @@ const Dump = struct { |
| 425 | 425 | |
| 426 | 426 | try jw.objectField("files"); |
| 427 | 427 | try jw.beginArray(); |
| 428 | for (self.file_list.toSliceConst()) |file| { | |
| 428 | for (self.file_list.span()) |file| { | |
| 429 | 429 | try jw.arrayElem(); |
| 430 | 430 | try jw.emitString(file); |
| 431 | 431 | } |
tools/process_headers.zig+4-4| ... | ... | @@ -324,7 +324,7 @@ pub fn main() !void { |
| 324 | 324 | }, |
| 325 | 325 | .os = .linux, |
| 326 | 326 | }; |
| 327 | search: for (search_paths.toSliceConst()) |search_path| { | |
| 327 | search: for (search_paths.span()) |search_path| { | |
| 328 | 328 | var sub_path: []const []const u8 = undefined; |
| 329 | 329 | switch (vendor) { |
| 330 | 330 | .musl => { |
| ... | ... | @@ -414,13 +414,13 @@ pub fn main() !void { |
| 414 | 414 | try contents_list.append(contents); |
| 415 | 415 | } |
| 416 | 416 | } |
| 417 | std.sort.sort(*Contents, contents_list.toSlice(), Contents.hitCountLessThan); | |
| 417 | std.sort.sort(*Contents, contents_list.span(), Contents.hitCountLessThan); | |
| 418 | 418 | var best_contents = contents_list.popOrNull().?; |
| 419 | 419 | if (best_contents.hit_count > 1) { |
| 420 | 420 | // worth it to make it generic |
| 421 | 421 | const full_path = try std.fs.path.join(allocator, &[_][]const u8{ out_dir, generic_name, path_kv.key }); |
| 422 | 422 | try std.fs.cwd().makePath(std.fs.path.dirname(full_path).?); |
| 423 | try std.io.writeFile(full_path, best_contents.bytes); | |
| 423 | try std.fs.cwd().writeFile(full_path, best_contents.bytes); | |
| 424 | 424 | best_contents.is_generic = true; |
| 425 | 425 | while (contents_list.popOrNull()) |contender| { |
| 426 | 426 | if (contender.hit_count > 1) { |
| ... | ... | @@ -447,7 +447,7 @@ pub fn main() !void { |
| 447 | 447 | }); |
| 448 | 448 | const full_path = try std.fs.path.join(allocator, &[_][]const u8{ out_dir, out_subpath, path_kv.key }); |
| 449 | 449 | try std.fs.cwd().makePath(std.fs.path.dirname(full_path).?); |
| 450 | try std.io.writeFile(full_path, contents.bytes); | |
| 450 | try std.fs.cwd().writeFile(full_path, contents.bytes); | |
| 451 | 451 | } |
| 452 | 452 | } |
| 453 | 453 | } |
tools/update_clang_options.zig+37-13| ... | ... | @@ -96,19 +96,19 @@ const known_options = [_]KnownOpt{ |
| 96 | 96 | }, |
| 97 | 97 | .{ |
| 98 | 98 | .name = "E", |
| 99 | .ident = "preprocess", | |
| 99 | .ident = "pp_or_asm", | |
| 100 | 100 | }, |
| 101 | 101 | .{ |
| 102 | 102 | .name = "preprocess", |
| 103 | .ident = "preprocess", | |
| 103 | .ident = "pp_or_asm", | |
| 104 | 104 | }, |
| 105 | 105 | .{ |
| 106 | 106 | .name = "S", |
| 107 | .ident = "driver_punt", | |
| 107 | .ident = "pp_or_asm", | |
| 108 | 108 | }, |
| 109 | 109 | .{ |
| 110 | 110 | .name = "assemble", |
| 111 | .ident = "driver_punt", | |
| 111 | .ident = "pp_or_asm", | |
| 112 | 112 | }, |
| 113 | 113 | .{ |
| 114 | 114 | .name = "O1", |
| ... | ... | @@ -175,20 +175,44 @@ const known_options = [_]KnownOpt{ |
| 175 | 175 | .ident = "verbose_cmds", |
| 176 | 176 | }, |
| 177 | 177 | .{ |
| 178 | .name = "fexceptions", | |
| 179 | .ident = "exceptions", | |
| 178 | .name = "L", | |
| 179 | .ident = "lib_dir", | |
| 180 | }, | |
| 181 | .{ | |
| 182 | .name = "library-directory", | |
| 183 | .ident = "lib_dir", | |
| 184 | }, | |
| 185 | .{ | |
| 186 | .name = "mcpu", | |
| 187 | .ident = "mcpu", | |
| 188 | }, | |
| 189 | .{ | |
| 190 | .name = "march", | |
| 191 | .ident = "mcpu", | |
| 192 | }, | |
| 193 | .{ | |
| 194 | .name = "mtune", | |
| 195 | .ident = "mcpu", | |
| 196 | }, | |
| 197 | .{ | |
| 198 | .name = "MD", | |
| 199 | .ident = "dep_file", | |
| 200 | }, | |
| 201 | .{ | |
| 202 | .name = "MV", | |
| 203 | .ident = "dep_file", | |
| 180 | 204 | }, |
| 181 | 205 | .{ |
| 182 | .name = "fno-exceptions", | |
| 183 | .ident = "no_exceptions", | |
| 206 | .name = "MF", | |
| 207 | .ident = "dep_file", | |
| 184 | 208 | }, |
| 185 | 209 | .{ |
| 186 | .name = "frtti", | |
| 187 | .ident = "rtti", | |
| 210 | .name = "F", | |
| 211 | .ident = "framework_dir", | |
| 188 | 212 | }, |
| 189 | 213 | .{ |
| 190 | .name = "fno-rtti", | |
| 191 | .ident = "no_rtti", | |
| 214 | .name = "framework", | |
| 215 | .ident = "framework", | |
| 192 | 216 | }, |
| 193 | 217 | }; |
| 194 | 218 | |
| ... | ... | @@ -239,7 +263,7 @@ pub fn main() anyerror!void { |
| 239 | 263 | try std.fmt.allocPrint(allocator, "-I={}/clang/include/clang/Driver", .{llvm_src_root}), |
| 240 | 264 | }; |
| 241 | 265 | |
| 242 | const child_result = try std.ChildProcess.exec2(.{ | |
| 266 | const child_result = try std.ChildProcess.exec(.{ | |
| 243 | 267 | .allocator = allocator, |
| 244 | 268 | .argv = &child_args, |
| 245 | 269 | .max_output_bytes = 100 * 1024 * 1024, |
tools/update_glibc.zig+7-7| ... | ... | @@ -223,15 +223,15 @@ pub fn main() !void { |
| 223 | 223 | var list = std.ArrayList([]const u8).init(allocator); |
| 224 | 224 | var it = global_fn_set.iterator(); |
| 225 | 225 | while (it.next()) |kv| try list.append(kv.key); |
| 226 | std.sort.sort([]const u8, list.toSlice(), strCmpLessThan); | |
| 227 | break :blk list.toSliceConst(); | |
| 226 | std.sort.sort([]const u8, list.span(), strCmpLessThan); | |
| 227 | break :blk list.span(); | |
| 228 | 228 | }; |
| 229 | 229 | const global_ver_list = blk: { |
| 230 | 230 | var list = std.ArrayList([]const u8).init(allocator); |
| 231 | 231 | var it = global_ver_set.iterator(); |
| 232 | 232 | while (it.next()) |kv| try list.append(kv.key); |
| 233 | std.sort.sort([]const u8, list.toSlice(), versionLessThan); | |
| 234 | break :blk list.toSliceConst(); | |
| 233 | std.sort.sort([]const u8, list.span(), versionLessThan); | |
| 234 | break :blk list.span(); | |
| 235 | 235 | }; |
| 236 | 236 | { |
| 237 | 237 | const vers_txt_path = try fs.path.join(allocator, &[_][]const u8{ glibc_out_dir, "vers.txt" }); |
| ... | ... | @@ -264,13 +264,13 @@ pub fn main() !void { |
| 264 | 264 | for (abi_lists) |*abi_list, abi_index| { |
| 265 | 265 | const kv = target_functions.get(@ptrToInt(abi_list)).?; |
| 266 | 266 | const fn_vers_list = &kv.value.fn_vers_list; |
| 267 | for (kv.value.list.toSliceConst()) |*ver_fn| { | |
| 267 | for (kv.value.list.span()) |*ver_fn| { | |
| 268 | 268 | const gop = try fn_vers_list.getOrPut(ver_fn.name); |
| 269 | 269 | if (!gop.found_existing) { |
| 270 | 270 | gop.kv.value = std.ArrayList(usize).init(allocator); |
| 271 | 271 | } |
| 272 | 272 | const ver_index = global_ver_set.get(ver_fn.ver).?.value; |
| 273 | if (std.mem.indexOfScalar(usize, gop.kv.value.toSliceConst(), ver_index) == null) { | |
| 273 | if (std.mem.indexOfScalar(usize, gop.kv.value.span(), ver_index) == null) { | |
| 274 | 274 | try gop.kv.value.append(ver_index); |
| 275 | 275 | } |
| 276 | 276 | } |
| ... | ... | @@ -297,7 +297,7 @@ pub fn main() !void { |
| 297 | 297 | try abilist_txt.writeByte('\n'); |
| 298 | 298 | continue; |
| 299 | 299 | }; |
| 300 | for (kv.value.toSliceConst()) |ver_index, it_i| { | |
| 300 | for (kv.value.span()) |ver_index, it_i| { | |
| 301 | 301 | if (it_i != 0) try abilist_txt.writeByte(' '); |
| 302 | 302 | try abilist_txt.print("{d}", .{ver_index}); |
| 303 | 303 | } |