/** * @brief Reads the current state of a gpio pin. * @param gpioNumber The number of the GPIO pin to read. * @param[out] state Pointer to the variable in which the GPIO pin state is * returned. * @return An error from #errStatus. */ errStatus gpioReadPin(int gpioNumber, eState * state) { errStatus rtn = ERROR_DEFAULT; if (gGpioMap == NULL) { dbgPrint(DBG_INFO, "gGpioMap was NULL. Ensure gpioSetup() was called successfully."); rtn = ERROR_NULL; } else if ((rtn = gpioValidatePin(gpioNumber)) != OK) { dbgPrint(DBG_INFO, "gpioValidatePin() failed. Pin %d isn't valid.", gpioNumber); } else { /* Check if the appropriate bit is high */ if (GPIO_GPLEV0 & (0x1 << gpioNumber)) { *state = high; } else { *state = low; } rtn = OK; } return rtn; }
/* * ::openEvents */ BOOL openEvents(HANDLE *outEvtDebugee, HANDLE *outEvtDebugger) { #define EVENT_NAME_LEN (32) #define SHMEM_NAME_LEN (64) wchar_t eventName[EVENT_NAME_LEN]; DWORD processId = 0; /* Sanity checks. */ if ((outEvtDebugee == NULL) || (outEvtDebugger == NULL)) { return TRUE; } /* TODO: Possible hazard when using multiple instances simultanously. */ processId = GetCurrentProcessId(); _snwprintf(eventName, EVENT_NAME_LEN, L"%udbgee", processId); if ((*outEvtDebugee = OpenEventW(EVENT_ALL_ACCESS, FALSE, eventName)) == NULL) { dbgPrint(DBGLVL_ERROR, "OpenEvent(\"%s\") failed: %u.\n", eventName, GetLastError()); return FALSE; } _snwprintf(eventName, EVENT_NAME_LEN, L"%udbgr", processId); if ((*outEvtDebugger = OpenEventW(EVENT_ALL_ACCESS, FALSE, eventName)) == NULL) { dbgPrint(DBGLVL_ERROR, "OpenEvent(\"%s\") failed: %u.\n", eventName, GetLastError()); return FALSE; } return TRUE; #undef EVENT_NAME_LEN }
static void getUnusedNameByPrefix(char **name, ShVariableList *vl, const char *prefix) { if (!(findFirstShVariableFromName(vl, prefix))) { /* name is free to use */ if (!(*name = (char*) malloc(strlen(prefix) + 1))) { dbgPrint(DBGLVL_ERROR, "CodeInsertion - not enough memory for result name\n"); exit(1); } strcpy(*name, prefix); } else { /* add randomized post-fix to name until its free */ if (!(*name = (char*) malloc( strlen(prefix) + 1 + CG_RANDOMIZED_POSTFIX_SIZE))) { dbgPrint(DBGLVL_ERROR, "CodeInsertion - not enough memory for result name\n"); exit(1); } strcpy(*name, prefix); while (findFirstShVariableFromName(vl, *name)) { char ran; int i; (*name)[strlen(prefix)] = '\0'; for (i = 0; i < CG_RANDOMIZED_POSTFIX_SIZE; i++) { ran = (char) ((rand() / (float) RAND_MAX) * ('Z' - 'A') + 'A'); strncat(*name, &ran, 1); } } } }
/** * @brief Sets the functionality of the desired pin. * @param gpioNumber The gpio pin number to change. * @param function The desired functionality for the pin. * @return An error from #errStatus. */ errStatus gpioSetFunction(int gpioNumber, eFunction function) { errStatus rtn = ERROR_DEFAULT; if (gGpioMap == NULL) { dbgPrint(DBG_INFO, "gGpioMap was NULL. Ensure gpioSetup() called successfully."); rtn = ERROR_NULL; } else if (function < eFunctionMin || function > eFunctionMax) { dbgPrint(DBG_INFO, "eFunction was out of range. %d", function); rtn = ERROR_RANGE; } else if ((rtn = gpioValidatePin(gpioNumber)) != OK) { dbgPrint(DBG_INFO, "gpioValidatePin() failed. Ensure pin %d is valid.", gpioNumber); } else { /* Clear what ever function bits currently exist - this puts the pin * into input mode.*/ *(gGpioMap + (gpioNumber / 10)) &= ~(GPFSEL_BITS << ((gpioNumber % 10) * 3)); /* Set the three pins for the pin to the desired value */ *(gGpioMap + (gpioNumber / 10)) |= (function << ((gpioNumber % 10) * 3)); rtn = OK; } return rtn; }
/* * ::openSharedMemory */ BOOL openSharedMemory(HANDLE *outShMem, void **outBaseAddr, const int size) { #define SHMEM_NAME_LEN (64) char shMemName[SHMEM_NAME_LEN]; if (!GetEnvironmentVariableA("GLSL_DEBUGGER_SHMID", shMemName, SHMEM_NAME_LEN)) { dbgPrint(DBGLVL_ERROR, "Oh Shit! No Shmid! Set GLSL_DEBUGGER_SHMID.\n"); return FALSE; } /* This creates a non-inheritable shared memory mapping! */ *outShMem = OpenFileMappingA(FILE_MAP_WRITE, FALSE, shMemName); if ((*outShMem == NULL) || (*outShMem == INVALID_HANDLE_VALUE)) { dbgPrint(DBGLVL_ERROR, "Opening of shared mem segment \"%s\" failed: %u.\n", shMemName, GetLastError()); return FALSE; } /* FILE_MAP_WRITE implies read */ *outBaseAddr = MapViewOfFile(*outShMem, FILE_MAP_WRITE, 0, 0, size); if (*outBaseAddr == NULL) { dbgPrint(DBGLVL_ERROR, "View mapping of shared mem segment \"%s\" failed: %u.\n", shMemName, GetLastError()); CloseHandle(*outShMem); return FALSE; } return TRUE; #undef SHMEM_NAME_LEN }
bool isChildofMain(TIntermNode *node, TIntermNode *root) { TIntermNode *main = getFunctionBySignature(MAIN_FUNC_SIGNATURE, root); if (!main) { dbgPrint(DBGLVL_ERROR, "CodeTools - could not find main function\n"); exit(1); } TIntermAggregate *aggregate; if (!(aggregate = main->getAsAggregate())) { dbgPrint(DBGLVL_ERROR, "CodeTools - main is not Aggregate\n"); exit(1); } TIntermSequence sequence = aggregate->getSequence(); TIntermSequence::iterator sit; for(sit = sequence.begin(); sit != sequence.end(); sit++) { if (*sit == node) { return true; } } return false; }
TType* getTypeDebugParameter(TIntermAggregate *node, int pnum) { TType *result = NULL; if (!node) return result; if (node->getOp() != EOpFunctionCall) return result; TIntermSequence funcCallSeq = node->getSequence(); if ((int) funcCallSeq.size() < pnum) { dbgPrint(DBGLVL_ERROR, "CodeTools - function does not have this much parameter\n"); exit(1); } if (!funcCallSeq[pnum]->getAsTyped()) { dbgPrint(DBGLVL_ERROR, "CodeTools - in parameter is not of type TIntermTyped\n"); exit(1); } return funcCallSeq[pnum]->getAsTyped()->getTypePointer(); }
static void dumpAstChangeableList(exec_list *cl) { if (!cl) return; dbgPrint(DBGLVL_INFO, "===> "); if (cl->is_empty()) dbgPrint(DBGLVL_INFO, "empty"); foreach_in_list(changeable_item, item, cl) { dumpShChangeable(item->changeable); }
void ShVarItem::setCurrentPointer(VertexBox *vb) { if (vb) { dbgPrint(DBGLVL_DEBUG, "setCurrentPointer: VertexBox %p numVertices=%i data=%p\n", vb, vb->getNumVertices(), vb->getDataPointer()); } else { dbgPrint(DBGLVL_DEBUG, "setCurrentPointer: NULL\n"); } setData(DF_DATA_CURRENTBOX, QVariant::fromValue<void*>((void*) vb)); }
void ShVarItem::setPixelBoxPointer(PixelBox *fb) { if (fb) { dbgPrint(DBGLVL_DEBUG, "setPixelBoxPointer: PixelBox %p w=%i h=%i dmap=%p coverage=%p\n", fb, fb->getWidth(), fb->getHeight(), fb->getDataMapPointer(), fb->getCoveragePointer()); } else { dbgPrint(DBGLVL_DEBUG, "setPixelBoxPointer: NULL\n"); } setData(DF_DATA_PIXELBOX, QVariant::fromValue<void*>((void*) fb)); }
/** * Free the library designated by 'hRemoteModule' in process 'hProcess'. */ static bool RemoteFreeLibrary(HANDLE hProcess, HANDLE hRemoteModule) { bool retval = false; // Result of overall operation. DWORD exitCode = 0; // Exit code of remote thread. HANDLE hThread = NULL; // Handle to remote thread. HMODULE hKernel32 = NULL; // Module handle of kernel32.dll. FARPROC freeLibrary = NULL; // Function pointer of LoadLibrary. /* Sanity checks. */ if (hProcess == NULL) { goto cleanup; } if (hRemoteModule == NULL) { goto cleanup; } /* Get Function pointer to LoadLibrary. */ if ((hKernel32 = ::GetModuleHandleA("kernel32")) == NULL) { dbgPrint(DBGLVL_ERROR, "Module handle of \"kernel32\" could not be retrieved: " "%u.\n", ::GetLastError()); goto cleanup; } if ((freeLibrary = ::GetProcAddress(hKernel32, "FreeLibrary")) == NULL) { dbgPrint(DBGLVL_ERROR, "\"FreeLibrary\" could not be found: %u.\n", ::GetLastError()); goto cleanup; } /* Unload the debug library from the remote process. */ if ((hThread = ::CreateRemoteThread(hProcess, NULL, 0, reinterpret_cast<LPTHREAD_START_ROUTINE>(freeLibrary), reinterpret_cast<void *>(hRemoteModule), 0, NULL)) == NULL) { goto cleanup; } /* Wait for FreeLibrary to complete. */ if (::WaitForSingleObject(hThread, INFINITE) != WAIT_OBJECT_0) { dbgPrint(DBGLVL_ERROR, "WaitForSingleObject failed: %u.\n", ::GetLastError()); goto cleanup; } /* Get exit code, which is the result of remote FreeLibrary. */ if (!::GetExitCodeThread(hThread, &exitCode)) { dbgPrint(DBGLVL_ERROR, "GetExitCodeThread failed: %u.\n", ::GetLastError()); goto cleanup; } retval = (exitCode != 0); /* Clean up. */ cleanup: if (hThread != NULL) { ::CloseHandle(hThread); } return retval; }
PixelBox* ShVarItem::getPixelBoxPointer(void) { QVariant v = data(DF_DATA_PIXELBOX); if (v.value<void*>() == NULL) { dbgPrint(DBGLVL_DEBUG, "getPixelBoxPointer: PixelBox not set\n"); return NULL; } else { dbgPrint(DBGLVL_DEBUG, "getPixelBoxPointer: PixelBox %p\n", v.value<void*>()); return (PixelBox*) v.value<void*>(); } }
/** * @brief Disables the I2C controller and unmaps the memory used for the * i2c functionality. This function should be called when finished * with the I2C module. * @return An error from #errStatus. */ errStatus gpioI2cCleanup(void) { errStatus rtn = ERROR_DEFAULT; int sda; int scl; if (gI2cMap == NULL) { dbgPrint(DBG_INFO, "gI2cMap was NULL. Ensure gpioI2cSetup() was called successfully."); rtn = ERROR_NOT_INITIALISED; } else if ((rtn = gpioGetI2cPins(&scl, &sda)) != OK) { dbgPrint(DBG_INFO, "gpioGetI2cPins() failed. %s", gpioErrToString(rtn)); } /* Set SDA pin to input */ else if ((rtn = gpioSetFunction(sda, input)) != OK) { dbgPrint(DBG_INFO, "gpioSetFunction() failed for SDA. %s", gpioErrToString(rtn)); } /* Set SCL pin to input */ else if ((rtn = gpioSetFunction(scl, input)) != OK) { dbgPrint(DBG_INFO, "gpioSetFunction() failed for SCL. %s", gpioErrToString(rtn)); } else { /* Disable the BSC Controller */ I2C_C &= ~BSC_I2CEN; /* Unmap the memory */ if (munmap((void *)gI2cMap, I2C_MAP_SIZE) != OK) { dbgPrint(DBG_INFO, "mummap() failed. errno: %s.", strerror(errno)); rtn = ERROR_EXTERNAL; } else { gI2cMap = NULL; rtn = OK; } } return rtn; }
/* TODO: error checking */ static int attachShaderObject(GLint programHandle, GLenum type, const char *src) { GLint shader, status; int error; dbgPrint(DBGLVL_COMPILERINFO, "ATTACH SHADER: %s\n-----------------\n%s\n--------------\n", lookupEnum(type), src); shader = ORIG_GL(glCreateShader)(type); error = glError(); if (error) { return error; } ORIG_GL(glShaderSource)(shader, 1, (void*)&src, NULL); error = glError(); if (error) { return error; } ORIG_GL(glCompileShader)(shader); error = glError(); if (error) { return error; } ORIG_GL(glGetShaderiv)(shader, GL_COMPILE_STATUS, &status); error = glError(); if (error) { return error; } printShaderInfoLog(shader); error = glError(); if (error) { return error; } if (!status) { dbgPrint(DBGLVL_ERROR, "DBG SHADER COMPILATION for %s failed!\n", lookupEnum(type)); return DBG_ERROR_DBG_SHADER_COMPILE_FAILED; } ORIG_GL(glAttachShader)(programHandle, shader); error = glError(); if (error) { return error; } ORIG_GL(glDeleteShader)(shader); error = glError(); if (error) { return error; } return DBG_NO_ERROR; }
void ProgramControl::closeEvents(void) { dbgPrint(DBGLVL_INFO, "Closing events ...\n"); if (_hEvtDebugger != NULL) { ::CloseHandle(_hEvtDebugger); _hEvtDebugger = NULL; } if (_hEvtDebuggee != NULL) { ::CloseHandle(_hEvtDebuggee); _hEvtDebuggee = NULL; } dbgPrint(DBGLVL_INFO, "Events closed.\n"); }
PPClsPack* PPAppReceiver::proxy_hello(PPClsPack& args) { dbgPrint(0, "calling proxyhello"); int* iArg = (int*)args(0).getData(); dbgPrint(0, "data=%d", *iArg); dumpCharArray((char*)iArg); dumpCharArray(args(0).getData()); *iArg *= -1; PPClsPack argRet(1); argRet(0) <<= PPFunPack(4, (char*)iArg); sendFn(argRet); dbgPrint(0, "proxyhello ended"); }
static unsigned long __stdcall _thread(void* _args) { SYSTEMTIME st = {0}; while (1) { if (g_isQuit) break; GetLocalTime(&st); dbgPrint("Now time is : %.2d:%.2d:%.2d:%.3d", st.wHour, st.wMinute, st.wSecond, st.wMilliseconds); Sleep(100); } g_isQuit = 0; dbgPrint("the thread quit in safe way ..."); return 0L; }
/* TODO: error checking */ static void printProgramInfoLog(GLhandleARB shader) { int length; GLcharARB *log; ORIG_GL(glGetProgramiv)(shader, GL_INFO_LOG_LENGTH, &length); if (length > 1) { if (!(log = (GLcharARB*)malloc(length*sizeof(GLcharARB)))) { dbgPrint(DBGLVL_ERROR, "Allocation of mem for GLSL info log failed\n"); exit(1); } ORIG_GL(glGetProgramInfoLog)(shader, length, NULL, log); dbgPrint(DBGLVL_INFO, "PROGRAM INFOLOG:\n%s\n", log); free(log); } }
bool PixelBox::isAllDataAvailable() { int x, y; bool *pDataMap; bool *pCoverage; if (!m_pDataMap) { return false; } pDataMap = m_pDataMap; pCoverage = m_pCoverage; for (y = 0; y < m_nHeight; y++) { for (x = 0; x < m_nWidth; x++) { if (*pCoverage && !*pDataMap) { dbgPrint(DBGLVL_INFO, "NOT ALL DATA AVILABLE, NEED READBACK =========================\n"); return false; } pDataMap++; pCoverage++; } } return true; }
/* Copy appropriate bytes out of the buffer. */ memcpy (dst, (char*)buffer + ((ALIGNED_DATA)src & (sizeof(ALIGNED_DATA) - 1)), size); free(buffer); } #endif /* _WIN32 */ #ifdef _WIN32 void cpyToProcess(DWORD pid, void *dst, void *src, size_t size) { SIZE_T numBytesWritten; HANDLE procHandle = OpenProcess(PROCESS_VM_WRITE | PROCESS_VM_OPERATION, FALSE, pid); if (procHandle == NULL) { dbgPrint(DBGLVL_ERROR, "cpyToProcess: could not open process %u\n", procHandle); exit(1); } if (WriteProcessMemory(procHandle, dst, src, size, &numBytesWritten) == 0) { dbgPrint(DBGLVL_ERROR, "cpyToProcess: copying failed: %u\n", GetLastError()); CloseHandle(procHandle); exit(1); } if (numBytesWritten != size) { dbgPrint(DBGLVL_ERROR, "cpyToProcess: could copy only %u out of %u bytes.\n", numBytesWritten, size); CloseHandle(procHandle); exit(1); } CloseHandle(procHandle); } #else /* _WIN32 */ void cpyToProcess(pid_t pid, void *dst, void *src, size_t size) { ALIGNED_DATA start, *buffer; size_t count; int i; /* Round starting address down to word boundary */ start = (ALIGNED_DATA)dst & -(ALIGNED_DATA)sizeof(ALIGNED_DATA); /* number of words to copy */ count = ((((ALIGNED_DATA)dst + size) - start) + sizeof(ALIGNED_DATA) - 1)/sizeof(ALIGNED_DATA); buffer = (ALIGNED_DATA*)malloc(count*sizeof(ALIGNED_DATA)); if (!buffer) { dbgPrint(DBGLVL_ERROR, "cpyFromProcess: Could not allocate buffer\n"); exit(1); } /* fill extra bytes at start and end of buffer with existing data */ buffer[0] = ptrace(PTRACE_PEEKTEXT, pid, (void*)start, 0); if (count > 1) { buffer[count - 1] = ptrace(PTRACE_PEEKTEXT, pid, (void*)(start + (count - 1)*sizeof(ALIGNED_DATA)), 0); } /* copy data */ memcpy ((char*)buffer + ((ALIGNED_DATA)dst & (sizeof(ALIGNED_DATA) - 1)), src, size); /* write buffer */ for (i = 0; i < count; i++) { ptrace(PTRACE_POKETEXT, pid, (void*)start, buffer[i]); start += sizeof(ALIGNED_DATA); } free(buffer); }
int getFunctionDebugParameter(TIntermAggregate *node) { int result = -1; int i; if (!node) return result; if ( node->getOp() != EOpFunction) { return result; } TIntermSequence funcDeclSeq = node->getSequence(); if (!funcDeclSeq[0] || !funcDeclSeq[0]->getAsAggregate() || !(funcDeclSeq[0]->getAsAggregate()->getOp() == EOpParameters)) { dbgPrint(DBGLVL_ERROR, "CodeTools - function does not comply with assumptions\n"); exit(1); } TIntermSequence funcDeclParamSeq = (funcDeclSeq[0]->getAsAggregate())->getSequence(); TIntermSequence::iterator pD = funcDeclParamSeq.begin(); for (i=0; pD != funcDeclParamSeq.end(); ++pD, ++i) { if ((*pD)->getAsFuncParamNode()->getType().getQualifier() == EvqIn) { result = i; } } return result; }
/* works at least for Linux on x86 architecture and for windows*/ #ifndef _WIN32 typedef intptr_t ALIGNED_DATA; #else /* _WIN32 */ typedef INT_PTR ALIGNED_DATA; #endif /* _WIN32 */ #ifdef _WIN32 void cpyFromProcess(DWORD pid, void *dst, void *src, size_t size) { SIZE_T numBytesRead; HANDLE procHandle = OpenProcess(PROCESS_VM_READ, FALSE, pid); if (procHandle == NULL) { dbgPrint(DBGLVL_ERROR, "cpyFromProcess: could not open process %u\n", procHandle); exit(1); } if (ReadProcessMemory(procHandle, src, dst, size, &numBytesRead) == 0) { dbgPrint(DBGLVL_ERROR, "cpyFromProcess: copying failed: %u\n", GetLastError()); CloseHandle(procHandle); exit(1); } if (numBytesRead != size) { dbgPrint(DBGLVL_ERROR, "cpyFromProcess: could copy only %u out of %u bytes.\n", numBytesRead, size); CloseHandle(procHandle); exit(1); } CloseHandle(procHandle); } #else /* _WIN32 */ void cpyFromProcess(pid_t pid, void *dst, void *src, size_t size) { ALIGNED_DATA start, *buffer; size_t count; int i; /* Round starting address down to word boundary */ start = (ALIGNED_DATA)src & -(ALIGNED_DATA)sizeof(ALIGNED_DATA); /* number of words to copy */ count = ((((ALIGNED_DATA)src + size) - start) + sizeof(ALIGNED_DATA) - 1)/sizeof(ALIGNED_DATA); buffer = (ALIGNED_DATA*)malloc(count*sizeof(ALIGNED_DATA)); if (!buffer) { dbgPrint(DBGLVL_ERROR, "cpyFromProcess: Could not allocate buffer\n"); exit(1); } /* read data from other process, word by word :-( */ for (i = 0; i < count; i++, start += sizeof(ALIGNED_DATA)) { buffer[i] = ptrace(PTRACE_PEEKTEXT, pid, (void*)start, 0); } /* Copy appropriate bytes out of the buffer. */ memcpy (dst, (char*)buffer + ((ALIGNED_DATA)src & (sizeof(ALIGNED_DATA) - 1)), size); free(buffer); }
static void getNewUnusedName(cgTypes type, char **name, ShVariableList *vl, EShLanguage l) { switch (type) { case CG_TYPE_RESULT: switch (l) { case EShLangVertex: case EShLangGeometry: if (!(*name = (char*) malloc(strlen(CG_RESULT_PREFIX) + 1))) { dbgPrint(DBGLVL_ERROR, "CodeInsertion - not enough memory for result name\n"); exit(1); } strcpy(*name, CG_RESULT_PREFIX); break; case EShLangFragment: getUnusedNameByPrefix(name, vl, CG_RESULT_PREFIX); break; default: break; } break; case CG_TYPE_CONDITION: getUnusedNameByPrefix(name, vl, CG_CONDITION_PREFIX); break; case CG_TYPE_PARAMETER: getUnusedNameByPrefix(name, vl, CG_PARAMETER_PREFIX); break; default: break; } }
/* * Process the results of a call to select(). <r> is select's return value, <rfds> and <wfds> * contain the file descriptors that select has marked as readable or writable and <nfds> is the * maximum number of file descriptors that may be set in <rfds> or <wfds>. */ void disProcessSelect(Dispatcher *dis, int r, int nfds, fd_set *rfds, fd_set *wfds) { P dbgPrint(stderr, "r = %d, nfds = %d.\n", r, nfds); P dumpfds(stderr, "\trfds:", nfds, rfds); P dumpfds(stderr, "\twfds:", nfds, wfds); if (r == 0) { P dbgPrint(stderr, "Timeout, calling disHandleTimer.\n"); disHandleTimer(dis); } else if (r > 0) { P dbgPrint(stderr, "Data available, calling disHandleFiles.\n"); disHandleFiles(dis, nfds, rfds, wfds); } }
static int shaderBaseTypeSize(GLenum t) { switch (t) { case GL_INT: return sizeof(GLint); case GL_UNSIGNED_INT: return sizeof(GLuint); case GL_BOOL: return sizeof(GLboolean); case GL_FLOAT: return sizeof(GLfloat); case GL_DOUBLE: return sizeof(GLdouble); case GL_BYTE: return sizeof(GLbyte); case GL_UNSIGNED_BYTE: return sizeof(GLubyte); case GL_SHORT: return sizeof(GLshort); case GL_UNSIGNED_SHORT: return sizeof(GLushort); default: dbgPrint(DBGLVL_ERROR, "HMM, unkown shader variable type: %i\n", t); return 0; } }
static void task(void * a) { uint8_t buf; while (1) { xQueueReceive(xQueue1,&buf,portMAX_DELAY); if(buf==0) { dbgPrint("BOTON IRQ 0 \n"); } else { dbgPrint("BOTON IRQ 1 \n"); } } }
/** * Suspend all threads of a remote process. */ bool RemoteSuspendAllThreads(HANDLE hProcess) { HANDLE hSnapshot = NULL; // Snapshot of all process threads. HANDLE hThread = NULL; // Handle to thread to suspend. THREADENTRY32 te; // Entry of a thread. /* Sanity checks. */ if (hProcess == NULL) { return false; } if ((hSnapshot = ::CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, ::GetProcessId(hProcess))) == INVALID_HANDLE_VALUE) { dbgPrint(DBGLVL_ERROR, "CreateToolhelp32Snapshot failed: %u.\n", ::GetLastError()); return false; } te.dwSize = sizeof(te); if (!::Thread32First(hSnapshot, &te)) { dbgPrint(DBGLVL_ERROR, "Thread32First failed: %u.\n", ::GetLastError()); ::CloseHandle(hSnapshot); return false; } do { if ((hThread = ::OpenThread(THREAD_SUSPEND_RESUME, FALSE, te.th32ThreadID)) == NULL) { dbgPrint(DBGLVL_ERROR, "OpenThread failed: %u.\n", ::GetLastError()); ::CloseHandle(hSnapshot); ::RemoteResumeAllThreads(hProcess); return false; } if (::SuspendThread(hThread) == -1) { dbgPrint(DBGLVL_ERROR, "SuspendThread failed: %u.\n", ::GetLastError()); ::CloseHandle(hThread); ::CloseHandle(hSnapshot); ::RemoteResumeAllThreads(hProcess); return false; } ::CloseHandle(hThread); } while (Thread32Next(hSnapshot, &te)); ::CloseHandle(hSnapshot); return true; }
void ProgramControl::freeShmem(void) { if (_fcalls != NULL) { if (!UnmapViewOfFile(_fcalls)) { dbgPrint(DBGLVL_ERROR, "View unmapping of shared mem segment failed: %u\n", GetLastError()); exit(1); } _fcalls = NULL; } if (_hShMem != INVALID_HANDLE_VALUE && _hShMem != NULL) { if (CloseHandle(_hShMem) == 0) { dbgPrint(DBGLVL_ERROR, "Closing handle of shared mem segment failed: %u\n", GetLastError()); exit(1); } _hShMem = INVALID_HANDLE_VALUE; } }
static void _cl_test_dbg_multi(void) { HANDLE h = CreateThread(NULL, 0, _thread, NULL, 0, NULL); if (NULL != h) { dbgPrint("Create the _thread success ..."); } else { dbgPrint("Create the _thread failed ..."); } if (NULL != h) { CloseHandle(h); h = NULL; } Sleep(2000); g_isQuit = 1; while (g_isQuit) Sleep(10); }
void APIENTRY glEnd(void) { #if 0 /* HAZARD maximally dangerous. this relies upon the fact that the debuglib is already loaded (sure, this here lib is loaded by it) to grab the correct address of the opengl32.dll glEnd. We do this because the contents of OrigglEnd are, as a matter of fact, f****d in the head and we end up in a totally wrong memory segment. This might have to do something with improper relocation of all the library goo, but we do not know. yet. */ HANDLE lib = LoadLibraryA("debuglib.dll"); dbgPrint(DBGLVL_DEBUG, "using special glEnd: 0x%x\n", OrigglEnd); dbgPrint(DBGLVL_DEBUG, "origglend = 0x%x\n", *((GetProcAddress(lib, "OrigglEnd")))); (*((GetProcAddress(lib, "OrigglEnd"))))(); (*((GetProcAddress(lib, "OrigglGetError"))))(); FreeLibrary(lib); #endif ORIG_GL(glEnd)(); setErrorCode(ORIG_GL(glGetError)()); }