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 1997-2003 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 #include <sys/isa_defs.h>
     30 
     31 #include <stdlib.h>
     32 #include <unistd.h>
     33 #include <signal.h>
     34 #include <memory.h>
     35 #include <errno.h>
     36 
     37 #include "P32ton.h"
     38 #include "libproc.h"
     39 
     40 /*
     41  * sigaction() system call -- executed by subject process.
     42  */
     43 int
     44 pr_sigaction(struct ps_prochandle *Pr,
     45 	int sig, const struct sigaction *act, struct sigaction *oact)
     46 {
     47 	sysret_t rval;			/* return value from sigaction() */
     48 	argdes_t argd[3];		/* arg descriptors for sigaction() */
     49 	argdes_t *adp;
     50 	int error;
     51 #ifdef _LP64
     52 	struct sigaction32 act32;
     53 	struct sigaction32 oact32;
     54 #endif	/* _LP64 */
     55 
     56 	if (Pr == NULL)		/* no subject process */
     57 		return (sigaction(sig, act, oact));
     58 
     59 	adp = &argd[0];		/* sig argument */
     60 	adp->arg_value = sig;
     61 	adp->arg_object = NULL;
     62 	adp->arg_type = AT_BYVAL;
     63 	adp->arg_inout = AI_INPUT;
     64 	adp->arg_size = 0;
     65 
     66 	adp++;			/* act argument */
     67 	adp->arg_value = 0;
     68 	if (act == NULL) {
     69 		adp->arg_type = AT_BYVAL;
     70 		adp->arg_inout = AI_INPUT;
     71 		adp->arg_object = NULL;
     72 		adp->arg_size = 0;
     73 	} else {
     74 		adp->arg_type = AT_BYREF;
     75 		adp->arg_inout = AI_INPUT;
     76 #ifdef _LP64
     77 		if (Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32) {
     78 			sigaction_n_to_32(act, &act32);
     79 			adp->arg_object = &act32;
     80 			adp->arg_size = sizeof (act32);
     81 		} else {
     82 			adp->arg_object = (void *)act;
     83 			adp->arg_size = sizeof (*act);
     84 		}
     85 #else	/* _LP64 */
     86 		adp->arg_object = (void *)act;
     87 		adp->arg_size = sizeof (*act);
     88 #endif	/* _LP64 */
     89 	}
     90 
     91 	adp++;			/* oact argument */
     92 	adp->arg_value = 0;
     93 	if (oact == NULL) {
     94 		adp->arg_type = AT_BYVAL;
     95 		adp->arg_inout = AI_INPUT;
     96 		adp->arg_object = NULL;
     97 		adp->arg_size = 0;
     98 	} else {
     99 		adp->arg_type = AT_BYREF;
    100 		adp->arg_inout = AI_OUTPUT;
    101 #ifdef _LP64
    102 		if (Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32) {
    103 			adp->arg_object = &oact32;
    104 			adp->arg_size = sizeof (oact32);
    105 		} else {
    106 			adp->arg_object = oact;
    107 			adp->arg_size = sizeof (*oact);
    108 		}
    109 #else	/* _LP64 */
    110 		adp->arg_object = oact;
    111 		adp->arg_size = sizeof (*oact);
    112 #endif	/* _LP64 */
    113 	}
    114 
    115 	error = Psyscall(Pr, &rval, SYS_sigaction, 3, &argd[0]);
    116 
    117 	if (error) {
    118 		errno = (error > 0)? error : ENOSYS;
    119 		return (-1);
    120 	}
    121 #ifdef _LP64
    122 	if (oact != NULL && Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32)
    123 		sigaction_32_to_n(&oact32, oact);
    124 #endif	/* _LP64 */
    125 	return (rval.sys_rval1);
    126 }
    127