Moved 16-bit global heap, DOS memory and selector functions to
[wine] / dlls / kernel / selector.c
1 /*
2  * Selector manipulation functions
3  *
4  * Copyright 1995 Alexandre Julliard
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22 #include "wine/port.h"
23
24 #include <string.h>
25
26 #include "winerror.h"
27 #include "wine/winbase16.h"
28 #include "miscemu.h"
29 #include "selectors.h"
30 #include "wine/server.h"
31 #include "wine/debug.h"
32 #include "toolhelp.h"
33
34 WINE_DEFAULT_DEBUG_CHANNEL(selector);
35
36 #define LDT_SIZE 8192
37
38 /* get the number of selectors needed to cover up to the selector limit */
39 inline static WORD get_sel_count( WORD sel )
40 {
41     return (wine_ldt_copy.limit[sel >> __AHSHIFT] >> 16) + 1;
42 }
43
44
45 /***********************************************************************
46  *           AllocSelectorArray   (KERNEL.206)
47  */
48 WORD WINAPI AllocSelectorArray16( WORD count )
49 {
50     WORD i, sel = wine_ldt_alloc_entries( count );
51
52     if (sel)
53     {
54         LDT_ENTRY entry;
55         wine_ldt_set_base( &entry, 0 );
56         wine_ldt_set_limit( &entry, 1 ); /* avoid 0 base and limit */
57         wine_ldt_set_flags( &entry, WINE_LDT_FLAGS_DATA );
58         for (i = 0; i < count; i++) wine_ldt_set_entry( sel + (i << __AHSHIFT), &entry );
59     }
60     return sel;
61 }
62
63
64 /***********************************************************************
65  *           AllocSelector   (KERNEL.175)
66  */
67 WORD WINAPI AllocSelector16( WORD sel )
68 {
69     WORD newsel, count, i;
70
71     count = sel ? get_sel_count(sel) : 1;
72     newsel = wine_ldt_alloc_entries( count );
73     TRACE("(%04x): returning %04x\n", sel, newsel );
74     if (!newsel) return 0;
75     if (!sel) return newsel;  /* nothing to copy */
76     for (i = 0; i < count; i++)
77     {
78         LDT_ENTRY entry;
79         wine_ldt_get_entry( sel + (i << __AHSHIFT), &entry );
80         wine_ldt_set_entry( newsel + (i << __AHSHIFT), &entry );
81     }
82     return newsel;
83 }
84
85
86 /***********************************************************************
87  *           FreeSelector   (KERNEL.176)
88  */
89 WORD WINAPI FreeSelector16( WORD sel )
90 {
91     LDT_ENTRY entry;
92
93     wine_ldt_get_entry( sel, &entry );
94     if (wine_ldt_is_empty( &entry )) return sel;  /* error */
95 #ifdef __i386__
96     /* Check if we are freeing current %fs selector */
97     if (!((wine_get_fs() ^ sel) & ~3))
98         WARN("Freeing %%fs selector (%04x), not good.\n", wine_get_fs() );
99 #endif  /* __i386__ */
100     wine_ldt_free_entries( sel, 1 );
101     return 0;
102 }
103
104
105 /***********************************************************************
106  *           SELECTOR_SetEntries
107  *
108  * Set the LDT entries for an array of selectors.
109  */
110 static void SELECTOR_SetEntries( WORD sel, const void *base, DWORD size, unsigned char flags )
111 {
112     LDT_ENTRY entry;
113     WORD i, count;
114
115     wine_ldt_set_base( &entry, base );
116     wine_ldt_set_limit( &entry, size - 1 );
117     wine_ldt_set_flags( &entry, flags );
118     count = (size + 0xffff) / 0x10000;
119     for (i = 0; i < count; i++)
120     {
121         wine_ldt_set_entry( sel + (i << __AHSHIFT), &entry );
122         wine_ldt_set_base( &entry, (char*)wine_ldt_get_base(&entry) + 0x10000);
123         /* yep, Windows sets limit like that, not 64K sel units */
124         wine_ldt_set_limit( &entry, wine_ldt_get_limit(&entry) - 0x10000 );
125     }
126 }
127
128
129 /***********************************************************************
130  *           SELECTOR_AllocBlock
131  *
132  * Allocate selectors for a block of linear memory.
133  */
134 WORD SELECTOR_AllocBlock( const void *base, DWORD size, unsigned char flags )
135 {
136     WORD sel, count;
137
138     if (!size) return 0;
139     count = (size + 0xffff) / 0x10000;
140     sel = wine_ldt_alloc_entries( count );
141     if (sel) SELECTOR_SetEntries( sel, base, size, flags );
142     return sel;
143 }
144
145
146 /***********************************************************************
147  *           SELECTOR_FreeBlock
148  *
149  * Free a block of selectors.
150  */
151 void SELECTOR_FreeBlock( WORD sel )
152 {
153     WORD i, count = get_sel_count( sel );
154
155     TRACE("(%04x,%d)\n", sel, count );
156     for (i = 0; i < count; i++) FreeSelector16( sel + (i << __AHSHIFT) );
157 }
158
159
160 /***********************************************************************
161  *           SELECTOR_ReallocBlock
162  *
163  * Change the size of a block of selectors.
164  */
165 WORD SELECTOR_ReallocBlock( WORD sel, const void *base, DWORD size )
166 {
167     LDT_ENTRY entry;
168     int oldcount, newcount;
169
170     if (!size) size = 1;
171     wine_ldt_get_entry( sel, &entry );
172     oldcount = (wine_ldt_get_limit(&entry) >> 16) + 1;
173     newcount = (size + 0xffff) >> 16;
174
175     sel = wine_ldt_realloc_entries( sel, oldcount, newcount );
176     if (sel) SELECTOR_SetEntries( sel, base, size, wine_ldt_get_flags(&entry) );
177     return sel;
178 }
179
180
181 /***********************************************************************
182  *           PrestoChangoSelector   (KERNEL.177)
183  */
184 WORD WINAPI PrestoChangoSelector16( WORD selSrc, WORD selDst )
185 {
186     LDT_ENTRY entry;
187     wine_ldt_get_entry( selSrc, &entry );
188     /* toggle the executable bit */
189     entry.HighWord.Bits.Type ^= (WINE_LDT_FLAGS_CODE ^ WINE_LDT_FLAGS_DATA);
190     wine_ldt_set_entry( selDst, &entry );
191     return selDst;
192 }
193
194
195 /***********************************************************************
196  *           AllocCStoDSAlias   (KERNEL.170)
197  *           AllocAlias         (KERNEL.172)
198  */
199 WORD WINAPI AllocCStoDSAlias16( WORD sel )
200 {
201     WORD newsel;
202     LDT_ENTRY entry;
203
204     newsel = wine_ldt_alloc_entries( 1 );
205     TRACE("(%04x): returning %04x\n",
206                       sel, newsel );
207     if (!newsel) return 0;
208     wine_ldt_get_entry( sel, &entry );
209     entry.HighWord.Bits.Type = WINE_LDT_FLAGS_DATA;
210     wine_ldt_set_entry( newsel, &entry );
211     return newsel;
212 }
213
214
215 /***********************************************************************
216  *           AllocDStoCSAlias   (KERNEL.171)
217  */
218 WORD WINAPI AllocDStoCSAlias16( WORD sel )
219 {
220     WORD newsel;
221     LDT_ENTRY entry;
222
223     newsel = wine_ldt_alloc_entries( 1 );
224     TRACE("(%04x): returning %04x\n",
225                       sel, newsel );
226     if (!newsel) return 0;
227     wine_ldt_get_entry( sel, &entry );
228     entry.HighWord.Bits.Type = WINE_LDT_FLAGS_CODE;
229     wine_ldt_set_entry( newsel, &entry );
230     return newsel;
231 }
232
233
234 /***********************************************************************
235  *           LongPtrAdd   (KERNEL.180)
236  */
237 void WINAPI LongPtrAdd16( DWORD ptr, DWORD add )
238 {
239     LDT_ENTRY entry;
240     wine_ldt_get_entry( SELECTOROF(ptr), &entry );
241     wine_ldt_set_base( &entry, (char *)wine_ldt_get_base(&entry) + add );
242     wine_ldt_set_entry( SELECTOROF(ptr), &entry );
243 }
244
245
246 /***********************************************************************
247  *             GetSelectorBase   (KERNEL.186)
248  */
249 DWORD WINAPI GetSelectorBase( WORD sel )
250 {
251     void *base = wine_ldt_copy.base[sel >> __AHSHIFT];
252
253     /* if base points into DOSMEM, assume we have to
254      * return pointer into physical lower 1MB */
255
256     return DOSMEM_MapLinearToDos( base );
257 }
258
259
260 /***********************************************************************
261  *             SetSelectorBase   (KERNEL.187)
262  */
263 WORD WINAPI SetSelectorBase( WORD sel, DWORD base )
264 {
265     LDT_ENTRY entry;
266     wine_ldt_get_entry( sel, &entry );
267     wine_ldt_set_base( &entry, DOSMEM_MapDosToLinear(base) );
268     wine_ldt_set_entry( sel, &entry );
269     return sel;
270 }
271
272
273 /***********************************************************************
274  *           GetSelectorLimit   (KERNEL.188)
275  */
276 DWORD WINAPI GetSelectorLimit16( WORD sel )
277 {
278     return wine_ldt_copy.limit[sel >> __AHSHIFT];
279 }
280
281
282 /***********************************************************************
283  *           SetSelectorLimit   (KERNEL.189)
284  */
285 WORD WINAPI SetSelectorLimit16( WORD sel, DWORD limit )
286 {
287     LDT_ENTRY entry;
288     wine_ldt_get_entry( sel, &entry );
289     wine_ldt_set_limit( &entry, limit );
290     wine_ldt_set_entry( sel, &entry );
291     return sel;
292 }
293
294
295 /***********************************************************************
296  *           SelectorAccessRights   (KERNEL.196)
297  */
298 WORD WINAPI SelectorAccessRights16( WORD sel, WORD op, WORD val )
299 {
300     LDT_ENTRY entry;
301     wine_ldt_get_entry( sel, &entry );
302
303     if (op == 0)  /* get */
304     {
305         return entry.HighWord.Bytes.Flags1 | ((entry.HighWord.Bytes.Flags2 << 8) & 0xf0);
306     }
307     else  /* set */
308     {
309         entry.HighWord.Bytes.Flags1 = LOBYTE(val) | 0xf0;
310         entry.HighWord.Bytes.Flags2 = (entry.HighWord.Bytes.Flags2 & 0x0f) | (HIBYTE(val) & 0xf0);
311         wine_ldt_set_entry( sel, &entry );
312         return 0;
313     }
314 }
315
316
317 /***********************************************************************
318  *           IsBadCodePtr   (KERNEL.336)
319  */
320 BOOL16 WINAPI IsBadCodePtr16( SEGPTR lpfn )
321 {
322     WORD sel;
323     LDT_ENTRY entry;
324
325     sel = SELECTOROF(lpfn);
326     if (!sel) return TRUE;
327     wine_ldt_get_entry( sel, &entry );
328     if (wine_ldt_is_empty( &entry )) return TRUE;
329     /* check for code segment, ignoring conforming, read-only and accessed bits */
330     if ((entry.HighWord.Bits.Type ^ WINE_LDT_FLAGS_CODE) & 0x18) return TRUE;
331     if (OFFSETOF(lpfn) > wine_ldt_get_limit(&entry)) return TRUE;
332     return FALSE;
333 }
334
335
336 /***********************************************************************
337  *           IsBadStringPtr   (KERNEL.337)
338  */
339 BOOL16 WINAPI IsBadStringPtr16( SEGPTR ptr, UINT16 size )
340 {
341     WORD sel;
342     LDT_ENTRY entry;
343
344     sel = SELECTOROF(ptr);
345     if (!sel) return TRUE;
346     wine_ldt_get_entry( sel, &entry );
347     if (wine_ldt_is_empty( &entry )) return TRUE;
348     /* check for data or readable code segment */
349     if (!(entry.HighWord.Bits.Type & 0x10)) return TRUE;  /* system descriptor */
350     if ((entry.HighWord.Bits.Type & 0x0a) == 0x08) return TRUE;  /* non-readable code segment */
351     if (strlen(MapSL(ptr)) < size) size = strlen(MapSL(ptr)) + 1;
352     if (size && (OFFSETOF(ptr) + size - 1 > wine_ldt_get_limit(&entry))) return TRUE;
353     return FALSE;
354 }
355
356
357 /***********************************************************************
358  *           IsBadHugeReadPtr   (KERNEL.346)
359  */
360 BOOL16 WINAPI IsBadHugeReadPtr16( SEGPTR ptr, DWORD size )
361 {
362     WORD sel;
363     LDT_ENTRY entry;
364
365     sel = SELECTOROF(ptr);
366     if (!sel) return TRUE;
367     wine_ldt_get_entry( sel, &entry );
368     if (wine_ldt_is_empty( &entry )) return TRUE;
369     /* check for data or readable code segment */
370     if (!(entry.HighWord.Bits.Type & 0x10)) return TRUE;  /* system descriptor */
371     if ((entry.HighWord.Bits.Type & 0x0a) == 0x08) return TRUE;  /* non-readable code segment */
372     if (size && (OFFSETOF(ptr) + size - 1 > wine_ldt_get_limit( &entry ))) return TRUE;
373     return FALSE;
374 }
375
376
377 /***********************************************************************
378  *           IsBadHugeWritePtr   (KERNEL.347)
379  */
380 BOOL16 WINAPI IsBadHugeWritePtr16( SEGPTR ptr, DWORD size )
381 {
382     WORD sel;
383     LDT_ENTRY entry;
384
385     sel = SELECTOROF(ptr);
386     if (!sel) return TRUE;
387     wine_ldt_get_entry( sel, &entry );
388     if (wine_ldt_is_empty( &entry )) return TRUE;
389     /* check for writeable data segment, ignoring expand-down and accessed flags */
390     if ((entry.HighWord.Bits.Type ^ WINE_LDT_FLAGS_DATA) & ~5) return TRUE;
391     if (size && (OFFSETOF(ptr) + size - 1 > wine_ldt_get_limit( &entry ))) return TRUE;
392     return FALSE;
393 }
394
395 /***********************************************************************
396  *           IsBadReadPtr   (KERNEL.334)
397  */
398 BOOL16 WINAPI IsBadReadPtr16( SEGPTR ptr, UINT16 size )
399 {
400     return IsBadHugeReadPtr16( ptr, size );
401 }
402
403
404 /***********************************************************************
405  *           IsBadWritePtr   (KERNEL.335)
406  */
407 BOOL16 WINAPI IsBadWritePtr16( SEGPTR ptr, UINT16 size )
408 {
409     return IsBadHugeWritePtr16( ptr, size );
410 }
411
412
413 /***********************************************************************
414  *           IsBadFlatReadWritePtr   (KERNEL.627)
415  */
416 BOOL16 WINAPI IsBadFlatReadWritePtr16( SEGPTR ptr, DWORD size, BOOL16 bWrite )
417 {
418     return bWrite? IsBadHugeWritePtr16( ptr, size )
419                  : IsBadHugeReadPtr16( ptr, size );
420 }
421
422
423 /***********************************************************************
424  *           MemoryRead   (TOOLHELP.78)
425  */
426 DWORD WINAPI MemoryRead16( WORD sel, DWORD offset, void *buffer, DWORD count )
427 {
428     LDT_ENTRY entry;
429     DWORD limit;
430
431     wine_ldt_get_entry( sel, &entry );
432     if (wine_ldt_is_empty( &entry )) return 0;
433     limit = wine_ldt_get_limit( &entry );
434     if (offset > limit) return 0;
435     if (offset + count > limit + 1) count = limit + 1 - offset;
436     memcpy( buffer, (char *)wine_ldt_get_base(&entry) + offset, count );
437     return count;
438 }
439
440
441 /***********************************************************************
442  *           MemoryWrite   (TOOLHELP.79)
443  */
444 DWORD WINAPI MemoryWrite16( WORD sel, DWORD offset, void *buffer, DWORD count )
445 {
446     LDT_ENTRY entry;
447     DWORD limit;
448
449     wine_ldt_get_entry( sel, &entry );
450     if (wine_ldt_is_empty( &entry )) return 0;
451     limit = wine_ldt_get_limit( &entry );
452     if (offset > limit) return 0;
453     if (offset + count > limit) count = limit + 1 - offset;
454     memcpy( (char *)wine_ldt_get_base(&entry) + offset, buffer, count );
455     return count;
456 }
457
458 /************************************* Win95 pointer mapping functions *
459  *
460  */
461
462 struct mapls_entry
463 {
464     struct mapls_entry *next;
465     void               *addr;   /* linear address */
466     int                 count;  /* ref count */
467     WORD                sel;    /* selector */
468 };
469
470 static struct mapls_entry *first_entry;
471
472
473 /***********************************************************************
474  *           MapLS   (KERNEL32.@)
475  *           MapLS   (KERNEL.358)
476  *
477  * Maps linear pointer to segmented.
478  */
479 SEGPTR WINAPI MapLS( LPCVOID ptr )
480 {
481     struct mapls_entry *entry, *free = NULL;
482     void *base;
483     SEGPTR ret = 0;
484
485     if (!HIWORD(ptr)) return (SEGPTR)ptr;
486
487     base = (char *)ptr - ((unsigned int)ptr & 0x7fff);
488     HeapLock( GetProcessHeap() );
489     for (entry = first_entry; entry; entry = entry->next)
490     {
491         if (entry->addr == base) break;
492         if (!entry->count) free = entry;
493     }
494
495     if (!entry)
496     {
497         if (!free)  /* no free entry found, create a new one */
498         {
499             if (!(free = HeapAlloc( GetProcessHeap(), 0, sizeof(*free) ))) goto done;
500             if (!(free->sel = SELECTOR_AllocBlock( base, 0x10000, WINE_LDT_FLAGS_DATA )))
501             {
502                 HeapFree( GetProcessHeap(), 0, free );
503                 goto done;
504             }
505             free->count = 0;
506             free->next = first_entry;
507             first_entry = free;
508         }
509         SetSelectorBase( free->sel, (DWORD)base );
510         free->addr = base;
511         entry = free;
512     }
513     entry->count++;
514     ret = MAKESEGPTR( entry->sel, (char *)ptr - (char *)entry->addr );
515  done:
516     HeapUnlock( GetProcessHeap() );
517     return ret;
518 }
519
520 /***********************************************************************
521  *           UnMapLS   (KERNEL32.@)
522  *           UnMapLS   (KERNEL.359)
523  *
524  * Free mapped selector.
525  */
526 void WINAPI UnMapLS( SEGPTR sptr )
527 {
528     struct mapls_entry *entry;
529     WORD sel = SELECTOROF(sptr);
530
531     if (sel)
532     {
533         HeapLock( GetProcessHeap() );
534         for (entry = first_entry; entry; entry = entry->next) if (entry->sel == sel) break;
535         if (entry && entry->count > 0) entry->count--;
536         HeapUnlock( GetProcessHeap() );
537     }
538 }
539
540 /***********************************************************************
541  *           MapSL   (KERNEL32.@)
542  *           MapSL   (KERNEL.357)
543  *
544  * Maps fixed segmented pointer to linear.
545  */
546 LPVOID WINAPI MapSL( SEGPTR sptr )
547 {
548     return (char *)wine_ldt_copy.base[SELECTOROF(sptr) >> __AHSHIFT] + OFFSETOF(sptr);
549 }
550
551 /***********************************************************************
552  *           MapSLFix   (KERNEL32.@)
553  *
554  * FIXME: MapSLFix and UnMapSLFixArray should probably prevent
555  * unexpected linear address change when GlobalCompact() shuffles
556  * moveable blocks.
557  */
558
559 LPVOID WINAPI MapSLFix( SEGPTR sptr )
560 {
561     return MapSL(sptr);
562 }
563
564 /***********************************************************************
565  *           UnMapSLFixArray   (KERNEL32.@)
566  */
567
568 void WINAPI UnMapSLFixArray( SEGPTR sptr[], INT length, CONTEXT86 *context )
569 {
570     /* Must not change EAX, hence defined as 'register' function */
571 }
572
573 /***********************************************************************
574  *           GetThreadSelectorEntry   (KERNEL32.@)
575  */
576 BOOL WINAPI GetThreadSelectorEntry( HANDLE hthread, DWORD sel, LPLDT_ENTRY ldtent)
577 {
578 #ifdef __i386__
579     BOOL ret;
580
581     if (!(sel & 4))  /* GDT selector */
582     {
583         sel &= ~3;  /* ignore RPL */
584         if (!sel)  /* null selector */
585         {
586             memset( ldtent, 0, sizeof(*ldtent) );
587             return TRUE;
588         }
589         ldtent->BaseLow                   = 0;
590         ldtent->HighWord.Bits.BaseMid     = 0;
591         ldtent->HighWord.Bits.BaseHi      = 0;
592         ldtent->LimitLow                  = 0xffff;
593         ldtent->HighWord.Bits.LimitHi     = 0xf;
594         ldtent->HighWord.Bits.Dpl         = 3;
595         ldtent->HighWord.Bits.Sys         = 0;
596         ldtent->HighWord.Bits.Pres        = 1;
597         ldtent->HighWord.Bits.Granularity = 1;
598         ldtent->HighWord.Bits.Default_Big = 1;
599         ldtent->HighWord.Bits.Type        = 0x12;
600         /* it has to be one of the system GDT selectors */
601         if (sel == (wine_get_ds() & ~3)) return TRUE;
602         if (sel == (wine_get_ss() & ~3)) return TRUE;
603         if (sel == (wine_get_cs() & ~3))
604         {
605             ldtent->HighWord.Bits.Type |= 8;  /* code segment */
606             return TRUE;
607         }
608         SetLastError( ERROR_NOACCESS );
609         return FALSE;
610     }
611
612     SERVER_START_REQ( get_selector_entry )
613     {
614         req->handle = hthread;
615         req->entry = sel >> __AHSHIFT;
616         if ((ret = !wine_server_call_err( req )))
617         {
618             if (!(reply->flags & WINE_LDT_FLAGS_ALLOCATED))
619             {
620                 SetLastError( ERROR_MR_MID_NOT_FOUND );  /* sic */
621                 ret = FALSE;
622             }
623             else
624             {
625                 wine_ldt_set_base( ldtent, (void *)reply->base );
626                 wine_ldt_set_limit( ldtent, reply->limit );
627                 wine_ldt_set_flags( ldtent, reply->flags );
628             }
629         }
630     }
631     SERVER_END_REQ;
632     return ret;
633 #else
634     SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
635     return FALSE;
636 #endif
637 }
638
639
640 /**********************************************************************
641  *              SMapLS*         (KERNEL32)
642  * These functions map linear pointers at [EBP+xxx] to segmented pointers
643  * and return them.
644  * Win95 uses some kind of alias structs, which it stores in [EBP+x] to
645  * unravel them at SUnMapLS. We just store the segmented pointer there.
646  */
647 static void
648 x_SMapLS_IP_EBP_x(CONTEXT86 *context,int argoff) {
649     DWORD       val,ptr;
650
651     val =*(DWORD*)(context->Ebp + argoff);
652     if (val<0x10000) {
653         ptr=val;
654         *(DWORD*)(context->Ebp + argoff) = 0;
655     } else {
656         ptr = MapLS((LPVOID)val);
657         *(DWORD*)(context->Ebp + argoff) = ptr;
658     }
659     context->Eax = ptr;
660 }
661
662 /***********************************************************************
663  *              SMapLS_IP_EBP_8 (KERNEL32.@)
664  */
665 void WINAPI SMapLS_IP_EBP_8 (CONTEXT86 *context) {x_SMapLS_IP_EBP_x(context, 8);}
666
667 /***********************************************************************
668  *              SMapLS_IP_EBP_12 (KERNEL32.@)
669  */
670 void WINAPI SMapLS_IP_EBP_12(CONTEXT86 *context) {x_SMapLS_IP_EBP_x(context,12);}
671
672 /***********************************************************************
673  *              SMapLS_IP_EBP_16 (KERNEL32.@)
674  */
675 void WINAPI SMapLS_IP_EBP_16(CONTEXT86 *context) {x_SMapLS_IP_EBP_x(context,16);}
676
677 /***********************************************************************
678  *              SMapLS_IP_EBP_20 (KERNEL32.@)
679  */
680 void WINAPI SMapLS_IP_EBP_20(CONTEXT86 *context) {x_SMapLS_IP_EBP_x(context,20);}
681
682 /***********************************************************************
683  *              SMapLS_IP_EBP_24 (KERNEL32.@)
684  */
685 void WINAPI SMapLS_IP_EBP_24(CONTEXT86 *context) {x_SMapLS_IP_EBP_x(context,24);}
686
687 /***********************************************************************
688  *              SMapLS_IP_EBP_28 (KERNEL32.@)
689  */
690 void WINAPI SMapLS_IP_EBP_28(CONTEXT86 *context) {x_SMapLS_IP_EBP_x(context,28);}
691
692 /***********************************************************************
693  *              SMapLS_IP_EBP_32 (KERNEL32.@)
694  */
695 void WINAPI SMapLS_IP_EBP_32(CONTEXT86 *context) {x_SMapLS_IP_EBP_x(context,32);}
696
697 /***********************************************************************
698  *              SMapLS_IP_EBP_36 (KERNEL32.@)
699  */
700 void WINAPI SMapLS_IP_EBP_36(CONTEXT86 *context) {x_SMapLS_IP_EBP_x(context,36);}
701
702 /***********************************************************************
703  *              SMapLS_IP_EBP_40 (KERNEL32.@)
704  */
705 void WINAPI SMapLS_IP_EBP_40(CONTEXT86 *context) {x_SMapLS_IP_EBP_x(context,40);}
706
707 /***********************************************************************
708  *              SMapLS (KERNEL32.@)
709  */
710 void WINAPI SMapLS( CONTEXT86 *context )
711 {
712     if (HIWORD(context->Eax))
713     {
714         context->Eax = MapLS( (LPVOID)context->Eax );
715         context->Edx = context->Eax;
716     } else {
717         context->Edx = 0;
718     }
719 }
720
721 /***********************************************************************
722  *              SUnMapLS (KERNEL32.@)
723  */
724
725 void WINAPI SUnMapLS( CONTEXT86 *context )
726 {
727     if (HIWORD(context->Eax)) UnMapLS( (SEGPTR)context->Eax );
728 }
729
730 inline static void x_SUnMapLS_IP_EBP_x(CONTEXT86 *context,int argoff)
731 {
732     SEGPTR *ptr = (SEGPTR *)(context->Ebp + argoff);
733     if (*ptr)
734     {
735         UnMapLS( *ptr );
736         *ptr = 0;
737     }
738 }
739
740 /***********************************************************************
741  *              SUnMapLS_IP_EBP_8 (KERNEL32.@)
742  */
743 void WINAPI SUnMapLS_IP_EBP_8 (CONTEXT86 *context) { x_SUnMapLS_IP_EBP_x(context, 8); }
744
745 /***********************************************************************
746  *              SUnMapLS_IP_EBP_12 (KERNEL32.@)
747  */
748 void WINAPI SUnMapLS_IP_EBP_12(CONTEXT86 *context) { x_SUnMapLS_IP_EBP_x(context,12); }
749
750 /***********************************************************************
751  *              SUnMapLS_IP_EBP_16 (KERNEL32.@)
752  */
753 void WINAPI SUnMapLS_IP_EBP_16(CONTEXT86 *context) { x_SUnMapLS_IP_EBP_x(context,16); }
754
755 /***********************************************************************
756  *              SUnMapLS_IP_EBP_20 (KERNEL32.@)
757  */
758 void WINAPI SUnMapLS_IP_EBP_20(CONTEXT86 *context) { x_SUnMapLS_IP_EBP_x(context,20); }
759
760 /***********************************************************************
761  *              SUnMapLS_IP_EBP_24 (KERNEL32.@)
762  */
763 void WINAPI SUnMapLS_IP_EBP_24(CONTEXT86 *context) { x_SUnMapLS_IP_EBP_x(context,24); }
764
765 /***********************************************************************
766  *              SUnMapLS_IP_EBP_28 (KERNEL32.@)
767  */
768 void WINAPI SUnMapLS_IP_EBP_28(CONTEXT86 *context) { x_SUnMapLS_IP_EBP_x(context,28); }
769
770 /***********************************************************************
771  *              SUnMapLS_IP_EBP_32 (KERNEL32.@)
772  */
773 void WINAPI SUnMapLS_IP_EBP_32(CONTEXT86 *context) { x_SUnMapLS_IP_EBP_x(context,32); }
774
775 /***********************************************************************
776  *              SUnMapLS_IP_EBP_36 (KERNEL32.@)
777  */
778 void WINAPI SUnMapLS_IP_EBP_36(CONTEXT86 *context) { x_SUnMapLS_IP_EBP_x(context,36); }
779
780 /***********************************************************************
781  *              SUnMapLS_IP_EBP_40 (KERNEL32.@)
782  */
783 void WINAPI SUnMapLS_IP_EBP_40(CONTEXT86 *context) { x_SUnMapLS_IP_EBP_x(context,40); }