kmalloc.c

来自「T-kernel 的extension源代码」· C语言 代码 · 共 113 行

C
113
字号
/* *---------------------------------------------------------------------- *    T-Kernel / Standard Extension * *    Copyright (C) 2006 by Ken Sakamura. All rights reserved. *    T-Kernel / Standard Extension is distributed  *      under the T-License for T-Kernel / Standard Extension. *---------------------------------------------------------------------- * *    Version:   1.00.00 *    Released by T-Engine Forum(http://www.t-engine.org) at 2006/8/11. * *---------------------------------------------------------------------- *//* *	kmalloc.c (libtkse) * *	Allocation of resident system memory * *	For system process *	Cannot be used in ordinary processes */#include "libtkse.h"#include <extension/memory.h>Inline	void	Kmeminit( void );#ifndef KMALLOCTESTEXPORT MACB	_Kmacb;		/* Kmalloc management information */#elseIMPORT MACB	_Kmacb;		/* Kmalloc management information */#endifInline void Kmeminit( void ){	if ( AlignMACB(&_Kmacb)->pagesz == 0U ) {		(void)_mem_init(M_SYSTEM|M_RESIDENT, &_Kmacb);	}}#ifndef KMALLOCTESTEXPORT void* Kmalloc( size_t size ){	void	*p;	MEMLOCK( return NULL )	Kmeminit();	p = _mem_malloc(size, &_Kmacb);	MEMUNLOCK()	return p;}EXPORT void* Kcalloc( size_t nmemb, size_t size ){	void	*p;	MEMLOCK( return NULL )	Kmeminit();	p = _mem_calloc(nmemb, size, &_Kmacb);	MEMUNLOCK()	return p;}EXPORT void* Krealloc( void *ptr, size_t size ){	void	*p;	MEMLOCK( return NULL )	Kmeminit();	p = _mem_realloc(ptr, size, &_Kmacb);	MEMUNLOCK()	return p;}EXPORT void Kfree( void *ptr ){	MEMLOCK( return )	Kmeminit();	_mem_free(ptr, &_Kmacb);	MEMUNLOCK()}#else /* KMALLOCTEST */EXPORT void Kmalloctest( int mode ){	MEMLOCK( return )	Kmeminit();	_mem_malloctest(mode, &_Kmacb);	MEMUNLOCK()}EXPORT BOOL Kmalloccheck( void *ptr ){	BOOL	b;	MEMLOCK( return FALSE )	Kmeminit();	b = _mem_malloccheck(ptr, &_Kmacb);	MEMUNLOCK()	return b;}#endif /* KMALLOCTEST */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?