Skip to content

Instantly share code, notes, and snippets.

@boxmein
Created March 28, 2014 16:22
Show Gist options
  • Save boxmein/9836787 to your computer and use it in GitHub Desktop.
Save boxmein/9836787 to your computer and use it in GitHub Desktop.
A C experiment to see if execl() can be used to pass around memory, if the new process's memory addresses are at the same location.
// Is the sub-process. Prints out the 'undefined' value of myvalue before it's assigned to.
//# gcc -o execl_receiver execl_receiver.c
#include <unistd.h>
#include <stdio.h>
extern char **environ;
// hopefully since it has the same memory location perchance it'll keep the value that
// last was written to that virtual memory location?
char myvalue;
int main() {
printf("initialized myvalue at %p to %x\r\n", &myvalue, myvalue);
myvalue = 5;
printf("assigned myvalue at %p to %x\r\n", &myvalue, myvalue);
}
// Creats the sub-process while leaving a memory value in place.
//# gcc -o execl_sender execl_sender.c
// However sadly, this doesn't seem to work on my system.
// C:\Users\Johannes\Kood\Cpp\etc>execl_sender_poop.exe
// sender:
// initialized myvalue at 00405068 to 0
// assigned myvalue at 00405068 to 5
// (receiver):
// initialized myvalue at 00405068 to 0
// assigned myvalue at 00405068 to 5
#include <unistd.h>
#include <stdio.h>
extern char **environ;
char myvalue;
int main() {
printf("initialized myvalue at %p to %x\r\n", &myvalue, myvalue);
myvalue = 5;
printf("assigned myvalue at %p to %x\r\n", &myvalue, myvalue);
// pure C, no reinterpret_cast<T>
execl("./execl_receiver", "./execl_receiver", (char*) NULL);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment