virtual.c 23.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
/*
 * WoW64 virtual memory functions
 *
 * Copyright 2021 Alexandre Julliard
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include <stdarg.h>

#include "ntstatus.h"
#define WIN32_NO_STATUS
#include "windef.h"
#include "winbase.h"
#include "winnt.h"
#include "winternl.h"
#include "winioctl.h"
#include "wow64_private.h"
#include "wine/debug.h"

WINE_DEFAULT_DEBUG_CHANNEL(wow);


36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
static MEMORY_RANGE_ENTRY *memory_range_entry_array_32to64( const MEMORY_RANGE_ENTRY32 *addresses32,
                                                            ULONG count )
{
    MEMORY_RANGE_ENTRY *addresses = Wow64AllocateTemp( sizeof(MEMORY_RANGE_ENTRY) * count );
    ULONG i;

    for (i = 0; i < count; i++)
    {
        addresses[i].VirtualAddress = ULongToPtr( addresses32[i].VirtualAddress );
        addresses[i].NumberOfBytes = addresses32[i].NumberOfBytes;
    }

    return addresses;
}

51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
static NTSTATUS mem_extended_parameters_32to64( MEM_EXTENDED_PARAMETER **ret_params,
                                                const MEM_EXTENDED_PARAMETER32 *params32, ULONG *count,
                                                BOOL set_limit )
{
    ULONG i;
    MEM_EXTENDED_PARAMETER *params;
    MEM_ADDRESS_REQUIREMENTS *req;
    MEM_ADDRESS_REQUIREMENTS32 *req32 = NULL;

    if (*count && !params32) return STATUS_INVALID_PARAMETER;

    params = Wow64AllocateTemp( (*count + 1) * sizeof(*params) + sizeof(*req) );
    req = (MEM_ADDRESS_REQUIREMENTS *)(params + *count + 1);

    for (i = 0; i < *count; i++)
    {
        params[i].Type = params32[i].Type;
        params[i].Reserved = 0;
        switch (params[i].Type)
        {
        case MemExtendedParameterAddressRequirements:
            req32 = ULongToPtr( params32[i].Pointer );
            params[i].Pointer = req;
            break;
        case MemExtendedParameterAttributeFlags:
        case MemExtendedParameterNumaNode:
        case MemExtendedParameterImageMachine:
            params[i].ULong = params32[i].ULong;
            break;
        case MemExtendedParameterPartitionHandle:
        case MemExtendedParameterUserPhysicalHandle:
            params[i].Handle = ULongToHandle( params32[i].Handle );
            break;
        }
    }

    if (req32)
    {
        if (req32->HighestEndingAddress > highest_user_address) return STATUS_INVALID_PARAMETER;
        req->LowestStartingAddress = ULongToPtr( req32->LowestStartingAddress );
        req->HighestEndingAddress  = ULongToPtr( req32->HighestEndingAddress );
        req->Alignment             = req32->Alignment;
    }
    else if (set_limit)
    {
        req->LowestStartingAddress = NULL;
        req->HighestEndingAddress  = (void *)highest_user_address;
        req->Alignment             = 0;

        params[i].Type = MemExtendedParameterAddressRequirements;
        params[i].Reserved = 0;
        params[i].Pointer = req;
        *count = i + 1;
    }
    *ret_params = params;
    return STATUS_SUCCESS;
}

109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
/**********************************************************************
 *           wow64_NtAllocateVirtualMemory
 */
NTSTATUS WINAPI wow64_NtAllocateVirtualMemory( UINT *args )
{
    HANDLE process = get_handle( &args );
    ULONG *addr32 = get_ptr( &args );
    ULONG_PTR zero_bits = get_ulong( &args );
    ULONG *size32 = get_ptr( &args );
    ULONG type = get_ulong( &args );
    ULONG protect = get_ulong( &args );

    void *addr;
    SIZE_T size;
    NTSTATUS status;

    status = NtAllocateVirtualMemory( process, addr_32to64( &addr, addr32 ), get_zero_bits( zero_bits ),
                                      size_32to64( &size, size32 ), type, protect );
    if (!status)
    {
        put_addr( addr32, addr );
        put_size( size32, size );
    }
    return status;
}


