]> The Tcpdump Group git mirrors - libpcap/commitdiff
Added a critical section on Windows to make pcap_compile thread safe.
authortest <[email protected]>
Wed, 15 Jul 2009 18:57:07 +0000 (11:57 -0700)
committertest <[email protected]>
Wed, 15 Jul 2009 18:57:07 +0000 (11:57 -0700)
This is a temporary patch that can be removed when we will make the
lexer, parser and code generator fully reentrant.

gencode.c
pcap-int.h
pcap-win32.c

index b18663193439ff2b3c201e8ea62462756143b333..28017c4b8871b85a0945fbd051b61a0d1754e6f8 100644 (file)
--- 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;
index bb52fb7f8d0ac80bf23901941d62f2ab25ba35d1..2d4b9bfaa8cef81e52184897cfeeae8efaddc218 100644 (file)
@@ -48,6 +48,7 @@ extern "C" {
 
 #ifdef WIN32
 #include <Packet32.h>
+extern CRITICAL_SECTION g_PcapCompileCriticalSection;
 #endif /* WIN32 */
 
 #ifdef MSDOS
index 8eb26d970107b9917cd9499263f36f5472cb7890..d199945544ccec4bd58fe6336fa0daa366c48030 100644 (file)
@@ -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()