Skip to content

Instantly share code, notes, and snippets.

View bionicbeagle's full-sized avatar

Stefan Boberg bionicbeagle

View GitHub Profile
@bionicbeagle
bionicbeagle / cpu_api.patch
Created November 30, 2022 21:07
nng 1.5.2 patch to enable runtime configuration of thread pools
diff --git a/include/nng/nng.h b/include/nng/nng.h
index cd75495a..1c6b7a61 100644
--- a/include/nng/nng.h
+++ b/include/nng/nng.h
@@ -1179,6 +1179,11 @@ NNG_DECL int nng_stream_listener_set_ptr(
NNG_DECL int nng_stream_listener_set_addr(
nng_stream_listener *, const char *, const nng_sockaddr *);
+#define NNG_CAN_LIMIT_THREADS
+NNG_DECL void nng_set_ncpu_max(int);
@bionicbeagle
bionicbeagle / QueryPerformanceCounter_1903.disasm
Created June 13, 2019 06:29
QueryPerformanceCounter from Windows 10 v1903
00007FFE496CBBB0 mov qword ptr [rsp+8],rbx
00007FFE496CBBB5 push rdi
00007FFE496CBBB6 sub rsp,20h
00007FFE496CBBBA mov r8b,byte ptr [7FFE03C6h]
00007FFE496CBBC2 mov rbx,rcx
00007FFE496CBBC5 test r8b,1
00007FFE496CBBC9 je 00007FFE496CBC3B
00007FFE496CBBCB mov r11,qword ptr [7FFE03B8h]
00007FFE496CBBD3 test r8b,2
00007FFE496CBBD7 je 00007FFE497698FF
@bionicbeagle
bionicbeagle / QueryPerformanceCounter_1903.disasm
Created June 13, 2019 06:29
QueryPerformanceCounter from Windows 10 v1903
00007FFE496CBBB0 mov qword ptr [rsp+8],rbx
00007FFE496CBBB5 push rdi
00007FFE496CBBB6 sub rsp,20h
00007FFE496CBBBA mov r8b,byte ptr [7FFE03C6h]
00007FFE496CBBC2 mov rbx,rcx
00007FFE496CBBC5 test r8b,1
00007FFE496CBBC9 je 00007FFE496CBC3B
00007FFE496CBBCB mov r11,qword ptr [7FFE03B8h]
00007FFE496CBBD3 test r8b,2
00007FFE496CBBD7 je 00007FFE497698FF
@bionicbeagle
bionicbeagle / QueryPerformanceCounter_1903.disasm
Created June 13, 2019 06:29
QueryPerformanceCounter from Windows 10 v1903
00007FFE496CBBB0 mov qword ptr [rsp+8],rbx
00007FFE496CBBB5 push rdi
00007FFE496CBBB6 sub rsp,20h
00007FFE496CBBBA mov r8b,byte ptr [7FFE03C6h]
00007FFE496CBBC2 mov rbx,rcx
00007FFE496CBBC5 test r8b,1
00007FFE496CBBC9 je 00007FFE496CBC3B
00007FFE496CBBCB mov r11,qword ptr [7FFE03B8h]
00007FFE496CBBD3 test r8b,2
00007FFE496CBBD7 je 00007FFE497698FF
@bionicbeagle
bionicbeagle / ProjectedFSLib.dll
Created April 15, 2018 20:43
Windows Projected File System exports
PrjClearNegativePathCache, 1, 0x3820
PrjCloseFile, 2, 0x2800
PrjCommandCallbacksInit, 3, 0x3d20
PrjCompleteCommand, 4, 0x34e0
PrjConfigureVolume, 5, 0x52b0
PrjConvertDirectoryToPlaceholder, 6, 0x1330
PrjCreatePlaceholderAsHardlink, 7, 0x1ea0
PrjDeleteFile, 8, 0x3120
PrjDetachDriver, 9, 0x5110
PrjDoesNameContainWildCards, 10, 0x5810
@bionicbeagle
bionicbeagle / bug.asm
Created December 13, 2013 18:35
VS2013 x64 compiler bug Note how the access to m_size (loaded into edx) is reordered to be after the detachBuffer() call:
; 12 : {
$LN6:
sub rsp, 40 ; 00000028H
; 13 : AllocatingBuffer outBuf;
lea rcx, QWORD PTR outBuf$[rsp]
call ??0AllocatingBuffer@@QEAA@XZ ; AllocatingBuffer::AllocatingBuffer
@bionicbeagle
bionicbeagle / gist:5178463
Created March 16, 2013 21:45
Example of using libuv with stateless lambdas
// Initialize uv_async_t for shutting down event loop
m_shutdownAsync.data = this;
uv_async_init(m_eventLoop, &m_shutdownAsync, [](uv_async_t* handle, int status) {
auto thisPtr = reinterpret_cast<DiscoService*>(handle->data);
uv_close((uv_handle_t*) handle, nullptr);
uv_close((uv_handle_t*) &thisPtr->m_recvSocket, nullptr);
uv_close((uv_handle_t*) &thisPtr->m_sendSocket, nullptr);
@bionicbeagle
bionicbeagle / gist:5094066
Last active December 14, 2015 13:29
So GetExitCodeProcess() returns TRUE (for success) even if you pass it a non-process handle. Thanks, I guess! This in conjunction with another bug which caused some code to keep using (and keep CLOSING) a process handle which had already been closed caused random lock-ups in an application and I spent several days looking for the root cause :/ B…
HANDLE h = CreateEvent(NULL, TRUE, FALSE, NULL);
DWORD dwExitCode = 9999;
if (GetExitCodeProcess(h, &dwExitCode))
{
printf("Developers, developers, developers!");
CloseHandle(h);
}
@bionicbeagle
bionicbeagle / gist:4730489
Last active December 12, 2015 06:38
Cause of weird thread-naming crashes was... shitty x64 port!
typedef struct tagTHREADNAME_INFO
{
DWORD dwType; // Must be 0x1000
LPCSTR szName; // Pointer to name (in user address space)
DWORD dwThreadID; // Thread ID (-1 for caller thread)
DWORD dwFlags; // Reserved for future use; must be zero
} THREADNAME_INFO;
static void setThreadName(DWORD dwThreadID, LPCSTR szThreadName )
{
@bionicbeagle
bionicbeagle / gist:4647628
Created January 27, 2013 09:57
Super optimized isNumber()
bool isNumber(const char number)
{
std::string tmp;
tmp += number;
return std::string::npos != findIgnoreCase("0123456789", tmp);
}