source: trunk/src/emx/src/lib/sys/DosFreeMemEx.c@ 1519

Last change on this file since 1519 was 1519, checked in by bird, 21 years ago

Big path handling change. Fixed wrong file headers. A new api or two. A bit of restructuring. And hopefully no new bug :-)

  • Property cvs2svn:cvs-rev set to 1.2
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 2.7 KB
Line 
1/* $Id: DosFreeMemEx.c 1519 2004-09-27 02:15:07Z bird $ */
2/** @file
3 *
4 * DosFreeMemEx.
5 *
6 * Copyright (c) 2004 knut st. osmundsen <[email protected]>
7 *
8 *
9 * This file is part of InnoTek LIBC.
10 *
11 * InnoTek LIBC 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 * (at your option) any later version.
15 *
16 * InnoTek LIBC is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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 InnoTek LIBC; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 *
25 */
26
27/*******************************************************************************
28* Header Files *
29*******************************************************************************/
30#include "libc-alias.h"
31#define INCL_ERRORS
32#define INCL_DOSMEMMGR
33#define INCL_FSMACROS
34#define INCL_EXAPIS
35#include <os2emx.h>
36#define __LIBC_LOG_GROUP __LIBC_LOG_GRP_DOSEX
37#include <InnoTekLIBC/logstrict.h>
38#include "DosEx.h"
39
40
41/**
42 * Free memory allocated by DosAllocMemEx.
43 *
44 * @returns See DosFreeMem().
45 * @param pv Address of the memory to free.
46 */
47APIRET APIENTRY DosFreeMemEx(PVOID pv)
48{
49 LIBCLOG_ENTER("pv=%p\n", pv);
50 DOSEXTYPE enmType;
51 int rc;
52 FS_VAR();
53
54 /*
55 * Validate input.
56 */
57 if (!pv)
58 LIBCLOG_RETURN_INT(ERROR_INVALID_ADDRESS);
59
60 /*
61 * We'll make guesses at which type to try first based on the address.
62 * It's difficult to tell exactly but we say that 3/4 of the address space
63 * below 512MB is shared. As for the high memory it's harder to say,
64 * especially since we don't know the limit of that memory, so there
65 * we'll just say everything about 900MB is more likely to be shared
66 * than private.
67 *
68 * If we don't find the address when both types have been tried
69 * we'll give it to DosFreeMem().
70 */
71 FS_SAVE_LOAD();
72 enmType = (uintptr_t)pv < 128*1024*1024 || ((uintptr_t)pv >= 512*1024*1024 && (uintptr_t)pv < 900*1024*1024)
73 ? DOSEX_TYPE_MEM_ALLOC : DOSEX_TYPE_MEM_OPEN;
74 rc = __libc_dosexFree(enmType, (unsigned)pv);
75 if (rc == -1)
76 {
77 enmType = enmType == DOSEX_TYPE_MEM_OPEN ? DOSEX_TYPE_MEM_ALLOC : DOSEX_TYPE_MEM_OPEN;
78 rc = __libc_dosexFree(enmType, (unsigned)pv);
79 if (rc == -1)
80 rc = DosFreeMem(pv);
81 }
82
83 FS_RESTORE();
84 LIBCLOG_RETURN_INT(rc);
85}
86
Note: See TracBrowser for help on using the repository browser.