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

apc.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 #define APCH        (HANDLE)'SOR '
00015 
00016 /* FUNCTIONS *****************************************************************/
00017 
00018 DWORD
00019 WINAPI
00020 WahOpenApcHelper(OUT PHANDLE ApcHelperHandle)
00021 {
00022     DWORD ErrorCode;
00023 
00024     /* Enter the prolog, make sure we're initialized */
00025     ErrorCode = WS2HELP_PROLOG();
00026     if (ErrorCode != ERROR_SUCCESS) return ErrorCode;
00027 
00028     /* Validate handle */
00029     if (!ApcHelperHandle) return ERROR_INVALID_PARAMETER;
00030 
00031     /* 
00032      * Return a bogus handle ("ROS")
00033      * Historical note:(MS sends "CKM", which probably stands for "Keith Moore"
00034      * (KM), one of the core architects of Winsock 2.2 from Microsoft.
00035      */
00036     *ApcHelperHandle = APCH;
00037     return ERROR_SUCCESS;
00038 }
00039 
00040 DWORD
00041 WINAPI
00042 WahCloseApcHelper(IN HANDLE ApcHelperHandle)
00043 {
00044     DWORD ErrorCode;
00045 
00046     /* Enter the prolog, make sure we're initialized */
00047     ErrorCode = WS2HELP_PROLOG();
00048     if (ErrorCode != ERROR_SUCCESS) return ErrorCode;
00049 
00050     /* Validate handle */
00051     if (ApcHelperHandle != APCH) return ERROR_INVALID_PARAMETER;
00052 
00053     /* return */
00054     return ERROR_SUCCESS;
00055 }
00056 
00057 DWORD
00058 WINAPI
00059 WahCloseThread(IN HANDLE ApcHelperHandle,
00060                IN LPWSATHREADID ThreadId)
00061 {
00062     DWORD ErrorCode;
00063 
00064     /* Enter the prolog, make sure we're initialized */
00065     ErrorCode = WS2HELP_PROLOG();
00066     if (ErrorCode != ERROR_SUCCESS) return ErrorCode;
00067 
00068     /* Validate handles */
00069     if ((ApcHelperHandle != APCH) || (!ThreadId) || (!ThreadId->ThreadHandle))
00070     {
00071         /* Invalid helper/thread handles */
00072         return ERROR_INVALID_PARAMETER;
00073     }
00074 
00075     /* Close the thread handle */
00076     if (CloseHandle(ThreadId->ThreadHandle))
00077     {
00078         /* Clear the sturcture */
00079         ThreadId->ThreadHandle = NULL;
00080         ThreadId->Reserved = 0;
00081         return NO_ERROR;
00082     }
00083 
00084     /* return */
00085     return GetLastError();
00086 }
00087 
00088 INT
00089 WINAPI 
00090 WahQueueUserApc(IN HANDLE ApcHelperHandle,
00091                 IN LPWSATHREADID ThreadId,
00092                 IN LPWSAUSERAPC ApcRoutine,
00093                 IN PVOID ApcContext OPTIONAL)
00094 {
00095     /* Validate params  */
00096     if ((ApcHelperHandle != APCH) ||
00097         (!ThreadId) ||
00098         (!ThreadId->ThreadHandle) ||
00099         (!ApcRoutine))
00100     {
00101         /* Invalid parameters */
00102         return ERROR_INVALID_PARAMETER;
00103     }
00104 
00105     /* Queue the APC */
00106     if (QueueUserAPC(ApcRoutine, ThreadId->ThreadHandle, (ULONG_PTR)ApcContext))
00107     {
00108         /* Return success */
00109         return ERROR_SUCCESS;
00110     }
00111 
00112     /* Fail */
00113     return GetLastError();
00114 }
00115 
00116 DWORD
00117 WINAPI
00118 WahOpenCurrentThread(IN HANDLE ApcHelperHandle,
00119                      OUT LPWSATHREADID ThreadId)
00120 {
00121     HANDLE ProcessHandle, ThreadHandle;
00122 
00123     /* Validate params  */
00124     if ((ApcHelperHandle != APCH) || (!ThreadId))
00125     {
00126         /* Invalid parameters */
00127         return ERROR_INVALID_PARAMETER;
00128     }
00129 
00130     /* Get the process/thread handles */
00131     ProcessHandle = GetCurrentProcess();
00132     ThreadHandle = GetCurrentThread();
00133 
00134     /* Duplicate the handle */
00135     if (DuplicateHandle(ProcessHandle,
00136                         ThreadHandle,
00137                         ProcessHandle,
00138                         &ThreadId->ThreadHandle,
00139                         0,
00140                         FALSE,
00141                         DUPLICATE_SAME_ACCESS))
00142     {
00143         /* Save the thread handle and return */
00144         ThreadId->Reserved = (DWORD_PTR)ThreadHandle;
00145         return ERROR_SUCCESS;
00146     }
00147 
00148     /* Fail */
00149     return GetLastError();
00150 }
00151 
00152 /* EOF */

Generated on Sat May 26 2012 04:25:41 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.