2019-05-27 19:21:11 +02:00
|
|
|
//----------------------------------------------------------------------------//
|
2020-09-27 17:33:48 +02:00
|
|
|
// OS on Kaleid //
|
2019-05-27 19:21:11 +02:00
|
|
|
// //
|
|
|
|
// Desc: Memory allocation functions //
|
|
|
|
// //
|
|
|
|
// //
|
2021-02-18 19:54:35 +01:00
|
|
|
// Copyright © 2018-2021 The OS/K Team //
|
2019-05-27 19:21:11 +02:00
|
|
|
// //
|
|
|
|
// 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
|
2020-02-19 22:19:58 +01:00
|
|
|
#include <liblist.h>
|
2019-05-27 19:21:11 +02:00
|
|
|
#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
|
|
|
|
|