Commit 17dbf94e authored by Kirill Smelkov's avatar Kirill Smelkov

X Provide mlock2 fallback for Ubuntu

which has glibc 2.23 but mlock2 was added only to glibc 2.27.
The kernel (4.4.x) has mlock2 though.
parent 6764bbfc
...@@ -25,6 +25,30 @@ from posix cimport mman ...@@ -25,6 +25,30 @@ from posix cimport mman
from cpython.exc cimport PyErr_SetFromErrno from cpython.exc cimport PyErr_SetFromErrno
#from libc.stdio cimport printf #from libc.stdio cimport printf
# mlock2 is provided starting from glibc 2.27
cdef extern from *:
"""
#if defined(__GLIBC__)
#if !__GLIBC_PREREQ(2, 27)
#include <unistd.h>
#include <sys/syscall.h>
static int mlock2(const void *addr, size_t len, int flags) {
long err = syscall(SYS_mlock2, addr, len, flags);
if (err != 0) {
errno = -err;
return -1;
}
return 0;
}
#endif
#endif
#ifndef MLOCK_ONFAULT
# define MLOCK_ONFAULT 1
#endif
"""
pass
cdef extern from "<sys/user.h>": cdef extern from "<sys/user.h>":
cpdef enum: cpdef enum:
PAGE_SIZE PAGE_SIZE
...@@ -40,7 +64,7 @@ cpdef enum: ...@@ -40,7 +64,7 @@ cpdef enum:
MADV_SEQUENTIAL = mman.MADV_SEQUENTIAL MADV_SEQUENTIAL = mman.MADV_SEQUENTIAL
MADV_WILLNEED = mman.MADV_WILLNEED MADV_WILLNEED = mman.MADV_WILLNEED
MADV_DONTNEED = mman.MADV_DONTNEED MADV_DONTNEED = mman.MADV_DONTNEED
MADV_FREE = mman.MADV_FREE #MADV_FREE = mman.MADV_FREE
MADV_REMOVE = mman.MADV_REMOVE MADV_REMOVE = mman.MADV_REMOVE
MS_ASYNC = mman.MS_ASYNC MS_ASYNC = mman.MS_ASYNC
......
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