Beispiel #1
0
static int wine_pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
{
  wine_cond_detail *detail;
  int last_waiter;

  if ( !((wine_cond)cond)->cond ) wine_cond_real_init(cond);
  detail = ((wine_cond)cond)->cond;

  /* Avoid race conditions. */
  RtlEnterCriticalSection (&detail->waiters_count_lock);
  detail->waiters_count++;
  RtlLeaveCriticalSection (&detail->waiters_count_lock);

  RtlLeaveCriticalSection ( ((wine_mutex)mutex)->critsect );
  NtWaitForMultipleObjects( 1, &detail->sema, FALSE, FALSE, NULL );

  /* Reacquire lock to avoid race conditions. */
  RtlEnterCriticalSection (&detail->waiters_count_lock);

  /* We're no longer waiting... */
  detail->waiters_count--;

  /* Check to see if we're the last waiter after <pthread_cond_broadcast>. */
  last_waiter = detail->was_broadcast && detail->waiters_count == 0;

  RtlLeaveCriticalSection (&detail->waiters_count_lock);

  /*
   * If we're the last waiter thread during this particular broadcast
   * then let all the other threads proceed.
   */
  if (last_waiter) NtSetEvent( detail->waiters_done, NULL );
  RtlEnterCriticalSection (((wine_mutex)mutex)->critsect);
  return 0;
}
Beispiel #2
0
BOOL
FASTCALL
EndUserApiHook(VOID)
{
  HMODULE hModule;
  USERAPIHOOKPROC pfn;  
  BOOL Ret = FALSE;

  if ( !InterlockedDecrement(&gcCallUserApiHook) )
  {
     if ( !gcLoadUserApiHook )
     {
        RtlEnterCriticalSection(&gcsUserApiHook);

        pfn = gpfnInitUserApi;
        hModule = ghmodUserApiHook;
        ghmodUserApiHook = NULL;
        gpfnInitUserApi = NULL;

        RtlLeaveCriticalSection(&gcsUserApiHook);

        if ( pfn ) Ret = pfn(uahStop, 0);

        if ( hModule ) Ret = FreeLibrary(hModule);
     }
  }
  return Ret;
}
Beispiel #3
0
//------------------------------------------------------------------------
//  CSocketMap::Lookup()
//
//  Given a socket handle, find the associated LSP socket object.
//------------------------------------------------------------------------
RSOCKET *CSocketMap::Lookup( SOCKET hSocket )
{
    SOCKET_MAP_ENTRY *pMap = m_pMap;

    if (!pMap)
    {
        return 0;
    }

    NTSTATUS  Status = RtlEnterCriticalSection(&m_cs);

    for (DWORD i=0; i<m_dwMapSize; i++)
    {
        if (pMap->hSocket == hSocket)
        {
            Status = RtlLeaveCriticalSection(&m_cs);
            return pMap->pRSocket;
        }

        pMap++;
    }

    Status = RtlLeaveCriticalSection(&m_cs);

    return 0;
}
Beispiel #4
0
VOID
LockConsoleHandleTable( VOID )

/*++

Routine Description:

    This routine locks the global console handle table. It also verifies
    that we're not in the USER critical section. This is necessary to
    prevent potential deadlocks. This routine is only defined in debug
    builds.

Arguments:

    none.

Return Value:

    none.

--*/

{
    RtlEnterCriticalSection(&ConsoleHandleLock);
}
Beispiel #5
0
BOOLEAN
NTAPI
SmpCheckDuplicateMuSessionId(IN ULONG MuSessionId)
{
    PSMP_SUBSYSTEM Subsystem;
    BOOLEAN FoundDuplicate = FALSE;
    PLIST_ENTRY NextEntry;

    /* Lock the subsystem database */
    RtlEnterCriticalSection(&SmpKnownSubSysLock);

    /* Scan each entry */
    NextEntry = SmpKnownSubSysHead.Flink;
    while (NextEntry != &SmpKnownSubSysHead)
    {
        /* Check if this entry has the same session ID */
        Subsystem = CONTAINING_RECORD(NextEntry, SMP_SUBSYSTEM, Entry);
        if (Subsystem->MuSessionId == MuSessionId)
        {
            /* Break out of here! */
            FoundDuplicate = TRUE;
            break;
        }
        
        /* Keep going */
        NextEntry = NextEntry->Flink;
    }

    /* Release the database and return the result */
    RtlLeaveCriticalSection(&SmpKnownSubSysLock);
    return FoundDuplicate;
}
Beispiel #6
0
/*
 * @implemented
 */
