Changeset 3543


Ignore:
Timestamp:
Aug 25, 2007, 8:10:29 AM (18 years ago)
Author:
bird
Message:

kRdr hacking.

Location:
trunk/kStuff
Files:
7 added
3 edited
3 copied

Legend:

Unmodified
Added
Removed
  • trunk/kStuff/include/k/kRdr.h

    r3542 r3543  
    2929
    3030#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>
    3632
    3733#ifdef __cplusplus
     
    4339 * @{ */
    4440
    45 /** Pointer to a file provider instance core. */
     41/** Pointer to a file provider instance. */
    4642typedef struct KRDR *PKRDR;
    47 /** Pointer to a file provider instance core pointer. */
     43/** Pointer to a file provider instance pointer. */
    4844typedef struct KRDR **PPKRDR;
    49 
    50 /**
    51  * File provider instance operations.
    52  */
    53 typedef struct KRDROPS
    54 {
    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 KRDR
    111 {
    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   0x19610919
    120 
    121 void    kRdrAddProvider(PKRDROPS pAdd);
    12245
    12346int     kRdrOpen(PPKRDR ppRdr, const char *pszFilename);
    12447int     kRdrOpenBuffered(PPKRDR ppRdr, const char *pszFilename);
    125 
    12648int     kRdrClose(   PKRDR pRdr);
    127 int     kRdrRead(    PKRDR pRdr, void *pvBuf, size_t cb, KLDRFOFF off);
     49int     kRdrRead(    PKRDR pRdr, void *pvBuf, KSIZE cb, KFOFF off);
    12850int     kRdrAllMap(  PKRDR pRdr, const void **ppvBits);
    12951int     kRdrAllUnmap(PKRDR pRdr, const void *pvBits);
     
    13254const char *kRdrName(PKRDR pRdr);
    13355KIPTR   kRdrNativeFH(PKRDR pRdr);
    134 
    13556KSIZE   kRdrPageSize(PKRDR pRdr);
     57#ifndef ___k_kLdr___
    13658int     kRdrMap(     PKRDR pRdr, void **ppvBase, KU32 cSegments, PCKLDRSEG paSegments, unsigned fFixed);
    13759int     kRdrRefresh( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments);
    13860int     kRdrProtect( PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments, unsigned fUnprotectOrProtect);
    13961int     kRdrUnmap(   PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments);
     62#endif /* !___k_kLdr___ */
    14063void    kRdrDone(    PKRDR pRdr);
    14164
  • trunk/kStuff/include/k/kRdrAll.h

    r3542 r3543  
    11/* $Id$ */
    22/** @file
    3  * kRdr - The File Provider.
     3 * kRdr - The File Provider, All Dependencies Included.
    44 */
    55
     
    2525 */
    2626
    27 #ifndef ___kRdr_h___
    28 #define ___kRdr_h___
     27#ifndef ___kRdrAll_h___
     28#define ___kRdrAll_h___
    2929
    3030#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>
    3633
    3734#ifdef __cplusplus
     
    4037
    4138
    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 */
    4943
    5044/**
     
    7367    int     (* pfnDestroy)( PKRDR pRdr);
    7468    /** @copydoc kRdrRead */
    75     int     (* pfnRead)(    PKRDR pRdr, void *pvBuf, size_t cb, KLDRFOFF off);
     69    int     (* pfnRead)(    PKRDR pRdr, void *pvBuf, size_t cb, KFOFF off);
    7670    /** @copydoc kRdrAllMap */
    7771    int     (* pfnAllMap)(  PKRDR pRdr, const void **ppvBits);
     
    8478    /** @copydoc kRdrName */
    8579    const char * (* pfnName)(PKRDR pRdr);
     80    /** @copydoc kRdrNativeFH */
     81    KIPTR  (* pfnNativeFH)(PKRDR pRdr);
    8682    /** @copydoc kRdrPageSize */
    8783    KSIZE   (* pfnPageSize)(PKRDR pRdr);
     
    110106typedef struct KRDR
    111107{
    112     /** Magic number (KLDRRDR_MAGIC). */
     108    /** Magic number (KRDR_MAGIC). */
    113109    KU32        u32Magic;
    114110    /** Pointer to the file provider operations. */
     
    116112} KRDR;
    117113
    118 /** The magic for KRDR::u32Magic. (Katsu Aki (Katsuaki Nakamura)) */
    119 #define KRDR_MAGIC   0x19610919
    120 
    121114void    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);
    141115
    142116/** @} */
  • trunk/kStuff/kDbg/kDbgModule.cpp

    r3541 r3543  
    66/*
    77 * Copyright (c) 2007 knut st. osmundsen <bird-src-spam@anduin.net>
    8  *
    98 *
    109 * This file is part of kStuff.
     
    3130*   Header Files                                                               *
    3231*******************************************************************************/
    33 #include <k/kDbg.h>
     32#include <k/kDbgAll.h>
    3433#include <k/kErrors.h>
    3534#include <string.h>
  • trunk/kStuff/kLdr/kLdrRdr.c

    r3537 r3543  
    2929*   Header Files                                                               *
    3030*******************************************************************************/
    31 #include <kLdr.h>
     31#include <k/kRdr.h>
    3232#include "kLdrInternal.h"
    3333
  • trunk/kStuff/kRdr/kRdr.c

    r3537 r3543  
    11/* $Id$ */
    22/** @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 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
     3 * 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
    1414 * (at your option) any later version.
    1515 *
    16  * kLdr is distributed in the hope that it will be useful,
     16 * kStuff is distributed in the hope that it will be useful,
    1717 * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1818 * 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
     19 * 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
    2323 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    2424 *
     
    2929*   Header Files                                                               *
    3030*******************************************************************************/
    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"
    7734
    7835
     
    8138*******************************************************************************/
    8239/** The list of file providers. */
    83 static PCKLDRRDROPS g_pRdrHead = &g_kLdrRdrFileOps;
     40static PCKRDROPS g_pRdrHead = &g_kRdrFileOps;
    8441
    8542
     
    8946 * @param   pAdd        The new file provider.
    9047 */
    91 void kLdrRdrAddProvider(PKLDRRDROPS pAdd)
     48void kRdrAddProvider(PKRDROPS pAdd)
    9249{
    9350    pAdd->pNext = g_pRdrHead;
     
    10360 * @param   pszFilename     The filename.
    10461 */
    105 int kLdrRdrOpen(PPKLDRRDR ppRdr, const char *pszFilename)
     62int kRdrOpen(PPKRDR ppRdr, const char *pszFilename)
    10663{
    10764    int             rc = -1;
    108     PCKLDRRDROPS    pCur;
     65    PCKRDROPS    pCur;
    10966    for (pCur = g_pRdrHead; pCur; pCur = pCur->pNext)
    11067    {
     
    12481 * @param   pRdr        The file provider instance.
    12582 */
    126 int kLdrRdrClose(PKLDRRDR pRdr)
    127 {
    128     KLDRRDR_VALIDATE(pRdr);
     83int kRdrClose(PKRDR pRdr)
     84{
     85    KRDR_VALIDATE(pRdr);
    12986    return pRdr->pOps->pfnDestroy(pRdr);
    13087}
     
    13996 * @param   off         Where to start reading.
    14097 */
    141 int kLdrRdrRead(PKLDRRDR pRdr, void *pvBuf, size_t cb, KLDRFOFF off)
    142 {
    143     KLDRRDR_VALIDATE(pRdr);
     98int kRdrRead(PKRDR pRdr, void *pvBuf, KSIZE cb, KFOFF off)
     99{
     100    KRDR_VALIDATE(pRdr);
    144101    return pRdr->pOps->pfnRead(pRdr, pvBuf, cb, off);
    145102}
     
    153110 *                      The size can be obtained using pfnSize.
    154111 */
    155 int kLdrRdrAllMap(PKLDRRDR pRdr, const void **ppvBits)
    156 {
    157     KLDRRDR_VALIDATE(pRdr);
     112int kRdrAllMap(PKRDR pRdr, const void **ppvBits)
     113{
     114    KRDR_VALIDATE(pRdr);
    158115    return pRdr->pOps->pfnAllMap(pRdr, ppvBits);
    159116}
    160117
    161118
    162 /** Unmap a file bits mapping obtained by KLDRRDROPS::pfnAllMap.
     119/** Unmap a file bits mapping obtained by KRDROPS::pfnAllMap.
    163120 *
    164121 * @returns 0 on success, OS specific error code on failure.
     
    166123 * @param   pvBits      The mapping address.
    167124 */
    168 int kLdrRdrAllUnmap(PKLDRRDR pRdr, const void *pvBits)
    169 {
    170     KLDRRDR_VALIDATE(pRdr);
     125int kRdrAllUnmap(PKRDR pRdr, const void *pvBits)
     126{
     127    KRDR_VALIDATE(pRdr);
    171128    return pRdr->pOps->pfnAllUnmap(pRdr, pvBits);
    172129}
     
    178135 * @param   pRdr        The file provider instance.
    179136 */
    180 KLDRFOFF kLdrRdrSize(PKLDRRDR pRdr)
    181 {
    182     KLDRRDR_VALIDATE(pRdr);
     137KFOFF kRdrSize(PKRDR pRdr)
     138{
     139    KRDR_VALIDATE(pRdr);
    183140    return pRdr->pOps->pfnSize(pRdr);
    184141}
     
    190147 * @param   pRdr        The file provider instance.
    191148 */
    192 KLDRFOFF kLdrRdrTell(PKLDRRDR pRdr)
    193 {
    194     KLDRRDR_VALIDATE(pRdr);
     149KFOFF kRdrTell(PKRDR pRdr)
     150{
     151    KRDR_VALIDATE(pRdr);
    195152    return pRdr->pOps->pfnTell(pRdr);
    196153}
     
    202159 * @param   pRdr        The file provider instance.
    203160 */
    204 const char *kLdrRdrName(PKLDRRDR pRdr)
    205 {
    206     KLDRRDR_VALIDATE_EX(pRdr, NULL);
     161const char *kRdrName(PKRDR pRdr)
     162{
     163    KRDR_VALIDATE_EX(pRdr, NULL);
    207164    return pRdr->pOps->pfnName(pRdr);
    208165}
    209166
    210167
     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 */
     173KIPTR kRdrNativeFH(PKRDR pRdr)
     174{
     175    KRDR_VALIDATE_EX(pRdr, -1);
     176    return pRdr->pOps->pfnNativeFH(pRdr);
     177}
     178
     179
    211180/**
    212181 * Gets the page size used when mapping sections of the file.
     
    215184 * @param   pRdr        The file provider instance.
    216185 */
    217 size_t  kLdrRdrPageSize(PKLDRRDR pRdr)
    218 {
    219     KLDRRDR_VALIDATE_EX(pRdr, 0x10000);
     186KSIZE kRdrPageSize(PKRDR pRdr)
     187{
     188    KRDR_VALIDATE_EX(pRdr, 0x10000);
    220189    return pRdr->pOps->pfnPageSize(pRdr);
    221190}
     
    236205 * @param   fFixed      If set, the address at *ppvBase should be the base address of the mapping.
    237206 */
    238 int kLdrRdrMap(PKLDRRDR pRdr, void **ppvBase, uint32_t cSegments, PCKLDRSEG paSegments, unsigned fFixed)
    239 {
    240     KLDRRDR_VALIDATE(pRdr);
     207int kRdrMap(PKRDR pRdr, void **ppvBase, KU32 cSegments, PCKLDRSEG paSegments, unsigned fFixed)
     208{
     209    KRDR_VALIDATE(pRdr);
    241210    return pRdr->pOps->pfnMap(pRdr, ppvBase, cSegments, paSegments, fFixed);
    242211}
     
    252221 * @param   paSegments  The segments thats going to be mapped.
    253222 */
    254 int kLdrRdrRefresh(PKLDRRDR pRdr, void *pvBase, uint32_t cSegments, PCKLDRSEG paSegments)
    255 {
    256     KLDRRDR_VALIDATE(pRdr);
     223int kRdrRefresh(PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments)
     224{
     225    KRDR_VALIDATE(pRdr);
    257226    return pRdr->pOps->pfnRefresh(pRdr, pvBase, cSegments, paSegments);
    258227}
     
    273242 *                                  When clean the segment protection is restored.
    274243 */
    275 int kLdrRdrProtect(PKLDRRDR pRdr, void *pvBase, uint32_t cSegments, PCKLDRSEG paSegments, unsigned fUnprotectOrProtect)
    276 {
    277     KLDRRDR_VALIDATE(pRdr);
     244int kRdrProtect(PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments, unsigned fUnprotectOrProtect)
     245{
     246    KRDR_VALIDATE(pRdr);
    278247    return pRdr->pOps->pfnProtect(pRdr, pvBase, cSegments, paSegments, fUnprotectOrProtect);
    279248}
     
    289258 * @param   paSegments  The segments thats going to be mapped.
    290259 */
    291 int kLdrRdrUnmap(PKLDRRDR pRdr, void *pvBase, uint32_t cSegments, PCKLDRSEG paSegments)
    292 {
    293     KLDRRDR_VALIDATE(pRdr);
     260int kRdrUnmap(PKRDR pRdr, void *pvBase, KU32 cSegments, PCKLDRSEG paSegments)
     261{
     262    KRDR_VALIDATE(pRdr);
    294263    return pRdr->pOps->pfnUnmap(pRdr, pvBase, cSegments, paSegments);
    295264}
     
    304273 * @param   pRdr        The file provider instance.
    305274 */
    306 void kLdrRdrDone(PKLDRRDR pRdr)
    307 {
    308     KLDRRDR_VALIDATE_VOID(pRdr);
     275void kRdrDone(PKRDR pRdr)
     276{
     277    KRDR_VALIDATE_VOID(pRdr);
    309278    pRdr->pOps->pfnDone(pRdr);
    310279}
Note: See TracChangeset for help on using the changeset viewer.