/**********************************************************************
 *           wow64_NtAllocateVirtualMemoryEx
 */
NTSTATUS WINAPI wow64_NtAllocateVirtualMemoryEx( UINT *args )
{
    HANDLE process = get_handle( &args );
    ULONG *addr32 = get_ptr( &args );
    ULONG *size32 = get_ptr( &args );
    ULONG type = get_ulong( &args );
    ULONG protect = get_ulong( &args );
146
    MEM_EXTENDED_PARAMETER32 *params32 = get_ptr( &args );
147 148 149 150 151
    ULONG count = get_ulong( &args );

    void *addr;
    SIZE_T size;
    NTSTATUS status;
152
    MEM_EXTENDED_PARAMETER *params64;
153
    BOOL set_limit = (!*addr32 && process == GetCurrentProcess());
154

155
    if ((status = mem_extended_parameters_32to64( &params64, params32, &count, set_limit ))) return status;
156 157

    status = NtAllocateVirtualMemoryEx( process, addr_32to64( &addr, addr32 ), size_32to64( &size, size32 ),
158
                                        type, protect, params64, count );
159 160 161 162 163 164 165 166 167
    if (!status)
    {
        put_addr( addr32, addr );
        put_size( size32, size );
    }
    return status;
}


168 169 170 171 172 173 174 175 176 177 178 179
/**********************************************************************
 *           wow64_NtAreMappedFilesTheSame
 */
NTSTATUS WINAPI wow64_NtAreMappedFilesTheSame( UINT *args )
{
    void *ptr1 = get_ptr( &args );
    void *ptr2 = get_ptr( &args );

    return NtAreMappedFilesTheSame( ptr1, ptr2 );
}


180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
/**********************************************************************
 *           wow64_NtFlushVirtualMemory
 */
NTSTATUS WINAPI wow64_NtFlushVirtualMemory( UINT *args )
{
    HANDLE process = get_handle( &args );
    ULONG *addr32 = get_ptr( &args );
    ULONG *size32 = get_ptr( &args );
    ULONG unknown = get_ulong( &args );

    void *addr;
    SIZE_T size;
    NTSTATUS status;

    status = NtFlushVirtualMemory( process, (const void **)addr_32to64( &addr, addr32 ),
                                   size_32to64( &size, size32 ), unknown );
    if (!status)
    {
        put_addr( addr32, addr );
        put_size( size32, size );
    }
    return status;
}


/**********************************************************************
 *           wow64_NtFreeVirtualMemory
 */
NTSTATUS WINAPI wow64_NtFreeVirtualMemory( UINT *args )
{
    HANDLE process = get_handle( &args );
    ULONG *addr32 = get_ptr( &args );
    ULONG *size32 = get_ptr( &args );
    ULONG type = get_ulong( &args );

    void *addr;
    SIZE_T size;
    NTSTATUS status;

    status = NtFreeVirtualMemory( process, addr_32to64( &addr, addr32 ),
                                  size_32to64( &size, size32 ), type );
    if (!status)
    {
        put_addr( addr32, addr );
        put_size( size32, size );
    }
    return status;
}


230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
/**********************************************************************
 *           wow64_NtGetNlsSectionPtr
 */
NTSTATUS WINAPI wow64_NtGetNlsSectionPtr( UINT *args )
{
    ULONG type = get_ulong( &args );
    ULONG id = get_ulong( &args );
    void *unknown = get_ptr( &args );
    ULONG *addr32 = get_ptr( &args );
    ULONG *size32 = get_ptr( &args );

    void *addr;
    SIZE_T size;
    NTSTATUS status;

    status = NtGetNlsSectionPtr( type, id, unknown, addr_32to64( &addr, addr32 ),
                                 size_32to64( &size, size32 ));
    if (!status)
    {
        put_addr( addr32, addr );
        put_size( size32, size );
    }
    return status;
}


