Skip to content

Commit

Permalink
Merge pull request #1158 from nasa/integration-candidate
Browse files Browse the repository at this point in the history
osal Integration candidate: 2021-09-21
  • Loading branch information
astrogeco authored Sep 22, 2021
2 parents 2a2defb + 9bac361 commit 42af0f7
Show file tree
Hide file tree
Showing 26 changed files with 533 additions and 91 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ set(BSP_SRCLIST
src/bsp/shared/src/bsp_default_app_run.c
src/bsp/shared/src/bsp_default_app_startup.c
src/bsp/shared/src/bsp_default_symtab.c
src/bsp/shared/src/bsp_default_resourcecfg.c
)

# Define the external "osal_bsp" static library target
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ The autogenerated OSAL user's guide can be viewed at <https://github.com/nasa/cF

## Version History

### Development Build: v5.1.0-rc1+dev619

- Enable symbol api test and MIR dump too large
- MIR symbol too long or table to long for osloader test
- Add bsp-specific configuration flag registry
- Add os-specifc socket flag function
- See <https://github.com/nasa/osal/pull/1158> and <https://github.com/nasa/cFS/pull/359>
### Development Build: v5.1.0-rc1+dev604

- Add typecast to memchr call
Expand Down
9 changes: 9 additions & 0 deletions src/bsp/shared/inc/bsp-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "osapi-common.h"
#include "osapi-bsp.h"
#include "osapi-error.h"
#include "osapi-idmap.h"

/*
* A set of simplified console control options
Expand Down Expand Up @@ -97,6 +98,14 @@ typedef struct
char ** ArgV; /* strings for boot/startup parameters */
int32 AppStatus; /* value which can be returned to the OS (0=nominal) */
osal_blockcount_t MaxQueueDepth; /* Queue depth limit supported by BSP (0=no limit) */

/*
* Configuration registry - abstract integer flags to select platform-specific options
* for each resource type. Flags are all platform-defined, and not every platform uses this
* feature.
*/
uint32 ResoureConfig[OS_OBJECT_TYPE_USER];

} OS_BSP_GlobalData_t;

/*
Expand Down
65 changes: 65 additions & 0 deletions src/bsp/shared/src/bsp_default_resourcecfg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer"
*
* Copyright (c) 2019 United States Government as represented by
* the Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* File: bsp_default_resourcecfg.c
*
* Purpose:
* Simple integer key/value table lookup to allow BSP-specific flags/options
* to be set for various resource types. Meanings are all platform-defined.
*
*/

#include "osapi-idmap.h"
#include "bsp-impl.h"

/* ---------------------------------------------------------
OS_BSP_SetResourceTypeConfig()
Helper function to register BSP-specific options.
--------------------------------------------------------- */
void OS_BSP_SetResourceTypeConfig(uint32 ResourceType, uint32 ConfigOptionValue)
{
if (ResourceType < OS_OBJECT_TYPE_USER)
{
OS_BSP_Global.ResoureConfig[ResourceType] = ConfigOptionValue;
}
}

