Skip to content

Commit 4062fe6

Browse files
authored
Merge pull request #917 from nasa/integration-candidate
osal Integration Candidate: 2021-03-23
2 parents ead5723 + 65e301e commit 4062fe6

File tree

326 files changed

+845
-578
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

326 files changed

+845
-578
lines changed

CONTRIBUTING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Contributing Guide
2+
3+
Please see our [top-level contributing guide](https://github.com/nasa/cFS/blob/main/CONTRIBUTING.md) for more information on how to contribute.

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,35 @@ The autogenerated OSAL user's guide can be viewed at <https://github.com/nasa/cF
1111

1212
## Version History
1313

14+
15+
### Development Build: v5.1.0-rc1+dev347
16+
17+
- Moves copyblock size to a macro and add comments. Defines `OS_CP_BLOCK_SIZE` and adds clear documentation that it could be adjusted for page size, performance, etc.
18+
- Removes while loop
19+
- Replaces all #includes of <os and <OSC_ matches with " to match coding standard.
20+
- Consolidates the duplicated switch in `OS_SocketOpen_Impl`
21+
- Add const to input pointers for `OS_FdSet_ConvertIn_Impl` and `OS_ObjectIdTransactionFinish`
22+
- Removes network prototypes defined in `osapi_sockets.h` that are also in `osapi_network.h`
23+
- Removes `NULL` redefine from `common_types.h`
24+
- Adds `Contributing.md` that points to bundle-level contribution guide
25+
- Reports test cases that "fail" as "not implemented" with new `UtAssert_NA` macro instead of `UtPrintf`
26+
- Calls to `OS_SelectSingle` and `OS_SelectMultiple` will fail if an FD within the set is outside the range of the underlying `FD_SETSIZE` from the C library.
27+
- Fixes calculation used for the relative time interval in the `select()` call. Also adds a UT case that specifically exercises the carryover described. Fixes delay when this carry condition is hit
28+
- Documents algorithm that provides application-controlled timeout on the connection initiation. Also adds a debug statement if the connect fails for a reason other than `EINPROGRESS`. No impact to normal behavior.
29+
- Adds check for `EAGAIN` if the system fails to allocate kernel-internal resources.
30+
- Adds a `CompileTimeAssert` to confirm that the size of the abstract buffer for socket addresses is large enough to store any of the enabled address types thereby removing the need for runtime tests.
31+
- With this change, if `OS_SOCKADDR_MAX_LENis` not large enough for the address type, osal will fail to compile. This enforces that the abstract size is large enough for any/all enabled address types, regardless of what is actually used.
32+
- Adds missing functional test for `OS_ShellOutputToFile`
33+
- Add test for `fcntl()` error return of -1 and report errno. If setting `O_NONBLOCK` fails, then debug message is printed and blocking mode is used and timeouts will not work as a result.
34+
- Improves error codes when attempting to seek on a pipe/socket. Translates the `OS_ERR_OPERATION_NOT_SUPPORTED` error rather than "not implemented". The `ESPIPE` errno means that seeking is not supported on the given file handle.
35+
- Renames `OS_U32ValueWrapper_t` as `OS_VoidPtrValueWrapper_t` to better indicate its purpose. The point is to pass a value through a `void*`. Adds a compile-time assert to check that this is only used to directly pass values which have a size of less than or equal to sizeof(void*).
36+
- Refactors the return statement for `OS_FileSys_FindVirtMountPoint()` so it is easier to read and adds some informational comments.
37+
- Reports an error if calling `timer_gettime` after `timer_settime` fails.
38+
- Returns `OS_ERROR` status to caller after an error on moduleInfoGet()
39+
- Removes an extraneous/unreachable OS_ObjectIdDefined check and its accompanying debug statement. The only way this check could have been reached would be if the normal unlock process was bypassed such that the underlying OS mutex was unlocked but OSAL state still had it owned by a task. This condition never happens at runtime.
40+
- Updates documentation for `OS_MAX_MODULE`
41+
- See <https://github.com/nasa/osal/pull/917>
42+
1443
### Development Build: v5.1.0-rc1+dev297
1544

1645
- Fix #836, Add Testing Tools to the Security Policy

src/os/inc/common_types.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,6 @@ extern "C"
125125
*/
126126
typedef void (*OS_ArgCallback_t)(osal_id_t object_id, void *arg);
127127

128-
#ifndef NULL /* pointer to nothing */
129-
#define NULL ((void *)0)
130-
#endif
131-
132128
/*
133129
** Check Sizes
134130
*/

src/os/inc/osapi-sockets.h

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -368,35 +368,6 @@ int32 OS_SocketGetIdByName(osal_id_t *sock_id, const char *sock_name);
368368
*/
369369
int32 OS_SocketGetInfo(osal_id_t sock_id, OS_socket_prop_t *sock_prop);
370370

371-
/*-------------------------------------------------------------------------------------*/
372-
/**
373-
* @brief Gets the network ID of the local machine
374-
*
375-
* The ID is an implementation-defined value and may not be consistent
376-
* in meaning across different platform types.
377-
*
378-
* @note This API may be removed in a future version of OSAL due to
379-
* inconsistencies between platforms.
380-
*
381-
* @return The ID or fixed value of -1 if the host id could not be found.
382-
* Note it is not possible to differentiate between error codes and valid
383-
* network IDs here. It is assumed, however, that -1 is never a valid ID.
384-
*/
385-
int32 OS_NetworkGetID(void);
386-
387-
/*-------------------------------------------------------------------------------------*/
388-
/**
389-
* @brief Gets the local machine network host name
390-
*
391-
* If configured in the underlying network stack,
392-
* this function retrieves the local hostname of the system.
393-
*
394-
* @param[out] host_name Buffer to hold name information
395-
* @param[in] name_len Maximum length of host name buffer
396-
*
397-
* @return Execution status, see @ref OSReturnCodes
398-
*/
399-
int32 OS_NetworkGetHostName(char *host_name, size_t name_len);
400371
/**@}*/
401372

402373
#endif

src/os/inc/osapi-version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
/*
3333
* Development Build Macro Definitions
3434
*/
35-
#define OS_BUILD_NUMBER 297
35+
#define OS_BUILD_NUMBER 347
3636
#define OS_BUILD_BASELINE "v5.1.0-rc1"
3737

3838
/*

src/os/portable/os-impl-bsd-select.c

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -72,32 +72,40 @@
7272
*
7373
* returns: Highest numbered file descriptor in the output fd_set
7474
*-----------------------------------------------------------------*/
75-
static int OS_FdSet_ConvertIn_Impl(fd_set *os_set, OS_FdSet *OSAL_set)
75+
static int32 OS_FdSet_ConvertIn_Impl(int *os_maxfd, fd_set *os_set, const OS_FdSet *OSAL_set)
7676
{
7777
size_t offset;
7878
size_t bit;
7979
osal_index_t id;
8080
uint8 objids;
8181
int osfd;
82-
int maxfd;
82+
int32 status;
8383

84-
maxfd = -1;
84+
status = OS_SUCCESS;
8585
for (offset = 0; offset < sizeof(OSAL_set->object_ids); ++offset)
8686
{
8787
objids = OSAL_set->object_ids[offset];
8888
bit = 0;
8989
while (objids != 0)
9090
{
91-
if (objids & 0x01)
91+
id = OSAL_INDEX_C((offset * 8) + bit);
92+
if ((objids & 0x01) != 0 && id < OS_MAX_NUM_OPEN_FILES)
9293
{
93-
id = OSAL_INDEX_C((offset * 8) + bit);
9494
osfd = OS_impl_filehandle_table[id].fd;
95-
if (osfd >= 0 && OS_impl_filehandle_table[id].selectable)
95+
if (osfd >= 0)
9696
{
97-
FD_SET(osfd, os_set);
98-
if (osfd > maxfd)
97+
if (osfd >= FD_SETSIZE || !OS_impl_filehandle_table[id].selectable)
98+
{
99+
/* out of range of select() implementation */
100+
status = OS_ERR_OPERATION_NOT_SUPPORTED;
101+
}
102+
else
99103
{
100-
maxfd = osfd;
104+
FD_SET(osfd, os_set);
105+
if (osfd > *os_maxfd)
106+
{
107+
*os_maxfd = osfd;
108+
}
101109
}
102110
}
103111
}
@@ -106,7 +114,7 @@ static int OS_FdSet_ConvertIn_Impl(fd_set *os_set, OS_FdSet *OSAL_set)
106114
}
107115
}
108116

109-
return maxfd;
117+
return status;
110118
} /* end OS_FdSet_ConvertIn_Impl */
111119

112120
/*----------------------------------------------------------------
@@ -134,9 +142,9 @@ static void OS_FdSet_ConvertOut_Impl(fd_set *output, OS_FdSet *Input)
134142
bit = 0;
135143
while (objids != 0)
136144
{
137-
if (objids & 0x01)
145+
id = OSAL_INDEX_C((offset * 8) + bit);
146+
if ((objids & 0x01) != 0 && id < OS_MAX_NUM_OPEN_FILES)
138147
{
139-
id = OSAL_INDEX_C((offset * 8) + bit);
140148
osfd = OS_impl_filehandle_table[id].fd;
141149
if (osfd < 0 || !FD_ISSET(osfd, output))
142150
{
@@ -214,12 +222,12 @@ static int32 OS_DoSelect(int maxfd, fd_set *rd_set, fd_set *wr_set, int32 msecs)
214222
if (tv.tv_usec < 0)
215223
{
216224
tv.tv_usec += 1000000;
217-
++tv.tv_sec;
225+
--tv.tv_sec;
218226
}
219227
}
220228

221229
os_status = select(maxfd + 1, rd_set, wr_set, NULL, tvptr);
222-
} while (os_status < 0 && errno == EINTR);
230+
} while (os_status < 0 && (errno == EINTR || errno == EAGAIN));
223231

224232
if (os_status < 0)
225233
{
@@ -267,6 +275,12 @@ int32 OS_SelectSingle_Impl(const OS_object_token_t *token, uint32 *SelectFlags,
267275
return OS_ERR_OPERATION_NOT_SUPPORTED;
268276
}
269277

278+
if (impl->fd >= FD_SETSIZE)
279+
{
280+
/* out of range of select() implementation */
281+
return OS_ERR_OPERATION_NOT_SUPPORTED;
282+
}
283+
270284
if (*SelectFlags != 0)
271285
{
272286
FD_ZERO(&wr_set);
@@ -319,41 +333,41 @@ int32 OS_SelectMultiple_Impl(OS_FdSet *ReadSet, OS_FdSet *WriteSet, int32 msecs)
319333
{
320334
fd_set wr_set;
321335
fd_set rd_set;
322-
int osfd;
323336
int maxfd;
324337
int32 return_code;
325338

326-
/*
327-
* This return code will be used if the set(s) do not
328-
* contain any file handles capable of select(). It
329-
* will be overwritten with the real result of the
330-
* select call, if selectable file handles were specified.
331-
*/
332-
return_code = OS_ERR_OPERATION_NOT_SUPPORTED;
333339
FD_ZERO(&rd_set);
334340
FD_ZERO(&wr_set);
335341
maxfd = -1;
336342
if (ReadSet != NULL)
337343
{
338-
osfd = OS_FdSet_ConvertIn_Impl(&rd_set, ReadSet);
339-
if (osfd > maxfd)
344+
return_code = OS_FdSet_ConvertIn_Impl(&maxfd, &rd_set, ReadSet);
345+
if (return_code != OS_SUCCESS)
340346
{
341-
maxfd = osfd;
347+
return return_code;
342348
}
343349
}
344350
if (WriteSet != NULL)
345351
{
346-
osfd = OS_FdSet_ConvertIn_Impl(&wr_set, WriteSet);
347-
if (osfd > maxfd)
352+
return_code = OS_FdSet_ConvertIn_Impl(&maxfd, &wr_set, WriteSet);
353+
if (return_code != OS_SUCCESS)
348354
{
349-
maxfd = osfd;
355+
return return_code;
350356
}
351357
}
352358

353359
if (maxfd >= 0)
354360
{
355361
return_code = OS_DoSelect(maxfd, &rd_set, &wr_set, msecs);
356362
}
363+
else
364+
{
365+
/*
366+
* This return code will be used if the set(s) were
367+
* both empty/NULL or otherwise did not contain valid filehandles.
368+
*/
369+
return_code = OS_ERR_INVALID_ID;
370+
}
357371

358372
if (return_code == OS_SUCCESS)
359373
{

src/os/portable/os-impl-bsd-sockets.c

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ typedef union
7373
#endif
7474
} OS_SockAddr_Accessor_t;
7575

76+
/*
77+
* Confirm that the abstract socket address buffer size (OS_SOCKADDR_MAX_LEN) is
78+
* large enough to store any of the enabled address types. If this is true, the
79+
* size of the above union will match OS_SOCKADDR_MAX_LEN. However, if any
80+
* implemention-provided struct types are larger than this, the union will be
81+
* larger, and this indicates a configuration error.
82+
*/
83+
CompileTimeAssert(sizeof(OS_SockAddr_Accessor_t) == OS_SOCKADDR_MAX_LEN, SockAddrSize);
84+
7685
/****************************************************************************************
7786
Sockets API
7887
***************************************************************************************/
@@ -102,10 +111,13 @@ int32 OS_SocketOpen_Impl(const OS_object_token_t *token)
102111
switch (stream->socket_type)
103112
{
104113
case OS_SocketType_DATAGRAM:
105-
os_type = SOCK_DGRAM;
114+
os_type = SOCK_DGRAM;
115+
os_proto = IPPROTO_UDP;
106116
break;
117+
107118
case OS_SocketType_STREAM:
108-
os_type = SOCK_STREAM;
119+
os_type = SOCK_STREAM;
120+
os_proto = IPPROTO_TCP;
109121
break;
110122

111123
default:
@@ -126,17 +138,6 @@ int32 OS_SocketOpen_Impl(const OS_object_token_t *token)
126138
return OS_ERR_NOT_IMPLEMENTED;
127139
}
128140

129-
/* Only AF_INET* at this point, can add cases if support is expanded */
130-
switch (stream->socket_type)
131-
{
132-
case OS_SocketType_DATAGRAM:
133-
os_proto = IPPROTO_UDP;
134-
break;
135-
case OS_SocketType_STREAM:
136-
os_proto = IPPROTO_TCP;
137-
break;
138-
}
139-
140141
impl->fd = socket(os_domain, os_type, os_proto);
141142
if (impl->fd < 0)
142143
{
@@ -200,7 +201,7 @@ int32 OS_SocketBind_Impl(const OS_object_token_t *token, const OS_SockAddr_t *Ad
200201
break;
201202
}
202203

203-
if (addrlen == 0 || addrlen > OS_SOCKADDR_MAX_LEN)
204+
if (addrlen == 0)
204205
{
205206
return OS_ERR_BAD_ADDRESS;
206207
}
@@ -273,10 +274,24 @@ int32 OS_SocketConnect_Impl(const OS_object_token_t *token, const OS_SockAddr_t
273274
{
274275
if (errno != EINPROGRESS)
275276
{
277+
OS_DEBUG("connect: %s\n", strerror(errno));
276278
return_code = OS_ERROR;
277279
}
278280
else
279281
{
282+
/*
283+
* If the socket was created in nonblocking mode (O_NONBLOCK flag) then the connect
284+
* runs in the background and connect() returns EINPROGRESS. In this case we still
285+
* want to provide the "normal" (blocking) semantics to the calling app, such that
286+
* when OS_SocketConnect() returns, the socket is ready for use.
287+
*
288+
* To provide consistent behavior to calling apps, this does a select() to wait
289+
* for the socket to become writable, meaning that the remote side is connected.
290+
*
291+
* An important point here is that the calling app can control the timeout. If the
292+
* normal/blocking connect() was used, the OS/IP stack controls the timeout, and it
293+
* can be quite long.
294+
*/
280295
operation = OS_STREAM_STATE_WRITABLE;
281296
if (impl->selectable)
282297
{
@@ -290,6 +305,10 @@ int32 OS_SocketConnect_Impl(const OS_object_token_t *token, const OS_SockAddr_t
290305
}
291306
else
292307
{
308+
/*
309+
* The SO_ERROR socket flag should also read back zero.
310+
* If not zero, something went wrong during connect
311+
*/
293312
sockopt = 0;
294313
slen = sizeof(sockopt);
295314
os_status = getsockopt(impl->fd, SOL_SOCKET, SO_ERROR, &sockopt, &slen);
@@ -560,7 +579,7 @@ int32 OS_SocketAddrInit_Impl(OS_SockAddr_t *Addr, OS_SocketDomain_t Domain)
560579
break;
561580
}
562581

563-
if (addrlen == 0 || addrlen > OS_SOCKADDR_MAX_LEN)
582+
if (addrlen == 0)
564583
{
565584
return OS_ERR_NOT_IMPLEMENTED;
566585
}

src/os/portable/os-impl-posix-io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ int32 OS_GenericSeek_Impl(const OS_object_token_t *token, int32 offset, uint32 w
138138
* Use a different error code to differentiate from an
139139
* error involving a bad whence/offset
140140
*/
141-
retval = OS_ERR_NOT_IMPLEMENTED;
141+
retval = OS_ERR_OPERATION_NOT_SUPPORTED;
142142
}
143143
else
144144
{

src/os/posix/inc/os-impl-tasks.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#ifndef OS_IMPL_TASKS_H
2929
#define OS_IMPL_TASKS_H
3030

31-
#include <os-shared-task.h>
31+
#include "os-shared-task.h"
3232

3333
#include "osconfig.h"
3434
#include <pthread.h>

src/os/posix/inc/os-posix.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
/*
5454
* Use the global definitions from the shared layer
5555
*/
56-
#include <os-shared-globaldefs.h>
56+
#include "os-shared-globaldefs.h"
5757

5858
/****************************************************************************************
5959
DEFINES

0 commit comments

Comments
 (0)