256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
/**********************************************************************
 *           wow64_NtGetWriteWatch
 */
NTSTATUS WINAPI wow64_NtGetWriteWatch( UINT *args )
{
    HANDLE handle = get_handle( &args );
    ULONG flags = get_ulong( &args );
    void *base = get_ptr( &args );
    SIZE_T size = get_ulong( &args );
    ULONG *addr_ptr = get_ptr( &args );
    ULONG *count_ptr = get_ptr( &args );
    ULONG *granularity = get_ptr( &args );

    ULONG_PTR i, count = *count_ptr;
    void **addresses;
    NTSTATUS status;

    if (!count || !size) return STATUS_INVALID_PARAMETER;
    if (flags & ~WRITE_WATCH_FLAG_RESET) return STATUS_INVALID_PARAMETER;
    if (!addr_ptr) return STATUS_ACCESS_VIOLATION;

277
    addresses = Wow64AllocateTemp( count * sizeof(*addresses) );
278 279 280 281 282 283 284 285 286
    if (!(status = NtGetWriteWatch( handle, flags, base, size, addresses, &count, granularity )))
    {
        for (i = 0; i < count; i++) addr_ptr[i] = PtrToUlong( addresses[i] );
        *count_ptr = count;
    }
    return status;
}


287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
/**********************************************************************
 *           wow64_NtInitializeNlsFiles
 */
NTSTATUS WINAPI wow64_NtInitializeNlsFiles( UINT *args )
{
    ULONG *addr32 = get_ptr( &args );
    LCID *lcid = get_ptr( &args );
    LARGE_INTEGER *size = get_ptr( &args );

    void *addr;
    NTSTATUS status;

    status = NtInitializeNlsFiles( addr_32to64( &addr, addr32 ), lcid, size );
    if (!status) put_addr( addr32, addr );
    return status;
}


305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
/**********************************************************************
 *           wow64_NtLockVirtualMemory
 */
NTSTATUS WINAPI wow64_NtLockVirtualMemory( UINT *args )
{
    HANDLE process = get_handle( &args );
    ULONG *addr32 = get_ptr( &args );
    ULONG *size32 = get_ptr( &args );
    ULONG unknown = get_ulong( &args );

    void *addr;
    SIZE_T size;
    NTSTATUS status;

    status = NtLockVirtualMemory( process, addr_32to64( &addr, addr32 ),
                                  size_32to64( &size, size32 ), unknown );
    if (!status)
    {
        put_addr( addr32, addr );
        put_size( size32, size );
    }
    return status;
}


330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
/**********************************************************************
 *           wow64_NtMapViewOfSection
 */
NTSTATUS WINAPI wow64_NtMapViewOfSection( UINT *args )
{
    HANDLE handle = get_handle( &args );
    HANDLE process = get_handle( &args );
    ULONG *addr32 = get_ptr( &args );
    ULONG_PTR zero_bits = get_ulong( &args );
    SIZE_T commit = get_ulong( &args );
    const LARGE_INTEGER *offset = get_ptr( &args );
    ULONG *size32 = get_ptr( &args );
    SECTION_INHERIT inherit = get_ulong( &args );
    ULONG alloc = get_ulong( &args );
    ULONG protect = get_ulong( &args );

    void *addr;
    SIZE_T size;
    NTSTATUS status;

    status = NtMapViewOfSection( handle, process, addr_32to64( &addr, addr32 ), get_zero_bits( zero_bits ),
                                 commit, offset, size_32to64( &size, size32 ), inherit, alloc, protect );
    if (NT_SUCCESS(status))
    {
354 355 356 357 358 359
        SECTION_IMAGE_INFORMATION info;

        if (!NtQuerySection( handle, SectionImageInformation, &info, sizeof(info), NULL ))
        {
            if (info.Machine == current_machine) init_image_mapping( addr );
        }
360 361 362 363 364 365
        put_addr( addr32, addr );
        put_size( size32, size );
    }
    return status;
}

