int main(void) { uint32_t nextBlink; uint32_t blinkState = 0; init(); // Disable line buffering on stdout setbuf(stdout, NULL); nextBlink = tickMs + BLINK_DELAY_MS; for(;;) { consoleProcess(); targetProcess(); if(tickMs > nextBlink) { nextBlink = tickMs + BLINK_DELAY_MS; if(blinkState) { GPIO_SetBits(GPIOD, GPIO_Pin_12); } else { GPIO_ResetBits(GPIOD, GPIO_Pin_12); } blinkState ^= 1; } __WFI(); } return 0; }
bool DuplicateHandle(HANDLE aSourceHandle, DWORD aTargetProcessId, HANDLE* aTargetHandle, DWORD aDesiredAccess, DWORD aOptions) { // If our process is the target just duplicate the handle. if (aTargetProcessId == base::GetCurrentProcId()) { return !!::DuplicateHandle(::GetCurrentProcess(), aSourceHandle, ::GetCurrentProcess(), aTargetHandle, aDesiredAccess, false, aOptions); } #if defined(MOZ_SANDBOX) // Try the broker next (will fail if not sandboxed). if (SandboxTarget::Instance()->BrokerDuplicateHandle(aSourceHandle, aTargetProcessId, aTargetHandle, aDesiredAccess, aOptions)) { return true; } #endif // Finally, see if we already have access to the process. ScopedProcessHandle targetProcess(OpenProcess(PROCESS_DUP_HANDLE, FALSE, aTargetProcessId)); if (!targetProcess) { #ifdef MOZ_CRASHREPORTER CrashReporter::AnnotateCrashReport( NS_LITERAL_CSTRING("IPCTransportFailureReason"), NS_LITERAL_CSTRING("Failed to open target process.")); #endif return false; } return !!::DuplicateHandle(::GetCurrentProcess(), aSourceHandle, targetProcess, aTargetHandle, aDesiredAccess, FALSE, aOptions); }