scsl/Arena.h

45 lines
1.1 KiB
C
Raw Normal View History

2023-10-06 03:13:46 +00:00
#ifndef KIMODEM_ARENA_H
#define KIMODEM_ARENA_H
#include <sys/stat.h>
#include <cstddef>
#include <cstdint>
typedef struct {
2023-10-06 06:08:35 +00:00
uint8_t *Store;
size_t Size;
2023-10-06 03:13:46 +00:00
int fd;
2023-10-06 06:08:35 +00:00
uint8_t Type;
2023-10-06 03:13:46 +00:00
} Arena;
2023-10-06 06:08:35 +00:00
/*
* InitializeArena is intended for use only with systems that
* do not initialize new variables to zero. It should be called
* exactly once, at the start of the program. Any other time the
* arena needs to be reset, it should be called with clear_arena
* or destroy_arena.
*/
void InitializeArena(Arena &arena);
int NewStaticArena(Arena &, uint8_t *, size_t);
int AllocNewArena(Arena &, size_t);
2023-10-06 03:13:46 +00:00
#if defined(__linux__)
2023-10-06 06:08:35 +00:00
int MMapArena(Arena &, int); /* arena will own fd */
int CreateArena(Arena &arena, const char *path, size_t size, mode_t mode);
int OpenArena(Arena &, const char *, size_t);
2023-10-06 03:13:46 +00:00
#endif
2023-10-06 06:08:35 +00:00
void ClearArena(Arena &);
int DestroyArena(Arena &); /* dispose of any memory used by arena */
2023-10-06 03:13:46 +00:00
/* DANGER: if arena is file backed (mmap or open), DO NOT WRITE TO THE
* BACKING FILE! */
2023-10-06 06:08:35 +00:00
int WriteArena(const Arena &arena, const char *path);
void DisplayArena(const Arena &arena);
2023-10-06 03:13:46 +00:00
#endif