Date: Mon, 9 Jul 2007 23:09:43 GMT From: Jesper Brix Rosenkilde <jbr@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 123238 for review Message-ID: <200707092309.l69N9hUX029957@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=123238 Change 123238 by jbr@jbr_bob on 2007/07/09 23:09:37 added sanity checking to vm_mapsysshm, mostly borrowed from vm_map_stack Affected files ... .. //depot/projects/soc2007/jbr-syscall/src/sys/kern/kern_exec.c#3 edit .. //depot/projects/soc2007/jbr-syscall/src/sys/vm/vm_map.c#4 edit .. //depot/projects/soc2007/jbr-syscall/src/sys/vm/vm_map.h#3 edit Differences ... ==== //depot/projects/soc2007/jbr-syscall/src/sys/kern/kern_exec.c#3 (text+ko) ==== @@ -919,7 +919,7 @@ } /* Allocate memory shared between process and kernel */ - error = vm_map_sysshm(map, sv->sv_minuser); + error = vm_map_sysshm(map, sv->sv_minuser, 8); if (error) return (error); ==== //depot/projects/soc2007/jbr-syscall/src/sys/vm/vm_map.c#4 (text+ko) ==== @@ -2987,9 +2987,50 @@ * process. */ int -vm_map_sysshm(vm_map_t map, vm_offset_t addr) +vm_map_sysshm(vm_map_t map, vm_offset_t addr, vm_size_t size) { - return (KERN_SUCCESS); + int error = 0; + vm_offset_t osize; + vm_map_entry_t new_entry, prev_entry; + rlim_t vmemlim; + + PROC_LOCK(curthread->td_proc); + vmemlim = lim_cur(curthread->td_proc, RLIMIT_VMEM); + PROC_UNLOCK(curthread->td_proc); + + vm_map_lock(map); + + /* if address is already mapped unlock and return with error */ + if (vm_map_lookup_entry(map, addr, &prev_entry)) { + vm_map_unlock(map); + return (KERN_NO_SPACE); + } + + osize = addr + round_page(size); + + /* check that we are within vmlimit */ + if (map->size + osize > vmemlim) { + vm_map_unlock(map); + return (KERN_NO_SPACE); + } + + error = vm_map_insert(map, NULL, 0, addr, osize, + VM_PROT_EXECUTE, VM_PROT_ALL, MAP_NOFAULT); + + if (error) { + if (prev_entry != &map->header) + vm_map_clip_end(map, prev_entry, addr); + + new_entry = prev_entry->next; + + if (new_entry->end != osize || new_entry->start != addr) + panic("Bad entry start/end for new sysshm"); + + new_entry->avail_ssize = round_page(size) - round_page(size); + } + + vm_map_unlock(map); + return (error); } /* ==== //depot/projects/soc2007/jbr-syscall/src/sys/vm/vm_map.h#3 (text+ko) ==== @@ -354,7 +354,7 @@ void vm_map_simplify_entry (vm_map_t, vm_map_entry_t); void vm_init2 (void); int vm_map_stack (vm_map_t, vm_offset_t, vm_size_t, vm_prot_t, vm_prot_t, int); -int vm_map_sysshm(vm_map_t, vm_offset_t); +int vm_map_sysshm(vm_map_t, vm_offset_t, vm_size_t); int vm_map_growstack (struct proc *p, vm_offset_t addr); int vm_map_unwire(vm_map_t map, vm_offset_t start, vm_offset_t end, int flags);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200707092309.l69N9hUX029957>