Back to index

glibc  2.9
Defines | Functions
hurdmsg.c File Reference
#include <hurd.h>
#include <hurd/msg_server.h>
#include <hurd/fd.h>
#include <unistd.h>
#include <limits.h>
#include <string.h>
#include <argz.h>

Go to the source code of this file.

Defines

#define AUTHCHECK

Functions

kern_return_t _S_msg_get_init_port (mach_port_t msgport, mach_port_t auth, int which, mach_port_t *result, mach_msg_type_name_t *result_type)
kern_return_t _S_msg_set_init_port (mach_port_t msgport, mach_port_t auth, int which, mach_port_t port)
kern_return_t _S_msg_get_init_ports (mach_port_t msgport, mach_port_t auth, mach_port_t **ports, mach_msg_type_name_t *ports_type, mach_msg_type_number_t *nports)
kern_return_t _S_msg_set_init_ports (mach_port_t msgport, mach_port_t auth, mach_port_t *ports, mach_msg_type_number_t nports)
static kern_return_t get_int (int which, int *value)
kern_return_t _S_msg_get_init_int (mach_port_t msgport, mach_port_t auth, int which, int *value)
kern_return_t _S_msg_get_init_ints (mach_port_t msgport, mach_port_t auth, int **values, mach_msg_type_number_t *nvalues)
static kern_return_t set_int (int which, int value)
kern_return_t _S_msg_set_init_int (mach_port_t msgport, mach_port_t auth, int which, int value)
kern_return_t _S_msg_set_init_ints (mach_port_t msgport, mach_port_t auth, int *values, mach_msg_type_number_t nvalues)
kern_return_t _S_msg_get_fd (mach_port_t msgport, mach_port_t auth, int which, mach_port_t *result, mach_msg_type_name_t *result_type)
kern_return_t _S_msg_set_fd (mach_port_t msgport, mach_port_t auth, int which, mach_port_t port)
kern_return_t _S_msg_get_env_variable (mach_port_t msgport, char *variable, char **data, mach_msg_type_number_t *datalen)
kern_return_t _S_msg_set_env_variable (mach_port_t msgport, mach_port_t auth, char *variable, char *value, int replace)
kern_return_t _S_msg_get_environment (mach_port_t msgport, char **data, mach_msg_type_number_t *datalen)
kern_return_t _S_msg_set_environment (mach_port_t msgport, mach_port_t auth, char *data, mach_msg_type_number_t datalen)
kern_return_t _S_msg_get_dtable (mach_port_t process, mach_port_t refport, portarray_t *dtable, mach_msg_type_name_t *dtablePoly, mach_msg_type_number_t *dtableCnt)
kern_return_t _S_msg_set_dtable (mach_port_t process, mach_port_t refport, portarray_t dtable, mach_msg_type_number_t dtableCnt)

Define Documentation

#define AUTHCHECK
Value:
if (auth != mach_task_self () && ! __USEPORT (AUTH, port == auth)) \
    return EPERM

Definition at line 28 of file hurdmsg.c.


Function Documentation

kern_return_t _S_msg_get_dtable ( mach_port_t  process,
mach_port_t  refport,
portarray_t *  dtable,
mach_msg_type_name_t *  dtablePoly,
mach_msg_type_number_t *  dtableCnt 
)

Definition at line 408 of file hurdmsg.c.

{ return EOPNOTSUPP; }
kern_return_t _S_msg_get_env_variable ( mach_port_t  msgport,
char *  variable,
char **  data,
mach_msg_type_number_t *  datalen 
)

Definition at line 314 of file hurdmsg.c.

{
  error_t err;
  mach_msg_type_number_t valuelen;
  const char *value = getenv (variable);

  if (value == NULL)
    return ENOENT;

  valuelen = strlen (value);
  if (valuelen > *datalen)
    {
      if (err = __vm_allocate (__mach_task_self (), 
                            (vm_address_t *) data, valuelen, 1))
       return err;
    }

  memcpy (*data, value, valuelen);
  *datalen = valuelen;

  return 0;
}

Here is the call graph for this function:

kern_return_t _S_msg_get_environment ( mach_port_t  msgport,
char **  data,
mach_msg_type_number_t *  datalen 
)

Definition at line 354 of file hurdmsg.c.

{
  /* Pack the environment into an array with nulls separating elements.  */
  if (__environ != NULL)
    {
      char *ap, **p;
      size_t envlen = 0;

      for (p = __environ; *p != NULL; ++p)
       envlen += strlen (*p) + 1;

      if (envlen > *datalen)
       {
         if (__vm_allocate (__mach_task_self (),
                          (vm_address_t *) data, envlen, 1))
           return ENOMEM;
       }

      ap = *data;
      for (p = __environ; *p != NULL; ++p)
       ap = __memccpy (ap, *p, '\0', ULONG_MAX);

      *datalen = envlen;
    }
  else
    *datalen = 0;

  return 0;
}

Here is the call graph for this function:

kern_return_t _S_msg_get_fd ( mach_port_t  msgport,
mach_port_t  auth,
int  which,
mach_port_t *  result,
mach_msg_type_name_t *  result_type 
)

