Module: xenomai-3
Branch: next
Commit: 450290bb5c82f0007027776be9e9bd09136f41be
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=450290bb5c82f0007027776be9e9bd09136f41be

Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>
Date:   Sat Oct 25 21:11:16 2014 +0200

cobalt/rtdm: add fcntl syscall

---

 include/cobalt/fcntl.h            |    2 +
 include/cobalt/kernel/rtdm/fd.h   |    2 +
 include/cobalt/kernel/rtdm/rtdm.h |    3 +
 include/cobalt/uapi/syscall.h     |  133 +++++++++++++++++++------------------
 kernel/cobalt/posix/io.c          |    6 ++
 kernel/cobalt/posix/io.h          |    2 +
 kernel/cobalt/posix/syscall.c     |   10 +--
 kernel/cobalt/rtdm/fd.c           |   42 +++++++++++-
 lib/cobalt/cobalt.wrappers        |    1 +
 lib/cobalt/rtdm.c                 |   18 +++++
 lib/cobalt/wrappers.c             |   13 ++++
 11 files changed, 159 insertions(+), 73 deletions(-)

diff --git a/include/cobalt/fcntl.h b/include/cobalt/fcntl.h
index ed96dd7..2a83a7a 100644
--- a/include/cobalt/fcntl.h
+++ b/include/cobalt/fcntl.h
@@ -29,6 +29,8 @@ extern "C" {
 
 COBALT_DECL(int, open(const char *path, int oflag, ...));
 
+COBALT_DECL(int, fcntl(int fd, int cmd, ...));
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/include/cobalt/kernel/rtdm/fd.h b/include/cobalt/kernel/rtdm/fd.h
index ccf0332..5685b3a 100644
--- a/include/cobalt/kernel/rtdm/fd.h
+++ b/include/cobalt/kernel/rtdm/fd.h
@@ -353,6 +353,8 @@ void rtdm_fd_put(struct rtdm_fd *fd);
 
 void rtdm_fd_unlock(struct rtdm_fd *fd);
 
+int rtdm_fd_fcntl(int ufd, int cmd, ...);
+
 int rtdm_fd_ioctl(int ufd, unsigned int request, ...);
 
 ssize_t rtdm_fd_read(int ufd, void __user *buf, size_t size);
diff --git a/include/cobalt/kernel/rtdm/rtdm.h 
b/include/cobalt/kernel/rtdm/rtdm.h
index db1e270..2b1c8fd 100644
--- a/include/cobalt/kernel/rtdm/rtdm.h
+++ b/include/cobalt/kernel/rtdm/rtdm.h
@@ -50,6 +50,9 @@ int __rtdm_dev_socket(int protocol_family,
 #define rt_dev_close(fd)                                       \
        rtdm_fd_close(fd, RTDM_FD_MAGIC)
 
+#define rt_dev_fcntl(fd, cmd, ...)                             \
+       rtdm_fd_fcntl(fd,cmd, __VA_ARGS__)
+
 #define rt_dev_ioctl(fd, request, ...)                         \
        rtdm_fd_ioctl(fd, request, __VA_ARGS__)
 
diff --git a/include/cobalt/uapi/syscall.h b/include/cobalt/uapi/syscall.h
index aa364a1..025d2ff 100644
--- a/include/cobalt/uapi/syscall.h
+++ b/include/cobalt/uapi/syscall.h
@@ -21,63 +21,63 @@
 #include <cobalt/uapi/asm-generic/syscall.h>
 
 #define sc_cobalt_bind                         0
-#define sc_cobalt_thread_create                1
-#define sc_cobalt_thread_getpid                2
-#define sc_cobalt_thread_setmode               3
-#define sc_cobalt_thread_setname               4
-#define sc_cobalt_thread_join                  5
-#define sc_cobalt_thread_kill                  6
+#define sc_cobalt_thread_create                        1
+#define sc_cobalt_thread_getpid                        2
+#define sc_cobalt_thread_setmode               3
+#define sc_cobalt_thread_setname               4
+#define sc_cobalt_thread_join                  5
+#define sc_cobalt_thread_kill                  6
 #define sc_cobalt_thread_setschedparam_ex      7
 #define sc_cobalt_thread_getschedparam_ex      8
-#define sc_cobalt_thread_getstat               9
+#define sc_cobalt_thread_getstat               9
 /* 10 unimp */
-#define sc_cobalt_sem_init                     11
-#define sc_cobalt_sem_destroy                  12
-#define sc_cobalt_sem_post                     13
-#define sc_cobalt_sem_wait                     14
-#define sc_cobalt_sem_trywait                  15
-#define sc_cobalt_sem_getvalue                 16
-#define sc_cobalt_sem_open                     17
-#define sc_cobalt_sem_close                    18
-#define sc_cobalt_sem_unlink                   19
-#define sc_cobalt_sem_timedwait                20
-#define sc_cobalt_sem_inquire                  21
+#define sc_cobalt_sem_init                     11
+#define sc_cobalt_sem_destroy                  12
+#define sc_cobalt_sem_post                     13
+#define sc_cobalt_sem_wait                     14
+#define sc_cobalt_sem_trywait                  15
+#define sc_cobalt_sem_getvalue                 16
+#define sc_cobalt_sem_open                     17
+#define sc_cobalt_sem_close                    18
+#define sc_cobalt_sem_unlink                   19
+#define sc_cobalt_sem_timedwait                        20
+#define sc_cobalt_sem_inquire                  21
 /* 22 unimp */
-#define sc_cobalt_sem_broadcast_np             23
-#define sc_cobalt_clock_getres                 24
-#define sc_cobalt_clock_gettime                25
-#define sc_cobalt_clock_settime                26
-#define sc_cobalt_clock_nanosleep              27
-#define sc_cobalt_mutex_init                   28
-#define sc_cobalt_mutex_check_init             29
-#define sc_cobalt_mutex_destroy                30
-#define sc_cobalt_mutex_lock                   31
-#define sc_cobalt_mutex_timedlock              32
-#define sc_cobalt_mutex_trylock                33
-#define sc_cobalt_mutex_unlock                 34
-#define sc_cobalt_cond_init                    35
-#define sc_cobalt_cond_destroy                 36
-#define sc_cobalt_cond_wait_prologue           37
-#define sc_cobalt_cond_wait_epilogue           38
-#define sc_cobalt_mq_open                      39
-#define sc_cobalt_mq_close                     40
-#define sc_cobalt_mq_unlink                    41
-#define sc_cobalt_mq_getattr                   42
-#define sc_cobalt_mq_setattr                   43
-#define sc_cobalt_mq_timedsend                 44
-#define sc_cobalt_mq_timedreceive              45
-#define sc_cobalt_mq_notify                    46
-#define sc_cobalt_sched_minprio                47
-#define sc_cobalt_sched_maxprio                48
-#define sc_cobalt_sched_weightprio             49
-#define sc_cobalt_sched_yield                  50
+#define sc_cobalt_sem_broadcast_np             23
+#define sc_cobalt_clock_getres                 24
+#define sc_cobalt_clock_gettime                        25
+#define sc_cobalt_clock_settime                        26
+#define sc_cobalt_clock_nanosleep              27
+#define sc_cobalt_mutex_init                   28
+#define sc_cobalt_mutex_check_init             29
+#define sc_cobalt_mutex_destroy                        30
+#define sc_cobalt_mutex_lock                   31
+#define sc_cobalt_mutex_timedlock              32
+#define sc_cobalt_mutex_trylock                        33
+#define sc_cobalt_mutex_unlock                 34
+#define sc_cobalt_cond_init                    35
+#define sc_cobalt_cond_destroy                 36
+#define sc_cobalt_cond_wait_prologue           37
+#define sc_cobalt_cond_wait_epilogue           38
+#define sc_cobalt_mq_open                      39
+#define sc_cobalt_mq_close                     40
+#define sc_cobalt_mq_unlink                    41
+#define sc_cobalt_mq_getattr                   42
+#define sc_cobalt_mq_setattr                   43
+#define sc_cobalt_mq_timedsend                 44
+#define sc_cobalt_mq_timedreceive              45
+#define sc_cobalt_mq_notify                    46
+#define sc_cobalt_sched_minprio                        47
+#define sc_cobalt_sched_maxprio                        48
+#define sc_cobalt_sched_weightprio             49
+#define sc_cobalt_sched_yield                  50
 #define sc_cobalt_sched_setconfig_np           51
 #define sc_cobalt_sched_getconfig_np           52
-#define sc_cobalt_timer_create                 53
-#define sc_cobalt_timer_delete                 54
-#define sc_cobalt_timer_settime                55
-#define sc_cobalt_timer_gettime                56
-#define sc_cobalt_timer_getoverrun             57
+#define sc_cobalt_timer_create                 53
+#define sc_cobalt_timer_delete                 54
+#define sc_cobalt_timer_settime                        55
+#define sc_cobalt_timer_gettime                        56
+#define sc_cobalt_timer_getoverrun             57
 #define sc_cobalt_timerfd_create               58
 #define sc_cobalt_timerfd_settime              59
 #define sc_cobalt_timerfd_gettime              60
@@ -87,27 +87,27 @@
 #define sc_cobalt_sigpending                   64
 #define sc_cobalt_kill                         65
 #define sc_cobalt_sigqueue                     66
-#define sc_cobalt_monitor_init                 67
-#define sc_cobalt_monitor_destroy              68
-#define sc_cobalt_monitor_enter                69
-#define sc_cobalt_monitor_wait                 70
-#define sc_cobalt_monitor_sync                 71
-#define sc_cobalt_monitor_exit                 72
-#define sc_cobalt_event_init                   73
-#define sc_cobalt_event_wait                   74
-#define sc_cobalt_event_sync                   75
-#define sc_cobalt_event_destroy                76
-#define sc_cobalt_event_inquire                77
+#define sc_cobalt_monitor_init                 67
+#define sc_cobalt_monitor_destroy              68
+#define sc_cobalt_monitor_enter                        69
+#define sc_cobalt_monitor_wait                 70
+#define sc_cobalt_monitor_sync                 71
+#define sc_cobalt_monitor_exit                 72
+#define sc_cobalt_event_init                   73
+#define sc_cobalt_event_wait                   74
+#define sc_cobalt_event_sync                   75
+#define sc_cobalt_event_destroy                        76
+#define sc_cobalt_event_inquire                        77
 #define sc_cobalt_open                         78
 #define sc_cobalt_socket                       79
 #define sc_cobalt_close                                80
 #define sc_cobalt_ioctl                                81
 #define sc_cobalt_read                         82
 #define sc_cobalt_write                                83
-#define sc_cobalt_recvmsg                      84
-#define sc_cobalt_sendmsg                      85
-#define sc_cobalt_mmap                         86
-#define sc_cobalt_select                       87
+#define sc_cobalt_recvmsg                      84
+#define sc_cobalt_sendmsg                      85
+#define sc_cobalt_mmap                         86
+#define sc_cobalt_select                       87
 #define sc_cobalt_migrate                      88
 #define sc_cobalt_archcall                     89
 #define sc_cobalt_info                         90
@@ -119,6 +119,7 @@
 #define sc_cobalt_serialdbg                    96
 #define sc_cobalt_extend                       97
 #define sc_cobalt_sysconf                      98
+#define sc_cobalt_fcntl                                99
 
 #define __NR_COBALT_SYSCALLS                   128 /* Power of 2 */
 
diff --git a/kernel/cobalt/posix/io.c b/kernel/cobalt/posix/io.c
index 0d7ca33..3a5e856 100644
--- a/kernel/cobalt/posix/io.c
+++ b/kernel/cobalt/posix/io.c
@@ -54,6 +54,12 @@ COBALT_SYSCALL(close, lostage, int, (int fd))
        return rtdm_fd_close(fd, 0);
 }
 
+COBALT_SYSCALL(fcntl, current,
+       int, (int fd, int cmd, int arg))
+{
+       return rtdm_fd_fcntl(fd, cmd, arg);
+}
+
 COBALT_SYSCALL(ioctl, probing,
               int, (int fd, unsigned int request, void __user *arg))
 {
diff --git a/kernel/cobalt/posix/io.h b/kernel/cobalt/posix/io.h
index b8f4ed4..2b49546 100644
--- a/kernel/cobalt/posix/io.h
+++ b/kernel/cobalt/posix/io.h
@@ -37,6 +37,8 @@ COBALT_SYSCALL_DECL(socket, int,
 
 COBALT_SYSCALL_DECL(close, int, (int fd));
 
+COBALT_SYSCALL_DECL(fcntl, int, (int fd, int cmd, int arg));
+
 COBALT_SYSCALL_DECL(ioctl, int,
                    (int fd, unsigned int request, void __user *arg));
 
diff --git a/kernel/cobalt/posix/syscall.c b/kernel/cobalt/posix/syscall.c
index e327f7e..1b128f1 100644
--- a/kernel/cobalt/posix/syscall.c
+++ b/kernel/cobalt/posix/syscall.c
@@ -511,7 +511,7 @@ static int cobalt_ni(void)
 
 #ifdef CONFIG_XENO_ARCH_SYS3264
 #include "syscall32.h"
-#endif 
+#endif
 
 static const cobalt_syshand cobalt_syscalls[] = {
        __COBALT_CALL_NI,
@@ -611,10 +611,11 @@ static const cobalt_syshand cobalt_syscalls[] = {
        __COBALT_CALL_ENTRY(backtrace),
        __COBALT_CALL_ENTRY(serialdbg),
        __COBALT_CALL_ENTRY(sysconf),
-       __COBALT_CALL_ENTRY(sysctl)
+       __COBALT_CALL_ENTRY(sysctl),
+       __COBALT_CALL_ENTRY(fcntl),
 #ifdef CONFIG_XENO_ARCH_SYS3264
 #include <asm/xenomai/syscall32-table.h>
-#endif 
+#endif
 };
 
 static const int cobalt_sysmodes[] = {
@@ -716,6 +717,7 @@ static const int cobalt_sysmodes[] = {
        __COBALT_MODE(serialdbg, current),
        __COBALT_MODE(sysconf, current),
        __COBALT_MODE(sysctl, probing),
+       __COBALT_MODE(fcntl, current),
 };
 
 static int handle_head_syscall(struct ipipe_domain *ipd, struct pt_regs *regs)
@@ -893,7 +895,7 @@ linux_syscall:
 
 bad_syscall:
        printk(XENO_WARN "bad syscall <%#lx>\n", __xn_syscall(regs));
-       
+
        __xn_error_return(regs, -ENOSYS);
 
        return KEVENT_STOP;
diff --git a/kernel/cobalt/rtdm/fd.c b/kernel/cobalt/rtdm/fd.c
index 61ace15..7e64457 100644
--- a/kernel/cobalt/rtdm/fd.c
+++ b/kernel/cobalt/rtdm/fd.c
@@ -33,6 +33,8 @@
 #include "posix/process.h"
 #include "posix/syscall.h"
 
+#define RTDM_SETFL_MASK (O_NONBLOCK)
+
 DEFINE_PRIVATE_XNLOCK(fdtree_lock);
 static LIST_HEAD(rtdm_fd_cleanup_queue);
 static struct semaphore rtdm_fd_cleanup_sem;
@@ -355,6 +357,40 @@ void rtdm_fd_unlock(struct rtdm_fd *fd)
 }
 EXPORT_SYMBOL_GPL(rtdm_fd_unlock);
 
+int rtdm_fd_fcntl(int ufd, int cmd, ...)
+{
+       struct rtdm_fd *fd;
+       va_list ap;
+       int arg;
+       int ret;
+
+       fd = rtdm_fd_get(ufd, 0);
+       if (IS_ERR(fd))
+               return PTR_ERR(fd);
+
+       va_start(ap, cmd);
+       arg = va_arg(ap, int);
+       va_end(ap);
+
+       switch (cmd) {
+       case F_GETFL:
+               ret = fd->oflags;
+               break;
+       case F_SETFL:
+               fd->oflags = (fd->oflags & ~RTDM_SETFL_MASK) |
+                       (arg & RTDM_SETFL_MASK);
+               ret = 0;
+               break;
+       default:
+               ret = -EINVAL;
+       }
+
+       rtdm_fd_put(fd);
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(rtdm_fd_fcntl);
+
 int rtdm_fd_ioctl(int ufd, unsigned int request, ...)
 {
        struct rtdm_fd *fd;
@@ -649,7 +685,7 @@ int rtdm_fd_select(int ufd, struct xnselector *selector,
                   unsigned int type)
 {
        struct rtdm_fd *fd;
-       int rc;
+       int ret;
 
        fd = rtdm_fd_get(ufd, 0);
        if (IS_ERR(fd))
@@ -657,14 +693,14 @@ int rtdm_fd_select(int ufd, struct xnselector *selector,
 
        set_compat_bit(fd);
 
-       rc = fd->ops->select(fd, selector, type, ufd);
+       ret = fd->ops->select(fd, selector, type, ufd);
 
        if (!XENO_ASSERT(COBALT, !spltest()))
                splnone();
 
        rtdm_fd_put(fd);
 
-       return rc;
+       return ret;
 }
 
 static void destroy_fd(void *cookie, struct xnid *id)
diff --git a/lib/cobalt/cobalt.wrappers b/lib/cobalt/cobalt.wrappers
index 329ff3b..ee13bcf 100644
--- a/lib/cobalt/cobalt.wrappers
+++ b/lib/cobalt/cobalt.wrappers
@@ -105,3 +105,4 @@
 --wrap sleep
 --wrap mmap
 --wrap time
+--wrap fcntl
diff --git a/lib/cobalt/rtdm.c b/lib/cobalt/rtdm.c
index f5432f7..26c271a 100644
--- a/lib/cobalt/rtdm.c
+++ b/lib/cobalt/rtdm.c
@@ -111,6 +111,24 @@ static int do_ioctl(int fd, unsigned long request, void 
*arg)
        return ret;
 }
 
+COBALT_IMPL(int, fcntl, (int fd, int cmd, ...))
+{
+       va_list ap;
+       int arg;
+       int ret;
+
+       va_start(ap, cmd);
+       arg = va_arg(ap, int);
+       va_end(ap);
+
+       ret = XENOMAI_SYSCALL3(sc_cobalt_fcntl, fd, cmd, arg);
+
+       if (ret != -EBADF && ret != -ENOSYS)
+               return set_errno(ret);
+
+       return __STD(fcntl(fd, cmd, arg));
+}
+
 COBALT_IMPL(int, ioctl, (int fd, unsigned long int request, ...))
 {
        va_list ap;
diff --git a/lib/cobalt/wrappers.c b/lib/cobalt/wrappers.c
index 47c67e1..30522a4 100644
--- a/lib/cobalt/wrappers.c
+++ b/lib/cobalt/wrappers.c
@@ -170,6 +170,19 @@ int __real_close(int fd)
 }
 
 __weak
+int __real_fcntl(int fd, int cmd, ...)
+{
+       va_list ap;
+       int arg;
+
+       va_start(ap, cmd);
+       arg = va_arg(ap, int);
+       va_end(ap);
+
+       return fcntl(fd, cmd, arg);
+}
+
+__weak
 int __real_ioctl(int fd, unsigned long int request, ...)
 {
        va_list ap;


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to