pola-rs/polars · error · RuntimeError
could not execute mprotect for CPUID check
Error message
could not execute mprotect for CPUID check
What it means
On non-Windows platforms the CPUID check writes machine code into an mmap buffer and then calls `mprotect` to make it executable. A non-zero return from `mprotect` raises `RuntimeError` with this message. It means the kernel refused to make the probe page PROT_READ|PROT_EXEC.
Solutions
- Relax the W^X/selinux/seccomp policy for the process or use an image without exec-memory restrictions.
- Run in a standard environment (no grsecurity/PaX) or a supported container base image.
- Use a polars build/variant that does not require the runtime CPUID probe.
Defensive patterns
Strategy: try-catch
Try / catch
try:
import polars as pl
except RuntimeError as e:
if 'mprotect' in str(e):
raise RuntimeError('environment blocks executable memory (W^X policy); relax SELinux/seccomp or use a standard image') from e
raise Prevention
- Use container images without W^X enforcement (no grsecurity/PaX) for polars workloads.
- Check SELinux/AppArmor/seccomp policies in CI before installing native-code packages.
- Test `import polars` in the target environment early in setup.
When it happens
Trigger: Constructing the CPUID check object on Linux/macOS where `mprotect(addr, size, PROT_READ|PROT_EXEC)` returns non-zero — commonly under SELinux/AppArmor, PaX/GRSEC W^X enforcement, or seccomp filters forbidding exec-memory.
Common situations: Hardened CI runners and containers with W^X policies; sandboxed environments (gVisor, Firecracker) with restrictive seccomp; distributions with SELinux enforcing.
Understand the failure class
Background: "unsupported platform" / "not supported on this platform" errors: what they mean and how to fix them — this error's family across 47 libraries.
Related errors
- accessing ` ` from the top-level `polars` module was…
- altair>=5.4.0 is required for `.plot`
- `arctan2` expected a `str` or `Expr` got a
- `arctan2` expected a `str` or `Expr` got a
- arr.dot query vector must be one-dimensional
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/d9344cd087d73b5d.
Report an issue: GitHub.
Appendix: source
Thrown at py-polars/src/polars/_cpu_check.py:199
# On some platforms PROT_WRITE + PROT_EXEC is forbidden, so we first
# only write and then mprotect into PROT_EXEC.
libc = _open_posix_libc()
mprotect = libc.mprotect
mprotect.argtypes = (ctypes.c_void_p, ctypes.c_size_t, ctypes.c_int)
mprotect.restype = ctypes.c_int
self.mmap = mmap.mmap(
-1,
size,
mmap.MAP_PRIVATE | mmap.MAP_ANONYMOUS,
mmap.PROT_READ | mmap.PROT_WRITE,
)
self.addr = ctypes.addressof(ctypes.c_void_p.from_buffer(self.mmap))
self.mmap.write(code)
if mprotect(self.addr, size, mmap.PROT_READ | mmap.PROT_EXEC) != 0:
msg = "could not execute mprotect for CPUID check"
raise RuntimeError(msg)
func_type = CFUNCTYPE(None, POINTER(CPUID_struct), c_uint32, c_uint32)
self.func_ptr = func_type(self.addr)
def __call__(self, eax: int, ecx: int = 0) -> CPUID_struct:
struct = CPUID_struct()
self.func_ptr(struct, eax, ecx)
return struct
def __del__(self) -> None:
if _IS_WINDOWS:
self.win.VirtualFree.restype = c_long
self.win.VirtualFree.argtypes = [c_void_p, c_size_t, c_ulong]
self.win.VirtualFree(self.addr, 0, _MEM_RELEASE)
def _read_cpu_flags() -> dict[str, bool]:
if not _SUPPORTS_CPUID:View on GitHub (pinned to fe841f959e)