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

kRdr hacking.

Location:
trunk/kStuff/kRdr
Files:
1 added
1 copied

Legend:

Unmodified
Added
Removed
  • 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.