/* * This module allocates an unused virtual address range for shm segments. * * Copyright (C) 2007 Bahadir Balban */ #include #include #include #include INC_GLUE(memory.h) #include #include void vaddr_pool_init(struct id_pool *pool, unsigned long start, unsigned long end) { pool = id_pool_new_init(__pfn(end - start)); } void *vaddr_new(struct id_pool *pool, int npages) { unsigned int shm_vpfn; if ((int)(shm_vpfn = ids_new_contiguous(pool, npages)) < 0) return 0; return (void *)__pfn_to_addr(shm_vpfn + SHM_AREA_START); } int vaddr_del(struct id_pool *pool, void *vaddr, int npages) { unsigned long idpfn = __pfn(page_align(vaddr) - SHM_AREA_START); if (ids_del_contiguous(pool, idpfn, npages) < 0) { printf("%s: Invalid address range returned to " "virtual address pool.\n", __FUNCTION__); return -1; } return 0; }