PVOID NTAPI
RtlPcToFileHeader(IN PVOID PcValue,
                  PVOID* BaseOfImage)
{
    PLIST_ENTRY ModuleListHead;
    PLIST_ENTRY Entry;
    PLDR_DATA_TABLE_ENTRY Module;
    PVOID ImageBase = NULL;

    RtlEnterCriticalSection (NtCurrentPeb()->LoaderLock);
    ModuleListHead = &NtCurrentPeb()->Ldr->InLoadOrderModuleList;
    Entry = ModuleListHead->Flink;
    while (Entry != ModuleListHead)
    {
        Module = CONTAINING_RECORD(Entry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);

        if ((ULONG_PTR)PcValue >= (ULONG_PTR)Module->DllBase &&
                (ULONG_PTR)PcValue < (ULONG_PTR)Module->DllBase + Module->SizeOfImage)
        {
            ImageBase = Module->DllBase;
            break;
        }
        Entry = Entry->Flink;
    }
    RtlLeaveCriticalSection (NtCurrentPeb()->LoaderLock);

    *BaseOfImage = ImageBase;
    return ImageBase;
}
Beispiel #7
0
/* Usermode only! */
VOID
NTAPI
RtlpAddHeapToProcessList(PHEAP Heap)
{
    PPEB Peb;

    /* Get PEB */
    Peb = RtlGetCurrentPeb();

    /* Acquire the lock */
    RtlEnterCriticalSection(&RtlpProcessHeapsListLock);

    //_SEH2_TRY {
    /* Check if max number of heaps reached */
    if (Peb->NumberOfHeaps == Peb->MaximumNumberOfHeaps)
    {
        // TODO: Handle this case
        ASSERT(FALSE);
    }

    /* Add the heap to the process heaps */
    Peb->ProcessHeaps[Peb->NumberOfHeaps] = Heap;
    Peb->NumberOfHeaps++;
    Heap->ProcessHeapsListIndex = (USHORT)Peb->NumberOfHeaps;
    // } _SEH2_FINALLY {

    /* Release the lock */
    RtlLeaveCriticalSection(&RtlpProcessHeapsListLock);

    // } _SEH2_END
}
Beispiel #8
0
/***********************************************************************
 *       TIME_GetBias [internal]
 *
 * Helper function calculates delta local time from UTC. 
 *
 * PARAMS
 *   utc [I] The current utc time.
 *   pdaylight [I] Local daylight.
 *
 * RETURNS
 *   The bias for the current timezone.
 */
static LONG TIME_GetBias(void)
{
    static time_t last_utc;
    static LONG last_bias;
    LONG ret;
    time_t utc;

    utc = time( NULL );

    RtlEnterCriticalSection( &TIME_tz_section );
    if (utc != last_utc)
    {
        RTL_DYNAMIC_TIME_ZONE_INFORMATION tzi;
        int is_dst = init_tz_info( &tzi );

	last_utc = utc;
        last_bias = tzi.Bias;
        last_bias += is_dst ? tzi.DaylightBias : tzi.StandardBias;
        last_bias *= SECSPERMIN;
    }

    ret = last_bias;

    RtlLeaveCriticalSection( &TIME_tz_section );
    return ret;
}
Beispiel #9
0
static VOID
ConSrvFreeHandlesTable(IN PCONSOLE_PROCESS_DATA ProcessData)
{
    RtlEnterCriticalSection(&ProcessData->HandleTableLock);

    if (ProcessData->HandleTable != NULL)
    {
        ULONG i;

        /*
         * ProcessData->ConsoleHandle is NULL (and the assertion fails) when
         * ConSrvFreeHandlesTable is called in ConSrvConnect during the
         * allocation of a new console.
         */
        // ASSERT(ProcessData->ConsoleHandle);
        if (ProcessData->ConsoleHandle != NULL)
        {
            /* Close all the console handles */
            for (i = 0; i < ProcessData->HandleTableSize; i++)
            {
                ConSrvCloseHandle(&ProcessData->HandleTable[i]);
            }
        }
        /* Free the handles table memory */
        ConsoleFreeHeap(ProcessData->HandleTable);
        ProcessData->HandleTable = NULL;
    }

    ProcessData->HandleTableSize = 0;

    RtlLeaveCriticalSection(&ProcessData->HandleTableLock);
}
Beispiel #10
0
VOID
LockConsole(
    IN PCONSOLE_INFORMATION Console
)

/*++

Routine Description:

    This routine locks the console.This routine is only defined
    in debug builds.

Arguments:

    none.

Return Value:

    none.

--*/

{
    RtlEnterCriticalSection(&(Console->ConsoleLock));
}
Beispiel #11
0
PDBGP_APP_THREAD
DbgpIsAppInHashTable(
    IN PCLIENT_ID AppClientId
    )

