/* Routine to go up tree */ static char *recurser(char *path_buf, int path_size, dev_t root_dev, ino_t root_ino,int depth) { struct stat st; dev_t this_dev; ino_t this_ino; //printf ("recurser(%i): %s\n",depth,path_buf); if (stat(path_buf, &st) < 0) { if (errno != EFAULT) { __set_errno(ERANGE); } return 0; } this_dev = st.st_dev; this_ino = st.st_ino; if (this_dev == root_dev && this_ino == root_ino) { if (path_size < 2) { __set_errno(ERANGE); return 0; } strcpy(path_buf, "/"); return path_buf; } if (strlen(path_buf) + 4 > path_size) { __set_errno(ERANGE); return 0; } strcat(path_buf, "/.."); if (recurser(path_buf, path_size, root_dev, root_ino,++depth) == 0) return 0; return search_dir(this_dev, this_ino, path_buf, path_size); }
static inline int __syscall_getcwd(char * buf, unsigned long size) { int len; char *cwd; struct stat st; int olderrno; olderrno = errno; len = -1; /* get stat for root to have a valid parameters for the terminating condition */ if (stat("/", &st) < 0) { /* root dir not found! */ return -1; } /* start with actual dir */ if (buf) strncpy(buf, ".", size); cwd = recurser(buf, size, st.st_dev, st.st_ino); if (cwd) { len = strlen(buf); __set_errno(olderrno); } return len; }
static inline int __syscall_getcwd(char * buf, unsigned long size) { int len; char *cwd; struct stat st; int olderrno,depth = 0; if (buf == NULL) { printf("<fixme> libc-getcwd: warning allocating memory for buffer\n"); buf = malloc(size); } if (stat("/", &st) < 0) { return EINVAL; } strcpy(buf, "."); olderrno = errno; len = -1; cwd = recurser(buf, size, st.st_dev, st.st_ino,depth); if (cwd) { len = strlen(buf); __set_errno(olderrno); } return len; }
bool recurser(int n, int origin) { bool ret = true; int level = origin - n + 1; std11::lock_guard<std11::recursive_mutex> l(rm); printf("Th[%08x] %s acquired Level %d lock\n", hash(std11::this_thread::get_id()), bracket_indent[level - 1], level); if (--n) { recurser(n, origin); } else { shared_resource += origin; printf("Th[%08x] incremented %d. (shared_resource = %d)\n", hash(std11::this_thread::get_id()), origin, shared_resource); if (shared_resource >= LIMIT) { ret = false; } } printf("Th[%08x] %s released Level %d lock\n", hash(std11::this_thread::get_id()), bracket_indent[level - 1], level); return ret; }
/* Routine to go up tree */ static char *recurser(char *path_buf, int path_size, dev_t root_dev, ino_t root_ino) { struct stat st; dev_t this_dev; ino_t this_ino; if (stat(path_buf, &st) < 0) { if (errno != EFAULT) goto oops; return 0; } this_dev = st.st_dev; this_ino = st.st_ino; if (this_dev == root_dev && this_ino == root_ino) { if (path_size < 2) { goto oops; } strcpy(path_buf, "/"); return path_buf; } if (strlen(path_buf) + 4 > path_size) { goto oops; } strcat(path_buf, "/.."); if (recurser(path_buf, path_size, root_dev, root_ino) == 0) return 0; return search_dir(this_dev, this_ino, path_buf, path_size); oops: __set_errno(ERANGE); return 0; }
char *getcwd(char *buf, int size) { struct stat st; if (size == 0) { if (buf != NULL) { __set_errno(EINVAL); return NULL; } size = PATH_MAX; } if (size < 3) { __set_errno(ERANGE); return NULL; } if (buf == NULL) { buf = malloc (size); if (buf == NULL) return NULL; } strcpy(buf, "."); if (stat("/", &st) < 0) { return NULL; } return recurser(buf, size, st.st_dev, st.st_ino); }
void recurser (int x) { int local_x; if (x > 0) recurser (x-1); local_x = x; }
void worker() { bool cont = true; do { int n = RANDOM(MIN_LEVEL, MAX_LEVEL); printf("Th[%08x] calling recurse(%d) ...\n", hash(std11::this_thread::get_id()), n); cont = recurser(n, n); std11::this_thread::yield(); } while (cont); }
int main () { struct1.val = 1; struct2.val = 2; ptr1 = &struct1; ptr2 = &struct2; marker1 (); func1 (); for (count = 0; count < 4; count++) { ival1 = count; ival3 = count; ival4 = count; } ival1 = count; /* Outside loop */ ival2 = count; ival3 = count; ival4 = count; marker2 (); if (doread) { static char msg[] = "type stuff for buf now:"; write (1, msg, sizeof (msg) - 1); read (0, &buf[0], 5); } marker4 (); /* We have a watchpoint on ptr1->val. It should be triggered if ptr1's value changes. */ ptr1 = ptr2; /* This should not trigger the watchpoint. If it does, then we used the wrong value chain to re-insert the watchpoints or we are not evaluating the watchpoint expression correctly. */ struct1.val = 5; marker5 (); /* We have a watchpoint on ptr1->val. It should be triggered if ptr1's value changes. */ ptr1 = ptr2; /* This should not trigger the watchpoint. If it does, then we used the wrong value chain to re-insert the watchpoints or we are not evaluating the watchpoint expression correctly. */ struct1.val = 5; marker5 (); /* We're going to watch locals of func2, to see that out-of-scope watchpoints are detected and properly deleted. */ marker6 (); /* This invocation is used for watches of a single local variable. */ func2 (); /* This invocation is used for watches of an expression involving a local variable. */ func2 (); /* This invocation is used for watches of a static (non-stack-based) local variable. */ func2 (); /* This invocation is used for watches of a local variable when recursion happens. */ marker6 (); recurser (2); marker6 (); func3 (); func4 (); return 0; } /* end of main */
void middle() { sleeper(); sibling(); recurser(); }