亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? api.c

?? ReactOS是一些高手根據Windows XP的內核編寫出的類XP。內核實現機理和API函數調用幾乎相同。甚至可以兼容XP的程序。喜歡研究系統內核的人可以看一看。
?? C
?? 第 1 頁 / 共 3 頁
字號:
/*
 * COPYRIGHT:       See COPYING in the top level directory
 * PROJECT:         ReactOS CSR Sub System
 * FILE:            subsys/csr/csrsrv/api.c
 * PURPOSE:         CSR Server DLL API LPC Implementation
 * PROGRAMMERS:     Alex Ionescu (alex@relsoft.net)
 */

/* INCLUDES ******************************************************************/

#include "srv.h"

#define NDEBUG
#include <debug.h>

/* DATA **********************************************************************/
BOOLEAN (*CsrClientThreadSetup)(VOID) = NULL;
ULONG CsrMaxApiRequestThreads;
UNICODE_STRING CsrSbApiPortName;
UNICODE_STRING CsrApiPortName;
HANDLE CsrSbApiPort;
HANDLE CsrApiPort;
PCSR_THREAD CsrSbApiRequestThreadPtr;
ULONG CsrpStaticThreadCount;
ULONG CsrpDynamicThreadTotal;

/* PRIVATE FUNCTIONS *********************************************************/

/*++
 * @name CsrCheckRequestThreads
 *
 * The CsrCheckRequestThreads routine checks if there are no more threads
 * to handle CSR API Requests, and creates a new thread if possible, to
 * avoid starvation.
 *
 * @param None.
 *
 * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
 *         if a new thread couldn't be created.
 *
 * @remarks None.
 *
 *--*/
NTSTATUS
NTAPI
CsrCheckRequestThreads(VOID)
{
    HANDLE hThread;
    CLIENT_ID ClientId;
    NTSTATUS Status;

    /* Decrease the count, and see if we're out */
    if (!(InterlockedDecrement(&CsrpStaticThreadCount)))
    {
        /* Check if we've still got space for a Dynamic Thread */
        if (CsrpDynamicThreadTotal < CsrMaxApiRequestThreads)
        {
            /* Create a new dynamic thread */
            Status = RtlCreateUserThread(NtCurrentProcess(),
                                         NULL,
                                         TRUE,
                                         0,
                                         0,
                                         0,
                                         (PVOID)CsrApiRequestThread,
                                         NULL,
                                         &hThread,
                                         &ClientId);
            /* Check success */
            if(NT_SUCCESS(Status))
            {
                /* Increase the thread counts */
                CsrpStaticThreadCount++;
                CsrpDynamicThreadTotal++;

                /* Add a new server thread */
                if (CsrAddStaticServerThread(hThread,
                                             &ClientId,
                                             CsrThreadIsServerThread))
                {
                    /* Activate it */
                    NtResumeThread(hThread,NULL);
                }
                else
                {
                    /* Failed to create a new static thread */
                    CsrpStaticThreadCount--;
                    CsrpDynamicThreadTotal--;

                    /* Terminate it */
                    NtTerminateThread(hThread,0);
                    NtClose(hThread);

                    /* Return */
                    return STATUS_UNSUCCESSFUL;
                }
            }
        }
    }

    /* Success */
    return STATUS_SUCCESS;
}

/*++
 * @name CsrSbApiPortInitialize
 *
 * The CsrSbApiPortInitialize routine initializes the LPC Port used for
 * communications with the Session Manager (SM) and initializes the static
 * thread that will handle connection requests and APIs.
 *
 * @param None
 *
 * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
 *         othwerwise.
 *
 * @remarks None.
 *
 *--*/
