Skip to content
Standard libraryZig 0.17.0Official documentation
Sourcestd/c/darwin.zig

Source line 1

std.c.darwin.__getdirentries64

function

Source line 381

pub extern "c" fn __getdirentries64(fd: c_int, buf_ptr: [*]u8, buf_len: usize, basep: *i64) isize

Parameters

fd: c_int
buf_ptr: [*]u8
buf_len: usize
basep: *i64

std.c.darwin.__ulock_wait

function

Source line 950

pub extern "c" fn __ulock_wait(op: UL, addr: ?*const anyopaque, val: u64, timeout_us: u32) c_int

Parameters

op: UL
addr: ?*const anyopaque
val: u64
timeout_us: u32

std.c.darwin.__ulock_wait2

function

Source line 949

pub extern "c" fn __ulock_wait2(op: UL, addr: ?*const anyopaque, val: u64, timeout_ns: u64, val2: u64) c_int

Parameters

op: UL
addr: ?*const anyopaque
val: u64
timeout_ns: u64
val2: u64

std.c.darwin.__ulock_wake

function

Source line 951

pub extern "c" fn __ulock_wake(op: UL, addr: ?*const anyopaque, val: u64) c_int

Parameters

op: UL
addr: ?*const anyopaque
val: u64

std.c.darwin._dyld_get_image_header

function

Source line 357

pub extern "c" fn _dyld_get_image_header(image_index: u32) ?*mach_header

Parameters

image_index: u32

std.c.darwin._dyld_get_image_header_containing_address

function

Source line 360

pub extern "c" fn _dyld_get_image_header_containing_address(address: *const anyopaque) ?*mach_header

Parameters

address: *const anyopaque

std.c.darwin._dyld_get_image_name

function

Source line 359

pub extern "c" fn _dyld_get_image_name(image_index: u32) [*:0]const u8

Parameters

image_index: u32

std.c.darwin._dyld_get_image_vmaddr_slide

function

Source line 358

pub extern "c" fn _dyld_get_image_vmaddr_slide(image_index: u32) usize

Parameters

image_index: u32

std.c.darwin._dyld_image_count

function

Source line 356

pub extern "c" fn _dyld_image_count() u32

std.c.darwin._host_page_size

function

Source line 879

pub extern "c" fn _host_page_size(task: mach_port_t, size: *vm_size_t) kern_return_t

Parameters

task: mach_port_t
size: *vm_size_t

std.c.darwin._NSGetExecutablePath

function

Source line 355

pub extern "c" fn _NSGetExecutablePath(buf: [*]u8, bufsize: *u32) c_int

Parameters

buf: [*]u8
bufsize: *u32

std.c.darwin.@"close$NOCANCEL"

function

Source line 414

pub extern "c" fn @"close$NOCANCEL"(fd: fd_t) c_int

Parameters

fd: fd_t

std.c.darwin.AF

alias

Source line 5

Alias of std.c.AF

std.c.darwin.assert

alias

Source line 4

Alias of std.debug.assert

std.c.darwin.boolean_t

type

Source line 834

std.c.darwin.builtin

constant

Source line 2

std.c.darwin.caddr_t

alias

Source line 7

Alias of std.c.caddr_t

std.c.darwin.CALENDAR_CLOCK

constant

Source line 1050

std.c.darwin.clock_get_time

function

Source line 416

pub extern "c" fn clock_get_time(clock_serv: clock_serv_t, cur_time: *mach_timespec_t) kern_return_t

Parameters

clock_serv: clock_serv_t
cur_time: *mach_timespec_t

std.c.darwin.clock_res_t

type

Source line 1032

std.c.darwin.clock_serv_t

alias

Source line 1031

Alias of std.c.darwin.mach_port_t

std.c.darwin.COPYFILE

container

Source line 371

Fields

ACL: bool = false
STAT: bool = false
XATTR: bool = false
DATA: bool = false
_: u28 = 0

std.c.darwin.copyfile_state_t

type

Source line 379

std.c.darwin.CPUFAMILY

container

Source line 1165

Fields

UNKNOWN = 0
POWERPC_G3 = 0xcee41549
POWERPC_G4 = 0x77c184ae
POWERPC_G5 = 0xed76d8aa
INTEL_6_13 = 0xaa33392b
INTEL_PENRYN = 0x78ea4fbc
INTEL_NEHALEM = 0x6b5a4cd2
INTEL_WESTMERE = 0x573b5eec
INTEL_SANDYBRIDGE = 0x5490b78c
INTEL_IVYBRIDGE = 0x1f65e835
INTEL_HASWELL = 0x10b282dc
INTEL_BROADWELL = 0x582ed09c
INTEL_SKYLAKE = 0x37fc219f
INTEL_KABYLAKE = 0x0f817246
ARM_9 = 0xe73283ae
ARM_11 = 0x8ff620d8
ARM_XSCALE = 0x53b005f5
ARM_12 = 0xbd1b0ae9
ARM_13 = 0x0cc90e64
ARM_14 = 0x96077ef1
ARM_15 = 0xa8511bca
ARM_SWIFT = 0x1e2d6381
ARM_CYCLONE = 0x37a09642
ARM_TYPHOON = 0x2c91a47e
ARM_TWISTER = 0x92fb37c8
ARM_HURRICANE = 0x67ceee93
ARM_MONSOON_MISTRAL = 0xe81e7ef6
ARM_VORTEX_TEMPEST = 0x07d34b9f
ARM_LIGHTNING_THUNDER = 0x462504d2
ARM_FIRESTORM_ICESTORM = 0x1b588bb3
ARM_BLIZZARD_AVALANCHE = 0xda33d83d
ARM_EVEREST_SAWTOOTH = 0x8765edea
ARM_COLL = 0x2876f5b5
ARM_IBIZA = 0xfa33415e
ARM_LOBOS = 0x5f4dea93
ARM_PALMA = 0x72015832
ARM_DONAN = 0x6f5129ac
ARM_BRAVA = 0x17d5b93a
ARM_TAHITI = 0x75d4acb9
ARM_TUPAI = 0x204526d0
ARM_HIDRA = 0x1d5a87e8
ARM_SOTRA = 0xf76c5b1a
ARM_THERA = 0xab345f09
ARM_TILOS = 0x01d7a72b
_

std.c.darwin.DB_RECORDTYPE

container

Source line 1525

From Common Security Services Manager Security.framework/Headers/cssm*.h

Fields

SCHEMA_INFO = SCHEMA_START + 0
SCHEMA_INDEXES = SCHEMA_START + 1
SCHEMA_ATTRIBUTES = SCHEMA_START + 2
SCHEMA_PARSING_MODULE = SCHEMA_START + 3
ANY = OPEN_GROUP_START + 0
CERT = OPEN_GROUP_START + 1
CRL = OPEN_GROUP_START + 2
POLICY = OPEN_GROUP_START + 3
GENERIC = OPEN_GROUP_START + 4
PUBLIC_KEY = OPEN_GROUP_START + 5
PRIVATE_KEY = OPEN_GROUP_START + 6
SYMMETRIC_KEY = OPEN_GROUP_START + 7
ALL_KEYS = OPEN_GROUP_START + 8
GENERIC_PASSWORD = APP_DEFINED_START + 0
INTERNET_PASSWORD = APP_DEFINED_START + 1
APPLESHARE_PASSWORD = APP_DEFINED_START + 2
X509_CERTIFICATE = APP_DEFINED_START + 0x1000
USER_TRUST
X509_CRL
UNLOCK_REFERRAL
EXTENDED_ATTRIBUTE
METADATA = APP_DEFINED_START + 0x8000
_

std.c.darwin.DB_RECORDTYPE.APP_DEFINED_END

constant

Source line 1567

std.c.darwin.DB_RECORDTYPE.APP_DEFINED_START

constant

Source line 1566

std.c.darwin.DB_RECORDTYPE.OPEN_GROUP_END

constant

Source line 1563

std.c.darwin.DB_RECORDTYPE.OPEN_GROUP_START

constant

Source line 1562

std.c.darwin.DB_RECORDTYPE.SCHEMA_END

constant

Source line 1559

std.c.darwin.DB_RECORDTYPE.SCHEMA_START

constant

Source line 1558

std.c.darwin.dispatch

alias

Source line 22

Alias of std.c.darwin.dispatch

std.c.darwin.dl_info

container

Source line 364

Fields

fname: [*:0]const u8
fbase: *anyopaque
sname: ?[*:0]const u8
saddr: ?*anyopaque

std.c.darwin.dladdr

function

Source line 362

pub extern "c" fn dladdr(addr: *const anyopaque, info: *dl_info) c_int

Parameters

addr: *const anyopaque
info: *dl_info

std.c.darwin.dyld_image_path_containing_address

function

Source line 361

pub extern "c" fn dyld_image_path_containing_address(address: *const anyopaque) ?[*:0]const u8

Parameters

address: *const anyopaque

std.c.darwin.E

container

Source line 1295

Fields

SUCCESS = 0

No error occurred.

PERM = 1

Operation not permitted

NOENT = 2

No such file or directory

SRCH = 3

No such process

INTR = 4

Interrupted system call

IO = 5

Input/output error

NXIO = 6

Device not configured

@"2BIG" = 7

Argument list too long

NOEXEC = 8

Exec format error

BADF = 9

Bad file descriptor

CHILD = 10

No child processes

DEADLK = 11

Resource deadlock avoided

NOMEM = 12

Cannot allocate memory

ACCES = 13

Permission denied

FAULT = 14

Bad address

NOTBLK = 15

Block device required

BUSY = 16

Device / Resource busy

EXIST = 17

File exists

XDEV = 18

Cross-device link

NODEV = 19

Operation not supported by device

NOTDIR = 20

Not a directory

ISDIR = 21

Is a directory

INVAL = 22

Invalid argument

NFILE = 23

Too many open files in system

MFILE = 24

Too many open files

NOTTY = 25

Inappropriate ioctl for device

TXTBSY = 26

Text file busy

FBIG = 27

File too large

NOSPC = 28

No space left on device

SPIPE = 29

Illegal seek

ROFS = 30

Read-only file system

MLINK = 31

Too many links

PIPE = 32

Broken pipe

DOM = 33

Numerical argument out of domain

RANGE = 34

Result too large

AGAIN = 35

Resource temporarily unavailable This is the same code used for WOULDBLOCK.

INPROGRESS = 36

Operation now in progress

ALREADY = 37

Operation already in progress

NOTSOCK = 38

Socket operation on non-socket

DESTADDRREQ = 39

Destination address required

MSGSIZE = 40

Message too long

PROTOTYPE = 41

Protocol wrong type for socket

NOPROTOOPT = 42

Protocol not available

PROTONOSUPPORT = 43

Protocol not supported

SOCKTNOSUPPORT = 44

Socket type not supported

OPNOTSUPP = 45

Operation not supported The same code is used for NOTSUP.

PFNOSUPPORT = 46

Protocol family not supported

AFNOSUPPORT = 47

Address family not supported by protocol family

ADDRINUSE = 48

Address already in use

ADDRNOTAVAIL = 49

Can't assign requested address

NETDOWN = 50

Network is down

NETUNREACH = 51

Network is unreachable

NETRESET = 52

Network dropped connection on reset

CONNABORTED = 53

Software caused connection abort

CONNRESET = 54

Connection reset by peer

NOBUFS = 55

No buffer space available

ISCONN = 56

Socket is already connected

NOTCONN = 57

Socket is not connected

SHUTDOWN = 58

Can't send after socket shutdown

TOOMANYREFS = 59

Too many references: can't splice

TIMEDOUT = 60

Operation timed out

CONNREFUSED = 61

Connection refused

LOOP = 62

Too many levels of symbolic links

NAMETOOLONG = 63

File name too long

HOSTDOWN = 64

Host is down

HOSTUNREACH = 65

No route to host

NOTEMPTY = 66

Directory not empty

PROCLIM = 67

Too many processes

USERS = 68

Too many users

DQUOT = 69

Disc quota exceeded

STALE = 70

Stale NFS file handle

REMOTE = 71

Too many levels of remote in path

BADRPC = 72

RPC struct is bad

RPCMISMATCH = 73

RPC version wrong

PROGUNAVAIL = 74

RPC prog. not avail

PROGMISMATCH = 75

Program version wrong

PROCUNAVAIL = 76

Bad procedure for program

NOLCK = 77

No locks available

NOSYS = 78

Function not implemented

FTYPE = 79

Inappropriate file type or format

AUTH = 80

Authentication error

NEEDAUTH = 81

Need authenticator

PWROFF = 82

Device power is off

DEVERR = 83

Device error, e.g. paper out

OVERFLOW = 84

Value too large to be stored in data type

BADEXEC = 85

Bad executable

BADARCH = 86

Bad CPU type in executable

SHLIBVERS = 87

Shared library version mismatch

BADMACHO = 88

Malformed Macho file

CANCELED = 89

Operation canceled

IDRM = 90

Identifier removed

NOMSG = 91

No message of desired type

ILSEQ = 92

Illegal byte sequence

NOATTR = 93

Attribute not found

BADMSG = 94

Bad message

MULTIHOP = 95

Reserved

NODATA = 96

No message available on STREAM

NOLINK = 97

Reserved

NOSR = 98

No STREAM resources

NOSTR = 99

Not a STREAM

PROTO = 100

Protocol error

TIME = 101

STREAM ioctl timeout

NOPOLICY = 103

No such policy registered

NOTRECOVERABLE = 104

State not recoverable

OWNERDEAD = 105

Previous owner died

QFULL = 106

Interface output queue is full

NOTCAPABLE = 107

Capabilities insufficient

_

std.c.darwin.EXC

container

Source line 26

Fields

NULL = 0
BAD_ACCESS = 1

Could not access memory

BAD_INSTRUCTION = 2

Instruction failed

ARITHMETIC = 3

Arithmetic exception

EMULATION = 4

Emulation instruction

SOFTWARE = 5

Software generated exception

BREAKPOINT = 6

Trace, breakpoint, etc.

SYSCALL = 7

System calls.

MACH_SYSCALL = 8

Mach system calls.

RPC_ALERT = 9

RPC alert

CRASH = 10

Abnormal process exit

RESOURCE = 11

Hit resource consumption limit

GUARD = 12

Violated guarded resource protections

CORPSE_NOTIFY = 13

Abnormal process exited to corpse state

_

std.c.darwin.EXC.MASK

container

Source line 60

Fields

_0: u1 = 0
BAD_ACCESS: bool = false
BAD_INSTRUCTION: bool = false
ARITHMETIC: bool = false
EMULATION: bool = false
SOFTWARE: bool = false
BREAKPOINT: bool = false
SYSCALL: bool = false
MACH_SYSCALL: bool = false
RPC_ALERT: bool = false
CRASH: bool = false
RESOURCE: bool = false
GUARD: bool = false
CORPSE_NOTIFY: bool = false
_14: u18 = 0

std.c.darwin.EXC.MASK.ALL

constant

Source line 79

MASK

std.c.darwin.EXC.MASK.MACHINE

constant

Source line 77

MASK

std.c.darwin.EXC.SOFT_SIGNAL

constant

Source line 58

std.c.darwin.EXC.TYPES_COUNT

constant

Source line 57

std.c.darwin.EXCEPTION

container

Source line 97

Fields

DEFAULT = 1

Send a catch_exception_raise message including the identity.

STATE = 2

Send a catch_exception_raise_state message including the thread state.

STATE_IDENTITY = 3

Send a catch_exception_raise_state_identity message including the thread identity and state.

IDENTITY_PROTECTED = 4

Send a catch_exception_raise_identity_protected message including protected task and thread identity.

_

std.c.darwin.exception_behavior_array_t

type

Source line 446

std.c.darwin.exception_behavior_t

type

Source line 445

std.c.darwin.exception_data_t

type

Source line 420

std.c.darwin.exception_data_type_t

alias

Source line 419

Alias of std.c.darwin.integer_t

std.c.darwin.exception_flavor_array_t

type

Source line 444

std.c.darwin.exception_handler_array_t

type

Source line 441

std.c.darwin.exception_handler_t

alias

Source line 440

Alias of std.c.darwin.mach_port_t

std.c.darwin.exception_mask_array_t

type

Source line 439

std.c.darwin.exception_mask_t

type

Source line 438

std.c.darwin.exception_port_array_t

alias

Source line 443

Alias of std.c.darwin.exception_handler_array_t

std.c.darwin.exception_port_t

alias

Source line 442

Alias of std.c.darwin.exception_handler_t

std.c.darwin.exception_type_t

type

Source line 352

std.c.darwin.FCNTL_FS_SPECIFIC_BASE

constant

Source line 1158

std.c.darwin.fcopyfile

function

Source line 380

pub extern "c" fn fcopyfile(from: fd_t, to: fd_t, state: ?copyfile_state_t, flags: COPYFILE) c_int

Parameters

from: fd_t
to: fd_t
state: ?copyfile_state_t
flags: COPYFILE

std.c.darwin.fd_t

alias

Source line 8

Alias of std.c.fd_t

std.c.darwin.host_t

alias

Source line 1040

Alias of std.c.darwin.mach_port_t

std.c.darwin.integer_t

type

Source line 1041

std.c.darwin.iovec_const

alias

Source line 9

Alias of std.posix.iovec_const

std.c.darwin.IP

namespace

Source line 1643

std.c.darwin.IP.ADD_MEMBERSHIP

constant

Source line 1655

std.c.darwin.IP.ADD_SOURCE_MEMBERSHIP

constant

Source line 1691

std.c.darwin.IP.BLOCK_SOURCE

constant

Source line 1693

std.c.darwin.IP.BOUND_IF

constant

Source line 1668

std.c.darwin.IP.DEFAULT_MULTICAST_LOOP

constant

Source line 1698

std.c.darwin.IP.DEFAULT_MULTICAST_TTL

constant

Source line 1697

std.c.darwin.IP.DONTFRAG

constant

Source line 1672

std.c.darwin.IP.DROP_MEMBERSHIP

constant

Source line 1656

std.c.darwin.IP.DROP_SOURCE_MEMBERSHIP

constant

Source line 1692

std.c.darwin.IP.DUMMYNET_CONFIGURE

constant

Source line 1685

std.c.darwin.IP.DUMMYNET_DEL

constant

Source line 1686

std.c.darwin.IP.DUMMYNET_FLUSH

constant

Source line 1687

std.c.darwin.IP.DUMMYNET_GET

constant

Source line 1688

std.c.darwin.IP.FAITH

constant

Source line 1665

std.c.darwin.IP.FW_ADD

constant

Source line 1673

std.c.darwin.IP.FW_DEL

constant

Source line 1674

std.c.darwin.IP.FW_FLUSH

constant

Source line 1675

std.c.darwin.IP.FW_GET

constant

Source line 1677

std.c.darwin.IP.FW_RESETLOG

constant

Source line 1678

std.c.darwin.IP.FW_ZERO

constant

Source line 1676

std.c.darwin.IP.HDRINCL

constant

Source line 1645

std.c.darwin.IP.IPSEC_POLICY

constant

Source line 1664

std.c.darwin.IP.MAX_GROUP_SRC_FILTER

constant

Source line 1701

std.c.darwin.IP.MAX_MEMBERSHIPS

constant

Source line 1700

std.c.darwin.IP.MAX_SOCK_MUTE_FILTER

constant

Source line 1703

std.c.darwin.IP.MAX_SOCK_SRC_FILTER

constant

Source line 1702

std.c.darwin.IP.MIN_MEMBERSHIPS

constant

Source line 1699

std.c.darwin.IP.MSFILTER

constant

Source line 1695

std.c.darwin.IP.MULTICAST_IF

constant

Source line 1652

std.c.darwin.IP.MULTICAST_IFINDEX

constant

Source line 1690

std.c.darwin.IP.MULTICAST_LOOP

constant

Source line 1654

std.c.darwin.IP.MULTICAST_TTL

constant

Source line 1653

std.c.darwin.IP.MULTICAST_VIF

constant

Source line 1657

std.c.darwin.IP.OLD_FW_ADD

constant

Source line 1679

std.c.darwin.IP.OLD_FW_DEL

constant

Source line 1680

std.c.darwin.IP.OLD_FW_FLUSH

constant

Source line 1681

std.c.darwin.IP.OLD_FW_GET

constant

Source line 1683

std.c.darwin.IP.OLD_FW_RESETLOG

constant

Source line 1684

std.c.darwin.IP.OLD_FW_ZERO

constant

Source line 1682

std.c.darwin.IP.OPTIONS

constant

Source line 1644

std.c.darwin.IP.PKTINFO

constant

Source line 1669

std.c.darwin.IP.PORTRANGE

constant

Source line 1662

std.c.darwin.IP.PORTRANGE_DEFAULT

constant

Source line 1704

std.c.darwin.IP.PORTRANGE_HIGH

constant

Source line 1705

std.c.darwin.IP.PORTRANGE_LOW

constant

Source line 1706

std.c.darwin.IP.RECVDSTADDR

constant

Source line 1650

std.c.darwin.IP.RECVIF

constant

Source line 1663

std.c.darwin.IP.RECVOPTS

constant

Source line 1648

std.c.darwin.IP.RECVPKTINFO

alias

Source line 1670

Alias of std.c.darwin.IP.PKTINFO

std.c.darwin.IP.RECVRETOPTS

constant

Source line 1649

std.c.darwin.IP.RECVTOS

constant

Source line 1671

std.c.darwin.IP.RECVTTL

constant

Source line 1667

std.c.darwin.IP.RETOPTS

constant

Source line 1651

std.c.darwin.IP.RSVP_OFF

constant

Source line 1659

std.c.darwin.IP.RSVP_ON

constant

Source line 1658

std.c.darwin.IP.RSVP_VIF_OFF

constant

Source line 1661

std.c.darwin.IP.RSVP_VIF_ON

constant

Source line 1660

std.c.darwin.IP.STRIPHDR

constant

Source line 1666

std.c.darwin.IP.TOS

constant

Source line 1646

std.c.darwin.IP.TRAFFIC_MGT_BACKGROUND

constant

Source line 1689

std.c.darwin.IP.TTL

constant

Source line 1647

std.c.darwin.IP.UNBLOCK_SOURCE

constant

Source line 1694

std.c.darwin.ipc_space_port_t

alias

Source line 449

Alias of std.c.darwin.ipc_space_t

std.c.darwin.ipc_space_t

alias

Source line 448

Alias of std.c.darwin.mach_port_t

std.c.darwin.IPTOS

namespace

Source line 1781

std.c.darwin.IPTOS.CE

constant

Source line 1786

std.c.darwin.IPTOS.DSCP_SHIFT

constant

Source line 1788

std.c.darwin.IPTOS.ECN_CE

constant

Source line 1792

std.c.darwin.IPTOS.ECN_ECT0

constant

Source line 1791

std.c.darwin.IPTOS.ECN_ECT1

constant

Source line 1790

std.c.darwin.IPTOS.ECN_MASK

constant

Source line 1793

std.c.darwin.IPTOS.ECN_NOTECT

constant

Source line 1789

std.c.darwin.IPTOS.ECT

constant

Source line 1787

std.c.darwin.IPTOS.LOWDELAY

constant

Source line 1782

std.c.darwin.IPTOS.MINCOST

constant

Source line 1785

std.c.darwin.IPTOS.PREC_CRITIC_ECP

constant

Source line 1796

std.c.darwin.IPTOS.PREC_FLASH

constant

Source line 1798

std.c.darwin.IPTOS.PREC_FLASHOVERRIDE

constant

Source line 1797

std.c.darwin.IPTOS.PREC_IMMEDIATE

constant

Source line 1799

std.c.darwin.IPTOS.PREC_INTERNETCONTROL

constant

Source line 1795

std.c.darwin.IPTOS.PREC_NETCONTROL

constant

Source line 1794

std.c.darwin.IPTOS.PREC_PRIORITY

constant

Source line 1800

std.c.darwin.IPTOS.PREC_ROUTINE

constant

Source line 1801

std.c.darwin.IPTOS.RELIABILITY

constant

Source line 1784

std.c.darwin.IPTOS.THROUGHPUT

constant

Source line 1783

std.c.darwin.IPV6

namespace

Source line 1710

std.c.darwin.IPV6.@"2292DSTOPTS"

constant

Source line 1722

std.c.darwin.IPV6.@"2292HOPLIMIT"

constant

Source line 1719

std.c.darwin.IPV6.@"2292HOPOPTS"

constant

Source line 1721

std.c.darwin.IPV6.@"2292NEXTHOP"

constant

Source line 1720

std.c.darwin.IPV6.@"2292PKTINFO"

constant

Source line 1718

std.c.darwin.IPV6.@"2292PKTOPTIONS"

constant

Source line 1724

std.c.darwin.IPV6.@"2292RTHDR"

constant

Source line 1723

std.c.darwin.IPV6.@"3542DSTOPTS"

constant

Source line 1752

std.c.darwin.IPV6.@"3542HOPLIMIT"

constant

Source line 1749

std.c.darwin.IPV6.@"3542HOPOPTS"

constant

Source line 1751

std.c.darwin.IPV6.@"3542NEXTHOP"

constant

Source line 1750

std.c.darwin.IPV6.@"3542PKTINFO"

constant

Source line 1748

std.c.darwin.IPV6.@"3542RTHDR"

constant

Source line 1753

std.c.darwin.IPV6.AUTOFLOWLABEL

constant

Source line 1760

std.c.darwin.IPV6.BINDV6ONLY

alias

Source line 1727

Alias of std.c.darwin.IPV6.V6ONLY

std.c.darwin.IPV6.BOUND_IF

constant

Source line 1764

std.c.darwin.IPV6.CHECKSUM

constant

Source line 1725

std.c.darwin.IPV6.DEFAULT_MULTICAST_HOPS

constant

Source line 1769

std.c.darwin.IPV6.DEFAULT_MULTICAST_LOOP

constant

Source line 1770

std.c.darwin.IPV6.DONTFRAG

constant

Source line 1761

std.c.darwin.IPV6.DSTOPTS

alias

Source line 1758

Alias of std.c.darwin.IPV6.@"3542DSTOPTS"

std.c.darwin.IPV6.FAITH

constant

Source line 1729

std.c.darwin.IPV6.FW_ADD

constant

Source line 1730

std.c.darwin.IPV6.FW_DEL

constant

Source line 1731

std.c.darwin.IPV6.FW_FLUSH

constant

Source line 1732

std.c.darwin.IPV6.FW_GET

constant

Source line 1734

std.c.darwin.IPV6.FW_ZERO

constant

Source line 1733

std.c.darwin.IPV6.HOPLIMIT

alias

Source line 1755

Alias of std.c.darwin.IPV6.@"3542HOPLIMIT"

std.c.darwin.IPV6.HOPOPTS

alias

Source line 1757

Alias of std.c.darwin.IPV6.@"3542HOPOPTS"

std.c.darwin.IPV6.IPSEC_POLICY

constant

Source line 1728

std.c.darwin.IPV6.JOIN_GROUP

constant

Source line 1715

std.c.darwin.IPV6.LEAVE_GROUP

constant

Source line 1716

std.c.darwin.IPV6.MAX_GROUP_SRC_FILTER

constant

Source line 1773

std.c.darwin.IPV6.MAX_MEMBERSHIPS

constant

Source line 1772

std.c.darwin.IPV6.MAX_SOCK_SRC_FILTER

constant

Source line 1774

std.c.darwin.IPV6.MIN_MEMBERSHIPS

constant

Source line 1771

std.c.darwin.IPV6.MSFILTER

constant

Source line 1763

std.c.darwin.IPV6.MULTICAST_HOPS

constant

Source line 1713

std.c.darwin.IPV6.MULTICAST_IF

constant

Source line 1712

std.c.darwin.IPV6.MULTICAST_LOOP

constant

Source line 1714

std.c.darwin.IPV6.NEXTHOP

alias

Source line 1756

Alias of std.c.darwin.IPV6.@"3542NEXTHOP"

std.c.darwin.IPV6.PATHMTU

constant

Source line 1746

std.c.darwin.IPV6.PKTINFO

alias

Source line 1754

Alias of std.c.darwin.IPV6.@"3542PKTINFO"

std.c.darwin.IPV6.PORTRANGE

constant

Source line 1717

std.c.darwin.IPV6.PORTRANGE_DEFAULT

constant

Source line 1775

std.c.darwin.IPV6.PORTRANGE_HIGH

constant

Source line 1776

std.c.darwin.IPV6.PORTRANGE_LOW

constant

Source line 1777

std.c.darwin.IPV6.PREFER_TEMPADDR

constant

Source line 1762

std.c.darwin.IPV6.REACHCONF

constant

Source line 1747

std.c.darwin.IPV6.RECVDSTOPTS

constant

Source line 1742

std.c.darwin.IPV6.RECVHOPLIMIT

constant

Source line 1739

std.c.darwin.IPV6.RECVHOPOPTS

constant

Source line 1741

std.c.darwin.IPV6.RECVPATHMTU

constant

Source line 1745

std.c.darwin.IPV6.RECVPKTINFO

constant

Source line 1738

std.c.darwin.IPV6.RECVRTHDR

constant

Source line 1740

std.c.darwin.IPV6.RECVRTHDRDSTOPTS

constant

Source line 1743

std.c.darwin.IPV6.RECVTCLASS

constant

Source line 1735

std.c.darwin.IPV6.RTHDR

alias

Source line 1759

Alias of std.c.darwin.IPV6.@"3542RTHDR"

std.c.darwin.IPV6.RTHDR_LOOSE

constant

Source line 1766

std.c.darwin.IPV6.RTHDR_STRICT

constant

Source line 1767

std.c.darwin.IPV6.RTHDR_TYPE_0

constant

Source line 1768

std.c.darwin.IPV6.RTHDRDSTOPTS

constant

Source line 1737

std.c.darwin.IPV6.TCLASS

constant

Source line 1736

std.c.darwin.IPV6.UNICAST_HOPS

constant

Source line 1711

std.c.darwin.IPV6.USE_MIN_MTU

constant

Source line 1744

std.c.darwin.IPV6.V6ONLY

constant

Source line 1726

std.c.darwin.kern_return_t

type

Source line 1039

std.c.darwin.KEVENT

namespace

Source line 113

std.c.darwin.KEVENT.FLAG

container

Source line 115

Used as the flags arg for kevent64.

Fields

IMMEDIATE: bool = false

immediate timeout

ERROR_EVENTS: bool = false

output events only include change

_: u30 = 0

std.c.darwin.KEVENT.FLAG.NONE

constant

Source line 123

no flag value

KEVENT.FLAG

std.c.darwin.kevent64

function

Source line 399

pub extern "c" fn kevent64( kq: c_int, changelist: [*]const kevent64_s, nchanges: c_int, eventlist: [*]kevent64_s, nevents: c_int, flags: KEVENT.FLAG, timeout: ?*const timespec, ) c_int

Parameters

kq: c_int
changelist: [*]const kevent64_s
nchanges: c_int
eventlist: [*]kevent64_s
nevents: c_int
flags: KEVENT.FLAG
timeout: ?*const timespec

std.c.darwin.kevent64_s

container

Source line 1006

Fields

ident: u64
filter: i16
flags: u16
fflags: u32
data: i64
udata: u64
ext: [2]u64

std.c.darwin.MACH

namespace

Source line 130

std.c.darwin.mach_absolute_time

function

Source line 395

pub extern "c" fn mach_absolute_time() u64

std.c.darwin.mach_continuous_time

function

Source line 396

pub extern "c" fn mach_continuous_time() u64

std.c.darwin.mach_exception_data_t

type

Source line 422

std.c.darwin.mach_exception_data_type_t

type

Source line 421

std.c.darwin.mach_hdr

constant

Source line 409

std.c.darwin.mach_header

alias

Source line 412

Alias of std.macho.mach_header

std.c.darwin.mach_header_64

alias

Source line 411

Alias of std.macho.mach_header_64

std.c.darwin.mach_host_self

function

Source line 415

pub extern "c" fn mach_host_self() mach_port_t

std.c.darwin.mach_msg

function

Source line 511

pub extern "c" fn mach_msg( msg: ?*mach_msg_header_t, option: mach_msg_option_t, send_size: mach_msg_size_t, rcv_size: mach_msg_size_t, rcv_name: mach_port_name_t, timeout: mach_msg_timeout_t, notify: mach_port_name_t, ) mach_msg_return_t

Parameters

std.c.darwin.mach_msg_bits_t

type

Source line 431

std.c.darwin.mach_msg_header_t

container

Source line 521

Fields

msgh_bits: mach_msg_bits_t
msgh_size: mach_msg_size_t
msgh_remote_port: mach_port_t
msgh_local_port: mach_port_t
msgh_voucher_port: mach_port_name_t
msgh_id: mach_msg_id_t

std.c.darwin.mach_msg_id_t

alias

Source line 432

Alias of std.c.darwin.integer_t

std.c.darwin.mach_msg_option_t

container

Source line 451

Fields

RCV: MACH.RCV
SEND: MACH.SEND

std.c.darwin.mach_msg_option_t.NONE

constant

Source line 455

mach_msg_option_t

std.c.darwin.mach_msg_option_t.sendAndRcv

function

Source line 457

pub fn sendAndRcv(send: MACH.SEND, rcv: MACH.RCV) mach_msg_option_t

Parameters

send: MACH.SEND
rcv: MACH.RCV

std.c.darwin.mach_msg_return_t

container

Source line 1056

Mach msg return values

Fields

SUCCESS = 0x00000000
SEND_IN_PROGRESS = 0x10000001

Thread is waiting to send. (Internal use only.)

SEND_INVALID_DATA = 0x10000002

Bogus in-line data.

SEND_INVALID_DEST = 0x10000003

Bogus destination port.

SEND_TIMED_OUT = 0x10000004

Message not sent before timeout expired.

SEND_INVALID_VOUCHER = 0x10000005

Bogus voucher port.

SEND_INTERRUPTED = 0x10000007

Software interrupt.

SEND_MSG_TOO_SMALL = 0x10000008

Data doesn't contain a complete message.

SEND_INVALID_REPLY = 0x10000009

Bogus reply port.

SEND_INVALID_RIGHT = 0x1000000a

Bogus port rights in the message body.

SEND_INVALID_NOTIFY = 0x1000000b

Bogus notify port argument.

SEND_INVALID_MEMORY = 0x1000000c

Invalid out-of-line memory pointer.

SEND_NO_BUFFER = 0x1000000d

No message buffer is available.

SEND_TOO_LARGE = 0x1000000e

Send is too large for port

SEND_INVALID_TYPE = 0x1000000f

Invalid msg-type specification.

SEND_INVALID_HEADER = 0x10000010

A field in the header had a bad value.

SEND_INVALID_TRAILER = 0x10000011

The trailer to be sent does not match kernel format.

SEND_INVALID_CONTEXT = 0x10000012

The sending thread context did not match the context on the dest port

SEND_INVALID_RT_OOL_SIZE = 0x10000015

compatibility: no longer a returned error

SEND_NO_GRANT_DEST = 0x10000016

The destination port doesn't accept ports in body

SEND_MSG_FILTERED = 0x10000017

Message send was rejected by message filter

RCV_IN_PROGRESS = 0x10004001

Thread is waiting for receive. (Internal use only.)

RCV_INVALID_NAME = 0x10004002

Bogus name for receive port/port-set.

RCV_TIMED_OUT = 0x10004003

Didn't get a message within the timeout value.

RCV_TOO_LARGE = 0x10004004

Message buffer is not large enough for inline data.

RCV_INTERRUPTED = 0x10004005

Software interrupt.

RCV_PORT_CHANGED = 0x10004006

compatibility: no longer a returned error

RCV_INVALID_NOTIFY = 0x10004007

Bogus notify port argument.

RCV_INVALID_DATA = 0x10004008

Bogus message buffer for inline data.

RCV_PORT_DIED = 0x10004009

Port/set was sent away/died during receive.

RCV_IN_SET = 0x1000400a

compatibility: no longer a returned error

RCV_HEADER_ERROR = 0x1000400b

Error receiving message header. See special bits (use extractResourceError).

RCV_BODY_ERROR = 0x1000400c

Error receiving message body. See special bits (use extractResourceError).

RCV_INVALID_TYPE = 0x1000400d

Invalid msg-type specification in scatter list.

RCV_SCATTER_SMALL = 0x1000400e

Out-of-line overwrite region is not large enough

RCV_INVALID_TRAILER = 0x1000400f

trailer type or number of trailer elements not supported

RCV_IN_PROGRESS_TIMED = 0x10004011

Waiting for receive with timeout. (Internal use only.)

RCV_INVALID_REPLY = 0x10004012

invalid reply port used in a STRICT_REPLY message

_

std.c.darwin.mach_msg_return_t.extractResourceError

type-function

Source line 1137

pub fn extractResourceError(ret: mach_msg_return_t) struct { error_code: mach_msg_return_t, resource_error: ?MACH.MSG, }

Parameters

std.c.darwin.mach_msg_size_t

alias

Source line 434

Alias of std.c.darwin.natural_t

std.c.darwin.mach_msg_timeout_t

container

Source line 462

Fields

NONE = 0
_

std.c.darwin.MACH_MSG_TYPE

constant

Source line 233

std.c.darwin.mach_msg_type_name_t

container

Source line 467

Fields

MOVE_RECEIVE = 16

Must hold receive right

MOVE_SEND = 17

Must hold send right(s)

MOVE_SEND_ONCE = 18

Must hold sendonce right

COPY_SEND = 19

Must hold send right(s)

MAKE_SEND = 20

Must hold receive right

MAKE_SEND_ONCE = 21

Must hold receive right

COPY_RECEIVE = 22

NOT VALID

DISPOSE_RECEIVE = 24

Must hold receive right

DISPOSE_SEND = 25

Must hold send right(s)

DISPOSE_SEND_ONCE = 26

Must hold sendonce right

_

std.c.darwin.mach_msg_type_number_t

alias

Source line 433

Alias of std.c.darwin.natural_t

std.c.darwin.mach_port_allocate

function

Source line 844

pub extern "c" fn mach_port_allocate( task: ipc_space_t, right: mach_port_right_t, name: *mach_port_name_t, ) kern_return_t

Parameters

std.c.darwin.mach_port_array_t

type

Source line 699

std.c.darwin.mach_port_deallocate

