Path: blob/master/src/jdk.hotspot.agent/linux/native/libsaproc/libproc_impl.h
41149 views
/*1* Copyright (c) 2003, 2020, 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// .eh_frame data37typedef struct eh_frame_info {38uintptr_t library_base_addr;39uintptr_t v_addr;40unsigned char* data;41int size;42} eh_frame_info;4344// list of shared objects45typedef struct lib_info {46char name[BUF_SIZE];47uintptr_t base;48uintptr_t end;49uintptr_t exec_start;50uintptr_t exec_end;51eh_frame_info eh_frame;52struct symtab* symtab;53int fd; // file descriptor for lib54struct lib_info* next;55} lib_info;5657// list of threads58typedef struct thread_info {59lwpid_t lwp_id;60struct user_regs_struct regs; // not for process, core uses for caching regset61struct thread_info* next;62} thread_info;6364// list of virtual memory maps65typedef struct map_info {66int fd; // file descriptor67off_t offset; // file offset of this mapping68uintptr_t vaddr; // starting virtual address69size_t memsz; // size of the mapping70uint32_t flags; // acces flags71struct map_info* next;72} map_info;7374// vtable for ps_prochandle75typedef struct ps_prochandle_ops {76// "derived class" clean-up77void (*release)(struct ps_prochandle* ph);78// read from debuggee79bool (*p_pread)(struct ps_prochandle *ph,80uintptr_t addr, char *buf, size_t size);81// write into debuggee82bool (*p_pwrite)(struct ps_prochandle *ph,83uintptr_t addr, const char *buf , size_t size);84// get integer regset of a thread85bool (*get_lwp_regs)(struct ps_prochandle* ph, lwpid_t lwp_id, struct user_regs_struct* regs);86} ps_prochandle_ops;8788// the ps_prochandle8990struct core_data {91int core_fd; // file descriptor of core file92int exec_fd; // file descriptor of exec file93int interp_fd; // file descriptor of interpreter (ld-linux.so.2)94// part of the class sharing workaround95int classes_jsa_fd; // file descriptor of class share archive96uintptr_t dynamic_addr; // address of dynamic section of a.out97uintptr_t ld_base_addr; // base address of ld.so98size_t num_maps; // number of maps.99map_info* maps; // maps in a linked list100// part of the class sharing workaround101map_info* class_share_maps;// class share maps in a linked list102map_info** map_array; // sorted (by vaddr) array of map_info pointers103};104105struct ps_prochandle {106ps_prochandle_ops* ops; // vtable ptr107pid_t pid;108int num_libs;109lib_info* libs; // head of lib list110lib_info* lib_tail; // tail of lib list - to append at the end111int num_threads;112thread_info* threads; // head of thread list113struct core_data* core; // data only used for core dumps, NULL for process114};115116#ifdef __cplusplus117extern "C" {118#endif119120int pathmap_open(const char* name);121122void print_debug(const char* format,...);123void print_error(const char* format,...);124bool is_debug();125126// deletes a thread from the thread list127void delete_thread_info(struct ps_prochandle* ph, thread_info* thr);128129// adds a new shared object to lib list, returns NULL on failure130lib_info* add_lib_info(struct ps_prochandle* ph, const char* libname, uintptr_t base);131132// adds a new shared object to lib list, supply open lib file descriptor as well133lib_info* add_lib_info_fd(struct ps_prochandle* ph, const char* libname, int fd,134uintptr_t base);135136// adds a new thread to threads list, returns NULL on failure137thread_info* add_thread_info(struct ps_prochandle* ph, lwpid_t lwp_id);138139// a test for ELF signature without using libelf140bool is_elf_file(int fd);141142#ifdef __cplusplus143}144#endif145146#endif //_LIBPROC_IMPL_H_147148149