/* ---------------------------------------------------------
OS_BSP_GetResourceTypeConfig()
Helper function to register BSP-specific options.
--------------------------------------------------------- */
uint32 OS_BSP_GetResourceTypeConfig(uint32 ResourceType)
{
uint32 ConfigOptionValue;

if (ResourceType < OS_OBJECT_TYPE_USER)
{
ConfigOptionValue = OS_BSP_Global.ResoureConfig[ResourceType];
}
else
{
ConfigOptionValue = 0;
}

return ConfigOptionValue;
}
16 changes: 16 additions & 0 deletions src/os/inc/osapi-bsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@
* @{
*/

/*----------------------------------------------------------------
Function: OS_BSP_SetResourceTypeConfig
Purpose: Sets BSP/platform-specific flags for the given resource type
Flags and bit meanings are all platform defined.
------------------------------------------------------------------*/
void OS_BSP_SetResourceTypeConfig(uint32 ResourceType, uint32 ConfigOptionValue);

/*----------------------------------------------------------------
Function: OS_BSP_SetResourceTypeConfig
Purpose: Gets BSP/platform-specific flags for the given resource type
Flags and bit meanings are all platform defined.
------------------------------------------------------------------*/
uint32 OS_BSP_GetResourceTypeConfig(uint32 ResourceType);

/*----------------------------------------------------------------
Function: OS_BSP_GetArgC
Expand Down
2 changes: 1 addition & 1 deletion src/os/inc/osapi-version.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
/*
* Development Build Macro Definitions
*/
#define OS_BUILD_NUMBER 604
#define OS_BUILD_NUMBER 619
#define OS_BUILD_BASELINE "v5.1.0-rc1"

/*
Expand Down
93 changes: 49 additions & 44 deletions src/os/portable/os-impl-bsd-sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,22 @@
DEFINES
****************************************************************************************/

/*
* The OS layer may define a macro to set the proper flags on newly-opened sockets.
* If not set, then a default implementation is used, which uses fcntl() to set O_NONBLOCK
*/
#ifndef OS_IMPL_SOCKET_FLAGS
#ifdef O_NONBLOCK
#define OS_IMPL_SOCKET_FLAGS O_NONBLOCK
#else
#define OS_IMPL_SOCKET_FLAGS 0 /* do not set any flags */
#endif
#endif

#ifndef OS_IMPL_SET_SOCKET_FLAGS
#define OS_IMPL_SET_SOCKET_FLAGS(tok) OS_SetSocketDefaultFlags_Impl(tok)
#endif

typedef union
{
char data[OS_SOCKADDR_MAX_LEN];
Expand All @@ -82,6 +98,37 @@ typedef union
*/
CompileTimeAssert(sizeof(OS_SockAddr_Accessor_t) == OS_SOCKADDR_MAX_LEN, SockAddrSize);

/*
* Default flags implementation: Set the O_NONBLOCK flag via fcntl().
* An implementation can also elect custom configuration by setting
* the OS_IMPL_SET_SOCKET_FLAGS macro to point to an alternate function.
*/
void OS_SetSocketDefaultFlags_Impl(const OS_object_token_t *token)
{
OS_impl_file_internal_record_t *impl;
int os_flags;

impl = OS_OBJECT_TABLE_GET(OS_impl_filehandle_table, *token);

os_flags = fcntl(impl->fd, F_GETFL);
if (os_flags == -1)
{
/* No recourse if F_GETFL fails - just report the error and move on. */
OS_DEBUG("fcntl(F_GETFL): %s\n", strerror(errno));
}
else
{
os_flags |= OS_IMPL_SOCKET_FLAGS;
if (fcntl(impl->fd, F_SETFL, os_flags) == -1)
{
/* No recourse if F_SETFL fails - just report the error and move on. */
OS_DEBUG("fcntl(F_SETFL): %s\n", strerror(errno));
}
}

impl->selectable = true;
}

/****************************************************************************************
Sockets API
***************************************************************************************/
Expand Down Expand Up @@ -160,23 +207,7 @@ int32 OS_SocketOpen_Impl(const OS_object_token_t *token)
* nonblock mode does improve robustness in the event that multiple tasks
* attempt to accept new connections from the same server socket at the same time.
*/
os_flags = fcntl(impl->fd, F_GETFL);
if (os_flags == -1)
{
/* No recourse if F_GETFL fails - just report the error and move on. */
OS_DEBUG("fcntl(F_GETFL): %s\n", strerror(errno));
}
else
{
os_flags |= OS_IMPL_SOCKET_FLAGS;
if (fcntl(impl->fd, F_SETFL, os_flags) == -1)
{
/* No recourse if F_SETFL fails - just report the error and move on. */
OS_DEBUG("fcntl(F_SETFL): %s\n", strerror(errno));
}
}

impl->selectable = OS_IMPL_SOCKET_SELECTABLE;
OS_IMPL_SET_SOCKET_FLAGS(token);

return OS_SUCCESS;
} /* end OS_SocketOpen_Impl */
Expand Down Expand Up @@ -397,7 +428,6 @@ int32 OS_SocketAccept_Impl(const OS_object_token_t *sock_token, const OS_object_
int32 return_code;
uint32 operation;
socklen_t addrlen;
int os_flags;
OS_impl_file_internal_record_t *sock_impl;
OS_impl_file_internal_record_t *conn_impl;

Expand Down Expand Up @@ -432,32 +462,7 @@ int32 OS_SocketAccept_Impl(const OS_object_token_t *sock_token, const OS_object_
{
Addr->ActualLength = addrlen;

/*
* Set the standard options on the filehandle by default --
* this may set it to non-blocking mode if the implementation supports it.
* any blocking would be done explicitly via the select() wrappers
*
* NOTE: The implementation still generally works without this flag set, but
* nonblock mode does improve robustness in the event that multiple tasks
* attempt to read from the same socket at the same time.
*/
os_flags = fcntl(conn_impl->fd, F_GETFL);
if (os_flags == -1)
{
/* No recourse if F_GETFL fails - just report the error and move on. */
OS_DEBUG("fcntl(F_GETFL): %s\n", strerror(errno));
}
else
{
os_flags |= OS_IMPL_SOCKET_FLAGS;
if (fcntl(conn_impl->fd, F_SETFL, os_flags) == -1)
{
/* No recourse if F_SETFL fails - just report the error and move on. */
OS_DEBUG("fcntl(F_SETFL): %s\n", strerror(errno));
}
}

conn_impl->selectable = OS_IMPL_SOCKET_SELECTABLE;
OS_IMPL_SET_SOCKET_FLAGS(conn_token);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/os/shared/inc/os-shared-sockets.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,5 +188,6 @@ int32 OS_SocketAddrSetPort_Impl(OS_SockAddr_t *Addr, uint16 PortNum);
* Not normally called outside the local unit, except during unit test
*/
void OS_CreateSocketName(const OS_object_token_t *token, const OS_SockAddr_t *Addr, const char *parent_name);
void OS_SetSocketDefaultFlags_Impl(const OS_object_token_t *token);

#endif /* OS_SHARED_SOCKETS_H */
1 change: 1 addition & 0 deletions src/os/vxworks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ if (OSAL_CONFIG_INCLUDE_NETWORK)
list(APPEND VXWORKS_IMPL_SRCLIST
src/os-impl-network.c
../portable/os-impl-bsd-sockets.c # Use BSD socket layer implementation
src/os-impl-sockets.c # Additional vxworks-specific code to handle socket flags
)
else()
list(APPEND VXWORKS_IMPL_SRCLIST
Expand Down
23 changes: 9 additions & 14 deletions src/os/vxworks/inc/os-impl-sockets.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#define OS_IMPL_SOCKETS_H

#include "os-impl-io.h"
#include "os-shared-globaldefs.h"

#include <fcntl.h>
#include <unistd.h>
Expand All @@ -37,25 +38,19 @@
#include <arpa/inet.h>
#include <netinet/in.h>
#include <hostLib.h>
#include <ioLib.h>

/*
* Socket descriptors should be usable with the select() API
* Override the socket flag set routine on this platform.
* This is required because some versions of VxWorks do not support
* the standard POSIX fcntl() opcodes, and must use ioctl() instead.
*/
#define OS_IMPL_SOCKET_SELECTABLE true

/*
* Use the O_NONBLOCK flag on sockets
*
* NOTE: the fcntl() F_GETFL/F_SETFL opcodes that set descriptor flags may not
* work correctly on some version of VxWorks.
*
* This flag is not strictly required, things still mostly work without it,
* but lack of this mode does introduce some potential race conditions if more
* than one task attempts to use the same descriptor handle at the same time.
*/
#define OS_IMPL_SOCKET_FLAGS O_NONBLOCK
#define OS_IMPL_SET_SOCKET_FLAGS(impl) OS_VxWorks_SetSocketFlags_Impl(impl)

/* The "in.h" header file supplied in VxWorks 6.9 is missing the "in_port_t" typedef */
typedef u_short in_port_t;

/* VxWorks-specific helper function to configure the socket flags on a connection */
void OS_VxWorks_SetSocketFlags_Impl(const OS_object_token_t *token);

#endif /* OS_IMPL_SOCKETS_H */
64 changes: 64 additions & 0 deletions src/os/vxworks/src/os-impl-sockets.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* NASA Docket No. GSC-18,370-1, and identified as "Operating System Abstraction Layer"
*
* Copyright (c) 2019 United States Government as represented by
* the Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* \file os-impl-sockets.c
* \ingroup vxworks
* \author joseph.p.hickey@nasa.gov
*
*/

/****************************************************************************************
INCLUDE FILES
***************************************************************************************/

#include "os-vxworks.h"
#include "os-shared-idmap.h"
#include "os-impl-io.h"
#include "os-impl-sockets.h"

/****************************************************************************************
INITIALIZATION FUNCTION
***************************************************************************************/

/*----------------------------------------------------------------
*
* Function: OS_VxWorks_ModuleAPI_Impl_Init
*
* Purpose: Local helper routine, not part of OSAL API.
*
*-----------------------------------------------------------------*/
void OS_VxWorks_SetSocketFlags_Impl(const OS_object_token_t *token)
{
OS_impl_file_internal_record_t *impl;
int os_flags;

impl = OS_OBJECT_TABLE_GET(OS_impl_filehandle_table, *token);

/* Use ioctl/FIONBIO on this platform, rather than standard fcntl() */
os_flags = 1;
if (ioctl(impl->fd, FIONBIO, &os_flags) == -1)
{
/* No recourse if ioctl fails - just report the error and move on. */
OS_DEBUG("ioctl(FIONBIO): %s\n", strerror(errno));
}

impl->selectable = true;
}
Loading

0 comments on commit 42af0f7

Please sign in to comment.