NTSTATUS
NTAPI
CsrSbApiPortInitialize(VOID)
{
    ULONG Size;
    PSECURITY_DESCRIPTOR PortSd;
    OBJECT_ATTRIBUTES ObjectAttributes;
    NTSTATUS Status;
    HANDLE hRequestThread;
    CLIENT_ID ClientId;

    /* Calculate how much space we'll need for the Port Name */
    Size = CsrDirectoryName.Length + sizeof(SB_PORT_NAME) + sizeof(WCHAR);

    /* Allocate space for it, and create it */
    CsrSbApiPortName.Buffer = RtlAllocateHeap(CsrHeap, 0, Size);
    CsrSbApiPortName.Length = 0;
    CsrSbApiPortName.MaximumLength = (USHORT)Size;
    RtlAppendUnicodeStringToString(&CsrSbApiPortName, &CsrDirectoryName);
    RtlAppendUnicodeToString(&CsrSbApiPortName, UNICODE_PATH_SEP);
    RtlAppendUnicodeToString(&CsrSbApiPortName, SB_PORT_NAME);

    /* Create Security Descriptor for this Port */
    CsrCreateLocalSystemSD(&PortSd);

    /* Initialize the Attributes */
    InitializeObjectAttributes(&ObjectAttributes,
                               &CsrSbApiPortName,
                               0,
                               PortSd,
                               NULL);

    /* Create the Port Object */
    Status = NtCreatePort(&CsrSbApiPort,
                          &ObjectAttributes,
                          sizeof(SB_CONNECTION_INFO),
                          sizeof(SB_API_MESSAGE),
                          32 * sizeof(SB_API_MESSAGE));
    if(!NT_SUCCESS(Status))
    {

    }

    /* Create the Thread to handle the API Requests */
    Status = RtlCreateUserThread(NtCurrentProcess(),
                                 NULL,
                                 TRUE,
                                 0,
                                 0,
                                 0,
                                 (PVOID)CsrSbApiRequestThread,
                                 NULL,
                                 &hRequestThread,
                                 &ClientId);
    if(!NT_SUCCESS(Status))
    {

    }

    /* Add it as a Static Server Thread */
    CsrSbApiRequestThreadPtr = CsrAddStaticServerThread(hRequestThread,
                                                        &ClientId,
                                                        0);

    /* Activate it */
    return NtResumeThread(hRequestThread, NULL);
}

/*++
 * @name CsrApiPortInitialize
 *
 * The CsrApiPortInitialize routine initializes the LPC Port used for
 * communications with the Client/Server Runtime (CSR) and initializes the
 * static thread that will handle connection requests and APIs.
 *
 * @param None
 *
 * @return STATUS_SUCCESS in case of success, STATUS_UNSUCCESSFUL
 *         othwerwise.
 *
 * @remarks None.
 *
 *--*/
NTSTATUS
NTAPI
CsrApiPortInitialize(VOID)
{
    ULONG Size;
    OBJECT_ATTRIBUTES ObjectAttributes;
    NTSTATUS Status;
    HANDLE hRequestEvent, hThread;
    CLIENT_ID ClientId;
    PLIST_ENTRY ListHead, NextEntry;
    PCSR_THREAD ServerThread;

    /* Calculate how much space we'll need for the Port Name */
    Size = CsrDirectoryName.Length + sizeof(CSR_PORT_NAME) + sizeof(WCHAR);

    /* Allocate space for it, and create it */
    CsrApiPortName.Buffer = RtlAllocateHeap(CsrHeap, 0, Size);
    CsrApiPortName.Length = 0;
    CsrApiPortName.MaximumLength = (USHORT)Size;
    RtlAppendUnicodeStringToString(&CsrApiPortName, &CsrDirectoryName);
    RtlAppendUnicodeToString(&CsrApiPortName, UNICODE_PATH_SEP);
    RtlAppendUnicodeToString(&CsrApiPortName, CSR_PORT_NAME);

    /* FIXME: Create a Security Descriptor */

    /* Initialize the Attributes */
    InitializeObjectAttributes(&ObjectAttributes,
                               &CsrApiPortName,
                               0,
                               NULL,
                               NULL /* FIXME*/);

    /* Create the Port Object */
    Status = NtCreatePort(&CsrApiPort,
                          &ObjectAttributes,
                          sizeof(CSR_CONNECTION_INFO),
                          sizeof(CSR_API_MESSAGE),
                          16 * PAGE_SIZE);
    if(!NT_SUCCESS(Status))
    {

    }

    /* Create the event the Port Thread will use */
    Status = NtCreateEvent(&hRequestEvent,
                           EVENT_ALL_ACCESS,
                           NULL,
                           SynchronizationEvent,
                           FALSE);
    if(!NT_SUCCESS(Status))
    {

    }

    /* Create the Request Thread */
    Status = RtlCreateUserThread(NtCurrentProcess(),
                                 NULL,
                                 TRUE,
                                 0,
                                 0,
                                 0,
                                 (PVOID)CsrApiRequestThread,
                                 (PVOID)hRequestEvent,
                                 &hThread,
                                 &ClientId);
    if(!NT_SUCCESS(Status))
    {

    }

    /* Add this as a static thread to CSRSRV */
    CsrAddStaticServerThread(hThread, &ClientId, CsrThreadIsServerThread);

    /* Get the Thread List Pointers */
    ListHead = &CsrRootProcess->ThreadList;
    NextEntry = ListHead->Flink;

    /* Start looping the list */
    while (NextEntry != ListHead)
    {
        /* Get the Thread */
        ServerThread = CONTAINING_RECORD(NextEntry, CSR_THREAD, Link);

        /* Start it up */
        Status = NtResumeThread(ServerThread->ThreadHandle, NULL);

        /* Is this a Server Thread? */
        if (ServerThread->Flags & CsrThreadIsServerThread)
        {
            /* If so, then wait for it to initialize */
            NtWaitForSingleObject(hRequestEvent, FALSE, NULL);
        }

        /* Next thread */
        NextEntry = NextEntry->Flink;
    }

    /* We don't need this anymore */
    NtClose(hRequestEvent);

    /* Return */
    return Status;
}

