/** * Discard all segments that have a defined order against the latest vector * clock of every thread -- these segments can no longer be involved in a * data race. */ static void thread_discard_ordered_segments(void) { unsigned i; VectorClock thread_vc_min; s_discard_ordered_segments_count++; vc_init(&thread_vc_min, 0, 0); thread_compute_minimum_vc(&thread_vc_min); if (sg_get_trace()) { char msg[256]; VectorClock thread_vc_max; vc_init(&thread_vc_max, 0, 0); thread_compute_maximum_vc(&thread_vc_max); VG_(snprintf)(msg, sizeof(msg), "Discarding ordered segments -- min vc is "); vc_snprint(msg + VG_(strlen)(msg), sizeof(msg) - VG_(strlen)(msg), &thread_vc_min); VG_(snprintf)(msg + VG_(strlen)(msg), sizeof(msg) - VG_(strlen)(msg), ", max vc is "); vc_snprint(msg + VG_(strlen)(msg), sizeof(msg) - VG_(strlen)(msg), &thread_vc_max); VG_(message)(Vg_UserMsg, "%s", msg); vc_cleanup(&thread_vc_max); } for (i = 0; i < sizeof(s_threadinfo) / sizeof(s_threadinfo[0]); i++) { Segment* sg; Segment* sg_next; for (sg = s_threadinfo[i].first; sg && (sg_next = sg->next) && vc_lte(&sg->vc, &thread_vc_min); sg = sg_next) { thread_discard_segment(i, sg); } } vc_cleanup(&thread_vc_min); }
static void mutex_initialize(struct mutex_info* const p, const Addr mutex, const SizeT size, const MutexT mutex_type) { tl_assert(mutex != 0); tl_assert(size > 0); tl_assert(p->a1 == mutex); tl_assert(p->a2 == mutex + size); p->cleanup = (void(*)(DrdClientobj*))&mutex_cleanup; p->mutex_type = mutex_type; p->recursion_count = 0; p->owner = DRD_INVALID_THREADID; vc_init(&p->vc, 0, 0); }
static struct rwlock_thread_info* lookup_or_insert_node(OSet* oset, const UWord tid) { struct rwlock_thread_info* q; q = VG_(OSetGen_Lookup)(oset, &tid); if (q == 0) { q = VG_(OSetGen_AllocNode)(oset, sizeof(*q)); q->tid = tid; q->reader_nesting_count = 0; q->writer_nesting_count = 0; vc_init(&q->vc, 0, 0); VG_(OSetGen_Insert)(oset, q); } tl_assert(q); return q; }
/** Initialize the memory pointed at by sg. * @note The creator and created thread ID's may be equal. */ static void sg_init(Segment* const sg, DrdThreadId const creator, DrdThreadId const created) { Segment* creator_sg; ThreadId vg_created = DrdThreadIdToVgThreadId(created); tl_assert(sg); tl_assert(creator == DRD_INVALID_THREADID || IsValidDrdThreadId(creator)); creator_sg = (creator != DRD_INVALID_THREADID ? thread_get_segment(creator) : 0); sg->next = 0; sg->prev = 0; sg->refcnt = 1; if (vg_created != VG_INVALID_THREADID && VG_(get_SP)(vg_created) != 0) sg->stacktrace = VG_(record_ExeContext)(vg_created, 0); else sg->stacktrace = 0; if (creator_sg) vc_copy(&sg->vc, &creator_sg->vc); else vc_init(&sg->vc, 0, 0); vc_increment(&sg->vc, created); sg->bm = bm_new(); if (drd_trace_segment) { char msg[256]; VG_(snprintf)(msg, sizeof(msg), "New segment for thread %d/%d for vc ", creator != VG_INVALID_THREADID ? DrdThreadIdToVgThreadId(creator) : DRD_INVALID_THREADID, creator); vc_snprint(msg + VG_(strlen)(msg), sizeof(msg) - VG_(strlen)(msg), &sg->vc); VG_(message)(Vg_UserMsg, "%s", msg); } }
/** * omap_voltage_late_init() - Init the various voltage parameters * * This API is to be called in the later stages of the * system boot to init the voltage controller and * voltage processors. */ int __init omap_voltage_late_init(void) { int i; if (!vdd_info) { pr_err("%s: Voltage driver support not added\n", __func__); return -EINVAL; } voltage_dir = debugfs_create_dir("voltage", NULL); if (IS_ERR(voltage_dir)) pr_err("%s: Unable to create voltage debugfs main dir\n", __func__); for (i = 0; i < nr_scalable_vdd; i++) { if (vdd_data_configure(&vdd_info[i])) continue; vc_init(&vdd_info[i]); vp_init(&vdd_info[i]); vdd_debugfs_init(&vdd_info[i]); } return 0; }
int main(int argc, char *argv[]) { const unsigned int tout = 1; char file[100]; char string[100]; int talpa; int rc; struct TalpaPacket_VettingDetails* details; struct TalpaPacketFragment_FileDetails* fdetails; char* fname; int status; int ok = 0; if ( argc == 3 ) { strcpy(file, argv[1]); strcpy(string, argv[2]); } else { strcpy(file, "/bin/true"); strcpy(string, "/bin/true"); } if ( (talpa = vc_init(0, tout*1000)) < 0 ) { fprintf(stderr, "Failed to initialize!\n"); return -1; } rc = fork(); if ( !rc ) { if ( execl(file, file, NULL) ) { fprintf(stderr, "Failed to exec %s (%d)!\n", file, errno); return -1; } } else if ( rc < 0 ) { fprintf(stderr, "Fork failed!\n"); return -1; } details = vc_get(talpa); if ( !details ) { fprintf(stderr, "Nothing caught!\n"); vc_exit(talpa); wait(NULL); return -1; } if ( vc_respond(talpa, details, TALPA_ALLOW) < 0 ) { fprintf(stderr, "Respond error!\n"); vc_exit(talpa); wait(NULL); return -1; } fdetails = vc_file_frag(details); fname = vc_file_name(fdetails); if ( !strcmp(fname, string) ) { ok = 1; } details = vc_get(talpa); if ( !details ) { fprintf(stderr, "Nothing caught 2!\n"); vc_exit(talpa); wait(NULL); return -1; } if ( vc_respond(talpa, details, TALPA_ALLOW) < 0 ) { fprintf(stderr, "Respond error 2!\n"); vc_exit(talpa); wait(NULL); return -1; } fdetails = vc_file_frag(details); fname = vc_file_name(fdetails); /* Wait for one more if we are under 2.6 kernel */ details = vc_get(talpa); if ( details ) { vc_respond(talpa, details, TALPA_ALLOW); } wait(&status); if ( ok ) { vc_exit(talpa); return 0; } if ( strcmp(fname, string) ) { fprintf(stderr, "String mismatch %s != %s!\n", fname, string); vc_exit(talpa); return -1; } if ( !WIFEXITED(status) ) { fprintf(stderr, "Child error!\n"); vc_exit(talpa); return -1; } if ( WEXITSTATUS(status) ) { fprintf(stderr, "Child exec failed!\n"); vc_exit(talpa); return -1; } vc_exit(talpa); return 0; }
int main(int argc, char *argv[]) { const unsigned int tout = 2; char dir[100]; char source[100]; char target[100]; char type[100]; char source_path[100]; char target_path[100]; int dirlen; int talpa; int rc; struct TalpaPacket_VettingDetails* details; int status; struct TalpaPacketFragment_FilesystemDetails* fsdetails; char* fsdev; if ( argc == 5 ) { strcpy(dir, argv[1]); strcpy(source, argv[2]); strcpy(target, argv[3]); strcpy(type, argv[4]); } else { strcpy(dir, "/tmp"); strcpy(source, "/dev"); strcpy(target, "/mnt"); strcpy(type, "ext2"); } strcpy(source_path, dir); strcat(source_path, source); strcpy(target_path, dir); strcat(target_path, target); dirlen = strlen(dir); if ( mount( source_path, target_path, type, 0, NULL) ) { fprintf(stderr, "Mount failed!\n"); return -1; } if ( (talpa = vc_init(0, tout*1000)) < 0 ) { fprintf(stderr, "Failed to initialize!\n"); return -1; } rc = fork(); if ( !rc ) { if ( chdir(dir) != 0 ) { fprintf(stderr, "(child) chdir failed!\n"); return -1; } if ( chroot(dir) != 0 ) { fprintf(stderr, "(child) chroot failed!\n"); return -1; } if ( umount2(target, 0) ) { fprintf(stderr, "(child) Umount failed!\n"); return -1; } return 0; } else if ( rc < 0 ) { fprintf(stderr, "Fork failed!\n"); return -1; } details = vc_get(talpa); if ( !details ) { fprintf(stderr, "Nothing caught!\n"); vc_exit(talpa); wait(NULL); return -1; } if ( vc_respond(talpa, details, TALPA_ALLOW) < 0 ) { fprintf(stderr, "Respond error!\n"); vc_exit(talpa); wait(NULL); return -1; } wait(&status); if ( details->header.type != TALPA_PKT_FILESYSTEMDETAIL ) { fprintf(stderr, "Didn't get TALPA_PKT_FILESYSTEMDETAIL type: %x != %x!\n", details->header.type, TALPA_PKT_FILESYSTEMDETAIL ); vc_exit(talpa); return -1; } fsdetails = vc_filesystem_frag(details); if ( fsdetails->operation != TALPA_UMOUNT ) { fprintf(stderr, "Didn't get TALPA_UMOUNT operation: %d != %d!\n", fsdetails->operation, TALPA_UMOUNT ); vc_exit(talpa); return -1; } fsdev = vc_filesystem_dev(fsdetails); if ( strcmp(fsdev, source_path) ) { fprintf(stderr, "String mismatch %s != %s!\n", fsdev, source); vc_exit(talpa); return -1; } if ( details->rootdir_len != dirlen ) { fprintf(stderr, "dir_len mismatch %d != %d!\n", details->rootdir_len, dirlen); vc_exit(talpa); return -1; } if ( !WIFEXITED(status) ) { fprintf(stderr, "Child error!\n"); vc_exit(talpa); return -1; } if ( WEXITSTATUS(status) ) { fprintf(stderr, "Child exec failed!\n"); vc_exit(talpa); return -1; } vc_exit(talpa); return 0; }