Definition at line 286 of file hurdmsg.c.

{
  AUTHCHECK;

  /* This creates a new user reference for the send right.
     Our reply message will move that reference to the caller.  */
  *result = __getdport (which);
  if (*result == MACH_PORT_NULL)
    return errno;
  *result_type = MACH_MSG_TYPE_MOVE_SEND;

  return 0;
}

Here is the call graph for this function:

kern_return_t _S_msg_get_init_int ( mach_port_t  msgport,
mach_port_t  auth,
int  which,
int value 
)

Definition at line 161 of file hurdmsg.c.

{
  AUTHCHECK;

  return get_int (which, value);
}

Here is the call graph for this function:

kern_return_t _S_msg_get_init_ints ( mach_port_t  msgport,
mach_port_t  auth,
int **  values,
mach_msg_type_number_t *  nvalues 
)

Definition at line 170 of file hurdmsg.c.

{
  error_t err;
  mach_msg_type_number_t i;

  AUTHCHECK;

  if (err = __vm_allocate (__mach_task_self (), (vm_address_t *) values,
                        INIT_INT_MAX * sizeof (int), 1))
    return err;
  *nvalues = INIT_INT_MAX;

  for (i = 0; i < INIT_INT_MAX; ++i)
    switch (err = get_int (i, &(*values)[i]))
      {
      case 0:               /* Success.  */
       break;
      case EINVAL:          /* Unknown index.  */
       (*values)[i] = 0;
       break;
      default:                     /* Lossage.  */
       __vm_deallocate (__mach_task_self (),
                      (vm_address_t) *values, INIT_INT_MAX * sizeof (int));
       return err;
      }

  return 0;
}

Here is the call graph for this function:

kern_return_t _S_msg_get_init_port ( mach_port_t  msgport,
mach_port_t  auth,
int  which,
mach_port_t *  result,
mach_msg_type_name_t *  result_type 
)

Definition at line 36 of file hurdmsg.c.

{
  AUTHCHECK;
  *result_type = MACH_MSG_TYPE_MOVE_SEND;
  /* This function adds a new user reference for the *RESULT it gives back.
     Our reply message uses a move-send right that consumes this reference.  */
  return _hurd_ports_get (which, result);
}

Here is the call graph for this function:

kern_return_t _S_msg_get_init_ports ( mach_port_t  msgport,
mach_port_t  auth,
mach_port_t **  ports,
mach_msg_type_name_t *  ports_type,
mach_msg_type_number_t *  nports 
)

Definition at line 62 of file hurdmsg.c.

{
  mach_msg_type_number_t i;
  error_t err;

  AUTHCHECK;

  if (err = __vm_allocate (__mach_task_self (), (vm_address_t *) ports,
                        _hurd_nports * sizeof (mach_port_t), 1))
    return err;
  *nports = _hurd_nports;

  for (i = 0; i < _hurd_nports; ++i)
    /* This function adds a new user ref for the *RESULT it gives back.
       Our reply message uses move-send rights that consumes this ref.  */
    if (err = _hurd_ports_get (i, &(*ports)[i]))
      {
       /* Died part way through.  Deallocate the ports already fetched.  */
       while (i-- > 0)
         __mach_port_deallocate (__mach_task_self (), (*ports)[i]);
       __vm_deallocate (__mach_task_self (),
                      (vm_address_t) *ports,
                      *nports * sizeof (mach_port_t));
       return err;
      }

  *ports_type = MACH_MSG_TYPE_MOVE_SEND;
  return 0;
}

Here is the call graph for this function:

kern_return_t _S_msg_set_dtable ( mach_port_t  process,
mach_port_t  refport,
portarray_t  dtable,
mach_msg_type_number_t  dtableCnt 
)

Definition at line 416 of file hurdmsg.c.

{ return EOPNOTSUPP; }
kern_return_t _S_msg_set_env_variable ( mach_port_t  msgport,
mach_port_t  auth,
char *  variable,
char *  value,
int  replace 
)

Definition at line 341 of file hurdmsg.c.

{
  AUTHCHECK;

  if (setenv (variable, value, replace)) /* XXX name space */
    return errno;
  return 0;
}

Here is the call graph for this function:

kern_return_t _S_msg_set_environment ( mach_port_t  msgport,
mach_port_t  auth,
char *  data,
mach_msg_type_number_t  datalen 
)

Definition at line 386 of file hurdmsg.c.

{
  int _hurd_split_args (char *, mach_msg_type_number_t, char **);
  int envc;
  char **envp;

  AUTHCHECK;

  envc = __argz_count (data, datalen);
  envp = malloc ((envc + 1) * sizeof (char *));
  if (envp == NULL)
    return errno;
  __argz_extract (data, datalen, envp);
  __environ = envp;         /* XXX cooperate with loadenv et al */
  return 0;
}

Here is the call graph for this function:

kern_return_t _S_msg_set_fd ( mach_port_t  msgport,
mach_port_t  auth,
int  which,
mach_port_t  port 
)

