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