Linux declarations for epoll polling, timerfd timers, and advisory file locking with flock.

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.

Constant example

"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

Imported functions

Stack effects list a C function's parameters with the first parameter on top; see importFunction.

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.

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

Signature examples

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

epoll descriptor creation

"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

Timer descriptor creation

"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