Changeset 3543
- Timestamp:
- Aug 25, 2007, 8:10:29 AM (18 years ago)
- Location:
- trunk/kStuff
- Files:
-
- 7 added
- 3 edited
- 3 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/kStuff/include/k/kRdr.h
r3542 r3543 29 29 30 30 #include <k/kDefs.h> 31 #ifndef ___k_kLdr___ 32 /* avoid dragging in kLdr.h */ 33 typedef enum KLDRPROT { KLDRPROT_32BIT_HACK = 0x7fffffff } KLDRPROT; 34 typedef const struct KLDRSEG *PCKLDRSEG; 35 #endif 31 #include <k/kTypes.h> 36 32 37 33 #ifdef __cplusplus … … 43 39 * @{ */ 44 40 45 /** Pointer to a file provider instance core. */41 /** Pointer to a file provider instance. */ 46 42 typedef struct KRDR *PKRDR; 47 /** Pointer to a file provider instance corepointer. */43 /** Pointer to a file provider instance pointer. */ 48 44 typedef struct KRDR **PPKRDR; 49 50 /**51 * File provider instance operations.52 */53 typedef struct KRDROPS54 {55 /** The name of this file provider. */56 const char *pszName;57 /** Pointer to the next file provider. */58 const struct KRDROPS *pNext;59 60 /** Try create a new file provider instance.61 *62 * @returns 0 on success, OS specific error code on failure.63 * @param ppRdr Where to store the file provider instance.64 * @param pszFilename The filename to open.65 */66 int (* pfnCreate)( PPKRDR ppRdr, const char *pszFilename);67 /** Destroy the file provider instance.68 *69 * @returns 0 on success, OS specific error code on failure.70 * On failure, the file provider instance will be in an indeterminate state - don't touch it!71 * @param pRdr The file provider instance.72 */73 int (* pfnDestroy)( PKRDR pRdr);74 /** @copydoc kRdrRead */75 int (* pfnRead)( PKRDR pRdr, void *pvBuf, size_t cb, KLDRFOFF off);76 /** @copydoc kRdrAllMap */77 int (* pfnAllMap)( PKRDR pRdr, const void **ppvBits);78 /** @copydoc kRdrAllUnmap */79 int (* pfnAllUnmap)(PKRDR pRdr, const void *pvBits);80 /** @copydoc kRdrSize */81 KFOFF (* pfnSize)( PKRDR pRdr);82 /** @copydoc kRdrTell */83 KFOFF (* pfnTell)( PKRDR pRdr);84 /** @copydoc kRdrName */85 const char * (* pfnName)(PKRDR pRdr);86 /** @copydoc kRdrPageSize */87 KSIZE (* pfnPageSize)(PKRDR pRdr);88 /** @copydoc kRdrMap */89 int (* pfnMap)( PKRDR pRdr, void **ppvBase, KU32 cSegments, PCKLDRSEG paSegments, unsigned fFixed);90 /** @copydoc kRdrRefresh */91 int (* pfnRefresh)( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments);92 /** @copydoc kRdrProtect */93 int (* pfnProtect)( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments, unsigned fUnprotectOrProtect);94 /** @copydoc kRdrUnmap */95 int (* pfnUnmap)( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments);96 /** @copydoc kRdrDone */97 void (* pfnDone)( PKRDR pRdr);98 /** The usual non-zero dummy that makes sure we've initialized all members. */99 KU32 u32Dummy;100 } KRDROPS;101 /** Pointer to file provider operations. */102 typedef KRDROPS *PKRDROPS;103 /** Pointer to const file provider operations. */104 typedef const KRDROPS *PCKRDROPS;105 106 107 /**108 * File provider instance core.109 */110 typedef struct KRDR111 {112 /** Magic number (KLDRRDR_MAGIC). */113 KU32 u32Magic;114 /** Pointer to the file provider operations. */115 PCKRDROPS pOps;116 } KRDR;117 118 /** The magic for KRDR::u32Magic. (Katsu Aki (Katsuaki Nakamura)) */119 #define KRDR_MAGIC 0x19610919120 121 void kRdrAddProvider(PKRDROPS pAdd);122 45 123 46 int kRdrOpen(PPKRDR ppRdr, const char *pszFilename); 124 47 int kRdrOpenBuffered(PPKRDR ppRdr, const char *pszFilename); 125 126 48 int kRdrClose( PKRDR pRdr); 127 int kRdrRead( PKRDR pRdr, void *pvBuf, size_t cb, KLDRFOFF off);49 int kRdrRead( PKRDR pRdr, void *pvBuf, KSIZE cb, KFOFF off); 128 50 int kRdrAllMap( PKRDR pRdr, const void **ppvBits); 129 51 int kRdrAllUnmap(PKRDR pRdr, const void *pvBits); … … 132 54 const char *kRdrName(PKRDR pRdr); 133 55 KIPTR kRdrNativeFH(PKRDR pRdr); 134 135 56 KSIZE kRdrPageSize(PKRDR pRdr); 57 #ifndef ___k_kLdr___ 136 58 int kRdrMap( PKRDR pRdr, void **ppvBase, KU32 cSegments, PCKLDRSEG paSegments, unsigned fFixed); 137 59 int kRdrRefresh( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments); 138 60 int kRdrProtect( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments, unsigned fUnprotectOrProtect); 139 61 int kRdrUnmap( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments); 62 #endif /* !___k_kLdr___ */ 140 63 void kRdrDone( PKRDR pRdr); 141 64 -
trunk/kStuff/include/k/kRdrAll.h
r3542 r3543 1 1 /* $Id$ */ 2 2 /** @file 3 * kRdr - The File Provider .3 * kRdr - The File Provider, All Dependencies Included. 4 4 */ 5 5 … … 25 25 */ 26 26 27 #ifndef ___kRdr _h___28 #define ___kRdr _h___27 #ifndef ___kRdrAll_h___ 28 #define ___kRdrAll_h___ 29 29 30 30 #include <k/kDefs.h> 31 #ifndef ___k_kLdr___ 32 /* avoid dragging in kLdr.h */ 33 typedef enum KLDRPROT { KLDRPROT_32BIT_HACK = 0x7fffffff } KLDRPROT; 34 typedef const struct KLDRSEG *PCKLDRSEG; 35 #endif 31 #include "../kLdr/kLdr.h" //later - <k/kLdr.h> 32 #include <k/kRdr.h> 36 33 37 34 #ifdef __cplusplus … … 40 37 41 38 42 /** @defgroup grp_kRdr kRdr - The File Provider 43 * @{ */ 44 45 /** Pointer to a file provider instance core. */ 46 typedef struct KRDR *PKRDR; 47 /** Pointer to a file provider instance core pointer. */ 48 typedef struct KRDR **PPKRDR; 39 /** @defgroup grp_kRdrAll All 40 * @addtogroup grp_kRdr 41 * @{ 42 */ 49 43 50 44 /** … … 73 67 int (* pfnDestroy)( PKRDR pRdr); 74 68 /** @copydoc kRdrRead */ 75 int (* pfnRead)( PKRDR pRdr, void *pvBuf, size_t cb, K LDRFOFF off);69 int (* pfnRead)( PKRDR pRdr, void *pvBuf, size_t cb, KFOFF off); 76 70 /** @copydoc kRdrAllMap */ 77 71 int (* pfnAllMap)( PKRDR pRdr, const void **ppvBits); … … 84 78 /** @copydoc kRdrName */ 85 79 const char * (* pfnName)(PKRDR pRdr); 80 /** @copydoc kRdrNativeFH */ 81 KIPTR (* pfnNativeFH)(PKRDR pRdr); 86 82 /** @copydoc kRdrPageSize */ 87 83 KSIZE (* pfnPageSize)(PKRDR pRdr); … … 110 106 typedef struct KRDR 111 107 { 112 /** Magic number (K LDRRDR_MAGIC). */108 /** Magic number (KRDR_MAGIC). */ 113 109 KU32 u32Magic; 114 110 /** Pointer to the file provider operations. */ … … 116 112 } KRDR; 117 113 118 /** The magic for KRDR::u32Magic. (Katsu Aki (Katsuaki Nakamura)) */119 #define KRDR_MAGIC 0x19610919120 121 114 void kRdrAddProvider(PKRDROPS pAdd); 122 123 int kRdrOpen(PPKRDR ppRdr, const char *pszFilename);124 int kRdrOpenBuffered(PPKRDR ppRdr, const char *pszFilename);125 126 int kRdrClose( PKRDR pRdr);127 int kRdrRead( PKRDR pRdr, void *pvBuf, size_t cb, KLDRFOFF off);128 int kRdrAllMap( PKRDR pRdr, const void **ppvBits);129 int kRdrAllUnmap(PKRDR pRdr, const void *pvBits);130 KFOFF kRdrSize( PKRDR pRdr);131 KFOFF kRdrTell( PKRDR pRdr);132 const char *kRdrName(PKRDR pRdr);133 KIPTR kRdrNativeFH(PKRDR pRdr);134 135 KSIZE kRdrPageSize(PKRDR pRdr);136 int kRdrMap( PKRDR pRdr, void **ppvBase, KU32 cSegments, PCKLDRSEG paSegments, unsigned fFixed);137 int kRdrRefresh( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments);138 int kRdrProtect( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments, unsigned fUnprotectOrProtect);139 int kRdrUnmap( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments);140 void kRdrDone( PKRDR pRdr);141 115 142 116 /** @} */ -
trunk/kStuff/kDbg/kDbgModule.cpp
r3541 r3543 6 6 /* 7 7 * Copyright (c) 2007 knut st. osmundsen <bird-src-spam@anduin.net> 8 *9 8 * 10 9 * This file is part of kStuff. … … 31 30 * Header Files * 32 31 *******************************************************************************/ 33 #include <k/kDbg .h>32 #include <k/kDbgAll.h> 34 33 #include <k/kErrors.h> 35 34 #include <string.h> -
trunk/kStuff/kLdr/kLdrRdr.c
r3537 r3543 29 29 * Header Files * 30 30 *******************************************************************************/ 31 #include <k Ldr.h>31 #include <k/kRdr.h> 32 32 #include "kLdrInternal.h" 33 33 -
trunk/kStuff/kRdr/kRdr.c
r3537 r3543 1 1 /* $Id$ */ 2 2 /** @file 3 * 4 * kLdr - The Dynamic Loader, file abstraction.5 * 6 * Copyright (c) 2006 knut st. osmundsen <bird-kbuild-src@anduin.net> 7 * 8 * 9 * This file is part of k Ldr.10 * 11 * k Ldris 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, or3 * kRdr - The File Provider. 4 */ 5 6 /* 7 * Copyright (c) 2006-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 modify 12 * it under the terms of the GNU Lesser General Public License as published 13 * by the Free Software Foundation; either version 2 of the License, or 14 14 * (at your option) any later version. 15 15 * 16 * k Ldris distributed in the hope that it will be useful,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 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 License22 * along with k Ldr; if not, write to the Free Software19 * GNU Lesser General Public License for more details. 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * along with kStuff; if not, write to the Free Software 23 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 24 * … … 29 29 * Header Files * 30 30 *******************************************************************************/ 31 #include <kLdr.h> 32 #include "kLdrInternal.h" 33 34 35 /******************************************************************************* 36 * Defined Constants And Macros * 37 *******************************************************************************/ 38 /** @def KLDRRDR_STRICT 39 * Define KLDRRDR_STRICT to enabled strict checks in KLDRMOD. */ 40 #define KLDRRDR_STRICT 1 41 42 /** @def KLDRRDR_ASSERT 43 * Assert that an expression is true when KLDR_STRICT is defined. 44 */ 45 #ifdef KLDRRDR_STRICT 46 # define KLDRRDR_ASSERT(expr) kldrHlpAssert(expr) 47 #else 48 # define KLDRRDR_ASSERT(expr) do {} while (0) 49 #endif 50 51 /** Return / crash validation of a reader argument. */ 52 #define KLDRRDR_VALIDATE_EX(pRdr, rc) \ 53 do { \ 54 if ( (pRdr)->u32Magic != KLDRRDR_MAGIC \ 55 || (pRdr)->pOps == NULL \ 56 )\ 57 { \ 58 return (rc); \ 59 } \ 60 } while (0) 61 62 /** Return / crash validation of a reader argument. */ 63 #define KLDRRDR_VALIDATE(pRdr) \ 64 KLDRRDR_VALIDATE_EX(pRdr, KLDR_ERR_INVALID_PARAMETER) 65 66 /** Return / crash validation of a reader argument. */ 67 #define KLDRRDR_VALIDATE_VOID(pRdr) \ 68 do { \ 69 if ( (pRdr)->u32Magic != KLDRRDR_MAGIC \ 70 || (pRdr)->pOps == NULL \ 71 )\ 72 { \ 73 return; \ 74 } \ 75 } while (0) 76 31 #include <k/kRdrAll.h> 32 #include <k/kErrors.h> 33 #include "kRdrInternal.h" 77 34 78 35 … … 81 38 *******************************************************************************/ 82 39 /** The list of file providers. */ 83 static PCK LDRRDROPS g_pRdrHead = &g_kLdrRdrFileOps;40 static PCKRDROPS g_pRdrHead = &g_kRdrFileOps; 84 41 85 42 … … 89 46 * @param pAdd The new file provider. 90 47 */ 91 void k LdrRdrAddProvider(PKLDRRDROPS pAdd)48 void kRdrAddProvider(PKRDROPS pAdd) 92 49 { 93 50 pAdd->pNext = g_pRdrHead; … … 103 60 * @param pszFilename The filename. 104 61 */ 105 int k LdrRdrOpen(PPKLDRRDR ppRdr, const char *pszFilename)62 int kRdrOpen(PPKRDR ppRdr, const char *pszFilename) 106 63 { 107 64 int rc = -1; 108 PCK LDRRDROPS pCur;65 PCKRDROPS pCur; 109 66 for (pCur = g_pRdrHead; pCur; pCur = pCur->pNext) 110 67 { … … 124 81 * @param pRdr The file provider instance. 125 82 */ 126 int k LdrRdrClose(PKLDRRDR pRdr)127 { 128 K LDRRDR_VALIDATE(pRdr);83 int kRdrClose(PKRDR pRdr) 84 { 85 KRDR_VALIDATE(pRdr); 129 86 return pRdr->pOps->pfnDestroy(pRdr); 130 87 } … … 139 96 * @param off Where to start reading. 140 97 */ 141 int k LdrRdrRead(PKLDRRDR pRdr, void *pvBuf, size_t cb, KLDRFOFF off)142 { 143 K LDRRDR_VALIDATE(pRdr);98 int kRdrRead(PKRDR pRdr, void *pvBuf, KSIZE cb, KFOFF off) 99 { 100 KRDR_VALIDATE(pRdr); 144 101 return pRdr->pOps->pfnRead(pRdr, pvBuf, cb, off); 145 102 } … … 153 110 * The size can be obtained using pfnSize. 154 111 */ 155 int k LdrRdrAllMap(PKLDRRDR pRdr, const void **ppvBits)156 { 157 K LDRRDR_VALIDATE(pRdr);112 int kRdrAllMap(PKRDR pRdr, const void **ppvBits) 113 { 114 KRDR_VALIDATE(pRdr); 158 115 return pRdr->pOps->pfnAllMap(pRdr, ppvBits); 159 116 } 160 117 161 118 162 /** Unmap a file bits mapping obtained by K LDRRDROPS::pfnAllMap.119 /** Unmap a file bits mapping obtained by KRDROPS::pfnAllMap. 163 120 * 164 121 * @returns 0 on success, OS specific error code on failure. … … 166 123 * @param pvBits The mapping address. 167 124 */ 168 int k LdrRdrAllUnmap(PKLDRRDR pRdr, const void *pvBits)169 { 170 K LDRRDR_VALIDATE(pRdr);125 int kRdrAllUnmap(PKRDR pRdr, const void *pvBits) 126 { 127 KRDR_VALIDATE(pRdr); 171 128 return pRdr->pOps->pfnAllUnmap(pRdr, pvBits); 172 129 } … … 178 135 * @param pRdr The file provider instance. 179 136 */ 180 K LDRFOFF kLdrRdrSize(PKLDRRDR pRdr)181 { 182 K LDRRDR_VALIDATE(pRdr);137 KFOFF kRdrSize(PKRDR pRdr) 138 { 139 KRDR_VALIDATE(pRdr); 183 140 return pRdr->pOps->pfnSize(pRdr); 184 141 } … … 190 147 * @param pRdr The file provider instance. 191 148 */ 192 K LDRFOFF kLdrRdrTell(PKLDRRDR pRdr)193 { 194 K LDRRDR_VALIDATE(pRdr);149 KFOFF kRdrTell(PKRDR pRdr) 150 { 151 KRDR_VALIDATE(pRdr); 195 152 return pRdr->pOps->pfnTell(pRdr); 196 153 } … … 202 159 * @param pRdr The file provider instance. 203 160 */ 204 const char *k LdrRdrName(PKLDRRDR pRdr)205 { 206 K LDRRDR_VALIDATE_EX(pRdr, NULL);161 const char *kRdrName(PKRDR pRdr) 162 { 163 KRDR_VALIDATE_EX(pRdr, NULL); 207 164 return pRdr->pOps->pfnName(pRdr); 208 165 } 209 166 210 167 168 /** Get the native file handle if possible. 169 * 170 * @returns The native file handle. Returns -1 if not available. 171 * @param pRdr The file provider instance. 172 */ 173 KIPTR kRdrNativeFH(PKRDR pRdr) 174 { 175 KRDR_VALIDATE_EX(pRdr, -1); 176 return pRdr->pOps->pfnNativeFH(pRdr); 177 } 178 179 211 180 /** 212 181 * Gets the page size used when mapping sections of the file. … … 215 184 * @param pRdr The file provider instance. 216 185 */ 217 size_t kLdrRdrPageSize(PKLDRRDR pRdr)218 { 219 K LDRRDR_VALIDATE_EX(pRdr, 0x10000);186 KSIZE kRdrPageSize(PKRDR pRdr) 187 { 188 KRDR_VALIDATE_EX(pRdr, 0x10000); 220 189 return pRdr->pOps->pfnPageSize(pRdr); 221 190 } … … 236 205 * @param fFixed If set, the address at *ppvBase should be the base address of the mapping. 237 206 */ 238 int k LdrRdrMap(PKLDRRDR pRdr, void **ppvBase, uint32_tcSegments, PCKLDRSEG paSegments, unsigned fFixed)239 { 240 K LDRRDR_VALIDATE(pRdr);207 int kRdrMap(PKRDR pRdr, void **ppvBase, KU32 cSegments, PCKLDRSEG paSegments, unsigned fFixed) 208 { 209 KRDR_VALIDATE(pRdr); 241 210 return pRdr->pOps->pfnMap(pRdr, ppvBase, cSegments, paSegments, fFixed); 242 211 } … … 252 221 * @param paSegments The segments thats going to be mapped. 253 222 */ 254 int k LdrRdrRefresh(PKLDRRDR pRdr, void *pvBase, uint32_tcSegments, PCKLDRSEG paSegments)255 { 256 K LDRRDR_VALIDATE(pRdr);223 int kRdrRefresh(PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments) 224 { 225 KRDR_VALIDATE(pRdr); 257 226 return pRdr->pOps->pfnRefresh(pRdr, pvBase, cSegments, paSegments); 258 227 } … … 273 242 * When clean the segment protection is restored. 274 243 */ 275 int k LdrRdrProtect(PKLDRRDR pRdr, void *pvBase, uint32_tcSegments, PCKLDRSEG paSegments, unsigned fUnprotectOrProtect)276 { 277 K LDRRDR_VALIDATE(pRdr);244 int kRdrProtect(PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments, unsigned fUnprotectOrProtect) 245 { 246 KRDR_VALIDATE(pRdr); 278 247 return pRdr->pOps->pfnProtect(pRdr, pvBase, cSegments, paSegments, fUnprotectOrProtect); 279 248 } … … 289 258 * @param paSegments The segments thats going to be mapped. 290 259 */ 291 int k LdrRdrUnmap(PKLDRRDR pRdr, void *pvBase, uint32_tcSegments, PCKLDRSEG paSegments)292 { 293 K LDRRDR_VALIDATE(pRdr);260 int kRdrUnmap(PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments) 261 { 262 KRDR_VALIDATE(pRdr); 294 263 return pRdr->pOps->pfnUnmap(pRdr, pvBase, cSegments, paSegments); 295 264 } … … 304 273 * @param pRdr The file provider instance. 305 274 */ 306 void k LdrRdrDone(PKLDRRDR pRdr)307 { 308 K LDRRDR_VALIDATE_VOID(pRdr);275 void kRdrDone(PKRDR pRdr) 276 { 277 KRDR_VALIDATE_VOID(pRdr); 309 278 pRdr->pOps->pfnDone(pRdr); 310 279 }
Note:
See TracChangeset
for help on using the changeset viewer.