mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-15 10:17:20 +00:00
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.
This commit is contained in:
parent
c075572228
commit
9caaadb63a
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=24437
@ -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 @@ cpu_startup(dummy)
|
||||
(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);
|
||||
|
||||
|
@ -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 @@ cpu_startup(dummy)
|
||||
(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);
|
||||
|
||||
|
@ -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 @@ execve(p, uap, retval)
|
||||
*/
|
||||
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 @@ execve(p, uap, retval)
|
||||
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 @@ execve(p, uap, retval)
|
||||
* 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 @@ execve(p, uap, retval)
|
||||
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);
|
||||
|
@ -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 @@ cpu_startup(dummy)
|
||||
(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);
|
||||
|
||||
|
@ -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 @@ cpu_startup(dummy)
|
||||
(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);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user