1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20: #include <sys/stat.h>
21: #include <stdlib.h>
22: #include <stdio.h>
23: #include <unistd.h>
24: #include <hurd.h>
25: #include <hurd/port.h>
26: #include "set-hooks.h"
27: #include "hurdmalloc.h"
28:
29:
30: int _hurd_exec_flags;
31: struct hurd_port *_hurd_ports;
32: unsigned int _hurd_nports;
33: mode_t _hurd_umask;
34: sigset_t _hurdsig_traced;
35:
36: char **__libc_argv;
37: int __libc_argc;
38:
39:
40: error_t
41: _hurd_ports_use (int which, error_t (*operate) (mach_port_t))
42: {
43: if (__builtin_expect (_hurd_ports == NULL, 0))
44:
45:
46:
47: return EGRATUITOUS;
48:
49: return HURD_PORT_USE (&_hurd_ports[which], (*operate) (port));
50: }
51:
52: DEFINE_HOOK (_hurd_subinit, (void));
53:
54: __typeof (_hurd_proc_init) _hurd_new_proc_init;
55:
56:
57:
58:
59:
60:
61: void
62: _hurd_init (int flags, char **argv,
63: mach_port_t *portarray, size_t portarraysize,
64: int *intarray, size_t intarraysize)
65: {
66: size_t i;
67:
68: _hurd_exec_flags = flags;
69:
70: _hurd_ports = malloc (portarraysize * sizeof (*_hurd_ports));
71: if (_hurd_ports == NULL)
72: __libc_fatal ("Can't allocate _hurd_ports\n");
73: _hurd_nports = portarraysize;
74:
75:
76: for (i = 0; i < portarraysize; ++i)
77: _hurd_port_init (&_hurd_ports[i], portarray[i]);
78:
79:
80:
81: __task_set_special_port (__mach_task_self (), TASK_BOOTSTRAP_PORT,
82: portarray[INIT_PORT_BOOTSTRAP]);
83:
84: if (intarraysize > INIT_UMASK)
85: _hurd_umask = intarray[INIT_UMASK] & 0777;
86: else
87: _hurd_umask = CMASK;
88:
89: if (intarraysize > INIT_TRACEMASK)
90: _hurdsig_traced = intarray[INIT_TRACEMASK];
91:
92:
93: if (portarray[INIT_PORT_PROC] != MACH_PORT_NULL)
94: _hurd_new_proc_init (argv, intarray, intarraysize);
95:
96:
97: __vm_deallocate (__mach_task_self (),
98: (vm_address_t) intarray,
99: intarraysize * sizeof (int));
100: __vm_deallocate (__mach_task_self (),
101: (vm_address_t) portarray,
102: portarraysize * sizeof (mach_port_t));
103:
104: if (flags & EXEC_SECURE)
105:
106:
107:
108: ;
109:
110:
111:
112:
113: RUN_HOOK (_hurd_subinit, ());
114: }
115: ^L
116: #include <hurd/signal.h>
117:
118:
119:
120: int _hide_arguments, _hide_environment;
121:
122:
123:
124: DEFINE_HOOK (_hurd_proc_subinit, (void));
125:
126:
127:
128:
129: void
130: _hurd_new_proc_init (char **argv,
131: const int *intarray, size_t intarraysize)
132: {
133: mach_port_t oldmsg;
134: struct hurd_userlink ulink;
135: process_t procserver;
136:
137:
138: _hurdsig_init (intarray, intarraysize);
139:
140:
141:
142:
143: procserver = _hurd_port_get (&_hurd_ports[INIT_PORT_PROC], &ulink);
144:
145:
146: __proc_setmsgport (procserver, _hurd_msgport, &oldmsg);
147: if (oldmsg != MACH_PORT_NULL)
148:
149: __mach_port_deallocate (__mach_task_self (), oldmsg);
150:
151:
152: __proc_set_arg_locations (procserver,
153: _hide_arguments ? 0 : (vm_address_t) argv,
154: _hide_environment ? 0 : (vm_address_t) __environ);
155:
156: _hurd_port_free (&_hurd_ports[INIT_PORT_PROC], &ulink, procserver);
157:
158:
159: _hurdsig_fault_init ();
160:
161:
162:
163:
164: RUN_HOOK (_hurd_proc_subinit, ());
165:
166:
167:
168:
169:
170:
171: if (!__sigisemptyset (&_hurdsig_traced)
172: #ifdef EXEC_SIGTRAP
173: && !(_hurd_exec_flags & EXEC_SIGTRAP)
174: #endif
175: )
176:
177:
178:
179: __msg_sig_post (_hurd_msgport, SIGTRAP, 0, __mach_task_self ());
180: }
181:
182: #include <shlib-compat.h>
183: versioned_symbol (libc, _hurd_new_proc_init, _hurd_proc_init, GLIBC_2_1);
184: ^L
185:
186:
187: error_t
188: _hurd_setproc (process_t procserver)
189: {
190: error_t err;
191: mach_port_t oldmsg;
192:
193:
194: if (err = __proc_setmsgport (procserver, _hurd_msgport, &oldmsg))
195: return err;
196: if (oldmsg != MACH_PORT_NULL)
197:
198: __mach_port_deallocate (__mach_task_self (), oldmsg);
199:
200:
201: if (err = __proc_set_arg_locations (procserver,
202: _hide_arguments ? 0 :
203: (vm_address_t) __libc_argv,
204: _hide_environment ? 0 :
205: (vm_address_t) __environ))
206: return err;
207:
208:
209: _hurd_port_set (&_hurd_ports[INIT_PORT_PROC], procserver);
210:
211: {
212: pid_t oldpgrp = _hurd_pgrp;
213:
214:
215:
216: RUN_HOOK (_hurd_proc_subinit, ());
217:
218: if (_hurd_pgrp != oldpgrp)
219: {
220:
221: DECLARE_HOOK (_hurd_pgrp_changed_hook, (pid_t));
222: RUN_HOOK (_hurd_pgrp_changed_hook, (_hurd_pgrp));
223: }
224: }
225:
226: return 0;
227: }