int get_random_fd(void) { return rand()%30000; #if VMW /* 25% chance of returning something new. */ if ((rand() % 4) == 0) return get_new_random_fd(); /* the rest of the time, return the same fd as last time. */ regen: if (shm->fd_lifetime == 0) { shm->current_fd = get_new_random_fd(); shm->fd_lifetime = rand_range(5, max_children); } else shm->fd_lifetime--; if (shm->current_fd == 0) { shm->fd_lifetime = 0; goto regen; } return shm->current_fd; #endif }
int get_random_fd(void) { /* 25% chance of returning something new. */ if ((rand() % 4) == 0) return get_new_random_fd(); /* the rest of the time, return the same fd as last time. */ regen: if (shm->fd_lifetime == 0) { shm->current_fd = get_new_random_fd(); shm->fd_lifetime = (rand() % shm->max_children) + 5; } else shm->fd_lifetime--; if (shm->current_fd == 0) { shm->fd_lifetime = 0; goto regen; } return shm->current_fd; }
static unsigned long fill_arg(struct syscallrecord *rec, unsigned int argnum) { struct syscallentry *entry; unsigned int call; enum argtype argtype; call = rec->nr; entry = syscalls[call].entry; if (argnum > entry->num_args) return 0; argtype = get_argtype(entry, argnum); switch (argtype) { case ARG_UNDEFINED: if (RAND_BOOL()) return (unsigned long) rand64(); return (unsigned long) get_writable_address(page_size); case ARG_FD: if (RAND_BOOL()) { unsigned int i; /* If this is the 2nd or more ARG_FD, make it unique */ for (i = 0; i < argnum; i++) { enum argtype arg; arg = get_argtype(entry, i); if (arg == ARG_FD) return get_new_random_fd(); } } return get_random_fd(); case ARG_LEN: return (unsigned long) get_len(); case ARG_ADDRESS: return handle_arg_address(rec, argnum); case ARG_NON_NULL_ADDRESS: return (unsigned long) get_non_null_address(); case ARG_MMAP: return (unsigned long) get_map(); case ARG_PID: return (unsigned long) get_pid(); case ARG_RANGE: return handle_arg_range(entry, argnum); case ARG_OP: /* Like ARG_LIST, but just a single value. */ return handle_arg_op(entry, argnum); case ARG_LIST: return handle_arg_list(entry, argnum); case ARG_CPU: return (unsigned long) get_cpu(); case ARG_PATHNAME: return (unsigned long) generate_pathname(); case ARG_IOVEC: return handle_arg_iovec(entry, rec, argnum); case ARG_IOVECLEN: case ARG_SOCKADDRLEN: /* We already set the len in the ARG_IOVEC/ARG_SOCKADDR case * So here we just return what we had set there. */ return get_argval(rec, argnum); case ARG_SOCKADDR: return handle_arg_sockaddr(entry, rec, argnum); case ARG_MODE_T: return handle_arg_mode_t(); case ARG_SOCKETINFO: return (unsigned long) get_rand_socketinfo(); } BUG("unreachable!\n"); }