| author | |
| committer | |
| log | 57f44eb2bd17fc0c4e9d09b8c8621867f784d2f0 |
| tree | 51f46cdc8f8ea0f4e642d62b3bf8fce58034362e |
| parent | 1fb15be05f1037aad53d2db32d13123363365d10 |
| parent | dd2450b1b21809c3fe62920498c318fbe519f579 |
| signature | Commit is signed but in an unrecognized format. |
Tier 2 support for FreeBSD31 files changed, 1896 insertions(+), 215 deletions(-)
CMakeLists.txt+5| ... | @@ -444,6 +444,7 @@ set(ZIG_STD_FILES | ... | @@ -444,6 +444,7 @@ set(ZIG_STD_FILES |
| 444 | "buffer.zig" | 444 | "buffer.zig" |
| 445 | "build.zig" | 445 | "build.zig" |
| 446 | "c/darwin.zig" | 446 | "c/darwin.zig" |
| 447 | "c/freebsd.zig" | ||
| 447 | "c/index.zig" | 448 | "c/index.zig" |
| 448 | "c/linux.zig" | 449 | "c/linux.zig" |
| 449 | "c/windows.zig" | 450 | "c/windows.zig" |
| ... | @@ -582,6 +583,10 @@ set(ZIG_STD_FILES | ... | @@ -582,6 +583,10 @@ set(ZIG_STD_FILES |
| 582 | "os/linux/vdso.zig" | 583 | "os/linux/vdso.zig" |
| 583 | "os/linux/x86_64.zig" | 584 | "os/linux/x86_64.zig" |
| 584 | "os/linux/arm64.zig" | 585 | "os/linux/arm64.zig" |
| 586 | "os/freebsd/errno.zig" | ||
| 587 | "os/freebsd/index.zig" | ||
| 588 | "os/freebsd/syscall.zig" | ||
| 589 | "os/freebsd/x86_64.zig" | ||
| 585 | "os/path.zig" | 590 | "os/path.zig" |
| 586 | "os/time.zig" | 591 | "os/time.zig" |
| 587 | "os/windows/advapi32.zig" | 592 | "os/windows/advapi32.zig" |
README.md+1-1| ... | @@ -89,7 +89,7 @@ clarity. | ... | @@ -89,7 +89,7 @@ clarity. |
| 89 | 89 | ||
| 90 | | | freestanding | linux | macosx | windows | freebsd | other | | 90 | | | freestanding | linux | macosx | windows | freebsd | other | |
| 91 | |--------|--------------|--------|--------|---------|---------|--------| | 91 | |--------|--------------|--------|--------|---------|---------|--------| |
| 92 | |x86_64 | Tier 2 | Tier 1 | Tier 1 | Tier 1 | Tier 3 | Tier 3 | | 92 | |x86_64 | Tier 2 | Tier 1 | Tier 1 | Tier 1 | Tier 2 | Tier 3 | |
| 93 | |i386 | Tier 2 | Tier 2 | Tier 2 | Tier 2 | Tier 3 | Tier 3 | | 93 | |i386 | Tier 2 | Tier 2 | Tier 2 | Tier 2 | Tier 3 | Tier 3 | |
| 94 | |arm | Tier 2 | Tier 3 | Tier 3 | Tier 3 | Tier 3 | Tier 3 | | 94 | |arm | Tier 2 | Tier 3 | Tier 3 | Tier 3 | Tier 3 | Tier 3 | |
| 95 | |arm64 | Tier 2 | Tier 2 | Tier 3 | Tier 3 | Tier 3 | Tier 3 | | 95 | |arm64 | Tier 2 | Tier 2 | Tier 3 | Tier 3 | Tier 3 | Tier 3 | |
build.zig+1-1| ... | @@ -297,7 +297,7 @@ fn configureStage2(b: *Builder, exe: var, ctx: Context) !void { | ... | @@ -297,7 +297,7 @@ fn configureStage2(b: *Builder, exe: var, ctx: Context) !void { |
| 297 | ); | 297 | ); |
| 298 | 298 | ||
| 299 | exe.linkSystemLibrary("pthread"); | 299 | exe.linkSystemLibrary("pthread"); |
| 300 | } else if (exe.target.isDarwin()) { | 300 | } else if (exe.target.isDarwin() or exe.target.isFreeBSD()) { |
| 301 | if (addCxxKnownPath(b, ctx, exe, "libgcc_eh.a", "")) { | 301 | if (addCxxKnownPath(b, ctx, exe, "libgcc_eh.a", "")) { |
| 302 | // Compiler is GCC. | 302 | // Compiler is GCC. |
| 303 | try addCxxKnownPath(b, ctx, exe, "libstdc++.a", null); | 303 | try addCxxKnownPath(b, ctx, exe, "libstdc++.a", null); |
cmake/Findclang.cmake+2| ... | @@ -30,6 +30,7 @@ else() | ... | @@ -30,6 +30,7 @@ else() |
| 30 | /usr/lib/llvm/7/include | 30 | /usr/lib/llvm/7/include |
| 31 | /usr/lib/llvm-7/include | 31 | /usr/lib/llvm-7/include |
| 32 | /usr/lib/llvm-7.0/include | 32 | /usr/lib/llvm-7.0/include |
| 33 | /usr/local/llvm70/include | ||
| 33 | /mingw64/include) | 34 | /mingw64/include) |
| 34 | 35 | ||
| 35 | macro(FIND_AND_ADD_CLANG_LIB _libname_) | 36 | macro(FIND_AND_ADD_CLANG_LIB _libname_) |
| ... | @@ -40,6 +41,7 @@ else() | ... | @@ -40,6 +41,7 @@ else() |
| 40 | /usr/lib/llvm/7/lib | 41 | /usr/lib/llvm/7/lib |
| 41 | /usr/lib/llvm-7/lib | 42 | /usr/lib/llvm-7/lib |
| 42 | /usr/lib/llvm-7.0/lib | 43 | /usr/lib/llvm-7.0/lib |
| 44 | /usr/local/llvm70/lib | ||
| 43 | /mingw64/lib | 45 | /mingw64/lib |
| 44 | /c/msys64/mingw64/lib | 46 | /c/msys64/mingw64/lib |
| 45 | c:\\msys64\\mingw64\\lib) | 47 | c:\\msys64\\mingw64\\lib) |
cmake/Findlld.cmake+8-3| ... | @@ -8,10 +8,14 @@ | ... | @@ -8,10 +8,14 @@ |
| 8 | 8 | ||
| 9 | find_path(LLD_INCLUDE_DIRS NAMES lld/Common/Driver.h | 9 | find_path(LLD_INCLUDE_DIRS NAMES lld/Common/Driver.h |
| 10 | PATHS | 10 | PATHS |
| 11 | /usr/lib/llvm-6.0/include | 11 | /usr/lib/llvm-7.0/include |
| 12 | /usr/local/llvm70/include | ||
| 12 | /mingw64/include) | 13 | /mingw64/include) |
| 13 | 14 | ||
| 14 | find_library(LLD_LIBRARY NAMES lld-6.0 lld PATHS /usr/lib/llvm-6.0/lib) | 15 | find_library(LLD_LIBRARY NAMES lld-7.0 lld70 lld |
| 16 | PATHS | ||
| 17 | /usr/lib/llvm-7.0/lib | ||
| 18 | /usr/local/llvm70/lib) | ||
| 15 | if(EXISTS ${LLD_LIBRARY}) | 19 | if(EXISTS ${LLD_LIBRARY}) |
| 16 | set(LLD_LIBRARIES ${LLD_LIBRARY}) | 20 | set(LLD_LIBRARIES ${LLD_LIBRARY}) |
| 17 | else() | 21 | else() |
| ... | @@ -19,7 +23,8 @@ else() | ... | @@ -19,7 +23,8 @@ else() |
| 19 | string(TOUPPER ${_libname_} _prettylibname_) | 23 | string(TOUPPER ${_libname_} _prettylibname_) |
| 20 | find_library(LLD_${_prettylibname_}_LIB NAMES ${_libname_} | 24 | find_library(LLD_${_prettylibname_}_LIB NAMES ${_libname_} |
| 21 | PATHS | 25 | PATHS |
| 22 | /usr/lib/llvm-6.0/lib | 26 | /usr/lib/llvm-7.0/lib |
| 27 | /usr/local/llvm70/lib | ||
| 23 | /mingw64/lib | 28 | /mingw64/lib |
| 24 | /c/msys64/mingw64/lib | 29 | /c/msys64/mingw64/lib |
| 25 | c:/msys64/mingw64/lib) | 30 | c:/msys64/mingw64/lib) |
cmake/Findllvm.cmake+1-1| ... | @@ -8,7 +8,7 @@ | ... | @@ -8,7 +8,7 @@ |
| 8 | # LLVM_LIBDIRS | 8 | # LLVM_LIBDIRS |
| 9 | 9 | ||
| 10 | find_program(LLVM_CONFIG_EXE | 10 | find_program(LLVM_CONFIG_EXE |
| 11 | NAMES llvm-config-7 llvm-config-7.0 llvm-config | 11 | NAMES llvm-config-7 llvm-config-7.0 llvm-config70 llvm-config |
| 12 | PATHS | 12 | PATHS |
| 13 | "/mingw64/bin" | 13 | "/mingw64/bin" |
| 14 | "/c/msys64/mingw64/bin" | 14 | "/c/msys64/mingw64/bin" |
src-self-hosted/libc_installation.zig+1-1| ... | @@ -172,7 +172,7 @@ pub const LibCInstallation = struct { | ... | @@ -172,7 +172,7 @@ pub const LibCInstallation = struct { |
| 172 | try group.call(findNativeStaticLibDir, self, loop); | 172 | try group.call(findNativeStaticLibDir, self, loop); |
| 173 | try group.call(findNativeDynamicLinker, self, loop); | 173 | try group.call(findNativeDynamicLinker, self, loop); |
| 174 | }, | 174 | }, |
| 175 | builtin.Os.macosx => { | 175 | builtin.Os.macosx, builtin.Os.freebsd => { |
| 176 | self.include_dir = try std.mem.dupe(loop.allocator, u8, "/usr/include"); | 176 | self.include_dir = try std.mem.dupe(loop.allocator, u8, "/usr/include"); |
| 177 | }, | 177 | }, |
| 178 | else => @compileError("unimplemented: find libc for this OS"), | 178 | else => @compileError("unimplemented: find libc for this OS"), |
src-self-hosted/target.zig+152-143| ... | @@ -299,152 +299,161 @@ pub const Target = union(enum) { | ... | @@ -299,152 +299,161 @@ pub const Target = union(enum) { |
| 299 | pub fn getDynamicLinkerPath(self: Target) ?[]const u8 { | 299 | pub fn getDynamicLinkerPath(self: Target) ?[]const u8 { |
| 300 | const env = self.getEnviron(); | 300 | const env = self.getEnviron(); |
| 301 | const arch = self.getArch(); | 301 | const arch = self.getArch(); |
| 302 | switch (env) { | 302 | const os = self.getOs(); |
| 303 | builtin.Environ.android => { | 303 | switch (os) { |
| 304 | if (self.is64bit()) { | 304 | builtin.Os.freebsd => { |
| 305 | return "/system/bin/linker64"; | 305 | return "/libexec/ld-elf.so.1"; |
| 306 | } else { | ||
| 307 | return "/system/bin/linker"; | ||
| 308 | } | ||
| 309 | }, | 306 | }, |
| 310 | builtin.Environ.gnux32 => { | 307 | builtin.Os.linux => { |
| 311 | if (arch == builtin.Arch.x86_64) { | 308 | switch (env) { |
| 312 | return "/libx32/ld-linux-x32.so.2"; | 309 | builtin.Environ.android => { |
| 310 | if (self.is64bit()) { | ||
| 311 | return "/system/bin/linker64"; | ||
| 312 | } else { | ||
| 313 | return "/system/bin/linker"; | ||
| 314 | } | ||
| 315 | }, | ||
| 316 | builtin.Environ.gnux32 => { | ||
| 317 | if (arch == builtin.Arch.x86_64) { | ||
| 318 | return "/libx32/ld-linux-x32.so.2"; | ||
| 319 | } | ||
| 320 | }, | ||
| 321 | builtin.Environ.musl, | ||
| 322 | builtin.Environ.musleabi, | ||
| 323 | builtin.Environ.musleabihf, | ||
| 324 | => { | ||
| 325 | if (arch == builtin.Arch.x86_64) { | ||
| 326 | return "/lib/ld-musl-x86_64.so.1"; | ||
| 327 | } | ||
| 328 | }, | ||
| 329 | else => {}, | ||
| 313 | } | 330 | } |
| 314 | }, | 331 | switch (arch) { |
| 315 | builtin.Environ.musl, | 332 | builtin.Arch.i386, |
| 316 | builtin.Environ.musleabi, | 333 | builtin.Arch.sparc, |
| 317 | builtin.Environ.musleabihf, | 334 | builtin.Arch.sparcel, |
| 318 | => { | 335 | => return "/lib/ld-linux.so.2", |
| 319 | if (arch == builtin.Arch.x86_64) { | 336 | |
| 320 | return "/lib/ld-musl-x86_64.so.1"; | 337 | builtin.Arch.aarch64v8_3a, |
| 338 | builtin.Arch.aarch64v8_2a, | ||
| 339 | builtin.Arch.aarch64v8_1a, | ||
| 340 | builtin.Arch.aarch64v8, | ||
| 341 | builtin.Arch.aarch64v8r, | ||
| 342 | builtin.Arch.aarch64v8m_baseline, | ||
| 343 | builtin.Arch.aarch64v8m_mainline, | ||
| 344 | => return "/lib/ld-linux-aarch64.so.1", | ||
| 345 | |||
| 346 | builtin.Arch.aarch64_bev8_3a, | ||
| 347 | builtin.Arch.aarch64_bev8_2a, | ||
| 348 | builtin.Arch.aarch64_bev8_1a, | ||
| 349 | builtin.Arch.aarch64_bev8, | ||
| 350 | builtin.Arch.aarch64_bev8r, | ||
| 351 | builtin.Arch.aarch64_bev8m_baseline, | ||
| 352 | builtin.Arch.aarch64_bev8m_mainline, | ||
| 353 | => return "/lib/ld-linux-aarch64_be.so.1", | ||
| 354 | |||
| 355 | builtin.Arch.armv8_3a, | ||
| 356 | builtin.Arch.armv8_2a, | ||
| 357 | builtin.Arch.armv8_1a, | ||
| 358 | builtin.Arch.armv8, | ||
| 359 | builtin.Arch.armv8r, | ||
| 360 | builtin.Arch.armv8m_baseline, | ||
| 361 | builtin.Arch.armv8m_mainline, | ||
| 362 | builtin.Arch.armv7, | ||
| 363 | builtin.Arch.armv7em, | ||
| 364 | builtin.Arch.armv7m, | ||
| 365 | builtin.Arch.armv7s, | ||
| 366 | builtin.Arch.armv7k, | ||
| 367 | builtin.Arch.armv7ve, | ||
| 368 | builtin.Arch.armv6, | ||
| 369 | builtin.Arch.armv6m, | ||
| 370 | builtin.Arch.armv6k, | ||
| 371 | builtin.Arch.armv6t2, | ||
| 372 | builtin.Arch.armv5, | ||
| 373 | builtin.Arch.armv5te, | ||
| 374 | builtin.Arch.armv4t, | ||
| 375 | builtin.Arch.thumb, | ||
| 376 | => return switch (self.getFloatAbi()) { | ||
| 377 | FloatAbi.Hard => return "/lib/ld-linux-armhf.so.3", | ||
| 378 | else => return "/lib/ld-linux.so.3", | ||
| 379 | }, | ||
| 380 | |||
| 381 | builtin.Arch.armebv8_3a, | ||
| 382 | builtin.Arch.armebv8_2a, | ||
| 383 | builtin.Arch.armebv8_1a, | ||
| 384 | builtin.Arch.armebv8, | ||
| 385 | builtin.Arch.armebv8r, | ||
| 386 | builtin.Arch.armebv8m_baseline, | ||
| 387 | builtin.Arch.armebv8m_mainline, | ||
| 388 | builtin.Arch.armebv7, | ||
| 389 | builtin.Arch.armebv7em, | ||
| 390 | builtin.Arch.armebv7m, | ||
| 391 | builtin.Arch.armebv7s, | ||
| 392 | builtin.Arch.armebv7k, | ||
| 393 | builtin.Arch.armebv7ve, | ||
| 394 | builtin.Arch.armebv6, | ||
| 395 | builtin.Arch.armebv6m, | ||
| 396 | builtin.Arch.armebv6k, | ||
| 397 | builtin.Arch.armebv6t2, | ||
| 398 | builtin.Arch.armebv5, | ||
| 399 | builtin.Arch.armebv5te, | ||
| 400 | builtin.Arch.armebv4t, | ||
| 401 | builtin.Arch.thumbeb, | ||
| 402 | => return switch (self.getFloatAbi()) { | ||
| 403 | FloatAbi.Hard => return "/lib/ld-linux-armhf.so.3", | ||
| 404 | else => return "/lib/ld-linux.so.3", | ||
| 405 | }, | ||
| 406 | |||
| 407 | builtin.Arch.mips, | ||
| 408 | builtin.Arch.mipsel, | ||
| 409 | builtin.Arch.mips64, | ||
| 410 | builtin.Arch.mips64el, | ||
| 411 | => return null, | ||
| 412 | |||
| 413 | builtin.Arch.powerpc => return "/lib/ld.so.1", | ||
| 414 | builtin.Arch.powerpc64 => return "/lib64/ld64.so.2", | ||
| 415 | builtin.Arch.powerpc64le => return "/lib64/ld64.so.2", | ||
| 416 | builtin.Arch.s390x => return "/lib64/ld64.so.1", | ||
| 417 | builtin.Arch.sparcv9 => return "/lib64/ld-linux.so.2", | ||
| 418 | builtin.Arch.x86_64 => return "/lib64/ld-linux-x86-64.so.2", | ||
| 419 | |||
| 420 | builtin.Arch.arc, | ||
| 421 | builtin.Arch.avr, | ||
| 422 | builtin.Arch.bpfel, | ||
| 423 | builtin.Arch.bpfeb, | ||
| 424 | builtin.Arch.hexagon, | ||
| 425 | builtin.Arch.msp430, | ||
| 426 | builtin.Arch.nios2, | ||
| 427 | builtin.Arch.r600, | ||
| 428 | builtin.Arch.amdgcn, | ||
| 429 | builtin.Arch.riscv32, | ||
| 430 | builtin.Arch.riscv64, | ||
| 431 | builtin.Arch.tce, | ||
| 432 | builtin.Arch.tcele, | ||
| 433 | builtin.Arch.xcore, | ||
| 434 | builtin.Arch.nvptx, | ||
| 435 | builtin.Arch.nvptx64, | ||
| 436 | builtin.Arch.le32, | ||
| 437 | builtin.Arch.le64, | ||
| 438 | builtin.Arch.amdil, | ||
| 439 | builtin.Arch.amdil64, | ||
| 440 | builtin.Arch.hsail, | ||
| 441 | builtin.Arch.hsail64, | ||
| 442 | builtin.Arch.spir, | ||
| 443 | builtin.Arch.spir64, | ||
| 444 | builtin.Arch.kalimbav3, | ||
| 445 | builtin.Arch.kalimbav4, | ||
| 446 | builtin.Arch.kalimbav5, | ||
| 447 | builtin.Arch.shave, | ||
| 448 | builtin.Arch.lanai, | ||
| 449 | builtin.Arch.wasm32, | ||
| 450 | builtin.Arch.wasm64, | ||
| 451 | builtin.Arch.renderscript32, | ||
| 452 | builtin.Arch.renderscript64, | ||
| 453 | => return null, | ||
| 321 | } | 454 | } |
| 322 | }, | 455 | }, |
| 323 | else => {}, | 456 | else => return null, |
| 324 | } | ||
| 325 | switch (arch) { | ||
| 326 | builtin.Arch.i386, | ||
| 327 | builtin.Arch.sparc, | ||
| 328 | builtin.Arch.sparcel, | ||
| 329 | => return "/lib/ld-linux.so.2", | ||
| 330 | |||
| 331 | builtin.Arch.aarch64v8_3a, | ||
| 332 | builtin.Arch.aarch64v8_2a, | ||
| 333 | builtin.Arch.aarch64v8_1a, | ||
| 334 | builtin.Arch.aarch64v8, | ||
| 335 | builtin.Arch.aarch64v8r, | ||
| 336 | builtin.Arch.aarch64v8m_baseline, | ||
| 337 | builtin.Arch.aarch64v8m_mainline, | ||
| 338 | => return "/lib/ld-linux-aarch64.so.1", | ||
| 339 | |||
| 340 | builtin.Arch.aarch64_bev8_3a, | ||
| 341 | builtin.Arch.aarch64_bev8_2a, | ||
| 342 | builtin.Arch.aarch64_bev8_1a, | ||
| 343 | builtin.Arch.aarch64_bev8, | ||
| 344 | builtin.Arch.aarch64_bev8r, | ||
| 345 | builtin.Arch.aarch64_bev8m_baseline, | ||
| 346 | builtin.Arch.aarch64_bev8m_mainline, | ||
| 347 | => return "/lib/ld-linux-aarch64_be.so.1", | ||
| 348 | |||
| 349 | builtin.Arch.armv8_3a, | ||
| 350 | builtin.Arch.armv8_2a, | ||
| 351 | builtin.Arch.armv8_1a, | ||
| 352 | builtin.Arch.armv8, | ||
| 353 | builtin.Arch.armv8r, | ||
| 354 | builtin.Arch.armv8m_baseline, | ||
| 355 | builtin.Arch.armv8m_mainline, | ||
| 356 | builtin.Arch.armv7, | ||
| 357 | builtin.Arch.armv7em, | ||
| 358 | builtin.Arch.armv7m, | ||
| 359 | builtin.Arch.armv7s, | ||
| 360 | builtin.Arch.armv7k, | ||
| 361 | builtin.Arch.armv7ve, | ||
| 362 | builtin.Arch.armv6, | ||
| 363 | builtin.Arch.armv6m, | ||
| 364 | builtin.Arch.armv6k, | ||
| 365 | builtin.Arch.armv6t2, | ||
| 366 | builtin.Arch.armv5, | ||
| 367 | builtin.Arch.armv5te, | ||
| 368 | builtin.Arch.armv4t, | ||
| 369 | builtin.Arch.thumb, | ||
| 370 | => return switch (self.getFloatAbi()) { | ||
| 371 | FloatAbi.Hard => return "/lib/ld-linux-armhf.so.3", | ||
| 372 | else => return "/lib/ld-linux.so.3", | ||
| 373 | }, | ||
| 374 | |||
| 375 | builtin.Arch.armebv8_3a, | ||
| 376 | builtin.Arch.armebv8_2a, | ||
| 377 | builtin.Arch.armebv8_1a, | ||
| 378 | builtin.Arch.armebv8, | ||
| 379 | builtin.Arch.armebv8r, | ||
| 380 | builtin.Arch.armebv8m_baseline, | ||
| 381 | builtin.Arch.armebv8m_mainline, | ||
| 382 | builtin.Arch.armebv7, | ||
| 383 | builtin.Arch.armebv7em, | ||
| 384 | builtin.Arch.armebv7m, | ||
| 385 | builtin.Arch.armebv7s, | ||
| 386 | builtin.Arch.armebv7k, | ||
| 387 | builtin.Arch.armebv7ve, | ||
| 388 | builtin.Arch.armebv6, | ||
| 389 | builtin.Arch.armebv6m, | ||
| 390 | builtin.Arch.armebv6k, | ||
| 391 | builtin.Arch.armebv6t2, | ||
| 392 | builtin.Arch.armebv5, | ||
| 393 | builtin.Arch.armebv5te, | ||
| 394 | builtin.Arch.armebv4t, | ||
| 395 | builtin.Arch.thumbeb, | ||
| 396 | => return switch (self.getFloatAbi()) { | ||
| 397 | FloatAbi.Hard => return "/lib/ld-linux-armhf.so.3", | ||
| 398 | else => return "/lib/ld-linux.so.3", | ||
| 399 | }, | ||
| 400 | |||
| 401 | builtin.Arch.mips, | ||
| 402 | builtin.Arch.mipsel, | ||
| 403 | builtin.Arch.mips64, | ||
| 404 | builtin.Arch.mips64el, | ||
| 405 | => return null, | ||
| 406 | |||
| 407 | builtin.Arch.powerpc => return "/lib/ld.so.1", | ||
| 408 | builtin.Arch.powerpc64 => return "/lib64/ld64.so.2", | ||
| 409 | builtin.Arch.powerpc64le => return "/lib64/ld64.so.2", | ||
| 410 | builtin.Arch.s390x => return "/lib64/ld64.so.1", | ||
| 411 | builtin.Arch.sparcv9 => return "/lib64/ld-linux.so.2", | ||
| 412 | builtin.Arch.x86_64 => return "/lib64/ld-linux-x86-64.so.2", | ||
| 413 | |||
| 414 | builtin.Arch.arc, | ||
| 415 | builtin.Arch.avr, | ||
| 416 | builtin.Arch.bpfel, | ||
| 417 | builtin.Arch.bpfeb, | ||
| 418 | builtin.Arch.hexagon, | ||
| 419 | builtin.Arch.msp430, | ||
| 420 | builtin.Arch.nios2, | ||
| 421 | builtin.Arch.r600, | ||
| 422 | builtin.Arch.amdgcn, | ||
| 423 | builtin.Arch.riscv32, | ||
| 424 | builtin.Arch.riscv64, | ||
| 425 | builtin.Arch.tce, | ||
| 426 | builtin.Arch.tcele, | ||
| 427 | builtin.Arch.xcore, | ||
| 428 | builtin.Arch.nvptx, | ||
| 429 | builtin.Arch.nvptx64, | ||
| 430 | builtin.Arch.le32, | ||
| 431 | builtin.Arch.le64, | ||
| 432 | builtin.Arch.amdil, | ||
| 433 | builtin.Arch.amdil64, | ||
| 434 | builtin.Arch.hsail, | ||
| 435 | builtin.Arch.hsail64, | ||
| 436 | builtin.Arch.spir, | ||
| 437 | builtin.Arch.spir64, | ||
| 438 | builtin.Arch.kalimbav3, | ||
| 439 | builtin.Arch.kalimbav4, | ||
| 440 | builtin.Arch.kalimbav5, | ||
| 441 | builtin.Arch.shave, | ||
| 442 | builtin.Arch.lanai, | ||
| 443 | builtin.Arch.wasm32, | ||
| 444 | builtin.Arch.wasm64, | ||
| 445 | builtin.Arch.renderscript32, | ||
| 446 | builtin.Arch.renderscript64, | ||
| 447 | => return null, | ||
| 448 | } | 457 | } |
| 449 | } | 458 | } |
| 450 | 459 | ||
| ... | @@ -493,6 +502,7 @@ pub const Target = union(enum) { | ... | @@ -493,6 +502,7 @@ pub const Target = union(enum) { |
| 493 | 502 | ||
| 494 | builtin.Os.linux, | 503 | builtin.Os.linux, |
| 495 | builtin.Os.macosx, | 504 | builtin.Os.macosx, |
| 505 | builtin.Os.freebsd, | ||
| 496 | builtin.Os.openbsd, | 506 | builtin.Os.openbsd, |
| 497 | builtin.Os.zen, | 507 | builtin.Os.zen, |
| 498 | => switch (id) { | 508 | => switch (id) { |
| ... | @@ -527,7 +537,6 @@ pub const Target = union(enum) { | ... | @@ -527,7 +537,6 @@ pub const Target = union(enum) { |
| 527 | builtin.Os.ananas, | 537 | builtin.Os.ananas, |
| 528 | builtin.Os.cloudabi, | 538 | builtin.Os.cloudabi, |
| 529 | builtin.Os.dragonfly, | 539 | builtin.Os.dragonfly, |
| 530 | builtin.Os.freebsd, | ||
| 531 | builtin.Os.fuchsia, | 540 | builtin.Os.fuchsia, |
| 532 | builtin.Os.ios, | 541 | builtin.Os.ios, |
| 533 | builtin.Os.kfreebsd, | 542 | builtin.Os.kfreebsd, |
src/analyze.cpp+8-1| ... | @@ -4591,7 +4591,10 @@ void find_libc_include_path(CodeGen *g) { | ... | @@ -4591,7 +4591,10 @@ void find_libc_include_path(CodeGen *g) { |
| 4591 | fprintf(stderr, "Unable to determine libc include path. --libc-include-dir"); | 4591 | fprintf(stderr, "Unable to determine libc include path. --libc-include-dir"); |
| 4592 | exit(1); | 4592 | exit(1); |
| 4593 | } | 4593 | } |
| 4594 | } else if (g->zig_target.os == OsLinux || g->zig_target.os == OsMacOSX) { | 4594 | } else if (g->zig_target.os == OsLinux || |
| 4595 | g->zig_target.os == OsMacOSX || | ||
| 4596 | g->zig_target.os == OsFreeBSD) | ||
| 4597 | { | ||
| 4595 | g->libc_include_dir = get_posix_libc_include_path(); | 4598 | g->libc_include_dir = get_posix_libc_include_path(); |
| 4596 | } else { | 4599 | } else { |
| 4597 | fprintf(stderr, "Unable to determine libc include path.\n" | 4600 | fprintf(stderr, "Unable to determine libc include path.\n" |
| ... | @@ -4639,6 +4642,8 @@ void find_libc_lib_path(CodeGen *g) { | ... | @@ -4639,6 +4642,8 @@ void find_libc_lib_path(CodeGen *g) { |
| 4639 | 4642 | ||
| 4640 | } else if (g->zig_target.os == OsLinux) { | 4643 | } else if (g->zig_target.os == OsLinux) { |
| 4641 | g->libc_lib_dir = get_linux_libc_lib_path("crt1.o"); | 4644 | g->libc_lib_dir = get_linux_libc_lib_path("crt1.o"); |
| 4645 | } else if (g->zig_target.os == OsFreeBSD) { | ||
| 4646 | g->libc_lib_dir = buf_create_from_str("/usr/lib"); | ||
| 4642 | } else { | 4647 | } else { |
| 4643 | zig_panic("Unable to determine libc lib path."); | 4648 | zig_panic("Unable to determine libc lib path."); |
| 4644 | } | 4649 | } |
| ... | @@ -4651,6 +4656,8 @@ void find_libc_lib_path(CodeGen *g) { | ... | @@ -4651,6 +4656,8 @@ void find_libc_lib_path(CodeGen *g) { |
| 4651 | return; | 4656 | return; |
| 4652 | } else if (g->zig_target.os == OsLinux) { | 4657 | } else if (g->zig_target.os == OsLinux) { |
| 4653 | g->libc_static_lib_dir = get_linux_libc_lib_path("crtbegin.o"); | 4658 | g->libc_static_lib_dir = get_linux_libc_lib_path("crtbegin.o"); |
| 4659 | } else if (g->zig_target.os == OsFreeBSD) { | ||
| 4660 | g->libc_static_lib_dir = buf_create_from_str("/usr/lib"); | ||
| 4654 | } else { | 4661 | } else { |
| 4655 | zig_panic("Unable to determine libc static lib path."); | 4662 | zig_panic("Unable to determine libc static lib path."); |
| 4656 | } | 4663 | } |
src/link.cpp+7| ... | @@ -150,6 +150,10 @@ static const char *getLDMOption(const ZigTarget *t) { | ... | @@ -150,6 +150,10 @@ static const char *getLDMOption(const ZigTarget *t) { |
| 150 | if (t->env_type == ZigLLVM_GNUX32) { | 150 | if (t->env_type == ZigLLVM_GNUX32) { |
| 151 | return "elf32_x86_64"; | 151 | return "elf32_x86_64"; |
| 152 | } | 152 | } |
| 153 | // Any target elf will use the freebsd osabi if suffixed with "_fbsd". | ||
| 154 | if (t->os == OsFreeBSD) { | ||
| 155 | return "elf_x86_64_fbsd"; | ||
| 156 | } | ||
| 153 | return "elf_x86_64"; | 157 | return "elf_x86_64"; |
| 154 | default: | 158 | default: |
| 155 | zig_unreachable(); | 159 | zig_unreachable(); |
| ... | @@ -191,6 +195,9 @@ static Buf *try_dynamic_linker_path(const char *ld_name) { | ... | @@ -191,6 +195,9 @@ static Buf *try_dynamic_linker_path(const char *ld_name) { |
| 191 | } | 195 | } |
| 192 | 196 | ||
| 193 | static Buf *get_dynamic_linker_path(CodeGen *g) { | 197 | static Buf *get_dynamic_linker_path(CodeGen *g) { |
| 198 | if (g->zig_target.os == OsFreeBSD) { | ||
| 199 | return buf_create_from_str("/libexec/ld-elf.so.1"); | ||
| 200 | } | ||
| 194 | if (g->is_native_target && g->zig_target.arch.arch == ZigLLVM_x86_64) { | 201 | if (g->is_native_target && g->zig_target.arch.arch == ZigLLVM_x86_64) { |
| 195 | static const char *ld_names[] = { | 202 | static const char *ld_names[] = { |
| 196 | "ld-linux-x86-64.so.2", | 203 | "ld-linux-x86-64.so.2", |
src/os.cpp+20-6| ... | @@ -50,10 +50,13 @@ typedef SSIZE_T ssize_t; | ... | @@ -50,10 +50,13 @@ typedef SSIZE_T ssize_t; |
| 50 | 50 | ||
| 51 | #endif | 51 | #endif |
| 52 | 52 | ||
| 53 | #if defined(ZIG_OS_LINUX) | 53 | #if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) |
| 54 | #include <link.h> | 54 | #include <link.h> |
| 55 | #endif | 55 | #endif |
| 56 | 56 | ||
| 57 | #if defined(ZIG_OS_FREEBSD) | ||
| 58 | #include <sys/sysctl.h> | ||
| 59 | #endif | ||
| 57 | 60 | ||
| 58 | #if defined(__MACH__) | 61 | #if defined(__MACH__) |
| 59 | #include <mach/clock.h> | 62 | #include <mach/clock.h> |
| ... | @@ -75,7 +78,9 @@ static clock_serv_t cclock; | ... | @@ -75,7 +78,9 @@ static clock_serv_t cclock; |
| 75 | #if defined(__APPLE__) && !defined(environ) | 78 | #if defined(__APPLE__) && !defined(environ) |
| 76 | #include <crt_externs.h> | 79 | #include <crt_externs.h> |
| 77 | #define environ (*_NSGetEnviron()) | 80 | #define environ (*_NSGetEnviron()) |
| 78 | #endif | 81 | #elif defined(ZIG_OS_FREEBSD) |
| 82 | extern char **environ; | ||
| 83 | #endif | ||
| 79 | 84 | ||
| 80 | #if defined(ZIG_OS_POSIX) | 85 | #if defined(ZIG_OS_POSIX) |
| 81 | static void populate_termination(Termination *term, int status) { | 86 | static void populate_termination(Termination *term, int status) { |
| ... | @@ -1444,6 +1449,15 @@ Error os_self_exe_path(Buf *out_path) { | ... | @@ -1444,6 +1449,15 @@ Error os_self_exe_path(Buf *out_path) { |
| 1444 | } | 1449 | } |
| 1445 | buf_resize(out_path, amt); | 1450 | buf_resize(out_path, amt); |
| 1446 | return ErrorNone; | 1451 | return ErrorNone; |
| 1452 | #elif defined(ZIG_OS_FREEBSD) | ||
| 1453 | buf_resize(out_path, PATH_MAX); | ||
| 1454 | int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; | ||
| 1455 | size_t cb = PATH_MAX; | ||
| 1456 | if (sysctl(mib, 4, buf_ptr(out_path), &cb, nullptr, 0) != 0) { | ||
| 1457 | return ErrorUnexpected; | ||
| 1458 | } | ||
| 1459 | buf_resize(out_path, cb); | ||
| 1460 | return ErrorNone; | ||
| 1447 | #endif | 1461 | #endif |
| 1448 | return ErrorFileNotFound; | 1462 | return ErrorFileNotFound; |
| 1449 | } | 1463 | } |
| ... | @@ -1749,7 +1763,7 @@ Error os_get_app_data_dir(Buf *out_path, const char *appname) { | ... | @@ -1749,7 +1763,7 @@ Error os_get_app_data_dir(Buf *out_path, const char *appname) { |
| 1749 | buf_resize(out_path, 0); | 1763 | buf_resize(out_path, 0); |
| 1750 | buf_appendf(out_path, "%s/Library/Application Support/%s", home_dir, appname); | 1764 | buf_appendf(out_path, "%s/Library/Application Support/%s", home_dir, appname); |
| 1751 | return ErrorNone; | 1765 | return ErrorNone; |
| 1752 | #elif defined(ZIG_OS_LINUX) | 1766 | #elif defined(ZIG_OS_POSIX) |
| 1753 | const char *home_dir = getenv("HOME"); | 1767 | const char *home_dir = getenv("HOME"); |
| 1754 | if (home_dir == nullptr) { | 1768 | if (home_dir == nullptr) { |
| 1755 | // TODO use /etc/passwd | 1769 | // TODO use /etc/passwd |
| ... | @@ -1762,7 +1776,7 @@ Error os_get_app_data_dir(Buf *out_path, const char *appname) { | ... | @@ -1762,7 +1776,7 @@ Error os_get_app_data_dir(Buf *out_path, const char *appname) { |
| 1762 | } | 1776 | } |
| 1763 | 1777 | ||
| 1764 | 1778 | ||
| 1765 | #if defined(ZIG_OS_LINUX) | 1779 | #if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) |
| 1766 | static int self_exe_shared_libs_callback(struct dl_phdr_info *info, size_t size, void *data) { | 1780 | static int self_exe_shared_libs_callback(struct dl_phdr_info *info, size_t size, void *data) { |
| 1767 | ZigList<Buf *> *libs = reinterpret_cast< ZigList<Buf *> *>(data); | 1781 | ZigList<Buf *> *libs = reinterpret_cast< ZigList<Buf *> *>(data); |
| 1768 | if (info->dlpi_name[0] == '/') { | 1782 | if (info->dlpi_name[0] == '/') { |
| ... | @@ -1773,7 +1787,7 @@ static int self_exe_shared_libs_callback(struct dl_phdr_info *info, size_t size, | ... | @@ -1773,7 +1787,7 @@ static int self_exe_shared_libs_callback(struct dl_phdr_info *info, size_t size, |
| 1773 | #endif | 1787 | #endif |
| 1774 | 1788 | ||
| 1775 | Error os_self_exe_shared_libs(ZigList<Buf *> &paths) { | 1789 | Error os_self_exe_shared_libs(ZigList<Buf *> &paths) { |
| 1776 | #if defined(ZIG_OS_LINUX) | 1790 | #if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) |
| 1777 | paths.resize(0); | 1791 | paths.resize(0); |
| 1778 | dl_iterate_phdr(self_exe_shared_libs_callback, &paths); | 1792 | dl_iterate_phdr(self_exe_shared_libs_callback, &paths); |
| 1779 | return ErrorNone; | 1793 | return ErrorNone; |
| ... | @@ -1942,7 +1956,7 @@ Error os_file_mtime(OsFile file, OsTimeStamp *mtime) { | ... | @@ -1942,7 +1956,7 @@ Error os_file_mtime(OsFile file, OsTimeStamp *mtime) { |
| 1942 | mtime->sec = (((ULONGLONG) last_write_time.dwHighDateTime) << 32) + last_write_time.dwLowDateTime; | 1956 | mtime->sec = (((ULONGLONG) last_write_time.dwHighDateTime) << 32) + last_write_time.dwLowDateTime; |
| 1943 | mtime->nsec = 0; | 1957 | mtime->nsec = 0; |
| 1944 | return ErrorNone; | 1958 | return ErrorNone; |
| 1945 | #elif defined(ZIG_OS_LINUX) | 1959 | #elif defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) |
| 1946 | struct stat statbuf; | 1960 | struct stat statbuf; |
| 1947 | if (fstat(file, &statbuf) == -1) | 1961 | if (fstat(file, &statbuf) == -1) |
| 1948 | return ErrorFileSystem; | 1962 | return ErrorFileSystem; |
src/os.hpp+2| ... | @@ -23,6 +23,8 @@ | ... | @@ -23,6 +23,8 @@ |
| 23 | #define ZIG_OS_WINDOWS | 23 | #define ZIG_OS_WINDOWS |
| 24 | #elif defined(__linux__) | 24 | #elif defined(__linux__) |
| 25 | #define ZIG_OS_LINUX | 25 | #define ZIG_OS_LINUX |
| 26 | #elif defined(__FreeBSD__) | ||
| 27 | #define ZIG_OS_FREEBSD | ||
| 26 | #else | 28 | #else |
| 27 | #define ZIG_OS_UNKNOWN | 29 | #define ZIG_OS_UNKNOWN |
| 28 | #endif | 30 | #endif |
src/target.cpp+1-1| ... | @@ -738,6 +738,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) { | ... | @@ -738,6 +738,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) { |
| 738 | case OsLinux: | 738 | case OsLinux: |
| 739 | case OsMacOSX: | 739 | case OsMacOSX: |
| 740 | case OsZen: | 740 | case OsZen: |
| 741 | case OsFreeBSD: | ||
| 741 | case OsOpenBSD: | 742 | case OsOpenBSD: |
| 742 | switch (id) { | 743 | switch (id) { |
| 743 | case CIntTypeShort: | 744 | case CIntTypeShort: |
| ... | @@ -774,7 +775,6 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) { | ... | @@ -774,7 +775,6 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) { |
| 774 | case OsAnanas: | 775 | case OsAnanas: |
| 775 | case OsCloudABI: | 776 | case OsCloudABI: |
| 776 | case OsDragonFly: | 777 | case OsDragonFly: |
| 777 | case OsFreeBSD: | ||
| 778 | case OsIOS: | 778 | case OsIOS: |
| 779 | case OsKFreeBSD: | 779 | case OsKFreeBSD: |
| 780 | case OsLv2: | 780 | case OsLv2: |
std/build.zig+7| ... | @@ -795,6 +795,13 @@ pub const Target = union(enum) { | ... | @@ -795,6 +795,13 @@ pub const Target = union(enum) { |
| 795 | }; | 795 | }; |
| 796 | } | 796 | } |
| 797 | 797 | ||
| 798 | pub fn isFreeBSD(self: *const Target) bool { | ||
| 799 | return switch (self.getOs()) { | ||
| 800 | builtin.Os.freebsd => true, | ||
| 801 | else => false, | ||
| 802 | }; | ||
| 803 | } | ||
| 804 | |||
| 798 | pub fn wantSharedLibSymLinks(self: *const Target) bool { | 805 | pub fn wantSharedLibSymLinks(self: *const Target) bool { |
| 799 | return !self.isWindows(); | 806 | return !self.isWindows(); |
| 800 | } | 807 | } |
std/c/freebsd.zig created+33| ... | @@ -0,0 +1,33 @@ | ||
| 1 | const timespec = @import("../os/freebsd/index.zig").timespec; | ||
| 2 | |||
| 3 | extern "c" fn __error() *c_int; | ||
| 4 | pub const _errno = __error; | ||
| 5 | |||
| 6 | pub extern "c" fn kqueue() c_int; | ||
| 7 | pub extern "c" fn kevent( | ||
| 8 | kq: c_int, | ||
| 9 | changelist: [*]const Kevent, | ||
| 10 | nchanges: c_int, | ||
| 11 | eventlist: [*]Kevent, | ||
| 12 | nevents: c_int, | ||
| 13 | timeout: ?*const timespec, | ||
| 14 | ) c_int; | ||
| 15 | pub extern "c" fn sysctl(name: [*]c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int; | ||
| 16 | pub extern "c" fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int; | ||
| 17 | pub extern "c" fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) c_int; | ||
| 18 | |||
| 19 | /// Renamed from `kevent` to `Kevent` to avoid conflict with function name. | ||
| 20 | pub const Kevent = extern struct { | ||
| 21 | ident: usize, | ||
| 22 | filter: i16, | ||
| 23 | flags: u16, | ||
| 24 | fflags: u32, | ||
| 25 | data: i64, | ||
| 26 | udata: usize, | ||
| 27 | // TODO ext | ||
| 28 | }; | ||
| 29 | |||
| 30 | pub const pthread_attr_t = extern struct { | ||
| 31 | __size: [56]u8, | ||
| 32 | __align: c_long, | ||
| 33 | }; | ||
std/c/index.zig+1| ... | @@ -5,6 +5,7 @@ pub use switch (builtin.os) { | ... | @@ -5,6 +5,7 @@ pub use switch (builtin.os) { |
| 5 | Os.linux => @import("linux.zig"), | 5 | Os.linux => @import("linux.zig"), |
| 6 | Os.windows => @import("windows.zig"), | 6 | Os.windows => @import("windows.zig"), |
| 7 | Os.macosx, Os.ios => @import("darwin.zig"), | 7 | Os.macosx, Os.ios => @import("darwin.zig"), |
| 8 | Os.freebsd => @import("freebsd.zig"), | ||
| 8 | else => empty_import, | 9 | else => empty_import, |
| 9 | }; | 10 | }; |
| 10 | const empty_import = @import("../empty.zig"); | 11 | const empty_import = @import("../empty.zig"); |
std/debug/index.zig+1| ... | @@ -1102,6 +1102,7 @@ pub const DebugInfo = switch (builtin.os) { | ... | @@ -1102,6 +1102,7 @@ pub const DebugInfo = switch (builtin.os) { |
| 1102 | self.elf.close(); | 1102 | self.elf.close(); |
| 1103 | } | 1103 | } |
| 1104 | }, | 1104 | }, |
| 1105 | builtin.Os.freebsd => struct {}, | ||
| 1105 | else => @compileError("Unsupported OS"), | 1106 | else => @compileError("Unsupported OS"), |
| 1106 | }; | 1107 | }; |
| 1107 | 1108 |
std/event/fs.zig+21-10| ... | @@ -83,6 +83,7 @@ pub async fn pwritev(loop: *Loop, fd: os.FileHandle, data: []const []const u8, o | ... | @@ -83,6 +83,7 @@ pub async fn pwritev(loop: *Loop, fd: os.FileHandle, data: []const []const u8, o |
| 83 | switch (builtin.os) { | 83 | switch (builtin.os) { |
| 84 | builtin.Os.macosx, | 84 | builtin.Os.macosx, |
| 85 | builtin.Os.linux, | 85 | builtin.Os.linux, |
| 86 | builtin.Os.freebsd, | ||
| 86 | => { | 87 | => { |
| 87 | const iovecs = try loop.allocator.alloc(os.posix.iovec_const, data.len); | 88 | const iovecs = try loop.allocator.alloc(os.posix.iovec_const, data.len); |
| 88 | defer loop.allocator.free(iovecs); | 89 | defer loop.allocator.free(iovecs); |
| ... | @@ -219,6 +220,7 @@ pub async fn preadv(loop: *Loop, fd: os.FileHandle, data: []const []u8, offset: | ... | @@ -219,6 +220,7 @@ pub async fn preadv(loop: *Loop, fd: os.FileHandle, data: []const []u8, offset: |
| 219 | switch (builtin.os) { | 220 | switch (builtin.os) { |
| 220 | builtin.Os.macosx, | 221 | builtin.Os.macosx, |
| 221 | builtin.Os.linux, | 222 | builtin.Os.linux, |
| 223 | builtin.Os.freebsd, | ||
| 222 | => { | 224 | => { |
| 223 | const iovecs = try loop.allocator.alloc(os.posix.iovec, data.len); | 225 | const iovecs = try loop.allocator.alloc(os.posix.iovec, data.len); |
| 224 | defer loop.allocator.free(iovecs); | 226 | defer loop.allocator.free(iovecs); |
| ... | @@ -399,7 +401,7 @@ pub async fn openPosix( | ... | @@ -399,7 +401,7 @@ pub async fn openPosix( |
| 399 | 401 | ||
| 400 | pub async fn openRead(loop: *Loop, path: []const u8) os.File.OpenError!os.FileHandle { | 402 | pub async fn openRead(loop: *Loop, path: []const u8) os.File.OpenError!os.FileHandle { |
| 401 | switch (builtin.os) { | 403 | switch (builtin.os) { |
| 402 | builtin.Os.macosx, builtin.Os.linux => { | 404 | builtin.Os.macosx, builtin.Os.linux, builtin.Os.freebsd => { |
| 403 | const flags = posix.O_LARGEFILE | posix.O_RDONLY | posix.O_CLOEXEC; | 405 | const flags = posix.O_LARGEFILE | posix.O_RDONLY | posix.O_CLOEXEC; |
| 404 | return await (async openPosix(loop, path, flags, os.File.default_mode) catch unreachable); | 406 | return await (async openPosix(loop, path, flags, os.File.default_mode) catch unreachable); |
| 405 | }, | 407 | }, |
| ... | @@ -427,6 +429,7 @@ pub async fn openWriteMode(loop: *Loop, path: []const u8, mode: os.File.Mode) os | ... | @@ -427,6 +429,7 @@ pub async fn openWriteMode(loop: *Loop, path: []const u8, mode: os.File.Mode) os |
| 427 | switch (builtin.os) { | 429 | switch (builtin.os) { |
| 428 | builtin.Os.macosx, | 430 | builtin.Os.macosx, |
| 429 | builtin.Os.linux, | 431 | builtin.Os.linux, |
| 432 | builtin.Os.freebsd, | ||
| 430 | => { | 433 | => { |
| 431 | const flags = posix.O_LARGEFILE | posix.O_WRONLY | posix.O_CREAT | posix.O_CLOEXEC | posix.O_TRUNC; | 434 | const flags = posix.O_LARGEFILE | posix.O_WRONLY | posix.O_CREAT | posix.O_CLOEXEC | posix.O_TRUNC; |
| 432 | return await (async openPosix(loop, path, flags, os.File.default_mode) catch unreachable); | 435 | return await (async openPosix(loop, path, flags, os.File.default_mode) catch unreachable); |
| ... | @@ -449,7 +452,7 @@ pub async fn openReadWrite( | ... | @@ -449,7 +452,7 @@ pub async fn openReadWrite( |
| 449 | mode: os.File.Mode, | 452 | mode: os.File.Mode, |
| 450 | ) os.File.OpenError!os.FileHandle { | 453 | ) os.File.OpenError!os.FileHandle { |
| 451 | switch (builtin.os) { | 454 | switch (builtin.os) { |
| 452 | builtin.Os.macosx, builtin.Os.linux => { | 455 | builtin.Os.macosx, builtin.Os.linux, builtin.Os.freebsd => { |
| 453 | const flags = posix.O_LARGEFILE | posix.O_RDWR | posix.O_CREAT | posix.O_CLOEXEC; | 456 | const flags = posix.O_LARGEFILE | posix.O_RDWR | posix.O_CREAT | posix.O_CLOEXEC; |
| 454 | return await (async openPosix(loop, path, flags, mode) catch unreachable); | 457 | return await (async openPosix(loop, path, flags, mode) catch unreachable); |
| 455 | }, | 458 | }, |
| ... | @@ -477,7 +480,7 @@ pub const CloseOperation = struct { | ... | @@ -477,7 +480,7 @@ pub const CloseOperation = struct { |
| 477 | os_data: OsData, | 480 | os_data: OsData, |
| 478 | 481 | ||
| 479 | const OsData = switch (builtin.os) { | 482 | const OsData = switch (builtin.os) { |
| 480 | builtin.Os.linux, builtin.Os.macosx => OsDataPosix, | 483 | builtin.Os.linux, builtin.Os.macosx, builtin.Os.freebsd => OsDataPosix, |
| 481 | 484 | ||
| 482 | builtin.Os.windows => struct { | 485 | builtin.Os.windows => struct { |
| 483 | handle: ?os.FileHandle, | 486 | handle: ?os.FileHandle, |
| ... | @@ -496,7 +499,7 @@ pub const CloseOperation = struct { | ... | @@ -496,7 +499,7 @@ pub const CloseOperation = struct { |
| 496 | self.* = CloseOperation{ | 499 | self.* = CloseOperation{ |
| 497 | .loop = loop, | 500 | .loop = loop, |
| 498 | .os_data = switch (builtin.os) { | 501 | .os_data = switch (builtin.os) { |
| 499 | builtin.Os.linux, builtin.Os.macosx => initOsDataPosix(self), | 502 | builtin.Os.linux, builtin.Os.macosx, builtin.Os.freebsd => initOsDataPosix(self), |
| 500 | builtin.Os.windows => OsData{ .handle = null }, | 503 | builtin.Os.windows => OsData{ .handle = null }, |
| 501 | else => @compileError("Unsupported OS"), | 504 | else => @compileError("Unsupported OS"), |
| 502 | }, | 505 | }, |
| ... | @@ -525,6 +528,7 @@ pub const CloseOperation = struct { | ... | @@ -525,6 +528,7 @@ pub const CloseOperation = struct { |
| 525 | switch (builtin.os) { | 528 | switch (builtin.os) { |
| 526 | builtin.Os.linux, | 529 | builtin.Os.linux, |
| 527 | builtin.Os.macosx, | 530 | builtin.Os.macosx, |
| 531 | builtin.Os.freebsd, | ||
| 528 | => { | 532 | => { |
| 529 | if (self.os_data.have_fd) { | 533 | if (self.os_data.have_fd) { |
| 530 | self.loop.posixFsRequest(&self.os_data.close_req_node); | 534 | self.loop.posixFsRequest(&self.os_data.close_req_node); |
| ... | @@ -546,6 +550,7 @@ pub const CloseOperation = struct { | ... | @@ -546,6 +550,7 @@ pub const CloseOperation = struct { |
| 546 | switch (builtin.os) { | 550 | switch (builtin.os) { |
| 547 | builtin.Os.linux, | 551 | builtin.Os.linux, |
| 548 | builtin.Os.macosx, | 552 | builtin.Os.macosx, |
| 553 | builtin.Os.freebsd, | ||
| 549 | => { | 554 | => { |
| 550 | self.os_data.close_req_node.data.msg.Close.fd = handle; | 555 | self.os_data.close_req_node.data.msg.Close.fd = handle; |
| 551 | self.os_data.have_fd = true; | 556 | self.os_data.have_fd = true; |
| ... | @@ -562,6 +567,7 @@ pub const CloseOperation = struct { | ... | @@ -562,6 +567,7 @@ pub const CloseOperation = struct { |
| 562 | switch (builtin.os) { | 567 | switch (builtin.os) { |
| 563 | builtin.Os.linux, | 568 | builtin.Os.linux, |
| 564 | builtin.Os.macosx, | 569 | builtin.Os.macosx, |
| 570 | builtin.Os.freebsd, | ||
| 565 | => { | 571 | => { |
| 566 | self.os_data.have_fd = false; | 572 | self.os_data.have_fd = false; |
| 567 | }, | 573 | }, |
| ... | @@ -576,6 +582,7 @@ pub const CloseOperation = struct { | ... | @@ -576,6 +582,7 @@ pub const CloseOperation = struct { |
| 576 | switch (builtin.os) { | 582 | switch (builtin.os) { |
| 577 | builtin.Os.linux, | 583 | builtin.Os.linux, |
| 578 | builtin.Os.macosx, | 584 | builtin.Os.macosx, |
| 585 | builtin.Os.freebsd, | ||
| 579 | => { | 586 | => { |
| 580 | assert(self.os_data.have_fd); | 587 | assert(self.os_data.have_fd); |
| 581 | return self.os_data.close_req_node.data.msg.Close.fd; | 588 | return self.os_data.close_req_node.data.msg.Close.fd; |
| ... | @@ -599,6 +606,7 @@ pub async fn writeFileMode(loop: *Loop, path: []const u8, contents: []const u8, | ... | @@ -599,6 +606,7 @@ pub async fn writeFileMode(loop: *Loop, path: []const u8, contents: []const u8, |
| 599 | switch (builtin.os) { | 606 | switch (builtin.os) { |
| 600 | builtin.Os.linux, | 607 | builtin.Os.linux, |
| 601 | builtin.Os.macosx, | 608 | builtin.Os.macosx, |
| 609 | builtin.Os.freebsd, | ||
| 602 | => return await (async writeFileModeThread(loop, path, contents, mode) catch unreachable), | 610 | => return await (async writeFileModeThread(loop, path, contents, mode) catch unreachable), |
| 603 | builtin.Os.windows => return await (async writeFileWindows(loop, path, contents) catch unreachable), | 611 | builtin.Os.windows => return await (async writeFileWindows(loop, path, contents) catch unreachable), |
| 604 | else => @compileError("Unsupported OS"), | 612 | else => @compileError("Unsupported OS"), |
| ... | @@ -704,7 +712,7 @@ pub fn Watch(comptime V: type) type { | ... | @@ -704,7 +712,7 @@ pub fn Watch(comptime V: type) type { |
| 704 | os_data: OsData, | 712 | os_data: OsData, |
| 705 | 713 | ||
| 706 | const OsData = switch (builtin.os) { | 714 | const OsData = switch (builtin.os) { |
| 707 | builtin.Os.macosx => struct { | 715 | builtin.Os.macosx, builtin.Os.freebsd => struct { |
| 708 | file_table: FileTable, | 716 | file_table: FileTable, |
| 709 | table_lock: event.Lock, | 717 | table_lock: event.Lock, |
| 710 | 718 | ||
| ... | @@ -793,7 +801,7 @@ pub fn Watch(comptime V: type) type { | ... | @@ -793,7 +801,7 @@ pub fn Watch(comptime V: type) type { |
| 793 | return self; | 801 | return self; |
| 794 | }, | 802 | }, |
| 795 | 803 | ||
| 796 | builtin.Os.macosx => { | 804 | builtin.Os.macosx, builtin.Os.freebsd => { |
| 797 | const self = try loop.allocator.createOne(Self); | 805 | const self = try loop.allocator.createOne(Self); |
| 798 | errdefer loop.allocator.destroy(self); | 806 | errdefer loop.allocator.destroy(self); |
| 799 | 807 | ||
| ... | @@ -813,7 +821,7 @@ pub fn Watch(comptime V: type) type { | ... | @@ -813,7 +821,7 @@ pub fn Watch(comptime V: type) type { |
| 813 | /// All addFile calls and removeFile calls must have completed. | 821 | /// All addFile calls and removeFile calls must have completed. |
| 814 | pub fn destroy(self: *Self) void { | 822 | pub fn destroy(self: *Self) void { |
| 815 | switch (builtin.os) { | 823 | switch (builtin.os) { |
| 816 | builtin.Os.macosx => { | 824 | builtin.Os.macosx, builtin.Os.freebsd => { |
| 817 | // TODO we need to cancel the coroutines before destroying the lock | 825 | // TODO we need to cancel the coroutines before destroying the lock |
| 818 | self.os_data.table_lock.deinit(); | 826 | self.os_data.table_lock.deinit(); |
| 819 | var it = self.os_data.file_table.iterator(); | 827 | var it = self.os_data.file_table.iterator(); |
| ... | @@ -855,14 +863,14 @@ pub fn Watch(comptime V: type) type { | ... | @@ -855,14 +863,14 @@ pub fn Watch(comptime V: type) type { |
| 855 | 863 | ||
| 856 | pub async fn addFile(self: *Self, file_path: []const u8, value: V) !?V { | 864 | pub async fn addFile(self: *Self, file_path: []const u8, value: V) !?V { |
| 857 | switch (builtin.os) { | 865 | switch (builtin.os) { |
| 858 | builtin.Os.macosx => return await (async addFileMacosx(self, file_path, value) catch unreachable), | 866 | builtin.Os.macosx, builtin.Os.freebsd => return await (async addFileKEvent(self, file_path, value) catch unreachable), |
| 859 | builtin.Os.linux => return await (async addFileLinux(self, file_path, value) catch unreachable), | 867 | builtin.Os.linux => return await (async addFileLinux(self, file_path, value) catch unreachable), |
| 860 | builtin.Os.windows => return await (async addFileWindows(self, file_path, value) catch unreachable), | 868 | builtin.Os.windows => return await (async addFileWindows(self, file_path, value) catch unreachable), |
| 861 | else => @compileError("Unsupported OS"), | 869 | else => @compileError("Unsupported OS"), |
| 862 | } | 870 | } |
| 863 | } | 871 | } |
| 864 | 872 | ||
| 865 | async fn addFileMacosx(self: *Self, file_path: []const u8, value: V) !?V { | 873 | async fn addFileKEvent(self: *Self, file_path: []const u8, value: V) !?V { |
| 866 | const resolved_path = try os.path.resolve(self.channel.loop.allocator, file_path); | 874 | const resolved_path = try os.path.resolve(self.channel.loop.allocator, file_path); |
| 867 | var resolved_path_consumed = false; | 875 | var resolved_path_consumed = false; |
| 868 | defer if (!resolved_path_consumed) self.channel.loop.allocator.free(resolved_path); | 876 | defer if (!resolved_path_consumed) self.channel.loop.allocator.free(resolved_path); |
| ... | @@ -871,7 +879,10 @@ pub fn Watch(comptime V: type) type { | ... | @@ -871,7 +879,10 @@ pub fn Watch(comptime V: type) type { |
| 871 | var close_op_consumed = false; | 879 | var close_op_consumed = false; |
| 872 | defer if (!close_op_consumed) close_op.finish(); | 880 | defer if (!close_op_consumed) close_op.finish(); |
| 873 | 881 | ||
| 874 | const flags = posix.O_SYMLINK | posix.O_EVTONLY; | 882 | const flags = switch (builtin.os) { |
| 883 | builtin.Os.macosx => posix.O_SYMLINK | posix.O_EVTONLY, | ||
| 884 | else => 0, | ||
| 885 | }; | ||
| 875 | const mode = 0; | 886 | const mode = 0; |
| 876 | const fd = try await (async openPosix(self.channel.loop, resolved_path, flags, mode) catch unreachable); | 887 | const fd = try await (async openPosix(self.channel.loop, resolved_path, flags, mode) catch unreachable); |
| 877 | close_op.setHandle(fd); | 888 | close_op.setHandle(fd); |
std/event/loop.zig+14-13| ... | @@ -49,7 +49,7 @@ pub const Loop = struct { | ... | @@ -49,7 +49,7 @@ pub const Loop = struct { |
| 49 | }; | 49 | }; |
| 50 | 50 | ||
| 51 | pub const EventFd = switch (builtin.os) { | 51 | pub const EventFd = switch (builtin.os) { |
| 52 | builtin.Os.macosx => MacOsEventFd, | 52 | builtin.Os.macosx, builtin.Os.freebsd => KEventFd, |
| 53 | builtin.Os.linux => struct { | 53 | builtin.Os.linux => struct { |
| 54 | base: ResumeNode, | 54 | base: ResumeNode, |
| 55 | epoll_op: u32, | 55 | epoll_op: u32, |
| ... | @@ -62,13 +62,13 @@ pub const Loop = struct { | ... | @@ -62,13 +62,13 @@ pub const Loop = struct { |
| 62 | else => @compileError("unsupported OS"), | 62 | else => @compileError("unsupported OS"), |
| 63 | }; | 63 | }; |
| 64 | 64 | ||
| 65 | const MacOsEventFd = struct { | 65 | const KEventFd = struct { |
| 66 | base: ResumeNode, | 66 | base: ResumeNode, |
| 67 | kevent: posix.Kevent, | 67 | kevent: posix.Kevent, |
| 68 | }; | 68 | }; |
| 69 | 69 | ||
| 70 | pub const Basic = switch (builtin.os) { | 70 | pub const Basic = switch (builtin.os) { |
| 71 | builtin.Os.macosx => MacOsBasic, | 71 | builtin.Os.macosx, builtin.Os.freebsd => KEventBasic, |
| 72 | builtin.Os.linux => struct { | 72 | builtin.Os.linux => struct { |
| 73 | base: ResumeNode, | 73 | base: ResumeNode, |
| 74 | }, | 74 | }, |
| ... | @@ -78,7 +78,7 @@ pub const Loop = struct { | ... | @@ -78,7 +78,7 @@ pub const Loop = struct { |
| 78 | else => @compileError("unsupported OS"), | 78 | else => @compileError("unsupported OS"), |
| 79 | }; | 79 | }; |
| 80 | 80 | ||
| 81 | const MacOsBasic = struct { | 81 | const KEventBasic = struct { |
| 82 | base: ResumeNode, | 82 | base: ResumeNode, |
| 83 | kev: posix.Kevent, | 83 | kev: posix.Kevent, |
| 84 | }; | 84 | }; |
| ... | @@ -214,7 +214,7 @@ pub const Loop = struct { | ... | @@ -214,7 +214,7 @@ pub const Loop = struct { |
| 214 | self.extra_threads[extra_thread_index] = try os.spawnThread(self, workerRun); | 214 | self.extra_threads[extra_thread_index] = try os.spawnThread(self, workerRun); |
| 215 | } | 215 | } |
| 216 | }, | 216 | }, |
| 217 | builtin.Os.macosx => { | 217 | builtin.Os.macosx, builtin.Os.freebsd => { |
| 218 | self.os_data.kqfd = try os.bsdKQueue(); | 218 | self.os_data.kqfd = try os.bsdKQueue(); |
| 219 | errdefer os.close(self.os_data.kqfd); | 219 | errdefer os.close(self.os_data.kqfd); |
| 220 | 220 | ||
| ... | @@ -369,7 +369,7 @@ pub const Loop = struct { | ... | @@ -369,7 +369,7 @@ pub const Loop = struct { |
| 369 | os.close(self.os_data.epollfd); | 369 | os.close(self.os_data.epollfd); |
| 370 | self.allocator.free(self.eventfd_resume_nodes); | 370 | self.allocator.free(self.eventfd_resume_nodes); |
| 371 | }, | 371 | }, |
| 372 | builtin.Os.macosx => { | 372 | builtin.Os.macosx, builtin.Os.freebsd => { |
| 373 | os.close(self.os_data.kqfd); | 373 | os.close(self.os_data.kqfd); |
| 374 | os.close(self.os_data.fs_kqfd); | 374 | os.close(self.os_data.fs_kqfd); |
| 375 | }, | 375 | }, |
| ... | @@ -484,7 +484,7 @@ pub const Loop = struct { | ... | @@ -484,7 +484,7 @@ pub const Loop = struct { |
| 484 | const eventfd_node = &resume_stack_node.data; | 484 | const eventfd_node = &resume_stack_node.data; |
| 485 | eventfd_node.base.handle = next_tick_node.data; | 485 | eventfd_node.base.handle = next_tick_node.data; |
| 486 | switch (builtin.os) { | 486 | switch (builtin.os) { |
| 487 | builtin.Os.macosx => { | 487 | builtin.Os.macosx, builtin.Os.freebsd => { |
| 488 | const kevent_array = (*[1]posix.Kevent)(&eventfd_node.kevent); | 488 | const kevent_array = (*[1]posix.Kevent)(&eventfd_node.kevent); |
| 489 | const empty_kevs = ([*]posix.Kevent)(undefined)[0..0]; | 489 | const empty_kevs = ([*]posix.Kevent)(undefined)[0..0]; |
| 490 | _ = os.bsdKEvent(self.os_data.kqfd, kevent_array, empty_kevs, null) catch { | 490 | _ = os.bsdKEvent(self.os_data.kqfd, kevent_array, empty_kevs, null) catch { |
| ... | @@ -546,6 +546,7 @@ pub const Loop = struct { | ... | @@ -546,6 +546,7 @@ pub const Loop = struct { |
| 546 | switch (builtin.os) { | 546 | switch (builtin.os) { |
| 547 | builtin.Os.linux, | 547 | builtin.Os.linux, |
| 548 | builtin.Os.macosx, | 548 | builtin.Os.macosx, |
| 549 | builtin.Os.freebsd, | ||
| 549 | => self.os_data.fs_thread.wait(), | 550 | => self.os_data.fs_thread.wait(), |
| 550 | else => {}, | 551 | else => {}, |
| 551 | } | 552 | } |
| ... | @@ -610,7 +611,7 @@ pub const Loop = struct { | ... | @@ -610,7 +611,7 @@ pub const Loop = struct { |
| 610 | os.posixWrite(self.os_data.final_eventfd, wakeup_bytes) catch unreachable; | 611 | os.posixWrite(self.os_data.final_eventfd, wakeup_bytes) catch unreachable; |
| 611 | return; | 612 | return; |
| 612 | }, | 613 | }, |
| 613 | builtin.Os.macosx => { | 614 | builtin.Os.macosx, builtin.Os.freebsd => { |
| 614 | self.posixFsRequest(&self.os_data.fs_end_request); | 615 | self.posixFsRequest(&self.os_data.fs_end_request); |
| 615 | const final_kevent = (*[1]posix.Kevent)(&self.os_data.final_kevent); | 616 | const final_kevent = (*[1]posix.Kevent)(&self.os_data.final_kevent); |
| 616 | const empty_kevs = ([*]posix.Kevent)(undefined)[0..0]; | 617 | const empty_kevs = ([*]posix.Kevent)(undefined)[0..0]; |
| ... | @@ -668,7 +669,7 @@ pub const Loop = struct { | ... | @@ -668,7 +669,7 @@ pub const Loop = struct { |
| 668 | } | 669 | } |
| 669 | } | 670 | } |
| 670 | }, | 671 | }, |
| 671 | builtin.Os.macosx => { | 672 | builtin.Os.macosx, builtin.Os.freebsd => { |
| 672 | var eventlist: [1]posix.Kevent = undefined; | 673 | var eventlist: [1]posix.Kevent = undefined; |
| 673 | const empty_kevs = ([*]posix.Kevent)(undefined)[0..0]; | 674 | const empty_kevs = ([*]posix.Kevent)(undefined)[0..0]; |
| 674 | const count = os.bsdKEvent(self.os_data.kqfd, empty_kevs, eventlist[0..], null) catch unreachable; | 675 | const count = os.bsdKEvent(self.os_data.kqfd, empty_kevs, eventlist[0..], null) catch unreachable; |
| ... | @@ -731,7 +732,7 @@ pub const Loop = struct { | ... | @@ -731,7 +732,7 @@ pub const Loop = struct { |
| 731 | self.beginOneEvent(); // finished in posixFsRun after processing the msg | 732 | self.beginOneEvent(); // finished in posixFsRun after processing the msg |
| 732 | self.os_data.fs_queue.put(request_node); | 733 | self.os_data.fs_queue.put(request_node); |
| 733 | switch (builtin.os) { | 734 | switch (builtin.os) { |
| 734 | builtin.Os.macosx => { | 735 | builtin.Os.macosx, builtin.Os.freebsd => { |
| 735 | const fs_kevs = (*[1]posix.Kevent)(&self.os_data.fs_kevent_wake); | 736 | const fs_kevs = (*[1]posix.Kevent)(&self.os_data.fs_kevent_wake); |
| 736 | const empty_kevs = ([*]posix.Kevent)(undefined)[0..0]; | 737 | const empty_kevs = ([*]posix.Kevent)(undefined)[0..0]; |
| 737 | _ = os.bsdKEvent(self.os_data.fs_kqfd, fs_kevs, empty_kevs, null) catch unreachable; | 738 | _ = os.bsdKEvent(self.os_data.fs_kqfd, fs_kevs, empty_kevs, null) catch unreachable; |
| ... | @@ -801,7 +802,7 @@ pub const Loop = struct { | ... | @@ -801,7 +802,7 @@ pub const Loop = struct { |
| 801 | else => unreachable, | 802 | else => unreachable, |
| 802 | } | 803 | } |
| 803 | }, | 804 | }, |
| 804 | builtin.Os.macosx => { | 805 | builtin.Os.macosx, builtin.Os.freebsd => { |
| 805 | const fs_kevs = (*[1]posix.Kevent)(&self.os_data.fs_kevent_wait); | 806 | const fs_kevs = (*[1]posix.Kevent)(&self.os_data.fs_kevent_wait); |
| 806 | var out_kevs: [1]posix.Kevent = undefined; | 807 | var out_kevs: [1]posix.Kevent = undefined; |
| 807 | _ = os.bsdKEvent(self.os_data.fs_kqfd, fs_kevs, out_kevs[0..], null) catch unreachable; | 808 | _ = os.bsdKEvent(self.os_data.fs_kqfd, fs_kevs, out_kevs[0..], null) catch unreachable; |
| ... | @@ -813,7 +814,7 @@ pub const Loop = struct { | ... | @@ -813,7 +814,7 @@ pub const Loop = struct { |
| 813 | 814 | ||
| 814 | const OsData = switch (builtin.os) { | 815 | const OsData = switch (builtin.os) { |
| 815 | builtin.Os.linux => LinuxOsData, | 816 | builtin.Os.linux => LinuxOsData, |
| 816 | builtin.Os.macosx => MacOsData, | 817 | builtin.Os.macosx, builtin.Os.freebsd => KEventData, |
| 817 | builtin.Os.windows => struct { | 818 | builtin.Os.windows => struct { |
| 818 | io_port: windows.HANDLE, | 819 | io_port: windows.HANDLE, |
| 819 | extra_thread_count: usize, | 820 | extra_thread_count: usize, |
| ... | @@ -821,7 +822,7 @@ pub const Loop = struct { | ... | @@ -821,7 +822,7 @@ pub const Loop = struct { |
| 821 | else => struct {}, | 822 | else => struct {}, |
| 822 | }; | 823 | }; |
| 823 | 824 | ||
| 824 | const MacOsData = struct { | 825 | const KEventData = struct { |
| 825 | kqfd: i32, | 826 | kqfd: i32, |
| 826 | final_kevent: posix.Kevent, | 827 | final_kevent: posix.Kevent, |
| 827 | fs_kevent_wake: posix.Kevent, | 828 | fs_kevent_wake: posix.Kevent, |
std/heap.zig+3-3| ... | @@ -70,7 +70,7 @@ pub const DirectAllocator = struct { | ... | @@ -70,7 +70,7 @@ pub const DirectAllocator = struct { |
| 70 | const self = @fieldParentPtr(DirectAllocator, "allocator", allocator); | 70 | const self = @fieldParentPtr(DirectAllocator, "allocator", allocator); |
| 71 | 71 | ||
| 72 | switch (builtin.os) { | 72 | switch (builtin.os) { |
| 73 | Os.linux, Os.macosx, Os.ios => { | 73 | Os.linux, Os.macosx, Os.ios, Os.freebsd => { |
| 74 | const p = os.posix; | 74 | const p = os.posix; |
| 75 | const alloc_size = if (alignment <= os.page_size) n else n + alignment; | 75 | const alloc_size = if (alignment <= os.page_size) n else n + alignment; |
| 76 | const addr = p.mmap(null, alloc_size, p.PROT_READ | p.PROT_WRITE, p.MAP_PRIVATE | p.MAP_ANONYMOUS, -1, 0); | 76 | const addr = p.mmap(null, alloc_size, p.PROT_READ | p.PROT_WRITE, p.MAP_PRIVATE | p.MAP_ANONYMOUS, -1, 0); |
| ... | @@ -121,7 +121,7 @@ pub const DirectAllocator = struct { | ... | @@ -121,7 +121,7 @@ pub const DirectAllocator = struct { |
| 121 | const self = @fieldParentPtr(DirectAllocator, "allocator", allocator); | 121 | const self = @fieldParentPtr(DirectAllocator, "allocator", allocator); |
| 122 | 122 | ||
| 123 | switch (builtin.os) { | 123 | switch (builtin.os) { |
| 124 | Os.linux, Os.macosx, Os.ios => { | 124 | Os.linux, Os.macosx, Os.ios, Os.freebsd => { |
| 125 | if (new_size <= old_mem.len) { | 125 | if (new_size <= old_mem.len) { |
| 126 | const base_addr = @ptrToInt(old_mem.ptr); | 126 | const base_addr = @ptrToInt(old_mem.ptr); |
| 127 | const old_addr_end = base_addr + old_mem.len; | 127 | const old_addr_end = base_addr + old_mem.len; |
| ... | @@ -166,7 +166,7 @@ pub const DirectAllocator = struct { | ... | @@ -166,7 +166,7 @@ pub const DirectAllocator = struct { |
| 166 | const self = @fieldParentPtr(DirectAllocator, "allocator", allocator); | 166 | const self = @fieldParentPtr(DirectAllocator, "allocator", allocator); |
| 167 | 167 | ||
| 168 | switch (builtin.os) { | 168 | switch (builtin.os) { |
| 169 | Os.linux, Os.macosx, Os.ios => { | 169 | Os.linux, Os.macosx, Os.ios, Os.freebsd => { |
| 170 | _ = os.posix.munmap(@ptrToInt(bytes.ptr), bytes.len); | 170 | _ = os.posix.munmap(@ptrToInt(bytes.ptr), bytes.len); |
| 171 | }, | 171 | }, |
| 172 | Os.windows => { | 172 | Os.windows => { |
std/mem.zig+4-4| ... | @@ -475,8 +475,8 @@ test "readIntBE/LE" { | ... | @@ -475,8 +475,8 @@ test "readIntBE/LE" { |
| 475 | assert(readIntBE(u8, []u8{0x32}) == 0x32); | 475 | assert(readIntBE(u8, []u8{0x32}) == 0x32); |
| 476 | assert(readIntLE(u8, []u8{0x12}) == 0x12); | 476 | assert(readIntLE(u8, []u8{0x12}) == 0x12); |
| 477 | 477 | ||
| 478 | assert(readIntBE(u16, []u8{0x12, 0x34}) == 0x1234); | 478 | assert(readIntBE(u16, []u8{ 0x12, 0x34 }) == 0x1234); |
| 479 | assert(readIntLE(u16, []u8{0x12, 0x34}) == 0x3412); | 479 | assert(readIntLE(u16, []u8{ 0x12, 0x34 }) == 0x3412); |
| 480 | 480 | ||
| 481 | assert(readIntBE(u72, []u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }) == 0x123456789abcdef024); | 481 | assert(readIntBE(u72, []u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }) == 0x123456789abcdef024); |
| 482 | assert(readIntLE(u72, []u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }) == 0xfedcba9876543210ec); | 482 | assert(readIntLE(u72, []u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }) == 0xfedcba9876543210ec); |
| ... | @@ -484,8 +484,8 @@ test "readIntBE/LE" { | ... | @@ -484,8 +484,8 @@ test "readIntBE/LE" { |
| 484 | assert(readIntBE(i8, []u8{0xff}) == -1); | 484 | assert(readIntBE(i8, []u8{0xff}) == -1); |
| 485 | assert(readIntLE(i8, []u8{0xfe}) == -2); | 485 | assert(readIntLE(i8, []u8{0xfe}) == -2); |
| 486 | 486 | ||
| 487 | assert(readIntBE(i16, []u8{0xff, 0xfd}) == -3); | 487 | assert(readIntBE(i16, []u8{ 0xff, 0xfd }) == -3); |
| 488 | assert(readIntLE(i16, []u8{0xfc, 0xff}) == -4); | 488 | assert(readIntLE(i16, []u8{ 0xfc, 0xff }) == -4); |
| 489 | } | 489 | } |
| 490 | 490 | ||
| 491 | /// Writes an integer to memory with size equal to bytes.len. Pads with zeroes | 491 | /// Writes an integer to memory with size equal to bytes.len. Pads with zeroes |
std/os/file.zig+3-3| ... | @@ -230,7 +230,7 @@ pub const File = struct { | ... | @@ -230,7 +230,7 @@ pub const File = struct { |
| 230 | 230 | ||
| 231 | pub fn seekForward(self: File, amount: isize) !void { | 231 | pub fn seekForward(self: File, amount: isize) !void { |
| 232 | switch (builtin.os) { | 232 | switch (builtin.os) { |
| 233 | Os.linux, Os.macosx, Os.ios => { | 233 | Os.linux, Os.macosx, Os.ios, Os.freebsd => { |
| 234 | const result = posix.lseek(self.handle, amount, posix.SEEK_CUR); | 234 | const result = posix.lseek(self.handle, amount, posix.SEEK_CUR); |
| 235 | const err = posix.getErrno(result); | 235 | const err = posix.getErrno(result); |
| 236 | if (err > 0) { | 236 | if (err > 0) { |
| ... | @@ -261,7 +261,7 @@ pub const File = struct { | ... | @@ -261,7 +261,7 @@ pub const File = struct { |
| 261 | 261 | ||
| 262 | pub fn seekTo(self: File, pos: usize) !void { | 262 | pub fn seekTo(self: File, pos: usize) !void { |
| 263 | switch (builtin.os) { | 263 | switch (builtin.os) { |
| 264 | Os.linux, Os.macosx, Os.ios => { | 264 | Os.linux, Os.macosx, Os.ios, Os.freebsd => { |
| 265 | const ipos = try math.cast(isize, pos); | 265 | const ipos = try math.cast(isize, pos); |
| 266 | const result = posix.lseek(self.handle, ipos, posix.SEEK_SET); | 266 | const result = posix.lseek(self.handle, ipos, posix.SEEK_SET); |
| 267 | const err = posix.getErrno(result); | 267 | const err = posix.getErrno(result); |
| ... | @@ -295,7 +295,7 @@ pub const File = struct { | ... | @@ -295,7 +295,7 @@ pub const File = struct { |
| 295 | 295 | ||
| 296 | pub fn getPos(self: File) !usize { | 296 | pub fn getPos(self: File) !usize { |
| 297 | switch (builtin.os) { | 297 | switch (builtin.os) { |
| 298 | Os.linux, Os.macosx, Os.ios => { | 298 | Os.linux, Os.macosx, Os.ios, Os.freebsd => { |
| 299 | const result = posix.lseek(self.handle, 0, posix.SEEK_CUR); | 299 | const result = posix.lseek(self.handle, 0, posix.SEEK_CUR); |
| 300 | const err = posix.getErrno(result); | 300 | const err = posix.getErrno(result); |
| 301 | if (err > 0) { | 301 | if (err > 0) { |
std/os/freebsd/errno.zig created+121| ... | @@ -0,0 +1,121 @@ | ||
| 1 | pub const EPERM = 1; // Operation not permitted | ||
| 2 | pub const ENOENT = 2; // No such file or directory | ||
| 3 | pub const ESRCH = 3; // No such process | ||
| 4 | pub const EINTR = 4; // Interrupted system call | ||
| 5 | pub const EIO = 5; // Input/output error | ||
| 6 | pub const ENXIO = 6; // Device not configured | ||
| 7 | pub const E2BIG = 7; // Argument list too long | ||
| 8 | pub const ENOEXEC = 8; // Exec format error | ||
| 9 | pub const EBADF = 9; // Bad file descriptor | ||
| 10 | pub const ECHILD = 10; // No child processes | ||
| 11 | pub const EDEADLK = 11; // Resource deadlock avoided | ||
| 12 | // 11 was EAGAIN | ||
| 13 | pub const ENOMEM = 12; // Cannot allocate memory | ||
| 14 | pub const EACCES = 13; // Permission denied | ||
| 15 | pub const EFAULT = 14; // Bad address | ||
| 16 | pub const ENOTBLK = 15; // Block device required | ||
| 17 | pub const EBUSY = 16; // Device busy | ||
| 18 | pub const EEXIST = 17; // File exists | ||
| 19 | pub const EXDEV = 18; // Cross-device link | ||
| 20 | pub const ENODEV = 19; // Operation not supported by device | ||
| 21 | pub const ENOTDIR = 20; // Not a directory | ||
| 22 | pub const EISDIR = 21; // Is a directory | ||
| 23 | pub const EINVAL = 22; // Invalid argument | ||
| 24 | pub const ENFILE = 23; // Too many open files in system | ||
| 25 | pub const EMFILE = 24; // Too many open files | ||
| 26 | pub const ENOTTY = 25; // Inappropriate ioctl for device | ||
| 27 | pub const ETXTBSY = 26; // Text file busy | ||
| 28 | pub const EFBIG = 27; // File too large | ||
| 29 | pub const ENOSPC = 28; // No space left on device | ||
| 30 | pub const ESPIPE = 29; // Illegal seek | ||
| 31 | pub const EROFS = 30; // Read-only filesystem | ||
| 32 | pub const EMLINK = 31; // Too many links | ||
| 33 | pub const EPIPE = 32; // Broken pipe | ||
| 34 | |||
| 35 | // math software | ||
| 36 | pub const EDOM = 33; // Numerical argument out of domain | ||
| 37 | pub const ERANGE = 34; // Result too large | ||
| 38 | |||
| 39 | // non-blocking and interrupt i/o | ||
| 40 | pub const EAGAIN = 35; // Resource temporarily unavailable | ||
| 41 | pub const EWOULDBLOCK = EAGAIN; // Operation would block | ||
| 42 | pub const EINPROGRESS = 36; // Operation now in progress | ||
| 43 | pub const EALREADY = 37; // Operation already in progress | ||
| 44 | |||
| 45 | // ipc/network software -- argument errors | ||
| 46 | pub const ENOTSOCK = 38; // Socket operation on non-socket | ||
| 47 | pub const EDESTADDRREQ = 39; // Destination address required | ||
| 48 | pub const EMSGSIZE = 40; // Message too long | ||
| 49 | pub const EPROTOTYPE = 41; // Protocol wrong type for socket | ||
| 50 | pub const ENOPROTOOPT = 42; // Protocol not available | ||
| 51 | pub const EPROTONOSUPPORT = 43; // Protocol not supported | ||
| 52 | pub const ESOCKTNOSUPPORT = 44; // Socket type not supported | ||
| 53 | pub const EOPNOTSUPP = 45; // Operation not supported | ||
| 54 | pub const ENOTSUP = EOPNOTSUPP; // Operation not supported | ||
| 55 | pub const EPFNOSUPPORT = 46; // Protocol family not supported | ||
| 56 | pub const EAFNOSUPPORT = 47; // Address family not supported by protocol family | ||
| 57 | pub const EADDRINUSE = 48; // Address already in use | ||
| 58 | pub const EADDRNOTAVAIL = 49; // Can't assign requested address | ||
| 59 | |||
| 60 | // ipc/network software -- operational errors | ||
| 61 | pub const ENETDOWN = 50; // Network is down | ||
| 62 | pub const ENETUNREACH = 51; // Network is unreachable | ||
| 63 | pub const ENETRESET = 52; // Network dropped connection on reset | ||
| 64 | pub const ECONNABORTED = 53; // Software caused connection abort | ||
| 65 | pub const ECONNRESET = 54; // Connection reset by peer | ||
| 66 | pub const ENOBUFS = 55; // No buffer space available | ||
| 67 | pub const EISCONN = 56; // Socket is already connected | ||
| 68 | pub const ENOTCONN = 57; // Socket is not connected | ||
| 69 | pub const ESHUTDOWN = 58; // Can't send after socket shutdown | ||
| 70 | pub const ETOOMANYREFS = 59; // Too many references: can't splice | ||
| 71 | pub const ETIMEDOUT = 60; // Operation timed out | ||
| 72 | pub const ECONNREFUSED = 61; // Connection refused | ||
| 73 | |||
| 74 | pub const ELOOP = 62; // Too many levels of symbolic links | ||
| 75 | pub const ENAMETOOLONG = 63; // File name too long | ||
| 76 | |||
| 77 | // should be rearranged | ||
| 78 | pub const EHOSTDOWN = 64; // Host is down | ||
| 79 | pub const EHOSTUNREACH = 65; // No route to host | ||
| 80 | pub const ENOTEMPTY = 66; // Directory not empty | ||
| 81 | |||
| 82 | // quotas & mush | ||
| 83 | pub const EPROCLIM = 67; // Too many processes | ||
| 84 | pub const EUSERS = 68; // Too many users | ||
| 85 | pub const EDQUOT = 69; // Disc quota exceeded | ||
| 86 | |||
| 87 | // Network File System | ||
| 88 | pub const ESTALE = 70; // Stale NFS file handle | ||
| 89 | pub const EREMOTE = 71; // Too many levels of remote in path | ||
| 90 | pub const EBADRPC = 72; // RPC struct is bad | ||
| 91 | pub const ERPCMISMATCH = 73; // RPC version wrong | ||
| 92 | pub const EPROGUNAVAIL = 74; // RPC prog. not avail | ||
| 93 | pub const EPROGMISMATCH = 75; // Program version wrong | ||
| 94 | pub const EPROCUNAVAIL = 76; // Bad procedure for program | ||
| 95 | |||
| 96 | pub const ENOLCK = 77; // No locks available | ||
| 97 | pub const ENOSYS = 78; // Function not implemented | ||
| 98 | |||
| 99 | pub const EFTYPE = 79; // Inappropriate file type or format | ||
| 100 | pub const EAUTH = 80; // Authentication error | ||
| 101 | pub const ENEEDAUTH = 81; // Need authenticator | ||
| 102 | pub const EIDRM = 82; // Identifier removed | ||
| 103 | pub const ENOMSG = 83; // No message of desired type | ||
| 104 | pub const EOVERFLOW = 84; // Value too large to be stored in data type | ||
| 105 | pub const ECANCELED = 85; // Operation canceled | ||
| 106 | pub const EILSEQ = 86; // Illegal byte sequence | ||
| 107 | pub const ENOATTR = 87; // Attribute not found | ||
| 108 | |||
| 109 | pub const EDOOFUS = 88; // Programming error | ||
| 110 | |||
| 111 | pub const EBADMSG = 89; // Bad message | ||
| 112 | pub const EMULTIHOP = 90; // Multihop attempted | ||
| 113 | pub const ENOLINK = 91; // Link has been severed | ||
| 114 | pub const EPROTO = 92; // Protocol error | ||
| 115 | |||
| 116 | pub const ENOTCAPABLE = 93; // Capabilities insufficient | ||
| 117 | pub const ECAPMODE = 94; // Not permitted in capability mode | ||
| 118 | pub const ENOTRECOVERABLE = 95; // State not recoverable | ||
| 119 | pub const EOWNERDEAD = 96; // Previous owner died | ||
| 120 | |||
| 121 | pub const ELAST = 96; // Must be equal largest errno | ||
std/os/freebsd/index.zig created+795| ... | @@ -0,0 +1,795 @@ | ||
| 1 | const assert = @import("../debug.zig").assert; | ||
| 2 | const builtin = @import("builtin"); | ||
| 3 | const arch = switch (builtin.arch) { | ||
| 4 | builtin.Arch.x86_64 => @import("x86_64.zig"), | ||
| 5 | else => @compileError("unsupported arch"), | ||
| 6 | }; | ||
| 7 | pub use @import("syscall.zig"); | ||
| 8 | pub use @import("errno.zig"); | ||
| 9 | |||
| 10 | const std = @import("../../index.zig"); | ||
| 11 | const c = std.c; | ||
| 12 | pub const Kevent = c.Kevent; | ||
| 13 | |||
| 14 | pub const PATH_MAX = 1024; | ||
| 15 | |||
| 16 | pub const STDIN_FILENO = 0; | ||
| 17 | pub const STDOUT_FILENO = 1; | ||
| 18 | pub const STDERR_FILENO = 2; | ||
| 19 | |||
| 20 | pub const PROT_NONE = 0; | ||
| 21 | pub const PROT_READ = 1; | ||
| 22 | pub const PROT_WRITE = 2; | ||
| 23 | pub const PROT_EXEC = 4; | ||
| 24 | |||
| 25 | pub const MAP_FAILED = @maxValue(usize); | ||
| 26 | pub const MAP_SHARED = 0x0001; | ||
| 27 | pub const MAP_PRIVATE = 0x0002; | ||
| 28 | pub const MAP_FIXED = 0x0010; | ||
| 29 | pub const MAP_STACK = 0x0400; | ||
| 30 | pub const MAP_NOSYNC = 0x0800; | ||
| 31 | pub const MAP_ANON = 0x1000; | ||
| 32 | pub const MAP_ANONYMOUS = MAP_ANON; | ||
| 33 | pub const MAP_FILE = 0; | ||
| 34 | pub const MAP_NORESERVE = 0; | ||
| 35 | |||
| 36 | pub const MAP_GUARD = 0x00002000; | ||
| 37 | pub const MAP_EXCL = 0x00004000; | ||
| 38 | pub const MAP_NOCORE = 0x00020000; | ||
| 39 | pub const MAP_PREFAULT_READ = 0x00040000; | ||
| 40 | pub const MAP_32BIT = 0x00080000; | ||
| 41 | |||
| 42 | pub const WNOHANG = 1; | ||
| 43 | pub const WUNTRACED = 2; | ||
| 44 | pub const WSTOPPED = WUNTRACED; | ||
| 45 | pub const WCONTINUED = 4; | ||
| 46 | pub const WNOWAIT = 8; | ||
| 47 | pub const WEXITED = 16; | ||
| 48 | pub const WTRAPPED = 32; | ||
| 49 | |||
| 50 | pub const SA_ONSTACK = 0x0001; | ||
| 51 | pub const SA_RESTART = 0x0002; | ||
| 52 | pub const SA_RESETHAND = 0x0004; | ||
| 53 | pub const SA_NOCLDSTOP = 0x0008; | ||
| 54 | pub const SA_NODEFER = 0x0010; | ||
| 55 | pub const SA_NOCLDWAIT = 0x0020; | ||
| 56 | pub const SA_SIGINFO = 0x0040; | ||
| 57 | |||
| 58 | pub const SIGHUP = 1; | ||
| 59 | pub const SIGINT = 2; | ||
| 60 | pub const SIGQUIT = 3; | ||
| 61 | pub const SIGILL = 4; | ||
| 62 | pub const SIGTRAP = 5; | ||
| 63 | pub const SIGABRT = 6; | ||
| 64 | pub const SIGIOT = SIGABRT; | ||
| 65 | pub const SIGEMT = 7; | ||
| 66 | pub const SIGFPE = 8; | ||
| 67 | pub const SIGKILL = 9; | ||
| 68 | pub const SIGBUS = 10; | ||
| 69 | pub const SIGSEGV = 11; | ||
| 70 | pub const SIGSYS = 12; | ||
| 71 | pub const SIGPIPE = 13; | ||
| 72 | pub const SIGALRM = 14; | ||
| 73 | pub const SIGTERM = 15; | ||
| 74 | pub const SIGURG = 16; | ||
| 75 | pub const SIGSTOP = 17; | ||
| 76 | pub const SIGTSTP = 18; | ||
| 77 | pub const SIGCONT = 19; | ||
| 78 | pub const SIGCHLD = 20; | ||
| 79 | pub const SIGTTIN = 21; | ||
| 80 | pub const SIGTTOU = 22; | ||
| 81 | pub const SIGIO = 23; | ||
| 82 | pub const SIGXCPU = 24; | ||
| 83 | pub const SIGXFSZ = 25; | ||
| 84 | pub const SIGVTALRM = 26; | ||
| 85 | pub const SIGPROF = 27; | ||
| 86 | pub const SIGWINCH = 28; | ||
| 87 | pub const SIGINFO = 29; | ||
| 88 | pub const SIGUSR1 = 30; | ||
| 89 | pub const SIGUSR2 = 31; | ||
| 90 | pub const SIGTHR = 32; | ||
| 91 | pub const SIGLWP = SIGTHR; | ||
| 92 | pub const SIGLIBRT = 33; | ||
| 93 | |||
| 94 | pub const SIGRTMIN = 65; | ||
| 95 | pub const SIGRTMAX = 126; | ||
| 96 | |||
| 97 | pub const O_RDONLY = 0o0; | ||
| 98 | pub const O_WRONLY = 0o1; | ||
| 99 | pub const O_RDWR = 0o2; | ||
| 100 | pub const O_ACCMODE = 0o3; | ||
| 101 | |||
| 102 | pub const O_CREAT = 0o100; | ||
| 103 | pub const O_EXCL = 0o200; | ||
| 104 | pub const O_NOCTTY = 0o400; | ||
| 105 | pub const O_TRUNC = 0o1000; | ||
| 106 | pub const O_APPEND = 0o2000; | ||
| 107 | pub const O_NONBLOCK = 0o4000; | ||
| 108 | pub const O_DSYNC = 0o10000; | ||
| 109 | pub const O_SYNC = 0o4010000; | ||
| 110 | pub const O_RSYNC = 0o4010000; | ||
| 111 | pub const O_DIRECTORY = 0o200000; | ||
| 112 | pub const O_NOFOLLOW = 0o400000; | ||
| 113 | pub const O_CLOEXEC = 0o2000000; | ||
| 114 | |||
| 115 | pub const O_ASYNC = 0o20000; | ||
| 116 | pub const O_DIRECT = 0o40000; | ||
| 117 | pub const O_LARGEFILE = 0; | ||
| 118 | pub const O_NOATIME = 0o1000000; | ||
| 119 | pub const O_PATH = 0o10000000; | ||
| 120 | pub const O_TMPFILE = 0o20200000; | ||
| 121 | pub const O_NDELAY = O_NONBLOCK; | ||
| 122 | |||
| 123 | pub const F_DUPFD = 0; | ||
| 124 | pub const F_GETFD = 1; | ||
| 125 | pub const F_SETFD = 2; | ||
| 126 | pub const F_GETFL = 3; | ||
| 127 | pub const F_SETFL = 4; | ||
| 128 | |||
| 129 | pub const F_SETOWN = 8; | ||
| 130 | pub const F_GETOWN = 9; | ||
| 131 | pub const F_SETSIG = 10; | ||
| 132 | pub const F_GETSIG = 11; | ||
| 133 | |||
| 134 | pub const F_GETLK = 5; | ||
| 135 | pub const F_SETLK = 6; | ||
| 136 | pub const F_SETLKW = 7; | ||
| 137 | |||
| 138 | pub const F_SETOWN_EX = 15; | ||
| 139 | pub const F_GETOWN_EX = 16; | ||
| 140 | |||
| 141 | pub const F_GETOWNER_UIDS = 17; | ||
| 142 | |||
| 143 | pub const SEEK_SET = 0; | ||
| 144 | pub const SEEK_CUR = 1; | ||
| 145 | pub const SEEK_END = 2; | ||
| 146 | |||
| 147 | pub const SIG_BLOCK = 1; | ||
| 148 | pub const SIG_UNBLOCK = 2; | ||
| 149 | pub const SIG_SETMASK = 3; | ||
| 150 | |||
| 151 | pub const SOCK_STREAM = 1; | ||
| 152 | pub const SOCK_DGRAM = 2; | ||
| 153 | pub const SOCK_RAW = 3; | ||
| 154 | pub const SOCK_RDM = 4; | ||
| 155 | pub const SOCK_SEQPACKET = 5; | ||
| 156 | |||
| 157 | pub const SOCK_CLOEXEC = 0x10000000; | ||
| 158 | pub const SOCK_NONBLOCK = 0x20000000; | ||
| 159 | |||
| 160 | // TODO: From here | ||
| 161 | pub const PROTO_ip = 0o000; | ||
| 162 | pub const PROTO_icmp = 0o001; | ||
| 163 | pub const PROTO_igmp = 0o002; | ||
| 164 | pub const PROTO_ggp = 0o003; | ||
| 165 | pub const PROTO_ipencap = 0o004; | ||
| 166 | pub const PROTO_st = 0o005; | ||
| 167 | pub const PROTO_tcp = 0o006; | ||
| 168 | pub const PROTO_egp = 0o010; | ||
| 169 | pub const PROTO_pup = 0o014; | ||
| 170 | pub const PROTO_udp = 0o021; | ||
| 171 | pub const PROTO_hmp = 0o024; | ||
| 172 | pub const PROTO_xns_idp = 0o026; | ||
| 173 | pub const PROTO_rdp = 0o033; | ||
| 174 | pub const PROTO_iso_tp4 = 0o035; | ||
| 175 | pub const PROTO_xtp = 0o044; | ||
| 176 | pub const PROTO_ddp = 0o045; | ||
| 177 | pub const PROTO_idpr_cmtp = 0o046; | ||
| 178 | pub const PROTO_ipv6 = 0o051; | ||
| 179 | pub const PROTO_ipv6_route = 0o053; | ||
| 180 | pub const PROTO_ipv6_frag = 0o054; | ||
| 181 | pub const PROTO_idrp = 0o055; | ||
| 182 | pub const PROTO_rsvp = 0o056; | ||
| 183 | pub const PROTO_gre = 0o057; | ||
| 184 | pub const PROTO_esp = 0o062; | ||
| 185 | pub const PROTO_ah = 0o063; | ||
| 186 | pub const PROTO_skip = 0o071; | ||
| 187 | pub const PROTO_ipv6_icmp = 0o072; | ||
| 188 | pub const PROTO_ipv6_nonxt = 0o073; | ||
| 189 | pub const PROTO_ipv6_opts = 0o074; | ||
| 190 | pub const PROTO_rspf = 0o111; | ||
| 191 | pub const PROTO_vmtp = 0o121; | ||
| 192 | pub const PROTO_ospf = 0o131; | ||
| 193 | pub const PROTO_ipip = 0o136; | ||
| 194 | pub const PROTO_encap = 0o142; | ||
| 195 | pub const PROTO_pim = 0o147; | ||
| 196 | pub const PROTO_raw = 0o377; | ||
| 197 | |||
| 198 | pub const PF_UNSPEC = 0; | ||
| 199 | pub const PF_LOCAL = 1; | ||
| 200 | pub const PF_UNIX = PF_LOCAL; | ||
| 201 | pub const PF_FILE = PF_LOCAL; | ||
| 202 | pub const PF_INET = 2; | ||
| 203 | pub const PF_AX25 = 3; | ||
| 204 | pub const PF_IPX = 4; | ||
| 205 | pub const PF_APPLETALK = 5; | ||
| 206 | pub const PF_NETROM = 6; | ||
| 207 | pub const PF_BRIDGE = 7; | ||
| 208 | pub const PF_ATMPVC = 8; | ||
| 209 | pub const PF_X25 = 9; | ||
| 210 | pub const PF_INET6 = 10; | ||
| 211 | pub const PF_ROSE = 11; | ||
| 212 | pub const PF_DECnet = 12; | ||
| 213 | pub const PF_NETBEUI = 13; | ||
| 214 | pub const PF_SECURITY = 14; | ||
| 215 | pub const PF_KEY = 15; | ||
| 216 | pub const PF_NETLINK = 16; | ||
| 217 | pub const PF_ROUTE = PF_NETLINK; | ||
| 218 | pub const PF_PACKET = 17; | ||
| 219 | pub const PF_ASH = 18; | ||
| 220 | pub const PF_ECONET = 19; | ||
| 221 | pub const PF_ATMSVC = 20; | ||
| 222 | pub const PF_RDS = 21; | ||
| 223 | pub const PF_SNA = 22; | ||
| 224 | pub const PF_IRDA = 23; | ||
| 225 | pub const PF_PPPOX = 24; | ||
| 226 | pub const PF_WANPIPE = 25; | ||
| 227 | pub const PF_LLC = 26; | ||
| 228 | pub const PF_IB = 27; | ||
| 229 | pub const PF_MPLS = 28; | ||
| 230 | pub const PF_CAN = 29; | ||
| 231 | pub const PF_TIPC = 30; | ||
| 232 | pub const PF_BLUETOOTH = 31; | ||
| 233 | pub const PF_IUCV = 32; | ||
| 234 | pub const PF_RXRPC = 33; | ||
| 235 | pub const PF_ISDN = 34; | ||
| 236 | pub const PF_PHONET = 35; | ||
| 237 | pub const PF_IEEE802154 = 36; | ||
| 238 | pub const PF_CAIF = 37; | ||
| 239 | pub const PF_ALG = 38; | ||
| 240 | pub const PF_NFC = 39; | ||
| 241 | pub const PF_VSOCK = 40; | ||
| 242 | pub const PF_MAX = 41; | ||
| 243 | |||
| 244 | pub const AF_UNSPEC = PF_UNSPEC; | ||
| 245 | pub const AF_LOCAL = PF_LOCAL; | ||
| 246 | pub const AF_UNIX = AF_LOCAL; | ||
| 247 | pub const AF_FILE = AF_LOCAL; | ||
| 248 | pub const AF_INET = PF_INET; | ||
| 249 | pub const AF_AX25 = PF_AX25; | ||
| 250 | pub const AF_IPX = PF_IPX; | ||
| 251 | pub const AF_APPLETALK = PF_APPLETALK; | ||
| 252 | pub const AF_NETROM = PF_NETROM; | ||
| 253 | pub const AF_BRIDGE = PF_BRIDGE; | ||
| 254 | pub const AF_ATMPVC = PF_ATMPVC; | ||
| 255 | pub const AF_X25 = PF_X25; | ||
| 256 | pub const AF_INET6 = PF_INET6; | ||
| 257 | pub const AF_ROSE = PF_ROSE; | ||
| 258 | pub const AF_DECnet = PF_DECnet; | ||
| 259 | pub const AF_NETBEUI = PF_NETBEUI; | ||
| 260 | pub const AF_SECURITY = PF_SECURITY; | ||
| 261 | pub const AF_KEY = PF_KEY; | ||
| 262 | pub const AF_NETLINK = PF_NETLINK; | ||
| 263 | pub const AF_ROUTE = PF_ROUTE; | ||
| 264 | pub const AF_PACKET = PF_PACKET; | ||
| 265 | pub const AF_ASH = PF_ASH; | ||
| 266 | pub const AF_ECONET = PF_ECONET; | ||
| 267 | pub const AF_ATMSVC = PF_ATMSVC; | ||
| 268 | pub const AF_RDS = PF_RDS; | ||
| 269 | pub const AF_SNA = PF_SNA; | ||
| 270 | pub const AF_IRDA = PF_IRDA; | ||
| 271 | pub const AF_PPPOX = PF_PPPOX; | ||
| 272 | pub const AF_WANPIPE = PF_WANPIPE; | ||
| 273 | pub const AF_LLC = PF_LLC; | ||
| 274 | pub const AF_IB = PF_IB; | ||
| 275 | pub const AF_MPLS = PF_MPLS; | ||
| 276 | pub const AF_CAN = PF_CAN; | ||
| 277 | pub const AF_TIPC = PF_TIPC; | ||
| 278 | pub const AF_BLUETOOTH = PF_BLUETOOTH; | ||
| 279 | pub const AF_IUCV = PF_IUCV; | ||
| 280 | pub const AF_RXRPC = PF_RXRPC; | ||
| 281 | pub const AF_ISDN = PF_ISDN; | ||
| 282 | pub const AF_PHONET = PF_PHONET; | ||
| 283 | pub const AF_IEEE802154 = PF_IEEE802154; | ||
| 284 | pub const AF_CAIF = PF_CAIF; | ||
| 285 | pub const AF_ALG = PF_ALG; | ||
| 286 | pub const AF_NFC = PF_NFC; | ||
| 287 | pub const AF_VSOCK = PF_VSOCK; | ||
| 288 | pub const AF_MAX = PF_MAX; | ||
| 289 | |||
| 290 | pub const DT_UNKNOWN = 0; | ||
| 291 | pub const DT_FIFO = 1; | ||
| 292 | pub const DT_CHR = 2; | ||
| 293 | pub const DT_DIR = 4; | ||
| 294 | pub const DT_BLK = 6; | ||
| 295 | pub const DT_REG = 8; | ||
| 296 | pub const DT_LNK = 10; | ||
| 297 | pub const DT_SOCK = 12; | ||
| 298 | pub const DT_WHT = 14; | ||
| 299 | |||
| 300 | /// add event to kq (implies enable) | ||
| 301 | pub const EV_ADD = 0x0001; | ||
| 302 | |||
| 303 | /// delete event from kq | ||
| 304 | pub const EV_DELETE = 0x0002; | ||
| 305 | |||
| 306 | /// enable event | ||
| 307 | pub const EV_ENABLE = 0x0004; | ||
| 308 | |||
| 309 | /// disable event (not reported) | ||
| 310 | pub const EV_DISABLE = 0x0008; | ||
| 311 | |||
| 312 | /// only report one occurrence | ||
| 313 | pub const EV_ONESHOT = 0x0010; | ||
| 314 | |||
| 315 | /// clear event state after reporting | ||
| 316 | pub const EV_CLEAR = 0x0020; | ||
| 317 | |||
| 318 | /// force immediate event output | ||
| 319 | /// ... with or without EV_ERROR | ||
| 320 | /// ... use KEVENT_FLAG_ERROR_EVENTS | ||
| 321 | /// on syscalls supporting flags | ||
| 322 | pub const EV_RECEIPT = 0x0040; | ||
| 323 | |||
| 324 | /// disable event after reporting | ||
| 325 | pub const EV_DISPATCH = 0x0080; | ||
| 326 | |||
| 327 | pub const EVFILT_READ = -1; | ||
| 328 | pub const EVFILT_WRITE = -2; | ||
| 329 | |||
| 330 | /// attached to aio requests | ||
| 331 | pub const EVFILT_AIO = -3; | ||
| 332 | |||
| 333 | /// attached to vnodes | ||
| 334 | pub const EVFILT_VNODE = -4; | ||
| 335 | |||
| 336 | /// attached to struct proc | ||
| 337 | pub const EVFILT_PROC = -5; | ||
| 338 | |||
| 339 | /// attached to struct proc | ||
| 340 | pub const EVFILT_SIGNAL = -6; | ||
| 341 | |||
| 342 | /// timers | ||
| 343 | pub const EVFILT_TIMER = -7; | ||
| 344 | |||
| 345 | /// Process descriptors | ||
| 346 | pub const EVFILT_PROCDESC = -8; | ||
| 347 | |||
| 348 | /// Filesystem events | ||
| 349 | pub const EVFILT_FS = -9; | ||
| 350 | |||
| 351 | pub const EVFILT_LIO = -10; | ||
| 352 | |||
| 353 | /// User events | ||
| 354 | pub const EVFILT_USER = -11; | ||
| 355 | |||
| 356 | /// Sendfile events | ||
| 357 | pub const EVFILT_SENDFILE = -12; | ||
| 358 | |||
| 359 | pub const EVFILT_EMPTY = -13; | ||
| 360 | |||
| 361 | /// On input, NOTE_TRIGGER causes the event to be triggered for output. | ||
| 362 | pub const NOTE_TRIGGER = 0x01000000; | ||
| 363 | |||
| 364 | /// ignore input fflags | ||
| 365 | pub const NOTE_FFNOP = 0x00000000; | ||
| 366 | |||
| 367 | /// and fflags | ||
| 368 | pub const NOTE_FFAND = 0x40000000; | ||
| 369 | |||
| 370 | /// or fflags | ||
| 371 | pub const NOTE_FFOR = 0x80000000; | ||
| 372 | |||
| 373 | /// copy fflags | ||
| 374 | pub const NOTE_FFCOPY = 0xc0000000; | ||
| 375 | |||
| 376 | /// mask for operations | ||
| 377 | pub const NOTE_FFCTRLMASK = 0xc0000000; | ||
| 378 | pub const NOTE_FFLAGSMASK = 0x00ffffff; | ||
| 379 | |||
| 380 | /// low water mark | ||
| 381 | pub const NOTE_LOWAT = 0x00000001; | ||
| 382 | |||
| 383 | /// behave like poll() | ||
| 384 | pub const NOTE_FILE_POLL = 0x00000002; | ||
| 385 | |||
| 386 | /// vnode was removed | ||
| 387 | pub const NOTE_DELETE = 0x00000001; | ||
| 388 | |||
| 389 | /// data contents changed | ||
| 390 | pub const NOTE_WRITE = 0x00000002; | ||
| 391 | |||
| 392 | /// size increased | ||
| 393 | pub const NOTE_EXTEND = 0x00000004; | ||
| 394 | |||
| 395 | /// attributes changed | ||
| 396 | pub const NOTE_ATTRIB = 0x00000008; | ||
| 397 | |||
| 398 | /// link count changed | ||
| 399 | pub const NOTE_LINK = 0x00000010; | ||
| 400 | |||
| 401 | /// vnode was renamed | ||
| 402 | pub const NOTE_RENAME = 0x00000020; | ||
| 403 | |||
| 404 | /// vnode access was revoked | ||
| 405 | pub const NOTE_REVOKE = 0x00000040; | ||
| 406 | |||
| 407 | /// vnode was opened | ||
| 408 | pub const NOTE_OPEN = 0x00000080; | ||
| 409 | |||
| 410 | /// file closed, fd did not allow write | ||
| 411 | pub const NOTE_CLOSE = 0x00000100; | ||
| 412 | |||
| 413 | /// file closed, fd did allow write | ||
| 414 | pub const NOTE_CLOSE_WRITE = 0x00000200; | ||
| 415 | |||
| 416 | /// file was read | ||
| 417 | pub const NOTE_READ = 0x00000400; | ||
| 418 | |||
| 419 | /// process exited | ||
| 420 | pub const NOTE_EXIT = 0x80000000; | ||
| 421 | |||
| 422 | /// process forked | ||
| 423 | pub const NOTE_FORK = 0x40000000; | ||
| 424 | |||
| 425 | /// process exec'd | ||
| 426 | pub const NOTE_EXEC = 0x20000000; | ||
| 427 | |||
| 428 | /// mask for signal & exit status | ||
| 429 | pub const NOTE_PDATAMASK = 0x000fffff; | ||
| 430 | pub const NOTE_PCTRLMASK = (~NOTE_PDATAMASK); | ||
| 431 | |||
| 432 | /// data is seconds | ||
| 433 | pub const NOTE_SECONDS = 0x00000001; | ||
| 434 | |||
| 435 | /// data is milliseconds | ||
| 436 | pub const NOTE_MSECONDS = 0x00000002; | ||
| 437 | |||
| 438 | /// data is microseconds | ||
| 439 | pub const NOTE_USECONDS = 0x00000004; | ||
| 440 | |||
| 441 | /// data is nanoseconds | ||
| 442 | pub const NOTE_NSECONDS = 0x00000008; | ||
| 443 | |||
| 444 | /// timeout is absolute | ||
| 445 | pub const NOTE_ABSTIME = 0x00000010; | ||
| 446 | |||
| 447 | pub const TCGETS = 0x5401; | ||
| 448 | pub const TCSETS = 0x5402; | ||
| 449 | pub const TCSETSW = 0x5403; | ||
| 450 | pub const TCSETSF = 0x5404; | ||
| 451 | pub const TCGETA = 0x5405; | ||
| 452 | pub const TCSETA = 0x5406; | ||
| 453 | pub const TCSETAW = 0x5407; | ||
| 454 | pub const TCSETAF = 0x5408; | ||
| 455 | pub const TCSBRK = 0x5409; | ||
| 456 | pub const TCXONC = 0x540A; | ||
| 457 | pub const TCFLSH = 0x540B; | ||
| 458 | pub const TIOCEXCL = 0x540C; | ||
| 459 | pub const TIOCNXCL = 0x540D; | ||
| 460 | pub const TIOCSCTTY = 0x540E; | ||
| 461 | pub const TIOCGPGRP = 0x540F; | ||
| 462 | pub const TIOCSPGRP = 0x5410; | ||
| 463 | pub const TIOCOUTQ = 0x5411; | ||
| 464 | pub const TIOCSTI = 0x5412; | ||
| 465 | pub const TIOCGWINSZ = 0x5413; | ||
| 466 | pub const TIOCSWINSZ = 0x5414; | ||
| 467 | pub const TIOCMGET = 0x5415; | ||
| 468 | pub const TIOCMBIS = 0x5416; | ||
| 469 | pub const TIOCMBIC = 0x5417; | ||
| 470 | pub const TIOCMSET = 0x5418; | ||
| 471 | pub const TIOCGSOFTCAR = 0x5419; | ||
| 472 | pub const TIOCSSOFTCAR = 0x541A; | ||
| 473 | pub const FIONREAD = 0x541B; | ||
| 474 | pub const TIOCINQ = FIONREAD; | ||
| 475 | pub const TIOCLINUX = 0x541C; | ||
| 476 | pub const TIOCCONS = 0x541D; | ||
| 477 | pub const TIOCGSERIAL = 0x541E; | ||
| 478 | pub const TIOCSSERIAL = 0x541F; | ||
| 479 | pub const TIOCPKT = 0x5420; | ||
| 480 | pub const FIONBIO = 0x5421; | ||
| 481 | pub const TIOCNOTTY = 0x5422; | ||
| 482 | pub const TIOCSETD = 0x5423; | ||
| 483 | pub const TIOCGETD = 0x5424; | ||
| 484 | pub const TCSBRKP = 0x5425; | ||
| 485 | pub const TIOCSBRK = 0x5427; | ||
| 486 | pub const TIOCCBRK = 0x5428; | ||
| 487 | pub const TIOCGSID = 0x5429; | ||
| 488 | pub const TIOCGRS485 = 0x542E; | ||
| 489 | pub const TIOCSRS485 = 0x542F; | ||
| 490 | pub const TIOCGPTN = 0x80045430; | ||
| 491 | pub const TIOCSPTLCK = 0x40045431; | ||
| 492 | pub const TIOCGDEV = 0x80045432; | ||
| 493 | pub const TCGETX = 0x5432; | ||
| 494 | pub const TCSETX = 0x5433; | ||
| 495 | pub const TCSETXF = 0x5434; | ||
| 496 | pub const TCSETXW = 0x5435; | ||
| 497 | pub const TIOCSIG = 0x40045436; | ||
| 498 | pub const TIOCVHANGUP = 0x5437; | ||
| 499 | pub const TIOCGPKT = 0x80045438; | ||
| 500 | pub const TIOCGPTLCK = 0x80045439; | ||
| 501 | pub const TIOCGEXCL = 0x80045440; | ||
| 502 | |||
| 503 | fn unsigned(s: i32) u32 { | ||
| 504 | return @bitCast(u32, s); | ||
| 505 | } | ||
| 506 | fn signed(s: u32) i32 { | ||
| 507 | return @bitCast(i32, s); | ||
| 508 | } | ||
| 509 | pub fn WEXITSTATUS(s: i32) i32 { | ||
| 510 | return signed((unsigned(s) & 0xff00) >> 8); | ||
| 511 | } | ||
| 512 | pub fn WTERMSIG(s: i32) i32 { | ||
| 513 | return signed(unsigned(s) & 0x7f); | ||
| 514 | } | ||
| 515 | pub fn WSTOPSIG(s: i32) i32 { | ||
| 516 | return WEXITSTATUS(s); | ||
| 517 | } | ||
| 518 | pub fn WIFEXITED(s: i32) bool { | ||
| 519 | return WTERMSIG(s) == 0; | ||
| 520 | } | ||
| 521 | pub fn WIFSTOPPED(s: i32) bool { | ||
| 522 | return @intCast(u16, (((unsigned(s) & 0xffff) *% 0x10001) >> 8)) > 0x7f00; | ||
| 523 | } | ||
| 524 | pub fn WIFSIGNALED(s: i32) bool { | ||
| 525 | return (unsigned(s) & 0xffff) -% 1 < 0xff; | ||
| 526 | } | ||
| 527 | |||
| 528 | pub const winsize = extern struct { | ||
| 529 | ws_row: u16, | ||
| 530 | ws_col: u16, | ||
| 531 | ws_xpixel: u16, | ||
| 532 | ws_ypixel: u16, | ||
| 533 | }; | ||
| 534 | |||
| 535 | /// Get the errno from a syscall return value, or 0 for no error. | ||
| 536 | pub fn getErrno(r: usize) usize { | ||
| 537 | const signed_r = @bitCast(isize, r); | ||
| 538 | return if (signed_r > -4096 and signed_r < 0) @intCast(usize, -signed_r) else 0; | ||
| 539 | } | ||
| 540 | |||
| 541 | pub fn dup2(old: i32, new: i32) usize { | ||
| 542 | return arch.syscall2(SYS_dup2, @intCast(usize, old), @intCast(usize, new)); | ||
| 543 | } | ||
| 544 | |||
| 545 | pub fn chdir(path: [*]const u8) usize { | ||
| 546 | return arch.syscall1(SYS_chdir, @ptrToInt(path)); | ||
| 547 | } | ||
| 548 | |||
| 549 | pub fn execve(path: [*]const u8, argv: [*]const ?[*]const u8, envp: [*]const ?[*]const u8) usize { | ||
| 550 | return arch.syscall3(SYS_execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp)); | ||
| 551 | } | ||
| 552 | |||
| 553 | pub fn fork() usize { | ||
| 554 | return arch.syscall0(SYS_fork); | ||
| 555 | } | ||
| 556 | |||
| 557 | pub fn getcwd(buf: [*]u8, size: usize) usize { | ||
| 558 | return arch.syscall2(SYS___getcwd, @ptrToInt(buf), size); | ||
| 559 | } | ||
| 560 | |||
| 561 | pub fn getdents(fd: i32, dirp: [*]u8, count: usize) usize { | ||
| 562 | return arch.syscall3(SYS_getdents, @intCast(usize, fd), @ptrToInt(dirp), count); | ||
| 563 | } | ||
| 564 | |||
| 565 | pub fn isatty(fd: i32) bool { | ||
| 566 | var wsz: winsize = undefined; | ||
| 567 | return arch.syscall3(SYS_ioctl, @intCast(usize, fd), TIOCGWINSZ, @ptrToInt(&wsz)) == 0; | ||
| 568 | } | ||
| 569 | |||
| 570 | pub fn readlink(noalias path: [*]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize { | ||
| 571 | return arch.syscall3(SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len); | ||
| 572 | } | ||
| 573 | |||
| 574 | pub fn mkdir(path: [*]const u8, mode: u32) usize { | ||
| 575 | return arch.syscall2(SYS_mkdir, @ptrToInt(path), mode); | ||
| 576 | } | ||
| 577 | |||
| 578 | pub fn mmap(address: ?*u8, length: usize, prot: usize, flags: usize, fd: i32, offset: isize) usize { | ||
| 579 | return arch.syscall6(SYS_mmap, @ptrToInt(address), length, prot, flags, @intCast(usize, fd), @bitCast(usize, offset)); | ||
| 580 | } | ||
| 581 | |||
| 582 | pub fn munmap(address: usize, length: usize) usize { | ||
| 583 | return arch.syscall2(SYS_munmap, address, length); | ||
| 584 | } | ||
| 585 | |||
| 586 | pub fn read(fd: i32, buf: [*]u8, count: usize) usize { | ||
| 587 | return arch.syscall3(SYS_read, @intCast(usize, fd), @ptrToInt(buf), count); | ||
| 588 | } | ||
| 589 | |||
| 590 | pub fn rmdir(path: [*]const u8) usize { | ||
| 591 | return arch.syscall1(SYS_rmdir, @ptrToInt(path)); | ||
| 592 | } | ||
| 593 | |||
| 594 | pub fn symlink(existing: [*]const u8, new: [*]const u8) usize { | ||
| 595 | return arch.syscall2(SYS_symlink, @ptrToInt(existing), @ptrToInt(new)); | ||
| 596 | } | ||
| 597 | |||
| 598 | pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: usize) usize { | ||
| 599 | return arch.syscall4(SYS_pread, @intCast(usize, fd), @ptrToInt(buf), count, offset); | ||
| 600 | } | ||
| 601 | |||
| 602 | pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: usize) usize { | ||
| 603 | return arch.syscall4(SYS_preadv, @intCast(usize, fd), @ptrToInt(iov), count, offset); | ||
| 604 | } | ||
| 605 | |||
| 606 | pub fn pipe(fd: *[2]i32) usize { | ||
| 607 | return pipe2(fd, 0); | ||
| 608 | } | ||
| 609 | |||
| 610 | pub fn pipe2(fd: *[2]i32, flags: usize) usize { | ||
| 611 | return arch.syscall2(SYS_pipe2, @ptrToInt(fd), flags); | ||
| 612 | } | ||
| 613 | |||
| 614 | pub fn write(fd: i32, buf: [*]const u8, count: usize) usize { | ||
| 615 | return arch.syscall3(SYS_write, @intCast(usize, fd), @ptrToInt(buf), count); | ||
| 616 | } | ||
| 617 | |||
| 618 | pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize { | ||
| 619 | return arch.syscall4(SYS_pwrite, @intCast(usize, fd), @ptrToInt(buf), count, offset); | ||
| 620 | } | ||
| 621 | |||
| 622 | pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: usize) usize { | ||
| 623 | return arch.syscall4(SYS_pwritev, @intCast(usize, fd), @ptrToInt(iov), count, offset); | ||
| 624 | } | ||
| 625 | |||
| 626 | pub fn rename(old: [*]const u8, new: [*]const u8) usize { | ||
| 627 | return arch.syscall2(SYS_rename, @ptrToInt(old), @ptrToInt(new)); | ||
| 628 | } | ||
| 629 | |||
| 630 | pub fn open(path: [*]const u8, flags: u32, perm: usize) usize { | ||
| 631 | return arch.syscall3(SYS_open, @ptrToInt(path), flags, perm); | ||
| 632 | } | ||
| 633 | |||
| 634 | pub fn create(path: [*]const u8, perm: usize) usize { | ||
| 635 | return arch.syscall2(SYS_creat, @ptrToInt(path), perm); | ||
| 636 | } | ||
| 637 | |||
| 638 | pub fn openat(dirfd: i32, path: [*]const u8, flags: usize, mode: usize) usize { | ||
| 639 | return arch.syscall4(SYS_openat, @intCast(usize, dirfd), @ptrToInt(path), flags, mode); | ||
| 640 | } | ||
| 641 | |||
| 642 | pub fn close(fd: i32) usize { | ||
| 643 | return arch.syscall1(SYS_close, @intCast(usize, fd)); | ||
| 644 | } | ||
| 645 | |||
| 646 | pub fn lseek(fd: i32, offset: isize, ref_pos: usize) usize { | ||
| 647 | return arch.syscall3(SYS_lseek, @intCast(usize, fd), @bitCast(usize, offset), ref_pos); | ||
| 648 | } | ||
| 649 | |||
| 650 | pub fn exit(status: i32) noreturn { | ||
| 651 | _ = arch.syscall1(SYS_exit, @bitCast(usize, isize(status))); | ||
| 652 | unreachable; | ||
| 653 | } | ||
| 654 | |||
| 655 | pub fn getrandom(buf: [*]u8, count: usize, flags: u32) usize { | ||
| 656 | return arch.syscall3(SYS_getrandom, @ptrToInt(buf), count, @intCast(usize, flags)); | ||
| 657 | } | ||
| 658 | |||
| 659 | pub fn kill(pid: i32, sig: i32) usize { | ||
| 660 | return arch.syscall2(SYS_kill, @bitCast(usize, @intCast(isize, pid)), @intCast(usize, sig)); | ||
| 661 | } | ||
| 662 | |||
| 663 | pub fn unlink(path: [*]const u8) usize { | ||
| 664 | return arch.syscall1(SYS_unlink, @ptrToInt(path)); | ||
| 665 | } | ||
| 666 | |||
| 667 | pub fn waitpid(pid: i32, status: *i32, options: i32) usize { | ||
| 668 | return arch.syscall4(SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), @bitCast(usize, isize(options)), 0); | ||
| 669 | } | ||
| 670 | |||
| 671 | pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize { | ||
| 672 | return arch.syscall2(SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem)); | ||
| 673 | } | ||
| 674 | |||
| 675 | pub fn setuid(uid: u32) usize { | ||
| 676 | return arch.syscall1(SYS_setuid, uid); | ||
| 677 | } | ||
| 678 | |||
| 679 | pub fn setgid(gid: u32) usize { | ||
| 680 | return arch.syscall1(SYS_setgid, gid); | ||
| 681 | } | ||
| 682 | |||
| 683 | pub fn setreuid(ruid: u32, euid: u32) usize { | ||
| 684 | return arch.syscall2(SYS_setreuid, ruid, euid); | ||
| 685 | } | ||
| 686 | |||
| 687 | pub fn setregid(rgid: u32, egid: u32) usize { | ||
| 688 | return arch.syscall2(SYS_setregid, rgid, egid); | ||
| 689 | } | ||
| 690 | |||
| 691 | pub fn sigprocmask(flags: u32, noalias set: *const sigset_t, noalias oldset: ?*sigset_t) usize { | ||
| 692 | // TODO: Implement | ||
| 693 | return 0; | ||
| 694 | } | ||
| 695 | |||
| 696 | pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigaction) usize { | ||
| 697 | // TODO: Implement | ||
| 698 | return 0; | ||
| 699 | } | ||
| 700 | |||
| 701 | const NSIG = 65; | ||
| 702 | const sigset_t = [128 / @sizeOf(usize)]usize; | ||
| 703 | const all_mask = []usize{@maxValue(usize)}; | ||
| 704 | const app_mask = []usize{0xfffffffc7fffffff}; | ||
| 705 | |||
| 706 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. | ||
| 707 | pub const Sigaction = struct { | ||
| 708 | // TODO: Adjust to use freebsd struct layout | ||
| 709 | handler: extern fn (i32) void, | ||
| 710 | mask: sigset_t, | ||
| 711 | flags: u32, | ||
| 712 | }; | ||
| 713 | |||
| 714 | pub const SIG_ERR = @intToPtr(extern fn (i32) void, @maxValue(usize)); | ||
| 715 | pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0); | ||
| 716 | pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1); | ||
| 717 | pub const empty_sigset = []usize{0} ** sigset_t.len; | ||
| 718 | |||
| 719 | pub fn raise(sig: i32) usize { | ||
| 720 | // TODO implement, see linux equivalent for what we want to try and do | ||
| 721 | return 0; | ||
| 722 | } | ||
| 723 | |||
| 724 | fn blockAllSignals(set: *sigset_t) void { | ||
| 725 | // TODO implement | ||
| 726 | } | ||
| 727 | |||
| 728 | fn blockAppSignals(set: *sigset_t) void { | ||
| 729 | // TODO implement | ||
| 730 | } | ||
| 731 | |||
| 732 | fn restoreSignals(set: *sigset_t) void { | ||
| 733 | // TODO implement | ||
| 734 | } | ||
| 735 | |||
| 736 | pub fn sigaddset(set: *sigset_t, sig: u6) void { | ||
| 737 | const s = sig - 1; | ||
| 738 | (*set)[usize(s) / usize.bit_count] |= usize(1) << (s & (usize.bit_count - 1)); | ||
| 739 | } | ||
| 740 | |||
| 741 | pub fn sigismember(set: *const sigset_t, sig: u6) bool { | ||
| 742 | const s = sig - 1; | ||
| 743 | return ((*set)[usize(s) / usize.bit_count] & (usize(1) << (s & (usize.bit_count - 1)))) != 0; | ||
| 744 | } | ||
| 745 | |||
| 746 | pub const Stat = arch.Stat; | ||
| 747 | pub const timespec = arch.timespec; | ||
| 748 | |||
| 749 | pub fn fstat(fd: i32, stat_buf: *Stat) usize { | ||
| 750 | return arch.syscall2(SYS_fstat, @intCast(usize, fd), @ptrToInt(stat_buf)); | ||
| 751 | } | ||
| 752 | |||
| 753 | pub const iovec = extern struct { | ||
| 754 | iov_base: [*]u8, | ||
| 755 | iov_len: usize, | ||
| 756 | }; | ||
| 757 | |||
| 758 | pub const iovec_const = extern struct { | ||
| 759 | iov_base: [*]const u8, | ||
| 760 | iov_len: usize, | ||
| 761 | }; | ||
| 762 | |||
| 763 | pub fn kqueue() usize { | ||
| 764 | return errnoWrap(c.kqueue()); | ||
| 765 | } | ||
| 766 | |||
| 767 | pub fn kevent(kq: i32, changelist: []const Kevent, eventlist: []Kevent, timeout: ?*const timespec) usize { | ||
| 768 | return errnoWrap(c.kevent( | ||
| 769 | kq, | ||
| 770 | changelist.ptr, | ||
| 771 | @intCast(c_int, changelist.len), | ||
| 772 | eventlist.ptr, | ||
| 773 | @intCast(c_int, eventlist.len), | ||
| 774 | timeout, | ||
| 775 | )); | ||
| 776 | } | ||
| 777 | |||
| 778 | pub fn sysctl(name: [*]c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) usize { | ||
| 779 | return errnoWrap(c.sysctl(name, namelen, oldp, oldlenp, newp, newlen)); | ||
| 780 | } | ||
| 781 | |||
| 782 | pub fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) usize { | ||
| 783 | return errnoWrap(c.sysctlbyname(name, oldp, oldlenp, newp, newlen)); | ||
| 784 | } | ||
| 785 | |||
| 786 | pub fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) usize { | ||
| 787 | return errnoWrap(c.sysctlnametomib(name, wibp, sizep)); | ||
| 788 | } | ||
| 789 | |||
| 790 | /// Takes the return value from a syscall and formats it back in the way | ||
| 791 | /// that the kernel represents it to libc. Errno was a mistake, let's make | ||
| 792 | /// it go away forever. | ||
| 793 | fn errnoWrap(value: isize) usize { | ||
| 794 | return @bitCast(usize, if (value == -1) -isize(c._errno().*) else value); | ||
| 795 | } | ||
std/os/freebsd/syscall.zig created+493| ... | @@ -0,0 +1,493 @@ | ||
| 1 | pub const SYS_syscall = 0; | ||
| 2 | pub const SYS_exit = 1; | ||
| 3 | pub const SYS_fork = 2; | ||
| 4 | pub const SYS_read = 3; | ||
| 5 | pub const SYS_write = 4; | ||
| 6 | pub const SYS_open = 5; | ||
| 7 | pub const SYS_close = 6; | ||
| 8 | pub const SYS_wait4 = 7; | ||
| 9 | // 8 is old creat | ||
| 10 | pub const SYS_link = 9; | ||
| 11 | pub const SYS_unlink = 10; | ||
| 12 | // 11 is obsolete execv | ||
| 13 | pub const SYS_chdir = 12; | ||
| 14 | pub const SYS_fchdir = 13; | ||
| 15 | pub const SYS_freebsd11_mknod = 14; | ||
| 16 | pub const SYS_chmod = 15; | ||
| 17 | pub const SYS_chown = 16; | ||
| 18 | pub const SYS_break = 17; | ||
| 19 | // 18 is freebsd4 getfsstat | ||
| 20 | // 19 is old lseek | ||
| 21 | pub const SYS_getpid = 20; | ||
| 22 | pub const SYS_mount = 21; | ||
| 23 | pub const SYS_unmount = 22; | ||
| 24 | pub const SYS_setuid = 23; | ||
| 25 | pub const SYS_getuid = 24; | ||
| 26 | pub const SYS_geteuid = 25; | ||
| 27 | pub const SYS_ptrace = 26; | ||
| 28 | pub const SYS_recvmsg = 27; | ||
| 29 | pub const SYS_sendmsg = 28; | ||
| 30 | pub const SYS_recvfrom = 29; | ||
| 31 | pub const SYS_accept = 30; | ||
| 32 | pub const SYS_getpeername = 31; | ||
| 33 | pub const SYS_getsockname = 32; | ||
| 34 | pub const SYS_access = 33; | ||
| 35 | pub const SYS_chflags = 34; | ||
| 36 | pub const SYS_fchflags = 35; | ||
| 37 | pub const SYS_sync = 36; | ||
| 38 | pub const SYS_kill = 37; | ||
| 39 | // 38 is old stat | ||
| 40 | pub const SYS_getppid = 39; | ||
| 41 | // 40 is old lstat | ||
| 42 | pub const SYS_dup = 41; | ||
| 43 | pub const SYS_freebsd10_pipe = 42; | ||
| 44 | pub const SYS_getegid = 43; | ||
| 45 | pub const SYS_profil = 44; | ||
| 46 | pub const SYS_ktrace = 45; | ||
| 47 | // 46 is old sigaction | ||
| 48 | pub const SYS_getgid = 47; | ||
| 49 | // 48 is old sigprocmask | ||
| 50 | pub const SYS_getlogin = 49; | ||
| 51 | pub const SYS_setlogin = 50; | ||
| 52 | pub const SYS_acct = 51; | ||
| 53 | // 52 is old sigpending | ||
| 54 | pub const SYS_sigaltstack = 53; | ||
| 55 | pub const SYS_ioctl = 54; | ||
| 56 | pub const SYS_reboot = 55; | ||
| 57 | pub const SYS_revoke = 56; | ||
| 58 | pub const SYS_symlink = 57; | ||
| 59 | pub const SYS_readlink = 58; | ||
| 60 | pub const SYS_execve = 59; | ||
| 61 | pub const SYS_umask = 60; | ||
| 62 | pub const SYS_chroot = 61; | ||
| 63 | // 62 is old fstat | ||
| 64 | // 63 is old getkerninfo | ||
| 65 | // 64 is old getpagesize | ||
| 66 | pub const SYS_msync = 65; | ||
| 67 | pub const SYS_vfork = 66; | ||
| 68 | // 67 is obsolete vread | ||
| 69 | // 68 is obsolete vwrite | ||
| 70 | // 69 is obsolete sbrk (still present on some platforms) | ||
| 71 | pub const SYS_sstk = 70; | ||
| 72 | // 71 is old mmap | ||
| 73 | pub const SYS_vadvise = 72; | ||
| 74 | pub const SYS_munmap = 73; | ||
| 75 | pub const SYS_mprotect = 74; | ||
| 76 | pub const SYS_madvise = 75; | ||
| 77 | // 76 is obsolete vhangup | ||
| 78 | // 77 is obsolete vlimit | ||
| 79 | pub const SYS_mincore = 78; | ||
| 80 | pub const SYS_getgroups = 79; | ||
| 81 | pub const SYS_setgroups = 80; | ||
| 82 | pub const SYS_getpgrp = 81; | ||
| 83 | pub const SYS_setpgid = 82; | ||
| 84 | pub const SYS_setitimer = 83; | ||
| 85 | // 84 is old wait | ||
| 86 | pub const SYS_swapon = 85; | ||
| 87 | pub const SYS_getitimer = 86; | ||
| 88 | // 87 is old gethostname | ||
| 89 | // 88 is old sethostname | ||
| 90 | pub const SYS_getdtablesize = 89; | ||
| 91 | pub const SYS_dup2 = 90; | ||
| 92 | pub const SYS_fcntl = 92; | ||
| 93 | pub const SYS_select = 93; | ||
| 94 | pub const SYS_fsync = 95; | ||
| 95 | pub const SYS_setpriority = 96; | ||
| 96 | pub const SYS_socket = 97; | ||
| 97 | pub const SYS_connect = 98; | ||
| 98 | // 99 is old accept | ||
| 99 | pub const SYS_getpriority = 100; | ||
| 100 | // 101 is old send | ||
| 101 | // 102 is old recv | ||
| 102 | // 103 is old sigreturn | ||
| 103 | pub const SYS_bind = 104; | ||
| 104 | pub const SYS_setsockopt = 105; | ||
| 105 | pub const SYS_listen = 106; | ||
| 106 | // 107 is obsolete vtimes | ||
| 107 | // 108 is old sigvec | ||
| 108 | // 109 is old sigblock | ||
| 109 | // 110 is old sigsetmask | ||
| 110 | // 111 is old sigsuspend | ||
| 111 | // 112 is old sigstack | ||
| 112 | // 113 is old recvmsg | ||
| 113 | // 114 is old sendmsg | ||
| 114 | // 115 is obsolete vtrace | ||
| 115 | pub const SYS_gettimeofday = 116; | ||
| 116 | pub const SYS_getrusage = 117; | ||
| 117 | pub const SYS_getsockopt = 118; | ||
| 118 | pub const SYS_readv = 120; | ||
| 119 | pub const SYS_writev = 121; | ||
| 120 | pub const SYS_settimeofday = 122; | ||
| 121 | pub const SYS_fchown = 123; | ||
| 122 | pub const SYS_fchmod = 124; | ||
| 123 | // 125 is old recvfrom | ||
| 124 | pub const SYS_setreuid = 126; | ||
| 125 | pub const SYS_setregid = 127; | ||
| 126 | pub const SYS_rename = 128; | ||
| 127 | // 129 is old truncate | ||
| 128 | // 130 is old ftruncate | ||
| 129 | pub const SYS_flock = 131; | ||
| 130 | pub const SYS_mkfifo = 132; | ||
| 131 | pub const SYS_sendto = 133; | ||
| 132 | pub const SYS_shutdown = 134; | ||
| 133 | pub const SYS_socketpair = 135; | ||
| 134 | pub const SYS_mkdir = 136; | ||
| 135 | pub const SYS_rmdir = 137; | ||
| 136 | pub const SYS_utimes = 138; | ||
| 137 | // 139 is obsolete 4.2 sigreturn | ||
| 138 | pub const SYS_adjtime = 140; | ||
| 139 | // 141 is old getpeername | ||
| 140 | // 142 is old gethostid | ||
| 141 | // 143 is old sethostid | ||
| 142 | // 144 is old getrlimit | ||
| 143 | // 145 is old setrlimit | ||
| 144 | // 146 is old killpg | ||
| 145 | pub const SYS_setsid = 147; | ||
| 146 | pub const SYS_quotactl = 148; | ||
| 147 | // 149 is old quota | ||
| 148 | // 150 is old getsockname | ||
| 149 | pub const SYS_nlm_syscall = 154; | ||
| 150 | pub const SYS_nfssvc = 155; | ||
| 151 | // 156 is old getdirentries | ||
| 152 | // 157 is freebsd4 statfs | ||
| 153 | // 158 is freebsd4 fstatfs | ||
| 154 | pub const SYS_lgetfh = 160; | ||
| 155 | pub const SYS_getfh = 161; | ||
| 156 | // 162 is freebsd4 getdomainname | ||
| 157 | // 163 is freebsd4 setdomainname | ||
| 158 | // 164 is freebsd4 uname | ||
| 159 | pub const SYS_sysarch = 165; | ||
| 160 | pub const SYS_rtprio = 166; | ||
| 161 | pub const SYS_semsys = 169; | ||
| 162 | pub const SYS_msgsys = 170; | ||
| 163 | pub const SYS_shmsys = 171; | ||
| 164 | // 173 is freebsd6 pread | ||
| 165 | // 174 is freebsd6 pwrite | ||
| 166 | pub const SYS_setfib = 175; | ||
| 167 | pub const SYS_ntp_adjtime = 176; | ||
| 168 | pub const SYS_setgid = 181; | ||
| 169 | pub const SYS_setegid = 182; | ||
| 170 | pub const SYS_seteuid = 183; | ||
| 171 | // 184 is obsolete lfs_bmapv | ||
| 172 | // 185 is obsolete lfs_markv | ||
| 173 | // 186 is obsolete lfs_segclean | ||
| 174 | // 187 is obsolete lfs_segwait | ||
| 175 | pub const SYS_freebsd11_stat = 188; | ||
| 176 | pub const SYS_freebsd11_fstat = 189; | ||
| 177 | pub const SYS_freebsd11_lstat = 190; | ||
| 178 | pub const SYS_pathconf = 191; | ||
| 179 | pub const SYS_fpathconf = 192; | ||
| 180 | pub const SYS_getrlimit = 194; | ||
| 181 | pub const SYS_setrlimit = 195; | ||
| 182 | pub const SYS_freebsd11_getdirentries = 196; | ||
| 183 | // 197 is freebsd6 mmap | ||
| 184 | pub const SYS___syscall = 198; | ||
| 185 | // 199 is freebsd6 lseek | ||
| 186 | // 200 is freebsd6 truncate | ||
| 187 | // 201 is freebsd6 ftruncate | ||
| 188 | pub const SYS___sysctl = 202; | ||
| 189 | pub const SYS_mlock = 203; | ||
| 190 | pub const SYS_munlock = 204; | ||
| 191 | pub const SYS_undelete = 205; | ||
| 192 | pub const SYS_futimes = 206; | ||
| 193 | pub const SYS_getpgid = 207; | ||
| 194 | pub const SYS_poll = 209; | ||
| 195 | pub const SYS_freebsd7___semctl = 220; | ||
| 196 | pub const SYS_semget = 221; | ||
| 197 | pub const SYS_semop = 222; | ||
| 198 | pub const SYS_freebsd7_msgctl = 224; | ||
| 199 | pub const SYS_msgget = 225; | ||
| 200 | pub const SYS_msgsnd = 226; | ||
| 201 | pub const SYS_msgrcv = 227; | ||
| 202 | pub const SYS_shmat = 228; | ||
| 203 | pub const SYS_freebsd7_shmctl = 229; | ||
| 204 | pub const SYS_shmdt = 230; | ||
| 205 | pub const SYS_shmget = 231; | ||
| 206 | pub const SYS_clock_gettime = 232; | ||
| 207 | pub const SYS_clock_settime = 233; | ||
| 208 | pub const SYS_clock_getres = 234; | ||
| 209 | pub const SYS_ktimer_create = 235; | ||
| 210 | pub const SYS_ktimer_delete = 236; | ||
| 211 | pub const SYS_ktimer_settime = 237; | ||
| 212 | pub const SYS_ktimer_gettime = 238; | ||
| 213 | pub const SYS_ktimer_getoverrun = 239; | ||
| 214 | pub const SYS_nanosleep = 240; | ||
| 215 | pub const SYS_ffclock_getcounter = 241; | ||
| 216 | pub const SYS_ffclock_setestimate = 242; | ||
| 217 | pub const SYS_ffclock_getestimate = 243; | ||
| 218 | pub const SYS_clock_nanosleep = 244; | ||
| 219 | pub const SYS_clock_getcpuclockid2 = 247; | ||
| 220 | pub const SYS_ntp_gettime = 248; | ||
| 221 | pub const SYS_minherit = 250; | ||
| 222 | pub const SYS_rfork = 251; | ||
| 223 | // 252 is obsolete openbsd_poll | ||
| 224 | pub const SYS_issetugid = 253; | ||
| 225 | pub const SYS_lchown = 254; | ||
| 226 | pub const SYS_aio_read = 255; | ||
| 227 | pub const SYS_aio_write = 256; | ||
| 228 | pub const SYS_lio_listio = 257; | ||
| 229 | pub const SYS_freebsd11_getdents = 272; | ||
| 230 | pub const SYS_lchmod = 274; | ||
| 231 | // 275 is obsolete netbsd_lchown | ||
| 232 | pub const SYS_lutimes = 276; | ||
| 233 | // 277 is obsolete netbsd_msync | ||
| 234 | pub const SYS_freebsd11_nstat = 278; | ||
| 235 | pub const SYS_freebsd11_nfstat = 279; | ||
| 236 | pub const SYS_freebsd11_nlstat = 280; | ||
| 237 | pub const SYS_preadv = 289; | ||
| 238 | pub const SYS_pwritev = 290; | ||
| 239 | // 297 is freebsd4 fhstatfs | ||
| 240 | pub const SYS_fhopen = 298; | ||
| 241 | pub const SYS_freebsd11_fhstat = 299; | ||
| 242 | pub const SYS_modnext = 300; | ||
| 243 | pub const SYS_modstat = 301; | ||
| 244 | pub const SYS_modfnext = 302; | ||
| 245 | pub const SYS_modfind = 303; | ||
| 246 | pub const SYS_kldload = 304; | ||
| 247 | pub const SYS_kldunload = 305; | ||
| 248 | pub const SYS_kldfind = 306; | ||
| 249 | pub const SYS_kldnext = 307; | ||
| 250 | pub const SYS_kldstat = 308; | ||
| 251 | pub const SYS_kldfirstmod = 309; | ||
| 252 | pub const SYS_getsid = 310; | ||
| 253 | pub const SYS_setresuid = 311; | ||
| 254 | pub const SYS_setresgid = 312; | ||
| 255 | // 313 is obsolete signanosleep | ||
| 256 | pub const SYS_aio_return = 314; | ||
| 257 | pub const SYS_aio_suspend = 315; | ||
| 258 | pub const SYS_aio_cancel = 316; | ||
| 259 | pub const SYS_aio_error = 317; | ||
| 260 | // 318 is freebsd6 aio_read | ||
| 261 | // 319 is freebsd6 aio_write | ||
| 262 | // 320 is freebsd6 lio_listio | ||
| 263 | pub const SYS_yield = 321; | ||
| 264 | // 322 is obsolete thr_sleep | ||
| 265 | // 323 is obsolete thr_wakeup | ||
| 266 | pub const SYS_mlockall = 324; | ||
| 267 | pub const SYS_munlockall = 325; | ||
| 268 | pub const SYS___getcwd = 326; | ||
| 269 | pub const SYS_sched_setparam = 327; | ||
| 270 | pub const SYS_sched_getparam = 328; | ||
| 271 | pub const SYS_sched_setscheduler = 329; | ||
| 272 | pub const SYS_sched_getscheduler = 330; | ||
| 273 | pub const SYS_sched_yield = 331; | ||
| 274 | pub const SYS_sched_get_priority_max = 332; | ||
| 275 | pub const SYS_sched_get_priority_min = 333; | ||
| 276 | pub const SYS_sched_rr_get_interval = 334; | ||
| 277 | pub const SYS_utrace = 335; | ||
| 278 | // 336 is freebsd4 sendfile | ||
| 279 | pub const SYS_kldsym = 337; | ||
| 280 | pub const SYS_jail = 338; | ||
| 281 | pub const SYS_nnpfs_syscall = 339; | ||
| 282 | pub const SYS_sigprocmask = 340; | ||
| 283 | pub const SYS_sigsuspend = 341; | ||
| 284 | // 342 is freebsd4 sigaction | ||
| 285 | pub const SYS_sigpending = 343; | ||
| 286 | // 344 is freebsd4 sigreturn | ||
| 287 | pub const SYS_sigtimedwait = 345; | ||
| 288 | pub const SYS_sigwaitinfo = 346; | ||
| 289 | pub const SYS___acl_get_file = 347; | ||
| 290 | pub const SYS___acl_set_file = 348; | ||
| 291 | pub const SYS___acl_get_fd = 349; | ||
| 292 | pub const SYS___acl_set_fd = 350; | ||
| 293 | pub const SYS___acl_delete_file = 351; | ||
| 294 | pub const SYS___acl_delete_fd = 352; | ||
| 295 | pub const SYS___acl_aclcheck_file = 353; | ||
| 296 | pub const SYS___acl_aclcheck_fd = 354; | ||
| 297 | pub const SYS_extattrctl = 355; | ||
| 298 | pub const SYS_extattr_set_file = 356; | ||
| 299 | pub const SYS_extattr_get_file = 357; | ||
| 300 | pub const SYS_extattr_delete_file = 358; | ||
| 301 | pub const SYS_aio_waitcomplete = 359; | ||
| 302 | pub const SYS_getresuid = 360; | ||
| 303 | pub const SYS_getresgid = 361; | ||
| 304 | pub const SYS_kqueue = 362; | ||
| 305 | pub const SYS_freebsd11_kevent = 363; | ||
| 306 | // 364 is obsolete __cap_get_proc | ||
| 307 | // 365 is obsolete __cap_set_proc | ||
| 308 | // 366 is obsolete __cap_get_fd | ||
| 309 | // 367 is obsolete __cap_get_file | ||
| 310 | // 368 is obsolete __cap_set_fd | ||
| 311 | // 369 is obsolete __cap_set_file | ||
| 312 | pub const SYS_extattr_set_fd = 371; | ||
| 313 | pub const SYS_extattr_get_fd = 372; | ||
| 314 | pub const SYS_extattr_delete_fd = 373; | ||
| 315 | pub const SYS___setugid = 374; | ||
| 316 | pub const SYS_eaccess = 376; | ||
| 317 | pub const SYS_afs3_syscall = 377; | ||
| 318 | pub const SYS_nmount = 378; | ||
| 319 | // 379 is obsolete kse_exit | ||
| 320 | // 380 is obsolete kse_wakeup | ||
| 321 | // 381 is obsolete kse_create | ||
| 322 | // 382 is obsolete kse_thr_interrupt | ||
| 323 | // 383 is obsolete kse_release | ||
| 324 | pub const SYS___mac_get_proc = 384; | ||
| 325 | pub const SYS___mac_set_proc = 385; | ||
| 326 | pub const SYS___mac_get_fd = 386; | ||
| 327 | pub const SYS___mac_get_file = 387; | ||
| 328 | pub const SYS___mac_set_fd = 388; | ||
| 329 | pub const SYS___mac_set_file = 389; | ||
| 330 | pub const SYS_kenv = 390; | ||
| 331 | pub const SYS_lchflags = 391; | ||
| 332 | pub const SYS_uuidgen = 392; | ||
| 333 | pub const SYS_sendfile = 393; | ||
| 334 | pub const SYS_mac_syscall = 394; | ||
| 335 | pub const SYS_freebsd11_getfsstat = 395; | ||
| 336 | pub const SYS_freebsd11_statfs = 396; | ||
| 337 | pub const SYS_freebsd11_fstatfs = 397; | ||
| 338 | pub const SYS_freebsd11_fhstatfs = 398; | ||
| 339 | pub const SYS_ksem_close = 400; | ||
| 340 | pub const SYS_ksem_post = 401; | ||
| 341 | pub const SYS_ksem_wait = 402; | ||
| 342 | pub const SYS_ksem_trywait = 403; | ||
| 343 | pub const SYS_ksem_init = 404; | ||
| 344 | pub const SYS_ksem_open = 405; | ||
| 345 | pub const SYS_ksem_unlink = 406; | ||
| 346 | pub const SYS_ksem_getvalue = 407; | ||
| 347 | pub const SYS_ksem_destroy = 408; | ||
| 348 | pub const SYS___mac_get_pid = 409; | ||
| 349 | pub const SYS___mac_get_link = 410; | ||
| 350 | pub const SYS___mac_set_link = 411; | ||
| 351 | pub const SYS_extattr_set_link = 412; | ||
| 352 | pub const SYS_extattr_get_link = 413; | ||
| 353 | pub const SYS_extattr_delete_link = 414; | ||
| 354 | pub const SYS___mac_execve = 415; | ||
| 355 | pub const SYS_sigaction = 416; | ||
| 356 | pub const SYS_sigreturn = 417; | ||
| 357 | pub const SYS_getcontext = 421; | ||
| 358 | pub const SYS_setcontext = 422; | ||
| 359 | pub const SYS_swapcontext = 423; | ||
| 360 | pub const SYS_swapoff = 424; | ||
| 361 | pub const SYS___acl_get_link = 425; | ||
| 362 | pub const SYS___acl_set_link = 426; | ||
| 363 | pub const SYS___acl_delete_link = 427; | ||
| 364 | pub const SYS___acl_aclcheck_link = 428; | ||
| 365 | pub const SYS_sigwait = 429; | ||
| 366 | pub const SYS_thr_create = 430; | ||
| 367 | pub const SYS_thr_exit = 431; | ||
| 368 | pub const SYS_thr_self = 432; | ||
| 369 | pub const SYS_thr_kill = 433; | ||
| 370 | pub const SYS_jail_attach = 436; | ||
| 371 | pub const SYS_extattr_list_fd = 437; | ||
| 372 | pub const SYS_extattr_list_file = 438; | ||
| 373 | pub const SYS_extattr_list_link = 439; | ||
| 374 | // 440 is obsolete kse_switchin | ||
| 375 | pub const SYS_ksem_timedwait = 441; | ||
| 376 | pub const SYS_thr_suspend = 442; | ||
| 377 | pub const SYS_thr_wake = 443; | ||
| 378 | pub const SYS_kldunloadf = 444; | ||
| 379 | pub const SYS_audit = 445; | ||
| 380 | pub const SYS_auditon = 446; | ||
| 381 | pub const SYS_getauid = 447; | ||
| 382 | pub const SYS_setauid = 448; | ||
| 383 | pub const SYS_getaudit = 449; | ||
| 384 | pub const SYS_setaudit = 450; | ||
| 385 | pub const SYS_getaudit_addr = 451; | ||
| 386 | pub const SYS_setaudit_addr = 452; | ||
| 387 | pub const SYS_auditctl = 453; | ||
| 388 | pub const SYS__umtx_op = 454; | ||
| 389 | pub const SYS_thr_new = 455; | ||
| 390 | pub const SYS_sigqueue = 456; | ||
| 391 | pub const SYS_kmq_open = 457; | ||
| 392 | pub const SYS_kmq_setattr = 458; | ||
| 393 | pub const SYS_kmq_timedreceive = 459; | ||
| 394 | pub const SYS_kmq_timedsend = 460; | ||
| 395 | pub const SYS_kmq_notify = 461; | ||
| 396 | pub const SYS_kmq_unlink = 462; | ||
| 397 | pub const SYS_abort2 = 463; | ||
| 398 | pub const SYS_thr_set_name = 464; | ||
| 399 | pub const SYS_aio_fsync = 465; | ||
| 400 | pub const SYS_rtprio_thread = 466; | ||
| 401 | pub const SYS_sctp_peeloff = 471; | ||
| 402 | pub const SYS_sctp_generic_sendmsg = 472; | ||
| 403 | pub const SYS_sctp_generic_sendmsg_iov = 473; | ||
| 404 | pub const SYS_sctp_generic_recvmsg = 474; | ||
| 405 | pub const SYS_pread = 475; | ||
| 406 | pub const SYS_pwrite = 476; | ||
| 407 | pub const SYS_mmap = 477; | ||
| 408 | pub const SYS_lseek = 478; | ||
| 409 | pub const SYS_truncate = 479; | ||
| 410 | pub const SYS_ftruncate = 480; | ||
| 411 | pub const SYS_thr_kill2 = 481; | ||
| 412 | pub const SYS_shm_open = 482; | ||
| 413 | pub const SYS_shm_unlink = 483; | ||
| 414 | pub const SYS_cpuset = 484; | ||
| 415 | pub const SYS_cpuset_setid = 485; | ||
| 416 | pub const SYS_cpuset_getid = 486; | ||
| 417 | pub const SYS_cpuset_getaffinity = 487; | ||
| 418 | pub const SYS_cpuset_setaffinity = 488; | ||
| 419 | pub const SYS_faccessat = 489; | ||
| 420 | pub const SYS_fchmodat = 490; | ||
| 421 | pub const SYS_fchownat = 491; | ||
| 422 | pub const SYS_fexecve = 492; | ||
| 423 | pub const SYS_freebsd11_fstatat = 493; | ||
| 424 | pub const SYS_futimesat = 494; | ||
| 425 | pub const SYS_linkat = 495; | ||
| 426 | pub const SYS_mkdirat = 496; | ||
| 427 | pub const SYS_mkfifoat = 497; | ||
| 428 | pub const SYS_freebsd11_mknodat = 498; | ||
| 429 | pub const SYS_openat = 499; | ||
| 430 | pub const SYS_readlinkat = 500; | ||
| 431 | pub const SYS_renameat = 501; | ||
| 432 | pub const SYS_symlinkat = 502; | ||
| 433 | pub const SYS_unlinkat = 503; | ||
| 434 | pub const SYS_posix_openpt = 504; | ||
| 435 | pub const SYS_gssd_syscall = 505; | ||
| 436 | pub const SYS_jail_get = 506; | ||
| 437 | pub const SYS_jail_set = 507; | ||
| 438 | pub const SYS_jail_remove = 508; | ||
| 439 | pub const SYS_closefrom = 509; | ||
| 440 | pub const SYS___semctl = 510; | ||
| 441 | pub const SYS_msgctl = 511; | ||
| 442 | pub const SYS_shmctl = 512; | ||
| 443 | pub const SYS_lpathconf = 513; | ||
| 444 | // 514 is obsolete cap_new | ||
| 445 | pub const SYS___cap_rights_get = 515; | ||
| 446 | pub const SYS_cap_enter = 516; | ||
| 447 | pub const SYS_cap_getmode = 517; | ||
| 448 | pub const SYS_pdfork = 518; | ||
| 449 | pub const SYS_pdkill = 519; | ||
| 450 | pub const SYS_pdgetpid = 520; | ||
| 451 | pub const SYS_pselect = 522; | ||
| 452 | pub const SYS_getloginclass = 523; | ||
| 453 | pub const SYS_setloginclass = 524; | ||
| 454 | pub const SYS_rctl_get_racct = 525; | ||
| 455 | pub const SYS_rctl_get_rules = 526; | ||
| 456 | pub const SYS_rctl_get_limits = 527; | ||
| 457 | pub const SYS_rctl_add_rule = 528; | ||
| 458 | pub const SYS_rctl_remove_rule = 529; | ||
| 459 | pub const SYS_posix_fallocate = 530; | ||
| 460 | pub const SYS_posix_fadvise = 531; | ||
| 461 | pub const SYS_wait6 = 532; | ||
| 462 | pub const SYS_cap_rights_limit = 533; | ||
| 463 | pub const SYS_cap_ioctls_limit = 534; | ||
| 464 | pub const SYS_cap_ioctls_get = 535; | ||
| 465 | pub const SYS_cap_fcntls_limit = 536; | ||
| 466 | pub const SYS_cap_fcntls_get = 537; | ||
| 467 | pub const SYS_bindat = 538; | ||
| 468 | pub const SYS_connectat = 539; | ||
| 469 | pub const SYS_chflagsat = 540; | ||
| 470 | pub const SYS_accept4 = 541; | ||
| 471 | pub const SYS_pipe2 = 542; | ||
| 472 | pub const SYS_aio_mlock = 543; | ||
| 473 | pub const SYS_procctl = 544; | ||
| 474 | pub const SYS_ppoll = 545; | ||
| 475 | pub const SYS_futimens = 546; | ||
| 476 | pub const SYS_utimensat = 547; | ||
| 477 | // 548 is obsolete numa_getaffinity | ||
| 478 | // 549 is obsolete numa_setaffinity | ||
| 479 | pub const SYS_fdatasync = 550; | ||
| 480 | pub const SYS_fstat = 551; | ||
| 481 | pub const SYS_fstatat = 552; | ||
| 482 | pub const SYS_fhstat = 553; | ||
| 483 | pub const SYS_getdirentries = 554; | ||
| 484 | pub const SYS_statfs = 555; | ||
| 485 | pub const SYS_fstatfs = 556; | ||
| 486 | pub const SYS_getfsstat = 557; | ||
| 487 | pub const SYS_fhstatfs = 558; | ||
| 488 | pub const SYS_mknodat = 559; | ||
| 489 | pub const SYS_kevent = 560; | ||
| 490 | pub const SYS_cpuset_getdomain = 561; | ||
| 491 | pub const SYS_cpuset_setdomain = 562; | ||
| 492 | pub const SYS_getrandom = 563; | ||
| 493 | pub const SYS_MAXSYSCALL = 564; | ||
std/os/freebsd/x86_64.zig created+136| ... | @@ -0,0 +1,136 @@ | ||
| 1 | const freebsd = @import("index.zig"); | ||
| 2 | const socklen_t = freebsd.socklen_t; | ||
| 3 | const iovec = freebsd.iovec; | ||
| 4 | |||
| 5 | pub const SYS_sbrk = 69; | ||
| 6 | |||
| 7 | pub fn syscall0(number: usize) usize { | ||
| 8 | return asm volatile ("syscall" | ||
| 9 | : [ret] "={rax}" (-> usize) | ||
| 10 | : [number] "{rax}" (number) | ||
| 11 | : "rcx", "r11" | ||
| 12 | ); | ||
| 13 | } | ||
| 14 | |||
| 15 | pub fn syscall1(number: usize, arg1: usize) usize { | ||
| 16 | return asm volatile ("syscall" | ||
| 17 | : [ret] "={rax}" (-> usize) | ||
| 18 | : [number] "{rax}" (number), | ||
| 19 | [arg1] "{rdi}" (arg1) | ||
| 20 | : "rcx", "r11" | ||
| 21 | ); | ||
| 22 | } | ||
| 23 | |||
| 24 | pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize { | ||
| 25 | return asm volatile ("syscall" | ||
| 26 | : [ret] "={rax}" (-> usize) | ||
| 27 | : [number] "{rax}" (number), | ||
| 28 | [arg1] "{rdi}" (arg1), | ||
| 29 | [arg2] "{rsi}" (arg2) | ||
| 30 | : "rcx", "r11" | ||
| 31 | ); | ||
| 32 | } | ||
| 33 | |||
| 34 | pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize { | ||
| 35 | return asm volatile ("syscall" | ||
| 36 | : [ret] "={rax}" (-> usize) | ||
| 37 | : [number] "{rax}" (number), | ||
| 38 | [arg1] "{rdi}" (arg1), | ||
| 39 | [arg2] "{rsi}" (arg2), | ||
| 40 | [arg3] "{rdx}" (arg3) | ||
| 41 | : "rcx", "r11" | ||
| 42 | ); | ||
| 43 | } | ||
| 44 | |||
| 45 | pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize { | ||
| 46 | return asm volatile ("syscall" | ||
| 47 | : [ret] "={rax}" (-> usize) | ||
| 48 | : [number] "{rax}" (number), | ||
| 49 | [arg1] "{rdi}" (arg1), | ||
| 50 | [arg2] "{rsi}" (arg2), | ||
| 51 | [arg3] "{rdx}" (arg3), | ||
| 52 | [arg4] "{r10}" (arg4) | ||
| 53 | : "rcx", "r11" | ||
| 54 | ); | ||
| 55 | } | ||
| 56 | |||
| 57 | pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize { | ||
| 58 | return asm volatile ("syscall" | ||
| 59 | : [ret] "={rax}" (-> usize) | ||
| 60 | : [number] "{rax}" (number), | ||
| 61 | [arg1] "{rdi}" (arg1), | ||
| 62 | [arg2] "{rsi}" (arg2), | ||
| 63 | [arg3] "{rdx}" (arg3), | ||
| 64 | [arg4] "{r10}" (arg4), | ||
| 65 | [arg5] "{r8}" (arg5) | ||
| 66 | : "rcx", "r11" | ||
| 67 | ); | ||
| 68 | } | ||
| 69 | |||
| 70 | pub fn syscall6( | ||
| 71 | number: usize, | ||
| 72 | arg1: usize, | ||
| 73 | arg2: usize, | ||
| 74 | arg3: usize, | ||
| 75 | arg4: usize, | ||
| 76 | arg5: usize, | ||
| 77 | arg6: usize, | ||
| 78 | ) usize { | ||
| 79 | return asm volatile ("syscall" | ||
| 80 | : [ret] "={rax}" (-> usize) | ||
| 81 | : [number] "{rax}" (number), | ||
| 82 | [arg1] "{rdi}" (arg1), | ||
| 83 | [arg2] "{rsi}" (arg2), | ||
| 84 | [arg3] "{rdx}" (arg3), | ||
| 85 | [arg4] "{r10}" (arg4), | ||
| 86 | [arg5] "{r8}" (arg5), | ||
| 87 | [arg6] "{r9}" (arg6) | ||
| 88 | : "rcx", "r11" | ||
| 89 | ); | ||
| 90 | } | ||
| 91 | |||
| 92 | pub nakedcc fn restore_rt() void { | ||
| 93 | asm volatile ("syscall" | ||
| 94 | : | ||
| 95 | : [number] "{rax}" (usize(SYS_rt_sigreturn)) | ||
| 96 | : "rcx", "r11" | ||
| 97 | ); | ||
| 98 | } | ||
| 99 | |||
| 100 | pub const msghdr = extern struct { | ||
| 101 | msg_name: &u8, | ||
| 102 | msg_namelen: socklen_t, | ||
| 103 | msg_iov: &iovec, | ||
| 104 | msg_iovlen: i32, | ||
| 105 | __pad1: i32, | ||
| 106 | msg_control: &u8, | ||
| 107 | msg_controllen: socklen_t, | ||
| 108 | __pad2: socklen_t, | ||
| 109 | msg_flags: i32, | ||
| 110 | }; | ||
| 111 | |||
| 112 | /// Renamed to Stat to not conflict with the stat function. | ||
| 113 | pub const Stat = extern struct { | ||
| 114 | dev: u64, | ||
| 115 | ino: u64, | ||
| 116 | nlink: usize, | ||
| 117 | |||
| 118 | mode: u32, | ||
| 119 | uid: u32, | ||
| 120 | gid: u32, | ||
| 121 | __pad0: u32, | ||
| 122 | rdev: u64, | ||
| 123 | size: i64, | ||
| 124 | blksize: isize, | ||
| 125 | blocks: i64, | ||
| 126 | |||
| 127 | atim: timespec, | ||
| 128 | mtim: timespec, | ||
| 129 | ctim: timespec, | ||
| 130 | __unused: [3]isize, | ||
| 131 | }; | ||
| 132 | |||
| 133 | pub const timespec = extern struct { | ||
| 134 | tv_sec: isize, | ||
| 135 | tv_nsec: isize, | ||
| 136 | }; | ||
std/os/get_app_data_dir.zig+1-1| ... | @@ -43,7 +43,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD | ... | @@ -43,7 +43,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD |
| 43 | }; | 43 | }; |
| 44 | return os.path.join(allocator, home_dir, "Library", "Application Support", appname); | 44 | return os.path.join(allocator, home_dir, "Library", "Application Support", appname); |
| 45 | }, | 45 | }, |
| 46 | builtin.Os.linux => { | 46 | builtin.Os.linux, builtin.Os.freebsd => { |
| 47 | const home_dir = os.getEnvPosix("HOME") orelse { | 47 | const home_dir = os.getEnvPosix("HOME") orelse { |
| 48 | // TODO look in /etc/passwd | 48 | // TODO look in /etc/passwd |
| 49 | return error.AppDataDirUnavailable; | 49 | return error.AppDataDirUnavailable; |
std/os/get_user_id.zig+1-1| ... | @@ -11,7 +11,7 @@ pub const UserInfo = struct { | ... | @@ -11,7 +11,7 @@ pub const UserInfo = struct { |
| 11 | /// POSIX function which gets a uid from username. | 11 | /// POSIX function which gets a uid from username. |
| 12 | pub fn getUserInfo(name: []const u8) !UserInfo { | 12 | pub fn getUserInfo(name: []const u8) !UserInfo { |
| 13 | return switch (builtin.os) { | 13 | return switch (builtin.os) { |
| 14 | Os.linux, Os.macosx, Os.ios => posixGetUserInfo(name), | 14 | Os.linux, Os.macosx, Os.ios, Os.freebsd => posixGetUserInfo(name), |
| 15 | else => @compileError("Unsupported OS"), | 15 | else => @compileError("Unsupported OS"), |
| 16 | }; | 16 | }; |
| 17 | } | 17 | } |
std/os/index.zig+29-17| ... | @@ -3,7 +3,7 @@ const builtin = @import("builtin"); | ... | @@ -3,7 +3,7 @@ const builtin = @import("builtin"); |
| 3 | const Os = builtin.Os; | 3 | const Os = builtin.Os; |
| 4 | const is_windows = builtin.os == Os.windows; | 4 | const is_windows = builtin.os == Os.windows; |
| 5 | const is_posix = switch (builtin.os) { | 5 | const is_posix = switch (builtin.os) { |
| 6 | builtin.Os.linux, builtin.Os.macosx => true, | 6 | builtin.Os.linux, builtin.Os.macosx, builtin.Os.freebsd => true, |
| 7 | else => false, | 7 | else => false, |
| 8 | }; | 8 | }; |
| 9 | const os = @This(); | 9 | const os = @This(); |
| ... | @@ -24,10 +24,12 @@ test "std.os" { | ... | @@ -24,10 +24,12 @@ test "std.os" { |
| 24 | pub const windows = @import("windows/index.zig"); | 24 | pub const windows = @import("windows/index.zig"); |
| 25 | pub const darwin = @import("darwin.zig"); | 25 | pub const darwin = @import("darwin.zig"); |
| 26 | pub const linux = @import("linux/index.zig"); | 26 | pub const linux = @import("linux/index.zig"); |
| 27 | pub const freebsd = @import("freebsd/index.zig"); | ||
| 27 | pub const zen = @import("zen.zig"); | 28 | pub const zen = @import("zen.zig"); |
| 28 | pub const posix = switch (builtin.os) { | 29 | pub const posix = switch (builtin.os) { |
| 29 | Os.linux => linux, | 30 | Os.linux => linux, |
| 30 | Os.macosx, Os.ios => darwin, | 31 | Os.macosx, Os.ios => darwin, |
| 32 | Os.freebsd => freebsd, | ||
| 31 | Os.zen => zen, | 33 | Os.zen => zen, |
| 32 | else => @compileError("Unsupported OS"), | 34 | else => @compileError("Unsupported OS"), |
| 33 | }; | 35 | }; |
| ... | @@ -40,7 +42,7 @@ pub const time = @import("time.zig"); | ... | @@ -40,7 +42,7 @@ pub const time = @import("time.zig"); |
| 40 | 42 | ||
| 41 | pub const page_size = 4 * 1024; | 43 | pub const page_size = 4 * 1024; |
| 42 | pub const MAX_PATH_BYTES = switch (builtin.os) { | 44 | pub const MAX_PATH_BYTES = switch (builtin.os) { |
| 43 | Os.linux, Os.macosx, Os.ios => posix.PATH_MAX, | 45 | Os.linux, Os.macosx, Os.ios, Os.freebsd => posix.PATH_MAX, |
| 44 | // Each UTF-16LE character may be expanded to 3 UTF-8 bytes. | 46 | // Each UTF-16LE character may be expanded to 3 UTF-8 bytes. |
| 45 | // If it would require 4 UTF-8 bytes, then there would be a surrogate | 47 | // If it would require 4 UTF-8 bytes, then there would be a surrogate |
| 46 | // pair in the UTF-16LE, and we (over)account 3 bytes for it that way. | 48 | // pair in the UTF-16LE, and we (over)account 3 bytes for it that way. |
| ... | @@ -101,7 +103,7 @@ const math = std.math; | ... | @@ -101,7 +103,7 @@ const math = std.math; |
| 101 | /// library implementation. | 103 | /// library implementation. |
| 102 | pub fn getRandomBytes(buf: []u8) !void { | 104 | pub fn getRandomBytes(buf: []u8) !void { |
| 103 | switch (builtin.os) { | 105 | switch (builtin.os) { |
| 104 | Os.linux => while (true) { | 106 | Os.linux, Os.freebsd => while (true) { |
| 105 | // TODO check libc version and potentially call c.getrandom. | 107 | // TODO check libc version and potentially call c.getrandom. |
| 106 | // See #397 | 108 | // See #397 |
| 107 | const errno = posix.getErrno(posix.getrandom(buf.ptr, buf.len, 0)); | 109 | const errno = posix.getErrno(posix.getrandom(buf.ptr, buf.len, 0)); |
| ... | @@ -174,7 +176,7 @@ pub fn abort() noreturn { | ... | @@ -174,7 +176,7 @@ pub fn abort() noreturn { |
| 174 | c.abort(); | 176 | c.abort(); |
| 175 | } | 177 | } |
| 176 | switch (builtin.os) { | 178 | switch (builtin.os) { |
| 177 | Os.linux, Os.macosx, Os.ios => { | 179 | Os.linux, Os.macosx, Os.ios, Os.freebsd => { |
| 178 | _ = posix.raise(posix.SIGABRT); | 180 | _ = posix.raise(posix.SIGABRT); |
| 179 | _ = posix.raise(posix.SIGKILL); | 181 | _ = posix.raise(posix.SIGKILL); |
| 180 | while (true) {} | 182 | while (true) {} |
| ... | @@ -196,7 +198,7 @@ pub fn exit(status: u8) noreturn { | ... | @@ -196,7 +198,7 @@ pub fn exit(status: u8) noreturn { |
| 196 | c.exit(status); | 198 | c.exit(status); |
| 197 | } | 199 | } |
| 198 | switch (builtin.os) { | 200 | switch (builtin.os) { |
| 199 | Os.linux, Os.macosx, Os.ios => { | 201 | Os.linux, Os.macosx, Os.ios, Os.freebsd => { |
| 200 | posix.exit(status); | 202 | posix.exit(status); |
| 201 | }, | 203 | }, |
| 202 | Os.windows => { | 204 | Os.windows => { |
| ... | @@ -419,7 +421,7 @@ pub fn posix_pwritev(fd: i32, iov: [*]const posix.iovec_const, count: usize, off | ... | @@ -419,7 +421,7 @@ pub fn posix_pwritev(fd: i32, iov: [*]const posix.iovec_const, count: usize, off |
| 419 | } | 421 | } |
| 420 | } | 422 | } |
| 421 | }, | 423 | }, |
| 422 | builtin.Os.linux => while (true) { | 424 | builtin.Os.linux, builtin.Os.freebsd => while (true) { |
| 423 | const rc = posix.pwritev(fd, iov, count, offset); | 425 | const rc = posix.pwritev(fd, iov, count, offset); |
| 424 | const err = posix.getErrno(rc); | 426 | const err = posix.getErrno(rc); |
| 425 | switch (err) { | 427 | switch (err) { |
| ... | @@ -687,7 +689,7 @@ pub fn getBaseAddress() usize { | ... | @@ -687,7 +689,7 @@ pub fn getBaseAddress() usize { |
| 687 | }; | 689 | }; |
| 688 | return phdr - @sizeOf(ElfHeader); | 690 | return phdr - @sizeOf(ElfHeader); |
| 689 | }, | 691 | }, |
| 690 | builtin.Os.macosx => return @ptrToInt(&std.c._mh_execute_header), | 692 | builtin.Os.macosx, builtin.Os.freebsd => return @ptrToInt(&std.c._mh_execute_header), |
| 691 | builtin.Os.windows => return @ptrToInt(windows.GetModuleHandleW(null)), | 693 | builtin.Os.windows => return @ptrToInt(windows.GetModuleHandleW(null)), |
| 692 | else => @compileError("Unsupported OS"), | 694 | else => @compileError("Unsupported OS"), |
| 693 | } | 695 | } |
| ... | @@ -1305,7 +1307,7 @@ pub fn deleteDirC(dir_path: [*]const u8) DeleteDirError!void { | ... | @@ -1305,7 +1307,7 @@ pub fn deleteDirC(dir_path: [*]const u8) DeleteDirError!void { |
| 1305 | const dir_path_w = try windows_util.cStrToPrefixedFileW(dir_path); | 1307 | const dir_path_w = try windows_util.cStrToPrefixedFileW(dir_path); |
| 1306 | return deleteDirW(&dir_path_w); | 1308 | return deleteDirW(&dir_path_w); |
| 1307 | }, | 1309 | }, |
| 1308 | Os.linux, Os.macosx, Os.ios => { | 1310 | Os.linux, Os.macosx, Os.ios, Os.freebsd => { |
| 1309 | const err = posix.getErrno(posix.rmdir(dir_path)); | 1311 | const err = posix.getErrno(posix.rmdir(dir_path)); |
| 1310 | switch (err) { | 1312 | switch (err) { |
| 1311 | 0 => return, | 1313 | 0 => return, |
| ... | @@ -1348,7 +1350,7 @@ pub fn deleteDir(dir_path: []const u8) DeleteDirError!void { | ... | @@ -1348,7 +1350,7 @@ pub fn deleteDir(dir_path: []const u8) DeleteDirError!void { |
| 1348 | const dir_path_w = try windows_util.sliceToPrefixedFileW(dir_path); | 1350 | const dir_path_w = try windows_util.sliceToPrefixedFileW(dir_path); |
| 1349 | return deleteDirW(&dir_path_w); | 1351 | return deleteDirW(&dir_path_w); |
| 1350 | }, | 1352 | }, |
| 1351 | Os.linux, Os.macosx, Os.ios => { | 1353 | Os.linux, Os.macosx, Os.ios, Os.freebsd => { |
| 1352 | const dir_path_c = try toPosixPath(dir_path); | 1354 | const dir_path_c = try toPosixPath(dir_path); |
| 1353 | return deleteDirC(&dir_path_c); | 1355 | return deleteDirC(&dir_path_c); |
| 1354 | }, | 1356 | }, |
| ... | @@ -1465,7 +1467,7 @@ pub const Dir = struct { | ... | @@ -1465,7 +1467,7 @@ pub const Dir = struct { |
| 1465 | allocator: *Allocator, | 1467 | allocator: *Allocator, |
| 1466 | 1468 | ||
| 1467 | pub const Handle = switch (builtin.os) { | 1469 | pub const Handle = switch (builtin.os) { |
| 1468 | Os.macosx, Os.ios => struct { | 1470 | Os.macosx, Os.ios, Os.freebsd => struct { |
| 1469 | fd: i32, | 1471 | fd: i32, |
| 1470 | seek: i64, | 1472 | seek: i64, |
| 1471 | buf: []u8, | 1473 | buf: []u8, |
| ... | @@ -1541,7 +1543,7 @@ pub const Dir = struct { | ... | @@ -1541,7 +1543,7 @@ pub const Dir = struct { |
| 1541 | .name_data = undefined, | 1543 | .name_data = undefined, |
| 1542 | }; | 1544 | }; |
| 1543 | }, | 1545 | }, |
| 1544 | Os.macosx, Os.ios => Handle{ | 1546 | Os.macosx, Os.ios, Os.freebsd => Handle{ |
| 1545 | .fd = try posixOpen( | 1547 | .fd = try posixOpen( |
| 1546 | dir_path, | 1548 | dir_path, |
| 1547 | posix.O_RDONLY | posix.O_NONBLOCK | posix.O_DIRECTORY | posix.O_CLOEXEC, | 1549 | posix.O_RDONLY | posix.O_NONBLOCK | posix.O_DIRECTORY | posix.O_CLOEXEC, |
| ... | @@ -1572,7 +1574,7 @@ pub const Dir = struct { | ... | @@ -1572,7 +1574,7 @@ pub const Dir = struct { |
| 1572 | Os.windows => { | 1574 | Os.windows => { |
| 1573 | _ = windows.FindClose(self.handle.handle); | 1575 | _ = windows.FindClose(self.handle.handle); |
| 1574 | }, | 1576 | }, |
| 1575 | Os.macosx, Os.ios, Os.linux => { | 1577 | Os.macosx, Os.ios, Os.linux, Os.freebsd => { |
| 1576 | self.allocator.free(self.handle.buf); | 1578 | self.allocator.free(self.handle.buf); |
| 1577 | os.close(self.handle.fd); | 1579 | os.close(self.handle.fd); |
| 1578 | }, | 1580 | }, |
| ... | @@ -1587,6 +1589,7 @@ pub const Dir = struct { | ... | @@ -1587,6 +1589,7 @@ pub const Dir = struct { |
| 1587 | Os.linux => return self.nextLinux(), | 1589 | Os.linux => return self.nextLinux(), |
| 1588 | Os.macosx, Os.ios => return self.nextDarwin(), | 1590 | Os.macosx, Os.ios => return self.nextDarwin(), |
| 1589 | Os.windows => return self.nextWindows(), | 1591 | Os.windows => return self.nextWindows(), |
| 1592 | Os.freebsd => return self.nextFreebsd(), | ||
| 1590 | else => @compileError("unimplemented"), | 1593 | else => @compileError("unimplemented"), |
| 1591 | } | 1594 | } |
| 1592 | } | 1595 | } |
| ... | @@ -1726,6 +1729,11 @@ pub const Dir = struct { | ... | @@ -1726,6 +1729,11 @@ pub const Dir = struct { |
| 1726 | }; | 1729 | }; |
| 1727 | } | 1730 | } |
| 1728 | } | 1731 | } |
| 1732 | |||
| 1733 | fn nextFreebsd(self: *Dir) !?Entry { | ||
| 1734 | //self.handle.buf = try self.allocator.alloc(u8, page_size); | ||
| 1735 | @compileError("TODO implement dirs for FreeBSD"); | ||
| 1736 | } | ||
| 1729 | }; | 1737 | }; |
| 1730 | 1738 | ||
| 1731 | pub fn changeCurDir(allocator: *Allocator, dir_path: []const u8) !void { | 1739 | pub fn changeCurDir(allocator: *Allocator, dir_path: []const u8) !void { |
| ... | @@ -2164,7 +2172,7 @@ pub fn unexpectedErrorWindows(err: windows.DWORD) UnexpectedError { | ... | @@ -2164,7 +2172,7 @@ pub fn unexpectedErrorWindows(err: windows.DWORD) UnexpectedError { |
| 2164 | pub fn openSelfExe() !os.File { | 2172 | pub fn openSelfExe() !os.File { |
| 2165 | switch (builtin.os) { | 2173 | switch (builtin.os) { |
| 2166 | Os.linux => return os.File.openReadC(c"/proc/self/exe"), | 2174 | Os.linux => return os.File.openReadC(c"/proc/self/exe"), |
| 2167 | Os.macosx, Os.ios => { | 2175 | Os.macosx, Os.ios, Os.freebsd => { |
| 2168 | var buf: [MAX_PATH_BYTES]u8 = undefined; | 2176 | var buf: [MAX_PATH_BYTES]u8 = undefined; |
| 2169 | const self_exe_path = try selfExePath(&buf); | 2177 | const self_exe_path = try selfExePath(&buf); |
| 2170 | buf[self_exe_path.len] = 0; | 2178 | buf[self_exe_path.len] = 0; |
| ... | @@ -2181,7 +2189,7 @@ pub fn openSelfExe() !os.File { | ... | @@ -2181,7 +2189,7 @@ pub fn openSelfExe() !os.File { |
| 2181 | 2189 | ||
| 2182 | test "openSelfExe" { | 2190 | test "openSelfExe" { |
| 2183 | switch (builtin.os) { | 2191 | switch (builtin.os) { |
| 2184 | Os.linux, Os.macosx, Os.ios, Os.windows => (try openSelfExe()).close(), | 2192 | Os.linux, Os.macosx, Os.ios, Os.windows, Os.freebsd => (try openSelfExe()).close(), |
| 2185 | else => return error.SkipZigTest, // Unsupported OS. | 2193 | else => return error.SkipZigTest, // Unsupported OS. |
| 2186 | } | 2194 | } |
| 2187 | } | 2195 | } |
| ... | @@ -2212,6 +2220,7 @@ pub fn selfExePathW(out_buffer: *[windows_util.PATH_MAX_WIDE]u16) ![]u16 { | ... | @@ -2212,6 +2220,7 @@ pub fn selfExePathW(out_buffer: *[windows_util.PATH_MAX_WIDE]u16) ![]u16 { |
| 2212 | pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) ![]u8 { | 2220 | pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) ![]u8 { |
| 2213 | switch (builtin.os) { | 2221 | switch (builtin.os) { |
| 2214 | Os.linux => return readLink(out_buffer, "/proc/self/exe"), | 2222 | Os.linux => return readLink(out_buffer, "/proc/self/exe"), |
| 2223 | Os.freebsd => return readLink(out_buffer, "/proc/curproc/file"), | ||
| 2215 | Os.windows => { | 2224 | Os.windows => { |
| 2216 | var utf16le_buf: [windows_util.PATH_MAX_WIDE]u16 = undefined; | 2225 | var utf16le_buf: [windows_util.PATH_MAX_WIDE]u16 = undefined; |
| 2217 | const utf16le_slice = try selfExePathW(&utf16le_buf); | 2226 | const utf16le_slice = try selfExePathW(&utf16le_buf); |
| ... | @@ -2250,7 +2259,7 @@ pub fn selfExeDirPath(out_buffer: *[MAX_PATH_BYTES]u8) ![]const u8 { | ... | @@ -2250,7 +2259,7 @@ pub fn selfExeDirPath(out_buffer: *[MAX_PATH_BYTES]u8) ![]const u8 { |
| 2250 | // will not return null. | 2259 | // will not return null. |
| 2251 | return path.dirname(full_exe_path).?; | 2260 | return path.dirname(full_exe_path).?; |
| 2252 | }, | 2261 | }, |
| 2253 | Os.windows, Os.macosx, Os.ios => { | 2262 | Os.windows, Os.macosx, Os.ios, Os.freebsd => { |
| 2254 | const self_exe_path = try selfExePath(out_buffer); | 2263 | const self_exe_path = try selfExePath(out_buffer); |
| 2255 | // Assume that the OS APIs return absolute paths, and therefore dirname | 2264 | // Assume that the OS APIs return absolute paths, and therefore dirname |
| 2256 | // will not return null. | 2265 | // will not return null. |
| ... | @@ -3095,10 +3104,13 @@ pub const CpuCountError = error{ | ... | @@ -3095,10 +3104,13 @@ pub const CpuCountError = error{ |
| 3095 | 3104 | ||
| 3096 | pub fn cpuCount(fallback_allocator: *mem.Allocator) CpuCountError!usize { | 3105 | pub fn cpuCount(fallback_allocator: *mem.Allocator) CpuCountError!usize { |
| 3097 | switch (builtin.os) { | 3106 | switch (builtin.os) { |
| 3098 | builtin.Os.macosx => { | 3107 | builtin.Os.macosx, builtin.Os.freebsd => { |
| 3099 | var count: c_int = undefined; | 3108 | var count: c_int = undefined; |
| 3100 | var count_len: usize = @sizeOf(c_int); | 3109 | var count_len: usize = @sizeOf(c_int); |
| 3101 | const rc = posix.sysctlbyname(c"hw.logicalcpu", @ptrCast(*c_void, &count), &count_len, null, 0); | 3110 | const rc = posix.sysctlbyname(switch (builtin.os) { |
| 3111 | builtin.Os.macosx => c"hw.logicalcpu", | ||
| 3112 | else => c"hw.ncpu", | ||
| 3113 | }, @ptrCast(*c_void, &count), &count_len, null, 0); | ||
| 3102 | const err = posix.getErrno(rc); | 3114 | const err = posix.getErrno(rc); |
| 3103 | switch (err) { | 3115 | switch (err) { |
| 3104 | 0 => return @intCast(usize, count), | 3116 | 0 => return @intCast(usize, count), |
std/os/path.zig+10-1| ... | @@ -1188,6 +1188,15 @@ pub fn realC(out_buffer: *[os.MAX_PATH_BYTES]u8, pathname: [*]const u8) RealErro | ... | @@ -1188,6 +1188,15 @@ pub fn realC(out_buffer: *[os.MAX_PATH_BYTES]u8, pathname: [*]const u8) RealErro |
| 1188 | 1188 | ||
| 1189 | return os.readLinkC(out_buffer, proc_path.ptr); | 1189 | return os.readLinkC(out_buffer, proc_path.ptr); |
| 1190 | }, | 1190 | }, |
| 1191 | Os.freebsd => { // XXX requires fdescfs | ||
| 1192 | const fd = try os.posixOpenC(pathname, posix.O_PATH | posix.O_NONBLOCK | posix.O_CLOEXEC, 0); | ||
| 1193 | defer os.close(fd); | ||
| 1194 | |||
| 1195 | var buf: ["/dev/fd/-2147483648\x00".len]u8 = undefined; | ||
| 1196 | const proc_path = fmt.bufPrint(buf[0..], "/dev/fd/{}\x00", fd) catch unreachable; | ||
| 1197 | |||
| 1198 | return os.readLinkC(out_buffer, proc_path.ptr); | ||
| 1199 | }, | ||
| 1191 | else => @compileError("TODO implement os.path.real for " ++ @tagName(builtin.os)), | 1200 | else => @compileError("TODO implement os.path.real for " ++ @tagName(builtin.os)), |
| 1192 | } | 1201 | } |
| 1193 | } | 1202 | } |
| ... | @@ -1202,7 +1211,7 @@ pub fn real(out_buffer: *[os.MAX_PATH_BYTES]u8, pathname: []const u8) RealError! | ... | @@ -1202,7 +1211,7 @@ pub fn real(out_buffer: *[os.MAX_PATH_BYTES]u8, pathname: []const u8) RealError! |
| 1202 | const pathname_w = try windows_util.sliceToPrefixedFileW(pathname); | 1211 | const pathname_w = try windows_util.sliceToPrefixedFileW(pathname); |
| 1203 | return realW(out_buffer, &pathname_w); | 1212 | return realW(out_buffer, &pathname_w); |
| 1204 | }, | 1213 | }, |
| 1205 | Os.macosx, Os.ios, Os.linux => { | 1214 | Os.macosx, Os.ios, Os.linux, Os.freebsd => { |
| 1206 | const pathname_c = try os.toPosixPath(pathname); | 1215 | const pathname_c = try os.toPosixPath(pathname); |
| 1207 | return realC(out_buffer, &pathname_c); | 1216 | return realC(out_buffer, &pathname_c); |
| 1208 | }, | 1217 | }, |
std/special/bootstrap.zig+14-4| ... | @@ -20,10 +20,17 @@ comptime { | ... | @@ -20,10 +20,17 @@ comptime { |
| 20 | 20 | ||
| 21 | nakedcc fn _start() noreturn { | 21 | nakedcc fn _start() noreturn { |
| 22 | switch (builtin.arch) { | 22 | switch (builtin.arch) { |
| 23 | builtin.Arch.x86_64 => { | 23 | builtin.Arch.x86_64 => switch (builtin.os) { |
| 24 | argc_ptr = asm ("lea (%%rsp), %[argc]" | 24 | builtin.Os.freebsd => { |
| 25 | : [argc] "=r" (-> [*]usize) | 25 | argc_ptr = asm ("lea (%%rdi), %[argc]" |
| 26 | ); | 26 | : [argc] "=r" (-> [*]usize) |
| 27 | ); | ||
| 28 | }, | ||
| 29 | else => { | ||
| 30 | argc_ptr = asm ("lea (%%rsp), %[argc]" | ||
| 31 | : [argc] "=r" (-> [*]usize) | ||
| 32 | ); | ||
| 33 | }, | ||
| 27 | }, | 34 | }, |
| 28 | builtin.Arch.i386 => { | 35 | builtin.Arch.i386 => { |
| 29 | argc_ptr = asm ("lea (%%esp), %[argc]" | 36 | argc_ptr = asm ("lea (%%esp), %[argc]" |
| ... | @@ -50,6 +57,9 @@ extern fn WinMainCRTStartup() noreturn { | ... | @@ -50,6 +57,9 @@ extern fn WinMainCRTStartup() noreturn { |
| 50 | 57 | ||
| 51 | // TODO https://github.com/ziglang/zig/issues/265 | 58 | // TODO https://github.com/ziglang/zig/issues/265 |
| 52 | fn posixCallMainAndExit() noreturn { | 59 | fn posixCallMainAndExit() noreturn { |
| 60 | if (builtin.os == builtin.Os.freebsd) { | ||
| 61 | @setAlignStack(16); | ||
| 62 | } | ||
| 53 | const argc = argc_ptr[0]; | 63 | const argc = argc_ptr[0]; |
| 54 | const argv = @ptrCast([*][*]u8, argc_ptr + 1); | 64 | const argv = @ptrCast([*][*]u8, argc_ptr + 1); |
| 55 | 65 |