matos/core/alloc.h

46 lines
995 B
C
Raw Normal View History

2019-04-11 22:34:20 +02:00
#pragma once
#include "paging.h"
2024-01-29 23:27:10 +01:00
#include "stddef.h"
#include "types.h"
2019-04-11 22:34:20 +02:00
2023-05-01 17:58:35 +02:00
/** Arbitrary size allocator **/
2021-01-25 20:05:38 +01:00
/*
* Initialize malloc system
*/
2021-08-09 09:26:10 +02:00
int allocSetup(size_t sizeOfArea, vaddr_t *areaAddr, vaddr_t *descAddr, vaddr_t *entryAddr);
2021-01-25 20:05:38 +01:00
2023-05-01 17:58:35 +02:00
/*
* Add Slice for some simple/commun size
*/
2021-08-09 09:26:10 +02:00
int allocPopulate();
2021-01-25 20:05:38 +01:00
/*
* Allow malloc to allocate elements of this precise size.
* Otherwise the allocation will be in the closest biggest pool.
* */
2021-10-28 23:18:05 +02:00
int allocBookSlab(size_t size, size_t sizeSlab, int selfContained, int neverEmpty);
2021-01-25 20:05:38 +01:00
void *malloc(size_t size);
2021-10-04 21:20:16 +02:00
void *zalloc(size_t size);
2021-01-25 20:05:38 +01:00
void free(void *ptr);
/* Stuct definition shared for test purpose
*/
struct slabEntry {
vaddr_t page;
void *freeEl;
2022-07-29 00:17:52 +02:00
size_t size;//of the allocated page
2021-10-28 23:18:05 +02:00
bool_t full;//TODO replace by freeEl == NULL
struct slabEntry *next;
struct slabEntry *prev;
};
struct slabDesc {
struct slabEntry slab;
size_t size;
2021-10-28 23:18:05 +02:00
bool_t neverEmpty;
struct slabDesc *next;
struct slabDesc *prev;
2019-04-11 22:34:20 +02:00
};