Linux-specific operating system calls.

The linux unit contains linux specific operating system calls.

The platform independent functionality of the FPC 1.0.X version of the linux unit has been split out over the unix, baseunix and unixutil units.

The X86-specific parts have been moved to the X86 unit.

People wanting to use the old version (FPC 1.0.X and before) of the linux can use the oldlinux unit instead.

Record with system information, used by the call. Number of seconds since boot. 1, 5 and 15 minute load averages. total amount of main memory. amount of free memory. amount of shared memory. amount of memory used by buffers. total amount of swapspace. amount of free swapspace. number of current processes. ? Pointer to record. Return kernel system information

SysInfo returns system information in Info. Returned information in Info includes:

uptime
Number of seconds since boot.
loads
1, 5 and 15 minute load averages.
totalram
total amount of main memory.
freeram
amount of free memory.
sharedram
amount of shared memory.
bufferram
amount of memory used by buffers.
totalswap
total amount of swapspace.
freeswap
amount of free swapspace.
procs
number of current processes.
None.
option: Signal mask to be sent at exit option: VM shared between processes option: fs info shared between processes option: open files shared between processes option: signal handlers shared between processes option: PID shared between processes Clone function prototype. Clone current process (create new thread)

Clone creates a child process which is a copy of the parent process, just like FpFork does. In difference with Fork, however, the child process shares some parts of it's execution context with its parent, so it is suitable for the implementation of threads: many instances of a program that share the same memory.

When the child process is created, it starts executing the function Func, and passes it Args. The return value of Func is either the explicit return value of the function, or the exit code of the child process.

The sp pointer points to the memory reserved as stack space for the child process. This address should be the top of the memory block to be used as stack.

The Flags determine the behaviour of the Clone call. The low byte of the Flags contains the number of the signal that will be sent to the parent when the child dies. This may be bitwise OR'ed with the following constants:

CLONE_VM
Parent and child share the same memory space, including memory (un)mapped with subsequent mmap calls.
CLONE_FS
Parent and child have the same view of the filesystem; the chroot, chdir and umask calls affect both processes.
CLONE_FILES
the file descriptor table of parent and child is shared.
CLONE_SIGHAND
the parent and child share the same table of signal handlers. The signal masks are different, though.
CLONE_PID
PArent and child have the same process ID.

Clone returns the process ID in the parent process, and -1 if an error occurred.

On error, -1 is returned to the parent, and no child is created.

sys_eagain
Too many processes are running.
sys_enomem
Not enough memory to create child process.
Support for some basic C types event_wait input file descriptor ready event event_wait output file descriptor ready event event_wait high priority data available on input file descriptor event_wait error condition on file descriptor event_wait hang up event Set event_wait edge trigger behaviour on file descriptor Set single-shot behaviour on epoll_wait. Add filedescriptor to list of events Modify event for filedescriptor Delete event for filedescriptor IOCTL: Get font in expanded form. IOCTL: Use font in expanded form. IOCTL: Get font in consolefontdesc record. IOCTL: Set font in consolefontdesc record. IOCTL: Reset to default font IOCTL: Get colour palette on VGA+ IOCTL: Set colour palette on VGA+ IOCTL: start/stop sound generation (0 for off) IOCTL: generate tone IOCTL: return current led state IOCTL: set led state IOCTL: get keyboard type IOCTL: add i/o port as valid IOCTL: delete i/o port as valid IOCTL: enable i/o to video board IOCTL: disable i/o to video board IOCTL: set text/graphics mode IOCTL: get current mode IOCTL: map display into address space IOCTL: unmap display from address space IOCTL: get screen mapping from kernel IOCTL: put screen mapping table in kernel IOCTL: get full Unicode screen mapping IOCTL: set full Unicode screen mapping IOCTL: get unicode-to-font mapping from kernel IOCTL: put unicode-to-font mapping in kernel IOCTL: clear table, possibly advise hash algorithm IOCTL: read kernel accent table IOCTL: write kernel accent table IOCTL: read kernel keycode table entry IOCTL: write kernel keycode table entry IOCTL: accept kbd generated signals IOCTL: font operations IOCTL: Keyboard types: 84 keys IOCTL: Keyboard types: 101 keys IOCTL: Keyboard types: other type IOCTL: LED_SCR : scroll lock led IOCTL: LED_SCR : Num lock led IOCTL: LED_CAP : caps lock led IOCTL: Tty modes: Text mode IOCTL: Tty modes: graphics mode IOCTL: Tty modes: Text mode (obsolete) IOCTL: Tty modes: Text mode (obsolete) Epoll data call structure Data structure used in EPOLL IOCTL call. Pointer to data File descriptor Unsigned 32-bit integer Unsigned 64-bit integer Alias for EPoll_Data type Pointer to EPoll_Data record Structure used in epoll_ctl call. Events to monitor User data Alias for EPoll_Event type Pointer to EPoll_Event type Create new epoll file descriptor

