提交 b64d66d0 编写于 作者: S Szabolcs Nagy 提交者: Rich Felker

add mlock2 linux syscall wrapper

mlock2 syscall was added in linux v4.4 and glibc has api for it.
It falls back to mlock in case of flags==0, so that case works
even on older kernels.

MLOCK_ONFAULT is moved under _GNU_SOURCE following glibc.
上级 84b25160
......@@ -94,6 +94,13 @@ extern "C" {
#define MADV_SOFT_OFFLINE 101
#endif
#ifdef _GNU_SOURCE
#define MREMAP_MAYMOVE 1
#define MREMAP_FIXED 2
#define MLOCK_ONFAULT 0x01
#endif
#include <bits/mman.h>
void *mmap (void *, size_t, int, int, int, off_t);
......@@ -110,14 +117,12 @@ int mlockall (int);
int munlockall (void);
#ifdef _GNU_SOURCE
#define MREMAP_MAYMOVE 1
#define MREMAP_FIXED 2
void *mremap (void *, size_t, size_t, int, ...);
int remap_file_pages (void *, size_t, int, size_t, int);
int mlock2 (const void *, size_t, unsigned);
#endif
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
#define MLOCK_ONFAULT 0x01
int madvise (void *, size_t, int);
int mincore (void *, size_t, unsigned char *);
#endif
......
#define _GNU_SOURCE 1
#include <sys/mman.h>
#include "syscall.h"
int mlock2(const void *addr, size_t len, unsigned flags)
{
if (flags == 0)
return mlock(addr, len);
return syscall(SYS_mlock2, addr, len, flags);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册