DevHelp VMProcessToGlobal

From EDM2
Jump to: navigation, search

This service converts an address in the current process address space to an address in the system region of the global address space.

Syntax

C

USHORT APIENTRY DevHelp_VMProcessToGlobal( ULONG Flags,
                                           LIN   LinearAddr,
                                           ULONG Length,
                                           PLIN  GlobalLinearAddr)

Assembler

MOV   EBX,LinearAddress     ; Linear Address within process address space
                            ;    that is to be mapped into a global context;
                            ;    must be on a page boundary
MOV   ECX,Length            ; Length of request in bytes
MOV   EAX,ActionFlags       ; Action to perform
                            ; If bit 0 (00001B) is set, the mapping created will
                            ;    be writable.  If this bit is clear, the mapping
                            ;    will be read only
                            ;   (Note:  Some hardware may not support read only
                            ;    mapping).
                            ; All other bits must be clear.

MOV   DL,DevHlp_VMProcessToGlobal

CALL  [Device_Help]

Parameters

C

Flags (ULONG) 
Action to perform:
MDHPG_READONLY - If bit 0 is clear, its mapping will be read only.
VMDHPG_WRITEV - If bit 0 is set, the mapping created will be writable.
All other bits must be clear.
LinearAddr (LIN) 
Linearaddress within process space that is to be mapped into a global context; must be on a page boundary.
Length (ULONG) 
Length of address space to be mapped.
GlobalLinearAddr (PLIN) 
Global offset to region of memory returned.

Assembler

MOV   EBX,LinearAddress     ; Linear Address within process address space
                            ;    that is to be mapped into a global context;
                            ;    must be on a page boundary
MOV   ECX,Length            ; Length of request in bytes
MOV   EAX,ActionFlags       ; Action to perform
                            ; If bit 0 (00001B) is set, the mapping created will
                            ;    be writable.  If this bit is clear, the mapping
                            ;    will be read only
                            ;   (Note:  Some hardware may not support read only
                            ;    mapping).
                            ; All other bits must be clear.

Return Code

C

Success Indicator: Clear if conversion is performed - returns GlobalLinearAddr.

Possible errors: EAX = Error code - ERROR_INVALID_PARAMETER (87)

Assembler

   'C' Clear if conversion performed.
       EAX = Global offset to region of memory.

   'C' Set if conversion not performed.
       EAX = Error code - ERROR_INVALID_PARAMETER (87)

Remarks

The address range must be on a page boundary and must not cross object boundaries. This call copies the linear mapping from the process's address space to the system-shared address space. This allows the physical device driver to access the data independent of the context of the current process. The following figure shows the mapping that is performed when a physical device driver calls VMProcessToGlobal.

The following figure shows Mapping Performed by VMProcessToGlobal.

          Before                                       After
 ┌───────────────────────┐ 4 Gigabytes ┌───────────────────────┐
 │                       │             │                       │
 │                       │             │                       │
 │     System Region     │             │     System Region     │
 │                       │             │                       │
 │                       │             ├───────────────────────┤
 │                       │             │       Object A        │
 │                       │             ├───────────────────────┤
 │                       │             │                       │
 ├───────┬───────┬───────┤             ├───────┬───────┬───────┤
 │       │       │       │             │       │       │       │
 │Process│Process│Process│             │Process│Process│Process│
 │   A   │   B   │   C   │             │   A   │   B   │   C   │
 │Address│Address│Address│             │Address│Address│Address│
 │ Space │ Space │ Space │             │ Space │ Space │ Space │
 ├───────┤       │       │             ├───────┤       │       │
 │ Obj A │       │       │             │ Obj A │       │       │
 ├───────┤       │       │             ├───────┤       │       │
 │       │       │       │             │       │       │       │
 └───────┴───────┴───────┘      0      └───────┴───────┴───────┘

Mapping Performed by VMProcessToGlobal

The following steps show to use the DevHlp services to gain interrupt time access to the buffer of a process:

  • If the user's buffer was allocated in the Local Descriptor Table (LDT) tiled region, use the SelToFlat macro to convert the address to a linear address.
  • Call VMLock to verify the address and to lock the range of memory needed into physical memory.
  • Call VMProcessToGlobal to map the private address of a process into global address space. See the previous figure for more details on the mapping performed.
  • If the physical device driver requests it, an array of physical addresses corresponding to the locked region is returned.
  • Access the memory using the FLAT selector and its linear address as returned by VMProcessToGlobal.
  • Call VMFree to remove global mapping to process address space.
  • Call VMUnLock to unlock the object.

Example Code

C

#include  "dhcalls.h"

USHORT APIENTRY DevHelp_VMProcessToGlobal( ULONG Flags,
                                           LIN   LinearAddr,
                                           ULONG Length,
                                           PLIN  GlobalLinearAddr)

Related Functions