diff options
author | dg <dg@FreeBSD.org> | 1997-03-31 11:11:26 +0000 |
---|---|---|
committer | dg <dg@FreeBSD.org> | 1997-03-31 11:11:26 +0000 |
commit | 1543ecae887bd6435390612196e8618908146b13 (patch) | |
tree | b3cef10263cd558d15c464c3bd089af47ce2da23 | |
parent | 8a15519b3ec7205f5ef40d8ceb1b3262f7b9ed8d (diff) | |
download | FreeBSD-src-1543ecae887bd6435390612196e8618908146b13.zip FreeBSD-src-1543ecae887bd6435390612196e8618908146b13.tar.gz |
Changed the way that the exec image header is read to be filesystem-
centric rather than VM-centric to fix a problem with errors not being
detectable when the header is read.
Killed exech_map as a result of these changes.
There appears to be no performance difference with this change.
-rw-r--r-- | sys/amd64/amd64/machdep.c | 4 | ||||
-rw-r--r-- | sys/i386/i386/machdep.c | 4 | ||||
-rw-r--r-- | sys/kern/kern_exec.c | 67 | ||||
-rw-r--r-- | sys/pc98/i386/machdep.c | 4 | ||||
-rw-r--r-- | sys/pc98/pc98/machdep.c | 4 | ||||
-rw-r--r-- | sys/vm/vm_kern.c | 3 | ||||
-rw-r--r-- | sys/vm/vm_kern.h | 3 |
7 files changed, 44 insertions, 45 deletions
diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c index c986a1d..461be83 100644 --- a/sys/amd64/amd64/machdep.c +++ b/sys/amd64/amd64/machdep.c @@ -35,7 +35,7 @@ * SUCH DAMAGE. * * from: @(#)machdep.c 7.4 (Berkeley) 6/3/91 - * $Id: machdep.c,v 1.232 1997/03/25 23:43:01 mpp Exp $ + * $Id: machdep.c,v 1.233 1997/03/28 12:37:44 joerg Exp $ */ #include "npx.h" @@ -338,8 +338,6 @@ again: (nswbuf*MAXPHYS) + pager_map_size, TRUE); exec_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr, (16*ARG_MAX), TRUE); - exech_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr, - (16*PAGE_SIZE), TRUE); u_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr, (maxproc*UPAGES*PAGE_SIZE), FALSE); diff --git a/sys/i386/i386/machdep.c b/sys/i386/i386/machdep.c index c986a1d..461be83 100644 --- a/sys/i386/i386/machdep.c +++ b/sys/i386/i386/machdep.c @@ -35,7 +35,7 @@ * SUCH DAMAGE. * * from: @(#)machdep.c 7.4 (Berkeley) 6/3/91 - * $Id: machdep.c,v 1.232 1997/03/25 23:43:01 mpp Exp $ + * $Id: machdep.c,v 1.233 1997/03/28 12:37:44 joerg Exp $ */ #include "npx.h" @@ -338,8 +338,6 @@ again: (nswbuf*MAXPHYS) + pager_map_size, TRUE); exec_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr, (16*ARG_MAX), TRUE); - exech_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr, - (16*PAGE_SIZE), TRUE); u_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr, (maxproc*UPAGES*PAGE_SIZE), FALSE); diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c index 21049a3..ac1469c 100644 --- a/sys/kern/kern_exec.c +++ b/sys/kern/kern_exec.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id$ + * $Id: kern_exec.c,v 1.52 1997/02/22 09:39:04 peter Exp $ */ #include <sys/param.h> @@ -47,6 +47,7 @@ #include <sys/shm.h> #include <sys/sysctl.h> #include <sys/vnode.h> +#include <sys/buf.h> #include <vm/vm.h> #include <vm/vm_param.h> @@ -102,6 +103,7 @@ execve(p, uap, retval) int error, len, i; struct image_params image_params, *imgp; struct vattr attr; + struct buf *bp = NULL; imgp = &image_params; @@ -158,29 +160,32 @@ interpret: */ error = exec_check_permissions(imgp); - /* - * Lose the lock on the vnode. It's no longer needed, and must not - * exist for the pagefault paging to work below. - */ - VOP_UNLOCK(imgp->vp, 0, p); - if (error) goto exec_fail_dealloc; /* - * Map the image header (first page) of the file into - * kernel address space + * Get the image header, which we define here as meaning the first + * page of the executable. */ - error = vm_mmap(exech_map, /* map */ - (vm_offset_t *)&imgp->image_header, /* address */ - PAGE_SIZE, /* size */ - VM_PROT_READ, /* protection */ - VM_PROT_READ, /* max protection */ - 0, /* flags */ - (caddr_t)imgp->vp, /* vnode */ - 0); /* offset */ + if (imgp->vp->v_mount && imgp->vp->v_mount->mnt_stat.f_iosize >= PAGE_SIZE) { + /* + * Get a buffer with (at least) the first page. + */ + error = bread(imgp->vp, 0, imgp->vp->v_mount->mnt_stat.f_iosize, + p->p_ucred, &bp); + imgp->image_header = bp->b_data; + } else { + /* + * The filesystem block size is too small, so do this the hard + * way. Malloc some space and read PAGE_SIZE worth of the image + * header into it. + */ + imgp->image_header = malloc(PAGE_SIZE, M_TEMP, M_WAITOK); + error = vn_rdwr(UIO_READ, imgp->vp, (void *)imgp->image_header, PAGE_SIZE, 0, + UIO_SYSSPACE, IO_NODELOCKED, p->p_ucred, NULL, p); + } + VOP_UNLOCK(imgp->vp, 0, p); if (error) { - uprintf("mmap failed: %d\n",error); goto exec_fail_dealloc; } @@ -203,13 +208,16 @@ interpret: if (error) goto exec_fail_dealloc; if (imgp->interpreted) { + /* free old bp/image_header */ + if (bp != NULL) { + brelse(bp); + bp = NULL; + } else { + free((void *)imgp->image_header, M_TEMP); + } /* free old vnode and name buffer */ vrele(ndp->ni_vp); FREE(ndp->ni_cnd.cn_pnbuf, M_NAMEI); - if (vm_map_remove(exech_map, (vm_offset_t)imgp->image_header, - (vm_offset_t)imgp->image_header + PAGE_SIZE)) - panic("execve: header dealloc failed (1)"); - /* set new name to that of the interpreter */ NDINIT(ndp, LOOKUP, LOCKLEAF | FOLLOW | SAVENAME, UIO_SYSSPACE, imgp->interpreter_name, p); @@ -321,9 +329,10 @@ interpret: * free various allocated resources */ kmem_free_wakeup(exec_map, (vm_offset_t)imgp->stringbase, ARG_MAX); - if (vm_map_remove(exech_map, (vm_offset_t)imgp->image_header, - (vm_offset_t)imgp->image_header + PAGE_SIZE)) - panic("execve: header dealloc failed (2)"); + if (bp != NULL) + brelse(bp); + else if (imgp->image_header != NULL) + free((void *)imgp->image_header, M_TEMP); vrele(ndp->ni_vp); FREE(ndp->ni_cnd.cn_pnbuf, M_NAMEI); @@ -332,10 +341,10 @@ interpret: exec_fail_dealloc: if (imgp->stringbase != NULL) kmem_free_wakeup(exec_map, (vm_offset_t)imgp->stringbase, ARG_MAX); - if (imgp->image_header && imgp->image_header != (char *)-1) - if (vm_map_remove(exech_map, (vm_offset_t)imgp->image_header, - (vm_offset_t)imgp->image_header + PAGE_SIZE)) - panic("execve: header dealloc failed (3)"); + if (bp != NULL) + brelse(bp); + else if (imgp->image_header != NULL) + free((void *)imgp->image_header, M_TEMP); if (ndp->ni_vp) vrele(ndp->ni_vp); FREE(ndp->ni_cnd.cn_pnbuf, M_NAMEI); diff --git a/sys/pc98/i386/machdep.c b/sys/pc98/i386/machdep.c index 204aa09..6cd3b891f 100644 --- a/sys/pc98/i386/machdep.c +++ b/sys/pc98/i386/machdep.c @@ -35,7 +35,7 @@ * SUCH DAMAGE. * * from: @(#)machdep.c 7.4 (Berkeley) 6/3/91 - * $Id: machdep.c,v 1.32 1997/03/26 07:03:30 kato Exp $ + * $Id: machdep.c,v 1.33 1997/03/29 02:48:49 kato Exp $ */ #include "npx.h" @@ -349,8 +349,6 @@ again: (nswbuf*MAXPHYS) + pager_map_size, TRUE); exec_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr, (16*ARG_MAX), TRUE); - exech_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr, - (16*PAGE_SIZE), TRUE); u_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr, (maxproc*UPAGES*PAGE_SIZE), FALSE); diff --git a/sys/pc98/pc98/machdep.c b/sys/pc98/pc98/machdep.c index 204aa09..6cd3b891f 100644 --- a/sys/pc98/pc98/machdep.c +++ b/sys/pc98/pc98/machdep.c @@ -35,7 +35,7 @@ * SUCH DAMAGE. * * from: @(#)machdep.c 7.4 (Berkeley) 6/3/91 - * $Id: machdep.c,v 1.32 1997/03/26 07:03:30 kato Exp $ + * $Id: machdep.c,v 1.33 1997/03/29 02:48:49 kato Exp $ */ #include "npx.h" @@ -349,8 +349,6 @@ again: (nswbuf*MAXPHYS) + pager_map_size, TRUE); exec_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr, (16*ARG_MAX), TRUE); - exech_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr, - (16*PAGE_SIZE), TRUE); u_map = kmem_suballoc(kernel_map, &minaddr, &maxaddr, (maxproc*UPAGES*PAGE_SIZE), FALSE); diff --git a/sys/vm/vm_kern.c b/sys/vm/vm_kern.c index bf4ee4a..a875230 100644 --- a/sys/vm/vm_kern.c +++ b/sys/vm/vm_kern.c @@ -61,7 +61,7 @@ * any improvements or extensions that they make and grant Carnegie the * rights to redistribute these changes. * - * $Id$ + * $Id: vm_kern.c,v 1.33 1997/02/22 09:48:21 peter Exp $ */ /* @@ -92,7 +92,6 @@ vm_map_t kernel_map=0; vm_map_t kmem_map=0; vm_map_t exec_map=0; -vm_map_t exech_map=0; vm_map_t clean_map=0; vm_map_t u_map=0; vm_map_t buffer_map=0; diff --git a/sys/vm/vm_kern.h b/sys/vm/vm_kern.h index 59e47db..b23150f 100644 --- a/sys/vm/vm_kern.h +++ b/sys/vm/vm_kern.h @@ -61,7 +61,7 @@ * any improvements or extensions that they make and grant Carnegie the * rights to redistribute these changes. * - * $Id$ + * $Id: vm_kern.h,v 1.12 1997/02/22 09:48:21 peter Exp $ */ #ifndef _VM_VM_KERN_H_ @@ -77,7 +77,6 @@ extern vm_map_t io_map; extern vm_map_t clean_map; extern vm_map_t phys_map; extern vm_map_t exec_map; -extern vm_map_t exech_map; extern vm_map_t u_map; extern vm_offset_t kernel_vm_end; |