/*++

Routine Description:

    This routine scans the application thread hash table looking
    for an application thread that matches the specified client id.

    If a matching application thread is found, then its address is
    returned.

Arguments:

    AppClientId - Supplies the address of ClientId of the application
        thread to locate.

Return Value:

    NULL - No application thread with a matching ClientId could be located.

    NON-NULL - Returns the address of the application thread that
        matches the specified ClientId.

--*/

{
    ULONG Index;
    PLIST_ENTRY Head, Next;
    PDBGP_APP_THREAD AppThread;

    RtlEnterCriticalSection(&DbgpHashTableLock);

    Index = DBGP_THREAD_CLIENT_ID_TO_INDEX(AppClientId);

    Head = &DbgpAppThreadHashTable[Index];
    Next = Head->Flink;

    while ( Next != Head ) {
        AppThread = CONTAINING_RECORD(Next,DBGP_APP_THREAD,HashTableLinks);
        if ( DBGP_CLIENT_IDS_EQUAL(
                &AppThread->AppClientId,
                AppClientId
                )) {
            RtlLeaveCriticalSection(&DbgpHashTableLock);
//DbgpDumpAppThread(AppThread);
            return AppThread;
        }
        Next = Next->Flink;
    }

    RtlLeaveCriticalSection(&DbgpHashTableLock);
#if DBG
//    DbgPrint("DBGSS: AppThread for %lx.%lx Not Found\n",AppClientId->UniqueProcess,AppClientId->UniqueThread);
#endif // DBG
    return NULL;
}
    HOOKFUNC NTSTATUS NTAPI MyRtlEnterCriticalSection(RTL_CRITICAL_SECTION *crit)
    {

        NTSTATUS rv = RtlEnterCriticalSection(crit);

        return rv;
    }
Beispiel #13
0
/*
 * @implemented
 */
PVOID NTAPI
RtlAddVectoredExceptionHandler(IN ULONG FirstHandler,
                               IN PVECTORED_EXCEPTION_HANDLER VectoredHandler)
{
  PRTL_VECTORED_EXCEPTION_HANDLER veh;

  veh = RtlAllocateHeap(RtlGetProcessHeap(),
                        0,
                        sizeof(RTL_VECTORED_EXCEPTION_HANDLER));
  if(veh != NULL)
  {
    veh->VectoredHandler = RtlEncodePointer(VectoredHandler);
    veh->Refs = 1;
    veh->Deleted = FALSE;
    RtlEnterCriticalSection(&RtlpVectoredExceptionLock);
    if(FirstHandler != 0)
    {
      InsertHeadList(&RtlpVectoredExceptionHead,
                     &veh->ListEntry);
    }
    else
    {
      InsertTailList(&RtlpVectoredExceptionHead,
                     &veh->ListEntry);
    }
    InterlockedIncrement (&RtlpVectoredExceptionsInstalled);
    RtlLeaveCriticalSection(&RtlpVectoredExceptionLock);
  }

  return veh;
}
Beispiel #14
0
/***********************************************************************
 *		VxDCall0 (KERNEL32.1)
 *		VxDCall1 (KERNEL32.2)
 *		VxDCall2 (KERNEL32.3)
 *		VxDCall3 (KERNEL32.4)
 *		VxDCall4 (KERNEL32.5)
 *		VxDCall5 (KERNEL32.6)
 *		VxDCall6 (KERNEL32.7)
 *		VxDCall7 (KERNEL32.8)
 *		VxDCall8 (KERNEL32.9)
 */