366 367 368 369 370 371 372 373 374 375 376 377
/**********************************************************************
 *           wow64_NtMapViewOfSectionEx
 */
NTSTATUS WINAPI wow64_NtMapViewOfSectionEx( UINT *args )
{
    HANDLE handle = get_handle( &args );
    HANDLE process = get_handle( &args );
    ULONG *addr32 = get_ptr( &args );
    const LARGE_INTEGER *offset = get_ptr( &args );
    ULONG *size32 = get_ptr( &args );
    ULONG alloc = get_ulong( &args );
    ULONG protect = get_ulong( &args );
378 379
    MEM_EXTENDED_PARAMETER32 *params32 = get_ptr( &args );
    ULONG count = get_ulong( &args );
380 381 382 383

    void *addr;
    SIZE_T size;
    NTSTATUS status;
384 385 386 387
    MEM_EXTENDED_PARAMETER *params64;
    BOOL set_limit = (!*addr32 && process == GetCurrentProcess());

    if ((status = mem_extended_parameters_32to64( &params64, params32, &count, set_limit ))) return status;
388

389 390
    status = NtMapViewOfSectionEx( handle, process, addr_32to64( &addr, addr32 ), offset,
                                   size_32to64( &size, size32 ), alloc, protect, params64, count );
391 392 393 394 395 396 397 398 399 400 401 402 403
    if (NT_SUCCESS(status))
    {
        SECTION_IMAGE_INFORMATION info;

        if (!NtQuerySection( handle, SectionImageInformation, &info, sizeof(info), NULL ))
        {
            if (info.Machine == current_machine) init_image_mapping( addr );
        }
        put_addr( addr32, addr );
        put_size( size32, size );
    }
    return status;
}
404

405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430
/**********************************************************************
 *           wow64_NtProtectVirtualMemory
 */
NTSTATUS WINAPI wow64_NtProtectVirtualMemory( UINT *args )
{
    HANDLE process = get_handle( &args );
    ULONG *addr32 = get_ptr( &args );
    ULONG *size32 = get_ptr( &args );
    ULONG new_prot = get_ulong( &args );
    ULONG *old_prot = get_ptr( &args );

    void *addr;
    SIZE_T size;
    NTSTATUS status;

    status = NtProtectVirtualMemory( process, addr_32to64( &addr, addr32 ),
                                     size_32to64( &size, size32 ), new_prot, old_prot );
    if (!status)
    {
        put_addr( addr32, addr );
        put_size( size32, size );
    }
    return status;
}


431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448
/**********************************************************************
 *           wow64_NtQueryVirtualMemory
 */
