Skip to content

Commit 36b129f

Browse files
committedAug 5, 2020
8250826: jhsdb does not work with coredump which comes from Substrate VM
Reviewed-by: cjplummer, sspitsyn
1 parent eaf70e0 commit 36b129f

File tree

6 files changed

+34
-13
lines changed

6 files changed

+34
-13
lines changed
 

‎src/jdk.hotspot.agent/linux/native/libsaproc/libproc_impl.h

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ typedef struct map_info {
6767
off_t offset; // file offset of this mapping
6868
uintptr_t vaddr; // starting virtual address
6969
size_t memsz; // size of the mapping
70+
uint32_t flags; // acces flags
7071
struct map_info* next;
7172
} map_info;
7273

‎src/jdk.hotspot.agent/linux/native/libsaproc/ps_core.c

+14-3
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ static bool read_core_segments(struct ps_prochandle* ph, ELF_EHDR* core_ehdr) {
351351
case PT_LOAD: {
352352
if (core_php->p_filesz != 0) {
353353
if (add_map_info(ph, ph->core->core_fd, core_php->p_offset,
354-
core_php->p_vaddr, core_php->p_filesz) == NULL) goto err;
354+
core_php->p_vaddr, core_php->p_filesz, core_php->p_flags) == NULL) goto err;
355355
}
356356
break;
357357
}
@@ -390,10 +390,21 @@ static bool read_lib_segments(struct ps_prochandle* ph, int lib_fd, ELF_EHDR* li
390390

391391
if (existing_map == NULL){
392392
if (add_map_info(ph, lib_fd, lib_php->p_offset,
393-
target_vaddr, lib_php->p_memsz) == NULL) {
393+
target_vaddr, lib_php->p_memsz, lib_php->p_flags) == NULL) {
394394
goto err;
395395
}
396+
} else if (lib_php->p_flags != existing_map->flags) {
397+
// Access flags for this memory region are different between the library
398+
// and coredump. It might be caused by mprotect() call at runtime.
399+
// We should respect the coredump.
400+
continue;
396401
} else {
402+
// Read only segments in ELF should not be any different from PT_LOAD segments
403+
// in the coredump.
404+
// Also the first page of the ELF header might be included
405+
// in the coredump (See JDK-7133122).
406+
// Thus we need to replace the PT_LOAD segment with the library version.
407+
//
397408
// Coredump stores value of p_memsz elf field
398409
// rounded up to page boundary.
399410

@@ -460,7 +471,7 @@ static bool read_exec_segments(struct ps_prochandle* ph, ELF_EHDR* exec_ehdr) {
460471
case PT_LOAD: {
461472
// add only non-writable segments of non-zero filesz
462473
if (!(exec_php->p_flags & PF_W) && exec_php->p_filesz != 0) {
463-
if (add_map_info(ph, ph->core->exec_fd, exec_php->p_offset, exec_php->p_vaddr, exec_php->p_filesz) == NULL) goto err;
474+
if (add_map_info(ph, ph->core->exec_fd, exec_php->p_offset, exec_php->p_vaddr, exec_php->p_filesz, exec_php->p_flags) == NULL) goto err;
464475
}
465476
break;
466477
}

‎src/jdk.hotspot.agent/macosx/native/libsaproc/libproc_impl.h

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ typedef struct map_info {
113113
uint64_t offset; // file offset of this mapping
114114
uint64_t vaddr; // starting virtual address
115115
size_t memsz; // size of the mapping
116+
uint32_t flags; // access flags
116117
struct map_info* next;
117118
} map_info;
118119

‎src/jdk.hotspot.agent/macosx/native/libsaproc/ps_core.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ static bool read_core_segments(struct ps_prochandle* ph) {
248248
print_debug("failed to read LC_SEGMENT_64 i = %d!\n", i);
249249
goto err;
250250
}
251-
if (add_map_info(ph, fd, segcmd.fileoff, segcmd.vmaddr, segcmd.vmsize) == NULL) {
251+
if (add_map_info(ph, fd, segcmd.fileoff, segcmd.vmaddr, segcmd.vmsize, segcmd.flags) == NULL) {
252252
print_debug("Failed to add map_info at i = %d\n", i);
253253
goto err;
254254
}
@@ -788,7 +788,7 @@ static bool read_core_segments(struct ps_prochandle* ph, ELF_EHDR* core_ehdr) {
788788
case PT_LOAD: {
789789
if (core_php->p_filesz != 0) {
790790
if (add_map_info(ph, ph->core->core_fd, core_php->p_offset,
791-
core_php->p_vaddr, core_php->p_filesz) == NULL) goto err;
791+
core_php->p_vaddr, core_php->p_filesz, core_php->p_flags) == NULL) goto err;
792792
}
793793
break;
794794
}
@@ -827,7 +827,7 @@ static bool read_lib_segments(struct ps_prochandle* ph, int lib_fd, ELF_EHDR* li
827827

828828
if (existing_map == NULL){
829829
if (add_map_info(ph, lib_fd, lib_php->p_offset,
830-
target_vaddr, lib_php->p_filesz) == NULL) {
830+
target_vaddr, lib_php->p_filesz, lib_php->p_flags) == NULL) {
831831
goto err;
832832
}
833833
} else {
@@ -893,7 +893,7 @@ static bool read_exec_segments(struct ps_prochandle* ph, ELF_EHDR* exec_ehdr) {
893893
case PT_LOAD: {
894894
// add only non-writable segments of non-zero filesz
895895
if (!(exec_php->p_flags & PF_W) && exec_php->p_filesz != 0) {
896-
if (add_map_info(ph, ph->core->exec_fd, exec_php->p_offset, exec_php->p_vaddr, exec_php->p_filesz) == NULL) goto err;
896+
if (add_map_info(ph, ph->core->exec_fd, exec_php->p_offset, exec_php->p_vaddr, exec_php->p_filesz, exec_php->p_flags) == NULL) goto err;
897897
}
898898
break;
899899
}

‎src/jdk.hotspot.agent/share/native/libsaproc/ps_core_common.c

+12-4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@
4141
#include "sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext.h"
4242
#endif
4343

44+
// Define a segment permission flag allowing read if there is a read flag. Otherwise use 0.
45+
#ifdef PF_R
46+
#define MAP_R_FLAG PF_R
47+
#else
48+
#define MAP_R_FLAG 0
49+
#endif
50+
4451
#ifdef LINUX
4552
// I have no idea why this function is called ps_pread() on macos but ps_pdread on linux.
4653
#define ps_pread ps_pdread
@@ -113,7 +120,7 @@ void core_release(struct ps_prochandle* ph) {
113120
}
114121
}
115122

116-
static map_info* allocate_init_map(int fd, off_t offset, uintptr_t vaddr, size_t memsz) {
123+
static map_info* allocate_init_map(int fd, off_t offset, uintptr_t vaddr, size_t memsz, uint32_t flags) {
117124
map_info* map;
118125
if ( (map = (map_info*) calloc(1, sizeof(map_info))) == NULL) {
119126
print_debug("can't allocate memory for map_info\n");
@@ -125,14 +132,15 @@ static map_info* allocate_init_map(int fd, off_t offset, uintptr_t vaddr, size_t
125132
map->offset = offset;
126133
map->vaddr = vaddr;
127134
map->memsz = memsz;
135+
map->flags = flags;
128136
return map;
129137
}
130138

131139
// add map info with given fd, offset, vaddr and memsz
132140
map_info* add_map_info(struct ps_prochandle* ph, int fd, off_t offset,
133-
uintptr_t vaddr, size_t memsz) {
141+
uintptr_t vaddr, size_t memsz, uint32_t flags) {
134142
map_info* map;
135-
if ((map = allocate_init_map(fd, offset, vaddr, memsz)) == NULL) {
143+
if ((map = allocate_init_map(fd, offset, vaddr, memsz, flags)) == NULL) {
136144
return NULL;
137145
}
138146

@@ -149,7 +157,7 @@ static map_info* add_class_share_map_info(struct ps_prochandle* ph, off_t offset
149157
uintptr_t vaddr, size_t memsz) {
150158
map_info* map;
151159
if ((map = allocate_init_map(ph->core->classes_jsa_fd,
152-
offset, vaddr, memsz)) == NULL) {
160+
offset, vaddr, memsz, MAP_R_FLAG)) == NULL) {
153161
return NULL;
154162
}
155163

‎src/jdk.hotspot.agent/share/native/libsaproc/ps_core_common.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -27,7 +27,7 @@
2727

2828
map_info* core_lookup(struct ps_prochandle *ph, uintptr_t addr);
2929
map_info* add_map_info(struct ps_prochandle* ph, int fd, off_t offset,
30-
uintptr_t vaddr, size_t memsz);
30+
uintptr_t vaddr, size_t memsz, uint32_t flags);
3131
void core_release(struct ps_prochandle* ph);
3232
bool read_string(struct ps_prochandle* ph, uintptr_t addr, char* buf, size_t size);
3333
bool init_classsharing_workaround(struct ps_prochandle* ph);

0 commit comments

Comments
 (0)
Please sign in to comment.