table_element *insert_outter_table(environment_list *current_header,table_element *initial, char* name, te_type type, char* flag, te_type value){ table_element *temp; table_element *node = malloc(sizeof(table_element)); node->name = (char*)strdup(name); node->type = type; node->flag = (char*)strdup(flag); node->value= value; if(strcmp(name,"paramcount")==0){ node->header=insert_paramcount(current_header); } if(strcmp(name,"program")==0){ node->header=insert_program(current_header); } if(initial==NULL){ initial=node; return initial; } for(temp = initial; temp->next != NULL; temp = temp->next); temp->next = node; return initial; }
void insert_program(goto_programt &body, const goto_programt::targett &pos, const goto_programt::instructionst &prog, const irep_idt &org_name, const irep_idt &new_name) { replacementst repl; repl.insert(std::make_pair(org_name, new_name)); insert_program(body, pos, prog, repl); }
/** * run_program * * Arguments: <program_id> <program name and arguments> * * Start the specified program. After fork'ing but before exec'ing, ptrace * the child so it will remain suspended until a corresponding resume_program * command. We do this so we can load a context for the program before it * actually starts running. This logic is taken from the task.c example in * the libpfm source code tree. **/ static int run_program(int argc, char **argv) { struct program *prog; int program_id; pid_t pid; int rc; program_id = strtoul(argv[1], NULL, 0); if (program_id <= 0) { LOG_ERROR("program ID must be a positive integer."); return EINVAL; } /* Make sure we haven't already started a program with this ID. */ prog = find_program(program_id); if (prog) { LOG_ERROR("Program with ID %d already exists.", program_id); return EINVAL; } prog = calloc(1, sizeof(*prog)); if (!prog) { LOG_ERROR("Can't allocate new program structure to run '%s'.", argv[2]); return ENOMEM; } prog->id = program_id; pid = fork(); if (pid == -1) { /* Error fork'ing. */ LOG_ERROR("Unable to fork child process."); return EINVAL; } else if (!pid) { /* Child */ /* This will cause the program to stop before executing the * first user level instruction. We can only load a context * if the program is in the STOPPED state. This child * process will sit here until we've process a resume_program * command. */ rc = ptrace(PTRACE_TRACEME, 0, NULL, NULL); if (rc) { rc = errno; LOG_ERROR("Error ptrace'ing '%s': %d", argv[2], rc); exit(rc); } execvp(argv[2], argv + 2); rc = errno; LOG_ERROR("Error exec'ing '%s': %d", argv[2], rc); exit(rc); } /* Parent */ prog->pid = pid; insert_program(prog); /* Wait for the child to exec. */ waitpid(pid, &rc, WUNTRACED); /* Check if process exited early. */ if (WIFEXITED(rc)) { LOG_ERROR("Program '%s' exited too early with status " "%d", argv[2], WEXITSTATUS(rc)); return WEXITSTATUS(rc); } LOG_INFO("Started program %d: '%s'.", program_id, argv[2]); return 0; }
void insert_program(goto_programt &body, const goto_programt::targett &pos, const goto_programt::instructionst &prog) { const replacementst replacements; insert_program(body, pos, prog, replacements); }