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