int main() { { Loader<Plugin> l; std::shared_ptr<Plugin> h = l.load("./testplugin.o"); std::cout << h->next() << std::endl; std::shared_ptr<Plugin> i = l.load("./testplugin.o"); std::cout << i->next() << std::endl; } // unload the triangle library }
void process_lines(vector<string> & lines) { const int nlines = lines.size(); // number of lines const int n = nlines - 1; // number of input data if (nlines < 2) { cout << "number of lines is wrong" << endl; exit(EXIT_FAILURE); } Loader loader; // frontend Docker docker; // backend for (int i = 0; i < n; ++i) { string input = lines[i + 1]; //cout << input << endl; loader.load(input); loader.check(); #if 1 vector<string> tokens = loader.get_tokens(); for (unsigned int i = 0; i < tokens.size() - 1; ++i) cout << tokens[i] << ","; cout << tokens[tokens.size() - 1]; #endif cout << endl; loader.build_complex(docker.complex); docker.run(); } }
/** * Entry point of loader. * At first of loop read load instruction json by stdin stream, and launch loader instance. * At last of loop, write result json for stdout stream. * @param argc * @param argv * @return Exit code of loader. */ int entry(int argc, char* argv[]) { // Read stdin and separate by '\0'. std::string line; picojson::object result; // Create logger. Logger::Syslog logger; logger.initialize("loader"); Logger::set_logger_delegate(&logger); // Load messages. Message::load("loader_message.json"); Logger::info(LoaderMid::L2001, std::string(LLVM_VERSION_STRING).c_str()); while (std::getline(std::cin, line, '\0')) { // Convert json string to picojson instance. picojson::value v; std::string err = picojson::parse(v, line); if (!err.empty()) { Logger::err(LoaderMid::L2003, err.c_str()); } result = v.get<picojson::object>(); Logger::info(LoaderMid::L2002, line.c_str()); try { // Make loader. Loader loader; // Read information from json. loader.in_pid = Convert::json2vpid(result.at("pid")); loader.in_name = result.at("name").get<std::string>(); loader.in_dst_nid = Convert::json2nid(result.at("dst_nid")); loader.in_src_nid = Convert::json2nid(result.at("src_nid")); loader.in_src_account = result.at("src_account").get<std::string>(); loader.in_type = result.at("type").get<std::string>(); // Convert arguments. std::vector<std::string> args; for (auto& it : result.at("args").get<picojson::array>()) { args.push_back(it.get<std::string>()); } // Load. loader.load(args); // Show result. result.insert(std::make_pair("result", picojson::value(0.0))); result.insert(std::make_pair("root_tid", Convert::vtid2json(loader.out_root_tid))); std::cout << picojson::value(result).serialize() << '\0'; Logger::info(LoaderMid::L2004, 0, loader.out_root_tid); } catch(const Error& ex) { // Show error information. result.insert(std::make_pair("result", picojson::value(-1.0))); result.insert(std::make_pair("reason", picojson::value(std::to_string(ex.reason)))); result.insert(std::make_pair("message", picojson::value(ex.mesg))); result.insert(std::make_pair("llvm_version", picojson::value(std::string(LLVM_VERSION_STRING)))); std::cout << picojson::value(result).serialize() << '\0'; Logger::warn(LoaderMid::L2005, -1, ex.reason, ex.mesg.c_str()); } catch(const std::exception& ex) { // Show error information. result.insert(std::make_pair("result", picojson::value(-1.0))); result.insert(std::make_pair("reason", picojson::value(std::to_string(-1)))); result.insert(std::make_pair("message", picojson::value(std::string(ex.what())))); result.insert(std::make_pair("llvm_version", picojson::value(std::string(LLVM_VERSION_STRING)))); std::cout << picojson::value(result).serialize() << '\0'; Logger::warn(LoaderMid::L2005, -1, -1, ex.what()); } catch (...) { int errsv = errno; // Show error information. result.insert(std::make_pair("result", picojson::value(-1.0))); result.insert(std::make_pair("reason", picojson::value(std::to_string(-2)))); result.insert(std::make_pair("message", picojson::value(std::string(std::strerror(errsv))))); result.insert(std::make_pair("llvm_version", picojson::value(std::string(LLVM_VERSION_STRING)))); std::cout << picojson::value(result).serialize() << '\0'; Logger::warn(LoaderMid::L2005, -1, -2, std::strerror(errsv)); } } return 0; }
void process_lines(vector<string> & lines) { const int nlines = lines.size(); // number of lines const int n = nlines - 1; // number of input data if (nlines < 2) { cout << "number of lines is wrong" << endl; exit(EXIT_FAILURE); } // prints modified CSV title vector<string> tokens; tokens = tokenlize(lines[0]); tokens[18] = "steps_total"; tokens[20] = "sz.n_prt"; tokens[21] = "sz.n_lig"; tokens[22] = "sz.n_tmp"; tokens[23] = "sz.n_rep"; tokens[24] = "sz.prt_npoint"; tokens[25] = "sz.lig_natom"; tokens[26] = "sz.kde_npoint"; tokens[27] = "sz.mcs_nrow"; for (unsigned int i = 0; i < tokens.size() - 1; ++i) cout << tokens[i] << ","; cout << tokens[tokens.size() - 1]; cout << endl; // CSV contents Loader loader; for (int i = 0; i < n; ++i) { string input = lines[i + 1]; //cout << input << endl; loader.load(input); loader.check(); #if 1 tokens = loader.get_tokens(); McPara mcpara = loader.get_mcpara(); ComplexSize sz = loader.get_sz(); tokens[18] = num2string(mcpara.steps_total); tokens[20] = num2string(sz.n_prt); tokens[21] = num2string(sz.n_lig); tokens[22] = num2string(sz.n_tmp); tokens[23] = num2string(sz.n_rep); tokens[24] = num2string(sz.prt_npoint); tokens[25] = num2string(sz.lig_natom); tokens[26] = num2string(sz.kde_npoint); tokens[27] = num2string(sz.mcs_nrow); for (unsigned int i = 0; i < tokens.size() - 1; ++i) cout << tokens[i] << ","; cout << tokens[tokens.size() - 1]; #endif cout << endl; } }
SpawnStatus spawn(const char *path, const char *args, const char *workdir, SecurityLevel secLvl, Pid requesterPid, Pid *outPid, File_t *outStdin, File_t *outStdout, File_t *outStderr, File_t inStdin, File_t inStdout, File_t inStderr) { // file of executable File_t file; // open input file if (!findFile(path, &file)) { klog("unable to open the file: %s, it doesn't exist on PATH directory", path); return SPAWN_STATUS_IO_ERROR; } // detect format BinaryFormat format = detectFormat(file); if (format == BF_UNKNOWN) { klog("binary has an unknown format: %s", path); return SPAWN_STATUS_FORMAT_ERROR; } // create empty target process auto targetProc = CreateEmptyProcess(secLvl); Pid targetPid = GetCreatedProcessID(targetProc); // apply configuration ProcessConfiguration configuration; configuration.sourcePath = (char*) path; ConfigureProcess(targetProc, configuration); // create a loader Loader *loader; if (format == BF_ELF32) loader = new Elf32Loader(targetProc, file); //else if (format == BF_ELF64) loader = new Elf64Loader(targetProc, file); else { klog("no loader implementation for binary format %i", format); return SPAWN_STATUS_FORMAT_ERROR; } // setup standard I/O if (!setupStdio(targetPid, requesterPid, outStdin, outStdout, outStderr, inStdin, inStdout, inStderr)) klog("unable to setup stdio for process %i", targetPid); // perform loading uintptr_t entryAddress; LoaderStatus ldrStat = loader->load(&entryAddress); SpawnStatus spawnStat = SPAWN_STATUS_UNKNOWN; if (ldrStat == LS_SUCCESSFUL) { // push command line arguments writeCliArgs(targetProc, args); // set working directory SetWorkingDirectoryP(workdir, targetProc); // attached loaded process AttachCreatedProcess(targetProc, entryAddress); // out-set process id *outPid = targetPid; spawnStat = SPAWN_STATUS_SUCCESSFUL; } else { // cancel creation & let kernel clean up CancelProcessCreation(targetProc); if (ldrStat == LS_IO_ERROR) spawnStat = SPAWN_STATUS_IO_ERROR; else if (ldrStat == LS_FORMAT_ERROR) spawnStat = SPAWN_STATUS_FORMAT_ERROR; else if (ldrStat == LS_MEMORY_ERROR) spawnStat = SPAWN_STATUS_MEMORY_ERROR; else { klog("loader return unknown status on failure %i", ldrStat); spawnStat = SPAWN_STATUS_UNKNOWN; } } // Close binary file Close(file); return spawnStat; }