epoll_create creates a new epoll file descriptor. The size argument indicates to the kernel approximately how many structures should be allocated, but is by no means an upper limit.

On success, a file descriptor is returned that can be used in subsequent or calls, and should be closed using the fpClose call.

On error, -1 is returned, and errno is set. fpClose
Modify an epoll file descriptor

epoll_ctl performs the op operation on epoll file descriptor epfd. The operation will be monitored on file descriptor fd, and is optionally controlled by event.

op can be one of the following values:

EPOLL_CTL_ADD
EPOLL_CTL_MOD
EPOLL_CTL_DEL

The events field in event_data is a bitmask of one or more of the following values:

EPOLLIN
The file is ready for read operations
EPOLLOUT
The file is ready for write operations.
EPOLLPRI
Urgent data is available for read operations.
EPOLLERR
An error condition is signaled on the file descriptor.
EPOLLHUP
A Hang up happened on the file descriptor.
EPOLLET
Set the Edge Triggered behaviour for the file descriptor.
EPOLLONESHOT
Set One-Shot behaviour for the file descriptor. The event will be triggered only once.
On error -1 is returned, and errno is set accordingly. fpClose
Wait for an event on an epoll file descriptor.

epoll_wait waits for timeout milliseconds for an event to occur on epoll file descriptor epfd. If timeout is -1, it waits indefinitely, if timeour is zero, it does not wait, but returns immediatly, even if no events were detected.

On return, data for at most maxevents will be returned in the memory pointed to by events. The function returns the number of file descriptors for which events were reported. This can be zero if the timeout was reached.

On error -1 is returned, and errno is set accordingly. fpClose
Clone options: if parent is traced, trace child also Clone options: suspend parent till child execs Clone options: Set child parent to parent of calling process. Clone options: Set child in thread group of calling process. Clone options: Start child in new (filesystem) namespace. Clone option: Caller and child share the same semaphore undo values Clone option: The newtls parameter is the TLS descriptor of the child Clone option: Store child thread ID in memory in both parent and child. Clone option: Erase child thread ID in child memory space when child exits. Clone option: Start clone detached. Clone option: Do not allow a ptrace call on this clone. Clone option: Store child thread ID in child memory. Clone option: Start child in stopped state. Futex option: Wait on futex till wake call arrives. Futex option: wakes any waiting processes on this futex Futex option: Associate file descriptor with futex. Futex option: requeue waiting processes on other futex. Futex option: requeue waiting processes on other futex, but check it's value first Futex option: Undocumented Futex option: Undocumented Futex option: Undocumented Futex option: Undocumented Futex operation: Undocumented Futex operation: Undocumented Futex operation: Undocumented Futex operation: Undocumented Futex operation: Undocumented Futex operation: Undocumented Futex operation: Undocumented Futex operation: Undocumented Futex operation: Undocumented Futex operation: Undocumented Futex operation: Undocumented Futex operation: Undocumented Futex operation:

FUTEX_OP Performs an operation on a futex:

FUTEX_OP := ((op and $F) shl 28) or  
            ((cmp and $F) shl 24) or 
            ((oparg and $FFF) shl 12) 
            or (cmparg and $FFF);
Modify_ldt option: Undocumented Modify_ldt option: Undocumented Modify_ldt option: Undocumented TLS segment descriptor : Undocumented TLS segment descriptor: Undocumented TLS segment descriptor: Undocumented TLS segment descriptor: Undocumented TLS segment descriptor: Undocumented TLS segment descriptor: Undocumented TLS segment descriptor: Undocumented TLS segment descriptor: Undocumented TLS segment descriptor: Undocumented TLS segment descriptor user_desc is the TLS (Thread Local Storage) segment descriptor used in the Clone call. It should not be used, as it contains highly kernel-specific data. TLS segment descriptor: Undocumented TLS segment descriptor: Undocumented TLS segment descriptor: Undocumented TLS segment descriptor: Undocumented Alias for user_desc record TUser_Desc is an alias for the type. Pointer to User_Desc record PUser_Desc is a pointer to the type. Alignment padding Total amount of high memory Total free amount of high memory in bytes Memory unit size in bytes Alignment adding Memory map grows down, like stack Read-only Memory area is marked as executable Memory pages are locked Do not check for reservations Pointer to user_cap_header record Root user capabilities header user_cap_header describes the root user capabilities for the current thread, as set by and Version of protocol Thread ID to apply/get capabilities from Pointer to user_cap_data record Capability description record user_cap_data describes the set of capabilities for the indicated thread. Capabilities effectively used by the kernel Limiting set of capabilities Capabilities that will be inherited across exec calls. Return the capabilities for the indicated thread

