Safe API Framework
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
Toggle main menu visibility
Loading...
Searching...
No Matches
sapi_safe_ptr.h
Go to the documentation of this file.
1
36
#ifndef SAFEAPI_OAL_SAFE_PTR_H
37
#define SAFEAPI_OAL_SAFE_PTR_H
38
39
#include "
safeapi/utils/status/sapi_status.h
"
40
#include "
safeapi/utils/types/sapi_types.h
"
41
42
#ifdef __cplusplus
43
extern
"C"
{
44
#endif
45
54
typedef
struct
55
{
56
void
*
ptr
;
57
size_t
size
;
58
uint32_t
canary
;
59
}
sapi_safe_ptr_t
;
60
73
sapi_status_t
sapi_safe_ptr_init
(
sapi_safe_ptr_t
*sp,
void
*ptr,
size_t
size);
74
82
bool
sapi_safe_ptr_is_valid
(
const
sapi_safe_ptr_t
*sp);
83
95
sapi_status_t
sapi_safe_ptr_get
(
const
sapi_safe_ptr_t
*sp,
void
**out_ptr);
96
115
sapi_status_t
sapi_safe_ptr_offset
(
const
sapi_safe_ptr_t
*sp,
size_t
offset,
size_t
length,
void
**out_ptr);
116
129
void
sapi_safe_ptr_invalidate
(
sapi_safe_ptr_t
*sp);
130
131
#ifdef __cplusplus
132
}
133
#endif
134
135
#endif
/* SAFEAPI_OAL_SAFE_PTR_H */
136
/* SAFEPTR */
sapi_safe_ptr_is_valid
bool sapi_safe_ptr_is_valid(const sapi_safe_ptr_t *sp)
Checks whether sp currently wraps a valid, non-invalidated region.
Definition
sapi_safe_ptr.c:33
sapi_safe_ptr_invalidate
void sapi_safe_ptr_invalidate(sapi_safe_ptr_t *sp)
Invalidates sp: clears the wrapped pointer and the canary, so every subsequent access on sp fails SAP...
Definition
sapi_safe_ptr.c:105
sapi_safe_ptr_get
sapi_status_t sapi_safe_ptr_get(const sapi_safe_ptr_t *sp, void **out_ptr)
Retrieves the wrapped pointer directly (the whole region, no offset) after validating it.
Definition
sapi_safe_ptr.c:46
sapi_safe_ptr_init
sapi_status_t sapi_safe_ptr_init(sapi_safe_ptr_t *sp, void *ptr, size_t size)
Initializes sp to wrap [ptr, ptr + size), writing the canary.
Definition
sapi_safe_ptr.c:17
sapi_safe_ptr_offset
sapi_status_t sapi_safe_ptr_offset(const sapi_safe_ptr_t *sp, size_t offset, size_t length, void **out_ptr)
Computes a bounds-checked pointer at offset within sp's region, verifying the caller's intended acces...
Definition
sapi_safe_ptr.c:66
sapi_status_t
sapi_status_t
Common result/status codes.
Definition
sapi_status.h:27
sapi_status.h
Common status/error codes returned by every Safe API Framework function. Shared across all OS Abstrac...
sapi_types.h
Common fixed-width types and the caller-owned-storage handle pattern used by every OAL service (see A...
sapi_safe_ptr_t
A bounds-checked, canary-protected wrapper around one raw memory region. Opaque to callers in spirit ...
Definition
sapi_safe_ptr.h:55
sapi_safe_ptr_t::size
size_t size
Definition
sapi_safe_ptr.h:57
sapi_safe_ptr_t::ptr
void * ptr
Definition
sapi_safe_ptr.h:56
sapi_safe_ptr_t::canary
uint32_t canary
Definition
sapi_safe_ptr.h:58
include
safeapi
oal
memory
sapi_safe_ptr.h
Generated by
1.18.0