mirror of
https://gitlab.os-k.eu/os-k-team/os-k.git
synced 2023-08-25 14:03:10 +02:00
Correcting a bug on real hw caused by malloc that non zeroises the mem it allocates
This commit is contained in:
parent
39091a44c1
commit
9f20e63df7
@ -47,14 +47,14 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg)
|
|||||||
// Memory & scheduler
|
// Memory & scheduler
|
||||||
MmInitMemoryMap();
|
MmInitMemoryMap();
|
||||||
|
|
||||||
// Several inits
|
|
||||||
MmInitHeap();
|
|
||||||
PsInitSched();
|
|
||||||
|
|
||||||
// Interrupts launching
|
// Interrupts launching
|
||||||
IdtSetup();
|
IdtSetup();
|
||||||
KeEnableIRQs();
|
KeEnableIRQs();
|
||||||
|
|
||||||
|
// Several inits
|
||||||
|
MmInitHeap();
|
||||||
|
//PsInitSched();
|
||||||
|
|
||||||
// Start drivers
|
// Start drivers
|
||||||
IoEnableRtc();
|
IoEnableRtc();
|
||||||
IoEnableKeyb();
|
IoEnableKeyb();
|
||||||
|
@ -46,8 +46,8 @@ error_t KalAllocMemoryEx(void **ptr, size_t req, int flags, size_t align)
|
|||||||
brk = (size_t)_heap_start + MmGetHeapSize();
|
brk = (size_t)_heap_start + MmGetHeapSize();
|
||||||
req = _ALIGN_UP(req + brk, align) - brk;
|
req = _ALIGN_UP(req + brk, align) - brk;
|
||||||
|
|
||||||
//DebugLog("MALLOC: start=%p, size=%lx, brk=%p, req=%lx\n",
|
/* DebugLog("MALLOC: start=%p, size=%lx, brk=%p, req=%lx\n", */
|
||||||
// _heap_start, MmGetHeapSize(), brk, req);
|
/* _heap_start, MmGetHeapSize(), brk, req); */
|
||||||
|
|
||||||
rc = MmGrowHeap(req);
|
rc = MmGrowHeap(req);
|
||||||
|
|
||||||
@ -59,12 +59,12 @@ error_t KalAllocMemoryEx(void **ptr, size_t req, int flags, size_t align)
|
|||||||
KeStartPanic("KalAllocMemory: Out of memory");
|
KeStartPanic("KalAllocMemory: Out of memory");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*ptr = (void *)brk;
|
||||||
|
|
||||||
if (flags & M_ZEROED) {
|
if (flags & M_ZEROED) {
|
||||||
memzero(*ptr, req);
|
memzero(*ptr, req);
|
||||||
}
|
}
|
||||||
|
|
||||||
*ptr = (void *)brk;
|
|
||||||
|
|
||||||
assert(*ptr);
|
assert(*ptr);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ noreturn void PoShutdownQemu(void)
|
|||||||
|
|
||||||
IoWriteWordOnPort(0x604, 0x2000);
|
IoWriteWordOnPort(0x604, 0x2000);
|
||||||
|
|
||||||
|
KeCrashSystem();
|
||||||
__builtin_unreachable();
|
__builtin_unreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,6 +46,7 @@ noreturn void PoShutdownVirtualbox(void)
|
|||||||
|
|
||||||
IoWriteWordOnPort(0x4004, 0x3400);
|
IoWriteWordOnPort(0x4004, 0x3400);
|
||||||
|
|
||||||
|
KeCrashSystem();
|
||||||
__builtin_unreachable();
|
__builtin_unreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,6 +58,7 @@ noreturn void PoShutdownBochs(void)
|
|||||||
|
|
||||||
IoWriteWordOnPort(0xB004, 0x2000);
|
IoWriteWordOnPort(0xB004, 0x2000);
|
||||||
|
|
||||||
|
KeCrashSystem();
|
||||||
__builtin_unreachable();
|
__builtin_unreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,5 +139,6 @@ void KeStartShell(void)
|
|||||||
|
|
||||||
KePauseCPU();
|
KePauseCPU();
|
||||||
}
|
}
|
||||||
|
KernLog("[EOI]\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ error_t BOpenPureBufEx(Buffer_t **pbuf, char *source, int mode, size_t size,
|
|||||||
if (!*pbuf) {
|
if (!*pbuf) {
|
||||||
buf = malloc(sizeof *buf);
|
buf = malloc(sizeof *buf);
|
||||||
if (!buf) return ENOMEM;
|
if (!buf) return ENOMEM;
|
||||||
buf->flags |= BF_BALLOC;
|
buf->flags = BF_BALLOC;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
buf = *pbuf;
|
buf = *pbuf;
|
||||||
@ -64,6 +64,7 @@ error_t BOpenPureBufEx(Buffer_t **pbuf, char *source, int mode, size_t size,
|
|||||||
|
|
||||||
buf->size = size;
|
buf->size = size;
|
||||||
buf->state = mode;
|
buf->state = mode;
|
||||||
|
//buf->buf = NULL;
|
||||||
|
|
||||||
if (source == NULL) {
|
if (source == NULL) {
|
||||||
KalAllocMemoryEx((void **)&buf->buf, buf->size, M_ZEROED, 0);
|
KalAllocMemoryEx((void **)&buf->buf, buf->size, M_ZEROED, 0);
|
||||||
|
@ -78,7 +78,7 @@ size_t snprintf(char *str, size_t n, const char *fmt, ...)
|
|||||||
size_t vsnprintf(char *str, size_t n, const char *fmt, va_list ap)
|
size_t vsnprintf(char *str, size_t n, const char *fmt, va_list ap)
|
||||||
{
|
{
|
||||||
size_t ret;
|
size_t ret;
|
||||||
error_t rc;
|
error_t rc = EOK;
|
||||||
Buffer_t *buf = NULL;
|
Buffer_t *buf = NULL;
|
||||||
|
|
||||||
assert(str && fmt);
|
assert(str && fmt);
|
||||||
@ -89,16 +89,26 @@ size_t vsnprintf(char *str, size_t n, const char *fmt, va_list ap)
|
|||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rc = BOpenPureBuf(&buf, BS_WRONLY, n-1);
|
||||||
|
|
||||||
// n-1 to leave place for the '\0'
|
// n-1 to leave place for the '\0'
|
||||||
if (BOpenPureBuf(&buf, BS_WRONLY, n-1) != EOK) {
|
if (rc != EOK) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = vbprintf(buf, fmt, ap);
|
rc = vbprintf(buf, fmt, ap);
|
||||||
|
|
||||||
// We don't mind EOFs, just just return how much was successfully written
|
// We don't mind EOFs, just just return how much was successfully written
|
||||||
if (rc != EOK && !(rc == EENDF && !(buf->flags & BF_EOF))) {
|
if (rc != EOK) {
|
||||||
|
if (rc == EENDF) {
|
||||||
|
if (!(buf->flags & BF_EOF)) {
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ret = (size_t)buf->wp - (size_t)buf->buf;
|
ret = (size_t)buf->wp - (size_t)buf->buf;
|
||||||
|
|
||||||
@ -114,7 +124,8 @@ size_t vsnprintf(char *str, size_t n, const char *fmt, va_list ap)
|
|||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
assert(!"vsnprintf() failure");
|
KeStartPanic("vsnprintf() failure\nRC: %d\nbuf->flags & BF_EOF: %d\n",
|
||||||
|
rc, buf->flags & BF_EOF);
|
||||||
*str = 0;
|
*str = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user