Module: xenomai-head Branch: master Commit: 653a38669af4427471ed8cdd129eb0bbb33ba178 URL: http://git.xenomai.org/?p=xenomai-head.git;a=commit;h=653a38669af4427471ed8cdd129eb0bbb33ba178
Author: Philippe Gerum <r...@xenomai.org> Date: Sun Jul 4 18:57:54 2010 +0200 nucleus: finalize heap mapping sanitization This commit extends 177f72136 to the MMU case, unifying heap mapping management for both mmu and nommu platforms. As a consequence of this change, the ABI revision levels for arm, powerpc and x86 are bumped in the same move. --- include/asm-arm/features.h | 2 +- include/asm-powerpc/features.h | 2 +- include/asm-x86/features_32.h | 2 +- include/asm-x86/features_64.h | 2 +- include/native/heap.h | 2 +- include/native/queue.h | 2 +- include/nucleus/heap.h | 19 +++---------- include/vrtx/vrtx.h | 4 +- ksrc/nucleus/heap.c | 54 ++++++++++++++++++--------------------- ksrc/nucleus/shadow.c | 2 +- ksrc/skins/native/syscall.c | 8 +++--- ksrc/skins/posix/syscall.c | 4 +-- ksrc/skins/psos+/syscall.c | 4 +- ksrc/skins/vrtx/syscall.c | 4 +- src/skins/common/sem_heap.c | 9 +------ src/skins/native/heap.c | 2 +- src/skins/native/queue.c | 2 +- src/skins/psos+/rn.c | 4 +- src/skins/vrtx/heap.c | 2 +- src/skins/vrtx/pt.c | 2 +- 20 files changed, 55 insertions(+), 77 deletions(-) diff --git a/include/asm-arm/features.h b/include/asm-arm/features.h index ecd76da..3e3da87 100644 --- a/include/asm-arm/features.h +++ b/include/asm-arm/features.h @@ -46,7 +46,7 @@ #define __xn_feat_arm_tsc 0x00000008 /* The ABI revision level we use on this arch. */ -#define XENOMAI_ABI_REV 3UL +#define XENOMAI_ABI_REV 4UL #if __LINUX_ARM_ARCH__ >= 6 /* ARMv6 has both atomic xchg and atomic_inc/dec etc. */ diff --git a/include/asm-powerpc/features.h b/include/asm-powerpc/features.h index e097905..901e790 100644 --- a/include/asm-powerpc/features.h +++ b/include/asm-powerpc/features.h @@ -22,7 +22,7 @@ #include <asm-generic/xenomai/features.h> /* The ABI revision level we use on this arch. */ -#define XENOMAI_ABI_REV 3UL +#define XENOMAI_ABI_REV 4UL #define XENOMAI_FEAT_DEP __xn_feat_generic_mask diff --git a/include/asm-x86/features_32.h b/include/asm-x86/features_32.h index 9ac0ea3..11fc75a 100644 --- a/include/asm-x86/features_32.h +++ b/include/asm-x86/features_32.h @@ -39,7 +39,7 @@ #define __xn_feat_x86_tsc 0x00000002 /* The ABI revision level we use on this arch. */ -#define XENOMAI_ABI_REV 3UL +#define XENOMAI_ABI_REV 4UL #ifdef CONFIG_X86_TSC #define __xn_feat_x86_tsc_mask __xn_feat_x86_tsc diff --git a/include/asm-x86/features_64.h b/include/asm-x86/features_64.h index 8f417ac..b0cf0ee 100644 --- a/include/asm-x86/features_64.h +++ b/include/asm-x86/features_64.h @@ -23,7 +23,7 @@ #include <asm-generic/xenomai/features.h> /* The ABI revision level we use on this arch. */ -#define XENOMAI_ABI_REV 3UL +#define XENOMAI_ABI_REV 4UL #define XENOMAI_FEAT_DEP __xn_feat_generic_mask diff --git a/include/native/heap.h b/include/native/heap.h index 443fd82..963f21c 100644 --- a/include/native/heap.h +++ b/include/native/heap.h @@ -62,7 +62,7 @@ typedef struct rt_heap_placeholder { void *opaque2; caddr_t mapbase; size_t mapsize; - xnheap_area_decl(); + unsigned long area; } RT_HEAP_PLACEHOLDER; #if defined(__KERNEL__) || defined(__XENO_SIM__) diff --git a/include/native/queue.h b/include/native/queue.h index b266c1d..a09154b 100644 --- a/include/native/queue.h +++ b/include/native/queue.h @@ -62,7 +62,7 @@ typedef struct rt_queue_placeholder { void *opaque2; caddr_t mapbase; size_t mapsize; - xnheap_area_decl(); + unsigned long area; } RT_QUEUE_PLACEHOLDER; #if defined(__KERNEL__) || defined(__XENO_SIM__) diff --git a/include/nucleus/heap.h b/include/nucleus/heap.h index 9758f5f..253dca3 100644 --- a/include/nucleus/heap.h +++ b/include/nucleus/heap.h @@ -207,16 +207,16 @@ void xnheap_destroy_mapped(xnheap_t *heap, void __user *mapaddr); #define xnheap_base_memory(heap) \ - ((caddr_t)(heap)->archdep.heapbase) + ((unsigned long)((heap)->archdep.heapbase)) #define xnheap_mapped_offset(heap,ptr) \ - (((caddr_t)(ptr)) - xnheap_base_memory(heap)) + (((caddr_t)(ptr)) - (caddr_t)xnheap_base_memory(heap)) #define xnheap_mapped_address(heap,off) \ - (xnheap_base_memory(heap) + (off)) + ((caddr_t)xnheap_base_memory(heap) + (off)) #define xnheap_mapped_p(heap) \ - (xnheap_base_memory(heap) != NULL) + (xnheap_base_memory(heap) != 0) #endif /* __KERNEL__ */ @@ -281,19 +281,10 @@ int xnheap_check_block(xnheap_t *heap, #define XNHEAP_DEV_NAME "/dev/rtheap" #define XNHEAP_DEV_MINOR 254 -#ifdef CONFIG_MMU -/* XXX: 2.5.x ABI preserved for MMU-enabled only. */ -#define xnheap_area_decl(); -#define xnheap_area_set(p, val) -#else -#define xnheap_area_decl() unsigned long area -#define xnheap_area_set(p, val) (p)->area = (unsigned long)(val) -#endif - struct xnheap_desc { unsigned long handle; unsigned int size; - xnheap_area_decl(); + unsigned long area; }; #endif /* !_XENO_NUCLEUS_HEAP_H */ diff --git a/include/vrtx/vrtx.h b/include/vrtx/vrtx.h index a77d2d1..c416e5b 100644 --- a/include/vrtx/vrtx.h +++ b/include/vrtx/vrtx.h @@ -70,14 +70,14 @@ typedef struct _vrtx_hdesc { int hid; void *hcb; size_t hsize; - xnheap_area_decl(); + unsigned long area; } vrtx_hdesc_t; typedef struct _vrtx_pdesc { int pid; void *ptcb; size_t ptsize; - xnheap_area_decl(); + unsigned long area; } vrtx_pdesc_t; #if defined(__KERNEL__) || defined(__XENO_SIM__) diff --git a/ksrc/nucleus/heap.c b/ksrc/nucleus/heap.c index c6cb581..fb55bdb 100644 --- a/ksrc/nucleus/heap.c +++ b/ksrc/nucleus/heap.c @@ -1223,9 +1223,9 @@ static int xnheap_ioctl(struct inode *inode, static int xnheap_mmap(struct file *file, struct vm_area_struct *vma) { - unsigned long offset, size, vaddr; + unsigned long size, vaddr; struct xnheap *heap; - int ret; + int kmflags, ret; if (vma->vm_ops != NULL || file->private_data == NULL) /* Caller should mmap() once for a given file instance, after @@ -1250,30 +1250,38 @@ static int xnheap_mmap(struct file *file, struct vm_area_struct *vma) vma->vm_private_data = file->private_data; vma->vm_ops = &xnheap_vmops; size = vma->vm_end - vma->vm_start; + kmflags = heap->archdep.kmflags; ret = -ENXIO; + /* + * Cannot map multi-extent heaps, we need the memory area we + * map from to be contiguous. + */ if (countq(&heap->extents) > 1) - /* Cannot map multi-extent heaps, we need the memory - area we map from to be contiguous. */ goto deref_out; - offset = vma->vm_pgoff << PAGE_SHIFT; - vaddr = (unsigned long)xnheap_base_memory(heap); + vaddr = vma->vm_pgoff << PAGE_SHIFT; -#ifdef CONFIG_MMU /* - * offset is actually an offset from the start of the heap - * memory. + * Despite the kernel sees a single backing device with direct + * mapping capabilities (/dev/rtheap), we do map different + * heaps through it, so we want a brand new mapping region for + * each of them in the nommu case. To this end, userland + * always requests mappings on non-overlapping areas for + * different heaps, by passing offset values which are actual + * RAM addresses. We do the same in the MMU case as well, to + * keep a single implementation for both. */ - if (offset + size > xnheap_extentsize(heap)) + if (vaddr + size > + xnheap_base_memory(heap) + xnheap_extentsize(heap)) goto deref_out; - vaddr += offset; +#ifdef CONFIG_MMU ret = -EAGAIN; - if ((heap->archdep.kmflags & ~XNHEAP_GFP_NONCACHED) == 0) { + if ((kmflags & ~XNHEAP_GFP_NONCACHED) == 0) { unsigned long maddr = vma->vm_start; - if (heap->archdep.kmflags == XNHEAP_GFP_NONCACHED) + if (kmflags == XNHEAP_GFP_NONCACHED) vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); while (size > 0) { @@ -1286,26 +1294,14 @@ static int xnheap_mmap(struct file *file, struct vm_area_struct *vma) } } else if (xnarch_remap_io_page_range(file,vma, vma->vm_start, - virt_to_phys((void *)vaddr), + __pa(vaddr), size, vma->vm_page_prot)) goto deref_out; xnarch_fault_range(vma); #else /* !CONFIG_MMU */ - /* - * Despite the kernel sees a single backing device with direct - * mapping capabilities (/dev/rtheap), we do map different - * heaps through it, so we want a brand new mapping region for - * each of them. To this end, we must request mappings on - * non-overlapping areas. To make sure of this in the nommu - * case, we request mappings from offsets representing the - * start RAM address of the heap memory. - */ - if (offset + size > vaddr + xnheap_extentsize(heap)) - goto deref_out; - - if ((heap->archdep.kmflags & ~XNHEAP_GFP_NONCACHED) != 0 || - heap->archdep.kmflags == XNHEAP_GFP_NONCACHED) + if ((kmflags & ~XNHEAP_GFP_NONCACHED) != 0 || + kmflags == XNHEAP_GFP_NONCACHED) vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); #endif /* !CONFIG_MMU */ @@ -1335,7 +1331,7 @@ static unsigned long xnheap_get_unmapped_area(struct file *file, if (heap == NULL) goto fail; - area = (unsigned long)xnheap_base_memory(heap); + area = xnheap_base_memory(heap); offset = pgoff << PAGE_SHIFT; if (offset < area || offset + len > area + xnheap_extentsize(heap)) diff --git a/ksrc/nucleus/shadow.c b/ksrc/nucleus/shadow.c index c410fe2..b2d4326 100644 --- a/ksrc/nucleus/shadow.c +++ b/ksrc/nucleus/shadow.c @@ -2057,7 +2057,7 @@ static int xnshadow_sys_sem_heap(struct pt_regs *regs) heap = &xnsys_ppd_get(global)->sem_heap; hd.handle = (unsigned long)heap; hd.size = xnheap_extentsize(heap); - xnheap_area_set(&hd, xnheap_base_memory(heap)); + hd.area = xnheap_base_memory(heap); return __xn_safe_copy_to_user(u_hd, &hd, sizeof(*u_hd)); } diff --git a/ksrc/skins/native/syscall.c b/ksrc/skins/native/syscall.c index 56407b8..c4d0357 100644 --- a/ksrc/skins/native/syscall.c +++ b/ksrc/skins/native/syscall.c @@ -2060,7 +2060,7 @@ static int __rt_queue_create(struct pt_regs *regs) ph.opaque = q->handle; ph.opaque2 = &q->bufpool; ph.mapsize = xnheap_extentsize(&q->bufpool); - xnheap_area_set(&ph, xnheap_base_memory(&q->bufpool)); + ph.area = xnheap_base_memory(&q->bufpool); if (__xn_safe_copy_to_user((void __user *)__xn_reg_arg1(regs), &ph, sizeof(ph))) return -EFAULT; @@ -2098,7 +2098,7 @@ static int __rt_queue_bind(struct pt_regs *regs) ph.opaque2 = &q->bufpool; ph.mapsize = xnheap_extentsize(&q->bufpool); - xnheap_area_set(&ph, xnheap_base_memory(&q->bufpool)); + ph.area = xnheap_base_memory(&q->bufpool); xnlock_put_irqrestore(&nklock, s); if (__xn_safe_copy_to_user((void __user *)__xn_reg_arg1(regs), &ph, sizeof(ph))) @@ -2584,7 +2584,7 @@ static int __rt_heap_create(struct pt_regs *regs) ph.opaque = heap->handle; ph.opaque2 = &heap->heap_base; ph.mapsize = xnheap_extentsize(&heap->heap_base); - xnheap_area_set(&ph, xnheap_base_memory(&heap->heap_base)); + ph.area = xnheap_base_memory(&heap->heap_base); if (__xn_safe_copy_to_user((void __user *)__xn_reg_arg1(regs), &ph, sizeof(ph))) return -EFAULT; @@ -2622,7 +2622,7 @@ static int __rt_heap_bind(struct pt_regs *regs) ph.opaque2 = &heap->heap_base; ph.mapsize = xnheap_extentsize(&heap->heap_base); - xnheap_area_set(&ph, xnheap_base_memory(&heap->heap_base)); + ph.area = xnheap_base_memory(&heap->heap_base); xnlock_put_irqrestore(&nklock, s); diff --git a/ksrc/skins/posix/syscall.c b/ksrc/skins/posix/syscall.c index 98709bd..25831ab 100644 --- a/ksrc/skins/posix/syscall.c +++ b/ksrc/skins/posix/syscall.c @@ -2613,9 +2613,7 @@ static int __mmap_prologue(struct pt_regs *regs) mmap_param.len = len; mmap_param.heapsize = xnheap_extentsize(heap); mmap_param.offset = xnheap_mapped_offset(heap, mmap_param.kaddr); -#ifndef CONFIG_MMU - mmap_param.offset += (unsigned long)xnheap_base_memory(heap); -#endif + mmap_param.offset += xnheap_base_memory(heap); return __xn_safe_copy_to_user((void __user *)__xn_reg_arg4(regs), &mmap_param, sizeof(mmap_param)); diff --git a/ksrc/skins/psos+/syscall.c b/ksrc/skins/psos+/syscall.c index ef20b48..3b6fab9 100644 --- a/ksrc/skins/psos+/syscall.c +++ b/ksrc/skins/psos+/syscall.c @@ -1139,7 +1139,7 @@ static int __rn_create(struct pt_regs *regs) u_long allocsz; void *rncb; u_long mapsize; - xnheap_area_decl(); + u_long area; } rninfo; psosrn_t *rn; u_long err; @@ -1166,7 +1166,7 @@ static int __rn_create(struct pt_regs *regs) rninfo.rnid = rn->handle; rninfo.rncb = &rn->heapbase; rninfo.mapsize = xnheap_extentsize(&rn->heapbase); - xnheap_area_set(&rninfo, xnheap_base_memory(&rn->heapbase)); + rninfo.area = xnheap_base_memory(&rn->heapbase); if (__xn_safe_copy_to_user((void __user *)__xn_reg_arg3(regs), &rninfo, sizeof(rninfo))) err = -EFAULT; diff --git a/ksrc/skins/vrtx/syscall.c b/ksrc/skins/vrtx/syscall.c index ab3a8e1..2606003 100644 --- a/ksrc/skins/vrtx/syscall.c +++ b/ksrc/skins/vrtx/syscall.c @@ -867,7 +867,7 @@ static int __sc_hcreate(struct pt_regs *regs) hdesc.hid = hid; hdesc.hcb = &heap->sysheap; hdesc.hsize = xnheap_extentsize(&heap->sysheap); - xnheap_area_set(&hdesc, xnheap_base_memory(&heap->sysheap)); + hdesc.area = xnheap_base_memory(&heap->sysheap); xnlock_put_irqrestore(&nklock, s); if (__xn_safe_copy_to_user((void __user *)__xn_reg_arg3(regs), @@ -1076,7 +1076,7 @@ static int __sc_pcreate(struct pt_regs *regs) pdesc.pid = pid; pdesc.ptcb = ptheap; pdesc.ptsize = xnheap_extentsize(ptheap); - xnheap_area_set(&pdesc, xnheap_base_memory(ptheap)); + pdesc.area = xnheap_base_memory(ptheap); xnlock_put_irqrestore(&nklock, s); return __xn_safe_copy_to_user((void __user *)__xn_reg_arg4(regs), diff --git a/src/skins/common/sem_heap.c b/src/skins/common/sem_heap.c index 0a66484..2adbdbc 100644 --- a/src/skins/common/sem_heap.c +++ b/src/skins/common/sem_heap.c @@ -22,7 +22,6 @@ struct xnvdso *nkvdso; void *xeno_map_heap(struct xnheap_desc *hd) { - unsigned long area; int fd, ret; void *addr; @@ -38,14 +37,8 @@ void *xeno_map_heap(struct xnheap_desc *hd) return MAP_FAILED; } -#ifdef CONFIG_MMU - /* XXX: 2.5.x ABI preserved for MMU-enabled only. */ - area = 0; -#else - area = hd->area; -#endif addr = mmap(NULL, hd->size, PROT_READ|PROT_WRITE, - MAP_SHARED, fd, area); + MAP_SHARED, fd, hd->area); close(fd); diff --git a/src/skins/native/heap.c b/src/skins/native/heap.c index 29b1329..4a71333 100644 --- a/src/skins/native/heap.c +++ b/src/skins/native/heap.c @@ -36,7 +36,7 @@ static int __map_heap_memory(RT_HEAP *heap, RT_HEAP_PLACEHOLDER *php) hd.handle = (unsigned long)php->opaque2; hd.size = php->mapsize; - xnheap_area_set(&hd, php->area); + hd.area = php->area; php->mapbase = xeno_map_heap(&hd); if (php->mapbase == MAP_FAILED) return -errno; diff --git a/src/skins/native/queue.c b/src/skins/native/queue.c index d104bd0..e645822 100644 --- a/src/skins/native/queue.c +++ b/src/skins/native/queue.c @@ -36,7 +36,7 @@ static int __map_queue_memory(RT_QUEUE *q, RT_QUEUE_PLACEHOLDER *php) hd.handle = (unsigned long)php->opaque2; hd.size = php->mapsize; - xnheap_area_set(&hd, php->area); + hd.area = php->area; php->mapbase = xeno_map_heap(&hd); if (php->mapbase == MAP_FAILED) return -errno; diff --git a/src/skins/psos+/rn.c b/src/skins/psos+/rn.c index f2de162..f254e37 100644 --- a/src/skins/psos+/rn.c +++ b/src/skins/psos+/rn.c @@ -32,7 +32,7 @@ struct rninfo { u_long allocsz; void *rncb; u_long mapsize; - xnheap_area_decl(); + u_long area; }; void *xeno_map_heap(struct xnheap_desc *hd); @@ -44,7 +44,7 @@ static int __map_heap_memory(const struct rninfo *rnip) hd.handle = (unsigned long)rnip->rncb; hd.size = rnip->mapsize; - xnheap_area_set(&hd, rnip->area); + hd.area = rnip->area; mapbase = xeno_map_heap(&hd); if (mapbase == MAP_FAILED) return -errno; diff --git a/src/skins/vrtx/heap.c b/src/skins/vrtx/heap.c index 53f387b..846838c 100644 --- a/src/skins/vrtx/heap.c +++ b/src/skins/vrtx/heap.c @@ -36,7 +36,7 @@ static int __map_heap_memory(const vrtx_hdesc_t *hdesc) hd.handle = (unsigned long)hdesc->hcb; hd.size = hdesc->hsize; - xnheap_area_set(&hd, hdesc->area); + hd.area = hdesc->area; mapbase = xeno_map_heap(&hd); if (mapbase == MAP_FAILED) return -errno; diff --git a/src/skins/vrtx/pt.c b/src/skins/vrtx/pt.c index 835299c..e41db57 100644 --- a/src/skins/vrtx/pt.c +++ b/src/skins/vrtx/pt.c @@ -36,7 +36,7 @@ static int __map_pt_memory(const vrtx_pdesc_t *pdesc) hd.handle = (unsigned long)pdesc->ptcb; hd.size = pdesc->ptsize; - xnheap_area_set(&hd, pdesc->area); + hd.area = pdesc->area; mapbase = xeno_map_heap(&hd); if (mapbase == MAP_FAILED) return -errno; _______________________________________________ Xenomai-git mailing list Xenomai-git@gna.org https://mail.gna.org/listinfo/xenomai-git