Skip to content

Commit

Permalink
kernel: Fix "Load of value 102, which is not a valid value for type '…
Browse files Browse the repository at this point in the history
…Code'" from UBSan
  • Loading branch information
scribam authored and frangarcj committed May 23, 2020
1 parent fcf844c commit 2bf8df7
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions vita3k/kernel/src/relocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ static void write_thumb_mov_abs(void *data, uint16_t symbol) {
pair->upper.imm4 = symbol >> 12;
}

static bool relocate_entry(void *data, Code code, uint32_t symval, uint32_t addend, uint32_t addr) {
static bool relocate_entry(void *data, uint32_t code, uint32_t symval, uint32_t addend, uint32_t addr) {
LOG_DEBUG_IF(LOG_RELOCATIONS, "code: {}, *data: {}, data: {}, addr: {}, symval: {}, addend: {}", code, log_hex(*(reinterpret_cast<uint32_t *>(data))), data, log_hex(addr), log_hex(symval), log_hex(addend));
switch (code) {
case None:
Expand Down Expand Up @@ -270,7 +270,7 @@ static bool relocate_entry(void *data, Code code, uint32_t symval, uint32_t adde
}

LOG_WARN("Unhandled relocation code {}.", code);
return true; // ignore unhadled relocations
return true; // ignore unhandled relocations
}

bool relocate(const void *entries, uint32_t size, const SegmentInfosForReloc &segments, const MemState &mem, bool is_var_import, uint32_t explicit_symval) {
Expand Down Expand Up @@ -319,7 +319,7 @@ bool relocate(const void *entries, uint32_t size, const SegmentInfosForReloc &se
LOG_DEBUG_IF(LOG_RELOCATIONS, "[FORMAT0]: offset: {}, code: {}, sym_seg: {}, sym_start: {}, patch_seg: {}, patch_start: {}, s: {}, p: {}, a: {}. {}",
format0_entry->offset, format0_entry->code, symbol_seg, log_hex(symbol_seg_start), patch_seg, log_hex(patch_seg_start), log_hex(s), log_hex(p), log_hex(a), log_hex((uint64_t)Ptr<uint32_t>(p).get(mem)));

if (!relocate_entry(Ptr<uint32_t>(p).get(mem), static_cast<Code>(format0_entry->code), s, a, p)) {
if (!relocate_entry(Ptr<uint32_t>(p).get(mem), format0_entry->code, s, a, p)) {
return false;
}

Expand All @@ -329,7 +329,7 @@ bool relocate(const void *entries, uint32_t size, const SegmentInfosForReloc &se
LOG_DEBUG_IF(LOG_RELOCATIONS, "[FORMAT0/2]: code: {}, sym_seg: {}, sym_start: {}, s: {}, patch_seg: {}, p: {}, a: {}. {}",
format0_entry->code2, format0_entry->symbol_segment, symbol_seg_start, format0_entry->patch_segment, log_hex(patch_seg_start), log_hex(s), log_hex(addr2), log_hex(a), log_hex((uint64_t)Ptr<uint32_t>(addr2).get(mem)));

if (!relocate_entry(Ptr<uint32_t>(addr2).get(mem), static_cast<Code>(format0_entry->code2), s, a, addr2)) {
if (!relocate_entry(Ptr<uint32_t>(addr2).get(mem), format0_entry->code2, s, a, addr2)) {
return false;
}
}
Expand Down Expand Up @@ -361,7 +361,7 @@ bool relocate(const void *entries, uint32_t size, const SegmentInfosForReloc &se
LOG_DEBUG_IF(LOG_RELOCATIONS, "[FORMAT1]: code: {}, sym_seg: {}, sym_start: {}, patch_seg: {}, data_start: {}, s: {}, offset: {}, p: {}, a: {}",
format1_entry->code, symbol_seg, log_hex(symbol_seg_start), patch_seg, log_hex(patch_seg_start), log_hex(s), format1_entry->patch_segment, patch_seg_start, log_hex(offset), log_hex(p), log_hex(a));

if (!relocate_entry(Ptr<uint32_t>(p).get(mem), static_cast<Code>(format1_entry->code), s, a, p)) {
if (!relocate_entry(Ptr<uint32_t>(p).get(mem), format1_entry->code, s, a, p)) {
return false;
}

Expand Down Expand Up @@ -405,7 +405,7 @@ bool relocate(const void *entries, uint32_t size, const SegmentInfosForReloc &se
LOG_DEBUG_IF(LOG_RELOCATIONS, "[FORMAT1_VAR_IMPORT]: code: {}, sym_seg: {}, sym_start: {}, patch_seg: {}, data_start: {}, s: {}, offset: {}, p: {}, a: {}",
format1_entry->code, symbol_seg, log_hex(symbol_seg_start), patch_seg, log_hex(patch_seg_start), log_hex(s), format1_entry->patch_segment, patch_seg_start, log_hex(offset), log_hex(p), log_hex(a));

if (!relocate_entry(Ptr<uint32_t>(p).get(mem), static_cast<Code>(format1_entry->code), s, a, p)) {
if (!relocate_entry(Ptr<uint32_t>(p).get(mem), format1_entry->code, s, a, p)) {
return false;
}

Expand Down Expand Up @@ -438,7 +438,7 @@ bool relocate(const void *entries, uint32_t size, const SegmentInfosForReloc &se
LOG_DEBUG_IF(LOG_RELOCATIONS, "[FORMAT2]: code: {}, sym_seg: {}, sym_start: {}, offset: {}, s: {}, p: {}, a: {}",
format2_entry->code, symbol_seg, log_hex(symbol_seg_start), log_hex(format2_entry->offset), log_hex(s), log_hex(p), log_hex(a));

if (!relocate_entry(Ptr<uint32_t>(p).get(mem), static_cast<Code>(g_type), s, a, p)) {
if (!relocate_entry(Ptr<uint32_t>(p).get(mem), g_type, s, a, p)) {
return false;
}

Expand Down Expand Up @@ -473,11 +473,11 @@ bool relocate(const void *entries, uint32_t size, const SegmentInfosForReloc &se
const auto a = g_addend;
const auto p = g_addr + g_offset;

if (!relocate_entry(Ptr<uint32_t>(p).get(mem), static_cast<Code>(g_type), s, a, p)) {
if (!relocate_entry(Ptr<uint32_t>(p).get(mem), g_type, s, a, p)) {
return false;
}

if (!relocate_entry(Ptr<uint32_t>(p + dist2).get(mem), static_cast<Code>(g_type2), s, a, p + dist2)) {
if (!relocate_entry(Ptr<uint32_t>(p + dist2).get(mem), g_type2, s, a, p + dist2)) {
return false;
}

Expand All @@ -496,11 +496,11 @@ bool relocate(const void *entries, uint32_t size, const SegmentInfosForReloc &se
const auto a = g_addend;
const auto p = g_addr + g_offset;

if (!relocate_entry(Ptr<uint32_t>(p).get(mem), static_cast<Code>(g_type), s, a, p)) {
if (!relocate_entry(Ptr<uint32_t>(p).get(mem), g_type, s, a, p)) {
return false;
}

if (!relocate_entry(Ptr<uint32_t>(p + dist2).get(mem), static_cast<Code>(g_type2), s, a, p + dist2)) {
if (!relocate_entry(Ptr<uint32_t>(p + dist2).get(mem), g_type2, s, a, p + dist2)) {
return false;
}

Expand All @@ -515,22 +515,22 @@ bool relocate(const void *entries, uint32_t size, const SegmentInfosForReloc &se
const auto a = g_addend;
const auto p = g_addr + g_offset;

if (!relocate_entry(Ptr<uint32_t>(p).get(mem), static_cast<Code>(g_type), s, a, p)) {
if (!relocate_entry(Ptr<uint32_t>(p).get(mem), g_type, s, a, p)) {
return false;
}

if (!relocate_entry(Ptr<uint32_t>(p + format5_entry->dist2).get(mem), static_cast<Code>(g_type2), s, a, p + format5_entry->dist2)) {
if (!relocate_entry(Ptr<uint32_t>(p + format5_entry->dist2).get(mem), g_type2, s, a, p + format5_entry->dist2)) {
return false;
}

g_offset += format5_entry->dist3;
const auto p2 = g_addr + g_offset;

if (!relocate_entry(Ptr<uint32_t>(p2).get(mem), static_cast<Code>(g_type), s, a, p2)) {
if (!relocate_entry(Ptr<uint32_t>(p2).get(mem), g_type, s, a, p2)) {
return false;
}

if (!relocate_entry(Ptr<uint32_t>(p2 + format5_entry->dist4).get(mem), static_cast<Code>(g_type2), s, a, p2 + format5_entry->dist4)) {
if (!relocate_entry(Ptr<uint32_t>(p2 + format5_entry->dist4).get(mem), g_type2, s, a, p2 + format5_entry->dist4)) {
return false;
}

Expand Down Expand Up @@ -564,7 +564,7 @@ bool relocate(const void *entries, uint32_t size, const SegmentInfosForReloc &se
const auto a = addend;
const auto p = g_addr + g_offset;

if (!relocate_entry(Ptr<uint32_t>(p).get(mem), static_cast<Code>(g_type), s, a, p)) {
if (!relocate_entry(Ptr<uint32_t>(p).get(mem), g_type, s, a, p)) {
return false;
}

Expand Down Expand Up @@ -616,7 +616,7 @@ bool relocate(const void *entries, uint32_t size, const SegmentInfosForReloc &se
const auto a = addend;
const auto p = g_addr + g_offset;

if (!relocate_entry(Ptr<uint32_t>(p).get(mem), static_cast<Code>(g_type), s, a, p)) {
if (!relocate_entry(Ptr<uint32_t>(p).get(mem), g_type, s, a, p)) {
return false;
}
} while (offsets >>= bitsize);
Expand Down

0 comments on commit 2bf8df7

Please sign in to comment.