From 80eeb4dd2196121be803aac1f3bf2bb0ef77f3e8 Mon Sep 17 00:00:00 2001 From: Christopher Milan Date: Tue, 2 Jun 2026 16:59:36 -0700 Subject: [PATCH] mockgpu: use autogen.libc (#16479) --- test/mockgpu/am/amgpu.py | 11 +-- test/mockgpu/amd/amddriver.py | 7 +- test/mockgpu/mockgpu.py | 8 +- test/mockgpu/nv/nvdriver.py | 11 +-- tinygrad/runtime/autogen/__init__.py | 7 +- tinygrad/runtime/autogen/libc.py | 142 ++++++++++++++++++++++++++- 6 files changed, 152 insertions(+), 34 deletions(-) diff --git a/test/mockgpu/am/amgpu.py b/test/mockgpu/am/amgpu.py index 88fd4b25bd..634fea3dae 100644 --- a/test/mockgpu/am/amgpu.py +++ b/test/mockgpu/am/amgpu.py @@ -1,14 +1,11 @@ # mypy: ignore-errors from __future__ import annotations -import ctypes, ctypes.util, struct, functools, os, mmap +import ctypes, struct, functools, os, mmap from tinygrad.runtime.autogen.am import am +from tinygrad.runtime.autogen import libc from tinygrad.runtime.support.amd import AMDReg, import_asic_regs from test.mockgpu.amd.amdgpu import AMDGPU -libc = ctypes.CDLL(ctypes.util.find_library("c")) -libc.mmap.argtypes = [ctypes.c_void_p, ctypes.c_size_t, ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_long] -libc.mmap.restype = ctypes.c_void_p - VRAM_SIZE = 512 << 20 IP_VERSIONS = { @@ -263,11 +260,11 @@ class MockMMIOInterface: class MockAMGPU(AMDGPU): def __init__(self, gpuid:int=0): super().__init__(gpuid) - self.vram_fd = os.memfd_create("vram") + self.vram_fd = libc.memfd_create(b"vram", libc.MFD_CLOEXEC) os.ftruncate(self.vram_fd, VRAM_SIZE) self.vram_addr = libc.mmap(0, VRAM_SIZE, mmap.PROT_READ | mmap.PROT_WRITE, mmap.MAP_SHARED, self.vram_fd, 0) self.vram = (ctypes.c_ubyte * VRAM_SIZE).from_address(self.vram_addr) - self.doorbell_fd = os.memfd_create("doorbell") + self.doorbell_fd = libc.memfd_create(b"doorbell", libc.MFD_CLOEXEC) os.ftruncate(self.doorbell_fd, 0x2000) self.arch = "rdna4" self._sysmem_map:dict[int,int] = {} diff --git a/test/mockgpu/amd/amddriver.py b/test/mockgpu/amd/amddriver.py index d58a9f4a3e..6d619bff6b 100644 --- a/test/mockgpu/amd/amddriver.py +++ b/test/mockgpu/amd/amddriver.py @@ -1,15 +1,10 @@ import pathlib, re, ctypes, mmap, collections, functools, copy, os -import tinygrad.runtime.autogen.kfd as kfd +from tinygrad.runtime.autogen import kfd, amdgpu_drm, libc import tinygrad.runtime.autogen.am.am as am -import tinygrad.runtime.autogen.amdgpu_drm as amdgpu_drm from tinygrad.helpers import from_mv from test.mockgpu.driver import VirtDriver, VirtFileDesc, TextFileDesc, DirFileDesc, VirtFile from test.mockgpu.amd.amdgpu import AMDGPU, gpu_props, GFX_TARGET_VERSION, MOCKGPU_ARCH -libc = ctypes.CDLL(ctypes.util.find_library("c")) -libc.mmap.argtypes = [ctypes.c_void_p, ctypes.c_size_t, ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_long] -libc.mmap.restype = ctypes.c_void_p - def ioctls_from_header(): # hdrpy = (pathlib.Path(__file__).parent.parent.parent.parent / "tinygrad" / "runtime" / "autogen" / "kfd.py").read_text() # pattern = r'# (AMDKFD_IOC_[A-Z0-9_]+)\s=\s_(IOW?R?).*\(( 0x[0-9a-fA-F]+) ,\s+struct\s([A-Za-z0-9_]+)\s+\)' diff --git a/test/mockgpu/mockgpu.py b/test/mockgpu/mockgpu.py index 03c17ad3b8..703b1932d3 100644 --- a/test/mockgpu/mockgpu.py +++ b/test/mockgpu/mockgpu.py @@ -1,16 +1,12 @@ -import ctypes, ctypes.util, time, os, builtins, fcntl +import ctypes, time, os, builtins, fcntl from tinygrad.helpers import DEV from tinygrad.runtime.support.hcq import FileIOInterface +from tinygrad.runtime.autogen import libc from test.mockgpu.nv.nvdriver import NVDriver from test.mockgpu.amd.amddriver import AMDDriver from test.mockgpu.am.amdriver import AMDriver, AMUSBDriver start = time.perf_counter() -# *** ioctl lib *** -libc = ctypes.CDLL(ctypes.util.find_library("c")) -libc.mmap.argtypes = [ctypes.c_void_p, ctypes.c_size_t, ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_long] -libc.mmap.restype = ctypes.c_void_p - drivers = [cls() for t in DEV.value if (cls:={"MOCKPCI+AMD": AMDriver, "MOCKKFD+AMD": AMDDriver, "MOCK+AMD": AMDDriver, "MOCKUSB+AMD": AMUSBDriver, "MOCK+NV": NVDriver}.get(f"{t.interface}+{t.device}"))] tracked_fds = {} diff --git a/test/mockgpu/nv/nvdriver.py b/test/mockgpu/nv/nvdriver.py index d89229db98..d0f9d945ec 100644 --- a/test/mockgpu/nv/nvdriver.py +++ b/test/mockgpu/nv/nvdriver.py @@ -1,17 +1,10 @@ import ctypes, mmap, collections, functools, os -from tinygrad.runtime.autogen import nv_570 as nv_gpu +from tinygrad.runtime.autogen import nv_570 as nv_gpu, libc from typing import cast, Any from tinygrad.helpers import to_mv from test.mockgpu.driver import VirtDriver, VirtFileDesc, VirtFile from test.mockgpu.nv.nvgpu import NVGPU -MAP_FIXED = 0x10 -libc = ctypes.CDLL(ctypes.util.find_library("c")) -libc.mmap.argtypes = [ctypes.c_void_p, ctypes.c_size_t, ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_long] -libc.mmap.restype = ctypes.c_void_p -libc.munmap.argtypes = [ctypes.c_void_p, ctypes.c_size_t] -libc.munmap.restype = ctypes.c_int - NVSubDevice = collections.namedtuple('NVSubDevice', ['device']) NVUserMode = collections.namedtuple('NVUserMode', ['subdevice']) NVVASpace = collections.namedtuple('NVVASpace', ['device']) @@ -258,7 +251,7 @@ class NVDriver(VirtDriver): elif nr == nv_gpu.UVM_ENABLE_PEER_ACCESS: pass # uvm and shared spaced are setup already, no emulation for now elif nr == nv_gpu.UVM_CREATE_EXTERNAL_RANGE: st = nv_gpu.UVM_CREATE_EXTERNAL_RANGE_PARAMS.from_address(argp) - libc.mmap(st.base, st.length, mmap.PROT_READ|mmap.PROT_WRITE, MAP_FIXED|mmap.MAP_SHARED|mmap.MAP_ANONYMOUS, -1, 0) + libc.mmap(st.base, st.length, mmap.PROT_READ|mmap.PROT_WRITE, libc.MAP_FIXED|mmap.MAP_SHARED|mmap.MAP_ANONYMOUS, -1, 0) elif nr == nv_gpu.UVM_MAP_EXTERNAL_ALLOCATION: st = nv_gpu.UVM_MAP_EXTERNAL_ALLOCATION_PARAMS.from_address(argp) for gpu_attr_id in range(st.gpuAttributesCount): diff --git a/tinygrad/runtime/autogen/__init__.py b/tinygrad/runtime/autogen/__init__.py index eb4b61c846..bed7583582 100644 --- a/tinygrad/runtime/autogen/__init__.py +++ b/tinygrad/runtime/autogen/__init__.py @@ -49,9 +49,10 @@ def load(name, files, **kwargs): def __getattr__(nm): match nm: - case "libc": return load("libc", lambda: ( - [i for i in system("dpkg -L libc6-dev").split() if 'sys/mman.h' in i or 'sys/syscall.h' in i] + - ["/usr/include/string.h", "/usr/include/elf.h", "/usr/include/unistd.h", "/usr/include/asm-generic/mman-common.h"]), dll="'c'", errno=True) + case "libc": + return load("libc", lambda: ([i for i in system("dpkg -L libc6-dev").split() if 'sys/mman.h' in i or 'bits/mman-shared.h' in i] + + ["/usr/include/string.h", "/usr/include/elf.h", "/usr/include/unistd.h", "/usr/include/asm-generic/mman-common.h"]), + args=["-D__USE_GNU", "-D_GNU_SOURCE"], dll="'c'", errno=True, recsym=True) case "avcodec": return load("avcodec", ["{}/libavcodec/hevc/hevc.h", "{}/libavcodec/cbs_h265.h"], srcs=ffmpeg_src) case "opencl": return load("opencl", ["{}/CL/cl.h"], dll="'OpenCL'", args=["-I{}"], srcs=opencl_src) case "cuda": return load("cuda", ["{}/include/cuda.h"], dll="'nvcuda' if WIN else 'cuda'", args=["-D__CUDA_API_VERSION_INTERNAL"], srcs=cudart_src, macros=False, prolog=["from tinygrad.helpers import WIN"]) diff --git a/tinygrad/runtime/autogen/libc.py b/tinygrad/runtime/autogen/libc.py index 3ee4feba08..fd674793c9 100644 --- a/tinygrad/runtime/autogen/libc.py +++ b/tinygrad/runtime/autogen/libc.py @@ -7,10 +7,27 @@ from tinygrad.runtime.support import c dll = c.DLL('libc', 'c', use_errno=True) off_t: TypeAlias = ctypes.c_int64 mode_t: TypeAlias = ctypes.c_uint32 +@dll.bind(ctypes.c_int32, c.POINTER[ctypes.c_char], ctypes.c_uint32) +def memfd_create(__name:c.POINTER[ctypes.c_char], __flags:int) -> int: ... size_t: TypeAlias = ctypes.c_uint64 +@dll.bind(ctypes.c_int32, ctypes.c_void_p, size_t, ctypes.c_uint32) +def mlock2(__addr:ctypes.c_void_p, __length:size_t, __flags:int) -> int: ... +@dll.bind(ctypes.c_int32, ctypes.c_uint32, ctypes.c_uint32) +def pkey_alloc(__flags:int, __access_rights:int) -> int: ... +@dll.bind(ctypes.c_int32, ctypes.c_int32, ctypes.c_uint32) +def pkey_set(__key:int, __access_rights:int) -> int: ... +@dll.bind(ctypes.c_int32, ctypes.c_int32) +def pkey_get(__key:int) -> int: ... +@dll.bind(ctypes.c_int32, ctypes.c_int32) +def pkey_free(__key:int) -> int: ... +@dll.bind(ctypes.c_int32, ctypes.c_void_p, size_t, ctypes.c_int32, ctypes.c_int32) +def pkey_mprotect(__addr:ctypes.c_void_p, __len:size_t, __prot:int, __pkey:int) -> int: ... __off_t: TypeAlias = ctypes.c_int64 @dll.bind(ctypes.c_void_p, ctypes.c_void_p, size_t, ctypes.c_int32, ctypes.c_int32, ctypes.c_int32, ctypes.c_int64) def mmap(__addr:ctypes.c_void_p, __len:size_t, __prot:int, __flags:int, __fd:int, __offset:ctypes.c_int64) -> ctypes.c_void_p: ... +__off64_t: TypeAlias = ctypes.c_int64 +@dll.bind(ctypes.c_void_p, ctypes.c_void_p, size_t, ctypes.c_int32, ctypes.c_int32, ctypes.c_int32, ctypes.c_int64) +def mmap64(__addr:ctypes.c_void_p, __len:size_t, __prot:int, __flags:int, __fd:int, __offset:ctypes.c_int64) -> ctypes.c_void_p: ... @dll.bind(ctypes.c_int32, ctypes.c_void_p, size_t) def munmap(__addr:ctypes.c_void_p, __len:size_t) -> int: ... @dll.bind(ctypes.c_int32, ctypes.c_void_p, size_t, ctypes.c_int32) @@ -31,10 +48,20 @@ def mlockall(__flags:int) -> int: ... def munlockall() -> int: ... @dll.bind(ctypes.c_int32, ctypes.c_void_p, size_t, c.POINTER[ctypes.c_ubyte]) def mincore(__start:ctypes.c_void_p, __len:size_t, __vec:c.POINTER[ctypes.c_ubyte]) -> int: ... +@dll.bind(ctypes.c_void_p, ctypes.c_void_p, size_t, size_t, ctypes.c_int32) +def mremap(__addr:ctypes.c_void_p, __old_len:size_t, __new_len:size_t, __flags:int) -> ctypes.c_void_p: ... +@dll.bind(ctypes.c_int32, ctypes.c_void_p, size_t, ctypes.c_int32, size_t, ctypes.c_int32) +def remap_file_pages(__start:ctypes.c_void_p, __size:size_t, __prot:int, __pgoff:size_t, __flags:int) -> int: ... @dll.bind(ctypes.c_int32, c.POINTER[ctypes.c_char], ctypes.c_int32, mode_t) def shm_open(__name:c.POINTER[ctypes.c_char], __oflag:int, __mode:mode_t) -> int: ... @dll.bind(ctypes.c_int32, c.POINTER[ctypes.c_char]) def shm_unlink(__name:c.POINTER[ctypes.c_char]) -> int: ... +__ssize_t: TypeAlias = ctypes.c_int64 +class struct_iovec(c.Struct): pass +@dll.bind(ctypes.c_int64, ctypes.c_int32, c.POINTER[struct_iovec], size_t, ctypes.c_int32, ctypes.c_uint32) +def process_madvise(__pid_fd:int, __iov:c.POINTER[struct_iovec], __count:size_t, __advice:int, __flags:int) -> ctypes.c_int64: ... +@dll.bind(ctypes.c_int32, ctypes.c_int32, ctypes.c_uint32) +def process_mrelease(pidfd:int, flags:int) -> int: ... @dll.bind(ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, size_t) def memcpy(__dest:ctypes.c_void_p, __src:ctypes.c_void_p, __n:size_t) -> ctypes.c_void_p: ... @dll.bind(ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, size_t) @@ -49,6 +76,10 @@ def memcmp(__s1:ctypes.c_void_p, __s2:ctypes.c_void_p, __n:size_t) -> int: ... def __memcmpeq(__s1:ctypes.c_void_p, __s2:ctypes.c_void_p, __n:size_t) -> int: ... @dll.bind(ctypes.c_void_p, ctypes.c_void_p, ctypes.c_int32, size_t) def memchr(__s:ctypes.c_void_p, __c:int, __n:size_t) -> ctypes.c_void_p: ... +@dll.bind(ctypes.c_void_p, ctypes.c_void_p, ctypes.c_int32) +def rawmemchr(__s:ctypes.c_void_p, __c:int) -> ctypes.c_void_p: ... +@dll.bind(ctypes.c_void_p, ctypes.c_void_p, ctypes.c_int32, size_t) +def memrchr(__s:ctypes.c_void_p, __c:int, __n:size_t) -> ctypes.c_void_p: ... @dll.bind(c.POINTER[ctypes.c_char], c.POINTER[ctypes.c_char], c.POINTER[ctypes.c_char]) def strcpy(__dest:c.POINTER[ctypes.c_char], __src:c.POINTER[ctypes.c_char]) -> c.POINTER[ctypes.c_char]: ... @dll.bind(c.POINTER[ctypes.c_char], c.POINTER[ctypes.c_char], c.POINTER[ctypes.c_char], size_t) @@ -118,16 +149,48 @@ def strlen(__s:c.POINTER[ctypes.c_char]) -> int: ... def strnlen(__string:c.POINTER[ctypes.c_char], __maxlen:size_t) -> size_t: ... @dll.bind(c.POINTER[ctypes.c_char], ctypes.c_int32) def strerror(__errnum:int) -> c.POINTER[ctypes.c_char]: ... -@dll.bind(ctypes.c_int32, ctypes.c_int32, c.POINTER[ctypes.c_char], size_t) -def strerror_r(__errnum:int, __buf:c.POINTER[ctypes.c_char], __buflen:size_t) -> int: ... +@dll.bind(c.POINTER[ctypes.c_char], ctypes.c_int32, c.POINTER[ctypes.c_char], size_t) +def strerror_r(__errnum:int, __buf:c.POINTER[ctypes.c_char], __buflen:size_t) -> c.POINTER[ctypes.c_char]: ... +@dll.bind(c.POINTER[ctypes.c_char], ctypes.c_int32) +def strerrordesc_np(__err:int) -> c.POINTER[ctypes.c_char]: ... +@dll.bind(c.POINTER[ctypes.c_char], ctypes.c_int32) +def strerrorname_np(__err:int) -> c.POINTER[ctypes.c_char]: ... @dll.bind(c.POINTER[ctypes.c_char], ctypes.c_int32, locale_t) def strerror_l(__errnum:int, __l:locale_t) -> c.POINTER[ctypes.c_char]: ... +@dll.bind(ctypes.c_int32, ctypes.c_void_p, ctypes.c_void_p, size_t) +def bcmp(__s1:ctypes.c_void_p, __s2:ctypes.c_void_p, __n:size_t) -> int: ... +@dll.bind(None, ctypes.c_void_p, ctypes.c_void_p, size_t) +def bcopy(__src:ctypes.c_void_p, __dest:ctypes.c_void_p, __n:size_t) -> None: ... +@dll.bind(None, ctypes.c_void_p, size_t) +def bzero(__s:ctypes.c_void_p, __n:size_t) -> None: ... +@dll.bind(c.POINTER[ctypes.c_char], c.POINTER[ctypes.c_char], ctypes.c_int32) +def index(__s:c.POINTER[ctypes.c_char], __c:int) -> c.POINTER[ctypes.c_char]: ... +@dll.bind(c.POINTER[ctypes.c_char], c.POINTER[ctypes.c_char], ctypes.c_int32) +def rindex(__s:c.POINTER[ctypes.c_char], __c:int) -> c.POINTER[ctypes.c_char]: ... +@dll.bind(ctypes.c_int32, ctypes.c_int32) +def ffs(__i:int) -> int: ... +@dll.bind(ctypes.c_int32, ctypes.c_int64) +def ffsl(__l:int) -> int: ... +@dll.bind(ctypes.c_int32, ctypes.c_int64) +def ffsll(__ll:int) -> int: ... +@dll.bind(ctypes.c_int32, c.POINTER[ctypes.c_char], c.POINTER[ctypes.c_char]) +def strcasecmp(__s1:c.POINTER[ctypes.c_char], __s2:c.POINTER[ctypes.c_char]) -> int: ... +@dll.bind(ctypes.c_int32, c.POINTER[ctypes.c_char], c.POINTER[ctypes.c_char], size_t) +def strncasecmp(__s1:c.POINTER[ctypes.c_char], __s2:c.POINTER[ctypes.c_char], __n:size_t) -> int: ... +@dll.bind(ctypes.c_int32, c.POINTER[ctypes.c_char], c.POINTER[ctypes.c_char], locale_t) +def strcasecmp_l(__s1:c.POINTER[ctypes.c_char], __s2:c.POINTER[ctypes.c_char], __loc:locale_t) -> int: ... +@dll.bind(ctypes.c_int32, c.POINTER[ctypes.c_char], c.POINTER[ctypes.c_char], size_t, locale_t) +def strncasecmp_l(__s1:c.POINTER[ctypes.c_char], __s2:c.POINTER[ctypes.c_char], __n:size_t, __loc:locale_t) -> int: ... @dll.bind(None, ctypes.c_void_p, size_t) def explicit_bzero(__s:ctypes.c_void_p, __n:size_t) -> None: ... @dll.bind(c.POINTER[ctypes.c_char], c.POINTER[c.POINTER[ctypes.c_char]], c.POINTER[ctypes.c_char]) def strsep(__stringp:c.POINTER[c.POINTER[ctypes.c_char]], __delim:c.POINTER[ctypes.c_char]) -> c.POINTER[ctypes.c_char]: ... @dll.bind(c.POINTER[ctypes.c_char], ctypes.c_int32) def strsignal(__sig:int) -> c.POINTER[ctypes.c_char]: ... +@dll.bind(c.POINTER[ctypes.c_char], ctypes.c_int32) +def sigabbrev_np(__sig:int) -> c.POINTER[ctypes.c_char]: ... +@dll.bind(c.POINTER[ctypes.c_char], ctypes.c_int32) +def sigdescr_np(__sig:int) -> c.POINTER[ctypes.c_char]: ... @dll.bind(c.POINTER[ctypes.c_char], c.POINTER[ctypes.c_char], c.POINTER[ctypes.c_char]) def __stpcpy(__dest:c.POINTER[ctypes.c_char], __src:c.POINTER[ctypes.c_char]) -> c.POINTER[ctypes.c_char]: ... @dll.bind(c.POINTER[ctypes.c_char], c.POINTER[ctypes.c_char], c.POINTER[ctypes.c_char]) @@ -140,6 +203,14 @@ def stpncpy(__dest:c.POINTER[ctypes.c_char], __src:c.POINTER[ctypes.c_char], __n def strlcpy(__dest:c.POINTER[ctypes.c_char], __src:c.POINTER[ctypes.c_char], __n:size_t) -> size_t: ... @dll.bind(size_t, c.POINTER[ctypes.c_char], c.POINTER[ctypes.c_char], size_t) def strlcat(__dest:c.POINTER[ctypes.c_char], __src:c.POINTER[ctypes.c_char], __n:size_t) -> size_t: ... +@dll.bind(ctypes.c_int32, c.POINTER[ctypes.c_char], c.POINTER[ctypes.c_char]) +def strverscmp(__s1:c.POINTER[ctypes.c_char], __s2:c.POINTER[ctypes.c_char]) -> int: ... +@dll.bind(c.POINTER[ctypes.c_char], c.POINTER[ctypes.c_char]) +def strfry(__string:c.POINTER[ctypes.c_char]) -> c.POINTER[ctypes.c_char]: ... +@dll.bind(ctypes.c_void_p, ctypes.c_void_p, size_t) +def memfrob(__s:ctypes.c_void_p, __n:size_t) -> ctypes.c_void_p: ... +@dll.bind(c.POINTER[ctypes.c_char], c.POINTER[ctypes.c_char]) +def basename(__filename:c.POINTER[ctypes.c_char]) -> c.POINTER[ctypes.c_char]: ... Elf32_Half: TypeAlias = ctypes.c_uint16 Elf64_Half: TypeAlias = ctypes.c_uint16 Elf32_Word: TypeAlias = ctypes.c_uint32 @@ -548,16 +619,25 @@ _anonenum0: dict[int, str] = {(Val_GNU_MIPS_ABI_FP_ANY:=0): 'Val_GNU_MIPS_ABI_FP ssize_t: TypeAlias = ctypes.c_int64 gid_t: TypeAlias = ctypes.c_uint32 uid_t: TypeAlias = ctypes.c_uint32 +off64_t: TypeAlias = ctypes.c_int64 useconds_t: TypeAlias = ctypes.c_uint32 pid_t: TypeAlias = ctypes.c_int32 intptr_t: TypeAlias = ctypes.c_int64 socklen_t: TypeAlias = ctypes.c_uint32 @dll.bind(ctypes.c_int32, c.POINTER[ctypes.c_char], ctypes.c_int32) def access(__name:c.POINTER[ctypes.c_char], __type:int) -> int: ... +@dll.bind(ctypes.c_int32, c.POINTER[ctypes.c_char], ctypes.c_int32) +def euidaccess(__name:c.POINTER[ctypes.c_char], __type:int) -> int: ... +@dll.bind(ctypes.c_int32, c.POINTER[ctypes.c_char], ctypes.c_int32) +def eaccess(__name:c.POINTER[ctypes.c_char], __type:int) -> int: ... +@dll.bind(ctypes.c_int32, ctypes.c_int32, c.POINTER[ctypes.c_char], c.Array[c.POINTER[ctypes.c_char], Literal[0]], c.Array[c.POINTER[ctypes.c_char], Literal[0]], ctypes.c_int32) +def execveat(__fd:int, __path:c.POINTER[ctypes.c_char], __argv:c.Array[c.POINTER[ctypes.c_char], Literal[0]], __envp:c.Array[c.POINTER[ctypes.c_char], Literal[0]], __flags:int) -> int: ... @dll.bind(ctypes.c_int32, ctypes.c_int32, c.POINTER[ctypes.c_char], ctypes.c_int32, ctypes.c_int32) def faccessat(__fd:int, __file:c.POINTER[ctypes.c_char], __type:int, __flag:int) -> int: ... @dll.bind(ctypes.c_int64, ctypes.c_int32, ctypes.c_int64, ctypes.c_int32) def lseek(__fd:int, __offset:ctypes.c_int64, __whence:int) -> ctypes.c_int64: ... +@dll.bind(ctypes.c_int64, ctypes.c_int32, ctypes.c_int64, ctypes.c_int32) +def lseek64(__fd:int, __offset:ctypes.c_int64, __whence:int) -> ctypes.c_int64: ... @dll.bind(ctypes.c_int32, ctypes.c_int32) def close(__fd:int) -> int: ... @dll.bind(None, ctypes.c_int32) @@ -570,8 +650,14 @@ def write(__fd:int, __buf:ctypes.c_void_p, __n:size_t) -> ssize_t: ... def pread(__fd:int, __buf:ctypes.c_void_p, __nbytes:size_t, __offset:ctypes.c_int64) -> ssize_t: ... @dll.bind(ssize_t, ctypes.c_int32, ctypes.c_void_p, size_t, ctypes.c_int64) def pwrite(__fd:int, __buf:ctypes.c_void_p, __n:size_t, __offset:ctypes.c_int64) -> ssize_t: ... +@dll.bind(ssize_t, ctypes.c_int32, ctypes.c_void_p, size_t, ctypes.c_int64) +def pread64(__fd:int, __buf:ctypes.c_void_p, __nbytes:size_t, __offset:ctypes.c_int64) -> ssize_t: ... +@dll.bind(ssize_t, ctypes.c_int32, ctypes.c_void_p, size_t, ctypes.c_int64) +def pwrite64(__fd:int, __buf:ctypes.c_void_p, __n:size_t, __offset:ctypes.c_int64) -> ssize_t: ... @dll.bind(ctypes.c_int32, c.Array[ctypes.c_int32, Literal[2]]) def pipe(__pipedes:c.Array[ctypes.c_int32, Literal[2]]) -> int: ... +@dll.bind(ctypes.c_int32, c.Array[ctypes.c_int32, Literal[2]], ctypes.c_int32) +def pipe2(__pipedes:c.Array[ctypes.c_int32, Literal[2]], __flags:int) -> int: ... @dll.bind(ctypes.c_uint32, ctypes.c_uint32) def alarm(__seconds:int) -> int: ... @dll.bind(ctypes.c_uint32, ctypes.c_uint32) @@ -599,14 +685,20 @@ def chdir(__path:c.POINTER[ctypes.c_char]) -> int: ... def fchdir(__fd:int) -> int: ... @dll.bind(c.POINTER[ctypes.c_char], c.POINTER[ctypes.c_char], size_t) def getcwd(__buf:c.POINTER[ctypes.c_char], __size:size_t) -> c.POINTER[ctypes.c_char]: ... +@dll.bind(c.POINTER[ctypes.c_char]) +def get_current_dir_name() -> c.POINTER[ctypes.c_char]: ... @dll.bind(c.POINTER[ctypes.c_char], c.POINTER[ctypes.c_char]) def getwd(__buf:c.POINTER[ctypes.c_char]) -> c.POINTER[ctypes.c_char]: ... @dll.bind(ctypes.c_int32, ctypes.c_int32) def dup(__fd:int) -> int: ... @dll.bind(ctypes.c_int32, ctypes.c_int32, ctypes.c_int32) def dup2(__fd:int, __fd2:int) -> int: ... +@dll.bind(ctypes.c_int32, ctypes.c_int32, ctypes.c_int32, ctypes.c_int32) +def dup3(__fd:int, __fd2:int, __flags:int) -> int: ... try: __environ = c.POINTER[c.POINTER[ctypes.c_char]].in_dll(dll, '__environ') # type: ignore except (ValueError,AttributeError): pass +try: environ = c.POINTER[c.POINTER[ctypes.c_char]].in_dll(dll, 'environ') # type: ignore +except (ValueError,AttributeError): pass @dll.bind(ctypes.c_int32, c.POINTER[ctypes.c_char], c.Array[c.POINTER[ctypes.c_char], Literal[0]], c.Array[c.POINTER[ctypes.c_char], Literal[0]]) def execve(__path:c.POINTER[ctypes.c_char], __argv:c.Array[c.POINTER[ctypes.c_char], Literal[0]], __envp:c.Array[c.POINTER[ctypes.c_char], Literal[0]]) -> int: ... @dll.bind(ctypes.c_int32, ctypes.c_int32, c.Array[c.POINTER[ctypes.c_char], Literal[0]], c.Array[c.POINTER[ctypes.c_char], Literal[0]]) @@ -621,6 +713,8 @@ def execl(__path:c.POINTER[ctypes.c_char], __arg:c.POINTER[ctypes.c_char]) -> in def execvp(__file:c.POINTER[ctypes.c_char], __argv:c.Array[c.POINTER[ctypes.c_char], Literal[0]]) -> int: ... @dll.bind(ctypes.c_int32, c.POINTER[ctypes.c_char], c.POINTER[ctypes.c_char]) def execlp(__file:c.POINTER[ctypes.c_char], __arg:c.POINTER[ctypes.c_char]) -> int: ... +@dll.bind(ctypes.c_int32, c.POINTER[ctypes.c_char], c.Array[c.POINTER[ctypes.c_char], Literal[0]], c.Array[c.POINTER[ctypes.c_char], Literal[0]]) +def execvpe(__file:c.POINTER[ctypes.c_char], __argv:c.Array[c.POINTER[ctypes.c_char], Literal[0]], __envp:c.Array[c.POINTER[ctypes.c_char], Literal[0]]) -> int: ... @dll.bind(ctypes.c_int32, ctypes.c_int32) def nice(__inc:int) -> int: ... @dll.bind(None, ctypes.c_int32) @@ -663,6 +757,8 @@ def getegid() -> ctypes.c_uint32: ... @dll.bind(ctypes.c_int32, ctypes.c_int32, c.Array[ctypes.c_uint32, Literal[0]]) def getgroups(__size:int, __list:c.Array[ctypes.c_uint32, Literal[0]]) -> int: ... @dll.bind(ctypes.c_int32, ctypes.c_uint32) +def group_member(__gid:ctypes.c_uint32) -> int: ... +@dll.bind(ctypes.c_int32, ctypes.c_uint32) def setuid(__uid:ctypes.c_uint32) -> int: ... @dll.bind(ctypes.c_int32, ctypes.c_uint32, ctypes.c_uint32) def setreuid(__ruid:ctypes.c_uint32, __euid:ctypes.c_uint32) -> int: ... @@ -674,10 +770,20 @@ def setgid(__gid:ctypes.c_uint32) -> int: ... def setregid(__rgid:ctypes.c_uint32, __egid:ctypes.c_uint32) -> int: ... @dll.bind(ctypes.c_int32, ctypes.c_uint32) def setegid(__gid:ctypes.c_uint32) -> int: ... +@dll.bind(ctypes.c_int32, c.POINTER[ctypes.c_uint32], c.POINTER[ctypes.c_uint32], c.POINTER[ctypes.c_uint32]) +def getresuid(__ruid:c.POINTER[ctypes.c_uint32], __euid:c.POINTER[ctypes.c_uint32], __suid:c.POINTER[ctypes.c_uint32]) -> int: ... +@dll.bind(ctypes.c_int32, c.POINTER[ctypes.c_uint32], c.POINTER[ctypes.c_uint32], c.POINTER[ctypes.c_uint32]) +def getresgid(__rgid:c.POINTER[ctypes.c_uint32], __egid:c.POINTER[ctypes.c_uint32], __sgid:c.POINTER[ctypes.c_uint32]) -> int: ... +@dll.bind(ctypes.c_int32, ctypes.c_uint32, ctypes.c_uint32, ctypes.c_uint32) +def setresuid(__ruid:ctypes.c_uint32, __euid:ctypes.c_uint32, __suid:ctypes.c_uint32) -> int: ... +@dll.bind(ctypes.c_int32, ctypes.c_uint32, ctypes.c_uint32, ctypes.c_uint32) +def setresgid(__rgid:ctypes.c_uint32, __egid:ctypes.c_uint32, __sgid:ctypes.c_uint32) -> int: ... @dll.bind(ctypes.c_int32) def fork() -> ctypes.c_int32: ... @dll.bind(ctypes.c_int32) def vfork() -> int: ... +@dll.bind(ctypes.c_int32) +def _Fork() -> ctypes.c_int32: ... @dll.bind(c.POINTER[ctypes.c_char], ctypes.c_int32) def ttyname(__fd:int) -> c.POINTER[ctypes.c_char]: ... @dll.bind(ctypes.c_int32, ctypes.c_int32, c.POINTER[ctypes.c_char], size_t) @@ -714,6 +820,8 @@ def getlogin() -> c.POINTER[ctypes.c_char]: ... def getlogin_r(__name:c.POINTER[ctypes.c_char], __name_len:size_t) -> int: ... @dll.bind(ctypes.c_int32, c.POINTER[ctypes.c_char]) def setlogin(__name:c.POINTER[ctypes.c_char]) -> int: ... +@dll.bind(ctypes.c_int32, ctypes.c_int32, c.POINTER[c.POINTER[ctypes.c_char]], c.POINTER[ctypes.c_char]) +def getopt(___argc:int, ___argv:c.POINTER[c.POINTER[ctypes.c_char]], __shortopts:c.POINTER[ctypes.c_char]) -> int: ... @dll.bind(ctypes.c_int32, c.POINTER[ctypes.c_char], size_t) def gethostname(__name:c.POINTER[ctypes.c_char], __len:size_t) -> int: ... @dll.bind(ctypes.c_int32, c.POINTER[ctypes.c_char], size_t) @@ -746,6 +854,8 @@ def chroot(__path:c.POINTER[ctypes.c_char]) -> int: ... def getpass(__prompt:c.POINTER[ctypes.c_char]) -> c.POINTER[ctypes.c_char]: ... @dll.bind(ctypes.c_int32, ctypes.c_int32) def fsync(__fd:int) -> int: ... +@dll.bind(ctypes.c_int32, ctypes.c_int32) +def syncfs(__fd:int) -> int: ... @dll.bind(ctypes.c_int64) def gethostid() -> int: ... @dll.bind(None) @@ -756,8 +866,12 @@ def getpagesize() -> int: ... def getdtablesize() -> int: ... @dll.bind(ctypes.c_int32, c.POINTER[ctypes.c_char], ctypes.c_int64) def truncate(__file:c.POINTER[ctypes.c_char], __length:ctypes.c_int64) -> int: ... +@dll.bind(ctypes.c_int32, c.POINTER[ctypes.c_char], ctypes.c_int64) +def truncate64(__file:c.POINTER[ctypes.c_char], __length:ctypes.c_int64) -> int: ... @dll.bind(ctypes.c_int32, ctypes.c_int32, ctypes.c_int64) def ftruncate(__fd:int, __length:ctypes.c_int64) -> int: ... +@dll.bind(ctypes.c_int32, ctypes.c_int32, ctypes.c_int64) +def ftruncate64(__fd:int, __length:ctypes.c_int64) -> int: ... @dll.bind(ctypes.c_int32, ctypes.c_void_p) def brk(__addr:ctypes.c_void_p) -> int: ... @dll.bind(ctypes.c_void_p, intptr_t) @@ -766,14 +880,34 @@ def sbrk(__delta:intptr_t) -> ctypes.c_void_p: ... def syscall(__sysno:int) -> int: ... @dll.bind(ctypes.c_int32, ctypes.c_int32, ctypes.c_int32, ctypes.c_int64) def lockf(__fd:int, __cmd:int, __len:ctypes.c_int64) -> int: ... +@dll.bind(ctypes.c_int32, ctypes.c_int32, ctypes.c_int32, ctypes.c_int64) +def lockf64(__fd:int, __cmd:int, __len:ctypes.c_int64) -> int: ... +@dll.bind(ssize_t, ctypes.c_int32, c.POINTER[ctypes.c_int64], ctypes.c_int32, c.POINTER[ctypes.c_int64], size_t, ctypes.c_uint32) +def copy_file_range(__infd:int, __pinoff:c.POINTER[ctypes.c_int64], __outfd:int, __poutoff:c.POINTER[ctypes.c_int64], __length:size_t, __flags:int) -> ssize_t: ... @dll.bind(ctypes.c_int32, ctypes.c_int32) def fdatasync(__fildes:int) -> int: ... @dll.bind(c.POINTER[ctypes.c_char], c.POINTER[ctypes.c_char], c.POINTER[ctypes.c_char]) def crypt(__key:c.POINTER[ctypes.c_char], __salt:c.POINTER[ctypes.c_char]) -> c.POINTER[ctypes.c_char]: ... +@dll.bind(None, ctypes.c_void_p, ctypes.c_void_p, ssize_t) +def swab(__from:ctypes.c_void_p, __to:ctypes.c_void_p, __n:ssize_t) -> None: ... @dll.bind(ctypes.c_int32, ctypes.c_void_p, size_t) def getentropy(__buffer:ctypes.c_void_p, __length:size_t) -> int: ... +@dll.bind(ctypes.c_int32, ctypes.c_uint32, ctypes.c_uint32, ctypes.c_int32) +def close_range(__fd:int, __max_fd:int, __flags:int) -> int: ... +@dll.bind(ctypes.c_int32) +def gettid() -> ctypes.c_int32: ... +MREMAP_MAYMOVE = 1 +MREMAP_FIXED = 2 +MREMAP_DONTUNMAP = 4 +MFD_CLOEXEC = 1 +MFD_ALLOW_SEALING = 2 +MFD_HUGETLB = 4 +MFD_NOEXEC_SEAL = 8 +MFD_EXEC = 0x10 +MLOCK_ONFAULT = 1 +PKEY_DISABLE_ACCESS = 0x1 +PKEY_DISABLE_WRITE = 0x2 _SYS_MMAN_H = 1 -_SYSCALL_H = 1 _STRING_H = 1 _ELF_H = 1 EI_NIDENT = (16) @@ -3884,6 +4018,8 @@ F_OK = 0 SEEK_SET = 0 SEEK_CUR = 1 SEEK_END = 2 +SEEK_DATA = 3 +SEEK_HOLE = 4 L_SET = SEEK_SET L_INCR = SEEK_CUR L_XTND = SEEK_END