void WINAPI __regs_VxDCall( DWORD service, CONTEXT86 *context )
{
    int i;
    VxDCallProc proc = NULL;

    RtlEnterCriticalSection( &vxd_section );
    for (i = 0; i < NB_VXD_SERVICES; i++)
    {
        if (HIWORD(service) != vxd_services[i].service) continue;
        if (!vxd_services[i].module)  /* need to load it */
        {
            if ((vxd_services[i].module = LoadLibraryW( vxd_services[i].name )))
                vxd_services[i].proc = (VxDCallProc)GetProcAddress( vxd_services[i].module, "VxDCall" );
        }
        proc = vxd_services[i].proc;
        break;
    }
    RtlLeaveCriticalSection( &vxd_section );

    if (proc) context->Eax = proc( service, context );
    else
    {
        FIXME( "Unknown/unimplemented VxD (%08x)\n", service);
        context->Eax = 0xffffffff; /* FIXME */
    }
}
Beispiel #15
0
/* retrieve the DeviceIoControl function for a Vxd given a file handle */
static DeviceIoProc get_vxd_proc( HANDLE handle )
{
    DeviceIoProc ret = NULL;
    int status, i;
    IO_STATUS_BLOCK io;
    FILE_INTERNAL_INFORMATION info;

    status = NtQueryInformationFile( handle, &io, &info, sizeof(info), FileInternalInformation );
    if (status)
    {
        SetLastError( RtlNtStatusToDosError(status) );
        return NULL;
    }

    RtlEnterCriticalSection( &vxd_section );

    for (i = 0; i < MAX_VXD_MODULES; i++)
    {
        if (!vxd_modules[i].module) break;
        if (vxd_modules[i].index.QuadPart == info.IndexNumber.QuadPart)
        {
            if (!(ret = vxd_modules[i].proc)) SetLastError( ERROR_INVALID_FUNCTION );
            goto done;
        }
    }
    /* FIXME: Here we could go through the directory to find the VxD name and load it. */
    /* Let's wait to find out if there are actually apps out there that try to share   */
    /* VxD handles between processes, before we go to the trouble of implementing it.  */
    ERR( "handle %p not found in module list, inherited from another process?\n", handle );

done:
    RtlLeaveCriticalSection( &vxd_section );
    return ret;
}
Beispiel #16
0
NTSTATUS WINAPI
crLdrEnumerateLoadedModules(IN BOOLEAN            ReservedFlag,
                            IN PLDR_ENUM_CALLBACK EnumProc,
                            IN PVOID              Context)
{
    if (ReservedFlag || EnumProc == NULL) {
        return STATUS_INVALID_PARAMETER;
    }

    if (LdrpInLdrInit) {
        RtlEnterCriticalSection(&LdrpLoaderLock);
    }

    LIST_ENTRY *currentNode = PebLdr.InLoadOrderModuleList.Flink;
    BOOLEAN stop = FALSE;
    __try {
        while(currentNode != &PebLdr.InLoadOrderModuleList) {
            LDR_DATA_TABLE_ENTRY* entry = CONTAINING_RECORD(currentNode, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
            EnumProc(entry, Context, &stop);
            if (stop) {
                break;
            }
            currentNode = currentNode->Flink;
        }
    }
    __finally {
        if (LdrpInLdrInit) {
            RtlLeaveCriticalSection(&LdrpLoaderLock);
        }        
    }

    return STATUS_SUCCESS;
}
Beispiel #17
0
/* Usermode only! */
VOID
NTAPI
RtlpRemoveHeapFromProcessList(PHEAP Heap)
{
    PPEB Peb;
    PHEAP *Current, *Next;
    ULONG Count;

    /* Get PEB */
    Peb = RtlGetCurrentPeb();

    /* Acquire the lock */
    RtlEnterCriticalSection(&RtlpProcessHeapsListLock);

    /* Check if we don't need anything to do */
    if ((Heap->ProcessHeapsListIndex == 0) ||
        (Heap->ProcessHeapsListIndex > Peb->NumberOfHeaps) ||
        (Peb->NumberOfHeaps == 0))
    {
        /* Release the lock */
        RtlLeaveCriticalSection(&RtlpProcessHeapsListLock);

        return;
    }

    /* The process actually has more than one heap.
       Use classic, lernt from university times algorithm for removing an entry
       from a static array */

    Current = (PHEAP *)&Peb->ProcessHeaps[Heap->ProcessHeapsListIndex - 1];
    Next = Current + 1;

    /* How many items we need to shift to the left */
    Count = Peb->NumberOfHeaps - (Heap->ProcessHeapsListIndex - 1);

    /* Move them all in a loop */
    while (--Count)
    {
        /* Copy it and advance next pointer */
        *Current = *Next;

        /* Update its index */
        (*Current)->ProcessHeapsListIndex -= 1;

        /* Advance pointers */
        Current++;
        Next++;
    }

    /* Decrease total number of heaps */
    Peb->NumberOfHeaps--;

    /* Zero last unused item */
    Peb->ProcessHeaps[Peb->NumberOfHeaps] = NULL;
    Heap->ProcessHeapsListIndex = 0;

    /* Release the lock */
    RtlLeaveCriticalSection(&RtlpProcessHeapsListLock);
}
Beispiel #18
0
NTSTATUS
NTAPI
RtlEnterHeapLock(IN OUT PHEAP_LOCK Lock, IN BOOLEAN Exclusive)
{
    UNREFERENCED_PARAMETER(Exclusive);

    return RtlEnterCriticalSection(&Lock->CriticalSection);
}
Beispiel #19
0
static int wine_pthread_mutex_lock(pthread_mutex_t *mutex)
{
  if (!((wine_mutex)mutex)->critsect)
    mutex_real_init( mutex );

  RtlEnterCriticalSection(((wine_mutex)mutex)->critsect);
  return 0;
}
Beispiel #20
0
PDBGP_APP_PROCESS
DbgpIsAppProcessInHashTable(
    IN PCLIENT_ID AppClientId
    )

/*++

Routine Description:

    This routine scans the application process hash table looking for an
    application process whose ClientId.UniqueOrocess field matches the
    specified client id's.

    If a matching application process is found, then its address is
    returned.

Arguments:

    AppClientId - Supplies the address of ClientId of the application
        process to locate.

Return Value:

    NULL - No application process with a matching ClientId could be located.

    NON-NULL - Returns the address of the application process that
        matches the specified ClientId.

--*/

{
    ULONG Index;
    PLIST_ENTRY Head, Next;
    PDBGP_APP_PROCESS AppProcess;

    RtlEnterCriticalSection(&DbgpHashTableLock);

    Index = DBGP_PROCESS_CLIENT_ID_TO_INDEX(AppClientId);

    Head = &DbgpAppProcessHashTable[Index];
    Next = Head->Flink;

    while ( Next != Head ) {
        AppProcess = CONTAINING_RECORD(Next,DBGP_APP_PROCESS,HashTableLinks);
        if ( AppProcess->AppClientId.UniqueProcess == AppClientId->UniqueProcess) {
            RtlLeaveCriticalSection(&DbgpHashTableLock);
            return AppProcess;
        }
        Next = Next->Flink;
    }

    RtlLeaveCriticalSection(&DbgpHashTableLock);
#if DBG
//    DbgPrint("DBGSS: AppProcess for %lx.%lx Not Found\n",AppClientId->UniqueProcess,AppClientId->UniqueThread);
#endif // DBG
    return NULL;
}
Beispiel #21
0
VOID NTAPI BaseSrvCleanupVdmRecords(ULONG ProcessId)
{
    PLIST_ENTRY i;
    PVDM_CONSOLE_RECORD ConsoleRecord = NULL;
    PVDM_DOS_RECORD DosRecord;

    /* Enter the critical section */
    RtlEnterCriticalSection(&DosCriticalSection);

    /* Search for a record that has the same process handle */
    for (i = VDMConsoleListHead.Flink; i != &VDMConsoleListHead; i = i->Flink)
    {
        ConsoleRecord = CONTAINING_RECORD(i, VDM_CONSOLE_RECORD, Entry);

        if (ConsoleRecord->ProcessId == ProcessId)
        {
            /* Cleanup the DOS records */
            while (ConsoleRecord->DosListHead.Flink != &ConsoleRecord->DosListHead)
            {
                DosRecord = CONTAINING_RECORD(ConsoleRecord->DosListHead.Flink,
                                              VDM_DOS_RECORD,
                                              Entry);

                /* Set the event and close it */
                NtSetEvent(DosRecord->ServerEvent, NULL);
                NtClose(DosRecord->ServerEvent);

                /* Remove the DOS entry */
                if (DosRecord->CommandInfo) BaseSrvFreeVDMInfo(DosRecord->CommandInfo);
                RemoveEntryList(&DosRecord->Entry);
                RtlFreeHeap(BaseSrvHeap, 0, DosRecord);
            }

            if (ConsoleRecord->CurrentDirs != NULL)
            {
                /* Free the current directories */
                RtlFreeHeap(BaseSrvHeap, 0, ConsoleRecord->CurrentDirs);
                ConsoleRecord->CurrentDirs = NULL;
                ConsoleRecord->CurDirsLength = 0;
            }

            /* Close the process handle */
            if (ConsoleRecord->ProcessHandle) NtClose(ConsoleRecord->ProcessHandle);

            /* Close the event handle */
            if (ConsoleRecord->ServerEvent) NtClose(ConsoleRecord->ServerEvent);

            /* Remove the console record */
            i = i->Blink;
            RemoveEntryList(&ConsoleRecord->Entry);
            RtlFreeHeap(BaseSrvHeap, 0, ConsoleRecord);
        }
    }

    /* Leave the critical section */
    RtlLeaveCriticalSection(&DosCriticalSection);
}
Beispiel #22
0
PSMPKNOWNSUBSYS
SmpLocateKnownSubSysByType(
    IN ULONG ImageType
    )

/*++

Routine Description:

    This function scans the known sub system table looking for
    a matching image type.

Arguments:

    ImageType - Supplies the image type whose sub system is to be located.

Return Value:

    NULL - The image type does not match a known subsystem.

    NON-NULL - Returns the address of the known subsystem.

--*/

{

    PSMPKNOWNSUBSYS KnownSubSys = NULL;
    PLIST_ENTRY Next;

    //
    // Aquire known subsystem lock
    //

    RtlEnterCriticalSection(&SmpKnownSubSysLock);

    Next = SmpKnownSubSysHead.Flink;

    while ( Next != &SmpKnownSubSysHead ) {

        KnownSubSys = CONTAINING_RECORD(Next,SMPKNOWNSUBSYS,Links);
        Next = Next->Flink;

        if ( KnownSubSys->ImageType == ImageType ) {
            break;
        } else {
            KnownSubSys = NULL;
        }
    }

    //
    // Unlock known subsystems
    //

    RtlLeaveCriticalSection(&SmpKnownSubSysLock);

    return KnownSubSys;
}
Beispiel #23
0
static inline void NT_getCurrentTimeAndAdjustEpoch(struct timeval *t, struct timeval *prevActualTime){

    /* retrieve the current system time.  Unfortunately this function is the
       best resolution standard Unix time function that we could find.  It IS
       affected by system clock changes so we will manually have to check for
       epoch changes and adjust accordingly. 

       NOTE: the timer will stay stable if the current system time is adjusted
             backward.  However, since it cannot be reliably detected, it does
             not account for forward time adjustments.  At worst, the client
             app will see an expectedly large time gap that includes the change
             in time.  At least it won't have to deal with a potential 
             wrap-around situation.
    */
    gettimeofday (t, NULL);


    RtlEnterCriticalSection(&TIME_sync_cs);
    
    /* we've moved past the epoch => change the epoch ;) */
    if (t->tv_sec < server_starttime.tv_sec ||
        (t->tv_sec == server_starttime.tv_sec && t->tv_usec < server_starttime.tv_usec)){

        /* adjust the epoch to account for the current tick value and the modified start time */
        server_starttime.tv_sec = t->tv_sec - (prevActualTime->tv_sec - server_starttime.tv_sec);
        server_starttime.tv_usec = t->tv_usec - (prevActualTime->tv_usec - server_starttime.tv_usec);

        /* the microsecond counter wrapped around => correct it */
        if (server_starttime.tv_usec < 0){
            server_starttime.tv_sec--;
            server_starttime.tv_usec = 1000000 + server_starttime.tv_usec;
        }
    }

    /* the clock was adjusted => change the epoch to reflect the change.  This tick count will
       return with the same value as the previous call. */
    else if (t->tv_sec < prevActualTime->tv_sec ||
             (t->tv_sec == prevActualTime->tv_sec && t->tv_usec < prevActualTime->tv_usec)){

        /* adjust the epoch by the time delta */
        server_starttime.tv_sec -= (prevActualTime->tv_sec - t->tv_sec);
        server_starttime.tv_usec -= (prevActualTime->tv_usec - t->tv_usec);

        /* the microsecond counter wrapped around => correct it */
        if (server_starttime.tv_usec < 0){
            server_starttime.tv_sec--;
            server_starttime.tv_usec = 1000000 + server_starttime.tv_usec;
        }
    }
    
    /* update the previous time values */
    prevActualTime->tv_sec = t->tv_sec;
    prevActualTime->tv_usec = t->tv_usec;    

    RtlLeaveCriticalSection(&TIME_sync_cs);    
}
Beispiel #24
0
BOOL
WINAPI
InitUserApiHook(HINSTANCE hInstance, USERAPIHOOKPROC pfn)
{
  USERAPIHOOK uah;

  ResetUserApiHook(&uah);

  RtlEnterCriticalSection(&gcsUserApiHook);

  if (!pfn(uahLoadInit,&uah) ||  // Swap data, User32 to and Uxtheme from!
       uah.ForceResetUserApiHook != (FARPROC)ForceResetUserApiHook ||
       uah.size <= 0 )
  {
     RtlLeaveCriticalSection(&gcsUserApiHook);
     return FALSE;
  }

  if ( ghmodUserApiHook )
  {
     if ( ghmodUserApiHook != hInstance )
     {
        RtlLeaveCriticalSection(&gcsUserApiHook);
        pfn(uahStop, 0);
        return FALSE;
     }
     gcLoadUserApiHook++;
  }
  else
  {
     ghmodUserApiHook = hInstance;
     // Do not over write GetRealWindowOwner.
     RtlCopyMemory(&guah, &uah, sizeof(USERAPIHOOK) - sizeof(LONG));
     gpfnInitUserApi = pfn;
     gcLoadUserApiHook = 1;
     gfUserApiHook = 1;
     // Copy Message Masks
     CopyMsgMask(&guah.DefWndProcArray,
                 &uah.DefWndProcArray,
                 &grgbDwpLiteHookMsg,
                  sizeof(grgbDwpLiteHookMsg));

     CopyMsgMask(&guah.WndProcArray,
                 &uah.WndProcArray,
                 &grgbWndLiteHookMsg,
                  sizeof(grgbWndLiteHookMsg));

     CopyMsgMask(&guah.DlgProcArray,
                 &uah.DlgProcArray,
                 &grgbDlgLiteHookMsg,
                  sizeof(grgbDlgLiteHookMsg));
  }
  RtlLeaveCriticalSection(&gcsUserApiHook);
  return TRUE;
}
Beispiel #25
0
VOID
WINAPI
redirect_EnterCriticalSection(
    __inout LPCRITICAL_SECTION lpCriticalSection
    )
{
    /* XXX: invoking ntdll routine b/c DR is already doing so.
     * We've seen some alloc/free mismatches in Initialize and Delete
     * though (DrMem i#333, DR i#963) so be on the lookout.
     */
    RtlEnterCriticalSection(lpCriticalSection);
}
Beispiel #26
0
static int wine_pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
                                       const struct timespec *abstime)
{
  LARGE_INTEGER time;
  int last_waiter;
  wine_cond_detail *detail;

  if ( !((wine_cond)cond)->cond ) wine_cond_real_init(cond);
  detail = ((wine_cond)cond)->cond;

  /* Avoid race conditions. */
  RtlEnterCriticalSection (&detail->waiters_count_lock);
  detail->waiters_count++;
  RtlLeaveCriticalSection (&detail->waiters_count_lock);

  RtlLeaveCriticalSection (((wine_mutex)mutex)->critsect);

  time.QuadPart = (ULONGLONG)abstime->tv_sec * 10000000 + abstime->tv_nsec / 100;
  time.QuadPart = -time.QuadPart;
  NtWaitForMultipleObjects( 1, &detail->sema, FALSE, FALSE, &time );

  /* Reacquire lock to avoid race conditions. */
  RtlEnterCriticalSection (&detail->waiters_count_lock);

  /* We're no longer waiting... */
  detail->waiters_count--;

  /* Check to see if we're the last waiter after <pthread_cond_broadcast>. */
  last_waiter = detail->was_broadcast && detail->waiters_count == 0;

  RtlLeaveCriticalSection (&detail->waiters_count_lock);

  /*
   * If we're the last waiter thread during this particular broadcast
   * then let all the other threads proceed.
   */
  if (last_waiter) NtSetEvent( detail->waiters_done, NULL );
  RtlEnterCriticalSection (((wine_mutex)mutex)->critsect);
  return 0;
}
Beispiel #27
0
NTSTATUS
ApiPreamble(
    IN HANDLE ConsoleHandle,
    OUT PCONSOLE_INFORMATION *Console
)
{
    NTSTATUS Status;
#ifdef _X86_
    //Do not lock the console if we are in the special case:
    //(1). we are in the middle of handshaking with ntvdm doing
    //     full-screen to windowed mode transition
    //(2). the calling process is THE ntvdm process(this implies that the
    //     the console has vdm registered.
    //(3). the console handle is the same one.
    // if (1), (2) and (3) are true then the console is already locked
    // (locked by the windowproc while processing the WM_FULLSCREEN
    // message)

    RtlEnterCriticalSection(&ConsoleVDMCriticalSection);
    if (ConsoleVDMOnSwitching != NULL &&
            ConsoleVDMOnSwitching->ConsoleHandle == ConsoleHandle &&
            ConsoleVDMOnSwitching->VDMProcessId == CONSOLE_CLIENTPROCESSID())
    {
        *Console = ConsoleVDMOnSwitching;
        return STATUS_SUCCESS;
    }
    RtlLeaveCriticalSection(&ConsoleVDMCriticalSection);
#endif

    LockConsoleHandleTable();
    Status = DereferenceConsoleHandle(ConsoleHandle,
                                      Console
                                     );
    if (!NT_SUCCESS(Status)) {
        UnlockConsoleHandleTable();
        return((ULONG) Status);
    }
    LockConsole(*Console);
    UnlockConsoleHandleTable();

    //
    // Make sure the console has been initialized and the window is valid
    //

    if ((*Console)->hWnd == NULL || ((*Console)->Flags & CONSOLE_TERMINATING)) {
        KdPrint(("CONSRV: bogus window for console %lx\n", *Console));
        UnlockConsole(*Console);
        return STATUS_INVALID_HANDLE;
    }

    return Status;
}
Beispiel #28
0
NTSTATUS
ConSrvInheritHandlesTable(IN PCONSOLE_PROCESS_DATA SourceProcessData,
                          IN PCONSOLE_PROCESS_DATA TargetProcessData)
{
    NTSTATUS Status = STATUS_SUCCESS;
    ULONG i, j;

    RtlEnterCriticalSection(&SourceProcessData->HandleTableLock);

    /* Inherit a handles table only if there is no already */
    if (TargetProcessData->HandleTable != NULL /* || TargetProcessData->HandleTableSize != 0 */)
    {
        Status = STATUS_UNSUCCESSFUL;
        goto Quit;
    }

    /* Allocate a new handle table for the child process */
    TargetProcessData->HandleTable = ConsoleAllocHeap(HEAP_ZERO_MEMORY,
                                                      SourceProcessData->HandleTableSize
                                                        * sizeof(CONSOLE_IO_HANDLE));
    if (TargetProcessData->HandleTable == NULL)
    {
        Status = STATUS_NO_MEMORY;
        goto Quit;
    }

    TargetProcessData->HandleTableSize = SourceProcessData->HandleTableSize;

    /*
     * Parse the parent process' handles table and, for each handle,
     * do a copy of it and reference it, if the handle is inheritable.
     */
    for (i = 0, j = 0; i < SourceProcessData->HandleTableSize; i++)
    {
        if (SourceProcessData->HandleTable[i].Object != NULL &&
            SourceProcessData->HandleTable[i].Inheritable)
        {
            /*
             * Copy the handle data and increment the reference count of the
             * pointed object (via the call to ConSrvCreateHandleEntry == AdjustHandleCounts).
             */
            TargetProcessData->HandleTable[j] = SourceProcessData->HandleTable[i];
            AdjustHandleCounts(&TargetProcessData->HandleTable[j], +1);
            ++j;
        }
    }

Quit:
    RtlLeaveCriticalSection(&SourceProcessData->HandleTableLock);
    return Status;
}
Beispiel #29
0
PWINSOCK_ASYNC_CONTEXT_BLOCK
WWS32FindAndRemoveAsyncContext (
    IN HANDLE AsyncTaskHandle32
    )
{
    PWINSOCK_ASYNC_CONTEXT_BLOCK context;
    PLIST_ENTRY listEntry;

    RtlEnterCriticalSection( &WWS32CriticalSection );

    //
    // Walk the global list of async context blocks, looking for
    // one that matches the specified task handle.
    //

    for ( listEntry = WWS32AsyncContextBlockListHead.Flink;
          listEntry != &WWS32AsyncContextBlockListHead;
          listEntry = listEntry->Flink ) {

        context = CONTAINING_RECORD(
                      listEntry,
                      WINSOCK_ASYNC_CONTEXT_BLOCK,
                      ContextBlockListEntry
                      );

        if ( context->AsyncTaskHandle32 == AsyncTaskHandle32 ) {

            //
            // Found a match.  Remove it from the global list, leave
            // the critical section, and return the context block.
            //

            RemoveEntryList( &context->ContextBlockListEntry );
            RtlLeaveCriticalSection( &WWS32CriticalSection );

            return context;
        }
    }

    //
    // A matching context block was not found on the list.
    //

    RtlLeaveCriticalSection( &WWS32CriticalSection );

    return NULL;

} // WWS32FindAndRemoveAsyncContext
Beispiel #30
0
VOID
ConfigInfoRegistryUpdate( )