NTSTATUS WINAPI wow64_NtQueryVirtualMemory( UINT *args )
{
    HANDLE handle = get_handle( &args );
    void *addr = get_ptr( &args );
    MEMORY_INFORMATION_CLASS class = get_ulong( &args );
    void *ptr = get_ptr( &args );
    ULONG len = get_ulong( &args );
    ULONG *retlen = get_ptr( &args );

    SIZE_T res_len = 0;
    NTSTATUS status;

    switch (class)
    {
    case MemoryBasicInformation:  /* MEMORY_BASIC_INFORMATION */
449 450 451 452 453
        if (len < sizeof(MEMORY_BASIC_INFORMATION32))
            status = STATUS_INFO_LENGTH_MISMATCH;
        else if ((ULONG_PTR)addr > highest_user_address)
            status = STATUS_INVALID_PARAMETER;
        else
454 455 456 457 458 459 460 461 462 463 464 465 466
        {
            MEMORY_BASIC_INFORMATION info;
            MEMORY_BASIC_INFORMATION32 *info32 = ptr;

            if (!(status = NtQueryVirtualMemory( handle, addr, class, &info, sizeof(info), &res_len )))
            {
                info32->BaseAddress = PtrToUlong( info.BaseAddress );
                info32->AllocationBase = PtrToUlong( info.AllocationBase );
                info32->AllocationProtect = info.AllocationProtect;
                info32->RegionSize = info.RegionSize;
                info32->State = info.State;
                info32->Protect = info.Protect;
                info32->Type = info.Type;
467 468
                if ((ULONG_PTR)info.BaseAddress + info.RegionSize > highest_user_address)
                    info32->RegionSize = highest_user_address - (ULONG_PTR)info.BaseAddress + 1;
469 470 471 472 473
            }
        }
        res_len = sizeof(MEMORY_BASIC_INFORMATION32);
        break;

474
    case MemoryMappedFilenameInformation:  /* MEMORY_SECTION_NAME */
475 476 477 478 479
    {
        MEMORY_SECTION_NAME *info;
        MEMORY_SECTION_NAME32 *info32 = ptr;
        SIZE_T size = len + sizeof(*info) - sizeof(*info32);

480
        info = Wow64AllocateTemp( size );
481 482 483 484 485 486 487 488 489 490 491
        if (!(status = NtQueryVirtualMemory( handle, addr, class, info, size, &res_len )))
        {
            info32->SectionFileName.Length = info->SectionFileName.Length;
            info32->SectionFileName.MaximumLength = info->SectionFileName.MaximumLength;
            info32->SectionFileName.Buffer = PtrToUlong( info32 + 1 );
            memcpy( info32 + 1, info->SectionFileName.Buffer, info->SectionFileName.MaximumLength );
        }
        res_len += sizeof(*info32) - sizeof(*info);
        break;
    }

492 493
    case MemoryRegionInformation: /* MEMORY_REGION_INFORMATION */
    {
494 495 496 497 498
        if (len < sizeof(MEMORY_REGION_INFORMATION32))
            status = STATUS_INFO_LENGTH_MISMATCH;
        if ((ULONG_PTR)addr > highest_user_address)
            status = STATUS_INVALID_PARAMETER;
        else
499 500 501 502 503 504 505 506 507 508 509 510 511
        {
            MEMORY_REGION_INFORMATION info;
            MEMORY_REGION_INFORMATION32 *info32 = ptr;

            if (!(status = NtQueryVirtualMemory( handle, addr, class, &info, sizeof(info), &res_len )))
            {
                info32->AllocationBase = PtrToUlong( info.AllocationBase );
                info32->AllocationProtect = info.AllocationProtect;
                info32->RegionType = info.RegionType;
                info32->RegionSize = info.RegionSize;
                info32->CommitSize = info.CommitSize;
                info32->PartitionId = info.PartitionId;
                info32->NodePreference = info.NodePreference;
512 513
                if ((ULONG_PTR)info.AllocationBase + info.RegionSize > highest_user_address)
                    info32->RegionSize = highest_user_address - (ULONG_PTR)info.AllocationBase + 1;
514 515 516 517 518 519
            }
        }
        res_len = sizeof(MEMORY_REGION_INFORMATION32);
        break;
    }

520 521 522 523 524 525
    case MemoryWorkingSetExInformation:  /* MEMORY_WORKING_SET_EX_INFORMATION */
    {
        MEMORY_WORKING_SET_EX_INFORMATION32 *info32 = ptr;
        MEMORY_WORKING_SET_EX_INFORMATION *info;
        ULONG i, count = len / sizeof(*info32);

526
        info = Wow64AllocateTemp( count * sizeof(*info) );
527 528 529 530 531 532 533 534 535 536
        for (i = 0; i < count; i++) info[i].VirtualAddress = ULongToPtr( info32[i].VirtualAddress );
        if (!(status = NtQueryVirtualMemory( handle, addr, class, info, count * sizeof(*info), &res_len )))
        {
            count = res_len / sizeof(*info);
            for (i = 0; i < count; i++) info32[i].VirtualAttributes.Flags = info[i].VirtualAttributes.Flags;
            res_len = count * sizeof(*info32);
        }
        break;
    }

537
    case MemoryWineUnixWow64Funcs:
538 539
        return STATUS_INVALID_INFO_CLASS;

540 541 542 543
    case MemoryWineUnixFuncs:
        status = NtQueryVirtualMemory( handle, addr, MemoryWineUnixWow64Funcs, ptr, len, &res_len );
        break;

544 545 546 547 548 549 550 551 552
    default:
        FIXME( "unsupported class %u\n", class );
        return STATUS_INVALID_INFO_CLASS;
    }
    if (!status || status == STATUS_INFO_LENGTH_MISMATCH) put_size( retlen, res_len );
    return status;
}


