mailing list of musl libc
 help / color / mirror / code / Atom feed
From: "Tottenham, Max" <mtottenh@akamai.com>
To: "musl@lists.openwall.com" <musl@lists.openwall.com>
Subject: [PATCH] [PATCH V1] Add mlock2 syscall wrapper
Date: Thu, 10 Dec 2015 16:49:44 +0000	[thread overview]
Message-ID: <573A4C00-DD93-4023-BEA5-AE4DA2F0EA7E@akamai.com> (raw)


The mlock2 syscall has been accepted upstream for kernel v4.4. This
patch adds a simple syscall wrapper to libc for x86_64 and i386.

-- Max Tottenham



---
 arch/i386/bits/mman.h      | 1 +
 arch/i386/bits/syscall.h   | 2 ++
 arch/x86_64/bits/mman.h    | 1 +
 arch/x86_64/bits/syscall.h | 2 ++
 include/sys/mman.h         | 1 +
 src/mman/mlock2.c          | 7 +++++++
 6 files changed, 14 insertions(+)
 create mode 100644 src/mman/mlock2.c


diff --git a/arch/i386/bits/mman.h b/arch/i386/bits/mman.h
index 0f53acb..0c9022f 100644
--- a/arch/i386/bits/mman.h
+++ b/arch/i386/bits/mman.h
@@ -38,6 +38,7 @@
 
 #define MCL_CURRENT     1
 #define MCL_FUTURE      2
+#define MCL_ONFAULT     4
 
 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 #define MADV_NORMAL      0
diff --git a/arch/i386/bits/syscall.h b/arch/i386/bits/syscall.h
index 2902f80..168ccd7 100644
--- a/arch/i386/bits/syscall.h
+++ b/arch/i386/bits/syscall.h
@@ -357,6 +357,7 @@
 #define __NR_memfd_create	356
 #define __NR_bpf		357
 #define __NR_execveat		358
+#define __NR_mlock2		376
 
 
 /* Repeated with SYS_ prefix */
@@ -720,3 +721,4 @@
 #define SYS_memfd_create	356
 #define SYS_bpf			357
 #define SYS_execveat		358
+#define SYS_mlock2		376
diff --git a/arch/x86_64/bits/mman.h b/arch/x86_64/bits/mman.h
index 846b7ea..f3235f4 100644
--- a/arch/x86_64/bits/mman.h
+++ b/arch/x86_64/bits/mman.h
@@ -38,6 +38,7 @@
 
 #define MCL_CURRENT     1
 #define MCL_FUTURE      2
+#define MCL_ONFAULT     4
 
 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 #define MADV_NORMAL      0
diff --git a/arch/x86_64/bits/syscall.h b/arch/x86_64/bits/syscall.h
index 96ec51f..ae27522 100644
--- a/arch/x86_64/bits/syscall.h
+++ b/arch/x86_64/bits/syscall.h
@@ -321,6 +321,7 @@
 #define __NR_kexec_file_load			320
 #define __NR_bpf				321
 #define __NR_execveat				322
+#define __NR_mlock2				325
 
 
 
@@ -649,3 +650,4 @@
 #define SYS_kexec_file_load			320
 #define SYS_bpf					321
 #define SYS_execveat				322
+#define SYS_mlock2				325
diff --git a/include/sys/mman.h b/include/sys/mman.h
index 9fc2db5..3c767ad 100644
--- a/include/sys/mman.h
+++ b/include/sys/mman.h
@@ -27,6 +27,7 @@ int msync (void *, size_t, int);
 int posix_madvise (void *, size_t, int);
 
 int mlock (const void *, size_t);
+int mlock2 (const void *, size_t, int);
 int munlock (const void *, size_t);
 int mlockall (int);
 int munlockall (void);
diff --git a/src/mman/mlock2.c b/src/mman/mlock2.c
new file mode 100644
index 0000000..a317f8a
--- /dev/null
+++ b/src/mman/mlock2.c
@@ -0,0 +1,7 @@
+#include <sys/mman.h>
+#include "syscall.h"
+
+int mlock2(const void *addr, size_t len, int flags)
+{
+	return syscall(SYS_mlock2, addr, len, flags);
+}
-- 
2.6.1



             reply	other threads:[~2015-12-10 16:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-10 16:49 Tottenham, Max [this message]
2015-12-10 17:02 ` Szabolcs Nagy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=573A4C00-DD93-4023-BEA5-AE4DA2F0EA7E@akamai.com \
    --to=mtottenh@akamai.com \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).