2 * Selector manipulation functions
4 * Copyright 1995 Alexandre Julliard
11 #include "wine/winbase16.h"
13 #include "selectors.h"
14 #include "stackframe.h"
15 #include "wine/server.h"
16 #include "debugtools.h"
19 DEFAULT_DEBUG_CHANNEL(selector
);
23 /* get the number of selectors needed to cover up to the selector limit */
24 inline static WORD
get_sel_count( WORD sel
)
26 return (wine_ldt_copy
.limit
[sel
>> __AHSHIFT
] >> 16) + 1;
29 /***********************************************************************
32 * Allocate a selector array without setting the LDT entries
34 static WORD
SELECTOR_AllocArray( WORD count
)
36 WORD i
, sel
, size
= 0;
39 for (i
= FIRST_LDT_ENTRY_TO_ALLOC
; i
< LDT_SIZE
; i
++)
41 if (wine_ldt_copy
.flags
[i
] & WINE_LDT_FLAGS_ALLOCATED
) size
= 0;
42 else if (++size
>= count
) break;
44 if (i
== LDT_SIZE
) return 0;
47 /* mark selectors as allocated */
48 for (i
= 0; i
< count
; i
++) wine_ldt_copy
.flags
[sel
+ i
] |= WINE_LDT_FLAGS_ALLOCATED
;
50 return (sel
<< __AHSHIFT
) | 7;
54 /***********************************************************************
55 * AllocSelectorArray (KERNEL.206)
57 WORD WINAPI
AllocSelectorArray16( WORD count
)
59 WORD i
, sel
= SELECTOR_AllocArray( count
);
64 wine_ldt_set_base( &entry
, 0 );
65 wine_ldt_set_limit( &entry
, 1 ); /* avoid 0 base and limit */
66 wine_ldt_set_flags( &entry
, WINE_LDT_FLAGS_DATA
);
67 for (i
= 0; i
< count
; i
++) wine_ldt_set_entry( sel
+ (i
<< __AHSHIFT
), &entry
);
73 /***********************************************************************
74 * AllocSelector (KERNEL.175)
76 WORD WINAPI
AllocSelector16( WORD sel
)
78 WORD newsel
, count
, i
;
80 count
= sel
? get_sel_count(sel
) : 1;
81 newsel
= SELECTOR_AllocArray( count
);
82 TRACE("(%04x): returning %04x\n", sel
, newsel
);
83 if (!newsel
) return 0;
84 if (!sel
) return newsel
; /* nothing to copy */
85 for (i
= 0; i
< count
; i
++)
88 wine_ldt_get_entry( sel
+ (i
<< __AHSHIFT
), &entry
);
89 wine_ldt_set_entry( newsel
+ (i
<< __AHSHIFT
), &entry
);
95 /***********************************************************************
96 * FreeSelector (KERNEL.176)
98 WORD WINAPI
FreeSelector16( WORD sel
)
102 if (IS_SELECTOR_FREE(sel
)) return sel
; /* error */
105 /* Check if we are freeing current %fs or %gs selector */
106 if (!((__get_fs() ^ sel
) & ~7))
108 WARN("Freeing %%fs selector (%04x), not good.\n", __get_fs() );
111 if (!((__get_gs() ^ sel
) & ~7)) __set_gs( 0 );
112 #endif /* __i386__ */
114 memset( &entry
, 0, sizeof(entry
) ); /* clear the LDT entries */
115 wine_ldt_set_entry( sel
, &entry
);
116 wine_ldt_copy
.flags
[sel
>> __AHSHIFT
] &= ~WINE_LDT_FLAGS_ALLOCATED
;
121 /***********************************************************************
122 * SELECTOR_SetEntries
124 * Set the LDT entries for an array of selectors.
126 static void SELECTOR_SetEntries( WORD sel
, const void *base
, DWORD size
, unsigned char flags
)
131 wine_ldt_set_base( &entry
, base
);
132 wine_ldt_set_limit( &entry
, size
- 1 );
133 wine_ldt_set_flags( &entry
, flags
);
134 /* Make sure base and limit are not 0 together if the size is not 0 */
135 if (!base
&& size
== 1) wine_ldt_set_limit( &entry
, 1 );
136 count
= (size
+ 0xffff) / 0x10000;
137 for (i
= 0; i
< count
; i
++)
139 wine_ldt_set_entry( sel
+ (i
<< __AHSHIFT
), &entry
);
140 wine_ldt_set_base( &entry
, wine_ldt_get_base(&entry
) + 0x10000 );
141 wine_ldt_set_limit( &entry
, wine_ldt_get_limit(&entry
) - 0x10000 );
146 /***********************************************************************
147 * SELECTOR_AllocBlock
149 * Allocate selectors for a block of linear memory.
151 WORD
SELECTOR_AllocBlock( const void *base
, DWORD size
, unsigned char flags
)
156 count
= (size
+ 0xffff) / 0x10000;
157 sel
= SELECTOR_AllocArray( count
);
158 if (sel
) SELECTOR_SetEntries( sel
, base
, size
, flags
);
163 /***********************************************************************
166 * Free a block of selectors.
168 void SELECTOR_FreeBlock( WORD sel
)
170 WORD i
, count
= get_sel_count( sel
);
172 TRACE("(%04x,%d)\n", sel
, count
);
173 for (i
= 0; i
< count
; i
++) FreeSelector16( sel
+ (i
<< __AHSHIFT
) );
177 /***********************************************************************
178 * SELECTOR_ReallocBlock
180 * Change the size of a block of selectors.
182 WORD
SELECTOR_ReallocBlock( WORD sel
, const void *base
, DWORD size
)
185 WORD i
, oldcount
, newcount
;
188 oldcount
= get_sel_count( sel
);
189 newcount
= (size
+ 0xffff) >> 16;
190 wine_ldt_get_entry( sel
, &entry
);
192 if (oldcount
< newcount
) /* We need to add selectors */
194 WORD index
= sel
>> __AHSHIFT
;
195 /* Check if the next selectors are free */
196 if (index
+ newcount
> LDT_SIZE
) i
= oldcount
;
198 for (i
= oldcount
; i
< newcount
; i
++)
199 if (wine_ldt_copy
.flags
[index
+i
] & WINE_LDT_FLAGS_ALLOCATED
) break;
201 if (i
< newcount
) /* they are not free */
203 SELECTOR_FreeBlock( sel
);
204 sel
= SELECTOR_AllocArray( newcount
);
206 else /* mark the selectors as allocated */
208 for (i
= oldcount
; i
< newcount
; i
++)
209 wine_ldt_copy
.flags
[index
+i
] |= WINE_LDT_FLAGS_ALLOCATED
;
212 else if (oldcount
> newcount
) /* We need to remove selectors */
214 SELECTOR_FreeBlock( sel
+ (newcount
<< __AHSHIFT
) );
216 if (sel
) SELECTOR_SetEntries( sel
, base
, size
, wine_ldt_get_flags(&entry
) );
221 /***********************************************************************
222 * PrestoChangoSelector (KERNEL.177)
224 WORD WINAPI
PrestoChangoSelector16( WORD selSrc
, WORD selDst
)
227 wine_ldt_get_entry( selSrc
, &entry
);
228 /* toggle the executable bit */
229 entry
.HighWord
.Bits
.Type
^= (WINE_LDT_FLAGS_CODE
^ WINE_LDT_FLAGS_DATA
);
230 wine_ldt_set_entry( selDst
, &entry
);
235 /***********************************************************************
236 * AllocCStoDSAlias (KERNEL.170)
237 * AllocAlias (KERNEL.172)
239 WORD WINAPI
AllocCStoDSAlias16( WORD sel
)
244 newsel
= SELECTOR_AllocArray( 1 );
245 TRACE("(%04x): returning %04x\n",
247 if (!newsel
) return 0;
248 wine_ldt_get_entry( sel
, &entry
);
249 entry
.HighWord
.Bits
.Type
= WINE_LDT_FLAGS_DATA
;
250 wine_ldt_set_entry( newsel
, &entry
);
255 /***********************************************************************
256 * AllocDStoCSAlias (KERNEL.171)
258 WORD WINAPI
AllocDStoCSAlias16( WORD sel
)
263 newsel
= SELECTOR_AllocArray( 1 );
264 TRACE("(%04x): returning %04x\n",
266 if (!newsel
) return 0;
267 wine_ldt_get_entry( sel
, &entry
);
268 entry
.HighWord
.Bits
.Type
= WINE_LDT_FLAGS_CODE
;
269 wine_ldt_set_entry( newsel
, &entry
);
274 /***********************************************************************
275 * LongPtrAdd (KERNEL.180)
277 void WINAPI
LongPtrAdd16( DWORD ptr
, DWORD add
)
280 wine_ldt_get_entry( SELECTOROF(ptr
), &entry
);
281 wine_ldt_set_base( &entry
, (char *)wine_ldt_get_base(&entry
) + add
);
282 wine_ldt_set_entry( SELECTOROF(ptr
), &entry
);
286 /***********************************************************************
287 * GetSelectorBase (KERNEL.186)
289 DWORD WINAPI
WIN16_GetSelectorBase( WORD sel
)
292 * Note: For Win32s processes, the whole linear address space is
293 * shifted by 0x10000 relative to the OS linear address space.
294 * See the comment in msdos/vxd.c.
297 DWORD base
= GetSelectorBase( sel
);
298 return W32S_WINE2APP( base
);
300 DWORD WINAPI
GetSelectorBase( WORD sel
)
302 void *base
= wine_ldt_copy
.base
[sel
>> __AHSHIFT
];
304 /* if base points into DOSMEM, assume we have to
305 * return pointer into physical lower 1MB */
307 return DOSMEM_MapLinearToDos( base
);
311 /***********************************************************************
312 * SetSelectorBase (KERNEL.187)
314 DWORD WINAPI
WIN16_SetSelectorBase( WORD sel
, DWORD base
)
317 * Note: For Win32s processes, the whole linear address space is
318 * shifted by 0x10000 relative to the OS linear address space.
319 * See the comment in msdos/vxd.c.
322 SetSelectorBase( sel
, W32S_APP2WINE( base
) );
325 WORD WINAPI
SetSelectorBase( WORD sel
, DWORD base
)
328 wine_ldt_get_entry( sel
, &entry
);
329 wine_ldt_set_base( &entry
, DOSMEM_MapDosToLinear(base
) );
330 wine_ldt_set_entry( sel
, &entry
);
335 /***********************************************************************
336 * GetSelectorLimit (KERNEL.188)
338 DWORD WINAPI
GetSelectorLimit16( WORD sel
)
340 return wine_ldt_copy
.limit
[sel
>> __AHSHIFT
];
344 /***********************************************************************
345 * SetSelectorLimit (KERNEL.189)
347 WORD WINAPI
SetSelectorLimit16( WORD sel
, DWORD limit
)
350 wine_ldt_get_entry( sel
, &entry
);
351 wine_ldt_set_limit( &entry
, limit
);
352 wine_ldt_set_entry( sel
, &entry
);
357 /***********************************************************************
358 * SelectorAccessRights (KERNEL.196)
360 WORD WINAPI
SelectorAccessRights16( WORD sel
, WORD op
, WORD val
)
363 wine_ldt_get_entry( sel
, &entry
);
365 if (op
== 0) /* get */
367 return entry
.HighWord
.Bytes
.Flags1
| ((entry
.HighWord
.Bytes
.Flags2
<< 8) & 0xf0);
371 entry
.HighWord
.Bytes
.Flags1
= LOBYTE(val
) | 0xf0;
372 entry
.HighWord
.Bytes
.Flags2
= (entry
.HighWord
.Bytes
.Flags2
& 0x0f) | (HIBYTE(val
) & 0xf0);
373 wine_ldt_set_entry( sel
, &entry
);
379 /***********************************************************************
380 * IsBadCodePtr (KERNEL.336)
382 BOOL16 WINAPI
IsBadCodePtr16( SEGPTR lpfn
)
387 sel
= SELECTOROF(lpfn
);
388 if (!sel
) return TRUE
;
389 if (IS_SELECTOR_FREE(sel
)) return TRUE
;
390 wine_ldt_get_entry( sel
, &entry
);
391 /* check for code segment, ignoring conforming, read-only and accessed bits */
392 if ((entry
.HighWord
.Bits
.Type
^ WINE_LDT_FLAGS_CODE
) & 0x18) return TRUE
;
393 if (OFFSETOF(lpfn
) > wine_ldt_get_limit(&entry
)) return TRUE
;
398 /***********************************************************************
399 * IsBadStringPtr (KERNEL.337)
401 BOOL16 WINAPI
IsBadStringPtr16( SEGPTR ptr
, UINT16 size
)
406 sel
= SELECTOROF(ptr
);
407 if (!sel
) return TRUE
;
408 if (IS_SELECTOR_FREE(sel
)) return TRUE
;
409 wine_ldt_get_entry( sel
, &entry
);
410 /* check for data or readable code segment */
411 if (!(entry
.HighWord
.Bits
.Type
& 0x10)) return TRUE
; /* system descriptor */
412 if ((entry
.HighWord
.Bits
.Type
& 0x0a) == 0x08) return TRUE
; /* non-readable code segment */
413 if (strlen(MapSL(ptr
)) < size
) size
= strlen(MapSL(ptr
)) + 1;
414 if (size
&& (OFFSETOF(ptr
) + size
- 1 > wine_ldt_get_limit(&entry
))) return TRUE
;
419 /***********************************************************************
420 * IsBadHugeReadPtr (KERNEL.346)
422 BOOL16 WINAPI
IsBadHugeReadPtr16( SEGPTR ptr
, DWORD size
)
427 sel
= SELECTOROF(ptr
);
428 if (!sel
) return TRUE
;
429 if (IS_SELECTOR_FREE(sel
)) return TRUE
;
430 wine_ldt_get_entry( sel
, &entry
);
431 /* check for data or readable code segment */
432 if (!(entry
.HighWord
.Bits
.Type
& 0x10)) return TRUE
; /* system descriptor */
433 if ((entry
.HighWord
.Bits
.Type
& 0x0a) == 0x08) return TRUE
; /* non-readable code segment */
434 if (size
&& (OFFSETOF(ptr
) + size
- 1 > wine_ldt_get_limit( &entry
))) return TRUE
;
439 /***********************************************************************
440 * IsBadHugeWritePtr (KERNEL.347)
442 BOOL16 WINAPI
IsBadHugeWritePtr16( SEGPTR ptr
, DWORD size
)
447 sel
= SELECTOROF(ptr
);
448 if (!sel
) return TRUE
;
449 if (IS_SELECTOR_FREE(sel
)) return TRUE
;
450 wine_ldt_get_entry( sel
, &entry
);
451 /* check for writeable data segment, ignoring expand-down and accessed flags */
452 if ((entry
.HighWord
.Bits
.Type
^ WINE_LDT_FLAGS_DATA
) & ~5) return TRUE
;
453 if (size
&& (OFFSETOF(ptr
) + size
- 1 > wine_ldt_get_limit( &entry
))) return TRUE
;
457 /***********************************************************************
458 * IsBadReadPtr (KERNEL.334)
460 BOOL16 WINAPI
IsBadReadPtr16( SEGPTR ptr
, UINT16 size
)
462 return IsBadHugeReadPtr16( ptr
, size
);
466 /***********************************************************************
467 * IsBadWritePtr (KERNEL.335)
469 BOOL16 WINAPI
IsBadWritePtr16( SEGPTR ptr
, UINT16 size
)
471 return IsBadHugeWritePtr16( ptr
, size
);
475 /***********************************************************************
476 * IsBadFlatReadWritePtr (KERNEL.627)
478 BOOL16 WINAPI
IsBadFlatReadWritePtr16( SEGPTR ptr
, DWORD size
, BOOL16 bWrite
)
480 return bWrite
? IsBadHugeWritePtr16( ptr
, size
)
481 : IsBadHugeReadPtr16( ptr
, size
);
485 /***********************************************************************
486 * MemoryRead (TOOLHELP.78)
488 DWORD WINAPI
MemoryRead16( WORD sel
, DWORD offset
, void *buffer
, DWORD count
)
490 WORD index
= sel
>> __AHSHIFT
;
492 if (!(wine_ldt_copy
.flags
[index
] & WINE_LDT_FLAGS_ALLOCATED
)) return 0;
493 if (offset
> wine_ldt_copy
.limit
[index
]) return 0;
494 if (offset
+ count
> wine_ldt_copy
.limit
[index
] + 1)
495 count
= wine_ldt_copy
.limit
[index
] + 1 - offset
;
496 memcpy( buffer
, (char *)wine_ldt_copy
.base
[index
] + offset
, count
);
501 /***********************************************************************
502 * MemoryWrite (TOOLHELP.79)
504 DWORD WINAPI
MemoryWrite16( WORD sel
, DWORD offset
, void *buffer
, DWORD count
)
506 WORD index
= sel
>> __AHSHIFT
;
508 if (!(wine_ldt_copy
.flags
[index
] & WINE_LDT_FLAGS_ALLOCATED
)) return 0;
509 if (offset
> wine_ldt_copy
.limit
[index
]) return 0;
510 if (offset
+ count
> wine_ldt_copy
.limit
[index
] + 1)
511 count
= wine_ldt_copy
.limit
[index
] + 1 - offset
;
512 memcpy( (char *)wine_ldt_copy
.base
[index
] + offset
, buffer
, count
);
516 /************************************* Win95 pointer mapping functions *
520 /***********************************************************************
524 * Maps fixed segmented pointer to linear.
526 LPVOID WINAPI
MapSL( SEGPTR sptr
)
528 return (char *)wine_ldt_copy
.base
[SELECTOROF(sptr
) >> __AHSHIFT
] + OFFSETOF(sptr
);
531 /***********************************************************************
532 * MapSLFix (KERNEL32.@)
534 * FIXME: MapSLFix and UnMapSLFixArray should probably prevent
535 * unexpected linear address change when GlobalCompact() shuffles
539 LPVOID WINAPI
MapSLFix( SEGPTR sptr
)
544 /***********************************************************************
545 * UnMapSLFixArray (KERNEL32.@)
548 void WINAPI
UnMapSLFixArray( SEGPTR sptr
[], INT length
, CONTEXT86
*context
)
550 /* Must not change EAX, hence defined as 'register' function */
553 /***********************************************************************
554 * GetThreadSelectorEntry (KERNEL32.@)
556 BOOL WINAPI
GetThreadSelectorEntry( HANDLE hthread
, DWORD sel
, LPLDT_ENTRY ldtent
)
561 if (!(sel
& 4)) /* GDT selector */
563 sel
&= ~3; /* ignore RPL */
564 if (!sel
) /* null selector */
566 memset( ldtent
, 0, sizeof(*ldtent
) );
570 ldtent
->HighWord
.Bits
.BaseMid
= 0;
571 ldtent
->HighWord
.Bits
.BaseHi
= 0;
572 ldtent
->LimitLow
= 0xffff;
573 ldtent
->HighWord
.Bits
.LimitHi
= 0xf;
574 ldtent
->HighWord
.Bits
.Dpl
= 3;
575 ldtent
->HighWord
.Bits
.Sys
= 0;
576 ldtent
->HighWord
.Bits
.Pres
= 1;
577 ldtent
->HighWord
.Bits
.Granularity
= 1;
578 ldtent
->HighWord
.Bits
.Default_Big
= 1;
579 ldtent
->HighWord
.Bits
.Type
= 0x12;
580 /* it has to be one of the system GDT selectors */
581 if (sel
== (__get_ds() & ~3)) return TRUE
;
582 if (sel
== (__get_ss() & ~3)) return TRUE
;
583 if (sel
== (__get_cs() & ~3))
585 ldtent
->HighWord
.Bits
.Type
|= 8; /* code segment */
588 SetLastError( ERROR_NOACCESS
);
592 SERVER_START_REQ( get_selector_entry
)
594 req
->handle
= hthread
;
595 req
->entry
= sel
>> __AHSHIFT
;
596 if ((ret
= !SERVER_CALL_ERR()))
598 if (!(req
->flags
& WINE_LDT_FLAGS_ALLOCATED
))
600 SetLastError( ERROR_MR_MID_NOT_FOUND
); /* sic */
605 wine_ldt_set_base( ldtent
, (void *)req
->base
);
606 wine_ldt_set_limit( ldtent
, req
->limit
);
607 wine_ldt_set_flags( ldtent
, req
->flags
);
614 SetLastError( ERROR_CALL_NOT_IMPLEMENTED
);
620 /**********************************************************************
622 * These functions map linear pointers at [EBP+xxx] to segmented pointers
624 * Win95 uses some kind of alias structs, which it stores in [EBP+x] to
625 * unravel them at SUnMapLS. We just store the segmented pointer there.
628 x_SMapLS_IP_EBP_x(CONTEXT86
*context
,int argoff
) {
631 val
=*(DWORD
*)(context
->Ebp
+ argoff
);
634 *(DWORD
*)(context
->Ebp
+ argoff
) = 0;
636 ptr
= MapLS((LPVOID
)val
);
637 *(DWORD
*)(context
->Ebp
+ argoff
) = ptr
;
642 /***********************************************************************
643 * SMapLS_IP_EBP_8 (KERNEL32.@)
645 void WINAPI
SMapLS_IP_EBP_8 (CONTEXT86
*context
) {x_SMapLS_IP_EBP_x(context
, 8);}
647 /***********************************************************************
648 * SMapLS_IP_EBP_12 (KERNEL32.@)
650 void WINAPI
SMapLS_IP_EBP_12(CONTEXT86
*context
) {x_SMapLS_IP_EBP_x(context
,12);}
652 /***********************************************************************
653 * SMapLS_IP_EBP_16 (KERNEL32.@)
655 void WINAPI
SMapLS_IP_EBP_16(CONTEXT86
*context
) {x_SMapLS_IP_EBP_x(context
,16);}
657 /***********************************************************************
658 * SMapLS_IP_EBP_20 (KERNEL32.@)
660 void WINAPI
SMapLS_IP_EBP_20(CONTEXT86
*context
) {x_SMapLS_IP_EBP_x(context
,20);}
662 /***********************************************************************
663 * SMapLS_IP_EBP_24 (KERNEL32.@)
665 void WINAPI
SMapLS_IP_EBP_24(CONTEXT86
*context
) {x_SMapLS_IP_EBP_x(context
,24);}
667 /***********************************************************************
668 * SMapLS_IP_EBP_28 (KERNEL32.@)
670 void WINAPI
SMapLS_IP_EBP_28(CONTEXT86
*context
) {x_SMapLS_IP_EBP_x(context
,28);}
672 /***********************************************************************
673 * SMapLS_IP_EBP_32 (KERNEL32.@)
675 void WINAPI
SMapLS_IP_EBP_32(CONTEXT86
*context
) {x_SMapLS_IP_EBP_x(context
,32);}
677 /***********************************************************************
678 * SMapLS_IP_EBP_36 (KERNEL32.@)
680 void WINAPI
SMapLS_IP_EBP_36(CONTEXT86
*context
) {x_SMapLS_IP_EBP_x(context
,36);}
682 /***********************************************************************
683 * SMapLS_IP_EBP_40 (KERNEL32.@)
685 void WINAPI
SMapLS_IP_EBP_40(CONTEXT86
*context
) {x_SMapLS_IP_EBP_x(context
,40);}
687 /***********************************************************************
688 * SMapLS (KERNEL32.@)
690 void WINAPI
SMapLS( CONTEXT86
*context
)
692 if (HIWORD(context
->Eax
))
694 context
->Eax
= MapLS( (LPVOID
)context
->Eax
);
695 context
->Edx
= context
->Eax
;
701 /***********************************************************************
702 * SUnMapLS (KERNEL32.@)
705 void WINAPI
SUnMapLS( CONTEXT86
*context
)
707 if (HIWORD(context
->Eax
)) UnMapLS( (SEGPTR
)context
->Eax
);
710 inline static void x_SUnMapLS_IP_EBP_x(CONTEXT86
*context
,int argoff
)
712 SEGPTR
*ptr
= (SEGPTR
*)(context
->Ebp
+ argoff
);
720 /***********************************************************************
721 * SUnMapLS_IP_EBP_8 (KERNEL32.@)
723 void WINAPI
SUnMapLS_IP_EBP_8 (CONTEXT86
*context
) { x_SUnMapLS_IP_EBP_x(context
, 8); }
725 /***********************************************************************
726 * SUnMapLS_IP_EBP_12 (KERNEL32.@)
728 void WINAPI
SUnMapLS_IP_EBP_12(CONTEXT86
*context
) { x_SUnMapLS_IP_EBP_x(context
,12); }
730 /***********************************************************************
731 * SUnMapLS_IP_EBP_16 (KERNEL32.@)
733 void WINAPI
SUnMapLS_IP_EBP_16(CONTEXT86
*context
) { x_SUnMapLS_IP_EBP_x(context
,16); }
735 /***********************************************************************
736 * SUnMapLS_IP_EBP_20 (KERNEL32.@)
738 void WINAPI
SUnMapLS_IP_EBP_20(CONTEXT86
*context
) { x_SUnMapLS_IP_EBP_x(context
,20); }
740 /***********************************************************************
741 * SUnMapLS_IP_EBP_24 (KERNEL32.@)
743 void WINAPI
SUnMapLS_IP_EBP_24(CONTEXT86
*context
) { x_SUnMapLS_IP_EBP_x(context
,24); }
745 /***********************************************************************
746 * SUnMapLS_IP_EBP_28 (KERNEL32.@)
748 void WINAPI
SUnMapLS_IP_EBP_28(CONTEXT86
*context
) { x_SUnMapLS_IP_EBP_x(context
,28); }
750 /***********************************************************************
751 * SUnMapLS_IP_EBP_32 (KERNEL32.@)
753 void WINAPI
SUnMapLS_IP_EBP_32(CONTEXT86
*context
) { x_SUnMapLS_IP_EBP_x(context
,32); }
755 /***********************************************************************
756 * SUnMapLS_IP_EBP_36 (KERNEL32.@)
758 void WINAPI
SUnMapLS_IP_EBP_36(CONTEXT86
*context
) { x_SUnMapLS_IP_EBP_x(context
,36); }
760 /***********************************************************************
761 * SUnMapLS_IP_EBP_40 (KERNEL32.@)
763 void WINAPI
SUnMapLS_IP_EBP_40(CONTEXT86
*context
) { x_SUnMapLS_IP_EBP_x(context
,40); }
765 /**********************************************************************
766 * AllocMappedBuffer (KERNEL32.38)
768 * This is a undocumented KERNEL32 function that
769 * SMapLS's a GlobalAlloc'ed buffer.
771 * Input: EDI register: size of buffer to allocate
772 * Output: EDI register: pointer to buffer
774 * Note: The buffer is preceded by 8 bytes:
777 * edi-4 SEGPTR to buffer
778 * edi-8 some magic Win95 needs for SUnMapLS
779 * (we use it for the memory handle)
781 * The SEGPTR is used by the caller!
784 void WINAPI
AllocMappedBuffer( CONTEXT86
*context
)
786 HGLOBAL handle
= GlobalAlloc(0, context
->Edi
+ 8);
787 DWORD
*buffer
= (DWORD
*)GlobalLock(handle
);
791 if (!(ptr
= MapLS(buffer
+ 2)))
793 GlobalUnlock(handle
);
798 context
->Eax
= context
->Edi
= 0;
804 context
->Eax
= (DWORD
) ptr
;
805 context
->Edi
= (DWORD
)(buffer
+ 2);
809 /**********************************************************************
810 * FreeMappedBuffer (KERNEL32.39)
812 * Free a buffer allocated by AllocMappedBuffer
814 * Input: EDI register: pointer to buffer
817 void WINAPI
FreeMappedBuffer( CONTEXT86
*context
)
821 DWORD
*buffer
= (DWORD
*)context
->Edi
- 2;
825 GlobalUnlock(buffer
[0]);
826 GlobalFree(buffer
[0]);
831 __ASM_GLOBAL_FUNC( __get_cs
, "movw %cs,%ax\n\tret" )
832 __ASM_GLOBAL_FUNC( __get_ds
, "movw %ds,%ax\n\tret" )
833 __ASM_GLOBAL_FUNC( __get_es
, "movw %es,%ax\n\tret" )
834 __ASM_GLOBAL_FUNC( __get_fs
, "movw %fs,%ax\n\tret" )
835 __ASM_GLOBAL_FUNC( __get_gs
, "movw %gs,%ax\n\tret" )
836 __ASM_GLOBAL_FUNC( __get_ss
, "movw %ss,%ax\n\tret" )
837 __ASM_GLOBAL_FUNC( __set_fs
, "movl 4(%esp),%eax\n\tmovw %ax,%fs\n\tret" )
838 __ASM_GLOBAL_FUNC( __set_gs
, "movl 4(%esp),%eax\n\tmovw %ax,%gs\n\tret" )