annotate agent/src/os/linux/libproc_impl.h @ 8058:2394a89e89f4

8008088: SA can hang the VM Reviewed-by: mgronlun, sla, dholmes
author rbackman
date Wed, 13 Feb 2013 09:46:19 +0100
parents c18cbe5936b8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
8058
2394a89e89f4 8008088: SA can hang the VM
rbackman
parents: 1552
diff changeset
2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 #ifndef _LIBPROC_IMPL_H_
a61af66fc99e Initial load
duke
parents:
diff changeset
26 #define _LIBPROC_IMPL_H_
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 #include <unistd.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
29 #include <limits.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
30 #include "libproc.h"
a61af66fc99e Initial load
duke
parents:
diff changeset
31 #include "symtab.h"
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // data structures in this file mimic those of Solaris 8.0 - libproc's Pcontrol.h
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 #define BUF_SIZE (PATH_MAX + NAME_MAX + 1)
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
37 // list of shared objects
a61af66fc99e Initial load
duke
parents:
diff changeset
38 typedef struct lib_info {
a61af66fc99e Initial load
duke
parents:
diff changeset
39 char name[BUF_SIZE];
a61af66fc99e Initial load
duke
parents:
diff changeset
40 uintptr_t base;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 struct symtab* symtab;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 int fd; // file descriptor for lib
a61af66fc99e Initial load
duke
parents:
diff changeset
43 struct lib_info* next;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 } lib_info;
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // list of threads
a61af66fc99e Initial load
duke
parents:
diff changeset
47 typedef struct thread_info {
a61af66fc99e Initial load
duke
parents:
diff changeset
48 lwpid_t lwp_id;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 pthread_t pthread_id; // not used cores, always -1
a61af66fc99e Initial load
duke
parents:
diff changeset
50 struct user_regs_struct regs; // not for process, core uses for caching regset
a61af66fc99e Initial load
duke
parents:
diff changeset
51 struct thread_info* next;
a61af66fc99e Initial load
duke
parents:
diff changeset
52 } thread_info;
a61af66fc99e Initial load
duke
parents:
diff changeset
53
a61af66fc99e Initial load
duke
parents:
diff changeset
54 // list of virtual memory maps
a61af66fc99e Initial load
duke
parents:
diff changeset
55 typedef struct map_info {
a61af66fc99e Initial load
duke
parents:
diff changeset
56 int fd; // file descriptor
a61af66fc99e Initial load
duke
parents:
diff changeset
57 off_t offset; // file offset of this mapping
a61af66fc99e Initial load
duke
parents:
diff changeset
58 uintptr_t vaddr; // starting virtual address
a61af66fc99e Initial load
duke
parents:
diff changeset
59 size_t memsz; // size of the mapping
a61af66fc99e Initial load
duke
parents:
diff changeset
60 struct map_info* next;
a61af66fc99e Initial load
duke
parents:
diff changeset
61 } map_info;
a61af66fc99e Initial load
duke
parents:
diff changeset
62
a61af66fc99e Initial load
duke
parents:
diff changeset
63 // vtable for ps_prochandle
a61af66fc99e Initial load
duke
parents:
diff changeset
64 typedef struct ps_prochandle_ops {
a61af66fc99e Initial load
duke
parents:
diff changeset
65 // "derived class" clean-up
a61af66fc99e Initial load
duke
parents:
diff changeset
66 void (*release)(struct ps_prochandle* ph);
a61af66fc99e Initial load
duke
parents:
diff changeset
67 // read from debuggee
a61af66fc99e Initial load
duke
parents:
diff changeset
68 bool (*p_pread)(struct ps_prochandle *ph,
a61af66fc99e Initial load
duke
parents:
diff changeset
69 uintptr_t addr, char *buf, size_t size);
a61af66fc99e Initial load
duke
parents:
diff changeset
70 // write into debuggee
a61af66fc99e Initial load
duke
parents:
diff changeset
71 bool (*p_pwrite)(struct ps_prochandle *ph,
a61af66fc99e Initial load
duke
parents:
diff changeset
72 uintptr_t addr, const char *buf , size_t size);
a61af66fc99e Initial load
duke
parents:
diff changeset
73 // get integer regset of a thread
a61af66fc99e Initial load
duke
parents:
diff changeset
74 bool (*get_lwp_regs)(struct ps_prochandle* ph, lwpid_t lwp_id, struct user_regs_struct* regs);
a61af66fc99e Initial load
duke
parents:
diff changeset
75 } ps_prochandle_ops;
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77 // the ps_prochandle
a61af66fc99e Initial load
duke
parents:
diff changeset
78
a61af66fc99e Initial load
duke
parents:
diff changeset
79 struct core_data {
a61af66fc99e Initial load
duke
parents:
diff changeset
80 int core_fd; // file descriptor of core file
a61af66fc99e Initial load
duke
parents:
diff changeset
81 int exec_fd; // file descriptor of exec file
a61af66fc99e Initial load
duke
parents:
diff changeset
82 int interp_fd; // file descriptor of interpreter (ld-linux.so.2)
a61af66fc99e Initial load
duke
parents:
diff changeset
83 // part of the class sharing workaround
a61af66fc99e Initial load
duke
parents:
diff changeset
84 int classes_jsa_fd; // file descriptor of class share archive
a61af66fc99e Initial load
duke
parents:
diff changeset
85 uintptr_t dynamic_addr; // address of dynamic section of a.out
a61af66fc99e Initial load
duke
parents:
diff changeset
86 uintptr_t ld_base_addr; // base address of ld.so
a61af66fc99e Initial load
duke
parents:
diff changeset
87 size_t num_maps; // number of maps.
a61af66fc99e Initial load
duke
parents:
diff changeset
88 map_info* maps; // maps in a linked list
a61af66fc99e Initial load
duke
parents:
diff changeset
89 // part of the class sharing workaround
a61af66fc99e Initial load
duke
parents:
diff changeset
90 map_info* class_share_maps;// class share maps in a linked list
a61af66fc99e Initial load
duke
parents:
diff changeset
91 map_info** map_array; // sorted (by vaddr) array of map_info pointers
a61af66fc99e Initial load
duke
parents:
diff changeset
92 };
a61af66fc99e Initial load
duke
parents:
diff changeset
93
a61af66fc99e Initial load
duke
parents:
diff changeset
94 struct ps_prochandle {
a61af66fc99e Initial load
duke
parents:
diff changeset
95 ps_prochandle_ops* ops; // vtable ptr
a61af66fc99e Initial load
duke
parents:
diff changeset
96 pid_t pid;
a61af66fc99e Initial load
duke
parents:
diff changeset
97 int num_libs;
a61af66fc99e Initial load
duke
parents:
diff changeset
98 lib_info* libs; // head of lib list
a61af66fc99e Initial load
duke
parents:
diff changeset
99 lib_info* lib_tail; // tail of lib list - to append at the end
a61af66fc99e Initial load
duke
parents:
diff changeset
100 int num_threads;
a61af66fc99e Initial load
duke
parents:
diff changeset
101 thread_info* threads; // head of thread list
a61af66fc99e Initial load
duke
parents:
diff changeset
102 struct core_data* core; // data only used for core dumps, NULL for process
a61af66fc99e Initial load
duke
parents:
diff changeset
103 };
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 int pathmap_open(const char* name);
a61af66fc99e Initial load
duke
parents:
diff changeset
106
a61af66fc99e Initial load
duke
parents:
diff changeset
107 void print_debug(const char* format,...);
8058
2394a89e89f4 8008088: SA can hang the VM
rbackman
parents: 1552
diff changeset
108 void print_error(const char* format,...);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
109 bool is_debug();
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 typedef bool (*thread_info_callback)(struct ps_prochandle* ph, pthread_t pid, lwpid_t lwpid);
a61af66fc99e Initial load
duke
parents:
diff changeset
112
a61af66fc99e Initial load
duke
parents:
diff changeset
113 // reads thread info using libthread_db and calls above callback for each thread
a61af66fc99e Initial load
duke
parents:
diff changeset
114 bool read_thread_info(struct ps_prochandle* ph, thread_info_callback cb);
a61af66fc99e Initial load
duke
parents:
diff changeset
115
a61af66fc99e Initial load
duke
parents:
diff changeset
116 // adds a new shared object to lib list, returns NULL on failure
a61af66fc99e Initial load
duke
parents:
diff changeset
117 lib_info* add_lib_info(struct ps_prochandle* ph, const char* libname, uintptr_t base);
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // adds a new shared object to lib list, supply open lib file descriptor as well
a61af66fc99e Initial load
duke
parents:
diff changeset
120 lib_info* add_lib_info_fd(struct ps_prochandle* ph, const char* libname, int fd,
a61af66fc99e Initial load
duke
parents:
diff changeset
121 uintptr_t base);
a61af66fc99e Initial load
duke
parents:
diff changeset
122
a61af66fc99e Initial load
duke
parents:
diff changeset
123 // adds a new thread to threads list, returns NULL on failure
a61af66fc99e Initial load
duke
parents:
diff changeset
124 thread_info* add_thread_info(struct ps_prochandle* ph, pthread_t pthread_id, lwpid_t lwp_id);
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 // a test for ELF signature without using libelf
a61af66fc99e Initial load
duke
parents:
diff changeset
127 bool is_elf_file(int fd);
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 #endif //_LIBPROC_IMPL_H_