From d8db596b3b59b876d710db7c77e0e5ea37ceb46d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 3 Jun 2015 09:24:17 -0600 Subject: [PATCH] POSIX message queues: Move mq_setattr() and mq_getattr() from nuttx/libc/mqueue to nuttx/sched/mqueue. Also add sysyscall support for mq_setattr() and mq_getattr(). This is necessary in protected and kernel builds because in those cases the message queue structure is protect and cannot be accessed directly from user mode code. Noted by Jouko Holopainen. --- include/sys/syscall.h | 18 ++++++----- libc/Makefile | 1 - libc/README.txt | 1 - libc/libc.csv | 2 -- libc/mqueue/Make.defs | 48 ----------------------------- sched/mqueue/Make.defs | 3 +- {libc => sched}/mqueue/mq_getattr.c | 24 ++------------- {libc => sched}/mqueue/mq_setattr.c | 24 ++------------- syscall/syscall.csv | 2 ++ syscall/syscall_lookup.h | 2 ++ syscall/syscall_stublookup.c | 3 ++ 11 files changed, 23 insertions(+), 105 deletions(-) delete mode 100644 libc/mqueue/Make.defs rename {libc => sched}/mqueue/mq_getattr.c (75%) rename {libc => sched}/mqueue/mq_setattr.c (77%) diff --git a/include/sys/syscall.h b/include/sys/syscall.h index 7d9dccd4a5..d21eba24e5 100644 --- a/include/sys/syscall.h +++ b/include/sys/syscall.h @@ -379,14 +379,16 @@ #ifndef CONFIG_DISABLE_MQUEUE # define SYS_mq_close (__SYS_mqueue+0) -# define SYS_mq_notify (__SYS_mqueue+1) -# define SYS_mq_open (__SYS_mqueue+2) -# define SYS_mq_receive (__SYS_mqueue+3) -# define SYS_mq_send (__SYS_mqueue+4) -# define SYS_mq_timedreceive (__SYS_mqueue+5) -# define SYS_mq_timedsend (__SYS_mqueue+6) -# define SYS_mq_unlink (__SYS_mqueue+7) -# define __SYS_environ (__SYS_mqueue+8) +# define SYS_mq_getattr (__SYS_mqueue+1) +# define SYS_mq_notify (__SYS_mqueue+2) +# define SYS_mq_open (__SYS_mqueue+3) +# define SYS_mq_receive (__SYS_mqueue+4) +# define SYS_mq_send (__SYS_mqueue+5) +# define SYS_mq_setattr (__SYS_mqueue+6) +# define SYS_mq_timedreceive (__SYS_mqueue+7) +# define SYS_mq_timedsend (__SYS_mqueue+8) +# define SYS_mq_unlink (__SYS_mqueue+9) +# define __SYS_environ (__SYS_mqueue+10) #else # define __SYS_environ __SYS_mqueue #endif diff --git a/libc/Makefile b/libc/Makefile index b1082dd514..ee1dbc9d28 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -71,7 +71,6 @@ include aio/Make.defs include pthread/Make.defs include semaphore/Make.defs include signal/Make.defs -include mqueue/Make.defs include math/Make.defs include fixedmath/Make.defs include net/Make.defs diff --git a/libc/README.txt b/libc/README.txt index 8e8fa9f733..6ccc1dd53b 100644 --- a/libc/README.txt +++ b/libc/README.txt @@ -32,7 +32,6 @@ we have: libgen - libgen.h fixedmath - fixedmath.h math - math.h - mqueue - pthread.h net - Various network-related header files: netinet/ether.h, arpa/inet.h pthread - pthread.h queue - queue.h diff --git a/libc/libc.csv b/libc/libc.csv index 605989c2af..69e4e4ef4a 100644 --- a/libc/libc.csv +++ b/libc/libc.csv @@ -75,8 +75,6 @@ "memmove","string.h","","FAR void","FAR void *","FAR const void *","size_t" "memset","string.h","","FAR void","FAR void *","int c","size_t" "mktime","time.h","","time_t","const struct tm *" -"mq_getattr","mqueue.h","!defined(CONFIG_DISABLE_MQUEUE)","int","mqd_t","struct mq_attr *" -"mq_setattr","mqueue.h","!defined(CONFIG_DISABLE_MQUEUE)","int","mqd_t","const struct mq_attr *","struct mq_attr *" "ntohl","arpa/inet.h","","uint32_t","uint32_t" "ntohs","arpa/inet.h","","uint16_t","uint16_t" "perror","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","void","FAR const char *" diff --git a/libc/mqueue/Make.defs b/libc/mqueue/Make.defs deleted file mode 100644 index 826970fa32..0000000000 --- a/libc/mqueue/Make.defs +++ /dev/null @@ -1,48 +0,0 @@ -############################################################################ -# libc/mqueue/Make.defs -# -# Copyright (C) 2011-2012 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. -# -############################################################################ - -ifneq ($(CONFIG_DISABLE_MQUEUE),y) - -# Add the mqueue C files to the build - -CSRCS += mq_setattr.c mq_getattr.c - -# Add the mqueue directory to the build - -DEPPATH += --dep-path mqueue -VPATH += :mqueue - -endif - diff --git a/sched/mqueue/Make.defs b/sched/mqueue/Make.defs index 6d38476893..ef2aaf0ff7 100644 --- a/sched/mqueue/Make.defs +++ b/sched/mqueue/Make.defs @@ -38,7 +38,8 @@ ifneq ($(CONFIG_DISABLE_MQUEUE),y) CSRCS += mq_send.c mq_timedsend.c mq_sndinternal.c mq_receive.c CSRCS += mq_timedreceive.c mq_rcvinternal.c mq_initialize.c CSRCS += mq_descreate.c mq_desclose.c mq_msgfree.c mq_msgqalloc.c -CSRCS += mq_msgqfree.c mq_release.c mq_recover.c +CSRCS += mq_msgqfree.c mq_release.c mq_recover.c mq_setattr.c +CSRCS += mq_getattr.c ifneq ($(CONFIG_DISABLE_SIGNALS),y) CSRCS += mq_waitirq.c mq_notify.c diff --git a/libc/mqueue/mq_getattr.c b/sched/mqueue/mq_getattr.c similarity index 75% rename from libc/mqueue/mq_getattr.c rename to sched/mqueue/mq_getattr.c index 0a3a0fed55..9e997dfe36 100644 --- a/libc/mqueue/mq_getattr.c +++ b/sched/mqueue/mq_getattr.c @@ -1,7 +1,7 @@ /************************************************************************ - * libc/mqueue/mq_getattr.c + * sched/mqueue/mq_getattr.c * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2011, 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -42,26 +42,6 @@ #include #include -/************************************************************************ - * Pre-processor Definitions - ************************************************************************/ - -/************************************************************************ - * Private Type Declarations - ************************************************************************/ - -/************************************************************************ - * Global Variables - ************************************************************************/ - -/************************************************************************ - * Private Variables - ************************************************************************/ - -/************************************************************************ - * Private Functions - ************************************************************************/ - /************************************************************************ * Public Functions ************************************************************************/ diff --git a/libc/mqueue/mq_setattr.c b/sched/mqueue/mq_setattr.c similarity index 77% rename from libc/mqueue/mq_setattr.c rename to sched/mqueue/mq_setattr.c index 03b01f1933..858621a15c 100644 --- a/libc/mqueue/mq_setattr.c +++ b/sched/mqueue/mq_setattr.c @@ -1,7 +1,7 @@ /************************************************************************ - * libc/mqueue/mq_setattr.c + * sched/mqueue/mq_setattr.c * - * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2011, 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -44,26 +44,6 @@ #include -/************************************************************************ - * Pre-processor Definitions - ************************************************************************/ - -/************************************************************************ - * Private Type Declarations - ************************************************************************/ - -/************************************************************************ - * Global Variables - ************************************************************************/ - -/************************************************************************ - * Private Variables - ************************************************************************/ - -/************************************************************************ - * Private Functions - ************************************************************************/ - /************************************************************************ * Public Functions ************************************************************************/ diff --git a/syscall/syscall.csv b/syscall/syscall.csv index 7d386b954a..82389b36f1 100644 --- a/syscall/syscall.csv +++ b/syscall/syscall.csv @@ -36,10 +36,12 @@ "mmap","sys/mman.h","CONFIG_NFILE_DESCRIPTORS > 0","FAR void*","FAR void*","size_t","int","int","int","off_t" "mount","sys/mount.h","CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FS_READABLE)","int","const char*","const char*","const char*","unsigned long","const void*" "mq_close","mqueue.h","!defined(CONFIG_DISABLE_MQUEUE)","int","mqd_t" +"mq_getattr","mqueue.h","!defined(CONFIG_DISABLE_MQUEUE)","int","mqd_t","struct mq_attr *" "mq_notify","mqueue.h","!defined(CONFIG_DISABLE_SIGNALS) && !defined(CONFIG_DISABLE_MQUEUE)","int","mqd_t","const struct sigevent*" "mq_open","mqueue.h","!defined(CONFIG_DISABLE_MQUEUE)","mqd_t","const char*","int","..." "mq_receive","mqueue.h","!defined(CONFIG_DISABLE_MQUEUE)","ssize_t","mqd_t","char*","size_t","int*" "mq_send","mqueue.h","!defined(CONFIG_DISABLE_MQUEUE)","int","mqd_t","const char*","size_t","int" +"mq_setattr","mqueue.h","!defined(CONFIG_DISABLE_MQUEUE)","int","mqd_t","const struct mq_attr *","struct mq_attr *" "mq_timedreceive","mqueue.h","!defined(CONFIG_DISABLE_MQUEUE)","ssize_t","mqd_t","char*","size_t","int*","const struct timespec*" "mq_timedsend","mqueue.h","!defined(CONFIG_DISABLE_MQUEUE)","int","mqd_t","const char*","size_t","int","const struct timespec*" "mq_unlink","mqueue.h","!defined(CONFIG_DISABLE_MQUEUE)","int","const char*" diff --git a/syscall/syscall_lookup.h b/syscall/syscall_lookup.h index 86b71cdcb3..b3838689ef 100644 --- a/syscall/syscall_lookup.h +++ b/syscall/syscall_lookup.h @@ -277,10 +277,12 @@ SYSCALL_LOOKUP(up_assert, 2, STUB_up_assert) #ifndef CONFIG_DISABLE_MQUEUE SYSCALL_LOOKUP(mq_close, 1, STUB_mq_close) + SYSCALL_LOOKUP(mq_getattr, 2, STUB_mq_getattr) SYSCALL_LOOKUP(mq_notify, 2, STUB_mq_notify) SYSCALL_LOOKUP(mq_open, 6, STUB_mq_open) SYSCALL_LOOKUP(mq_receive, 4, STUB_mq_receive) SYSCALL_LOOKUP(mq_send, 4, STUB_mq_send) + SYSCALL_LOOKUP(mq_setattr, 3, STUB_mq_setattr) SYSCALL_LOOKUP(mq_timedreceive, 5, STUB_mq_timedreceive) SYSCALL_LOOKUP(mq_timedsend, 5, STUB_mq_timedsend) SYSCALL_LOOKUP(mq_unlink, 1, STUB_mq_unlink) diff --git a/syscall/syscall_stublookup.c b/syscall/syscall_stublookup.c index 00945eee49..aa9d17a508 100644 --- a/syscall/syscall_stublookup.c +++ b/syscall/syscall_stublookup.c @@ -289,6 +289,7 @@ uintptr_t STUB_pthread_sigmask(int nbr, uintptr_t parm1, uintptr_t parm2, /* The following are defined only if message queues are enabled */ uintptr_t STUB_mq_close(int nbr, uintptr_t parm1); +uintptr_t STUB_mq_getattr(int nbr, uintptr_t parm1, uintptr_t parm2); uintptr_t STUB_mq_notify(int nbr, uintptr_t parm1, uintptr_t parm2); uintptr_t STUB_mq_open(int nbr, uintptr_t parm1, uintptr_t parm2, uintptr_t parm3, uintptr_t parm4, uintptr_t parm5, @@ -297,6 +298,8 @@ uintptr_t STUB_mq_receive(int nbr, uintptr_t parm1, uintptr_t parm2, uintptr_t parm3, uintptr_t parm4); uintptr_t STUB_mq_send(int nbr, uintptr_t parm1, uintptr_t parm2, uintptr_t parm3, uintptr_t parm4); +uintptr_t STUB_mq_setattr(int nbr, uintptr_t parm1, uintptr_t parm2, + uintptr_t parm3); uintptr_t STUB_mq_timedreceive(int nbr, uintptr_t parm1, uintptr_t parm2, uintptr_t parm3, uintptr_t parm4, uintptr_t parm5); uintptr_t STUB_mq_timedsend(int nbr, uintptr_t parm1, uintptr_t parm2,