Commit 01ae0773 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent daa9d2df
...@@ -192,17 +192,17 @@ def test_wcfs_client_down_efault(): ...@@ -192,17 +192,17 @@ def test_wcfs_client_down_efault():
fh = wconn.open(zf._p_oid) fh = wconn.open(zf._p_oid)
defer(fh.close) defer(fh.close)
m1 = fh.mmap(1, 4) m1 = fh.mmap(1, 4); defer(m1.unmap)
defer(m1.unmap) m2 = fh.mmap(3, 3); defer(m2.unmap)
tm1 = tMapping(t, m1) tm1 = tMapping(t, m1)
tm2 = tMapping(t, m2)
tm1.assertBlk(1, '', {}) tm1.assertBlk(1, '', {})
tm1.assertBlk(2, 'c1', {}) tm1.assertBlk(2, 'c1', {})
tm1.assertBlk(3, 'd1', {}) tm1.assertBlk(3, 'd1', {}); tm2.assertBlk(3, 'd1', {})
tm1.assertBlk(4, '', {}) tm1.assertBlk(4, '', {}); tm2.assertBlk(4, '', {})
pass; tm2.assertBlk(5, '', {})
with panics("not faulted"): tm1.assertBlkFaults(2)
with panics("not faulted"): tm1.assertBlkFaults(3)
# close fileh -> m1 must turn into efaulting memory # close fileh -> m1 must turn into efaulting memory
fh.close() fh.close()
...@@ -210,3 +210,13 @@ def test_wcfs_client_down_efault(): ...@@ -210,3 +210,13 @@ def test_wcfs_client_down_efault():
tm1.assertBlkFaults(2) tm1.assertBlkFaults(2)
tm1.assertBlkFaults(3) tm1.assertBlkFaults(3)
tm1.assertBlkFaults(4) tm1.assertBlkFaults(4)
# verify that read_mustfault works as expected.
def test_read_mustfault():
mem = mm.map_zero_ro(mm.PAGE_SIZE)
with panics("not faulted"): read_mustfault(mem[:1])
mm.protect(mem, mm.PROT_NONE)
read_mustfault(mem[:1])
mm.protect(mem, mm.PROT_READ)
with panics("not faulted"): read_mustfault(mem[:1])
...@@ -54,6 +54,11 @@ cdef extern from "<sys/user.h>": ...@@ -54,6 +54,11 @@ cdef extern from "<sys/user.h>":
PAGE_SIZE PAGE_SIZE
cpdef enum: cpdef enum:
PROT_EXEC = mman.PROT_EXEC
PROT_READ = mman.PROT_READ
PROT_WRITE = mman.PROT_WRITE
PROT_NONE = mman.PROT_NONE
MLOCK_ONFAULT = mman.MLOCK_ONFAULT MLOCK_ONFAULT = mman.MLOCK_ONFAULT
MCL_CURRENT = mman.MCL_CURRENT MCL_CURRENT = mman.MCL_CURRENT
MCL_FUTURE = mman.MCL_FUTURE MCL_FUTURE = mman.MCL_FUTURE
...@@ -204,6 +209,20 @@ def advise(const unsigned char[::1] mem not None, int advice): ...@@ -204,6 +209,20 @@ def advise(const unsigned char[::1] mem not None, int advice):
return return
# protect sets protectionon a region of memory.
#
# see mprotect(2) for details.
def protect(const unsigned char[::1] mem not None, int prot):
cdef const void *addr = &mem[0]
cdef size_t size = mem.shape[0]
cdef err = mman.mprotect(<void *>addr, size, prot)
if err:
PyErr_SetFromErrno(OSError)
return
# sync asks the kernel to synchronize the file with a memory map. # sync asks the kernel to synchronize the file with a memory map.
# #
# see msync(2) for details. # see msync(2) for details.
......
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