function

Source line 849

pub extern "c" fn mach_port_deallocate(task: ipc_space_t, name: mach_port_name_t) kern_return_t

Parameters

std.c.darwin.mach_port_insert_right

function

Source line 850

pub extern "c" fn mach_port_insert_right( task: ipc_space_t, name: mach_port_name_t, right: mach_port_t, right_type: mach_msg_type_name_t, ) kern_return_t

Parameters

std.c.darwin.mach_port_name_t

alias

Source line 1033

Alias of std.c.darwin.natural_t

std.c.darwin.MACH_PORT_RIGHT

constant

Source line 234

std.c.darwin.mach_port_right_t

container

Source line 492

Fields

SEND = 0
RECEIVE = 1
SEND_ONCE = 2
PORT_SET = 3
DEAD_NAME = 4
LABELH = 5

Obsolete right

NUMBER = 6

Right not implemented

_

std.c.darwin.mach_port_t

type

Source line 24

std.c.darwin.mach_task_basic_info

container

Source line 864

Fields

virtual_size: mach_vm_size_t

Virtual memory size (bytes)

resident_size: mach_vm_size_t

Resident memory size (bytes)

user_time: time_value_t

Total user run time for terminated threads

system_time: time_value_t

Total system run time for terminated threads

policy: policy_t

Default policy for new threads

suspend_count: mach_vm_size_t

Suspend count for task

std.c.darwin.MACH_TASK_BASIC_INFO

constant

Source line 235

std.c.darwin.MACH_TASK_BASIC_INFO_COUNT

constant

Source line 236

std.c.darwin.mach_task_self

function

Source line 507

pub fn mach_task_self() callconv(.c) mach_port_t

std.c.darwin.mach_task_self_

variable

Source line 506

mach_port_t

std.c.darwin.mach_timebase_info

function

Source line 397

pub extern "c" fn mach_timebase_info(tinfo: ?*mach_timebase_info_data) kern_return_t

Parameters

std.c.darwin.mach_timebase_info_data

container

Source line 1001

Fields

numer: u32
denom: u32

std.c.darwin.mach_timespec_t

container

Source line 1035

Fields

sec: c_uint
nsec: clock_res_t

std.c.darwin.mach_vm_address_t

type

Source line 428

std.c.darwin.mach_vm_protect

function

Source line 836

pub extern "c" fn mach_vm_protect( target_task: vm_map_t, address: mach_vm_address_t, size: mach_vm_size_t, set_maximum: boolean_t, new_protection: vm_prot_t, ) kern_return_t

Parameters

target_task: vm_map_t
address: mach_vm_address_t
size: mach_vm_size_t
set_maximum: boolean_t
new_protection: vm_prot_t

std.c.darwin.mach_vm_read

function

Source line 554

pub extern "c" fn mach_vm_read( target_task: vm_map_read_t, address: mach_vm_address_t, size: mach_vm_size_t, data: *vm_offset_t, data_cnt: *mach_msg_type_number_t, ) kern_return_t

Parameters

target_task: vm_map_read_t
address: mach_vm_address_t
size: mach_vm_size_t
data: *vm_offset_t
data_cnt: *mach_msg_type_number_t

std.c.darwin.mach_vm_read_overwrite

function

Source line 561

pub extern "c" fn mach_vm_read_overwrite( target_task: vm_map_read_t, address: mach_vm_address_t, size: mach_vm_size_t, data: mach_vm_address_t, outsize: *mach_vm_size_t, ) kern_return_t

Parameters

target_task: vm_map_read_t
address: mach_vm_address_t
size: mach_vm_size_t
data: mach_vm_address_t
outsize: *mach_vm_size_t

std.c.darwin.mach_vm_region

function

Source line 574

pub extern "c" fn mach_vm_region( target_task: vm_map_t, address: *mach_vm_address_t, size: *mach_vm_size_t, flavor: vm_region_flavor_t, info: vm_region_info_t, info_cnt: *mach_msg_type_number_t, object_name: *mach_port_t, ) kern_return_t

Parameters

target_task: vm_map_t
address: *mach_vm_address_t
size: *mach_vm_size_t
flavor: vm_region_flavor_t
info: vm_region_info_t
info_cnt: *mach_msg_type_number_t
object_name: *mach_port_t

std.c.darwin.mach_vm_region_recurse

function

Source line 583

pub extern "c" fn mach_vm_region_recurse( target_task: vm_map_t, address: *mach_vm_address_t, size: *mach_vm_size_t, nesting_depth: *natural_t, info: vm_region_recurse_info_t, info_cnt: *mach_msg_type_number_t, ) kern_return_t

Parameters

target_task: vm_map_t
address: *mach_vm_address_t
size: *mach_vm_size_t
nesting_depth: *natural_t
info: vm_region_recurse_info_t
info_cnt: *mach_msg_type_number_t

std.c.darwin.mach_vm_size_t

type

Source line 430

std.c.darwin.mach_vm_write

function

Source line 568

pub extern "c" fn mach_vm_write( target_task: vm_map_t, address: mach_vm_address_t, data: vm_offset_t, data_cnt: mach_msg_type_number_t, ) kern_return_t

Parameters

target_task: vm_map_t
address: mach_vm_address_t
data: vm_offset_t
data_cnt: mach_msg_type_number_t

std.c.darwin.MACH.EXCEPTION

container

Source line 131

Fields

_: u29 = 0
BACKTRACE_PREFERRED: bool = false

Prefer sending a catch_exception_raice_backtrace message, if applicable.

ERRORS: bool = false

include additional exception specific errors, not used yet.

CODES: bool = false

Send 64-bit code and subcode in the exception header */

std.c.darwin.MACH.EXCEPTION.MASK

constant

Source line 140

exception_mask_t

std.c.darwin.MACH.MSG

container

Source line 147

Fields

_0: u10 = 0
VM_KERNEL: bool = false

Kernel resource shortage handling an IPC capability.

IPC_KERNEL: bool = false

Kernel resource shortage handling out-of-line memory.

VM_SPACE: bool = false

No room in VM address space for out-of-line memory.

IPC_SPACE: bool = false

No room in IPC name space for another capability name.

_14: u18 = 0

std.c.darwin.MACH.MSG.MASK

constant

Source line 159

kern_return_t

std.c.darwin.MACH.MSG.OPTION_NONE

constant

Source line 167

mach_msg_option_t

std.c.darwin.MACH.MSG.STRICT_REPLY

constant

Source line 168

std.c.darwin.MACH.MSG.TIMEOUT_NONE

constant

Source line 166

mach_msg_timeout_t

std.c.darwin.MACH.MSG.TYPE

alias

Source line 170

Alias of std.c.darwin.mach_msg_type_name_t

std.c.darwin.MACH.PORT

namespace

Source line 173

std.c.darwin.MACH.PORT.NULL

constant

Source line 174

mach_port_t

std.c.darwin.MACH.PORT.RIGHT

alias

Source line 175

Alias of std.c.darwin.mach_port_right_t

std.c.darwin.MACH.RCV

container

Source line 178

Fields

_0: u1 = 0
MSG: bool = true

Other flags are only valid if this one is set.

LARGE: bool = false
LARGE_IDENTITY: bool = false
_4: u4 = 0
TIMEOUT: bool = false
STRICT_REPLY: bool = false

Shared between RCV and SEND. Used to be MACH_RCV_NOTIFY.

INTERRUPT: bool = false
VOUCHER: bool = false
GUARDED_DESC: bool = false
_13: u1 = 0
SYNC_WAIT: bool = false
SYNC_PEEK: bool = false
_16: u16 = 0

std.c.darwin.MACH.SEND

container

Source line 197

Fields

MSG: bool = true

Other flags are only valid if this one is set.

_1: u3 = 0
TIMEOUT: bool = false
OVERRIDE: bool = false
INTERRUPT: bool = false
NOTIFY: bool = false
_8: u1 = 0
STRICT_REPLY: bool = false

Shared between RCV and SEND.

_10: u6 = 0
FILTER_NONFATAL: bool = false

User-only. If you're the kernel, this bit is MACH_SEND_ALWAYS.

TRAILER: bool = false
NOIMPORTANCE: bool = false

Synonymous to MACH_SEND_NODENAP.

IMPORTANCE: bool = false

Kernel-only.

SYNC_OVERRIDE: bool = false
PROPAGATE_QOS: bool = false

Synonymous to MACH_SEND_SYNC_USE_THRPRI.

KERNEL: bool = false

Kernel-only.

SYNC_BOOTSTRAP_CHECKIN: bool = false
_24: u8 = 0

std.c.darwin.MACH.TASK

namespace

Source line 225

std.c.darwin.MACH.TASK.BASIC

namespace

Source line 226

std.c.darwin.MACH.TASK.BASIC.INFO

constant

Source line 227

std.c.darwin.MACH.TASK.BASIC.INFO_COUNT

constant

Source line 228

mach_msg_type_number_t

std.c.darwin.MATTR

namespace

Source line 238

std.c.darwin.MATTR.CACHE

constant

Source line 240

Cachability

vm_machine_attribute_t

std.c.darwin.MATTR.MIGRATE

constant

Source line 242

Migrability

vm_machine_attribute_t

std.c.darwin.MATTR.REPLICATE

constant

Source line 244

Replicability

vm_machine_attribute_t

std.c.darwin.MATTR.VAL_CACHE_FLUSH

constant

Source line 252

Flush from all caches

vm_machine_attribute_t

std.c.darwin.MATTR.VAL_CACHE_SYNC

constant

Source line 258

Sync I+D caches

vm_machine_attribute_t

std.c.darwin.MATTR.VAL_DCACHE_FLUSH

constant

Source line 254

Flush from data caches

vm_machine_attribute_t

std.c.darwin.MATTR.VAL_GET

constant

Source line 250

(Generic) return current value

vm_machine_attribute_t

std.c.darwin.MATTR.VAL_GET_INFO

constant

Source line 260

Get page info (stats)

vm_machine_attribute_t

std.c.darwin.MATTR.VAL_ICACHE_FLUSH

constant

Source line 256

Flush from instruction caches

vm_machine_attribute_t

std.c.darwin.MATTR.VAL_OFF

constant

Source line 246

(Generic) turn attribute off

vm_machine_attribute_t

std.c.darwin.MATTR.VAL_ON

constant

Source line 248

(Generic) turn attribute on

vm_machine_attribute_t

std.c.darwin.memory_object_offset_t

type

Source line 593

std.c.darwin.mode_t

alias

Source line 10

Alias of std.c.mode_t

std.c.darwin.MSG

namespace

Source line 1603

std.c.darwin.MSG.CTRUNC

constant

Source line 1615

control data lost before delivery

std.c.darwin.MSG.DONTROUTE

constant

Source line 1609

send without using routing tables

std.c.darwin.MSG.DONTWAIT

constant

Source line 1619

this message should be nonblocking

std.c.darwin.MSG.EOF

constant

Source line 1621

data completes connection

std.c.darwin.MSG.EOR

constant

Source line 1611

data completes record

std.c.darwin.MSG.FLUSH

constant

Source line 1625

Start of 'hold' seq; dump so_temp, deprecated

std.c.darwin.MSG.HAVEMORE

constant

Source line 1631

Data ready to be read

std.c.darwin.MSG.HOLD

constant

Source line 1627

Hold frag in so_temp, deprecated

std.c.darwin.MSG.NEEDSA

constant

Source line 1635

Fail receive if socket address cannot be allocated

std.c.darwin.MSG.NOSIGNAL

constant

Source line 1637

do not generate SIGPIPE on EOF

std.c.darwin.MSG.OOB

constant

Source line 1605

process out-of-band data

std.c.darwin.MSG.PEEK

constant

Source line 1607

peek at incoming message

std.c.darwin.MSG.RCVMORE

constant

Source line 1633

Data remains in current pkt

std.c.darwin.MSG.SEND

constant

Source line 1629

Send the packet in so_temp, deprecated

std.c.darwin.MSG.TRUNC

constant

Source line 1613

data discarded before delivery

std.c.darwin.MSG.USEUPCALL

constant

Source line 1639

Inherit upcall in sock_accept

std.c.darwin.MSG.WAITALL

constant

Source line 1617

wait for full request or error

std.c.darwin.MSG.WAITSTREAM

constant

Source line 1623

wait up to full request, may return partial

std.c.darwin.native_arch

constant

Source line 3

std.c.darwin.natural_t

type

Source line 1034

std.c.darwin.NSIG

constant

Source line 902

std.c.darwin.NSVersionOfRunTimeLibrary

function

Source line 354

pub extern "c" fn NSVersionOfRunTimeLibrary(library_name: [*:0]const u8) u32

Parameters

library_name: [*:0]const u8

std.c.darwin.off_t

alias

Source line 11

Alias of std.c.off_t

std.c.darwin.OPEN_MAX

constant

Source line 1162

std.c.darwin.OS

namespace

Source line 263

std.c.darwin.os_log_create

function

Source line 987

pub extern "c" fn os_log_create(subsystem: [*]const u8, category: [*]const u8) os_log_t

Parameters

subsystem: [*]const u8
category: [*]const u8

std.c.darwin.os_log_t

type

Source line 971

std.c.darwin.os_log_type_enabled

function

Source line 988

pub extern "c" fn os_log_type_enabled(log: os_log_t, tpe: os_log_type_t) bool

Parameters

std.c.darwin.os_log_type_t

container

Source line 972

Fields

DEFAULT = 0x00

default messages always captures

INFO = 0x01

messages with additional infos

DEBUG = 0x02

debug messages

ERROR = 0x10

error messages

FAULT = 0x11

unexpected conditions messages

_

std.c.darwin.os_signpost_enabled

function

Source line 993

pub extern "c" fn os_signpost_enabled(log: os_log_t) bool

Parameters

log: os_log_t

std.c.darwin.os_signpost_id_generate

function

Source line 989

pub extern "c" fn os_signpost_id_generate(log: os_log_t) os_signpost_id_t

Parameters

log: os_log_t

std.c.darwin.os_signpost_id_make_with_pointer

function

Source line 992

pub extern "c" fn os_signpost_id_make_with_pointer(log: os_log_t, ptr: ?*anyopaque) os_signpost_id_t

Parameters

log: os_log_t
ptr: ?*anyopaque

std.c.darwin.os_signpost_id_t

container

Source line 964

Fields

NULL = 0
INVALID = !0
EXCLUSIVE = 0xeeeeb0b5b2b2eeee
_

std.c.darwin.os_signpost_interval_begin

function

Source line 990

pub extern "c" fn os_signpost_interval_begin(log: os_log_t, signpos: os_signpost_id_t, func: [*]const u8, ...) void

Parameters

log: os_log_t
signpos: os_signpost_id_t
func: [*]const u8

std.c.darwin.os_signpost_interval_end

function

Source line 991

pub extern "c" fn os_signpost_interval_end(log: os_log_t, signpos: os_signpost_id_t, func: [*]const u8, ...) void

Parameters

log: os_log_t
signpos: os_signpost_id_t
func: [*]const u8

std.c.darwin.os_unfair_lock

container

Source line 954

Fields

_os_unfair_lock_opaque: u32 = 0

std.c.darwin.os_unfair_lock_assert_not_owner

function

Source line 962

pub extern "c" fn os_unfair_lock_assert_not_owner(o: os_unfair_lock_t) void

Parameters

std.c.darwin.os_unfair_lock_assert_owner

function

Source line 961

pub extern "c" fn os_unfair_lock_assert_owner(o: os_unfair_lock_t) void

Parameters

std.c.darwin.os_unfair_lock_lock

function

Source line 958

pub extern "c" fn os_unfair_lock_lock(o: os_unfair_lock_t) void

Parameters

std.c.darwin.os_unfair_lock_t

type

Source line 953

std.c.darwin.os_unfair_lock_trylock

function

Source line 960

pub extern "c" fn os_unfair_lock_trylock(o: os_unfair_lock_t) bool

Parameters

std.c.darwin.os_unfair_lock_unlock

function

Source line 959

pub extern "c" fn os_unfair_lock_unlock(o: os_unfair_lock_t) void

Parameters

std.c.darwin.OS.LOG_CATEGORY

namespace

Source line 264

std.c.darwin.OS.LOG_CATEGORY.DYNAMIC_STACK_TRACING

constant

Source line 267

*const u8

std.c.darwin.OS.LOG_CATEGORY.DYNAMIC_TRACING

constant

Source line 266

*const u8

std.c.darwin.OS.LOG_CATEGORY.POINTS_OF_INTEREST

constant

Source line 265

*const u8

std.c.darwin.pid_for_task

function

Source line 553

pub extern "c" fn pid_for_task(target_tport: mach_port_name_t, pid: *pid_t) kern_return_t

Parameters

target_tport: mach_port_name_t
pid: *pid_t

std.c.darwin.pid_t

alias

Source line 12

Alias of std.c.pid_t

std.c.darwin.policy_t

type

Source line 731

std.c.darwin.posix_spawn

function

Source line 1278

pub extern "c" fn posix_spawn( pid: *pid_t, path: [*:0]const u8, actions: ?*const posix_spawn_file_actions_t, attr: ?*const posix_spawnattr_t, argv: [*:null]const ?[*:0]const u8, env: [*:null]const ?[*:0]const u8, ) c_int

Parameters

pid: *pid_t
path: [*:0]const u8
actions: ?*const posix_spawn_file_actions_t
attr: ?*const posix_spawnattr_t
argv: [*:null]const ?[*:0]const u8
env: [*:null]const ?[*:0]const u8

std.c.darwin.POSIX_SPAWN

container

Source line 1235

Fields

RESETIDS: bool = false
SETPGROUP: bool = false
SETSIGDEF: bool = false
SETSIGMASK: bool = false
_4: u2 = 0
SETEXEC: bool = false
START_SUSPENDED: bool = false
DISABLE_ASLR: bool = false
_9: u1 = 0
SETSID: bool = false
RESLIDE: bool = false
_12: u2 = 0
CLOEXEC_DEFAULT: bool = false
_15: u1 = 0

std.c.darwin.posix_spawn_file_actions_addchdir_np

function

Source line 1276

pub extern "c" fn posix_spawn_file_actions_addchdir_np(actions: *posix_spawn_file_actions_t, path: [*:0]const u8) c_int

Parameters

actions: *posix_spawn_file_actions_t
path: [*:0]const u8

std.c.darwin.posix_spawn_file_actions_addclose

function

Source line 1262

pub extern "c" fn posix_spawn_file_actions_addclose(actions: *posix_spawn_file_actions_t, filedes: fd_t) c_int

Parameters

actions: *posix_spawn_file_actions_t
filedes: fd_t

std.c.darwin.posix_spawn_file_actions_adddup2

function

Source line 1270

pub extern "c" fn posix_spawn_file_actions_adddup2( actions: *posix_spawn_file_actions_t, filedes: fd_t, newfiledes: fd_t, ) c_int

Parameters

actions: *posix_spawn_file_actions_t
filedes: fd_t
newfiledes: fd_t

std.c.darwin.posix_spawn_file_actions_addfchdir_np

function

Source line 1277

pub extern "c" fn posix_spawn_file_actions_addfchdir_np(actions: *posix_spawn_file_actions_t, filedes: fd_t) c_int

Parameters

actions: *posix_spawn_file_actions_t
filedes: fd_t

