linux_exec_machdep.c revision 1.1.2.2 1 1.1.2.2 skrll /* $NetBSD: linux_exec_machdep.c,v 1.1.2.2 2004/11/14 08:15:33 skrll Exp $ */
2 1.1.2.2 skrll
3 1.1.2.2 skrll /*-
4 1.1.2.2 skrll * Copyright (c) 2004 The NetBSD Foundation, Inc.
5 1.1.2.2 skrll * All rights reserved.
6 1.1.2.2 skrll *
7 1.1.2.2 skrll * This code is derived from software contributed to The NetBSD Foundation
8 1.1.2.2 skrll * by Christos Zoulas.
9 1.1.2.2 skrll *
10 1.1.2.2 skrll * Redistribution and use in source and binary forms, with or without
11 1.1.2.2 skrll * modification, are permitted provided that the following conditions
12 1.1.2.2 skrll * are met:
13 1.1.2.2 skrll * 1. Redistributions of source code must retain the above copyright
14 1.1.2.2 skrll * notice, this list of conditions and the following disclaimer.
15 1.1.2.2 skrll * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.2.2 skrll * notice, this list of conditions and the following disclaimer in the
17 1.1.2.2 skrll * documentation and/or other materials provided with the distribution.
18 1.1.2.2 skrll * 3. All advertising materials mentioning features or use of this software
19 1.1.2.2 skrll * must display the following acknowledgement:
20 1.1.2.2 skrll * This product includes software developed by the NetBSD
21 1.1.2.2 skrll * Foundation, Inc. and its contributors.
22 1.1.2.2 skrll * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1.2.2 skrll * contributors may be used to endorse or promote products derived
24 1.1.2.2 skrll * from this software without specific prior written permission.
25 1.1.2.2 skrll *
26 1.1.2.2 skrll * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1.2.2 skrll * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1.2.2 skrll * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1.2.2 skrll * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1.2.2 skrll * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1.2.2 skrll * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1.2.2 skrll * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1.2.2 skrll * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1.2.2 skrll * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1.2.2 skrll * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1.2.2 skrll * POSSIBILITY OF SUCH DAMAGE.
37 1.1.2.2 skrll */
38 1.1.2.2 skrll
39 1.1.2.2 skrll #include <sys/cdefs.h>
40 1.1.2.2 skrll __KERNEL_RCSID(0, "$NetBSD: linux_exec_machdep.c,v 1.1.2.2 2004/11/14 08:15:33 skrll Exp $");
41 1.1.2.2 skrll
42 1.1.2.2 skrll #if defined(_KERNEL_OPT)
43 1.1.2.2 skrll #include "opt_vm86.h"
44 1.1.2.2 skrll #include "opt_user_ldt.h"
45 1.1.2.2 skrll #endif
46 1.1.2.2 skrll
47 1.1.2.2 skrll #include <sys/param.h>
48 1.1.2.2 skrll #include <sys/systm.h>
49 1.1.2.2 skrll #include <sys/resource.h>
50 1.1.2.2 skrll #include <sys/proc.h>
51 1.1.2.2 skrll #include <sys/conf.h>
52 1.1.2.2 skrll #include <sys/exec.h>
53 1.1.2.2 skrll #include <sys/exec_elf.h>
54 1.1.2.2 skrll #include <sys/vnode.h>
55 1.1.2.2 skrll #include <sys/lwp.h>
56 1.1.2.2 skrll
57 1.1.2.2 skrll #include <machine/cpu.h>
58 1.1.2.2 skrll #include <machine/vmparam.h>
59 1.1.2.2 skrll
60 1.1.2.2 skrll #include <uvm/uvm.h>
61 1.1.2.2 skrll
62 1.1.2.2 skrll #include <compat/linux/common/linux_types.h>
63 1.1.2.2 skrll #include <compat/linux/common/linux_signal.h>
64 1.1.2.2 skrll #include <compat/linux/common/linux_util.h>
65 1.1.2.2 skrll #include <compat/linux/common/linux_ioctl.h>
66 1.1.2.2 skrll #include <compat/linux/common/linux_hdio.h>
67 1.1.2.2 skrll #include <compat/linux/common/linux_exec.h>
68 1.1.2.2 skrll #include <compat/linux/common/linux_machdep.h>
69 1.1.2.2 skrll #include <compat/linux/common/linux_errno.h>
70 1.1.2.2 skrll
71 1.1.2.2 skrll int
72 1.1.2.2 skrll linux_exec_setup_stack(struct proc *p, struct exec_package *epp)
73 1.1.2.2 skrll {
74 1.1.2.2 skrll u_long max_stack_size;
75 1.1.2.2 skrll u_long access_linear_min, access_size;
76 1.1.2.2 skrll u_long noaccess_linear_min, noaccess_size;
77 1.1.2.2 skrll
78 1.1.2.2 skrll #ifndef USRSTACK32
79 1.1.2.2 skrll #define USRSTACK32 (0x00000000ffffffffL&~PGOFSET)
80 1.1.2.2 skrll #endif
81 1.1.2.2 skrll
82 1.1.2.2 skrll if (epp->ep_flags & EXEC_32) {
83 1.1.2.2 skrll epp->ep_minsaddr = USRSTACK32;
84 1.1.2.2 skrll max_stack_size = MAXSSIZ;
85 1.1.2.2 skrll } else {
86 1.1.2.2 skrll epp->ep_minsaddr = USRSTACK;
87 1.1.2.2 skrll max_stack_size = MAXSSIZ;
88 1.1.2.2 skrll }
89 1.1.2.2 skrll
90 1.1.2.2 skrll if (epp->ep_minsaddr > LINUX_USRSTACK)
91 1.1.2.2 skrll epp->ep_minsaddr = LINUX_USRSTACK;
92 1.1.2.2 skrll #ifdef DEBUG_LINUX
93 1.1.2.2 skrll else {
94 1.1.2.2 skrll /*
95 1.1.2.2 skrll * Someone needs to make KERNBASE and TEXTADDR
96 1.1.2.2 skrll * java versions < 1.4.2 need the stack to be
97 1.1.2.2 skrll * at 0xC0000000
98 1.1.2.2 skrll */
99 1.1.2.2 skrll uprintf("Cannot setup stack to 0xC0000000, "
100 1.1.2.2 skrll "java will not work properly\n");
101 1.1.2.2 skrll }
102 1.1.2.2 skrll #endif
103 1.1.2.2 skrll epp->ep_maxsaddr = (u_long)STACK_GROW(epp->ep_minsaddr,
104 1.1.2.2 skrll max_stack_size);
105 1.1.2.2 skrll epp->ep_ssize = p->p_rlimit[RLIMIT_STACK].rlim_cur;
106 1.1.2.2 skrll
107 1.1.2.2 skrll /*
108 1.1.2.2 skrll * set up commands for stack. note that this takes *two*, one to
109 1.1.2.2 skrll * map the part of the stack which we can access, and one to map
110 1.1.2.2 skrll * the part which we can't.
111 1.1.2.2 skrll *
112 1.1.2.2 skrll * arguably, it could be made into one, but that would require the
113 1.1.2.2 skrll * addition of another mapping proc, which is unnecessary
114 1.1.2.2 skrll */
115 1.1.2.2 skrll access_size = epp->ep_ssize;
116 1.1.2.2 skrll access_linear_min = (u_long)STACK_ALLOC(epp->ep_minsaddr, access_size);
117 1.1.2.2 skrll noaccess_size = max_stack_size - access_size;
118 1.1.2.2 skrll noaccess_linear_min = (u_long)STACK_ALLOC(STACK_GROW(epp->ep_minsaddr,
119 1.1.2.2 skrll access_size), noaccess_size);
120 1.1.2.2 skrll if (noaccess_size > 0) {
121 1.1.2.2 skrll NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_zero, noaccess_size,
122 1.1.2.2 skrll noaccess_linear_min, NULLVP, 0, VM_PROT_NONE);
123 1.1.2.2 skrll }
124 1.1.2.2 skrll KASSERT(access_size > 0);
125 1.1.2.2 skrll NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_zero, access_size,
126 1.1.2.2 skrll access_linear_min, NULLVP, 0, VM_PROT_READ | VM_PROT_WRITE);
127 1.1.2.2 skrll
128 1.1.2.2 skrll return 0;
129 1.1.2.2 skrll }
130