1 /* Copyright (C) 1992, 1994, 1995, 1996 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
16 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, 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
);
249 _S_msg_set_init_int (mach_port_t msgport
, mach_port_t auth
,
250 int which
, int value
)
254 return set_int (which
, value
);
258 _S_msg_set_init_ints (mach_port_t msgport
, mach_port_t auth
,
259 int *values
, mach_msg_type_number_t nvalues
)
262 mach_msg_type_number_t i
;
266 for (i
= 0; i
< INIT_INT_MAX
; ++i
)
267 switch (err
= set_int (i
, values
[i
]))
269 case 0: /* Success. */
271 case EINVAL
: /* Unknown index. */
273 default: /* Lossage. */
282 _S_msg_get_fd (mach_port_t msgport
, mach_port_t auth
, int which
,
283 mach_port_t
*result
, mach_msg_type_name_t
*result_type
)
287 /* This creates a new user reference for the send right.
288 Our reply message will move that reference to the caller. */
289 *result
= __getdport (which
);
290 if (*result
== MACH_PORT_NULL
)
292 *result_type
= MACH_MSG_TYPE_MOVE_SEND
;
298 _S_msg_set_fd (mach_port_t msgport
, mach_port_t auth
,
299 int which
, mach_port_t port
)
303 /* We consume the reference if successful. */
304 return HURD_FD_USE (which
, (_hurd_port2fd (descriptor
, port
, 0), 0));
307 /* Snarfing and frobbing environment variables. */
310 _S_msg_get_env_variable (mach_port_t msgport
,
312 char **data
, mach_msg_type_number_t
*datalen
)
314 const char *value
= getenv (variable
);
319 /* XXX this pointer might become invalid */
321 *datalen
= strlen (value
);
327 _S_msg_set_env_variable (mach_port_t msgport
, mach_port_t auth
,
334 if (setenv (variable
, value
, replace
)) /* XXX name space */
340 _S_msg_get_environment (mach_port_t msgport
,
341 char **data
, mach_msg_type_number_t
*datalen
)
343 /* Pack the environment into an array with nulls separating elements. */
344 if (__environ
!= NULL
)
349 for (p
= __environ
; *p
!= NULL
; ++p
)
350 envlen
+= strlen (*p
) + 1;
352 if (envlen
> *datalen
)
354 if (__vm_allocate (__mach_task_self (),
355 (vm_address_t
*) data
, envlen
, 1))
360 for (p
= __environ
; *p
!= NULL
; ++p
)
361 ap
= __memccpy (ap
, *p
, '\0', ULONG_MAX
);
372 _S_msg_set_environment (mach_port_t msgport
, mach_port_t auth
,
373 char *data
, mach_msg_type_number_t datalen
)
375 int _hurd_split_args (char *, mach_msg_type_number_t
, char **);
381 envc
= __argz_count (data
, datalen
);
382 envp
= malloc ((envc
+ 1) * sizeof (char *));
385 __argz_extract (data
, datalen
, envp
);
386 __environ
= envp
; /* XXX cooperate with loadenv et al */
394 _S_msg_get_dtable (mach_port_t process
,
397 mach_msg_type_name_t
*dtablePoly
,
398 mach_msg_type_number_t
*dtableCnt
)
399 { return EOPNOTSUPP
; }
402 _S_msg_set_dtable (mach_port_t process
,
405 mach_msg_type_number_t dtableCnt
)
406 { return EOPNOTSUPP
; }