Jump to content

DosGetSharedMem: Difference between revisions

From EDM2
Ak120 (talk | contribs)
mNo edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
=== Syntax ===
=== Syntax ===
 
  DosGetSharedMem( ''pBaseAddress'', ''ulAttributeFlags'' )
  rc = DosGetSharedMem( ''pBaseAddress'',  
                      ''ulAttributeFlags'' );
 


=== Parameters ===
=== Parameters ===
PVOID ''pBaseAddress'' (input)
;PVOID ''pBaseAddress'' (input):This is the base virtual address of the gettable and shared memory block.
 
;ULONG ''ulAttributeFlags'' (input):Flags that describe the desired access protection.
This is the base virtual address of the gettable and shared memory block.
 
ULONG ''ulAttributeFlags'' (input)
 
Flags that describe the desired access protection.


=== Access protection ===
=== Access protection ===
Setting '''PAG_READ''' (0x00000001) tells the system that read access is desired.
:'''PAG_READ''' (0x00000001) tells the system that read access is desired.
 
:'''PAG_WRITE''' (0x00000002) tells the system that write access is desired.
Setting '''PAG_WRITE''' (0x00000002) tells the system that write access is desired.
:'''PAG_EXECUTE''' (0x00000004) tells the system that execute access is desired.
 
:'''PAG_GUARD''' (0x00000008) tells the system that access to the memory object should cause a guard page exception to be raised, in the subject process.
Setting '''PAG_EXECUTE''' (0x00000004) tells the system that execute access is  
desired.
 
Setting '''PAG_GUARD''' (0x00000008) tells the system that access to the memory object  
should cause a guard page exception to be raised, in the subject process.


At least one of '''PAG_READ''','''PAG_WRITE''' or '''PAG_EXECUTE''' must be set.
At least one of '''PAG_READ''','''PAG_WRITE''' or '''PAG_EXECUTE''' must be set.
   
   
=== Returns ===
=== Returns ===
  APIRET rc
APIRET rc
The following values can be returned
The following values can be returned:
       
{|class="wikitable"
{| border="1"
|-
|0
|0
|NO_ERROR
|NO_ERROR
Line 51: Line 35:
|212
|212
|ERROR_LOCKED
|ERROR_LOCKED
|}
|}
=== Include Info ===
 
#define INCL_DOSMEMMGR
#include <bsememf.h>
#include <os2.h>
 


=== Usage Explanation ===
=== Usage Explanation ===
DosGetSharedMem is used to get access to a shared memory block. This will take the virtual  
DosGetSharedMem is used to get access to a shared memory block. This will take the virtual  
address of the memory block and allocate it to the virtual-address space of the process.  
address of the memory block and allocate it to the virtual-address space of the process.  
Line 69: Line 46:


The shared memory must be gettable (it must have been created by [[DosAllocSharedMem]], with '''OBJ_GETTABLE''' set).
The shared memory must be gettable (it must have been created by [[DosAllocSharedMem]], with '''OBJ_GETTABLE''' set).


The desired access protection must be compatible with the access protection that was set  
The desired access protection must be compatible with the access protection that was set  
when the gettable shared memory block was created.
when the gettable shared memory block was created.
=== Relevant Structures ===
=== Gotchas ===
   
   
=== Sample Code ===
=== Sample Code ===
<pre>
<pre>
#define INCL_DOSMEMMGR
#define INCL_DOSMEMMGR
#include  
#include <bsememf.h>
#include  
#include <os2.h>


PVOID pBaseAddress;
PVOID pBaseAddress;
Line 105: Line 76:
   /* We have an error we must take care of. */
   /* We have an error we must take care of. */
}
}
</pre>  
</pre>
 
=== See Also ===
=== See Also ===
[[OS2 API:CPI:DosAllocSharedMem|DosAllocSharedMem]], [[OS2 API:CPI:DosGetNamedSharedMem|DosGetNamedSharedMem]], [[OS2 API:CPI:DosGiveSharedMem|DosGiveSharedMem]]
*[[DosAllocSharedMem]]
 
*[[DosGetNamedSharedMem]]
*[[DosGiveSharedMem]]


[[Category:The OS/2 API Project]]
[[Category:Dos]]

Latest revision as of 20:29, 30 October 2017

Syntax

DosGetSharedMem( pBaseAddress, ulAttributeFlags )

Parameters

PVOID pBaseAddress (input)
This is the base virtual address of the gettable and shared memory block.
ULONG ulAttributeFlags (input)
Flags that describe the desired access protection.

Access protection

PAG_READ (0x00000001) tells the system that read access is desired.
PAG_WRITE (0x00000002) tells the system that write access is desired.
PAG_EXECUTE (0x00000004) tells the system that execute access is desired.
PAG_GUARD (0x00000008) tells the system that access to the memory object should cause a guard page exception to be raised, in the subject process.

At least one of PAG_READ,PAG_WRITE or PAG_EXECUTE must be set.

Returns

APIRET rc

The following values can be returned:

0 NO_ERROR
5 ERROR_ACCESS_DENIED
8 ERROR_NOT_ENOUGH_MEMORY
87 ERROR_INVALID_PARAMETER
95 ERROR_INTERRUPT
212 ERROR_LOCKED

Usage Explanation

DosGetSharedMem is used to get access to a shared memory block. This will take the virtual address of the memory block and allocate it to the virtual-address space of the process. The virtual address should be the same as the one returned when the gettable shared memory block was created. For the process to know this address, some sort of information exchange must occur between the process, and the process that created the gettable shared memory block.

The shared memory must be gettable (it must have been created by DosAllocSharedMem, with OBJ_GETTABLE set).

The desired access protection must be compatible with the access protection that was set when the gettable shared memory block was created.

Sample Code

#define INCL_DOSMEMMGR
#include <bsememf.h>
#include <os2.h>

PVOID pBaseAddress;
      /* Pointer to the base address of the allocated memory. */

ULONG ulAttributeFlags;
      /* Flags describing the memory block's characteristics. */

APIRET rc;
      /* Recieving the return code */

AttributeFlags = PAG_WRITE | PAG_READ | PAG_COMMIT;
      /* We request read and write access to the shared memory */
      /* block, and also to have the pages of the memory block */
      /* committed at once within the virtual memory.          */

rc = DosGetSharedMem( pBaseAddress, ulAttributeFlags);

if (rc != 0)
{
   /* We have an error we must take care of. */
}

See Also