int sys_shmem_access(void) { int pageNumber; if(argint(0,&pageNumber)<0) return -1; if(shmem_access(pageNumber)==0) return -1; return (int)shmem_access(pageNumber); }
int main(int argc, char *argv[]) { char *ptr; int i; char d, arr[6] = "CS537"; int pid = fork(); if (pid < 0) { test_failed(); } else if (pid == 0) { // printf(1, "child shmem_counter before access: %d\n", shmem_count(3)); ptr = shmem_access(3); if (ptr == NULL) { test_failed(); } for (i = 0; i < 5; i++) { *(ptr+i) = arr[i]; printf(1, "write: %c\n", *(ptr+i)); } for (i = 0; i < 5; i++) { d = *(ptr+i); printf(1, "read in child: %c\n", d); } // printf(1, "child shmem_counter after access: %d\n", shmem_count(3)); exit(); } else { wait(); // printf(1, "parent shmem_counter before access: %d\n", shmem_count(3)); ptr = shmem_access(3); // printf(1, "parent shmem_counter after access: %d\n", shmem_count(3)); if (ptr == NULL) { test_failed(); } for (i = 0; i < 5; i++) { printf(1, "read in parent: %c\n", *(ptr+i)); if (*(ptr+i) != arr[i]) { printf(1, "%d\t%c\t%c\n", shmem_count(3), *(ptr+i), arr[i]); test_failed(); } } } test_passed(); exit(); }
int main(int argc, char *argv[]) { printf(1, "%x\n",shmem_access(0)); exit(); }
int main(int argc, char *argv[]) { void *ptr; int n; int i; for (i = 0; i < 4; i++) { ptr = shmem_access(i); if (ptr == NULL) { test_failed(); } } int pid = fork(); if (pid < 0) { test_failed(); } else if (pid == 0) { for (i = 0; i < 4; i++) { n = shmem_count(i); if (n != 2) { test_failed(); } } exit(); } else { wait(); } test_passed(); exit(); }
int main(int argc, char *argv[]) { void *ptr; int i; for (i = 0; i < 4; i++) { ptr = shmem_access(i); if (ptr == NULL) { test_failed(); } } int pid = fork(); if (pid < 0) { test_failed(); } else if (pid == 0) { exec("echo", args); //echo represents shmem_access_exec2_helper.c printf(1, "exec failed!\n"); test_failed(); exit(); } else { wait(); } exit(); }
int sys_shmem_access(void) { int page_num; // get page_num if(argint(0, &page_num) < 0) return -1; // given currently running process return (int)shmem_access(page_num, proc); }
int main(int argc, char *argv[]) { // printf(1, "%x\n",shmem_access(0)); char *c=(char*) shmem_access(0); printf(1,"return valur of shmem_access=%p\n",c); printf(1,"return value of shmem_access=%p =%c\n",c,*c); exit(); }
int main(int argc, char *argv[]) { char *ptr; int i; ptr = shmem_access(3); if (ptr == NULL) { test_failed(); } char arr[4] = "tmp"; for (i = 0; i < 4; i++) { *(ptr+i) = arr[i]; } //argstr int fd = open(ptr, O_WRONLY|O_CREATE); if (fd == -1) { printf(1, "open system call failed to take a string from within a shared page\n"); test_failed(); } //argptr int n = write(fd, ptr, 10); if (n == -1) { printf(1, "write system call failed to take a pointer from within a shared page\n"); test_failed(); } //making sure invalid strings are still caught int fd2 = open((char *)(USERTOP/2), O_WRONLY|O_CREATE); if (fd2 != -1) { printf(1, "open system call successfully accepted an invalid string\n"); test_failed(); } //making sure invalid pointers are still caught n = write(fd, (char *)(USERTOP/2), 10); if (n != -1) { printf(1, "write system call successfully accepted an invalid pointer\n"); test_failed(); } //making sure edge case is checked printf(1, "%d\n", ptr); n = write(fd, (char *)(ptr + 4094), 3); if (n != -1) { printf(1, "write system call successfully accepted an overflowing pointer in a shared page\n"); test_failed(); } test_passed(); exit(); }
int main(int argc, char *argv[]) { char *ptr; int i; char arr[6] = "CS537"; int pid = fork(); if (pid < 0) { test_failed(); } else if (pid == 0) { ptr = shmem_access(3); if (ptr == NULL) { test_failed(); } for (i = 0; i < 5; i++) { *(ptr+i) = arr[i]; } exit(); } else { wait(); ptr = shmem_access(3); if (ptr == NULL) { test_failed(); } for (i = 0; i < 5; i++) { if (*(ptr+i) != arr[i]) { test_failed(); } } } test_passed(); exit(); }