⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imalloc.c

📁 这个linux源代码是很全面的~基本完整了~使用c编译的~由于时间问题我没有亲自测试~但就算用来做参考资料也是非常好的
💻 C
字号:
/* * c 2001 PPC 64 Team, IBM Corp *  *      This program 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 *      2 of the License, or (at your option) any later version. */#include <linux/slab.h>#include <linux/vmalloc.h>#include <linux/spinlock.h>#include <asm/uaccess.h>#include <asm/pgalloc.h>rwlock_t imlist_lock = RW_LOCK_UNLOCKED;struct vm_struct * imlist = NULL;struct vm_struct *get_im_area(unsigned long size){	unsigned long addr;	struct vm_struct **p, *tmp, *area;  	area = (struct vm_struct *) kmalloc(sizeof(*area), GFP_KERNEL);	if (!area)		return NULL;	addr = IMALLOC_START;	write_lock(&imlist_lock);	for (p = &imlist; (tmp = *p) ; p = &tmp->next) {		if (size + addr < (unsigned long) tmp->addr)			break;		addr = tmp->size + (unsigned long) tmp->addr;		if (addr > IMALLOC_END-size) {			write_unlock(&imlist_lock);			kfree(area);			return NULL;		}	}	area->flags = 0;	area->addr = (void *)addr;	area->size = size;	area->next = *p;	*p = area;	write_unlock(&imlist_lock);	return area;}void ifree(void * addr){	struct vm_struct **p, *tmp;  	if (!addr)		return;	if ((PAGE_SIZE-1) & (unsigned long) addr) {		printk(KERN_ERR "Trying to ifree() bad address (%p)\n", addr);		return;	}	write_lock(&imlist_lock);	for (p = &imlist ; (tmp = *p) ; p = &tmp->next) {		if (tmp->addr == addr) {			*p = tmp->next;			kfree(tmp);			write_unlock(&imlist_lock);			return;		}	}	write_unlock(&imlist_lock);	printk(KERN_ERR "Trying to ifree() nonexistent area (%p)\n", addr);}

⌨️ 快捷键说明

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