VirtualBox

Changeset 4229 in vbox for trunk/src/VBox/Runtime


Ignore:
Timestamp:
Aug 19, 2007 4:24:51 PM (17 years ago)
Author:
vboxsync
Message:

Ported thread2-r0drv to Nt (completely untested).

Location:
trunk/src/VBox/Runtime
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/Makefile.kmk

    r4219 r4229  
    777777        r0drv/nt/spinlock-r0drv-nt.cpp \
    778778        r0drv/nt/thread-r0drv-nt.cpp \
     779        r0drv/nt/thread2-r0drv-nt.cpp \
    779780        string/strncmp.cpp
    780781
  • trunk/src/VBox/Runtime/include/internal/thread.h

    r4071 r4229  
    8585    RTTHREADSTATE volatile  enmState;
    8686#if defined(RT_OS_WINDOWS) && defined(IN_RING3)
    87     /** The thread handle.
     87    /** The thread handle
    8888     * This is not valid until the create function has returned! */
    8989    uintptr_t               hThread;
  • trunk/src/VBox/Runtime/r0drv/nt/thread2-r0drv-nt.cpp

    r4071 r4229  
    2222
    2323#include <iprt/thread.h>
     24#include <iprt/assert.h>
    2425#include <iprt/err.h>
    2526
    2627#include "internal/thread.h"
     28
     29
     30int rtThreadNativeInit(void)
     31{
     32    /* No TLS in Ring-0. :-/ */
     33    return VINF_SUCCESS;
     34}
    2735
    2836
     
    3240}
    3341
     42
     43int rtThreadNativeSetPriority(PRTTHREADINT pThread, RTTHREADTYPE enmType)
     44{
     45    /*
     46     * Convert the IPRT priority type to NT priority.
     47     *
     48     * The NT priority is in the range 0..32, with realtime starting
     49     * at 16 and the default for user processes at 8. (Should try find
     50     * the appropriate #defines for some of this...)
     51     */
     52    KPRIORITY Priority;
     53    switch (enmType)
     54    {
     55        case RTTHREADTYPE_INFREQUENT_POLLER:    Priority = 6; break;
     56        case RTTHREADTYPE_EMULATION:            Priority = 7; break;
     57        case RTTHREADTYPE_DEFAULT:              Priority = 8; break;
     58        case RTTHREADTYPE_MSG_PUMP:             Priority = 9; break;
     59        case RTTHREADTYPE_IO:                   Priority = LOW_REALTIME_PRIORITY; break;
     60        case RTTHREADTYPE_TIMER:                Priority = MAXIMUM_PRIORITY; break;
     61
     62        default:
     63            AssertMsgFailed(("enmType=%d\n", enmType));
     64            return VERR_INVALID_PARAMETER;
     65    }
     66
     67    /*
     68     * Do the actual modification.
     69     */
     70    NTSTATUS rc = KeSetPriorityThread((PKTHREAD)pThread->Core.Key, Priority);
     71    AssertMsg(NT_SUCCESS(rc), ("%#x\n", rc));
     72    return RTErrConvertFromNtStatus(rc);
     73}
     74
     75
     76int rtThreadNativeAdopt(PRTTHREADINT pThread)
     77{
     78    return VERR_NOT_IMPLEMENTED;
     79}
     80
     81
     82/**
     83 * Native kernel thread wrapper function.
     84 *
     85 * This will forward to rtThreadMain and do termination upon return.
     86 *
     87 * @param pvArg         Pointer to the argument package.
     88 */
     89static VOID __stdcall rtThreadNativeMain(PVOID pvArg)
     90{
     91    PETHREAD Self = PsGetCurrentThread();
     92    PRTTHREADINT pThread = (PRTTHREADINT)pvArg;
     93
     94    rtThreadMain(pThread, (RTNATIVETHREAD)Self, &pThread->szName[0]);
     95
     96    ObDereferenceObject(Self); /* the rtThreadNativeCreate ref. */
     97}
     98
     99
     100int rtThreadNativeCreate(PRTTHREADINT pThreadInt, PRTNATIVETHREAD pNativeThread)
     101{
     102    /*
     103     * PsCreateSysemThread create a thread an give us a handle in return.
     104     * We requests the object for that handle and then close it, so what
     105     * we keep around is the pointer to the thread object and not a handle.
     106     * The thread will dereference the object before returning.
     107     */
     108    HANDLE hThread = NULL;
     109    OBJECT_ATTRIBUTES ObjAttr;
     110    InitializeObjectAttributes(&ObjAttr, NULL, OBJ_KERNEL_HANDLE, NULL, NULL);
     111    NTSTATUS rc = PsCreateSystemThread(&hThread,
     112                                       THREAD_ALL_ACCESS,
     113                                       &ObjAttr,
     114                                       NULL /* ProcessHandle - kernel */,
     115                                       NULL /* ClientID - kernel */,
     116                                       rtThreadNativeMain,
     117                                       pThreadInt);
     118    if (NT_SUCCESS(rc))
     119    {
     120        PVOID pvThreadObj;
     121        rc = ObReferenceObjectByHandle(hThread, THREAD_ALL_ACCESS, NULL /* object type */,
     122                                       KernelMode, &pvThreadObj, NULL /* handle info */);
     123        if (NT_SUCCESS(rc))
     124        {
     125            ZwClose(hThread);
     126            *pNativeThread = (RTNATIVETHREAD)pvThreadObj;
     127        }
     128        else
     129            AssertMsgFailed(("%#x\n", rc));
     130    }
     131    return RTErrConvertFromNtStatus(rc);
     132}
     133
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette