Ignore:
Timestamp:
Aug 31, 2007, 6:09:23 AM (18 years ago)
Author:
bird
Message:

kHlp work...

Location:
trunk/kStuff/kHlp/Bare
Files:
1 added
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/kStuff/kHlp/Bare/kHlpBareMem.c

    r3571 r3573  
    11/* $Id$ */
    22/** @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 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,
     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,
    1717 * 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 */
    2726
    2827/*******************************************************************************
    2928*   Header Files                                                               *
    3029*******************************************************************************/
    31 #ifdef __OS2__
     30#include <k/kHlpAlloc.h>
     31
     32#if K_OS == K_OS_OS2
    3233# define INCL_BASE
    3334# define INCL_ERRORS
    3435# include <os2.h>
    35 #elif defined(__WIN__)
     36#elif  K_OS == K_OS_WINDOWS
    3637# include <Windows.h>
    3738#else
    3839# error "port me"
    3940#endif
    40 
    41 #include <k/kLdr.h>
    42 #include "kLdrHlp.h"
    4341
    4442
     
    4644*   Global Variables                                                           *
    4745*******************************************************************************/
    48 #ifdef __OS2__
     46#if K_OS == K_OS_OS2
    4947/** The base of the stub object.
    5048 * The OS/2 exe stub consists of a single data object. When allocating memory
     
    5452static KSIZE            g_cbStub = 0;
    5553
    56 #elif defined(__WIN__)
     54#elif  K_OS == K_OS_WINDOWS
    5755/** The system info. */
    5856static SYSTEM_INFO      g_SystemInfo;
     
    6361
    6462
    65 #ifdef __OS2__
    66 static ULONG kldrHlpPageProtToNative(KPROT enmProt)
     63#if K_OS == K_OS_OS2
     64static ULONG kHlpPageProtToNative(KPROT enmProt)
    6765{
    6866    switch (enmProt)
     
    7573        case KPROT_EXECUTE_READWRITE:    return PAG_COMMIT | PAG_EXECUTE | PAG_READ | PAG_WRITE;
    7674        default:
    77             kldrHlpAssert(0);
     75            kHlpAssert(0);
    7876            return ~0U;
    7977    }
    8078}
    81 #elif defined(__WIN__)
    82 static DWORD kldrHlpPageProtToNative(KPROT enmProt)
     79#elif  K_OS == K_OS_WINDOWS
     80static DWORD kHlpPageProtToNative(KPROT enmProt)
    8381{
    8482    switch (enmProt)
     
    9189        case KPROT_EXECUTE_READWRITE:    return PAGE_EXECUTE_READWRITE;
    9290        default:
    93             kldrHlpAssert(0);
     91            kHlpAssert(0);
    9492            return ~0U;
    9593    }
     
    107105 * @param   enmProt     The new protection. Copy-on-write is invalid.
    108106 */
    109 int     kldrHlpPageAlloc(void **ppv, KSIZE cb, KPROT enmProt, unsigned fFixed)
    110 {
    111 #ifdef __OS2__
     107KHLP_DECL(int) kHlpPageAlloc(void **ppv, KSIZE cb, KPROT enmProt, KBOOL fFixed)
     108{
     109#if K_OS == K_OS_OS2
    112110    APIRET  rc;
    113     ULONG   fFlags = kldrHlpPageProtToNative(enmProt);;
     111    ULONG   fFlags = kHlpPageProtToNative(enmProt);;
    114112
    115113    if (!fFixed)
     
    128126    if (!rc)
    129127        return 0;
    130     kldrHlpAssert(0);
    131     return rc;
    132 
    133 #elif defined(__WIN__)
     128    kHlpAssert(0);
     129    return rc;
     130
     131#elif  K_OS == K_OS_WINDOWS
    134132    /* (We don't have to care about the stub here, because the stub will be unmapped before we get here.) */
    135133    int     rc;
    136     DWORD   fProt = kldrHlpPageProtToNative(enmProt);
     134    DWORD   fProt = kHlpPageProtToNative(enmProt);
    137135
    138136    if (!g_SystemInfo.dwPageSize)
     
    143141        return 0;
    144142    rc = GetLastError();
    145     kldrHlpAssert(0);
     143    kHlpAssert(0);
    146144    return rc;
    147145
     
    155153 * Change the protection of one or more pages in an allocation.
    156154 *
    157  * (This will of course only work correctly on memory allocated by kldrHlpPageAlloc().)
     155 * (This will of course only work correctly on memory allocated by kHlpPageAlloc().)
    158156 *
    159157 * @returns 0 on success, non-zero OS status code on failure.
     
    162160 * @param   enmProt     The new protection. Copy-on-write is invalid.
    163161 */
    164 int     kldrHlpPageProtect(void *pv, KSIZE cb, KPROT enmProt)
    165 {
    166 #ifdef __OS2__
     162KHLP_DECL(int) kHlpPageProtect(void *pv, KSIZE cb, KPROT enmProt)
     163{
     164#if K_OS == K_OS_OS2
    167165    APIRET      rc;
    168     ULONG       fFlags = kldrHlpPageProtToNative(enmProt);;
     166    ULONG       fFlags = kHlpPageProtToNative(enmProt);;
    169167
    170168    /*
     
    188186        }
    189187    }
    190     kldrHlpAssert(!rc);
    191     return rc;
    192 
    193 #elif defined(__WIN__)
     188    kHlpAssert(!rc);
     189    return rc;
     190
     191#elif  K_OS == K_OS_WINDOWS
    194192    DWORD fOldProt = 0;
    195     DWORD fProt = kldrHlpPageProtToNative(enmProt);
     193    DWORD fProt = kHlpPageProtToNative(enmProt);
    196194    int rc = 0;
    197195
     
    199197    {
    200198        rc = GetLastError();
    201         kldrHlpAssert(0);
     199        kHlpAssert(0);
    202200    }
    203201    return rc;
     
    209207
    210208/**
    211  * Free memory allocated by kldrHlpPageAlloc().
     209 * Free memory allocated by kHlpPageAlloc().
    212210 *
    213211 * @returns 0 on success, non-zero OS status code on failure.
    214  * @param   pv          The address returned by kldrHlpPageAlloc().
    215  * @param   cb          The byte count requested from kldrHlpPageAlloc().
    216  */
    217 int     kldrHlpPageFree(void *pv, KSIZE cb)
    218 {
    219 #ifdef __OS2__
     212 * @param   pv          The address returned by kHlpPageAlloc().
     213 * @param   cb          The byte count requested from kHlpPageAlloc().
     214 */
     215KHLP_DECL(int) skHlpPageFree(void *pv, KSIZE cb)
     216{
     217#if K_OS == K_OS_OS2
    220218    APIRET rc;
    221219
     
    242240            if (rc)
    243241            {
    244                 kldrHlpAssert(!rc);
     242                kHlpAssert(!rc);
    245243                return rc;
    246244            }
     
    259257     */
    260258    rc = DosFreeMem(pv);
    261     kldrHlpAssert(!rc);
    262     return rc;
    263 
    264 #elif defined(__WIN__)
     259    kHlpAssert(!rc);
     260    return rc;
     261
     262#elif  K_OS == K_OS_WINDOWS
    265263    /*
    266264     * Free the object.
     
    270268    {
    271269        rc = GetLastError();
    272         kldrHlpAssert(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.