Base/core/exports/librr/memory.h

47 lines
2.5 KiB
C
Raw Normal View History

2023-12-01 15:36:36 +00:00
#ifndef RR_MEMORY_H
#define RR_MEMORY_H
2023-12-01 15:36:36 +00:00
#include <librr/types.h>
/// @brief Tests if two memory regions overlap partially or completely.
/// @param block1 Block to check for overlapping with block2.
// If the address of this block is higher than that of block2, the blocks will be swapped internally.
/// @param length1 The length of the first block.
/// @param block2 The second block to check for overlapping.
2023-12-02 16:11:33 +00:00
/// @param length2 The length of the second block.
2023-12-01 15:36:36 +00:00
/// @return Whether the two blocks overlap.
bool_t rr_mem_overlap(void *block1, usz_t length1, void *block2, usz_t length2);
/// @brief Checks if two memory blocks contain the equal data.
/// @param block1 Address of the data to be checked for equality with 'block2'
/// @param block2 Address of the other memory block. In cases where there is a clear correct version,
/// this should be the correct data to be checked against.
/// @param count How many bytes will be checked.
2023-12-02 16:11:33 +00:00
/// @return Whether the two memory regions are equal.
2023-12-01 15:36:36 +00:00
bool_t rr_memequ(void *block1, void *block2, usz_t count);
2023-12-02 16:11:33 +00:00
/// @brief Sets all bytes in a memory region all to one byte.
/// @param destination Address to the memory region to fill with one byte.
2023-12-01 15:36:36 +00:00
/// @param count Number of bytes to set; length of 'destination'
/// @param value Value to write to every bte of 'destination'.
void rr_memset(void *destination, usz_t count, u8_t value);
/// @brief Repeats a sequence until a number of bytes was filled, potentially only writing a sequence half-way.
/// @attention The sequence cannot be contained in the destination.
/// @param destination Address in memory in which the sequence will be repeated.
/// @param num_bytes How many bytes of the destination should be filled. The last sequence can be partially finished.
/// @param sequence Sequence of bytes which will be written to destination.
2023-12-02 16:11:33 +00:00
/// @param len_sequence Length of 'sequence'.
2023-12-01 15:36:36 +00:00
/// @return The number of attempted or partial repetitions which have been performed.
usz_t rr_memrep(void *destination, usz_t num_bytes, void *sequence, usz_t len_sequence);
2023-12-02 16:11:33 +00:00
/// @brief Copies a given number of bytes from a source memory region to a destination memory region.
/// @attention The source and the destination cannot overlap!
/// @param destination Memory region to which to write.
/// @param source Memory region from which to read the bytes to write into the destination.
/// @param num_bytes Number of bytes to copy from the source to the destination.
void rr_memcopy(void *destination, void *source, usz_t num_bytes);
2023-12-01 15:36:36 +00:00
#endif // RR_MEMORY_H