Definition at line 302 of file hurdmsg.c.

{
  AUTHCHECK;

  /* We consume the reference if successful.  */
  return HURD_FD_USE (which, (_hurd_port2fd (descriptor, port, 0), 0));
}

Here is the call graph for this function:

kern_return_t _S_msg_set_init_int ( mach_port_t  msgport,
mach_port_t  auth,
int  which,
int  value 
)

Definition at line 253 of file hurdmsg.c.

{
  AUTHCHECK;

  return set_int (which, value);
}

Here is the call graph for this function:

kern_return_t _S_msg_set_init_ints ( mach_port_t  msgport,
mach_port_t  auth,
int values,
mach_msg_type_number_t  nvalues 
)

Definition at line 262 of file hurdmsg.c.

{
  error_t err;
  mach_msg_type_number_t i;

  AUTHCHECK;

  for (i = 0; i < INIT_INT_MAX; ++i)
    switch (err = set_int (i, values[i]))
      {
      case 0:               /* Success.  */
       break;
      case EINVAL:          /* Unknown index.  */
       break;
      default:                     /* Lossage.  */
       return err;
      }

  return 0;
}

Here is the call graph for this function:

kern_return_t _S_msg_set_init_port ( mach_port_t  msgport,
mach_port_t  auth,
int  which,
mach_port_t  port 
)

Definition at line 47 of file hurdmsg.c.

{
  error_t err;

  AUTHCHECK;

  err = _hurd_ports_set (which, port);
  if (err == 0)
    __mach_port_deallocate (__mach_task_self (), port);

  return 0;
}

Here is the call graph for this function:

kern_return_t _S_msg_set_init_ports ( mach_port_t  msgport,
mach_port_t  auth,
mach_port_t *  ports,
mach_msg_type_number_t  nports 
)

Definition at line 96 of file hurdmsg.c.

{
  mach_msg_type_number_t i;
  error_t err;

  AUTHCHECK;

  for (i = 0; i < _hurd_nports; ++i)
    {
      if (err = _hurd_ports_set (i, ports[i]))
       return err;
      else
       __mach_port_deallocate (__mach_task_self (), ports[i]);
    }

  return 0;
}

Here is the call graph for this function:

static kern_return_t get_int ( int  which,
int value 
) [static]

Definition at line 118 of file hurdmsg.c.

{
  switch (which)
    {
    case INIT_UMASK:
      *value = _hurd_umask;
      return 0;
    case INIT_SIGMASK:
      {
       struct hurd_sigstate *ss = _hurd_thread_sigstate (_hurd_sigthread);
       __spin_lock (&ss->lock);
       *value = ss->blocked;
       __spin_unlock (&ss->lock);
       return 0;
      }
    case INIT_SIGPENDING:
      {
       struct hurd_sigstate *ss = _hurd_thread_sigstate (_hurd_sigthread);
       __spin_lock (&ss->lock);
       *value = ss->pending;
       __spin_unlock (&ss->lock);
       return 0;
      }
    case INIT_SIGIGN:
      {
       struct hurd_sigstate *ss = _hurd_thread_sigstate (_hurd_sigthread);
       sigset_t ign;
       int sig;
       __spin_lock (&ss->lock);
       __sigemptyset (&ign);
       for (sig = 1; sig < NSIG; ++sig)
         if (ss->actions[sig].sa_handler == SIG_IGN)
           __sigaddset (&ign, sig);
       __spin_unlock (&ss->lock);
       *value = ign;
       return 0;
      }
    default:
      return EINVAL;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static kern_return_t set_int ( int  which,
int  value 
) [static]

Definition at line 202 of file hurdmsg.c.

{
  switch (which)
    {
    case INIT_UMASK:
      _hurd_umask = value;
      return 0;

      /* These are pretty odd things to do.  But you asked for it.  */
    case INIT_SIGMASK:
      {
       struct hurd_sigstate *ss = _hurd_thread_sigstate (_hurd_sigthread);
       __spin_lock (&ss->lock);
       ss->blocked = value;
       __spin_unlock (&ss->lock);
       return 0;
      }
    case INIT_SIGPENDING:
      {
       struct hurd_sigstate *ss = _hurd_thread_sigstate (_hurd_sigthread);
       __spin_lock (&ss->lock);
       ss->pending = value;
       __spin_unlock (&ss->lock);
       return 0;
      }
    case INIT_SIGIGN:
      {
       struct hurd_sigstate *ss = _hurd_thread_sigstate (_hurd_sigthread);
       int sig;
       const sigset_t ign = value;
       __spin_lock (&ss->lock);
       for (sig = 1; sig < NSIG; ++sig)
         {
           if (__sigismember (&ign, sig))
             ss->actions[sig].sa_handler = SIG_IGN;
           else if (ss->actions[sig].sa_handler == SIG_IGN)
             ss->actions[sig].sa_handler = SIG_DFL;
         }
       __spin_unlock (&ss->lock);
       return 0;

      case INIT_TRACEMASK:
       _hurdsig_traced = value;
       return 0;
      }
    default:
      return EINVAL;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function: