2 * Global heap functions
4 * Copyright 1995 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 /* 0xffff sometimes seems to mean: CURRENT_DS */
23 #include "wine/port.h"
25 #include <sys/types.h>
33 #ifdef HAVE_SYS_PARAM_H
34 #include <sys/param.h>
36 #ifdef HAVE_SYS_SYSCTL_H
37 #include <sys/sysctl.h>
40 #include "wine/winbase16.h"
44 #include "selectors.h"
46 #include "stackframe.h"
47 #include "wine/debug.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(global
);
52 /* Global arena block */
55 DWORD base
; /* Base address (0 if discarded) */
56 DWORD size
; /* Size in bytes (0 indicates a free block) */
57 HGLOBAL16 handle
; /* Handle for this block */
58 HGLOBAL16 hOwner
; /* Owner of this block */
59 BYTE lockCount
; /* Count of GlobalFix() calls */
60 BYTE pageLockCount
; /* Count of GlobalPageLock() calls */
61 BYTE flags
; /* Allocation flags */
62 BYTE selCount
; /* Number of selectors allocated for this block */
66 /*static*/ GLOBALARENA
*pGlobalArena
= NULL
;
67 /*static*/ int globalArenaSize
= 0;
69 #define VALID_HANDLE(handle) (((handle)>>__AHSHIFT)<globalArenaSize)
70 #define GET_ARENA_PTR(handle) (pGlobalArena + ((handle) >> __AHSHIFT))
73 /***********************************************************************
74 * GlobalLock16 (KERNEL32.25)
76 * This is the GlobalLock16() function used by 32-bit code.
79 * Pointer to first byte of memory block
82 LPVOID WINAPI
GlobalLock16(
83 HGLOBAL16 handle
/* [in] Handle of global memory object */
85 if (!handle
) return 0;
86 if (!VALID_HANDLE(handle
))
88 GET_ARENA_PTR(handle
)->lockCount
++;
89 return (LPVOID
)GET_ARENA_PTR(handle
)->base
;
93 /***********************************************************************
94 * FarGetOwner (KERNEL.404)
96 HANDLE16 WINAPI
FarGetOwner16( HGLOBAL16 handle
)
98 if (!VALID_HANDLE(handle
)) {
99 WARN("Invalid handle 0x%04x passed to FarGetOwner!\n",handle
);
102 return GET_ARENA_PTR(handle
)->hOwner
;