Compare commits
No commits in common. "f22689fcf5564bba6d925a799512f72a4665bee5" and "795b0ca8d46c9a697fac1eec472a091a55f5676e" have entirely different histories.
f22689fcf5
...
795b0ca8d4
@ -80,8 +80,6 @@ void decode_page_fault_error_code(u64 code)
|
|||||||
|
|
||||||
decode_page_fault_error_code(regs->error);
|
decode_page_fault_error_code(regs->error);
|
||||||
|
|
||||||
CPU::print_stack_trace_at(regs);
|
|
||||||
|
|
||||||
if (!is_in_kernel(regs))
|
if (!is_in_kernel(regs))
|
||||||
{
|
{
|
||||||
// FIXME: Kill this process with SIGSEGV once we have signals and all that.
|
// FIXME: Kill this process with SIGSEGV once we have signals and all that.
|
||||||
@ -107,6 +105,8 @@ void decode_page_fault_error_code(u64 code)
|
|||||||
unreachable();
|
unreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CPU::print_stack_trace_at(regs);
|
||||||
|
|
||||||
CPU::efficient_halt();
|
CPU::efficient_halt();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,31 +118,6 @@ void decode_page_fault_error_code(u64 code)
|
|||||||
|
|
||||||
CPU::print_stack_trace_at(regs);
|
CPU::print_stack_trace_at(regs);
|
||||||
|
|
||||||
if (!is_in_kernel(regs))
|
|
||||||
{
|
|
||||||
// FIXME: Kill this process with SIGSEGV once we have signals and all that.
|
|
||||||
kerrorln("Current task %zu was terminated because of a general protection fault", Scheduler::current()->id);
|
|
||||||
if (Scheduler::current()->is_kernel) Scheduler::current()->state = ThreadState::Dying;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
auto* current = Scheduler::current();
|
|
||||||
auto* parent = current->parent;
|
|
||||||
if (parent && parent->state == ThreadState::Waiting)
|
|
||||||
{
|
|
||||||
auto child = *parent->child_being_waited_for;
|
|
||||||
if (child == -1 || child == (pid_t)current->id)
|
|
||||||
{
|
|
||||||
parent->child_being_waited_for = (pid_t)current->id;
|
|
||||||
parent->wake_up();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
current->state = ThreadState::Exited;
|
|
||||||
}
|
|
||||||
Scheduler::current()->status = 127;
|
|
||||||
kernel_yield();
|
|
||||||
unreachable();
|
|
||||||
}
|
|
||||||
|
|
||||||
CPU::efficient_halt();
|
CPU::efficient_halt();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -327,14 +302,14 @@ namespace CPU
|
|||||||
asm volatile("hlt");
|
asm volatile("hlt");
|
||||||
}
|
}
|
||||||
|
|
||||||
[[noreturn]] void efficient_halt() // Halt the CPU, using the lowest power possible. On x86-64 we do this using
|
[[noreturn]] void efficient_halt() // Halt the CPU, using the lowest power possible. On x86-64 we do this using the
|
||||||
// the "hlt" instruction, which puts the CPU into a low-power idle state
|
// "hlt" instruction, which puts the CPU into a low-power idle state until the
|
||||||
// until the next interrupt arrives... and we disable interrupts beforehand.
|
// next interrupt arrives... and we disable interrupts beforehand.
|
||||||
{
|
{
|
||||||
asm volatile("cli"); // Disable interrupts
|
asm volatile("cli"); // Disable interrupts
|
||||||
loop:
|
loop:
|
||||||
asm volatile("hlt"); // Let the cpu rest and pause until the next interrupt arrives... which in this case
|
asm volatile("hlt"); // Let the cpu rest and pause until the next interrupt arrives... which in this case should
|
||||||
// should be never (unless an NMI arrives) :)
|
// be never (unless an NMI arrives) :)
|
||||||
goto loop; // Safeguard: if we ever wake up, start our low-power rest again
|
goto loop; // Safeguard: if we ever wake up, start our low-power rest again
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#include "thread/ThreadImage.h"
|
#include "thread/ThreadImage.h"
|
||||||
#include "memory/MemoryManager.h"
|
#include "memory/MemoryManager.h"
|
||||||
#include "thread/Thread.h"
|
#include "thread/Thread.h"
|
||||||
#include <luna/Alignment.h>
|
|
||||||
#include <luna/CString.h>
|
#include <luna/CString.h>
|
||||||
|
|
||||||
static constexpr usize DEFAULT_USER_STACK_PAGES = 6;
|
static constexpr usize DEFAULT_USER_STACK_PAGES = 6;
|
||||||
@ -123,7 +122,7 @@ void ThreadImage::apply(Thread* thread)
|
|||||||
|
|
||||||
thread->kernel_stack = m_kernel_stack;
|
thread->kernel_stack = m_kernel_stack;
|
||||||
thread->stack = m_user_stack;
|
thread->stack = m_user_stack;
|
||||||
thread->set_sp(align_down<16>(m_sp));
|
thread->set_sp(m_sp);
|
||||||
|
|
||||||
thread->directory = m_directory;
|
thread->directory = m_directory;
|
||||||
|
|
||||||
|
@ -27,9 +27,6 @@ extern FILE* stderr;
|
|||||||
#define stderr stderr
|
#define stderr stderr
|
||||||
|
|
||||||
#define BUFSIZ 1024
|
#define BUFSIZ 1024
|
||||||
#define FILENAME_MAX \
|
|
||||||
1024 // As Luna does not impose a limit on this, this is the recommended size for character arrays holding a file
|
|
||||||
// name.
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
||||||
@ -44,9 +41,6 @@ extern "C"
|
|||||||
/* Bind a stream to a file descriptor. */
|
/* Bind a stream to a file descriptor. */
|
||||||
FILE* fdopen(int fd, const char* mode);
|
FILE* fdopen(int fd, const char* mode);
|
||||||
|
|
||||||
/* Change the underlying file and mode of a stream. */
|
|
||||||
FILE* freopen(const char* path, const char* mode, FILE* stream);
|
|
||||||
|
|
||||||
/* Close a file and frees up its stream. */
|
/* Close a file and frees up its stream. */
|
||||||
int fclose(FILE* stream);
|
int fclose(FILE* stream);
|
||||||
|
|
||||||
@ -101,9 +95,6 @@ extern "C"
|
|||||||
/* Read a character from standard input. */
|
/* Read a character from standard input. */
|
||||||
int getchar(void);
|
int getchar(void);
|
||||||
|
|
||||||
/* Push a character back to stream so that it can be read again. */
|
|
||||||
int ungetc(int c, FILE* stream);
|
|
||||||
|
|
||||||
/* Read a line from stream. */
|
/* Read a line from stream. */
|
||||||
char* fgets(char* buf, size_t size, FILE* stream);
|
char* fgets(char* buf, size_t size, FILE* stream);
|
||||||
|
|
||||||
|
@ -46,12 +46,6 @@ static int fdopen_check_compatible_mode(int fd, int new_flags)
|
|||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
int fflush(FILE*)
|
|
||||||
{
|
|
||||||
// FIXME: Files are not buffered right now.
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
FILE* fopen(const char* path, const char* mode)
|
FILE* fopen(const char* path, const char* mode)
|
||||||
{
|
{
|
||||||
int flags;
|
int flags;
|
||||||
@ -91,25 +85,6 @@ extern "C"
|
|||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE* freopen(const char* path, const char* mode, FILE* stream)
|
|
||||||
{
|
|
||||||
int flags;
|
|
||||||
|
|
||||||
if ((flags = fopen_parse_mode(mode)) < 0) return nullptr;
|
|
||||||
|
|
||||||
close(stream->_fd);
|
|
||||||
|
|
||||||
if (!path) { fail("FIXME: freopen() called with path=nullptr"); }
|
|
||||||
|
|
||||||
int fd = open(path, flags, 0666);
|
|
||||||
if (fd < 0) { return nullptr; }
|
|
||||||
|
|
||||||
stream->_fd = fd;
|
|
||||||
clearerr(stream);
|
|
||||||
|
|
||||||
return stream;
|
|
||||||
}
|
|
||||||
|
|
||||||
int fclose(FILE* stream)
|
int fclose(FILE* stream)
|
||||||
{
|
{
|
||||||
if (close(stream->_fd) < 0) return EOF;
|
if (close(stream->_fd) < 0) return EOF;
|
||||||
@ -485,9 +460,4 @@ extern "C"
|
|||||||
if (!f) close(fd);
|
if (!f) close(fd);
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ungetc(int, FILE*)
|
|
||||||
{
|
|
||||||
fail("FIXME: ungetc: not implemented");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -503,18 +503,15 @@ usize vstring_format(char* buf, usize max, const char* format, va_list ap)
|
|||||||
[](char c, void* arg) -> Result<void> {
|
[](char c, void* arg) -> Result<void> {
|
||||||
StringFormatInfo* info_arg = (StringFormatInfo*)arg;
|
StringFormatInfo* info_arg = (StringFormatInfo*)arg;
|
||||||
if (!info_arg->remaining) return {};
|
if (!info_arg->remaining) return {};
|
||||||
if (info_arg->buffer)
|
*(info_arg->buffer) = c;
|
||||||
{
|
info_arg->buffer++;
|
||||||
*(info_arg->buffer) = c;
|
|
||||||
info_arg->buffer++;
|
|
||||||
}
|
|
||||||
info_arg->remaining--;
|
info_arg->remaining--;
|
||||||
return {};
|
return {};
|
||||||
},
|
},
|
||||||
&info, ap)
|
&info, ap)
|
||||||
.value();
|
.value();
|
||||||
|
|
||||||
if (info.buffer) *(info.buffer) = 0;
|
*(info.buffer) = 0;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -6,5 +6,5 @@ Stack::Stack(u64 base, usize bytes) : m_base(base), m_bytes(bytes)
|
|||||||
|
|
||||||
u64 Stack::top() const
|
u64 Stack::top() const
|
||||||
{
|
{
|
||||||
return (m_base + m_bytes) - 16;
|
return (m_base + m_bytes) - sizeof(void*);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user