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/kHlpBareHeap.c

    r3570 r3573  
    11/* $Id$ */
    22/** @file
    3  *
    4  * kLdr - The Dynamic Loader, Helper Functions, Heap.
    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
    14  * (at your option) any later version.
    15  *
    16  * kLdr is distributed in the hope that it will be useful,
     3 * kHlpBare - Heap.
     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
     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
     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
    2424 *
    2525 */
     
    3030*   Header Files                                                               *
    3131*******************************************************************************/
    32 #ifdef __OS2__
     32#include <k/kHlpAlloc.h>
     33
     34#if K_OS == K_OS_OS2
    3335# define INCL_BASE
    3436# define INCL_ERRORS
    3537# include <os2.h>
    36 #elif defined(__WIN__)
     38#elif  K_OS == K_OS_WINDOWS
    3739# include <Windows.h>
    3840#else
    3941# error "port me"
    4042#endif
    41 
    42 #include <k/kLdr.h>
    43 #include "kLdrHlp.h"
    44 
    4543
    4644
     
    8785 * Assert that a heap free block is valid. */
    8886#ifdef KLDRHEAP_STRICT
    89 # define KLDRHEAP_ASSERT(expr)      kldrHlpAssert(expr)
     87# define KLDRHEAP_ASSERT(expr)      kHlpAssert(expr)
    9088
    9189# define KLDRHEAP_ASSERT_BLOCK(pHeap, pBlock) \
     
    193191 * @returns 0 on success, non-zero OS specific status code on failure.
    194192 */
    195 int kldrHlpHeapInit(void)
     193KHLP_DECL(int) kHlpHeapInit(void)
    196194{
    197195    return kLdrHeapInit(&g_Heap);
     
    202200 * Terminates the kLdr heap.
    203201 */
    204 void kldrHlpHeapTerm(void)
     202KHLP_DECL(void) kHlpHeapTerm(void)
    205203{
    206204    kLdrHeapDelete(&g_Heap);
     
    214212 * @param   cb      The requested heap block size.
    215213 */
    216 void *kldrHlpAlloc(KSIZE cb)
     214KHLP_DECL(void *) kHlpAlloc(KSIZE cb)
    217215{
    218216    return kLdrHeapAlloc(&g_Heap, cb);
     
    226224 * @param   cb      The requested heap block size.
    227225 */
    228 void *kldrHlpAllocZ(KSIZE cb)
     226KHLP_DECL(void *) kHlpAllocZ(KSIZE cb)
    229227{
    230228    void *pv = kLdrHeapAlloc(&g_Heap, cb);
    231229    if (pv)
    232         kLdrHlpMemSet(pv, 0, cb);
     230        kHlpMemSet(pv, 0, cb);
    233231    return pv;
    234232}
     
    238236 * Frees memory allocated off the kLdr heap.
    239237 *
    240  * @param   pv      Pointer to the heap block returned by kldrHlpAlloc().
    241  */
    242 void kldrHlpFree(void *pv)
     238 * @param   pv      Pointer to the heap block returned by kHlpAlloc().
     239 */
     240KHLP_DECL(void) kHlpFree(void *pv)
    243241{
    244242    kLdrHeapFree(&g_Heap, pv);
     
    252250 * @param   cb      The amount of memory.
    253251 */
    254 void kldrHlpHeapDonate(void *pv, KSIZE cb)
     252KHLP_DECL(void) kHlpHeapDonate(void *pv, KSIZE cb)
    255253{
    256254    kLdrHeapDonate(&g_Heap, pv, cb);
     
    652650static int kLdrHeapSegAlloc(PKLDRHEAPSEG pSeg, KSIZE cbMin)
    653651{
    654 #ifdef __OS2__
     652#if K_OS == K_OS_OS2
    655653    APIRET rc;
    656654
     
    667665    }
    668666
    669 #elif defined(__WIN__)
     667#elif  K_OS == K_OS_WINDOWS
    670668    pSeg->cb = (cbMin + 0xffff) & ~(KSIZE)0xffff;
    671669    pSeg->pvBase = VirtualAlloc(NULL, pSeg->cb, MEM_COMMIT, PAGE_READWRITE);
     
    691689static void kLdrHeapSegFree(PKLDRHEAPSEG pSeg)
    692690{
    693 #ifdef __OS2__
     691#if K_OS == K_OS_OS2
    694692    APIRET rc = DosFreeMem(pSeg->pvBase);
    695693    KLDRHEAP_ASSERT(!rc); (void)rc;
    696694
    697 #elif defined(__WIN__)
     695#elif  K_OS == K_OS_WINDOWS
    698696    BOOL fRc = VirtualFree(pSeg->pvBase, 0 /*pSeg->cb*/, MEM_RELEASE);
    699697    KLDRHEAP_ASSERT(fRc); (void)fRc;
Note: See TracChangeset for help on using the changeset viewer.