kernel: Fix off-by-one error in symbol lookup and add locking
This resulted in very weird backtraces.
This commit is contained in:
parent
b3cbbea9d6
commit
ba4e807f8e
@ -3,6 +3,7 @@
|
||||
#include "arch/MMU.h"
|
||||
#include "boot/bootboot.h"
|
||||
#include "fs/InitRD.h"
|
||||
#include "lib/Mutex.h"
|
||||
#include <luna/Scanf.h>
|
||||
#include <luna/TarStream.h>
|
||||
#include <luna/Vector.h>
|
||||
@ -18,6 +19,7 @@ struct Symbol
|
||||
};
|
||||
|
||||
Vector<Symbol> g_symbols;
|
||||
static Mutex g_lock;
|
||||
|
||||
extern const u8 kernel_start;
|
||||
extern const u8 kernel_end;
|
||||
@ -38,6 +40,8 @@ namespace Symbols
|
||||
{
|
||||
Result<void> load()
|
||||
{
|
||||
ScopedMutexLock lock(g_lock);
|
||||
|
||||
const u64 virtual_initrd_address = MMU::translate_physical_address(bootboot.initrd_ptr);
|
||||
|
||||
TarStream stream;
|
||||
@ -80,14 +84,11 @@ namespace Symbols
|
||||
if (address < (u64)&kernel_start) return StringView {};
|
||||
if (address >= (u64)&kernel_end) return StringView {};
|
||||
|
||||
ScopedMutexLock lock(g_lock);
|
||||
|
||||
for (isize i = (isize)g_symbols.size() - 1; i >= 0; i--)
|
||||
{
|
||||
if (g_symbols[i].address < address)
|
||||
{
|
||||
usize index = i + 1;
|
||||
if (index == g_symbols.size()) return StringView {};
|
||||
return StringView { g_symbols[index].symbol };
|
||||
}
|
||||
if (g_symbols[i].address < address) { return StringView { g_symbols[i].symbol }; }
|
||||
}
|
||||
|
||||
return StringView {};
|
||||
|
Loading…
Reference in New Issue
Block a user