1 /*
2 * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef _LIBPROC_IMPL_H_
26 #define _LIBPROC_IMPL_H_
27
28 #include <unistd.h>
29 #include <limits.h>
30 #include "libproc.h"
31 #include "symtab.h"
32
33 // data structures in this file mimic those of Solaris 8.0 - libproc's Pcontrol.h
34
35 #define BUF_SIZE (PATH_MAX + NAME_MAX + 1)
36
37 // list of shared objects
38 typedef struct lib_info {
39 char name[BUF_SIZE];
40 uintptr_t base;
41 struct symtab* symtab;
42 int fd; // file descriptor for lib
43 struct lib_info* next;
44 } lib_info;
45
46 // list of threads
47 typedef struct thread_info {
48 lwpid_t lwp_id;
49 struct user_regs_struct regs; // not for process, core uses for caching regset
50 struct thread_info* next;
51 } thread_info;
52
53 // list of virtual memory maps
54 typedef struct map_info {
55 int fd; // file descriptor
56 off_t offset; // file offset of this mapping
57 uintptr_t vaddr; // starting virtual address
58 size_t memsz; // size of the mapping
59 struct map_info* next;
60 } map_info;
84 uintptr_t dynamic_addr; // address of dynamic section of a.out
85 uintptr_t ld_base_addr; // base address of ld.so
86 size_t num_maps; // number of maps.
87 map_info* maps; // maps in a linked list
88 // part of the class sharing workaround
89 map_info* class_share_maps;// class share maps in a linked list
90 map_info** map_array; // sorted (by vaddr) array of map_info pointers
91 };
92
93 struct ps_prochandle {
94 ps_prochandle_ops* ops; // vtable ptr
95 pid_t pid;
96 int num_libs;
97 lib_info* libs; // head of lib list
98 lib_info* lib_tail; // tail of lib list - to append at the end
99 int num_threads;
100 thread_info* threads; // head of thread list
101 struct core_data* core; // data only used for core dumps, NULL for process
102 };
103
104 int pathmap_open(const char* name);
105
106 void print_debug(const char* format,...);
107 void print_error(const char* format,...);
108 bool is_debug();
109
110 // deletes a thread from the thread list
111 void delete_thread_info(struct ps_prochandle* ph, thread_info* thr);
112
113 // adds a new shared object to lib list, returns NULL on failure
114 lib_info* add_lib_info(struct ps_prochandle* ph, const char* libname, uintptr_t base);
115
116 // adds a new shared object to lib list, supply open lib file descriptor as well
117 lib_info* add_lib_info_fd(struct ps_prochandle* ph, const char* libname, int fd,
118 uintptr_t base);
119
120 // adds a new thread to threads list, returns NULL on failure
121 thread_info* add_thread_info(struct ps_prochandle* ph, lwpid_t lwp_id);
122
123 // a test for ELF signature without using libelf
124 bool is_elf_file(int fd);
125
126 #endif //_LIBPROC_IMPL_H_
|
1 /*
2 * Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef _LIBPROC_IMPL_H_
26 #define _LIBPROC_IMPL_H_
27
28 #include <unistd.h>
29 #include <limits.h>
30 #include "libproc.h"
31 #include "symtab.h"
32
33 // data structures in this file mimic those of Solaris 8.0 - libproc's Pcontrol.h
34
35 #define BUF_SIZE (PATH_MAX + NAME_MAX + 1)
36
37 // .eh_frame data
38 typedef struct eh_frame_info {
39 uintptr_t library_base_addr;
40 uintptr_t v_addr;
41 unsigned char* data;
42 } eh_frame_info;
43
44 // list of shared objects
45 typedef struct lib_info {
46 char name[BUF_SIZE];
47 uintptr_t base;
48 uintptr_t exec_start;
49 uintptr_t exec_end;
50 eh_frame_info eh_frame;
51 struct symtab* symtab;
52 int fd; // file descriptor for lib
53 struct lib_info* next;
54 } lib_info;
55
56 // list of threads
57 typedef struct thread_info {
58 lwpid_t lwp_id;
59 struct user_regs_struct regs; // not for process, core uses for caching regset
60 struct thread_info* next;
61 } thread_info;
62
63 // list of virtual memory maps
64 typedef struct map_info {
65 int fd; // file descriptor
66 off_t offset; // file offset of this mapping
67 uintptr_t vaddr; // starting virtual address
68 size_t memsz; // size of the mapping
69 struct map_info* next;
70 } map_info;
94 uintptr_t dynamic_addr; // address of dynamic section of a.out
95 uintptr_t ld_base_addr; // base address of ld.so
96 size_t num_maps; // number of maps.
97 map_info* maps; // maps in a linked list
98 // part of the class sharing workaround
99 map_info* class_share_maps;// class share maps in a linked list
100 map_info** map_array; // sorted (by vaddr) array of map_info pointers
101 };
102
103 struct ps_prochandle {
104 ps_prochandle_ops* ops; // vtable ptr
105 pid_t pid;
106 int num_libs;
107 lib_info* libs; // head of lib list
108 lib_info* lib_tail; // tail of lib list - to append at the end
109 int num_threads;
110 thread_info* threads; // head of thread list
111 struct core_data* core; // data only used for core dumps, NULL for process
112 };
113
114 #ifdef __cplusplus
115 extern "C" {
116 #endif
117
118 int pathmap_open(const char* name);
119
120 void print_debug(const char* format,...);
121 void print_error(const char* format,...);
122 bool is_debug();
123
124 // deletes a thread from the thread list
125 void delete_thread_info(struct ps_prochandle* ph, thread_info* thr);
126
127 // adds a new shared object to lib list, returns NULL on failure
128 lib_info* add_lib_info(struct ps_prochandle* ph, const char* libname, uintptr_t base);
129
130 // adds a new shared object to lib list, supply open lib file descriptor as well
131 lib_info* add_lib_info_fd(struct ps_prochandle* ph, const char* libname, int fd,
132 uintptr_t base);
133
134 // adds a new thread to threads list, returns NULL on failure
135 thread_info* add_thread_info(struct ps_prochandle* ph, lwpid_t lwp_id);
136
137 // a test for ELF signature without using libelf
138 bool is_elf_file(int fd);
139
140 #ifdef __cplusplus
141 }
142 #endif
143
144 #endif //_LIBPROC_IMPL_H_
|