dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libproc / common / pr_memcntl.c
blob0b2a306e759eb43bbc9473c442c7963b6306b465
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
23 * Copyright (c) 1998-2001 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <stdlib.h>
30 #include <unistd.h>
31 #include <errno.h>
32 #include <sys/types.h>
33 #include <sys/mman.h>
34 #include "libproc.h"
37 * memcntl() system call -- executed by subject process
40 int
41 pr_memcntl(struct ps_prochandle *Pr,
42 caddr_t addr, size_t len, int cmd, caddr_t arg, int attr, int mask)
44 sysret_t rval; /* return value from memcntl() */
45 argdes_t argd[6]; /* arg descriptors for memcntl() */
46 argdes_t *adp;
47 int error;
49 if (Pr == NULL) /* no subject process */
50 return (memcntl(addr, len, cmd, arg, attr, mask));
52 adp = &argd[0]; /* addr argument */
53 adp->arg_value = (uintptr_t)addr;
54 adp->arg_object = NULL;
55 adp->arg_type = AT_BYVAL;
56 adp->arg_inout = AI_INPUT;
57 adp->arg_size = 0;
59 adp++; /* len argument */
60 adp->arg_value = len;
61 adp->arg_object = NULL;
62 adp->arg_type = AT_BYVAL;
63 adp->arg_inout = AI_INPUT;
64 adp->arg_size = 0;
66 adp++; /* cmd argument */
67 adp->arg_value = cmd;
68 adp->arg_object = NULL;
69 adp->arg_type = AT_BYVAL;
70 adp->arg_inout = AI_INPUT;
71 adp->arg_size = 0;
73 adp++; /* arg argument */
74 if (cmd == MC_HAT_ADVISE) {
75 adp->arg_value = 0;
76 adp->arg_object = arg;
77 adp->arg_type = AT_BYREF;
78 adp->arg_inout = AI_INPUT;
79 #ifdef _LP64
80 if (Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32)
81 adp->arg_size = sizeof (struct memcntl_mha32);
82 else
83 adp->arg_size = sizeof (struct memcntl_mha);
84 #else
85 adp->arg_size = sizeof (struct memcntl_mha);
86 #endif
87 } else {
88 adp->arg_value = (uintptr_t)arg;
89 adp->arg_object = NULL;
90 adp->arg_type = AT_BYVAL;
91 adp->arg_inout = AI_INPUT;
92 adp->arg_size = 0;
95 adp++; /* attr argument */
96 adp->arg_value = attr;
97 adp->arg_object = NULL;
98 adp->arg_type = AT_BYVAL;
99 adp->arg_inout = AI_INPUT;
100 adp->arg_size = 0;
102 adp++; /* mask argument */
103 adp->arg_value = mask;
104 adp->arg_object = NULL;
105 adp->arg_type = AT_BYVAL;
106 adp->arg_inout = AI_INPUT;
107 adp->arg_size = 0;
109 error = Psyscall(Pr, &rval, SYS_memcntl, 6, &argd[0]);
111 if (error) {
112 errno = (error > 0)? error : ENOSYS;
113 return (-1);
115 return (0);