553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572
/**********************************************************************
 *           wow64_NtReadVirtualMemory
 */
NTSTATUS WINAPI wow64_NtReadVirtualMemory( UINT *args )
{
    HANDLE process = get_handle( &args );
    const void *addr = get_ptr( &args );
    void *buffer = get_ptr( &args );
    SIZE_T size = get_ulong( &args );
    ULONG *retlen = get_ptr( &args );

    SIZE_T ret_size;
    NTSTATUS status;

    status = NtReadVirtualMemory( process, addr, buffer, size, &ret_size );
    put_size( retlen, ret_size );
    return status;
}


573 574 575 576 577 578 579 580 581 582 583 584 585
/**********************************************************************
 *           wow64_NtResetWriteWatch
 */
NTSTATUS WINAPI wow64_NtResetWriteWatch( UINT *args )
{
    HANDLE process = get_handle( &args );
    void *base = get_ptr( &args );
    SIZE_T size = get_ulong( &args );

    return NtResetWriteWatch( process, base, size );
}


586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616
/**********************************************************************
 *           wow64_NtSetInformationVirtualMemory
 */
NTSTATUS WINAPI wow64_NtSetInformationVirtualMemory( UINT *args )
{
    HANDLE process = get_handle( &args );
    VIRTUAL_MEMORY_INFORMATION_CLASS info_class = get_ulong( &args );
    ULONG count = get_ulong( &args );
    MEMORY_RANGE_ENTRY32 *addresses32 = get_ptr( &args );
    PVOID ptr = get_ptr( &args );
    ULONG len = get_ulong( &args );

    MEMORY_RANGE_ENTRY *addresses;

    if (!count) return STATUS_INVALID_PARAMETER_3;
    addresses = memory_range_entry_array_32to64( addresses32, count );

    switch (info_class)
    {
    case VmPrefetchInformation:
        break;
    default:
        FIXME( "(%p,info_class=%u,%lu,%p,%p,%lu): not implemented\n",
               process, info_class, count, addresses32, ptr, len );
        return STATUS_INVALID_PARAMETER_2;
    }

    return NtSetInformationVirtualMemory( process, info_class, count, addresses, ptr, len );
}


617 618 619 620 621 622 623 624 625 626 627 628
/**********************************************************************
 *           wow64_NtSetLdtEntries
 */
NTSTATUS WINAPI wow64_NtSetLdtEntries( UINT *args )
{
    ULONG sel1 = get_ulong( &args );
    ULONG entry1_low = get_ulong( &args );
    ULONG entry1_high = get_ulong( &args );
    ULONG sel2 = get_ulong( &args );
    ULONG entry2_low = get_ulong( &args );
    ULONG entry2_high = get_ulong( &args );

629
    FIXME( "%04lx %08lx %08lx %04lx %08lx %08lx: stub\n",
630 631 632 633 634
           sel1, entry1_low, entry1_high, sel2, entry2_low, entry2_high );
    return STATUS_NOT_IMPLEMENTED;
}


