Actually shared memory between programs, Windows programming languages

650 views Asked by At

I'm on a Windows platform, and I've been researching into how the OS works, what C# C++ VB C can do, but I kept running into this "insulated space" problem across multiple programs.

Is it possible, however hard or difficult, to start two programs, in their insulated space?

For example:

A.exe Start of program, in physical RAM: 0 x 0000 0000 0000 00FF

B.exe Start of program, in physical RAM: 0 x 0000 0000 00FF 0000

These programs have their own variable "foo" in the address "0x0F". For obvious boundary reasons, 0x0F is a local address, and it means nothing between the two programs. Each of the two programs resolves the 0x0F differently, to two different values.

Is it possible to, somehow, share this memory, physically, just by making that local variable in the two separate programs point to the same physical address?

I'm aware that local variables are handled normally as local, and are resolved, by adding the program's start offset to the variable, to get the physical location of that variable.

I've shoddily drawn an image to represent my point: enter image description here

In short, how do I map local memory in two separate programs, to point to the absolute same location physically? Or at the very least, how do I get the programs to be aware of physical addresses (such as where they are, where their variables are physically, so they can see one another in physical RAM and modify one another) so that I can emulate this behavior?

Note: This has to be done by mapping, otherwise I would just be copying the memory through serialization techniques.

Yes I'm aware this would violate a lot of OS safeties and design specifications. Yes I'm aware this could pose huge security risks. Yes I'm aware this can also affect stability of the system. Yes I'm aware the OS might move memory around due to pagefile and would force the programs to re-negotiate their addressing. I still wish to achieve this effect regardless. Even if I have to write my own driver(s). I just have no idea how to start this project.

PS: Something like a raw pointer to actual physical memory in the RAM between the two programs. But it has to be allocated into a DLL or 3rd program, or into one of the two programs, so the OS doesn't just over-write it. I need to access this data directly, without any proxies i.e. the OS, because I need performance speed!

PPS: I was thinking marshalling, invoke, DLL's, and things of that nature may help, but they're all in their insulated space, due to the nature of Window's memory management. I have no idea if Linux is the same in this regard. I'd love to jump ship if Linux actually can easily support the above idea.

PPPS: Sort of like how SQL works, except I don't want the delay between writing a query, sending it to the server, waiting for the server to pass it back serially, then deserializing the data, and using it.

PPSPSP: This sort of behavior exists in embedded machines, as all the software runs in the same shared physical space, they can see one another and all the data. I wish to emulate this behavior in an operating system, without performance losses (i.e. serializing data between app domains), and without creating specialized software to run my programs inside of (an emulator).

PPPSSSPP: I want program A and program B to access the same physical memory in RAM, as a form of IPC. I need the actual physical access, not an imitation of it. Pretend it's a 1920x1080 image, that I need to iterate through and modify with two programs at the same time, where the image would be a 2D array of struct Pixel(int A,R,G,B). I have too many uses and needs for this technique to start listing all of them.

0

There are 0 answers