Release 960114
[wine/gsoc-2012-control.git] / memory / global.c
blob680e9fb10530864fb814073b1c53162ce3576198
1 /*
2 * Global heap functions
4 * Copyright 1995 Alexandre Julliard
5 */
7 #include <sys/types.h>
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <string.h>
12 #include "windows.h"
13 #include "global.h"
14 #include "toolhelp.h"
15 #include "selectors.h"
16 #include "dde_mem.h"
17 #include "stackframe.h"
18 #include "options.h"
19 #include "stddebug.h"
20 #include "debug.h"
22 /* Global arena block */
23 typedef struct
25 DWORD base; /* Base address */
26 DWORD size; /* Size in bytes (0 indicates a free block) */
27 HGLOBAL handle; /* Handle for this block */
28 HGLOBAL hOwner; /* Owner of this block */
29 BYTE lockCount; /* Count of GlobalFix() calls */
30 BYTE pageLockCount; /* Count of GlobalPageLock() calls */
31 BYTE flags; /* Allocation flags */
32 BYTE selCount; /* Number of selectors allocated for this block */
33 int shmid;
34 } GLOBALARENA;
36 /* Flags definitions */
37 #define GA_MOVEABLE 0x02 /* same as GMEM_MOVEABLE */
38 #define GA_DGROUP 0x04
39 #define GA_DISCARDABLE 0x08
40 #define GA_IPCSHARE 0x10 /* same as GMEM_DDESHARE */
42 /* Arena array */
43 static GLOBALARENA *pGlobalArena = NULL;
44 static int globalArenaSize = 0;
46 #define GLOBAL_MAX_ALLOC_SIZE 0x00ff0000 /* Largest allocation is 16M - 64K */
48 #define GET_ARENA_PTR(handle) (pGlobalArena + ((handle) >> __AHSHIFT))
50 /***********************************************************************
51 * GLOBAL_GetArena
53 * Return the arena for a given selector, growing the arena array if needed.
55 static GLOBALARENA *GLOBAL_GetArena( WORD sel, WORD selcount )
57 if (((sel >> __AHSHIFT) + selcount) > globalArenaSize)
59 int newsize = ((sel >> __AHSHIFT) + selcount + 0xff) & ~0xff;
60 GLOBALARENA *pNewArena = realloc( pGlobalArena,
61 newsize * sizeof(GLOBALARENA) );
62 if (!pNewArena) return 0;
63 pGlobalArena = pNewArena;
64 memset( pGlobalArena + globalArenaSize, 0,
65 (newsize - globalArenaSize) * sizeof(GLOBALARENA) );
66 globalArenaSize = newsize;
68 return pGlobalArena + (sel >> __AHSHIFT);
72 void debug_handles()
74 int printed=0;
75 int i;
76 for (i = globalArenaSize-1 ; i>=0 ; i--) {
77 if (pGlobalArena[i].size!=0 && (pGlobalArena[i].handle & 0x8000)){
78 printed=1;
79 printf("0x%08x, ",pGlobalArena[i].handle);
82 if (printed)
83 printf("\n");
87 /***********************************************************************
88 * GLOBAL_CreateBlock
90 * Create a global heap block for a fixed range of linear memory.
92 HGLOBAL GLOBAL_CreateBlock( WORD flags, const void *ptr, DWORD size,
93 HGLOBAL hOwner, BOOL isCode,
94 BOOL is32Bit, BOOL isReadOnly,
95 SHMDATA *shmdata )
97 WORD sel, selcount;
98 GLOBALARENA *pArena;
100 /* Allocate the selector(s) */
102 sel = SELECTOR_AllocBlock( ptr, size,
103 isCode ? SEGMENT_CODE : SEGMENT_DATA,
104 is32Bit, isReadOnly );
106 if (!sel) return 0;
107 selcount = (size + 0xffff) / 0x10000;
109 if (!(pArena = GLOBAL_GetArena( sel, selcount )))
111 FreeSelector( sel );
112 return 0;
115 /* Fill the arena block */
117 pArena->base = (DWORD)ptr;
118 pArena->size = GET_SEL_LIMIT(sel) + 1;
119 if ((flags & GMEM_DDESHARE) && Options.ipc)
121 pArena->handle = shmdata->handle;
122 pArena->shmid = shmdata->shmid;
123 shmdata->sel = sel;
125 else
127 pArena->handle = (flags & GMEM_MOVEABLE) ? sel - 1 : sel;
128 pArena->shmid = 0;
130 pArena->hOwner = hOwner;
131 pArena->lockCount = 0;
132 pArena->pageLockCount = 0;
133 pArena->flags = flags & GA_MOVEABLE;
134 if (flags & GMEM_DISCARDABLE) pArena->flags |= GA_DISCARDABLE;
135 if (flags & GMEM_DDESHARE) pArena->flags |= GA_IPCSHARE;
136 if (!isCode) pArena->flags |= GA_DGROUP;
137 pArena->selCount = selcount;
138 if (selcount > 1) /* clear the next arena blocks */
139 memset( pArena + 1, 0, (selcount - 1) * sizeof(GLOBALARENA) );
141 return pArena->handle;
145 /***********************************************************************
146 * GLOBAL_FreeBlock
148 * Free a block allocated by GLOBAL_CreateBlock, without touching
149 * the associated linear memory range.
151 BOOL GLOBAL_FreeBlock( HGLOBAL handle )
153 WORD sel;
155 if (!handle) return TRUE;
156 sel = GlobalHandleToSel( handle );
157 if (FreeSelector( sel )) return FALSE; /* failed */
158 memset( GET_ARENA_PTR(sel), 0, sizeof(GLOBALARENA) );
159 return TRUE;
163 /***********************************************************************
164 * GLOBAL_Alloc
166 * Implementation of GlobalAlloc()
168 HGLOBAL GLOBAL_Alloc( WORD flags, DWORD size, HGLOBAL hOwner,
169 BOOL isCode, BOOL is32Bit, BOOL isReadOnly )
171 void *ptr;
172 HGLOBAL handle;
173 SHMDATA shmdata;
175 dprintf_global( stddeb, "GlobalAlloc: %ld flags=%04x\n", size, flags );
177 /* Fixup the size */
179 if (size >= GLOBAL_MAX_ALLOC_SIZE - 0x1f) return 0;
180 if (size == 0) size = 0x20;
181 else size = (size + 0x1f) & ~0x1f;
183 /* Allocate the linear memory */
185 #ifdef CONFIG_IPC
186 if ((flags & GMEM_DDESHARE) && Options.ipc)
187 ptr = DDE_malloc(flags, size, &shmdata);
188 else
189 #endif /* CONFIG_IPC */
190 ptr = malloc( size );
191 if (!ptr) return 0;
193 /* Allocate the selector(s) */
195 handle = GLOBAL_CreateBlock( flags, ptr, size, hOwner,
196 isCode, is32Bit, isReadOnly, &shmdata);
197 if (!handle)
199 free( ptr );
200 return 0;
203 if (flags & GMEM_ZEROINIT) memset( ptr, 0, size );
204 return handle;
208 #ifdef CONFIG_IPC
209 /***********************************************************************
210 * GLOBAL_FindArena
212 * Find the arena for a given handle
213 * (when handle is not serial - e.g. DDE)
215 static GLOBALARENA *GLOBAL_FindArena( HGLOBAL handle)
217 int i;
218 for (i = globalArenaSize-1 ; i>=0 ; i--) {
219 if (pGlobalArena[i].size!=0 && pGlobalArena[i].handle == handle)
220 return ( &pGlobalArena[i] );
222 return NULL;
226 /***********************************************************************
227 * DDE_GlobalHandleToSel
230 WORD DDE_GlobalHandleToSel( HGLOBAL handle )
232 GLOBALARENA *pArena;
233 SEGPTR segptr;
235 pArena= GLOBAL_FindArena(handle);
236 if (pArena) {
237 int ArenaIdx = pArena - pGlobalArena;
239 /* See if synchronized to the shared memory */
240 return DDE_SyncHandle(handle, ( ArenaIdx << __AHSHIFT) | 7);
243 /* attach the block */
244 DDE_AttachHandle(handle, &segptr);
246 return SELECTOROF( segptr );
248 #endif /* CONFIG_IPC */
251 /***********************************************************************
252 * GlobalAlloc (KERNEL.15)
254 HGLOBAL GlobalAlloc( WORD flags, DWORD size )
256 HANDLE owner = GetCurrentPDB();
258 if (flags & GMEM_DDESHARE)
259 owner = GetExePtr(owner); /* Make it a module handle */
260 return GLOBAL_Alloc( flags, size, owner, FALSE, FALSE, FALSE );
264 /***********************************************************************
265 * GlobalReAlloc (KERNEL.16)
267 HGLOBAL GlobalReAlloc( HGLOBAL handle, DWORD size, WORD flags )
269 WORD selcount;
270 DWORD oldsize;
271 void *ptr;
272 GLOBALARENA *pArena, *pNewArena;
273 WORD sel = GlobalHandleToSel( handle );
275 dprintf_global( stddeb, "GlobalReAlloc: %04x %ld flags=%04x\n",
276 handle, size, flags );
277 if (!handle) return 0;
279 #ifdef CONFIG_IPC
280 if (Options.ipc && (flags & GMEM_DDESHARE || is_dde_handle(handle))) {
281 fprintf(stdnimp,
282 "GlobalReAlloc: shared memory reallocating unimplemented\n");
283 return 0;
285 #endif /* CONFIG_IPC */
287 pArena = GET_ARENA_PTR( handle );
289 /* Discard the block if requested */
291 if ((size == 0) && (flags & GMEM_MOVEABLE) && !(flags & GMEM_MODIFY))
293 if (!(pArena->flags & GA_MOVEABLE) ||
294 !(pArena->flags & GA_DISCARDABLE) ||
295 (pArena->lockCount > 0) || (pArena->pageLockCount > 0)) return 0;
296 free( (void *)pArena->base );
297 pArena->base = 0;
298 /* Note: we rely on the fact that SELECTOR_ReallocBlock won't */
299 /* change the selector if we are shrinking the block */
300 SELECTOR_ReallocBlock( sel, 0, 1, SEGMENT_DATA, 0, 0 );
301 return handle;
304 /* Fixup the size */
306 if (size > GLOBAL_MAX_ALLOC_SIZE - 0x20) return 0;
307 if (size == 0) size = 0x20;
308 else size = (size + 0x1f) & ~0x1f;
310 /* Change the flags */
312 if (flags & GMEM_MODIFY)
314 /* Change the flags, leaving GA_DGROUP alone */
315 pArena->flags = (pArena->flags & GA_DGROUP) | (flags & GA_MOVEABLE);
316 if (flags & GMEM_DISCARDABLE) pArena->flags |= GA_DISCARDABLE;
317 return handle;
320 /* Reallocate the linear memory */
322 ptr = (void *)pArena->base;
323 oldsize = pArena->size;
324 dprintf_global(stddeb,"oldsize %08lx\n",oldsize);
325 if (size == oldsize) return handle; /* Nothing to do */
327 ptr = realloc( ptr, size );
328 if (!ptr)
330 FreeSelector( sel );
331 memset( pArena, 0, sizeof(GLOBALARENA) );
332 return 0;
335 /* Reallocate the selector(s) */
337 sel = SELECTOR_ReallocBlock( sel, ptr, size, SEGMENT_DATA, 0, 0 );
338 if (!sel)
340 free( ptr );
341 memset( pArena, 0, sizeof(GLOBALARENA) );
342 return 0;
344 selcount = (size + 0xffff) / 0x10000;
346 if (!(pNewArena = GLOBAL_GetArena( sel, selcount )))
348 free( ptr );
349 FreeSelector( sel );
350 return 0;
353 /* Fill the new arena block */
355 if (pNewArena != pArena) memcpy( pNewArena, pArena, sizeof(GLOBALARENA) );
356 pNewArena->base = (DWORD)ptr;
357 pNewArena->size = GET_SEL_LIMIT(sel) + 1;
358 pNewArena->selCount = selcount;
359 pNewArena->handle = (pNewArena->flags & GA_MOVEABLE) ? sel - 1 : sel;
361 if (selcount > 1) /* clear the next arena blocks */
362 memset( pNewArena + 1, 0, (selcount - 1) * sizeof(GLOBALARENA) );
364 if ((oldsize < size) && (flags & GMEM_ZEROINIT))
365 memset( (char *)ptr + oldsize, 0, size - oldsize );
366 return pNewArena->handle;
370 /***********************************************************************
371 * GlobalFree (KERNEL.17)
373 HGLOBAL GlobalFree( HGLOBAL handle )
375 void *ptr = GlobalLock( handle );
377 dprintf_global( stddeb, "GlobalFree: %04x\n", handle );
378 if (!GLOBAL_FreeBlock( handle )) return handle; /* failed */
379 #ifdef CONFIG_IPC
380 if (is_dde_handle(handle)) return DDE_GlobalFree(handle);
381 #endif /* CONFIG_IPC */
382 if (ptr) free( ptr );
383 return 0;
387 /***********************************************************************
388 * WIN16_GlobalLock (KERNEL.18)
390 * This is the GlobalLock() function used by 16-bit code.
392 SEGPTR WIN16_GlobalLock( HGLOBAL handle )
394 dprintf_global( stddeb, "WIN16_GlobalLock(%04x) -> %08lx\n",
395 handle, MAKELONG( 0, GlobalHandleToSel(handle)) );
396 if (!handle) return 0;
398 #ifdef CONFIG_IPC
399 if (is_dde_handle(handle))
400 return (SEGPTR)MAKELONG( 0, DDE_GlobalHandleToSel(handle) );
401 #endif /* CONFIG_IPC */
403 if (!GET_ARENA_PTR(handle)->base) return (SEGPTR)0;
404 return (SEGPTR)MAKELONG( 0, GlobalHandleToSel(handle) );
408 /***********************************************************************
409 * GlobalLock (KERNEL.18)
411 * This is the GlobalLock() function used by 32-bit code.
413 LPVOID GlobalLock( HGLOBAL handle )
415 if (!handle) return 0;
416 #ifdef CONFIG_IPC
417 if (is_dde_handle(handle)) return DDE_AttachHandle(handle, NULL);
418 #endif
419 return (LPSTR)GET_ARENA_PTR(handle)->base;
423 /***********************************************************************
424 * GlobalUnlock (KERNEL.19)
426 BOOL GlobalUnlock( HGLOBAL handle )
428 dprintf_global( stddeb, "GlobalUnlock: %04x\n", handle );
429 return 0;
433 /***********************************************************************
434 * GlobalSize (KERNEL.20)
436 DWORD GlobalSize( HGLOBAL handle )
438 dprintf_global( stddeb, "GlobalSize: %04x\n", handle );
439 if (!handle) return 0;
440 return GET_ARENA_PTR(handle)->size;
444 /***********************************************************************
445 * GlobalHandle (KERNEL.21)
447 DWORD GlobalHandle( WORD sel )
449 dprintf_global( stddeb, "GlobalHandle: %04x\n", sel );
450 return MAKELONG( GET_ARENA_PTR(sel)->handle, GlobalHandleToSel(sel) );
454 /***********************************************************************
455 * GlobalFlags (KERNEL.22)
457 WORD GlobalFlags( HGLOBAL handle )
459 GLOBALARENA *pArena;
461 dprintf_global( stddeb, "GlobalFlags: %04x\n", handle );
462 pArena = GET_ARENA_PTR(handle);
463 return pArena->lockCount |
464 ((pArena->flags & GA_DISCARDABLE) ? GMEM_DISCARDABLE : 0) |
465 ((pArena->base == 0) ? GMEM_DISCARDED : 0);
469 /***********************************************************************
470 * LockSegment (KERNEL.23)
472 HGLOBAL LockSegment( HGLOBAL handle )
474 dprintf_global( stddeb, "LockSegment: %04x\n", handle );
475 if (handle == (HGLOBAL)-1) handle = CURRENT_DS;
476 GET_ARENA_PTR(handle)->lockCount++;
477 return handle;
481 /***********************************************************************
482 * UnlockSegment (KERNEL.24)
484 void UnlockSegment( HGLOBAL handle )
486 dprintf_global( stddeb, "UnlockSegment: %04x\n", handle );
487 if (handle == (HGLOBAL)-1) handle = CURRENT_DS;
488 GET_ARENA_PTR(handle)->lockCount--;
489 /* FIXME: this ought to return the lock count in CX (go figure...) */
493 /***********************************************************************
494 * GlobalCompact (KERNEL.25)
496 DWORD GlobalCompact( DWORD desired )
498 return GLOBAL_MAX_ALLOC_SIZE;
502 /***********************************************************************
503 * GlobalFreeAll (KERNEL.26)
505 void GlobalFreeAll( HANDLE owner )
507 DWORD i;
508 GLOBALARENA *pArena;
510 pArena = pGlobalArena;
511 for (i = 0; i < globalArenaSize; i++, pArena++)
513 if ((pArena->size != 0) && (pArena->hOwner == owner))
514 GlobalFree( pArena->handle );
519 /***********************************************************************
520 * GlobalWire (KERNEL.111)
522 SEGPTR GlobalWire( HGLOBAL handle )
524 return WIN16_GlobalLock( handle );
528 /***********************************************************************
529 * GlobalUnWire (KERNEL.112)
531 BOOL GlobalUnWire( HGLOBAL handle )
533 return GlobalUnlock( handle );
537 /***********************************************************************
538 * GlobalDOSAlloc (KERNEL.184)
540 DWORD GlobalDOSAlloc( DWORD size )
542 WORD sel = GlobalAlloc( GMEM_FIXED, size );
543 if (!sel) return 0;
544 return MAKELONG( sel, sel /* this one ought to be a real-mode segment */ );
548 /***********************************************************************
549 * GlobalDOSFree (KERNEL.185)
551 WORD GlobalDOSFree( WORD sel )
553 return GlobalFree( GlobalHandle(sel) ) ? sel : 0;
557 /***********************************************************************
558 * SetSwapAreaSize (KERNEL.106)
560 LONG SetSwapAreaSize( WORD size )
562 dprintf_global(stdnimp, "STUB: SetSwapAreaSize(%d)\n", size );
563 return MAKELONG( size, 0xffff );
567 /***********************************************************************
568 * GlobalLRUOldest (KERNEL.163)
570 HGLOBAL GlobalLRUOldest( HGLOBAL handle )
572 dprintf_global( stddeb, "GlobalLRUOldest: %04x\n", handle );
573 if (handle == (HGLOBAL)-1) handle = CURRENT_DS;
574 return handle;
578 /***********************************************************************
579 * GlobalLRUNewest (KERNEL.164)
581 HGLOBAL GlobalLRUNewest( HGLOBAL handle )
583 dprintf_global( stddeb, "GlobalLRUNewest: %04x\n", handle );
584 if (handle == (HGLOBAL)-1) handle = CURRENT_DS;
585 return handle;
589 /***********************************************************************
590 * GetFreeSpace (KERNEL.169)
592 DWORD GetFreeSpace( UINT wFlags )
594 return GLOBAL_MAX_ALLOC_SIZE;
598 /***********************************************************************
599 * GlobalPageLock (KERNEL.191)
601 WORD GlobalPageLock( HGLOBAL handle )
603 dprintf_global( stddeb, "GlobalPageLock: %04x\n", handle );
604 return ++(GET_ARENA_PTR(handle)->pageLockCount);
608 /***********************************************************************
609 * GlobalPageUnlock (KERNEL.192)
611 WORD GlobalPageUnlock( HGLOBAL handle )
613 dprintf_global( stddeb, "GlobalPageUnlock: %04x\n", handle );
614 return --(GET_ARENA_PTR(handle)->pageLockCount);
618 /***********************************************************************
619 * GlobalFix (KERNEL.197)
621 void GlobalFix( HGLOBAL handle )
623 dprintf_global( stddeb, "GlobalFix: %04x\n", handle );
624 GET_ARENA_PTR(handle)->lockCount++;
628 /***********************************************************************
629 * GlobalUnfix (KERNEL.198)
631 void GlobalUnfix( HGLOBAL handle )
633 dprintf_global( stddeb, "GlobalUnfix: %04x\n", handle );
634 GET_ARENA_PTR(handle)->lockCount--;
638 /***********************************************************************
639 * FarSetOwner (KERNEL.403)
641 void FarSetOwner( HANDLE handle, WORD hOwner )
643 GET_ARENA_PTR(handle)->hOwner = hOwner;
647 /***********************************************************************
648 * FarGetOwner (KERNEL.404)
650 WORD FarGetOwner( HANDLE handle )
652 return GET_ARENA_PTR(handle)->hOwner;
656 /***********************************************************************
657 * GlobalHandleToSel (TOOLHELP.50)
659 WORD GlobalHandleToSel( HGLOBAL handle )
661 dprintf_toolhelp( stddeb, "GlobalHandleToSel: %04x\n", handle );
662 if (!handle) return 0;
663 #ifdef CONFIG_IPC
664 if (is_dde_handle(handle)) return DDE_GlobalHandleToSel(handle);
665 #endif
666 if (!(handle & 7))
668 fprintf( stderr, "Program attempted invalid selector conversion\n" );
669 return handle - 1;
671 return handle | 7;
675 /***********************************************************************
676 * GlobalFirst (TOOLHELP.51)
678 BOOL GlobalFirst( GLOBALENTRY *pGlobal, WORD wFlags )
680 if (wFlags == GLOBAL_LRU) return FALSE;
681 pGlobal->dwNext = 0;
682 return GlobalNext( pGlobal, wFlags );
686 /***********************************************************************
687 * GlobalNext (TOOLHELP.52)
689 BOOL GlobalNext( GLOBALENTRY *pGlobal, WORD wFlags)
691 GLOBALARENA *pArena;
693 if (pGlobal->dwNext >= globalArenaSize) return FALSE;
694 pArena = pGlobalArena + pGlobal->dwNext;
695 if (wFlags == GLOBAL_FREE) /* only free blocks */
697 int i;
698 for (i = pGlobal->dwNext; i < globalArenaSize; i++, pArena++)
699 if (pArena->size == 0) break; /* block is free */
700 if (i >= globalArenaSize) return FALSE;
701 pGlobal->dwNext = i;
704 pGlobal->dwAddress = pArena->base;
705 pGlobal->dwBlockSize = pArena->size;
706 pGlobal->hBlock = pArena->handle;
707 pGlobal->wcLock = pArena->lockCount;
708 pGlobal->wcPageLock = pArena->pageLockCount;
709 pGlobal->wFlags = (GetCurrentPDB() == pArena->hOwner);
710 pGlobal->wHeapPresent = FALSE;
711 pGlobal->hOwner = pArena->hOwner;
712 pGlobal->wType = GT_UNKNOWN;
713 pGlobal->wData = 0;
714 pGlobal->dwNext++;
715 return TRUE;
719 /***********************************************************************
720 * GlobalInfo (TOOLHELP.53)
722 BOOL GlobalInfo( GLOBALINFO *pInfo )
724 int i;
725 GLOBALARENA *pArena;
727 pInfo->wcItems = globalArenaSize;
728 pInfo->wcItemsFree = 0;
729 pInfo->wcItemsLRU = 0;
730 for (i = 0, pArena = pGlobalArena; i < globalArenaSize; i++, pArena++)
731 if (pArena->size == 0) pInfo->wcItemsFree++;
732 return TRUE;
736 /***********************************************************************
737 * GlobalEntryHandle (TOOLHELP.54)
739 BOOL GlobalEntryHandle( GLOBALENTRY *pGlobal, HGLOBAL hItem )
741 return FALSE;
745 /***********************************************************************
746 * GlobalEntryModule (TOOLHELP.55)
748 BOOL GlobalEntryModule( GLOBALENTRY *pGlobal, HMODULE hModule, WORD wSeg )
750 return FALSE;
754 /***********************************************************************
755 * MemManInfo (TOOLHELP.72)
757 BOOL MemManInfo( MEMMANINFO *pInfo )
759 #ifdef linux
760 /* FIXME: does not take into account the dwSize member
761 * could be corrupting memory therefore
763 /* shamefully stolen from free */
764 DWORD availmem = 0;
765 DWORD totalmem = 0;
766 FILE *meminfo;
767 char buf[80];
768 int col[5];
769 int n;
771 if ((meminfo = fopen("/proc/meminfo", "r")) < 0) {
772 perror("wine: open");
773 exit(1);
776 fgets(buf, 80, meminfo); /* read first line */
777 while ( fgets(buf, 80, meminfo) ) {
778 n = sscanf( buf, "%*s %d %d %d %d %d", &col[0], &col[1], &col[2], &col[3], &col[4]);
779 if ( n < 1 ) continue; /* escape the loop at the top */
780 totalmem += col[0];
781 availmem += col[2] + col[4];
784 fprintf(stderr,"MemManInfo called with dwSize = %ld\n",pInfo->dwSize);
785 pInfo->wPageSize = getpagesize();
786 pInfo->dwLargestFreeBlock = availmem;
787 pInfo->dwTotalLinearSpace = totalmem / pInfo->wPageSize;
788 pInfo->dwMaxPagesAvailable = pInfo->dwLargestFreeBlock / pInfo->wPageSize;
789 pInfo->dwMaxPagesLockable = pInfo->dwMaxPagesLockable;
790 /* FIXME: the next three are not quite correct */
791 pInfo->dwTotalUnlockedPages = pInfo->dwMaxPagesAvailable;
792 pInfo->dwFreePages = pInfo->dwMaxPagesAvailable;
793 pInfo->dwTotalPages = pInfo->dwMaxPagesAvailable;
794 /* FIXME: the three above are not quite correct */
795 pInfo->dwFreeLinearSpace = pInfo->dwMaxPagesAvailable;
796 pInfo->dwSwapFilePages = 0L;
797 return TRUE;
798 #else
799 return TRUE;
800 #endif
803 /***********************************************************************
804 * GlobalAlloc32
805 * implements GlobalAlloc (KERNEL32.316)
806 * LocalAlloc (KERNEL32.372)
808 void *GlobalAlloc32(int flags,int size)
810 dprintf_global(stddeb,"GlobalAlloc32(%x,%x)\n",flags,size);
811 return malloc(size);