Extract binary resources to files, to fit the standard.
[wine/multimedia.git] / memory / global.c
blob7d2a95e15ea352b5fe2651ec81d3f54fdaa7f066
1 /*
2 * Global heap functions
4 * Copyright 1995 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 /* 0xffff sometimes seems to mean: CURRENT_DS */
22 #include "config.h"
23 #include "wine/port.h"
25 #include <sys/types.h>
26 #include <stdlib.h>
27 #include <time.h>
28 #include <stdio.h>
29 #ifdef HAVE_UNISTD_H
30 # include <unistd.h>
31 #endif
32 #include <string.h>
33 #ifdef HAVE_SYS_PARAM_H
34 #include <sys/param.h>
35 #endif
36 #ifdef HAVE_SYS_SYSCTL_H
37 #include <sys/sysctl.h>
38 #endif
40 #include "wine/winbase16.h"
41 #include "ntstatus.h"
42 #include "global.h"
43 #include "toolhelp.h"
44 #include "selectors.h"
45 #include "miscemu.h"
46 #include "stackframe.h"
47 #include "wine/debug.h"
48 #include "winerror.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(global);
52 /* Global arena block */
53 typedef struct
55 DWORD base; /* Base address (0 if discarded) */
56 DWORD size; /* Size in bytes (0 indicates a free block) */
57 HGLOBAL16 handle; /* Handle for this block */
58 HGLOBAL16 hOwner; /* Owner of this block */
59 BYTE lockCount; /* Count of GlobalFix() calls */
60 BYTE pageLockCount; /* Count of GlobalPageLock() calls */
61 BYTE flags; /* Allocation flags */
62 BYTE selCount; /* Number of selectors allocated for this block */
63 } GLOBALARENA;
65 /* Arena array */
66 /*static*/ GLOBALARENA *pGlobalArena = NULL;
67 /*static*/ int globalArenaSize = 0;
69 #define VALID_HANDLE(handle) (((handle)>>__AHSHIFT)<globalArenaSize)
70 #define GET_ARENA_PTR(handle) (pGlobalArena + ((handle) >> __AHSHIFT))
73 /***********************************************************************
74 * GlobalLock16 (KERNEL32.25)
76 * This is the GlobalLock16() function used by 32-bit code.
78 * RETURNS
79 * Pointer to first byte of memory block
80 * NULL: Failure
82 LPVOID WINAPI GlobalLock16(
83 HGLOBAL16 handle /* [in] Handle of global memory object */
84 ) {
85 if (!handle) return 0;
86 if (!VALID_HANDLE(handle))
87 return 0;
88 GET_ARENA_PTR(handle)->lockCount++;
89 return (LPVOID)GET_ARENA_PTR(handle)->base;
93 /***********************************************************************
94 * FarGetOwner (KERNEL.404)
96 HANDLE16 WINAPI FarGetOwner16( HGLOBAL16 handle )
98 if (!VALID_HANDLE(handle)) {
99 WARN("Invalid handle 0x%04x passed to FarGetOwner!\n",handle);
100 return 0;
102 return GET_ARENA_PTR(handle)->hOwner;