From c95a82da158dadef07f3ed49a88b09c87b0552c1 Mon Sep 17 00:00:00 2001 From: Stas Sergeev Date: Thu, 12 Sep 2024 00:44:41 +0300 Subject: [PATCH] plt: add API versioning --- src/libc/dj64/plt.S | 13 ++++++++++++- src/libc/dj64/plt.h | 1 + src/libc/dj64/thunks.c | 8 ++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/libc/dj64/plt.S b/src/libc/dj64/plt.S index 5fda4eb0..459058c0 100644 --- a/src/libc/dj64/plt.S +++ b/src/libc/dj64/plt.S @@ -249,6 +249,7 @@ plt_init: movl %fs:STUBINFO_SELF_SIZE, %ecx movl %fs:STUBINFO_MEM_BASE, %edx call ctrl + jc 2f /* free mem */ movl $0x502, %eax movw handle, %di @@ -275,17 +276,27 @@ plt_init: movl $0, %ecx movl %fs:STUBINFO_MEM_BASE, %edx call ctrl + jc 2b jmp 11b ctrl: pushal movl %esp, %edx movl __plt_handle, %eax - movl $AUX_CORE, %ebx + movl $0, %ebx + movb $AUX_CORE, %bl + movb $DL_API_VER, %bh movl $DL_SET_SYMTAB, %ecx movl %cs, %esi lcalll *__plt_ctrl + testl %eax, %eax + jnz 1f + popal + clc + ret +1: popal + stc ret .global plt_done diff --git a/src/libc/dj64/plt.h b/src/libc/dj64/plt.h index 82a4fd12..5689299c 100644 --- a/src/libc/dj64/plt.h +++ b/src/libc/dj64/plt.h @@ -1 +1,2 @@ #define DL_SET_SYMTAB 0 +#define DL_API_VER 1 diff --git a/src/libc/dj64/thunks.c b/src/libc/dj64/thunks.c index 3d93ee19..d49abe97 100644 --- a/src/libc/dj64/thunks.c +++ b/src/libc/dj64/thunks.c @@ -247,7 +247,15 @@ static void do_early_init(int handle) static int dj64_ctrl(int handle, int libid, int fn, unsigned esi, uint8_t *sp) { dpmi_regs *regs = (dpmi_regs *)sp; + int ver = libid >> 8; assert(handle < MAX_HANDLES); + if (ver != DL_API_VER) { + djloudprintf("dj64: API version mismatch, got %i want %i\n", + ver, DL_API_VER); + if (ver == 0) // this doesn't even handle errors, so terminate + dj64api->exit(1); + return -1; + } switch (fn) { case DL_SET_SYMTAB: { struct udisp *u = &udisps[handle];