/*++
 * @name CsrApiRequestThread
 *
 * The CsrApiRequestThread routine handles incoming messages or connection
 * requests on the CSR API LPC Port.
 *
 * @param Parameter
 *        System-default user-defined parameter. Unused.
 *
 * @return The thread exit code, if the thread is terminated.
 *
 * @remarks Before listening on the port, the routine will first attempt
 *          to connect to the user subsystem.
 *
 *--*/
NTSTATUS
NTAPI
CsrApiRequestThread(IN PVOID Parameter)
{
    PTEB Teb = NtCurrentTeb();
    LARGE_INTEGER TimeOut;
    PCSR_THREAD CurrentThread;
    NTSTATUS Status;
    PCSR_API_MESSAGE ReplyMsg = NULL;
    CSR_API_MESSAGE ReceiveMsg;
    PCSR_THREAD CsrThread;
    PCSR_PROCESS CsrProcess;
    PHARDERROR_MSG HardErrorMsg;
    PVOID PortContext;
    ULONG MessageType;
    ULONG i;
    PCSR_SERVER_DLL ServerDll;
    PCLIENT_DIED_MSG ClientDiedMsg;
    PDBGKM_MSG DebugMessage;
    ULONG ServerId, ApiId;
    ULONG Reply;

    /* Probably because of the way GDI is loaded, this has to be done here */
    Teb->GdiClientPID = HandleToUlong(Teb->Cid.UniqueProcess);
    Teb->GdiClientTID = HandleToUlong(Teb->Cid.UniqueThread);

    /* Set up the timeout for the connect (30 seconds) */
    TimeOut.QuadPart = -30 * 1000 * 1000 * 10;

    /* Connect to user32 */
    while (!CsrConnectToUser())
    {
        /* Keep trying until we get a response */
        Teb->Win32ClientInfo[0] = 0;
        NtDelayExecution(FALSE, &TimeOut);
    }

    /* Get our thread */
    CurrentThread = Teb->CsrClientThread;

    /* If we got an event... */
    if (Parameter)
    {
        /* Set it, to let stuff waiting on us load */
        NtSetEvent((HANDLE)Parameter, NULL);

        /* Increase the Thread Counts */
        InterlockedIncrement(&CsrpStaticThreadCount);
        InterlockedIncrement(&CsrpDynamicThreadTotal);
    }

    /* Now start the loop */
    while (TRUE)
    {
        /* Make sure the real CID is set */
        Teb->RealClientId = Teb->Cid;

        /* Wait for a message to come through */
        Status = NtReplyWaitReceivePort(CsrApiPort,
                                        &PortContext,
                                        (PPORT_MESSAGE)ReplyMsg,
                                        (PPORT_MESSAGE)&ReceiveMsg);

        /* Check if we didn't get success */
        if(Status != STATUS_SUCCESS)
        {
            /* If we only got a warning, keep going */
            if (NT_SUCCESS(Status)) continue;

            /* We failed big time, so start out fresh */
            ReplyMsg = NULL;
            continue;
        }

        /* Use whatever Client ID we got */
        Teb->RealClientId = ReceiveMsg.Header.ClientId;

        /* Get the Message Type */
        MessageType = ReceiveMsg.Header.u2.s2.Type;

        /* Handle connection requests */
        if (MessageType == LPC_CONNECTION_REQUEST)
        {
            /* Handle the Connection Request */
            CsrApiHandleConnectionRequest(&ReceiveMsg);
            ReplyMsg = NULL;
            continue;
        }

        /* It's some other kind of request. Get the lock for the lookup*/
        CsrAcquireProcessLock();

        /* Now do the lookup to get the CSR_THREAD */
        CsrThread = CsrLocateThreadByClientId(&CsrProcess,
                                              &ReceiveMsg.Header.ClientId);

        /* Did we find a thread? */
        if(!CsrThread)
        {
            /* This wasn't a CSR Thread, release lock */
            CsrReleaseProcessLock();

            /* If this was an exception, handle it */
            if (MessageType == LPC_EXCEPTION)
            {
                ReplyMsg = &ReceiveMsg;
                ReplyMsg->Status = DBG_CONTINUE;
            }
            else if (MessageType == LPC_PORT_CLOSED ||
                     MessageType == LPC_CLIENT_DIED)
            {
                /* The Client or Port are gone, loop again */
                ReplyMsg = NULL;
            }
            else if (MessageType == LPC_ERROR_EVENT)
            {
                /* If it's a hard error, handle this too */
                HardErrorMsg = (PHARDERROR_MSG)&ReceiveMsg;

                /* Default it to unhandled */
                HardErrorMsg->Response = ResponseNotHandled;

                /* Check if there are free api threads */
                CsrCheckRequestThreads();
                if (CsrpStaticThreadCount)
                {
                    /* Loop every Server DLL */
                    for (i = 0; i < CSR_SERVER_DLL_MAX; i++)
                    {
                        /* Get the Server DLL */
                        ServerDll = CsrLoadedServerDll[i];

                        /* Check if it's valid and if it has a Hard Error Callback */
                        if (ServerDll && ServerDll->HardErrorCallback)
                        {
                            /* Call it */
                            (*ServerDll->HardErrorCallback)(CsrThread, HardErrorMsg);

                            /* If it's handled, get out of here */
                            if (HardErrorMsg->Response != ResponseNotHandled) break;
                        }
                    }
                }

                /* Increase the thread count */
                InterlockedIncrement(&CsrpStaticThreadCount);

                /* If the response was 0xFFFFFFFF, we'll ignore it */
                if (HardErrorMsg->Response == 0xFFFFFFFF)
                {

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日本中文在线一区| 欧美国产精品一区二区| 久久先锋影音av鲁色资源网| 国产欧美在线观看一区| 亚洲日本在线a| 日韩中文字幕亚洲一区二区va在线| 久久99精品久久久久久久久久久久 | 亚洲国产成人tv| 久久狠狠亚洲综合| aaa亚洲精品| 欧美一区二区三区啪啪| 中文av字幕一区| 偷拍一区二区三区四区| 国产a久久麻豆| 欧美私人免费视频| 久久精品一级爱片| 亚洲线精品一区二区三区 | 欧美国产激情二区三区| 亚洲第一成年网| 国产精品99久久久久久似苏梦涵| 在线视频欧美区| 久久一日本道色综合| 亚洲一区二区四区蜜桃| 国产精品自拍av| 欧美午夜免费电影| 国产欧美精品一区二区三区四区| 香蕉成人啪国产精品视频综合网| 国产成人在线看| 欧美人妖巨大在线| 自拍偷拍国产亚洲| 国产精品一品二品| 欧美一区二区视频在线观看| 国产精品女上位| 裸体一区二区三区| 欧美在线小视频| 亚洲国产高清在线| 久久99精品久久久久久久久久久久 | 精品日韩一区二区三区| 亚洲一区免费观看| 99久久精品国产一区| 欧美精品一区二区三区一线天视频| 一区二区三区美女视频| 成人一区二区三区在线观看| 欧美mv和日韩mv的网站| 亚洲大片在线观看| 91浏览器在线视频| 中文字幕av免费专区久久| 久久97超碰国产精品超碰| 欧美精品v日韩精品v韩国精品v| 中文字幕日韩一区| 国产suv精品一区二区6| 欧美成人女星排行榜| 日本视频一区二区| 欧美精品在欧美一区二区少妇| 亚洲乱码国产乱码精品精98午夜| 国产成人在线视频网站| 久久男人中文字幕资源站| 麻豆精品国产91久久久久久| 欧美精品高清视频| 亚洲电影你懂得| 欧美亚洲国产一区在线观看网站| 亚洲欧美福利一区二区| 成人av综合一区| 中文幕一区二区三区久久蜜桃| 国产伦精一区二区三区| 久久你懂得1024| 国产一二精品视频| 久久久国产一区二区三区四区小说| 久久99最新地址| 日韩欧美一区二区免费| 麻豆专区一区二区三区四区五区| 91精品免费在线| 免费美女久久99| 日韩精品一区二区三区四区| 久久成人免费电影| 精品日韩99亚洲| 国产另类ts人妖一区二区| 久久一夜天堂av一区二区三区| 国产另类ts人妖一区二区| 国产香蕉久久精品综合网| 国产成人99久久亚洲综合精品| 国产亚洲综合av| 成人理论电影网| 亚洲视频你懂的| 日本高清不卡视频| 香蕉av福利精品导航| 日韩亚洲欧美在线观看| 精品亚洲aⅴ乱码一区二区三区| 精品日本一线二线三线不卡| 国产乱码精品一区二区三区av | 麻豆国产精品777777在线| 欧美成人三级在线| 国产成人av一区二区三区在线 | youjizz国产精品| 亚洲欧美偷拍另类a∨色屁股| 欧美性色黄大片| 亚洲成人自拍偷拍| 日韩免费看网站| 成人网在线免费视频| 亚洲人快播电影网| 91精品国产综合久久精品app | 亚洲精品一区二区三区影院| 国产精一品亚洲二区在线视频| 欧美国产激情一区二区三区蜜月| 国产91在线看| 亚洲欧美自拍偷拍色图| 欧美日韩在线直播| 日韩avvvv在线播放| 日韩欧美专区在线| 国产精品88av| 欧美精品一区二区三区蜜桃| 99re热视频这里只精品| 亚洲永久免费av| 日韩免费视频一区| 成人晚上爱看视频| 夜夜嗨av一区二区三区| 亚洲精品在线三区| 99久久777色| 午夜激情一区二区三区| 欧美mv日韩mv| av中文字幕亚洲| 麻豆一区二区99久久久久| 国产三级精品视频| 97国产一区二区| 午夜影视日本亚洲欧洲精品| 在线综合+亚洲+欧美中文字幕| 激情亚洲综合在线| 亚洲精选视频免费看| 8v天堂国产在线一区二区| 成人av动漫在线| 亚洲成a人在线观看| 久久综合色婷婷| 91视频免费看| 日韩av电影免费观看高清完整版 | av网站一区二区三区| 亚洲在线观看免费| wwww国产精品欧美| 99久久伊人久久99| 手机精品视频在线观看| 久久精品一区二区三区av| 91传媒视频在线播放| 久久精品国产亚洲aⅴ| 久久综合九色综合97婷婷女人| 欧美三级视频在线| 国产成人午夜片在线观看高清观看| 亚洲自拍偷拍av| 久久精品日韩一区二区三区| 一本久久a久久免费精品不卡| 国产乱码精品一区二区三区五月婷| 一二三区精品视频| 国产日韩亚洲欧美综合| 91精品国产综合久久小美女| 国产精品一区二区免费不卡| 日韩av电影一区| 亚洲欧美日韩久久精品| 2020国产精品| 欧美肥妇bbw| www.欧美.com| 国产伦精品一区二区三区在线观看| 一区二区三区中文字幕在线观看| 337p日本欧洲亚洲大胆色噜噜| 91福利在线播放| 91视频国产观看| 国产suv精品一区二区6| 久久国产夜色精品鲁鲁99| 一区二区三区蜜桃| 国产精品久久久久久亚洲毛片 | 国产九九视频一区二区三区| 五月激情综合网| 亚洲美女屁股眼交3| 久久久久久久网| 欧美高清视频一二三区| 91麻豆精品视频| 成人av手机在线观看| 国产精品18久久久| 裸体在线国模精品偷拍| 久草热8精品视频在线观看| 亚洲成在人线免费| 一区二区三区四区亚洲| 国产精品第四页| 国产精品久久久久影院老司| 国产亚洲一区二区三区| 欧美精品乱码久久久久久| 欧美美女bb生活片| 欧美视频中文一区二区三区在线观看 | 色综合天天综合狠狠| 日本欧美肥老太交大片| 美美哒免费高清在线观看视频一区二区 | 一本久久a久久精品亚洲| 色婷婷国产精品久久包臀| 95精品视频在线| 床上的激情91.| 国产成人综合亚洲网站| 精品一区二区三区久久| 国产一区二区三区四区五区入口| 日本不卡一区二区三区| 丝袜亚洲精品中文字幕一区| 亚洲第一在线综合网站| 亚洲免费观看高清完整版在线 | 99精品视频一区二区|