From: test Date: Wed, 15 Jul 2009 18:57:07 +0000 (-0700) Subject: Added a critical section on Windows to make pcap_compile thread safe. X-Git-Tag: libpcap-1.1.0~114 X-Git-Url: https://git.tcpdump.org/libpcap/commitdiff_plain/32c168dad42e24a3bcd246253358ed750334c376 Added a critical section on Windows to make pcap_compile thread safe. This is a temporary patch that can be removed when we will make the lexer, parser and code generator fully reentrant. --- diff --git a/gencode.c b/gencode.c index b1866319..28017c4b 100644 --- a/gencode.c +++ b/gencode.c @@ -377,10 +377,35 @@ syntax() static bpf_u_int32 netmask; static int snaplen; int no_optimize; +#ifdef WIN32 +static int +pcap_compile_unsafe(pcap_t *p, struct bpf_program *program, + const char *buf, int optimize, bpf_u_int32 mask); + +int +pcap_compile(pcap_t *p, struct bpf_program *program, + const char *buf, int optimize, bpf_u_int32 mask) +{ + int result; + + EnterCriticalSection(&g_PcapCompileCriticalSection); + OutputDebugString("Hello my dear, I locked myself\n"); + result = pcap_compile_unsafe(p, program, buf, optimize, mask); + + LeaveCriticalSection(&g_PcapCompileCriticalSection); + + return result; +} + +static int +pcap_compile_unsafe(pcap_t *p, struct bpf_program *program, + const char *buf, int optimize, bpf_u_int32 mask) +#else /* WIN32 */ int pcap_compile(pcap_t *p, struct bpf_program *program, const char *buf, int optimize, bpf_u_int32 mask) +#endif /* WIN32 */ { extern int n_errors; const char * volatile xbuf = buf; diff --git a/pcap-int.h b/pcap-int.h index bb52fb7f..2d4b9bfa 100644 --- a/pcap-int.h +++ b/pcap-int.h @@ -48,6 +48,7 @@ extern "C" { #ifdef WIN32 #include +extern CRITICAL_SECTION g_PcapCompileCriticalSection; #endif /* WIN32 */ #ifdef MSDOS diff --git a/pcap-win32.c b/pcap-win32.c index 8eb26d97..d1999455 100644 --- a/pcap-win32.c +++ b/pcap-win32.c @@ -78,6 +78,23 @@ struct bpf_hdr { plus alignment padding) */ }; +CRITICAL_SECTION g_PcapCompileCriticalSection; + +BOOL WINAPI DllMain( + HANDLE hinstDLL, + DWORD dwReason, + LPVOID lpvReserved +) +{ + if (dwReason == DLL_PROCESS_ATTACH) + { + OutputDebugString("Hello my dear, I INITIALIZED THE CS\n"); + InitializeCriticalSection(&g_PcapCompileCriticalSection); + } + + return TRUE; +} + /* Start winsock */ int wsockinit()