Module rsyscall.sys.eventfd

#include <sys/eventfd.h>

Expand source code Browse git
"`#include <sys/eventfd.h>`"
from __future__ import annotations
from rsyscall._raw import lib # type: ignore
from rsyscall.near.sysif import SyscallInterface
from rsyscall.sys.syscall import SYS
import enum
import rsyscall.near.types as near
import typing as t
from rsyscall.handle.fd import BaseFileDescriptor, FileDescriptorTask

__all__ = [
    "EFD",
    "EventFileDescriptor",
    "EventfdTask",
]

class EFD(enum.IntFlag):
    NONE = 0
    CLOEXEC = lib.EFD_CLOEXEC
    NONBLOCK = lib.EFD_NONBLOCK
    SEMAPHORE = lib.EFD_SEMAPHORE

async def _eventfd(sysif: SyscallInterface, initval: int, flags: EFD) -> near.FileDescriptor:
    "The raw, near, eventfd syscall."
    return near.FileDescriptor(await sysif.syscall(SYS.eventfd2, initval, flags))

T_fd = t.TypeVar('T_fd', bound='EventFileDescriptor')
class EventFileDescriptor(BaseFileDescriptor):
    pass

class EventfdTask(FileDescriptorTask[T_fd]):
    async def eventfd(self, initval: int, flags: EFD=EFD.NONE) -> T_fd:
        return self.make_fd_handle(await _eventfd(self.sysif, initval, flags|EFD.CLOEXEC))

Classes

class EFD (value, names=None, *, module=None, qualname=None, type=None, start=1)

An enumeration.

Expand source code Browse git
class EFD(enum.IntFlag):
    NONE = 0
    CLOEXEC = lib.EFD_CLOEXEC
    NONBLOCK = lib.EFD_NONBLOCK
    SEMAPHORE = lib.EFD_SEMAPHORE

Ancestors

  • enum.IntFlag
  • builtins.int
  • enum.Flag
  • enum.Enum

Class variables

var NONE
var CLOEXEC
var NONBLOCK
var SEMAPHORE
class EventFileDescriptor (task: FileDescriptorTask, near: FileDescriptor, valid: bool)

A file descriptor accessed through some Task

This is an rsyscall-internal base class, which other FileDescriptor objects inherit from for core lifecycle methods. See FileDescriptor for more information.

Expand source code Browse git
class EventFileDescriptor(BaseFileDescriptor):
    pass

Ancestors

Subclasses

Inherited members

class EventfdTask (sysif: SyscallInterface, near_process: Process, fd_table: FDTable, address_space: AddressSpace, pidns: PidNamespace)

A wrapper around SyscallInterface which tracks the namespaces of the underlying process

Note that this is a base class for the more fully featured Task.

We store namespace objects to represent the namespaces that we believe that underlying processes is in. Since we have complete control over the process, we can make sure this belief is accurate, by updating our stored namespaces when the process changes namespace. That isn't done here; it's done in handle.Task.

Currently, we store only one PidNamespace. But each process actually has two pid namespaces:

  • the process's own pid namespace, which determines the pids returned from getpid, clone, and other syscalls.
  • the pid namespace that new children will be in.

The two pid namespaces only differ if we call unshare(CLONE.NEWPID). Currently we don't do that because unshare(CLONE.NEWPID) makes monitoring children more complex, since they can be deleted without leaving a zombie at any time if the pid namespace shuts down. But if we did call unshare(CLONE.NEWPID), we'd need to handle this right.

In the analogy to near and far pointers, this is like a segment register, if a segment register was write-only. Then we'd need to maintain the knowledge of what the segment register was set to, outside the segment register itself. That's what we do here.

There actually were systems where segment registers were, if not quite write-only, at least expensive to set and expensive to read. For example, x86_64 - the FS and GS segment registers can only be set via syscall. If you wanted to use segmentation on such systems, you'd probably have a structure much like this one.

Expand source code Browse git
class EventfdTask(FileDescriptorTask[T_fd]):
    async def eventfd(self, initval: int, flags: EFD=EFD.NONE) -> T_fd:
        return self.make_fd_handle(await _eventfd(self.sysif, initval, flags|EFD.CLOEXEC))

Ancestors

Subclasses

Class variables

var sysifSyscallInterface
var near_processProcess
var fd_tableFDTable
var address_spaceAddressSpace
var pidnsPidNamespace

Methods

async def eventfd(self, initval: int, flags: EFD = EFD.NONE) ‑> ~T_fd
Expand source code Browse git
async def eventfd(self, initval: int, flags: EFD=EFD.NONE) -> T_fd:
    return self.make_fd_handle(await _eventfd(self.sysif, initval, flags|EFD.CLOEXEC))

Inherited members