Linux declarations for epoll polling, timerfd timers, advisory file locking with flock, file information with statx, and signal descriptors with signalfd.
Functions that report failure with -1 set errno.
Constants
epoll control operations
| Name | Value | Meaning |
|---|---|---|
EPOLL_CTL_ADD | 1 | Adds a descriptor to the interest list. |
EPOLL_CTL_DEL | 2 | Removes a descriptor from the interest list. |
EPOLL_CTL_MOD | 3 | Modifies a descriptor in the interest list. |
epoll event flags
| Name | Value | Meaning |
|---|---|---|
EPOLLERR | 0x008n32 | Error condition. |
EPOLLHUP | 0x010n32 | Hang-up condition. |
EPOLLIN | 0x001n32 | Readable condition. |
EPOLLONESHOT | 0x40000000n32 | Disables the event after one delivery. |
EPOLLOUT | 0x004n32 | Writable condition. |
timerfd flags
| Name | Value | Meaning |
|---|---|---|
TFD_NONBLOCK | 2048 | Nonblocking timerfd flag. |
flock operations
| Name | Value | Meaning |
|---|---|---|
LOCK_EX | 0x2 | Requests an exclusive lock. |
LOCK_NB | 0x4 | Requests a nonblocking operation. |
LOCK_SH | 0x1 | Requests a shared lock. |
LOCK_UN | 0x8 | Releases a lock. |
signalfd flags
| Name | Value | Meaning |
|---|---|---|
SFD_CLOEXEC | 0x80000 | Close-on-exec signalfd flag. |
SFD_NONBLOCK | 0x800 | Nonblocking signalfd flag. |
Example: constants of linux
EPOLL_CTL_ADD is 1, EPOLLIN is 1n32, and TFD_NONBLOCK is 2048, each with its declared schema.
"control" use
"linux/linux" use
{} () {} [
EPOLL_CTL_ADD printStack _:;
EPOLLIN printStack _:;
TFD_NONBLOCK printStack _:;
] "main" exportFunction
Expected Output During Compilation
1
1n32
2048
Schemas
epoll_event
(-- epoll_event) Defines the imported epoll-event schema.EpollEvent alias
| Field | Schema | Role |
|---|---|---|
events | Nat32 | readiness mask |
ptr | Natx Ref | event data as an address |
fd | Int32 Ref | event data as a descriptor |
u32 | Nat32 Ref | event data as a 32-bit value |
u64 | Nat64 Ref | event data as a 64-bit value |
- The views share storage and preserve the record's constness.
linux/architecturemust point tox86_64,arm64, ori386for the target CPU; it selects bothEpollEventandUcontext.tiny pull(2.2.0or later) creates this link onx86_64andarm64;i386requires manual setup.
From the directory containing linux/, run the command for the target CPU:
# x86_64
ln -sfnT x86_64 linux/architecture
# arm64 / aarch64
ln -sfnT arm64 linux/architecture
# i386 / i686
ln -sfnT i386 linux/architecture
signalfd_siginfo
(-- signalfd_siginfo) Defines the signal information read from a signalfd descriptor.Dict schema
| Field | Schema | Role |
|---|---|---|
ssi_signo | Nat32 | signal number |
ssi_errno | Int32 | error number |
ssi_code | Int32 | signal code |
ssi_pid | Nat32 | identifier of the sending process |
ssi_uid | Nat32 | real user identifier of the sending process |
ssi_fd | Int32 | file descriptor for SIGIO |
ssi_tid | Nat32 | kernel timer identifier for POSIX timers |
ssi_band | Nat32 | band event for SIGIO |
ssi_overrun | Nat32 | POSIX timer overrun count |
ssi_trapno | Nat32 | trap number that caused the signal |
ssi_status | Int32 | exit status or signal for SIGCHLD |
ssi_int | Int32 | value passed with the signal, as an integer |
ssi_ptr | Nat64 | value passed with the signal, as an address |
ssi_utime | Nat64 | user CPU time consumed for SIGCHLD |
ssi_stime | Nat64 | system CPU time consumed for SIGCHLD |
ssi_addr | Nat64 | address that generated the signal |
ssi_addr_lsb | Nat16 | least-significant address bit for SIGBUS |
padding2 | Nat16 | padding |
ssi_syscall | Int32 | system-call number for SIGSYS |
ssi_call_addr | Nat64 | address of the system-call instruction for SIGSYS |
ssi_arch | Nat32 | architecture of the system call for SIGSYS |
padding | Nat8 28 array | padding |
Imported functions
Stack effects list a C function's parameters with the first parameter on top; see the stack-order rule.
epoll_create1
(flags -- result) Creates an epoll file descriptor.Inputs
flags:Int32descriptor creation flags.
Outputs
result:Int32new descriptor, or-1on failure.
epoll_ctl
(event fd op epfd -- result) Adds, removes, or modifies a descriptor in an epoll interest list.Inputs
event:epoll_eventRefcaller-owned event record for the operation.fd:Int32descriptor to control.op:Int32epoll control operation.epfd:Int32epoll descriptor.
Outputs
result:Int320on success, or-1on failure.
epoll_wait
(timeout maxevents events epfd -- result) Waits for ready epoll events.Inputs
timeout:Int32wait timeout in milliseconds;-1waits indefinitely,0returns immediately.maxevents:Int32capacity of events inepoll_eventrecords.events:Natxaddress of contiguous writableepoll_eventrecords; the call fills them with ready events.epfd:Int32epoll descriptor.
Outputs
result:Int32number of ready events,0on timeout, or-1on failure.
flock
(op fd -- result) Applies a file-lock operation.Inputs
Outputs
result:Int320on success, or-1on failure.
signalfd
(flags mask fd -- result) Creates or updates a signal file descriptor.Inputs
flags:Int32descriptor creation flags.mask:sigset_tCrefsignal set to accept through the descriptor.fd:Int32descriptor to update, or-1to create one.
Outputs
result:Int32new or updated descriptor, or-1on failure.
statx
(statxbuf mask flags path dirfd -- result) Retrieves information about a file.Inputs
statxbuf:Natxaddress of caller-owned writable 256-byte storage that receives the file information.mask:Nat32mask of the requested fields.flags:Int32path-resolution and synchronization flags.path:Natxaddress of a zero-terminated path string.dirfd:Int32directory descriptor used to resolve a relative path.
Outputs
result:Int320on success, or-1on failure.
timerfd_create
(flags clockid -- result) Creates a timer file descriptor.Inputs
Outputs
result:Int32new descriptor, or-1on failure.
timerfd_settime
(old_value new_value flags fd -- result) Sets a timerfd expiration and interval.Inputs
old_value:itimerspecRefcaller-owned writable storage that receives the previous timer setting, or a typedNILitimerspec Refwhen the previous setting is not needed.new_value:itimerspecCrefborrowed timer setting to apply.flags:Int32timer-setting flags.fd:Int32timerfd descriptor.
Outputs
result:Int320on success, or-1on failure.
Examples
Example: epoll_wait and timerfd_settime signatures
Printing imported names during compilation shows exact imported signatures for representative declarations.
"control" use
"linux/linux" use
{} Int32 {} [
@epoll_wait printStack _:;
@timerfd_settime printStack _:;
0
] "main" exportFunction
Expected Output During Compilation
{epfd: Int32; events: Natx; maxevents: Int32; timeout: Int32;} Int32 {convention: "";} codeRef
{fd: Int32; flags: Int32; new_value: {it_interval: {tv_sec: Intx; tv_nsec: Intx;}; it_value: {tv_sec: Intx; tv_nsec: Intx;};} Cref; old_value: {it_interval: {tv_sec: Intx; tv_nsec: Intx;}; it_value: {tv_sec: Intx; tv_nsec: Intx;};} Ref;} Int32 {convention: "";} codeRef
Example: epoll descriptor creation
epoll_create1 returns a nonnegative descriptor, and close releases it with result 0.
"String" use
"control" use
"linux/linux" use
"linux/posix" use
{} Int32 {} [
epfd: 0 epoll_create1;
epClose: epfd close;
("created=" epfd 0 < ~ LF
"close=" epClose 0 = LF) printList
0
] "main" exportFunction
Expected Output
created=TRUE
close=TRUE
Example: timer descriptor creation
timerfd_create with TFD_NONBLOCK and CLOCK_MONOTONIC returns a nonnegative descriptor, and close releases it with result 0.
"String" use
"control" use
"linux/linux" use
"linux/posix" use
{} Int32 {} [
fd: TFD_NONBLOCK CLOCK_MONOTONIC timerfd_create;
closeResult: fd close;
("created=" fd 0 < ~ LF
"close=" closeResult 0 = LF) printList
0
] "main" exportFunction
Expected Output
created=TRUE
close=TRUE
See also
- linux/errno · macos/errno · windows/errno: Accessor for platform error-number storage.
- linux/posix · macos/posix: POSIX process, timing, descriptor, and context declarations.
- linux/runningTime · macos/runningTime · windows/runningTime: Elapsed-time helper built on platform timing APIs.
- sync/sync: Cross-platform scheduling, sleep, time, IPv4 formatting, and TCP helpers.
- linux/socket · macos/socket: Linux and macOS socket declarations, constants, address schemas, and imported functions.