Diff
Added: AppleSGLX/trunk/tests/shared_mapping/NOTES (0 => 239)
--- AppleSGLX/trunk/tests/shared_mapping/NOTES (rev 0)
+++ AppleSGLX/trunk/tests/shared_mapping/NOTES 2009-02-22 23:06:59 UTC (rev 239)
@@ -0,0 +1,8 @@
+The client and server programs are protypes to test the behavior
+of GLXPixmap shared memory in a controlled environment
+
+The client faults after munmapping and truncating its fd, but the
+server keeps going. This is a good thing from a security perspective.
+
+The client sees the servers changes, and the server can see the
+client changes, but the server won't fault if the file is truncated.
Added: AppleSGLX/trunk/tests/shared_mapping/bld.sh (0 => 239)
--- AppleSGLX/trunk/tests/shared_mapping/bld.sh (rev 0)
+++ AppleSGLX/trunk/tests/shared_mapping/bld.sh 2009-02-22 23:06:59 UTC (rev 239)
@@ -0,0 +1,2 @@
+gcc client.c -o client
+gcc server.c -o server
Added: AppleSGLX/trunk/tests/shared_mapping/clean.sh (0 => 239)
--- AppleSGLX/trunk/tests/shared_mapping/clean.sh (rev 0)
+++ AppleSGLX/trunk/tests/shared_mapping/clean.sh 2009-02-22 23:06:59 UTC (rev 239)
@@ -0,0 +1 @@
+rm -f client server *~
Added: AppleSGLX/trunk/tests/shared_mapping/client.c (0 => 239)
--- AppleSGLX/trunk/tests/shared_mapping/client.c (rev 0)
+++ AppleSGLX/trunk/tests/shared_mapping/client.c 2009-02-22 23:06:59 UTC (rev 239)
@@ -0,0 +1,55 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+int main(int argc, char *argv[]) {
+ int fd;
+ size_t length;
+ void *buffer;
+
+ fd = shm_open("FOOBAR", O_RDWR, 0);
+
+ if(-1 == fd) {
+ perror("shm_open");
+ return EXIT_FAILURE;
+ }
+
+
+ length = sysconf(_SC_PAGESIZE) * 2;
+
+ buffer = mmap(NULL, length,
+ PROT_READ | PROT_WRITE,
+ MAP_FILE | MAP_SHARED, fd, 0);
+
+ if(MAP_FAILED == buffer) {
+ perror("mmap");
+ shm_unlink("FOOBAR");
+ close(fd);
+ return EXIT_FAILURE;
+ }
+
+ while(1) {
+ unsigned char *cp, *cplimit;
+
+ cp = buffer;
+ cplimit = cp + length;
+
+ while(cp < cplimit) {
+ printf("cp %x\n", *cp);
+ ++cp;
+ }
+
+ if(-1 == munmap(buffer, length))
+ perror("munmap");
+
+ if(-1 == ftruncate(fd, 10))
+ perror("ftruncate");
+ }
+
+
+ return EXIT_SUCCESS;
+}
Added: AppleSGLX/trunk/tests/shared_mapping/server.c (0 => 239)
--- AppleSGLX/trunk/tests/shared_mapping/server.c (rev 0)
+++ AppleSGLX/trunk/tests/shared_mapping/server.c 2009-02-22 23:06:59 UTC (rev 239)
@@ -0,0 +1,63 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+int main(int argc, char *argv[]) {
+ int fd;
+ size_t length;
+ void *buffer;
+ int b;
+
+ shm_unlink("FOOBAR");
+
+ fd = shm_open("FOOBAR", O_RDWR | O_EXCL | O_CREAT,
+ S_IRUSR | S_IWUSR | S_IROTH | S_IWOTH);
+
+ if(-1 == fd) {
+ perror("shm_open");
+ return EXIT_FAILURE;
+ }
+
+
+ length = sysconf(_SC_PAGESIZE) * 2;
+
+ if(-1 == ftruncate(fd, length)) {
+ perror("ftruncate");
+ shm_unlink("FOOBAR");
+ close(fd);
+ return EXIT_FAILURE;
+ }
+
+ printf("length %zu\n", length);
+
+ buffer = mmap(NULL, length,
+ PROT_READ | PROT_WRITE,
+ MAP_FILE | MAP_SHARED, fd, 0);
+
+ if(MAP_FAILED == buffer) {
+ perror("mmap");
+ shm_unlink("FOOBAR");
+ close(fd);
+ return EXIT_FAILURE;
+ }
+
+ b = 0;
+ while(1) {
+ printf("b %d\n", b);
+
+ memset(buffer, b, length);
+ ++b;
+
+ if(b > 255)
+ b = 0;
+
+ sleep(1);
+ }
+
+
+ return EXIT_SUCCESS;
+}