2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright (c) 1998-2001 by Sun Microsystems, Inc.
2N/A * All rights reserved.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A#include <stdlib.h>
2N/A#include <unistd.h>
2N/A#include <errno.h>
2N/A#include <sys/types.h>
2N/A#include <sys/mman.h>
2N/A#include "libproc.h"
2N/A
2N/A/*
2N/A * memcntl() system call -- executed by subject process
2N/A */
2N/A
2N/Aint
2N/Apr_memcntl(struct ps_prochandle *Pr,
2N/A caddr_t addr, size_t len, int cmd, caddr_t arg, int attr, int mask)
2N/A{
2N/A sysret_t rval; /* return value from memcntl() */
2N/A argdes_t argd[6]; /* arg descriptors for memcntl() */
2N/A argdes_t *adp;
2N/A int error;
2N/A
2N/A if (Pr == NULL) /* no subject process */
2N/A return (memcntl(addr, len, cmd, arg, attr, mask));
2N/A
2N/A adp = &argd[0]; /* addr argument */
2N/A adp->arg_value = (uintptr_t)addr;
2N/A adp->arg_object = NULL;
2N/A adp->arg_type = AT_BYVAL;
2N/A adp->arg_inout = AI_INPUT;
2N/A adp->arg_size = 0;
2N/A
2N/A adp++; /* len argument */
2N/A adp->arg_value = len;
2N/A adp->arg_object = NULL;
2N/A adp->arg_type = AT_BYVAL;
2N/A adp->arg_inout = AI_INPUT;
2N/A adp->arg_size = 0;
2N/A
2N/A adp++; /* cmd argument */
2N/A adp->arg_value = cmd;
2N/A adp->arg_object = NULL;
2N/A adp->arg_type = AT_BYVAL;
2N/A adp->arg_inout = AI_INPUT;
2N/A adp->arg_size = 0;
2N/A
2N/A adp++; /* arg argument */
2N/A if (cmd == MC_HAT_ADVISE) {
2N/A adp->arg_value = 0;
2N/A adp->arg_object = arg;
2N/A adp->arg_type = AT_BYREF;
2N/A adp->arg_inout = AI_INPUT;
2N/A#ifdef _LP64
2N/A if (Pstatus(Pr)->pr_dmodel == PR_MODEL_ILP32)
2N/A adp->arg_size = sizeof (struct memcntl_mha32);
2N/A else
2N/A adp->arg_size = sizeof (struct memcntl_mha);
2N/A#else
2N/A adp->arg_size = sizeof (struct memcntl_mha);
2N/A#endif
2N/A } else {
2N/A adp->arg_value = (uintptr_t)arg;
2N/A adp->arg_object = NULL;
2N/A adp->arg_type = AT_BYVAL;
2N/A adp->arg_inout = AI_INPUT;
2N/A adp->arg_size = 0;
2N/A }
2N/A
2N/A adp++; /* attr argument */
2N/A adp->arg_value = attr;
2N/A adp->arg_object = NULL;
2N/A adp->arg_type = AT_BYVAL;
2N/A adp->arg_inout = AI_INPUT;
2N/A adp->arg_size = 0;
2N/A
2N/A adp++; /* mask argument */
2N/A adp->arg_value = mask;
2N/A adp->arg_object = NULL;
2N/A adp->arg_type = AT_BYVAL;
2N/A adp->arg_inout = AI_INPUT;
2N/A adp->arg_size = 0;
2N/A
2N/A error = Psyscall(Pr, &rval, SYS_memcntl, 6, &argd[0]);
2N/A
2N/A if (error) {
2N/A errno = (error > 0)? error : ENOSYS;
2N/A return (-1);
2N/A }
2N/A return (0);
2N/A}