aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2008-07-24 00:29:25 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-07-24 13:47:27 -0400
commitb087498eb5605673b0f260a7620d91818cd72304 (patch)
tree977d9dbcd326a9582dfc5ad000995d26886c872e
parent9deb27baedb79759c3ab9435a7d8b841842d56e9 (diff)
flag parameters: eventfd
This patch adds the new eventfd2 syscall. It extends the old eventfd syscall by one parameter which is meant to hold a flag value. In this patch the only flag support is EFD_CLOEXEC which causes the close-on-exec flag for the returned file descriptor to be set. A new name EFD_CLOEXEC is introduced which in this implementation must have the same value as O_CLOEXEC. The following test must be adjusted for architectures other than x86 and x86-64 and in case the syscall numbers changed. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #include <fcntl.h> #include <stdio.h> #include <unistd.h> #include <sys/syscall.h> #ifndef __NR_eventfd2 # ifdef __x86_64__ # define __NR_eventfd2 290 # elif defined __i386__ # define __NR_eventfd2 328 # else # error "need __NR_eventfd2" # endif #endif #define EFD_CLOEXEC O_CLOEXEC int main (void) { int fd = syscall (__NR_eventfd2, 1, 0); if (fd == -1) { puts ("eventfd2(0) failed"); return 1; } int coe = fcntl (fd, F_GETFD); if (coe == -1) { puts ("fcntl failed"); return 1; } if (coe & FD_CLOEXEC) { puts ("eventfd2(0) sets close-on-exec flag"); return 1; } close (fd); fd = syscall (__NR_eventfd2, 1, EFD_CLOEXEC); if (fd == -1) { puts ("eventfd2(EFD_CLOEXEC) failed"); return 1; } coe = fcntl (fd, F_GETFD); if (coe == -1) { puts ("fcntl failed"); return 1; } if ((coe & FD_CLOEXEC) == 0) { puts ("eventfd2(EFD_CLOEXEC) does not set close-on-exec flag"); return 1; } close (fd); puts ("OK"); return 0; } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [akpm@linux-foundation.org: add sys_ni stub] Signed-off-by: Ulrich Drepper <drepper@redhat.com> Acked-by: Davide Libenzi <davidel@xmailserver.org> Cc: Michael Kerrisk <mtk.manpages@googlemail.com> Cc: <linux-arch@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--arch/x86/ia32/ia32entry.S1
-rw-r--r--arch/x86/kernel/syscall_table_32.S1
-rw-r--r--fs/eventfd.c13
-rw-r--r--include/asm-x86/unistd_32.h1
-rw-r--r--include/asm-x86/unistd_64.h2
-rw-r--r--include/linux/eventfd.h6
-rw-r--r--include/linux/syscalls.h1
-rw-r--r--kernel/sys_ni.c1
8 files changed, 24 insertions, 2 deletions
diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
index c308128b9251..cf0eb31745ca 100644
--- a/arch/x86/ia32/ia32entry.S
+++ b/arch/x86/ia32/ia32entry.S
@@ -827,4 +827,5 @@ ia32_sys_call_table:
827 .quad compat_sys_timerfd_settime /* 325 */ 827 .quad compat_sys_timerfd_settime /* 325 */
828 .quad compat_sys_timerfd_gettime 828 .quad compat_sys_timerfd_gettime
829 .quad compat_sys_signalfd4 829 .quad compat_sys_signalfd4
830 .quad sys_eventfd2
830ia32_syscall_end: 831ia32_syscall_end:
diff --git a/arch/x86/kernel/syscall_table_32.S b/arch/x86/kernel/syscall_table_32.S
index c12a36c9fd51..cf112cb11c37 100644
--- a/arch/x86/kernel/syscall_table_32.S
+++ b/arch/x86/kernel/syscall_table_32.S
@@ -327,3 +327,4 @@ ENTRY(sys_call_table)
327 .long sys_timerfd_settime /* 325 */ 327 .long sys_timerfd_settime /* 325 */
328 .long sys_timerfd_gettime 328 .long sys_timerfd_gettime
329 .long sys_signalfd4 329 .long sys_signalfd4
330 .long sys_eventfd2
diff --git a/fs/eventfd.c b/fs/eventfd.c
index 6094265ca409..bd420e6478ad 100644
--- a/fs/eventfd.c
+++ b/fs/eventfd.c
@@ -198,11 +198,14 @@ struct file *eventfd_fget(int fd)
198 return file; 198 return file;
199} 199}
200 200
201asmlinkage long sys_eventfd(unsigned int count) 201asmlinkage long sys_eventfd2(unsigned int count, int flags)
202{ 202{
203 int fd; 203 int fd;
204 struct eventfd_ctx *ctx; 204 struct eventfd_ctx *ctx;
205 205
206 if (flags & ~EFD_CLOEXEC)
207 return -EINVAL;
208
206 ctx = kmalloc(sizeof(*ctx), GFP_KERNEL); 209 ctx = kmalloc(sizeof(*ctx), GFP_KERNEL);
207 if (!ctx) 210 if (!ctx)
208 return -ENOMEM; 211 return -ENOMEM;
@@ -214,9 +217,15 @@ asmlinkage long sys_eventfd(unsigned int count)
214 * When we call this, the initialization must be complete, since 217 * When we call this, the initialization must be complete, since
215 * anon_inode_getfd() will install the fd. 218 * anon_inode_getfd() will install the fd.
216 */ 219 */
217 fd = anon_inode_getfd("[eventfd]", &eventfd_fops, ctx, 0); 220 fd = anon_inode_getfd("[eventfd]", &eventfd_fops, ctx,
221 flags & O_CLOEXEC);
218 if (fd < 0) 222 if (fd < 0)
219 kfree(ctx); 223 kfree(ctx);
220 return fd; 224 return fd;
221} 225}
222 226
227asmlinkage long sys_eventfd(unsigned int count)
228{
229 return sys_eventfd2(count, 0);
230}
231
diff --git a/include/asm-x86/unistd_32.h b/include/asm-x86/unistd_32.h
index c310371f5613..edbd8723c939 100644
--- a/include/asm-x86/unistd_32.h
+++ b/include/asm-x86/unistd_32.h
@@ -333,6 +333,7 @@
333#define __NR_timerfd_settime 325 333#define __NR_timerfd_settime 325
334#define __NR_timerfd_gettime 326 334#define __NR_timerfd_gettime 326
335#define __NR_signalfd4 327 335#define __NR_signalfd4 327
336#define __NR_eventfd2 328
336 337
337#ifdef __KERNEL__ 338#ifdef __KERNEL__
338 339
diff --git a/include/asm-x86/unistd_64.h b/include/asm-x86/unistd_64.h
index e0a9b45b2346..fb059a6feeb1 100644
--- a/include/asm-x86/unistd_64.h
+++ b/include/asm-x86/unistd_64.h
@@ -643,6 +643,8 @@ __SYSCALL(__NR_timerfd_gettime, sys_timerfd_gettime)
643__SYSCALL(__NR_paccept, sys_paccept) 643__SYSCALL(__NR_paccept, sys_paccept)
644#define __NR_signalfd4 289 644#define __NR_signalfd4 289
645__SYSCALL(__NR_signalfd4, sys_signalfd4) 645__SYSCALL(__NR_signalfd4, sys_signalfd4)
646#define __NR_eventfd2 290
647__SYSCALL(__NR_eventfd2, sys_eventfd2)
646 648
647 649
648#ifndef __NO_STUBS 650#ifndef __NO_STUBS
diff --git a/include/linux/eventfd.h b/include/linux/eventfd.h
index a701399b7fed..a6c0eaedb1b0 100644
--- a/include/linux/eventfd.h
+++ b/include/linux/eventfd.h
@@ -10,6 +10,12 @@
10 10
11#ifdef CONFIG_EVENTFD 11#ifdef CONFIG_EVENTFD
12 12
13/* For O_CLOEXEC */
14#include <linux/fcntl.h>
15
16/* Flags for eventfd2. */
17#define EFD_CLOEXEC O_CLOEXEC
18
13struct file *eventfd_fget(int fd); 19struct file *eventfd_fget(int fd);
14int eventfd_signal(struct file *file, int n); 20int eventfd_signal(struct file *file, int n);
15 21
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index 1c2707797845..9ab09926a7f2 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -617,6 +617,7 @@ asmlinkage long sys_timerfd_settime(int ufd, int flags,
617 struct itimerspec __user *otmr); 617 struct itimerspec __user *otmr);
618asmlinkage long sys_timerfd_gettime(int ufd, struct itimerspec __user *otmr); 618asmlinkage long sys_timerfd_gettime(int ufd, struct itimerspec __user *otmr);
619asmlinkage long sys_eventfd(unsigned int count); 619asmlinkage long sys_eventfd(unsigned int count);
620asmlinkage long sys_eventfd2(unsigned int count, int flags);
620asmlinkage long sys_fallocate(int fd, int mode, loff_t offset, loff_t len); 621asmlinkage long sys_fallocate(int fd, int mode, loff_t offset, loff_t len);
621 622
622int kernel_execve(const char *filename, char *const argv[], char *const envp[]); 623int kernel_execve(const char *filename, char *const argv[], char *const envp[]);
diff --git a/kernel/sys_ni.c b/kernel/sys_ni.c
index 8627c89ae9e8..2a361ccdc7ca 100644
--- a/kernel/sys_ni.c
+++ b/kernel/sys_ni.c
@@ -164,3 +164,4 @@ cond_syscall(sys_timerfd_gettime);
164cond_syscall(compat_sys_timerfd_settime); 164cond_syscall(compat_sys_timerfd_settime);
165cond_syscall(compat_sys_timerfd_gettime); 165cond_syscall(compat_sys_timerfd_gettime);
166cond_syscall(sys_eventfd); 166cond_syscall(sys_eventfd);
167cond_syscall(sys_eventfd2);