std.c.darwin.posix_spawn_file_actions_addinherit_np

function

Source line 1275

pub extern "c" fn posix_spawn_file_actions_addinherit_np(actions: *posix_spawn_file_actions_t, filedes: fd_t) c_int

Parameters

actions: *posix_spawn_file_actions_t
filedes: fd_t

std.c.darwin.posix_spawn_file_actions_addopen

function

Source line 1263

pub extern "c" fn posix_spawn_file_actions_addopen( actions: *posix_spawn_file_actions_t, filedes: fd_t, path: [*:0]const u8, oflag: c_int, mode: mode_t, ) c_int

Parameters

actions: *posix_spawn_file_actions_t
filedes: fd_t
path: [*:0]const u8
oflag: c_int
mode: mode_t

std.c.darwin.posix_spawn_file_actions_destroy

function

Source line 1261

pub extern "c" fn posix_spawn_file_actions_destroy(actions: *posix_spawn_file_actions_t) c_int

Parameters

std.c.darwin.posix_spawn_file_actions_init

function

Source line 1260

pub extern "c" fn posix_spawn_file_actions_init(actions: *posix_spawn_file_actions_t) c_int

Parameters

std.c.darwin.posix_spawn_file_actions_t

type

Source line 1253

std.c.darwin.posix_spawnattr_destroy

function

Source line 1255

pub extern "c" fn posix_spawnattr_destroy(attr: *posix_spawnattr_t) c_int

Parameters

std.c.darwin.posix_spawnattr_getflags

function

Source line 1256

pub extern "c" fn posix_spawnattr_getflags(attr: *const posix_spawnattr_t, flags: *POSIX_SPAWN) c_int

Parameters

attr: *const posix_spawnattr_t
flags: *POSIX_SPAWN

std.c.darwin.posix_spawnattr_getpgroup

function

Source line 1257

pub extern "c" fn posix_spawnattr_getpgroup(attr: *const posix_spawnattr_t, pgroup: *pid_t) c_int

Parameters

attr: *const posix_spawnattr_t
pgroup: *pid_t

std.c.darwin.posix_spawnattr_init

function

Source line 1254

pub extern "c" fn posix_spawnattr_init(attr: *posix_spawnattr_t) c_int

Parameters

std.c.darwin.posix_spawnattr_setflags

function

Source line 1258

pub extern "c" fn posix_spawnattr_setflags(attr: *posix_spawnattr_t, flags: POSIX_SPAWN) c_int

Parameters

std.c.darwin.posix_spawnattr_setpgroup

function

Source line 1259

pub extern "c" fn posix_spawnattr_setpgroup(attr: *posix_spawnattr_t, pgroup: pid_t) c_int

Parameters

attr: *posix_spawnattr_t
pgroup: pid_t

std.c.darwin.posix_spawnattr_t

type

Source line 1252

std.c.darwin.posix_spawnp

function

Source line 1286

pub extern "c" fn posix_spawnp( pid: *pid_t, path: [*:0]const u8, actions: ?*const posix_spawn_file_actions_t, attr: ?*const posix_spawnattr_t, argv: [*:null]const ?[*:0]const u8, env: [*:null]const ?[*:0]const u8, ) c_int

Parameters

pid: *pid_t
path: [*:0]const u8
actions: ?*const posix_spawn_file_actions_t
attr: ?*const posix_spawnattr_t
argv: [*:null]const ?[*:0]const u8
env: [*:null]const ?[*:0]const u8

std.c.darwin.PROT

alias

Source line 6

Alias of std.c.PROT

std.c.darwin.PT

container

Source line 1213

Fields

TRACE_ME = 0
READ_I = 1
READ_D = 2
READ_U = 3
WRITE_I = 4
WRITE_D = 5
WRITE_U = 6
CONTINUE = 7
KILL = 8
STEP = 9
DETACH = 11
SIGEXC = 12
THUPDATE = 13
ATTACHEXC = 14
FORCEQUOTA = 30
DENY_ATTACH = 31
_

std.c.darwin.pthread_attr_get_qos_class_np

function

Source line 997

pub extern "c" fn pthread_attr_get_qos_class_np(attr: *pthread_attr_t, qos_class: *qos_class_t, relative_priority: *c_int) c_int

Parameters

attr: *pthread_attr_t
qos_class: *qos_class_t
relative_priority: *c_int

std.c.darwin.pthread_attr_set_qos_class_np

function

Source line 996

pub extern "c" fn pthread_attr_set_qos_class_np(attr: *pthread_attr_t, qos_class: qos_class_t, relative_priority: c_int) c_int

Parameters

attr: *pthread_attr_t
qos_class: qos_class_t
relative_priority: c_int

std.c.darwin.pthread_attr_t

alias

Source line 13

Alias of std.c.pthread_attr_t

std.c.darwin.pthread_get_qos_class_np

function

Source line 999

pub extern "c" fn pthread_get_qos_class_np(pthread: std.c.pthread_t, qos_class: *qos_class_t, relative_priority: *c_int) c_int

Parameters

pthread: std.c.pthread_t
qos_class: *qos_class_t
relative_priority: *c_int

std.c.darwin.pthread_set_qos_class_self_np

function

Source line 998

pub extern "c" fn pthread_set_qos_class_self_np(qos_class: qos_class_t, relative_priority: c_int) c_int

Parameters

qos_class: qos_class_t
relative_priority: c_int

std.c.darwin.pthread_setname_np

function

Source line 995

pub extern "c" fn pthread_setname_np(name: [*:0]const u8) c_int

Parameters

name: [*:0]const u8

std.c.darwin.ptrace

function

Source line 1233

pub extern "c" fn ptrace(request: PT, pid: pid_t, addr: caddr_t, data: c_int) c_int

Parameters

request: PT
pid: pid_t
addr: caddr_t
data: c_int

std.c.darwin.qos_class_t

container

Source line 904

Fields

USER_INTERACTIVE = 0x21

highest priority QOS class for critical tasks

USER_INITIATED = 0x19

slightly more moderate priority QOS class

DEFAULT = 0x15

default QOS class when none is set

UTILITY = 0x11

more energy efficient QOS class than default

BACKGROUND = 0x09

QOS class more appropriate for background tasks

UNSPECIFIED = 0x00

QOS class as a return value

_

std.c.darwin.RENAME

container

Source line 383

Fields

SECLUDE: bool = false
SWAP: bool = false
EXCL: bool = false
RESERVED1: bool = false
NOFOLLOW_ANY: bool = false
RESOLVE_BENEATH: bool = false
_: u26 = 0

std.c.darwin.renameatx_np

function

Source line 393

pub extern "c" fn renameatx_np(fromfd: c_int, from: [*:0]const u8, tofd: c_int, to: [*:0]const u8, flags: RENAME) c_int

Parameters

fromfd: c_int
from: [*:0]const u8
tofd: c_int
to: [*:0]const u8
flags: RENAME

std.c.darwin.sendfile

function

Source line 889

pub extern "c" fn sendfile( in_fd: fd_t, out_fd: fd_t, offset: off_t, len: *off_t, sf_hdtr: ?*sf_hdtr, flags: u32, ) c_int

Parameters

in_fd: fd_t
out_fd: fd_t
offset: off_t
len: *off_t
sf_hdtr: ?*sf_hdtr
flags: u32

std.c.darwin.sf_hdtr

alias

Source line 15

Alias of std.c.sf_hdtr

std.c.darwin.shm_open

function

Source line 417

pub extern "c" fn shm_open(name: [*:0]const u8, flag: c_int, ...) c_int

Parameters

name: [*:0]const u8
flag: c_int

std.c.darwin.sigset_t

type

Source line 899

std.c.darwin.std

alias

Source line 1

Alias of std

std.c.darwin.SYSPROTO_CONTROL

constant

Source line 1053

std.c.darwin.SYSPROTO_EVENT

constant

Source line 1052

std.c.darwin.TASK

namespace

Source line 271

std.c.darwin.task_flavor_t

alias

Source line 1042

Alias of std.c.darwin.natural_t

std.c.darwin.task_for_pid

function

Source line 552

pub extern "c" fn task_for_pid(target_tport: mach_port_name_t, pid: pid_t, t: *mach_port_name_t) kern_return_t

Parameters

target_tport: mach_port_name_t
pid: pid_t
t: *mach_port_name_t

std.c.darwin.task_get_exception_ports

function

Source line 530

pub extern "c" fn task_get_exception_ports( task: task_t, exception_mask: exception_mask_t, masks: exception_mask_array_t, masks_cnt: *mach_msg_type_number_t, old_handlers: exception_handler_array_t, old_behaviors: exception_behavior_array_t, old_flavors: exception_flavor_array_t, ) kern_return_t

Parameters

std.c.darwin.task_info

function

Source line 857

pub extern "c" fn task_info( target_task: task_name_t, flavor: task_flavor_t, task_info_out: task_info_t, task_info_outCnt: *mach_msg_type_number_t, ) kern_return_t

Parameters

target_task: task_name_t
flavor: task_flavor_t
task_info_out: task_info_t
task_info_outCnt: *mach_msg_type_number_t

std.c.darwin.task_info_t

type

Source line 1043

std.c.darwin.task_name_t

alias

Source line 1044

Alias of std.c.darwin.mach_port_name_t

std.c.darwin.TASK_NULL

constant

Source line 280

std.c.darwin.task_policy_flavor_t

alias

Source line 729

Alias of std.c.darwin.natural_t

std.c.darwin.task_policy_t

type

Source line 730

std.c.darwin.task_read_t

alias

Source line 547

Alias of std.c.darwin.mach_port_t

std.c.darwin.task_resume

function

Source line 549

pub extern "c" fn task_resume(target_task: task_read_t) kern_return_t

Parameters

target_task: task_read_t

std.c.darwin.task_set_exception_ports

function

Source line 539

pub extern "c" fn task_set_exception_ports( task: task_t, exception_mask: exception_mask_t, new_port: mach_port_t, behavior: exception_behavior_t, new_flavor: thread_state_flavor_t, ) kern_return_t

Parameters

task: task_t
exception_mask: exception_mask_t
new_port: mach_port_t
behavior: exception_behavior_t
new_flavor: thread_state_flavor_t

std.c.darwin.task_suspend

function

Source line 550

pub extern "c" fn task_suspend(target_task: task_read_t) kern_return_t

Parameters

target_task: task_read_t

std.c.darwin.task_t

alias

Source line 435

Alias of std.c.darwin.mach_port_t

std.c.darwin.task_threads

function

Source line 701

pub extern "c" fn task_threads( target_task: mach_port_t, init_port_set: *mach_port_array_t, init_port_count: *mach_msg_type_number_t, ) kern_return_t

Parameters

target_task: mach_port_t
init_port_set: *mach_port_array_t
init_port_count: *mach_msg_type_number_t

std.c.darwin.task_vm_info

container

Source line 768

Fields

virtual_size: mach_vm_size_t
region_count: integer_t
page_size: integer_t
resident_size: mach_vm_size_t
resident_size_peak: mach_vm_size_t
device: mach_vm_size_t
device_peak: mach_vm_size_t
internal: mach_vm_size_t
internal_peak: mach_vm_size_t
external: mach_vm_size_t
external_peak: mach_vm_size_t
reusable: mach_vm_size_t
reusable_peak: mach_vm_size_t
purgeable_volatile_pmap: mach_vm_size_t
purgeable_volatile_resident: mach_vm_size_t
purgeable_volatile_virtual: mach_vm_size_t
compressed: mach_vm_size_t
compressed_peak: mach_vm_size_t
compressed_lifetime: mach_vm_size_t
phys_footprint: mach_vm_size_t
min_address: mach_vm_address_t
max_address: mach_vm_address_t
ledger_phys_footprint_peak: i64
ledger_purgeable_nonvolatile: i64
ledger_purgeable_novolatile_compressed: i64
ledger_purgeable_volatile: i64
ledger_purgeable_volatile_compressed: i64
ledger_tag_network_nonvolatile: i64
ledger_tag_network_nonvolatile_compressed: i64
ledger_tag_network_volatile: i64
ledger_tag_network_volatile_compressed: i64
ledger_tag_media_footprint: i64
ledger_tag_media_footprint_compressed: i64
ledger_tag_media_nofootprint: i64
ledger_tag_media_nofootprint_compressed: i64
ledger_tag_graphics_footprint: i64
ledger_tag_graphics_footprint_compressed: i64
ledger_tag_graphics_nofootprint: i64
ledger_tag_graphics_nofootprint_compressed: i64
ledger_tag_neural_footprint: i64
ledger_tag_neural_footprint_compressed: i64
ledger_tag_neural_nofootprint: i64
ledger_tag_neural_nofootprint_compressed: i64
limit_bytes_remaining: u64
decompressions: integer_t

std.c.darwin.TASK_VM_INFO

constant

Source line 281

std.c.darwin.TASK_VM_INFO_COUNT

constant

Source line 282

std.c.darwin.task_vm_info_data_t

alias

Source line 831

Alias of std.c.darwin.task_vm_info

std.c.darwin.TASK.NULL

constant

Source line 272

task_t

std.c.darwin.TASK.VM

namespace

Source line 274

std.c.darwin.TASK.VM.INFO

constant

Source line 275

std.c.darwin.TASK.VM.INFO_COUNT

constant

Source line 276

mach_msg_type_number_t

std.c.darwin.TCP

namespace

Source line 1570

std.c.darwin.TCP.CONNECTION_INFO

constant

Source line 1600

State of the TCP connection

std.c.darwin.TCP.CONNECTIONTIMEOUT

constant

Source line 1582

Connection timeout

std.c.darwin.TCP.ENABLE_ECN

constant

Source line 1596

Enable ECN on a connection

std.c.darwin.TCP.FASTOPEN

constant

Source line 1598

Enable/Disable TCP Fastopen on this socket

std.c.darwin.TCP.KEEPALIVE

constant

Source line 1580

Idle time used when SO_KEEPALIVE is enabled

std.c.darwin.TCP.KEEPCNT

constant

Source line 1592

Number of keepalives before clsoe

std.c.darwin.TCP.KEEPINTVL

constant

Source line 1590

Interval between keepalives

std.c.darwin.TCP.MAXSEG

constant

Source line 1574

Limit MSS

std.c.darwin.TCP.NODELAY

constant

Source line 1572

Turn off Nagle's algorithm

std.c.darwin.TCP.NOOPT

constant

Source line 1578

Don't use TCP options

std.c.darwin.TCP.NOPUSH

constant

Source line 1576

Don't push last block of write

std.c.darwin.TCP.PERSIST_TIMEOUT

constant

Source line 1584

Time after which a conection in persist timeout will terminate.

std.c.darwin.TCP.RXT_CONNDROPTIME

constant

Source line 1586

Time after which TCP retransmissions will be stopped and the connection will be dropped.

std.c.darwin.TCP.RXT_FINDROP

constant

Source line 1588

Drop a connection after retransmitting the FIN 3 times.

std.c.darwin.TCP.SENDMOREACKS

constant

Source line 1594

Always ack every other packet

std.c.darwin.THREAD

namespace

Source line 284

std.c.darwin.thread_act_t

alias

Source line 697

Alias of std.c.darwin.mach_port_t

std.c.darwin.thread_basic_info

container

Source line 738

Fields

user_time: time_value_t
system_time: time_value_t
cpu_usage: integer_t
policy: policy_t
run_state: integer_t
flags: integer_t
suspend_count: integer_t
sleep_time: integer_t

std.c.darwin.THREAD_BASIC_INFO

constant

Source line 307

std.c.darwin.THREAD_BASIC_INFO_COUNT

constant

Source line 308

std.c.darwin.thread_flavor_t

alias

Source line 726

Alias of std.c.darwin.natural_t

std.c.darwin.thread_get_state

function

Source line 706

pub extern "c" fn thread_get_state( thread: thread_act_t, flavor: thread_flavor_t, state: thread_state_t, count: *mach_msg_type_number_t, ) kern_return_t

Parameters

std.c.darwin.thread_identifier_info

container

Source line 757

Fields

thread_id: u64

System-wide unique 64-bit thread id

thread_handle: u64

Handle to be used by libproc

dispatch_qaddr: u64

libdispatch queue address

std.c.darwin.THREAD_IDENTIFIER_INFO_COUNT

constant

Source line 309

std.c.darwin.thread_info

function

Source line 718

pub extern "c" fn thread_info( thread: thread_act_t, flavor: thread_flavor_t, info: thread_info_t, count: *mach_msg_type_number_t, ) kern_return_t

Parameters

std.c.darwin.thread_info_t

type

Source line 727

std.c.darwin.THREAD_NULL

constant

Source line 306

std.c.darwin.thread_port_t

alias

Source line 436

Alias of std.c.darwin.task_t

std.c.darwin.thread_resume

function

Source line 724

pub extern "c" fn thread_resume(thread: thread_act_t) kern_return_t

Parameters

thread: thread_act_t

std.c.darwin.thread_set_state

function

Source line 712

pub extern "c" fn thread_set_state( thread: thread_act_t, flavor: thread_flavor_t, new_state: thread_state_t, count: mach_msg_type_number_t, ) kern_return_t

Parameters

std.c.darwin.thread_state_flavor_t

type

Source line 447

std.c.darwin.THREAD_STATE_NONE

constant

Source line 310

std.c.darwin.thread_state_t

type

Source line 698

std.c.darwin.thread_t

alias

Source line 437

Alias of std.c.darwin.thread_port_t

std.c.darwin.THREAD.BASIC

namespace

Source line 287

std.c.darwin.THREAD.BASIC.INFO

constant

Source line 288

std.c.darwin.THREAD.BASIC.INFO_COUNT

constant

Source line 289

mach_msg_type_number_t

std.c.darwin.THREAD.IDENTIFIER

namespace

Source line 292

std.c.darwin.THREAD.IDENTIFIER.INFO

constant

Source line 293

std.c.darwin.THREAD.IDENTIFIER.INFO_COUNT

constant

Source line 294

mach_msg_type_number_t

std.c.darwin.THREAD.NULL

constant

Source line 285

thread_t

std.c.darwin.THREAD.STATE

namespace

Source line 297

std.c.darwin.THREAD.STATE.NONE

constant

Source line 298

std.c.darwin.time_value

container

Source line 733

Fields

seconds: integer_t
microseconds: integer_t

std.c.darwin.time_value_t

alias

Source line 728

Alias of std.c.darwin.time_value

std.c.darwin.timespec

alias

Source line 14

Alias of std.c.timespec

std.c.darwin.UL

container

Source line 926

Undocumented futex-like API available on darwin 16+ (macOS 10.12+, iOS 10.0+, tvOS 10.0+, watchOS 3.0+, catalyst 13.0+).

[ulock.h]: https://github.com/apple/darwin-xnu/blob/master/bsd/sys/ulock.h [sys_ulock.c]: https://github.com/apple/darwin-xnu/blob/master/bsd/kern/sys_ulock.c

Fields

op: Op
WAKE_ALL: bool = false
WAKE_THREAD: bool = false
_10: u6 = 0
WAIT_WORKQ_DATA_CONTENTION: bool = false
WAIT_CANCEL_POINT: bool = false
WAIT_ADAPTIVE_SPIN: bool = false
_19: u5 = 0
NO_ERRNO: bool = false
_: u7 = 0

std.c.darwin.UL.Op

container

Source line 938

Fields

COMPARE_AND_WAIT = 1
UNFAIR_LOCK = 2
COMPARE_AND_WAIT_SHARED = 3
UNFAIR_LOCK64_SHARED = 4
COMPARE_AND_WAIT64 = 5
COMPARE_AND_WAIT64_SHARED = 6
_

std.c.darwin.VM

namespace

Source line 312

std.c.darwin.vm_address_t

alias

Source line 1045

Alias of std.c.darwin.vm_offset_t

std.c.darwin.vm_behavior_t

type

Source line 594

std.c.darwin.vm_deallocate

function

Source line 880

pub extern "c" fn vm_deallocate(target_task: vm_map_t, address: vm_address_t, size: vm_size_t) kern_return_t

Parameters

target_task: vm_map_t
address: vm_address_t
size: vm_size_t

std.c.darwin.vm_inherit_t

type

Source line 592

std.c.darwin.vm_machine_attribute

function

Source line 881

pub extern "c" fn vm_machine_attribute( target_task: vm_map_t, address: vm_address_t, size: vm_size_t, attribute: vm_machine_attribute_t, value: *vm_machine_attribute_val_t, ) kern_return_t

Parameters

target_task: vm_map_t
address: vm_address_t
size: vm_size_t
attribute: vm_machine_attribute_t
value: *vm_machine_attribute_val_t

std.c.darwin.vm_machine_attribute_t

type

Source line 1047

std.c.darwin.vm_machine_attribute_val_t

type

Source line 1048

std.c.darwin.vm_map_read_t

alias

Source line 424

Alias of std.c.darwin.mach_port_t

std.c.darwin.vm_map_t

alias

Source line 423

Alias of std.c.darwin.mach_port_t

std.c.darwin.vm_object_id_t

type

Source line 596

std.c.darwin.vm_offset_t

type

Source line 429

std.c.darwin.vm_prot_t

alias

Source line 833

Alias of std.macho.vm_prot_t

std.c.darwin.vm_region_basic_info_64

container

Source line 598

Fields

protection: vm_prot_t
max_protection: vm_prot_t
inheritance: vm_inherit_t
shared: boolean_t
reserved: boolean_t
offset: memory_object_offset_t
behavior: vm_behavior_t
user_wired_count: u16

std.c.darwin.vm_region_extended_info

container

Source line 609

Fields

protection: vm_prot_t
user_tag: u32
pages_resident: u32
pages_shared_now_private: u32
pages_swapped_out: u32
pages_dirtied: u32
ref_count: u32
shadow_depth: u16
external_pager: u8
share_mode: u8
pages_reusable: u32

std.c.darwin.vm_region_flavor_t

type

Source line 425

std.c.darwin.vm_region_info_t

type

Source line 426

std.c.darwin.vm_region_recurse_info_t

type

Source line 427

std.c.darwin.vm_region_submap_info_64

container

Source line 631

Fields

protection: vm_prot_t
max_protection: vm_prot_t
inheritance: vm_inherit_t
offset: memory_object_offset_t
user_tag: u32
pages_resident: u32
pages_shared_now_private: u32
pages_swapped_out: u32
pages_dirtied: u32
ref_count: u32
shadow_depth: u16
external_pager: u8
share_mode: u8
is_submap: boolean_t
behavior: vm_behavior_t
object_id: vm32_object_id_t
user_wired_count: u16
pages_reusable: u32
object_id_full: vm_object_id_t

std.c.darwin.vm_region_submap_short_info_64

container

Source line 669

Fields

protection: vm_prot_t
max_protection: vm_prot_t
inheritance: vm_inherit_t
offset: memory_object_offset_t
user_tag: u32
ref_count: u32
shadow_depth: u16
external_pager: u8
share_mode: u8
is_submap: boolean_t
behavior: vm_behavior_t
object_id: vm32_object_id_t
user_wired_count: u16

std.c.darwin.vm_region_top_info

container

Source line 623

Fields

obj_id: u32
ref_count: u32
private_pages_resident: u32
shared_pages_resident: u32
share_mode: u8

std.c.darwin.vm_size_t

alias

Source line 1046

Alias of std.c.darwin.mach_vm_size_t

std.c.darwin.VM.BEHAVIOR

namespace

Source line 321

std.c.darwin.VM.BEHAVIOR.CAN_REUSE

constant

Source line 332

vm_behavior_t

std.c.darwin.VM.BEHAVIOR.DEFAULT

constant

Source line 322

vm_behavior_t

std.c.darwin.VM.BEHAVIOR.DONTNEED

constant

Source line 327

vm_behavior_t

std.c.darwin.VM.BEHAVIOR.FREE

constant

Source line 328

vm_behavior_t

std.c.darwin.VM.BEHAVIOR.PAGEOUT

constant

Source line 333

vm_behavior_t

std.c.darwin.VM.BEHAVIOR.RANDOM

constant

Source line 323

vm_behavior_t

std.c.darwin.VM.BEHAVIOR.REUSABLE

constant

Source line 330

vm_behavior_t

std.c.darwin.VM.BEHAVIOR.REUSE

constant

Source line 331

vm_behavior_t

std.c.darwin.VM.BEHAVIOR.RSEQNTL

constant

Source line 325

vm_behavior_t

std.c.darwin.VM.BEHAVIOR.SEQUENTIAL

constant

Source line 324

vm_behavior_t

std.c.darwin.VM.BEHAVIOR.WILLNEED

constant

Source line 326

vm_behavior_t

std.c.darwin.VM.BEHAVIOR.ZERO_WIRED_PAGES

constant

Source line 329

vm_behavior_t

std.c.darwin.VM.INHERIT

namespace

Source line 313

std.c.darwin.VM.INHERIT.COPY

constant

Source line 315

vm_inherit_t

std.c.darwin.VM.INHERIT.DEFAULT

alias

Source line 318

Alias of std.c.darwin.VM.INHERIT.COPY

std.c.darwin.VM.INHERIT.DONATE_COPY

constant

Source line 317

vm_inherit_t

std.c.darwin.VM.INHERIT.NONE

constant

Source line 316

vm_inherit_t

std.c.darwin.VM.INHERIT.SHARE

constant

Source line 314

vm_inherit_t

std.c.darwin.VM.MAKE_TAG

function

Source line 347

pub fn MAKE_TAG(tag: u8) u32

Parameters

tag: u8

std.c.darwin.VM.REGION

namespace

Source line 336

std.c.darwin.VM.REGION.BASIC_INFO_64

constant

Source line 337

std.c.darwin.VM.REGION.BASIC_INFO_COUNT

constant

Source line 342

mach_msg_type_number_t

std.c.darwin.VM.REGION.EXTENDED_INFO

constant

Source line 338

std.c.darwin.VM.REGION.EXTENDED_INFO_COUNT

constant

Source line 343

mach_msg_type_number_t

std.c.darwin.VM.REGION.SUBMAP_INFO_COUNT_64

constant

Source line 340

mach_msg_type_number_t

std.c.darwin.VM.REGION.SUBMAP_SHORT_INFO_COUNT_64

constant

Source line 341

mach_msg_type_number_t

std.c.darwin.VM.REGION.TOP_INFO

constant

Source line 339

std.c.darwin.VM.REGION.TOP_INFO_COUNT

constant

Source line 344

mach_msg_type_number_t

std.c.darwin.vm32_object_id_t

type

Source line 595

Source code

std/c/darwin.zig

const std = @import("std");
const builtin = @import("builtin");
const native_arch = builtin.target.cpu.arch;
const assert = std.debug.assert;
const AF = std.c.AF;
const PROT = std.c.PROT;
const caddr_t = std.c.caddr_t;
const fd_t = std.c.fd_t;
const iovec_const = std.posix.iovec_const;
const mode_t = std.c.mode_t;
const off_t = std.c.off_t;
const pid_t = std.c.pid_t;
const pthread_attr_t = std.c.pthread_attr_t;
const timespec = std.c.timespec;
const sf_hdtr = std.c.sf_hdtr;

comptime {
    assert(builtin.os.tag.isDarwin()); // Prevent access of std.c symbols on wrong OS.
}

// Grand Central Dispatch is exposed by libSystem.
pub const dispatch = @import("darwin/dispatch.zig");

pub const mach_port_t = c_uint;

pub const EXC = enum(exception_type_t) {
    NULL = 0,
    /// Could not access memory
    BAD_ACCESS = 1,
    /// Instruction failed
    BAD_INSTRUCTION = 2,
    /// Arithmetic exception
    ARITHMETIC = 3,
    /// Emulation instruction
    EMULATION = 4,
    /// Software generated exception
    SOFTWARE = 5,
    /// Trace, breakpoint, etc.
    BREAKPOINT = 6,
    /// System calls.
    SYSCALL = 7,
    /// Mach system calls.
    MACH_SYSCALL = 8,
    /// RPC alert
    RPC_ALERT = 9,
    /// Abnormal process exit
    CRASH = 10,
    /// Hit resource consumption limit
    RESOURCE = 11,
    /// Violated guarded resource protections
    GUARD = 12,
    /// Abnormal process exited to corpse state
    CORPSE_NOTIFY = 13,

    _,

    pub const TYPES_COUNT = @typeInfo(EXC).@"enum".field_names.len;
    pub const SOFT_SIGNAL = 0x10003;

    pub const MASK = packed struct(u32) {
        _0: u1 = 0,
        BAD_ACCESS: bool = false,
        BAD_INSTRUCTION: bool = false,
        ARITHMETIC: bool = false,
        EMULATION: bool = false,
        SOFTWARE: bool = false,
        BREAKPOINT: bool = false,
        SYSCALL: bool = false,
        MACH_SYSCALL: bool = false,
        RPC_ALERT: bool = false,
        CRASH: bool = false,
        RESOURCE: bool = false,
        GUARD: bool = false,
        CORPSE_NOTIFY: bool = false,
        _14: u18 = 0,

        pub const MACHINE: MASK = @bitCast(@as(u32, 0));

        pub const ALL: MASK = .{
            .BAD_ACCESS = true,
            .BAD_INSTRUCTION = true,
            .ARITHMETIC = true,
            .EMULATION = true,
            .SOFTWARE = true,
            .BREAKPOINT = true,
            .SYSCALL = true,
            .MACH_SYSCALL = true,
            .RPC_ALERT = true,
            .CRASH = true,
            .RESOURCE = true,
            .GUARD = true,
            .CORPSE_NOTIFY = true,
        };
    };
};

pub const EXCEPTION = enum(u32) {
    /// Send a catch_exception_raise message including the identity.
    DEFAULT = 1,
    /// Send a catch_exception_raise_state message including the
    /// thread state.
    STATE = 2,
    /// Send a catch_exception_raise_state_identity message including
    /// the thread identity and state.
    STATE_IDENTITY = 3,
    /// Send a catch_exception_raise_identity_protected message including protected task
    /// and thread identity.
    IDENTITY_PROTECTED = 4,

    _,
};

pub const KEVENT = struct {
    /// Used as the `flags` arg for `kevent64`.
    pub const FLAG = packed struct(c_uint) {
        /// immediate timeout
        IMMEDIATE: bool = false,
        /// output events only include change
        ERROR_EVENTS: bool = false,
        _: u30 = 0,

        /// no flag value
        pub const NONE: KEVENT.FLAG = .{
            .IMMEDIATE = false,
            .ERROR_EVENTS = false,
        };
    };
};

pub const MACH = struct {
    pub const EXCEPTION = packed struct(exception_mask_t) {
        _: u29 = 0,
        /// Prefer sending a catch_exception_raice_backtrace message, if applicable.
        BACKTRACE_PREFERRED: bool = false,
        /// include additional exception specific errors, not used yet.
        ERRORS: bool = false,
        /// Send 64-bit code and subcode in the exception header */
        CODES: bool = false,

        pub const MASK: exception_mask_t = @bitCast(MACH.EXCEPTION{
            .BACKTRACE_PREFERRED = true,
            .ERRORS = true,
            .CODES = true,
        });
    };

    pub const MSG = packed struct(kern_return_t) {
        _0: u10 = 0,
        /// Kernel resource shortage handling an IPC capability.
        VM_KERNEL: bool = false,
        /// Kernel resource shortage handling out-of-line memory.
        IPC_KERNEL: bool = false,
        /// No room in VM address space for out-of-line memory.
        VM_SPACE: bool = false,
        /// No room in IPC name space for another capability name.
        IPC_SPACE: bool = false,
        _14: u18 = 0,

        pub const MASK: kern_return_t = @bitCast(MACH.MSG{
            .VM_KERNEL = true,
            .IPC_KERNEL = true,
            .VM_SPACE = true,
            .IPC_SPACE = true,
        });

        pub const TIMEOUT_NONE: mach_msg_timeout_t = .NONE;
        pub const OPTION_NONE: mach_msg_option_t = .NONE;
        pub const STRICT_REPLY = @compileError("use MACH.RCV.STRICT_REPLY and/or MACH.SEND.STRICT_REPLY");

        pub const TYPE = mach_msg_type_name_t;
    };

    pub const PORT = struct {
        pub const NULL: mach_port_t = 0;
        pub const RIGHT = mach_port_right_t;
    };

    pub const RCV = packed struct(integer_t) {
        _0: u1 = 0,
        /// Other flags are only valid if this one is set.
        MSG: bool = true,
        LARGE: bool = false,
        LARGE_IDENTITY: bool = false,
        _4: u4 = 0,
        TIMEOUT: bool = false,
        /// Shared between `RCV` and `SEND`. Used to be `MACH_RCV_NOTIFY`.
        STRICT_REPLY: bool = false,
        INTERRUPT: bool = false,
        VOUCHER: bool = false,
        GUARDED_DESC: bool = false,
        _13: u1 = 0,
        SYNC_WAIT: bool = false,
        SYNC_PEEK: bool = false,
        _16: u16 = 0,
    };

    pub const SEND = packed struct(integer_t) {
        /// Other flags are only valid if this one is set.
        MSG: bool = true,
        _1: u3 = 0,
        TIMEOUT: bool = false,
        OVERRIDE: bool = false,
        INTERRUPT: bool = false,
        NOTIFY: bool = false,
        _8: u1 = 0,
        /// Shared between `RCV` and `SEND`.
        STRICT_REPLY: bool = false,
        _10: u6 = 0,
        /// User-only. If you're the kernel, this bit is `MACH_SEND_ALWAYS`.
        FILTER_NONFATAL: bool = false,
        TRAILER: bool = false,
        /// Synonymous to `MACH_SEND_NODENAP`.
        NOIMPORTANCE: bool = false,
        /// Kernel-only.
        IMPORTANCE: bool = false,
        SYNC_OVERRIDE: bool = false,
        /// Synonymous to `MACH_SEND_SYNC_USE_THRPRI`.
        PROPAGATE_QOS: bool = false,
        /// Kernel-only.
        KERNEL: bool = false,
        SYNC_BOOTSTRAP_CHECKIN: bool = false,
        _24: u8 = 0,
    };

    pub const TASK = struct {
        pub const BASIC = struct {
            pub const INFO = 20;
            pub const INFO_COUNT: mach_msg_type_number_t = @sizeOf(mach_task_basic_info) / @sizeOf(natural_t);
        };
    };
};

pub const MACH_MSG_TYPE = @compileError("use MACH.MSG.TYPE");
pub const MACH_PORT_RIGHT = @compileError("use MACH.PORT.RIGHT");
pub const MACH_TASK_BASIC_INFO = @compileError("use MACH.TASK.BASIC.INFO");
pub const MACH_TASK_BASIC_INFO_COUNT = @compileError("use MACH.TASK.BASIC.INFO_COUNT");

pub const MATTR = struct {
    /// Cachability
    pub const CACHE: vm_machine_attribute_t = 1;
    /// Migrability
    pub const MIGRATE: vm_machine_attribute_t = 2;
    /// Replicability
    pub const REPLICATE: vm_machine_attribute_t = 4;
    /// (Generic) turn attribute off
    pub const VAL_OFF: vm_machine_attribute_t = 0;
    /// (Generic) turn attribute on
    pub const VAL_ON: vm_machine_attribute_t = 1;
    /// (Generic) return current value
    pub const VAL_GET: vm_machine_attribute_t = 2;
    /// Flush from all caches
    pub const VAL_CACHE_FLUSH: vm_machine_attribute_t = 6;
    /// Flush from data caches
    pub const VAL_DCACHE_FLUSH: vm_machine_attribute_t = 7;
    /// Flush from instruction caches
    pub const VAL_ICACHE_FLUSH: vm_machine_attribute_t = 8;
    /// Sync I+D caches
    pub const VAL_CACHE_SYNC: vm_machine_attribute_t = 9;
    /// Get page info (stats)
    pub const VAL_GET_INFO: vm_machine_attribute_t = 10;
};

pub const OS = struct {
    pub const LOG_CATEGORY = struct {
        pub const POINTS_OF_INTEREST: *const u8 = "PointsOfInterest";
        pub const DYNAMIC_TRACING: *const u8 = "DynamicTracing";
        pub const DYNAMIC_STACK_TRACING: *const u8 = "DynamicStackTracing";
    };
};

pub const TASK = struct {
    pub const NULL: task_t = 0;

    pub const VM = struct {
        pub const INFO = 22;
        pub const INFO_COUNT: mach_msg_type_number_t = @sizeOf(task_vm_info_data_t) / @sizeOf(natural_t);
    };
};

pub const TASK_NULL = @compileError("use TASK.NULL");
pub const TASK_VM_INFO = @compileError("use TASK.VM.INFO");
pub const TASK_VM_INFO_COUNT = @compileError("use TASK.VM.INFO_COUNT");

pub const THREAD = struct {
    pub const NULL: thread_t = 0;

    pub const BASIC = struct {
        pub const INFO = 3;
        pub const INFO_COUNT: mach_msg_type_number_t = @sizeOf(thread_basic_info) / @sizeOf(natural_t);
    };

    pub const IDENTIFIER = struct {
        pub const INFO = 4;
        pub const INFO_COUNT: mach_msg_type_number_t = @sizeOf(thread_identifier_info) / @sizeOf(natural_t);
    };

    pub const STATE = struct {
        pub const NONE = switch (native_arch) {
            .aarch64 => 5,
            .x86_64 => 13,
            else => @compileError("unsupported arch"),
        };
    };
};

pub const THREAD_NULL = @compileError("use THREAD.NULL");
pub const THREAD_BASIC_INFO = @compileError("use THREAD.BASIC.INFO");
pub const THREAD_BASIC_INFO_COUNT = @compileError("use THREAD.BASIC.INFO_COUNT");
pub const THREAD_IDENTIFIER_INFO_COUNT = @compileError("use THREAD.IDENTIFIER.INFO_COUNT");
pub const THREAD_STATE_NONE = @compileError("use THREAD.STATE.NONE");

pub const VM = struct {
    pub const INHERIT = struct {
        pub const SHARE: vm_inherit_t = 0;
        pub const COPY: vm_inherit_t = 1;
        pub const NONE: vm_inherit_t = 2;
        pub const DONATE_COPY: vm_inherit_t = 3;
        pub const DEFAULT = VM.INHERIT.COPY;
    };

    pub const BEHAVIOR = struct {
        pub const DEFAULT: vm_behavior_t = 0;
        pub const RANDOM: vm_behavior_t = 1;
        pub const SEQUENTIAL: vm_behavior_t = 2;
        pub const RSEQNTL: vm_behavior_t = 3;
        pub const WILLNEED: vm_behavior_t = 4;
        pub const DONTNEED: vm_behavior_t = 5;
        pub const FREE: vm_behavior_t = 6;
        pub const ZERO_WIRED_PAGES: vm_behavior_t = 7;
        pub const REUSABLE: vm_behavior_t = 8;
        pub const REUSE: vm_behavior_t = 9;
        pub const CAN_REUSE: vm_behavior_t = 10;
        pub const PAGEOUT: vm_behavior_t = 11;
    };

    pub const REGION = struct {
        pub const BASIC_INFO_64 = 9;
        pub const EXTENDED_INFO = 13;
        pub const TOP_INFO = 12;
        pub const SUBMAP_INFO_COUNT_64: mach_msg_type_number_t = @sizeOf(vm_region_submap_info_64) / @sizeOf(natural_t);
        pub const SUBMAP_SHORT_INFO_COUNT_64: mach_msg_type_number_t = @sizeOf(vm_region_submap_short_info_64) / @sizeOf(natural_t);
        pub const BASIC_INFO_COUNT: mach_msg_type_number_t = @sizeOf(vm_region_basic_info_64) / @sizeOf(c_int);
        pub const EXTENDED_INFO_COUNT: mach_msg_type_number_t = @sizeOf(vm_region_extended_info) / @sizeOf(natural_t);
        pub const TOP_INFO_COUNT: mach_msg_type_number_t = @sizeOf(vm_region_top_info) / @sizeOf(natural_t);
    };

    pub fn MAKE_TAG(tag: u8) u32 {
        return @as(u32, tag) << 24;
    }
};

pub const exception_type_t = c_int;

pub extern "c" fn NSVersionOfRunTimeLibrary(library_name: [*:0]const u8) u32;
pub extern "c" fn _NSGetExecutablePath(buf: [*]u8, bufsize: *u32) c_int;
pub extern "c" fn _dyld_image_count() u32;
pub extern "c" fn _dyld_get_image_header(image_index: u32) ?*mach_header;
pub extern "c" fn _dyld_get_image_vmaddr_slide(image_index: u32) usize;
pub extern "c" fn _dyld_get_image_name(image_index: u32) [*:0]const u8;
pub extern "c" fn _dyld_get_image_header_containing_address(address: *const anyopaque) ?*mach_header;
pub extern "c" fn dyld_image_path_containing_address(address: *const anyopaque) ?[*:0]const u8;
pub extern "c" fn dladdr(addr: *const anyopaque, info: *dl_info) c_int;

pub const dl_info = extern struct {
    fname: [*:0]const u8,
    fbase: *anyopaque,
    sname: ?[*:0]const u8,
    saddr: ?*anyopaque,
};

pub const COPYFILE = packed struct(u32) {
    ACL: bool = false,
    STAT: bool = false,
    XATTR: bool = false,
    DATA: bool = false,
    _: u28 = 0,
};

pub const copyfile_state_t = *opaque {};
pub extern "c" fn fcopyfile(from: fd_t, to: fd_t, state: ?copyfile_state_t, flags: COPYFILE) c_int;
pub extern "c" fn __getdirentries64(fd: c_int, buf_ptr: [*]u8, buf_len: usize, basep: *i64) isize;

pub const RENAME = packed struct(u32) {
    SECLUDE: bool = false,
    SWAP: bool = false,
    EXCL: bool = false,
    RESERVED1: bool = false,
    NOFOLLOW_ANY: bool = false,
    RESOLVE_BENEATH: bool = false,
    _: u26 = 0,
};

pub extern "c" fn renameatx_np(fromfd: c_int, from: [*:0]const u8, tofd: c_int, to: [*:0]const u8, flags: RENAME) c_int;

pub extern "c" fn mach_absolute_time() u64;
pub extern "c" fn mach_continuous_time() u64;
pub extern "c" fn mach_timebase_info(tinfo: ?*mach_timebase_info_data) kern_return_t;

pub extern "c" fn kevent64(
    kq: c_int,
    changelist: [*]const kevent64_s,
    nchanges: c_int,
    eventlist: [*]kevent64_s,
    nevents: c_int,
    flags: KEVENT.FLAG,
    timeout: ?*const timespec,
) c_int;

pub const mach_hdr = if (@sizeOf(usize) == 8) mach_header_64 else mach_header;

pub const mach_header_64 = std.macho.mach_header_64;
pub const mach_header = std.macho.mach_header;

pub extern "c" fn @"close$NOCANCEL"(fd: fd_t) c_int;
pub extern "c" fn mach_host_self() mach_port_t;
pub extern "c" fn clock_get_time(clock_serv: clock_serv_t, cur_time: *mach_timespec_t) kern_return_t;
pub extern "c" fn shm_open(name: [*:0]const u8, flag: c_int, ...) c_int;

pub const exception_data_type_t = integer_t;
pub const exception_data_t = ?*mach_exception_data_type_t;
pub const mach_exception_data_type_t = i64;
pub const mach_exception_data_t = ?*mach_exception_data_type_t;
pub const vm_map_t = mach_port_t;
pub const vm_map_read_t = mach_port_t;
pub const vm_region_flavor_t = c_int;
pub const vm_region_info_t = *c_int;
pub const vm_region_recurse_info_t = *c_int;
pub const mach_vm_address_t = usize;
pub const vm_offset_t = usize;
pub const mach_vm_size_t = u64;
pub const mach_msg_bits_t = c_uint;
pub const mach_msg_id_t = integer_t;
pub const mach_msg_type_number_t = natural_t;
pub const mach_msg_size_t = natural_t;
pub const task_t = mach_port_t;
pub const thread_port_t = task_t;
pub const thread_t = thread_port_t;
pub const exception_mask_t = c_uint;
pub const exception_mask_array_t = [*]exception_mask_t;
pub const exception_handler_t = mach_port_t;
pub const exception_handler_array_t = [*]exception_handler_t;
pub const exception_port_t = exception_handler_t;
pub const exception_port_array_t = exception_handler_array_t;
pub const exception_flavor_array_t = [*]thread_state_flavor_t;
pub const exception_behavior_t = c_uint;
pub const exception_behavior_array_t = [*]exception_behavior_t;
pub const thread_state_flavor_t = c_int;
pub const ipc_space_t = mach_port_t;
pub const ipc_space_port_t = ipc_space_t;

pub const mach_msg_option_t = packed union(integer_t) {
    RCV: MACH.RCV,
    SEND: MACH.SEND,

    pub const NONE: mach_msg_option_t = @bitCast(@as(integer_t, 0));

    pub fn sendAndRcv(send: MACH.SEND, rcv: MACH.RCV) mach_msg_option_t {
        return @bitCast(@as(integer_t, @bitCast(send)) | @as(integer_t, @bitCast(rcv)));
    }
};

pub const mach_msg_timeout_t = enum(natural_t) {
    NONE = 0,
    _,
};

pub const mach_msg_type_name_t = enum(c_uint) {
    /// Must hold receive right
    MOVE_RECEIVE = 16,
    /// Must hold send right(s)
    MOVE_SEND = 17,
    /// Must hold sendonce right
    MOVE_SEND_ONCE = 18,
    /// Must hold send right(s)
    COPY_SEND = 19,
    /// Must hold receive right
    MAKE_SEND = 20,
    /// Must hold receive right
    MAKE_SEND_ONCE = 21,
    /// NOT VALID
    COPY_RECEIVE = 22,
    /// Must hold receive right
    DISPOSE_RECEIVE = 24,
    /// Must hold send right(s)
    DISPOSE_SEND = 25,
    /// Must hold sendonce right
    DISPOSE_SEND_ONCE = 26,

    _,
};

pub const mach_port_right_t = enum(natural_t) {
    SEND = 0,
    RECEIVE = 1,
    SEND_ONCE = 2,
    PORT_SET = 3,
    DEAD_NAME = 4,
    /// Obsolete right
    LABELH = 5,
    /// Right not implemented
    NUMBER = 6,

    _,
};

extern "c" var mach_task_self_: mach_port_t;
pub fn mach_task_self() callconv(.c) mach_port_t {
    return mach_task_self_;
}

pub extern "c" fn mach_msg(
    msg: ?*mach_msg_header_t,
    option: mach_msg_option_t,
    send_size: mach_msg_size_t,
    rcv_size: mach_msg_size_t,
    rcv_name: mach_port_name_t,
    timeout: mach_msg_timeout_t,
    notify: mach_port_name_t,
) mach_msg_return_t;

pub const mach_msg_header_t = extern struct {
    msgh_bits: mach_msg_bits_t,
    msgh_size: mach_msg_size_t,
    msgh_remote_port: mach_port_t,
    msgh_local_port: mach_port_t,
    msgh_voucher_port: mach_port_name_t,
    msgh_id: mach_msg_id_t,
};

pub extern "c" fn task_get_exception_ports(
    task: task_t,
    exception_mask: exception_mask_t,
    masks: exception_mask_array_t,
    masks_cnt: *mach_msg_type_number_t,
    old_handlers: exception_handler_array_t,
    old_behaviors: exception_behavior_array_t,
    old_flavors: exception_flavor_array_t,
) kern_return_t;
pub extern "c" fn task_set_exception_ports(
    task: task_t,
    exception_mask: exception_mask_t,
    new_port: mach_port_t,
    behavior: exception_behavior_t,
    new_flavor: thread_state_flavor_t,
) kern_return_t;

pub const task_read_t = mach_port_t;

pub extern "c" fn task_resume(target_task: task_read_t) kern_return_t;
pub extern "c" fn task_suspend(target_task: task_read_t) kern_return_t;

pub extern "c" fn task_for_pid(target_tport: mach_port_name_t, pid: pid_t, t: *mach_port_name_t) kern_return_t;
pub extern "c" fn pid_for_task(target_tport: mach_port_name_t, pid: *pid_t) kern_return_t;
pub extern "c" fn mach_vm_read(
    target_task: vm_map_read_t,
    address: mach_vm_address_t,
    size: mach_vm_size_t,
    data: *vm_offset_t,
    data_cnt: *mach_msg_type_number_t,
) kern_return_t;
pub extern "c" fn mach_vm_read_overwrite(
    target_task: vm_map_read_t,
    address: mach_vm_address_t,
    size: mach_vm_size_t,
    data: mach_vm_address_t,
    outsize: *mach_vm_size_t,
) kern_return_t;
pub extern "c" fn mach_vm_write(
    target_task: vm_map_t,
    address: mach_vm_address_t,
    data: vm_offset_t,
    data_cnt: mach_msg_type_number_t,
) kern_return_t;
pub extern "c" fn mach_vm_region(
    target_task: vm_map_t,
    address: *mach_vm_address_t,
    size: *mach_vm_size_t,
    flavor: vm_region_flavor_t,
    info: vm_region_info_t,
    info_cnt: *mach_msg_type_number_t,
    object_name: *mach_port_t,
) kern_return_t;
pub extern "c" fn mach_vm_region_recurse(
    target_task: vm_map_t,
    address: *mach_vm_address_t,
    size: *mach_vm_size_t,
    nesting_depth: *natural_t,
    info: vm_region_recurse_info_t,
    info_cnt: *mach_msg_type_number_t,
) kern_return_t;

pub const vm_inherit_t = u32;
pub const memory_object_offset_t = u64;
pub const vm_behavior_t = i32;
pub const vm32_object_id_t = u32;
pub const vm_object_id_t = u64;

pub const vm_region_basic_info_64 = extern struct {
    protection: vm_prot_t,
    max_protection: vm_prot_t,
    inheritance: vm_inherit_t,
    shared: boolean_t,
    reserved: boolean_t,
    offset: memory_object_offset_t,
    behavior: vm_behavior_t,
    user_wired_count: u16,
};

pub const vm_region_extended_info = extern struct {
    protection: vm_prot_t,
    user_tag: u32,
    pages_resident: u32,
    pages_shared_now_private: u32,
    pages_swapped_out: u32,
    pages_dirtied: u32,
    ref_count: u32,
    shadow_depth: u16,
    external_pager: u8,
    share_mode: u8,
    pages_reusable: u32,
};

pub const vm_region_top_info = extern struct {
    obj_id: u32,
    ref_count: u32,
    private_pages_resident: u32,
    shared_pages_resident: u32,
    share_mode: u8,
};

pub const vm_region_submap_info_64 = extern struct {
    // present across protection
    protection: vm_prot_t,
    // max avail through vm_prot
    max_protection: vm_prot_t,
    // behavior of map/obj on fork
    inheritance: vm_inherit_t,
    // offset into object/map
    offset: memory_object_offset_t,
    // user tag on map entry
    user_tag: u32,
    // only valid for objects
    pages_resident: u32,
    // only for objects
    pages_shared_now_private: u32,
    // only for objects
    pages_swapped_out: u32,
    // only for objects
    pages_dirtied: u32,
    // obj/map mappers, etc.
    ref_count: u32,
    // only for obj
    shadow_depth: u16,
    // only for obj
    external_pager: u8,
    // see enumeration
    share_mode: u8,
    // submap vs obj
    is_submap: boolean_t,
    // access behavior hint
    behavior: vm_behavior_t,
    // obj/map name, not a handle
    object_id: vm32_object_id_t,
    user_wired_count: u16,
    pages_reusable: u32,
    object_id_full: vm_object_id_t,
};

pub const vm_region_submap_short_info_64 = extern struct {
    // present access protection
    protection: vm_prot_t,
    // max avail through vm_prot
    max_protection: vm_prot_t,
    // behavior of map/obj on fork
    inheritance: vm_inherit_t,
    // offset into object/map
    offset: memory_object_offset_t,
    // user tag on map entry
    user_tag: u32,
    // obj/map mappers, etc
    ref_count: u32,
    // only for obj
    shadow_depth: u16,
    // only for obj
    external_pager: u8,
    // see enumeration
    share_mode: u8,
    //  submap vs obj
    is_submap: boolean_t,
    // access behavior hint
    behavior: vm_behavior_t,
    // obj/map name, not a handle
    object_id: vm32_object_id_t,
    user_wired_count: u16,
};

pub const thread_act_t = mach_port_t;
pub const thread_state_t = *natural_t;
pub const mach_port_array_t = [*]mach_port_t;

pub extern "c" fn task_threads(
    target_task: mach_port_t,
    init_port_set: *mach_port_array_t,
    init_port_count: *mach_msg_type_number_t,
) kern_return_t;
pub extern "c" fn thread_get_state(
    thread: thread_act_t,
    flavor: thread_flavor_t,
    state: thread_state_t,
    count: *mach_msg_type_number_t,
) kern_return_t;
pub extern "c" fn thread_set_state(
    thread: thread_act_t,
    flavor: thread_flavor_t,
    new_state: thread_state_t,
    count: mach_msg_type_number_t,
) kern_return_t;
pub extern "c" fn thread_info(
    thread: thread_act_t,
    flavor: thread_flavor_t,
    info: thread_info_t,
    count: *mach_msg_type_number_t,
) kern_return_t;
pub extern "c" fn thread_resume(thread: thread_act_t) kern_return_t;

pub const thread_flavor_t = natural_t;
pub const thread_info_t = *integer_t;
pub const time_value_t = time_value;
pub const task_policy_flavor_t = natural_t;
pub const task_policy_t = *integer_t;
pub const policy_t = c_int;

pub const time_value = extern struct {
    seconds: integer_t,
    microseconds: integer_t,
};

pub const thread_basic_info = extern struct {
    // user run time
    user_time: time_value_t,
    // system run time
    system_time: time_value_t,
    // scaled cpu usage percentage
    cpu_usage: integer_t,
    // scheduling policy in effect
    policy: policy_t,
    // run state
    run_state: integer_t,
    // various flags
    flags: integer_t,
    // suspend count for thread
    suspend_count: integer_t,
    // number of seconds that thread has been sleeping
    sleep_time: integer_t,
};

pub const thread_identifier_info = extern struct {
    /// System-wide unique 64-bit thread id
    thread_id: u64,

    /// Handle to be used by libproc
    thread_handle: u64,

    /// libdispatch queue address
    dispatch_qaddr: u64,
};

pub const task_vm_info = extern struct {
    // virtual memory size (bytes)
    virtual_size: mach_vm_size_t,
    // number of memory regions
    region_count: integer_t,
    page_size: integer_t,
    // resident memory size (bytes)
    resident_size: mach_vm_size_t,
    // peak resident size (bytes)
    resident_size_peak: mach_vm_size_t,

    device: mach_vm_size_t,
    device_peak: mach_vm_size_t,
    internal: mach_vm_size_t,
    internal_peak: mach_vm_size_t,
    external: mach_vm_size_t,
    external_peak: mach_vm_size_t,
    reusable: mach_vm_size_t,
    reusable_peak: mach_vm_size_t,
    purgeable_volatile_pmap: mach_vm_size_t,
    purgeable_volatile_resident: mach_vm_size_t,
    purgeable_volatile_virtual: mach_vm_size_t,
    compressed: mach_vm_size_t,
    compressed_peak: mach_vm_size_t,
    compressed_lifetime: mach_vm_size_t,

    // added for rev1
    phys_footprint: mach_vm_size_t,

    // added for rev2
    min_address: mach_vm_address_t,
    max_address: mach_vm_address_t,

    // added for rev3
    ledger_phys_footprint_peak: i64,
    ledger_purgeable_nonvolatile: i64,
    ledger_purgeable_novolatile_compressed: i64,
    ledger_purgeable_volatile: i64,
    ledger_purgeable_volatile_compressed: i64,
    ledger_tag_network_nonvolatile: i64,
    ledger_tag_network_nonvolatile_compressed: i64,
    ledger_tag_network_volatile: i64,
    ledger_tag_network_volatile_compressed: i64,
    ledger_tag_media_footprint: i64,
    ledger_tag_media_footprint_compressed: i64,
    ledger_tag_media_nofootprint: i64,
    ledger_tag_media_nofootprint_compressed: i64,
    ledger_tag_graphics_footprint: i64,
    ledger_tag_graphics_footprint_compressed: i64,
    ledger_tag_graphics_nofootprint: i64,
    ledger_tag_graphics_nofootprint_compressed: i64,
    ledger_tag_neural_footprint: i64,
    ledger_tag_neural_footprint_compressed: i64,
    ledger_tag_neural_nofootprint: i64,
    ledger_tag_neural_nofootprint_compressed: i64,

    // added for rev4
    limit_bytes_remaining: u64,

    // added for rev5
    decompressions: integer_t,
};

pub const task_vm_info_data_t = task_vm_info;

pub const vm_prot_t = std.macho.vm_prot_t;
pub const boolean_t = c_int;

pub extern "c" fn mach_vm_protect(
    target_task: vm_map_t,
    address: mach_vm_address_t,
    size: mach_vm_size_t,
    set_maximum: boolean_t,
    new_protection: vm_prot_t,
) kern_return_t;

