author | iklam |
Wed, 13 Nov 2019 16:36:54 -0800 | |
changeset 59070 | 22ee476cc664 |
parent 58541 | 8bc609fcd691 |
permissions | -rw-r--r-- |
58541
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
1 |
/* |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
4 |
* |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
8 |
* |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
13 |
* accompanied this code). |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
14 |
* |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
18 |
* |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
21 |
* questions. |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
22 |
* |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
23 |
*/ |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
24 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
25 |
#include <jni.h> // just include something, or else solaris compiler will complain that this file is empty |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
26 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
27 |
#if defined(LINUX) || defined(__APPLE__) |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
28 |
#include <unistd.h> |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
29 |
#include <fcntl.h> |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
30 |
#include <string.h> |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
31 |
#include <stdlib.h> |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
32 |
#include <stddef.h> |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
33 |
#ifdef LINUX |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
34 |
#include <elf.h> |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
35 |
#include <link.h> |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
36 |
#include "proc_service.h" |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
37 |
#include "salibelf.h" |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
38 |
#endif |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
39 |
#include "libproc_impl.h" |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
40 |
#include "cds.h" |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
41 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
42 |
#ifdef __APPLE__ |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
43 |
#include "sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext.h" |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
44 |
#endif |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
45 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
46 |
#ifdef LINUX |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
47 |
// I have no idea why this function is called ps_pread() on macos but ps_pdread on linux. |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
48 |
#define ps_pread ps_pdread |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
49 |
#endif |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
50 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
51 |
// Common code shared between linux/native/libsaproc/ps_core.c and macosx/native/libsaproc/ps_core.c |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
52 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
53 |
//---------------------------------------------------------------------- |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
54 |
// ps_prochandle cleanup helper functions |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
55 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
56 |
// close all file descriptors |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
57 |
static void close_files(struct ps_prochandle* ph) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
58 |
lib_info* lib = NULL; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
59 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
60 |
// close core file descriptor |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
61 |
if (ph->core->core_fd >= 0) |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
62 |
close(ph->core->core_fd); |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
63 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
64 |
// close exec file descriptor |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
65 |
if (ph->core->exec_fd >= 0) |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
66 |
close(ph->core->exec_fd); |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
67 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
68 |
// close interp file descriptor |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
69 |
if (ph->core->interp_fd >= 0) |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
70 |
close(ph->core->interp_fd); |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
71 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
72 |
// close class share archive file |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
73 |
if (ph->core->classes_jsa_fd >= 0) |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
74 |
close(ph->core->classes_jsa_fd); |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
75 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
76 |
// close all library file descriptors |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
77 |
lib = ph->libs; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
78 |
while (lib) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
79 |
int fd = lib->fd; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
80 |
if (fd >= 0 && fd != ph->core->exec_fd) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
81 |
close(fd); |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
82 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
83 |
lib = lib->next; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
84 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
85 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
86 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
87 |
// clean all map_info stuff |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
88 |
static void destroy_map_info(struct ps_prochandle* ph) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
89 |
map_info* map = ph->core->maps; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
90 |
while (map) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
91 |
map_info* next = map->next; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
92 |
free(map); |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
93 |
map = next; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
94 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
95 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
96 |
if (ph->core->map_array) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
97 |
free(ph->core->map_array); |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
98 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
99 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
100 |
// Part of the class sharing workaround |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
101 |
map = ph->core->class_share_maps; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
102 |
while (map) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
103 |
map_info* next = map->next; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
104 |
free(map); |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
105 |
map = next; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
106 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
107 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
108 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
109 |
// ps_prochandle operations |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
110 |
void core_release(struct ps_prochandle* ph) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
111 |
if (ph->core) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
112 |
close_files(ph); |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
113 |
destroy_map_info(ph); |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
114 |
free(ph->core); |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
115 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
116 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
117 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
118 |
static map_info* allocate_init_map(int fd, off_t offset, uintptr_t vaddr, size_t memsz) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
119 |
map_info* map; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
120 |
if ( (map = (map_info*) calloc(1, sizeof(map_info))) == NULL) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
121 |
print_debug("can't allocate memory for map_info\n"); |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
122 |
return NULL; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
123 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
124 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
125 |
// initialize map |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
126 |
map->fd = fd; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
127 |
map->offset = offset; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
128 |
map->vaddr = vaddr; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
129 |
map->memsz = memsz; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
130 |
return map; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
131 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
132 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
133 |
// add map info with given fd, offset, vaddr and memsz |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
134 |
map_info* add_map_info(struct ps_prochandle* ph, int fd, off_t offset, |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
135 |
uintptr_t vaddr, size_t memsz) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
136 |
map_info* map; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
137 |
if ((map = allocate_init_map(fd, offset, vaddr, memsz)) == NULL) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
138 |
return NULL; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
139 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
140 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
141 |
// add this to map list |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
142 |
map->next = ph->core->maps; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
143 |
ph->core->maps = map; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
144 |
ph->core->num_maps++; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
145 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
146 |
return map; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
147 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
148 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
149 |
// Part of the class sharing workaround |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
150 |
static map_info* add_class_share_map_info(struct ps_prochandle* ph, off_t offset, |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
151 |
uintptr_t vaddr, size_t memsz) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
152 |
map_info* map; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
153 |
if ((map = allocate_init_map(ph->core->classes_jsa_fd, |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
154 |
offset, vaddr, memsz)) == NULL) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
155 |
return NULL; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
156 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
157 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
158 |
map->next = ph->core->class_share_maps; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
159 |
ph->core->class_share_maps = map; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
160 |
return map; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
161 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
162 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
163 |
// Return the map_info for the given virtual address. We keep a sorted |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
164 |
// array of pointers in ph->map_array, so we can binary search. |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
165 |
map_info* core_lookup(struct ps_prochandle *ph, uintptr_t addr) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
166 |
int mid, lo = 0, hi = ph->core->num_maps - 1; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
167 |
map_info *mp; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
168 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
169 |
while (hi - lo > 1) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
170 |
mid = (lo + hi) / 2; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
171 |
if (addr >= ph->core->map_array[mid]->vaddr) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
172 |
lo = mid; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
173 |
} else { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
174 |
hi = mid; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
175 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
176 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
177 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
178 |
if (addr < ph->core->map_array[hi]->vaddr) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
179 |
mp = ph->core->map_array[lo]; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
180 |
} else { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
181 |
mp = ph->core->map_array[hi]; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
182 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
183 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
184 |
if (addr >= mp->vaddr && addr < mp->vaddr + mp->memsz) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
185 |
return (mp); |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
186 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
187 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
188 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
189 |
// Part of the class sharing workaround |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
190 |
// Unfortunately, we have no way of detecting -Xshare state. |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
191 |
// Check out the share maps atlast, if we don't find anywhere. |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
192 |
// This is done this way so to avoid reading share pages |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
193 |
// ahead of other normal maps. For eg. with -Xshare:off we don't |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
194 |
// want to prefer class sharing data to data from core. |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
195 |
mp = ph->core->class_share_maps; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
196 |
if (mp) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
197 |
print_debug("can't locate map_info at 0x%lx, trying class share maps\n", addr); |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
198 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
199 |
while (mp) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
200 |
if (addr >= mp->vaddr && addr < mp->vaddr + mp->memsz) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
201 |
print_debug("located map_info at 0x%lx from class share maps\n", addr); |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
202 |
return (mp); |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
203 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
204 |
mp = mp->next; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
205 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
206 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
207 |
print_debug("can't locate map_info at 0x%lx\n", addr); |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
208 |
return (NULL); |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
209 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
210 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
211 |
//--------------------------------------------------------------- |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
212 |
// Part of the class sharing workaround: |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
213 |
// |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
214 |
// With class sharing, pages are mapped from classes.jsa file. |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
215 |
// The read-only class sharing pages are mapped as MAP_SHARED, |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
216 |
// PROT_READ pages. These pages are not dumped into core dump. |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
217 |
// With this workaround, these pages are read from classes.jsa. |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
218 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
219 |
static bool read_jboolean(struct ps_prochandle* ph, uintptr_t addr, jboolean* pvalue) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
220 |
jboolean i; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
221 |
if (ps_pread(ph, (psaddr_t) addr, &i, sizeof(i)) == PS_OK) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
222 |
*pvalue = i; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
223 |
return true; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
224 |
} else { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
225 |
return false; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
226 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
227 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
228 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
229 |
static bool read_pointer(struct ps_prochandle* ph, uintptr_t addr, uintptr_t* pvalue) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
230 |
uintptr_t uip; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
231 |
if (ps_pread(ph, (psaddr_t) addr, (char *)&uip, sizeof(uip)) == PS_OK) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
232 |
*pvalue = uip; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
233 |
return true; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
234 |
} else { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
235 |
return false; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
236 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
237 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
238 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
239 |
// used to read strings from debuggee |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
240 |
bool read_string(struct ps_prochandle* ph, uintptr_t addr, char* buf, size_t size) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
241 |
size_t i = 0; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
242 |
char c = ' '; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
243 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
244 |
while (c != '\0') { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
245 |
if (ps_pread(ph, (psaddr_t) addr, &c, sizeof(char)) != PS_OK) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
246 |
return false; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
247 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
248 |
if (i < size - 1) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
249 |
buf[i] = c; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
250 |
} else { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
251 |
// smaller buffer |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
252 |
return false; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
253 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
254 |
i++; addr++; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
255 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
256 |
buf[i] = '\0'; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
257 |
return true; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
258 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
259 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
260 |
#ifdef LINUX |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
261 |
// mangled name of Arguments::SharedArchivePath |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
262 |
#define SHARED_ARCHIVE_PATH_SYM "_ZN9Arguments17SharedArchivePathE" |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
263 |
#define USE_SHARED_SPACES_SYM "UseSharedSpaces" |
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58541
diff
changeset
|
264 |
#define SHARED_BASE_ADDRESS_SYM "SharedBaseAddress" |
58541
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
265 |
#define LIBJVM_NAME "/libjvm.so" |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
266 |
#endif |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
267 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
268 |
#ifdef __APPLE__ |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
269 |
// mangled name of Arguments::SharedArchivePath |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
270 |
#define SHARED_ARCHIVE_PATH_SYM "__ZN9Arguments17SharedArchivePathE" |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
271 |
#define USE_SHARED_SPACES_SYM "_UseSharedSpaces" |
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58541
diff
changeset
|
272 |
#define SHARED_BASE_ADDRESS_SYM "_SharedBaseAddress" |
58541
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
273 |
#define LIBJVM_NAME "/libjvm.dylib" |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
274 |
#endif |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
275 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
276 |
bool init_classsharing_workaround(struct ps_prochandle* ph) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
277 |
lib_info* lib = ph->libs; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
278 |
while (lib != NULL) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
279 |
// we are iterating over shared objects from the core dump. look for |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
280 |
// libjvm.so. |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
281 |
const char *jvm_name = 0; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
282 |
if ((jvm_name = strstr(lib->name, LIBJVM_NAME)) != 0) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
283 |
char classes_jsa[PATH_MAX]; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
284 |
CDSFileMapHeaderBase header; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
285 |
int fd = -1; |
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58541
diff
changeset
|
286 |
uintptr_t useSharedSpacesAddr = 0; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58541
diff
changeset
|
287 |
uintptr_t sharedBaseAddressAddr = 0, sharedBaseAddress = 0; |
58541
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
288 |
uintptr_t sharedArchivePathAddrAddr = 0, sharedArchivePathAddr = 0; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
289 |
jboolean useSharedSpaces = 0; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
290 |
int m; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
291 |
size_t n; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
292 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
293 |
memset(classes_jsa, 0, sizeof(classes_jsa)); |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
294 |
jvm_name = lib->name; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
295 |
useSharedSpacesAddr = lookup_symbol(ph, jvm_name, USE_SHARED_SPACES_SYM); |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
296 |
if (useSharedSpacesAddr == 0) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
297 |
print_debug("can't lookup 'UseSharedSpaces' flag\n"); |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
298 |
return false; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
299 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
300 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
301 |
// Hotspot vm types are not exported to build this library. So |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
302 |
// using equivalent type jboolean to read the value of |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
303 |
// UseSharedSpaces which is same as hotspot type "bool". |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
304 |
if (read_jboolean(ph, useSharedSpacesAddr, &useSharedSpaces) != true) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
305 |
print_debug("can't read the value of 'UseSharedSpaces' flag\n"); |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
306 |
return false; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
307 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
308 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
309 |
if ((int)useSharedSpaces == 0) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
310 |
print_debug("UseSharedSpaces is false, assuming -Xshare:off!\n"); |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
311 |
return true; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
312 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
313 |
|
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58541
diff
changeset
|
314 |
sharedBaseAddressAddr = lookup_symbol(ph, jvm_name, SHARED_BASE_ADDRESS_SYM); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58541
diff
changeset
|
315 |
if (sharedBaseAddressAddr == 0) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58541
diff
changeset
|
316 |
print_debug("can't lookup 'SharedBaseAddress' flag\n"); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58541
diff
changeset
|
317 |
return false; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58541
diff
changeset
|
318 |
} |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58541
diff
changeset
|
319 |
|
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58541
diff
changeset
|
320 |
if (read_pointer(ph, sharedBaseAddressAddr, &sharedBaseAddress) != true) { |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58541
diff
changeset
|
321 |
print_debug("can't read the value of 'SharedBaseAddress' flag\n"); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58541
diff
changeset
|
322 |
return false; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58541
diff
changeset
|
323 |
} |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58541
diff
changeset
|
324 |
|
58541
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
325 |
sharedArchivePathAddrAddr = lookup_symbol(ph, jvm_name, SHARED_ARCHIVE_PATH_SYM); |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
326 |
if (sharedArchivePathAddrAddr == 0) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
327 |
print_debug("can't lookup shared archive path symbol\n"); |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
328 |
return false; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
329 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
330 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
331 |
if (read_pointer(ph, sharedArchivePathAddrAddr, &sharedArchivePathAddr) != true) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
332 |
print_debug("can't read shared archive path pointer\n"); |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
333 |
return false; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
334 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
335 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
336 |
if (read_string(ph, sharedArchivePathAddr, classes_jsa, sizeof(classes_jsa)) != true) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
337 |
print_debug("can't read shared archive path value\n"); |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
338 |
return false; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
339 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
340 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
341 |
print_debug("looking for %s\n", classes_jsa); |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
342 |
// open the class sharing archive file |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
343 |
fd = pathmap_open(classes_jsa); |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
344 |
if (fd < 0) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
345 |
print_debug("can't open %s!\n", classes_jsa); |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
346 |
ph->core->classes_jsa_fd = -1; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
347 |
return false; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
348 |
} else { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
349 |
print_debug("opened %s\n", classes_jsa); |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
350 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
351 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
352 |
// read CDSFileMapHeaderBase from the file |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
353 |
memset(&header, 0, sizeof(CDSFileMapHeaderBase)); |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
354 |
if ((n = read(fd, &header, sizeof(CDSFileMapHeaderBase))) |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
355 |
!= sizeof(CDSFileMapHeaderBase)) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
356 |
print_debug("can't read shared archive file map header from %s\n", classes_jsa); |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
357 |
close(fd); |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
358 |
return false; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
359 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
360 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
361 |
// check file magic |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
362 |
if (header._magic != CDS_ARCHIVE_MAGIC) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
363 |
print_debug("%s has bad shared archive file magic number 0x%x, expecting 0x%x\n", |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
364 |
classes_jsa, header._magic, CDS_ARCHIVE_MAGIC); |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
365 |
close(fd); |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
366 |
return false; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
367 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
368 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
369 |
// check version |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
370 |
if (header._version != CURRENT_CDS_ARCHIVE_VERSION) { |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
371 |
print_debug("%s has wrong shared archive file version %d, expecting %d\n", |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
372 |
classes_jsa, header._version, CURRENT_CDS_ARCHIVE_VERSION); |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
373 |
close(fd); |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
374 |
return false; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
375 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
376 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
377 |
ph->core->classes_jsa_fd = fd; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
378 |
// add read-only maps from classes.jsa to the list of maps |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
379 |
for (m = 0; m < NUM_CDS_REGIONS; m++) { |
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58541
diff
changeset
|
380 |
if (header._space[m]._read_only && |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58541
diff
changeset
|
381 |
!header._space[m]._is_heap_region && |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58541
diff
changeset
|
382 |
!header._space[m]._is_bitmap_region) { |
58541
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
383 |
// With *some* linux versions, the core file doesn't include read-only mmap'ed |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
384 |
// files regions, so let's add them here. This is harmless if the core file also |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
385 |
// include these regions. |
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58541
diff
changeset
|
386 |
uintptr_t base = sharedBaseAddress + (uintptr_t) header._space[m]._mapping_offset; |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58541
diff
changeset
|
387 |
size_t size = header._space[m]._used; |
58541
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
388 |
// no need to worry about the fractional pages at-the-end. |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
389 |
// possible fractional pages are handled by core_read_data. |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
390 |
add_class_share_map_info(ph, (off_t) header._space[m]._file_offset, |
59070
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58541
diff
changeset
|
391 |
base, size); |
22ee476cc664
8231610: Relocate the CDS archive if it cannot be mapped to the requested address
iklam
parents:
58541
diff
changeset
|
392 |
print_debug("added a share archive map [%d] at 0x%lx (size 0x%lx bytes)\n", m, base, size); |
58541
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
393 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
394 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
395 |
return true; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
396 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
397 |
lib = lib->next; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
398 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
399 |
return true; |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
400 |
} |
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
401 |
|
8bc609fcd691
8231986: [SA] Consolidate parts of the Linux and MacOSX versions of ps_core.c
iklam
parents:
diff
changeset
|
402 |
#endif // defined(LINUX) || defined(__APPLE__) |