Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/agent/src/os/bsd/libproc.h
38833 views
/*1* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef _LIBPROC_H_25#define _LIBPROC_H_2627#include <unistd.h>28#include <stdint.h>29#include <stdarg.h>30#include <stdio.h>31#include <stdlib.h>32#include <string.h>33#include <fcntl.h>3435#ifdef __APPLE__36typedef enum ps_err_e {37PS_OK, PS_ERR, PS_BADPID, PS_BADLID,38PS_BADADDR, PS_NOSYM, PS_NOFREGS39} ps_err_e;4041#ifndef psaddr_t42#define psaddr_t uintptr_t43#endif4445#ifndef bool46typedef int bool;47#define true 148#define false 049#endif // bool5051#ifndef lwpid_t52#define lwpid_t uintptr_t53#endif5455#include <mach/thread_status.h>56#else // __APPLE__57#include <elf.h>58#include <link.h>59#include <machine/reg.h>60#include <proc_service.h>61#if defined(sparc) || defined(sparcv9)62/*63If _LP64 is defined ptrace.h should be taken from /usr/include/asm-sparc6464otherwise it should be from /usr/include/asm-sparc65These two files define pt_regs structure differently66*/67#ifdef _LP6468#include "asm-sparc64/ptrace.h"69#else70#include "asm-sparc/ptrace.h"71#endif7273#endif //sparc or sparcv97475// This C bool type must be int for compatibility with BSD calls and76// it would be a mistake to equivalence it to C++ bool on many platforms77typedef int bool;78#define true 179#define false 08081#endif // __APPLE__8283/************************************************************************************84850. This is very minimal subset of Solaris libproc just enough for current application.86Please note that the bulk of the functionality is from proc_service interface. This87adds Pgrab__ and some missing stuff. We hide the difference b/w live process and core88file by this interface.89901. pthread_id is unique. We store this in OSThread::_pthread_id in JVM code.91922. All threads see the same pid when they call getpid().93We used to save the result of ::getpid() call in OSThread::_thread_id.94Because gettid returns actual pid of thread (lwp id), this is95unique again. We therefore use OSThread::_thread_id as unique identifier.96973. There is a unique LWP id under both thread libraries. libthread_db maps pthread_id98to its underlying lwp_id under both the thread libraries. thread_info.lwp_id stores99lwp_id of the thread. The lwp id is nothing but the actual pid of clone'd processes. But100unfortunately libthread_db does not work very well for core dumps. So, we get pthread_id101only for processes. For core dumps, we don't use libthread_db at all (like gdb).1021034. ptrace operates on this LWP id under both the thread libraries. When we say 'pid' for104ptrace call, we refer to lwp_id of the thread.1051065. for core file, we parse ELF files and read data from them. For processes we use107combination of ptrace and /proc calls.108109*************************************************************************************/110111struct reg;112struct ps_prochandle;113114// attach to a process115struct ps_prochandle* Pgrab(pid_t pid);116117// attach to a core dump118struct ps_prochandle* Pgrab_core(const char* execfile, const char* corefile);119120// release a process or core121void Prelease(struct ps_prochandle* ph);122123// functions not directly available in Solaris libproc124125// initialize libproc (call this only once per app)126// pass true to make library verbose127bool init_libproc(bool verbose);128129// get number of threads130int get_num_threads(struct ps_prochandle* ph);131132// get lwp_id of n'th thread133lwpid_t get_lwp_id(struct ps_prochandle* ph, int index);134135// get regs for a given lwp136bool get_lwp_regs(struct ps_prochandle* ph, lwpid_t lid, struct reg* regs);137138// get number of shared objects139int get_num_libs(struct ps_prochandle* ph);140141// get name of n'th lib142const char* get_lib_name(struct ps_prochandle* ph, int index);143144// get base of lib145uintptr_t get_lib_base(struct ps_prochandle* ph, int index);146147// returns true if given library is found in lib list148bool find_lib(struct ps_prochandle* ph, const char *lib_name);149150// symbol lookup151uintptr_t lookup_symbol(struct ps_prochandle* ph, const char* object_name,152const char* sym_name);153154// address->nearest symbol lookup. return NULL for no symbol155const char* symbol_for_pc(struct ps_prochandle* ph, uintptr_t addr, uintptr_t* poffset);156157#endif //__LIBPROC_H_158159160