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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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"
42 #include "kernel16_private.h"
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(global
);
47 /* Global arena block */
50 void *base
; /* Base address (0 if discarded) */
51 DWORD size
; /* Size in bytes (0 indicates a free block) */
52 HGLOBAL16 handle
; /* Handle for this block */
53 HGLOBAL16 hOwner
; /* Owner of this block */
54 BYTE lockCount
; /* Count of GlobalFix() calls */
55 BYTE pageLockCount
; /* Count of GlobalPageLock() calls */
56 BYTE flags
; /* Allocation flags */
57 BYTE selCount
; /* Number of selectors allocated for this block */
60 /* Flags definitions */
61 #define GA_MOVEABLE 0x02 /* same as GMEM_MOVEABLE */
62 #define GA_DGROUP 0x04
63 #define GA_DISCARDABLE 0x08
64 #define GA_IPCSHARE 0x10 /* same as GMEM_DDESHARE */
65 #define GA_DOSMEM 0x20
67 /* Arena array (FIXME) */
68 static GLOBALARENA
*pGlobalArena
;
69 static int globalArenaSize
;
71 #define GLOBAL_MAX_ALLOC_SIZE 0x00ff0000 /* Largest allocation is 16M - 64K */
72 #define GLOBAL_MAX_COUNT 8192 /* Max number of allocated blocks */
74 #define VALID_HANDLE(handle) (((handle)>>__AHSHIFT)<globalArenaSize)
75 #define GET_ARENA_PTR(handle) (pGlobalArena + ((handle) >> __AHSHIFT))
77 static HANDLE
get_win16_heap(void)
79 static HANDLE win16_heap
;
81 /* we create global memory block with execute permission. The access can be limited
82 * for 16-bit code on selector level */
83 if (!win16_heap
) win16_heap
= HeapCreate(HEAP_CREATE_ENABLE_EXECUTE
, 0, 0);
87 /***********************************************************************
90 * Return the arena for a given selector, growing the arena array if needed.
92 static GLOBALARENA
*GLOBAL_GetArena( WORD sel
, WORD selcount
)
94 if (((sel
>> __AHSHIFT
) + selcount
) > globalArenaSize
)
96 int newsize
= ((sel
>> __AHSHIFT
) + selcount
+ 0xff) & ~0xff;
100 pGlobalArena
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
101 GLOBAL_MAX_COUNT
* sizeof(GLOBALARENA
) );
102 if (!pGlobalArena
) return 0;
103 /* Hack: store a pointer to it in THHOOK instead of a handle */
104 *(GLOBALARENA
**)&pThhook
->hGlobalHeap
= pGlobalArena
;
106 if (newsize
> GLOBAL_MAX_COUNT
) return 0;
107 globalArenaSize
= newsize
;
109 return pGlobalArena
+ (sel
>> __AHSHIFT
);
112 void debug_handles(void)
116 for (i
= globalArenaSize
-1 ; i
>=0 ; i
--) {
117 if (pGlobalArena
[i
].size
!=0 && (pGlobalArena
[i
].handle
& 0x8000)){
119 DPRINTF("0x%08x, ",pGlobalArena
[i
].handle
);
127 /***********************************************************************
130 * Create a global heap block for a fixed range of linear memory.
132 HGLOBAL16
GLOBAL_CreateBlock( WORD flags
, void *ptr
, DWORD size
,
133 HGLOBAL16 hOwner
, unsigned char selflags
)
138 /* Allocate the selector(s) */
140 sel
= SELECTOR_AllocBlock( ptr
, size
, selflags
);
142 selcount
= (size
+ 0xffff) / 0x10000;
144 if (!(pArena
= GLOBAL_GetArena( sel
, selcount
)))
146 SELECTOR_FreeBlock( sel
);
150 /* Fill the arena block */
153 pArena
->size
= GetSelectorLimit16(sel
) + 1;
154 pArena
->handle
= (flags
& GMEM_MOVEABLE
) ? sel
- 1 : sel
;
155 pArena
->hOwner
= hOwner
;
156 pArena
->lockCount
= 0;
157 pArena
->pageLockCount
= 0;
158 pArena
->flags
= flags
& GA_MOVEABLE
;
159 if (flags
& GMEM_DISCARDABLE
) pArena
->flags
|= GA_DISCARDABLE
;
160 if (flags
& GMEM_DDESHARE
) pArena
->flags
|= GA_IPCSHARE
;
161 if (!(selflags
& (WINE_LDT_FLAGS_CODE
^WINE_LDT_FLAGS_DATA
))) pArena
->flags
|= GA_DGROUP
;
162 pArena
->selCount
= selcount
;
163 if (selcount
> 1) /* clear the next arena blocks */
164 memset( pArena
+ 1, 0, (selcount
- 1) * sizeof(GLOBALARENA
) );
166 return pArena
->handle
;
170 /***********************************************************************
173 * Free a block allocated by GLOBAL_CreateBlock, without touching
174 * the associated linear memory range.
176 BOOL16
GLOBAL_FreeBlock( HGLOBAL16 handle
)
181 if (!handle
) return TRUE
;
182 sel
= GlobalHandleToSel16( handle
);
183 if (!VALID_HANDLE(sel
)) return FALSE
;
184 pArena
= GET_ARENA_PTR(sel
);
187 WARN( "already free %x\n", handle
);
190 SELECTOR_FreeBlock( sel
);
191 memset( pArena
, 0, sizeof(GLOBALARENA
) );
195 /***********************************************************************
198 BOOL16
GLOBAL_MoveBlock( HGLOBAL16 handle
, void *ptr
, DWORD size
)
203 if (!handle
) return TRUE
;
204 sel
= GlobalHandleToSel16( handle
);
205 if (!VALID_HANDLE(sel
)) return FALSE
;
206 pArena
= GET_ARENA_PTR(sel
);
207 if (pArena
->selCount
!= 1)
212 SELECTOR_ReallocBlock( sel
, ptr
, size
);
216 /***********************************************************************
219 * Implementation of GlobalAlloc16()
221 HGLOBAL16
GLOBAL_Alloc( UINT16 flags
, DWORD size
, HGLOBAL16 hOwner
, unsigned char selflags
)
226 TRACE("%d flags=%04x\n", size
, flags
);
228 /* If size is 0, create a discarded block */
230 if (size
== 0) return GLOBAL_CreateBlock( flags
, NULL
, 1, hOwner
, selflags
);
234 if (size
>= GLOBAL_MAX_ALLOC_SIZE
- 0x1f) return 0;
235 size
= (size
+ 0x1f) & ~0x1f;
237 /* Allocate the linear memory */
238 ptr
= HeapAlloc( get_win16_heap(), 0, size
);
239 /* FIXME: free discardable blocks and try again? */
242 /* Allocate the selector(s) */
244 handle
= GLOBAL_CreateBlock( flags
, ptr
, size
, hOwner
, selflags
);
247 HeapFree( get_win16_heap(), 0, ptr
);
251 if (flags
& GMEM_ZEROINIT
) memset( ptr
, 0, size
);
255 /***********************************************************************
256 * GlobalAlloc (KERNEL.15)
257 * GlobalAlloc16 (KERNEL32.24)
259 * Allocate a global memory object.
265 HGLOBAL16 WINAPI
GlobalAlloc16(
266 UINT16 flags
, /* [in] Object allocation attributes */
267 DWORD size
/* [in] Number of bytes to allocate */
269 HANDLE16 owner
= GetCurrentPDB16();
271 if (flags
& GMEM_DDESHARE
)
273 /* make it owned by the calling module */
274 STACK16FRAME
*frame
= CURRENT_STACK16
;
275 owner
= GetExePtr( frame
->cs
);
277 return GLOBAL_Alloc( flags
, size
, owner
, WINE_LDT_FLAGS_DATA
);
281 /***********************************************************************
282 * GlobalReAlloc (KERNEL.16)
284 * Change the size or attributes of a global memory object.
290 HGLOBAL16 WINAPI
GlobalReAlloc16(
291 HGLOBAL16 handle
, /* [in] Handle of global memory object */
292 DWORD size
, /* [in] New size of block */
293 UINT16 flags
/* [in] How to reallocate object */
298 GLOBALARENA
*pArena
, *pNewArena
;
299 WORD sel
= GlobalHandleToSel16( handle
);
300 HANDLE heap
= get_win16_heap();
302 TRACE("%04x %d flags=%04x\n",
303 handle
, size
, flags
);
304 if (!handle
) return 0;
306 if (!VALID_HANDLE(handle
))
308 WARN("Invalid handle 0x%04x!\n", handle
);
311 pArena
= GET_ARENA_PTR( handle
);
313 /* Discard the block if requested */
315 if ((size
== 0) && (flags
& GMEM_MOVEABLE
) && !(flags
& GMEM_MODIFY
))
317 if (!(pArena
->flags
& GA_MOVEABLE
) ||
318 !(pArena
->flags
& GA_DISCARDABLE
) ||
319 (pArena
->lockCount
> 0) || (pArena
->pageLockCount
> 0)) return 0;
320 if (pArena
->flags
& GA_DOSMEM
)
321 DOSMEM_FreeBlock( pArena
->base
);
323 HeapFree( heap
, 0, pArena
->base
);
326 /* Note: we rely on the fact that SELECTOR_ReallocBlock won't
327 * change the selector if we are shrinking the block.
328 * FIXME: shouldn't we keep selectors until the block is deleted?
330 SELECTOR_ReallocBlock( sel
, 0, 1 );
336 if (size
> GLOBAL_MAX_ALLOC_SIZE
- 0x20) return 0;
337 if (size
== 0) size
= 0x20;
338 else size
= (size
+ 0x1f) & ~0x1f;
340 /* Change the flags */
342 if (flags
& GMEM_MODIFY
)
344 /* Change the flags, leaving GA_DGROUP alone */
345 pArena
->flags
= (pArena
->flags
& GA_DGROUP
) | (flags
& GA_MOVEABLE
);
346 if (flags
& GMEM_DISCARDABLE
) pArena
->flags
|= GA_DISCARDABLE
;
350 /* Reallocate the linear memory */
353 oldsize
= pArena
->size
;
354 TRACE("oldbase %p oldsize %08x newsize %08x\n", ptr
,oldsize
,size
);
355 if (ptr
&& (size
== oldsize
)) return handle
; /* Nothing to do */
357 if (pArena
->flags
& GA_DOSMEM
)
359 if (DOSMEM_ResizeBlock(ptr
, size
, TRUE
) == size
)
361 else if(pArena
->pageLockCount
> 0)
365 newptr
= DOSMEM_AllocBlock( size
, 0 );
368 memcpy( newptr
, ptr
, oldsize
);
369 DOSMEM_FreeBlock( ptr
);
376 * if more than one reader (e.g. some pointer has been
377 * given out by GetVDMPointer32W16),
378 * only try to realloc in place
382 newptr
= HeapReAlloc( heap
,
383 (pArena
->pageLockCount
> 0) ? HEAP_REALLOC_IN_PLACE_ONLY
: 0,
386 newptr
= HeapAlloc( heap
, 0, size
);
392 FIXME("Realloc failed lock %d\n",pArena
->pageLockCount
);
393 if (pArena
->pageLockCount
<1)
395 if (pArena
->flags
& GA_DOSMEM
)
396 DOSMEM_FreeBlock( pArena
->base
);
398 HeapFree( heap
, 0, ptr
);
399 SELECTOR_FreeBlock( sel
);
400 memset( pArena
, 0, sizeof(GLOBALARENA
) );
406 /* Reallocate the selector(s) */
408 sel
= SELECTOR_ReallocBlock( sel
, ptr
, size
);
411 if (pArena
->flags
& GA_DOSMEM
)
412 DOSMEM_FreeBlock( pArena
->base
);
414 HeapFree( heap
, 0, ptr
);
415 memset( pArena
, 0, sizeof(GLOBALARENA
) );
418 selcount
= (size
+ 0xffff) / 0x10000;
420 if (!(pNewArena
= GLOBAL_GetArena( sel
, selcount
)))
422 if (pArena
->flags
& GA_DOSMEM
)
423 DOSMEM_FreeBlock( pArena
->base
);
425 HeapFree( heap
, 0, ptr
);
426 SELECTOR_FreeBlock( sel
);
430 /* Fill the new arena block
431 As we may have used HEAP_REALLOC_IN_PLACE_ONLY, areas may overlap*/
433 if (pNewArena
!= pArena
) memmove( pNewArena
, pArena
, sizeof(GLOBALARENA
) );
434 pNewArena
->base
= ptr
;
435 pNewArena
->size
= GetSelectorLimit16(sel
) + 1;
436 pNewArena
->selCount
= selcount
;
437 pNewArena
->handle
= (pNewArena
->flags
& GA_MOVEABLE
) ? sel
- 1 : sel
;
439 if (selcount
> 1) /* clear the next arena blocks */
440 memset( pNewArena
+ 1, 0, (selcount
- 1) * sizeof(GLOBALARENA
) );
442 if ((oldsize
< size
) && (flags
& GMEM_ZEROINIT
))
443 memset( (char *)ptr
+ oldsize
, 0, size
- oldsize
);
444 return pNewArena
->handle
;
448 /***********************************************************************
449 * GlobalFree (KERNEL.17)
450 * GlobalFree16 (KERNEL32.31)
455 HGLOBAL16 WINAPI
GlobalFree16(
456 HGLOBAL16 handle
/* [in] Handle of global memory object */
460 if (!VALID_HANDLE(handle
))
462 WARN("Invalid handle 0x%04x passed to GlobalFree16!\n",handle
);
465 ptr
= GET_ARENA_PTR(handle
)->base
;
467 TRACE("%04x\n", handle
);
468 if (!GLOBAL_FreeBlock( handle
)) return handle
; /* failed */
469 HeapFree( get_win16_heap(), 0, ptr
);
474 /**********************************************************************
475 * K32WOWGlobalLock16 (KERNEL32.60)
477 SEGPTR WINAPI
K32WOWGlobalLock16( HGLOBAL16 handle
)
479 WORD sel
= GlobalHandleToSel16( handle
);
480 TRACE("(%04x) -> %08x\n", handle
, MAKELONG( 0, sel
) );
484 if (handle
== (HGLOBAL16
)-1) handle
= CURRENT_DS
;
486 if (!VALID_HANDLE(handle
)) {
487 WARN("Invalid handle 0x%04x passed to WIN16_GlobalLock16!\n",handle
);
490 else if (!GET_ARENA_PTR(handle
)->base
)
493 GET_ARENA_PTR(handle
)->lockCount
++;
496 return MAKESEGPTR( sel
, 0 );
501 /***********************************************************************
502 * GlobalLock (KERNEL.18)
504 * This is the GlobalLock16() function used by 16-bit code.
506 SEGPTR WINAPI
WIN16_GlobalLock16( HGLOBAL16 handle
)
508 SEGPTR ret
= K32WOWGlobalLock16( handle
);
509 CURRENT_STACK16
->ecx
= SELECTOROF(ret
); /* selector must be returned in CX as well */
514 /***********************************************************************
515 * GlobalLock16 (KERNEL32.25)
517 * This is the GlobalLock16() function used by 32-bit code.
520 * Pointer to first byte of memory block
523 LPVOID WINAPI
GlobalLock16(
524 HGLOBAL16 handle
/* [in] Handle of global memory object */
526 if (!handle
) return 0;
527 if (!VALID_HANDLE(handle
))
529 GET_ARENA_PTR(handle
)->lockCount
++;
530 return GET_ARENA_PTR(handle
)->base
;
534 /***********************************************************************
535 * GlobalUnlock (KERNEL.19)
536 * GlobalUnlock16 (KERNEL32.26)
538 * Should the return values be cast to booleans?
541 * TRUE: Object is still locked
542 * FALSE: Object is unlocked
544 BOOL16 WINAPI
GlobalUnlock16(
545 HGLOBAL16 handle
/* [in] Handle of global memory object */
547 GLOBALARENA
*pArena
= GET_ARENA_PTR(handle
);
548 if (!VALID_HANDLE(handle
)) {
549 WARN("Invalid handle 0x%04x passed to GlobalUnlock16!\n",handle
);
552 TRACE("%04x\n", handle
);
553 if (pArena
->lockCount
) pArena
->lockCount
--;
554 return pArena
->lockCount
;
557 /***********************************************************************
558 * GlobalChangeLockCount (KERNEL.365)
560 * This is declared as a register function as it has to preserve
561 * *all* registers, even AX/DX !
564 void WINAPI
GlobalChangeLockCount16( HGLOBAL16 handle
, INT16 delta
,
568 GlobalLock16( handle
);
569 else if ( delta
== -1 )
570 GlobalUnlock16( handle
);
572 ERR("(%04X, %d): strange delta value\n", handle
, delta
);
575 /***********************************************************************
576 * GlobalSize (KERNEL.20)
577 * GlobalSize16 (KERNEL32.32)
579 * Get the current size of a global memory object.
582 * Size in bytes of object
585 DWORD WINAPI
GlobalSize16(
586 HGLOBAL16 handle
/* [in] Handle of global memory object */
588 TRACE("%04x\n", handle
);
589 if (!handle
) return 0;
590 if (!VALID_HANDLE(handle
))
592 return GET_ARENA_PTR(handle
)->size
;
596 /***********************************************************************
597 * GlobalHandle (KERNEL.21)
599 * Get the handle associated with a pointer to the global memory block.
602 * Why is GlobalHandleToSel used here with the sel as input?
608 DWORD WINAPI
GlobalHandle16(
609 WORD sel
/* [in] Address of global memory block */
611 TRACE("%04x\n", sel
);
612 if (!VALID_HANDLE(sel
)) {
613 WARN("Invalid handle 0x%04x passed to GlobalHandle16!\n",sel
);
616 return MAKELONG( GET_ARENA_PTR(sel
)->handle
, GlobalHandleToSel16(sel
) );
619 /***********************************************************************
620 * GlobalHandleNoRIP (KERNEL.159)
622 DWORD WINAPI
GlobalHandleNoRIP16( WORD sel
)
625 for (i
= globalArenaSize
-1 ; i
>=0 ; i
--) {
626 if (pGlobalArena
[i
].size
!=0 && pGlobalArena
[i
].handle
== sel
)
627 return MAKELONG( GET_ARENA_PTR(sel
)->handle
, GlobalHandleToSel16(sel
) );
633 /***********************************************************************
634 * GlobalFlags (KERNEL.22)
636 * Get information about a global memory object.
639 * Should this return GMEM_INVALID_HANDLE instead of 0 on invalid
643 * Value specifying flags and lock count
644 * GMEM_INVALID_HANDLE: Invalid handle
646 UINT16 WINAPI
GlobalFlags16(
647 HGLOBAL16 handle
/* [in] Handle of global memory object */
651 TRACE("%04x\n", handle
);
652 if (!VALID_HANDLE(handle
)) {
653 WARN("Invalid handle 0x%04x passed to GlobalFlags16!\n",handle
);
656 pArena
= GET_ARENA_PTR(handle
);
657 return pArena
->lockCount
|
658 ((pArena
->flags
& GA_DISCARDABLE
) ? GMEM_DISCARDABLE
: 0) |
659 ((pArena
->base
== 0) ? GMEM_DISCARDED
: 0);
663 /***********************************************************************
664 * LockSegment (KERNEL.23)
666 HGLOBAL16 WINAPI
LockSegment16( HGLOBAL16 handle
)
668 TRACE("%04x\n", handle
);
669 if (handle
== (HGLOBAL16
)-1) handle
= CURRENT_DS
;
670 if (!VALID_HANDLE(handle
)) {
671 WARN("Invalid handle 0x%04x passed to LockSegment16!\n",handle
);
674 GET_ARENA_PTR(handle
)->lockCount
++;
679 /***********************************************************************
680 * UnlockSegment (KERNEL.24)
682 void WINAPI
UnlockSegment16( HGLOBAL16 handle
)
684 TRACE("%04x\n", handle
);
685 if (handle
== (HGLOBAL16
)-1) handle
= CURRENT_DS
;
686 if (!VALID_HANDLE(handle
)) {
687 WARN("Invalid handle 0x%04x passed to UnlockSegment16!\n",handle
);
690 GET_ARENA_PTR(handle
)->lockCount
--;
691 /* FIXME: this ought to return the lock count in CX (go figure...) */
695 /***********************************************************************
696 * GlobalCompact (KERNEL.25)
698 DWORD WINAPI
GlobalCompact16( DWORD desired
)
700 return GLOBAL_MAX_ALLOC_SIZE
;
704 /***********************************************************************
705 * GlobalFreeAll (KERNEL.26)
707 void WINAPI
GlobalFreeAll16( HGLOBAL16 owner
)
712 pArena
= pGlobalArena
;
713 for (i
= 0; i
< globalArenaSize
; i
++, pArena
++)
715 if ((pArena
->size
!= 0) && (pArena
->hOwner
== owner
))
716 GlobalFree16( pArena
->handle
);
721 /***********************************************************************
722 * GlobalWire (KERNEL.111)
723 * GlobalWire16 (KERNEL32.29)
725 SEGPTR WINAPI
GlobalWire16( HGLOBAL16 handle
)
727 return WIN16_GlobalLock16( handle
);
731 /***********************************************************************
732 * GlobalUnWire (KERNEL.112)
733 * GlobalUnWire16 (KERNEL32.30)
735 BOOL16 WINAPI
GlobalUnWire16( HGLOBAL16 handle
)
737 return !GlobalUnlock16( handle
);
741 /***********************************************************************
742 * SetSwapAreaSize (KERNEL.106)
744 LONG WINAPI
SetSwapAreaSize16( WORD size
)
746 FIXME("(%d) - stub!\n", size
);
747 return MAKELONG( size
, 0xffff );
751 /***********************************************************************
752 * GlobalLRUOldest (KERNEL.163)
754 HGLOBAL16 WINAPI
GlobalLRUOldest16( HGLOBAL16 handle
)
756 TRACE("%04x\n", handle
);
757 if (handle
== (HGLOBAL16
)-1) handle
= CURRENT_DS
;
762 /***********************************************************************
763 * GlobalLRUNewest (KERNEL.164)
765 HGLOBAL16 WINAPI
GlobalLRUNewest16( HGLOBAL16 handle
)
767 TRACE("%04x\n", handle
);
768 if (handle
== (HGLOBAL16
)-1) handle
= CURRENT_DS
;
773 /***********************************************************************
774 * GetFreeSpace (KERNEL.169)
776 DWORD WINAPI
GetFreeSpace16( UINT16 wFlags
)
779 GlobalMemoryStatus( &ms
);
780 return ms
.dwAvailVirtual
;
783 /***********************************************************************
784 * GlobalDOSAlloc (KERNEL.184)
786 * Allocate memory in the first MB.
789 * Address (HW=Paragraph segment; LW=Selector)
791 DWORD WINAPI
GlobalDOSAlloc16(
792 DWORD size
/* [in] Number of bytes to be allocated */
795 LPVOID lpBlock
= DOSMEM_AllocBlock( size
, &uParagraph
);
799 HMODULE16 hModule
= GetModuleHandle16("KERNEL");
803 wSelector
= GLOBAL_CreateBlock(GMEM_FIXED
, lpBlock
, size
, hModule
, WINE_LDT_FLAGS_DATA
);
804 pArena
= GET_ARENA_PTR(wSelector
);
805 pArena
->flags
|= GA_DOSMEM
;
806 return MAKELONG(wSelector
,uParagraph
);
812 /***********************************************************************
813 * GlobalDOSFree (KERNEL.185)
815 * Free memory allocated with GlobalDOSAlloc
821 WORD WINAPI
GlobalDOSFree16(
822 WORD sel
/* [in] Selector */
824 DWORD block
= GetSelectorBase(sel
);
826 if( block
&& block
< 0x100000 )
828 LPVOID lpBlock
= DOSMEM_MapDosToLinear( block
);
829 if( DOSMEM_FreeBlock( lpBlock
) )
830 GLOBAL_FreeBlock( sel
);
837 /***********************************************************************
838 * GlobalPageLock (KERNEL.191)
839 * GlobalSmartPageLock(KERNEL.230)
841 WORD WINAPI
GlobalPageLock16( HGLOBAL16 handle
)
843 TRACE("%04x\n", handle
);
844 if (!VALID_HANDLE(handle
)) {
845 WARN("Invalid handle 0x%04x passed to GlobalPageLock!\n",handle
);
848 return ++(GET_ARENA_PTR(handle
)->pageLockCount
);
852 /***********************************************************************
853 * GlobalPageUnlock (KERNEL.192)
854 * GlobalSmartPageUnlock(KERNEL.231)
856 WORD WINAPI
GlobalPageUnlock16( HGLOBAL16 handle
)
858 TRACE("%04x\n", handle
);
859 if (!VALID_HANDLE(handle
)) {
860 WARN("Invalid handle 0x%04x passed to GlobalPageUnlock!\n",handle
);
863 return --(GET_ARENA_PTR(handle
)->pageLockCount
);
867 /***********************************************************************
868 * GlobalFix (KERNEL.197)
869 * GlobalFix16 (KERNEL32.27)
871 WORD WINAPI
GlobalFix16( HGLOBAL16 handle
)
873 TRACE("%04x\n", handle
);
874 if (!VALID_HANDLE(handle
)) {
875 WARN("Invalid handle 0x%04x passed to GlobalFix16!\n",handle
);
878 GET_ARENA_PTR(handle
)->lockCount
++;
880 return GlobalHandleToSel16(handle
);
884 /***********************************************************************
885 * GlobalUnfix (KERNEL.198)
886 * GlobalUnfix16 (KERNEL32.28)
888 void WINAPI
GlobalUnfix16( HGLOBAL16 handle
)
890 TRACE("%04x\n", handle
);
891 if (!VALID_HANDLE(handle
)) {
892 WARN("Invalid handle 0x%04x passed to GlobalUnfix16!\n",handle
);
895 GET_ARENA_PTR(handle
)->lockCount
--;
899 /***********************************************************************
900 * FarSetOwner (KERNEL.403)
902 void WINAPI
FarSetOwner16( HGLOBAL16 handle
, HANDLE16 hOwner
)
904 if (!VALID_HANDLE(handle
)) {
905 WARN("Invalid handle 0x%04x passed to FarSetOwner!\n",handle
);
908 GET_ARENA_PTR(handle
)->hOwner
= hOwner
;
912 /***********************************************************************
913 * FarGetOwner (KERNEL.404)
915 HANDLE16 WINAPI
FarGetOwner16( HGLOBAL16 handle
)
917 if (!VALID_HANDLE(handle
)) {
918 WARN("Invalid handle 0x%04x passed to FarGetOwner!\n",handle
);
921 return GET_ARENA_PTR(handle
)->hOwner
;
925 /************************************************************************
926 * GlobalMasterHandle (KERNEL.28)
929 * Should return selector and handle of the information structure for
930 * the global heap. selector and handle are stored in the THHOOK as
931 * pGlobalHeap and hGlobalHeap.
932 * As Wine doesn't have this structure, we return both values as zero
933 * Applications should interpret this as "No Global Heap"
935 DWORD WINAPI
GlobalMasterHandle16(void)
941 /***********************************************************************
942 * GlobalHandleToSel (TOOLHELP.50)
944 * FIXME: This is in TOOLHELP but we keep a copy here for now.
946 WORD WINAPI
GlobalHandleToSel16( HGLOBAL16 handle
)
948 if (!handle
) return 0;
949 if (!VALID_HANDLE(handle
)) {
950 WARN("Invalid handle 0x%04x passed to GlobalHandleToSel!\n",handle
);
955 WARN("Program attempted invalid selector conversion\n" );
962 /***********************************************************************
963 * GetFreeMemInfo (KERNEL.316)
965 DWORD WINAPI
GetFreeMemInfo16(void)
968 GlobalMemoryStatus( &status
);
969 return MAKELONG( status
.dwTotalVirtual
/getpagesize(), status
.dwAvailVirtual
/getpagesize() );
972 /***********************************************************************
973 * A20Proc (KERNEL.165)
975 void WINAPI
A20Proc16( WORD unused
)
977 /* this is also a NOP in Windows */
980 /***********************************************************************
981 * LimitEMSPages (KERNEL.156)
983 DWORD WINAPI
LimitEMSPages16( DWORD unused
)