1
0
mirror of https://gitlab.os-k.eu/os-k-team/os-k.git synced 2023-08-25 14:03:10 +02:00

Non-locking I/O for panic()

This commit is contained in:
Julian Barathieu 2019-04-04 18:41:39 +02:00
parent 0bdad29198
commit 887aa60973
4 changed files with 40 additions and 20 deletions

View File

@ -25,6 +25,7 @@
#include <kernel/buf.h>
extern error_t bputc(Buffer_t *buf, uchar ch);
error_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap);
//
// Prints formatted string on buf according to fmt
@ -35,11 +36,25 @@ error_t BPrintOnBuf(Buffer_t *buf, const char *fmt, ...)
va_list ap;
va_start(ap, fmt);
rc = BPrintOnBufV(buf, fmt, ap);
ExAcquireLock(&buf->lock);
rc = vbprintf(buf, fmt, ap);
ExReleaseLock(&buf->lock);
va_end(ap);
return rc;
}
error_t BPrintOnBufV(Buffer_t *buf, const char *fmt, va_list ap)
{
error_t rc;
ExAcquireLock(&buf->lock);
rc = vbprintf(buf, fmt, ap);
ExReleaseLock(&buf->lock);
return rc;
}
//
// Prints 0 for octal, 0x for hexadecimal, 0b for binary
//
@ -81,10 +96,10 @@ static error_t bdopadding(Buffer_t *buf, size_t width, size_t len,
#define fmtnext() do{fmt++;if(*fmt==0){rc=EINVAL;goto leave;}}while(0)
//
// Actually does BPrintOnBuf's job
// Actually does BPrintOnBuf's job; doesn't lock anything
// Quite a long function
//
error_t BPrintOnBufV(Buffer_t *buf, const char *fmt, va_list ap)
error_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap)
{
error_t rc = EOK;
int tmpwidth;
@ -120,8 +135,6 @@ error_t BPrintOnBufV(Buffer_t *buf, const char *fmt, va_list ap)
return EBADF;
}
ExAcquireLock(&buf->lock);
//----------------------------------------------------------------------------//
// We come back here after dealing with a modifier
@ -367,7 +380,6 @@ loop:
//----------------------------------------------------------------------------//
leave:
ExReleaseLock(&buf->lock);
return rc;
}

View File

@ -147,18 +147,18 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic)
// Sanity checks and hello world
BtInitSanity(mbMagic);
//Memory mapping
// Memory mapping
MmInitMemoryMap();
// Heap initialization
MmInitHeap();
//int i = 0;
//while(i < 512) { KernLog("%d\n", i++);}
//MmPrintMemoryMap();
PsInitSched();
// We're out
PsFiniSched();
KeCrashSystem(); //yay
KeStartPanic("Test Panic %d", 4);
KeCrashSystem();
}

View File

@ -44,9 +44,7 @@ error_t bvgaflusher(Buffer_t *buf)
ushort *fbp = BtGetBootInfo(video).framebufferAddr;
const uchar color = 0xf;
assert(buf->lastLF == 0);
uchar *currentLine = buf->wp - buf->lineLen;
uchar *currentLine = buf->wp - buf->lineLen - buf->lastLF;
uchar *ptr = (uchar *)lmax((size_t)buf->buf,
(size_t)currentLine
- (buf->nLines - 1) * buf->lineLen);

View File

@ -28,6 +28,8 @@
#include <kernel/sched.h>
#include <kernel/panic.h>
error_t vbprintf(Buffer_t *buf, const char *fmt, va_list ap);
//
// Failed assert() handler
//
@ -55,21 +57,29 @@ noreturn void KeStartPanic(const char *fmt, ...)
PsCurProc = NULL;
if (BStdOut == NULL) KeCrashSystem();
ExAttemptLock(&BStdOut->lock);
if (fmt == NULL) {
fmt = "(no message given)";
}
if (KePanicStr[0] != 0) {
KernLog("\nDouble panic!");
vbprintf(BStdOut, "\nDouble panic!", NULL);
KeHaltCPU();
}
KePanicStr[0] = 1;
// We don't check vbprintf's output
// If it fails, what could we do anyway?
vbprintf(BStdOut, "\nPanic!\n\n", NULL);
va_start(ap, fmt);
vsnprintf((char *)KePanicStr, PANICSTR_SIZE, fmt, ap);
vbprintf(BStdOut, fmt, ap);
va_end(ap);
KernLog("\nPanic!\n\n");
KernLog((char *)KePanicStr);
BStdOut->flusher(BStdOut);
KeHaltCPU();
}