/*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
*
* - Neither the name of Oracle nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This source code is provided to illustrate the usage of a given feature
* or technique and has been deliberately simplified. Additional steps
* required for a production-quality application, such as security checks,
* input validation and proper error handling, might not be present in
* this sample code.
*/
#include <fcntl.h>
#if !defined(LINUX) && !defined(_ALLBSD_SOURCE)
#include <procfs.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <dlfcn.h>
#include <netdb.h>
#include <time.h>
#include "jni.h"
#include "jvm_md.h"
#include "hprof.h"
int
md_getpid(void)
{
if ( pid >= 0 ) {
return pid;
}
return pid;
}
void
{
}
void
md_init(void)
{
#if defined(LINUX) || defined(_ALLBSD_SOURCE)
/* No Hi-Res timer option? */
#else
if ( gdata->micro_state_accounting ) {
char proc_ctl_fn[48];
int procfd;
/* Turn on micro state accounting, once per process */
if (procfd >= 0) {
long ctl_op[2];
}
}
#endif
}
int
{
struct sockaddr_in s;
int fd;
/* create a socket */
/* find remote host's addr from name */
return -1;
}
(void)memset((char *)&s, 0, sizeof(s));
/* set remote host's addr; its already in network byte order */
/* set remote host's port */
s.sin_family = AF_INET;
/* now try connecting */
return 0;
}
return fd;
}
int
{
}
int
{
}
int
{
}
int
{
}
int
{
}
int
{
}
{
} else {
}
return new_pos;
}
void
{
}
int
{
int res;
do {
return res;
}
int
{
int res;
do {
return res;
}
int
{
int res;
do {
return res;
}
/* Time of day in milli-seconds */
static jlong
md_timeofday(void)
{
if ( gettimeofday(&tv, (void *)0) != 0 ) {
return (jlong)0; /* EOVERFLOW ? */
}
/*LINTED*/
}
/* Hi-res timer in micro-seconds */
md_get_microsecs(void)
{
#if defined(LINUX) || defined(_ALLBSD_SOURCE)
#else
#endif
}
/* Time of day in milli-seconds */
md_get_timemillis(void)
{
return md_timeofday();
}
/* Current CPU hi-res CPU time used */
{
#if defined(LINUX) || defined(_ALLBSD_SOURCE)
return md_timeofday();
#else
#endif
}
void
{
void *addr;
libdir[0] = 0;
#if defined(LINUX) || defined(_ALLBSD_SOURCE)
addr = (void*)&Agent_OnLoad;
#else
/* Just using &Agent_OnLoad will get the first external symbol with
* this name in the first .so, which may not be libhprof.so.
* On Solaris we can actually ask for the address of our Agent_OnLoad.
*/
/* Just in case the above didn't work (missing linker patch?). */
addr = (void*)&Agent_OnLoad;
}
#endif
/* Use dladdr() to get the full path to libhprof.so, which we use to find
* the prelude file.
*/
char * lastSlash;
/* Full path to library name, need to move up one directory to 'lib' */
*lastSlash = '\0';
}
#ifndef __APPLE__
// not sure why other platforms have to go up two levels, but on macos we only need up one
*lastSlash = '\0';
}
#endif /* __APPLE__ */
}
}
int
{
}
int
{
int ret;
return ret;
}
void
{
char *p;
buf[0] = 0;
if ( p != NULL ) {
}
}
unsigned
md_htons(unsigned short s)
{
return htons(s);
}
unsigned
md_htonl(unsigned l)
{
return htonl(l);
}
unsigned
md_ntohs(unsigned short s)
{
return ntohs(s);
}
unsigned
md_ntohl(unsigned l)
{
return ntohl(l);
}
// Loosely based on os_solaris.cpp
if (p == NULL) {
}
/* check for NULL path */
if (p == pathname) {
continue;
}
break;
}
pathname = p + 1;
*buffer = '\0';
}
}
/* Create the actual fill filename for a dynamic library. */
void
{
int pnamelen;
/* Length of options directory location. */
*holder = '\0';
/* Quietly truncate on buffer overflow. Should be an error. */
return;
}
/* Construct path to library */
if (pnamelen == 0) {
} else {
}
}
/* Load this library (return NULL on error, and error message in err_buf) */
void *
{
void * result;
}
return result;
}
/* Unload this library */
void
{
}
/* Find an entry point inside this library (return NULL if not found) */
void *
{
void * sym;
return sym;
}