Abstraction Layer (al)#

group al

Abstraction layer over the target platform (POSIX or bare metal).

rcsw/al/al.h#

Platform selection (POSIX or bare metal) for the abstraction layer.

Defines

RCSW_CONFIG_PLATFORM_POSIX#

Configuration setting to build the abstraction layer for/against POSIX OSes.

RCSW_CONFIG_PLATFORM_BAREMETAL#

Configuration setting to build the abstraction layer for bare-metal applications.

RCSW_PLATFORM_POSIX#

rcsw/al/clock.h#

Includes the clock interface for the platform RCSW is built for: rcsw/al/posix/clock.h or rcsw/al/baremetal/clock.h. Both declare the same functions.

struct timespec clock_monotime(void)#

Get the monotonic system time.

Returns:

The time.

struct timespec clock_realtime(void)#

Get the real system time.

Returns:

The time.

rcsw/al/types.h#

Base type definitions for RCSW.

Defines

__linux__#
bool_t#

A C boolean type: the same as bool (from <stdbool.h>) on all supported platforms.

Typedefs

typedef uint32_t dptr_t#

A C data pointer type.

All persistent runtime data in RCSW is stored via this type so that casts like:

(struct mystruct*)node->data

work as intended on all targets, provided the data structure’s elt_size is sizeof(struct mystruct): element i of a pool is at i * elt_size from a base aligned to RCSW_CONFIG_PTR_ALIGN, exactly like a C array of that type, so each element has its type’s alignment. (An elt_size that is not a multiple of RCSW_CONFIG_PTR_ALIGN does not give every element that stronger alignment.) On some embedded targets (e.g., ARM), if node->data points to a stack address with alignment 1, casting to a struct with alignment > 1 can cause a hardware trap because the compiler generates load/store instructions that assume the required alignment.

Choosing a value

Use the alignment of the most strictly aligned type stored in RCSW-managed memory. The library itself stores pointers and int32_t there, so it must be at least the target’s alignment of both (checked when the library is built): e.g., 8 on 64-bit targets, 4 on most 32-bit ones.

Implementation

Alignment is enforced by choosing an integer typedef whose natural alignment matches RCSW_CONFIG_PTR_ALIGN, so that array elements of that type are aligned to it. This is checked when the library is built: some ABIs (e.g., 32-bit x86) align uint64_t to 4 bytes, and 8 is rejected there.

Note

A C11 _Alignas approach was considered but rejected: _Alignas is not permitted on a typedef (C11 §6.7.5), and placing it on a single-member struct wrapper would change how dptr_t is used at every call site. The integer-width trick is already sufficient — _Alignof(uint32_t)==4 guarantees 4-byte-aligned array elements just as reliably as _Alignas(4) would.