1 /* Copyright (C) 1992, 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
20 #include <hurd/msg_server.h>
29 if (auth != mach_task_self () && ! __USEPORT (AUTH, port == auth)) \
33 /* Snarfing and frobbing the init ports. */
36 _S_msg_get_init_port (mach_port_t msgport
, mach_port_t auth
, int which
,
37 mach_port_t
*result
, mach_msg_type_name_t
*result_type
)
40 *result_type
= MACH_MSG_TYPE_MOVE_SEND
;
41 /* This function adds a new user reference for the *RESULT it gives back.
42 Our reply message uses a move-send right that consumes this reference. */
43 return _hurd_ports_get (which
, result
);
47 _S_msg_set_init_port (mach_port_t msgport
, mach_port_t auth
,
48 int which
, mach_port_t port
)
54 err
= _hurd_ports_set (which
, port
);
56 __mach_port_deallocate (__mach_task_self (), port
);
62 _S_msg_get_init_ports (mach_port_t msgport
, mach_port_t auth
,
64 mach_msg_type_name_t
*ports_type
,
65 mach_msg_type_number_t
*nports
)
67 mach_msg_type_number_t i
;
72 if (err
= __vm_allocate (__mach_task_self (), (vm_address_t
*) ports
,
73 _hurd_nports
* sizeof (mach_port_t
), 1))
75 *nports
= _hurd_nports
;
77 for (i
= 0; i
< _hurd_nports
; ++i
)
78 /* This function adds a new user ref for the *RESULT it gives back.
79 Our reply message uses move-send rights that consumes this ref. */
80 if (err
= _hurd_ports_get (i
, &(*ports
)[i
]))
82 /* Died part way through. Deallocate the ports already fetched. */
84 __mach_port_deallocate (__mach_task_self (), (*ports
)[i
]);
85 __vm_deallocate (__mach_task_self (),
86 (vm_address_t
) *ports
,
87 *nports
* sizeof (mach_port_t
));
91 *ports_type
= MACH_MSG_TYPE_MOVE_SEND
;
96 _S_msg_set_init_ports (mach_port_t msgport
, mach_port_t auth
,
97 mach_port_t
*ports
, mach_msg_type_number_t nports
)
99 mach_msg_type_number_t i
;
104 for (i
= 0; i
< _hurd_nports
; ++i
)
106 if (err
= _hurd_ports_set (i
, ports
[i
]))
109 __mach_port_deallocate (__mach_task_self (), ports
[i
]);
115 /* Snarfing and frobbing the init ints. */
118 get_int (int which
, int *value
)
123 *value
= _hurd_umask
;
127 struct hurd_sigstate
*ss
= _hurd_thread_sigstate (_hurd_sigthread
);
128 __spin_lock (&ss
->lock
);
129 *value
= ss
->blocked
;
130 __spin_unlock (&ss
->lock
);
133 case INIT_SIGPENDING
:
135 struct hurd_sigstate
*ss
= _hurd_thread_sigstate (_hurd_sigthread
);
136 __spin_lock (&ss
->lock
);
137 *value
= ss
->pending
;
138 __spin_unlock (&ss
->lock
);
143 struct hurd_sigstate
*ss
= _hurd_thread_sigstate (_hurd_sigthread
);
146 __spin_lock (&ss
->lock
);
147 __sigemptyset (&ign
);
148 for (sig
= 1; sig
< NSIG
; ++sig
)
149 if (ss
->actions
[sig
].sa_handler
== SIG_IGN
)
150 __sigaddset (&ign
, sig
);
151 __spin_unlock (&ss
->lock
);
161 _S_msg_get_init_int (mach_port_t msgport
, mach_port_t auth
,
162 int which
, int *value
)
166 return get_int (which
, value
);
170 _S_msg_get_init_ints (mach_port_t msgport
, mach_port_t auth
,
171 int **values
, mach_msg_type_number_t
*nvalues
)
174 mach_msg_type_number_t i
;
178 if (err
= __vm_allocate (__mach_task_self (), (vm_address_t
*) values
,
179 INIT_INT_MAX
* sizeof (int), 1))
181 *nvalues
= INIT_INT_MAX
;
183 for (i
= 0; i
< INIT_INT_MAX
; ++i
)
184 switch (err
= get_int (i
, &(*values
)[i
]))
186 case 0: /* Success. */
188 case EINVAL
: /* Unknown index. */
191 default: /* Lossage. */
192 __vm_deallocate (__mach_task_self (),
193 (vm_address_t
) *values
, INIT_INT_MAX
* sizeof (int));
202 set_int (int which
, int value
)
210 /* These are pretty odd things to do. But you asked for it. */
213 struct hurd_sigstate
*ss
= _hurd_thread_sigstate (_hurd_sigthread
);
214 __spin_lock (&ss
->lock
);
216 __spin_unlock (&ss
->lock
);
219 case INIT_SIGPENDING
:
221 struct hurd_sigstate
*ss
= _hurd_thread_sigstate (_hurd_sigthread
);
222 __spin_lock (&ss
->lock
);
224 __spin_unlock (&ss
->lock
);
229 struct hurd_sigstate
*ss
= _hurd_thread_sigstate (_hurd_sigthread
);
231 const sigset_t ign
= value
;
232 __spin_lock (&ss
->lock
);
233 for (sig
= 1; sig
< NSIG
; ++sig
)
235 if (__sigismember (&ign
, sig
))
236 ss
->actions
[sig
].sa_handler
= SIG_IGN
;
237 else if (ss
->actions
[sig
].sa_handler
== SIG_IGN
)
238 ss
->actions
[sig
].sa_handler
= SIG_DFL
;
240 __spin_unlock (&ss
->lock
);
244 _hurdsig_traced
= value
;
253 _S_msg_set_init_int (mach_port_t msgport
, mach_port_t auth
,
254 int which
, int value
)
258 return set_int (which
, value
);
262 _S_msg_set_init_ints (mach_port_t msgport
, mach_port_t auth
,
263 int *values
, mach_msg_type_number_t nvalues
)
266 mach_msg_type_number_t i
;
270 for (i
= 0; i
< INIT_INT_MAX
; ++i
)
271 switch (err
= set_int (i
, values
[i
]))
273 case 0: /* Success. */
275 case EINVAL
: /* Unknown index. */
277 default: /* Lossage. */
286 _S_msg_get_fd (mach_port_t msgport
, mach_port_t auth
, int which
,
287 mach_port_t
*result
, mach_msg_type_name_t
*result_type
)
291 /* This creates a new user reference for the send right.
292 Our reply message will move that reference to the caller. */
293 *result
= __getdport (which
);
294 if (*result
== MACH_PORT_NULL
)
296 *result_type
= MACH_MSG_TYPE_MOVE_SEND
;
302 _S_msg_set_fd (mach_port_t msgport
, mach_port_t auth
,
303 int which
, mach_port_t port
)
307 /* We consume the reference if successful. */
308 return HURD_FD_USE (which
, (_hurd_port2fd (descriptor
, port
, 0), 0));
311 /* Snarfing and frobbing environment variables. */
314 _S_msg_get_env_variable (mach_port_t msgport
,
316 char **data
, mach_msg_type_number_t
*datalen
)
319 mach_msg_type_number_t valuelen
;
320 const char *value
= getenv (variable
);
325 valuelen
= strlen (value
);
326 if (valuelen
> *datalen
)
328 if (err
= __vm_allocate (__mach_task_self (),
329 (vm_address_t
*) data
, valuelen
, 1))
333 memcpy (*data
, value
, valuelen
);
341 _S_msg_set_env_variable (mach_port_t msgport
, mach_port_t auth
,
348 if (setenv (variable
, value
, replace
)) /* XXX name space */
354 _S_msg_get_environment (mach_port_t msgport
,
355 char **data
, mach_msg_type_number_t
*datalen
)
357 /* Pack the environment into an array with nulls separating elements. */
358 if (__environ
!= NULL
)
363 for (p
= __environ
; *p
!= NULL
; ++p
)
364 envlen
+= strlen (*p
) + 1;
366 if (envlen
> *datalen
)
368 if (__vm_allocate (__mach_task_self (),
369 (vm_address_t
*) data
, envlen
, 1))
374 for (p
= __environ
; *p
!= NULL
; ++p
)
375 ap
= __memccpy (ap
, *p
, '\0', ULONG_MAX
);
386 _S_msg_set_environment (mach_port_t msgport
, mach_port_t auth
,
387 char *data
, mach_msg_type_number_t datalen
)
389 int _hurd_split_args (char *, mach_msg_type_number_t
, char **);
395 envc
= __argz_count (data
, datalen
);
396 envp
= malloc ((envc
+ 1) * sizeof (char *));
399 __argz_extract (data
, datalen
, envp
);
400 __environ
= envp
; /* XXX cooperate with loadenv et al */
408 _S_msg_get_dtable (mach_port_t process
,
411 mach_msg_type_name_t
*dtablePoly
,
412 mach_msg_type_number_t
*dtableCnt
)
413 { return EOPNOTSUPP
; }
416 _S_msg_set_dtable (mach_port_t process
,
419 mach_msg_type_number_t dtableCnt
)
420 { return EOPNOTSUPP
; }