pub extern "c" fn mach_port_allocate(
    task: ipc_space_t,
    right: mach_port_right_t,
    name: *mach_port_name_t,
) kern_return_t;
pub extern "c" fn mach_port_deallocate(task: ipc_space_t, name: mach_port_name_t) kern_return_t;
pub extern "c" fn mach_port_insert_right(
    task: ipc_space_t,
    name: mach_port_name_t,
    right: mach_port_t,
    right_type: mach_msg_type_name_t,
) kern_return_t;

pub extern "c" fn task_info(
    target_task: task_name_t,
    flavor: task_flavor_t,
    task_info_out: task_info_t,
    task_info_outCnt: *mach_msg_type_number_t,
) kern_return_t;

pub const mach_task_basic_info = extern struct {
    /// Virtual memory size (bytes)
    virtual_size: mach_vm_size_t,
    /// Resident memory size (bytes)
    resident_size: mach_vm_size_t,
    /// Total user run time for terminated threads
    user_time: time_value_t,
    /// Total system run time for terminated threads
    system_time: time_value_t,
    /// Default policy for new threads
    policy: policy_t,
    /// Suspend count for task
    suspend_count: mach_vm_size_t,
};

pub extern "c" fn _host_page_size(task: mach_port_t, size: *vm_size_t) kern_return_t;
pub extern "c" fn vm_deallocate(target_task: vm_map_t, address: vm_address_t, size: vm_size_t) kern_return_t;
pub extern "c" fn vm_machine_attribute(
    target_task: vm_map_t,
    address: vm_address_t,
    size: vm_size_t,
    attribute: vm_machine_attribute_t,
    value: *vm_machine_attribute_val_t,
) kern_return_t;

pub extern "c" fn sendfile(
    in_fd: fd_t,
    out_fd: fd_t,
    offset: off_t,
    len: *off_t,
    sf_hdtr: ?*sf_hdtr,
    flags: u32,
) c_int;

// https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/bsd/sys/_types.h#L74
pub const sigset_t = u32;

// https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/bsd/sys/signal.h#L76
pub const NSIG = 32;

pub const qos_class_t = enum(c_uint) {
    /// highest priority QOS class for critical tasks
    USER_INTERACTIVE = 0x21,
    /// slightly more moderate priority QOS class
    USER_INITIATED = 0x19,
    /// default QOS class when none is set
    DEFAULT = 0x15,
    /// more energy efficient QOS class than default
    UTILITY = 0x11,
    /// QOS class more appropriate for background tasks
    BACKGROUND = 0x09,
    /// QOS class as a return value
    UNSPECIFIED = 0x00,

    _,
};

/// Undocumented futex-like API available on darwin 16+
/// (macOS 10.12+, iOS 10.0+, tvOS 10.0+, watchOS 3.0+, catalyst 13.0+).
///
/// [ulock.h]: https://github.com/apple/darwin-xnu/blob/master/bsd/sys/ulock.h
/// [sys_ulock.c]: https://github.com/apple/darwin-xnu/blob/master/bsd/kern/sys_ulock.c
pub const UL = packed struct(u32) {
    op: Op,
    WAKE_ALL: bool = false,
    WAKE_THREAD: bool = false,
    _10: u6 = 0,
    WAIT_WORKQ_DATA_CONTENTION: bool = false,
    WAIT_CANCEL_POINT: bool = false,
    WAIT_ADAPTIVE_SPIN: bool = false,
    _19: u5 = 0,
    NO_ERRNO: bool = false,
    _: u7 = 0,

    pub const Op = enum(u8) {
        COMPARE_AND_WAIT = 1,
        UNFAIR_LOCK = 2,
        COMPARE_AND_WAIT_SHARED = 3,
        UNFAIR_LOCK64_SHARED = 4,
        COMPARE_AND_WAIT64 = 5,
        COMPARE_AND_WAIT64_SHARED = 6,
        _,
    };
};

pub extern "c" fn __ulock_wait2(op: UL, addr: ?*const anyopaque, val: u64, timeout_ns: u64, val2: u64) c_int;
pub extern "c" fn __ulock_wait(op: UL, addr: ?*const anyopaque, val: u64, timeout_us: u32) c_int;
pub extern "c" fn __ulock_wake(op: UL, addr: ?*const anyopaque, val: u64) c_int;

pub const os_unfair_lock_t = *os_unfair_lock;
pub const os_unfair_lock = extern struct {
    _os_unfair_lock_opaque: u32 = 0,
};

pub extern "c" fn os_unfair_lock_lock(o: os_unfair_lock_t) void;
pub extern "c" fn os_unfair_lock_unlock(o: os_unfair_lock_t) void;
pub extern "c" fn os_unfair_lock_trylock(o: os_unfair_lock_t) bool;
pub extern "c" fn os_unfair_lock_assert_owner(o: os_unfair_lock_t) void;
pub extern "c" fn os_unfair_lock_assert_not_owner(o: os_unfair_lock_t) void;

pub const os_signpost_id_t = enum(u64) {
    NULL = 0,
    INVALID = !0,
    EXCLUSIVE = 0xeeeeb0b5b2b2eeee,
    _,
};

pub const os_log_t = *opaque {};
pub const os_log_type_t = enum(u8) {
    /// default messages always captures
    DEFAULT = 0x00,
    /// messages with additional infos
    INFO = 0x01,
    /// debug messages
    DEBUG = 0x02,
    /// error messages
    ERROR = 0x10,
    /// unexpected conditions messages
    FAULT = 0x11,

    _,
};

pub extern "c" fn os_log_create(subsystem: [*]const u8, category: [*]const u8) os_log_t;
pub extern "c" fn os_log_type_enabled(log: os_log_t, tpe: os_log_type_t) bool;
pub extern "c" fn os_signpost_id_generate(log: os_log_t) os_signpost_id_t;
pub extern "c" fn os_signpost_interval_begin(log: os_log_t, signpos: os_signpost_id_t, func: [*]const u8, ...) void;
pub extern "c" fn os_signpost_interval_end(log: os_log_t, signpos: os_signpost_id_t, func: [*]const u8, ...) void;
pub extern "c" fn os_signpost_id_make_with_pointer(log: os_log_t, ptr: ?*anyopaque) os_signpost_id_t;
pub extern "c" fn os_signpost_enabled(log: os_log_t) bool;

pub extern "c" fn pthread_setname_np(name: [*:0]const u8) c_int;
pub extern "c" fn pthread_attr_set_qos_class_np(attr: *pthread_attr_t, qos_class: qos_class_t, relative_priority: c_int) c_int;
pub extern "c" fn pthread_attr_get_qos_class_np(attr: *pthread_attr_t, qos_class: *qos_class_t, relative_priority: *c_int) c_int;
pub extern "c" fn pthread_set_qos_class_self_np(qos_class: qos_class_t, relative_priority: c_int) c_int;
pub extern "c" fn pthread_get_qos_class_np(pthread: std.c.pthread_t, qos_class: *qos_class_t, relative_priority: *c_int) c_int;

pub const mach_timebase_info_data = extern struct {
    numer: u32,
    denom: u32,
};

pub const kevent64_s = extern struct {
    ident: u64,
    filter: i16,
    flags: u16,
    fflags: u32,
    data: i64,
    udata: u64,
    ext: [2]u64,
};

// sys/types.h on macos uses #pragma pack() so these checks are
// to make sure the struct is laid out the same. These values were
// produced from C code using the offsetof macro.
comptime {
    if (builtin.target.os.tag.isDarwin()) {
        assert(@offsetOf(kevent64_s, "ident") == 0);
        assert(@offsetOf(kevent64_s, "filter") == 8);
        assert(@offsetOf(kevent64_s, "flags") == 10);
        assert(@offsetOf(kevent64_s, "fflags") == 12);
        assert(@offsetOf(kevent64_s, "data") == 16);
        assert(@offsetOf(kevent64_s, "udata") == 24);
        assert(@offsetOf(kevent64_s, "ext") == 32);
    }
}

pub const clock_serv_t = mach_port_t;
pub const clock_res_t = c_int;
pub const mach_port_name_t = natural_t;
pub const natural_t = c_uint;
pub const mach_timespec_t = extern struct {
    sec: c_uint,
    nsec: clock_res_t,
};
pub const kern_return_t = c_int;
pub const host_t = mach_port_t;
pub const integer_t = c_int;
pub const task_flavor_t = natural_t;
pub const task_info_t = *integer_t;
pub const task_name_t = mach_port_name_t;
pub const vm_address_t = vm_offset_t;
pub const vm_size_t = mach_vm_size_t;
pub const vm_machine_attribute_t = usize;
pub const vm_machine_attribute_val_t = isize;

pub const CALENDAR_CLOCK = 1;

pub const SYSPROTO_EVENT = 1;
pub const SYSPROTO_CONTROL = 2;

/// Mach msg return values
pub const mach_msg_return_t = enum(kern_return_t) {
    SUCCESS = 0x00000000,

    /// Thread is waiting to send.  (Internal use only.)
    SEND_IN_PROGRESS = 0x10000001,
    /// Bogus in-line data.
    SEND_INVALID_DATA = 0x10000002,
    /// Bogus destination port.
    SEND_INVALID_DEST = 0x10000003,
    ///  Message not sent before timeout expired.
    SEND_TIMED_OUT = 0x10000004,
    ///  Bogus voucher port.
    SEND_INVALID_VOUCHER = 0x10000005,
    ///  Software interrupt.
    SEND_INTERRUPTED = 0x10000007,
    ///  Data doesn't contain a complete message.
    SEND_MSG_TOO_SMALL = 0x10000008,
    ///  Bogus reply port.
    SEND_INVALID_REPLY = 0x10000009,
    ///  Bogus port rights in the message body.
    SEND_INVALID_RIGHT = 0x1000000a,
    ///  Bogus notify port argument.
    SEND_INVALID_NOTIFY = 0x1000000b,
    ///  Invalid out-of-line memory pointer.
    SEND_INVALID_MEMORY = 0x1000000c,
    ///  No message buffer is available.
    SEND_NO_BUFFER = 0x1000000d,
    ///  Send is too large for port
    SEND_TOO_LARGE = 0x1000000e,
    ///  Invalid msg-type specification.
    SEND_INVALID_TYPE = 0x1000000f,
    ///  A field in the header had a bad value.
    SEND_INVALID_HEADER = 0x10000010,
    ///  The trailer to be sent does not match kernel format.
    SEND_INVALID_TRAILER = 0x10000011,
    ///  The sending thread context did not match the context on the dest port
    SEND_INVALID_CONTEXT = 0x10000012,
    ///  compatibility: no longer a returned error
    SEND_INVALID_RT_OOL_SIZE = 0x10000015,
    ///  The destination port doesn't accept ports in body
    SEND_NO_GRANT_DEST = 0x10000016,
    ///  Message send was rejected by message filter
    SEND_MSG_FILTERED = 0x10000017,

    ///  Thread is waiting for receive.  (Internal use only.)
    RCV_IN_PROGRESS = 0x10004001,
    ///  Bogus name for receive port/port-set.
    RCV_INVALID_NAME = 0x10004002,
    ///  Didn't get a message within the timeout value.
    RCV_TIMED_OUT = 0x10004003,
    ///  Message buffer is not large enough for inline data.
    RCV_TOO_LARGE = 0x10004004,
    ///  Software interrupt.
    RCV_INTERRUPTED = 0x10004005,
    ///  compatibility: no longer a returned error
    RCV_PORT_CHANGED = 0x10004006,
    ///  Bogus notify port argument.
    RCV_INVALID_NOTIFY = 0x10004007,
    ///  Bogus message buffer for inline data.
    RCV_INVALID_DATA = 0x10004008,
    ///  Port/set was sent away/died during receive.
    RCV_PORT_DIED = 0x10004009,
    ///  compatibility: no longer a returned error
    RCV_IN_SET = 0x1000400a,
    ///  Error receiving message header.  See special bits (use `extractResourceError`).
    RCV_HEADER_ERROR = 0x1000400b,
    ///  Error receiving message body.  See special bits (use `extractResourceError`).
    RCV_BODY_ERROR = 0x1000400c,
    ///  Invalid msg-type specification in scatter list.
    RCV_INVALID_TYPE = 0x1000400d,
    ///  Out-of-line overwrite region is not large enough
    RCV_SCATTER_SMALL = 0x1000400e,
    ///  trailer type or number of trailer elements not supported
    RCV_INVALID_TRAILER = 0x1000400f,
    ///  Waiting for receive with timeout. (Internal use only.)
    RCV_IN_PROGRESS_TIMED = 0x10004011,
    ///  invalid reply port used in a STRICT_REPLY message
    RCV_INVALID_REPLY = 0x10004012,

    _,

    pub fn extractResourceError(ret: mach_msg_return_t) struct {
        error_code: mach_msg_return_t,
        resource_error: ?MACH.MSG,
    } {
        const return_code: mach_msg_return_t = @fromBackingInt(@intCast(@backingInt(ret) & ~MACH.MSG.MASK));
        switch (return_code) {
            .RCV_HEADER_ERROR, .RCV_BODY_ERROR => {
                const resource_error: MACH.MSG = @bitCast(@backingInt(ret) & MACH.MSG.MASK);
                return .{
                    .error_code = return_code,
                    .resource_error = resource_error,
                };
            },
            else => return .{
                .error_code = ret,
                .resource_error = null,
            },
        }
    }
};

pub const FCNTL_FS_SPECIFIC_BASE = 0x00010000;

/// Max open files per process
/// https://opensource.apple.com/source/xnu/xnu-4903.221.2/bsd/sys/syslimits.h.auto.html
pub const OPEN_MAX = 10240;

// CPU families mapping
pub const CPUFAMILY = enum(u32) {
    UNKNOWN = 0,
    POWERPC_G3 = 0xcee41549,
    POWERPC_G4 = 0x77c184ae,
    POWERPC_G5 = 0xed76d8aa,
    INTEL_6_13 = 0xaa33392b,
    INTEL_PENRYN = 0x78ea4fbc,
    INTEL_NEHALEM = 0x6b5a4cd2,
    INTEL_WESTMERE = 0x573b5eec,
    INTEL_SANDYBRIDGE = 0x5490b78c,
    INTEL_IVYBRIDGE = 0x1f65e835,
    INTEL_HASWELL = 0x10b282dc,
    INTEL_BROADWELL = 0x582ed09c,
    INTEL_SKYLAKE = 0x37fc219f,
    INTEL_KABYLAKE = 0x0f817246,
    ARM_9 = 0xe73283ae,
    ARM_11 = 0x8ff620d8,
    ARM_XSCALE = 0x53b005f5,
    ARM_12 = 0xbd1b0ae9,
    ARM_13 = 0x0cc90e64,
    ARM_14 = 0x96077ef1,
    ARM_15 = 0xa8511bca,
    ARM_SWIFT = 0x1e2d6381,
    ARM_CYCLONE = 0x37a09642,
    ARM_TYPHOON = 0x2c91a47e,
    ARM_TWISTER = 0x92fb37c8,
    ARM_HURRICANE = 0x67ceee93,
    ARM_MONSOON_MISTRAL = 0xe81e7ef6,
    ARM_VORTEX_TEMPEST = 0x07d34b9f,
    ARM_LIGHTNING_THUNDER = 0x462504d2,
    ARM_FIRESTORM_ICESTORM = 0x1b588bb3,
    ARM_BLIZZARD_AVALANCHE = 0xda33d83d,
    ARM_EVEREST_SAWTOOTH = 0x8765edea,
    ARM_COLL = 0x2876f5b5,
    ARM_IBIZA = 0xfa33415e,
    ARM_LOBOS = 0x5f4dea93,
    ARM_PALMA = 0x72015832,
    ARM_DONAN = 0x6f5129ac,
    ARM_BRAVA = 0x17d5b93a,
    ARM_TAHITI = 0x75d4acb9,
    ARM_TUPAI = 0x204526d0,
    ARM_HIDRA = 0x1d5a87e8,
    ARM_SOTRA = 0xf76c5b1a,
    ARM_THERA = 0xab345f09,
    ARM_TILOS = 0x01d7a72b,
    _,
};

pub const PT = enum(c_int) {
    TRACE_ME = 0,
    READ_I = 1,
    READ_D = 2,
    READ_U = 3,
    WRITE_I = 4,
    WRITE_D = 5,
    WRITE_U = 6,
    CONTINUE = 7,
    KILL = 8,
    STEP = 9,
    DETACH = 11,
    SIGEXC = 12,
    THUPDATE = 13,
    ATTACHEXC = 14,
    FORCEQUOTA = 30,
    DENY_ATTACH = 31,
    _,
};

pub extern "c" fn ptrace(request: PT, pid: pid_t, addr: caddr_t, data: c_int) c_int;

pub const POSIX_SPAWN = packed struct(c_short) {
    RESETIDS: bool = false,
    SETPGROUP: bool = false,
    SETSIGDEF: bool = false,
    SETSIGMASK: bool = false,
    _4: u2 = 0,
    SETEXEC: bool = false,
    START_SUSPENDED: bool = false,
    DISABLE_ASLR: bool = false,
    _9: u1 = 0,
    SETSID: bool = false,
    RESLIDE: bool = false,
    _12: u2 = 0,
    CLOEXEC_DEFAULT: bool = false,
    _15: u1 = 0,
};

pub const posix_spawnattr_t = *opaque {};
pub const posix_spawn_file_actions_t = *opaque {};
pub extern "c" fn posix_spawnattr_init(attr: *posix_spawnattr_t) c_int;
pub extern "c" fn posix_spawnattr_destroy(attr: *posix_spawnattr_t) c_int;
pub extern "c" fn posix_spawnattr_getflags(attr: *const posix_spawnattr_t, flags: *POSIX_SPAWN) c_int;
pub extern "c" fn posix_spawnattr_getpgroup(attr: *const posix_spawnattr_t, pgroup: *pid_t) c_int;
pub extern "c" fn posix_spawnattr_setflags(attr: *posix_spawnattr_t, flags: POSIX_SPAWN) c_int;
pub extern "c" fn posix_spawnattr_setpgroup(attr: *posix_spawnattr_t, pgroup: pid_t) c_int;
pub extern "c" fn posix_spawn_file_actions_init(actions: *posix_spawn_file_actions_t) c_int;
pub extern "c" fn posix_spawn_file_actions_destroy(actions: *posix_spawn_file_actions_t) c_int;
pub extern "c" fn posix_spawn_file_actions_addclose(actions: *posix_spawn_file_actions_t, filedes: fd_t) c_int;
pub extern "c" fn posix_spawn_file_actions_addopen(
    actions: *posix_spawn_file_actions_t,
    filedes: fd_t,
    path: [*:0]const u8,
    oflag: c_int,
    mode: mode_t,
) c_int;
pub extern "c" fn posix_spawn_file_actions_adddup2(
    actions: *posix_spawn_file_actions_t,
    filedes: fd_t,
    newfiledes: fd_t,
) c_int;
pub extern "c" fn posix_spawn_file_actions_addinherit_np(actions: *posix_spawn_file_actions_t, filedes: fd_t) c_int;
pub extern "c" fn posix_spawn_file_actions_addchdir_np(actions: *posix_spawn_file_actions_t, path: [*:0]const u8) c_int;
pub extern "c" fn posix_spawn_file_actions_addfchdir_np(actions: *posix_spawn_file_actions_t, filedes: fd_t) c_int;
pub extern "c" fn posix_spawn(
    pid: *pid_t,
    path: [*:0]const u8,
    actions: ?*const posix_spawn_file_actions_t,
    attr: ?*const posix_spawnattr_t,
    argv: [*:null]const ?[*:0]const u8,
    env: [*:null]const ?[*:0]const u8,
) c_int;
pub extern "c" fn posix_spawnp(
    pid: *pid_t,
    path: [*:0]const u8,
    actions: ?*const posix_spawn_file_actions_t,
    attr: ?*const posix_spawnattr_t,
    argv: [*:null]const ?[*:0]const u8,
    env: [*:null]const ?[*:0]const u8,
) c_int;

