From 055769254d3f615aa372655d072c98c92f801db6 Mon Sep 17 00:00:00 2001 From: NAKAMURA Gou Date: Thu, 12 Mar 2015 16:28:57 +0900 Subject: [PATCH] implement mlockall()/munlockall() for LTP syscall --- arch/x86/kernel/include/arch/mman.h | 6 +++++ arch/x86/kernel/include/syscall_list.h | 2 ++ kernel/syscall.c | 31 ++++++++++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/arch/x86/kernel/include/arch/mman.h b/arch/x86/kernel/include/arch/mman.h index a8e25161..70bf7a04 100644 --- a/arch/x86/kernel/include/arch/mman.h +++ b/arch/x86/kernel/include/arch/mman.h @@ -27,4 +27,10 @@ #define MAP_STACK 0x00020000 #define MAP_HUGETLB 0x00040000 +/* + * for mlockall() + */ +#define MCL_CURRENT 0x01 +#define MCL_FUTURE 0x02 + #endif /* HEADER_ARCH_MMAN_H */ diff --git a/arch/x86/kernel/include/syscall_list.h b/arch/x86/kernel/include/syscall_list.h index 85c17320..5313b0a8 100644 --- a/arch/x86/kernel/include/syscall_list.h +++ b/arch/x86/kernel/include/syscall_list.h @@ -88,6 +88,8 @@ SYSCALL_HANDLED(147, sched_get_priority_min) SYSCALL_HANDLED(148, sched_rr_get_interval) SYSCALL_HANDLED(149, mlock) SYSCALL_HANDLED(150, munlock) +SYSCALL_HANDLED(151, mlockall) +SYSCALL_HANDLED(152, munlockall) SYSCALL_HANDLED(158, arch_prctl) SYSCALL_HANDLED(160, setrlimit) SYSCALL_HANDLED(186, gettid) diff --git a/kernel/syscall.c b/kernel/syscall.c index 086ab045..042f36f4 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -5038,6 +5038,37 @@ out2: return error; } +SYSCALL_DECLARE(mlockall) +{ + const int flags = ihk_mc_syscall_arg0(ctx); + struct process *proc = cpu_local_var(current); + uid_t euid = geteuid(); + + if (!flags || (flags & ~(MCL_CURRENT|MCL_FUTURE))) { + kprintf("mlockall(0x%x):invalid flags: EINVAL\n", flags); + return -EINVAL; + } + + if (!euid) { + kprintf("mlockall(0x%x):priv user: 0\n", flags); + return 0; + } + + if (proc->rlimit[MCK_RLIMIT_MEMLOCK].rlim_cur != 0) { + kprintf("mlockall(0x%x):limits exists: ENOMEM\n", flags); + return -ENOMEM; + } + + kprintf("mlockall(0x%x):no lock permitted: EPERM\n", flags); + return -EPERM; +} /* sys_mlockall() */ + +SYSCALL_DECLARE(munlockall) +{ + kprintf("munlockall(): 0\n"); + return 0; +} /* sys_munlockall() */ + SYSCALL_DECLARE(remap_file_pages) { const uintptr_t start0 = ihk_mc_syscall_arg0(ctx);