Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/agent/src/os/linux/libproc.h
38833 views
/*1* Copyright (c) 2003, 2015, 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 <jni.h>28#include <unistd.h>29#include <stdint.h>30#include "proc_service.h"3132#ifdef ALT_SASRCDIR33#include "libproc_md.h"34#endif3536#include <sys/ptrace.h>3738#if defined(aarch64)39#include "asm/ptrace.h"40#endif4142/************************************************************************************43440. This is very minimal subset of Solaris libproc just enough for current application.45Please note that the bulk of the functionality is from proc_service interface. This46adds Pgrab__ and some missing stuff. We hide the difference b/w live process and core47file by this interface.48491. pthread_id unique in both NPTL & LinuxThreads. We store this in50OSThread::_pthread_id in JVM code.51522. All threads see the same pid when they call getpid() under NPTL.53Threads receive different pid under LinuxThreads. We used to save the result of54::getpid() call in OSThread::_thread_id. This way uniqueness of OSThread::_thread_id55was lost under NPTL. Now, we store the result of ::gettid() call in56OSThread::_thread_id. Because gettid returns actual pid of thread (lwp id), this is57unique again. We therefore use OSThread::_thread_id as unique identifier.58593. There is a unique LWP id under both thread libraries. libthread_db maps pthread_id60to its underlying lwp_id under both the thread libraries. thread_info.lwp_id stores61lwp_id of the thread. The lwp id is nothing but the actual pid of clone'd processes. But62unfortunately libthread_db does not work very well for core dumps. So, we get pthread_id63only for processes. For core dumps, we don't use libthread_db at all (like gdb).64654. ptrace operates on this LWP id under both the thread libraries. When we say 'pid' for66ptrace call, we refer to lwp_id of the thread.67685. for core file, we parse ELF files and read data from them. For processes we use69combination of ptrace and /proc calls.7071*************************************************************************************/727374#if defined(sparc) || defined(sparcv9) || defined(ppc64)75#include <asm/ptrace.h>76#define user_regs_struct pt_regs77#endif78#if defined(aarch64)79#define user_regs_struct user_pt_regs80#endif8182// This C bool type must be int for compatibility with Linux calls and83// it would be a mistake to equivalence it to C++ bool on many platforms8485typedef int bool;86#define true 187#define false 08889struct ps_prochandle;9091// attach to a process92struct ps_prochandle* Pgrab(pid_t pid, char* err_buf, size_t err_buf_len);9394// attach to a core dump95struct ps_prochandle* Pgrab_core(const char* execfile, const char* corefile);9697// release a process or core98void Prelease(struct ps_prochandle* ph);99100// functions not directly available in Solaris libproc101102// initialize libproc (call this only once per app)103// pass true to make library verbose104bool init_libproc(bool verbose);105106// get number of threads107int get_num_threads(struct ps_prochandle* ph);108109// get lwp_id of n'th thread110lwpid_t get_lwp_id(struct ps_prochandle* ph, int index);111112// get regs for a given lwp113bool get_lwp_regs(struct ps_prochandle* ph, lwpid_t lid, struct user_regs_struct* regs);114115// get number of shared objects116int get_num_libs(struct ps_prochandle* ph);117118// get name of n'th lib119const char* get_lib_name(struct ps_prochandle* ph, int index);120121// get base of lib122uintptr_t get_lib_base(struct ps_prochandle* ph, int index);123124// returns true if given library is found in lib list125bool find_lib(struct ps_prochandle* ph, const char *lib_name);126127// symbol lookup128uintptr_t lookup_symbol(struct ps_prochandle* ph, const char* object_name,129const char* sym_name);130131// address->nearest symbol lookup. return NULL for no symbol132const char* symbol_for_pc(struct ps_prochandle* ph, uintptr_t addr, uintptr_t* poffset);133134struct ps_prochandle* get_proc_handle(JNIEnv* env, jobject this_obj);135136void throw_new_debugger_exception(JNIEnv* env, const char* errMsg);137138#endif //__LIBPROC_H_139140141