07955c83c6
* Finally bring syscall.h up to speed and include all syscalls in the syscall module of the C library. * Remove the third-party obfuscated C demos (we have nyancat, good enough) * Fix userspace apps to build without complaining about undeclared strtok_r by disable __STRICT_ANSI__ * Fix .eh_frame by including the proper stuff with libgcc.
53 lines
940 B
C
53 lines
940 B
C
/*
|
|
* shm-server - client program to demonstrate shared memory.
|
|
*/
|
|
#include <sys/types.h>
|
|
#include <syscall.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
|
|
#define SHMSZ 27
|
|
|
|
int main(int argc, char ** argv) {
|
|
char c;
|
|
volatile char *shm;
|
|
volatile char *s;
|
|
|
|
if (argc < 2) {
|
|
fprintf(stderr, "%s: expected argument\n", argv[0]);
|
|
return 1;
|
|
}
|
|
char * key = argv[1];
|
|
|
|
/*
|
|
* Attach to the shared memory chunk
|
|
*/
|
|
size_t size = SHMSZ;
|
|
if ((shm = (char *)syscall_shm_obtain(key, &size)) == (char *) NULL) {
|
|
return 1;
|
|
}
|
|
printf("Server: mounted to 0x%x\n", shm);
|
|
|
|
/*
|
|
* Now put some things into the memory for the
|
|
* other process to read.
|
|
*/
|
|
s = shm;
|
|
|
|
for (c = 'a'; c <= 'z'; c++)
|
|
*s++ = c;
|
|
*s = '\0';
|
|
|
|
|
|
/*
|
|
* Finally, we wait until the other process
|
|
* changes the first character of our memory
|
|
* to '*', indicating that it has read what
|
|
* we put there.
|
|
*/
|
|
while (*shm != '*') {}
|
|
|
|
return 0;
|
|
}
|