tkernel_2/include/sys/memalloc.h | bare source | permlink (0.02 seconds) |
1: /* 2: *---------------------------------------------------------------------- 3: * T-Kernel 2.0 Software Package 4: * 5: * Copyright 2011 by Ken Sakamura. 6: * This software is distributed under the latest version of T-License 2.x. 7: *---------------------------------------------------------------------- 8: * 9: * Released by T-Engine Forum(http://www.t-engine.org/) at 2011/05/17. 10: * Modified by TRON Forum(http://www.tron.org/) at 2015/06/01. 11: * 12: *---------------------------------------------------------------------- 13: */ 14: 15: /* 16: * @(#)memalloc.h (sys) 17: * 18: * Memory allocation library 19: */ 20: 21: #ifndef __SYS_MEMALLOC_H__ 22: #define __SYS_MEMALLOC_H__ 23: 24: #include <basic.h> 25: #include <tk/typedef.h> 26: #include <sys/queue.h> 27: 28: #ifdef __cplusplus 29: extern "C" { 30: #endif 31: 32: /* 33: * Memory allocation control information 34: * In the address, the &areaque position must be aligned in 35: * 8 byte units. (The lower three bits must be 0) 36: * The 'nouse' area is used to adjust the address. 37: * It is not possible to write to 'nouse'. 38: */ 39: typedef struct MemoryAllocateControlBlock { 40: const QUEUE nouse; /* Area used for alignment */ 41: 42: /* Area queue connects the various partitioned areas of the 43: * allocated page. 44: * Addresses are arranged in ascending order within each page, 45: * and in no particular order between pages. */ 46: QUEUE areaque; 47: /* Free queue connects unused areas within the allocated 48: * page. Arranged in order of free area size, starting with 49: * the smallest. */ 50: QUEUE freeque; 51: 52: UINT pagesz; /* Page size (number of bytes) */ 53: UINT mematr; /* Memory attributes */ 54: INT testmode; /* Test mode */ 55: 56: /* Memory allocate/release function */ 57: void* (*getblk)( INT nblk, UINT mematr ); 58: void (*relblk)( void *ptr ); 59: } MACB; 60: 61: /* 62: * Correction to align the &areaque position with the 8 byte boundary 63: */ 64: #define AlignMACB(macb) ( (MACB*)((UW)macb & ~0x00000007U) ) 65: 66: IMPORT ER _tkm_init( UINT mematr, MACB *macb ); /* for T-Kernel use */ 67: IMPORT ER _mem_init( UINT mematr, MACB *macb ); /* for extension use */ 68: 69: IMPORT void* _mem_malloc( size_t size, MACB *macb ); 70: IMPORT void* _mem_calloc( size_t nmemb, size_t size, MACB *macb ); 71: IMPORT void* _mem_realloc( void *ptr, size_t size, MACB *macb ); 72: IMPORT void _mem_free( void *ptr, MACB *macb ); 73: IMPORT void _mem_malloctest( int mode, MACB *macb ); 74: IMPORT BOOL _mem_malloccheck( void *ptr, MACB *macb ); 75: 76: /* 77: * Option setting: minimum fragment size 78: * must be size 'sizeof(QUEUE) * 2' or more. 79: */ 80: IMPORT size_t _mem_minfragment; 81: 82: #ifdef __cplusplus 83: } 84: #endif 85: #endif /* __SYS_MEMALLOC_H__ */