2 * Selector manipulation functions
4 * Copyright 1995 Alexandre Julliard
8 #include "wine/winbase16.h"
11 #include "selectors.h"
12 #include "stackframe.h"
17 /***********************************************************************
18 * AllocSelectorArray (KERNEL.206)
20 WORD WINAPI
AllocSelectorArray16( WORD count
)
22 WORD i
, sel
, size
= 0;
26 for (i
= FIRST_LDT_ENTRY_TO_ALLOC
; i
< LDT_SIZE
; i
++)
28 if (!IS_LDT_ENTRY_FREE(i
)) size
= 0;
29 else if (++size
>= count
) break;
31 if (i
== LDT_SIZE
) return 0;
35 entry
.type
= SEGMENT_DATA
;
36 entry
.seg_32bit
= FALSE
;
37 entry
.read_only
= FALSE
;
38 entry
.limit_in_pages
= FALSE
;
39 entry
.limit
= 1; /* avoid 0 base and limit */
41 for (i
= 0; i
< count
; i
++)
43 /* Mark selector as allocated */
44 ldt_flags_copy
[sel
+ i
] |= LDT_FLAGS_ALLOCATED
;
45 LDT_SetEntry( sel
+ i
, &entry
);
47 return ENTRY_TO_SELECTOR( sel
);
51 /***********************************************************************
52 * AllocSelector (KERNEL.175)
54 WORD WINAPI
AllocSelector16( WORD sel
)
56 WORD newsel
, count
, i
;
58 count
= sel
? ((GET_SEL_LIMIT(sel
) >> 16) + 1) : 1;
59 newsel
= AllocSelectorArray16( count
);
60 TRACE(selector
, "(%04x): returning %04x\n",
62 if (!newsel
) return 0;
63 if (!sel
) return newsel
; /* nothing to copy */
64 for (i
= 0; i
< count
; i
++)
67 LDT_GetEntry( SELECTOR_TO_ENTRY(sel
) + i
, &entry
);
68 LDT_SetEntry( SELECTOR_TO_ENTRY(newsel
) + i
, &entry
);
74 /***********************************************************************
75 * FreeSelector (KERNEL.176)
77 WORD WINAPI
FreeSelector16( WORD sel
)
79 if (IS_SELECTOR_FREE(sel
)) return sel
; /* error */
80 SELECTOR_FreeBlock( sel
, 1 );
85 /***********************************************************************
88 * Set the LDT entries for an array of selectors.
90 static void SELECTOR_SetEntries( WORD sel
, const void *base
, DWORD size
,
91 enum seg_type type
, BOOL is32bit
,
97 /* The limit for the first selector is the whole */
98 /* block. The next selectors get a 64k limit. */
99 entry
.base
= (unsigned long)base
;
101 entry
.seg_32bit
= is32bit
;
102 entry
.read_only
= readonly
;
103 entry
.limit_in_pages
= (size
> 0x100000);
104 if (entry
.limit_in_pages
) entry
.limit
= ((size
+ 0xfff) >> 12) - 1;
105 else entry
.limit
= size
- 1;
106 /* Make sure base and limit are not 0 together if the size is not 0 */
107 if (!base
&& !entry
.limit
&& size
) entry
.limit
= 1;
108 count
= (size
+ 0xffff) / 0x10000;
109 for (i
= 0; i
< count
; i
++)
111 LDT_SetEntry( SELECTOR_TO_ENTRY(sel
) + i
, &entry
);
112 entry
.base
+= 0x10000;
113 /* Apparently the next selectors should *not* get a 64k limit. */
114 /* Can't remember where I read they should... --AJ */
115 entry
.limit
-= entry
.limit_in_pages
? 0x10 : 0x10000;
120 /***********************************************************************
121 * SELECTOR_AllocBlock
123 * Allocate selectors for a block of linear memory.
125 WORD
SELECTOR_AllocBlock( const void *base
, DWORD size
, enum seg_type type
,
126 BOOL is32bit
, BOOL readonly
)
131 count
= (size
+ 0xffff) / 0x10000;
132 sel
= AllocSelectorArray16( count
);
133 if (sel
) SELECTOR_SetEntries( sel
, base
, size
, type
, is32bit
, readonly
);
138 /***********************************************************************
141 * Move a block of selectors in linear memory.
143 void SELECTOR_MoveBlock( WORD sel
, const void *new_base
)
145 WORD i
, count
= (GET_SEL_LIMIT(sel
) >> 16) + 1;
147 for (i
= 0; i
< count
; i
++)
150 LDT_GetEntry( SELECTOR_TO_ENTRY(sel
) + i
, &entry
);
151 entry
.base
= (unsigned long)new_base
;
152 LDT_SetEntry( SELECTOR_TO_ENTRY(sel
) + i
, &entry
);
157 /***********************************************************************
160 * Free a block of selectors.
162 void SELECTOR_FreeBlock( WORD sel
, WORD count
)
167 TRACE(selector
, "(%04x,%d)\n", sel
, count
);
168 sel
&= ~(__AHINCR
- 1); /* clear bottom bits of selector */
169 nextsel
= sel
+ (count
<< __AHSHIFT
);
173 /* Check if we are freeing current %fs or %gs selector */
177 if ((fs
>= sel
) && (fs
< nextsel
))
179 WARN(selector
, "Freeing %%fs selector (%04x), not good.\n", fs
);
183 if ((gs
>= sel
) && (gs
< nextsel
)) SET_GS( 0 );
185 #endif /* __i386__ */
187 memset( &entry
, 0, sizeof(entry
) ); /* clear the LDT entries */
188 for (i
= SELECTOR_TO_ENTRY(sel
); count
; i
++, count
--)
190 LDT_SetEntry( i
, &entry
);
191 ldt_flags_copy
[i
] &= ~LDT_FLAGS_ALLOCATED
;
196 /***********************************************************************
197 * SELECTOR_ReallocBlock
199 * Change the size of a block of selectors.
201 WORD
SELECTOR_ReallocBlock( WORD sel
, const void *base
, DWORD size
,
202 enum seg_type type
, BOOL is32bit
, BOOL readonly
)
204 WORD i
, oldcount
, newcount
;
207 oldcount
= (GET_SEL_LIMIT(sel
) >> 16) + 1;
208 newcount
= (size
+ 0xffff) >> 16;
210 if (oldcount
< newcount
) /* We need to add selectors */
212 /* Check if the next selectors are free */
213 if (SELECTOR_TO_ENTRY(sel
) + newcount
> LDT_SIZE
) i
= oldcount
;
215 for (i
= oldcount
; i
< newcount
; i
++)
216 if (!IS_LDT_ENTRY_FREE(SELECTOR_TO_ENTRY(sel
)+i
)) break;
218 if (i
< newcount
) /* they are not free */
220 SELECTOR_FreeBlock( sel
, oldcount
);
221 sel
= AllocSelectorArray16( newcount
);
223 else /* mark the selectors as allocated */
225 for (i
= oldcount
; i
< newcount
; i
++)
226 ldt_flags_copy
[SELECTOR_TO_ENTRY(sel
)+i
] |=LDT_FLAGS_ALLOCATED
;
229 else if (oldcount
> newcount
) /* We need to remove selectors */
231 SELECTOR_FreeBlock( ENTRY_TO_SELECTOR(SELECTOR_TO_ENTRY(sel
)+newcount
),
232 oldcount
- newcount
);
234 if (sel
) SELECTOR_SetEntries( sel
, base
, size
, type
, is32bit
, readonly
);
239 /***********************************************************************
240 * PrestoChangoSelector (KERNEL.177)
242 WORD WINAPI
PrestoChangoSelector16( WORD selSrc
, WORD selDst
)
245 LDT_GetEntry( SELECTOR_TO_ENTRY( selSrc
), &entry
);
246 entry
.type
^= SEGMENT_CODE
; /* toggle the executable bit */
247 LDT_SetEntry( SELECTOR_TO_ENTRY( selDst
), &entry
);
252 /***********************************************************************
253 * AllocCStoDSAlias (KERNEL.170)
255 WORD WINAPI
AllocCStoDSAlias16( WORD sel
)
260 newsel
= AllocSelectorArray16( 1 );
261 TRACE(selector
, "(%04x): returning %04x\n",
263 if (!newsel
) return 0;
264 LDT_GetEntry( SELECTOR_TO_ENTRY(sel
), &entry
);
265 entry
.type
= SEGMENT_DATA
;
266 LDT_SetEntry( SELECTOR_TO_ENTRY(newsel
), &entry
);
271 /***********************************************************************
272 * AllocDStoCSAlias (KERNEL.171)
274 WORD WINAPI
AllocDStoCSAlias16( WORD sel
)
279 newsel
= AllocSelectorArray16( 1 );
280 TRACE(selector
, "(%04x): returning %04x\n",
282 if (!newsel
) return 0;
283 LDT_GetEntry( SELECTOR_TO_ENTRY(sel
), &entry
);
284 entry
.type
= SEGMENT_CODE
;
285 LDT_SetEntry( SELECTOR_TO_ENTRY(newsel
), &entry
);
290 /***********************************************************************
291 * LongPtrAdd (KERNEL.180)
293 void WINAPI
LongPtrAdd16( DWORD ptr
, DWORD add
)
296 LDT_GetEntry( SELECTOR_TO_ENTRY(SELECTOROF(ptr
)), &entry
);
298 LDT_SetEntry( SELECTOR_TO_ENTRY(SELECTOROF(ptr
)), &entry
);
302 /***********************************************************************
303 * GetSelectorBase (KERNEL.186)
305 DWORD WINAPI
WIN16_GetSelectorBase( WORD sel
)
308 * Note: For Win32s processes, the whole linear address space is
309 * shifted by 0x10000 relative to the OS linear address space.
310 * See the comment in msdos/vxd.c.
313 DWORD base
= GetSelectorBase( sel
);
314 return W32S_WINE2APP( base
, W32S_APPLICATION() ? W32S_OFFSET
: 0 );
316 DWORD WINAPI
GetSelectorBase( WORD sel
)
318 DWORD base
= GET_SEL_BASE(sel
);
320 /* if base points into DOSMEM, assume we have to
321 * return pointer into physical lower 1MB */
323 return DOSMEM_MapLinearToDos( (LPVOID
)base
);
327 /***********************************************************************
328 * SetSelectorBase (KERNEL.187)
330 DWORD WINAPI
WIN16_SetSelectorBase( WORD sel
, DWORD base
)
333 * Note: For Win32s processes, the whole linear address space is
334 * shifted by 0x10000 relative to the OS linear address space.
335 * See the comment in msdos/vxd.c.
338 SetSelectorBase( sel
,
339 W32S_APP2WINE( base
, W32S_APPLICATION() ? W32S_OFFSET
: 0 ) );
342 WORD WINAPI
SetSelectorBase( WORD sel
, DWORD base
)
346 LDT_GetEntry( SELECTOR_TO_ENTRY(sel
), &entry
);
348 entry
.base
= (DWORD
)DOSMEM_MapDosToLinear(base
);
350 LDT_SetEntry( SELECTOR_TO_ENTRY(sel
), &entry
);
355 /***********************************************************************
356 * GetSelectorLimit (KERNEL.188)
358 DWORD WINAPI
GetSelectorLimit16( WORD sel
)
360 return GET_SEL_LIMIT(sel
);
364 /***********************************************************************
365 * SetSelectorLimit (KERNEL.189)
367 WORD WINAPI
SetSelectorLimit16( WORD sel
, DWORD limit
)
370 LDT_GetEntry( SELECTOR_TO_ENTRY(sel
), &entry
);
371 entry
.limit_in_pages
= (limit
>= 0x100000);
372 if (entry
.limit_in_pages
) entry
.limit
= limit
>> 12;
373 else entry
.limit
= limit
;
374 LDT_SetEntry( SELECTOR_TO_ENTRY(sel
), &entry
);
379 /***********************************************************************
380 * SelectorAccessRights (KERNEL.196)
382 WORD WINAPI
SelectorAccessRights16( WORD sel
, WORD op
, WORD val
)
385 LDT_GetEntry( SELECTOR_TO_ENTRY(sel
), &entry
);
386 if (op
== 0) /* get */
388 return 0x01 | /* accessed */
389 0x10 | /* not system */
392 ((entry
.read_only
== 0) << 1) |
394 (entry
.seg_32bit
<< 14) |
395 (entry
.limit_in_pages
<< 15);
399 entry
.read_only
= ((val
& 2) == 0);
400 entry
.type
= (val
>> 2) & 3;
401 entry
.seg_32bit
= val
& 0x4000;
402 entry
.limit_in_pages
= val
& 0x8000;
403 LDT_SetEntry( SELECTOR_TO_ENTRY(sel
), &entry
);
409 /***********************************************************************
410 * IsBadCodePtr16 (KERNEL.336)
412 BOOL16 WINAPI
IsBadCodePtr16( SEGPTR lpfn
)
417 sel
= SELECTOROF(lpfn
);
418 if (!sel
) return TRUE
;
419 if (IS_SELECTOR_FREE(sel
)) return TRUE
;
420 LDT_GetEntry( SELECTOR_TO_ENTRY(sel
), &entry
);
421 if (entry
.type
!= SEGMENT_CODE
) return TRUE
;
422 if (OFFSETOF(lpfn
) > GET_SEL_LIMIT(sel
)) return TRUE
;
427 /***********************************************************************
428 * IsBadStringPtr16 (KERNEL.337)
430 BOOL16 WINAPI
IsBadStringPtr16( SEGPTR ptr
, UINT16 size
)
435 sel
= SELECTOROF(ptr
);
436 if (!sel
) return TRUE
;
437 if (IS_SELECTOR_FREE(sel
)) return TRUE
;
438 LDT_GetEntry( SELECTOR_TO_ENTRY(sel
), &entry
);
439 if ((entry
.type
== SEGMENT_CODE
) && entry
.read_only
) return TRUE
;
440 if (strlen(PTR_SEG_TO_LIN(ptr
)) < size
) size
= strlen(PTR_SEG_TO_LIN(ptr
));
441 if (OFFSETOF(ptr
) + size
- 1 > GET_SEL_LIMIT(sel
)) return TRUE
;
446 /***********************************************************************
447 * IsBadHugeReadPtr16 (KERNEL.346)
449 BOOL16 WINAPI
IsBadHugeReadPtr16( SEGPTR ptr
, DWORD size
)
454 sel
= SELECTOROF(ptr
);
455 if (!sel
) return TRUE
;
456 if (IS_SELECTOR_FREE(sel
)) return TRUE
;
457 LDT_GetEntry( SELECTOR_TO_ENTRY(sel
), &entry
);
458 if ((entry
.type
== SEGMENT_CODE
) && entry
.read_only
) return TRUE
;
459 if (OFFSETOF(ptr
) + size
- 1 > GET_SEL_LIMIT(sel
)) return TRUE
;
464 /***********************************************************************
465 * IsBadHugeWritePtr16 (KERNEL.347)
467 BOOL16 WINAPI
IsBadHugeWritePtr16( SEGPTR ptr
, DWORD size
)
472 sel
= SELECTOROF(ptr
);
473 if (!sel
) return TRUE
;
474 if (IS_SELECTOR_FREE(sel
)) return TRUE
;
475 LDT_GetEntry( SELECTOR_TO_ENTRY(sel
), &entry
);
476 if ((entry
.type
== SEGMENT_CODE
) || entry
.read_only
) return TRUE
;
477 if (OFFSETOF(ptr
) + size
- 1 > GET_SEL_LIMIT(sel
)) return TRUE
;
481 /***********************************************************************
482 * IsBadReadPtr16 (KERNEL.334)
484 BOOL16 WINAPI
IsBadReadPtr16( SEGPTR ptr
, UINT16 size
)
486 return IsBadHugeReadPtr16( ptr
, size
);
490 /***********************************************************************
491 * IsBadWritePtr16 (KERNEL.335)
493 BOOL16 WINAPI
IsBadWritePtr16( SEGPTR ptr
, UINT16 size
)
495 return IsBadHugeWritePtr16( ptr
, size
);
499 /***********************************************************************
500 * MemoryRead (TOOLHELP.78)
502 DWORD WINAPI
MemoryRead16( WORD sel
, DWORD offset
, void *buffer
, DWORD count
)
504 if (IS_SELECTOR_FREE(sel
)) return 0;
505 if (offset
> GET_SEL_LIMIT(sel
)) return 0;
506 if (offset
+ count
> GET_SEL_LIMIT(sel
) + 1)
507 count
= GET_SEL_LIMIT(sel
) + 1 - offset
;
508 memcpy( buffer
, ((char *)GET_SEL_BASE(sel
)) + offset
, count
);
513 /***********************************************************************
514 * MemoryWrite (TOOLHELP.79)
516 DWORD WINAPI
MemoryWrite16( WORD sel
, DWORD offset
, void *buffer
, DWORD count
)
518 if (IS_SELECTOR_FREE(sel
)) return 0;
519 if (offset
> GET_SEL_LIMIT(sel
)) return 0;
520 if (offset
+ count
> GET_SEL_LIMIT(sel
) + 1)
521 count
= GET_SEL_LIMIT(sel
) + 1 - offset
;
522 memcpy( ((char *)GET_SEL_BASE(sel
)) + offset
, buffer
, count
);
526 /************************************* Win95 pointer mapping functions *
530 /***********************************************************************
531 * MapSL (KERNEL32.523)
533 * Maps fixed segmented pointer to linear.
535 LPVOID WINAPI
MapSL( SEGPTR sptr
)
537 return (LPVOID
)PTR_SEG_TO_LIN(sptr
);
540 /***********************************************************************
541 * MapSLFix (KERNEL32.524)
543 * FIXME: MapSLFix and UnMapSLFixArray should probably prevent
544 * unexpected linear address change when GlobalCompact() shuffles
548 LPVOID WINAPI
MapSLFix( SEGPTR sptr
)
550 return (LPVOID
)PTR_SEG_TO_LIN(sptr
);
553 /***********************************************************************
554 * UnMapSLFixArray (KERNEL32.701)
557 REGS_ENTRYPOINT(UnMapSLFixArray
) /* SEGPTR sptr[], INT32 length */
559 /* Must not change EAX, hence defined as 'register' function */
560 /* We need to remove the arguments ourselves */
561 ESP_reg( context
) += 8;
564 /***********************************************************************
565 * MapLS (KERNEL32.522)
567 * Maps linear pointer to segmented.
569 SEGPTR WINAPI
MapLS( LPVOID ptr
)
575 WORD sel
= SELECTOR_AllocBlock( ptr
, 0x10000, SEGMENT_DATA
, FALSE
, FALSE
);
576 return PTR_SEG_OFF_TO_SEGPTR( sel
, 0 );
581 /***********************************************************************
582 * UnMapLS (KERNEL32.700)
584 * Free mapped selector.
586 void WINAPI
UnMapLS( SEGPTR sptr
)
588 if (SELECTOROF(sptr
))
589 SELECTOR_FreeBlock( SELECTOROF(sptr
), 1 );
592 /***********************************************************************
593 * GetThreadSelectorEntry (KERNEL32)
594 * FIXME: add #ifdef i386 for non x86
596 BOOL WINAPI
GetThreadSelectorEntry( HANDLE hthread
, DWORD sel
,
601 LDT_GetEntry(SELECTOR_TO_ENTRY(sel
),&ldtentry
);
602 ldtent
->BaseLow
= ldtentry
.base
& 0x0000ffff;
603 ldtent
->HighWord
.Bits
.BaseMid
= (ldtentry
.base
& 0x00ff0000) >> 16;
604 ldtent
->HighWord
.Bits
.BaseHi
= (ldtentry
.base
& 0xff000000) >> 24;
605 ldtent
->LimitLow
= ldtentry
.limit
& 0x0000ffff;
606 ldtent
->HighWord
.Bits
.LimitHi
= (ldtentry
.limit
& 0x00ff0000) >> 16;
607 ldtent
->HighWord
.Bits
.Dpl
= 3;
608 ldtent
->HighWord
.Bits
.Sys
= 0;
609 ldtent
->HighWord
.Bits
.Pres
= 1;
610 ldtent
->HighWord
.Bits
.Type
= 0x10|(ldtentry
.type
<< 2);
611 if (ldtentry
.read_only
)
612 ldtent
->HighWord
.Bits
.Type
|=0x2;
613 ldtent
->HighWord
.Bits
.Granularity
= ldtentry
.limit_in_pages
;
614 ldtent
->HighWord
.Bits
.Default_Big
= ldtentry
.seg_32bit
;
619 /**********************************************************************
621 * These functions map linear pointers at [EBP+xxx] to segmented pointers
623 * Win95 uses some kind of alias structs, which it stores in [EBP+x] to
624 * unravel them at SUnMapLS. We just store the segmented pointer there.
627 x_SMapLS_IP_EBP_x(CONTEXT
*context
,int argoff
) {
630 val
=*(DWORD
*)(EBP_reg(context
)+argoff
);
633 *(DWORD
*)(EBP_reg(context
)+argoff
) = 0;
635 ptr
= MapLS((LPVOID
)val
);
636 *(DWORD
*)(EBP_reg(context
)+argoff
) = ptr
;
638 EAX_reg(context
) = ptr
;
641 REGS_ENTRYPOINT(SMapLS_IP_EBP_8
) {x_SMapLS_IP_EBP_x(context
,8);}
642 REGS_ENTRYPOINT(SMapLS_IP_EBP_12
) {x_SMapLS_IP_EBP_x(context
,12);}
643 REGS_ENTRYPOINT(SMapLS_IP_EBP_16
) {x_SMapLS_IP_EBP_x(context
,16);}
644 REGS_ENTRYPOINT(SMapLS_IP_EBP_20
) {x_SMapLS_IP_EBP_x(context
,20);}
645 REGS_ENTRYPOINT(SMapLS_IP_EBP_24
) {x_SMapLS_IP_EBP_x(context
,24);}
646 REGS_ENTRYPOINT(SMapLS_IP_EBP_28
) {x_SMapLS_IP_EBP_x(context
,28);}
647 REGS_ENTRYPOINT(SMapLS_IP_EBP_32
) {x_SMapLS_IP_EBP_x(context
,32);}
648 REGS_ENTRYPOINT(SMapLS_IP_EBP_36
) {x_SMapLS_IP_EBP_x(context
,36);}
649 REGS_ENTRYPOINT(SMapLS_IP_EBP_40
) {x_SMapLS_IP_EBP_x(context
,40);}
651 REGS_ENTRYPOINT(SMapLS
)
653 if (EAX_reg(context
)>=0x10000) {
654 EAX_reg(context
) = MapLS((LPVOID
)EAX_reg(context
));
655 EDX_reg(context
) = EAX_reg(context
);
657 EDX_reg(context
) = 0;
661 REGS_ENTRYPOINT(SUnMapLS
)
663 if (EAX_reg(context
)>=0x10000)
664 UnMapLS((SEGPTR
)EAX_reg(context
));
668 x_SUnMapLS_IP_EBP_x(CONTEXT
*context
,int argoff
) {
669 if (*(DWORD
*)(EBP_reg(context
)+argoff
))
670 UnMapLS(*(DWORD
*)(EBP_reg(context
)+argoff
));
671 *(DWORD
*)(EBP_reg(context
)+argoff
)=0;
673 REGS_ENTRYPOINT(SUnMapLS_IP_EBP_8
) { x_SUnMapLS_IP_EBP_x(context
,8); }
674 REGS_ENTRYPOINT(SUnMapLS_IP_EBP_12
) { x_SUnMapLS_IP_EBP_x(context
,12); }
675 REGS_ENTRYPOINT(SUnMapLS_IP_EBP_16
) { x_SUnMapLS_IP_EBP_x(context
,16); }
676 REGS_ENTRYPOINT(SUnMapLS_IP_EBP_20
) { x_SUnMapLS_IP_EBP_x(context
,20); }
677 REGS_ENTRYPOINT(SUnMapLS_IP_EBP_24
) { x_SUnMapLS_IP_EBP_x(context
,24); }
678 REGS_ENTRYPOINT(SUnMapLS_IP_EBP_28
) { x_SUnMapLS_IP_EBP_x(context
,28); }
679 REGS_ENTRYPOINT(SUnMapLS_IP_EBP_32
) { x_SUnMapLS_IP_EBP_x(context
,32); }
680 REGS_ENTRYPOINT(SUnMapLS_IP_EBP_36
) { x_SUnMapLS_IP_EBP_x(context
,36); }
681 REGS_ENTRYPOINT(SUnMapLS_IP_EBP_40
) { x_SUnMapLS_IP_EBP_x(context
,40); }
683 /**********************************************************************
684 * AllocMappedBuffer (KERNEL32.38)
686 * This is a undocumented KERNEL32 function that
687 * SMapLS's a GlobalAlloc'ed buffer.
689 * Input: EDI register: size of buffer to allocate
690 * Output: EDI register: pointer to buffer
692 * Note: The buffer is preceeded by 8 bytes:
695 * edi-4 SEGPTR to buffer
696 * edi-8 some magic Win95 needs for SUnMapLS
697 * (we use it for the memory handle)
699 * The SEGPTR is used by the caller!
702 REGS_ENTRYPOINT(AllocMappedBuffer
)
704 HGLOBAL handle
= GlobalAlloc(0, EDI_reg(context
) + 8);
705 DWORD
*buffer
= (DWORD
*)GlobalLock(handle
);
709 if (!(ptr
= MapLS(buffer
+ 2)))
711 GlobalUnlock(handle
);
716 EAX_reg(context
) = EDI_reg(context
) = 0;
722 EAX_reg(context
) = (DWORD
) ptr
;
723 EDI_reg(context
) = (DWORD
)(buffer
+ 2);
727 /**********************************************************************
728 * FreeMappedBuffer (KERNEL32.39)
730 * Free a buffer allocated by AllocMappedBuffer
732 * Input: EDI register: pointer to buffer
735 REGS_ENTRYPOINT(FreeMappedBuffer
)
737 if (EDI_reg(context
))
739 DWORD
*buffer
= (DWORD
*)EDI_reg(context
) - 2;
743 GlobalUnlock(buffer
[0]);
744 GlobalFree(buffer
[0]);
748 /**********************************************************************
749 * WOWGetVDMPointer (KERNEL32.55)
750 * Get linear from segmented pointer. (MSDN lib)
752 LPVOID WINAPI
WOWGetVDMPointer(DWORD vp
,DWORD nrofbytes
,BOOL
protected)
754 /* FIXME: add size check too */
756 return PTR_SEG_TO_LIN(vp
);
758 return DOSMEM_MapRealToLinear(vp
);
761 /**********************************************************************
762 * GetVDMPointer32W (KERNEL.516)
764 LPVOID WINAPI
GetVDMPointer32W(DWORD vp
,WORD mode
)
766 return WOWGetVDMPointer(vp
,0,(DWORD
)mode
);
769 /**********************************************************************
770 * WOWGetVDMPointerFix (KERNEL32.55)
771 * Dito, but fix heapsegment (MSDN lib)
773 LPVOID WINAPI
WOWGetVDMPointerFix(DWORD vp
,DWORD nrofbytes
,BOOL
protected)
775 /* FIXME: fix heapsegment */
776 return WOWGetVDMPointer(vp
,nrofbytes
,protected);
779 /**********************************************************************
780 * WOWGetVDMPointerUnFix (KERNEL32.56)
782 void WINAPI
WOWGetVDMPointerUnfix(DWORD vp
)
784 /* FIXME: unfix heapsegment */
787 /***********************************************************************
788 * UTSelectorOffsetToLinear (WIN32S16.48)
790 * rough guesswork, but seems to work (I had no "reasonable" docu)
792 LPVOID WINAPI
UTSelectorOffsetToLinear16(SEGPTR sptr
)
794 return PTR_SEG_TO_LIN(sptr
);
797 /***********************************************************************
798 * UTLinearToSelectorOffset (WIN32S16.49)
800 * FIXME: I don't know if that's the right way to do linear -> segmented
802 SEGPTR WINAPI
UTLinearToSelectorOffset16(LPVOID lptr
)