xref: /illumos-gate/usr/src/lib/libproc/common/pr_memcntl.c (revision 533affcbc7fc4d0c8132976ea454aaa715fe2307)
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) 1998-2001 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <errno.h>
30 #include <sys/types.h>
31 #include <sys/mman.h>
32 #include "libproc.h"
33 
34 /*
35  * memcntl() system call -- executed by subject process
36  */
37 
38 int
39 pr_memcntl(struct ps_prochandle *Pr,
40 	caddr_t addr, size_t len, int cmd, caddr_t arg, int attr, int mask)
41 {
42 	sysret_t rval;			/* return value from memcntl() */
43 	argdes_t argd[6];		/* arg descriptors for memcntl() */
44 	argdes_t *adp;
45 	int error;
46 
47 	if (Pr == NULL)		/* no subject process */
48 		return (memcntl(addr, len, cmd, arg, attr, mask));
49 
50 	adp = &argd[0];		/* addr argument */
51 	adp->arg_value = (uintptr_t)addr;
52 	adp->arg_object = NULL;
53 	adp->arg_type = AT_BYVAL;
54 	adp->arg_inout = AI_INPUT;
55 	adp->arg_size = 0;
56 
57 	adp++;			/* len argument */
58 	adp->arg_value = len;
59 	adp->arg_object = NULL;
60 	adp->arg_type = AT_BYVAL;
61 	adp->arg_inout = AI_INPUT;
62 	adp->arg_size = 0;
63 
64 	adp++;			/* cmd argument */
65 	adp->arg_value = cmd;
66 	adp->arg_object = NULL;
67 	adp->arg_type = AT_BYVAL;
68 	adp->arg_inout = AI_INPUT;
69 	adp->arg_size = 0;
70 
71 	adp++;			/* arg argument */
72 	if (cmd == MC_HAT_ADVISE) {
73 		adp->arg_value = 0;
74 		adp->arg_object = arg;
75 		adp->arg_type = AT_BYREF;
76 		adp->arg_inout = AI_INPUT;
77 #ifdef _LP64
78 		if (Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32)
79 			adp->arg_size = sizeof (struct memcntl_mha32);
80 		else
81 			adp->arg_size = sizeof (struct memcntl_mha);
82 #else
83 		adp->arg_size = sizeof (struct memcntl_mha);
84 #endif
85 	} else {
86 		adp->arg_value = (uintptr_t)arg;
87 		adp->arg_object = NULL;
88 		adp->arg_type = AT_BYVAL;
89 		adp->arg_inout = AI_INPUT;
90 		adp->arg_size = 0;
91 	}
92 
93 	adp++;			/* attr argument */
94 	adp->arg_value = attr;
95 	adp->arg_object = NULL;
96 	adp->arg_type = AT_BYVAL;
97 	adp->arg_inout = AI_INPUT;
98 	adp->arg_size = 0;
99 
100 	adp++;			/* mask argument */
101 	adp->arg_value = mask;
102 	adp->arg_object = NULL;
103 	adp->arg_type = AT_BYVAL;
104 	adp->arg_inout = AI_INPUT;
105 	adp->arg_size = 0;
106 
107 	error = Psyscall(Pr, &rval, SYS_memcntl, 6, &argd[0]);
108 
109 	if (error) {
110 		errno = (error > 0)? error : ENOSYS;
111 		return (-1);
112 	}
113 	return (0);
114 }
115