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