API Version 0

Since shared memory can be read and written by anyone, don't trust the data. All data is assumed in the VPVR-Host Format (Little Endian)

This shared memory uses a client-server architecture where VPVR is the server and creator of the shared memory, while all other applications are clients that may connect to the server (i.e. use the shared memory). For C++ mark all shared memory as volatile. Use similar approach for other programming languages.

An application (VPVR, DMD, backglass, Spytool...) should only write into fields where write permission is given.

Reserved values for ID (do not use them for your client)
VPVR (reserved for Server)

Used for allocating
NONE
FREE
FAIL

Suggested Names:
UDMD for UltraDMD
XDMD for XDMD
DB2S for directb2s backglasses
SPYT for Spy Tool

Try to avoid running more than one tool with the same ID at the same time

Behavior for all Clients
Check if HEADER is VPVR
Check if you support a version between MIN_VER and MAX_VER.
Generate random numbers, not only based on a time stamp. Also use application name and process ID and other unique and/or changing data. This is important to prevent two different clients with same REQUEST_ID to connect to the same slot.
Always update the entire entry (if it is UINT64, always write the upper and lower 32-bit block!).

Aquiring a slot / Allocating a datablock:
1. Wait until NEXT_SLOT_OFFSET != 0xffffffffffffffff
2. Read Value from NEXT_SLOT_OFFSET and replace it with 0xffffffffffffffff
3. Check if REQUEST_ID from is NONE (otherwise return to step 1)
4. Write your ID into REQUEST_ID and a random number (see above) into REQUEST_RND.
5. Wait until VPVR writes your ID and your random number into ACK_ID and ACK_RND. Return to step 1 otherwise.
6. Write the desired block size into SIZE and your desired version number into VERSION (normally this field contains the same value as MAX_VER)
7. Wait until VPVR either assigns you a vaild OFFSET (>0). If no valid block is available ACK_ID is set to FAIL
8. Set STATUS to 1
8. Write your DATA_TYPE and an all other Data into your slot
9. Set STATUS to 2

If ACK_ID is set to FAIL change REQUEST_ID to FREE as soon as possible and stop reading/writing data into the slot or the assinged datablock. VPVR will block the slot and the datablock as long as the REQUEST_ID is not free. This can lead to severe memory leak or an out of Shared Memory abort.


Returning a Slot:
1. Write into the field REQUEST_ID FREE. Note after that you are no longer OWNER of the SLOT or the memory block. VPVR may reuse both for any other purpose, including offering it in NEXT_SLOT_OFFSET
