Changeset 3573 for trunk/kStuff/kHlp/Bare/kHlpBareMem.c
- Timestamp:
- Aug 31, 2007, 6:09:23 AM (18 years ago)
- Location:
- trunk/kStuff/kHlp/Bare
- Files:
-
- 1 added
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/kStuff/kHlp/Bare/kHlpBareMem.c
r3571 r3573 1 1 /* $Id$ */ 2 2 /** @file 3 * 4 * kLdr - The Dynamic Loader, Memory Helper Functions.5 * 6 * Copyright (c) 2006-2007 knut st. osmundsen <bird-kbuild-src@anduin.net> 7 * 8 * 9 * This file is part of k Ldr.10 * 11 * k Ldr 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 * k Ldris distributed in the hope that it will be useful,3 * kHlp - Generic Page Memory Functions. 4 */ 5 6 /* 7 * Copyright (c) 2007 knut st. osmundsen <bird-src-spam@anduin.net> 8 * 9 * This file is part of kStuff. 10 * 11 * kStuff is free software; you can redistribute it and/or 12 * modify it under the terms of the GNU Lesser General Public 13 * License as published by the Free Software Foundation; either 14 * version 2.1 of the License, or (at your option) any later version. 15 * 16 * kStuff is distributed in the hope that it will be useful, 17 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 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 * Lesser General Public License for more details. 20 * 21 * You should have received a copy of the GNU Lesser General Public 22 * License along with kStuff; if not, write to the Free Software 23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 24 * 25 */ 27 26 28 27 /******************************************************************************* 29 28 * Header Files * 30 29 *******************************************************************************/ 31 #ifdef __OS2__ 30 #include <k/kHlpAlloc.h> 31 32 #if K_OS == K_OS_OS2 32 33 # define INCL_BASE 33 34 # define INCL_ERRORS 34 35 # include <os2.h> 35 #elif defined(__WIN__)36 #elif K_OS == K_OS_WINDOWS 36 37 # include <Windows.h> 37 38 #else 38 39 # error "port me" 39 40 #endif 40 41 #include <k/kLdr.h>42 #include "kLdrHlp.h"43 41 44 42 … … 46 44 * Global Variables * 47 45 *******************************************************************************/ 48 #if def __OS2__46 #if K_OS == K_OS_OS2 49 47 /** The base of the stub object. 50 48 * The OS/2 exe stub consists of a single data object. When allocating memory … … 54 52 static KSIZE g_cbStub = 0; 55 53 56 #elif defined(__WIN__)54 #elif K_OS == K_OS_WINDOWS 57 55 /** The system info. */ 58 56 static SYSTEM_INFO g_SystemInfo; … … 63 61 64 62 65 #if def __OS2__66 static ULONG k ldrHlpPageProtToNative(KPROT enmProt)63 #if K_OS == K_OS_OS2 64 static ULONG kHlpPageProtToNative(KPROT enmProt) 67 65 { 68 66 switch (enmProt) … … 75 73 case KPROT_EXECUTE_READWRITE: return PAG_COMMIT | PAG_EXECUTE | PAG_READ | PAG_WRITE; 76 74 default: 77 k ldrHlpAssert(0);75 kHlpAssert(0); 78 76 return ~0U; 79 77 } 80 78 } 81 #elif defined(__WIN__)82 static DWORD k ldrHlpPageProtToNative(KPROT enmProt)79 #elif K_OS == K_OS_WINDOWS 80 static DWORD kHlpPageProtToNative(KPROT enmProt) 83 81 { 84 82 switch (enmProt) … … 91 89 case KPROT_EXECUTE_READWRITE: return PAGE_EXECUTE_READWRITE; 92 90 default: 93 k ldrHlpAssert(0);91 kHlpAssert(0); 94 92 return ~0U; 95 93 } … … 107 105 * @param enmProt The new protection. Copy-on-write is invalid. 108 106 */ 109 int kldrHlpPageAlloc(void **ppv, KSIZE cb, KPROT enmProt, unsignedfFixed)110 { 111 #if def __OS2__107 KHLP_DECL(int) kHlpPageAlloc(void **ppv, KSIZE cb, KPROT enmProt, KBOOL fFixed) 108 { 109 #if K_OS == K_OS_OS2 112 110 APIRET rc; 113 ULONG fFlags = k ldrHlpPageProtToNative(enmProt);;111 ULONG fFlags = kHlpPageProtToNative(enmProt);; 114 112 115 113 if (!fFixed) … … 128 126 if (!rc) 129 127 return 0; 130 k ldrHlpAssert(0);131 return rc; 132 133 #elif defined(__WIN__)128 kHlpAssert(0); 129 return rc; 130 131 #elif K_OS == K_OS_WINDOWS 134 132 /* (We don't have to care about the stub here, because the stub will be unmapped before we get here.) */ 135 133 int rc; 136 DWORD fProt = k ldrHlpPageProtToNative(enmProt);134 DWORD fProt = kHlpPageProtToNative(enmProt); 137 135 138 136 if (!g_SystemInfo.dwPageSize) … … 143 141 return 0; 144 142 rc = GetLastError(); 145 k ldrHlpAssert(0);143 kHlpAssert(0); 146 144 return rc; 147 145 … … 155 153 * Change the protection of one or more pages in an allocation. 156 154 * 157 * (This will of course only work correctly on memory allocated by k ldrHlpPageAlloc().)155 * (This will of course only work correctly on memory allocated by kHlpPageAlloc().) 158 156 * 159 157 * @returns 0 on success, non-zero OS status code on failure. … … 162 160 * @param enmProt The new protection. Copy-on-write is invalid. 163 161 */ 164 int kldrHlpPageProtect(void *pv, KSIZE cb, KPROT enmProt)165 { 166 #if def __OS2__162 KHLP_DECL(int) kHlpPageProtect(void *pv, KSIZE cb, KPROT enmProt) 163 { 164 #if K_OS == K_OS_OS2 167 165 APIRET rc; 168 ULONG fFlags = k ldrHlpPageProtToNative(enmProt);;166 ULONG fFlags = kHlpPageProtToNative(enmProt);; 169 167 170 168 /* … … 188 186 } 189 187 } 190 k ldrHlpAssert(!rc);191 return rc; 192 193 #elif defined(__WIN__)188 kHlpAssert(!rc); 189 return rc; 190 191 #elif K_OS == K_OS_WINDOWS 194 192 DWORD fOldProt = 0; 195 DWORD fProt = k ldrHlpPageProtToNative(enmProt);193 DWORD fProt = kHlpPageProtToNative(enmProt); 196 194 int rc = 0; 197 195 … … 199 197 { 200 198 rc = GetLastError(); 201 k ldrHlpAssert(0);199 kHlpAssert(0); 202 200 } 203 201 return rc; … … 209 207 210 208 /** 211 * Free memory allocated by k ldrHlpPageAlloc().209 * Free memory allocated by kHlpPageAlloc(). 212 210 * 213 211 * @returns 0 on success, non-zero OS status code on failure. 214 * @param pv The address returned by k ldrHlpPageAlloc().215 * @param cb The byte count requested from k ldrHlpPageAlloc().216 */ 217 int kldrHlpPageFree(void *pv, KSIZE cb)218 { 219 #if def __OS2__212 * @param pv The address returned by kHlpPageAlloc(). 213 * @param cb The byte count requested from kHlpPageAlloc(). 214 */ 215 KHLP_DECL(int) skHlpPageFree(void *pv, KSIZE cb) 216 { 217 #if K_OS == K_OS_OS2 220 218 APIRET rc; 221 219 … … 242 240 if (rc) 243 241 { 244 k ldrHlpAssert(!rc);242 kHlpAssert(!rc); 245 243 return rc; 246 244 } … … 259 257 */ 260 258 rc = DosFreeMem(pv); 261 k ldrHlpAssert(!rc);262 return rc; 263 264 #elif defined(__WIN__)259 kHlpAssert(!rc); 260 return rc; 261 262 #elif K_OS == K_OS_WINDOWS 265 263 /* 266 264 * Free the object. … … 270 268 { 271 269 rc = GetLastError(); 272 k ldrHlpAssert(0);273 } 274 return rc; 275 276 #else 277 # error "port me" 278 #endif 279 } 280 270 kHlpAssert(0); 271 } 272 return rc; 273 274 #else 275 # error "port me" 276 #endif 277 } 278
Note:
See TracChangeset
for help on using the changeset viewer.