/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <limits.h>
#include "libproc.h"
#include "Pcontrol.h"
#include "Pisadep.h"
#include "Putil.h"
/*
* Look for a SYSCALL instruction in the process's address space.
*/
int
{
int mapfd;
uchar_t *p;
/* try the most recently-seen syscall address */
syspri = 0;
sysaddr = 0;
if (P->sysaddr != 0 &&
/* try the previous instruction */
&sysaddr);
return (0);
}
/* open the /proc/<pid>/map file */
procfs_path, (int)P->pid);
return (-1);
}
/* allocate a plausible initial buffer size */
nmap = 50;
/* read all the map structures, allocating more space as needed */
for (;;) {
dprintf("Pscantext: failed to allocate buffer\n");
return (-1);
}
if (nmappings < 0) {
dprintf("Pscantext: failed to read map file: %s\n",
return (-1);
}
break;
/* allocate a bigger buffer */
nmap *= 2;
}
/*
* Scan each executable mapping looking for a syscall instruction.
* In dynamically linked executables, syscall instructions are
* typically only found in shared libraries. Because shared libraries
* are most often mapped at the top of the address space, we minimize
* our expected search time by starting at the last mapping and working
* our way down to the first mapping.
*/
/* avoid non-EXEC mappings; avoid the stack and heap */
continue;
continue;
n2bytes = 0;
else {
}
/* search text for a SYSCALL instruction */
if (nbytes <= 0) { /* shift buffers */
break;
nbytes);
n2bytes = 0;
BLKSIZE);
}
p += sizeof (instr_t);
}
}
return (0);
else
return (-1);
}