int MiniConsole::dump() { /* * We dump on screen the textual console contents. * We care about user set variables. * */ int co=getGlobalIntVariable(FIM_VID_CONSOLE_LINE_OFFSET); int lw=getGlobalIntVariable(FIM_VID_CONSOLE_LINE_WIDTH ); int ls=getGlobalIntVariable(FIM_VID_CONSOLE_ROWS ); setGlobalVariable(FIM_VID_CONSOLE_BUFFER_TOTAL,bsize); setGlobalVariable(FIM_VID_CONSOLE_BUFFER_FREE,(int)bsize-(int)(bp-buffer)); setGlobalVariable(FIM_VID_CONSOLE_BUFFER_USED,(int)(bp-buffer)); // we eventually update internal variables now setRows(ls); if( lw > 0 && lw!=lwidth ) reformat(lw); if(co>=0) { scroll=scroll%(rows+1); if(scroll>0) return do_dump((cline-rows+1-co)>=0?(cline-(rows-scroll)+1-co):0,cline-co); else return do_dump((cline-rows+1-co)>=0?(cline-rows+1-co):0,cline-co); } else return do_dump(-co-1,cline); return -1; }
bool Cache::freeCachedImage(Image *image) { /* * if the supplied image is cached as a master image of a clone, it is freed and deregistered. * if not, no action is performed. * */ // WARNING : FIXME : DANGER !! if( !image )return false; // if( is_in_cache(image) && usageCounter[image->getKey()]==1 ) if( is_in_clone_cache(image) ) { usageCounter[image->getKey()]--; erase_clone(image); // we _always_ immediately delete clones setGlobalVariable(FIM_VID_CACHE_STATUS,getReport().c_str()); return true; } else if( is_in_cache(image) ) { usageCounter[image->getKey()]--; if( (usageCounter[image->getKey()])==0 && image->getKey().second!=FIM_E_STDIN ) { #if 0 if( need_free() && image->getKey().second!=FIM_E_STDIN ) { cache_key_t key = image->getKey(); this->erase( image ); usageCounter.erase(key); } #else /* doing it here is dangerous : */ if( need_free() ) { Image * lrui = get_lru(true); if(lrui && ( lrui->getKey().second!=FIM_E_STDIN )) { cache_key_t key = lrui->getKey(); this->erase( lrui ); usageCounter.erase(key); } // missing usageCounter.erase().. } #endif } setGlobalVariable(FIM_VID_CACHE_STATUS,getReport().c_str()); return true; } return false; }
int Cache::prefetch(cache_key_t key) { // if(need_free()) // free_some_lru(); if(key.first == FIM_STDIN_IMAGE_NAME) return 0;// just a fix in the case the browser is still lame if(is_in_cache(key)) return 0; if(!loadNewImage(key)) return -1; setGlobalVariable(FIM_VID_CACHED_IMAGES,cached_elements()); setGlobalVariable(FIM_VID_CACHE_STATUS,getReport().c_str()); return 0; // return getCachedImage(key)?0:-1; }
JSCExecutor::JSCExecutor( Bridge *bridge, int workerId, JSCExecutor *owner, const std::string& script, const std::unordered_map<std::string, std::string>& globalObjAsJSON, const folly::dynamic& jscConfig) : m_bridge(bridge), m_workerId(workerId), m_owner(owner), m_deviceCacheDir(owner->m_deviceCacheDir), m_messageQueueThread(MessageQueues::getCurrentMessageQueueThread()), m_jscConfig(jscConfig) { // We post initOnJSVMThread here so that the owner doesn't have to wait for // initialization on its own thread m_messageQueueThread->runOnQueue([this, script, globalObjAsJSON] () { initOnJSVMThread(); installGlobalFunction(m_context, "postMessage", nativePostMessage); for (auto& it : globalObjAsJSON) { setGlobalVariable(it.first, it.second); } // TODO(9604438): Protect against script does not exist std::string scriptSrc = WebWorkerUtil::loadScriptFromAssets(script); // TODO(9994180): Throw on error loadApplicationScript(scriptSrc, script); }); }
Image * Cache::setAndCacheStdinCachedImage(Image * image) { /* FIXME : document me * */ if(!image) return NULL; cache_key_t key(FIM_STDIN_IMAGE_NAME,FIM_E_STDIN); try { #ifdef FIM_CACHE_DEBUG Image * oi=image; #endif image = new Image(*image); // cloning if(image) { cacheNewImage( image ); } } catch(FimException e) { /* we will survive :P */ image = NULL; /* we make sure no taint remains */ // if( e != FIM_E_NO_IMAGE )throw FIM_E_TRAGIC; /* hope this never occurs :P */ } if(!image)return NULL; //means that cloning failed. setGlobalVariable(FIM_VID_CACHE_STATUS,getReport().c_str()); return image; //so, it could be a clone.. }
int Cache::erase(fim::Image* oi) { /* * erases the image from the image cache * */ /* acca' nun stimm'a'ppazzia' */ if(!oi) { return -1; } if(is_in_cache(oi) ) { usageCounter[oi->getKey()]=0; /* NOTE : the user should call usageCounter.erase(key) after this ! */ lru.erase(oi); imageCache.erase(reverseCache[oi]); reverseCache.erase(oi); // delete imageCache[reverseCache[oi]]; #ifdef FIM_CACHE_DEBUG std::cout << "will erase "<< oi << "\n"; cout << "deleting " << oi->getName() << "\n"; #endif delete oi; // NEW !! setGlobalVariable(FIM_VID_CACHED_IMAGES,cached_elements()); return 0; } return -1; }
ProxyExecutor::ProxyExecutor(jni::global_ref<jobject>&& executorInstance, std::shared_ptr<ExecutorDelegate> delegate) : m_executor(std::move(executorInstance)) , m_delegate(delegate) { folly::dynamic nativeModuleConfig = folly::dynamic::array; { SystraceSection s("collectNativeModuleDescriptions"); auto moduleRegistry = delegate->getModuleRegistry(); for (const auto& name : moduleRegistry->moduleNames()) { auto config = moduleRegistry->getConfig(name); nativeModuleConfig.push_back(config ? config->config : nullptr); } } folly::dynamic config = folly::dynamic::object ("remoteModuleConfig", std::move(nativeModuleConfig)); SystraceSection t("setGlobalVariable"); setGlobalVariable( "__fbBatchedBridgeConfig", folly::make_unique<JSBigStdString>(folly::toJson(config))); }
bool Cache::cacheNewImage( fim::Image* ni ) { #ifdef FIM_CACHE_DEBUG std::cout << "going to cache: "<< ni << "\n"; #endif /* acca' nun stimm'a'ppazzia' */ if(!ni)return false; this->imageCache[ni->getKey()]=ni; this->reverseCache[ni]= ni->getKey(); lru_touch( ni->getKey() ); usageCounter[ ni->getKey()]=0; // we yet don't assume any usage setGlobalVariable(FIM_VID_CACHED_IMAGES,cached_elements()); return true; }
JSCExecutor::JSCExecutor( Bridge *bridge, std::shared_ptr<MessageQueueThread> messageQueueThread, int workerId, JSCExecutor *owner, const std::string& script, const std::unordered_map<std::string, std::string>& globalObjAsJSON, const folly::dynamic& jscConfig) : m_bridge(bridge), m_workerId(workerId), m_owner(owner), m_deviceCacheDir(owner->m_deviceCacheDir), m_messageQueueThread(messageQueueThread), m_jscConfig(jscConfig) { // We post initOnJSVMThread here so that the owner doesn't have to wait for // initialization on its own thread m_messageQueueThread->runOnQueue([this, script, globalObjAsJSON] () { initOnJSVMThread(); installGlobalFunction(m_context, "postMessage", nativePostMessage); for (auto& it : globalObjAsJSON) { setGlobalVariable(it.first, it.second); } // Try to load the script from the network if script is a URL // NB: For security, this will only work in debug builds std::string scriptSrc; if (script.find("http://") == 0 || script.find("https://") == 0) { std::stringstream outfileBuilder; outfileBuilder << m_deviceCacheDir << "/workerScript" << m_workerId << ".js"; scriptSrc = WebWorkerUtil::loadScriptFromNetworkSync(script, outfileBuilder.str()); } else { // TODO(9604438): Protect against script does not exist scriptSrc = WebWorkerUtil::loadScriptFromAssets(script); } // TODO(9994180): Throw on error loadApplicationScript(scriptSrc, script); }); }
void ProxyExecutor::loadApplicationScript( std::unique_ptr<const JSBigString>, std::string sourceURL) { folly::dynamic nativeModuleConfig = folly::dynamic::array; { SystraceSection s("collectNativeModuleDescriptions"); auto moduleRegistry = m_delegate->getModuleRegistry(); for (const auto& name : moduleRegistry->moduleNames()) { auto config = moduleRegistry->getConfig(name); nativeModuleConfig.push_back(config ? config->config : nullptr); } } folly::dynamic config = folly::dynamic::object ("remoteModuleConfig", std::move(nativeModuleConfig)); { SystraceSection t("setGlobalVariable"); setGlobalVariable( "__fbBatchedBridgeConfig", folly::make_unique<JSBigStdString>(folly::toJson(config))); } static auto loadApplicationScript = jni::findClassStatic(EXECUTOR_BASECLASS)->getMethod<void(jstring)>("loadApplicationScript"); // The proxy ignores the script data passed in. loadApplicationScript( m_executor.get(), jni::make_jstring(sourceURL).get()); // We can get pending calls here to native but the queue will be drained when // we launch the application. }
// sample: myinc:///System/Window/Close#HelloWindow // func = Window/Close // arg = HelloWindow QVariant DSystemFuncs::run(const QString &func, const QStringList &arg, const QObject * nativeSender ) { QStringList f = (func.toLower()).split('/', QString::SkipEmptyParts ); if (f.count() <= 1) return g_vErr; const QString* tmp = &f.at(0); if ( *tmp == QString("window") ) { /// window funcs tmp = &f.at(1); if ( *tmp == QString("close") ) { DSystemFuncs::closeWidget( arg.count() != 0 ? arg.at(0): nativeSender->objectName() ); return g_vSuc; } else if ( *tmp == QString("open")) { return MAKE_BOOL(DSystemFuncs::openWidget( arg.at(0) )); } else if ( *tmp == "object") { if ((arg.count() == 0) || (arg.count() > 4)) return g_vErr; int c = arg.count(); return DSystemFuncs::object( c==2?nativeSender->objectName():arg.at(0), arg.at(c - 2), arg.at(c - 1) ); } else if ( *tmp == "setobject" ) { if ((arg.count() == 0) || (arg.count() > 4)) return g_vErr; int c = arg.count(); DSystemFuncs::setObject( c == 3 ? nativeSender->objectName() : arg.at(0), arg.at(1), arg.at(2), arg.at(3) ); return g_vSuc; } else if ( *tmp == "refresh" ) { return MAKE_BOOL(refreshWidget( (arg.count() == 0)? nativeSender->objectName(): arg.at(0) )); } } else if ( *tmp == QString("var") ) { // variable funcs tmp = &f.at(1); if (arg.count() < 1) { return g_vErr; } if ( *tmp == QString("global") ) { /// this is Global Variables if (f.count() != 3) return g_vErr; tmp = &f.at(2); if (*tmp == QString("get")) return getGlobalVariable( arg.at(0) ); else if (*tmp == QString("set")) { if (arg.count() < 2 ) return g_vErr; setGlobalVariable( arg.at(0), arg.at(1) ); return g_vSuc; } } else if ( *tmp == QString("local")) { if (f.count() != 3) return g_vErr; if (arg.count() < 2 ) return g_vErr; tmp = &f.at(2); if (*tmp == QString("get")) return DSystemFuncs::getVariable( arg.at(0), arg.at(1) ); else if (*tmp == QString("set")) { if (arg.count() < 3 ) return g_vErr; DSystemFuncs::setVariable( arg.at(0), arg.at(1), arg.at(2) ); return g_vSuc; } } } else if ( *tmp == g_sNull.toLower() ) return g_vNull; else if ( *tmp == "succses" ) return g_vSuc; else if ( *tmp == "error" ) return g_vErr; return g_vErr; }
int main(int argc, char *argv[]){ char preprocess_file_name[FILE_PATH]; char output_file_name[FILE_PATH]; FILE *target_source_file, *output; TYPEDEF_TABLE_LIST *typedef_table_list_zen, *typedef_table_list; STRUCT_TABLE_LIST *struct_table_list; VARIABLE_TABLE_LIST *variable_table_list_zen, *variable_table_list; ValidateVariableList *varidate_variable_list; ValidateStatementList *validate_statement_list; INCLUDE_LIST *include_list; ForInformationList *for_information_list; FUNCTION_INFORMATION_LIST *function_information_list; EXPR_SLICING_LIST *expr_slicing_list; AST *pre_programAST, *programAST; //フラグデータベースの設定 int flag_database = getFlagDatabase(argc, argv); //ヘルプモードが含まれていたらヘルプだけ表示させる if(isHelpMode(flag_database)){ viewHelp(); } //そうでなければ、検証式付加処理に進める else{ int i; //フラグを飛ばす for(i = 1;i < argc && strlen(argv[i]) >= 2 && ( argv[i][0] == '-' && argv[i][1] == '-' ); i++); if(i == argc){ fprintf(stderr, "開くファイル名が存在しません!\n"); exit(1); } if(argc >= ENABLE_ARGUMENT){ //ファイル名を設定する(これは他のエラー処理などでファイル名を表示させるようにするために必要) setFileName(argv[i]); //前処理に成功した場合 if(preProcesser(argv[i])){ //プリプロセス後のファイル名の設定 snprintf(preprocess_file_name, FILE_PATH, "%s_out.c_pre.c", argv[i]); //インクルードファイルリストを取得 include_list = INCLUDE_LIST_new(); readIncludeDataFromFile(preprocess_file_name, include_list); target_source_file = fopen(preprocess_file_name, "r"); if(target_source_file != NULL){ //ここから変数宣言の分割処理 pre_programAST = parserANSIC(target_source_file, &typedef_table_list_zen); //ASTノードに、返却の型名・ブロックレベル・ブロックIDを付加する。 setASTReturnType(pre_programAST); setASTBlocklevelAndId(pre_programAST); //AST木から変数テーブルを生成 variable_table_list_zen = VARIABLE_TABLE_LIST_new(); getVARIABLE_TABLE_LIST(variable_table_list_zen, pre_programAST); printVARIABLE_TABLE_LIST(variable_table_list_zen); fclose(target_source_file); //分割後を出力させるために同じファイルに上書きさせる output = fopen(preprocess_file_name, "w"); OutputSourceAfterDivitionDeclarator(output, pre_programAST, variable_table_list_zen); fclose(output); //ここまで変数宣言の分割処理 //ソースファイルを開ける(ここは確実に開けるので、チェック機構はなしにする) target_source_file = fopen(preprocess_file_name, "r"); programAST = parserANSIC(target_source_file, &typedef_table_list); //ASTノードに、返却の型名・ブロックレベル・ブロックIDを付加する。 setASTReturnType(programAST); setASTBlocklevelAndId(programAST); //XMLモードである場合 if(isXmlMode(flag_database)){ //AST木全体をXMLとして出力する traverseASTwithXML(programAST, 0); printTargetASTNode(programAST, "array_access", 1, 1); printTargetASTNode(programAST, "direct_ref", 1, 1); printTargetASTNode(programAST, "expression_statement", 1, 1); printTargetASTNode(programAST, "function_definition", 1, 1); printTargetASTNode(programAST, "if_statement",1, 1); }else{ //AST木全体を出力する //traverseAST(programAST, 0); //AST木からプログラムを出力する //int tmp = 1; //printDataFromAST(programAST, &tmp); //AST木から生成したTYPEDEFテーブルを表示 //printTYPEDEF_TABLE_LIST(typedef_table_list); //AST木から構造体テーブルを生成して出力 struct_table_list = STRUCT_TABLE_LIST_new(); getSTRUCT_TABLE_DATA(struct_table_list, programAST); //printSTRUCT_TABLE_LIST(struct_table_list); //AST木から変数テーブルを生成して出力 variable_table_list = VARIABLE_TABLE_LIST_new(); getVARIABLE_TABLE_LIST(variable_table_list, programAST); getParameterVARIABLE_TABLE_LIST(variable_table_list, programAST); //変数テーブルから検証用変数テーブルを生成して出力 varidate_variable_list = ValidateVariableList_new(); getValidate_Variable(variable_table_list, varidate_variable_list); //printVALIDATE_VARIABLE_LIST(varidate_variable_list); //関数に関するリストを生成して出力 function_information_list = FUNCTION_INFORMATION_LIST_new(); getFunctionInformation(function_information_list, programAST); getFunctionInformationFromFile(function_information_list, "./Standard_library.ini"); printFUNCTION_INFORMATION_LIST(function_information_list); //(実験)指定されたASTの情報を出力 //printTargetASTNode(programAST, "call_function", 0, 0); //printTargetASTNode(programAST, "direct_ref", 0, 0); //printTargetASTNode(programAST, "assignment_expression", 0, 0); //printTargetASTNode(programAST, "expression_statement", 0, 0); //変数一覧表の初期化 initializeVariableOfStatementList(); //検証式の生成 validate_statement_list = ValidateStatementList_new(); for_information_list = ForInformationList_new(); createValidateStatementFromArrayDefine(varidate_variable_list, validate_statement_list, variable_table_list, function_information_list); createVaridateStatementFromPointerDefine(validate_statement_list, variable_table_list, function_information_list); createValidateStatement(programAST, function_information_list, variable_table_list, varidate_variable_list, validate_statement_list, for_information_list, isUndefineControlCheckMode(flag_database), isZeroDivitionCheckMode(flag_database), isArrayUnboundCheckMode(flag_database), isFreeViolationCheckMode(flag_database)); if(isProgramSlicingMode(flag_database)){ //検証式リストをASTノードごとにソートする validateStatementListSort(validate_statement_list); //プログラムスライシングリストに関する情報を生成 expr_slicing_list = EXPR_SLICING_LIST_new(); createStatementNodeList(programAST, expr_slicing_list, NULL, variable_table_list, function_information_list); //関数内で使用されているグローバル変数を抽出し、プログラムスライシングの関数呼び出しの対象の変数に設定する setGlobalVariable(expr_slicing_list, expr_slicing_list); //プログラムスライシングの対象の変数および依存関係に対して、データ依存関係を追加する createDD_listAll(expr_slicing_list, function_information_list, expr_slicing_list); //プログラムスライシングに関する情報を出力させる print_EXPR_SLICING_LIST(expr_slicing_list); print_tree_EXPR_SLICING_LIST(expr_slicing_list, 0); //プログラムスライシング情報をもとに、検証式を出力させる createValidateStatementAdderFileEachCheck(expr_slicing_list, validate_statement_list, varidate_variable_list, for_information_list, include_list); }else{ //出力ファイルに検証式付きのプログラムを出力させる snprintf(output_file_name, FILE_PATH, "%s_output.c", preprocess_file_name); output = fopen(output_file_name, "w"); //printProgramDataWithValidateStatement(programAST, varidate_variable_list, validate_statement_list, for_information_list); fprintProgramDataWithValidateStatement(output, programAST, varidate_variable_list, validate_statement_list, for_information_list, function_information_list, variable_table_list); //入力ファイルおよび出力ファイルを閉じる fclose(target_source_file); fclose(output); //インクルードリストからインクルードを付加する addIncludeDataFromFile(output_file_name, include_list); } } }else{ printf("PreProcesser is failed!! Please Check your source file!!\n"); } } } } return 0; }
Image * Cache::useCachedImage(cache_key_t key) { /* * the calling function needs an image, so calls this method. * if we already have the desired image and it is already used, * a clone is built and returned. * * if we have an unused master, we return it. * * then declare this image as used and increase a relative counter. * * a freeImage action will do the converse operation (and delete). * if the image is not already cached, it is loaded, if possible. * * so, if there is no such image, NULL is returned * */ #ifdef FIM_CACHE_DEBUG std::cout << " useCachedImage(\""<<key.first<<","<<key.second<<"\")\n"; #endif Image * image=NULL; if(!is_in_cache(key)) { /* * no Image cached at all for this filename * */ image = loadNewImage(key); if(!image)return NULL; // bad luck! usageCounter[key]=1; setGlobalVariable(FIM_VID_CACHE_STATUS,getReport().c_str()); return image; // usageCounter[key]=0; } else { /* * at least one copy of this filename image is in cache * */ image=getCachedImage(key);// in this way we update the LRU cache :) if(!image) { // critical error #ifdef FIM_CACHE_DEBUG cout << "critical internal cache error!\n"; #endif setGlobalVariable(FIM_VID_CACHE_STATUS,getReport().c_str()); return NULL; } if( used_image( key ) ) { // if the image was already used, cloning occurs // image = image->getClone(); // EVIL !! try { #ifdef FIM_CACHE_DEBUG Image * oi=image; #endif image = new Image(*image); // cloning #ifdef FIM_CACHE_DEBUG std::cout << " cloned image: \"" <<image->getName()<< "\" "<< image << " from \""<<oi->getName() <<"\" " << oi << "\n"; #endif } catch(FimException e) { /* we will survive :P */ image = NULL; /* we make sure no taint remains */ // if( e != FIM_E_NO_IMAGE )throw FIM_E_TRAGIC; /* hope this never occurs :P */ } if(!image)return NULL; //means that cloning failed. clone_pool.insert(image); // we have a clone cloneUsageCounter[image]=1; } lru_touch( key ); // if loading and eventual cloning succeeded, we count the image as used of course usageCounter[key]++; setGlobalVariable(FIM_VID_CACHE_STATUS,getReport().c_str()); return image; //so, it could be a clone.. } }