source: rtems/cpukit/include/rtems/score/status.h @ e2255453

5
Last change on this file since e2255453 was e2255453, checked in by Martin Erik Werner <martinerikwerner@…>, on 01/19/20 at 15:11:38

Use EAGAIN for POSIX mq wait in ISR error

Modify the status code returned by _CORE_message_queue_Submit() when it
detects a wait about to happen in an ISR (which would be deadly) to
return a status which translated to EAGAIN instead of ENOMEM.

This is only relevant for POSIX message queues, since Classic API message
queues cannot block on send.

The motivation is to match the "most related" errno value returned from
mq_send() and mq_timedsend() according to POSIX, via Open Group:

[EAGAIN]

The O_NONBLOCK flag is set in the message queue description
associated with mqdes, and the specified message queue is full.

or via the RTEMS POSIX users documentation

EAGAIN

The message queue is non-blocking, and there is no room on the queue
for another message as specified by the mq_maxmsg.

Neither of these matches the case ofi avoided ISR wait perfectly, but
they seem to be the closest equivalent, unless it is desirable to keep a
new non-standard error for this case. It is presumed that this is not
desirable.

The previously returned ENOMEM error value is not documented in either
the Open Group or the RTEMS POSIX uses documentation. A companion patch
corrects the documentation to include this error condition.

Based on the discussion in:
https://lists.rtems.org/pipermail/devel/2020-January/056891.html

closes #3857.

Message-Id: <CAF9ehCW5P12ZkZja4UPYTbdBFUyC1VKVL-tU7nyUtvK1Lz2Z3g@…>

  • Property mode set to 100644