635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659
/**********************************************************************
 *           wow64_NtUnlockVirtualMemory
 */
NTSTATUS WINAPI wow64_NtUnlockVirtualMemory( UINT *args )
{
    HANDLE process = get_handle( &args );
    ULONG *addr32 = get_ptr( &args );
    ULONG *size32 = get_ptr( &args );
    ULONG unknown = get_ulong( &args );

    void *addr;
    SIZE_T size;
    NTSTATUS status;

    status = NtUnlockVirtualMemory( process, addr_32to64( &addr, addr32 ),
                                    size_32to64( &size, size32 ), unknown );
    if (!status)
    {
        put_addr( addr32, addr );
        put_size( size32, size );
    }
    return status;
}


660 661 662 663 664 665 666 667 668 669 670 671
/**********************************************************************
 *           wow64_NtUnmapViewOfSection
 */
NTSTATUS WINAPI wow64_NtUnmapViewOfSection( UINT *args )
{
    HANDLE process = get_handle( &args );
    void *addr = get_ptr( &args );

    return NtUnmapViewOfSection( process, addr );
}


672 673 674 675 676 677 678 679 680 681 682 683 684
/**********************************************************************
 *           wow64_NtUnmapViewOfSectionEx
 */
NTSTATUS WINAPI wow64_NtUnmapViewOfSectionEx( UINT *args )
{
    HANDLE process = get_handle( &args );
    void *addr = get_ptr( &args );
    ULONG flags = get_ulong( &args );

    return NtUnmapViewOfSectionEx( process, addr, flags );
}


685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730
/**********************************************************************
 *           wow64_NtWow64AllocateVirtualMemory64
 */
NTSTATUS WINAPI wow64_NtWow64AllocateVirtualMemory64( UINT *args )
{
    HANDLE process = get_handle( &args );
    void **addr = get_ptr( &args );
    ULONG_PTR zero_bits = get_ulong64( &args );
    SIZE_T *size = get_ptr( &args );
    ULONG type = get_ulong( &args );
    ULONG protect = get_ulong( &args );

    return NtAllocateVirtualMemory( process, addr, zero_bits, size, type, protect );
}


/**********************************************************************
 *           wow64_NtWow64ReadVirtualMemory64
 */
NTSTATUS WINAPI wow64_NtWow64ReadVirtualMemory64( UINT *args )
{
    HANDLE process = get_handle( &args );
    void *addr = (void *)(ULONG_PTR)get_ulong64( &args );
    void *buffer = get_ptr( &args );
    SIZE_T size = get_ulong64( &args );
    SIZE_T *ret_size = get_ptr( &args );

    return NtReadVirtualMemory( process, addr, buffer, size, ret_size );
}


/**********************************************************************
 *           wow64_NtWow64WriteVirtualMemory64
 */
NTSTATUS WINAPI wow64_NtWow64WriteVirtualMemory64( UINT *args )
{
    HANDLE process = get_handle( &args );
    void *addr = (void *)(ULONG_PTR)get_ulong64( &args );
    const void *buffer = get_ptr( &args );
    SIZE_T size = get_ulong64( &args );
    SIZE_T *ret_size = get_ptr( &args );

    return NtWriteVirtualMemory( process, addr, buffer, size, ret_size );
}


731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748
/**********************************************************************
 *           wow64_NtWriteVirtualMemory
 */
NTSTATUS WINAPI wow64_NtWriteVirtualMemory( UINT *args )
{
    HANDLE process = get_handle( &args );
    void *addr = get_ptr( &args );
    const void *buffer = get_ptr( &args );
    SIZE_T size = get_ulong( &args );
    ULONG *retlen = get_ptr( &args );

    SIZE_T ret_size;
    NTSTATUS status;

    status = NtWriteVirtualMemory( process, addr, buffer, size, &ret_size );
    put_size( retlen, ret_size );
    return status;
}