/*++

Routine Description:


Arguments:


Return Value:


--*/

{
   DWORD ReplicationType, ReplicationTime;

#if DBG
   if (TraceFlags & TRACE_FUNCTION_TRACE)
      dprintf(TEXT("LLS TRACE: ConfigInfoRegistryUpdate\n"));
#endif

   RtlEnterCriticalSection(&ConfigInfoLock);

   //
   // Update values from Registry
   //
   ReplicationTime = ConfigInfo.ReplicationTime;
   ReplicationType = ConfigInfo.ReplicationType;
   ConfigInfoRegistryInit( &ConfigInfo.UseEnterprise, ConfigInfo.EnterpriseServer,
                           &ConfigInfo.ReplicationType, &ConfigInfo.ReplicationTime,
                           &ConfigInfo.LogLevel );

   if ( (ConfigInfo.ReplicationTime == 0) && (LLS_REPLICATION_TYPE_TIME != ConfigInfo.ReplicationType) )
      ConfigInfo.ReplicationTime = DEFAULT_REPLICATION_TIME;

   //
   // Adjust replication time if it has changed
   //
   if ((ReplicationTime != ConfigInfo.ReplicationTime) || (ReplicationType != ConfigInfo.ReplicationType))
      ReplicationTimeSet();

   RtlLeaveCriticalSection(&ConfigInfoLock);

} // ConfigInfoRegistryUpdate