centos7 mlock2

C++
#define _GNU_SOURCE
#include <unistd.h>
#include <errno.h>
#include <asm-generic/mman-common.h>
#include <sys/syscall.h>
#include <sys/mman.h>

inline int mlock2(const void* addr, size_t length, unsigned int flags) noexcept
{
    if (flags == 0)
    {
        return mlock(addr, length);
    }
    int ret = syscall(SYS_mlock2, addr, length, flags);
    return (ret == 0 || errno != ENOSYS) ? ret : -1;
}
Source

Also in C++: