Fix dlmalloc horror bug - mman_map overwrites application code

This commit is contained in:
2025-09-14 19:07:00 +02:00
parent e6891b39cc
commit 26ff717b50
18 changed files with 197 additions and 137 deletions

View File

@ -5,23 +5,23 @@ SECTIONS {
.text ALIGN(4K):
{
*(.text .text.*)
*(.text .text*)
}
.rodata (READONLY): ALIGN(4K)
{
*(.rodata .rodata.*)
*(.rodata .rodata*)
}
.data ALIGN(4K):
{
*(.data .data.*)
*(.data .data*)
}
.bss ALIGN(4K):
{
_bss_start = .;
*(.bss .bss.*)
*(.bss .bss*)
_bss_end = .;
}
}

View File

@ -6,16 +6,11 @@
#include <uprintf.h>
#include <ansiq/all.h>
#include <string/char.h>
void *string_memset2(void *p, int c, size_t n) {
char *cp = p;
for (size_t i = 0; i < n; i++) cp[i] = c;
return p;
}
#include <util/util.h>
void main(void) {
char *tbargs[] = { "-m", "interactive" };
int32_t tb = processctl(-1, PCTL_SPAWN, (uint64_t)"base:/bin/tb", (uint64_t)&tbargs, 2);
char *tbargs[] = { "-m", "runfile", "-f", "base:/scripts/init.tb" };
int32_t tb = processctl(-1, PCTL_SPAWN, (uint64_t)"base:/bin/tb", (uint64_t)&tbargs, ARRLEN(tbargs));
uint64_t selfpid = (uint64_t)processctl(-1, PCTL_GETPID, 0, 0, 0);
ipcpipe(tb, IPCPIPE_OUT, IPCPIPE_REPLACE, (uint8_t *)selfpid, IPCPIPE_OUT);
processctl(tb, PCTL_RUN, 0, 0, 0);

View File

@ -8,16 +8,21 @@
#include <ansiq/all.h>
#include <system/system.h>
#include <sysdefs/ipcpipe.h>
#include <sysdefs/ioctl.h>
#include <sysdefs/processctl.h>
#include <errors.h>
static struct {
struct {
char *modestr;
enum { MODE_INTERACTIVE = 1, MODE_RUNFILE = 2 } mode;
char *filepath;
} CONFIG;
#define LINEBUF_MAX 1024
static Arg ARGS[] = {
ARG("-m", ARG_STRING, &CONFIG.modestr),
ARG("-f", ARG_STRING, &CONFIG.filepath),
ARG_END(),
};
@ -38,11 +43,18 @@ void set_config(void) {
} else {
CONFIG.mode = MODE_RUNFILE;
}
uprintf("CONFIG.mode = %d\n", CONFIG.mode);
}
void process_cmd(char *cmdtext) {
}
void do_file(char *filepath) {
int32_t ioh = ioctl(IOCTL_NOHANDLE, IOCTL_OPENF, (uint64_t)filepath, IOCTL_F_READ, 0);
if (ioh < 0) {
LOG(LOG_ERR, "Could not open %s: %s\n", filepath, ERRSTRING(ioh));
return;
}
}
void do_mode_interactive(void) {
@ -62,8 +74,6 @@ void do_mode_interactive(void) {
}
linebuf[cursor - 1] = '\0';
uprintf("\n");
process_cmd(linebuf);
}
}
@ -72,5 +82,11 @@ void main(void) {
if (CONFIG.mode == MODE_INTERACTIVE) {
do_mode_interactive();
} else if (CONFIG.mode == MODE_RUNFILE) {
if (CONFIG.filepath == NULL) {
uprintf("No file provided\n");
return;
}
do_file(CONFIG.filepath);
}
}