Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-winehq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-winehq
Commits
1ff9e763
Commit
1ff9e763
authored
Mar 31, 2022
by
Rémi Bernon
Committed by
Alexandre Julliard
Mar 31, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kernel32: Synchronize the HLOCAL helpers with kernelbase.
Signed-off-by:
Rémi Bernon
<
rbernon@codeweavers.com
>
Signed-off-by:
Alexandre Julliard
<
julliard@winehq.org
>
parent
82bab836
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
52 deletions
+53
-52
heap.c
dlls/kernel32/heap.c
+53
-52
No files found.
dlls/kernel32/heap.c
View file @
1ff9e763
...
...
@@ -140,42 +140,45 @@ BOOL WINAPI HeapDestroy( HANDLE heap /* [in] Handle of heap */ )
}
/*
* Win32 Global heap functions (GlobalXXX).
* These functions included in Win32 for compatibility with 16 bit Windows
* Especially the moveable blocks and handles are oldish.
* But the ability to directly allocate memory with GPTR and LPTR is widely
* used.
*
* The handle stuff looks horrible, but it's implemented almost like Win95
* does it.
*
*/
/***********************************************************************
* Global/local heap functions, keep in sync with kernelbase/memory.c
***********************************************************************/
#include "pshpack1.h"
struct
mem_entry
{
WORD
magic
;
void
*
ptr
;
BYTE
flags
;
BYTE
lock
;
};
#define MAGIC_GLOBAL_USED 0x5342
#define HANDLE_TO_INTERN(h) ((PGLOBAL32_INTERN)(((char *)(h))-2))
#define INTERN_TO_HANDLE(i) (&((i)->Pointer))
#define POINTER_TO_HANDLE(p) (*(((const HGLOBAL *)(p))-2))
#define ISHANDLE(h) (((ULONG_PTR)(h)&2)!=0)
#define ISPOINTER(h) (((ULONG_PTR)(h)&2)==0)
/* align the storage needed for the HGLOBAL on an 8byte boundary thus
* GlobalAlloc/GlobalReAlloc'ing with GMEM_MOVEABLE of memory with
* size = 8*k, where k=1,2,3,... alloc's exactly the given size.
#include "poppack.h"
#define MAGIC_LOCAL_USED 0x5342
#define POINTER_TO_HANDLE( p ) (*(((const HGLOBAL *)( p )) - 2))
/* align the storage needed for the HLOCAL on an 8-byte boundary thus
* LocalAlloc/LocalReAlloc'ing with LMEM_MOVEABLE of memory with
* size = 8*k, where k=1,2,3,... allocs exactly the given size.
* The Minolta DiMAGE Image Viewer heavily relies on this, corrupting
* the output jpeg's > 1 MB if not */
#define H
GLOBAL_STORAGE (sizeof(HGLOBAL)*
2)
#define H
LOCAL_STORAGE (sizeof(HLOCAL) *
2)
#include "pshpack1.h"
static
inline
struct
mem_entry
*
unsafe_mem_from_HLOCAL
(
HLOCAL
handle
)
{
struct
mem_entry
*
mem
=
CONTAINING_RECORD
(
handle
,
struct
mem_entry
,
ptr
);
if
(
!
((
ULONG_PTR
)
handle
&
2
))
return
NULL
;
if
(
mem
->
magic
!=
MAGIC_LOCAL_USED
)
return
NULL
;
return
mem
;
}
typedef
struct
__GLOBAL32_INTERN
static
inline
void
*
unsafe_ptr_from_HLOCAL
(
HLOCAL
handle
)
{
WORD
Magic
;
LPVOID
Pointer
;
BYTE
Flags
;
BYTE
LockCount
;
}
GLOBAL32_INTERN
,
*
PGLOBAL32_INTERN
;
if
((
ULONG_PTR
)
handle
&
2
)
return
NULL
;
return
handle
;
}
#include "poppack.h"
/***********************************************************************
* GlobalLock (KERNEL32.@)
...
...
@@ -217,7 +220,7 @@ void *WINAPI GlobalLock( HGLOBAL handle )
*/
BOOL
WINAPI
GlobalUnlock
(
HGLOBAL
handle
)
{
if
(
ISPOINTER
(
handle
))
return
TRUE
;
if
(
unsafe_ptr_from_HLOCAL
(
handle
))
return
TRUE
;
return
LocalUnlock
(
handle
);
}
...
...
@@ -233,7 +236,7 @@ BOOL WINAPI GlobalUnlock( HGLOBAL handle )
*/
HGLOBAL
WINAPI
GlobalHandle
(
const
void
*
ptr
)
{
PGLOBAL32_INTERN
mem
;
struct
mem_entry
*
mem
;
HGLOBAL
handle
;
LPCVOID
test
;
...
...
@@ -253,7 +256,7 @@ HGLOBAL WINAPI GlobalHandle( const void *ptr )
/* note that if ptr is a pointer to a block allocated by */
/* GlobalAlloc with GMEM_MOVEABLE then magic test in HeapValidate */
/* will fail. */
if
(
ISPOINTER
(
ptr
))
if
(
(
ptr
=
unsafe_ptr_from_HLOCAL
(
(
HLOCAL
)
ptr
)
))
{
if
(
HeapValidate
(
GetProcessHeap
(),
HEAP_NO_SERIALIZE
,
ptr
))
{
...
...
@@ -265,11 +268,10 @@ HGLOBAL WINAPI GlobalHandle( const void *ptr )
else
handle
=
(
HGLOBAL
)
ptr
;
/* Now test handle either passed in or retrieved from pointer */
mem
=
HANDLE_TO_INTERN
(
handle
);
if
(
mem
->
Magic
==
MAGIC_GLOBAL_USED
)
if
((
mem
=
unsafe_mem_from_HLOCAL
(
handle
)))
{
test
=
mem
->
Pointe
r
;
if
(
HeapValidate
(
GetProcessHeap
(),
HEAP_NO_SERIALIZE
,
(
const
char
*
)
test
-
H
GLOB
AL_STORAGE
)
&&
/* obj(-handle) valid arena? */
test
=
mem
->
pt
r
;
if
(
HeapValidate
(
GetProcessHeap
(),
HEAP_NO_SERIALIZE
,
(
const
char
*
)
test
-
H
LOC
AL_STORAGE
)
&&
/* obj(-handle) valid arena? */
HeapValidate
(
GetProcessHeap
(),
HEAP_NO_SERIALIZE
,
mem
))
/* intern valid arena? */
break
;
/* valid moveable block */
}
...
...
@@ -320,8 +322,9 @@ HGLOBAL WINAPI GlobalReAlloc( HGLOBAL handle, SIZE_T size, UINT flags )
*/
SIZE_T
WINAPI
GlobalSize
(
HGLOBAL
handle
)
{
PGLOBAL32_INTERN
mem
;
struct
mem_entry
*
mem
;
SIZE_T
retval
;
void
*
ptr
;
TRACE_
(
globalmem
)(
"handle %p
\n
"
,
handle
);
...
...
@@ -331,27 +334,26 @@ SIZE_T WINAPI GlobalSize( HGLOBAL handle )
return
0
;
}
if
(
ISPOINTER
(
handle
))
if
(
(
ptr
=
unsafe_ptr_from_HLOCAL
(
handle
)
))
{
retval
=
HeapSize
(
GetProcessHeap
(),
0
,
handle
);
retval
=
HeapSize
(
GetProcessHeap
(),
0
,
ptr
);
if
(
retval
==
~
(
SIZE_T
)
0
)
/* It might be a GMEM_MOVEABLE data pointer */
{
retval
=
HeapSize
(
GetProcessHeap
(),
0
,
(
char
*
)
handle
-
HGLOB
AL_STORAGE
);
if
(
retval
!=
~
(
SIZE_T
)
0
)
retval
-=
H
GLOB
AL_STORAGE
;
retval
=
HeapSize
(
GetProcessHeap
(),
0
,
(
char
*
)
ptr
-
HLOC
AL_STORAGE
);
if
(
retval
!=
~
(
SIZE_T
)
0
)
retval
-=
H
LOC
AL_STORAGE
;
}
}
else
{
RtlLockHeap
(
GetProcessHeap
()
);
mem
=
HANDLE_TO_INTERN
(
handle
);
if
(
mem
->
Magic
==
MAGIC_GLOBAL_USED
)
if
((
mem
=
unsafe_mem_from_HLOCAL
(
handle
)))
{
if
(
!
mem
->
Pointe
r
)
/* handle case of GlobalAlloc( ??,0) */
if
(
!
mem
->
pt
r
)
/* handle case of GlobalAlloc( ??,0) */
retval
=
0
;
else
{
retval
=
HeapSize
(
GetProcessHeap
(),
0
,
(
char
*
)
mem
->
Pointer
-
HGLOB
AL_STORAGE
);
if
(
retval
!=
~
(
SIZE_T
)
0
)
retval
-=
H
GLOB
AL_STORAGE
;
retval
=
HeapSize
(
GetProcessHeap
(),
0
,
(
char
*
)
mem
->
ptr
-
HLOC
AL_STORAGE
);
if
(
retval
!=
~
(
SIZE_T
)
0
)
retval
-=
H
LOC
AL_STORAGE
;
}
}
else
...
...
@@ -418,23 +420,22 @@ VOID WINAPI GlobalUnfix( HGLOBAL handle )
*/
UINT
WINAPI
GlobalFlags
(
HGLOBAL
handle
)
{
PGLOBAL32_INTERN
mem
;
struct
mem_entry
*
mem
;
DWORD
retval
;
TRACE_
(
globalmem
)(
"handle %p
\n
"
,
handle
);
if
(
ISPOINTER
(
handle
))
if
(
unsafe_ptr_from_HLOCAL
(
handle
))
{
retval
=
0
;
}
else
{
RtlLockHeap
(
GetProcessHeap
()
);
mem
=
HANDLE_TO_INTERN
(
handle
);
if
(
mem
->
Magic
==
MAGIC_GLOBAL_USED
)
if
((
mem
=
unsafe_mem_from_HLOCAL
(
handle
)))
{
retval
=
mem
->
LockCount
+
(
mem
->
F
lags
<<
8
);
if
(
mem
->
Pointe
r
==
0
)
retval
|=
GMEM_DISCARDED
;
retval
=
mem
->
lock
+
(
mem
->
f
lags
<<
8
);
if
(
mem
->
pt
r
==
0
)
retval
|=
GMEM_DISCARDED
;
}
else
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment