Home | History | Annotate | Download | only in common
      1 /*
      2  * CDDL HEADER START
      3  *
      4  * The contents of this file are subject to the terms of the
      5  * Common Development and Distribution License, Version 1.0 only
      6  * (the "License").  You may not use this file except in compliance
      7  * with the License.
      8  *
      9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
     10  * or http://www.opensolaris.org/os/licensing.
     11  * See the License for the specific language governing permissions
     12  * and limitations under the License.
     13  *
     14  * When distributing Covered Code, include this CDDL HEADER in each
     15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     16  * If applicable, add the following below this CDDL HEADER, with the
     17  * fields enclosed by brackets "[]" replaced with your own identifying
     18  * information: Portions Copyright [yyyy] [name of copyright owner]
     19  *
     20  * CDDL HEADER END
     21  */
     22 /*
     23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
     24  * Use is subject to license terms.
     25  */
     26 
     27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
     28 
     29 #define	_LARGEFILE64_SOURCE
     30 
     31 #include <sys/task.h>
     32 #include <sys/types.h>
     33 
     34 #include <zone.h>
     35 #include <errno.h>
     36 #include <project.h>
     37 #include <stdlib.h>
     38 #include <strings.h>
     39 #include <unistd.h>
     40 
     41 #include "libproc.h"
     42 
     43 zoneid_t
     44 pr_getzoneid(struct ps_prochandle *Pr)
     45 {
     46 	sysret_t rval;
     47 	argdes_t argd[2];
     48 	argdes_t *adp;
     49 	int error;
     50 
     51 	if (Pr == NULL)		/* no subject process */
     52 		return (getzoneid());
     53 
     54 	adp = &argd[0];
     55 	adp->arg_value = 6;	/* switch for zone_lookup in zone */
     56 	adp->arg_object = NULL;
     57 	adp->arg_type = AT_BYVAL;
     58 	adp->arg_inout = AI_INPUT;
     59 	adp->arg_size = 0;
     60 
     61 	adp = &argd[1];
     62 	adp->arg_value = 0;	/* arguement for zone_lookup in zone */
     63 	adp->arg_object = NULL;
     64 	adp->arg_type = AT_BYVAL;
     65 	adp->arg_inout = AI_INPUT;
     66 	adp->arg_size = 0;
     67 
     68 	error = Psyscall(Pr, &rval, SYS_zone, 2, &argd[0]);
     69 
     70 	if (error) {
     71 		errno = (error > 0) ? error : ENOSYS;
     72 		return (-1);
     73 	}
     74 	return (rval.sys_rval1);
     75 }
     76 
     77 projid_t
     78 pr_getprojid(struct ps_prochandle *Pr)
     79 {
     80 	sysret_t rval;
     81 	argdes_t argd[1];
     82 	argdes_t *adp;
     83 	int error;
     84 
     85 	if (Pr == NULL)		/* no subject process */
     86 		return (getprojid());
     87 
     88 	adp = &argd[0];
     89 	adp->arg_value = 2;	/* switch for getprojid in tasksys */
     90 	adp->arg_object = NULL;
     91 	adp->arg_type = AT_BYVAL;
     92 	adp->arg_inout = AI_INPUT;
     93 	adp->arg_size = 0;
     94 
     95 	error = Psyscall(Pr, &rval, SYS_tasksys, 1, &argd[0]);
     96 
     97 	if (error) {
     98 		errno = (error > 0) ? error : ENOSYS;
     99 		return (-1);
    100 	}
    101 	return (rval.sys_rval1);
    102 }
    103 
    104 taskid_t
    105 pr_gettaskid(struct ps_prochandle *Pr)
    106 {
    107 	sysret_t rval;
    108 	argdes_t argd[1];
    109 	argdes_t *adp;
    110 	int error;
    111 
    112 	if (Pr == NULL)		/* no subject process */
    113 		return (gettaskid());
    114 
    115 	adp = &argd[0];
    116 	adp->arg_value = 1;	/* switch for gettaskid in tasksys */
    117 	adp->arg_object = NULL;
    118 	adp->arg_type = AT_BYVAL;
    119 	adp->arg_inout = AI_INPUT;
    120 	adp->arg_size = 0;
    121 
    122 	error = Psyscall(Pr, &rval, SYS_tasksys, 1, &argd[0]);
    123 
    124 	if (error) {
    125 		errno = (error > 0) ? error : ENOSYS;
    126 		return (-1);
    127 	}
    128 	return (rval.sys_rval1);
    129 }
    130 
    131 taskid_t
    132 pr_settaskid(struct ps_prochandle *Pr, projid_t project, int flags)
    133 {
    134 	sysret_t rval;
    135 	argdes_t argd[3];
    136 	argdes_t *adp;
    137 	int error;
    138 
    139 	if (Pr == NULL)		/* No subject process */
    140 		return (settaskid(project, flags));
    141 
    142 	adp = &argd[0];
    143 	adp->arg_value = 0;	/* switch for settaskid in tasksys */
    144 	adp->arg_object = NULL;
    145 	adp->arg_type = AT_BYVAL;
    146 	adp->arg_inout = AI_INPUT;
    147 	adp->arg_size = 0;
    148 
    149 	adp++;
    150 	adp->arg_value = project;
    151 	adp->arg_object = NULL;
    152 	adp->arg_type = AT_BYVAL;
    153 	adp->arg_inout = AI_INPUT;
    154 	adp->arg_size = sizeof (project);
    155 
    156 	adp++;
    157 	adp->arg_value = flags;
    158 	adp->arg_object = NULL;
    159 	adp->arg_type = AT_BYVAL;
    160 	adp->arg_inout = AI_INPUT;
    161 	adp->arg_size = 0;
    162 
    163 	error = Psyscall(Pr, &rval, SYS_tasksys, 3, &argd[0]);
    164 
    165 	if (error) {
    166 		errno = (error > 0) ? error : ENOSYS;
    167 		return (-1);
    168 	}
    169 	return (rval.sys_rval1);
    170 }
    171