Max OS 0.3
Loading...
Searching...
No Matches
symbols.cpp File Reference

Implementation of symbol resolution for instruction pointers. More...

#include <common/symbols.h>

Go to the source code of this file.

Functions

const charMaxOS::common::resolve_symbol (uintptr_t rip, uintptr_t link_base, uintptr_t load_base)
 resolve an instruction pointer (rip) to a symbol name and optional offset.
 

Detailed Description

Implementation of symbol resolution for instruction pointers.

Date
10th September 2025
Author
Max Tyson

Definition in file symbols.cpp.

Function Documentation

◆ resolve_symbol()

const char * MaxOS::common::resolve_symbol ( uintptr_t  rip,
uintptr_t  link_base,
uintptr_t  load_base 
)

resolve an instruction pointer (rip) to a symbol name and optional offset.

Parameters
ripInstruction pointer
link_baseWhere the kernel is linked at
load_baseWhere the kernel is loaded at
Returns
The symbol name

Definition at line 23 of file symbols.cpp.

23 {
24
25 // No symbols
26 if(KERNEL_SYMBOLS_COUNT == 0)
27 return nullptr;
28
29 // Convert load to linked
30 uintptr_t offset = 0;
31 if(load_base >= link_base)
32 offset = load_base - link_base;
33
34 // Get the adjusted address
35 uintptr_t adjusted_address = rip;
36 if(rip >= offset)
37 adjusted_address = rip - offset;
38
39 // Binary Search for symbol
40 size_t left = 0;
41 size_t right = KERNEL_SYMBOLS_COUNT;
42 while(left < right) {
43 size_t middle = (left + right) >> 1;
44 if(kernel_symbols[middle].address <= adjusted_address)
45 left = middle + 1;
46 else
47 right = middle;
48 }
49
50 return left == 0 ? nullptr : kernel_symbols[left - 1].name;
51 }

References MaxOS::common::resolve_symbol().

Referenced by MaxOS::common::resolve_symbol(), and MaxOS::system::CPU::stack_trace().