From: "Richard Weinberger (sigma star gmbh)" <rw@kernel.org>
To: xenomai@lists.linux.dev
Cc: upstream+xenomai@sigma-star.at, Richard Weinberger <richard@nod.at>
Subject: [PATCH 3/7] lib/alchemy: Document the actual calling context requirements
Date: Wed, 25 Nov 2026 22:34:15 +0100 [thread overview]
Message-ID: <20261125213419.2363742-4-rw@kernel.org> (raw)
In-Reply-To: <20261125213419.2363742-1-rw@kernel.org>
From: Richard Weinberger <richard@nod.at>
Many services document -EPERM for callers which are not "Xenomai
threads", but actually require a Copperplate TCB (Alchemy, pSOS or
VxWorks task, or the main thread), or even an Alchemy task. Cobalt
POSIX threads are Xenomai threads, yet refused.
Introduce the term "Xenomai task" in the glossary and document the
requirement which is actually enforced. Also fix a few wrong errno
values, API tags and copy&paste errors along the way.
No functional change.
Signed-off-by: Richard Weinberger <richard@nod.at>
---
lib/alchemy/alarm.c | 9 -----
lib/alchemy/buffer.c | 11 +++---
lib/alchemy/cond.c | 3 +-
lib/alchemy/event.c | 9 +++--
lib/alchemy/heap.c | 7 ++--
lib/alchemy/mutex.c | 3 +-
lib/alchemy/pipe.c | 11 +++---
lib/alchemy/queue.c | 11 +++---
lib/alchemy/sem.c | 3 +-
lib/alchemy/task.c | 78 ++++++++++++++++++++++--------------------
lib/copperplate/init.c | 10 ++++++
11 files changed, 85 insertions(+), 70 deletions(-)
diff --git a/lib/alchemy/alarm.c b/lib/alchemy/alarm.c
index 14cb4e248..9d5171175 100644
--- a/lib/alchemy/alarm.c
+++ b/lib/alchemy/alarm.c
@@ -155,9 +155,6 @@ static void alarm_handler(struct timerobj *tmobj)
* - -EEXIST is returned if the @a name is conflicting with an already
* registered alarm.
*
- * - -EPERM is returned if this service was called from an
- * asynchronous context.
- *
* @apitags{mode-unrestricted, switch-secondary}
*
* @note Alarms are process-private objects and thus cannot be shared
@@ -237,9 +234,6 @@ out:
*
* - -EINVAL is returned if @a alarm is not a valid alarm descriptor.
*
- * - -EPERM is returned if this service was called from an
- * asynchronous context.
- *
* @apitags{mode-unrestricted, switch-secondary}
*/
#ifndef DOXYGEN_CPP
@@ -298,9 +292,6 @@ out:
*
* - -EINVAL is returned if @a alarm is not a valid alarm descriptor.
*
- * - -EPERM is returned if this service was called from an invalid
- * context.
- *
* @apitags{xthread-only, switch-primary}
*
* @note Each of the initial @a value and @a interval is interpreted
diff --git a/lib/alchemy/buffer.c b/lib/alchemy/buffer.c
index b9526304d..4f826fb27 100644
--- a/lib/alchemy/buffer.c
+++ b/lib/alchemy/buffer.c
@@ -424,8 +424,8 @@ out:
* waiting for data. In such event, @a bf is no more valid upon return
* of this service.
*
- * - -EPERM is returned if this service should block, but was not
- * called from a Xenomai thread.
+ * - -EPERM is returned if this service was not called from a Xenomai
+ * task, unless @a abs_timeout is { .tv_sec = 0, .tv_nsec = 0 }.
*
* @note A short read (i.e. fewer bytes returned than requested by @a
* len) may happen whenever a pathological use of the buffer is
@@ -664,8 +664,8 @@ out:
* waiting for buffer space. In such event, @a bf is no more valid
* upon return of this service.
*
- * - -EPERM is returned if this service should block, but was not
- * called from a Xenomai thread.
+ * - -EPERM is returned if this service was not called from a Xenomai
+ * task, unless @a abs_timeout is { .tv_sec = 0, .tv_nsec = 0 }.
*
* @apitags{xthread-nowait, switch-primary}
*/
@@ -914,7 +914,8 @@ out:
* the specified amount of time.
*
* - -EPERM is returned if this service should block, but was not
- * called from a Xenomai thread.
+ * called from a Xenomai task. Over Cobalt, this error is also returned
+ * if the caller is not a Xenomai thread, even if it should not block.
*
* @apitags{xthread-nowait, switch-primary}
*
diff --git a/lib/alchemy/cond.c b/lib/alchemy/cond.c
index 4409e3f5b..1a4ccacc3 100644
--- a/lib/alchemy/cond.c
+++ b/lib/alchemy/cond.c
@@ -458,7 +458,8 @@ int rt_cond_inquire(RT_COND *cond, RT_COND_INFO *info)
* the specified amount of time.
*
* - -EPERM is returned if this service should block, but was not
- * called from a Xenomai thread.
+ * called from a Xenomai task. Over Cobalt, this error is also returned
+ * if the caller is not a Xenomai thread, even if it should not block.
*
* @apitags{xthread-nowait, switch-primary}
*
diff --git a/lib/alchemy/event.c b/lib/alchemy/event.c
index 8ba76f333..8428db539 100644
--- a/lib/alchemy/event.c
+++ b/lib/alchemy/event.c
@@ -378,8 +378,10 @@ out:
* sleeping on it. In such a case, @a event is no more valid upon
* return of this service.
*
- * - -EPERM is returned if this service should block, but was not
- * called from a Xenomai thread.
+ * - -EPERM is returned if this service was not called from a Xenomai
+ * task, unless @a abs_timeout is { .tv_sec = 0, .tv_nsec = 0 }. Over
+ * Cobalt, this error is also returned if the caller is not a Xenomai
+ * thread.
*
* @apitags{xthread-nowait, switch-primary}
*/
@@ -583,7 +585,8 @@ out:
* the specified amount of time.
*
* - -EPERM is returned if this service should block, but was not
- * called from a Xenomai thread.
+ * called from a Xenomai task. Over Cobalt, this error is also returned
+ * if the caller is not a Xenomai thread, even if it should not block.
*
* @apitags{xthread-nowait, switch-primary}
*
diff --git a/lib/alchemy/heap.c b/lib/alchemy/heap.c
index 140fdc656..fb3424f5f 100644
--- a/lib/alchemy/heap.c
+++ b/lib/alchemy/heap.c
@@ -408,8 +408,8 @@ out:
* waiting for a block. In such event, @a heap is no more valid upon
* return of this service.
*
- * - -EPERM is returned if this service should block, but was not
- * called from a Xenomai thread.
+ * - -EPERM is returned if this service was not called from a Xenomai
+ * task, unless @a abs_timeout is { .tv_sec = 0, .tv_nsec = 0 }.
*
* @apitags{xthread-nowait, switch-primary}
*
@@ -639,7 +639,8 @@ out:
* the specified amount of time.
*
* - -EPERM is returned if this service should block, but was not
- * called from a Xenomai thread.
+ * called from a Xenomai task. Over Cobalt, this error is also returned
+ * if the caller is not a Xenomai thread, even if it should not block.
*
* @apitags{xthread-nowait, switch-primary}
*
diff --git a/lib/alchemy/mutex.c b/lib/alchemy/mutex.c
index 9609f1fa5..75d7ff3d3 100644
--- a/lib/alchemy/mutex.c
+++ b/lib/alchemy/mutex.c
@@ -499,7 +499,8 @@ out:
* the specified amount of time.
*
* - -EPERM is returned if this service should block, but was not
- * called from a Xenomai thread.
+ * called from a Xenomai task. Over Cobalt, this error is also returned
+ * if the caller is not a Xenomai thread, even if it should not block.
*
* @apitags{xthread-nowait, switch-primary}
*
diff --git a/lib/alchemy/pipe.c b/lib/alchemy/pipe.c
index a266a380f..b5ada2c7d 100644
--- a/lib/alchemy/pipe.c
+++ b/lib/alchemy/pipe.c
@@ -289,7 +289,7 @@ out:
* @fn ssize_t rt_pipe_read(RT_PIPE *pipe, void *buf, size_t size, RTIME timeout)
* @brief Read from a pipe (with relative scalar timeout).
*
- * This routine is a variant of rt_queue_read_timed() accepting a
+ * This routine is a variant of rt_pipe_read_timed() accepting a
* relative timeout specification expressed as a scalar value.
*
* @param pipe The pipe descriptor.
@@ -354,7 +354,7 @@ ssize_t rt_pipe_read(RT_PIPE *pipe,
* @fn ssize_t rt_pipe_read_until(RT_PIPE *pipe, void *buf, size_t size, RTIME abs_timeout)
* @brief Read from a pipe (with absolute scalar timeout).
*
- * This routine is a variant of rt_queue_read_timed() accepting an
+ * This routine is a variant of rt_pipe_read_timed() accepting an
* absolute timeout specification expressed as a scalar value.
*
* @param pipe The pipe descriptor.
@@ -420,8 +420,8 @@ ssize_t rt_pipe_read(RT_PIPE *pipe,
* waiting for a message. In such event, @a pipe is no more valid upon
* return of this service.
*
- * - -EPERM is returned if this service should block, but was not
- * called from a Xenomai thread.
+ * - -EPERM is returned if this service was not called from a Xenomai
+ * task, unless @a abs_timeout is { .tv_sec = 0, .tv_nsec = 0 }.
*
* @apitags{xthread-nowait, switch-primary}
*/
@@ -637,7 +637,8 @@ ssize_t rt_pipe_stream(RT_PIPE *pipe,
* the specified amount of time.
*
* - -EPERM is returned if this service should block, but was not
- * called from a Xenomai thread.
+ * called from a Xenomai task. Over Cobalt, this error is also returned
+ * if the caller is not a Xenomai thread, even if it should not block.
*
* @apitags{xthread-nowait}
*
diff --git a/lib/alchemy/queue.c b/lib/alchemy/queue.c
index 0dba63f2b..e91973920 100644
--- a/lib/alchemy/queue.c
+++ b/lib/alchemy/queue.c
@@ -792,8 +792,8 @@ out:
* waiting for a message. In such event, @a q is no more valid upon
* return of this service.
*
- * - -EPERM is returned if this service should block, but was not
- * called from a Xenomai thread.
+ * - -EPERM is returned if this service was not called from a Xenomai
+ * task, unless @a abs_timeout is { .tv_sec = 0, .tv_nsec = 0 }.
*
* @apitags{xthread-nowait, switch-primary}
*/
@@ -952,8 +952,8 @@ out:
* waiting for a message. In such event, @a q is no more valid upon
* return of this service.
*
- * - -EPERM is returned if this service should block, but was not
- * called from a Xenomai thread.
+ * - -EPERM is returned if this service was not called from a Xenomai
+ * task, unless @a abs_timeout is { .tv_sec = 0, .tv_nsec = 0 }.
*
* @apitags{xthread-nowait, switch-primary}
*/
@@ -1159,7 +1159,8 @@ out:
* the specified amount of time.
*
* - -EPERM is returned if this service should block, but was not
- * called from a Xenomai thread.
+ * called from a Xenomai task. Over Cobalt, this error is also returned
+ * if the caller is not a Xenomai thread, even if it should not block.
*
* @apitags{xthread-nowait, switch-primary}
*
diff --git a/lib/alchemy/sem.c b/lib/alchemy/sem.c
index e88c6e4d6..6a561574c 100644
--- a/lib/alchemy/sem.c
+++ b/lib/alchemy/sem.c
@@ -536,7 +536,8 @@ out:
* the specified amount of time.
*
* - -EPERM is returned if this service should block, but was not
- * called from a Xenomai thread.
+ * called from a Xenomai task. Over Cobalt, this error is also returned
+ * if the caller is not a Xenomai thread, even if it should not block.
*
* @apitags{xthread-nowait, switch-primary}
*
diff --git a/lib/alchemy/task.c b/lib/alchemy/task.c
index dcb3de42c..2f61c8580 100644
--- a/lib/alchemy/task.c
+++ b/lib/alchemy/task.c
@@ -473,8 +473,8 @@ out:
*
* - -EINVAL is returned if @a task is not a valid task descriptor.
*
- * - -EPERM is returned if @a task is NULL and this service was called
- * from an invalid context. In addition, this error is always raised
+ * - -EPERM is returned if @a task is NULL but the caller is not an
+ * Alchemy task. In addition, this error is always raised
* when this service is called from asynchronous context, such as a
* timer/alarm handler.
*
@@ -562,10 +562,12 @@ int rt_task_join(RT_TASK *task)
*
* @return Zero is returned upon success. Otherwise:
*
- * - -EINVAL is returned if @a task is NULL but the caller is not a
- * Xenomai task, or if @a task is non-NULL but not a valid task
+ * - -EINVAL is returned if @a task is non-NULL but not a valid task
* descriptor.
*
+ * - -EPERM is returned if @a task is NULL but the caller is not an
+ * Alchemy task.
+ *
* - -EINVAL is returned if @a cpus contains no processors that are
* currently physically on the system and permitted to the process
* according to any restrictions that may be imposed by the "cpuset"
@@ -707,12 +709,13 @@ out:
* - -EEXIST is returned if the @a name is conflicting with an already
* registered task.
*
- * - -EBUSY is returned if the caller is not a regular POSIX thread.
+ * - -EBUSY is returned if the caller already is an Alchemy, pSOS or
+ * VxWorks task.
*
* - -EPERM is returned if this service was called from an invalid
* context, e.g. interrupt handler.
*
- * @apitags{pthread-only, switch-secondary, switch-primary}
+ * @apitags{thread-unrestricted, switch-secondary, switch-primary}
*
* @sideeffect Over Cobalt, if the caller is a plain POSIX thread, it
* is turned into a Xenomai _shadow_ thread, with full access to all
@@ -809,10 +812,12 @@ undo:
*
* @return Zero is returned upon success. Otherwise:
*
- * - -EINVAL is returned if @a task is NULL but the caller is not a
- * Xenomai task, or if @a task is non-NULL but not a valid task
+ * - -EINVAL is returned if @a task is non-NULL but not a valid task
* descriptor.
*
+ * - -EPERM is returned if @a task is NULL but the caller is not an
+ * Alchemy task.
+ *
* - -ETIMEDOUT is returned if @a idate is different from TM_INFINITE
* and represents a date in the past.
*
@@ -919,8 +924,8 @@ out:
* task. If @a overruns_r is non-NULL, the count of pending overruns
* is written to the pointed memory location.
*
- * - -EPERM is returned if this service was called from an invalid
- * context.
+ * - -EPERM is returned if this service was not called from a Xenomai
+ * task.
*
* @apitags{xthread-only, switch-primary}
*
@@ -957,13 +962,11 @@ int rt_task_wait_period(unsigned long *overruns_r)
*
* - -ETIMEDOUT is returned if @a date has already elapsed.
*
- * - -EPERM is returned if this service was called from an invalid
- * context.
+ * - -EPERM is returned if this service was not called from a Xenomai
+ * task.
*
* @apitags{xthread-only, switch-primary}
*
- * @note The caller must be an Alchemy task if @a task is NULL.
- *
* @note The @a date value is interpreted as a multiple of the Alchemy
* clock resolution (see --alchemy-clock-resolution option, defaults
* to 1 nanosecond).
@@ -1058,7 +1061,7 @@ int rt_task_sleep(RTIME delay)
*
* @return See rt_task_create().
*
- * @apitags{mode-unrestricted, switch-secondary}
+ * @apitags{xthread-only, mode-unrestricted, switch-secondary}
*
* @sideeffect see rt_task_create().
*/
@@ -1126,12 +1129,11 @@ int rt_task_same(RT_TASK *task1, RT_TASK *task2)
*
* @return Zero is returned upon success. Otherwise:
*
- * - -EINVAL is returned if @a task is NULL but the caller is not a
- * Xenomai task, or if @a task is non-NULL but not a valid task
+ * - -EINVAL is returned if @a task is non-NULL but not a valid task
* descriptor.
*
- * - -EPERM is returned if @a task is NULL and this service was called
- * from an invalid context.
+ * - -EPERM is returned if @a task is NULL but the caller is not an
+ * Alchemy task.
*
* @apitags{mode-unrestricted, switch-primary}
*
@@ -1256,8 +1258,8 @@ RT_TASK *rt_task_self(void)
* - -EINVAL is returned if @a task is not a valid task descriptor, or
* if @a prio is invalid.
*
- * - -EPERM is returned if @a task is NULL and this service was called
- * from an invalid context.
+ * - -EPERM is returned if @a task is NULL but the caller is not an
+ * Alchemy task.
*
* @apitags{mode-unrestricted, switch-primary, switch-secondary}
*
@@ -1389,8 +1391,8 @@ out:
* - -EINVAL is returned if @a task is not a valid task descriptor, or
* if @a prio is invalid.
*
- * - -EPERM is returned if @a task is NULL and this service was called
- * from an invalid context.
+ * - -EPERM is returned if @a task is NULL but the caller is not an
+ * Alchemy task.
*
* @apitags{mode-unrestricted, switch-primary}
*
@@ -1483,11 +1485,12 @@ out:
*
* @return Zero is returned upon success. Otherwise:
*
- * - -EINVAL is returned if @a task is not a valid task descriptor, or
- * if any bit from @a clrmask or @a setmask is invalid.
-
- * - -EPERM is returned if this service was called from an invalid
- * context.
+ * - -EINVAL is returned if any bit from @a clrmask or @a setmask is
+ * invalid.
+ *
+ * - -EPERM is returned if this service was not called from an Alchemy
+ * task, or if it was called from an asynchronous context with bits
+ * other than T_LOCK in @a clrmask or @a setmask.
*
* @apitags{xthread-only, switch-primary}
*
@@ -1549,8 +1552,8 @@ out:
* - -EINVAL is returned if @a task is not a valid task descriptor, or
* if @a prio is invalid.
*
- * - -EPERM is returned if @a task is NULL and this service was called
- * from an invalid context.
+ * - -EPERM is returned if @a task is NULL but the caller is not an
+ * Alchemy task.
*
* @apitags{mode-unrestricted, switch-primary}
*
@@ -1699,8 +1702,8 @@ out:
*
* - -EINVAL is returned if @a task is not a valid task descriptor.
*
- * - -EPERM is returned if this service was called from an invalid
- * context.
+ * - -EPERM is returned if this service was not called from a Xenomai
+ * task.
*
* - -ENOBUFS is returned if @a mcb_r does not point at a message area
* large enough to collect the remote task's reply. This includes the
@@ -1906,8 +1909,8 @@ out:
* token should be passed to rt_task_reply(), in order to send back a
* reply to and unblock the remote task appropriately. Otherwise:
*
- * - -EPERM is returned if this service was called from an invalid
- * context.
+ * - -EPERM is returned if this service was not called from an Alchemy
+ * task.
*
* - -EINTR is returned if rt_task_unblock() was called for the
* current task before a message was received.
@@ -2038,8 +2041,8 @@ out:
* calling rt_task_send(). In such a case, the remote task also
* receives -ENOBUFS on return from rt_task_send().
*
- * - -EPERM is returned if this service was called from an invalid
- * context.
+ * - -EPERM is returned if this service was not called from an Alchemy
+ * task.
*
* @apitags{xthread-only, switch-primary}
*/
@@ -2147,7 +2150,8 @@ out:
* the specified amount of time.
*
* - -EPERM is returned if this service should block, but was not
- * called from a Xenomai thread.
+ * called from a Xenomai task. Over Cobalt, this error is also returned
+ * if the caller is not a Xenomai thread, even if it should not block.
*
* @apitags{xthread-nowait, switch-primary}
*
diff --git a/lib/copperplate/init.c b/lib/copperplate/init.c
index 01969cfea..3eea6b51f 100644
--- a/lib/copperplate/init.c
+++ b/lib/copperplate/init.c
@@ -337,6 +337,16 @@ copperplate_setup_call(copperplate_interface);
* excluding such threads which have been promoted to the real-time
* domain afterwards (aka "shadowed") over Cobalt.
*
+ * @attention By Xenomai task, we mean the subset of Xenomai threads
+ * which have a Copperplate thread control block: tasks created or
+ * shadowed by one of the RTOS APIs based on Copperplate (Alchemy,
+ * pSOS, VxWorks), and the thread which initialized the Xenomai
+ * libraries (i.e. normally main()). Cobalt/POSIX threads created by
+ * the POSIX API are Xenomai threads, but not Xenomai tasks. Some
+ * services further require the caller to be a task of a particular
+ * API, e.g. an Alchemy task created by rt_task_create() or
+ * rt_task_shadow().
+ *
* @par
* <b>Context tags</b>
* <TABLE>
--
2.55.0
next prev parent reply other threads:[~2026-11-25 21:34 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 21:34 [PATCH 0/7] Alchemy: Fix calling context checks and documentation Richard Weinberger (sigma star gmbh)
2026-11-25 21:34 ` [PATCH 1/7] lib/alchemy/mutex: Allow any Xenomai thread to acquire a mutex Richard Weinberger (sigma star gmbh)
2026-11-26 6:14 ` Jan Kiszka
2026-11-26 7:53 ` Richard Weinberger
2026-11-25 21:34 ` [PATCH 2/7] lib/alchemy/task: Allow rt_task_yield() from any thread Richard Weinberger (sigma star gmbh)
2026-11-25 21:34 ` Richard Weinberger (sigma star gmbh) [this message]
2026-11-25 21:34 ` [PATCH 4/7] lib/alchemy/pipe: Do not require a Xenomai task for blocking reads Richard Weinberger (sigma star gmbh)
2026-11-25 21:34 ` [PATCH 5/7] lib/alchemy/event: Require a Xenomai task only for waiting over Mercury Richard Weinberger (sigma star gmbh)
2026-11-25 21:34 ` [PATCH 6/7] lib/alchemy: Require a Xenomai task only when actually waiting Richard Weinberger (sigma star gmbh)
2026-11-26 6:09 ` Jan Kiszka
2026-11-25 21:34 ` [PATCH 7/7] testsuite/smokey/alchemytests: Test Alchemy services from POSIX threads Richard Weinberger (sigma star gmbh)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261125213419.2363742-4-rw@kernel.org \
--to=rw@kernel.org \
--cc=richard@nod.at \
--cc=upstream+xenomai@sigma-star.at \
--cc=xenomai@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.