Don't allocate too much stuff on the stack
This commit is contained in:
parent
709b2e6f55
commit
e6ea8fe642
|
@ -1,6 +1,6 @@
|
|||
#undef DEBUG_DARWIN
|
||||
#undef DEBUG_MACH
|
||||
/* $NetBSD: darwin_mman.c,v 1.20 2005/12/11 12:19:56 christos Exp $ */
|
||||
/* $NetBSD: darwin_mman.c,v 1.21 2006/06/20 03:21:30 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2002 The NetBSD Foundation, Inc.
|
||||
|
@ -39,7 +39,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: darwin_mman.c,v 1.20 2005/12/11 12:19:56 christos Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: darwin_mman.c,v 1.21 2006/06/20 03:21:30 christos Exp $");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
|
@ -88,8 +88,8 @@ darwin_sys_load_shared_file(l, v, retval)
|
|||
vaddr_t base;
|
||||
struct proc *p = l->l_proc;
|
||||
int flags;
|
||||
char filename[MAXPATHLEN + 1];
|
||||
mach_sf_mapping_t *mapp;
|
||||
char *filename;
|
||||
mach_sf_mapping_t *mapp = NULL;
|
||||
size_t maplen;
|
||||
struct sys_open_args open_cup;
|
||||
struct sys_close_args close_cup;
|
||||
|
@ -103,14 +103,15 @@ darwin_sys_load_shared_file(l, v, retval)
|
|||
int need_relocation;
|
||||
struct exec_vmcmd evc;
|
||||
|
||||
if ((error = copyin(SCARG(uap, filename), &filename, MAXPATHLEN)) != 0)
|
||||
return error;
|
||||
filename = malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
|
||||
if ((error = copyin(SCARG(uap, filename), filename, MAXPATHLEN)) != 0)
|
||||
goto bad1;
|
||||
|
||||
if ((error = copyin(SCARG(uap, base), &base, sizeof(base))) != 0)
|
||||
return error;
|
||||
goto bad1;
|
||||
|
||||
if ((error = copyin(SCARG(uap, flags), &flags, sizeof(base))) != 0)
|
||||
return error;
|
||||
goto bad1;
|
||||
|
||||
#ifdef DEBUG_DARWIN
|
||||
DPRINTF(("darwin_sys_load_shared_file: filename = %p ",
|
||||
|
@ -127,14 +128,14 @@ darwin_sys_load_shared_file(l, v, retval)
|
|||
SCARG(&open_cup, flags) = O_RDONLY;
|
||||
SCARG(&open_cup, mode) = 0;
|
||||
if ((error = bsd_sys_open(l, &open_cup, &fdc)) != 0)
|
||||
return error;
|
||||
goto bad1;
|
||||
|
||||
fd = (int)fdc;
|
||||
fdp = p->p_fd;
|
||||
fp = fd_getfile(fdp, fd);
|
||||
if (fp == NULL) {
|
||||
error = EBADF;
|
||||
goto bad3;
|
||||
goto bad2;
|
||||
}
|
||||
FILE_USE(fp);
|
||||
vp = (struct vnode *)fp->f_data;
|
||||
|
@ -143,7 +144,7 @@ darwin_sys_load_shared_file(l, v, retval)
|
|||
if (SCARG(uap, count) < 0 ||
|
||||
SCARG(uap, count) > PAGE_SIZE / sizeof(*mapp)) {
|
||||
error = EINVAL;
|
||||
goto bad3;
|
||||
goto bad2;
|
||||
}
|
||||
maplen = SCARG(uap, count) * sizeof(*mapp);
|
||||
mapp = malloc(maplen, M_TEMP, M_WAITOK);
|
||||
|
@ -232,19 +233,21 @@ darwin_sys_load_shared_file(l, v, retval)
|
|||
DPRINTF(("Success\n"));
|
||||
}
|
||||
bad2:
|
||||
free(mapp, M_TEMP);
|
||||
bad3:
|
||||
if (mapp)
|
||||
free(mapp, M_TEMP);
|
||||
vrele(vp);
|
||||
FILE_UNUSE(fp, l);
|
||||
SCARG(&close_cup, fd) = fd;
|
||||
if ((error = sys_close(l, &close_cup, retval)) != 0)
|
||||
return error;
|
||||
goto bad1;
|
||||
|
||||
if ((error = copyout(&base, SCARG(uap, base), sizeof(base))) != 0)
|
||||
return error;
|
||||
goto bad1;
|
||||
|
||||
if ((error = copyout(&flags, SCARG(uap, flags), sizeof(base))) != 0)
|
||||
return error;
|
||||
goto bad1;
|
||||
bad1:
|
||||
free(filename, M_TEMP);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue