Changeset 2967
- Timestamp:
- Feb 13, 2007, 11:28:46 PM (18 years ago)
- Location:
- trunk/kLdr/testcase
- Files:
-
- 3 added
- 3 edited
- 3 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/kLdr/testcase/Makefile.kmk
r2965 r2967 121 121 TEMPLATE_TSTBARE_DEFS = __DARWIN__ 122 122 TEMPLATE_TSTBARE_LIBS = 123 TEMPLATE_TSTBARE_CFLAGS += -static 123 TEMPLATE_TSTBARE_CFLAGS += -static -fno-common 124 124 TEMPLATE_TSTBARE_LDFLAGS += -nostdlib -r 125 125 else … … 270 270 # 271 271 PROGRAMS += tst-3-driver 272 ifeq ($(BUILD_TARGET),darwin) 273 SYSMODS += tst-3 274 else 272 275 DLLS += tst-3 276 LIBRARIES.win = tst-3-imp 277 LIBRARIES.os2 = tst-3-imp 278 endif 273 279 274 280 tst-3_TEMPLATE = TSTBAREDLL 275 tst-3_SOURCES = tst-3.c tst DllMainStub.c281 tst-3_SOURCES = tst-3.c tst-3-ext.c tstDllMainStub.c 276 282 tst-3_SOURCES.os2= tstDllMainStub-os2.asm 283 tst-3_LIBS.os2 = $(TARGET_tst-3-imp) 284 tst-3_LIBS.win = $(TARGET_tst-3-imp) 285 286 tst-3-imp_TEMPLATE = TSTBAREDLL 287 tst-3-imp_SOURCES.win = tst-3-imp-win.def 288 tst-3-imp_SOURCES.os2 = tst-3-imp-os2.def 277 289 278 290 tst-3-driver_TEMPLATE = TSTPROG -
trunk/kLdr/testcase/tst-3-driver.c
r2965 r2967 72 72 73 73 74 /** 75 * External symbol used by the testcase module. 76 */ 77 static int Tst3Ext(int iFortyTwo) 78 { 79 if (iFortyTwo != 42) 80 return 256; 81 return 42; 82 } 83 84 85 /** 86 * Callback for resolving the Tst3Ext import. 87 */ 74 88 static int GetImport(PKLDRMOD pMod, uint32_t iImport, uint32_t iSymbol, const char *pchSymbol, size_t cchSymbol, 75 89 const char *pszVersion, PKLDRADDR puValue, uint32_t *pfKind, void *pvUser) 76 90 { 77 /** todo */ 78 return -1; 91 if (*pfKind != KLDRSYMKIND_REQ_FLAT) 92 return -1; 93 94 if ( !strncmp(pchSymbol, "Tst3Ext", strlen("Tst3Ext")) 95 || !strncmp(pchSymbol, "_Tst3Ext", strlen("_Tst3Ext"))) 96 { 97 *puValue = (uintptr_t)&Tst3Ext; 98 *pfKind = KLDRSYMKIND_CODE | (sizeof(pfKind) == 4 ? KLDRSYMKIND_32BIT : KLDRSYMKIND_64BIT); 99 return 0; 100 } 101 102 return -2; 79 103 } 80 104 … … 100 124 /* get bits. */ 101 125 cbImage = kLdrModSize(pMod); 102 pvBits = malloc((size_t)cbImage );126 pvBits = malloc((size_t)cbImage + 0xfff); 103 127 if (pvBits) 104 128 { 105 KLDRADDR BaseAddress = (uintptr_t)pvBits; 106 rc = kLdrModGetBits(pMod, pvBits, BaseAddress, GetImport, NULL); 129 void *pvBits2 = (void *)( ((uintptr_t)pvBits + 0xfff) & ~(uintptr_t)0xfff ); 130 131 KLDRADDR BaseAddress = (uintptr_t)pvBits2; 132 rc = kLdrModGetBits(pMod, pvBits2, BaseAddress, GetImport, NULL); 107 133 if (!rc) 108 134 { 109 const char *pszSym = MY_NAME("Tst3");110 135 KLDRADDR EntryPoint; 111 136 112 137 /* call into it */ 113 rc = kLdrModQuerySymbol(pMod, pvBits , BaseAddress, NIL_KLDRMOD_SYM_ORDINAL, pszSym, strlen(pszSym), NULL, NULL, NULL,138 rc = kLdrModQuerySymbol(pMod, pvBits2, BaseAddress, NIL_KLDRMOD_SYM_ORDINAL, "_Tst3", strlen("_Tst3"), NULL, NULL, NULL, 114 139 &EntryPoint, NULL); 140 if (rc == KLDR_ERR_SYMBOL_NOT_FOUND) 141 rc = kLdrModQuerySymbol(pMod, pvBits2, BaseAddress, NIL_KLDRMOD_SYM_ORDINAL, "Tst3", strlen("Tst3"), NULL, NULL, NULL, 142 &EntryPoint, NULL); 115 143 if (!rc) 116 144 { … … 120 148 { 121 149 /* relocate twice and try again. */ 122 rc = kLdrModRelocateBits(pMod, pvBits , BaseAddress + 0x22000, BaseAddress, GetImport, NULL);150 rc = kLdrModRelocateBits(pMod, pvBits2, BaseAddress + 0x22000, BaseAddress, GetImport, NULL); 123 151 if (!rc) 124 152 { 125 rc = kLdrModRelocateBits(pMod, pvBits , BaseAddress, BaseAddress + 0x22000, GetImport, NULL);153 rc = kLdrModRelocateBits(pMod, pvBits2, BaseAddress, BaseAddress + 0x22000, GetImport, NULL); 126 154 if (!rc) 127 155 { … … 178 206 */ 179 207 if (!g_cErrors) 180 printf("tst- 0-driver: SUCCESS\n");208 printf("tst-3-driver: SUCCESS\n"); 181 209 else 182 printf("tst- 0-driver: FAILURE - %d errors\n", g_cErrors);210 printf("tst-3-driver: FAILURE - %d errors\n", g_cErrors); 183 211 return !!g_cErrors; 184 212 } -
trunk/kLdr/testcase/tst-3-ext.c
r2965 r2967 2 2 /** @file 3 3 * 4 * kLdr - Dynamic Loader testcase no. 3, Driver.4 * kLdr - Dynamic Loader testcase no. 3, 2nd object module. 5 5 * 6 6 * Copyright (c) 2006 knut st. osmundsen <bird-kbuild-src@anduin.net> … … 28 28 #include "tst.h" 29 29 30 31 int g_i1 = 1; 32 int g_i2 = 2; 33 int *g_pi1 = &g_i1; 34 35 int Tst3Sub(int); 36 int (*g_pfnTst3Sub)(int) = &Tst3Sub; 37 38 char g_achBss[256]; 39 40 41 MY_EXPORT(int) Tst3(int iFortyTwo) 42 { 43 int rc; 44 45 if (iFortyTwo != 42) 46 return 0; 47 if (g_i1 != 1) 48 return 1; 49 if (g_i2 != 2) 50 return 2; 51 if (g_pi1 != &g_i1) 52 return 3; 53 if (g_pfnTst3Sub != &Tst3Sub) 54 return 4; 55 rc = Tst3Sub(iFortyTwo); 56 if (rc != g_pfnTst3Sub(iFortyTwo)) 57 return 5; 58 for (rc = 0; rc < sizeof(g_achBss); rc++) 59 if (g_achBss[rc]) 60 return 6; 61 if (g_achBss[0] || g_achBss[1] || g_achBss[255]) 62 return 7; 63 64 return 42; 65 } 66 30 extern int g_i1; 67 31 68 32 int Tst3Sub(int iFortyTwo) 69 33 { 70 return iFortyTwo * 11 ;34 return iFortyTwo * 11 * g_i1; 71 35 } 72 36 -
trunk/kLdr/testcase/tst-3-imp-os2.def
r2965 r2967 1 /* $Id$ */ 2 /**@file3 * 4 * kLdr - Dynamic Loader testcase no. 3, Driver.5 * 6 *Copyright (c) 2006 knut st. osmundsen <bird-kbuild-src@anduin.net>7 * 8 * 9 *This file is part of kLdr.10 * 11 *kLdr is free software; you can redistribute it and/or modify12 *it under the terms of the GNU General Public License as published by13 *the Free Software Foundation; either version 2 of the License, or14 *(at your option) any later version.15 * 16 *kLdr is distributed in the hope that it will be useful,17 *but WITHOUT ANY WARRANTY; without even the implied warranty of18 *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the19 *GNU General Public License for more details.20 * 21 *You should have received a copy of the GNU General Public License22 *along with kLdr; if not, write to the Free Software23 *Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA24 * 25 */ 1 ; $Id$ 2 ;; @file 3 ; 4 ; kLdr - Dynamic Loader testcase no. 3, Fake module import library - OS/2. 5 ; 6 ; Copyright (c) 2006 knut st. osmundsen <bird-kbuild-src@anduin.net> 7 ; 8 ; 9 ; This file is part of kLdr. 10 ; 11 ; kLdr is free software; you can redistribute it and/or modify 12 ; it under the terms of the GNU General Public License as published by 13 ; the Free Software Foundation; either version 2 of the License, or 14 ; (at your option) any later version. 15 ; 16 ; kLdr is distributed in the hope that it will be useful, 17 ; but WITHOUT ANY WARRANTY; without even the implied warranty of 18 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 ; GNU General Public License for more details. 20 ; 21 ; You should have received a copy of the GNU General Public License 22 ; along with kLdr; if not, write to the Free Software 23 ; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 ; 25 ; 26 26 27 LIBRARY tst-3-imp 28 EXPORTS 29 _Tst3Ext 27 30 28 #include "tst.h"29 30 31 int g_i1 = 1;32 int g_i2 = 2;33 int *g_pi1 = &g_i1;34 35 int Tst3Sub(int);36 int (*g_pfnTst3Sub)(int) = &Tst3Sub;37 38 char g_achBss[256];39 40 41 MY_EXPORT(int) Tst3(int iFortyTwo)42 {43 int rc;44 45 if (iFortyTwo != 42)46 return 0;47 if (g_i1 != 1)48 return 1;49 if (g_i2 != 2)50 return 2;51 if (g_pi1 != &g_i1)52 return 3;53 if (g_pfnTst3Sub != &Tst3Sub)54 return 4;55 rc = Tst3Sub(iFortyTwo);56 if (rc != g_pfnTst3Sub(iFortyTwo))57 return 5;58 for (rc = 0; rc < sizeof(g_achBss); rc++)59 if (g_achBss[rc])60 return 6;61 if (g_achBss[0] || g_achBss[1] || g_achBss[255])62 return 7;63 64 return 42;65 }66 67 68 int Tst3Sub(int iFortyTwo)69 {70 return iFortyTwo * 11;71 }72 -
trunk/kLdr/testcase/tst-3-imp-win.def
r2965 r2967 1 /* $Id$ */ 2 /**@file3 * 4 * kLdr - Dynamic Loader testcase no. 3, Driver.5 * 6 *Copyright (c) 2006 knut st. osmundsen <bird-kbuild-src@anduin.net>7 * 8 * 9 *This file is part of kLdr.10 * 11 *kLdr is free software; you can redistribute it and/or modify12 *it under the terms of the GNU General Public License as published by13 *the Free Software Foundation; either version 2 of the License, or14 *(at your option) any later version.15 * 16 *kLdr is distributed in the hope that it will be useful,17 *but WITHOUT ANY WARRANTY; without even the implied warranty of18 *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the19 *GNU General Public License for more details.20 * 21 *You should have received a copy of the GNU General Public License22 *along with kLdr; if not, write to the Free Software23 *Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA24 * 25 */ 1 ; $Id$ 2 ;; @file 3 ; 4 ; kLdr - Dynamic Loader testcase no. 3, Fake module import library - Windows. 5 ; 6 ; Copyright (c) 2006 knut st. osmundsen <bird-kbuild-src@anduin.net> 7 ; 8 ; 9 ; This file is part of kLdr. 10 ; 11 ; kLdr is free software; you can redistribute it and/or modify 12 ; it under the terms of the GNU General Public License as published by 13 ; the Free Software Foundation; either version 2 of the License, or 14 ; (at your option) any later version. 15 ; 16 ; kLdr is distributed in the hope that it will be useful, 17 ; but WITHOUT ANY WARRANTY; without even the implied warranty of 18 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 ; GNU General Public License for more details. 20 ; 21 ; You should have received a copy of the GNU General Public License 22 ; along with kLdr; if not, write to the Free Software 23 ; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 ; 25 ; 26 26 27 LIBRARY tst-3-imp 28 EXPORTS 29 Tst3Ext 27 30 28 #include "tst.h"29 30 31 int g_i1 = 1;32 int g_i2 = 2;33 int *g_pi1 = &g_i1;34 35 int Tst3Sub(int);36 int (*g_pfnTst3Sub)(int) = &Tst3Sub;37 38 char g_achBss[256];39 40 41 MY_EXPORT(int) Tst3(int iFortyTwo)42 {43 int rc;44 45 if (iFortyTwo != 42)46 return 0;47 if (g_i1 != 1)48 return 1;49 if (g_i2 != 2)50 return 2;51 if (g_pi1 != &g_i1)52 return 3;53 if (g_pfnTst3Sub != &Tst3Sub)54 return 4;55 rc = Tst3Sub(iFortyTwo);56 if (rc != g_pfnTst3Sub(iFortyTwo))57 return 5;58 for (rc = 0; rc < sizeof(g_achBss); rc++)59 if (g_achBss[rc])60 return 6;61 if (g_achBss[0] || g_achBss[1] || g_achBss[255])62 return 7;63 64 return 42;65 }66 67 68 int Tst3Sub(int iFortyTwo)69 {70 return iFortyTwo * 11;71 }72 -
trunk/kLdr/testcase/tst-3.c
r2965 r2967 33 33 int *g_pi1 = &g_i1; 34 34 35 int Tst3Sub(int);35 extern int Tst3Sub(int); 36 36 int (*g_pfnTst3Sub)(int) = &Tst3Sub; 37 38 MY_IMPORT(int) Tst3Ext(int); 39 int (*g_pfnTst3Ext)(int) = &Tst3Ext; 37 40 38 41 char g_achBss[256]; … … 56 59 if (rc != g_pfnTst3Sub(iFortyTwo)) 57 60 return 5; 61 rc = Tst3Ext(iFortyTwo); 62 if (rc != 42) 63 return 6; 64 rc = g_pfnTst3Ext(iFortyTwo); 65 if (rc != 42) 66 return 7; 58 67 for (rc = 0; rc < sizeof(g_achBss); rc++) 59 68 if (g_achBss[rc]) 60 return 6;69 return 8; 61 70 if (g_achBss[0] || g_achBss[1] || g_achBss[255]) 62 return 7;71 return 9; 63 72 64 73 return 42; 65 74 } 66 75 67 68 int Tst3Sub(int iFortyTwo)69 {70 return iFortyTwo * 11;71 }72
Note:
See TracChangeset
for help on using the changeset viewer.