POSIX declarations used by Linux and macOS timing, descriptor, process, pipe, and context-switching helpers.
Functions that report failure with -1 set errno.
Constants
Error numbers
| Name | Linux | macOS | Meaning |
|---|---|---|---|
EAGAIN | 11 | 35 | Resource temporarily unavailable. |
EBADF | — | 9 | Bad file descriptor. |
EINPROGRESS | 115 | 36 | Operation in progress. |
EINTR | 4 | 4 | Interrupted operation. |
ENOENT | — | 2 | No such file or directory. |
EWOULDBLOCK | EAGAIN | EAGAIN | Operation would block. |
Descriptor control
| Name | Linux | macOS | Meaning |
|---|---|---|---|
F_SETFD | 2 | 2 | Sets descriptor flags. |
FD_CLOEXEC | 1 | 1 | Close-on-exec descriptor flag. |
O_NONBLOCK | 2048 | 4 | Nonblocking file-status flag. |
Memory mappings
| Name | Linux | macOS | Meaning |
|---|---|---|---|
MAP_ANONYMOUS | 0x0020 | 0x1000 | Anonymous mapping flag. |
MAP_PRIVATE | 0x0002 | 0x0002 | Private mapping flag. |
MAP_STACK | 0x020000 | — | Stack mapping flag. |
Open flags
| Name | Linux | macOS | Meaning |
|---|---|---|---|
O_CLOEXEC | 0x80000 | — | Close-on-exec open flag. |
O_CREAT | 0x40 | — | Create-if-absent open flag. |
O_RDWR | 0x2 | — | Read-and-write open flag. |
Memory protections
| Name | Linux | macOS | Meaning |
|---|---|---|---|
PROT_NONE | 0x0 | 0x0 | No-access protection. |
PROT_READ | 0x1 | 0x1 | Read protection. |
PROT_WRITE | 0x2 | 0x2 | Write protection. |
Process and wait
| Name | Linux | macOS | Meaning |
|---|---|---|---|
SIGKILL | 9 | 9 | Terminate-process signal. |
WNOHANG | 1 | — | Do not wait for a child state change. |
Clocks
| Name | Linux | macOS | Meaning |
|---|---|---|---|
CLOCK_BOOTTIME | 7 | — | Boot-time clock identifier. |
CLOCK_MONOTONIC | 1 | 6 | Monotonic clock identifier. |
Schemas
__darwin_mcontext_data
(-- __darwin_mcontext_data) Defines Darwin machine-context storage.Nat8 824 array; macOS only
timespec
(-- timespec) Defines seconds and nanoseconds for one time value.Dict schema
ucontext_t
(-- ucontext_t) Defines user-context storage.Linux: Ucontext alias; macOS: Dict schema
Linux
| Field | Schema | Role |
|---|---|---|
uc_flags | Natx | context flags |
uc_link | [ucontext_t] Mref | successor context |
uc_stack | {ss_sp: Natx; ss_flags: Int32; ss_size: Natx;} | stack used by this context |
- The remaining fields are processor-specific:
linux/architectureselects the processor layout forUcontext, and dependent schemas such asstack_tbelong tolinux/architecture/Ucontext, notlinux/posix. For thelinux/architecturelink, seeepoll_event.
macOS
| Field | Schema | Role |
|---|---|---|
uc_onstack | Int32 | alternate-stack state |
uc_sigmask | sigset_t | signal mask |
uc_stack | stack_t | stack used by this context |
uc_link | [ucontext_t] Mref | successor context |
uc_mcsize | Natx | machine-context size |
uc_mcontext | [__darwin_mcontext_data] Mref | machine context |
__mcontext_data | __darwin_mcontext_data | machine-context storage |
Helpers
WEXITSTATUS
(status -- result) Extracts the exit status from a wait status for which WIFEXITED is true and returns an Int32.Imported functions
Stack effects list a C function's parameters with the first parameter on top; see importFunction.
Inputs
tp:timespecRefcaller-owned writable time storage; the call writes it.clk_id:clockid_tclock identifier.
Outputs
result:Int320on success, or-1on failure.
close
(fildes -- result) Closes a file descriptor.Inputs
fildes:Int32file descriptor to close.
Outputs
result:Int320on success, or-1on failure.
execvp
(argv file -- result) Replaces the current process image with the named executable.Inputs
argv:Natxaddress of a zero-terminated array of addresses of zero-terminated argument strings.file:Natxaddress of a zero-terminated executable path; a name without a slash is searched for in the directories listed inPATH.
Outputs
result:Int32-1on failure; on success, the call does not return.
fcntl
(varargs cmd fildes -- result) Applies a descriptor command.Inputs
varargs:ListorTupleholding the additional arguments, the first one as item 0; use()when there are none.cmd:Int32descriptor command.fildes:Int32file descriptor to control.
Outputs
result:Int32command-specific result, or-1on failure.
fork
(-- result) Creates a child process.Inputs
- None.
Outputs
result:Int32child process identifier in the parent,0in the child, or-1on failure.
getcontext
(ucp -- result) Saves the current user context.Inputs
ucp:ucontext_tRefcaller-owned writable context storage; the call writes it.
Outputs
result:Int320on success, or-1on failure.
getpid
(-- result) Returns the calling process identifier.Inputs
- None.
Outputs
result:Int32calling process identifier.
kill
(sig pid -- result) Sends a signal to a process.Inputs
Outputs
result:Int320on success, or-1on failure.
makecontext
(varargs argc func ucp --) Initializes a user context for a function call.Inputs
varargs:ListorTupleholding the additional arguments, the first one as item 0; use()when there are none.argc:Int32number of additional arguments passed to the target function.func:Natxaddress of the target function.ucp:ucontext_tRefcontext obtained withgetcontext, withuc_stackanduc_linkconfigured; the call sets its entry point and arguments.
Outputs
- None.
mmap
(offset fd flags prot length addr -- result) Maps memory into the process address space.Inputs
offset:Intxmapping offset in bytes, a multiple of the page size.fd:Int32file descriptor for the mapped object, or-1withMAP_ANONYMOUSinflagsfor an anonymous mapping.flags:Int32mapping flags, which must includeMAP_PRIVATEorMAP_SHARED.prot:Int32memory-protection flags.length:Natxnonzero mapping length in bytes.addr:Natxrequested mapping address, or0nxfor no address hint.
Outputs
result:Natxmapped address, or the all-bits-one value on failure.
mprotect
(prot length addr -- result) Changes protection on a memory range.Inputs
prot:Int32memory-protection flags.length:Natxrange length in bytes.addr:Natxstart address of the memory range, a multiple of the page size.
Outputs
result:Int320on success, or-1on failure.
open
(varargs flags path -- result) Opens a path with flags.Inputs
varargs:ListorTupleholding the additional arguments, the first one as item 0; use()when there are none.flags:Int32open flags;O_CREATalso requires the file-creation mode as anInt32item ofvarargs.path:Natxaddress of a zero-terminated path string.
Outputs
result:Int32new descriptor, or-1on failure.
Remarks
- Linux declaration only.
pause
(-- result) Waits for a signal.Inputs
- None.
Outputs
result:Int32-1after a signal handler returns.
Remarks
- Linux declaration only.
pipe
(filedes -- result) Creates a pipe and fills its descriptor pair.Inputs
filedes:{in:Int32; out:Int32;}Refcaller-owned descriptor-pair storage; the call writes the read descriptor toinand the write descriptor toout.
Outputs
result:Int320on success, or-1on failure.
read
(size buffer filedes -- result) Reads bytes from a file descriptor.Inputs
size:Natxnumber of bytes requested.buffer:Natxaddress of writable byte storage.filedes:Int32file descriptor to read.
Outputs
result:Intxnumber of bytes read,0ixat end of file, or-1ixon failure.
swapcontext
(ucp oucp -- result) Saves one user context and activates another.Inputs
ucp:ucontext_tRefcontext to activate.oucp:ucontext_tRefcaller-owned writable storage for the saved context; the call writes it.
Outputs
result:Int320when the saved context is resumed, or-1on failure.
waitpid
(options wstatus pid -- result) Waits for a child process state change.Inputs
options:Int32wait options.wstatus:Int32Refcaller-owned writable storage that receives the wait status, or a typedNILInt32 Refwhen the status is not needed.pid:Int32child process identifier to wait for.
Outputs
Examples
Signature examples
Printing imported names during compilation shows exact imported signatures for representative declarations.
"control" use
"linux/posix" use
{} Int32 {} [
@clock_gettime printStack _:;
@fcntl printStack _:;
@pipe printStack _:;
@waitpid printStack _:;
0
] "main" exportFunction
Expected Output During Compilation
{clk_id: Int32; tp: {tv_sec: Intx; tv_nsec: Intx;} Ref;} Int32 {convention: "";} codeRef
{fildes: Int32; cmd: Int32;} Int32 {convention: ""; variadic: TRUE;} codeRef
{filedes: {in: Int32; out: Int32;} Ref;} Int32 {convention: "";} codeRef
{pid: Int32; wstatus: Int32 Ref; options: Int32;} Int32 {convention: "";} codeRef
macOS signature and layout example
Printing representative macOS declarations during compilation shows exact imported signatures and the field count of ucontext_t.
"control" use
"macos/posix" use
{} Int32 {} [
@clock_gettime printStack _:;
@getpid printStack _:;
ucontext_t fieldCount printStack _:;
0
] "main" exportFunction
Expected Output During Compilation
{clk_id: Int32; tp: {tv_sec: Intx; tv_nsec: Intx;} Ref;} Int32 {convention: "";} codeRef
{} Int32 {convention: "";} codeRef
7
Pipe round-trip
"String" use
"control" use
"posix" use
{} Int32 {} [
fds: {in: Int32; out: Int32;};
pipeResult: @fds pipe;
bytesWritten: 1nx "A" storageAddress fds.out new write;
byte: 0n8;
bytesRead: 1nx @byte storageAddress fds.in new read;
closeIn: fds.in new close;
closeOut: fds.out new close;
("pipe=" pipeResult LF
"written=" bytesWritten LF
"read=" bytesRead LF
"byte=" byte LF
"closeIn=" closeIn LF
"closeOut=" closeOut LF) printList
0
] "main" exportFunction
Expected Output
pipe=0
written=1
read=1
byte=65
closeIn=0
closeOut=0
See also
- linux/errno · macos/errno · windows/errno: Accessor for platform error-number storage.
- linux/linux: Linux epoll, timerfd, and flock declarations.
- macos/macos: macOS kqueue and kevent declarations.
- linux/Process · macos/Process · windows/Process: Cross-platform process wrapper with explicit creation, waiting, and termination helpers.
- linux/runningTime · macos/runningTime · windows/runningTime: Elapsed-time helper built on platform timing APIs.
- linux/socket · macos/socket: Linux and macOS socket declarations, constants, address schemas, and imported functions.