ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

dllmain.c
Go to the documentation of this file.
00001 /*
00002  * COPYRIGHT:   See COPYING in the top level directory
00003  * PROJECT:     ReactOS WinSock 2 DLL
00004  * FILE:        include/ws2_32.h
00005  * PURPOSE:     WinSock 2 DLL header
00006  */
00007 
00008 /* INCLUDES ******************************************************************/
00009 
00010 #include "precomp.h"
00011 
00012 /* DATA **********************************************************************/
00013 
00014 HANDLE GlobalHeap;
00015 BOOL Ws2helpInitialized = FALSE;
00016 CRITICAL_SECTION StartupSyncronization;
00017 HINSTANCE LibraryHdl;
00018 
00019 /* FUNCTIONS *****************************************************************/
00020 
00021 VOID
00022 WINAPI
00023 NewCtxInit(VOID)
00024 {
00025     NT_PRODUCT_TYPE ProductType = NtProductWinNt;
00026     SYSTEM_INFO SystemInfo;
00027     DWORD NumHandleBuckets;
00028     HKEY KeyHandle;
00029     DWORD RegSize = sizeof(DWORD);
00030     DWORD RegType;
00031     DWORD Mask;
00032 
00033     /* Try to figure out if this is a workstation or server install */
00034     RtlGetNtProductType(&ProductType);
00035 
00036     /* Get the system info */
00037     GetSystemInfo(&SystemInfo);
00038 
00039     /* If this is an MP machine, set the default spinlock */
00040     if (SystemInfo.dwNumberOfProcessors > 1) gdwSpinCount = 2000;
00041 
00042     /* Figure how many "Handle Buckets" we'll use. Start with the default */
00043     NumHandleBuckets = ProductType == NtProductWinNt ? 8 : 32;
00044 
00045     /* Open the registry settings */
00046     if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
00047                      "System\\CurrentControlSet\\Services\\Winsock2\\Parameters",
00048                      0,
00049                      KEY_QUERY_VALUE,
00050                      &KeyHandle) == ERROR_SUCCESS)
00051     {
00052         /* Query the key */
00053         RegQueryValueEx(KeyHandle,
00054                         "Ws2_32NumHandleBuckets",
00055                         0,
00056                         &RegType,
00057                         (LPBYTE)&NumHandleBuckets,
00058                         &RegSize);
00059 
00060         /* Are we on MP? */
00061         if (SystemInfo.dwNumberOfProcessors > 1)
00062         {
00063             /* Also check for a custom spinlock setting */
00064             RegQueryValueEx(KeyHandle,
00065                             "Ws2_32SpinCount",
00066                             0,
00067                             &RegType,
00068                             (LPBYTE)&gdwSpinCount,
00069                             &RegSize);
00070         }
00071 
00072         /* Close the key, we're done */
00073         RegCloseKey(KeyHandle);
00074     }
00075 
00076     /* Now get the bucket count and normalize it to be log2 and within 256 */
00077     for (Mask = 256; !(Mask & NumHandleBuckets); Mask >>= 1);
00078     NumHandleBuckets = Mask;
00079 
00080     /* Normalize it again, to be within OS parameters */
00081     if (ProductType == NtProductWinNt)
00082     {
00083         /* Is it within norms for non-server editions? */
00084         if (NumHandleBuckets > 32) NumHandleBuckets = 32;
00085         else if (NumHandleBuckets < 8) NumHandleBuckets = 8;
00086     }
00087     else
00088     {
00089         /* Is it within norms for server editions? */
00090         if (NumHandleBuckets > 256) NumHandleBuckets = 256;
00091         else if (NumHandleBuckets < 32) NumHandleBuckets = 32;
00092     }
00093 
00094     /* Normalize the spincount */
00095     if (gdwSpinCount > 8000) gdwSpinCount = 8000;
00096 
00097     /* Set the final mask */
00098     gHandleToIndexMask = NumHandleBuckets -1;
00099 }
00100 
00101 DWORD
00102 WINAPI
00103 Ws2helpInitialize(VOID)
00104 {
00105     /* Enter the startup CS */
00106     EnterCriticalSection(&StartupSyncronization);
00107 
00108     /* Check again for init */
00109     if (!Ws2helpInitialized)
00110     {
00111         /* Initialize us */
00112         NewCtxInit();
00113         Ws2helpInitialized = TRUE;
00114     }
00115 
00116     /* Leave the CS and return */
00117     LeaveCriticalSection(&StartupSyncronization);
00118     return ERROR_SUCCESS;
00119 }
00120 
00121 BOOL 
00122 APIENTRY 
00123 DllMain(HANDLE hModule, 
00124         DWORD  dwReason, 
00125         LPVOID lpReserved)
00126 {
00127     switch (dwReason)
00128     {
00129         case DLL_PROCESS_ATTACH:
00130         
00131             /* Save our handle */
00132             LibraryHdl = hModule;
00133 
00134             /* Improve Performance */
00135             DisableThreadLibraryCalls(hModule);
00136 
00137             /* Initialize startup CS */
00138             InitializeCriticalSection(&StartupSyncronization);
00139 
00140             /* Get Global Heap */
00141             GlobalHeap = GetProcessHeap();
00142             break;
00143 
00144         case DLL_THREAD_ATTACH:
00145         case DLL_THREAD_DETACH:
00146             break;
00147 
00148         case DLL_PROCESS_DETACH:
00149 
00150             /* Make sure we loaded */
00151             if (!LibraryHdl) break;
00152 
00153             /* Check if we are cleaning up */
00154             if (lpReserved)
00155             {
00156                 /* Free the security descriptor */
00157                 if (pSDPipe) HeapFree(GlobalHeap, 0, pSDPipe);
00158 
00159                 /* Close the event */
00160                 if (ghWriterEvent) CloseHandle(ghWriterEvent);
00161 
00162                 /* Delete the startup CS */
00163                 DeleteCriticalSection(&StartupSyncronization);
00164                 Ws2helpInitialized = FALSE;
00165             }
00166             break;
00167     }
00168 
00169     return TRUE;
00170 }

Generated on Sun May 27 2012 04:22:39 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.