summaryrefslogtreecommitdiffstats
path: root/src/lib/kStuff/kLdr/testcase
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/kStuff/kLdr/testcase')
-rw-r--r--src/lib/kStuff/kLdr/testcase/Makefile.kmk305
-rw-r--r--src/lib/kStuff/kLdr/testcase/bin/tst-3.dll.win.x86bin0 -> 3072 bytes
-rw-r--r--src/lib/kStuff/kLdr/testcase/bin/tst-3.rel.darwin.x86bin0 -> 2800 bytes
-rw-r--r--src/lib/kStuff/kLdr/testcase/tst-0-a.c10
-rw-r--r--src/lib/kStuff/kLdr/testcase/tst-0-b.c10
-rw-r--r--src/lib/kStuff/kLdr/testcase/tst-0-c.c10
-rw-r--r--src/lib/kStuff/kLdr/testcase/tst-0-d.c8
-rw-r--r--src/lib/kStuff/kLdr/testcase/tst-0-driver.c502
-rw-r--r--src/lib/kStuff/kLdr/testcase/tst-0.c13
-rw-r--r--src/lib/kStuff/kLdr/testcase/tst-1-a.c10
-rw-r--r--src/lib/kStuff/kLdr/testcase/tst-1-b.c10
-rw-r--r--src/lib/kStuff/kLdr/testcase/tst-1-c.c10
-rw-r--r--src/lib/kStuff/kLdr/testcase/tst-1-d.c8
-rw-r--r--src/lib/kStuff/kLdr/testcase/tst-1.c15
-rw-r--r--src/lib/kStuff/kLdr/testcase/tst-2-a.c8
-rw-r--r--src/lib/kStuff/kLdr/testcase/tst-2-b.c10
-rw-r--r--src/lib/kStuff/kLdr/testcase/tst-2-c.c10
-rw-r--r--src/lib/kStuff/kLdr/testcase/tst-2-d.c10
-rw-r--r--src/lib/kStuff/kLdr/testcase/tst-2.c16
-rw-r--r--src/lib/kStuff/kLdr/testcase/tst-3-driver.c216
-rw-r--r--src/lib/kStuff/kLdr/testcase/tst-3-ext.c39
-rw-r--r--src/lib/kStuff/kLdr/testcase/tst-3-imp-os2.def34
-rw-r--r--src/lib/kStuff/kLdr/testcase/tst-3-imp-win.def34
-rw-r--r--src/lib/kStuff/kLdr/testcase/tst-3.c78
-rw-r--r--src/lib/kStuff/kLdr/testcase/tst.h57
-rw-r--r--src/lib/kStuff/kLdr/testcase/tstDllMain.c192
-rw-r--r--src/lib/kStuff/kLdr/testcase/tstDllMainStub-os2.asm40
-rw-r--r--src/lib/kStuff/kLdr/testcase/tstDllMainStub.c76
-rw-r--r--src/lib/kStuff/kLdr/testcase/tstExeMainStub-os2.asm40
-rw-r--r--src/lib/kStuff/kLdr/testcase/tstExeMainStub.c93
30 files changed, 1864 insertions, 0 deletions
diff --git a/src/lib/kStuff/kLdr/testcase/Makefile.kmk b/src/lib/kStuff/kLdr/testcase/Makefile.kmk
new file mode 100644
index 0000000..7b3efb6
--- /dev/null
+++ b/src/lib/kStuff/kLdr/testcase/Makefile.kmk
@@ -0,0 +1,305 @@
+# $Id: Makefile.kmk 29 2009-07-01 20:30:29Z bird $
+## @file
+# kBuild Makefile for the kLdr testcases.
+#
+
+#
+# Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+#
+# Permission is hereby granted, free of charge, to any person
+# obtaining a copy of this software and associated documentation
+# files (the "Software"), to deal in the Software without
+# restriction, including without limitation the rights to use,
+# copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following
+# conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+# OTHER DEALINGS IN THE SOFTWARE.
+#
+
+# generate rules.
+DEPTH ?= ../..
+SUB_DEPTH = ../..
+include $(PATH_KBUILD)/subheader.kmk
+
+
+#
+# Templates for the testcases.
+#
+TEMPLATE_TST = Testcase template
+ifeq ($(BUILD_TARGET),win)
+ ifeq ($(BUILD_TARGET_ARCH),x86)
+ TEMPLATE_TST_TOOL = VCC70
+ TEMPLATE_TST_CFLAGS = -W3 -Zi -Zl -MD
+ TEMPLATE_TST_CXXFLAGS = -W3 -Zi -Zl -MD
+ TEMPLATE_TST_LIBS = \
+ $(PATH_TOOL_VCC70_LIB)/oldnames.lib \
+ $(PATH_TOOL_VCC70_LIB)/msvcrt.lib
+ else
+ TEMPLATE_TST_TOOL = VCC80AMD64
+ TEMPLATE_TST_CFLAGS = -W3 -Zi -Zl -MD
+ TEMPLATE_TST_CXXFLAGS = -W3 -Zi -Zl -MD
+ TEMPLATE_TST_LIBS = \
+ $(PATH_TOOL_VCC80AMD64_LIB)/oldnames.lib \
+ $(PATH_TOOL_VCC80AMD64_LIB)/msvcrt.lib
+ endif
+ TEMPLATE_TST_CFLAGS.release = -O2
+ TEMPLATE_TST_CXXFLAGS.release = -O2
+ TEMPLATE_TST_ASFLAGS = -f win
+ TEMPLATE_TST_DEFS = __WIN__
+ TEMPLATE_TST_SDKS.x86 = WIN32SDK
+ TEMPLATE_TST_SDKS.amd64 = WIN64SDK
+
+else
+ TEMPLATE_TST_CFLAGS = -Wall -pedantic -g
+ TEMPLATE_TST_CFLAGS.release = -O2
+ TEMPLATE_TST_LDFLAGS =
+ ifneq ($(filter os2,$(BUILD_TARGET)),)
+ TEMPLATE_TST_TOOL = GCC3OMF
+ TEMPLATE_TST_ASFLAGS = -f obj
+ TEMPLATE_TST_LIBS = os2 gcc end
+ else ifneq ($(filter darwin,$(BUILD_TARGET)),)
+ TEMPLATE_TST_TOOL = GCC4MACHO
+ TEMPLATE_TST_ASFLAGS = -f macho
+ TEMPLATE_TST_DEFS = __DARWIN__
+ TEMPLATE_TST_LIBS =
+ else
+ TEMPLATE_TST_TOOL = GCC3
+ TEMPLATE_TST_ASFLAGS = -f elf
+ TEMPLATE_TST_LIBS = gcc
+ endif
+endif
+TEMPLATE_TST_INCS := $(PATH_SUB_CURRENT) $(PATH_SUB_ROOT)/include
+
+
+TEMPLATE_TSTPROG = Testcase program template
+TEMPLATE_TSTPROG_EXTENDS = TST
+
+
+TEMPLATE_TSTDLL = Testcase dll template
+TEMPLATE_TSTDLL_EXTENDS = TST
+
+
+TEMPLATE_TSTBARE = Bare bone testcase template
+ifeq ($(BUILD_TARGET),win)
+ ifeq ($(BUILD_TARGET_ARCH),x86)
+ TEMPLATE_TSTBARE_TOOL = VCC70
+ else
+ TEMPLATE_TSTBARE_TOOL = VCC80AMD64
+ endif
+ TEMPLATE_TSTBARE_CFLAGS = -W3 -Zi -Zl
+ TEMPLATE_TSTBARE_CFLAGS.release = -O2
+ TEMPLATE_TSTBARE_CXXFLAGS = -W3 -Zi -Zl
+ TEMPLATE_TSTBARE_CXXFLAGS.release = -O2
+ TEMPLATE_TSTBARE_ASFLAGS = -f win
+ TEMPLATE_TSTBARE_DEFS = __WIN__
+ TEMPLATE_TSTBARE_SDKS.x86 = WIN32SDK
+ TEMPLATE_TSTBARE_SDKS.amd64 = WIN64SDK
+
+else
+ TEMPLATE_TSTBARE_CFLAGS = -Wall -pedantic -g
+ TEMPLATE_TSTBARE_CFLAGS.release = -O2
+ TEMPLATE_TSTBARE_LDFLAGS = -nostdlib -lgcc
+ ifeq ($(filter-out os2,$(BUILD_TARGET)),)
+ TEMPLATE_TSTBARE_TOOL = GCC3OMF
+ TEMPLATE_TSTBARE_ASFLAGS = -f obj
+ TEMPLATE_TSTBARE_ASTOOL = NASM
+ TEMPLATE_TSTBARE_DEFS = main=main_wrapped
+ TEMPLATE_TSTBARE_LIBS = os2
+ else ifeq ($(filter-out darwin,$(BUILD_TARGET)),)
+ TEMPLATE_TSTBARE_TOOL = GCC4MACHO
+ TEMPLATE_TSTBARE_ASFLAGS = -f macho
+ TEMPLATE_TSTBARE_ASTOOL = NASM
+ TEMPLATE_TSTBARE_DEFS = __DARWIN__
+ TEMPLATE_TSTBARE_LIBS =
+ TEMPLATE_TSTBARE_CFLAGS += -static -fno-common
+ TEMPLATE_TSTBARE_LDFLAGS += -nostdlib -r
+ else
+ TEMPLATE_TSTBARE_TOOL = GCC3
+ TEMPLATE_TSTBARE_ASFLAGS = -f elf
+ TEMPLATE_TSTBARE_LIBS = gcc
+ endif
+endif
+TEMPLATE_TSTBARE_INCS := $(PATH_SUB_CURRENT) $(PATH_SUB_ROOT)/include
+
+TEMPLATE_TSTBAREPROG = Bare bone testcase program template
+TEMPLATE_TSTBAREPROG_EXTENDS = TSTBARE
+ifneq ($(filter win win32 win64,$(BUILD_TARGET)),)
+TEMPLATE_TSTBAREPROG_LDFLAGS += -Entry:WindowsMain -FIXED:NO
+else
+TEMPLATE_TSTBAREPROG_LDFLAGS.nt += -FIXED:NO
+endif
+
+
+TEMPLATE_TSTBAREDLL = Bare bone testcase dll template
+TEMPLATE_TSTBAREDLL_EXTENDS = TSTBARE
+ifeq ($(BUILD_TARGET),win)
+ TEMPLATE_TSTBAREDLL_LDFLAGS += -Entry:DllMain
+else ifeq ($(BUILD_TARGET),darwin)
+# TEMPLATE_TSTBAREDLL_CFLAGS += -dynamiclib
+# TEMPLATE_TSTBAREDLL_LDFLAGS += -dynamiclib
+endif
+
+
+
+
+#
+# tst-0: four dlls, three of which depends on the 4th and no external dependencies.
+# The purpose of this testcase is to debug the dynamic loader without
+# messing with the native loader at all.
+#
+PROGRAMS += tst-0 tst-0-driver
+DLLS += tst-0-a tst-0-b tst-0-c tst-0-d
+
+tst-0-driver_TEMPLATE = TSTPROG
+tst-0-driver_SOURCES = tst-0-driver.c
+
+tst-0-a_TEMPLATE = TSTBAREDLL
+tst-0-a_SOURCES = tst-0-a.c tstDllMainStub.c
+tst-0-a_SOURCES.os2= tstDllMainStub-os2.asm
+
+tst-0-b_TEMPLATE = TSTBAREDLL
+tst-0-b_SOURCES = tst-0-b.c tstDllMainStub.c
+tst-0-b_SOURCES.os2= tstDllMainStub-os2.asm
+
+tst-0-c_TEMPLATE = TSTBAREDLL
+tst-0-c_SOURCES = tst-0-c.c tstDllMainStub.c
+tst-0-c_SOURCES.os2= tstDllMainStub-os2.asm
+
+tst-0-d_TEMPLATE = TSTBAREDLL
+tst-0-d_SOURCES = tst-0-d.c tstDllMainStub.c
+tst-0-d_SOURCES.os2= tstDllMainStub-os2.asm
+
+tst-0_TEMPLATE = TSTBAREPROG
+tst-0_SOURCES = tst-0.c tstExeMainStub.c
+tst-0_SOURCES.os2= tstExeMainStub-os2.asm
+
+ifeq ($(BUILD_TARGET),win)
+tst-0-driver_LIBS= $(PATH_LIB)/kLdr.lib
+tst-0-a_LIBS = $(PATH_TARGET)/tst-0-d/tst-0-d.lib
+tst-0-b_LIBS = $(PATH_TARGET)/tst-0-d/tst-0-d.lib
+tst-0-c_LIBS = $(PATH_TARGET)/tst-0-d/tst-0-d.lib
+tst-0_LIBS = $(TARGET_tst-0-a:.dll=.lib) $(TARGET_tst-0-b:.dll=.lib) $(TARGET_tst-0-c:.dll=.lib)
+else
+tst-0-driver_LIBS= $(PATH_DLL)/kLdr$(SUFF_DLL)
+tst-0-a_LIBS = $(subst -a,-d,$(TARGET_tst-0-a))
+tst-0-b_LIBS = $(subst -b,-d,$(TARGET_tst-0-b))
+tst-0-c_LIBS = $(subst -c,-d,$(TARGET_tst-0-c))
+tst-0_LIBS = $(TARGET_tst-0-a) $(TARGET_tst-0-b) $(TARGET_tst-0-c)
+endif
+
+
+#
+# tst-1: four dlls, three of which depends on the 4th and the testcase depends on those three again.
+#
+PROGRAMS += tst-1
+DLLS += tst-1-a tst-1-b tst-1-c tst-1-d
+
+tst-1-a_TEMPLATE = TSTDLL
+tst-1-a_SOURCES = tst-1-a.c tstDllMain.c
+
+tst-1-b_TEMPLATE = TSTDLL
+tst-1-b_SOURCES = tst-1-b.c tstDllMain.c
+
+tst-1-c_TEMPLATE = TSTDLL
+tst-1-c_SOURCES = tst-1-c.c tstDllMain.c
+
+tst-1-d_TEMPLATE = TSTDLL
+tst-1-d_SOURCES = tst-1-d.c tstDllMain.c
+
+tst-1_TEMPLATE = TSTPROG
+tst-1_SOURCES = tst-1.c
+
+ifeq ($(BUILD_TARGET),win)
+tst-1-a_LIBS = $(PATH_TARGET)/tst-1-d/tst-1-d.lib
+tst-1-b_LIBS = $(PATH_TARGET)/tst-1-d/tst-1-d.lib
+tst-1-c_LIBS = $(PATH_TARGET)/tst-1-d/tst-1-d.lib
+tst-1_LIBS = $(TARGET_tst-1-a:.dll=.lib) $(TARGET_tst-1-b:.dll=.lib) $(TARGET_tst-1-c:.dll=.lib)
+else
+tst-1-a_LIBS = $(subst -a,-d,$(TARGET_tst-1-a))
+tst-1-b_LIBS = $(subst -b,-d,$(TARGET_tst-1-b))
+tst-1-c_LIBS = $(subst -c,-d,$(TARGET_tst-1-c))
+tst-1_LIBS = $(TARGET_tst-1-a) $(TARGET_tst-1-b) $(TARGET_tst-1-c)
+endif
+
+
+#
+# tst-2: four dlls, three of which depends on the 1st, and the testcase depends on those all of them.
+#
+PROGRAMS += tst-2
+DLLS += tst-2-a tst-2-b tst-2-c tst-2-d
+
+tst-2-a_TEMPLATE = TSTDLL
+tst-2-a_SOURCES = tst-2-a.c tstDllMain.c
+
+tst-2-b_TEMPLATE = TSTDLL
+tst-2-b_SOURCES = tst-2-b.c tstDllMain.c
+
+tst-2-c_TEMPLATE = TSTDLL
+tst-2-c_SOURCES = tst-2-c.c tstDllMain.c
+
+tst-2-d_TEMPLATE = TSTDLL
+tst-2-d_SOURCES = tst-2-d.c tstDllMain.c
+
+tst-2_TEMPLATE = TSTPROG
+tst-2_SOURCES = tst-2.c
+
+ifeq ($(BUILD_TARGET),win)
+tst-2-b_LIBS = $(PATH_TARGET)/tst-2-a/tst-2-a.lib
+tst-2-c_LIBS = $(PATH_TARGET)/tst-2-a/tst-2-a.lib
+tst-2-d_LIBS = $(PATH_TARGET)/tst-2-a/tst-2-a.lib
+tst-2_LIBS = $(TARGET_tst-2-b:.dll=.lib) $(TARGET_tst-2-c:.dll=.lib) $(TARGET_tst-2-d:.dll=.lib) $(TARGET_tst-2-a:.dll=.lib)
+else
+tst-2-b_LIBS = $(subst -b,-a,$(TARGET_tst-2-b))
+tst-2-c_LIBS = $(subst -c,-a,$(TARGET_tst-2-c))
+tst-2-d_LIBS = $(subst -d,-a,$(TARGET_tst-2-d))
+tst-2_LIBS = $(TARGET_tst-2-a) $(TARGET_tst-2-b) $(TARGET_tst-2-c) $(TARGET_tst-2-d)
+endif
+
+
+#
+# tst-3: Single module.
+#
+PROGRAMS += tst-3-driver
+ifeq ($(BUILD_TARGET),darwin)
+SYSMODS += tst-3
+else
+DLLS += tst-3
+LIBRARIES.win += tst-3-imp
+LIBRARIES.os2 += tst-3-imp
+endif
+
+tst-3_TEMPLATE = TSTBAREDLL
+tst-3_SOURCES = tst-3.c tst-3-ext.c tstDllMainStub.c
+tst-3_SOURCES.os2= tstDllMainStub-os2.asm
+tst-3_LIBS.os2 = $(TARGET_tst-3-imp)
+tst-3_LIBS.win = $(TARGET_tst-3-imp)
+
+tst-3-imp_TEMPLATE = TSTBAREDLL
+tst-3-imp_SOURCES.win = tst-3-imp-win.def
+tst-3-imp_SOURCES.os2 = tst-3-imp-os2.def
+
+tst-3-driver_TEMPLATE = TSTPROG
+tst-3-driver_SOURCES = tst-3-driver.c
+
+ifeq ($(BUILD_TARGET),win)
+tst-3-driver_LIBS = $(PATH_LIB)/kLdr.lib
+else
+tst-3-driver_LIBS = $(PATH_DLL)/kLdr$(SUFF_DLL)
+endif
+
+
+# generate rules.
+include $(PATH_KBUILD)/subfooter.kmk
+
diff --git a/src/lib/kStuff/kLdr/testcase/bin/tst-3.dll.win.x86 b/src/lib/kStuff/kLdr/testcase/bin/tst-3.dll.win.x86
new file mode 100644
index 0000000..2a48ccb
--- /dev/null
+++ b/src/lib/kStuff/kLdr/testcase/bin/tst-3.dll.win.x86
Binary files differ
diff --git a/src/lib/kStuff/kLdr/testcase/bin/tst-3.rel.darwin.x86 b/src/lib/kStuff/kLdr/testcase/bin/tst-3.rel.darwin.x86
new file mode 100644
index 0000000..a18a919
--- /dev/null
+++ b/src/lib/kStuff/kLdr/testcase/bin/tst-3.rel.darwin.x86
Binary files differ
diff --git a/src/lib/kStuff/kLdr/testcase/tst-0-a.c b/src/lib/kStuff/kLdr/testcase/tst-0-a.c
new file mode 100644
index 0000000..a5533f2
--- /dev/null
+++ b/src/lib/kStuff/kLdr/testcase/tst-0-a.c
@@ -0,0 +1,10 @@
+#include "tst.h"
+const char *g_pszName = "a";
+
+MY_IMPORT(int) FuncD(void);
+
+MY_EXPORT(int) FuncA(void)
+{
+ return FuncD() | (g_pszName[0] == 'a' ? 0x42 : 0x0001);
+}
+
diff --git a/src/lib/kStuff/kLdr/testcase/tst-0-b.c b/src/lib/kStuff/kLdr/testcase/tst-0-b.c
new file mode 100644
index 0000000..286b179
--- /dev/null
+++ b/src/lib/kStuff/kLdr/testcase/tst-0-b.c
@@ -0,0 +1,10 @@
+#include "tst.h"
+const char *g_pszName = "b";
+
+MY_IMPORT(int) FuncD(void);
+
+MY_EXPORT(int) FuncB(void)
+{
+ return FuncD() | (g_pszName[0] == 'b' ? 0x4200 : 0x0010);
+}
+
diff --git a/src/lib/kStuff/kLdr/testcase/tst-0-c.c b/src/lib/kStuff/kLdr/testcase/tst-0-c.c
new file mode 100644
index 0000000..3c9d449
--- /dev/null
+++ b/src/lib/kStuff/kLdr/testcase/tst-0-c.c
@@ -0,0 +1,10 @@
+#include "tst.h"
+const char *g_pszName = "c";
+
+MY_IMPORT(int) FuncD(void);
+
+MY_EXPORT(int) FuncC(void)
+{
+ return FuncD() | (g_pszName[0] == 'c' ? 0x420000 : 0x0100);
+}
+
diff --git a/src/lib/kStuff/kLdr/testcase/tst-0-d.c b/src/lib/kStuff/kLdr/testcase/tst-0-d.c
new file mode 100644
index 0000000..a5501b0
--- /dev/null
+++ b/src/lib/kStuff/kLdr/testcase/tst-0-d.c
@@ -0,0 +1,8 @@
+#include "tst.h"
+const char *g_pszName = "d";
+
+MY_EXPORT(int) FuncD(void)
+{
+ return g_pszName[0] == 'd' ? 0x42000000 : 0x1000;
+}
+
diff --git a/src/lib/kStuff/kLdr/testcase/tst-0-driver.c b/src/lib/kStuff/kLdr/testcase/tst-0-driver.c
new file mode 100644
index 0000000..be304d5
--- /dev/null
+++ b/src/lib/kStuff/kLdr/testcase/tst-0-driver.c
@@ -0,0 +1,502 @@
+/* $Id: tst-0-driver.c 29 2009-07-01 20:30:29Z bird $ */
+/** @file
+ * kLdr - Dynamic Loader testcase no. 0, Driver.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include "tst.h"
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+/*******************************************************************************
+* Defined Constants And Macros *
+*******************************************************************************/
+/** Select the appropriate KLDRSYMKIND bit define. */
+#define MY_KLDRSYMKIND_BITS ( sizeof(void *) == 4 ? KLDRSYMKIND_32BIT : KLDRSYMKIND_64BIT )
+
+
+/*******************************************************************************
+* Global Variables *
+*******************************************************************************/
+/** The numbers of errors. */
+static int g_cErrors = 0;
+
+
+
+/**
+ * Report failure.
+ */
+static int Failure(const char *pszFormat, ...)
+{
+ va_list va;
+
+ g_cErrors++;
+
+ printf("tst-0-driver: ");
+ va_start(va, pszFormat);
+ vprintf(pszFormat, va);
+ va_end(va);
+ printf("\n");
+ return 1;
+}
+
+
+int main(int argc, char **argv)
+{
+ const char *pszErrInit = "Error, szErr wasn't zapped";
+ char szErr[512];
+ char szBuf[512];
+ char *psz;
+ KSIZE cch;
+ HKLDRMOD hMod;
+ int rc;
+
+ /*
+ * The first thing to do is a simple load / unload test
+ * using the tst-0-a library (it'll drag in tst-0-d).
+ */
+ printf("tst-0-driver: Basic API test using 'tst-0-a'...\n");
+ hMod = (HKLDRMOD)0xffffeeee;
+ strcpy(szErr, pszErrInit);
+ rc = kLdrDyldLoad("tst-0-a", NULL, NULL, KLDRDYLD_SEARCH_HOST,
+ KLDRDYLD_LOAD_FLAGS_RECURSIVE_INIT, &hMod, szErr, sizeof(szErr));
+ if (rc)
+ Failure("kLdrDyldLoad(\"tst-0\",...) failed, rc=%d (%#x). szErr='%s'.\n", rc, rc, szErr);
+ if (!strcmp(szErr, pszErrInit))
+ Failure("szErr wasn't set.\n");
+ if (hMod == (HKLDRMOD)0xffffeeee)
+ Failure("hMod wasn't set.\n");
+ if (hMod == NIL_HKLDRMOD && !rc)
+ Failure("rc=0 but hMod=NIL_HKLDRMOD\n");
+ if (!rc)
+ {
+ HKLDRMOD hMod2;
+ HKLDRMOD hMod3;
+ printf("tst-0-driver: hMod=%p ('tst-0-a')\n", (void *)hMod);
+
+ /*
+ * Simple test of kLdrDyldFindByName.
+ */
+ hMod2 = (HKLDRMOD)0xffffeeee;
+ rc = kLdrDyldFindByName("tst-0", NULL, NULL, KLDRDYLD_SEARCH_HOST, 0, &hMod2);
+ if (!rc)
+ Failure("kLdrDyldFindByName(\"tst-0\",,,) didn't fail!\n");
+ if (rc && hMod2 != NIL_HKLDRMOD)
+ Failure("hMod2 wasn't set correctly on kLdrDyldFindByName failure!\n");
+
+ hMod2 = (HKLDRMOD)0xffffeeee;
+ rc = kLdrDyldFindByName("tst-0-a", NULL, NULL, KLDRDYLD_SEARCH_HOST, 0, &hMod2);
+ if (rc)
+ Failure("kLdrDyldFindByName(\"tst-0-a\",,,) failed, rc=%d (%#x)\n", rc, rc);
+ if (!rc && hMod2 != hMod)
+ Failure("kLdrDyldFindByName(\"tst-0-a\",,,) returned the wrong module handle: %p instead of %p\n",
+ (void *)hMod2, (void *)hMod);
+
+ hMod2 = (HKLDRMOD)0xffffeeee;
+ rc = kLdrDyldFindByName("tst-0-d", NULL, NULL, KLDRDYLD_SEARCH_HOST, 0, &hMod2);
+ if (!rc)
+ printf("tst-0-driver: hMod2=%p ('tst-0-d')\n", (void *)hMod2);
+ else
+ Failure("kLdrDyldFindByName(\"tst-0-d\",,,) failed, rc=%d (%#x)\n", rc, rc);
+
+ /*
+ * Get the name and filename for each of the two modules.
+ */
+ rc = kLdrDyldGetName(hMod2, szBuf, sizeof(szBuf));
+ if (!rc)
+ {
+ printf("tst-0-driver: name: '%s' ('tst-0-d')\n", szBuf);
+ psz = strstr(szBuf, "-0-");
+ if ( !psz
+ || strnicmp(psz, "-0-d", sizeof("-0-d") - 1))
+ Failure("kLdrDyldGetName(\"tst-0-d\",,,) -> '%s': pattern '-0-d' not found\n", szBuf);
+
+ /* overflow test. */
+ cch = strlen(szBuf);
+ szBuf[cch + 1] = szBuf[cch] = szBuf[cch - 1] = 'x';
+ szBuf[cch + 2] = '\0';
+ rc = kLdrDyldGetName(hMod2, szBuf, cch);
+ if (rc == KERR_BUFFER_OVERFLOW)
+ {
+ if (!szBuf[0])
+ Failure("kLdrDyldGetName didn't return partial result on overflow\n");
+ else if (szBuf[cch - 1])
+ Failure("kLdrDyldGetName didn't terminate partial result correctly overflow: '%s'\n", szBuf);
+ else if (szBuf[cch] != 'x')
+ Failure("kLdrDyldGetName exceeded the buffer limit on partial overflow: '%s'\n", szBuf);
+ }
+ else
+ Failure("kLdrDyldGetName(\"tst-0-d\",,,) -> rc=%d (%#x) instead of KERR_BUFFER_OVERFLOW\n", rc, rc);
+
+ /* check that we can query the module by the returned name. */
+ rc = kLdrDyldGetName(hMod2, szBuf, sizeof(szBuf));
+ if (!rc)
+ {
+ hMod3 = (HKLDRMOD)0xffffeeee;
+ rc = kLdrDyldFindByName(szBuf, NULL, NULL, KLDRDYLD_SEARCH_HOST, 0, &hMod3);
+ if (rc || hMod3 != hMod2)
+ Failure("kLdrDyldFindByName(\"%s\",,,) failed, rc=%d (%#x) hMod3=%p hMod2=%p\n",
+ szBuf, rc, rc, (void *)hMod3, (void *)hMod2);
+ }
+ else
+ Failure("kLdrDyldGetName(\"tst-0-d\",,,) failed (b), rc=%d (%#x)\n", rc, rc);
+ }
+ else
+ Failure("kLdrDyldGetName(\"tst-0-d\",,,) failed, rc=%d (%#x)\n", rc, rc);
+
+ rc = kLdrDyldGetFilename(hMod2, szBuf, sizeof(szBuf));
+ if (!rc)
+ {
+ printf("tst-0-driver: filename: '%s' ('tst-0-d')\n", szBuf);
+
+ /* overflow test. */
+ cch = strlen(szBuf);
+ szBuf[cch + 1] = szBuf[cch] = szBuf[cch - 1] = 'x';
+ szBuf[cch + 2] = '\0';
+ rc = kLdrDyldGetFilename(hMod2, szBuf, cch);
+ if (rc == KERR_BUFFER_OVERFLOW)
+ {
+ if (!szBuf[0])
+ Failure("kLdrDyldGetFilename didn't return partial result on overflow\n");
+ else if (szBuf[cch - 1])
+ Failure("kLdrDyldGetFilename didn't terminate partial result correctly overflow: '%s'\n", szBuf);
+ else if (szBuf[cch] != 'x')
+ Failure("kLdrDyldGetFilename exceeded the buffer limit on partial overflow: '%s'\n", szBuf);
+ }
+ else
+ Failure("kLdrDyldGetFilename(\"tst-0-d\",,,) -> rc=%d (%#x) instead of KERR_BUFFER_OVERFLOW\n", rc, rc);
+
+ /* check that we can query the module by the returned filename. */
+ rc = kLdrDyldGetFilename(hMod2, szBuf, sizeof(szBuf));
+ if (!rc)
+ {
+ hMod3 = (HKLDRMOD)0xffffeeee;
+ rc = kLdrDyldFindByName(szBuf, NULL, NULL, KLDRDYLD_SEARCH_HOST, 0, &hMod3);
+ if (rc || hMod3 != hMod2)
+ Failure("kLdrDyldFindByName(\"%s\",,,) failed, rc=%d (%#x) hMod3=%p hMod2=%p\n",
+ szBuf, rc, rc, (void *)hMod3, (void *)hMod2);
+ }
+ else
+ Failure("kLdrDyldGetName(\"tst-0-d\",,,) failed (b), rc=%d (%#x)\n", rc, rc);
+ }
+ else
+ Failure("kLdrDyldGetFilename(\"tst-0-d\",,,) failed, rc=%d (%#x)\n", rc, rc);
+
+ /* the other module */
+ rc = kLdrDyldGetName(hMod, szBuf, sizeof(szBuf));
+ if (!rc)
+ {
+ printf("tst-0-driver: name: '%s' ('tst-0-a')\n", szBuf);
+ psz = strstr(szBuf, "-0-");
+ if ( !psz
+ || strnicmp(psz, "-0-a", sizeof("-0-a") - 1))
+ Failure("kLdrDyldGetName(\"tst-0-a\",,,) -> '%s': pattern '-0-a' not found\n", szBuf);
+
+ /* check that we can query the module by the returned name. */
+ hMod3 = (HKLDRMOD)0xffffeeee;
+ rc = kLdrDyldFindByName(szBuf, NULL, NULL, KLDRDYLD_SEARCH_HOST, 0, &hMod3);
+ if (rc || hMod3 != hMod)
+ Failure("kLdrDyldFindByName(\"%s\",,,) failed, rc=%d (%#x) hMod3=%p hMod=%p\n",
+ szBuf, rc, rc, (void *)hMod3, (void *)hMod);
+ }
+ else
+ Failure("kLdrDyldGetName(\"tst-0-a\",,,) failed, rc=%d (%#x)\n", rc, rc);
+
+ rc = kLdrDyldGetFilename(hMod, szBuf, sizeof(szBuf));
+ if (!rc)
+ {
+ printf("tst-0-driver: filename: '%s' ('tst-0-a')\n", szBuf);
+
+ /* check that we can query the module by the returned filename. */
+ hMod3 = (HKLDRMOD)0xffffeeee;
+ rc = kLdrDyldFindByName(szBuf, NULL, NULL, KLDRDYLD_SEARCH_HOST, 0, &hMod3);
+ if (rc || hMod3 != hMod)
+ Failure("kLdrDyldFindByName(\"%s\",,,) failed, rc=%d (%#x) hMod3=%p hMod=%p\n",
+ szBuf, rc, rc, (void *)hMod3, (void *)hMod);
+ }
+ else
+ Failure("kLdrDyldGetFilename(\"tst-0-a\",,,) failed, rc=%d (%#x)\n", rc, rc);
+
+
+ /*
+ * Resolve the symbol exported by each of the two modules and call them.
+ */
+ if (!g_cErrors)
+ {
+ KUPTR uValue;
+ KU32 fKind;
+
+ fKind = 0xffeeffee;
+ uValue = ~(KUPTR)42;
+ rc = kLdrDyldQuerySymbol(hMod, NIL_KLDRMOD_SYM_ORDINAL, MY_NAME("FuncA"), NULL, &uValue, &fKind);
+ if (!rc)
+ {
+ if (uValue == ~(KUPTR)42)
+ Failure("kLdrDyldQuerySymbol(\"tst-0-a\",,\"FuncA\",): uValue wasn't set.\n");
+ if (fKind == 0xffeeffee)
+ Failure("kLdrDyldQuerySymbol(\"tst-0-a\",,\"FuncA\",): fKind wasn't set.\n");
+ if ( (fKind & KLDRSYMKIND_BIT_MASK) != KLDRSYMKIND_NO_BIT
+ && (fKind & KLDRSYMKIND_BIT_MASK) != MY_KLDRSYMKIND_BITS)
+ Failure("fKind=%#x indicates a different code 'bit' mode than we running at.\n", fKind);
+ if ( (fKind & KLDRSYMKIND_TYPE_MASK) != KLDRSYMKIND_NO_TYPE
+ && (fKind & KLDRSYMKIND_TYPE_MASK) != KLDRSYMKIND_CODE)
+ Failure("fKind=%#x indicates that \"FuncA\" isn't code.\n", fKind);
+ if (fKind & KLDRSYMKIND_FORWARDER)
+ Failure("fKind=%#x indicates that \"FuncA\" is a forwarder. it isn't.\n", fKind);
+
+ /* call it. */
+ if (!g_cErrors)
+ {
+ int (*pfnFuncA)(void) = (int (*)(void))uValue;
+ rc = pfnFuncA();
+ if (rc != 0x42000042)
+ Failure("FuncA returned %#x expected 0x42000042\n", rc);
+ }
+
+ /*
+ * Test kLdrDyldFindByAddress now that we've got an address.
+ */
+ hMod3 = (HKLDRMOD)0xeeeeffff;
+ rc = kLdrDyldFindByAddress(uValue, &hMod3, NULL, NULL);
+ if (!rc)
+ {
+ KUPTR offSegment;
+ KU32 iSegment;
+
+ if (hMod3 != hMod)
+ Failure("kLdrDyldFindByAddress(%#p/*FuncA*/, \"tst-0-a\",,,) return incorrect hMod3=%p instead of %p.\n",
+ uValue, hMod3, hMod);
+
+ hMod3 = (HKLDRMOD)0xeeeeffff;
+ iSegment = 0x42424242;
+ rc = kLdrDyldFindByAddress(uValue, &hMod3, &iSegment, &offSegment);
+ if (!rc)
+ {
+ if (hMod3 != hMod)
+ Failure("Bad hMod3 on 2nd kLdrDyldFindByAddress call.\n");
+ if (iSegment > 0x1000) /* safe guess */
+ Failure("Bad iSegment=%#x\n", iSegment);
+ if (offSegment > 0x100000) /* guesswork */
+ Failure("Bad offSegment=%p\n", (void *)offSegment);
+ }
+ else
+ Failure("kLdrDyldFindByAddress(%#p/*FuncA*/, \"tst-0-a\",,,) failed (b), rc=%d (%#x)\n",
+ uValue, rc, rc);
+
+ /* negative test */
+ hMod3 = (HKLDRMOD)0xeeeeffff;
+ iSegment = 0x42424242;
+ offSegment = 0x87654321;
+ rc = kLdrDyldFindByAddress(~(KUPTR)16, &hMod3, &iSegment, &offSegment);
+ if (!rc)
+ Failure("negative kLdrDyldFindByAddress test returned successfully!\n");
+ if (iSegment != ~(KU32)0)
+ Failure("negative kLdrDyldFindByAddress: bad iSegment=%#x\n", iSegment);
+ if (offSegment != ~(KUPTR)0)
+ Failure("negative kLdrDyldFindByAddress: bad offSegment=%p\n", (void *)offSegment);
+ if (hMod3 != NIL_HKLDRMOD)
+ Failure("negative kLdrDyldFindByAddress: bad hMod3=%p\n", (void *)hMod3);
+ }
+ else
+ Failure("kLdrDyldFindByAddress(%#p/*FuncA*/, \"tst-0-a\",,,) failed, rc=%d (%#x)\n",
+ uValue, rc, rc);
+ }
+ else
+ Failure("kLdrDyldQuerySymbol(\"tst-0-a\",,\"FuncA\",) failed, rc=%d (%#x)\n", rc, rc);
+
+ fKind = 0xffeeffee;
+ uValue = ~(KUPTR)42;
+ rc = kLdrDyldQuerySymbol(hMod2, NIL_KLDRMOD_SYM_ORDINAL, MY_NAME("FuncD"), NULL, &uValue, &fKind);
+ if (!rc)
+ {
+ if (uValue == ~(KUPTR)42)
+ Failure("kLdrDyldQuerySymbol(\"tst-0-d\",,\"FuncD\",): uValue wasn't set.\n");
+ if (fKind == 0xffeeffee)
+ Failure("kLdrDyldQuerySymbol(\"tst-0-d\",,\"FuncD\",): fKind wasn't set.\n");
+ if ( (fKind & KLDRSYMKIND_BIT_MASK) != KLDRSYMKIND_NO_BIT
+ && (fKind & KLDRSYMKIND_BIT_MASK) != MY_KLDRSYMKIND_BITS)
+ Failure("fKind=%#x indicates a different code 'bit' mode than we running at.\n", fKind);
+ if ( (fKind & KLDRSYMKIND_TYPE_MASK) != KLDRSYMKIND_NO_TYPE
+ && (fKind & KLDRSYMKIND_TYPE_MASK) != KLDRSYMKIND_CODE)
+ Failure("fKind=%#x indicates that \"FuncD\" isn't code.\n", fKind);
+ if (fKind & KLDRSYMKIND_FORWARDER)
+ Failure("fKind=%#x indicates that \"FuncD\" is a forwarder. it isn't.\n", fKind);
+
+ /* call it. */
+ if (!g_cErrors)
+ {
+ int (*pfnFuncD)(void) = (int (*)(void))uValue;
+ rc = pfnFuncD();
+ if (rc != 0x42000000)
+ Failure("FuncD returned %#x expected 0x42000000\n", rc);
+ }
+
+ /* use the address to get the module handle. */
+ hMod3 = (HKLDRMOD)0xeeeeffff;
+ rc = kLdrDyldFindByAddress(uValue, &hMod3, NULL, NULL);
+ if (!rc)
+ {
+ if (hMod3 != hMod2)
+ Failure("kLdrDyldFindByAddress(%#p/*FuncD*/,,,) return incorrect hMod3=%p instead of %p.\n",
+ uValue, hMod3, hMod2);
+ }
+ else
+ Failure("kLdrDyldFindByAddress(%#p/*FuncD*/,,,) failed, rc=%d (%#x)\n",
+ uValue, rc, rc);
+ }
+ else
+ Failure("kLdrDyldQuerySymbol(\"tst-0-a\",,\"FuncA\",) failed, rc=%d (%#x)\n", rc, rc);
+
+ }
+
+ /*
+ * Finally unload it.
+ */
+ rc = kLdrDyldUnload(hMod);
+ if (rc)
+ Failure("kLdrDyldUnload() failed. rc=%d (%#x)\n", rc, rc);
+ if (!rc)
+ {
+ rc = kLdrDyldFindByName("tst-0-d", NULL, NULL, KLDRDYLD_SEARCH_HOST, 0, &hMod2);
+ if (rc != KLDR_ERR_MODULE_NOT_FOUND)
+ Failure("kLdrDyldFindByName(\"tst-0-d\",,,) return rc=%d (%#x), expected KLDR_ERR_MODULE_NOT_FOUND\n", rc, rc);
+
+ rc = kLdrDyldFindByName("tst-0-a", NULL, NULL, KLDRDYLD_SEARCH_HOST, 0, &hMod2);
+ if (rc != KLDR_ERR_MODULE_NOT_FOUND)
+ Failure("kLdrDyldFindByName(\"tst-0-a\",,,) return rc=%d (%#x), expected KLDR_ERR_MODULE_NOT_FOUND\n", rc, rc);
+ }
+ }
+
+ /*
+ * Now do what tst-0 would do; load the three dlls, resolve and call their functions.
+ */
+ if (!g_cErrors)
+ {
+ HKLDRMOD hModA;
+ int (*pfnFuncA)(void);
+ HKLDRMOD hModB;
+ int (*pfnFuncB)(void);
+ HKLDRMOD hModC;
+ int (*pfnFuncC)(void);
+ KUPTR uValue;
+
+ rc = kLdrDyldLoad("tst-0-a", NULL, NULL, KLDRDYLD_SEARCH_HOST, 0, &hModA, NULL, 0);
+ if (rc)
+ Failure("kLdrDyldLoad(\"tst-0-a\",,,,) -> %d (%#x)\n", rc, rc);
+ if (!rc)
+ {
+ rc = kLdrDyldLoad("tst-0-b", NULL, NULL, KLDRDYLD_SEARCH_HOST, 0, &hModB, szErr, sizeof(szErr));
+ if (rc)
+ Failure("kLdrDyldLoad(\"tst-0-b\",,,,) -> %d (%#x) szErr='%s'\n", rc, rc, szErr);
+ }
+ if (!rc)
+ {
+ rc = kLdrDyldLoad("tst-0-c", NULL, NULL, KLDRDYLD_SEARCH_HOST, 0, &hModC, szErr, sizeof(szErr));
+ if (rc)
+ Failure("kLdrDyldLoad(\"tst-0-c\",,,,) -> %d (%#x) szErr='%s'\n", rc, rc, szErr);
+ }
+ if (!rc)
+ {
+ rc = kLdrDyldQuerySymbol(hModA, NIL_KLDRMOD_SYM_ORDINAL, MY_NAME("FuncA"), NULL, &uValue, NULL);
+ if (!rc)
+ pfnFuncA = (int (*)(void))uValue;
+ else
+ Failure("kLdrDyldQuerySymbol(,,\"FuncA\",,) -> %d (%#x)\n", rc, rc);
+ }
+ if (!rc)
+ {
+ rc = kLdrDyldQuerySymbol(hModB, NIL_KLDRMOD_SYM_ORDINAL, MY_NAME("FuncB"), NULL, &uValue, NULL);
+ if (!rc)
+ pfnFuncB = (int (*)(void))uValue;
+ else
+ Failure("kLdrDyldQuerySymbol(,,\"FuncB\",,) -> %d (%#x)\n", rc, rc);
+ }
+ if (!rc)
+ {
+ rc = kLdrDyldQuerySymbol(hModC, NIL_KLDRMOD_SYM_ORDINAL, MY_NAME("FuncC"), NULL, &uValue, NULL);
+ if (!rc)
+ pfnFuncC = (int (*)(void))uValue;
+ else
+ Failure("kLdrDyldQuerySymbol(,,\"FuncA\",,) -> %d (%#x)\n", rc, rc);
+ }
+ if (!rc)
+ {
+ int u = pfnFuncA() | pfnFuncB() | pfnFuncC();
+ if (u == 0x42424242)
+ printf("tst-0-driver: FuncA/B/C => %#x (correct)\n", u);
+ else
+ Failure("FuncA/B/C => %#x\n", u);
+
+ rc = kLdrDyldUnload(hModA);
+ if (rc)
+ Failure("Unload A failed, rc=%d (%#x)\n", rc, rc);
+ u = pfnFuncB() | pfnFuncC();
+ if (u != 0x42424200)
+ Failure("FuncB/C returns %#x instead of 0x42424200 after unloading A\n", u);
+
+ rc = kLdrDyldUnload(hModB);
+ if (rc)
+ Failure("Unload B failed, rc=%d (%#x)\n", rc, rc);
+ u = pfnFuncC();
+ if (u != 0x42420000)
+ Failure("FuncC returns %#x instead of 0x42420000 after unloading A\n", u);
+
+ rc = kLdrDyldUnload(hModC);
+ if (rc)
+ Failure("Unload C failed, rc=%d (%#x)\n", rc, rc);
+
+ rc = kLdrDyldFindByName("tst-0-d", NULL, NULL, KLDRDYLD_SEARCH_HOST, 0, &hMod);
+ if (rc != KLDR_ERR_MODULE_NOT_FOUND)
+ Failure("Query for \"tst-0-d\" after unloading A,B and C returns rc=%d (%#x) instead of KLDR_ERR_MODULE_NOT_FOUND\n",
+ rc, rc);
+ }
+ }
+
+ /*
+ * Now invoke the executable stub which launches the tst-0 program.
+ */
+ if (!g_cErrors)
+ {
+ /// @todo
+ }
+
+ /*
+ * Summary
+ */
+ if (!g_cErrors)
+ printf("tst-0-driver: SUCCESS\n");
+ else
+ printf("tst-0-driver: FAILURE - %d errors\n", g_cErrors);
+ return !!g_cErrors;
+}
+
diff --git a/src/lib/kStuff/kLdr/testcase/tst-0.c b/src/lib/kStuff/kLdr/testcase/tst-0.c
new file mode 100644
index 0000000..d19c35c
--- /dev/null
+++ b/src/lib/kStuff/kLdr/testcase/tst-0.c
@@ -0,0 +1,13 @@
+#include "tst.h"
+
+MY_IMPORT(int) FuncA(void);
+MY_IMPORT(int) FuncB(void);
+MY_IMPORT(int) FuncC(void);
+
+int main()
+{
+ unsigned u;
+ u = FuncA() | FuncB() | FuncC();
+ return u == 0x42424242 ? 0 : 1;
+}
+
diff --git a/src/lib/kStuff/kLdr/testcase/tst-1-a.c b/src/lib/kStuff/kLdr/testcase/tst-1-a.c
new file mode 100644
index 0000000..d554112
--- /dev/null
+++ b/src/lib/kStuff/kLdr/testcase/tst-1-a.c
@@ -0,0 +1,10 @@
+#include "tst.h"
+const char *g_pszName = "a";
+
+MY_IMPORT(int) FuncD(void);
+
+MY_EXPORT(int) FuncA(void)
+{
+ return FuncD();
+}
+
diff --git a/src/lib/kStuff/kLdr/testcase/tst-1-b.c b/src/lib/kStuff/kLdr/testcase/tst-1-b.c
new file mode 100644
index 0000000..5156e58
--- /dev/null
+++ b/src/lib/kStuff/kLdr/testcase/tst-1-b.c
@@ -0,0 +1,10 @@
+#include "tst.h"
+const char *g_pszName = "b";
+
+MY_IMPORT(int) FuncD(void);
+
+MY_EXPORT(int) FuncB(void)
+{
+ return FuncD();
+}
+
diff --git a/src/lib/kStuff/kLdr/testcase/tst-1-c.c b/src/lib/kStuff/kLdr/testcase/tst-1-c.c
new file mode 100644
index 0000000..c40f55d
--- /dev/null
+++ b/src/lib/kStuff/kLdr/testcase/tst-1-c.c
@@ -0,0 +1,10 @@
+#include "tst.h"
+const char *g_pszName = "c";
+
+MY_IMPORT(int) FuncD(void);
+
+MY_EXPORT(int) FuncC(void)
+{
+ return FuncD();
+}
+
diff --git a/src/lib/kStuff/kLdr/testcase/tst-1-d.c b/src/lib/kStuff/kLdr/testcase/tst-1-d.c
new file mode 100644
index 0000000..ab8bf93
--- /dev/null
+++ b/src/lib/kStuff/kLdr/testcase/tst-1-d.c
@@ -0,0 +1,8 @@
+#include "tst.h"
+const char *g_pszName = "d";
+
+MY_EXPORT(int) FuncD(void)
+{
+ return 0;
+}
+
diff --git a/src/lib/kStuff/kLdr/testcase/tst-1.c b/src/lib/kStuff/kLdr/testcase/tst-1.c
new file mode 100644
index 0000000..58b9770
--- /dev/null
+++ b/src/lib/kStuff/kLdr/testcase/tst-1.c
@@ -0,0 +1,15 @@
+#include "tst.h"
+#include <stdio.h>
+
+MY_IMPORT(int) FuncA(void);
+MY_IMPORT(int) FuncB(void);
+MY_IMPORT(int) FuncC(void);
+
+int main()
+{
+ printf("graph:\n"
+ " tst-1 -> a -> d\n"
+ " b -> d\n"
+ " c -> d\n");
+ return FuncA() + FuncB() + FuncC();
+}
diff --git a/src/lib/kStuff/kLdr/testcase/tst-2-a.c b/src/lib/kStuff/kLdr/testcase/tst-2-a.c
new file mode 100644
index 0000000..274f92e
--- /dev/null
+++ b/src/lib/kStuff/kLdr/testcase/tst-2-a.c
@@ -0,0 +1,8 @@
+#include "tst.h"
+const char *g_pszName = "a";
+
+MY_EXPORT(int) FuncA(void)
+{
+ return 0;
+}
+
diff --git a/src/lib/kStuff/kLdr/testcase/tst-2-b.c b/src/lib/kStuff/kLdr/testcase/tst-2-b.c
new file mode 100644
index 0000000..63c2c58
--- /dev/null
+++ b/src/lib/kStuff/kLdr/testcase/tst-2-b.c
@@ -0,0 +1,10 @@
+#include "tst.h"
+const char *g_pszName = "b";
+
+MY_IMPORT(int) FuncA(void);
+
+MY_EXPORT(int) FuncB(void)
+{
+ return FuncA();
+}
+
diff --git a/src/lib/kStuff/kLdr/testcase/tst-2-c.c b/src/lib/kStuff/kLdr/testcase/tst-2-c.c
new file mode 100644
index 0000000..29ab68f
--- /dev/null
+++ b/src/lib/kStuff/kLdr/testcase/tst-2-c.c
@@ -0,0 +1,10 @@
+#include "tst.h"
+const char *g_pszName = "c";
+
+MY_IMPORT(int) FuncA(void);
+
+MY_EXPORT(int) FuncC(void)
+{
+ return FuncA();
+}
+
diff --git a/src/lib/kStuff/kLdr/testcase/tst-2-d.c b/src/lib/kStuff/kLdr/testcase/tst-2-d.c
new file mode 100644
index 0000000..34efd0a
--- /dev/null
+++ b/src/lib/kStuff/kLdr/testcase/tst-2-d.c
@@ -0,0 +1,10 @@
+#include "tst.h"
+const char *g_pszName = "d";
+
+MY_IMPORT(int) FuncA(void);
+
+MY_EXPORT(int) FuncD(void)
+{
+ return FuncA();
+}
+
diff --git a/src/lib/kStuff/kLdr/testcase/tst-2.c b/src/lib/kStuff/kLdr/testcase/tst-2.c
new file mode 100644
index 0000000..6110a4b
--- /dev/null
+++ b/src/lib/kStuff/kLdr/testcase/tst-2.c
@@ -0,0 +1,16 @@
+#include "tst.h"
+
+MY_IMPORT(int) FuncA(void);
+MY_IMPORT(int) FuncB(void);
+MY_IMPORT(int) FuncC(void);
+MY_IMPORT(int) FuncD(void);
+
+int main()
+{
+ printf("graph:\n"
+ " tst-2 -> b -> a\n"
+ " c -> a\n"
+ " d -> a\n"
+ " a\n");
+ return FuncA() + FuncB() + FuncC() + FuncD();
+}
diff --git a/src/lib/kStuff/kLdr/testcase/tst-3-driver.c b/src/lib/kStuff/kLdr/testcase/tst-3-driver.c
new file mode 100644
index 0000000..483a585
--- /dev/null
+++ b/src/lib/kStuff/kLdr/testcase/tst-3-driver.c
@@ -0,0 +1,216 @@
+/* $Id: tst-3-driver.c 29 2009-07-01 20:30:29Z bird $ */
+/** @file
+ * kLdr - Dynamic Loader testcase no. 3, Driver.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include "tst.h"
+#include <k/kErr.h>
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#ifdef _MSC_VER
+# include <malloc.h>
+#endif
+
+
+/*******************************************************************************
+* Defined Constants And Macros *
+*******************************************************************************/
+/** Select the appropriate KLDRSYMKIND bit define. */
+#define MY_KLDRSYMKIND_BITS ( sizeof(void *) == 4 ? KLDRSYMKIND_32BIT : KLDRSYMKIND_64BIT )
+
+
+/*******************************************************************************
+* Global Variables *
+*******************************************************************************/
+/** The numbers of errors. */
+static int g_cErrors = 0;
+
+
+/**
+ * Report failure.
+ */
+static int Failure(const char *pszFormat, ...)
+{
+ va_list va;
+
+ g_cErrors++;
+
+ printf("tst-3-driver: ");
+ va_start(va, pszFormat);
+ vprintf(pszFormat, va);
+ va_end(va);
+ printf("\n");
+ return 1;
+}
+
+
+/**
+ * External symbol used by the testcase module.
+ */
+static int Tst3Ext(int iFortyTwo)
+{
+ if (iFortyTwo != 42)
+ return 256;
+ return 42;
+}
+
+
+/**
+ * Callback for resolving the Tst3Ext import.
+ */
+static int GetImport(PKLDRMOD pMod, KU32 iImport, KU32 iSymbol, const char *pchSymbol, KSIZE cchSymbol,
+ const char *pszVersion, PKLDRADDR puValue, KU32 *pfKind, void *pvUser)
+{
+ if (*pfKind != KLDRSYMKIND_REQ_FLAT)
+ return -1;
+
+ if ( !strncmp(pchSymbol, "Tst3Ext", strlen("Tst3Ext"))
+ || !strncmp(pchSymbol, "_Tst3Ext", strlen("_Tst3Ext")))
+ {
+ *puValue = (KUPTR)&Tst3Ext;
+ *pfKind = KLDRSYMKIND_CODE | (sizeof(pfKind) == 4 ? KLDRSYMKIND_32BIT : KLDRSYMKIND_64BIT);
+ return 0;
+ }
+
+ return -2;
+}
+
+
+/**
+ * Performs the tests on one module.
+ * @returns non sense.
+ */
+int TestModule(const char *pszFile)
+{
+ PKLDRMOD pMod;
+ KLDRSIZE cbImage;
+ void *pvBits;
+ int rc;
+
+ printf("tst-3-driver: testing '%s'...\n", pszFile);
+
+ /* open it. */
+ rc = kLdrModOpen(pszFile, &pMod);
+ if (rc)
+ return Failure("kLdrModOpen(%s,) -> %#d (%s)\n", pszFile, rc, kErrName(rc));
+
+ /* get bits. */
+ cbImage = kLdrModSize(pMod);
+ pvBits = malloc((KSIZE)cbImage + 0xfff);
+ if (pvBits)
+ {
+ void *pvBits2 = (void *)( ((KUPTR)pvBits + 0xfff) & ~(KUPTR)0xfff );
+
+ KLDRADDR BaseAddress = (KUPTR)pvBits2;
+ rc = kLdrModGetBits(pMod, pvBits2, BaseAddress, GetImport, NULL);
+ if (!rc)
+ {
+ KLDRADDR EntryPoint;
+
+ /* call into it */
+ rc = kLdrModQuerySymbol(pMod, pvBits2, BaseAddress, NIL_KLDRMOD_SYM_ORDINAL, "_Tst3", strlen("_Tst3"), NULL, NULL, NULL,
+ &EntryPoint, NULL);
+ if (rc == KLDR_ERR_SYMBOL_NOT_FOUND)
+ rc = kLdrModQuerySymbol(pMod, pvBits2, BaseAddress, NIL_KLDRMOD_SYM_ORDINAL, "Tst3", strlen("Tst3"), NULL, NULL, NULL,
+ &EntryPoint, NULL);
+ if (!rc)
+ {
+ int (*pfnEntryPoint)(int) = (int (*)(int)) ((KUPTR)EntryPoint);
+ rc = pfnEntryPoint(42);
+ if (rc == 42)
+ {
+ /* relocate twice and try again. */
+ rc = kLdrModRelocateBits(pMod, pvBits2, BaseAddress + 0x22000, BaseAddress, GetImport, NULL);
+ if (!rc)
+ {
+ rc = kLdrModRelocateBits(pMod, pvBits2, BaseAddress, BaseAddress + 0x22000, GetImport, NULL);
+ if (!rc)
+ {
+ rc = pfnEntryPoint(42);
+ if (rc == 42)
+ {
+ printf("tst-3-driver: success.\n");
+ }
+ else
+ Failure("pfnEntryPoint(42) -> %d (2nd)\n", rc);
+ }
+ else
+ Failure("kLdrModRelocateBits(,,, + 0x22000,,,) -> %#x (%s)\n", rc, kErrName(rc));
+ }
+ else
+ Failure("kLdrModRelocateBits(,, + 0x22000,,,,) -> %#x (%s)\n", rc, kErrName(rc));
+ }
+ else
+ Failure("pfnEntryPoint(42) -> %d (1st)\n", rc);
+ }
+ else
+ Failure("kLdrModQuerySymbol -> %#x (%s)\n", rc, kErrName(rc));
+ }
+ else
+ Failure("kLdrModGetBits -> %#x (%s)\n", rc, kErrName(rc));
+ free(pvBits);
+ }
+ else
+ Failure("malloc(%lx) -> NULL\n", (long)cbImage);
+
+ /* clean up */
+ rc = kLdrModClose(pMod);
+ if (rc)
+ Failure("kLdrModOpen(%s,) -> %#x (%s)\n", pszFile, rc, kErrName(rc));
+ return 0;
+}
+
+
+int main(int argc, char **argv)
+{
+ int i;
+
+ /*
+ * Test all the given modules (requires arguments).
+ */
+ for (i = 1; i < argc; i++)
+ {
+ TestModule(argv[i]);
+ }
+
+
+ /*
+ * Summary
+ */
+ if (!g_cErrors)
+ printf("tst-3-driver: SUCCESS\n");
+ else
+ printf("tst-3-driver: FAILURE - %d errors\n", g_cErrors);
+ return !!g_cErrors;
+}
diff --git a/src/lib/kStuff/kLdr/testcase/tst-3-ext.c b/src/lib/kStuff/kLdr/testcase/tst-3-ext.c
new file mode 100644
index 0000000..2b4c839
--- /dev/null
+++ b/src/lib/kStuff/kLdr/testcase/tst-3-ext.c
@@ -0,0 +1,39 @@
+/* $Id: tst-3-ext.c 29 2009-07-01 20:30:29Z bird $ */
+/** @file
+ * kLdr - Dynamic Loader testcase no. 3, 2nd object module.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "tst.h"
+
+extern int g_i1;
+
+int Tst3Sub(int iFortyTwo)
+{
+ return iFortyTwo * 11 * g_i1;
+}
+
diff --git a/src/lib/kStuff/kLdr/testcase/tst-3-imp-os2.def b/src/lib/kStuff/kLdr/testcase/tst-3-imp-os2.def
new file mode 100644
index 0000000..9ec3b13
--- /dev/null
+++ b/src/lib/kStuff/kLdr/testcase/tst-3-imp-os2.def
@@ -0,0 +1,34 @@
+; $Id: tst-3-imp-os2.def 29 2009-07-01 20:30:29Z bird $
+;; @file
+; kLdr - Dynamic Loader testcase no. 3, Fake module import library - OS/2.
+;
+
+;
+; Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+;
+; Permission is hereby granted, free of charge, to any person
+; obtaining a copy of this software and associated documentation
+; files (the "Software"), to deal in the Software without
+; restriction, including without limitation the rights to use,
+; copy, modify, merge, publish, distribute, sublicense, and/or sell
+; copies of the Software, and to permit persons to whom the
+; Software is furnished to do so, subject to the following
+; conditions:
+;
+; The above copyright notice and this permission notice shall be
+; included in all copies or substantial portions of the Software.
+;
+; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+; OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+; OTHER DEALINGS IN THE SOFTWARE.
+;
+
+LIBRARY tst-3-imp
+EXPORTS
+ _Tst3Ext
+
diff --git a/src/lib/kStuff/kLdr/testcase/tst-3-imp-win.def b/src/lib/kStuff/kLdr/testcase/tst-3-imp-win.def
new file mode 100644
index 0000000..7381804
--- /dev/null
+++ b/src/lib/kStuff/kLdr/testcase/tst-3-imp-win.def
@@ -0,0 +1,34 @@
+; $Id: tst-3-imp-win.def 29 2009-07-01 20:30:29Z bird $
+;; @file
+; kLdr - Dynamic Loader testcase no. 3, Fake module import library - Windows.
+;
+
+;
+; Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+;
+; Permission is hereby granted, free of charge, to any person
+; obtaining a copy of this software and associated documentation
+; files (the "Software"), to deal in the Software without
+; restriction, including without limitation the rights to use,
+; copy, modify, merge, publish, distribute, sublicense, and/or sell
+; copies of the Software, and to permit persons to whom the
+; Software is furnished to do so, subject to the following
+; conditions:
+;
+; The above copyright notice and this permission notice shall be
+; included in all copies or substantial portions of the Software.
+;
+; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+; OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+; OTHER DEALINGS IN THE SOFTWARE.
+;
+
+LIBRARY tst-3-imp
+EXPORTS
+ Tst3Ext
+
diff --git a/src/lib/kStuff/kLdr/testcase/tst-3.c b/src/lib/kStuff/kLdr/testcase/tst-3.c
new file mode 100644
index 0000000..ed89d9e
--- /dev/null
+++ b/src/lib/kStuff/kLdr/testcase/tst-3.c
@@ -0,0 +1,78 @@
+/* $Id: tst-3.c 29 2009-07-01 20:30:29Z bird $ */
+/** @file
+ * kLdr - Dynamic Loader testcase no. 3, Driver.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "tst.h"
+
+
+int g_i1 = 1;
+int g_i2 = 2;
+int *g_pi1 = &g_i1;
+
+extern int Tst3Sub(int);
+int (*g_pfnTst3Sub)(int) = &Tst3Sub;
+
+MY_IMPORT(int) Tst3Ext(int);
+int (*g_pfnTst3Ext)(int) = &Tst3Ext;
+
+char g_achBss[256];
+
+
+MY_EXPORT(int) Tst3(int iFortyTwo)
+{
+ int rc;
+
+ if (iFortyTwo != 42)
+ return 0;
+ if (g_i1 != 1)
+ return 1;
+ if (g_i2 != 2)
+ return 2;
+ if (g_pi1 != &g_i1)
+ return 3;
+ if (g_pfnTst3Sub != &Tst3Sub)
+ return 4;
+ rc = Tst3Sub(iFortyTwo);
+ if (rc != g_pfnTst3Sub(iFortyTwo))
+ return 5;
+ rc = Tst3Ext(iFortyTwo);
+ if (rc != 42)
+ return 6;
+ rc = g_pfnTst3Ext(iFortyTwo);
+ if (rc != 42)
+ return 7;
+ for (rc = 0; rc < sizeof(g_achBss); rc++)
+ if (g_achBss[rc])
+ return 8;
+ if (g_achBss[0] || g_achBss[1] || g_achBss[255])
+ return 9;
+
+ return 42;
+}
+
diff --git a/src/lib/kStuff/kLdr/testcase/tst.h b/src/lib/kStuff/kLdr/testcase/tst.h
new file mode 100644
index 0000000..f06dba7
--- /dev/null
+++ b/src/lib/kStuff/kLdr/testcase/tst.h
@@ -0,0 +1,57 @@
+/* $Id: tst.h 29 2009-07-01 20:30:29Z bird $ */
+/** @file
+ * kLdr testcase header.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef ___tst_h___
+#define ___tst_h___
+
+#include <k/kLdr.h>
+#include <k/kHlp.h>
+
+#if K_OS == K_OS_OS2 \
+ || K_OS == K_OS_WINDOWS
+# define MY_EXPORT(type) __declspec(dllexport) type
+/*# define MY_IMPORT(type) extern __declspec(dllimport) type*/
+# define MY_IMPORT(type) extern type
+#else
+# define MY_EXPORT(type) type
+# define MY_IMPORT(type) extern type
+#endif
+
+#if K_OS == K_OS_OS2 \
+ || K_OS == K_OS_DARWIN
+# define MY_NAME(a) "_" a
+#else
+# define MY_NAME(a) a
+#endif
+
+extern const char *g_pszName;
+
+#endif
+
diff --git a/src/lib/kStuff/kLdr/testcase/tstDllMain.c b/src/lib/kStuff/kLdr/testcase/tstDllMain.c
new file mode 100644
index 0000000..b86819c
--- /dev/null
+++ b/src/lib/kStuff/kLdr/testcase/tstDllMain.c
@@ -0,0 +1,192 @@
+/* $Id: tstDllMain.c 29 2009-07-01 20:30:29Z bird $ */
+/** @file
+ * kLdr testcase.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include "tst.h"
+
+#if K_OS == K_OS_OS2
+# define INCL_BASE
+# include <os2.h>
+# include <string.h>
+
+#elif K_OS == K_OS_WINDOWS
+# include <windows.h>
+# include <string.h>
+
+#elif K_OS == K_OS_DARWIN
+# include <unistd.h>
+# include <string.h>
+
+#else
+# error "port me"
+#endif
+
+
+/*******************************************************************************
+* Internal Functions *
+*******************************************************************************/
+void tstWrite(const char *psz);
+
+
+
+#if K_OS == K_OS_OS2
+/**
+ * OS/2 DLL 'main'
+ */
+ULONG _System _DLL_InitTerm(HMODULE hmod, ULONG fFlags)
+{
+ switch (fFlags)
+ {
+ case 0:
+ tstWrite("init: ");
+ tstWrite(g_pszName);
+ tstWrite("\n");
+ return TRUE;
+
+ case 1:
+ tstWrite("term: ");
+ tstWrite(g_pszName);
+ tstWrite("\n");
+ return TRUE;
+
+ default:
+ tstWrite("!invalid!: ");
+ tstWrite(g_pszName);
+ tstWrite("\n");
+ return FALSE;
+ }
+}
+
+#elif K_OS == K_OS_WINDOWS
+
+/**
+ * OS/2 DLL 'main'
+ */
+BOOL __stdcall DllMain(HANDLE hDllHandle, DWORD dwReason, LPVOID lpReserved)
+{
+ switch (dwReason)
+ {
+ case DLL_PROCESS_ATTACH:
+ tstWrite("init: ");
+ tstWrite(g_pszName);
+ tstWrite("\n");
+ return TRUE;
+
+ case DLL_PROCESS_DETACH:
+ tstWrite("term: ");
+ tstWrite(g_pszName);
+ tstWrite("\n");
+ return TRUE;
+
+ case DLL_THREAD_ATTACH:
+ tstWrite("thread init: ");
+ tstWrite(g_pszName);
+ tstWrite("\n");
+ return TRUE;
+
+ case DLL_THREAD_DETACH:
+ tstWrite("thread term: ");
+ tstWrite(g_pszName);
+ tstWrite("\n");
+ return TRUE;
+
+ default:
+ tstWrite("!invalid!: ");
+ tstWrite(g_pszName);
+ tstWrite("\n");
+ return FALSE;
+ }
+}
+
+#elif K_OS == K_OS_DARWIN
+/* later */
+
+#else
+# error "port me"
+#endif
+
+
+/**
+ * Writes a string with unix lineendings.
+ *
+ * @param pszMsg The string.
+ */
+void tstWrite(const char *pszMsg)
+{
+#if K_OS == K_OS_OS2 || K_OS == K_OS_WINDOWS
+ /*
+ * Line by line.
+ */
+ ULONG cbWritten;
+ const char *pszNl = strchr(pszMsg, '\n');
+
+ while (pszNl)
+ {
+ cbWritten = pszNl - pszMsg;
+
+#if K_OS == K_OS_OS2
+ if (cbWritten)
+ DosWrite((HFILE)2, pszMsg, cbWritten, &cbWritten);
+ DosWrite((HFILE)2, "\r\n", 2, &cbWritten);
+#else
+ if (cbWritten)
+ WriteFile((HANDLE)STD_ERROR_HANDLE, pszMsg, cbWritten, &cbWritten, NULL);
+ WriteFile((HANDLE)STD_ERROR_HANDLE, "\r\n", 2, &cbWritten, NULL);
+#endif
+
+ /* next */
+ pszMsg = pszNl + 1;
+ pszNl = strchr(pszMsg, '\n');
+ }
+
+ /*
+ * Remaining incomplete line.
+ */
+ if (*pszMsg)
+ {
+ cbWritten = strlen(pszMsg);
+#if K_OS == K_OS_OS2
+ DosWrite((HFILE)2, pszMsg, cbWritten, &cbWritten);
+#else
+ WriteFile((HANDLE)STD_ERROR_HANDLE, pszMsg, cbWritten, &cbWritten, NULL);
+#endif
+ }
+
+#elif K_OS == K_OS_DARWIN
+ write(STDERR_FILENO, pszMsg, strlen(pszMsg));
+
+#else
+# error "port me"
+#endif
+}
+
+
diff --git a/src/lib/kStuff/kLdr/testcase/tstDllMainStub-os2.asm b/src/lib/kStuff/kLdr/testcase/tstDllMainStub-os2.asm
new file mode 100644
index 0000000..76dad01
--- /dev/null
+++ b/src/lib/kStuff/kLdr/testcase/tstDllMainStub-os2.asm
@@ -0,0 +1,40 @@
+; $Id: tstDllMainStub-os2.asm 29 2009-07-01 20:30:29Z bird $
+;; @file
+; kLdr - OS/2 entry point thingy...
+;
+
+;
+; Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+;
+; Permission is hereby granted, free of charge, to any person
+; obtaining a copy of this software and associated documentation
+; files (the "Software"), to deal in the Software without
+; restriction, including without limitation the rights to use,
+; copy, modify, merge, publish, distribute, sublicense, and/or sell
+; copies of the Software, and to permit persons to whom the
+; Software is furnished to do so, subject to the following
+; conditions:
+;
+; The above copyright notice and this permission notice shall be
+; included in all copies or substantial portions of the Software.
+;
+; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+; OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+; OTHER DEALINGS IN THE SOFTWARE.
+;
+
+segment TEXT32 public CLASS=CODE align=16 use32
+extern _DLL_InitTerm
+..start:
+ jmp _DLL_InitTerm
+
+segment DATA32 stack CLASS=DATA align=16 use32
+
+global WEAK$ZERO
+WEAK$ZERO EQU 0
+
diff --git a/src/lib/kStuff/kLdr/testcase/tstDllMainStub.c b/src/lib/kStuff/kLdr/testcase/tstDllMainStub.c
new file mode 100644
index 0000000..67681c8
--- /dev/null
+++ b/src/lib/kStuff/kLdr/testcase/tstDllMainStub.c
@@ -0,0 +1,76 @@
+/* $Id: tstDllMainStub.c 29 2009-07-01 20:30:29Z bird $ */
+/** @file
+ * kLdr testcase - DLL Stub.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include "tst.h"
+
+#if K_OS == K_OS_OS2
+# define INCL_BASE
+# include <os2.h>
+
+#elif K_OS == K_OS_WINDOWS
+# include <windows.h>
+
+#elif K_OS == K_OS_DARWIN
+/* later */
+
+#else
+# error "port me"
+#endif
+
+
+#if K_OS == K_OS_OS2
+/**
+ * OS/2 DLL 'main'
+ */
+ULONG _System _DLL_InitTerm(HMODULE hmod, ULONG fFlag)
+{
+ return TRUE;
+}
+
+#elif K_OS == K_OS_WINDOWS
+
+/**
+ * Window DLL 'main'
+ */
+BOOL __stdcall DllMain(HANDLE hDllHandle, DWORD dwReason, LPVOID lpReserved)
+{
+ return TRUE;
+}
+
+#elif K_OS == K_OS_DARWIN
+/* later */
+
+#else
+# error "port me"
+#endif
+
diff --git a/src/lib/kStuff/kLdr/testcase/tstExeMainStub-os2.asm b/src/lib/kStuff/kLdr/testcase/tstExeMainStub-os2.asm
new file mode 100644
index 0000000..d4a8ee9
--- /dev/null
+++ b/src/lib/kStuff/kLdr/testcase/tstExeMainStub-os2.asm
@@ -0,0 +1,40 @@
+; $Id: tstExeMainStub-os2.asm 29 2009-07-01 20:30:29Z bird $
+;; @file
+; kLdr - OS/2 entry point thingy...
+;
+
+;
+; Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+;
+; Permission is hereby granted, free of charge, to any person
+; obtaining a copy of this software and associated documentation
+; files (the "Software"), to deal in the Software without
+; restriction, including without limitation the rights to use,
+; copy, modify, merge, publish, distribute, sublicense, and/or sell
+; copies of the Software, and to permit persons to whom the
+; Software is furnished to do so, subject to the following
+; conditions:
+;
+; The above copyright notice and this permission notice shall be
+; included in all copies or substantial portions of the Software.
+;
+; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+; OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+; OTHER DEALINGS IN THE SOFTWARE.
+;
+
+segment TEXT32 public CLASS=CODE align=16 use32
+extern OS2Main
+..start:
+ jmp OS2Main
+
+segment DATA32 stack CLASS=DATA align=16 use32
+
+global WEAK$ZERO
+WEAK$ZERO EQU 0
+
diff --git a/src/lib/kStuff/kLdr/testcase/tstExeMainStub.c b/src/lib/kStuff/kLdr/testcase/tstExeMainStub.c
new file mode 100644
index 0000000..9ec9f47
--- /dev/null
+++ b/src/lib/kStuff/kLdr/testcase/tstExeMainStub.c
@@ -0,0 +1,93 @@
+/* $Id: tstExeMainStub.c 29 2009-07-01 20:30:29Z bird $ */
+/** @file
+ * kLdr testcase - DLL Stub.
+ */
+
+/*
+ * Copyright (c) 2006-2007 Knut St. Osmundsen <bird-kStuff-spamix@anduin.net>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include "tst.h"
+
+#if K_OS == K_OS_OS2
+# define INCL_BASE
+# include <os2.h>
+
+#elif K_OS == K_OS_WINDOWS
+/* nothing */
+
+#elif K_OS == K_OS_NT
+# include <ddk/ntapi.h> /** @todo fix the nt port. */
+
+#else
+# error "port me"
+#endif
+
+
+extern int main();
+
+
+#if K_OS == K_OS_OS2
+/**
+ * OS/2 'main'.
+ */
+ULONG _System OS2Main(HMODULE hmod, ULONG fFlag, ULONG ulReserved, PSZ pszzEnv, PSZ pszzCmdLine)
+{
+ int rc;
+ rc = main();
+ return rc;
+}
+
+#elif K_OS == K_OS_WINDOWS
+/**
+ * Windows'main'
+ */
+int WindowsMain(void)
+{
+ int rc;
+ rc = main();
+ return rc;
+}
+
+#elif K_OS == K_OS_NT
+/**
+ * Windows NT 'main'
+ */
+VOID NtProcess(HANDLE hDllHandle, DWORD dwReason, LPVOID lpReserved)
+{
+ int rc;
+ rc = main();
+ /* (no way around this) */
+ for (;;)
+ ZwTerminateProcess(NtCurrentProcess(), rc);
+}
+
+#else
+# error "port me"
+#endif
+
+