xref: /titanic_41/usr/src/lib/efcode/fcdriver/ioctl.c (revision 03831d35f7499c87d51205817c93e9a8d42c4bae)
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 (c) 2000 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <sys/stat.h>
30 #include <fcntl.h>
31 #include <unistd.h>
32 #include <stdlib.h>
33 #include <stdio.h>
34 #include <strings.h>
35 #include <fcntl.h>
36 #include <stdarg.h>
37 #include <errno.h>
38 
39 #include <fcode/private.h>
40 #include <fcode/log.h>
41 
42 #include <fcdriver/fcdriver.h>
43 
44 #define	FCC_MAX_CELLS	10
45 
46 int
47 fc_run_priv(common_data_t *cdp, char *service, int nin, int nout, ...)
48 {
49 	va_list ap;
50 	int i, error, no_err;
51 	fc_cell_t fc_req[FCC_FIXED_CELLS+FCC_MAX_CELLS];
52 	struct fc_client_interface *cip = (struct fc_client_interface *)fc_req;
53 	fc_cell_t *fcp;
54 	char *error_msg;
55 
56 	no_err = nin & FCRP_NOERROR;
57 	nin &= ~FCRP_NOERROR;
58 
59 	bzero(fc_req, sizeof (fc_req));
60 	if (nin + nout > FCC_MAX_CELLS) {
61 		log_message(MSG_ERROR, "%s: too many ins (%d) and outs (%d)\n",
62 		    service, nin, nout);
63 		nin = min(nin, FCC_MAX_CELLS);
64 		nout = FCC_MAX_CELLS - nin;
65 	}
66 	va_start(ap, nout);
67 	cip->svc_name = fc_ptr2cell(service);
68 	cip->nargs = fc_int2cell(nin);
69 	cip->nresults = fc_int2cell(nout);
70 	for (i = 0; i < nin; i++)
71 		fc_arg(cip, i) = va_arg(ap, fc_cell_t);
72 	error = ioctl(cdp->fcode_fd, FC_RUN_PRIV, cip);
73 	for (i = 0; i < nout; i++) {
74 		fcp = va_arg(ap, fc_cell_t *);
75 		*fcp = fc_result(cip, i);
76 	}
77 	va_end(ap);
78 
79 	if (error)
80 		error_msg = strerror(errno);
81 	else if (cip->priv_error) {
82 		error_msg = "Priv violation";
83 		error = 1;
84 	} else if (cip->error) {
85 		error_msg = "Error";
86 		error = 1;
87 	}
88 	if ((error & !no_err) ||
89 	    (get_interpreter_debug_level() & DEBUG_REG_ACCESS)) {
90 		if (error)
91 			log_message(MSG_ERROR, "%s: FC_RUN_PRIV: %s: ",
92 			    cdp->Progname, error_msg);
93 		log_message(MSG_ERROR, "%s ( ", service);
94 		for (i = 0; i < nin; i++)
95 			log_message(MSG_ERROR, "%llx ",
96 			    (uint64_t)fc_arg(cip, i));
97 		log_message(MSG_ERROR, ")");
98 		if (error)
99 			;
100 		else if (nout) {
101 			log_message(MSG_ERROR, " ->");
102 			for (i = 0; i < nout; i++)
103 				log_message(MSG_ERROR, " %llx",
104 				    (uint64_t)fc_result(cip, i));
105 		} else
106 			log_message(MSG_ERROR, " OK");
107 		log_message(MSG_ERROR, "\n");
108 	}
109 	return (error);
110 }
111