capget returns the capabilities of the indicated thread in header. The thread is identified by the process ID, or -1 for all caller (and child) process ID's.

Refer to the linux man pages (7 capabilities) for more info.

On success, zero is returned, on error -1 is returned, and fperrno is set to the error.
Set the capabilities for the indicated thread

capget sets the capabilities of the indicated thread in header. The thread is identified by the process ID, or -1 for all caller (and child) process ID's.

Refer to the linux man pages (7 capabilities) for more info.

On success, zero is returned, on error -1 is returned, and fperrno is set to the error.
Perform chown operation Bypass file operation (rwx) checks Bypass file read-only operation checks Bypass owner ID checks Do not clear SUID/GUID bits on modified files ? Bypass permission checks for sending signals Allow GID manipulations Allow process ID manipulations Allow to set other process' capabilities Allow setting ext2 file attributes Allow binding to ports less than 1024 Allow socket broadcast operations Allow network operations (e.g. setting socket options) Allow use of RAW and PACKET sockets Allow memory locking calls Bypass permission checks on IPC operations Allow loading/unloading of kernel modules Allow raw I/O port operations Allow chroot calls. Allow ptrace calls Allow acct calls Allow various system administration calls Allow reboot calls Allowing raising process and thread priorities Allow use of special resources or raising of resource limits Allow system or real-time clock modification Allow vhangup calls Allow creation of special files through mknod calls Allow file leases Allow writing to kernel audit log Allow manipulation of kernel auditing features Current capability version in use by kernel Move pages instead of copying Don't block on pipe splicing operations Expect more data Pages spliced in are a gift Unused in linux Undocumented linux extension of Poll Peer Shutdown/closed writing half of connection Wait for write-out of previously-submitted specified pages before writing more data. Initiate write of all dirty pages in the specified range. Wait upon write-out of specified pages in the range after performing any write. Force committing of data to disk

sync_file_range forces the linux kernel to write any data pages of a specified file (file descriptor fd) to disk. The range of the file is specified by the offset offset and the number of bytes nbytes. Options is an OR-ed combination of

SYNC_FILE_RANGE_WAIT_BEFORE
SYNC_FILE_RANGE_WRITE
SYNC_FILE_RANGE_WAIT_AFTER

If none is specified, the operation does nothing.

On return -1 is returned and fperrno is set to the actual error code. See the linux man page for more on the error codes.
Synchronize the data in memory with the data on storage device fdatasync does the same as fpfsync but does not flush the metadata, unless it is vital to the correct reading/writing of the file. In practice, this means that unless the file size changed, the file metadata will not be synced. Perform a futex operation

futex performs an operation on a memory futex as described in the kernel manual page for futex. The mutex is located at uaddr, the operation op is one of the following constants:

FUTEX_WAIT
FUTEX_WAKE
FUTEX_FD
FUTEX_REQUEUE
FUTEX_CMP_REQUEUE

The value to check for is indicated in val, and a timeout can be specified in timeout. The optional arguments addr2 and val3 are used only with the FUTEX_REQUEUE and FUTEX_CMP_REQUEUE operations.

In case of an error, -1 is return. All other return values must be interpreted according to the operation performed.

This call directly interfaces with the Linux kernel, more information can be found in the kernel manual pages.

On error, -1 is returned. Use to get the error code.
Yield the processor to another thread. sched_yield yields the processor to another thread. The current thread is put at the back of its queue. If there is only 1 thread in the application, the thread continues to run. The call always returns zero. Inotify close on exec flag. IN_CLOEXEC can be set to indicate that the inotify file handle must be closed on exec. Do not block on read IN_NONBLOCK can be set to indicate that the inotify file handle should not block read operations. INotify event structure

