Skip to content

Commit

Permalink
dosobj: define swappable context
Browse files Browse the repository at this point in the history
dosemu2 now supports out-of-order client termination, so we can't
assume any static context to be permanent.
  • Loading branch information
stsp committed Aug 9, 2024
1 parent d4cc47e commit 4674801
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
18 changes: 13 additions & 5 deletions src/libc/dj64/dosobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,21 @@
#include <dpmi.h>
#include <dj64/util.h>
#include <libc/djthunks.h>
#include <libc/djctx.h>
#include "smalloc.h"
#include "dosobj.h"

static smpool pool;
static uint32_t base;
static int initialized;
struct dost {
smpool pool;
uint32_t base;
int initialized;
};

static struct dost *dst;
DJ64_DEFINE_SWAPPABLE_CONTEXT(dost, dst)
#define pool dst->pool
#define base dst->base
#define initialized dst->initialized

static void err_printf(int prio, const char *fmt, ...) PRINTF(2);
static void err_printf(int prio, const char *fmt, ...)
Expand All @@ -57,8 +66,7 @@ static void err_printf(int prio, const char *fmt, ...)

void dosobj_init(void *ptr, int size)
{
if (initialized)
smdestroy(&pool);
assert(!initialized);
sminit(&pool, ptr, size);
smregister_error_notifier(&pool, err_printf);
base = PTR_DATA(ptr);
Expand Down
5 changes: 2 additions & 3 deletions src/libc/dj64/thunks.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,10 +521,9 @@ void crt1_startup(int handle)

assert(handle < MAX_HANDLES);
__djgpp_nearptr_enable(); // speeds up things considerably
u = &udisps[handle];
if (u->full_init)
dosobj_init(dosobj_page, 4096);
dosobj_init(dosobj_page, 4096);

u = &udisps[handle];
__crt1_startup(u->main);
}

Expand Down

0 comments on commit 4674801

Please sign in to comment.