GLuint LoadShader(const char * vert_filename, const char * frag_filename){ GLuint handle = glCreateProgram(); GLint link_status; if (vert_filename && strlen(vert_filename)) { char *vert_source = ReadFileData(vert_filename); GLuint vert_shader = CompileShader(vert_source, GL_VERTEX_SHADER); glAttachShader(handle, vert_shader); free(vert_source); } if (frag_filename && strlen(frag_filename)) { char *frag_source = ReadFileData(frag_filename); GLuint frag_shader = CompileShader(frag_source, GL_FRAGMENT_SHADER); glAttachShader(handle, frag_shader); free(frag_source); } glLinkProgram(handle); glGetProgramiv(handle, GL_LINK_STATUS, &link_status); if (link_status == GL_FALSE) { GLchar messages[256]; glGetProgramInfoLog(handle, sizeof(messages), 0, &messages[0]); fprintf(stderr, "%s\n", messages); exit(1); } return handle; }
GLuint genRenderProg(GLuint texHandle) { GLuint progHandle = glCreateProgram(); GLuint vp = glCreateShader(GL_VERTEX_SHADER); GLuint fp = glCreateShader(GL_FRAGMENT_SHADER); const char *vpcode= ReadFileData("resource\\shader\\vertexshader.glsl"); const char *fpcode = ReadFileData("resource\\shader\\fragmentshader.glsl"); glShaderSource(vp,1, &vpcode, 0); glShaderSource(fp,1, &fpcode, 0); glCompileShader(vp); int rvalue=0; glGetShaderiv(vp, GL_COMPILE_STATUS, &rvalue); assert(rvalue); glAttachShader(progHandle, vp); rvalue=0; glCompileShader(fp); glGetShaderiv(fp, GL_COMPILE_STATUS, &rvalue); assert(rvalue); glAttachShader(progHandle, fp); glBindFragDataLocation(progHandle, 0, "color"); glLinkProgram(progHandle); rvalue = 0; glGetProgramiv(progHandle, GL_LINK_STATUS, &rvalue); assert(rvalue); glUseProgram(progHandle); glUniform1i(glGetUniformLocation(progHandle, "srcTex"), 0); GLuint posBuf; glGenBuffers(1, &posBuf); glBindBuffer(GL_ARRAY_BUFFER, posBuf); float data[] = { -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f }; glBufferData(GL_ARRAY_BUFFER, sizeof(float)* 8, data, GL_STREAM_DRAW); GLint posPtr = glGetAttribLocation(progHandle, "pos"); glVertexAttribPointer(posPtr, 2, GL_FLOAT, GL_FALSE, 0, 0); glEnableVertexAttribArray(posPtr); return progHandle; }
// // Parse either a .conf file provided by the user or the default from glslang::DefaultTBuiltInResource // void ProcessConfigFile() { char** configStrings = 0; char* config = 0; if (ConfigFile.size() > 0) { configStrings = ReadFileData(ConfigFile.c_str()); if (configStrings) config = *configStrings; else { printf("Error opening configuration file; will instead use the default configuration\n"); usage(); } } if (config == 0) { Resources = glslang::DefaultTBuiltInResource; return; } glslang::DecodeResourceLimits(&Resources, config); if (configStrings) FreeFileData(configStrings); else delete[] config; }
int ModifyEvents(FILE *f, int nNumEvents, int nMin, double *pOffsets, int n) { RLOG_EVENT event; int i, index; int error; MPL_msg_printf("Modifying %d events\n", nNumEvents); fseek(f, 0, SEEK_CUR); for (i=0; i<nNumEvents; i++) { error = ReadFileData((char*)&event, sizeof(RLOG_EVENT), f); if (error) { rlog_err_printf("reading event failed.\n"); return -1; } index = event.rank - nMin; if (index >= 0 && index < n && pOffsets[index] != 0) { event.start_time += pOffsets[index]; event.end_time += pOffsets[index]; fseek(f, -(int)sizeof(RLOG_EVENT), SEEK_CUR); error = WriteFileData((const char *)&event, sizeof(RLOG_EVENT), f); if (error) { rlog_err_printf("writing modified event failed.\n"); return -1; } fseek(f, 0, SEEK_CUR); } } return 0; }
const cxStr *cxUtil::DocumentData(cchars file) { CX_ASSERT(cxStr::IsOK(file), "path error"); const cxStr *path = DocumentPath(file); if(!cxStr::IsOK(path)){ return nullptr; } return ReadFileData(path); }
// // Read a file's data into a string, and parse it using Hlsl2Glsl_Parse // bool ParseFile(const char *fileName, ShHandle parser, int debugOptions) { int ret; char *data = ReadFileData(fileName); if (!data) return false; ret = Hlsl2Glsl_Parse(parser, data, ETargetGLSL_120, debugOptions); FreeFileData(data); return ret ? true : false; }
bool CCommonUtils::CalcFileHash(ALG_ID hashType, LPCTSTR lpFileName, BYTE* lpHash, DWORD dwHashSize) { LPVOID lpData; DWORD dwLen; bool bRet = false; lpData = ReadFileData(lpFileName, dwLen); if(lpData) { bRet = CalcHash(hashType, (LPBYTE)lpData, dwLen, lpHash, dwHashSize); free(lpData); } return bRet; }
int RLOG_GetNextArrow(RLOG_IOStruct *pInput, RLOG_ARROW *pArrow) { if (pInput == NULL) return -1; if (pInput->nCurArrow >= pInput->nNumArrows) return 1; fseek(pInput->f, pInput->nArrowOffset + (pInput->nCurArrow * sizeof(RLOG_ARROW)), SEEK_SET); if (ReadFileData((char*)pArrow, sizeof(RLOG_ARROW), pInput->f)) { rlog_err_printf("Error reading next rlog arrow\n"); return -1; } pInput->nCurArrow++; return 0; }
int RLOG_GetArrow(RLOG_IOStruct *pInput, int i, RLOG_ARROW *pArrow) { if (pInput == NULL || pArrow == NULL || i < 0 || i >= pInput->nNumArrows) return -1; fseek(pInput->f, pInput->nArrowOffset + (i * sizeof(RLOG_ARROW)), SEEK_SET); if (ReadFileData((char*)pArrow, sizeof(RLOG_ARROW), pInput->f)) { rlog_err_printf("Error reading rlog arrow\n"); return -1; } pInput->nCurArrow = i+1; return 0; }
int RLOG_GetNextState(RLOG_IOStruct *pInput, RLOG_STATE *pState) { if (pInput == NULL || pState == NULL) return -1; if (pInput->nCurState >= pInput->nNumStates) return 1; fseek(pInput->f, pInput->nStateOffset + (pInput->nCurState * sizeof(RLOG_STATE)), SEEK_SET); if (ReadFileData((char*)pState, sizeof(RLOG_STATE), pInput->f)) { rlog_err_printf("Error reading next rlog state\n"); return -1; } pInput->nCurState++; return 0; }
int C_DECL main(int argc, char* argv[]) { { // One time init InitResources(); glslang::InitializeProcess(); spv::Parameterize(); } const char* File = ReadFileData(argv[1]); DoCompile(File); glslang::FinalizeProcess(); return 0; }
// // Read a file's data into a string, and compile it using the old interface ShCompile, // for non-linkable results. // void CompileFile(const char* fileName, ShHandle compiler) { int ret = 0; char** shaderStrings = ReadFileData(fileName); if (! shaderStrings) { usage(); } int* lengths = new int[NumShaderStrings]; // move to length-based strings, rather than null-terminated strings for (int s = 0; s < NumShaderStrings; ++s) lengths[s] = (int)strlen(shaderStrings[s]); if (! shaderStrings) { CompileFailed = true; return; } EShMessages messages = EShMsgDefault; SetMessageOptions(messages); for (int i = 0; i < ((Options & EOptionMemoryLeakMode) ? 100 : 1); ++i) { for (int j = 0; j < ((Options & EOptionMemoryLeakMode) ? 100 : 1); ++j) { //ret = ShCompile(compiler, shaderStrings, NumShaderStrings, lengths, EShOptNone, &Resources, Options, (Options & EOptionDefaultDesktop) ? 110 : 100, false, messages); ret = ShCompile(compiler, shaderStrings, NumShaderStrings, nullptr, EShOptNone, &Resources, Options, (Options & EOptionDefaultDesktop) ? 110 : 100, false, messages); //const char* multi[12] = { "# ve", "rsion", " 300 e", "s", "\n#err", // "or should be l", "ine 1", "string 5\n", "float glo", "bal", // ";\n#error should be line 2\n void main() {", "global = 2.3;}" }; //const char* multi[7] = { "/", "/", "\\", "\n", "\n", "#", "version 300 es" }; //ret = ShCompile(compiler, multi, 7, nullptr, EShOptNone, &Resources, Options, (Options & EOptionDefaultDesktop) ? 110 : 100, false, messages); } if (Options & EOptionMemoryLeakMode) glslang::OS_DumpMemoryCounters(); } delete [] lengths; FreeFileData(shaderStrings); if (ret == 0) CompileFailed = true; }
status_t PackageFileHeapReader::Init() { if (fUncompressedHeapSize == 0) return B_OK; // Determine number of chunks and adjust the compressed heap size (subtract // the size of the chunk size array at the end). Note that the size of the // last chunk has not been saved, since it size is implied. ssize_t chunkCount = (fUncompressedHeapSize + kChunkSize - 1) / kChunkSize; if (chunkCount <= 0) return B_OK; fCompressedHeapSize -= (chunkCount - 1) * 2; // allocate a buffer uint16* buffer = (uint16*)malloc(kChunkSize); if (buffer == NULL) return B_NO_MEMORY; MemoryDeleter bufferDeleter(buffer); // read the chunk size array size_t remainingChunks = chunkCount - 1; size_t index = 0; uint64 offset = fCompressedHeapSize; while (remainingChunks > 0) { size_t toRead = std::min(remainingChunks, kChunkSize / 2); status_t error = ReadFileData(offset, buffer, toRead * 2); if (error != B_OK) return error; if (!fOffsets.InitChunksOffsets(chunkCount, index, buffer, toRead)) return B_NO_MEMORY; remainingChunks -= toRead; index += toRead; offset += toRead * 2; } return B_OK; }
void SPFS::ExtractToFile(LPCTSTR spfsFileName,LPCTSTR targetPathFileName) { // find file in pack file. // ---------------------------------- DWORD offset = 0; // offset of file. DWORD size = 0; // size of file. DWORD written = 0; // size of written bytes. if( !FindFile(spfsFileName,offset,size) ) throw new SPFSException(_T("not found file in pack !"),SPFS_FILE_IS_NOT_OPENED); // read founded file from pack. //----------------------------- char* lpBuff = (char*)malloc(size); if( !ReadFileData(offset,size,lpBuff,size,written) && written == size ) throw new SPFSException(_T("can't read file data !"),SPFS_FILE_CANT_READ); //----------------------------- // check for file existing & create current file. // ---------------------------------------------- if( !_access(targetPathFileName,0) ) throw new SPFSException(_T("that file allready exists!"),SPFS_FILE_ALLREADY_EXISTS); // create file to write into. HANDLE hFile = CreateFile(targetPathFileName,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,CREATE_NEW,0,NULL); if( hFile == (HANDLE)-1 ) throw new SPFSException(_T("can't create file !"),SPFS_FILE_CANT_CREATE); // ---------------------------------------------- // write contained file. // ----------------------------------------------------------------- if( !WriteFile(hFile,lpBuff,size,&written,NULL) || written != size ) { free(lpBuff); CloseHandle(hFile); throw new SPFSException(_T("can't write contained file !"),SPFS_FILE_CANT_WRITE); } free(lpBuff); CloseHandle(hFile); // ----------------------------------------------------------------- }
// // Do file IO part of compile and link, handing off the pure // API/programmatic mode to CompileAndLinkShaderUnits(), which can // be put in a loop for testing memory footprint and performance. // // This is just for linking mode: meaning all the shaders will be put into the // the same program linked together. // // This means there are a limited number of work items (not multi-threading mode) // and that the point is testing at the linking level. Hence, to enable // performance and memory testing, the actual compile/link can be put in // a loop, independent of processing the work items and file IO. // void CompileAndLinkShaderFiles() { std::vector<ShaderCompUnit> compUnits; // Transfer all the work items from to a simple list of // of compilation units. (We don't care about the thread // work-item distribution properties in this path, which // is okay due to the limited number of shaders, know since // they are all getting linked together.) glslang::TWorkItem* workItem; while (Worklist.remove(workItem)) { ShaderCompUnit compUnit( FindLanguage(workItem->name), workItem->name, ReadFileData(workItem->name.c_str()) ); if (! compUnit.text) { usage(); return; } compUnits.push_back(compUnit); } // Actual call to programmatic processing of compile and link, // in a loop for testing memory and performance. This part contains // all the perf/memory that a programmatic consumer will care about. for (int i = 0; i < ((Options & EOptionMemoryLeakMode) ? 100 : 1); ++i) { for (int j = 0; j < ((Options & EOptionMemoryLeakMode) ? 100 : 1); ++j) CompileAndLinkShaderUnits(compUnits); if (Options & EOptionMemoryLeakMode) glslang::OS_DumpMemoryCounters(); } for (auto it = compUnits.begin(); it != compUnits.end(); ++it) FreeFileData(it->text); }
int RLOG_GetEvent(RLOG_IOStruct *pInput, int rank, int recursion_level, int index, RLOG_EVENT *pEvent) { int rank_index; if (pInput == NULL || pEvent == NULL || rank < pInput->header.nMinRank || rank > pInput->header.nMaxRank) return -1; rank_index = rank - pInput->header.nMinRank; if (recursion_level < 0 || recursion_level >= pInput->pNumEventRecursions[rank_index]) return -1; if (index < 0 || index >= pInput->ppNumEvents[rank_index][recursion_level]) return -1; fseek(pInput->f, pInput->ppEventOffset[rank_index][recursion_level] + (index * sizeof(RLOG_EVENT)), SEEK_SET); if (ReadFileData((char*)pEvent, sizeof(RLOG_EVENT), pInput->f)) { rlog_err_printf("Error reading rlog event\n"); return -1; } /* GetEvent sets the current iteration position also */ pInput->ppCurEvent[rank_index][recursion_level] = index+1; return 0; }
int RLOG_GetNextEvent(RLOG_IOStruct *pInput, int rank, int recursion_level, RLOG_EVENT *pEvent) { int rank_index; if (pInput == NULL || recursion_level < 0 || pEvent == NULL || rank < pInput->header.nMinRank || rank > pInput->header.nMaxRank) return -1; rank_index = rank - pInput->header.nMinRank; if (recursion_level < pInput->pNumEventRecursions[rank_index] && pInput->ppCurEvent[rank_index] != NULL) { if (pInput->ppCurEvent[rank_index][recursion_level] >= pInput->ppNumEvents[rank_index][recursion_level]) return 1; fseek(pInput->f, pInput->ppEventOffset[rank_index][recursion_level] + (pInput->ppCurEvent[rank_index][recursion_level] * sizeof(RLOG_EVENT)), SEEK_SET); if (ReadFileData((char*)pEvent, sizeof(RLOG_EVENT), pInput->f)) { rlog_err_printf("Error reading next rlog event\n"); return -1; } pInput->ppCurEvent[rank_index][recursion_level]++; return 0; } return 1; }
void SPFS::LoadFileAsString(LPCSTR spfsFileName,string& sResultStr) { if( !IsOpen() ) throw new SPFSException(_T("pack file isn't opened !"),SPFS_FILE_IS_NOT_OPENED); DWORD offset = 0; // offset of file. DWORD size = 0; // size of file. DWORD written = 0; // size of written bytes. // find file in pack file. if( !FindFile(spfsFileName,offset,size) ) throw new SPFSException(_T("not found file in pack !"),SPFS_FILE_IS_NOT_OPENED); char* lpBuff = (char*)malloc(size+1); if( ReadFileData(offset,size,lpBuff,size,written) && written == size ) { lpBuff[size] = 0x00; sResultStr = lpBuff; } else throw new SPFSException(_T("can't read file data !"),SPFS_FILE_CANT_READ); free(lpBuff); }
bool XConfig::ReadFileData(XElement *curElement, int level, TSTR &lpTemp) { while(*lpTemp) { if(*lpTemp == '}') return level != 0; if(*lpTemp == '{') //unnamed object, usually only happens at the start of the file, ignore { ++lpTemp; if(!ReadFileData(curElement, level+1, lpTemp)) return false; } else if(*lpTemp != ' ' && *lpTemp != L' ' && *lpTemp != '\t' && *lpTemp != '\r' && *lpTemp != '\n' && *lpTemp != ',') { String strName; if(*lpTemp == '"') strName = ProcessString(lpTemp); else { TSTR lpDataStart = lpTemp; lpTemp = schr(lpTemp, ':'); if(!lpTemp) return false; *lpTemp = 0; strName = lpDataStart; *lpTemp = ':'; strName.KillSpaces(); } //--------------------------- lpTemp = schr(lpTemp, ':'); if(!lpTemp) return false; ++lpTemp; while( *lpTemp == ' ' || *lpTemp == L' ' || *lpTemp == '\t' ) { ++lpTemp; } //--------------------------- if(*lpTemp == '{') //element { ++lpTemp; XElement *newElement = curElement->CreateElement(strName); if(!ReadFileData(newElement, level+1, lpTemp)) return false; } else //item { String data; if(*lpTemp == '"') data = ProcessString(lpTemp); else { TSTR lpDataStart = lpTemp; lpTemp = schr(lpTemp, '\n'); if(!lpTemp) return false; if(lpTemp[-1] == '\r') --lpTemp; if(lpTemp != lpDataStart) { TCHAR oldChar = *lpTemp; *lpTemp = 0; data = lpDataStart; *lpTemp = oldChar; data.KillSpaces(); } } lpTemp = schr(lpTemp, '\n'); if(!lpTemp && curElement != RootElement) return false; curElement->SubItems << new XDataItem(strName, data); } } ++lpTemp; } return (curElement == RootElement); }
static int ModifyArrows(FILE *f, int nNumArrows, int nMin, double *pOffsets, int n) { RLOG_ARROW arrow, *pArray; int i, index, bModified; long arrow_pos; int error; double temp_time; fseek(f, 0, SEEK_CUR); arrow_pos = ftell(f); if (arrow_pos == -1) return errno; pArray = (RLOG_ARROW*)MPIU_Malloc(nNumArrows * sizeof(RLOG_ARROW)); if (pArray) { MPL_msg_printf("Modifying %d arrows\n", nNumArrows); /* read the arrows */ fseek(f, 0, SEEK_CUR); error = ReadFileData((char*)pArray, nNumArrows * sizeof(RLOG_ARROW), f); if (error) { MPIU_Free(pArray); return error; } /* modify the arrows */ for (i=0; i<nNumArrows; i++) { arrow = pArray[i]; bModified = FALSE; index = (arrow.leftright == RLOG_ARROW_RIGHT) ? arrow.src - nMin : arrow.dest - nMin; if (index >= 0 && index < n && pOffsets[index] != 0) { arrow.start_time += pOffsets[index]; bModified = TRUE; } index = (arrow.leftright == RLOG_ARROW_RIGHT) ? arrow.dest - nMin : arrow.src - nMin; if (index >= 0 && index < n && pOffsets[index] != 0) { arrow.end_time += pOffsets[index]; bModified = TRUE; } if (bModified) { if (arrow.start_time > arrow.end_time) { temp_time = arrow.start_time; arrow.start_time = arrow.end_time; arrow.end_time = temp_time; arrow.leftright = (arrow.leftright == RLOG_ARROW_LEFT) ? RLOG_ARROW_RIGHT : RLOG_ARROW_LEFT; } pArray[i] = arrow; } } /* sort the arrows */ qsort(pArray, (size_t)nNumArrows, sizeof(RLOG_ARROW), (int (*)(const void *,const void*))compareArrows); /* write the arrows back */ fseek(f, arrow_pos, SEEK_SET); error = WriteFileData((char*)pArray, nNumArrows * sizeof(RLOG_ARROW), f); if (error) { MPIU_Free(pArray); return error; } fseek(f, 0, SEEK_CUR); MPIU_Free(pArray); } else { MPL_error_printf("Error: unable to allocate an array big enough to hold %d arrows\n", nNumArrows); return -1; } return 0; }
// // For linking mode: Will independently parse each item in the worklist, but then put them // in the same program and link them together. // // Uses the new C++ interface instead of the old handle-based interface. // void CompileAndLinkShaders() { // keep track of what to free std::list<glslang::TShader*> shaders; EShMessages messages = EShMsgDefault; SetMessageOptions(messages); // // Per-shader processing... // glslang::TProgram& program = *new glslang::TProgram; glslang::TWorkItem* workItem; while (Worklist.remove(workItem)) { EShLanguage stage = FindLanguage(workItem->name); glslang::TShader* shader = new glslang::TShader(stage); shaders.push_back(shader); char** shaderStrings = ReadFileData(workItem->name.c_str()); if (! shaderStrings) { usage(); delete &program; return; } const int defaultVersion = Options & EOptionDefaultDesktop? 110: 100; shader->setStrings(shaderStrings, 1); if (Options & EOptionOutputPreprocessed) { std::string str; if (shader->preprocess(&Resources, defaultVersion, ENoProfile, false, false, messages, &str, glslang::TShader::ForbidInclude())) { PutsIfNonEmpty(str.c_str()); } else { CompileFailed = true; } StderrIfNonEmpty(shader->getInfoLog()); StderrIfNonEmpty(shader->getInfoDebugLog()); FreeFileData(shaderStrings); continue; } if (! shader->parse(&Resources, defaultVersion, false, messages)) CompileFailed = true; program.addShader(shader); if (! (Options & EOptionSuppressInfolog)) { PutsIfNonEmpty(workItem->name.c_str()); PutsIfNonEmpty(shader->getInfoLog()); PutsIfNonEmpty(shader->getInfoDebugLog()); } FreeFileData(shaderStrings); } // // Program-level processing... // if (! (Options & EOptionOutputPreprocessed) && ! program.link(messages)) LinkFailed = true; if (! (Options & EOptionSuppressInfolog)) { PutsIfNonEmpty(program.getInfoLog()); PutsIfNonEmpty(program.getInfoDebugLog()); } if (Options & EOptionDumpReflection) { program.buildReflection(); program.dumpReflection(); } if (Options & EOptionSpv) { if (CompileFailed || LinkFailed) printf("SPIR-V is not generated for failed compile or link\n"); else { for (int stage = 0; stage < EShLangCount; ++stage) { if (program.getIntermediate((EShLanguage)stage)) { std::vector<unsigned int> spirv; glslang::GlslangToSpv(*program.getIntermediate((EShLanguage)stage), spirv); glslang::OutputSpv(spirv, GetBinaryName((EShLanguage)stage)); if (Options & EOptionHumanReadableSpv) { spv::Parameterize(); spv::Disassemble(std::cout, spirv); } } } } } // Free everything up, program has to go before the shaders // because it might have merged stuff from the shaders, and // the stuff from the shaders has to have its destructors called // before the pools holding the memory in the shaders is freed. delete &program; while (shaders.size() > 0) { delete shaders.back(); shaders.pop_back(); } }
RLOG_IOStruct *RLOG_CreateInputStruct(const char *filename) { int i, j, rank_index, cur_rank, min_rank = 0; RLOG_IOStruct *pInput; int type, length; /* allocate an input structure */ pInput = (RLOG_IOStruct*)MPIU_Malloc(sizeof(RLOG_IOStruct)); if (pInput == NULL) { MPL_error_printf("malloc failed - %s\n", strerror(errno)); return NULL; } pInput->ppCurEvent = NULL; pInput->ppCurGlobalEvent = NULL; pInput->gppCurEvent = NULL; pInput->gppPrevEvent = NULL; pInput->ppEventOffset = NULL; pInput->ppNumEvents = NULL; pInput->nNumArrows = 0; /* open the input rlog file */ pInput->f = fopen(filename, "rb"); if (pInput->f == NULL) { MPL_error_printf("fopen(%s) failed, error: %s\n", filename, strerror(errno)); MPIU_Free(pInput); return NULL; } pInput->nNumRanks = 0; /* read the sections */ while (fread(&type, sizeof(int), 1, pInput->f)) { fread(&length, sizeof(int), 1, pInput->f); switch (type) { case RLOG_HEADER_SECTION: /*printf("type: RLOG_HEADER_SECTION, length: %d\n", length);*/ if (length != sizeof(RLOG_FILE_HEADER)) { MPL_error_printf("error in header size %d != %d\n", length, (int)sizeof(RLOG_FILE_HEADER)); } if (ReadFileData((char*)&pInput->header, sizeof(RLOG_FILE_HEADER), pInput->f)) { rlog_err_printf("reading rlog header failed\n"); return NULL; } pInput->nNumRanks = pInput->header.nMaxRank + 1 - pInput->header.nMinRank; min_rank = pInput->header.nMinRank; pInput->pRank = (int*)MPIU_Malloc(pInput->nNumRanks * sizeof(int)); pInput->pNumEventRecursions = (int*)MPIU_Malloc(pInput->nNumRanks * sizeof(int)); pInput->ppNumEvents = (int**)MPIU_Malloc(pInput->nNumRanks * sizeof(int*)); pInput->ppCurEvent = (int**)MPIU_Malloc(pInput->nNumRanks * sizeof(int*)); pInput->ppCurGlobalEvent = (int**)MPIU_Malloc(pInput->nNumRanks * sizeof(int*)); pInput->gppCurEvent = (RLOG_EVENT**)MPIU_Malloc(pInput->nNumRanks * sizeof(RLOG_EVENT*)); pInput->gppPrevEvent = (RLOG_EVENT**)MPIU_Malloc(pInput->nNumRanks * sizeof(RLOG_EVENT*)); pInput->ppEventOffset = (long**)MPIU_Malloc(pInput->nNumRanks * sizeof(long*)); for (i=0; i<pInput->nNumRanks; i++) { pInput->pRank[i] = -1; pInput->pNumEventRecursions[i] = 0; pInput->ppNumEvents[i] = NULL; pInput->ppCurEvent[i] = NULL; pInput->ppCurGlobalEvent[i] = NULL; pInput->gppCurEvent[i] = NULL; pInput->gppPrevEvent[i] = NULL; pInput->ppEventOffset[i] = NULL; } break; case RLOG_STATE_SECTION: /*printf("type: RLOG_STATE_SECTION, length: %d\n", length);*/ pInput->nNumStates = length / sizeof(RLOG_STATE); pInput->nStateOffset = ftell(pInput->f); fseek(pInput->f, length, SEEK_CUR); break; case RLOG_ARROW_SECTION: /*printf("type: RLOG_ARROW_SECTION, length: %d\n", length);*/ pInput->nNumArrows = length / sizeof(RLOG_ARROW); pInput->nArrowOffset = ftell(pInput->f); fseek(pInput->f, length, SEEK_CUR); break; case RLOG_EVENT_SECTION: /*printf("type: RLOG_EVENT_SECTION, length: %d, ", length);*/ fread(&cur_rank, sizeof(int), 1, pInput->f); if (cur_rank - min_rank >= pInput->nNumRanks) { MPL_error_printf("Error: event section out of range - %d <= %d <= %d\n", pInput->header.nMinRank, cur_rank, pInput->header.nMaxRank); MPIU_Free(pInput); return NULL; } rank_index = cur_rank - min_rank; fread(&pInput->pNumEventRecursions[rank_index], sizeof(int), 1, pInput->f); /*printf("levels: %d\n", pInput->nNumEventRecursions);*/ if (pInput->pNumEventRecursions[rank_index]) { pInput->ppCurEvent[rank_index] = (int*)MPIU_Malloc(pInput->pNumEventRecursions[rank_index] * sizeof(int)); pInput->ppCurGlobalEvent[rank_index] = (int*)MPIU_Malloc(pInput->pNumEventRecursions[rank_index] * sizeof(int)); pInput->gppCurEvent[rank_index] = (RLOG_EVENT*)MPIU_Malloc(pInput->pNumEventRecursions[rank_index] * sizeof(RLOG_EVENT)); pInput->gppPrevEvent[rank_index] = (RLOG_EVENT*)MPIU_Malloc(pInput->pNumEventRecursions[rank_index] * sizeof(RLOG_EVENT)); pInput->ppNumEvents[rank_index] = (int*)MPIU_Malloc(pInput->pNumEventRecursions[rank_index] * sizeof(int)); pInput->ppEventOffset[rank_index] = (long*)MPIU_Malloc(pInput->pNumEventRecursions[rank_index] * sizeof(long)); } for (i=0; i<pInput->pNumEventRecursions[rank_index]; i++) { fread(&pInput->ppNumEvents[rank_index][i], sizeof(int), 1, pInput->f); /*printf(" level %2d: %d events\n", i, pInput->pNumEvents[i]);*/ } if (pInput->pNumEventRecursions[rank_index]) { pInput->ppEventOffset[rank_index][0] = ftell(pInput->f); for (i=1; i<pInput->pNumEventRecursions[rank_index]; i++) { pInput->ppEventOffset[rank_index][i] = pInput->ppEventOffset[rank_index][i-1] + (pInput->ppNumEvents[rank_index][i-1] * sizeof(RLOG_EVENT)); } } length -= ((pInput->pNumEventRecursions[rank_index] + 2) * sizeof(int)); fseek(pInput->f, length, SEEK_CUR); break; default: /*printf("unknown section: type %d, length %d\n", type, length);*/ fseek(pInput->f, length, SEEK_CUR); break; } } /* reset the iterators */ RLOG_ResetStateIter(pInput); RLOG_ResetArrowIter(pInput); for (j=0; j<pInput->nNumRanks; j++) { for (i=0; i<pInput->pNumEventRecursions[j]; i++) RLOG_ResetEventIter(pInput, j+pInput->header.nMinRank, i); } RLOG_ResetGlobalIter(pInput); return pInput; }
// // Parse either a .conf file provided by the user or the default string above. // void ProcessConfigFile() { char** configStrings = 0; char* config = 0; if (ConfigFile.size() > 0) { configStrings = ReadFileData(ConfigFile.c_str()); if (configStrings) config = *configStrings; else { printf("Error opening configuration file; will instead use the default configuration\n"); usage(); } } if (config == 0) { config = new char[strlen(DefaultConfig) + 1]; strcpy(config, DefaultConfig); } const char* delims = " \t\n\r"; const char* token = strtok(config, delims); while (token) { const char* valueStr = strtok(0, delims); if (valueStr == 0 || ! (valueStr[0] == '-' || (valueStr[0] >= '0' && valueStr[0] <= '9'))) { printf("Error: '%s' bad .conf file. Each name must be followed by one number.\n", valueStr ? valueStr : ""); return; } int value = atoi(valueStr); if (strcmp(token, "MaxLights") == 0) Resources.maxLights = value; else if (strcmp(token, "MaxClipPlanes") == 0) Resources.maxClipPlanes = value; else if (strcmp(token, "MaxTextureUnits") == 0) Resources.maxTextureUnits = value; else if (strcmp(token, "MaxTextureCoords") == 0) Resources.maxTextureCoords = value; else if (strcmp(token, "MaxVertexAttribs") == 0) Resources.maxVertexAttribs = value; else if (strcmp(token, "MaxVertexUniformComponents") == 0) Resources.maxVertexUniformComponents = value; else if (strcmp(token, "MaxVaryingFloats") == 0) Resources.maxVaryingFloats = value; else if (strcmp(token, "MaxVertexTextureImageUnits") == 0) Resources.maxVertexTextureImageUnits = value; else if (strcmp(token, "MaxCombinedTextureImageUnits") == 0) Resources.maxCombinedTextureImageUnits = value; else if (strcmp(token, "MaxTextureImageUnits") == 0) Resources.maxTextureImageUnits = value; else if (strcmp(token, "MaxFragmentUniformComponents") == 0) Resources.maxFragmentUniformComponents = value; else if (strcmp(token, "MaxDrawBuffers") == 0) Resources.maxDrawBuffers = value; else if (strcmp(token, "MaxVertexUniformVectors") == 0) Resources.maxVertexUniformVectors = value; else if (strcmp(token, "MaxVaryingVectors") == 0) Resources.maxVaryingVectors = value; else if (strcmp(token, "MaxFragmentUniformVectors") == 0) Resources.maxFragmentUniformVectors = value; else if (strcmp(token, "MaxVertexOutputVectors") == 0) Resources.maxVertexOutputVectors = value; else if (strcmp(token, "MaxFragmentInputVectors") == 0) Resources.maxFragmentInputVectors = value; else if (strcmp(token, "MinProgramTexelOffset") == 0) Resources.minProgramTexelOffset = value; else if (strcmp(token, "MaxProgramTexelOffset") == 0) Resources.maxProgramTexelOffset = value; else if (strcmp(token, "MaxClipDistances") == 0) Resources.maxClipDistances = value; else if (strcmp(token, "MaxComputeWorkGroupCountX") == 0) Resources.maxComputeWorkGroupCountX = value; else if (strcmp(token, "MaxComputeWorkGroupCountY") == 0) Resources.maxComputeWorkGroupCountY = value; else if (strcmp(token, "MaxComputeWorkGroupCountZ") == 0) Resources.maxComputeWorkGroupCountZ = value; else if (strcmp(token, "MaxComputeWorkGroupSizeX") == 0) Resources.maxComputeWorkGroupSizeX = value; else if (strcmp(token, "MaxComputeWorkGroupSizeY") == 0) Resources.maxComputeWorkGroupSizeY = value; else if (strcmp(token, "MaxComputeWorkGroupSizeZ") == 0) Resources.maxComputeWorkGroupSizeZ = value; else if (strcmp(token, "MaxComputeUniformComponents") == 0) Resources.maxComputeUniformComponents = value; else if (strcmp(token, "MaxComputeTextureImageUnits") == 0) Resources.maxComputeTextureImageUnits = value; else if (strcmp(token, "MaxComputeImageUniforms") == 0) Resources.maxComputeImageUniforms = value; else if (strcmp(token, "MaxComputeAtomicCounters") == 0) Resources.maxComputeAtomicCounters = value; else if (strcmp(token, "MaxComputeAtomicCounterBuffers") == 0) Resources.maxComputeAtomicCounterBuffers = value; else if (strcmp(token, "MaxVaryingComponents") == 0) Resources.maxVaryingComponents = value; else if (strcmp(token, "MaxVertexOutputComponents") == 0) Resources.maxVertexOutputComponents = value; else if (strcmp(token, "MaxGeometryInputComponents") == 0) Resources.maxGeometryInputComponents = value; else if (strcmp(token, "MaxGeometryOutputComponents") == 0) Resources.maxGeometryOutputComponents = value; else if (strcmp(token, "MaxFragmentInputComponents") == 0) Resources.maxFragmentInputComponents = value; else if (strcmp(token, "MaxImageUnits") == 0) Resources.maxImageUnits = value; else if (strcmp(token, "MaxCombinedImageUnitsAndFragmentOutputs") == 0) Resources.maxCombinedImageUnitsAndFragmentOutputs = value; else if (strcmp(token, "MaxCombinedShaderOutputResources") == 0) Resources.maxCombinedShaderOutputResources = value; else if (strcmp(token, "MaxImageSamples") == 0) Resources.maxImageSamples = value; else if (strcmp(token, "MaxVertexImageUniforms") == 0) Resources.maxVertexImageUniforms = value; else if (strcmp(token, "MaxTessControlImageUniforms") == 0) Resources.maxTessControlImageUniforms = value; else if (strcmp(token, "MaxTessEvaluationImageUniforms") == 0) Resources.maxTessEvaluationImageUniforms = value; else if (strcmp(token, "MaxGeometryImageUniforms") == 0) Resources.maxGeometryImageUniforms = value; else if (strcmp(token, "MaxFragmentImageUniforms") == 0) Resources.maxFragmentImageUniforms = value; else if (strcmp(token, "MaxCombinedImageUniforms") == 0) Resources.maxCombinedImageUniforms = value; else if (strcmp(token, "MaxGeometryTextureImageUnits") == 0) Resources.maxGeometryTextureImageUnits = value; else if (strcmp(token, "MaxGeometryOutputVertices") == 0) Resources.maxGeometryOutputVertices = value; else if (strcmp(token, "MaxGeometryTotalOutputComponents") == 0) Resources.maxGeometryTotalOutputComponents = value; else if (strcmp(token, "MaxGeometryUniformComponents") == 0) Resources.maxGeometryUniformComponents = value; else if (strcmp(token, "MaxGeometryVaryingComponents") == 0) Resources.maxGeometryVaryingComponents = value; else if (strcmp(token, "MaxTessControlInputComponents") == 0) Resources.maxTessControlInputComponents = value; else if (strcmp(token, "MaxTessControlOutputComponents") == 0) Resources.maxTessControlOutputComponents = value; else if (strcmp(token, "MaxTessControlTextureImageUnits") == 0) Resources.maxTessControlTextureImageUnits = value; else if (strcmp(token, "MaxTessControlUniformComponents") == 0) Resources.maxTessControlUniformComponents = value; else if (strcmp(token, "MaxTessControlTotalOutputComponents") == 0) Resources.maxTessControlTotalOutputComponents = value; else if (strcmp(token, "MaxTessEvaluationInputComponents") == 0) Resources.maxTessEvaluationInputComponents = value; else if (strcmp(token, "MaxTessEvaluationOutputComponents") == 0) Resources.maxTessEvaluationOutputComponents = value; else if (strcmp(token, "MaxTessEvaluationTextureImageUnits") == 0) Resources.maxTessEvaluationTextureImageUnits = value; else if (strcmp(token, "MaxTessEvaluationUniformComponents") == 0) Resources.maxTessEvaluationUniformComponents = value; else if (strcmp(token, "MaxTessPatchComponents") == 0) Resources.maxTessPatchComponents = value; else if (strcmp(token, "MaxPatchVertices") == 0) Resources.maxPatchVertices = value; else if (strcmp(token, "MaxTessGenLevel") == 0) Resources.maxTessGenLevel = value; else if (strcmp(token, "MaxViewports") == 0) Resources.maxViewports = value; else if (strcmp(token, "MaxVertexAtomicCounters") == 0) Resources.maxVertexAtomicCounters = value; else if (strcmp(token, "MaxTessControlAtomicCounters") == 0) Resources.maxTessControlAtomicCounters = value; else if (strcmp(token, "MaxTessEvaluationAtomicCounters") == 0) Resources.maxTessEvaluationAtomicCounters = value; else if (strcmp(token, "MaxGeometryAtomicCounters") == 0) Resources.maxGeometryAtomicCounters = value; else if (strcmp(token, "MaxFragmentAtomicCounters") == 0) Resources.maxFragmentAtomicCounters = value; else if (strcmp(token, "MaxCombinedAtomicCounters") == 0) Resources.maxCombinedAtomicCounters = value; else if (strcmp(token, "MaxAtomicCounterBindings") == 0) Resources.maxAtomicCounterBindings = value; else if (strcmp(token, "MaxVertexAtomicCounterBuffers") == 0) Resources.maxVertexAtomicCounterBuffers = value; else if (strcmp(token, "MaxTessControlAtomicCounterBuffers") == 0) Resources.maxTessControlAtomicCounterBuffers = value; else if (strcmp(token, "MaxTessEvaluationAtomicCounterBuffers") == 0) Resources.maxTessEvaluationAtomicCounterBuffers = value; else if (strcmp(token, "MaxGeometryAtomicCounterBuffers") == 0) Resources.maxGeometryAtomicCounterBuffers = value; else if (strcmp(token, "MaxFragmentAtomicCounterBuffers") == 0) Resources.maxFragmentAtomicCounterBuffers = value; else if (strcmp(token, "MaxCombinedAtomicCounterBuffers") == 0) Resources.maxCombinedAtomicCounterBuffers = value; else if (strcmp(token, "MaxAtomicCounterBufferSize") == 0) Resources.maxAtomicCounterBufferSize = value; else if (strcmp(token, "MaxTransformFeedbackBuffers") == 0) Resources.maxTransformFeedbackBuffers = value; else if (strcmp(token, "MaxTransformFeedbackInterleavedComponents") == 0) Resources.maxTransformFeedbackInterleavedComponents = value; else if (strcmp(token, "MaxCullDistances") == 0) Resources.maxCullDistances = value; else if (strcmp(token, "MaxCombinedClipAndCullDistances") == 0) Resources.maxCombinedClipAndCullDistances = value; else if (strcmp(token, "MaxSamples") == 0) Resources.maxSamples = value; else if (strcmp(token, "nonInductiveForLoops") == 0) Resources.limits.nonInductiveForLoops = (value != 0); else if (strcmp(token, "whileLoops") == 0) Resources.limits.whileLoops = (value != 0); else if (strcmp(token, "doWhileLoops") == 0) Resources.limits.doWhileLoops = (value != 0); else if (strcmp(token, "generalUniformIndexing") == 0) Resources.limits.generalUniformIndexing = (value != 0); else if (strcmp(token, "generalAttributeMatrixVectorIndexing") == 0) Resources.limits.generalAttributeMatrixVectorIndexing = (value != 0); else if (strcmp(token, "generalVaryingIndexing") == 0) Resources.limits.generalVaryingIndexing = (value != 0); else if (strcmp(token, "generalSamplerIndexing") == 0) Resources.limits.generalSamplerIndexing = (value != 0); else if (strcmp(token, "generalVariableIndexing") == 0) Resources.limits.generalVariableIndexing = (value != 0); else if (strcmp(token, "generalConstantMatrixVectorIndexing") == 0) Resources.limits.generalConstantMatrixVectorIndexing = (value != 0); else printf("Warning: unrecognized limit (%s) in configuration file.\n", token); token = strtok(0, delims); } if (configStrings) FreeFileData(configStrings); }
// // For linking mode: Will independently parse each item in the worklist, but then put them // in the same program and link them together. // // Uses the new C++ interface instead of the old handle-based interface. // void CompileAndLinkShaders(krafix::Target target, const char* filename, const char* tempdir, const glslang::TShader::Includer& includer) { // keep track of what to free std::list<glslang::TShader*> shaders; EShMessages messages = EShMsgDefault; SetMessageOptions(messages); // // Per-shader processing... // glslang::TProgram& program = *new glslang::TProgram; glslang::TWorkItem* workItem; while (Worklist.remove(workItem)) { EShLanguage stage = FindLanguage(workItem->name); glslang::TShader* shader = new glslang::TShader(stage); shaders.push_back(shader); char** shaderStrings = ReadFileData(workItem->name.c_str()); if (! shaderStrings) { usage(); delete &program; return; } const int defaultVersion = Options & EOptionDefaultDesktop? 110: 100; shader->setStrings(shaderStrings, 1); if (Options & EOptionOutputPreprocessed) { std::string str; if (shader->preprocess(&Resources, defaultVersion, ENoProfile, false, false, messages, &str, includer)) { PutsIfNonEmpty(str.c_str()); } else { CompileFailed = true; } StderrIfNonEmpty(shader->getInfoLog()); StderrIfNonEmpty(shader->getInfoDebugLog()); FreeFileData(shaderStrings); continue; } if (! shader->parse(&Resources, defaultVersion, ENoProfile, false, false, messages, includer)) CompileFailed = true; program.addShader(shader); if (! (Options & EOptionSuppressInfolog)) { //PutsIfNonEmpty(workItem->name.c_str()); PutsIfNonEmpty(shader->getInfoLog()); PutsIfNonEmpty(shader->getInfoDebugLog()); } FreeFileData(shaderStrings); } // // Program-level processing... // if (! (Options & EOptionOutputPreprocessed) && ! program.link(messages)) LinkFailed = true; if (! (Options & EOptionSuppressInfolog)) { PutsIfNonEmpty(program.getInfoLog()); PutsIfNonEmpty(program.getInfoDebugLog()); } if (Options & EOptionDumpReflection) { program.buildReflection(); program.dumpReflection(); } if (Options & EOptionSpv) { if (CompileFailed || LinkFailed) printf("SPIRV is not generated for failed compile or link\n"); else { for (int stage = 0; stage < EShLangCount; ++stage) { if (program.getIntermediate((EShLanguage)stage)) { std::vector<unsigned int> spirv; glslang::GlslangToSpv(*program.getIntermediate((EShLanguage)stage), spirv); krafix::Translator* translator = NULL; std::map<std::string, int> attributes; switch (target.lang) { case krafix::GLSL: translator = new krafix::GlslTranslator(spirv, (EShLanguage)stage); break; case krafix::HLSL: translator = new krafix::HlslTranslator(spirv, (EShLanguage)stage); break; case krafix::Metal: translator = new krafix::MetalTranslator(spirv, (EShLanguage)stage); break; case krafix::AGAL: translator = new krafix::AgalTranslator(spirv, (EShLanguage)stage); break; case krafix::VarList: translator = new krafix::VarListTranslator(spirv, (EShLanguage)stage); break; } if (target.lang == krafix::HLSL && target.system != krafix::Unity) { std::string temp = std::string(tempdir) + "/" + removeExtension(extractFilename(workItem->name)) + ".hlsl"; translator->outputCode(target, temp.c_str(), attributes); if (target.version == 9) { compileHLSLToD3D9(temp.c_str(), filename, attributes, (EShLanguage)stage); } else { compileHLSLToD3D11(temp.c_str(), filename, attributes, (EShLanguage)stage); } } else { translator->outputCode(target, filename, attributes); } delete translator; //glslang::OutputSpv(spirv, GetBinaryName((EShLanguage)stage)); if (Options & EOptionHumanReadableSpv) { spv::Parameterize(); spv::Disassemble(std::cout, spirv); } } } } } // Free everything up, program has to go before the shaders // because it might have merged stuff from the shaders, and // the stuff from the shaders has to have its destructors called // before the pools holding the memory in the shaders is freed. delete &program; while (shaders.size() > 0) { delete shaders.back(); shaders.pop_back(); } }
bool CCommonUtils::VerifyFile(LPCTSTR lpFileName, LPVOID lpKeyData, DWORD dwKeySize, LPCTSTR lpBase64) { LPVOID lpFileData = NULL; DWORD dwFileSize = 0; bool bRet = false; HCRYPTPROV hProv = NULL; HCRYPTKEY hKey = NULL; HCRYPTHASH hHash = NULL; LPVOID lpSignature = NULL; DWORD dwSigSize = 0; try { lpFileData = ReadFileData(lpFileName, dwFileSize); if(!lpFileData) { throw _com_error(E_FAIL); } if(!CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, 0)) { throw _com_error(HRESULT_FROM_WIN32(GetLastError())); } if(!CryptImportKey(hProv, (LPBYTE)lpKeyData, dwKeySize, NULL, 0, &hKey)) { throw _com_error(HRESULT_FROM_WIN32(GetLastError())); } if(!CryptCreateHash(hProv, CALG_SHA1, 0, 0, &hHash)) { throw _com_error(HRESULT_FROM_WIN32(GetLastError())); } if(!CryptHashData(hHash, (LPBYTE)lpFileData, dwFileSize, 0)) { throw _com_error(HRESULT_FROM_WIN32(GetLastError())); } if(!CryptStringToBinary(lpBase64, 0, CRYPT_STRING_BASE64, NULL, &dwSigSize, NULL, NULL)) { throw _com_error(HRESULT_FROM_WIN32(GetLastError())); } lpSignature = malloc(dwSigSize); if(!CryptStringToBinary(lpBase64, 0, CRYPT_STRING_BASE64, (LPBYTE)lpSignature, &dwSigSize, NULL, NULL)) { throw _com_error(HRESULT_FROM_WIN32(GetLastError())); } if(!CryptVerifySignature(hHash, (LPBYTE)lpSignature, dwSigSize, hKey, NULL, 0)) { throw _com_error(HRESULT_FROM_WIN32(GetLastError())); } bRet = true; } catch(_com_error& err) { DEBUG_PRINTF(L"Error in verifying file 0x%08X\n", err.Error()); } if(hHash) { CryptDestroyHash(hHash); } if(hProv) { CryptReleaseContext(hProv, 0); } if(lpSignature) { free(lpSignature); } if(lpFileData) { free(lpFileData); } if(lpKeyData) { free(lpKeyData); } return bRet; }
INTN EFIAPI ShellAppMain ( IN UINTN Argc, IN CHAR16 **Argv ) { EFI_STATUS Status; UINTN Index; UINT32 FileSize; UINT32 BufferSize; UINT8 *FileBuffer; UINT8 *Buffer; EFI_PHYSICAL_ADDRESS Address; UINTN CountOfBlocks; EFI_TPL OldTpl; BOOLEAN ResetRequired; BOOLEAN FlashError; Index = 0; FileSize = 0; BufferSize = 0; FileBuffer = NULL; Buffer = NULL; Address = 0; CountOfBlocks = 0; ResetRequired = FALSE; FlashError = FALSE; Status = EFI_SUCCESS; mInputData.FullFlashUpdate = TRUE; // // Publish our HII data. // HiiHandle = HiiAddPackages ( &gEfiCallerIdGuid, NULL, FirmwareUpdateStrings, NULL ); if (HiiHandle == NULL) { Status = EFI_OUT_OF_RESOURCES; goto Done; } // // Locate the SPI protocol. // Status = gBS->LocateProtocol ( &gEfiSpiProtocolGuid, NULL, (VOID **)&mSpiProtocol ); if (EFI_ERROR (Status)) { PrintToken (STRING_TOKEN (STR_SPI_NOT_FOUND), HiiHandle); return EFI_DEVICE_ERROR; } // // Parse the command line. // Status = ParseCommandLine (Argc, Argv); if (EFI_ERROR (Status)) { PrintHelpInfo (); Status = EFI_SUCCESS; goto Done; } // // Display sign-on information. // PrintToken (STRING_TOKEN (STR_FWUPDATE_FIRMWARE_VOL_UPDATE), HiiHandle); PrintToken (STRING_TOKEN (STR_FWUPDATE_VERSION), HiiHandle); PrintToken (STRING_TOKEN (STR_FWUPDATE_COPYRIGHT), HiiHandle); // // Test to see if the firmware needs to be updated. // if (mInputData.UpdateFromFile) { // // Get the file to use in the update. // PrintToken (STRING_TOKEN (STR_FWUPDATE_READ_FILE), HiiHandle, mInputData.FileName); Status = ReadFileData (mInputData.FileName, &FileBuffer, &FileSize); if (EFI_ERROR (Status)) { PrintToken (STRING_TOKEN (STR_FWUPDATE_READ_FILE_ERROR), HiiHandle, mInputData.FileName); goto Done; } // // Check that the file and flash sizes match. // if (FileSize != PcdGet32 (PcdFlashChipSize)) { PrintToken (STRING_TOKEN (STR_FWUPDATE_SIZE), HiiHandle); Status = EFI_UNSUPPORTED; goto Done; } // // Display flash update information. // PrintToken (STRING_TOKEN (STR_FWUPDATE_UPDATING_FIRMWARE), HiiHandle); // // Update it. // Buffer = FileBuffer; BufferSize = FileSize; Address = PcdGet32 (PcdFlashChipBase); CountOfBlocks = (UINTN) (BufferSize / BLOCK_SIZE); // // Raise TPL to TPL_NOTIFY to block any event handler, // while still allowing RaiseTPL(TPL_NOTIFY) within // output driver during Print(). // OldTpl = gBS->RaiseTPL (TPL_NOTIFY); for (Index = 0; Index < CountOfBlocks; Index++) { // // Handle block based on address and contents. // if (!UpdateBlock (Address)) { DEBUG((EFI_D_INFO, "Skipping block at 0x%lx\n", Address)); } else if (!EFI_ERROR (InternalCompareBlock (Address, Buffer))) { DEBUG((EFI_D_INFO, "Skipping block at 0x%lx (already programmed)\n", Address)); } else { // // Display a dot for each block being updated. // Print (L"."); // // Flag that the flash image will be changed and the system must be rebooted // to use the change. // ResetRequired = TRUE; // // Make updating process uninterruptable, // so that the flash memory area is not accessed by other entities // which may interfere with the updating process. // Status = InternalEraseBlock (Address); ASSERT_EFI_ERROR(Status); if (EFI_ERROR (Status)) { gBS->RestoreTPL (OldTpl); FlashError = TRUE; goto Done; } Status = InternalWriteBlock ( Address, Buffer, (BufferSize > BLOCK_SIZE ? BLOCK_SIZE : BufferSize) ); if (EFI_ERROR (Status)) { gBS->RestoreTPL (OldTpl); FlashError = TRUE; goto Done; } } // // Move to next block to update. // Address += BLOCK_SIZE; Buffer += BLOCK_SIZE; if (BufferSize > BLOCK_SIZE) { BufferSize -= BLOCK_SIZE; } else { BufferSize = 0; } } gBS->RestoreTPL (OldTpl); // // Print result of update. // if (!FlashError) { if (ResetRequired) { Print (L"\n"); PrintToken (STRING_TOKEN (STR_FWUPDATE_UPDATE_SUCCESS), HiiHandle); } else { PrintToken (STRING_TOKEN (STR_FWUPDATE_NO_RESET), HiiHandle); } } else { goto Done; } } // // All flash updates are done so see if the system needs to be reset. // if (ResetRequired && !FlashError) { // // Update successful. // for (Index = 5; Index > 0; Index--) { PrintToken (STRING_TOKEN (STR_FWUPDATE_SHUTDOWN), HiiHandle, Index); gBS->Stall (1000000); } gRT->ResetSystem (EfiResetShutdown, EFI_SUCCESS, 0, NULL); PrintToken (STRING_TOKEN (STR_FWUPDATE_MANUAL_RESET), HiiHandle); CpuDeadLoop (); } Done: // // Print flash update failure message if error detected. // if (FlashError) { PrintToken (STRING_TOKEN (STR_FWUPDATE_UPDATE_FAILED), HiiHandle, Index); } // // Do cleanup. // if (HiiHandle != NULL) { HiiRemovePackages (HiiHandle); } if (FileBuffer) { gBS->FreePool (FileBuffer); } return Status; }
/*----------------------------------------------------------------------*/ int main(int argc,char *argv[]) { int fd,wd,x; ssize_t len,i; struct inotify_event equeue[QUEUE_LEN]; struct watch_list_t* pwatch_list = watch_list; char szCommand[BUF_LEN]; char szMessage[BUF_LEN]; char* szFile=NULL; char szBuffer[BUF_LEN]; int num_watch_files=0; int nDiff=0; char szMD5new[BUF_LEN]; int sleep_time=60; if(argc>1) { szFile=argv[1]; } else { printf("Use: %s [ini filename]\n",argv[0]); exit(-1); } #ifdef DAEMONIZE daemon(); #endif /* get the number of files to watch */ x=ReadIniArg(szFile, FILEWATCH,"num_files",szBuffer,BUF_LEN); if(x) { num_watch_files=atoi(szBuffer); } /* get the sleep time */ x=ReadIniArg(szFile, FILEWATCH,"sleep_time",szBuffer,BUF_LEN); if(x) { sleep_time=atoi(szBuffer); } sprintf(szMessage,"watching %d files every %d seconds", num_watch_files,sleep_time); locallog(szMessage); /* set up the basic paramters */ ReadFileData(szFile,num_watch_files); memset(equeue,0,sizeof(struct inotify_event)*QUEUE_LEN); fd=inotify_init(); if(fd==-1) { perror("inotify_init"); exit(EXIT_FAILURE); } /* do the work */ for(x=0;x<num_watch_files;x++) { watch_list[x].wd=inotify_add_watch(fd, watch_list[x].szFile, IN_CLOSE_WRITE); sprintf(szMessage,"watching %s",watch_list[x].szFile); locallog(szMessage); } #ifdef EVENT_QUEUE_METHOD while(1) { len = read (fd,equeue,QUEUE_LEN); i=0; while(i<len) { struct inotify_event *event = (struct inotify_event*) &equeue[i]; if(event->mask && IN_CLOSE_WRITE) { print_event(event); for(x=0;x<MAX_WATCH_FILES;x++) { if(event->wd == watch_list[x].wd) { sprintf(szMessage,"file %s closed",watch_list[x].szFile); locallog(szMessage); /* check the MD5 to see if the file changed */ MD5File(watch_list[x].szFile,szMD5new); nDiff=strcmp(watch_list[x].szMD5,szMD5new); if(nDiff) { DoFileCommand(x); strcpy(watch_list[x].szMD5,szMD5new); } } } } i++; } sleep(2); } inotify_rm_watch(fd); #endif #ifdef POLLING_METHOD while(1) { sleep(sleep_time); for(x=0;x<num_watch_files;x++) { /* check the MD5 to see if the file changed */ MD5File(watch_list[x].szFile,szMD5new); nDiff=strcmp(watch_list[x].szMD5,szMD5new); if(nDiff) { DoFileCommand(x); strcpy(watch_list[x].szMD5,szMD5new); sprintf(szMessage,"file %s new MD5: %s", watch_list[x].szFile, watch_list[x].szMD5); locallog(szMessage); } } } #endif }
bool XConfig::Open(CTSTR lpFile) { if(RootElement) { if(strFileName.CompareI(lpFile)) return true; Close(); } //------------------------------------- XFile file; if(!file.Open(lpFile, XFILE_READ, XFILE_OPENALWAYS)) return false; RootElement = new XElement(this, NULL, TEXT("Root")); strFileName = lpFile; DWORD dwFileSize = (DWORD)file.GetFileSize(); LPSTR lpFileDataUTF8 = (LPSTR)Allocate(dwFileSize+1); zero(lpFileDataUTF8, dwFileSize+1); file.Read(lpFileDataUTF8, dwFileSize); TSTR lpFileData = utf8_createTstr(lpFileDataUTF8); Free(lpFileDataUTF8); //------------------------------------- // remove comments TSTR lpComment, lpEndComment; while(lpComment = sstr(lpFileData, TEXT("/*"))) { lpEndComment = sstr(lpFileData, TEXT("*/")); assert(lpEndComment); assert(lpComment < lpEndComment); if(!lpEndComment || (lpComment > lpEndComment)) { file.Close(); Close(false); Free(lpFileData); CrashError(TEXT("Error parsing X file '%s'"), strFileName.Array()); } mcpy(lpComment, lpEndComment+3, slen(lpEndComment+3)+1); } //------------------------------------- TSTR lpTemp = lpFileData; if(!ReadFileData(RootElement, 0, lpTemp)) { for(DWORD i=0; i<RootElement->SubItems.Num(); i++) delete RootElement->SubItems[i]; CrashError(TEXT("Error parsing X file '%s'"), strFileName.Array()); Free(lpFileData); Close(false); file.Close(); } Free(lpFileData); file.Close(); return true; }
int IRLOG_GetNextRecord(IRLOG_IOStruct *pInput) { int num_valid, num_read; pInput->pCurHeader = pInput->pNextHeader; if (pInput->pEnd - pInput->pCurHeader < sizeof(RLOG_HEADER)) { num_valid = (int)(pInput->pEnd - pInput->pCurHeader); if (pInput->pCurHeader != pInput->buffer) memcpy(pInput->buffer, pInput->pCurHeader, num_valid); ReadFileData(pInput->buffer + num_valid, sizeof(RLOG_HEADER) - num_valid, pInput->f); pInput->pCurHeader = pInput->buffer; pInput->pNextHeader = pInput->buffer; pInput->pEnd = pInput->buffer + sizeof(RLOG_HEADER); } /* copy the current header into a temporary variable so the bytes can be manipulated */ memcpy(&pInput->header, pInput->pCurHeader, sizeof(RLOG_HEADER)); /* CLOGByteSwapDouble(&(header.timestamp), 1); CLOGByteSwapInt(&(header.rectype), 1); CLOGByteSwapInt(&(header.length), 1); */ while (pInput->pCurHeader + pInput->header.length > pInput->pEnd) { num_valid = (int)(pInput->pEnd - pInput->pCurHeader); if (pInput->pCurHeader != pInput->buffer) memcpy(pInput->buffer, pInput->pCurHeader, num_valid); num_read = (int)fread(pInput->buffer + num_valid, 1, RLOG_BUFFSIZE - num_valid, pInput->f); if (num_read == 0) { MPIU_Error_printf("RLOG Error: unable to get the next record.\n"); return 1; } pInput->pEnd = pInput->buffer + num_valid + num_read; pInput->pCurHeader = pInput->buffer; } pInput->pNextHeader = pInput->pCurHeader + pInput->header.length; switch (pInput->header.type) { case RLOG_INVALID_TYPE: MPIU_Error_printf("RLOG Error: invalid record type.\n"); return 1; break; case RLOG_ENDLOG_TYPE: return 1; break; case RLOG_EVENT_TYPE: memcpy(&pInput->record.event, pInput->pCurHeader + sizeof(RLOG_HEADER), sizeof(RLOG_EVENT)); break; case RLOG_IARROW_TYPE: memcpy(&pInput->record.iarrow, pInput->pCurHeader + sizeof(RLOG_HEADER), sizeof(RLOG_IARROW)); break; case RLOG_STATE_TYPE: memcpy(&pInput->record.state, pInput->pCurHeader + sizeof(RLOG_HEADER), sizeof(RLOG_STATE)); break; case RLOG_COMM_TYPE: memcpy(&pInput->record.comm, pInput->pCurHeader + sizeof(RLOG_HEADER), sizeof(RLOG_COMM)); break; default: MPIU_Error_printf("RLOG Error: unknown record type %d.\n", pInput->header.type); return 1; break; } return 0; }
bool CMyAPEInfo::ReadMetaData(CSongMetaData & MetaData) const { return ReadFileData(MetaData) && ReadTagData(MetaData); }