inotify_event is the structure used to report changes in a directory. When reading a inotify file descriptor, one or more inotify_event records can be read from the file descriptor.

Watch descriptor (as returned by inotify_add_watch) Event mask Cookie, used to pair move events Length of name Filename for which a change is reported Pointer to inotify_event structure. Data was read from file. Data was written to file. File attributes changed. File opened for write was closed File opened for read was closed File was opened File was moved away from watched directory File was moved into watched directory File was closed (read or write) File was moved (in or out of directory) A file was created in the directory. A file was deleted from the directory. Directory or file under observation was deleted. Directory or file under observation was moved. File system on which file resides was unmounted. Only reported. Queue overflowed. Only reported. Watch was ignored (removed). Only reported. Only watch filename if it is a directory. Do not follow symlinks Add events to existing watch (OR-ing the sets) if one exists. Event subject is a directory (reported only) Only report one event, then remove the watch. All possible events OR-ed together. Initialize a new inotify file descriptor inotify_init initializes a new INotify file descriptor. No options can be specified. On return, the file descriptor is returned. On Error, -1 is returned. fpgeterrno can be used to get more detailed error information Initialize a new inotify file descriptor with extra options.

inotify_init1 initializes a new INotify file descriptor. The following options can be OR-ed and passed in flags:

IN_NONBLOCK
IN_CLOEXEC
On Error, -1 is returned. fpgeterrno can be used to get more detailed error information.
Add a watch to a notify file descriptor

inotify_add_watch can be used to add a watch to an initialized inotify file descriptor (fd). The file or directory to watch can be specified in the name parameter, and the events that must be reported can be specified in mask. The following flags can be specified:

IN_ACCESS
Data was read from file.
IN_MODIFY
Data was written to file.
IN_ATTRIB
File attributes changed.
IN_CLOSE_WRITE
File opened for write was closed
IN_CLOSE_NOWRITE
File opened for read was closed
IN_CLOSE
File was closed (read or write)
IN_OPEN
File was opened
IN_MOVED_FROM
File was moved away from watched directory
IN_MOVED_TO
File was moved into watched directory
IN_MOVE
File was moved (in or out of directory)
IN_CREATE
A file was created in the directory.
IN_DELETE
A file was deleted from the directory.
IN_DELETE_SELF
Directory or file under observation was deleted.
IN_MOVE_SELF
Directory or file under observation was moved.
IN_ALL_EVENTS
All possible events OR-ed together.

These events can be OR-ed with some flags, controlling the behaviour of the watch:

IN_ONLYDIR
Only watch filename if it is a directory.
IN_ISDIR
Event occurred against directory.
IN_DONT_FOLLOW
Do not follow symlinks
IN_MASK_ADD
Add events to existing watch (OR-ing the sets) if one exists.
IN_ONESHOT
Only report one event, then remove the watch.

On return, the function returns a watch descriptor, which will be reported in the structure's wd.

On Error, -1 is returned. fpgeterrno can be used to get more detailed error information.
Remove watch from Inotify file descriptor. inotify_rm_watch removes watch descriptor wd from inotify descriptor fd. On success, 0 is returned. On Error, -1 is returned. fpgeterrno can be used to get more detailed error information. System wide real-time clock. Can only be set by root. Monotonic system time since some undetermined start point. Can change if time is set. Processs-specific high-resolution timer from the CPU. Thread-specific high-resolution timer from the CPU. Like CLOCK_MONOTONIC, not subject to NTP adjustments Less precise (but faster) version of CLOCK_REALTIME Less precise (but faster) version of CLOCK_MONOTONIC High resolution timer Maximum number of clocks in the system Mask for supported clocks Monotonic clocks mask Clock id type Get clock resolution clock_getres returns the resolution of the clock specified in clk_id in the res structure. It can be Nil. if the clock exists and the resolution can be retrieved, 0 is returned. On Error, -1 is returned. fpgeterrno can be used to get more detailed error information. Get the time of a clock clock_gettime returns the current time of the clock specified in clk_id in the tp structure. If the clock exists and the time can be retrieved, 0 is returned. On Error, -1 is returned. fpgeterrno can be used to get more detailed error information. Set the time of a clock clock_settime sets the current time of the clock specified in clk_id. The time is specified in the tp structure. If the clock exists and the time can be retrieved, 0 is returned. The resolution is truncated to the resolution supported by the specified clock. Note that not all clocks can be set. On Error, -1 is returned. fpgeterrno can be used to get more detailed error information.