10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*6247Sraf * Common Development and Distribution License (the "License"). 6*6247Sraf * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 21*6247Sraf 220Sstevel@tonic-gate /* 23*6247Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 280Sstevel@tonic-gate 290Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */ 300Sstevel@tonic-gate /* All Rights Reserved */ 310Sstevel@tonic-gate 32*6247Sraf #include "synonyms.h" 33*6247Sraf #include <sys/types.h> 34*6247Sraf #include <sys/procset.h> 35*6247Sraf #include <sys/priocntl.h> 36*6247Sraf #include <stdarg.h> 37*6247Sraf #include <errno.h> 380Sstevel@tonic-gate 390Sstevel@tonic-gate /* 40*6247Sraf * The declarations of __priocntlset() and __priocntl() were in prior releases 41*6247Sraf * in <sys/priocntl.h>. They are used to define PC_VERSION at compile time, 42*6247Sraf * based on the contents of the header file. This behavior is now changed. 43*6247Sraf * Old binaries call __priocntl() and __priocntlset() instead of priocntl() 44*6247Sraf * and priocntlset(). New binaries call priocntl() and priocntlset(). 450Sstevel@tonic-gate */ 460Sstevel@tonic-gate 470Sstevel@tonic-gate /* 480Sstevel@tonic-gate * defined in priocntlset.s 490Sstevel@tonic-gate */ 500Sstevel@tonic-gate extern long __priocntlset(int, procset_t *, int, caddr_t, ...); 510Sstevel@tonic-gate 520Sstevel@tonic-gate static int pc_vaargs2parms(va_list valist, pc_vaparms_t *vp); 530Sstevel@tonic-gate 540Sstevel@tonic-gate long 550Sstevel@tonic-gate __priocntl(int pc_version, idtype_t idtype, id_t id, int cmd, caddr_t arg) 560Sstevel@tonic-gate { 570Sstevel@tonic-gate procset_t procset; 580Sstevel@tonic-gate 590Sstevel@tonic-gate setprocset(&procset, POP_AND, idtype, id, P_ALL, 0); 600Sstevel@tonic-gate 610Sstevel@tonic-gate return (__priocntlset(pc_version, &procset, cmd, arg, 0)); 620Sstevel@tonic-gate } 630Sstevel@tonic-gate 64*6247Sraf /* 65*6247Sraf * Internally to libc, we call this function rather than priocntl() 66*6247Sraf * when the cmd is not PC_GETXPARMS or PC_SETXPARMS. We do this 67*6247Sraf * for the sake of calling common code in various places. One of 68*6247Sraf * these places is in spawn() and spawnp(), where we must not call 69*6247Sraf * any function that is exported from libc while in the child of vfork(). 70*6247Sraf */ 71*6247Sraf long 72*6247Sraf _private_priocntl(idtype_t idtype, id_t id, int cmd, void *arg) 73*6247Sraf { 74*6247Sraf extern long _private__priocntlset(int, procset_t *, int, caddr_t, ...); 75*6247Sraf procset_t procset; 76*6247Sraf 77*6247Sraf setprocset(&procset, POP_AND, idtype, id, P_ALL, 0); 78*6247Sraf return (_private__priocntlset(PC_VERSION, &procset, cmd, arg, 0)); 79*6247Sraf } 80*6247Sraf 810Sstevel@tonic-gate 820Sstevel@tonic-gate /*VARARGS3*/ 830Sstevel@tonic-gate long 840Sstevel@tonic-gate priocntl(idtype_t idtype, id_t id, int cmd, ...) 850Sstevel@tonic-gate { 860Sstevel@tonic-gate procset_t procset; 870Sstevel@tonic-gate va_list valist; 880Sstevel@tonic-gate pc_vaparms_t varparms; 890Sstevel@tonic-gate caddr_t arg; 900Sstevel@tonic-gate int error; 910Sstevel@tonic-gate 920Sstevel@tonic-gate setprocset(&procset, POP_AND, idtype, id, P_ALL, 0); 930Sstevel@tonic-gate 940Sstevel@tonic-gate va_start(valist, cmd); 950Sstevel@tonic-gate arg = va_arg(valist, caddr_t); 960Sstevel@tonic-gate 970Sstevel@tonic-gate if (cmd != PC_GETXPARMS && cmd != PC_SETXPARMS) { 980Sstevel@tonic-gate va_end(valist); 990Sstevel@tonic-gate return (__priocntlset(PC_VERSION, &procset, cmd, arg, 0)); 1000Sstevel@tonic-gate } 1010Sstevel@tonic-gate 1020Sstevel@tonic-gate error = pc_vaargs2parms(valist, &varparms); 1030Sstevel@tonic-gate va_end(valist); 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate if (error) { 1060Sstevel@tonic-gate errno = error; 1070Sstevel@tonic-gate return (-1); 1080Sstevel@tonic-gate } 1090Sstevel@tonic-gate 1100Sstevel@tonic-gate return (__priocntlset(PC_VERSION, &procset, cmd, arg, &varparms)); 1110Sstevel@tonic-gate } 1120Sstevel@tonic-gate 1130Sstevel@tonic-gate 1140Sstevel@tonic-gate /*VARARGS2*/ 1150Sstevel@tonic-gate long 1160Sstevel@tonic-gate priocntlset(procset_t *procsetp, int cmd, ...) 1170Sstevel@tonic-gate { 1180Sstevel@tonic-gate va_list valist; 1190Sstevel@tonic-gate pc_vaparms_t varparms; 1200Sstevel@tonic-gate caddr_t arg; 1210Sstevel@tonic-gate int error; 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate va_start(valist, cmd); 1240Sstevel@tonic-gate arg = va_arg(valist, caddr_t); 1250Sstevel@tonic-gate 1260Sstevel@tonic-gate if (cmd != PC_GETXPARMS && cmd != PC_SETXPARMS) { 1270Sstevel@tonic-gate va_end(valist); 1280Sstevel@tonic-gate return (__priocntlset(PC_VERSION, procsetp, cmd, arg, 0)); 1290Sstevel@tonic-gate } 1300Sstevel@tonic-gate 1310Sstevel@tonic-gate error = pc_vaargs2parms(valist, &varparms); 1320Sstevel@tonic-gate va_end(valist); 1330Sstevel@tonic-gate 1340Sstevel@tonic-gate if (error) { 1350Sstevel@tonic-gate errno = error; 1360Sstevel@tonic-gate return (-1); 1370Sstevel@tonic-gate } 1380Sstevel@tonic-gate 1390Sstevel@tonic-gate return (__priocntlset(PC_VERSION, procsetp, cmd, arg, &varparms)); 1400Sstevel@tonic-gate } 1410Sstevel@tonic-gate 1420Sstevel@tonic-gate 1430Sstevel@tonic-gate static int 1440Sstevel@tonic-gate pc_vaargs2parms(va_list valist, pc_vaparms_t *vp) 1450Sstevel@tonic-gate { 1460Sstevel@tonic-gate pc_vaparm_t *vpp = &vp->pc_parms[0]; 1470Sstevel@tonic-gate int key; 1480Sstevel@tonic-gate 1490Sstevel@tonic-gate for (vp->pc_vaparmscnt = 0; 1500Sstevel@tonic-gate (key = va_arg(valist, int)) != PC_KY_NULL; vpp++) { 1510Sstevel@tonic-gate if (++vp->pc_vaparmscnt > PC_VAPARMCNT) 1520Sstevel@tonic-gate return (EINVAL); 1530Sstevel@tonic-gate 1540Sstevel@tonic-gate vpp->pc_key = key; 1550Sstevel@tonic-gate vpp->pc_parm = va_arg(valist, uintptr_t); 1560Sstevel@tonic-gate } 1570Sstevel@tonic-gate 1580Sstevel@tonic-gate return (0); 1590Sstevel@tonic-gate } 160