Luna/kernel/src/trace/StackTracer.cpp
apio da2ede3450 Kernel, libc, userspace: Implement file descriptors
Kernel: Implement a descriptor struct which stores the opened node and read offset, and give each task 8 of those.
Implement three syscalls: sys_read, sys_open and sys_close (sys_write still writes to the console instead of using a fd, for now)
Implement three new errors: ENOENT, EBADF and EMFILE.

libc: Implement the new errors, and the new syscalls in syscall().
Also fix _RETURN_WITH_ERRNO() to set errno correctly, which was making strerror() return null, thus crashing perror().

userspace: make init demonstrate the new file API.
2022-10-10 20:21:39 +02:00

52 lines
1.2 KiB
C++

#include "trace/StackTracer.h"
#include "memory/Memory.h"
#include "std/stdio.h"
#include "trace/Resolve.h"
StackTracer::StackTracer()
{
asm("mov %%rbp, %0" : "=r"(m_base_pointer));
}
StackTracer::StackTracer(uintptr_t base_pointer) : m_base_pointer(base_pointer)
{
}
typedef struct stackframe
{
struct stackframe* next;
uintptr_t instruction;
} stackframe;
void StackTracer::trace()
{
stackframe* frame = (stackframe*)m_base_pointer;
while (frame)
{
char symbol_name[512];
get_symbol_name(frame->instruction, symbol_name);
printf("%lx: %s\n", frame->instruction, symbol_name);
frame = frame->next;
}
}
void StackTracer::trace_with_ip(uintptr_t ip)
{
char symbol_name[512];
get_symbol_name(ip, symbol_name);
printf("%lx: %s\n", ip, symbol_name);
trace();
}
bool stack_trace_contains(uintptr_t address)
{
uintptr_t base_pointer;
asm volatile("mov %%rbp, %0" : "=r"(base_pointer));
stackframe* frame = (stackframe*)base_pointer;
while (Memory::is_kernel_address((uintptr_t)frame))
{
if (frame->instruction == address) return true;
frame = frame->next;
}
return false;
}