|
rlib
Convenience library for useful things
|
Inline memcmp / memcpy / memmove / memset wrappers with rlib's NULL-tolerant convention.
More...
Files | |
| file | rmemops.h |
| Inline byte-buffer primitives (see Inline byte-buffer primitives). | |
Macros | |
| #define | r_memclear(ptr, size) r_memset (ptr, 0, size) |
Convenience wrapper: r_memset (ptr, 0, size). | |
Functions | |
| static int | r_memcmp (rconstpointer a, rconstpointer b, rsize size) |
Lexicographically compare size bytes of a and b. | |
| static rpointer | r_memset (rpointer a, int v, rsize size) |
Fill size bytes at a with byte value v. | |
| static rpointer | r_memcpy (void *R_ATTR_RESTRICT dst, const void *R_ATTR_RESTRICT src, rsize size) |
Copy size bytes from src to dst. | |
| static rpointer | r_memmove (rpointer dst, rconstpointer src, rsize size) |
Copy size bytes from src to dst, allowing overlap. | |
Inline memcmp / memcpy / memmove / memset wrappers with rlib's NULL-tolerant convention.
These live in rlib/types/ rather than rlib/rmem.h because rendianness.h's load / store helpers (r_load_be{16,32,64} et al.) need them, and that header is processed earlier in the include chain than rmem.h. The bulk of rmem.h's API (allocators, vtables, scanners) continues to live there.
Each function is a static inline wrapper around the corresponding libc primitive plus rlib's NULL-tolerant convention. The libc primitive is a "magic" intrinsic on every modern compiler that gets replaced with inline movdqu / vld1q / rep movs for known constant sizes, so wrapping the call site behind a function-pointer indirection (or an extern R_API symbol) would defeat the point.
For the non-inline cousins:
r_memcmp_ct — constant-time compare, stays externr_memclear_secure — optimiser-resistant zero, stays externboth live in rmem.h.
|
inlinestatic |
Lexicographically compare size bytes of a and b.
Thin wrapper around libc memcmp with NULL-tolerant semantics: a NULL pointer compares less than a non-NULL pointer, two NULLs compare equal. For constant-time tag / digest comparison use r_memcmp_ct from rmem.h instead.
| a | First buffer (may be NULL). |
| b | Second buffer (may be NULL). |
| size | Number of bytes to compare. |
a<b, positive if a>b, zero if equal.
|
inlinestatic |
Copy size bytes from src to dst.
Thin wrapper around libc memcpy. Requires src and dst not to overlap (use r_memmove if they might). A NULL src or NULL dst is a no-op (returns NULL); otherwise returns dst.
| dst | Destination buffer (may be NULL). |
| src | Source buffer (may be NULL). |
| size | Number of bytes to copy. |
dst if both pointers were non-NULL, NULL otherwise.
|
inlinestatic |
Copy size bytes from src to dst, allowing overlap.
Thin wrapper around libc memmove. Use when src and dst may overlap; r_memcpy is faster when they're known disjoint. A NULL pointer on either side is a no-op (returns NULL).
| dst | Destination buffer (may be NULL). |
| src | Source buffer (may be NULL). |
| size | Number of bytes to copy. |
dst if both pointers were non-NULL, NULL otherwise. Fill size bytes at a with byte value v.
Thin wrapper around libc memset. A NULL a is a no-op (returns NULL). For wiping secret material use r_memclear_secure from rmem.h - the optimiser is free to elide regular r_memset on a buffer that's about to be freed.
| a | Destination buffer (may be NULL). |
| v | Byte value to write (low 8 bits used). |
| size | Number of bytes to write. |
a.