1
0
mirror of https://gitlab.os-k.eu/os-k-team/os-k.git synced 2023-08-25 14:03:10 +02:00
os-k/include/mm/malloc.h
Julian Barathieu 35be48eec4 stuff
2019-05-27 19:21:11 +02:00

103 lines
3.3 KiB
C

//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
// Desc: Memory allocation functions //
// //
// //
// Copyright © 2018-2019 The OS/K Team //
// //
// This file is part of OS/K. //
// //
// OS/K is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// any later version. //
// //
// OS/K is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY//without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
//----------------------------------------------------------------------------//
#ifndef _KERNEL_H
#include <kernel.h>
#endif
#ifndef _LIB_LIST_H
#include <lib/list.h>
#endif
#ifndef _MM_MALLOC_H
#define _MM_MALLOC_H
#ifndef PAGESIZE
#define PAGESIZE 4096
#endif
typedef struct Cache_t Cache_t;
typedef struct Pool_t Pool_t;
// Operation on objects
typedef void (*ObjCtor_t)(Cache_t *cache,
Pool_t *pool,
void *obj);
//
// A cache containing many pools
//
struct Cache_t
{
// Synchronization
Spinlock_t lock;
// Cache name
char name[64];
// Size of each object
size_t objsize;
// Number of objects allocated
size_t objused;
// Number of available objects including unused
size_t objtotal;
// Number of objects per pool
size_t objperpool;
// Object constructor
ObjOper_t *ctor;
// Object destructor
ObjOper_t *dtor;
// Object pools without any allocated object
ListHead_t *freepools;
// Object pools containing some allocated objects
ListHead_t *usedpools;
// Objects pools containing no unallocated object
ListHead_t *fullpools;
};
//
// A pool of allocable objects
// Takes a fixed amount of pages
//
struct Pool_t
{
};
//
// Allocates memory from the kernel heap
//
void *kmalloc(size_t req, uint flags);
void *kmemalign(size_t req, uint align, uint flags);
#endif