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

NameValueMeaning
EPOLL_CTL_ADD1Adds a descriptor to the interest list.
EPOLL_CTL_DEL2Removes a descriptor from the interest list.
EPOLL_CTL_MOD3Modifies a descriptor in the interest list.

epoll event flags

NameValueMeaning
EPOLLERR0x008n32Error condition.
EPOLLHUP0x010n32Hang-up condition.
EPOLLIN0x001n32Readable condition.
EPOLLONESHOT0x40000000n32Disables the event after one delivery.
EPOLLOUT0x004n32Writable condition.

timerfd flags

NameValueMeaning
TFD_NONBLOCK2048Nonblocking timerfd flag.

flock operations

NameValueMeaning
LOCK_EX0x2Requests an exclusive lock.
LOCK_NB0x4Requests a nonblocking operation.
LOCK_SH0x1Requests a shared lock.
LOCK_UN0x8Releases a lock.

signalfd flags

NameValueMeaning
SFD_CLOEXEC0x80000Close-on-exec signalfd flag.
SFD_NONBLOCK0x800Nonblocking 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

FieldSchemaRole
eventsNat32readiness mask
ptrNatx Refevent data as an address
fdInt32 Refevent data as a descriptor
u32Nat32 Refevent data as a 32-bit value
u64Nat64 Refevent data as a 64-bit value
  • The views share storage and preserve the record's constness.
  • linux/architecture must point to x86_64, arm64, or i386 for the target CPU; it selects both EpollEvent and Ucontext.
  • tiny pull (2.2.0 or later) creates this link on x86_64 and arm64; i386 requires 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

FieldSchemaRole
ssi_signoNat32signal number
ssi_errnoInt32error number
ssi_codeInt32signal code
ssi_pidNat32identifier of the sending process
ssi_uidNat32real user identifier of the sending process
ssi_fdInt32file descriptor for SIGIO
ssi_tidNat32kernel timer identifier for POSIX timers
ssi_bandNat32band event for SIGIO
ssi_overrunNat32POSIX timer overrun count
ssi_trapnoNat32trap number that caused the signal
ssi_statusInt32exit status or signal for SIGCHLD
ssi_intInt32value passed with the signal, as an integer
ssi_ptrNat64value passed with the signal, as an address
ssi_utimeNat64user CPU time consumed for SIGCHLD
ssi_stimeNat64system CPU time consumed for SIGCHLD
ssi_addrNat64address that generated the signal
ssi_addr_lsbNat16least-significant address bit for SIGBUS
padding2Nat16padding
ssi_syscallInt32system-call number for SIGSYS
ssi_call_addrNat64address of the system-call instruction for SIGSYS
ssi_archNat32architecture of the system call for SIGSYS
paddingNat8 28 arraypadding

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: Int32 descriptor creation flags.

Outputs

  • result: Int32 new descriptor, or -1 on failure.

epoll_ctl

(event fd op epfd -- result) Adds, removes, or modifies a descriptor in an epoll interest list.

Inputs

  • event: epoll_event Ref caller-owned event record for the operation.
  • fd: Int32 descriptor to control.
  • op: Int32 epoll control operation.
  • epfd: Int32 epoll descriptor.

Outputs

  • result: Int32 0 on success, or -1 on failure.

epoll_wait

(timeout maxevents events epfd -- result) Waits for ready epoll events.

Inputs

  • timeout: Int32 wait timeout in milliseconds; -1 waits indefinitely, 0 returns immediately.
  • maxevents: Int32 capacity of events in epoll_event records.
  • events: Natx address of contiguous writable epoll_event records; the call fills them with ready events.
  • epfd: Int32 epoll descriptor.

Outputs

  • result: Int32 number of ready events, 0 on timeout, or -1 on failure.

flock

(op fd -- result) Applies a file-lock operation.

Inputs

  • op: Int32 lock operation flags.
  • fd: Int32 file descriptor to lock.

Outputs

  • result: Int32 0 on success, or -1 on failure.

signalfd

(flags mask fd -- result) Creates or updates a signal file descriptor.

Inputs

  • flags: Int32 descriptor creation flags.
  • mask: sigset_t Cref signal set to accept through the descriptor.
  • fd: Int32 descriptor to update, or -1 to create one.

Outputs

  • result: Int32 new or updated descriptor, or -1 on failure.

statx

(statxbuf mask flags path dirfd -- result) Retrieves information about a file.

Inputs

  • statxbuf: Natx address of caller-owned writable 256-byte storage that receives the file information.
  • mask: Nat32 mask of the requested fields.
  • flags: Int32 path-resolution and synchronization flags.
  • path: Natx address of a zero-terminated path string.
  • dirfd: Int32 directory descriptor used to resolve a relative path.

Outputs

  • result: Int32 0 on success, or -1 on failure.

timerfd_create

(flags clockid -- result) Creates a timer file descriptor.

Inputs

  • flags: Int32 timerfd creation flags.
  • clockid: Int32 clock identifier.

Outputs

  • result: Int32 new descriptor, or -1 on failure.

timerfd_settime

(old_value new_value flags fd -- result) Sets a timerfd expiration and interval.

Inputs

  • old_value: itimerspec Ref caller-owned writable storage that receives the previous timer setting, or a typed NIL itimerspec Ref when the previous setting is not needed.
  • new_value: itimerspec Cref borrowed timer setting to apply.
  • flags: Int32 timer-setting flags.
  • fd: Int32 timerfd descriptor.

Outputs

  • result: Int32 0 on success, or -1 on 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