static ssize_t ibs_proc_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) { char c; if (count) { if (get_user(c, buf)) return -EFAULT; if (c == 'b' && !running) { start_profiling(); running = 1; } else if (c == 'e' && running) { enable_carrefour = 1; stop_profiling(); running = 0; } else if (c == 'x' && running) { enable_carrefour = 0; stop_profiling(); #if ADAPTIVE_SAMPLING //printk("[ADAPTIVE] Carrefour disabled, reducing the IBS sampling rate\n"); sampling_rate = sampling_rate_cheap; #endif start_profiling(); } else if (c == 'k' && running) { enable_carrefour = 0; stop_profiling(); running = 0; } #if ENABLE_INTERLEAVING else if (c == 'i') { enable_interleaving = 0; } else if (c == 'I') { enable_interleaving = 1; } #endif else if (c == 'T') { if(count > 1) { /* get buffer size */ char * buf_tmp = kmalloc(count, GFP_KERNEL | __GFP_ZERO); char * index = buf_tmp; char * next_idx; int node = 0; if (copy_from_user(buf_tmp, buf, count)) { return -EFAULT; } // Skip the I index++; for (next_idx = index; next_idx < buf_tmp + count; next_idx++) { if(*next_idx == ',' || next_idx == (buf_tmp + count -1)) { unsigned long value; if(*next_idx == ',') { *next_idx = 0; } if(kstrtol(index, 10, &value) < 0) { printk("Value is %s (%lu)\n", index, value); printk(KERN_WARNING "Strange bug\n"); memset(&nr_accesses_node, 0, sizeof(unsigned long) * MAX_NUMNODES); break; } nr_accesses_node[node++] = value; index = next_idx+1; //printk("Node %d --> %lu\n", node -1, nr_accesses_node[node-1]); } } kfree(buf_tmp); } } #if ENABLE_REPLICATION && REPLICATION_PER_TID else if (c == 'Z') { int pid, enabled; int ret = sscanf(buf, "Z\t%d\t%d\n", &pid, &enabled); if(ret != 2) { printk("Error %s\n", buf); } else { printk("Replication for pid %d => %d\n", pid, enabled); change_replication_state(pid, enabled); if(enabled) { enable_replication = 1; } } } #elif ENABLE_REPLICATION else if (c == 'r') { enable_replication = 0; } else if (c == 'R') { enable_replication = 1; } #endif #if ENABLE_MIGRATION else if (c == 'M') { enable_migration = 1; } else if (c == 'm') { enable_migration = 0; } #endif #if ADAPTIVE_SAMPLING else if (c == 'F') { // Increases the ibs frequency sampling_rate = sampling_rate_accurate; } else if (c == 'f') { // Decreases the ibs frequency sampling_rate = sampling_rate_cheap; } #endif } return count; }
static long px_tp_d_ioctl( struct file *fp, unsigned int cmd, unsigned long arg) #endif { switch (cmd) { case PX_TP_CMD_START_MODULE_TRACKING: return start_module_tracking(); case PX_TP_CMD_START_SAMPLING: return start_sampling((bool *)arg); case PX_TP_CMD_STOP_PROFILING: return stop_profiling(); case PX_TP_CMD_PAUSE_PROFILING: return pause_profiling(); case PX_TP_CMD_RESUME_PROFILING: return resume_profiling(); case PX_TP_CMD_ALLOC_EVENT_BUFFER: return allocate_event_buffer((unsigned int *)arg); case PX_TP_CMD_ALLOC_MODULE_BUFFER: return allocate_module_buffer((unsigned int *)arg); case PX_TP_CMD_FREE_EVENT_BUFFER: return free_event_buffer(); case PX_TP_CMD_FREE_MODULE_BUFFER: return free_module_buffer(); case PX_TP_CMD_SET_AUTO_LAUNCH_APP_PID: return set_auto_launch_app_pid((pid_t *)arg); case PX_TP_CMD_SET_WAIT_IMAGE_LOAD_NAME: return set_wait_image_load_name((char *)arg); case PX_TP_CMD_QUERY_REQUEST: return query_request((struct query_request_data *)arg); case PX_TP_CMD_GET_CPU_ID: return get_cpu_id((unsigned long *)arg); case PX_TP_CMD_GET_TARGET_RAW_DATA_LENGTH: return get_target_raw_data_length((unsigned long *)arg); case PX_TP_CMD_GET_TARGET_INFO: return get_target_info((unsigned long *)arg); case PX_TP_CMD_GET_CPU_FREQ: return get_cpu_freq((unsigned int *)arg); case PX_TP_CMD_GET_TIMESTAMP_FREQ: return get_timestamp_frequency((unsigned long *)arg); case PX_TP_CMD_GET_TIMESTAMP: return get_time_stamp((unsigned long long *)arg); case PX_TP_CMD_ADD_MODULE_RECORD: return add_module_record((struct add_module_data *)arg); #if 0 case PX_TP_CMD_RESET_EVENT_BUFFER_FULL: return reset_event_buffer_full((bool *)arg); case PX_TP_CMD_RESET_MODULE_BUFFER_FULL: return reset_module_buffer_full((bool *)arg); #endif // case PX_TP_CMD_SET_KERNEL_FUNC_ADDR: // return set_kernel_func_addr((struct tp_kernel_func_addr *)arg); // case PX_TP_CMD_HOOK_ADDRESS: // return hook_address((struct tp_hook_address *)arg); case PX_TP_CMD_READ_EVENT_BUFFER: return read_event_buffer((struct read_buffer_data *)arg); case PX_TP_CMD_READ_MODULE_BUFFER: return read_module_buffer((struct read_buffer_data *)arg); case PX_TP_CMD_GET_POSSIBLE_CPU_NUM: return get_possible_cpu_number((unsigned int *)arg); case PX_TP_CMD_GET_ONLINE_CPU_NUM: return get_online_cpu_number((unsigned int *)arg); default: return -EINVAL; } }
int main(int argc, char *argv[]) { init_sli(); __set_profiling(root); if (argc < 5) errx(1, "not enough arguments"); argv++; argc--; const char *binary = argv[0]; const char *typesdb = argv[1]; const char *callgraph = argv[2]; const char *staticdb = argv[3]; argv += 4; argc -= 4; bool assert_mode = false; bool double_free_mode = false; bool indirect_call_mode = false; if (!strcmp(argv[argc - 1], "assertions")) { assert_mode = true; argc--; } else if (!strcmp(argv[argc - 1], "doublefree")) { double_free_mode = true; argc--; } else if (!strcmp(argv[argc - 1], "icall")) { indirect_call_mode = true; argc--; } if (argc > 2) errx(1, "Too many arguments"); VexPtr<Oracle> oracle; { MachineState *ms = MachineState::readELFExec(binary); Thread *thr = ms->findThread(ThreadId(1)); oracle = new Oracle(ms, thr, typesdb); } oracle->loadCallGraph(oracle, callgraph, staticdb, ALLOW_GC); DumpFix df(oracle); LibVEX_gc(ALLOW_GC); int start_percentage; int end_percentage; start_percentage = 0; end_percentage = 100; AllowableOptimisations opt = AllowableOptimisations::defaultOptimisations .enableassumePrivateStack() .setAddressSpace(oracle->ms->addressSpace); if (assert_mode || double_free_mode) opt = opt.enableallPointersGood(); if (double_free_mode) opt = opt.enablefreeMightRace(); if (argc == 1 || argc == 2) { DynAnalysisRip vr; const char *succ; if (parseDynAnalysisRip(&vr, argv[0], &succ)) { int only_store_cfg = -1; int expected_nr_store_cfgs = -1; argc--; argv++; if (argc == 1) { if (sscanf(argv[0], "%d/%d", &only_store_cfg, &expected_nr_store_cfgs) != 2 || only_store_cfg < 0 || expected_nr_store_cfgs <= 0 || only_store_cfg >= expected_nr_store_cfgs) { errx(1, "expected final argument to be <store_cfg>/<nr_store_cfgs>, not %s", argv[0]); } } consider_rip(vr, 1, oracle, df, opt, only_store_cfg, expected_nr_store_cfgs, ALLOW_GC); df.finish(); return 0; } if (argc != 1 || sscanf(argv[0], "%d...%d", &start_percentage, &end_percentage) != 2) errx(1, "expect argument to be either a VexRip or s...d where s and d are start and end percentages, not %s", argv[0]); } std::vector<DynAnalysisRip> schedule; VexPtr<TypesDb::all_instrs_iterator> instrIterator; unsigned long total_instructions; bool use_schedule = false; /* Shut compiler up */ total_instructions = -1; if (getenv("SOS22_MINIMAL_DIRECT_INSTR_SCHEDULE")) { loadSchedule(getenv("SOS22_MINIMAL_DIRECT_INSTR_SCHEDULE"), schedule); use_schedule = true; } else if (assert_mode) { oracle->findAssertions(schedule); use_schedule = true; } else if (double_free_mode) { oracle->findFrees(schedule); use_schedule = true; } else if (indirect_call_mode) { oracle->findIndirectCalls(schedule); use_schedule = true; } else { instrIterator = oracle->type_db->enumerateAllInstructions(); total_instructions = oracle->type_db->nrDistinctInstructions(); } if (use_schedule) total_instructions = schedule.size(); printf("%ld instructions to protect\n", total_instructions); /* There are a couple of important properties here: -- 0...100 must precisely cover the entire range -- a...b and b...c must, between them, cover precisely the same range as a...c i.e. no duplicates or gaps. */ unsigned long start_instr = (total_instructions * start_percentage) / 100; unsigned long end_instr = end_percentage == 100 ? total_instructions - 1: (total_instructions * end_percentage) / 100 - 1; unsigned long instructions_to_process = end_instr - start_instr; printf("Processing instructions %ld to %ld\n", start_instr, end_instr); unsigned long cntr = 0; InstructionConsumer ic(start_instr, instructions_to_process, total_instructions, opt); if (use_schedule) { initialise_profiling(); start_profiling(); for (unsigned long idx = start_instr; idx <= end_instr; idx++) { ic(oracle, df, schedule[idx], cntr); cntr++; } stop_profiling(); dump_profiling_data(); } else { /* Skip the ones we've been told to skip. */ for (unsigned long a = 0; a < start_instr; a++) instrIterator->advance(); while (cntr < instructions_to_process) { assert(!instrIterator->finished()); DynAnalysisRip dar; instrIterator->fetch(&dar); instrIterator->advance(); ic(oracle, df, dar, cntr); cntr++; } } df.finish(); return 0; }
static long px_hotspot_d_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) #endif { int ret; if ((ret = check_ioctl(fp, cmd, arg)) != 0) return ret; switch (cmd) { case PX_HS_CMD_START_MODULE_TRACKING: return start_module_tracking_hs(); case PX_HS_CMD_START_SAMPLING: return start_sampling((bool *)arg); case PX_HS_CMD_STOP_PROFILING: return stop_profiling(); case PX_HS_CMD_PAUSE_PROFILING: return pause_profiling(); case PX_HS_CMD_RESUME_PROFILING: return resume_profiling(); case PX_HS_CMD_ALLOC_SAMPLE_BUFFER: return allocate_all_sample_buffers((unsigned int *)arg); case PX_HS_CMD_ALLOC_MODULE_BUFFER: return allocate_module_buffer((unsigned int *)arg); case PX_HS_CMD_FREE_SAMPLE_BUFFER: return free_all_sample_buffers(); case PX_HS_CMD_FREE_MODULE_BUFFER: return free_module_buffer(); case PX_HS_CMD_SET_AUTO_LAUNCH_APP_PID: return set_auto_launch_app_pid((pid_t *)arg); case PX_HS_CMD_SET_WAIT_IMAGE_LOAD_NAME: return set_wait_image_load_name((char *)arg); case PX_HS_CMD_SET_TBS_SETTINGS: return set_tbs_settings((struct HSTimerSettings *)arg); case PX_HS_CMD_SET_EBS_SETTINGS: return set_ebs_settings((struct HSEventSettings *)arg); case PX_HS_CMD_SET_CALIBRATION_MODE: return set_calibration_mode((bool *)arg); case PX_HS_CMD_QUERY_REQUEST: return query_request((struct query_request_data *)arg); case PX_HS_CMD_GET_CALIBRATION_RESULT: return get_calibration_result((struct calibration_result *)arg); case PX_HS_CMD_GET_CPU_ID: return get_cpu_id((unsigned long *)arg); case PX_HS_CMD_GET_TARGET_RAW_DATA_LENGTH: return get_target_raw_data_length((unsigned long *)arg); case PX_HS_CMD_GET_TARGET_INFO: return get_target_info((unsigned long *)arg); case PX_HS_CMD_GET_CPU_FREQ: return get_cpu_freq((unsigned int *)arg); case PX_HS_CMD_GET_TIMESTAMP_FREQ: return get_timestamp_frequency((unsigned long *)arg); case PX_HS_CMD_GET_TIMESTAMP: return get_time_stamp((unsigned long long *)arg); case PX_HS_CMD_ADD_MODULE_RECORD: return add_module_record_hs((struct add_module_data *)arg); case PX_HS_CMD_READ_SAMPLE_BUFFER: return read_sample_buffer((struct read_buffer_data *)arg); case PX_HS_CMD_READ_MODULE_BUFFER: return read_module_buffer((struct read_buffer_data *)arg); case PX_HS_CMD_READ_TOTAL_SAMPLE_COUNT: return read_total_sample_count((unsigned long long *)arg); case PX_HS_CMD_GET_POSSIBLE_CPU_NUM: return get_possible_cpu_number((unsigned int *)arg); case PX_HS_CMD_GET_ONLINE_CPU_NUM: return get_online_cpu_number((unsigned int *)arg); default: return -EINVAL; } }