Skip to content

Commit

Permalink
Patch libunwind manually to fix the access violation to unblock sourc…
Browse files Browse the repository at this point in the history
…e build (dotnet#97813)
  • Loading branch information
cshung committed Feb 1, 2024
1 parent 113af73 commit 5cd9eb8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/native/external/libunwind-version.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ Apply https://github.com/libunwind/libunwind/pull/701
Apply https://github.com/libunwind/libunwind/pull/703
Apply https://github.com/libunwind/libunwind/pull/704
Revert https://github.com/libunwind/libunwind/pull/503 # issue: https://github.com/libunwind/libunwind/issues/702
Apply https://github.com/libunwind/libunwind/pull/714
21 changes: 13 additions & 8 deletions src/native/external/libunwind/src/dwarf/Gget_proc_info_in_range.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,30 @@ unw_get_proc_info_in_range (unw_word_t start_ip,
if (eh_frame_table != 0) {
unw_accessors_t *a = unw_get_accessors_int (as);

struct dwarf_eh_frame_hdr* exhdr = NULL;
if ((*a->access_mem)(as, eh_frame_table, (unw_word_t*)&exhdr, 0, arg) < 0) {
unw_word_t data;
if ((*a->access_mem)(as, eh_frame_table, &data, 0, arg) < 0) {
return -UNW_EINVAL;
}
/* we are reading only the first 4 `char` members of `struct dwarf_eh_frame_hdr`, which
* are guaranteed to fit into the first `sizeof(unw_word_t)` bytes */
struct dwarf_eh_frame_hdr exhdr;
memcpy(&exhdr, &data, sizeof(data));

if (exhdr->version != DW_EH_VERSION) {
Debug (1, "Unexpected version %d\n", exhdr->version);
if (exhdr.version != DW_EH_VERSION) {
Debug (1, "Unexpected version %d\n", exhdr.version);
return -UNW_EBADVERSION;
}
unw_word_t addr = eh_frame_table + offsetof(struct dwarf_eh_frame_hdr, eh_frame);
unw_word_t eh_frame_start;
unw_word_t fde_count;

/* read eh_frame_ptr */
if ((ret = dwarf_read_encoded_pointer(as, a, &addr, exhdr->eh_frame_ptr_enc, pi, &eh_frame_start, arg)) < 0) {
if ((ret = dwarf_read_encoded_pointer(as, a, &addr, exhdr.eh_frame_ptr_enc, pi, &eh_frame_start, arg)) < 0) {
return ret;
}

/* read fde_count */
if ((ret = dwarf_read_encoded_pointer(as, a, &addr, exhdr->fde_count_enc, pi, &fde_count, arg)) < 0) {
if ((ret = dwarf_read_encoded_pointer(as, a, &addr, exhdr.fde_count_enc, pi, &fde_count, arg)) < 0) {
return ret;
}

Expand All @@ -87,8 +91,8 @@ unw_get_proc_info_in_range (unw_word_t start_ip,
return -UNW_ENOINFO;
}

if (exhdr->table_enc != (DW_EH_PE_datarel | DW_EH_PE_sdata4)) {
Debug (1, "Table encoding not supported %x\n", exhdr->table_enc);
if (exhdr.table_enc != (DW_EH_PE_datarel | DW_EH_PE_sdata4)) {
Debug (1, "Table encoding not supported %x\n", exhdr.table_enc);
return -UNW_EINVAL;
}

Expand All @@ -113,3 +117,4 @@ unw_get_proc_info_in_range (unw_word_t start_ip,
}
return UNW_ESUCCESS;
}

0 comments on commit 5cd9eb8

Please sign in to comment.