You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
naka/include/map.h

45 lines
804 B

//! Memory mapping abstraction
#ifndef _MAP_H
#define _MAP_H
#include <stdbool.h>
#include "ints.h"
typedef enum mm_err {
MAP_ERR_UNKNOWN = 0,
MAP_SUCCESS = 1,
MAP_ERR_MMAP,
MAP_ERR_UNMAP,
MAP_ERR_OPEN,
MAP_ERR_CLOSE,
} map_result_t;
typedef union memory_map {
// Common
struct {
void* origin;
usize len;
};
// Specific to anon / file
struct mm_file {
void* origin;
usize len;
off_t fd_offset;
int fd;
} file;
struct mm_anon {
void* origin;
usize len;
} anon;
} map_t;
map_result_t map_fd(int fd, bool write, usize size, off_t offset, map_t *pOUT map);
map_result_t map_file(const char* file, bool write, usize size, off_t offset, map_t *pOUT map);
map_result_t map_anon(void* ptr, usize len, map_t *pOUT map);
map_result_t map_free(map_t map);
#endif /* _MAP_H */