diff options
-rwxr-xr-x | nuttx/ChangeLog | 7 | ||||
-rw-r--r-- | nuttx/fs/mqueue/mq_open.c | 13 | ||||
-rw-r--r-- | nuttx/include/mqueue.h | 39 | ||||
-rw-r--r-- | nuttx/sched/mqueue/mq_msgqalloc.c | 32 | ||||
-rw-r--r-- | nuttx/sched/mqueue/mq_rcvinternal.c | 4 | ||||
-rw-r--r-- | nuttx/sched/mqueue/mq_receive.c | 5 | ||||
-rw-r--r-- | nuttx/sched/mqueue/mq_send.c | 6 | ||||
-rw-r--r-- | nuttx/sched/mqueue/mq_sndinternal.c | 7 | ||||
-rw-r--r-- | nuttx/sched/mqueue/mq_timedreceive.c | 6 | ||||
-rw-r--r-- | nuttx/sched/mqueue/mq_timedsend.c | 5 | ||||
-rw-r--r-- | nuttx/sched/mqueue/mqueue.h | 20 |
11 files changed, 74 insertions, 70 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 96aeb3354..43bf5fcd4 100755 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -9140,3 +9140,10 @@ * /drivers/eeprom/spi_xx25xx.c and /include/nuttx/eeprom/spi_xx25xx.h: Add support for ST Micro EEPROM device geometries. From Sebastien Lorquet (2014-12-5). + * sched/mqueue: msg type should be char * not void * in mq_send, + mq_timedsend, mq_receive, and mq_timedreceive. Noted by Pierre-Noel + Bouteville (2014-12-05). + * fs/mqueue/mq_open.c and sched/mqueue/mq_msgqalloc.c: In message queue + creation return ENOSPC error if size exceeds the configured size of + pre-allocated messages; Use ENOSPC vs ENOMEM per OpenGroup.org. From + Pierre-Noel Bouteville (2014-12-6). diff --git a/nuttx/fs/mqueue/mq_open.c b/nuttx/fs/mqueue/mq_open.c index 076971287..f2b95b9b5 100644 --- a/nuttx/fs/mqueue/mq_open.c +++ b/nuttx/fs/mqueue/mq_open.c @@ -52,17 +52,8 @@ #include "inode/inode.h" #include "mqueue/mqueue.h" -#if 0 -#include <sys/types.h> -#include <stdint.h> -#include <debug.h> - - -#include "sched/sched.h" -#endif - /**************************************************************************** - * Pre-procesor Definitions + * Pre-processor Definitions ****************************************************************************/ /**************************************************************************** @@ -220,7 +211,7 @@ mqd_t mq_open(FAR const char *mq_name, int oflags, ...) msgq = (FAR struct mqueue_inode_s*)mq_msgqalloc(mode, attr); if (!msgq) { - errcode = ENOMEM; + errcode = ENOSPC; goto errout_with_inode; } diff --git a/nuttx/include/mqueue.h b/nuttx/include/mqueue.h index e29dfb2c5..6719cbd42 100644 --- a/nuttx/include/mqueue.h +++ b/nuttx/include/mqueue.h @@ -69,33 +69,34 @@ struct mq_attr typedef FAR struct mq_des *mqd_t; /******************************************************************************** - * Global Variables - ********************************************************************************/ - -/******************************************************************************** - * Global Function Prototypes + * Public Data ********************************************************************************/ #ifdef __cplusplus #define EXTERN extern "C" -extern "C" { +extern "C" +{ #else #define EXTERN extern #endif -EXTERN mqd_t mq_open(const char *mq_name, int oflags, ...); -EXTERN int mq_close(mqd_t mqdes ); -EXTERN int mq_unlink(const char *mq_name); -EXTERN int mq_send(mqd_t mqdes, const void *msg, size_t msglen, int prio); -EXTERN int mq_timedsend(mqd_t mqdes, const char *msg, size_t msglen, int prio, - const struct timespec *abstime); -EXTERN ssize_t mq_receive(mqd_t mqdes, void *msg, size_t msglen, int *prio); -EXTERN ssize_t mq_timedreceive(mqd_t mqdes, void *msg, size_t msglen, - int *prio, const struct timespec *abstime); -EXTERN int mq_notify(mqd_t mqdes, const struct sigevent *notification); -EXTERN int mq_setattr(mqd_t mqdes, const struct mq_attr *mq_stat, - struct mq_attr *oldstat); -EXTERN int mq_getattr(mqd_t mqdes, struct mq_attr *mq_stat); +/******************************************************************************** + * Public Function Prototypes + ********************************************************************************/ + +mqd_t mq_open(FAR const char *mq_name, int oflags, ...); +int mq_close(mqd_t mqdes ); +int mq_unlink(FAR const char *mq_name); +int mq_send(mqd_t mqdes, FAR const char *msg, size_t msglen, int prio); +int mq_timedsend(mqd_t mqdes, FAR const char *msg, size_t msglen, int prio, + FAR const struct timespec *abstime); +ssize_t mq_receive(mqd_t mqdes, FAR char *msg, size_t msglen, FAR int *prio); +ssize_t mq_timedreceive(mqd_t mqdes, FAR char *msg, size_t msglen, FAR int *prio, + FAR const struct timespec *abstime); +int mq_notify(mqd_t mqdes, const struct sigevent *notification); +int mq_setattr(mqd_t mqdes, FAR const struct mq_attr *mq_stat, + FAR struct mq_attr *oldstat); +int mq_getattr(mqd_t mqdes, FAR struct mq_attr *mq_stat); #undef EXTERN #ifdef __cplusplus diff --git a/nuttx/sched/mqueue/mq_msgqalloc.c b/nuttx/sched/mqueue/mq_msgqalloc.c index 6b5cea76e..280f1f182 100644 --- a/nuttx/sched/mqueue/mq_msgqalloc.c +++ b/nuttx/sched/mqueue/mq_msgqalloc.c @@ -40,6 +40,7 @@ #include <nuttx/config.h> #include <mqueue.h> +#include <assert.h> #include <nuttx/kmalloc.h> #include <nuttx/sched.h> @@ -77,16 +78,16 @@ * * Description: * This function implements a part of the POSIX message queue open logic. - * It allocates and initializes a structu mqueue_inode_s structure. + * It allocates and initializes a struct mqueue_inode_s structure. * * Parameters: * mode - mode_t value is ignored * attr - The mq_maxmsg attribute is used at the time that the message * queue is created to determine the maximum number of - * messages that may be placed in the message queue. + * messages that may be placed in the message queue. * * Return Value: - * The allocated and initalized message queue structure or NULL in the + * The allocated and initialized message queue structure or NULL in the * event of a failure. * ****************************************************************************/ @@ -96,9 +97,21 @@ FAR struct mqueue_inode_s *mq_msgqalloc(mode_t mode, { FAR struct mqueue_inode_s *msgq; + /* Check if the caller is attempting to allocate a message for messages + * larger than the configured maximum message size. + */ + + DEBUGASSERT(!attr || attr->mq_msgsize <= MQ_MAX_BYTES); + if (attr && attr->mq_msgsize > MQ_MAX_BYTES) + { + return NULL; + } + /* Allocate memory for the new message queue. */ - msgq = (FAR struct mqueue_inode_s*)kmm_zalloc(sizeof(struct mqueue_inode_s)); + msgq = (FAR struct mqueue_inode_s*) + kmm_zalloc(sizeof(struct mqueue_inode_s)); + if (msgq) { /* Initialize the new named message queue */ @@ -106,15 +119,8 @@ FAR struct mqueue_inode_s *mq_msgqalloc(mode_t mode, sq_init(&msgq->msglist); if (attr) { - msgq->maxmsgs = (int16_t)attr->mq_maxmsg; - if (attr->mq_msgsize <= MQ_MAX_BYTES) - { - msgq->maxmsgsize = (int16_t)attr->mq_msgsize; - } - else - { - msgq->maxmsgsize = MQ_MAX_BYTES; - } + msgq->maxmsgs = (int16_t)attr->mq_maxmsg; + msgq->maxmsgsize = (int16_t)attr->mq_msgsize; } else { diff --git a/nuttx/sched/mqueue/mq_rcvinternal.c b/nuttx/sched/mqueue/mq_rcvinternal.c index bd0878700..9c69dfe64 100644 --- a/nuttx/sched/mqueue/mq_rcvinternal.c +++ b/nuttx/sched/mqueue/mq_rcvinternal.c @@ -103,7 +103,7 @@ * ****************************************************************************/ -int mq_verifyreceive(mqd_t mqdes, void *msg, size_t msglen) +int mq_verifyreceive(mqd_t mqdes, FAR char *msg, size_t msglen) { /* Verify the input parameters */ @@ -246,7 +246,7 @@ FAR struct mqueue_msg_s *mq_waitreceive(mqd_t mqdes) ****************************************************************************/ ssize_t mq_doreceive(mqd_t mqdes, FAR struct mqueue_msg_s *mqmsg, - FAR void *ubuffer, int *prio) + FAR char *ubuffer, int *prio) { FAR struct tcb_s *btcb; irqstate_t saved_state; diff --git a/nuttx/sched/mqueue/mq_receive.c b/nuttx/sched/mqueue/mq_receive.c index a146a39ac..8468daebd 100644 --- a/nuttx/sched/mqueue/mq_receive.c +++ b/nuttx/sched/mqueue/mq_receive.c @@ -112,7 +112,8 @@ * ************************************************************************/ -ssize_t mq_receive(mqd_t mqdes, void *msg, size_t msglen, int *prio) +ssize_t mq_receive(mqd_t mqdes, FAR char *msg, size_t msglen, + FAR int *prio) { FAR struct mqueue_msg_s *mqmsg; irqstate_t saved_state; @@ -129,7 +130,7 @@ ssize_t mq_receive(mqd_t mqdes, void *msg, size_t msglen, int *prio) return ERROR; } - /* Get the next mesage from the message queue. We will disable + /* Get the next message from the message queue. We will disable * pre-emption until we have completed the message received. This * is not too bad because if the receipt takes a long time, it will * be because we are blocked waiting for a message and pre-emption diff --git a/nuttx/sched/mqueue/mq_send.c b/nuttx/sched/mqueue/mq_send.c index 0b6a48d04..697e0a0ec 100644 --- a/nuttx/sched/mqueue/mq_send.c +++ b/nuttx/sched/mqueue/mq_send.c @@ -76,13 +76,13 @@ * Name: mq_send * * Description: - * This function adds the specificied message (msg) to the message queue + * This function adds the specified message (msg) to the message queue * (mqdes). The "msglen" parameter specifies the length of the message * in bytes pointed to by "msg." This length must not exceed the maximum * message length from the mq_getattr(). * * If the message queue is not full, mq_send() place the message in the - * message queue at the position indicated by the "prio" argrument. + * message queue at the position indicated by the "prio" argument. * Messages with higher priority will be inserted before lower priority * messages. The value of "prio" must not exceed MQ_PRIO_MAX. * @@ -115,7 +115,7 @@ * ****************************************************************************/ -int mq_send(mqd_t mqdes, const void *msg, size_t msglen, int prio) +int mq_send(mqd_t mqdes, FAR const char *msg, size_t msglen, int prio) { FAR struct mqueue_inode_s *msgq; FAR struct mqueue_msg_s *mqmsg = NULL; diff --git a/nuttx/sched/mqueue/mq_sndinternal.c b/nuttx/sched/mqueue/mq_sndinternal.c index a13b363ce..4291ee721 100644 --- a/nuttx/sched/mqueue/mq_sndinternal.c +++ b/nuttx/sched/mqueue/mq_sndinternal.c @@ -108,7 +108,7 @@ * ****************************************************************************/ -int mq_verifysend(mqd_t mqdes, const void *msg, size_t msglen, int prio) +int mq_verifysend(mqd_t mqdes, FAR const char *msg, size_t msglen, int prio) { /* Verify the input parameters */ @@ -324,7 +324,7 @@ int mq_waitsend(mqd_t mqdes) * ****************************************************************************/ -int mq_dosend(mqd_t mqdes, FAR struct mqueue_msg_s *mqmsg, FAR const void *msg, +int mq_dosend(mqd_t mqdes, FAR struct mqueue_msg_s *mqmsg, FAR const char *msg, size_t msglen, int prio) { FAR struct tcb_s *btcb; @@ -345,7 +345,7 @@ int mq_dosend(mqd_t mqdes, FAR struct mqueue_msg_s *mqmsg, FAR const void *msg, /* Copy the message data into the message */ - memcpy((void*)mqmsg->mail, (const void*)msg, msglen); + memcpy((void*)mqmsg->mail, (FAR const void*)msg, msglen); /* Insert the new message in the message queue */ @@ -438,4 +438,3 @@ int mq_dosend(mqd_t mqdes, FAR struct mqueue_msg_s *mqmsg, FAR const void *msg, sched_unlock(); return OK; } - diff --git a/nuttx/sched/mqueue/mq_timedreceive.c b/nuttx/sched/mqueue/mq_timedreceive.c index 4173b0692..ef9f0b6a5 100644 --- a/nuttx/sched/mqueue/mq_timedreceive.c +++ b/nuttx/sched/mqueue/mq_timedreceive.c @@ -179,8 +179,8 @@ static void mq_rcvtimeout(int argc, uint32_t pid) * ****************************************************************************/ -ssize_t mq_timedreceive(mqd_t mqdes, void *msg, size_t msglen, - int *prio, const struct timespec *abstime) +ssize_t mq_timedreceive(mqd_t mqdes, FAR char *msg, size_t msglen, + FAR int *prio, FAR const struct timespec *abstime) { FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; FAR struct mqueue_msg_s *mqmsg; @@ -216,7 +216,7 @@ ssize_t mq_timedreceive(mqd_t mqdes, void *msg, size_t msglen, return ERROR; } - /* Get the next mesage from the message queue. We will disable + /* Get the next message from the message queue. We will disable * pre-emption until we have completed the message received. This * is not too bad because if the receipt takes a long time, it will * be because we are blocked waiting for a message and pre-emption diff --git a/nuttx/sched/mqueue/mq_timedsend.c b/nuttx/sched/mqueue/mq_timedsend.c index 23cb61c2f..a5aa11c84 100644 --- a/nuttx/sched/mqueue/mq_timedsend.c +++ b/nuttx/sched/mqueue/mq_timedsend.c @@ -180,8 +180,8 @@ static void mq_sndtimeout(int argc, uint32_t pid) * ****************************************************************************/ -int mq_timedsend(mqd_t mqdes, const char *msg, size_t msglen, int prio, - const struct timespec *abstime) +int mq_timedsend(mqd_t mqdes, FAR const char *msg, size_t msglen, int prio, + FAR const struct timespec *abstime) { FAR struct tcb_s *rtcb = (FAR struct tcb_s *)g_readytorun.head; FAR struct mqueue_inode_s *msgq; @@ -318,4 +318,3 @@ int mq_timedsend(mqd_t mqdes, const char *msg, size_t msglen, int prio, rtcb->waitdog = NULL; return ret; } - diff --git a/nuttx/sched/mqueue/mqueue.h b/nuttx/sched/mqueue/mqueue.h index 02b08d351..bd771e140 100644 --- a/nuttx/sched/mqueue/mqueue.h +++ b/nuttx/sched/mqueue/mqueue.h @@ -90,15 +90,15 @@ enum mqalloc_e struct mqueue_msg_s { - FAR struct mqueue_msg_s *next; /* Forward link to next message */ - uint8_t type; /* (Used to manage allocations) */ - uint8_t priority; /* priority of message */ + FAR struct mqueue_msg_s *next; /* Forward link to next message */ + uint8_t type; /* (Used to manage allocations) */ + uint8_t priority; /* priority of message */ #if MQ_MAX_BYTES < 256 - uint8_t msglen; /* Message data length */ + uint8_t msglen; /* Message data length */ #else - uint16_t msglen; /* Message data length */ + uint16_t msglen; /* Message data length */ #endif - uint8_t mail[MQ_MAX_BYTES]; /* Message data */ + char mail[MQ_MAX_BYTES]; /* Message data */ }; /**************************************************************************** @@ -150,18 +150,18 @@ void mq_waitirq(FAR struct tcb_s *wtcb, int errcode); /* mq_rcvinternal.c ********************************************************/ -int mq_verifyreceive(mqd_t mqdes, void *msg, size_t msglen); +int mq_verifyreceive(mqd_t mqdes, FAR char *msg, size_t msglen); FAR struct mqueue_msg_s *mq_waitreceive(mqd_t mqdes); ssize_t mq_doreceive(mqd_t mqdes, FAR struct mqueue_msg_s *mqmsg, - FAR void *ubuffer, FAR int *prio); + FAR char *ubuffer, FAR int *prio); /* mq_sndinternal.c ********************************************************/ -int mq_verifysend(mqd_t mqdes, FAR const void *msg, size_t msglen, int prio); +int mq_verifysend(mqd_t mqdes, FAR const char *msg, size_t msglen, int prio); FAR struct mqueue_msg_s *mq_msgalloc(void); int mq_waitsend(mqd_t mqdes); int mq_dosend(mqd_t mqdes, FAR struct mqueue_msg_s *mqmsg, - FAR const void *msg, size_t msglen, int prio); + FAR const char *msg, size_t msglen, int prio); /* mq_release.c ************************************************************/ |