Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/agent/src/os/linux/libproc_impl.h
38833 views
/*1* Copyright (c) 2003, 2019, 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_IMPL_H_25#define _LIBPROC_IMPL_H_2627#include <unistd.h>28#include <limits.h>29#include "libproc.h"30#include "symtab.h"3132// data structures in this file mimic those of Solaris 8.0 - libproc's Pcontrol.h3334#define BUF_SIZE (PATH_MAX + NAME_MAX + 1)3536// list of shared objects37typedef struct lib_info {38char name[BUF_SIZE];39uintptr_t base;40struct symtab* symtab;41int fd; // file descriptor for lib42struct lib_info* next;43} lib_info;4445// list of threads46typedef struct thread_info {47lwpid_t lwp_id;48pthread_t pthread_id; // not used cores, always -149struct user_regs_struct regs; // not for process, core uses for caching regset50struct thread_info* next;51} thread_info;5253// list of virtual memory maps54typedef struct map_info {55int fd; // file descriptor56off_t offset; // file offset of this mapping57uintptr_t vaddr; // starting virtual address58size_t memsz; // size of the mapping59struct map_info* next;60} map_info;6162// vtable for ps_prochandle63typedef struct ps_prochandle_ops {64// "derived class" clean-up65void (*release)(struct ps_prochandle* ph);66// read from debuggee67bool (*p_pread)(struct ps_prochandle *ph,68uintptr_t addr, char *buf, size_t size);69// write into debuggee70bool (*p_pwrite)(struct ps_prochandle *ph,71uintptr_t addr, const char *buf , size_t size);72// get integer regset of a thread73bool (*get_lwp_regs)(struct ps_prochandle* ph, lwpid_t lwp_id, struct user_regs_struct* regs);74} ps_prochandle_ops;7576// the ps_prochandle7778struct core_data {79int core_fd; // file descriptor of core file80int exec_fd; // file descriptor of exec file81int interp_fd; // file descriptor of interpreter (ld-linux.so.2)82// part of the class sharing workaround83int classes_jsa_fd; // file descriptor of class share archive84uintptr_t dynamic_addr; // address of dynamic section of a.out85uintptr_t ld_base_addr; // base address of ld.so86size_t num_maps; // number of maps.87map_info* maps; // maps in a linked list88// part of the class sharing workaround89map_info* class_share_maps;// class share maps in a linked list90map_info** map_array; // sorted (by vaddr) array of map_info pointers91};9293struct ps_prochandle {94ps_prochandle_ops* ops; // vtable ptr95pid_t pid;96int num_libs;97lib_info* libs; // head of lib list98lib_info* lib_tail; // tail of lib list - to append at the end99int num_threads;100thread_info* threads; // head of thread list101struct core_data* core; // data only used for core dumps, NULL for process102};103104int pathmap_open(const char* name);105106void print_debug(const char* format,...);107void print_error(const char* format,...);108bool is_debug();109110typedef bool (*thread_info_callback)(struct ps_prochandle* ph, pthread_t pid, lwpid_t lwpid);111112// reads thread info using libthread_db and calls above callback for each thread113bool read_thread_info(struct ps_prochandle* ph, thread_info_callback cb);114115// deletes a thread from the thread list116void delete_thread_info(struct ps_prochandle* ph, thread_info* thr);117118// adds a new shared object to lib list, returns NULL on failure119lib_info* add_lib_info(struct ps_prochandle* ph, const char* libname, uintptr_t base);120121// adds a new shared object to lib list, supply open lib file descriptor as well122lib_info* add_lib_info_fd(struct ps_prochandle* ph, const char* libname, int fd,123uintptr_t base);124125// adds a new thread to threads list, returns NULL on failure126thread_info* add_thread_info(struct ps_prochandle* ph, pthread_t pthread_id, lwpid_t lwp_id);127128// a test for ELF signature without using libelf129bool is_elf_file(int fd);130131#endif //_LIBPROC_IMPL_H_132133134