File size: 4.0 KB
Line 
1/*
2 * Copyright (c) 2016 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.org/license/LICENSE.
13 */
14
15#ifndef _RTEMS_SCORE_STATUS_H
16#define _RTEMS_SCORE_STATUS_H
17
18#include <rtems/score/basedefs.h>
19
20#include <errno.h>
21#include <pthread.h>
22
23#ifdef __cplusplus
24extern "C" {
25#endif /* __cplusplus */
26
27/**
28 * @brief Status code parts for the Classic API.
29 *
30 * Must be in synchronization with rtems_status_code.
31 */
32typedef enum {
33  STATUS_CLASSIC_INCORRECT_STATE = 14,
34  STATUS_CLASSIC_INTERNAL_ERROR = 13,
35  STATUS_CLASSIC_INVALID_NUMBER = 10,
36  STATUS_CLASSIC_INVALID_PRIORITY = 19,
37  STATUS_CLASSIC_INVALID_SIZE = 8,
38  STATUS_CLASSIC_NO_MEMORY = 26,
39  STATUS_CLASSIC_NOT_DEFINED = 11,
40  STATUS_CLASSIC_NOT_OWNER_OF_RESOURCE = 23,
41  STATUS_CLASSIC_OBJECT_WAS_DELETED = 7,
42  STATUS_CLASSIC_PROXY_BLOCKING = 29,
43  STATUS_CLASSIC_RESOURCE_IN_USE = 12,
44  STATUS_CLASSIC_SUCCESSFUL = 0,
45  STATUS_CLASSIC_TIMEOUT = 6,
46  STATUS_CLASSIC_TOO_MANY = 5,
47  STATUS_CLASSIC_UNSATISFIED = 13
48} Status_Classic;
49
50/**
51 * @brief Macro to build a status code from Classic and POSIX API parts.
52 */
53#define STATUS_BUILD( classic_status, posix_status ) \
54  ( ( ( (unsigned int) ( posix_status ) ) << 8 ) | ( classic_status ) )
55
56/**
57 * @brief Macro to get the Classic API status code.
58 */
59#define STATUS_GET_CLASSIC( status ) \
60  ( ( status ) & 0xff )
61
62/**
63 * @brief Macro to get the POSIX API status code.
64 *
65 * Performs an arithmetic shift to reconstruct a negative POSIX status.
66 */
67#define STATUS_GET_POSIX( status ) \
68  ( ( ( (int) ( status ) ) | 0xff ) >> 8 )
69
70/**
71 * @brief Status codes.
72 */
73typedef enum {
74  STATUS_BARRIER_AUTOMATICALLY_RELEASED =
75    STATUS_BUILD( STATUS_CLASSIC_SUCCESSFUL, PTHREAD_BARRIER_SERIAL_THREAD ),
76  STATUS_DEADLOCK =
77    STATUS_BUILD( STATUS_CLASSIC_INCORRECT_STATE, EDEADLK ),
78  STATUS_FLUSHED =
79    STATUS_BUILD( STATUS_CLASSIC_UNSATISFIED, EAGAIN ),
80  STATUS_INCORRECT_STATE =
81    STATUS_BUILD( STATUS_CLASSIC_INCORRECT_STATE, EINVAL ),
82  STATUS_INTERRUPTED =
83    STATUS_BUILD( STATUS_CLASSIC_INTERNAL_ERROR, EINTR ),
84  STATUS_INVALID_NUMBER =
85    STATUS_BUILD( STATUS_CLASSIC_INVALID_NUMBER, EINVAL ),
86  STATUS_INVALID_PRIORITY =
87    STATUS_BUILD( STATUS_CLASSIC_INVALID_PRIORITY, EINVAL ),
88  STATUS_MAXIMUM_COUNT_EXCEEDED =
89    STATUS_BUILD( STATUS_CLASSIC_INTERNAL_ERROR, EOVERFLOW ),
90  STATUS_MESSAGE_INVALID_SIZE =
91    STATUS_BUILD( STATUS_CLASSIC_INVALID_SIZE, EMSGSIZE ),
92  STATUS_MESSAGE_QUEUE_WAIT_IN_ISR =
93    STATUS_BUILD( STATUS_CLASSIC_INTERNAL_ERROR, EAGAIN ),
94  STATUS_MESSAGE_QUEUE_WAS_DELETED =
95    STATUS_BUILD( STATUS_CLASSIC_OBJECT_WAS_DELETED, EBADF ),
96  STATUS_MINUS_ONE =
97    -1,
98  STATUS_MUTEX_CEILING_VIOLATED =
99    STATUS_BUILD( STATUS_CLASSIC_INVALID_PRIORITY, EINVAL ),
100  STATUS_NESTING_NOT_ALLOWED =
101    STATUS_BUILD( STATUS_CLASSIC_UNSATISFIED, EDEADLK ),
102  STATUS_NO_MEMORY =
103    STATUS_BUILD( STATUS_CLASSIC_NO_MEMORY, EINVAL ),
104  STATUS_NOT_DEFINED =
105    STATUS_BUILD( STATUS_CLASSIC_NOT_DEFINED, EINVAL ),
106  STATUS_NOT_OWNER =
107    STATUS_BUILD( STATUS_CLASSIC_NOT_OWNER_OF_RESOURCE, EPERM ),
108  STATUS_OBJECT_WAS_DELETED =
109    STATUS_BUILD( STATUS_CLASSIC_OBJECT_WAS_DELETED, EINVAL ),
110  STATUS_PROXY_BLOCKING =
111    STATUS_BUILD( STATUS_CLASSIC_PROXY_BLOCKING, EINVAL ),
112  STATUS_RESOURCE_IN_USE =
113    STATUS_BUILD( STATUS_CLASSIC_RESOURCE_IN_USE, EBUSY ),
114  STATUS_RESULT_TOO_LARGE =
115    STATUS_BUILD( STATUS_CLASSIC_UNSATISFIED, ERANGE ),
116  STATUS_SUCCESSFUL =
117    STATUS_BUILD( STATUS_CLASSIC_SUCCESSFUL, 0 ),
118  STATUS_TIMEOUT =
119    STATUS_BUILD( STATUS_CLASSIC_TIMEOUT, ETIMEDOUT ),
120  STATUS_TOO_MANY =
121    STATUS_BUILD( STATUS_CLASSIC_TOO_MANY, EAGAIN ),
122  STATUS_UNAVAILABLE =
123    STATUS_BUILD( STATUS_CLASSIC_UNSATISFIED, EBUSY ),
124  STATUS_UNSATISFIED =
125    STATUS_BUILD( STATUS_CLASSIC_UNSATISFIED, EAGAIN )
126} Status_Control;
127
128#ifdef __cplusplus
129}
130#endif /* __cplusplus */
131
132#endif /* _RTEMS_SCORE_STATUS_H */
Note: See TracBrowser for help on using the repository browser.