diff --git a/configs/spark/composite/defconfig b/configs/spark/composite/defconfig index 0dc4785c85..a9e5dc654f 100644 --- a/configs/spark/composite/defconfig +++ b/configs/spark/composite/defconfig @@ -644,6 +644,8 @@ CONFIG_ARCH_HAVE_NET=y CONFIG_DISABLE_PSEUDOFS_OPERATIONS=y CONFIG_FS_READABLE=y CONFIG_FS_WRITABLE=y +ONFIG_FS_NAMED_SEMAPHORES=y +CONFIG_FS_NAMED_SEMPATH="/var/sem" # CONFIG_FS_RAMMAP is not set CONFIG_FS_FAT=y CONFIG_FAT_LCNAMES=y diff --git a/configs/spark/nsh/defconfig b/configs/spark/nsh/defconfig index ae369d91e7..ba2f2c0009 100644 --- a/configs/spark/nsh/defconfig +++ b/configs/spark/nsh/defconfig @@ -644,6 +644,8 @@ CONFIG_ARCH_HAVE_NET=y CONFIG_DISABLE_PSEUDOFS_OPERATIONS=y CONFIG_FS_READABLE=y CONFIG_FS_WRITABLE=y +ONFIG_FS_NAMED_SEMAPHORES=y +CONFIG_FS_NAMED_SEMPATH="/var/sem" # CONFIG_FS_RAMMAP is not set CONFIG_FS_FAT=y CONFIG_FAT_LCNAMES=y diff --git a/configs/spark/usbmsc/defconfig b/configs/spark/usbmsc/defconfig index 75034aa95b..9dba9d6bcf 100644 --- a/configs/spark/usbmsc/defconfig +++ b/configs/spark/usbmsc/defconfig @@ -608,6 +608,8 @@ CONFIG_ARCH_HAVE_NET=y CONFIG_DISABLE_PSEUDOFS_OPERATIONS=y CONFIG_FS_READABLE=y CONFIG_FS_WRITABLE=y +ONFIG_FS_NAMED_SEMAPHORES=y +CONFIG_FS_NAMED_SEMPATH="/var/sem" # CONFIG_FS_RAMMAP is not set CONFIG_FS_FAT=y CONFIG_FAT_LCNAMES=y diff --git a/configs/spark/usbnsh/defconfig b/configs/spark/usbnsh/defconfig index c45baddfe4..af299c3e78 100644 --- a/configs/spark/usbnsh/defconfig +++ b/configs/spark/usbnsh/defconfig @@ -598,6 +598,8 @@ CONFIG_CDCACM_PRODUCTSTR="CDC/ACM Serial" CONFIG_DISABLE_PSEUDOFS_OPERATIONS=y CONFIG_FS_READABLE=y CONFIG_FS_WRITABLE=y +ONFIG_FS_NAMED_SEMAPHORES=y +CONFIG_FS_NAMED_SEMPATH="/var/sem" # CONFIG_FS_RAMMAP is not set CONFIG_FS_FAT=y # CONFIG_FAT_LCNAMES is not set diff --git a/configs/spark/usbserial/defconfig b/configs/spark/usbserial/defconfig index b3cf0a90c0..d9dce6ff95 100644 --- a/configs/spark/usbserial/defconfig +++ b/configs/spark/usbserial/defconfig @@ -618,6 +618,8 @@ CONFIG_ARCH_HAVE_NET=y CONFIG_DISABLE_PSEUDOFS_OPERATIONS=y CONFIG_FS_READABLE=y CONFIG_FS_WRITABLE=y +ONFIG_FS_NAMED_SEMAPHORES=y +CONFIG_FS_NAMED_SEMPATH="/var/sem" # CONFIG_FS_RAMMAP is not set CONFIG_FS_FAT=y CONFIG_FAT_LCNAMES=y diff --git a/fs/Kconfig b/fs/Kconfig index 12a68e36b1..cbb7c6ed91 100644 --- a/fs/Kconfig +++ b/fs/Kconfig @@ -48,6 +48,7 @@ config FS_WRITABLE bool default n +source fs/semaphore/Kconfig source fs/mmap/Kconfig source fs/fat/Kconfig source fs/nfs/Kconfig diff --git a/fs/semaphore/Kconfig b/fs/semaphore/Kconfig new file mode 100644 index 0000000000..abf0bb9bed --- /dev/null +++ b/fs/semaphore/Kconfig @@ -0,0 +1,20 @@ +# +# For a description of the syntax of this configuration file, +# see misc/tools/kconfig-language.txt. +# + +config FS_NAMED_SEMAPHORES + bool "Named semaphore support" + default n + ---help--- + Include support for named semaphores. + +if FS_NAMED_SEMAPHORES + +config FS_NAMED_SEMPATH + string "Path to semaphore storage" + default "/var/sem" + ---help--- + The path to where named semaphores will exist in the VFS namespace. + +endif # FS_NAMED_SEMAPHORES diff --git a/fs/semaphore/Make.defs b/fs/semaphore/Make.defs new file mode 100644 index 0000000000..1664abf286 --- /dev/null +++ b/fs/semaphore/Make.defs @@ -0,0 +1,45 @@ +############################################################################ +# fs/semaphore/Make.defs +# +# Copyright (C) 2014 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +# Include named semaphore support + +ifneq ($(CONFIG_FS_NAMED_SEMAPHORES),0) + +# Include named semaphore build support + +DEPPATH += --dep-path semaphore +VPATH += :semaphore +CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)fs$(DELIM)semaphore} +endif diff --git a/include/semaphore.h b/include/semaphore.h index 99f0678248..5818f0fb7e 100644 --- a/include/semaphore.h +++ b/include/semaphore.h @@ -129,15 +129,18 @@ struct timespec; /* Defined in time.h */ int sem_init(FAR sem_t *sem, int pshared, unsigned int value); int sem_destroy(FAR sem_t *sem); -FAR sem_t *sem_open(FAR const char *name, int oflag, ...); -int sem_close(FAR sem_t *sem); -int sem_unlink(FAR const char *name); int sem_wait(FAR sem_t *sem); int sem_timedwait(FAR sem_t *sem, FAR const struct timespec *abstime); int sem_trywait(FAR sem_t *sem); int sem_post(FAR sem_t *sem); int sem_getvalue(FAR sem_t *sem, FAR int *sval); +#ifdef CONFIG_FS_NAMED_SEMAPHORES +FAR sem_t *sem_open(FAR const char *name, int oflag, ...); +int sem_close(FAR sem_t *sem); +int sem_unlink(FAR const char *name); +#endif + #undef EXTERN #ifdef __cplusplus } diff --git a/include/sys/syscall.h b/include/sys/syscall.h index 6a350eb0a5..4a85ee3310 100644 --- a/include/sys/syscall.h +++ b/include/sys/syscall.h @@ -80,31 +80,42 @@ #define SYS_sched_setscheduler (CONFIG_SYS_RESERVED+10) #define SYS_sched_unlock (CONFIG_SYS_RESERVED+11) #define SYS_sched_yield (CONFIG_SYS_RESERVED+12) -#define SYS_sem_close (CONFIG_SYS_RESERVED+13) +#define SYS_set_errno (CONFIG_SYS_RESERVED+13) + +/* Semaphores */ + #define SYS_sem_destroy (CONFIG_SYS_RESERVED+14) -#define SYS_sem_open (CONFIG_SYS_RESERVED+15) -#define SYS_sem_post (CONFIG_SYS_RESERVED+16) -#define SYS_sem_timedwait (CONFIG_SYS_RESERVED+17) -#define SYS_sem_trywait (CONFIG_SYS_RESERVED+18) -#define SYS_sem_unlink (CONFIG_SYS_RESERVED+19) -#define SYS_sem_wait (CONFIG_SYS_RESERVED+20) -#define SYS_set_errno (CONFIG_SYS_RESERVED+21) +#define SYS_sem_post (CONFIG_SYS_RESERVED+15) +#define SYS_sem_timedwait (CONFIG_SYS_RESERVED+16) +#define SYS_sem_trywait (CONFIG_SYS_RESERVED+17) +#define SYS_sem_wait (CONFIG_SYS_RESERVED+18) + +/* Named semaphores */ + +#ifdef CONFIG_FS_NAMED_SEMAPHORES +# define SYS_sem_open (CONFIG_SYS_RESERVED+19) +# define SYS_sem_close (CONFIG_SYS_RESERVED+20) +# define SYS_sem_unlink (CONFIG_SYS_RESERVED+21) +# define __SYS_task_create (CONFIG_SYS_RESERVED+22) +#else +# define __SYS_task_create (CONFIG_SYS_RESERVED+19) +#endif /* Task creation APIs based on global entry points cannot be use with * address environments. */ #ifndef CONFIG_BUILD_KERNEL -# define SYS_task_create (CONFIG_SYS_RESERVED+22) -# define __SYS_task_delete (CONFIG_SYS_RESERVED+23) +# define SYS_task_create __SYS_task_create +# define __SYS_task_delete (__SYS_task_create+1) /* pgalloc() is only available with address environments with the page * allocator selected. MMU support from the CPU is also required. */ #else -# define SYS_pgalloc (CONFIG_SYS_RESERVED+22) -# define __SYS_task_delete (CONFIG_SYS_RESERVED+23) +# define SYS_pgalloc __SYS_task_create +# define __SYS_task_delete (__SYS_task_create+1) #endif # define SYS_task_delete __SYS_task_delete diff --git a/syscall/syscall.csv b/syscall/syscall.csv index 56f8518ed4..218f33ae3c 100644 --- a/syscall/syscall.csv +++ b/syscall/syscall.csv @@ -99,13 +99,13 @@ "sched_yield","sched.h","","int" "seekdir","dirent.h","CONFIG_NFILE_DESCRIPTORS > 0","void","FAR DIR*","off_t" "select","sys/select.h","!defined(CONFIG_DISABLE_POLL) && (CONFIG_NSOCKET_DESCRIPTORS > 0 || CONFIG_NFILE_DESCRIPTORS > 0)","int","int","FAR fd_set*","FAR fd_set*","FAR fd_set*","FAR struct timeval*" -"sem_close","semaphore.h","","int","FAR sem_t*" +"sem_close","semaphore.h","defined(CONFIG_FS_NAMED_SEMAPHORES)","int","FAR sem_t*" "sem_destroy","semaphore.h","","int","FAR sem_t*" -"sem_open","semaphore.h","","FAR sem_t*","FAR const char*","int","..." +"sem_open","semaphore.h","defined(CONFIG_FS_NAMED_SEMAPHORES)","FAR sem_t*","FAR const char*","int","..." "sem_post","semaphore.h","","int","FAR sem_t*" "sem_timedwait","semaphore.h","","int","FAR sem_t*","FAR const struct timespec *" "sem_trywait","semaphore.h","","int","FAR sem_t*" -"sem_unlink","semaphore.h","","int","FAR const char*" +"sem_unlink","semaphore.h","defined(CONFIG_FS_NAMED_SEMAPHORES)","int","FAR const char*" "sem_wait","semaphore.h","","int","FAR sem_t*" "send","sys/socket.h","CONFIG_NSOCKET_DESCRIPTORS > 0 && defined(CONFIG_NET)","ssize_t","int","FAR const void*","size_t","int" "sendfile","sys/sendfile.h","CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_NET_SENDFILE)","ssize_t","int","int","FAR off_t*","size_t" diff --git a/syscall/syscall_lookup.h b/syscall/syscall_lookup.h index 9b14f91158..ad5d0495c2 100644 --- a/syscall/syscall_lookup.h +++ b/syscall/syscall_lookup.h @@ -56,15 +56,24 @@ SYSCALL_LOOKUP(sched_setparam, 2, STUB_sched_setparam) SYSCALL_LOOKUP(sched_setscheduler, 3, STUB_sched_setscheduler) SYSCALL_LOOKUP(sched_unlock, 0, STUB_sched_unlock) SYSCALL_LOOKUP(sched_yield, 0, STUB_sched_yield) -SYSCALL_LOOKUP(sem_close, 1, STUB_sem_close) +SYSCALL_LOOKUP(set_errno, 1, STUB_set_errno) + +/* Semaphores */ + SYSCALL_LOOKUP(sem_destroy, 2, STUB_sem_destroy) -SYSCALL_LOOKUP(sem_open, 6, STUB_sem_open) SYSCALL_LOOKUP(sem_post, 1, STUB_sem_post) SYSCALL_LOOKUP(sem_timedwait, 2, STUB_sem_timedwait) SYSCALL_LOOKUP(sem_trywait, 1, STUB_sem_trywait) -SYSCALL_LOOKUP(sem_unlink, 1, STUB_sem_unlink) SYSCALL_LOOKUP(sem_wait, 1, STUB_sem_wait) -SYSCALL_LOOKUP(set_errno, 1, STUB_set_errno) + +/* Named semaphores */ + +#ifdef defined(CONFIG_FS_NAMED_SEMAPHORES) +SYSCALL_LOOKUP(sem_open, 6, STUB_sem_open) +SYSCALL_LOOKUP(sem_close, 1, STUB_sem_close) +SYSCALL_LOOKUP(sem_unlink, 1, STUB_sem_unlink) +#endif + #ifndef CONFIG_BUILD_KERNEL SYSCALL_LOOKUP(task_create, 5, STUB_task_create) #else