Commit 68aa2401 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent fff59cb0
......@@ -340,6 +340,7 @@ void test_file_access_synthetic(void)
int err;
/* MUST_FAULT(code) - checks that code faults */
/* somewhat dup in wcfs_test.pyx */
sigjmp_buf fault_jmp;
volatile int fault_expected = 0;
void sigfault_handler(int sig) {
......
......@@ -23,8 +23,9 @@
"""Module wcfs_test.pyx complements wcfs_test.py with things that cannot be
implemented in Python."""
from posix.signal cimport sigaction, sigaction_t, siginfo_t, SA_SIGINFO
from libc.signal cimport SIGBUS
from posix.signal cimport sigaction, sigaction_t, siginfo_t, SA_SIGINFO, sigemptyset
from libc.signal cimport SIGBUS, SIGSEGV
from libc.setjmp cimport sigjmp_buf, sigsetjmp, siglongjmp
from libc.stdlib cimport abort
from libc.string cimport strlen
from posix.unistd cimport write, sleep
......@@ -32,8 +33,8 @@ from posix.types cimport off_t
from cpython.exc cimport PyErr_SetFromErrno
from golang cimport chan, pychan, select, panic, topyexc
from golang cimport time
from golang cimport chan, pychan, select, panic, topyexc, cbool
from golang cimport sync, time
# _tDB is pyx part of tDB.
cdef class _tDB:
......@@ -86,6 +87,57 @@ def read_nogil(const unsigned char[::1] mem not None) -> bytes:
return bytes(bytearray([b]))
# read_mustfault verifies that read-access to mem causes SIGSEGV.
cdef sync.Mutex mustfaultMu # one at a time as sigaction is per-process
cdef sigjmp_buf mustfaultJmp
cdef cbool faultExpected = False
cdef cbool faultedOk = False
cdef unsigned char mustfaultG # global var for compiler not to optimize-out p[0] access
cdef void mustfaultSighand(int sig) nogil:
if not faultExpected:
panic("unexpected fault")
# just return from sighandler to proper place
faultedOk = True
siglongjmp(mustfaultJmp, 1)
cdef void _read_mustfault(const unsigned char *p) nogil except +topyexc:
global faultExpected, faultedOk
cdef sigaction_t act, saveact
act.sa_handler = mustfaultSighand
act.sa_flags = 0
sigemptyset(&act.sa_mask) # XXX err
sigaction(SIGSEGV, &act, &saveact) # XXX err
faultExpected = True
faultedOk = False
if sigsetjmp(mustfaultJmp, 1) == 0:
mustfaultG = p[0] # should pagefault -> sighandler does longjmp
panic("not faulted") # XXX -> just error ?
else:
# faulted
if not faultedOk:
panic("faulted, but !faultedOk")
faultExpected = False
sigaction(SIGSEGV, &saveact, NULL) # XXX err
def read_mustfault(const unsigned char[::1] mem not None):
assert len(mem) == 1, "read_mustfault: only [1] mem is supported for now"
# somewhat dup of MUST_FAULT in test_virtmem.c
with nogil:
mustfaultMu.lock()
_read_mustfault(&mem[0])
mustfaultMu.unlock()
# --------
cdef extern from "<fcntl.h>" nogil:
int posix_fadvise(int fd, off_t offset, off_t len, int advice);
enum: POSIX_FADV_DONTNEED
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment