Alexandre Julliard | 234bc24 | 1994-12-10 13:02:28 +0000 | [diff] [blame] | 1 | /* |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 2 | * Global heap functions |
| 3 | * |
| 4 | * Copyright 1995 Alexandre Julliard |
| 5 | */ |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 6 | /* 0xffff sometimes seems to mean: CURRENT_DS */ |
Alexandre Julliard | 121bd98 | 1993-07-08 17:37:25 +0000 | [diff] [blame] | 7 | |
Alexandre Julliard | 808cb04 | 1995-08-17 17:11:36 +0000 | [diff] [blame] | 8 | #include <sys/types.h> |
Alexandre Julliard | 121bd98 | 1993-07-08 17:37:25 +0000 | [diff] [blame] | 9 | #include <stdlib.h> |
Marcus Meissner | 6189c19 | 2000-03-04 19:19:15 +0000 | [diff] [blame] | 10 | #include <time.h> |
Alexandre Julliard | 383da68 | 2000-02-10 22:15:21 +0000 | [diff] [blame] | 11 | #include <stdio.h> |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 12 | #include <unistd.h> |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 13 | #include <string.h> |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 14 | |
Marcus Meissner | 04c3e1d | 1999-02-19 10:37:02 +0000 | [diff] [blame] | 15 | #include "wine/winbase16.h" |
Lawson Whitney | 969515d | 2000-10-02 22:27:37 +0000 | [diff] [blame] | 16 | #include "wine/exception.h" |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 17 | #include "global.h" |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 18 | #include "heap.h" |
Alexandre Julliard | 3f2abfa | 1994-08-16 15:43:11 +0000 | [diff] [blame] | 19 | #include "toolhelp.h" |
Alexandre Julliard | 234bc24 | 1994-12-10 13:02:28 +0000 | [diff] [blame] | 20 | #include "selectors.h" |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 21 | #include "miscemu.h" |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 22 | #include "stackframe.h" |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 23 | #include "module.h" |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 24 | #include "debugtools.h" |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 25 | #include "winerror.h" |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 26 | |
Alexandre Julliard | 383da68 | 2000-02-10 22:15:21 +0000 | [diff] [blame] | 27 | DEFAULT_DEBUG_CHANNEL(global); |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 28 | |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 29 | /* Global arena block */ |
| 30 | typedef struct |
| 31 | { |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 32 | DWORD base; /* Base address (0 if discarded) */ |
| 33 | DWORD size; /* Size in bytes (0 indicates a free block) */ |
| 34 | HGLOBAL16 handle; /* Handle for this block */ |
| 35 | HGLOBAL16 hOwner; /* Owner of this block */ |
| 36 | BYTE lockCount; /* Count of GlobalFix() calls */ |
| 37 | BYTE pageLockCount; /* Count of GlobalPageLock() calls */ |
| 38 | BYTE flags; /* Allocation flags */ |
| 39 | BYTE selCount; /* Number of selectors allocated for this block */ |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 40 | } GLOBALARENA; |
| 41 | |
| 42 | /* Flags definitions */ |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 43 | #define GA_MOVEABLE 0x02 /* same as GMEM_MOVEABLE */ |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 44 | #define GA_DGROUP 0x04 |
| 45 | #define GA_DISCARDABLE 0x08 |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 46 | #define GA_IPCSHARE 0x10 /* same as GMEM_DDESHARE */ |
Andreas Mohr | d23f506 | 2000-10-02 22:16:21 +0000 | [diff] [blame] | 47 | #define GA_DOSMEM 0x20 |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 48 | |
| 49 | /* Arena array */ |
| 50 | static GLOBALARENA *pGlobalArena = NULL; |
| 51 | static int globalArenaSize = 0; |
| 52 | |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 53 | #define GLOBAL_MAX_ALLOC_SIZE 0x00ff0000 /* Largest allocation is 16M - 64K */ |
Alexandre Julliard | 121bd98 | 1993-07-08 17:37:25 +0000 | [diff] [blame] | 54 | |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 55 | #define VALID_HANDLE(handle) (((handle)>>__AHSHIFT)<globalArenaSize) |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 56 | #define GET_ARENA_PTR(handle) (pGlobalArena + ((handle) >> __AHSHIFT)) |
Alexandre Julliard | 75a839a | 1993-07-15 11:13:45 +0000 | [diff] [blame] | 57 | |
Lawson Whitney | 969515d | 2000-10-02 22:27:37 +0000 | [diff] [blame] | 58 | /* filter for page-fault exceptions */ |
| 59 | /* It is possible for a bogus global pointer to cause a */ |
| 60 | /* page zero reference, so I include EXCEPTION_PRIV_INSTRUCTION too. */ |
| 61 | |
| 62 | static WINE_EXCEPTION_FILTER(page_fault) |
| 63 | { |
| 64 | switch (GetExceptionCode()) { |
| 65 | case (EXCEPTION_ACCESS_VIOLATION): |
| 66 | case (EXCEPTION_PRIV_INSTRUCTION): |
| 67 | return EXCEPTION_EXECUTE_HANDLER; |
| 68 | default: |
| 69 | return EXCEPTION_CONTINUE_SEARCH; |
| 70 | } |
| 71 | } |
| 72 | |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 73 | /*********************************************************************** |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 74 | * GLOBAL_GetArena |
| 75 | * |
| 76 | * Return the arena for a given selector, growing the arena array if needed. |
Alexandre Julliard | dba420a | 1994-02-02 06:48:31 +0000 | [diff] [blame] | 77 | */ |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 78 | static GLOBALARENA *GLOBAL_GetArena( WORD sel, WORD selcount ) |
Alexandre Julliard | dba420a | 1994-02-02 06:48:31 +0000 | [diff] [blame] | 79 | { |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 80 | if (((sel >> __AHSHIFT) + selcount) > globalArenaSize) |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 81 | { |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 82 | int newsize = ((sel >> __AHSHIFT) + selcount + 0xff) & ~0xff; |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 83 | GLOBALARENA *pNewArena = realloc( pGlobalArena, |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 84 | newsize * sizeof(GLOBALARENA) ); |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 85 | if (!pNewArena) return 0; |
| 86 | pGlobalArena = pNewArena; |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 87 | memset( pGlobalArena + globalArenaSize, 0, |
| 88 | (newsize - globalArenaSize) * sizeof(GLOBALARENA) ); |
| 89 | globalArenaSize = newsize; |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 90 | } |
| 91 | return pGlobalArena + (sel >> __AHSHIFT); |
| 92 | } |
Alexandre Julliard | dba420a | 1994-02-02 06:48:31 +0000 | [diff] [blame] | 93 | |
Juergen Schmied | ebc2b77 | 1998-11-14 18:59:30 +0000 | [diff] [blame] | 94 | void debug_handles(void) |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 95 | { |
| 96 | int printed=0; |
| 97 | int i; |
| 98 | for (i = globalArenaSize-1 ; i>=0 ; i--) { |
| 99 | if (pGlobalArena[i].size!=0 && (pGlobalArena[i].handle & 0x8000)){ |
| 100 | printed=1; |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 101 | DPRINTF("0x%08x, ",pGlobalArena[i].handle); |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 102 | } |
| 103 | } |
| 104 | if (printed) |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 105 | DPRINTF("\n"); |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 106 | } |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 107 | |
| 108 | |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 109 | /*********************************************************************** |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 110 | * GLOBAL_CreateBlock |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 111 | * |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 112 | * Create a global heap block for a fixed range of linear memory. |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 113 | */ |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 114 | HGLOBAL16 GLOBAL_CreateBlock( WORD flags, const void *ptr, DWORD size, |
Alexandre Julliard | d90840e | 1996-06-11 16:02:08 +0000 | [diff] [blame] | 115 | HGLOBAL16 hOwner, BOOL16 isCode, |
Alexandre Julliard | 4fef2f1 | 2000-08-09 22:27:11 +0000 | [diff] [blame] | 116 | BOOL16 is32Bit, BOOL16 isReadOnly ) |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 117 | { |
| 118 | WORD sel, selcount; |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 119 | GLOBALARENA *pArena; |
Alexandre Julliard | dba420a | 1994-02-02 06:48:31 +0000 | [diff] [blame] | 120 | |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 121 | /* Allocate the selector(s) */ |
| 122 | |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 123 | sel = SELECTOR_AllocBlock( ptr, size, |
| 124 | isCode ? SEGMENT_CODE : SEGMENT_DATA, |
| 125 | is32Bit, isReadOnly ); |
| 126 | |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 127 | if (!sel) return 0; |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 128 | selcount = (size + 0xffff) / 0x10000; |
| 129 | |
| 130 | if (!(pArena = GLOBAL_GetArena( sel, selcount ))) |
| 131 | { |
Alexandre Julliard | 8cc3a5e | 1996-08-11 15:49:51 +0000 | [diff] [blame] | 132 | SELECTOR_FreeBlock( sel, selcount ); |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 133 | return 0; |
| 134 | } |
| 135 | |
| 136 | /* Fill the arena block */ |
| 137 | |
| 138 | pArena->base = (DWORD)ptr; |
| 139 | pArena->size = GET_SEL_LIMIT(sel) + 1; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 140 | pArena->handle = (flags & GMEM_MOVEABLE) ? sel - 1 : sel; |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 141 | pArena->hOwner = hOwner; |
| 142 | pArena->lockCount = 0; |
| 143 | pArena->pageLockCount = 0; |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 144 | pArena->flags = flags & GA_MOVEABLE; |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 145 | if (flags & GMEM_DISCARDABLE) pArena->flags |= GA_DISCARDABLE; |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 146 | if (flags & GMEM_DDESHARE) pArena->flags |= GA_IPCSHARE; |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 147 | if (!isCode) pArena->flags |= GA_DGROUP; |
| 148 | pArena->selCount = selcount; |
| 149 | if (selcount > 1) /* clear the next arena blocks */ |
| 150 | memset( pArena + 1, 0, (selcount - 1) * sizeof(GLOBALARENA) ); |
Alexandre Julliard | dba420a | 1994-02-02 06:48:31 +0000 | [diff] [blame] | 151 | |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 152 | return pArena->handle; |
| 153 | } |
Alexandre Julliard | 121bd98 | 1993-07-08 17:37:25 +0000 | [diff] [blame] | 154 | |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 155 | |
| 156 | /*********************************************************************** |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 157 | * GLOBAL_FreeBlock |
| 158 | * |
| 159 | * Free a block allocated by GLOBAL_CreateBlock, without touching |
| 160 | * the associated linear memory range. |
| 161 | */ |
Alexandre Julliard | d90840e | 1996-06-11 16:02:08 +0000 | [diff] [blame] | 162 | BOOL16 GLOBAL_FreeBlock( HGLOBAL16 handle ) |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 163 | { |
| 164 | WORD sel; |
Alexandre Julliard | 8cc3a5e | 1996-08-11 15:49:51 +0000 | [diff] [blame] | 165 | GLOBALARENA *pArena; |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 166 | |
| 167 | if (!handle) return TRUE; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 168 | sel = GlobalHandleToSel16( handle ); |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 169 | if (!VALID_HANDLE(sel)) |
| 170 | return FALSE; |
Alexandre Julliard | 8cc3a5e | 1996-08-11 15:49:51 +0000 | [diff] [blame] | 171 | pArena = GET_ARENA_PTR(sel); |
| 172 | SELECTOR_FreeBlock( sel, (pArena->size + 0xffff) / 0x10000 ); |
| 173 | memset( pArena, 0, sizeof(GLOBALARENA) ); |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 174 | return TRUE; |
| 175 | } |
| 176 | |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 177 | /*********************************************************************** |
| 178 | * GLOBAL_MoveBlock |
| 179 | */ |
| 180 | BOOL16 GLOBAL_MoveBlock( HGLOBAL16 handle, const void *ptr, DWORD size ) |
| 181 | { |
| 182 | WORD sel; |
| 183 | GLOBALARENA *pArena; |
| 184 | |
| 185 | if (!handle) return TRUE; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 186 | sel = GlobalHandleToSel16( handle ); |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 187 | if (!VALID_HANDLE(sel)) |
| 188 | return FALSE; |
| 189 | pArena = GET_ARENA_PTR(sel); |
| 190 | if (pArena->selCount != 1) |
| 191 | return FALSE; |
| 192 | |
| 193 | pArena->base = (DWORD)ptr; |
| 194 | pArena->size = size; |
| 195 | |
| 196 | SELECTOR_MoveBlock( sel, ptr ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 197 | SetSelectorLimit16( sel, size-1 ); |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 198 | |
| 199 | return TRUE; |
| 200 | } |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 201 | |
| 202 | /*********************************************************************** |
| 203 | * GLOBAL_Alloc |
| 204 | * |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 205 | * Implementation of GlobalAlloc16() |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 206 | */ |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 207 | HGLOBAL16 GLOBAL_Alloc( UINT16 flags, DWORD size, HGLOBAL16 hOwner, |
Alexandre Julliard | d90840e | 1996-06-11 16:02:08 +0000 | [diff] [blame] | 208 | BOOL16 isCode, BOOL16 is32Bit, BOOL16 isReadOnly ) |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 209 | { |
| 210 | void *ptr; |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 211 | HGLOBAL16 handle; |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 212 | |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 213 | TRACE("%ld flags=%04x\n", size, flags ); |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 214 | |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 215 | /* If size is 0, create a discarded block */ |
| 216 | |
| 217 | if (size == 0) return GLOBAL_CreateBlock( flags, NULL, 1, hOwner, isCode, |
Alexandre Julliard | 4fef2f1 | 2000-08-09 22:27:11 +0000 | [diff] [blame] | 218 | is32Bit, isReadOnly ); |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 219 | |
| 220 | /* Fixup the size */ |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 221 | |
Alexandre Julliard | a2f2e01 | 1995-06-06 16:40:35 +0000 | [diff] [blame] | 222 | if (size >= GLOBAL_MAX_ALLOC_SIZE - 0x1f) return 0; |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 223 | size = (size + 0x1f) & ~0x1f; |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 224 | |
Marcus Meissner | e32a317 | 1999-07-11 14:13:56 +0000 | [diff] [blame] | 225 | /* Allocate the linear memory */ |
Alexandre Julliard | 079fd72 | 2000-01-25 01:41:35 +0000 | [diff] [blame] | 226 | ptr = HeapAlloc( GetProcessHeap(), 0, size ); |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 227 | /* FIXME: free discardable blocks and try again? */ |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 228 | if (!ptr) return 0; |
| 229 | |
| 230 | /* Allocate the selector(s) */ |
| 231 | |
| 232 | handle = GLOBAL_CreateBlock( flags, ptr, size, hOwner, |
Alexandre Julliard | 4fef2f1 | 2000-08-09 22:27:11 +0000 | [diff] [blame] | 233 | isCode, is32Bit, isReadOnly ); |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 234 | if (!handle) |
| 235 | { |
Alexandre Julliard | 079fd72 | 2000-01-25 01:41:35 +0000 | [diff] [blame] | 236 | HeapFree( GetProcessHeap(), 0, ptr ); |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 237 | return 0; |
| 238 | } |
| 239 | |
| 240 | if (flags & GMEM_ZEROINIT) memset( ptr, 0, size ); |
| 241 | return handle; |
| 242 | } |
| 243 | |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 244 | /*********************************************************************** |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 245 | * GlobalAlloc16 (KERNEL.15) |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 246 | * RETURNS |
| 247 | * Handle: Success |
| 248 | * NULL: Failure |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 249 | */ |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 250 | HGLOBAL16 WINAPI GlobalAlloc16( |
| 251 | UINT16 flags, /* [in] Object allocation attributes */ |
| 252 | DWORD size /* [in] Number of bytes to allocate */ |
| 253 | ) { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 254 | HANDLE16 owner = GetCurrentPDB16(); |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 255 | |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 256 | if (flags & GMEM_DDESHARE) |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 257 | owner = GetExePtr(owner); /* Make it a module handle */ |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 258 | return GLOBAL_Alloc( flags, size, owner, FALSE, FALSE, FALSE ); |
Alexandre Julliard | 121bd98 | 1993-07-08 17:37:25 +0000 | [diff] [blame] | 259 | } |
Alexandre Julliard | 7cbe657 | 1995-01-09 18:21:16 +0000 | [diff] [blame] | 260 | |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 261 | |
| 262 | /*********************************************************************** |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 263 | * GlobalReAlloc16 (KERNEL.16) |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 264 | * RETURNS |
| 265 | * Handle: Success |
| 266 | * NULL: Failure |
Alexandre Julliard | 7cbe657 | 1995-01-09 18:21:16 +0000 | [diff] [blame] | 267 | */ |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 268 | HGLOBAL16 WINAPI GlobalReAlloc16( |
| 269 | HGLOBAL16 handle, /* [in] Handle of global memory object */ |
| 270 | DWORD size, /* [in] New size of block */ |
| 271 | UINT16 flags /* [in] How to reallocate object */ |
| 272 | ) { |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 273 | WORD selcount; |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 274 | DWORD oldsize; |
| 275 | void *ptr; |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 276 | GLOBALARENA *pArena, *pNewArena; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 277 | WORD sel = GlobalHandleToSel16( handle ); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 278 | |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 279 | TRACE("%04x %ld flags=%04x\n", |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 280 | handle, size, flags ); |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 281 | if (!handle) return 0; |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 282 | |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 283 | if (!VALID_HANDLE(handle)) { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 284 | WARN("Invalid handle 0x%04x!\n", handle); |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 285 | return 0; |
| 286 | } |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 287 | pArena = GET_ARENA_PTR( handle ); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 288 | |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 289 | /* Discard the block if requested */ |
| 290 | |
Alexandre Julliard | ded3038 | 1995-07-06 17:18:27 +0000 | [diff] [blame] | 291 | if ((size == 0) && (flags & GMEM_MOVEABLE) && !(flags & GMEM_MODIFY)) |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 292 | { |
| 293 | if (!(pArena->flags & GA_MOVEABLE) || |
| 294 | !(pArena->flags & GA_DISCARDABLE) || |
| 295 | (pArena->lockCount > 0) || (pArena->pageLockCount > 0)) return 0; |
Alexandre Julliard | 079fd72 | 2000-01-25 01:41:35 +0000 | [diff] [blame] | 296 | HeapFree( GetProcessHeap(), 0, (void *)pArena->base ); |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 297 | pArena->base = 0; |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 298 | |
| 299 | /* Note: we rely on the fact that SELECTOR_ReallocBlock won't |
| 300 | * change the selector if we are shrinking the block. |
| 301 | * FIXME: shouldn't we keep selectors until the block is deleted? |
| 302 | */ |
Alexandre Julliard | 284c9b9 | 1999-04-11 15:07:13 +0000 | [diff] [blame] | 303 | SELECTOR_ReallocBlock( sel, 0, 1 ); |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 304 | return handle; |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 305 | } |
| 306 | |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 307 | /* Fixup the size */ |
| 308 | |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 309 | if (size > GLOBAL_MAX_ALLOC_SIZE - 0x20) return 0; |
| 310 | if (size == 0) size = 0x20; |
| 311 | else size = (size + 0x1f) & ~0x1f; |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 312 | |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 313 | /* Change the flags */ |
| 314 | |
| 315 | if (flags & GMEM_MODIFY) |
| 316 | { |
| 317 | /* Change the flags, leaving GA_DGROUP alone */ |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 318 | pArena->flags = (pArena->flags & GA_DGROUP) | (flags & GA_MOVEABLE); |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 319 | if (flags & GMEM_DISCARDABLE) pArena->flags |= GA_DISCARDABLE; |
| 320 | return handle; |
| 321 | } |
| 322 | |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 323 | /* Reallocate the linear memory */ |
| 324 | |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 325 | ptr = (void *)pArena->base; |
| 326 | oldsize = pArena->size; |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 327 | TRACE("oldsize %08lx\n",oldsize); |
Alexandre Julliard | 7d654eb | 1996-02-25 11:36:22 +0000 | [diff] [blame] | 328 | if (ptr && (size == oldsize)) return handle; /* Nothing to do */ |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 329 | |
Andreas Mohr | d23f506 | 2000-10-02 22:16:21 +0000 | [diff] [blame] | 330 | if (pArena->flags & GA_DOSMEM) |
Ove Kaaven | 7b49914 | 2000-07-28 22:23:59 +0000 | [diff] [blame] | 331 | ptr = DOSMEM_ResizeBlock(ptr, size, NULL); |
Bertho Stultiens | c1d1cfe | 1999-04-18 12:14:06 +0000 | [diff] [blame] | 332 | else |
Alexandre Julliard | 079fd72 | 2000-01-25 01:41:35 +0000 | [diff] [blame] | 333 | ptr = HeapReAlloc( GetProcessHeap(), 0, ptr, size ); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 334 | if (!ptr) |
| 335 | { |
Alexandre Julliard | 8cc3a5e | 1996-08-11 15:49:51 +0000 | [diff] [blame] | 336 | SELECTOR_FreeBlock( sel, (oldsize + 0xffff) / 0x10000 ); |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 337 | memset( pArena, 0, sizeof(GLOBALARENA) ); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 338 | return 0; |
| 339 | } |
| 340 | |
| 341 | /* Reallocate the selector(s) */ |
| 342 | |
Alexandre Julliard | 284c9b9 | 1999-04-11 15:07:13 +0000 | [diff] [blame] | 343 | sel = SELECTOR_ReallocBlock( sel, ptr, size ); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 344 | if (!sel) |
| 345 | { |
Alexandre Julliard | 079fd72 | 2000-01-25 01:41:35 +0000 | [diff] [blame] | 346 | HeapFree( GetProcessHeap(), 0, ptr ); |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 347 | memset( pArena, 0, sizeof(GLOBALARENA) ); |
| 348 | return 0; |
| 349 | } |
| 350 | selcount = (size + 0xffff) / 0x10000; |
| 351 | |
| 352 | if (!(pNewArena = GLOBAL_GetArena( sel, selcount ))) |
| 353 | { |
Alexandre Julliard | 079fd72 | 2000-01-25 01:41:35 +0000 | [diff] [blame] | 354 | HeapFree( GetProcessHeap(), 0, ptr ); |
Alexandre Julliard | 8cc3a5e | 1996-08-11 15:49:51 +0000 | [diff] [blame] | 355 | SELECTOR_FreeBlock( sel, selcount ); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 356 | return 0; |
| 357 | } |
| 358 | |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 359 | /* Fill the new arena block */ |
| 360 | |
| 361 | if (pNewArena != pArena) memcpy( pNewArena, pArena, sizeof(GLOBALARENA) ); |
| 362 | pNewArena->base = (DWORD)ptr; |
| 363 | pNewArena->size = GET_SEL_LIMIT(sel) + 1; |
| 364 | pNewArena->selCount = selcount; |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 365 | pNewArena->handle = (pNewArena->flags & GA_MOVEABLE) ? sel - 1 : sel; |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 366 | |
| 367 | if (selcount > 1) /* clear the next arena blocks */ |
| 368 | memset( pNewArena + 1, 0, (selcount - 1) * sizeof(GLOBALARENA) ); |
| 369 | |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 370 | if ((oldsize < size) && (flags & GMEM_ZEROINIT)) |
| 371 | memset( (char *)ptr + oldsize, 0, size - oldsize ); |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 372 | return pNewArena->handle; |
Alexandre Julliard | 7cbe657 | 1995-01-09 18:21:16 +0000 | [diff] [blame] | 373 | } |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 374 | |
| 375 | |
| 376 | /*********************************************************************** |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 377 | * GlobalFree16 (KERNEL.17) |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 378 | * RETURNS |
| 379 | * NULL: Success |
| 380 | * Handle: Failure |
Alexandre Julliard | 121bd98 | 1993-07-08 17:37:25 +0000 | [diff] [blame] | 381 | */ |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 382 | HGLOBAL16 WINAPI GlobalFree16( |
| 383 | HGLOBAL16 handle /* [in] Handle of global memory object */ |
| 384 | ) { |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 385 | void *ptr; |
Alexandre Julliard | 121bd98 | 1993-07-08 17:37:25 +0000 | [diff] [blame] | 386 | |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 387 | if (!VALID_HANDLE(handle)) { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 388 | WARN("Invalid handle 0x%04x passed to GlobalFree16!\n",handle); |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 389 | return 0; |
| 390 | } |
| 391 | ptr = (void *)GET_ARENA_PTR(handle)->base; |
| 392 | |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 393 | TRACE("%04x\n", handle ); |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 394 | if (!GLOBAL_FreeBlock( handle )) return handle; /* failed */ |
Alexandre Julliard | 079fd72 | 2000-01-25 01:41:35 +0000 | [diff] [blame] | 395 | if (ptr) HeapFree( GetProcessHeap(), 0, ptr ); |
Alexandre Julliard | 121bd98 | 1993-07-08 17:37:25 +0000 | [diff] [blame] | 396 | return 0; |
| 397 | } |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 398 | |
| 399 | |
| 400 | /*********************************************************************** |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 401 | * WIN16_GlobalLock16 (KERNEL.18) |
Alexandre Julliard | 121bd98 | 1993-07-08 17:37:25 +0000 | [diff] [blame] | 402 | * |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 403 | * This is the GlobalLock16() function used by 16-bit code. |
Alexandre Julliard | 121bd98 | 1993-07-08 17:37:25 +0000 | [diff] [blame] | 404 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 405 | SEGPTR WINAPI WIN16_GlobalLock16( HGLOBAL16 handle ) |
Alexandre Julliard | 121bd98 | 1993-07-08 17:37:25 +0000 | [diff] [blame] | 406 | { |
Ulrich Weigand | b2682d4 | 1999-07-27 16:10:24 +0000 | [diff] [blame] | 407 | WORD sel = GlobalHandleToSel16( handle ); |
| 408 | TRACE("(%04x) -> %08lx\n", handle, MAKELONG( 0, sel ) ); |
| 409 | |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 410 | if (handle) |
| 411 | { |
| 412 | if (handle == (HGLOBAL16)-1) handle = CURRENT_DS; |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 413 | |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 414 | if (!VALID_HANDLE(handle)) { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 415 | WARN("Invalid handle 0x%04x passed to WIN16_GlobalLock16!\n",handle); |
Ulrich Weigand | b2682d4 | 1999-07-27 16:10:24 +0000 | [diff] [blame] | 416 | sel = 0; |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 417 | } |
Ulrich Weigand | 81a8057 | 1999-07-28 16:36:29 +0000 | [diff] [blame] | 418 | else if (!GET_ARENA_PTR(handle)->base) |
Ulrich Weigand | b2682d4 | 1999-07-27 16:10:24 +0000 | [diff] [blame] | 419 | sel = 0; |
| 420 | else |
| 421 | GET_ARENA_PTR(handle)->lockCount++; |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 422 | } |
Ulrich Weigand | b2682d4 | 1999-07-27 16:10:24 +0000 | [diff] [blame] | 423 | |
| 424 | CURRENT_STACK16->ecx = sel; /* selector must be returned in CX as well */ |
| 425 | return PTR_SEG_OFF_TO_SEGPTR( sel, 0 ); |
Alexandre Julliard | 121bd98 | 1993-07-08 17:37:25 +0000 | [diff] [blame] | 426 | } |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 427 | |
| 428 | |
| 429 | /*********************************************************************** |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 430 | * GlobalLock16 (KERNEL.18) |
Alexandre Julliard | 75a839a | 1993-07-15 11:13:45 +0000 | [diff] [blame] | 431 | * |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 432 | * This is the GlobalLock16() function used by 32-bit code. |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 433 | * |
| 434 | * RETURNS |
| 435 | * Pointer to first byte of memory block |
| 436 | * NULL: Failure |
Alexandre Julliard | 75a839a | 1993-07-15 11:13:45 +0000 | [diff] [blame] | 437 | */ |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 438 | LPVOID WINAPI GlobalLock16( |
| 439 | HGLOBAL16 handle /* [in] Handle of global memory object */ |
| 440 | ) { |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 441 | if (!handle) return 0; |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 442 | if (!VALID_HANDLE(handle)) |
| 443 | return (LPVOID)0; |
Alexandre Julliard | 3db94ef | 1997-09-28 17:43:24 +0000 | [diff] [blame] | 444 | GET_ARENA_PTR(handle)->lockCount++; |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 445 | return (LPVOID)GET_ARENA_PTR(handle)->base; |
Alexandre Julliard | 75a839a | 1993-07-15 11:13:45 +0000 | [diff] [blame] | 446 | } |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 447 | |
| 448 | |
| 449 | /*********************************************************************** |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 450 | * GlobalUnlock16 (KERNEL.19) |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 451 | * NOTES |
| 452 | * Should the return values be cast to booleans? |
| 453 | * |
| 454 | * RETURNS |
| 455 | * TRUE: Object is still locked |
| 456 | * FALSE: Object is unlocked |
Alexandre Julliard | 75a839a | 1993-07-15 11:13:45 +0000 | [diff] [blame] | 457 | */ |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 458 | BOOL16 WINAPI GlobalUnlock16( |
| 459 | HGLOBAL16 handle /* [in] Handle of global memory object */ |
| 460 | ) { |
Alexandre Julliard | 3db94ef | 1997-09-28 17:43:24 +0000 | [diff] [blame] | 461 | GLOBALARENA *pArena = GET_ARENA_PTR(handle); |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 462 | if (!VALID_HANDLE(handle)) { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 463 | WARN("Invalid handle 0x%04x passed to GlobalUnlock16!\n",handle); |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 464 | return 0; |
| 465 | } |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 466 | TRACE("%04x\n", handle ); |
Alexandre Julliard | 3db94ef | 1997-09-28 17:43:24 +0000 | [diff] [blame] | 467 | if (pArena->lockCount) pArena->lockCount--; |
| 468 | return pArena->lockCount; |
Alexandre Julliard | 75a839a | 1993-07-15 11:13:45 +0000 | [diff] [blame] | 469 | } |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 470 | |
Ulrich Weigand | 23e9b04 | 1998-12-01 15:19:54 +0000 | [diff] [blame] | 471 | /*********************************************************************** |
| 472 | * GlobalChangeLockCount (KERNEL.365) |
| 473 | * |
| 474 | * This is declared as a register function as it has to preserve |
| 475 | * *all* registers, even AX/DX ! |
| 476 | * |
| 477 | */ |
Ulrich Weigand | b5151d0 | 1999-07-25 11:27:36 +0000 | [diff] [blame] | 478 | void WINAPI GlobalChangeLockCount16( HGLOBAL16 handle, INT16 delta, |
| 479 | CONTEXT86 *context ) |
Ulrich Weigand | 23e9b04 | 1998-12-01 15:19:54 +0000 | [diff] [blame] | 480 | { |
Ulrich Weigand | 23e9b04 | 1998-12-01 15:19:54 +0000 | [diff] [blame] | 481 | if ( delta == 1 ) |
| 482 | GlobalLock16( handle ); |
| 483 | else if ( delta == -1 ) |
| 484 | GlobalUnlock16( handle ); |
| 485 | else |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 486 | ERR("(%04X, %d): strange delta value\n", handle, delta ); |
Ulrich Weigand | 23e9b04 | 1998-12-01 15:19:54 +0000 | [diff] [blame] | 487 | } |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 488 | |
| 489 | /*********************************************************************** |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 490 | * GlobalSize16 (KERNEL.20) |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 491 | * RETURNS |
| 492 | * Size in bytes of object |
| 493 | * 0: Failure |
Alexandre Julliard | 75a839a | 1993-07-15 11:13:45 +0000 | [diff] [blame] | 494 | */ |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 495 | DWORD WINAPI GlobalSize16( |
| 496 | HGLOBAL16 handle /* [in] Handle of global memory object */ |
| 497 | ) { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 498 | TRACE("%04x\n", handle ); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 499 | if (!handle) return 0; |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 500 | if (!VALID_HANDLE(handle)) |
| 501 | return 0; |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 502 | return GET_ARENA_PTR(handle)->size; |
Alexandre Julliard | 75a839a | 1993-07-15 11:13:45 +0000 | [diff] [blame] | 503 | } |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 504 | |
| 505 | |
| 506 | /*********************************************************************** |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 507 | * GlobalHandle16 (KERNEL.21) |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 508 | * NOTES |
| 509 | * Why is GlobalHandleToSel used here with the sel as input? |
| 510 | * |
| 511 | * RETURNS |
| 512 | * Handle: Success |
| 513 | * NULL: Failure |
Alexandre Julliard | 75a839a | 1993-07-15 11:13:45 +0000 | [diff] [blame] | 514 | */ |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 515 | DWORD WINAPI GlobalHandle16( |
| 516 | WORD sel /* [in] Address of global memory block */ |
| 517 | ) { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 518 | TRACE("%04x\n", sel ); |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 519 | if (!VALID_HANDLE(sel)) { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 520 | WARN("Invalid handle 0x%04x passed to GlobalHandle16!\n",sel); |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 521 | return 0; |
| 522 | } |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 523 | return MAKELONG( GET_ARENA_PTR(sel)->handle, GlobalHandleToSel16(sel) ); |
Alexandre Julliard | 75a839a | 1993-07-15 11:13:45 +0000 | [diff] [blame] | 524 | } |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 525 | |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 526 | /*********************************************************************** |
| 527 | * GlobalHandleNoRIP (KERNEL.159) |
| 528 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 529 | DWORD WINAPI GlobalHandleNoRIP16( WORD sel ) |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 530 | { |
| 531 | int i; |
| 532 | for (i = globalArenaSize-1 ; i>=0 ; i--) { |
| 533 | if (pGlobalArena[i].size!=0 && pGlobalArena[i].handle == sel) |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 534 | return MAKELONG( GET_ARENA_PTR(sel)->handle, GlobalHandleToSel16(sel) ); |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 535 | } |
| 536 | return 0; |
| 537 | } |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 538 | |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 539 | |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 540 | /*********************************************************************** |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 541 | * GlobalFlags16 (KERNEL.22) |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 542 | * NOTES |
| 543 | * Should this return GMEM_INVALID_HANDLE instead of 0 on invalid |
| 544 | * handle? |
| 545 | * |
| 546 | * RETURNS |
| 547 | * Value specifying flags and lock count |
| 548 | * GMEM_INVALID_HANDLE: Invalid handle |
Alexandre Julliard | 75a839a | 1993-07-15 11:13:45 +0000 | [diff] [blame] | 549 | */ |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 550 | UINT16 WINAPI GlobalFlags16( |
| 551 | HGLOBAL16 handle /* [in] Handle of global memory object */ |
| 552 | ) { |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 553 | GLOBALARENA *pArena; |
| 554 | |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 555 | TRACE("%04x\n", handle ); |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 556 | if (!VALID_HANDLE(handle)) { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 557 | WARN("Invalid handle 0x%04x passed to GlobalFlags16!\n",handle); |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 558 | return 0; |
| 559 | } |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 560 | pArena = GET_ARENA_PTR(handle); |
| 561 | return pArena->lockCount | |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 562 | ((pArena->flags & GA_DISCARDABLE) ? GMEM_DISCARDABLE : 0) | |
| 563 | ((pArena->base == 0) ? GMEM_DISCARDED : 0); |
Alexandre Julliard | 75a839a | 1993-07-15 11:13:45 +0000 | [diff] [blame] | 564 | } |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 565 | |
| 566 | |
| 567 | /*********************************************************************** |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 568 | * LockSegment16 (KERNEL.23) |
Alexandre Julliard | 75a839a | 1993-07-15 11:13:45 +0000 | [diff] [blame] | 569 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 570 | HGLOBAL16 WINAPI LockSegment16( HGLOBAL16 handle ) |
Alexandre Julliard | 75a839a | 1993-07-15 11:13:45 +0000 | [diff] [blame] | 571 | { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 572 | TRACE("%04x\n", handle ); |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 573 | if (handle == (HGLOBAL16)-1) handle = CURRENT_DS; |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 574 | if (!VALID_HANDLE(handle)) { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 575 | WARN("Invalid handle 0x%04x passed to LockSegment16!\n",handle); |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 576 | return 0; |
| 577 | } |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 578 | GET_ARENA_PTR(handle)->lockCount++; |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 579 | return handle; |
Alexandre Julliard | 75a839a | 1993-07-15 11:13:45 +0000 | [diff] [blame] | 580 | } |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 581 | |
| 582 | |
| 583 | /*********************************************************************** |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 584 | * UnlockSegment16 (KERNEL.24) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 585 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 586 | void WINAPI UnlockSegment16( HGLOBAL16 handle ) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 587 | { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 588 | TRACE("%04x\n", handle ); |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 589 | if (handle == (HGLOBAL16)-1) handle = CURRENT_DS; |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 590 | if (!VALID_HANDLE(handle)) { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 591 | WARN("Invalid handle 0x%04x passed to UnlockSegment16!\n",handle); |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 592 | return; |
| 593 | } |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 594 | GET_ARENA_PTR(handle)->lockCount--; |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 595 | /* FIXME: this ought to return the lock count in CX (go figure...) */ |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 596 | } |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 597 | |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 598 | |
| 599 | /*********************************************************************** |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 600 | * GlobalCompact16 (KERNEL.25) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 601 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 602 | DWORD WINAPI GlobalCompact16( DWORD desired ) |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 603 | { |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 604 | return GLOBAL_MAX_ALLOC_SIZE; |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 605 | } |
| 606 | |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 607 | |
| 608 | /*********************************************************************** |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 609 | * GlobalFreeAll (KERNEL.26) |
| 610 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 611 | void WINAPI GlobalFreeAll16( HGLOBAL16 owner ) |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 612 | { |
| 613 | DWORD i; |
| 614 | GLOBALARENA *pArena; |
| 615 | |
| 616 | pArena = pGlobalArena; |
| 617 | for (i = 0; i < globalArenaSize; i++, pArena++) |
| 618 | { |
| 619 | if ((pArena->size != 0) && (pArena->hOwner == owner)) |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 620 | GlobalFree16( pArena->handle ); |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 621 | } |
| 622 | } |
| 623 | |
| 624 | |
| 625 | /*********************************************************************** |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 626 | * GlobalWire16 (KERNEL.111) |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 627 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 628 | SEGPTR WINAPI GlobalWire16( HGLOBAL16 handle ) |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 629 | { |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 630 | return WIN16_GlobalLock16( handle ); |
Alexandre Julliard | 8d24ae6 | 1994-04-05 21:42:43 +0000 | [diff] [blame] | 631 | } |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 632 | |
| 633 | |
| 634 | /*********************************************************************** |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 635 | * GlobalUnWire16 (KERNEL.112) |
Alexandre Julliard | 3f2abfa | 1994-08-16 15:43:11 +0000 | [diff] [blame] | 636 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 637 | BOOL16 WINAPI GlobalUnWire16( HGLOBAL16 handle ) |
Alexandre Julliard | 3f2abfa | 1994-08-16 15:43:11 +0000 | [diff] [blame] | 638 | { |
Alexandre Julliard | 3db94ef | 1997-09-28 17:43:24 +0000 | [diff] [blame] | 639 | return !GlobalUnlock16( handle ); |
Alexandre Julliard | 3f2abfa | 1994-08-16 15:43:11 +0000 | [diff] [blame] | 640 | } |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 641 | |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 642 | |
| 643 | /*********************************************************************** |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 644 | * SetSwapAreaSize16 (KERNEL.106) |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 645 | */ |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 646 | LONG WINAPI SetSwapAreaSize16( WORD size ) |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 647 | { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 648 | FIXME("(%d) - stub!\n", size ); |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 649 | return MAKELONG( size, 0xffff ); |
| 650 | } |
Alexandre Julliard | 3a405ba | 1994-10-30 16:25:19 +0000 | [diff] [blame] | 651 | |
Alexandre Julliard | 3a405ba | 1994-10-30 16:25:19 +0000 | [diff] [blame] | 652 | |
| 653 | /*********************************************************************** |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 654 | * GlobalLRUOldest (KERNEL.163) |
Alexandre Julliard | 3a405ba | 1994-10-30 16:25:19 +0000 | [diff] [blame] | 655 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 656 | HGLOBAL16 WINAPI GlobalLRUOldest16( HGLOBAL16 handle ) |
Alexandre Julliard | 3a405ba | 1994-10-30 16:25:19 +0000 | [diff] [blame] | 657 | { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 658 | TRACE("%04x\n", handle ); |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 659 | if (handle == (HGLOBAL16)-1) handle = CURRENT_DS; |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 660 | return handle; |
Alexandre Julliard | 3a405ba | 1994-10-30 16:25:19 +0000 | [diff] [blame] | 661 | } |
| 662 | |
Alexandre Julliard | 3a405ba | 1994-10-30 16:25:19 +0000 | [diff] [blame] | 663 | |
| 664 | /*********************************************************************** |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 665 | * GlobalLRUNewest (KERNEL.164) |
Alexandre Julliard | 3a405ba | 1994-10-30 16:25:19 +0000 | [diff] [blame] | 666 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 667 | HGLOBAL16 WINAPI GlobalLRUNewest16( HGLOBAL16 handle ) |
Alexandre Julliard | 3a405ba | 1994-10-30 16:25:19 +0000 | [diff] [blame] | 668 | { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 669 | TRACE("%04x\n", handle ); |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 670 | if (handle == (HGLOBAL16)-1) handle = CURRENT_DS; |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 671 | return handle; |
Alexandre Julliard | 3a405ba | 1994-10-30 16:25:19 +0000 | [diff] [blame] | 672 | } |
| 673 | |
Alexandre Julliard | 3a405ba | 1994-10-30 16:25:19 +0000 | [diff] [blame] | 674 | |
| 675 | /*********************************************************************** |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 676 | * GetFreeSpace16 (KERNEL.169) |
Alexandre Julliard | 3a405ba | 1994-10-30 16:25:19 +0000 | [diff] [blame] | 677 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 678 | DWORD WINAPI GetFreeSpace16( UINT16 wFlags ) |
Alexandre Julliard | 3a405ba | 1994-10-30 16:25:19 +0000 | [diff] [blame] | 679 | { |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 680 | MEMORYSTATUS ms; |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 681 | GlobalMemoryStatus( &ms ); |
| 682 | return ms.dwAvailVirtual; |
Alexandre Julliard | 3a405ba | 1994-10-30 16:25:19 +0000 | [diff] [blame] | 683 | } |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 684 | |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 685 | /*********************************************************************** |
| 686 | * GlobalDOSAlloc (KERNEL.184) |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 687 | * RETURNS |
| 688 | * Address (HW=Paragraph segment; LW=Selector) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 689 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 690 | DWORD WINAPI GlobalDOSAlloc16( |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 691 | DWORD size /* [in] Number of bytes to be allocated */ |
| 692 | ) { |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 693 | UINT16 uParagraph; |
Ove Kaaven | 7b49914 | 2000-07-28 22:23:59 +0000 | [diff] [blame] | 694 | LPVOID lpBlock = DOSMEM_GetBlock( size, &uParagraph ); |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 695 | |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 696 | if( lpBlock ) |
| 697 | { |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 698 | HMODULE16 hModule = GetModuleHandle16("KERNEL"); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 699 | WORD wSelector; |
Andreas Mohr | d23f506 | 2000-10-02 22:16:21 +0000 | [diff] [blame] | 700 | GLOBALARENA *pArena; |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 701 | |
| 702 | wSelector = GLOBAL_CreateBlock(GMEM_FIXED, lpBlock, size, |
Alexandre Julliard | 4fef2f1 | 2000-08-09 22:27:11 +0000 | [diff] [blame] | 703 | hModule, 0, 0, 0 ); |
Andreas Mohr | d23f506 | 2000-10-02 22:16:21 +0000 | [diff] [blame] | 704 | pArena = GET_ARENA_PTR(wSelector); |
| 705 | pArena->flags |= GA_DOSMEM; |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 706 | return MAKELONG(wSelector,uParagraph); |
| 707 | } |
| 708 | return 0; |
| 709 | } |
| 710 | |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 711 | |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 712 | /*********************************************************************** |
| 713 | * GlobalDOSFree (KERNEL.185) |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 714 | * RETURNS |
| 715 | * NULL: Success |
| 716 | * sel: Failure |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 717 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 718 | WORD WINAPI GlobalDOSFree16( |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 719 | WORD sel /* [in] Selector */ |
| 720 | ) { |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 721 | DWORD block = GetSelectorBase(sel); |
| 722 | |
| 723 | if( block && block < 0x100000 ) |
| 724 | { |
| 725 | LPVOID lpBlock = DOSMEM_MapDosToLinear( block ); |
Ove Kaaven | 7b49914 | 2000-07-28 22:23:59 +0000 | [diff] [blame] | 726 | if( DOSMEM_FreeBlock( lpBlock ) ) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 727 | GLOBAL_FreeBlock( sel ); |
| 728 | sel = 0; |
| 729 | } |
| 730 | return sel; |
| 731 | } |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 732 | |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 733 | |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 734 | /*********************************************************************** |
| 735 | * GlobalPageLock (KERNEL.191) |
| 736 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 737 | WORD WINAPI GlobalPageLock16( HGLOBAL16 handle ) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 738 | { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 739 | TRACE("%04x\n", handle ); |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 740 | if (!VALID_HANDLE(handle)) { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 741 | WARN("Invalid handle 0x%04x passed to GlobalPageLock!\n",handle); |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 742 | return 0; |
| 743 | } |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 744 | return ++(GET_ARENA_PTR(handle)->pageLockCount); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | |
| 748 | /*********************************************************************** |
| 749 | * GlobalPageUnlock (KERNEL.192) |
| 750 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 751 | WORD WINAPI GlobalPageUnlock16( HGLOBAL16 handle ) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 752 | { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 753 | TRACE("%04x\n", handle ); |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 754 | if (!VALID_HANDLE(handle)) { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 755 | WARN("Invalid handle 0x%04x passed to GlobalPageUnlock!\n",handle); |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 756 | return 0; |
| 757 | } |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 758 | return --(GET_ARENA_PTR(handle)->pageLockCount); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | |
| 762 | /*********************************************************************** |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 763 | * GlobalFix16 (KERNEL.197) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 764 | */ |
Ulrich Weigand | 85a7ff4 | 1998-10-11 19:10:10 +0000 | [diff] [blame] | 765 | WORD WINAPI GlobalFix16( HGLOBAL16 handle ) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 766 | { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 767 | TRACE("%04x\n", handle ); |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 768 | if (!VALID_HANDLE(handle)) { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 769 | WARN("Invalid handle 0x%04x passed to GlobalFix16!\n",handle); |
Ulrich Weigand | 85a7ff4 | 1998-10-11 19:10:10 +0000 | [diff] [blame] | 770 | return 0; |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 771 | } |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 772 | GET_ARENA_PTR(handle)->lockCount++; |
Ulrich Weigand | 85a7ff4 | 1998-10-11 19:10:10 +0000 | [diff] [blame] | 773 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 774 | return GlobalHandleToSel16(handle); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | |
| 778 | /*********************************************************************** |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 779 | * GlobalUnfix16 (KERNEL.198) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 780 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 781 | void WINAPI GlobalUnfix16( HGLOBAL16 handle ) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 782 | { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 783 | TRACE("%04x\n", handle ); |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 784 | if (!VALID_HANDLE(handle)) { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 785 | WARN("Invalid handle 0x%04x passed to GlobalUnfix16!\n",handle); |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 786 | return; |
| 787 | } |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 788 | GET_ARENA_PTR(handle)->lockCount--; |
| 789 | } |
| 790 | |
| 791 | |
| 792 | /*********************************************************************** |
| 793 | * FarSetOwner (KERNEL.403) |
| 794 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 795 | void WINAPI FarSetOwner16( HGLOBAL16 handle, HANDLE16 hOwner ) |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 796 | { |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 797 | if (!VALID_HANDLE(handle)) { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 798 | WARN("Invalid handle 0x%04x passed to FarSetOwner!\n",handle); |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 799 | return; |
| 800 | } |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 801 | GET_ARENA_PTR(handle)->hOwner = hOwner; |
| 802 | } |
| 803 | |
| 804 | |
| 805 | /*********************************************************************** |
| 806 | * FarGetOwner (KERNEL.404) |
| 807 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 808 | HANDLE16 WINAPI FarGetOwner16( HGLOBAL16 handle ) |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 809 | { |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 810 | if (!VALID_HANDLE(handle)) { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 811 | WARN("Invalid handle 0x%04x passed to FarGetOwner!\n",handle); |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 812 | return 0; |
| 813 | } |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 814 | return GET_ARENA_PTR(handle)->hOwner; |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | |
| 818 | /*********************************************************************** |
| 819 | * GlobalHandleToSel (TOOLHELP.50) |
| 820 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 821 | WORD WINAPI GlobalHandleToSel16( HGLOBAL16 handle ) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 822 | { |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 823 | if (!handle) return 0; |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 824 | if (!VALID_HANDLE(handle)) { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 825 | WARN("Invalid handle 0x%04x passed to GlobalHandleToSel!\n",handle); |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 826 | return 0; |
| 827 | } |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 828 | if (!(handle & 7)) |
| 829 | { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 830 | WARN("Program attempted invalid selector conversion\n" ); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 831 | return handle - 1; |
| 832 | } |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 833 | return handle | 7; |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 837 | /*********************************************************************** |
| 838 | * GlobalFirst (TOOLHELP.51) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 839 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 840 | BOOL16 WINAPI GlobalFirst16( GLOBALENTRY *pGlobal, WORD wFlags ) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 841 | { |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 842 | if (wFlags == GLOBAL_LRU) return FALSE; |
| 843 | pGlobal->dwNext = 0; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 844 | return GlobalNext16( pGlobal, wFlags ); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 845 | } |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 846 | |
| 847 | |
| 848 | /*********************************************************************** |
| 849 | * GlobalNext (TOOLHELP.52) |
| 850 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 851 | BOOL16 WINAPI GlobalNext16( GLOBALENTRY *pGlobal, WORD wFlags) |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 852 | { |
| 853 | GLOBALARENA *pArena; |
| 854 | |
Alexandre Julliard | 594997c | 1995-04-30 10:05:20 +0000 | [diff] [blame] | 855 | if (pGlobal->dwNext >= globalArenaSize) return FALSE; |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 856 | pArena = pGlobalArena + pGlobal->dwNext; |
| 857 | if (wFlags == GLOBAL_FREE) /* only free blocks */ |
| 858 | { |
| 859 | int i; |
| 860 | for (i = pGlobal->dwNext; i < globalArenaSize; i++, pArena++) |
| 861 | if (pArena->size == 0) break; /* block is free */ |
| 862 | if (i >= globalArenaSize) return FALSE; |
| 863 | pGlobal->dwNext = i; |
| 864 | } |
| 865 | |
| 866 | pGlobal->dwAddress = pArena->base; |
| 867 | pGlobal->dwBlockSize = pArena->size; |
| 868 | pGlobal->hBlock = pArena->handle; |
| 869 | pGlobal->wcLock = pArena->lockCount; |
| 870 | pGlobal->wcPageLock = pArena->pageLockCount; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 871 | pGlobal->wFlags = (GetCurrentPDB16() == pArena->hOwner); |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 872 | pGlobal->wHeapPresent = FALSE; |
| 873 | pGlobal->hOwner = pArena->hOwner; |
| 874 | pGlobal->wType = GT_UNKNOWN; |
| 875 | pGlobal->wData = 0; |
| 876 | pGlobal->dwNext++; |
| 877 | return TRUE; |
| 878 | } |
| 879 | |
| 880 | |
| 881 | /*********************************************************************** |
| 882 | * GlobalInfo (TOOLHELP.53) |
| 883 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 884 | BOOL16 WINAPI GlobalInfo16( GLOBALINFO *pInfo ) |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 885 | { |
| 886 | int i; |
| 887 | GLOBALARENA *pArena; |
| 888 | |
| 889 | pInfo->wcItems = globalArenaSize; |
| 890 | pInfo->wcItemsFree = 0; |
| 891 | pInfo->wcItemsLRU = 0; |
| 892 | for (i = 0, pArena = pGlobalArena; i < globalArenaSize; i++, pArena++) |
| 893 | if (pArena->size == 0) pInfo->wcItemsFree++; |
| 894 | return TRUE; |
| 895 | } |
| 896 | |
| 897 | |
| 898 | /*********************************************************************** |
| 899 | * GlobalEntryHandle (TOOLHELP.54) |
| 900 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 901 | BOOL16 WINAPI GlobalEntryHandle16( GLOBALENTRY *pGlobal, HGLOBAL16 hItem ) |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 902 | { |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 903 | GLOBALARENA *pArena = GET_ARENA_PTR(hItem); |
| 904 | |
| 905 | pGlobal->dwAddress = pArena->base; |
| 906 | pGlobal->dwBlockSize = pArena->size; |
| 907 | pGlobal->hBlock = pArena->handle; |
| 908 | pGlobal->wcLock = pArena->lockCount; |
| 909 | pGlobal->wcPageLock = pArena->pageLockCount; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 910 | pGlobal->wFlags = (GetCurrentPDB16() == pArena->hOwner); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 911 | pGlobal->wHeapPresent = FALSE; |
| 912 | pGlobal->hOwner = pArena->hOwner; |
| 913 | pGlobal->wType = GT_UNKNOWN; |
| 914 | pGlobal->wData = 0; |
| 915 | pGlobal->dwNext++; |
| 916 | return TRUE; |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | |
| 920 | /*********************************************************************** |
| 921 | * GlobalEntryModule (TOOLHELP.55) |
| 922 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 923 | BOOL16 WINAPI GlobalEntryModule16( GLOBALENTRY *pGlobal, HMODULE16 hModule, |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 924 | WORD wSeg ) |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 925 | { |
Andreas Mohr | d23f506 | 2000-10-02 22:16:21 +0000 | [diff] [blame] | 926 | FIXME("(%p, 0x%04x, 0x%04x), stub.\n", pGlobal, hModule, wSeg); |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 927 | return FALSE; |
| 928 | } |
| 929 | |
| 930 | |
| 931 | /*********************************************************************** |
| 932 | * MemManInfo (TOOLHELP.72) |
| 933 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 934 | BOOL16 WINAPI MemManInfo16( MEMMANINFO *info ) |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 935 | { |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 936 | MEMORYSTATUS status; |
Alexandre Julliard | 4f8c37b | 1996-01-14 18:12:01 +0000 | [diff] [blame] | 937 | |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 938 | /* |
| 939 | * Not unsurprisingly although the documention says you |
| 940 | * _must_ provide the size in the dwSize field, this function |
| 941 | * (under Windows) always fills the structure and returns true. |
| 942 | */ |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 943 | GlobalMemoryStatus( &status ); |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 944 | info->wPageSize = VIRTUAL_GetPageSize(); |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 945 | info->dwLargestFreeBlock = status.dwAvailVirtual; |
| 946 | info->dwMaxPagesAvailable = info->dwLargestFreeBlock / info->wPageSize; |
| 947 | info->dwMaxPagesLockable = info->dwMaxPagesAvailable; |
| 948 | info->dwTotalLinearSpace = status.dwTotalVirtual / info->wPageSize; |
| 949 | info->dwTotalUnlockedPages = info->dwTotalLinearSpace; |
| 950 | info->dwFreePages = info->dwMaxPagesAvailable; |
| 951 | info->dwTotalPages = info->dwTotalLinearSpace; |
| 952 | info->dwFreeLinearSpace = info->dwMaxPagesAvailable; |
| 953 | info->dwSwapFilePages = status.dwTotalPageFile / info->wPageSize; |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 954 | return TRUE; |
| 955 | } |
Alexandre Julliard | 2787be8 | 1995-05-22 18:23:01 +0000 | [diff] [blame] | 956 | |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 957 | /*********************************************************************** |
| 958 | * GetFreeMemInfo (KERNEL.316) |
| 959 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 960 | DWORD WINAPI GetFreeMemInfo16(void) |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 961 | { |
| 962 | MEMMANINFO info; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 963 | MemManInfo16( &info ); |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 964 | return MAKELONG( info.dwTotalLinearSpace, info.dwMaxPagesAvailable ); |
| 965 | } |
| 966 | |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 967 | /* |
| 968 | * Win32 Global heap functions (GlobalXXX). |
| 969 | * These functions included in Win32 for compatibility with 16 bit Windows |
| 970 | * Especially the moveable blocks and handles are oldish. |
| 971 | * But the ability to directly allocate memory with GPTR and LPTR is widely |
| 972 | * used. |
| 973 | * |
| 974 | * The handle stuff looks horrible, but it's implemented almost like Win95 |
| 975 | * does it. |
| 976 | * |
| 977 | */ |
| 978 | |
| 979 | #define MAGIC_GLOBAL_USED 0x5342 |
| 980 | #define GLOBAL_LOCK_MAX 0xFF |
Alexandre Julliard | 17216f5 | 1997-10-12 16:30:17 +0000 | [diff] [blame] | 981 | #define HANDLE_TO_INTERN(h) ((PGLOBAL32_INTERN)(((char *)(h))-2)) |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 982 | #define INTERN_TO_HANDLE(i) ((HGLOBAL) &((i)->Pointer)) |
| 983 | #define POINTER_TO_HANDLE(p) (*(((HGLOBAL *)(p))-1)) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 984 | #define ISHANDLE(h) (((DWORD)(h)&2)!=0) |
| 985 | #define ISPOINTER(h) (((DWORD)(h)&2)==0) |
| 986 | |
| 987 | typedef struct __GLOBAL32_INTERN |
| 988 | { |
| 989 | WORD Magic; |
| 990 | LPVOID Pointer WINE_PACKED; |
| 991 | BYTE Flags; |
| 992 | BYTE LockCount; |
| 993 | } GLOBAL32_INTERN, *PGLOBAL32_INTERN; |
| 994 | |
Noel Borthwick | 83579c8 | 1999-07-24 12:18:04 +0000 | [diff] [blame] | 995 | /*********************************************************************** |
| 996 | * GLOBAL_GetHeap |
| 997 | * |
| 998 | * Returns the appropriate heap to be used. If the object was created |
| 999 | * With GMEM_DDESHARE we allocated it on the system heap. |
| 1000 | */ |
| 1001 | static HANDLE GLOBAL_GetHeap( HGLOBAL hmem ) |
| 1002 | { |
| 1003 | HANDLE heap; |
| 1004 | |
| 1005 | TRACE("() hmem=%x\n", hmem); |
| 1006 | |
| 1007 | /* Get the appropriate heap to be used for this object */ |
| 1008 | if (ISPOINTER(hmem)) |
| 1009 | heap = GetProcessHeap(); |
| 1010 | else |
| 1011 | { |
| 1012 | PGLOBAL32_INTERN pintern; |
| 1013 | pintern=HANDLE_TO_INTERN(hmem); |
| 1014 | |
| 1015 | /* If it was DDESHARE it was created on the shared system heap */ |
| 1016 | pintern=HANDLE_TO_INTERN(hmem); |
| 1017 | heap = ( pintern->Flags & (GMEM_DDESHARE >> 8) ) |
| 1018 | ? SystemHeap : GetProcessHeap(); |
| 1019 | } |
| 1020 | |
| 1021 | return heap; |
| 1022 | } |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 1023 | |
| 1024 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1025 | * GlobalAlloc (KERNEL32.315) |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 1026 | * RETURNS |
| 1027 | * Handle: Success |
| 1028 | * NULL: Failure |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 1029 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1030 | HGLOBAL WINAPI GlobalAlloc( |
| 1031 | UINT flags, /* [in] Object allocation attributes */ |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 1032 | DWORD size /* [in] Number of bytes to allocate */ |
| 1033 | ) { |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1034 | PGLOBAL32_INTERN pintern; |
| 1035 | DWORD hpflags; |
| 1036 | LPVOID palloc; |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 1037 | |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1038 | if(flags&GMEM_ZEROINIT) |
| 1039 | hpflags=HEAP_ZERO_MEMORY; |
| 1040 | else |
| 1041 | hpflags=0; |
| 1042 | |
Noel Borthwick | 83579c8 | 1999-07-24 12:18:04 +0000 | [diff] [blame] | 1043 | TRACE("() flags=%04x\n", flags ); |
| 1044 | |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1045 | if((flags & GMEM_MOVEABLE)==0) /* POINTER */ |
| 1046 | { |
| 1047 | palloc=HeapAlloc(GetProcessHeap(), hpflags, size); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1048 | return (HGLOBAL) palloc; |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1049 | } |
| 1050 | else /* HANDLE */ |
| 1051 | { |
Noel Borthwick | 83579c8 | 1999-07-24 12:18:04 +0000 | [diff] [blame] | 1052 | HANDLE heap; |
| 1053 | |
| 1054 | /* If DDESHARE is set, create on the shared system heap */ |
| 1055 | heap = (flags & GMEM_DDESHARE) ? SystemHeap : GetProcessHeap(); |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 1056 | |
Noel Borthwick | 83579c8 | 1999-07-24 12:18:04 +0000 | [diff] [blame] | 1057 | /* HeapLock(heap); */ |
| 1058 | |
| 1059 | pintern=HeapAlloc(heap, 0, sizeof(GLOBAL32_INTERN)); |
Eric Pouech | 3bcfb90 | 2000-06-24 12:51:24 +0000 | [diff] [blame] | 1060 | if (!pintern) return NULL; |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1061 | if(size) |
| 1062 | { |
Eric Pouech | 3bcfb90 | 2000-06-24 12:51:24 +0000 | [diff] [blame] | 1063 | if (!(palloc=HeapAlloc(heap, hpflags, size+sizeof(HGLOBAL)))) { |
| 1064 | HeapFree(heap, 0, pintern); |
| 1065 | return NULL; |
| 1066 | } |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1067 | *(HGLOBAL *)palloc=INTERN_TO_HANDLE(pintern); |
Patrik Stridvall | a9a671d | 1999-04-25 19:01:52 +0000 | [diff] [blame] | 1068 | pintern->Pointer=(char *) palloc+sizeof(HGLOBAL); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1069 | } |
| 1070 | else |
| 1071 | pintern->Pointer=NULL; |
| 1072 | pintern->Magic=MAGIC_GLOBAL_USED; |
| 1073 | pintern->Flags=flags>>8; |
| 1074 | pintern->LockCount=0; |
| 1075 | |
Noel Borthwick | 83579c8 | 1999-07-24 12:18:04 +0000 | [diff] [blame] | 1076 | /* HeapUnlock(heap); */ |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1077 | |
| 1078 | return INTERN_TO_HANDLE(pintern); |
| 1079 | } |
| 1080 | } |
| 1081 | |
| 1082 | |
| 1083 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1084 | * GlobalLock (KERNEL32.326) |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 1085 | * RETURNS |
| 1086 | * Pointer to first byte of block |
| 1087 | * NULL: Failure |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1088 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1089 | LPVOID WINAPI GlobalLock( |
| 1090 | HGLOBAL hmem /* [in] Handle of global memory object */ |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 1091 | ) { |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1092 | PGLOBAL32_INTERN pintern; |
| 1093 | LPVOID palloc; |
| 1094 | |
| 1095 | if(ISPOINTER(hmem)) |
| 1096 | return (LPVOID) hmem; |
| 1097 | |
| 1098 | /* HeapLock(GetProcessHeap()); */ |
| 1099 | |
| 1100 | pintern=HANDLE_TO_INTERN(hmem); |
| 1101 | if(pintern->Magic==MAGIC_GLOBAL_USED) |
| 1102 | { |
| 1103 | if(pintern->LockCount<GLOBAL_LOCK_MAX) |
| 1104 | pintern->LockCount++; |
| 1105 | palloc=pintern->Pointer; |
| 1106 | } |
| 1107 | else |
| 1108 | { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 1109 | WARN("invalid handle\n"); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1110 | palloc=(LPVOID) NULL; |
| 1111 | } |
| 1112 | /* HeapUnlock(GetProcessHeap()); */; |
| 1113 | return palloc; |
| 1114 | } |
| 1115 | |
| 1116 | |
| 1117 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1118 | * GlobalUnlock (KERNEL32.332) |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 1119 | * RETURNS |
| 1120 | * TRUE: Object is still locked |
| 1121 | * FALSE: Object is unlocked |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1122 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1123 | BOOL WINAPI GlobalUnlock( |
| 1124 | HGLOBAL hmem /* [in] Handle of global memory object */ |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 1125 | ) { |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1126 | PGLOBAL32_INTERN pintern; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1127 | BOOL locked; |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1128 | |
| 1129 | if(ISPOINTER(hmem)) |
| 1130 | return FALSE; |
| 1131 | |
| 1132 | /* HeapLock(GetProcessHeap()); */ |
| 1133 | pintern=HANDLE_TO_INTERN(hmem); |
| 1134 | |
| 1135 | if(pintern->Magic==MAGIC_GLOBAL_USED) |
| 1136 | { |
| 1137 | if((pintern->LockCount<GLOBAL_LOCK_MAX)&&(pintern->LockCount>0)) |
| 1138 | pintern->LockCount--; |
| 1139 | |
| 1140 | locked=(pintern->LockCount==0) ? FALSE : TRUE; |
| 1141 | } |
| 1142 | else |
| 1143 | { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 1144 | WARN("invalid handle\n"); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1145 | locked=FALSE; |
| 1146 | } |
| 1147 | /* HeapUnlock(GetProcessHeap()); */ |
| 1148 | return locked; |
| 1149 | } |
| 1150 | |
| 1151 | |
| 1152 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1153 | * GlobalHandle (KERNEL32.325) |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 1154 | * Returns the handle associated with the specified pointer. |
| 1155 | * |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 1156 | * RETURNS |
| 1157 | * Handle: Success |
| 1158 | * NULL: Failure |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1159 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1160 | HGLOBAL WINAPI GlobalHandle( |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 1161 | LPCVOID pmem /* [in] Pointer to global memory block */ |
| 1162 | ) { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1163 | HGLOBAL handle; |
Guy Albertelli | 9867997 | 2000-01-15 21:59:12 +0000 | [diff] [blame] | 1164 | HANDLE heap; |
Guy Albertelli | 4ef6413 | 2000-01-23 02:25:11 +0000 | [diff] [blame] | 1165 | PGLOBAL32_INTERN maybe_intern; |
| 1166 | LPCVOID test; |
Guy Albertelli | 9867997 | 2000-01-15 21:59:12 +0000 | [diff] [blame] | 1167 | |
| 1168 | if (!pmem) |
| 1169 | { |
Lawson Whitney | 969515d | 2000-10-02 22:27:37 +0000 | [diff] [blame] | 1170 | SetLastError( ERROR_INVALID_PARAMETER ); |
| 1171 | return 0; |
Guy Albertelli | 9867997 | 2000-01-15 21:59:12 +0000 | [diff] [blame] | 1172 | } |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 1173 | |
Lawson Whitney | 969515d | 2000-10-02 22:27:37 +0000 | [diff] [blame] | 1174 | __TRY |
| 1175 | { |
| 1176 | handle = 0; |
Guy Albertelli | 4ef6413 | 2000-01-23 02:25:11 +0000 | [diff] [blame] | 1177 | |
Lawson Whitney | 969515d | 2000-10-02 22:27:37 +0000 | [diff] [blame] | 1178 | /* note that if pmem is a pointer to a a block allocated by */ |
| 1179 | /* GlobalAlloc with GMEM_MOVEABLE then magic test in HeapValidate */ |
| 1180 | /* will fail. */ |
| 1181 | if (ISPOINTER(pmem)) { |
| 1182 | heap = GLOBAL_GetHeap( (HGLOBAL)pmem ); |
| 1183 | if (HeapValidate( heap, 0, pmem )) { |
| 1184 | handle = (HGLOBAL)pmem; /* valid fixed block */ |
| 1185 | break; |
| 1186 | } |
| 1187 | handle = POINTER_TO_HANDLE(pmem); |
| 1188 | } else |
| 1189 | handle = (HGLOBAL)pmem; |
| 1190 | |
| 1191 | /* Now test handle either passed in or retrieved from pointer */ |
| 1192 | heap = GLOBAL_GetHeap( handle ); |
| 1193 | maybe_intern = HANDLE_TO_INTERN( handle ); |
| 1194 | if (maybe_intern->Magic == MAGIC_GLOBAL_USED) { |
| 1195 | test = maybe_intern->Pointer; |
| 1196 | if (HeapValidate( heap, 0, ((HGLOBAL *)test)-1 ) && /* obj(-handle) valid arena? */ |
| 1197 | HeapValidate( heap, 0, maybe_intern )) /* intern valid arena? */ |
| 1198 | break; /* valid moveable block */ |
| 1199 | } |
| 1200 | handle = 0; |
| 1201 | SetLastError( ERROR_INVALID_HANDLE ); |
Alexandre Julliard | 17216f5 | 1997-10-12 16:30:17 +0000 | [diff] [blame] | 1202 | } |
Lawson Whitney | 969515d | 2000-10-02 22:27:37 +0000 | [diff] [blame] | 1203 | __EXCEPT(page_fault) |
| 1204 | { |
| 1205 | SetLastError( ERROR_INVALID_HANDLE ); |
| 1206 | return 0; |
| 1207 | } |
| 1208 | __ENDTRY |
Alexandre Julliard | 17216f5 | 1997-10-12 16:30:17 +0000 | [diff] [blame] | 1209 | |
Lawson Whitney | 969515d | 2000-10-02 22:27:37 +0000 | [diff] [blame] | 1210 | return handle; |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1211 | } |
| 1212 | |
| 1213 | |
| 1214 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1215 | * GlobalReAlloc (KERNEL32.328) |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 1216 | * RETURNS |
| 1217 | * Handle: Success |
| 1218 | * NULL: Failure |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1219 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1220 | HGLOBAL WINAPI GlobalReAlloc( |
| 1221 | HGLOBAL hmem, /* [in] Handle of global memory object */ |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 1222 | DWORD size, /* [in] New size of block */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1223 | UINT flags /* [in] How to reallocate object */ |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 1224 | ) { |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1225 | LPVOID palloc; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1226 | HGLOBAL hnew; |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1227 | PGLOBAL32_INTERN pintern; |
Noel Borthwick | 83579c8 | 1999-07-24 12:18:04 +0000 | [diff] [blame] | 1228 | HANDLE heap = GLOBAL_GetHeap( hmem ); |
Alexandre Julliard | d10ca9c | 1999-09-04 11:26:56 +0000 | [diff] [blame] | 1229 | DWORD heap_flags = (flags & GMEM_ZEROINIT) ? HEAP_ZERO_MEMORY : 0; |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1230 | |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 1231 | hnew = 0; |
Noel Borthwick | 83579c8 | 1999-07-24 12:18:04 +0000 | [diff] [blame] | 1232 | /* HeapLock(heap); */ |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1233 | if(flags & GMEM_MODIFY) /* modify flags */ |
| 1234 | { |
| 1235 | if( ISPOINTER(hmem) && (flags & GMEM_MOVEABLE)) |
| 1236 | { |
| 1237 | /* make a fixed block moveable |
| 1238 | * actually only NT is able to do this. But it's soo simple |
| 1239 | */ |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1240 | if (hmem == 0) |
| 1241 | { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 1242 | ERR("GlobalReAlloc32 with null handle!\n"); |
Alexandre Julliard | 0ad42fa | 1999-01-31 15:04:42 +0000 | [diff] [blame] | 1243 | SetLastError( ERROR_NOACCESS ); |
Alexandre Julliard | a0d7731 | 1998-09-13 16:32:00 +0000 | [diff] [blame] | 1244 | return 0; |
| 1245 | } |
Noel Borthwick | 83579c8 | 1999-07-24 12:18:04 +0000 | [diff] [blame] | 1246 | size=HeapSize(heap, 0, (LPVOID) hmem); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1247 | hnew=GlobalAlloc( flags, size); |
| 1248 | palloc=GlobalLock(hnew); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1249 | memcpy(palloc, (LPVOID) hmem, size); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1250 | GlobalUnlock(hnew); |
| 1251 | GlobalFree(hmem); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1252 | } |
| 1253 | else if( ISPOINTER(hmem) &&(flags & GMEM_DISCARDABLE)) |
| 1254 | { |
| 1255 | /* change the flags to make our block "discardable" */ |
| 1256 | pintern=HANDLE_TO_INTERN(hmem); |
| 1257 | pintern->Flags = pintern->Flags | (GMEM_DISCARDABLE >> 8); |
| 1258 | hnew=hmem; |
| 1259 | } |
| 1260 | else |
| 1261 | { |
| 1262 | SetLastError(ERROR_INVALID_PARAMETER); |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 1263 | hnew = 0; |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1264 | } |
| 1265 | } |
| 1266 | else |
| 1267 | { |
| 1268 | if(ISPOINTER(hmem)) |
| 1269 | { |
| 1270 | /* reallocate fixed memory */ |
Alexandre Julliard | d10ca9c | 1999-09-04 11:26:56 +0000 | [diff] [blame] | 1271 | hnew=(HGLOBAL)HeapReAlloc(heap, heap_flags, (LPVOID) hmem, size); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1272 | } |
| 1273 | else |
| 1274 | { |
| 1275 | /* reallocate a moveable block */ |
| 1276 | pintern=HANDLE_TO_INTERN(hmem); |
Ulrich Weigand | 2e7008c | 2000-10-19 20:24:25 +0000 | [diff] [blame] | 1277 | |
| 1278 | #if 0 |
| 1279 | /* Apparently Windows doesn't care whether the handle is locked at this point */ |
| 1280 | /* See also the same comment in GlobalFree() */ |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 1281 | if(pintern->LockCount>1) { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 1282 | ERR("handle 0x%08lx is still locked, cannot realloc!\n",(DWORD)hmem); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1283 | SetLastError(ERROR_INVALID_HANDLE); |
Ulrich Weigand | 2e7008c | 2000-10-19 20:24:25 +0000 | [diff] [blame] | 1284 | } else |
| 1285 | #endif |
| 1286 | if(size!=0) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1287 | { |
| 1288 | hnew=hmem; |
| 1289 | if(pintern->Pointer) |
| 1290 | { |
Huw D M Davies | c43fdb7 | 2000-04-13 15:57:06 +0000 | [diff] [blame] | 1291 | if((palloc = HeapReAlloc(heap, heap_flags, |
| 1292 | (char *) pintern->Pointer-sizeof(HGLOBAL), |
| 1293 | size+sizeof(HGLOBAL))) == NULL) |
| 1294 | return 0; /* Block still valid */ |
Patrik Stridvall | a9a671d | 1999-04-25 19:01:52 +0000 | [diff] [blame] | 1295 | pintern->Pointer=(char *) palloc+sizeof(HGLOBAL); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1296 | } |
| 1297 | else |
| 1298 | { |
Huw D M Davies | c43fdb7 | 2000-04-13 15:57:06 +0000 | [diff] [blame] | 1299 | if((palloc=HeapAlloc(heap, heap_flags, size+sizeof(HGLOBAL))) |
| 1300 | == NULL) |
| 1301 | return 0; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1302 | *(HGLOBAL *)palloc=hmem; |
Patrik Stridvall | a9a671d | 1999-04-25 19:01:52 +0000 | [diff] [blame] | 1303 | pintern->Pointer=(char *) palloc+sizeof(HGLOBAL); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1304 | } |
| 1305 | } |
| 1306 | else |
| 1307 | { |
| 1308 | if(pintern->Pointer) |
| 1309 | { |
Noel Borthwick | 83579c8 | 1999-07-24 12:18:04 +0000 | [diff] [blame] | 1310 | HeapFree(heap, 0, (char *) pintern->Pointer-sizeof(HGLOBAL)); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1311 | pintern->Pointer=NULL; |
| 1312 | } |
| 1313 | } |
| 1314 | } |
| 1315 | } |
Noel Borthwick | 83579c8 | 1999-07-24 12:18:04 +0000 | [diff] [blame] | 1316 | /* HeapUnlock(heap); */ |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1317 | return hnew; |
| 1318 | } |
| 1319 | |
| 1320 | |
| 1321 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1322 | * GlobalFree (KERNEL32.322) |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 1323 | * RETURNS |
| 1324 | * NULL: Success |
| 1325 | * Handle: Failure |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1326 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1327 | HGLOBAL WINAPI GlobalFree( |
| 1328 | HGLOBAL hmem /* [in] Handle of global memory object */ |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 1329 | ) { |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1330 | PGLOBAL32_INTERN pintern; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1331 | HGLOBAL hreturned = 0; |
Noel Borthwick | 83579c8 | 1999-07-24 12:18:04 +0000 | [diff] [blame] | 1332 | HANDLE heap = GLOBAL_GetHeap( hmem ); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1333 | |
| 1334 | if(ISPOINTER(hmem)) /* POINTER */ |
| 1335 | { |
Noel Borthwick | 83579c8 | 1999-07-24 12:18:04 +0000 | [diff] [blame] | 1336 | if(!HeapFree(heap, 0, (LPVOID) hmem)) hmem = 0; |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1337 | } |
| 1338 | else /* HANDLE */ |
| 1339 | { |
Noel Borthwick | 83579c8 | 1999-07-24 12:18:04 +0000 | [diff] [blame] | 1340 | /* HeapLock(heap); */ |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1341 | pintern=HANDLE_TO_INTERN(hmem); |
| 1342 | |
| 1343 | if(pintern->Magic==MAGIC_GLOBAL_USED) |
| 1344 | { |
Guy Albertelli | 4ef6413 | 2000-01-23 02:25:11 +0000 | [diff] [blame] | 1345 | |
| 1346 | /* WIN98 does not make this test. That is you can free a */ |
| 1347 | /* block you have not unlocked. Go figure!! */ |
| 1348 | /* if(pintern->LockCount!=0) */ |
| 1349 | /* SetLastError(ERROR_INVALID_HANDLE); */ |
| 1350 | |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1351 | if(pintern->Pointer) |
Noel Borthwick | 83579c8 | 1999-07-24 12:18:04 +0000 | [diff] [blame] | 1352 | if(!HeapFree(heap, 0, |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1353 | (char *)(pintern->Pointer)-sizeof(HGLOBAL))) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1354 | hreturned=hmem; |
Noel Borthwick | 83579c8 | 1999-07-24 12:18:04 +0000 | [diff] [blame] | 1355 | if(!HeapFree(heap, 0, pintern)) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1356 | hreturned=hmem; |
| 1357 | } |
Noel Borthwick | 83579c8 | 1999-07-24 12:18:04 +0000 | [diff] [blame] | 1358 | /* HeapUnlock(heap); */ |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1359 | } |
| 1360 | return hreturned; |
| 1361 | } |
| 1362 | |
| 1363 | |
| 1364 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1365 | * GlobalSize (KERNEL32.329) |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 1366 | * RETURNS |
| 1367 | * Size in bytes of the global memory object |
| 1368 | * 0: Failure |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1369 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1370 | DWORD WINAPI GlobalSize( |
| 1371 | HGLOBAL hmem /* [in] Handle of global memory object */ |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 1372 | ) { |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1373 | DWORD retval; |
| 1374 | PGLOBAL32_INTERN pintern; |
Noel Borthwick | 83579c8 | 1999-07-24 12:18:04 +0000 | [diff] [blame] | 1375 | HANDLE heap = GLOBAL_GetHeap( hmem ); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1376 | |
| 1377 | if(ISPOINTER(hmem)) |
| 1378 | { |
Noel Borthwick | 83579c8 | 1999-07-24 12:18:04 +0000 | [diff] [blame] | 1379 | retval=HeapSize(heap, 0, (LPVOID) hmem); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1380 | } |
| 1381 | else |
| 1382 | { |
Noel Borthwick | 83579c8 | 1999-07-24 12:18:04 +0000 | [diff] [blame] | 1383 | /* HeapLock(heap); */ |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1384 | pintern=HANDLE_TO_INTERN(hmem); |
| 1385 | |
| 1386 | if(pintern->Magic==MAGIC_GLOBAL_USED) |
| 1387 | { |
Guy Albertelli | 3db8e19 | 1999-02-14 17:38:24 +0000 | [diff] [blame] | 1388 | if (!pintern->Pointer) /* handle case of GlobalAlloc( ??,0) */ |
| 1389 | return 0; |
Noel Borthwick | 83579c8 | 1999-07-24 12:18:04 +0000 | [diff] [blame] | 1390 | retval=HeapSize(heap, 0, |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1391 | (char *)(pintern->Pointer)-sizeof(HGLOBAL))-4; |
Rein Klazes | eaec1ee | 1999-07-11 13:50:24 +0000 | [diff] [blame] | 1392 | if (retval == 0xffffffff-4) retval = 0; |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1393 | } |
| 1394 | else |
| 1395 | { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 1396 | WARN("invalid handle\n"); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1397 | retval=0; |
| 1398 | } |
Noel Borthwick | 83579c8 | 1999-07-24 12:18:04 +0000 | [diff] [blame] | 1399 | /* HeapUnlock(heap); */ |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1400 | } |
Guy Albertelli | 3db8e19 | 1999-02-14 17:38:24 +0000 | [diff] [blame] | 1401 | /* HeapSize returns 0xffffffff on failure */ |
| 1402 | if (retval == 0xffffffff) retval = 0; |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1403 | return retval; |
| 1404 | } |
| 1405 | |
| 1406 | |
| 1407 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1408 | * GlobalWire (KERNEL32.333) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1409 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1410 | LPVOID WINAPI GlobalWire(HGLOBAL hmem) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1411 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1412 | return GlobalLock( hmem ); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1413 | } |
| 1414 | |
| 1415 | |
| 1416 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1417 | * GlobalUnWire (KERNEL32.330) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1418 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1419 | BOOL WINAPI GlobalUnWire(HGLOBAL hmem) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1420 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1421 | return GlobalUnlock( hmem); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1422 | } |
| 1423 | |
| 1424 | |
| 1425 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1426 | * GlobalFix (KERNEL32.320) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1427 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1428 | VOID WINAPI GlobalFix(HGLOBAL hmem) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1429 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1430 | GlobalLock( hmem ); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1431 | } |
| 1432 | |
| 1433 | |
| 1434 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1435 | * GlobalUnfix (KERNEL32.331) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1436 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1437 | VOID WINAPI GlobalUnfix(HGLOBAL hmem) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1438 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1439 | GlobalUnlock( hmem); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1440 | } |
| 1441 | |
| 1442 | |
| 1443 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1444 | * GlobalFlags (KERNEL32.321) |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 1445 | * Returns information about the specified global memory object |
| 1446 | * |
| 1447 | * NOTES |
| 1448 | * Should this return GMEM_INVALID_HANDLE on invalid handle? |
| 1449 | * |
| 1450 | * RETURNS |
| 1451 | * Value specifying allocation flags and lock count |
| 1452 | * GMEM_INVALID_HANDLE: Failure |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1453 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1454 | UINT WINAPI GlobalFlags( |
| 1455 | HGLOBAL hmem /* [in] Handle to global memory object */ |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 1456 | ) { |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1457 | DWORD retval; |
| 1458 | PGLOBAL32_INTERN pintern; |
| 1459 | |
| 1460 | if(ISPOINTER(hmem)) |
| 1461 | { |
| 1462 | retval=0; |
| 1463 | } |
| 1464 | else |
| 1465 | { |
| 1466 | /* HeapLock(GetProcessHeap()); */ |
| 1467 | pintern=HANDLE_TO_INTERN(hmem); |
| 1468 | if(pintern->Magic==MAGIC_GLOBAL_USED) |
| 1469 | { |
| 1470 | retval=pintern->LockCount + (pintern->Flags<<8); |
| 1471 | if(pintern->Pointer==0) |
| 1472 | retval|= GMEM_DISCARDED; |
| 1473 | } |
| 1474 | else |
| 1475 | { |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 1476 | WARN("Invalid handle: %04x", hmem); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1477 | retval=0; |
| 1478 | } |
| 1479 | /* HeapUnlock(GetProcessHeap()); */ |
| 1480 | } |
| 1481 | return retval; |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 1482 | } |
| 1483 | |
| 1484 | |
| 1485 | /*********************************************************************** |
Patrik Stridvall | 2d6457c | 2000-03-28 20:22:59 +0000 | [diff] [blame] | 1486 | * GlobalCompact (KERNEL32.316) |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 1487 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1488 | DWORD WINAPI GlobalCompact( DWORD minfree ) |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 1489 | { |
| 1490 | return 0; /* GlobalCompact does nothing in Win32 */ |
| 1491 | } |
| 1492 | |
| 1493 | |
| 1494 | /*********************************************************************** |
Alexandre Julliard | 0e270f4 | 1996-08-24 18:26:35 +0000 | [diff] [blame] | 1495 | * GlobalMemoryStatus (KERNEL32.327) |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 1496 | * RETURNS |
| 1497 | * None |
Alexandre Julliard | 0e270f4 | 1996-08-24 18:26:35 +0000 | [diff] [blame] | 1498 | */ |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 1499 | VOID WINAPI GlobalMemoryStatus( |
| 1500 | LPMEMORYSTATUS lpmem |
| 1501 | ) { |
Marcus Meissner | 6189c19 | 2000-03-04 19:19:15 +0000 | [diff] [blame] | 1502 | static MEMORYSTATUS cached_memstatus; |
| 1503 | static int cache_lastchecked = 0; |
Francois Gouget | ea5924c | 2000-10-28 00:34:29 +0000 | [diff] [blame] | 1504 | SYSTEM_INFO si; |
Patrik Stridvall | 7e9913f | 2000-03-08 18:25:22 +0000 | [diff] [blame] | 1505 | #ifdef linux |
Marcus Meissner | 6189c19 | 2000-03-04 19:19:15 +0000 | [diff] [blame] | 1506 | FILE *f; |
Patrik Stridvall | 7e9913f | 2000-03-08 18:25:22 +0000 | [diff] [blame] | 1507 | #endif |
Marcus Meissner | 6189c19 | 2000-03-04 19:19:15 +0000 | [diff] [blame] | 1508 | |
| 1509 | if (time(NULL)==cache_lastchecked) { |
| 1510 | memcpy(lpmem,&cached_memstatus,sizeof(MEMORYSTATUS)); |
| 1511 | return; |
| 1512 | } |
| 1513 | cache_lastchecked = time(NULL); |
| 1514 | |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 1515 | #ifdef linux |
Marcus Meissner | 6189c19 | 2000-03-04 19:19:15 +0000 | [diff] [blame] | 1516 | f = fopen( "/proc/meminfo", "r" ); |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 1517 | if (f) |
| 1518 | { |
| 1519 | char buffer[256]; |
Stephen Crowley | 59c4a32 | 1998-11-24 20:41:02 +0000 | [diff] [blame] | 1520 | int total, used, free, shared, buffers, cached; |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 1521 | |
Stephen Crowley | 59c4a32 | 1998-11-24 20:41:02 +0000 | [diff] [blame] | 1522 | lpmem->dwLength = sizeof(MEMORYSTATUS); |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 1523 | lpmem->dwTotalPhys = lpmem->dwAvailPhys = 0; |
| 1524 | lpmem->dwTotalPageFile = lpmem->dwAvailPageFile = 0; |
| 1525 | while (fgets( buffer, sizeof(buffer), f )) |
| 1526 | { |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1527 | /* old style /proc/meminfo ... */ |
Stephen Crowley | 59c4a32 | 1998-11-24 20:41:02 +0000 | [diff] [blame] | 1528 | if (sscanf( buffer, "Mem: %d %d %d %d %d %d", &total, &used, &free, &shared, &buffers, &cached )) |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 1529 | { |
| 1530 | lpmem->dwTotalPhys += total; |
Stephen Crowley | 59c4a32 | 1998-11-24 20:41:02 +0000 | [diff] [blame] | 1531 | lpmem->dwAvailPhys += free + buffers + cached; |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 1532 | } |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1533 | if (sscanf( buffer, "Swap: %d %d %d", &total, &used, &free )) |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 1534 | { |
| 1535 | lpmem->dwTotalPageFile += total; |
| 1536 | lpmem->dwAvailPageFile += free; |
| 1537 | } |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1538 | |
| 1539 | /* new style /proc/meminfo ... */ |
| 1540 | if (sscanf(buffer, "MemTotal: %d", &total)) |
| 1541 | lpmem->dwTotalPhys = total*1024; |
| 1542 | if (sscanf(buffer, "MemFree: %d", &free)) |
| 1543 | lpmem->dwAvailPhys = free*1024; |
| 1544 | if (sscanf(buffer, "SwapTotal: %d", &total)) |
| 1545 | lpmem->dwTotalPageFile = total*1024; |
| 1546 | if (sscanf(buffer, "SwapFree: %d", &free)) |
| 1547 | lpmem->dwAvailPageFile = free*1024; |
Stephen Crowley | 59c4a32 | 1998-11-24 20:41:02 +0000 | [diff] [blame] | 1548 | if (sscanf(buffer, "Buffers: %d", &buffers)) |
| 1549 | lpmem->dwAvailPhys += buffers*1024; |
| 1550 | if (sscanf(buffer, "Cached: %d", &cached)) |
| 1551 | lpmem->dwAvailPhys += cached*1024; |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 1552 | } |
| 1553 | fclose( f ); |
| 1554 | |
| 1555 | if (lpmem->dwTotalPhys) |
| 1556 | { |
Francois Gouget | ea5924c | 2000-10-28 00:34:29 +0000 | [diff] [blame] | 1557 | DWORD TotalPhysical = lpmem->dwTotalPhys+lpmem->dwTotalPageFile; |
| 1558 | DWORD AvailPhysical = lpmem->dwAvailPhys+lpmem->dwAvailPageFile; |
| 1559 | lpmem->dwMemoryLoad = (TotalPhysical-AvailPhysical) |
| 1560 | / (TotalPhysical / 100); |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 1561 | } |
Marcus Meissner | fddbcf3 | 2000-03-07 12:24:58 +0000 | [diff] [blame] | 1562 | } else |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 1563 | #endif |
Marcus Meissner | fddbcf3 | 2000-03-07 12:24:58 +0000 | [diff] [blame] | 1564 | { |
| 1565 | /* FIXME: should do something for other systems */ |
| 1566 | lpmem->dwMemoryLoad = 0; |
| 1567 | lpmem->dwTotalPhys = 16*1024*1024; |
| 1568 | lpmem->dwAvailPhys = 16*1024*1024; |
| 1569 | lpmem->dwTotalPageFile = 16*1024*1024; |
| 1570 | lpmem->dwAvailPageFile = 16*1024*1024; |
Marcus Meissner | fddbcf3 | 2000-03-07 12:24:58 +0000 | [diff] [blame] | 1571 | } |
Francois Gouget | ea5924c | 2000-10-28 00:34:29 +0000 | [diff] [blame] | 1572 | GetSystemInfo(&si); |
| 1573 | lpmem->dwTotalVirtual = si.lpMaximumApplicationAddress-si.lpMinimumApplicationAddress; |
| 1574 | /* FIXME: we should track down all the already allocated VM pages and substract them, for now arbitrarily remove 64KB so that it matches NT */ |
| 1575 | lpmem->dwAvailVirtual = lpmem->dwTotalVirtual-64*1024; |
Marcus Meissner | fddbcf3 | 2000-03-07 12:24:58 +0000 | [diff] [blame] | 1576 | memcpy(&cached_memstatus,lpmem,sizeof(MEMORYSTATUS)); |
Alexandre Julliard | 0e270f4 | 1996-08-24 18:26:35 +0000 | [diff] [blame] | 1577 | } |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1578 | |
Alexandre Julliard | 4220b29 | 1999-07-11 17:20:01 +0000 | [diff] [blame] | 1579 | /*********************************************************************** |
| 1580 | * A20Proc16 (KERNEL.165) |
| 1581 | */ |
| 1582 | void WINAPI A20Proc16( WORD unused ) |
| 1583 | { |
| 1584 | /* this is also a NOP in Windows */ |
| 1585 | } |
| 1586 | |
| 1587 | /*********************************************************************** |
| 1588 | * LimitEMSPages16 (KERNEL.156) |
| 1589 | */ |
| 1590 | DWORD WINAPI LimitEMSPages16( DWORD unused ) |
| 1591 | { |
| 1592 | return 0; |
| 1593 | } |