From 3b1cc69d68bd25cf23e7d1ac16d55533379bce30 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 26 Sep 2018 06:57:49 -0600 Subject: [PATCH] include/nutt: Fix definitions used to access OS functions within the libraries. In the FLAT build, we must always set the errno and/or create cancellation points because the same library functions are used within the OS as are used by applications. This could cause issues for the OS but corrects some problems at the user interface. Noted by Federico Braghiroli in Bitbucket issue 121. --- include/nuttx/fs/fs.h | 13 +++++++++---- include/nuttx/mqueue.h | 12 +++++------- include/nuttx/net/net.h | 7 ++++++- include/nuttx/sched.h | 7 ++++++- include/nuttx/semaphore.h | 11 +++++------ include/nuttx/signal.h | 7 ++++++- 6 files changed, 37 insertions(+), 20 deletions(-) diff --git a/include/nuttx/fs/fs.h b/include/nuttx/fs/fs.h index 82de23a870..23313d9786 100644 --- a/include/nuttx/fs/fs.h +++ b/include/nuttx/fs/fs.h @@ -73,16 +73,21 @@ * (libuc.a and libunx.a). The that case, the correct interface must be * used for the build context. * - * The interfaces open(), close(), creat(), read(), pread(), write(), - * pwrite(), poll(), select(), fcntl(), and aio_suspend() are all - * cancellation points. + * REVISIT: In the flat build, the same functions must be used both by + * the OS and by applications. We have to use the normal user functions + * in this case or we will fail to set the errno or fail to create the + * cancellation point. + * + * The interfaces close(), creat(), read(), pread(), write(), pwrite(), + * poll(), select(), fcntl(), and aio_suspend() are all cancellation + * points. * * REVISIT: These cancellation points are an issue and may cause * violations: It use of these internally will cause the calling function * to become a cancellation points! */ -#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__) +#if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__) # ifdef CONFIG_CPP_HAVE_VARARGS # define _NX_OPEN(p,f,...) nx_open(p,f,##__VA_ARGS__) # else diff --git a/include/nuttx/mqueue.h b/include/nuttx/mqueue.h index 9c6a650c28..c33f1768aa 100644 --- a/include/nuttx/mqueue.h +++ b/include/nuttx/mqueue.h @@ -68,15 +68,13 @@ * (libuc.a and libunx.a). The that case, the correct interface must be * used for the build context. * - * The interfaces sigtimedwait(), sigwait(), sigwaitinfo(), sleep(), - * nanosleep(), and usleep() are cancellation points. - * - * REVISIT: The fact that these interfaces are cancellation points is an - * issue and may cause violations: It use of these internally will cause - * the calling function to become a cancellation points! + * REVISIT: In the flat build, the same functions must be used both by + * the OS and by applications. We have to use the normal user functions + * in this case or we will fail to set the errno or fail to create the + * cancellation point. */ -#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__) +#if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__) # define _MQ_SEND(d,m,l,p) nxmq_send(d,m,l,p) # define _MQ_TIMEDSEND(d,m,l,p,t) nxmq_timedsend(d,m,l,p,t) # define _MQ_RECEIVE(d,m,l,p) nxmq_receive(d,m,l,p) diff --git a/include/nuttx/net/net.h b/include/nuttx/net/net.h index 93569abae1..081424bb12 100644 --- a/include/nuttx/net/net.h +++ b/include/nuttx/net/net.h @@ -65,6 +65,11 @@ * (libuc.a and libunx.a). The that case, the correct interface must be * used for the build context. * + * REVISIT: In the flat build, the same functions must be used both by + * the OS and by applications. We have to use the normal user functions + * in this case or we will fail to set the errno or fail to create the + * cancellation point. + * * The interfaces accept(), read(), recv(), recvfrom(), write(), send(), * sendto() are all cancellation points. * @@ -73,7 +78,7 @@ * to become a cancellation points! */ -#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__) +#if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__) # define _NX_SEND(s,b,l,f) nx_send(s,b,l,f) # define _NX_RECV(s,b,l,f) nx_recv(s,b,l,f) # define _NX_RECVFROM(s,b,l,f,a,n) nx_recvfrom(s,b,l,f,a,n) diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h index ebac8152ac..17fb370622 100644 --- a/include/nuttx/sched.h +++ b/include/nuttx/sched.h @@ -188,9 +188,14 @@ * used both by the OS (libkc.a and libknx.a) or by the applications * (libuc.a and libunx.a). The that case, the correct interface must be * used for the build context. + * + * REVISIT: In the flat build, the same functions must be used both by + * the OS and by applications. We have to use the normal user functions + * in this case or we will fail to set the errno or fail to create the + * cancellation point. */ -#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__) +#if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__) # define _SCHED_GETPARAM(t,p) nxsched_getparam(t,p) # define _SCHED_SETPARAM(t,p) nxsched_setparam(t,p) # define _SCHED_GETSCHEDULER(t) nxsched_getscheduler(t) diff --git a/include/nuttx/semaphore.h b/include/nuttx/semaphore.h index 4a44f2f4ea..0b0fc8dbf6 100644 --- a/include/nuttx/semaphore.h +++ b/include/nuttx/semaphore.h @@ -68,14 +68,13 @@ * (libuc.a and libunx.a). The that case, the correct interface must be * used for the build context. * - * The interfaces sem_wait() and sem_timedwait() are cancellation points. - * - * REVISIT: The fact that sem_wait() and sem_timedwait() are cancellation - * points is an issue and may cause violations: It use of these internally - * will cause the calling function to become a cancellation points! + * REVISIT: In the flat build, the same functions must be used both by + * the OS and by applications. We have to use the normal user functions + * in this case or we will fail to set the errno or fail to create the + * cancellation point. */ -#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__) +#if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__) # define _SEM_INIT(s,p,c) nxsem_init(s,p,c) # define _SEM_DESTROY(s) nxsem_destroy(s) # define _SEM_WAIT(s) nxsem_wait(s) diff --git a/include/nuttx/signal.h b/include/nuttx/signal.h index fda07825a6..8d48adda23 100644 --- a/include/nuttx/signal.h +++ b/include/nuttx/signal.h @@ -61,6 +61,11 @@ * (libuc.a and libunx.a). The that case, the correct interface must be * used for the build context. * + * REVISIT: In the flat build, the same functions must be used both by + * the OS and by applications. We have to use the normal user functions + * in this case or we will fail to set the errno or fail to create the + * cancellation point. + * * The interfaces sigtimedwait(), sigwait(), sigwaitinfo(), sleep(), * nanosleep(), and usleep() are cancellation points. * @@ -69,7 +74,7 @@ * the calling function to become a cancellation points! */ -#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__) +#if !defined(CONFIG_BUILD_FLAT) && defined(__KERNEL__) # define _SIG_PROCMASK(h,s,o) nxsig_procmask(h,s,o) # define _SIG_SIGACTION(s,a,o) nxsig_action(s,a,o,false) # define _SIG_QUEUE(p,s,v) nxsig_queue(p,s,v)