| /* |
| * Global heap functions |
| * |
| * Copyright 1995 Alexandre Julliard |
| * |
| * This library is free software; you can redistribute it and/or |
| * modify it under the terms of the GNU Lesser General Public |
| * License as published by the Free Software Foundation; either |
| * version 2.1 of the License, or (at your option) any later version. |
| * |
| * This library is distributed in the hope that it will be useful, |
| * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| * Lesser General Public License for more details. |
| * |
| * You should have received a copy of the GNU Lesser General Public |
| * License along with this library; if not, write to the Free Software |
| * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| */ |
| /* 0xffff sometimes seems to mean: CURRENT_DS */ |
| |
| #include "config.h" |
| #include "wine/port.h" |
| |
| #include <sys/types.h> |
| #include <stdlib.h> |
| #include <time.h> |
| #include <stdio.h> |
| #ifdef HAVE_UNISTD_H |
| # include <unistd.h> |
| #endif |
| #include <string.h> |
| #ifdef HAVE_SYS_PARAM_H |
| #include <sys/param.h> |
| #endif |
| #ifdef HAVE_SYS_SYSCTL_H |
| #include <sys/sysctl.h> |
| #endif |
| |
| #include "wine/winbase16.h" |
| #include "ntstatus.h" |
| #include "global.h" |
| #include "toolhelp.h" |
| #include "selectors.h" |
| #include "miscemu.h" |
| #include "stackframe.h" |
| #include "wine/debug.h" |
| #include "winerror.h" |
| |
| WINE_DEFAULT_DEBUG_CHANNEL(global); |
| |
| /* Global arena block */ |
| typedef struct |
| { |
| DWORD base; /* Base address (0 if discarded) */ |
| DWORD size; /* Size in bytes (0 indicates a free block) */ |
| HGLOBAL16 handle; /* Handle for this block */ |
| HGLOBAL16 hOwner; /* Owner of this block */ |
| BYTE lockCount; /* Count of GlobalFix() calls */ |
| BYTE pageLockCount; /* Count of GlobalPageLock() calls */ |
| BYTE flags; /* Allocation flags */ |
| BYTE selCount; /* Number of selectors allocated for this block */ |
| } GLOBALARENA; |
| |
| /* Arena array */ |
| /*static*/ GLOBALARENA *pGlobalArena = NULL; |
| /*static*/ int globalArenaSize = 0; |
| |
| #define VALID_HANDLE(handle) (((handle)>>__AHSHIFT)<globalArenaSize) |
| #define GET_ARENA_PTR(handle) (pGlobalArena + ((handle) >> __AHSHIFT)) |
| |
| |
| /*********************************************************************** |
| * GlobalLock16 (KERNEL32.25) |
| * |
| * This is the GlobalLock16() function used by 32-bit code. |
| * |
| * RETURNS |
| * Pointer to first byte of memory block |
| * NULL: Failure |
| */ |
| LPVOID WINAPI GlobalLock16( |
| HGLOBAL16 handle /* [in] Handle of global memory object */ |
| ) { |
| if (!handle) return 0; |
| if (!VALID_HANDLE(handle)) |
| return 0; |
| GET_ARENA_PTR(handle)->lockCount++; |
| return (LPVOID)GET_ARENA_PTR(handle)->base; |
| } |
| |
| |
| /*********************************************************************** |
| * FarGetOwner (KERNEL.404) |
| */ |
| HANDLE16 WINAPI FarGetOwner16( HGLOBAL16 handle ) |
| { |
| if (!VALID_HANDLE(handle)) { |
| WARN("Invalid handle 0x%04x passed to FarGetOwner!\n",handle); |
| return 0; |
| } |
| return GET_ARENA_PTR(handle)->hOwner; |
| } |