Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Selector manipulation functions |
| 3 | * |
| 4 | * Copyright 1995 Alexandre Julliard |
| 5 | */ |
| 6 | |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 7 | #include <string.h> |
Dimitrie O. Paun | 0b7a7bb | 2000-11-25 01:31:17 +0000 | [diff] [blame^] | 8 | |
| 9 | #include "config.h" |
Alexandre Julliard | 0a7c1f6 | 2000-01-27 02:54:17 +0000 | [diff] [blame] | 10 | #include "winerror.h" |
Marcus Meissner | 04c3e1d | 1999-02-19 10:37:02 +0000 | [diff] [blame] | 11 | #include "wine/winbase16.h" |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 12 | #include "ldt.h" |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 13 | #include "miscemu.h" |
Alexandre Julliard | fa68b75 | 1995-04-03 16:55:37 +0000 | [diff] [blame] | 14 | #include "selectors.h" |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 15 | #include "stackframe.h" |
Andreas Mohr | a00b49f | 1998-12-07 10:48:09 +0000 | [diff] [blame] | 16 | #include "process.h" |
Alexandre Julliard | 0a7c1f6 | 2000-01-27 02:54:17 +0000 | [diff] [blame] | 17 | #include "server.h" |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 18 | #include "debugtools.h" |
Patrik Stridvall | 1ed4ecf | 1999-06-26 14:58:24 +0000 | [diff] [blame] | 19 | #include "toolhelp.h" |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 20 | |
Alexandre Julliard | 0a7c1f6 | 2000-01-27 02:54:17 +0000 | [diff] [blame] | 21 | DEFAULT_DEBUG_CHANNEL(selector); |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 22 | |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 23 | #define LDT_SIZE 8192 |
| 24 | |
| 25 | /* get the number of selectors needed to cover up to the selector limit */ |
| 26 | inline static WORD get_sel_count( WORD sel ) |
| 27 | { |
| 28 | return (wine_ldt_copy.limit[sel >> __AHSHIFT] >> 16) + 1; |
| 29 | } |
| 30 | |
| 31 | /*********************************************************************** |
| 32 | * SELECTOR_AllocArray |
| 33 | * |
| 34 | * Allocate a selector array without setting the LDT entries |
| 35 | */ |
| 36 | static WORD SELECTOR_AllocArray( WORD count ) |
| 37 | { |
| 38 | WORD i, sel, size = 0; |
| 39 | |
| 40 | if (!count) return 0; |
| 41 | for (i = FIRST_LDT_ENTRY_TO_ALLOC; i < LDT_SIZE; i++) |
| 42 | { |
| 43 | if (wine_ldt_copy.flags[i] & WINE_LDT_FLAGS_ALLOCATED) size = 0; |
| 44 | else if (++size >= count) break; |
| 45 | } |
| 46 | if (i == LDT_SIZE) return 0; |
| 47 | sel = i - size + 1; |
| 48 | |
| 49 | /* mark selectors as allocated */ |
| 50 | for (i = 0; i < count; i++) wine_ldt_copy.flags[sel + i] |= WINE_LDT_FLAGS_ALLOCATED; |
| 51 | |
| 52 | return (sel << __AHSHIFT) | 7; |
| 53 | } |
| 54 | |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 55 | |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 56 | /*********************************************************************** |
| 57 | * AllocSelectorArray (KERNEL.206) |
| 58 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 59 | WORD WINAPI AllocSelectorArray16( WORD count ) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 60 | { |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 61 | WORD i, sel = SELECTOR_AllocArray( count ); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 62 | |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 63 | if (sel) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 64 | { |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 65 | LDT_ENTRY entry; |
| 66 | wine_ldt_set_base( &entry, 0 ); |
| 67 | wine_ldt_set_limit( &entry, 1 ); /* avoid 0 base and limit */ |
| 68 | wine_ldt_set_flags( &entry, WINE_LDT_FLAGS_DATA ); |
| 69 | for (i = 0; i < count; i++) wine_ldt_set_entry( sel + (i << __AHSHIFT), &entry ); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 70 | } |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 71 | return sel; |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | |
| 75 | /*********************************************************************** |
| 76 | * AllocSelector (KERNEL.175) |
| 77 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 78 | WORD WINAPI AllocSelector16( WORD sel ) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 79 | { |
| 80 | WORD newsel, count, i; |
| 81 | |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 82 | count = sel ? get_sel_count(sel) : 1; |
| 83 | newsel = SELECTOR_AllocArray( count ); |
| 84 | TRACE("(%04x): returning %04x\n", sel, newsel ); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 85 | if (!newsel) return 0; |
| 86 | if (!sel) return newsel; /* nothing to copy */ |
| 87 | for (i = 0; i < count; i++) |
| 88 | { |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 89 | LDT_ENTRY entry; |
| 90 | wine_ldt_get_entry( sel + (i << __AHSHIFT), &entry ); |
| 91 | wine_ldt_set_entry( newsel + (i << __AHSHIFT), &entry ); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 92 | } |
| 93 | return newsel; |
| 94 | } |
| 95 | |
| 96 | |
| 97 | /*********************************************************************** |
| 98 | * FreeSelector (KERNEL.176) |
| 99 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 100 | WORD WINAPI FreeSelector16( WORD sel ) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 101 | { |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 102 | LDT_ENTRY entry; |
| 103 | |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 104 | if (IS_SELECTOR_FREE(sel)) return sel; /* error */ |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 105 | |
| 106 | #ifdef __i386__ |
| 107 | /* Check if we are freeing current %fs or %gs selector */ |
| 108 | if (!((__get_fs() ^ sel) & ~7)) |
| 109 | { |
| 110 | WARN("Freeing %%fs selector (%04x), not good.\n", __get_fs() ); |
| 111 | __set_fs( 0 ); |
| 112 | } |
| 113 | if (!((__get_gs() ^ sel) & ~7)) __set_gs( 0 ); |
| 114 | #endif /* __i386__ */ |
| 115 | |
| 116 | memset( &entry, 0, sizeof(entry) ); /* clear the LDT entries */ |
| 117 | wine_ldt_set_entry( sel, &entry ); |
| 118 | wine_ldt_copy.flags[sel >> __AHSHIFT] &= ~WINE_LDT_FLAGS_ALLOCATED; |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 119 | return 0; |
| 120 | } |
| 121 | |
| 122 | |
| 123 | /*********************************************************************** |
| 124 | * SELECTOR_SetEntries |
| 125 | * |
| 126 | * Set the LDT entries for an array of selectors. |
| 127 | */ |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 128 | static void SELECTOR_SetEntries( WORD sel, const void *base, DWORD size, unsigned char flags ) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 129 | { |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 130 | LDT_ENTRY entry; |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 131 | WORD i, count; |
| 132 | |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 133 | wine_ldt_set_base( &entry, base ); |
| 134 | wine_ldt_set_limit( &entry, size - 1 ); |
| 135 | wine_ldt_set_flags( &entry, flags ); |
Alexandre Julliard | 7d654eb | 1996-02-25 11:36:22 +0000 | [diff] [blame] | 136 | /* Make sure base and limit are not 0 together if the size is not 0 */ |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 137 | if (!base && size == 1) wine_ldt_set_limit( &entry, 1 ); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 138 | count = (size + 0xffff) / 0x10000; |
| 139 | for (i = 0; i < count; i++) |
| 140 | { |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 141 | wine_ldt_set_entry( sel + (i << __AHSHIFT), &entry ); |
| 142 | wine_ldt_set_base( &entry, wine_ldt_get_base(&entry) + 0x10000 ); |
| 143 | wine_ldt_set_limit( &entry, wine_ldt_get_limit(&entry) - 0x10000 ); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 144 | } |
| 145 | } |
| 146 | |
| 147 | |
| 148 | /*********************************************************************** |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 149 | * SELECTOR_AllocBlock |
| 150 | * |
| 151 | * Allocate selectors for a block of linear memory. |
| 152 | */ |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 153 | WORD SELECTOR_AllocBlock( const void *base, DWORD size, unsigned char flags ) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 154 | { |
| 155 | WORD sel, count; |
| 156 | |
| 157 | if (!size) return 0; |
| 158 | count = (size + 0xffff) / 0x10000; |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 159 | sel = SELECTOR_AllocArray( count ); |
| 160 | if (sel) SELECTOR_SetEntries( sel, base, size, flags ); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 161 | return sel; |
| 162 | } |
| 163 | |
| 164 | |
| 165 | /*********************************************************************** |
Alexandre Julliard | 8cc3a5e | 1996-08-11 15:49:51 +0000 | [diff] [blame] | 166 | * SELECTOR_FreeBlock |
| 167 | * |
| 168 | * Free a block of selectors. |
| 169 | */ |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 170 | void SELECTOR_FreeBlock( WORD sel ) |
Alexandre Julliard | 8cc3a5e | 1996-08-11 15:49:51 +0000 | [diff] [blame] | 171 | { |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 172 | WORD i, count = get_sel_count( sel ); |
Alexandre Julliard | 8cc3a5e | 1996-08-11 15:49:51 +0000 | [diff] [blame] | 173 | |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 174 | TRACE("(%04x,%d)\n", sel, count ); |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 175 | for (i = 0; i < count; i++) FreeSelector16( sel + (i << __AHSHIFT) ); |
Alexandre Julliard | 8cc3a5e | 1996-08-11 15:49:51 +0000 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | |
| 179 | /*********************************************************************** |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 180 | * SELECTOR_ReallocBlock |
| 181 | * |
| 182 | * Change the size of a block of selectors. |
| 183 | */ |
Alexandre Julliard | 284c9b9 | 1999-04-11 15:07:13 +0000 | [diff] [blame] | 184 | WORD SELECTOR_ReallocBlock( WORD sel, const void *base, DWORD size ) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 185 | { |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 186 | LDT_ENTRY entry; |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 187 | WORD i, oldcount, newcount; |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 188 | |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 189 | if (!size) size = 1; |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 190 | oldcount = get_sel_count( sel ); |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 191 | newcount = (size + 0xffff) >> 16; |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 192 | wine_ldt_get_entry( sel, &entry ); |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 193 | |
| 194 | if (oldcount < newcount) /* We need to add selectors */ |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 195 | { |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 196 | WORD index = sel >> __AHSHIFT; |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 197 | /* Check if the next selectors are free */ |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 198 | if (index + newcount > LDT_SIZE) i = oldcount; |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 199 | else |
| 200 | for (i = oldcount; i < newcount; i++) |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 201 | if (wine_ldt_copy.flags[index+i] & WINE_LDT_FLAGS_ALLOCATED) break; |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 202 | |
| 203 | if (i < newcount) /* they are not free */ |
| 204 | { |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 205 | SELECTOR_FreeBlock( sel ); |
| 206 | sel = SELECTOR_AllocArray( newcount ); |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 207 | } |
| 208 | else /* mark the selectors as allocated */ |
| 209 | { |
| 210 | for (i = oldcount; i < newcount; i++) |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 211 | wine_ldt_copy.flags[index+i] |= WINE_LDT_FLAGS_ALLOCATED; |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 212 | } |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 213 | } |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 214 | else if (oldcount > newcount) /* We need to remove selectors */ |
| 215 | { |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 216 | SELECTOR_FreeBlock( sel + (newcount << __AHSHIFT) ); |
Alexandre Julliard | e2991ea | 1995-07-29 13:09:43 +0000 | [diff] [blame] | 217 | } |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 218 | if (sel) SELECTOR_SetEntries( sel, base, size, wine_ldt_get_flags(&entry) ); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 219 | return sel; |
| 220 | } |
| 221 | |
| 222 | |
| 223 | /*********************************************************************** |
| 224 | * PrestoChangoSelector (KERNEL.177) |
| 225 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 226 | WORD WINAPI PrestoChangoSelector16( WORD selSrc, WORD selDst ) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 227 | { |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 228 | LDT_ENTRY entry; |
| 229 | wine_ldt_get_entry( selSrc, &entry ); |
| 230 | /* toggle the executable bit */ |
| 231 | entry.HighWord.Bits.Type ^= (WINE_LDT_FLAGS_CODE ^ WINE_LDT_FLAGS_DATA); |
| 232 | wine_ldt_set_entry( selDst, &entry ); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 233 | return selDst; |
| 234 | } |
| 235 | |
| 236 | |
| 237 | /*********************************************************************** |
| 238 | * AllocCStoDSAlias (KERNEL.170) |
| 239 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 240 | WORD WINAPI AllocCStoDSAlias16( WORD sel ) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 241 | { |
| 242 | WORD newsel; |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 243 | LDT_ENTRY entry; |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 244 | |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 245 | newsel = SELECTOR_AllocArray( 1 ); |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 246 | TRACE("(%04x): returning %04x\n", |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 247 | sel, newsel ); |
| 248 | if (!newsel) return 0; |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 249 | wine_ldt_get_entry( sel, &entry ); |
| 250 | entry.HighWord.Bits.Type = WINE_LDT_FLAGS_DATA; |
| 251 | wine_ldt_set_entry( newsel, &entry ); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 252 | return newsel; |
| 253 | } |
| 254 | |
| 255 | |
| 256 | /*********************************************************************** |
| 257 | * AllocDStoCSAlias (KERNEL.171) |
| 258 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 259 | WORD WINAPI AllocDStoCSAlias16( WORD sel ) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 260 | { |
| 261 | WORD newsel; |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 262 | LDT_ENTRY entry; |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 263 | |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 264 | newsel = SELECTOR_AllocArray( 1 ); |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 265 | TRACE("(%04x): returning %04x\n", |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 266 | sel, newsel ); |
| 267 | if (!newsel) return 0; |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 268 | wine_ldt_get_entry( sel, &entry ); |
| 269 | entry.HighWord.Bits.Type = WINE_LDT_FLAGS_CODE; |
| 270 | wine_ldt_set_entry( newsel, &entry ); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 271 | return newsel; |
| 272 | } |
| 273 | |
| 274 | |
| 275 | /*********************************************************************** |
| 276 | * LongPtrAdd (KERNEL.180) |
| 277 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 278 | void WINAPI LongPtrAdd16( DWORD ptr, DWORD add ) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 279 | { |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 280 | LDT_ENTRY entry; |
| 281 | wine_ldt_get_entry( SELECTOROF(ptr), &entry ); |
| 282 | wine_ldt_set_base( &entry, (char *)wine_ldt_get_base(&entry) + add ); |
| 283 | wine_ldt_set_entry( SELECTOROF(ptr), &entry ); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | |
| 287 | /*********************************************************************** |
| 288 | * GetSelectorBase (KERNEL.186) |
| 289 | */ |
Andreas Mohr | a00b49f | 1998-12-07 10:48:09 +0000 | [diff] [blame] | 290 | DWORD WINAPI WIN16_GetSelectorBase( WORD sel ) |
| 291 | { |
| 292 | /* |
| 293 | * Note: For Win32s processes, the whole linear address space is |
| 294 | * shifted by 0x10000 relative to the OS linear address space. |
| 295 | * See the comment in msdos/vxd.c. |
| 296 | */ |
| 297 | |
| 298 | DWORD base = GetSelectorBase( sel ); |
| 299 | return W32S_WINE2APP( base, W32S_APPLICATION() ? W32S_OFFSET : 0 ); |
| 300 | } |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 301 | DWORD WINAPI GetSelectorBase( WORD sel ) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 302 | { |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 303 | void *base = wine_ldt_copy.base[sel >> __AHSHIFT]; |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 304 | |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 305 | /* if base points into DOSMEM, assume we have to |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 306 | * return pointer into physical lower 1MB */ |
| 307 | |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 308 | return DOSMEM_MapLinearToDos( base ); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | |
| 312 | /*********************************************************************** |
| 313 | * SetSelectorBase (KERNEL.187) |
| 314 | */ |
Andreas Mohr | a00b49f | 1998-12-07 10:48:09 +0000 | [diff] [blame] | 315 | DWORD WINAPI WIN16_SetSelectorBase( WORD sel, DWORD base ) |
| 316 | { |
| 317 | /* |
| 318 | * Note: For Win32s processes, the whole linear address space is |
| 319 | * shifted by 0x10000 relative to the OS linear address space. |
| 320 | * See the comment in msdos/vxd.c. |
| 321 | */ |
| 322 | |
| 323 | SetSelectorBase( sel, |
| 324 | W32S_APP2WINE( base, W32S_APPLICATION() ? W32S_OFFSET : 0 ) ); |
| 325 | return sel; |
| 326 | } |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 327 | WORD WINAPI SetSelectorBase( WORD sel, DWORD base ) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 328 | { |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 329 | LDT_ENTRY entry; |
| 330 | wine_ldt_get_entry( sel, &entry ); |
| 331 | wine_ldt_set_base( &entry, DOSMEM_MapDosToLinear(base) ); |
| 332 | wine_ldt_set_entry( sel, &entry ); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 333 | return sel; |
| 334 | } |
| 335 | |
| 336 | |
| 337 | /*********************************************************************** |
| 338 | * GetSelectorLimit (KERNEL.188) |
| 339 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 340 | DWORD WINAPI GetSelectorLimit16( WORD sel ) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 341 | { |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 342 | return wine_ldt_copy.limit[sel >> __AHSHIFT]; |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | |
| 346 | /*********************************************************************** |
| 347 | * SetSelectorLimit (KERNEL.189) |
| 348 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 349 | WORD WINAPI SetSelectorLimit16( WORD sel, DWORD limit ) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 350 | { |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 351 | LDT_ENTRY entry; |
| 352 | wine_ldt_get_entry( sel, &entry ); |
| 353 | wine_ldt_set_limit( &entry, limit ); |
| 354 | wine_ldt_set_entry( sel, &entry ); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 355 | return sel; |
| 356 | } |
| 357 | |
| 358 | |
| 359 | /*********************************************************************** |
| 360 | * SelectorAccessRights (KERNEL.196) |
| 361 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 362 | WORD WINAPI SelectorAccessRights16( WORD sel, WORD op, WORD val ) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 363 | { |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 364 | LDT_ENTRY entry; |
| 365 | wine_ldt_get_entry( sel, &entry ); |
| 366 | |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 367 | if (op == 0) /* get */ |
| 368 | { |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 369 | return entry.HighWord.Bytes.Flags1 | ((entry.HighWord.Bytes.Flags2 << 8) & 0xf0); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 370 | } |
| 371 | else /* set */ |
| 372 | { |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 373 | entry.HighWord.Bytes.Flags1 = LOBYTE(val) | 0xf0; |
| 374 | entry.HighWord.Bytes.Flags2 = (entry.HighWord.Bytes.Flags2 & 0x0f) | (HIBYTE(val) & 0xf0); |
| 375 | wine_ldt_set_entry( sel, &entry ); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 376 | return 0; |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | |
| 381 | /*********************************************************************** |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 382 | * IsBadCodePtr16 (KERNEL.336) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 383 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 384 | BOOL16 WINAPI IsBadCodePtr16( SEGPTR lpfn ) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 385 | { |
| 386 | WORD sel; |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 387 | LDT_ENTRY entry; |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 388 | |
| 389 | sel = SELECTOROF(lpfn); |
Alexandre Julliard | bd34d4f | 1995-06-20 19:08:12 +0000 | [diff] [blame] | 390 | if (!sel) return TRUE; |
| 391 | if (IS_SELECTOR_FREE(sel)) return TRUE; |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 392 | wine_ldt_get_entry( sel, &entry ); |
| 393 | /* check for code segment, ignoring conforming, read-only and accessed bits */ |
| 394 | if ((entry.HighWord.Bits.Type ^ WINE_LDT_FLAGS_CODE) & 0x18) return TRUE; |
| 395 | if (OFFSETOF(lpfn) > wine_ldt_get_limit(&entry)) return TRUE; |
Alexandre Julliard | bd34d4f | 1995-06-20 19:08:12 +0000 | [diff] [blame] | 396 | return FALSE; |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | |
| 400 | /*********************************************************************** |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 401 | * IsBadStringPtr16 (KERNEL.337) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 402 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 403 | BOOL16 WINAPI IsBadStringPtr16( SEGPTR ptr, UINT16 size ) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 404 | { |
| 405 | WORD sel; |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 406 | LDT_ENTRY entry; |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 407 | |
| 408 | sel = SELECTOROF(ptr); |
Alexandre Julliard | bd34d4f | 1995-06-20 19:08:12 +0000 | [diff] [blame] | 409 | if (!sel) return TRUE; |
| 410 | if (IS_SELECTOR_FREE(sel)) return TRUE; |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 411 | wine_ldt_get_entry( sel, &entry ); |
| 412 | /* check for data or readable code segment */ |
| 413 | if (!(entry.HighWord.Bits.Type & 0x10)) return TRUE; /* system descriptor */ |
| 414 | if ((entry.HighWord.Bits.Type & 0x0a) == 0x08) return TRUE; /* non-readable code segment */ |
Uwe Bonnes | 0a1645d | 1999-08-15 18:44:06 +0000 | [diff] [blame] | 415 | if (strlen(PTR_SEG_TO_LIN(ptr)) < size) size = strlen(PTR_SEG_TO_LIN(ptr)) + 1; |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 416 | if (size && (OFFSETOF(ptr) + size - 1 > wine_ldt_get_limit(&entry))) return TRUE; |
Alexandre Julliard | bd34d4f | 1995-06-20 19:08:12 +0000 | [diff] [blame] | 417 | return FALSE; |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | |
| 421 | /*********************************************************************** |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 422 | * IsBadHugeReadPtr16 (KERNEL.346) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 423 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 424 | BOOL16 WINAPI IsBadHugeReadPtr16( SEGPTR ptr, DWORD size ) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 425 | { |
| 426 | WORD sel; |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 427 | LDT_ENTRY entry; |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 428 | |
| 429 | sel = SELECTOROF(ptr); |
Alexandre Julliard | bd34d4f | 1995-06-20 19:08:12 +0000 | [diff] [blame] | 430 | if (!sel) return TRUE; |
| 431 | if (IS_SELECTOR_FREE(sel)) return TRUE; |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 432 | wine_ldt_get_entry( sel, &entry ); |
| 433 | /* check for data or readable code segment */ |
| 434 | if (!(entry.HighWord.Bits.Type & 0x10)) return TRUE; /* system descriptor */ |
| 435 | if ((entry.HighWord.Bits.Type & 0x0a) == 0x08) return TRUE; /* non-readable code segment */ |
| 436 | if (size && (OFFSETOF(ptr) + size - 1 > wine_ldt_get_limit( &entry ))) return TRUE; |
Alexandre Julliard | bd34d4f | 1995-06-20 19:08:12 +0000 | [diff] [blame] | 437 | return FALSE; |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | |
| 441 | /*********************************************************************** |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 442 | * IsBadHugeWritePtr16 (KERNEL.347) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 443 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 444 | BOOL16 WINAPI IsBadHugeWritePtr16( SEGPTR ptr, DWORD size ) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 445 | { |
| 446 | WORD sel; |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 447 | LDT_ENTRY entry; |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 448 | |
| 449 | sel = SELECTOROF(ptr); |
Alexandre Julliard | bd34d4f | 1995-06-20 19:08:12 +0000 | [diff] [blame] | 450 | if (!sel) return TRUE; |
| 451 | if (IS_SELECTOR_FREE(sel)) return TRUE; |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 452 | wine_ldt_get_entry( sel, &entry ); |
| 453 | /* check for writeable data segment, ignoring expand-down and accessed flags */ |
| 454 | if ((entry.HighWord.Bits.Type ^ WINE_LDT_FLAGS_DATA) & ~5) return TRUE; |
| 455 | if (size && (OFFSETOF(ptr) + size - 1 > wine_ldt_get_limit( &entry ))) return TRUE; |
Alexandre Julliard | bd34d4f | 1995-06-20 19:08:12 +0000 | [diff] [blame] | 456 | return FALSE; |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | /*********************************************************************** |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 460 | * IsBadReadPtr16 (KERNEL.334) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 461 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 462 | BOOL16 WINAPI IsBadReadPtr16( SEGPTR ptr, UINT16 size ) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 463 | { |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 464 | return IsBadHugeReadPtr16( ptr, size ); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | |
| 468 | /*********************************************************************** |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 469 | * IsBadWritePtr16 (KERNEL.335) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 470 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 471 | BOOL16 WINAPI IsBadWritePtr16( SEGPTR ptr, UINT16 size ) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 472 | { |
Alexandre Julliard | 8bbf818 | 1996-09-13 16:50:47 +0000 | [diff] [blame] | 473 | return IsBadHugeWritePtr16( ptr, size ); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | |
| 477 | /*********************************************************************** |
Ulrich Weigand | 98b5f77 | 1999-07-27 17:09:14 +0000 | [diff] [blame] | 478 | * IsBadFlatReadWritePtr16 (KERNEL.627) |
| 479 | */ |
| 480 | BOOL16 WINAPI IsBadFlatReadWritePtr16( SEGPTR ptr, DWORD size, BOOL16 bWrite ) |
| 481 | { |
| 482 | return bWrite? IsBadHugeWritePtr16( ptr, size ) |
| 483 | : IsBadHugeReadPtr16( ptr, size ); |
| 484 | } |
| 485 | |
| 486 | |
| 487 | /*********************************************************************** |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 488 | * MemoryRead (TOOLHELP.78) |
| 489 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 490 | DWORD WINAPI MemoryRead16( WORD sel, DWORD offset, void *buffer, DWORD count ) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 491 | { |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 492 | WORD index = sel >> __AHSHIFT; |
| 493 | |
| 494 | if (!(wine_ldt_copy.flags[index] & WINE_LDT_FLAGS_ALLOCATED)) return 0; |
| 495 | if (offset > wine_ldt_copy.limit[index]) return 0; |
| 496 | if (offset + count > wine_ldt_copy.limit[index] + 1) |
| 497 | count = wine_ldt_copy.limit[index] + 1 - offset; |
| 498 | memcpy( buffer, (char *)wine_ldt_copy.base[index] + offset, count ); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 499 | return count; |
| 500 | } |
| 501 | |
| 502 | |
| 503 | /*********************************************************************** |
| 504 | * MemoryWrite (TOOLHELP.79) |
| 505 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 506 | DWORD WINAPI MemoryWrite16( WORD sel, DWORD offset, void *buffer, DWORD count ) |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 507 | { |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 508 | WORD index = sel >> __AHSHIFT; |
| 509 | |
| 510 | if (!(wine_ldt_copy.flags[index] & WINE_LDT_FLAGS_ALLOCATED)) return 0; |
| 511 | if (offset > wine_ldt_copy.limit[index]) return 0; |
| 512 | if (offset + count > wine_ldt_copy.limit[index] + 1) |
| 513 | count = wine_ldt_copy.limit[index] + 1 - offset; |
| 514 | memcpy( (char *)wine_ldt_copy.base[index] + offset, buffer, count ); |
Alexandre Julliard | e2abbb1 | 1995-03-19 17:39:39 +0000 | [diff] [blame] | 515 | return count; |
| 516 | } |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 517 | |
| 518 | /************************************* Win95 pointer mapping functions * |
| 519 | * |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 520 | */ |
| 521 | |
| 522 | /*********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 523 | * MapSL (KERNEL32.523) |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 524 | * |
| 525 | * Maps fixed segmented pointer to linear. |
| 526 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 527 | LPVOID WINAPI MapSL( SEGPTR sptr ) |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 528 | { |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 529 | return (char *)wine_ldt_copy.base[SELECTOROF(sptr) >> __AHSHIFT] + OFFSETOF(sptr); |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 530 | } |
| 531 | |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 532 | /*********************************************************************** |
| 533 | * MapSLFix (KERNEL32.524) |
| 534 | * |
| 535 | * FIXME: MapSLFix and UnMapSLFixArray should probably prevent |
| 536 | * unexpected linear address change when GlobalCompact() shuffles |
| 537 | * moveable blocks. |
| 538 | */ |
| 539 | |
| 540 | LPVOID WINAPI MapSLFix( SEGPTR sptr ) |
| 541 | { |
| 542 | return (LPVOID)PTR_SEG_TO_LIN(sptr); |
| 543 | } |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 544 | |
| 545 | /*********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 546 | * UnMapSLFixArray (KERNEL32.701) |
| 547 | */ |
| 548 | |
Ulrich Weigand | eb94c7d | 1999-11-13 23:54:04 +0000 | [diff] [blame] | 549 | void WINAPI UnMapSLFixArray( SEGPTR sptr[], INT length, CONTEXT86 *context ) |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 550 | { |
Ulrich Weigand | 90c245c | 1999-02-02 10:34:46 +0000 | [diff] [blame] | 551 | /* Must not change EAX, hence defined as 'register' function */ |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | /*********************************************************************** |
| 555 | * MapLS (KERNEL32.522) |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 556 | * |
| 557 | * Maps linear pointer to segmented. |
| 558 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 559 | SEGPTR WINAPI MapLS( LPVOID ptr ) |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 560 | { |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 561 | if (!HIWORD(ptr)) |
| 562 | return (SEGPTR)ptr; |
| 563 | else |
| 564 | { |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 565 | WORD sel = SELECTOR_AllocBlock( ptr, 0x10000, WINE_LDT_FLAGS_DATA ); |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 566 | return PTR_SEG_OFF_TO_SEGPTR( sel, 0 ); |
| 567 | } |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | |
| 571 | /*********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 572 | * UnMapLS (KERNEL32.700) |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 573 | * |
| 574 | * Free mapped selector. |
| 575 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 576 | void WINAPI UnMapLS( SEGPTR sptr ) |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 577 | { |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 578 | if (SELECTOROF(sptr)) FreeSelector16( SELECTOROF(sptr) ); |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 579 | } |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 580 | |
| 581 | /*********************************************************************** |
| 582 | * GetThreadSelectorEntry (KERNEL32) |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 583 | */ |
Alexandre Julliard | 0a7c1f6 | 2000-01-27 02:54:17 +0000 | [diff] [blame] | 584 | BOOL WINAPI GetThreadSelectorEntry( HANDLE hthread, DWORD sel, LPLDT_ENTRY ldtent) |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 585 | { |
Alexandre Julliard | 0a7c1f6 | 2000-01-27 02:54:17 +0000 | [diff] [blame] | 586 | #ifdef __i386__ |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 587 | BOOL ret; |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 588 | |
Alexandre Julliard | 0a7c1f6 | 2000-01-27 02:54:17 +0000 | [diff] [blame] | 589 | if (!(sel & 4)) /* GDT selector */ |
| 590 | { |
Alexandre Julliard | 0a7c1f6 | 2000-01-27 02:54:17 +0000 | [diff] [blame] | 591 | sel &= ~3; /* ignore RPL */ |
| 592 | if (!sel) /* null selector */ |
| 593 | { |
| 594 | memset( ldtent, 0, sizeof(*ldtent) ); |
| 595 | return TRUE; |
| 596 | } |
| 597 | ldtent->BaseLow = 0; |
| 598 | ldtent->HighWord.Bits.BaseMid = 0; |
| 599 | ldtent->HighWord.Bits.BaseHi = 0; |
| 600 | ldtent->LimitLow = 0xffff; |
| 601 | ldtent->HighWord.Bits.LimitHi = 0xf; |
| 602 | ldtent->HighWord.Bits.Dpl = 3; |
| 603 | ldtent->HighWord.Bits.Sys = 0; |
| 604 | ldtent->HighWord.Bits.Pres = 1; |
| 605 | ldtent->HighWord.Bits.Granularity = 1; |
| 606 | ldtent->HighWord.Bits.Default_Big = 1; |
| 607 | ldtent->HighWord.Bits.Type = 0x12; |
| 608 | /* it has to be one of the system GDT selectors */ |
Alexandre Julliard | 916f975 | 2000-02-26 16:51:13 +0000 | [diff] [blame] | 609 | if (sel == (__get_ds() & ~3)) return TRUE; |
| 610 | if (sel == (__get_ss() & ~3)) return TRUE; |
| 611 | if (sel == (__get_cs() & ~3)) |
Alexandre Julliard | 0a7c1f6 | 2000-01-27 02:54:17 +0000 | [diff] [blame] | 612 | { |
| 613 | ldtent->HighWord.Bits.Type |= 8; /* code segment */ |
| 614 | return TRUE; |
| 615 | } |
| 616 | SetLastError( ERROR_NOACCESS ); |
| 617 | return FALSE; |
| 618 | } |
| 619 | |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 620 | SERVER_START_REQ |
Alexandre Julliard | 0a7c1f6 | 2000-01-27 02:54:17 +0000 | [diff] [blame] | 621 | { |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 622 | struct get_selector_entry_request *req = server_alloc_req( sizeof(*req), 0 ); |
| 623 | |
| 624 | req->handle = hthread; |
| 625 | req->entry = sel >> __AHSHIFT; |
| 626 | if ((ret = !server_call( REQ_GET_SELECTOR_ENTRY ))) |
| 627 | { |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 628 | if (!(req->flags & WINE_LDT_FLAGS_ALLOCATED)) |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 629 | { |
| 630 | SetLastError( ERROR_MR_MID_NOT_FOUND ); /* sic */ |
| 631 | ret = FALSE; |
| 632 | } |
| 633 | else |
| 634 | { |
Alexandre Julliard | 914406f | 2000-11-14 01:54:49 +0000 | [diff] [blame] | 635 | wine_ldt_set_base( ldtent, (void *)req->base ); |
| 636 | wine_ldt_set_limit( ldtent, req->limit ); |
| 637 | wine_ldt_set_flags( ldtent, req->flags ); |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 638 | } |
| 639 | } |
Alexandre Julliard | 0a7c1f6 | 2000-01-27 02:54:17 +0000 | [diff] [blame] | 640 | } |
Alexandre Julliard | 9c2370b | 2000-08-30 00:00:48 +0000 | [diff] [blame] | 641 | SERVER_END_REQ; |
| 642 | return ret; |
Alexandre Julliard | 0a7c1f6 | 2000-01-27 02:54:17 +0000 | [diff] [blame] | 643 | #else |
Ulrich Weigand | afd6a4b | 2000-06-04 01:48:05 +0000 | [diff] [blame] | 644 | SetLastError( ERROR_CALL_NOT_IMPLEMENTED ); |
Alexandre Julliard | 0a7c1f6 | 2000-01-27 02:54:17 +0000 | [diff] [blame] | 645 | return FALSE; |
| 646 | #endif |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | |
| 650 | /********************************************************************** |
| 651 | * SMapLS* (KERNEL32) |
| 652 | * These functions map linear pointers at [EBP+xxx] to segmented pointers |
| 653 | * and return them. |
| 654 | * Win95 uses some kind of alias structs, which it stores in [EBP+x] to |
| 655 | * unravel them at SUnMapLS. We just store the segmented pointer there. |
| 656 | */ |
| 657 | static void |
Ulrich Weigand | eb94c7d | 1999-11-13 23:54:04 +0000 | [diff] [blame] | 658 | x_SMapLS_IP_EBP_x(CONTEXT86 *context,int argoff) { |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 659 | DWORD val,ptr; |
| 660 | |
Alexandre Julliard | d8fab2e | 2000-09-25 23:53:07 +0000 | [diff] [blame] | 661 | val =*(DWORD*)(context->Ebp + argoff); |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 662 | if (val<0x10000) { |
| 663 | ptr=val; |
Alexandre Julliard | d8fab2e | 2000-09-25 23:53:07 +0000 | [diff] [blame] | 664 | *(DWORD*)(context->Ebp + argoff) = 0; |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 665 | } else { |
| 666 | ptr = MapLS((LPVOID)val); |
Alexandre Julliard | d8fab2e | 2000-09-25 23:53:07 +0000 | [diff] [blame] | 667 | *(DWORD*)(context->Ebp + argoff) = ptr; |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 668 | } |
Alexandre Julliard | d8fab2e | 2000-09-25 23:53:07 +0000 | [diff] [blame] | 669 | context->Eax = ptr; |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 670 | } |
| 671 | |
Patrik Stridvall | 54fe838 | 2000-04-06 20:21:16 +0000 | [diff] [blame] | 672 | /*********************************************************************** |
| 673 | * SMapLS_IP_EBP_8 (KERNEL32.601) |
| 674 | */ |
Ulrich Weigand | eb94c7d | 1999-11-13 23:54:04 +0000 | [diff] [blame] | 675 | void WINAPI SMapLS_IP_EBP_8 (CONTEXT86 *context) {x_SMapLS_IP_EBP_x(context, 8);} |
Patrik Stridvall | 54fe838 | 2000-04-06 20:21:16 +0000 | [diff] [blame] | 676 | |
| 677 | /*********************************************************************** |
| 678 | * SMapLS_IP_EBP_12 (KERNEL32.593) |
| 679 | */ |
Ulrich Weigand | eb94c7d | 1999-11-13 23:54:04 +0000 | [diff] [blame] | 680 | void WINAPI SMapLS_IP_EBP_12(CONTEXT86 *context) {x_SMapLS_IP_EBP_x(context,12);} |
Patrik Stridvall | 54fe838 | 2000-04-06 20:21:16 +0000 | [diff] [blame] | 681 | |
| 682 | /*********************************************************************** |
| 683 | * SMapLS_IP_EBP_16 (KERNEL32.594) |
| 684 | */ |
Ulrich Weigand | eb94c7d | 1999-11-13 23:54:04 +0000 | [diff] [blame] | 685 | void WINAPI SMapLS_IP_EBP_16(CONTEXT86 *context) {x_SMapLS_IP_EBP_x(context,16);} |
Patrik Stridvall | 54fe838 | 2000-04-06 20:21:16 +0000 | [diff] [blame] | 686 | |
| 687 | /*********************************************************************** |
| 688 | * SMapLS_IP_EBP_20 (KERNEL32.595) |
| 689 | */ |
Ulrich Weigand | eb94c7d | 1999-11-13 23:54:04 +0000 | [diff] [blame] | 690 | void WINAPI SMapLS_IP_EBP_20(CONTEXT86 *context) {x_SMapLS_IP_EBP_x(context,20);} |
Patrik Stridvall | 54fe838 | 2000-04-06 20:21:16 +0000 | [diff] [blame] | 691 | |
| 692 | /*********************************************************************** |
| 693 | * SMapLS_IP_EBP_24 (KERNEL32.596) |
| 694 | */ |
Ulrich Weigand | eb94c7d | 1999-11-13 23:54:04 +0000 | [diff] [blame] | 695 | void WINAPI SMapLS_IP_EBP_24(CONTEXT86 *context) {x_SMapLS_IP_EBP_x(context,24);} |
Patrik Stridvall | 54fe838 | 2000-04-06 20:21:16 +0000 | [diff] [blame] | 696 | |
| 697 | /*********************************************************************** |
| 698 | * SMapLS_IP_EBP_28 (KERNEL32.597) |
| 699 | */ |
Ulrich Weigand | eb94c7d | 1999-11-13 23:54:04 +0000 | [diff] [blame] | 700 | void WINAPI SMapLS_IP_EBP_28(CONTEXT86 *context) {x_SMapLS_IP_EBP_x(context,28);} |
Patrik Stridvall | 54fe838 | 2000-04-06 20:21:16 +0000 | [diff] [blame] | 701 | |
| 702 | /*********************************************************************** |
| 703 | * SMapLS_IP_EBP_32 (KERNEL32.598) |
| 704 | */ |
Ulrich Weigand | eb94c7d | 1999-11-13 23:54:04 +0000 | [diff] [blame] | 705 | void WINAPI SMapLS_IP_EBP_32(CONTEXT86 *context) {x_SMapLS_IP_EBP_x(context,32);} |
Patrik Stridvall | 54fe838 | 2000-04-06 20:21:16 +0000 | [diff] [blame] | 706 | |
| 707 | /*********************************************************************** |
| 708 | * SMapLS_IP_EBP_36 (KERNEL32.599) |
| 709 | */ |
Ulrich Weigand | eb94c7d | 1999-11-13 23:54:04 +0000 | [diff] [blame] | 710 | void WINAPI SMapLS_IP_EBP_36(CONTEXT86 *context) {x_SMapLS_IP_EBP_x(context,36);} |
Patrik Stridvall | 54fe838 | 2000-04-06 20:21:16 +0000 | [diff] [blame] | 711 | |
| 712 | /*********************************************************************** |
| 713 | * SMapLS_IP_EBP_40 (KERNEL32.600) |
| 714 | */ |
Ulrich Weigand | eb94c7d | 1999-11-13 23:54:04 +0000 | [diff] [blame] | 715 | void WINAPI SMapLS_IP_EBP_40(CONTEXT86 *context) {x_SMapLS_IP_EBP_x(context,40);} |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 716 | |
Patrik Stridvall | 54fe838 | 2000-04-06 20:21:16 +0000 | [diff] [blame] | 717 | /*********************************************************************** |
| 718 | * SMapLS (KERNEL32.592) |
| 719 | */ |
Ulrich Weigand | eb94c7d | 1999-11-13 23:54:04 +0000 | [diff] [blame] | 720 | void WINAPI SMapLS( CONTEXT86 *context ) |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 721 | { |
Alexandre Julliard | d8fab2e | 2000-09-25 23:53:07 +0000 | [diff] [blame] | 722 | if (HIWORD(context->Eax)) |
| 723 | { |
| 724 | context->Eax = MapLS( (LPVOID)context->Eax ); |
| 725 | context->Edx = context->Eax; |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 726 | } else { |
Alexandre Julliard | d8fab2e | 2000-09-25 23:53:07 +0000 | [diff] [blame] | 727 | context->Edx = 0; |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 728 | } |
| 729 | } |
| 730 | |
Patrik Stridvall | 54fe838 | 2000-04-06 20:21:16 +0000 | [diff] [blame] | 731 | /*********************************************************************** |
| 732 | * SUnMapLS (KERNEL32.602) |
| 733 | */ |
| 734 | |
Ulrich Weigand | eb94c7d | 1999-11-13 23:54:04 +0000 | [diff] [blame] | 735 | void WINAPI SUnMapLS( CONTEXT86 *context ) |
Alexandre Julliard | 3db94ef | 1997-09-28 17:43:24 +0000 | [diff] [blame] | 736 | { |
Alexandre Julliard | d8fab2e | 2000-09-25 23:53:07 +0000 | [diff] [blame] | 737 | if (HIWORD(context->Eax)) UnMapLS( (SEGPTR)context->Eax ); |
Alexandre Julliard | 3db94ef | 1997-09-28 17:43:24 +0000 | [diff] [blame] | 738 | } |
| 739 | |
Alexandre Julliard | d8fab2e | 2000-09-25 23:53:07 +0000 | [diff] [blame] | 740 | inline static void x_SUnMapLS_IP_EBP_x(CONTEXT86 *context,int argoff) |
| 741 | { |
| 742 | SEGPTR *ptr = (SEGPTR *)(context->Ebp + argoff); |
| 743 | if (*ptr) |
| 744 | { |
| 745 | UnMapLS( *ptr ); |
| 746 | *ptr = 0; |
| 747 | } |
Alexandre Julliard | 3db94ef | 1997-09-28 17:43:24 +0000 | [diff] [blame] | 748 | } |
Patrik Stridvall | 54fe838 | 2000-04-06 20:21:16 +0000 | [diff] [blame] | 749 | |
| 750 | /*********************************************************************** |
| 751 | * SUnMapLS_IP_EBP_8 (KERNEL32.611) |
| 752 | */ |
Ulrich Weigand | eb94c7d | 1999-11-13 23:54:04 +0000 | [diff] [blame] | 753 | void WINAPI SUnMapLS_IP_EBP_8 (CONTEXT86 *context) { x_SUnMapLS_IP_EBP_x(context, 8); } |
Patrik Stridvall | 54fe838 | 2000-04-06 20:21:16 +0000 | [diff] [blame] | 754 | |
| 755 | /*********************************************************************** |
| 756 | * SUnMapLS_IP_EBP_12 (KERNEL32.603) |
| 757 | */ |
Ulrich Weigand | eb94c7d | 1999-11-13 23:54:04 +0000 | [diff] [blame] | 758 | void WINAPI SUnMapLS_IP_EBP_12(CONTEXT86 *context) { x_SUnMapLS_IP_EBP_x(context,12); } |
Patrik Stridvall | 54fe838 | 2000-04-06 20:21:16 +0000 | [diff] [blame] | 759 | |
| 760 | /*********************************************************************** |
| 761 | * SUnMapLS_IP_EBP_16 (KERNEL32.604) |
| 762 | */ |
Ulrich Weigand | eb94c7d | 1999-11-13 23:54:04 +0000 | [diff] [blame] | 763 | void WINAPI SUnMapLS_IP_EBP_16(CONTEXT86 *context) { x_SUnMapLS_IP_EBP_x(context,16); } |
Patrik Stridvall | 54fe838 | 2000-04-06 20:21:16 +0000 | [diff] [blame] | 764 | |
| 765 | /*********************************************************************** |
| 766 | * SUnMapLS_IP_EBP_20 (KERNEL32.605) |
| 767 | */ |
Ulrich Weigand | eb94c7d | 1999-11-13 23:54:04 +0000 | [diff] [blame] | 768 | void WINAPI SUnMapLS_IP_EBP_20(CONTEXT86 *context) { x_SUnMapLS_IP_EBP_x(context,20); } |
Patrik Stridvall | 54fe838 | 2000-04-06 20:21:16 +0000 | [diff] [blame] | 769 | |
| 770 | /*********************************************************************** |
| 771 | * SUnMapLS_IP_EBP_24 (KERNEL32.606) |
| 772 | */ |
Ulrich Weigand | eb94c7d | 1999-11-13 23:54:04 +0000 | [diff] [blame] | 773 | void WINAPI SUnMapLS_IP_EBP_24(CONTEXT86 *context) { x_SUnMapLS_IP_EBP_x(context,24); } |
Patrik Stridvall | 54fe838 | 2000-04-06 20:21:16 +0000 | [diff] [blame] | 774 | |
| 775 | /*********************************************************************** |
| 776 | * SUnMapLS_IP_EBP_28 (KERNEL32.607) |
| 777 | */ |
Ulrich Weigand | eb94c7d | 1999-11-13 23:54:04 +0000 | [diff] [blame] | 778 | void WINAPI SUnMapLS_IP_EBP_28(CONTEXT86 *context) { x_SUnMapLS_IP_EBP_x(context,28); } |
Patrik Stridvall | 54fe838 | 2000-04-06 20:21:16 +0000 | [diff] [blame] | 779 | |
| 780 | /*********************************************************************** |
| 781 | * SUnMapLS_IP_EBP_32 (KERNEL32.608) |
| 782 | */ |
Ulrich Weigand | eb94c7d | 1999-11-13 23:54:04 +0000 | [diff] [blame] | 783 | void WINAPI SUnMapLS_IP_EBP_32(CONTEXT86 *context) { x_SUnMapLS_IP_EBP_x(context,32); } |
Patrik Stridvall | 54fe838 | 2000-04-06 20:21:16 +0000 | [diff] [blame] | 784 | |
| 785 | /*********************************************************************** |
| 786 | * SUnMapLS_IP_EBP_36 (KERNEL32.609) |
| 787 | */ |
Ulrich Weigand | eb94c7d | 1999-11-13 23:54:04 +0000 | [diff] [blame] | 788 | void WINAPI SUnMapLS_IP_EBP_36(CONTEXT86 *context) { x_SUnMapLS_IP_EBP_x(context,36); } |
Patrik Stridvall | 54fe838 | 2000-04-06 20:21:16 +0000 | [diff] [blame] | 789 | |
| 790 | /*********************************************************************** |
| 791 | * SUnMapLS_IP_EBP_40 (KERNEL32.610) |
| 792 | */ |
Ulrich Weigand | eb94c7d | 1999-11-13 23:54:04 +0000 | [diff] [blame] | 793 | void WINAPI SUnMapLS_IP_EBP_40(CONTEXT86 *context) { x_SUnMapLS_IP_EBP_x(context,40); } |
Alexandre Julliard | 3db94ef | 1997-09-28 17:43:24 +0000 | [diff] [blame] | 794 | |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 795 | /********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 796 | * AllocMappedBuffer (KERNEL32.38) |
| 797 | * |
| 798 | * This is a undocumented KERNEL32 function that |
| 799 | * SMapLS's a GlobalAlloc'ed buffer. |
| 800 | * |
| 801 | * Input: EDI register: size of buffer to allocate |
| 802 | * Output: EDI register: pointer to buffer |
| 803 | * |
| 804 | * Note: The buffer is preceeded by 8 bytes: |
| 805 | * ... |
| 806 | * edi+0 buffer |
| 807 | * edi-4 SEGPTR to buffer |
| 808 | * edi-8 some magic Win95 needs for SUnMapLS |
| 809 | * (we use it for the memory handle) |
| 810 | * |
| 811 | * The SEGPTR is used by the caller! |
| 812 | */ |
| 813 | |
Ulrich Weigand | eb94c7d | 1999-11-13 23:54:04 +0000 | [diff] [blame] | 814 | void WINAPI AllocMappedBuffer( CONTEXT86 *context ) |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 815 | { |
Alexandre Julliard | d8fab2e | 2000-09-25 23:53:07 +0000 | [diff] [blame] | 816 | HGLOBAL handle = GlobalAlloc(0, context->Edi + 8); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 817 | DWORD *buffer = (DWORD *)GlobalLock(handle); |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 818 | SEGPTR ptr = 0; |
| 819 | |
| 820 | if (buffer) |
| 821 | if (!(ptr = MapLS(buffer + 2))) |
| 822 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 823 | GlobalUnlock(handle); |
| 824 | GlobalFree(handle); |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | if (!ptr) |
Alexandre Julliard | d8fab2e | 2000-09-25 23:53:07 +0000 | [diff] [blame] | 828 | context->Eax = context->Edi = 0; |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 829 | else |
| 830 | { |
| 831 | buffer[0] = handle; |
| 832 | buffer[1] = ptr; |
| 833 | |
Alexandre Julliard | d8fab2e | 2000-09-25 23:53:07 +0000 | [diff] [blame] | 834 | context->Eax = (DWORD) ptr; |
| 835 | context->Edi = (DWORD)(buffer + 2); |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 836 | } |
| 837 | } |
| 838 | |
| 839 | /********************************************************************** |
| 840 | * FreeMappedBuffer (KERNEL32.39) |
| 841 | * |
| 842 | * Free a buffer allocated by AllocMappedBuffer |
| 843 | * |
| 844 | * Input: EDI register: pointer to buffer |
| 845 | */ |
| 846 | |
Ulrich Weigand | eb94c7d | 1999-11-13 23:54:04 +0000 | [diff] [blame] | 847 | void WINAPI FreeMappedBuffer( CONTEXT86 *context ) |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 848 | { |
Alexandre Julliard | d8fab2e | 2000-09-25 23:53:07 +0000 | [diff] [blame] | 849 | if (context->Edi) |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 850 | { |
Alexandre Julliard | d8fab2e | 2000-09-25 23:53:07 +0000 | [diff] [blame] | 851 | DWORD *buffer = (DWORD *)context->Edi - 2; |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 852 | |
| 853 | UnMapLS(buffer[1]); |
| 854 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 855 | GlobalUnlock(buffer[0]); |
| 856 | GlobalFree(buffer[0]); |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 857 | } |
| 858 | } |
| 859 | |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 860 | |
| 861 | /*********************************************************************** |
| 862 | * UTSelectorOffsetToLinear (WIN32S16.48) |
| 863 | * |
| 864 | * rough guesswork, but seems to work (I had no "reasonable" docu) |
| 865 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 866 | LPVOID WINAPI UTSelectorOffsetToLinear16(SEGPTR sptr) |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 867 | { |
| 868 | return PTR_SEG_TO_LIN(sptr); |
| 869 | } |
| 870 | |
| 871 | /*********************************************************************** |
| 872 | * UTLinearToSelectorOffset (WIN32S16.49) |
| 873 | * |
| 874 | * FIXME: I don't know if that's the right way to do linear -> segmented |
| 875 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 876 | SEGPTR WINAPI UTLinearToSelectorOffset16(LPVOID lptr) |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 877 | { |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 878 | return (SEGPTR)lptr; |
| 879 | } |
Alexandre Julliard | 916f975 | 2000-02-26 16:51:13 +0000 | [diff] [blame] | 880 | |
| 881 | #ifdef __i386__ |
Patrik Stridvall | ea4f831 | 2000-02-27 16:39:48 +0000 | [diff] [blame] | 882 | __ASM_GLOBAL_FUNC( __get_cs, "movw %cs,%ax\n\tret" ) |
| 883 | __ASM_GLOBAL_FUNC( __get_ds, "movw %ds,%ax\n\tret" ) |
| 884 | __ASM_GLOBAL_FUNC( __get_es, "movw %es,%ax\n\tret" ) |
| 885 | __ASM_GLOBAL_FUNC( __get_fs, "movw %fs,%ax\n\tret" ) |
| 886 | __ASM_GLOBAL_FUNC( __get_gs, "movw %gs,%ax\n\tret" ) |
| 887 | __ASM_GLOBAL_FUNC( __get_ss, "movw %ss,%ax\n\tret" ) |
| 888 | __ASM_GLOBAL_FUNC( __set_fs, "movl 4(%esp),%eax\n\tmovw %ax,%fs\n\tret" ) |
| 889 | __ASM_GLOBAL_FUNC( __set_gs, "movl 4(%esp),%eax\n\tmovw %ax,%gs\n\tret" ) |
Alexandre Julliard | 916f975 | 2000-02-26 16:51:13 +0000 | [diff] [blame] | 890 | #endif |