pub const E = enum(u16) {
    /// No error occurred.
    SUCCESS = 0,
    /// Operation not permitted
    PERM = 1,
    /// No such file or directory
    NOENT = 2,
    /// No such process
    SRCH = 3,
    /// Interrupted system call
    INTR = 4,
    /// Input/output error
    IO = 5,
    /// Device not configured
    NXIO = 6,
    /// Argument list too long
    @"2BIG" = 7,
    /// Exec format error
    NOEXEC = 8,
    /// Bad file descriptor
    BADF = 9,
    /// No child processes
    CHILD = 10,
    /// Resource deadlock avoided
    DEADLK = 11,
    /// Cannot allocate memory
    NOMEM = 12,
    /// Permission denied
    ACCES = 13,
    /// Bad address
    FAULT = 14,
    /// Block device required
    NOTBLK = 15,
    /// Device / Resource busy
    BUSY = 16,
    /// File exists
    EXIST = 17,
    /// Cross-device link
    XDEV = 18,
    /// Operation not supported by device
    NODEV = 19,
    /// Not a directory
    NOTDIR = 20,
    /// Is a directory
    ISDIR = 21,
    /// Invalid argument
    INVAL = 22,
    /// Too many open files in system
    NFILE = 23,
    /// Too many open files
    MFILE = 24,
    /// Inappropriate ioctl for device
    NOTTY = 25,
    /// Text file busy
    TXTBSY = 26,
    /// File too large
    FBIG = 27,
    /// No space left on device
    NOSPC = 28,
    /// Illegal seek
    SPIPE = 29,
    /// Read-only file system
    ROFS = 30,
    /// Too many links
    MLINK = 31,
    /// Broken pipe
    PIPE = 32,
    // math software
    /// Numerical argument out of domain
    DOM = 33,
    /// Result too large
    RANGE = 34,
    // non-blocking and interrupt i/o
    /// Resource temporarily unavailable
    /// This is the same code used for `WOULDBLOCK`.
    AGAIN = 35,
    /// Operation now in progress
    INPROGRESS = 36,
    /// Operation already in progress
    ALREADY = 37,
    // ipc/network software -- argument errors
    /// Socket operation on non-socket
    NOTSOCK = 38,
    /// Destination address required
    DESTADDRREQ = 39,
    /// Message too long
    MSGSIZE = 40,
    /// Protocol wrong type for socket
    PROTOTYPE = 41,
    /// Protocol not available
    NOPROTOOPT = 42,
    /// Protocol not supported
    PROTONOSUPPORT = 43,
    /// Socket type not supported
    SOCKTNOSUPPORT = 44,
    /// Operation not supported
    /// The same code is used for `NOTSUP`.
    OPNOTSUPP = 45,
    /// Protocol family not supported
    PFNOSUPPORT = 46,
    /// Address family not supported by protocol family
    AFNOSUPPORT = 47,
    /// Address already in use
    ADDRINUSE = 48,
    /// Can't assign requested address
    // ipc/network software -- operational errors
    ADDRNOTAVAIL = 49,
    /// Network is down
    NETDOWN = 50,
    /// Network is unreachable
    NETUNREACH = 51,
    /// Network dropped connection on reset
    NETRESET = 52,
    /// Software caused connection abort
    CONNABORTED = 53,
    /// Connection reset by peer
    CONNRESET = 54,
    /// No buffer space available
    NOBUFS = 55,
    /// Socket is already connected
    ISCONN = 56,
    /// Socket is not connected
    NOTCONN = 57,
    /// Can't send after socket shutdown
    SHUTDOWN = 58,
    /// Too many references: can't splice
    TOOMANYREFS = 59,
    /// Operation timed out
    TIMEDOUT = 60,
    /// Connection refused
    CONNREFUSED = 61,
    /// Too many levels of symbolic links
    LOOP = 62,
    /// File name too long
    NAMETOOLONG = 63,
    /// Host is down
    HOSTDOWN = 64,
    /// No route to host
    HOSTUNREACH = 65,
    /// Directory not empty
    // quotas & mush
    NOTEMPTY = 66,
    /// Too many processes
    PROCLIM = 67,
    /// Too many users
    USERS = 68,
    /// Disc quota exceeded
    // Network File System
    DQUOT = 69,
    /// Stale NFS file handle
    STALE = 70,
    /// Too many levels of remote in path
    REMOTE = 71,
    /// RPC struct is bad
    BADRPC = 72,
    /// RPC version wrong
    RPCMISMATCH = 73,
    /// RPC prog. not avail
    PROGUNAVAIL = 74,
    /// Program version wrong
    PROGMISMATCH = 75,
    /// Bad procedure for program
    PROCUNAVAIL = 76,
    /// No locks available
    NOLCK = 77,
    /// Function not implemented
    NOSYS = 78,
    /// Inappropriate file type or format
    FTYPE = 79,
    /// Authentication error
    AUTH = 80,
    /// Need authenticator
    NEEDAUTH = 81,
    // Intelligent device errors
    /// Device power is off
    PWROFF = 82,
    /// Device error, e.g. paper out
    DEVERR = 83,
    /// Value too large to be stored in data type
    OVERFLOW = 84,
    // Program loading errors
    /// Bad executable
    BADEXEC = 85,
    /// Bad CPU type in executable
    BADARCH = 86,
    /// Shared library version mismatch
    SHLIBVERS = 87,
    /// Malformed Macho file
    BADMACHO = 88,
    /// Operation canceled
    CANCELED = 89,
    /// Identifier removed
    IDRM = 90,
    /// No message of desired type
    NOMSG = 91,
    /// Illegal byte sequence
    ILSEQ = 92,
    /// Attribute not found
    NOATTR = 93,
    /// Bad message
    BADMSG = 94,
    /// Reserved
    MULTIHOP = 95,
    /// No message available on STREAM
    NODATA = 96,
    /// Reserved
    NOLINK = 97,
    /// No STREAM resources
    NOSR = 98,
    /// Not a STREAM
    NOSTR = 99,
    /// Protocol error
    PROTO = 100,
    /// STREAM ioctl timeout
    TIME = 101,
    /// No such policy registered
    NOPOLICY = 103,
    /// State not recoverable
    NOTRECOVERABLE = 104,
    /// Previous owner died
    OWNERDEAD = 105,
    /// Interface output queue is full
    QFULL = 106,
    /// Capabilities insufficient
    NOTCAPABLE = 107,
    _,
};

/// From Common Security Services Manager
/// Security.framework/Headers/cssm*.h
pub const DB_RECORDTYPE = enum(u32) {
    // Record Types defined in the Schema Management Name Space
    SCHEMA_INFO = SCHEMA_START + 0,
    SCHEMA_INDEXES = SCHEMA_START + 1,
    SCHEMA_ATTRIBUTES = SCHEMA_START + 2,
    SCHEMA_PARSING_MODULE = SCHEMA_START + 3,

    // Record Types defined in the Open Group Application Name Space
    ANY = OPEN_GROUP_START + 0,
    CERT = OPEN_GROUP_START + 1,
    CRL = OPEN_GROUP_START + 2,
    POLICY = OPEN_GROUP_START + 3,
    GENERIC = OPEN_GROUP_START + 4,
    PUBLIC_KEY = OPEN_GROUP_START + 5,
    PRIVATE_KEY = OPEN_GROUP_START + 6,
    SYMMETRIC_KEY = OPEN_GROUP_START + 7,
    ALL_KEYS = OPEN_GROUP_START + 8,

    // AppleFileDL record types
    GENERIC_PASSWORD = APP_DEFINED_START + 0,
    INTERNET_PASSWORD = APP_DEFINED_START + 1,
    APPLESHARE_PASSWORD = APP_DEFINED_START + 2,

    X509_CERTIFICATE = APP_DEFINED_START + 0x1000,
    USER_TRUST,
    X509_CRL,
    UNLOCK_REFERRAL,
    EXTENDED_ATTRIBUTE,
    METADATA = APP_DEFINED_START + 0x8000,

    _,

    // Schema Management Name Space Range Definition
    pub const SCHEMA_START = 0x00000000;
    pub const SCHEMA_END = SCHEMA_START + 4;

    // Open Group Application Name Space Range Definition
    pub const OPEN_GROUP_START = 0x0000000A;
    pub const OPEN_GROUP_END = OPEN_GROUP_START + 8;

    // Industry At Large Application Name Space Range Definition
    pub const APP_DEFINED_START = 0x80000000;
    pub const APP_DEFINED_END = 0xffffffff;
};

pub const TCP = struct {
    /// Turn off Nagle's algorithm
    pub const NODELAY = 0x01;
    /// Limit MSS
    pub const MAXSEG = 0x02;
    /// Don't push last block of write
    pub const NOPUSH = 0x04;
    /// Don't use TCP options
    pub const NOOPT = 0x08;
    /// Idle time used when SO_KEEPALIVE is enabled
    pub const KEEPALIVE = 0x10;
    /// Connection timeout
    pub const CONNECTIONTIMEOUT = 0x20;
    /// Time after which a conection in persist timeout will terminate.
    pub const PERSIST_TIMEOUT = 0x40;
    /// Time after which TCP retransmissions will be stopped and the connection will be dropped.
    pub const RXT_CONNDROPTIME = 0x80;
    /// Drop a connection after retransmitting the FIN 3 times.
    pub const RXT_FINDROP = 0x100;
    /// Interval between keepalives
    pub const KEEPINTVL = 0x101;
    /// Number of keepalives before clsoe
    pub const KEEPCNT = 0x102;
    /// Always ack every other packet
    pub const SENDMOREACKS = 0x103;
    /// Enable ECN on a connection
    pub const ENABLE_ECN = 0x104;
    /// Enable/Disable TCP Fastopen on this socket
    pub const FASTOPEN = 0x105;
    /// State of the TCP connection
    pub const CONNECTION_INFO = 0x106;
};

pub const MSG = struct {
    /// process out-of-band data
    pub const OOB = 0x1;
    /// peek at incoming message
    pub const PEEK = 0x2;
    /// send without using routing tables
    pub const DONTROUTE = 0x4;
    /// data completes record
    pub const EOR = 0x8;
    /// data discarded before delivery
    pub const TRUNC = 0x10;
    /// control data lost before delivery
    pub const CTRUNC = 0x20;
    /// wait for full request or error
    pub const WAITALL = 0x40;
    /// this message should be nonblocking
    pub const DONTWAIT = 0x80;
    /// data completes connection
    pub const EOF = 0x100;
    /// wait up to full request, may return partial
    pub const WAITSTREAM = 0x200;
    /// Start of 'hold' seq; dump so_temp, deprecated
    pub const FLUSH = 0x400;
    /// Hold frag in so_temp, deprecated
    pub const HOLD = 0x800;
    /// Send the packet in so_temp, deprecated
    pub const SEND = 0x1000;
    /// Data ready to be read
    pub const HAVEMORE = 0x2000;
    /// Data remains in current pkt
    pub const RCVMORE = 0x4000;
    /// Fail receive if socket address cannot be allocated
    pub const NEEDSA = 0x10000;
    /// do not generate SIGPIPE on EOF
    pub const NOSIGNAL = 0x80000;
    /// Inherit upcall in sock_accept
    pub const USEUPCALL = 0x80000000;
};

// https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/bsd/netinet/in.h#L454
pub const IP = struct {
    pub const OPTIONS = 1;
    pub const HDRINCL = 2;
    pub const TOS = 3;
    pub const TTL = 4;
    pub const RECVOPTS = 5;
    pub const RECVRETOPTS = 6;
    pub const RECVDSTADDR = 7;
    pub const RETOPTS = 8;
    pub const MULTICAST_IF = 9;
    pub const MULTICAST_TTL = 10;
    pub const MULTICAST_LOOP = 11;
    pub const ADD_MEMBERSHIP = 12;
    pub const DROP_MEMBERSHIP = 13;
    pub const MULTICAST_VIF = 14;
    pub const RSVP_ON = 15;
    pub const RSVP_OFF = 16;
    pub const RSVP_VIF_ON = 17;
    pub const RSVP_VIF_OFF = 18;
    pub const PORTRANGE = 19;
    pub const RECVIF = 20;
    pub const IPSEC_POLICY = 21;
    pub const FAITH = 22;
    pub const STRIPHDR = 23;
    pub const RECVTTL = 24;
    pub const BOUND_IF = 25;
    pub const PKTINFO = 26;
    pub const RECVPKTINFO = PKTINFO;
    pub const RECVTOS = 27;
    pub const DONTFRAG = 28;
    pub const FW_ADD = 40;
    pub const FW_DEL = 41;
    pub const FW_FLUSH = 42;
    pub const FW_ZERO = 43;
    pub const FW_GET = 44;
    pub const FW_RESETLOG = 45;
    pub const OLD_FW_ADD = 50;
    pub const OLD_FW_DEL = 51;
    pub const OLD_FW_FLUSH = 52;
    pub const OLD_FW_ZERO = 53;
    pub const OLD_FW_GET = 54;
    pub const OLD_FW_RESETLOG = 56;
    pub const DUMMYNET_CONFIGURE = 60;
    pub const DUMMYNET_DEL = 61;
    pub const DUMMYNET_FLUSH = 62;
    pub const DUMMYNET_GET = 64;
    pub const TRAFFIC_MGT_BACKGROUND = 65;
    pub const MULTICAST_IFINDEX = 66;
    pub const ADD_SOURCE_MEMBERSHIP = 70;
    pub const DROP_SOURCE_MEMBERSHIP = 71;
    pub const BLOCK_SOURCE = 72;
    pub const UNBLOCK_SOURCE = 73;
    pub const MSFILTER = 74;
    // Same namespace, but these are arguments rather than option names
    pub const DEFAULT_MULTICAST_TTL = 1;
    pub const DEFAULT_MULTICAST_LOOP = 1;
    pub const MIN_MEMBERSHIPS = 31;
    pub const MAX_MEMBERSHIPS = 4095;
    pub const MAX_GROUP_SRC_FILTER = 512;
    pub const MAX_SOCK_SRC_FILTER = 128;
    pub const MAX_SOCK_MUTE_FILTER = 128;
    pub const PORTRANGE_DEFAULT = 0;
    pub const PORTRANGE_HIGH = 1;
    pub const PORTRANGE_LOW = 2;
};

// https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/bsd/netinet6/in6.h#L521
pub const IPV6 = struct {
    pub const UNICAST_HOPS = 4;
    pub const MULTICAST_IF = 9;
    pub const MULTICAST_HOPS = 10;
    pub const MULTICAST_LOOP = 11;
    pub const JOIN_GROUP = 12;
    pub const LEAVE_GROUP = 13;
    pub const PORTRANGE = 14;
    pub const @"2292PKTINFO" = 19;
    pub const @"2292HOPLIMIT" = 20;
    pub const @"2292NEXTHOP" = 21;
    pub const @"2292HOPOPTS" = 22;
    pub const @"2292DSTOPTS" = 23;
    pub const @"2292RTHDR" = 24;
    pub const @"2292PKTOPTIONS" = 25;
    pub const CHECKSUM = 26;
    pub const V6ONLY = 27;
    pub const BINDV6ONLY = V6ONLY;
    pub const IPSEC_POLICY = 28;
    pub const FAITH = 29;
    pub const FW_ADD = 30;
    pub const FW_DEL = 31;
    pub const FW_FLUSH = 32;
    pub const FW_ZERO = 33;
    pub const FW_GET = 34;
    pub const RECVTCLASS = 35;
    pub const TCLASS = 36;
    pub const RTHDRDSTOPTS = 57;
    pub const RECVPKTINFO = 61;
    pub const RECVHOPLIMIT = 37;
    pub const RECVRTHDR = 38;
    pub const RECVHOPOPTS = 39;
    pub const RECVDSTOPTS = 40;
    pub const RECVRTHDRDSTOPTS = 41;
    pub const USE_MIN_MTU = 42;
    pub const RECVPATHMTU = 43;
    pub const PATHMTU = 44;
    pub const REACHCONF = 45;
    pub const @"3542PKTINFO" = 46;
    pub const @"3542HOPLIMIT" = 47;
    pub const @"3542NEXTHOP" = 48;
    pub const @"3542HOPOPTS" = 49;
    pub const @"3542DSTOPTS" = 50;
    pub const @"3542RTHDR" = 51;
    pub const PKTINFO = @"3542PKTINFO";
    pub const HOPLIMIT = @"3542HOPLIMIT";
    pub const NEXTHOP = @"3542NEXTHOP";
    pub const HOPOPTS = @"3542HOPOPTS";
    pub const DSTOPTS = @"3542DSTOPTS";
    pub const RTHDR = @"3542RTHDR";
    pub const AUTOFLOWLABEL = 59;
    pub const DONTFRAG = 62;
    pub const PREFER_TEMPADDR = 63;
    pub const MSFILTER = 74;
    pub const BOUND_IF = 125;
    // Same namespace, but these are arguments rather than option names
    pub const RTHDR_LOOSE = 0;
    pub const RTHDR_STRICT = 1;
    pub const RTHDR_TYPE_0 = 0;
    pub const DEFAULT_MULTICAST_HOPS = 1;
    pub const DEFAULT_MULTICAST_LOOP = 1;
    pub const MIN_MEMBERSHIPS = 31;
    pub const MAX_MEMBERSHIPS = 4095;
    pub const MAX_GROUP_SRC_FILTER = 512;
    pub const MAX_SOCK_SRC_FILTER = 128;
    pub const PORTRANGE_DEFAULT = 0;
    pub const PORTRANGE_HIGH = 1;
    pub const PORTRANGE_LOW = 2;
};

// https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/bsd/netinet/ip.h#L129
pub const IPTOS = struct {
    pub const LOWDELAY = 0x10;
    pub const THROUGHPUT = 0x08;
    pub const RELIABILITY = 0x04;
    pub const MINCOST = 0x02;
    pub const CE = 0x01;
    pub const ECT = 0x02;
    pub const DSCP_SHIFT = 2;
    pub const ECN_NOTECT = 0x00;
    pub const ECN_ECT1 = 0x01;
    pub const ECN_ECT0 = 0x02;
    pub const ECN_CE = 0x03;
    pub const ECN_MASK = 0x03;
    pub const PREC_NETCONTROL = 0xe0;
    pub const PREC_INTERNETCONTROL = 0xc0;
    pub const PREC_CRITIC_ECP = 0xa0;
    pub const PREC_FLASHOVERRIDE = 0x80;
    pub const PREC_FLASH = 0x60;
    pub const PREC_IMMEDIATE = 0x40;
    pub const PREC_PRIORITY = 0x20;
    pub const PREC_ROUTINE = 0x00;
};