tkernel_2/lib/libtk/src/mem.h | bare source | permlink (0.00 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: * @(#)mem.h (libtk) 17: * 18: * Memory local allocation library 19: */ 20: 21: #include <basic.h> 22: #include <sys/memalloc.h> 23: #include <libstr.h> 24: 25: /* 26: * Minimum fragmentation unit 27: * Since memory is allocated in ROUNDSZ units, 28: * the lower three bits of the address must be 0. 29: * These low three bits are used in the flag in the area queue. 30: */ 31: #define ROUNDSZ ( sizeof(QUEUE) ) /* 8 byte */ 32: #define ROUND(sz) ( ((UINT)(sz) + (ROUNDSZ-1)) & ~(ROUNDSZ-1) ) 33: 34: /* Minimum fragment size */ 35: #define MIN_FRAGMENT ( _mem_minfragment ) 36: 37: /* 38: * Flag that uses the lower bits of the area queue prev 39: */ 40: #define AREA_USE 0x00000001U /* In use */ 41: #define AREA_TOP 0x00000002U /* Top of page */ 42: #define AREA_END 0x00000004U /* End of page */ 43: #define AREA_MASK 0x00000007U 44: 45: #define setAreaFlag(q, f) ( (q)->prev = (QUEUE*)((UW)(q)->prev | (UW)(f)) ) 46: #define clrAreaFlag(q, f) ( (q)->prev = (QUEUE*)((UW)(q)->prev & ~(UW)(f)) ) 47: #define chkAreaFlag(q, f) ( ((UW)(q)->prev & (UW)(f)) != 0 ) 48: 49: #define Mask(x) ( (QUEUE*)((UW)(x) & ~AREA_MASK) ) 50: #define Assign(x, y) ( (x) = (QUEUE*)(((UW)(x) & AREA_MASK) | (UW)(y)) ) 51: 52: /* 53: * Area size 54: */ 55: #define AreaSize(aq) ( (VB*)(aq)->next - (VB*)((aq) + 1) ) 56: #define FreeSize(fq) ( (VB*)((fq) - 1)->next - (VB*)(fq) ) 57: 58: /* 59: * Memory allocation check function 60: */ 61: IMPORT BOOL (*_mem_chkalloc)( void *ptr, int mode, MACB *macb );