AllocPage

Allocates non-swappable memory pages.

32-bit API

#include "scnsm.h"

BOOL DeviceIoControl(
    HANDLE hDevice, // handle to SCNSM driver
    DWORD dwControlCode, // control code of operation to perform
    LPVOID pInBuffer // (Unused) pointer to input data buffer
    DWORD cbInBuffer // (Unused) size of input buffer
    LPVOID pOutBuffer // pointer to output data buffer
    DWORD cbOutBuffer // number of pages to allocate
    LPDWORD pcbReturned // (Unused) pointer to receive output byte count
    LPOVERLAPPED pOverlapped // (Unused)
);

16-bit API

include scnsm.inc

    mov ax, dwControlCode
    mov bx, cbOutBuffer
    lea cx, pOutBuffer
    lea dx, hOutBuffer
    call [hDevice]

Uses EAX, EBX, ECX, EDX, Flags.

Parameters

hDevice
[in] Handle to SCNSM driver. For 32-bit API, returned by CreateFile. For 16-bit API, returned by int 2fh.
dwControlCode
[in] Must be NSM_ALLOCPAGE.
hOutBuffer
[out] Receives the allocated memory handle. Used by FreePage (16-bit API) to free the memory.
pOutBuffer
[out] Receives a pointer to the memory page.
cbOutBuffer
[in] Desired number of memory pages to allocate.

Return Values

32-bit API

If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError for error codes defined below.

16-bit API

If the function succeeds, the EAX register is zero. If the function fails, the EAX register holds an error code defined below.

Remarks

Windows 3.x does not support dynamic allocation fixed, contiguous memory pages as required by AllocPage. Win3.x allows such allocations only when the driver is loaded, at startup. Consequently, When SCNSM is loaded, a single, semaphore-locked page is allocated and used throughout that Windows session. If the page has already been allocated to a process, AllocPage fails with ERROR_LOCK_VIOLATION until the process holding the page frees it with FreePage.

Error Codes

ERROR_INVALID_FUNCTION (1)
An unsupported control code was entered.
ERROR_NOT_ENOUGH_MEMORY (8)
There is not enough memory to fullfill the allocation request.
ERROR_BAD_ENVIRONMENT (10)
Virtual machine where allocation is requested is not the system virtual machine (16-bit API only).
ERROR_GEN_FAILURE (31)
An unknown error has occurred.
ERROR_LOCK_VIOLATION (33)
The only available memory is locked by another process.
ERROR_INVALID_PARAMETER (87)
An input parameter is invalid.