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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Wed Apr 16 11:59:29 2014 +0200

alchemy: check call mode bits when applicable

---

 lib/alchemy/buffer.c |    4 +++-
 lib/alchemy/event.c  |   14 +++++++++++---
 lib/alchemy/heap.c   |    7 +++++--
 lib/alchemy/pipe.c   |    6 +++++-
 lib/alchemy/queue.c  |   15 ++++++++++-----
 lib/alchemy/sem.c    |    7 +++++--
 6 files changed, 39 insertions(+), 14 deletions(-)

diff --git a/lib/alchemy/buffer.c b/lib/alchemy/buffer.c
index 36f9e12..f77a4c7 100644
--- a/lib/alchemy/buffer.c
+++ b/lib/alchemy/buffer.c
@@ -192,6 +192,8 @@ fnref_register(libalchemy, buffer_finalize);
  *
  * @return Zero is returned upon success. Otherwise:
  *
+ * - -EINVAL is returned if @a mode is invalid or @a bufsz is zero.
+ *
  * - -ENOMEM is returned if the system fails to get memory from the
  * main heap in order to create the buffer.
  *
@@ -220,7 +222,7 @@ int rt_buffer_create(RT_BUFFER *bf, const char *name,
        if (threadobj_irq_p())
                return -EPERM;
 
-       if (bufsz == 0)
+       if (bufsz == 0 || (mode & ~B_PRIO) != 0)
                return -EINVAL;
 
        CANCEL_DEFER(svc);
diff --git a/lib/alchemy/event.c b/lib/alchemy/event.c
index 827ad6f..37c6569 100644
--- a/lib/alchemy/event.c
+++ b/lib/alchemy/event.c
@@ -145,6 +145,8 @@ fnref_register(libalchemy, event_finalize);
  *
  * @return Zero is returned upon success. Otherwise:
  *
+ * - -EINVAL is returned if @a mode is invalid.
+ *
  * - -ENOMEM is returned if the system fails to get memory from the
  * main heap in order to create the event flag group.
  *
@@ -172,6 +174,9 @@ int rt_event_create(RT_EVENT *event, const char *name,
        if (threadobj_irq_p())
                return -EPERM;
 
+       if (mode & ~EV_PRIO)
+               return -EINVAL;
+
        CANCEL_DEFER(svc);
 
        evcb = xnmalloc(sizeof(*evcb));
@@ -353,8 +358,8 @@ out:
  * - -EINTR is returned if rt_task_unblock() was called for the
  * current task before the request is satisfied.
  *
- * - -EINVAL is returned if @a event is not a valid event flag group
- * descriptor.
+ * - -EINVAL is returned if @a mode is invalid, or @a event is not a
+ * valid event flag group descriptor.
  *
  * - -EIDRM is returned if @a event is deleted while the caller was
  * sleeping on it. In such a case, @a event is no more valid upon
@@ -384,6 +389,9 @@ int rt_event_wait_timed(RT_EVENT *event,
        if (!threadobj_current_p() && !alchemy_poll_mode(abs_timeout))
                return -EPERM;
 
+       if (mode & ~EVOBJ_ANY)
+               return -EINVAL;
+
        CANCEL_DEFER(svc);
 
        evcb = find_alchemy_event(event, &ret);
@@ -415,7 +423,7 @@ out:
  *
  * @return Zero is returned upon success. Otherwise:
  *
- * - -EINVAL is returned if @a event is not a valid event flag group
+ * - -EINVAL is returned if @a event is not an event flag group
  * descriptor.
  *
  * Valid calling context: any.
diff --git a/lib/alchemy/heap.c b/lib/alchemy/heap.c
index 46e691c..560e085 100644
--- a/lib/alchemy/heap.c
+++ b/lib/alchemy/heap.c
@@ -192,8 +192,8 @@ fnref_register(libalchemy, heap_finalize);
  *
  * @return Zero is returned upon success. Otherwise:
  *
- * - -EINVAL is returned if @a heapsz is not in the valid range
- * [2k..2Gb].
+ * - -EINVAL is returned if @a mode is invalid, or @a heapsz is not in
+ * the range [2k..2Gb].
  *
  * - -ENOMEM is returned if the system fails to get memory from the
  * main heap in order to create the heap.
@@ -225,6 +225,9 @@ int rt_heap_create(RT_HEAP *heap,
        if (heapsz < 2048 || heapsz >= 1U << 31)
                return -EINVAL;
 
+       if (mode & ~(H_PRIO|H_SINGLE))
+               return -EINVAL;
+
        CANCEL_DEFER(svc);
 
        ret = -ENOMEM;
diff --git a/lib/alchemy/pipe.c b/lib/alchemy/pipe.c
index 27f814e..48420f1 100644
--- a/lib/alchemy/pipe.c
+++ b/lib/alchemy/pipe.c
@@ -450,7 +450,8 @@ out:
  * @return Upon success, this service returns @a size. Upon error, one
  * of the following error codes is returned:
  *
- * - -EINVAL is returned if @a pipe is not a pipe descriptor.
+ * - -EINVAL is returned if @a mode is invalid or @a pipe is not a
+ * pipe descriptor.
  *
  * - -ENOMEM is returned if not enough buffer space is available to
  * complete the operation.
@@ -467,6 +468,9 @@ ssize_t rt_pipe_write(RT_PIPE *pipe,
 {
        int flags = 0;
 
+       if (mode & ~P_URGENT)
+               return -EINVAL;
+
        if (mode & P_URGENT)
                flags |= MSG_OOB;
 
diff --git a/lib/alchemy/queue.c b/lib/alchemy/queue.c
index ef9320f..4cb2a4f 100644
--- a/lib/alchemy/queue.c
+++ b/lib/alchemy/queue.c
@@ -171,6 +171,8 @@ fnref_register(libalchemy, queue_finalize);
  *
  * @return Zero is returned upon success. Otherwise:
  *
+ * - -EINVAL is returned if @a mode is invalid or @a poolsize is zero.
+ *
  * - -ENOMEM is returned if the system fails to get memory from the
  * main heap in order to create the queue.
  *
@@ -485,9 +487,8 @@ out:
  * message has been enqueued. Upon error, one of the following error
  * codes is returned:
  *
- * - -EINVAL is returned if @a q is not a message queue descriptor, or
- * @a buf is not a valid message buffer obtained from a previous call
- * to rt_queue_alloc().
+ * - -EINVAL is returned if @a q is not a message queue descriptor, @a
+ * mode is invalid, or @a buf is NULL.
  *
  * - -ENOMEM is returned if queuing the message would exceed the limit
  * defined for the queue at creation.
@@ -505,7 +506,7 @@ int rt_queue_send(RT_QUEUE *queue,
        struct service svc;
        int ret = 0;
 
-       if (buf == NULL)
+       if (buf == NULL || (mode & ~(Q_URGENT|Q_BROADCAST)) != 0)
                return -EINVAL;
 
        msg = (struct alchemy_queue_msg *)buf - 1;
@@ -601,7 +602,8 @@ out:
  * message has been enqueued. Upon error, one of the following error
  * codes is returned:
  *
- * - -EINVAL is returned if @a q is not a message queue descriptor.
+ * - -EINVAL is returned if @a mode is invalid, or @a q is not a
+ * essage queue descriptor.
  *
  * - -ENOMEM is returned if queuing the message would exceed the limit
  * defined for the queue at creation, or if no memory can be obtained
@@ -621,6 +623,9 @@ int rt_queue_write(RT_QUEUE *queue,
        struct service svc;
        size_t usersz;
 
+       if (mode & ~(Q_URGENT|Q_BROADCAST))
+               return -EINVAL;
+
        if (size == 0)
                return 0;
 
diff --git a/lib/alchemy/sem.c b/lib/alchemy/sem.c
index d5ed5a7..f2bb241 100644
--- a/lib/alchemy/sem.c
+++ b/lib/alchemy/sem.c
@@ -153,8 +153,8 @@ fnref_register(libalchemy, sem_finalize);
  *
  * @return Zero is returned upon success. Otherwise:
  *
- * - -EINVAL is returned if the @a icount is non-zero and S_PULSE is
- * set in @a mode.
+ * - -EINVAL is returned if @a icount is non-zero and S_PULSE is set
+ * in @a mode, or @a mode is otherwise invalid.
  *
  * - -ENOMEM is returned if the system fails to get memory from the
  * main heap in order to create the semaphore.
@@ -183,6 +183,9 @@ int rt_sem_create(RT_SEM *sem, const char *name,
        if (threadobj_irq_p())
                return -EPERM;
 
+       if (mode & ~(S_PRIO|S_PULSE))
+               return -EINVAL;
+
        if (mode & S_PULSE) {
                if (icount > 0)
                        return -EINVAL;


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

Reply via email to