VirtualBox

Ignore:
Timestamp:
Dec 2, 2021 12:39:54 PM (3 years ago)
Author:
vboxsync
Message:

SUP: Map SUPSemEvent* onto IPRT's RTSemEvent* in driverless mode. This isn't quite perfect yet, since we don't implement RTSemEventMultiWaitEx in ring-3. bugref:10138

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/Support/SUPLibSem.cpp

    r82968 r92700  
    3535#include <VBox/param.h>
    3636#include <iprt/assert.h>
     37#include <iprt/semaphore.h>
     38#include <iprt/time.h>
    3739
    3840#include "SUPLibInternal.h"
     
    112114    AssertPtrReturn(phEvent, VERR_INVALID_POINTER);
    113115
    114     SUPSEMOP3 Req;
    115     int rc = supSemOp3(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)NIL_SUPSEMEVENT, SUPSEMOP3_CREATE, &Req);
    116     if (RT_SUCCESS(rc))
    117         *phEvent = (SUPSEMEVENT)(uintptr_t)Req.u.Out.hSem;
     116    int rc;
     117    if (!g_supLibData.fDriverless)
     118    {
     119        SUPSEMOP3 Req;
     120        rc = supSemOp3(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)NIL_SUPSEMEVENT, SUPSEMOP3_CREATE, &Req);
     121        if (RT_SUCCESS(rc))
     122            *phEvent = (SUPSEMEVENT)(uintptr_t)Req.u.Out.hSem;
     123    }
     124    else
     125    {
     126        RTSEMEVENT hEvent;
     127        rc = RTSemEventCreate(&hEvent);
     128        if (RT_SUCCESS(rc))
     129            *phEvent = (SUPSEMEVENT)hEvent;
     130    }
    118131    return rc;
    119132}
     
    124137    if (hEvent == NIL_SUPSEMEVENT)
    125138        return VINF_SUCCESS;
    126     return supSemOp2(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)hEvent, SUPSEMOP2_CLOSE, 0);
     139    int rc;
     140    if (!g_supLibData.fDriverless)
     141        rc = supSemOp2(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)hEvent, SUPSEMOP2_CLOSE, 0);
     142    else
     143        rc = RTSemEventDestroy((RTSEMEVENT)hEvent);
     144    return rc;
    127145}
    128146
     
    130148SUPDECL(int) SUPSemEventSignal(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent)
    131149{
    132     return supSemOp2(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)hEvent, SUPSEMOP2_SIGNAL, 0);
     150    int rc;
     151    if (!g_supLibData.fDriverless)
     152        rc = supSemOp2(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)hEvent, SUPSEMOP2_SIGNAL, 0);
     153    else
     154        rc = RTSemEventSignal((RTSEMEVENT)hEvent);
     155    return rc;
    133156}
    134157
     
    136159SUPDECL(int) SUPSemEventWaitNoResume(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent, uint32_t cMillies)
    137160{
    138     return supSemOp2(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)hEvent, SUPSEMOP2_WAIT_MS_REL, cMillies);
     161    int rc;
     162    if (!g_supLibData.fDriverless)
     163        rc = supSemOp2(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)hEvent, SUPSEMOP2_WAIT_MS_REL, cMillies);
     164    else
     165        rc = RTSemEventWaitNoResume((RTSEMEVENT)hEvent, cMillies);
     166    return rc;
    139167}
    140168
     
    142170SUPDECL(int) SUPSemEventWaitNsAbsIntr(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent, uint64_t uNsTimeout)
    143171{
    144     return supSemOp2(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)hEvent, SUPSEMOP2_WAIT_NS_ABS, uNsTimeout);
     172    int rc;
     173    if (!g_supLibData.fDriverless)
     174        rc = supSemOp2(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)hEvent, SUPSEMOP2_WAIT_NS_ABS, uNsTimeout);
     175    else
     176    {
     177#if 0
     178        rc = RTSemEventWaitEx((RTSEMEVENT)hEvent,
     179                              RTSEMWAIT_FLAGS_ABSOLUTE | RTSEMWAIT_FLAGS_NANOSECS | RTSEMWAIT_FLAGS_NORESUME, uNsTimeout);
     180#else
     181        uint64_t nsNow = RTTimeNanoTS();
     182        if (nsNow < uNsTimeout)
     183            rc = RTSemEventWaitNoResume((RTSEMEVENT)hEvent, (uNsTimeout - nsNow + RT_NS_1MS - 1) / RT_NS_1MS);
     184        else
     185            rc = VERR_TIMEOUT;
     186#endif
     187    }
     188    return rc;
    145189}
    146190
     
    148192SUPDECL(int) SUPSemEventWaitNsRelIntr(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent, uint64_t cNsTimeout)
    149193{
    150     return supSemOp2(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)hEvent, SUPSEMOP2_WAIT_NS_REL, cNsTimeout);
     194    int rc;
     195    if (!g_supLibData.fDriverless)
     196        rc = supSemOp2(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)hEvent, SUPSEMOP2_WAIT_NS_REL, cNsTimeout);
     197    else
     198    {
     199#if 0
     200        rc = RTSemEventWaitEx((RTSEMEVENT)hEvent,
     201                              RTSEMWAIT_FLAGS_RELATIVE | RTSEMWAIT_FLAGS_NANOSECS | RTSEMWAIT_FLAGS_NORESUME, cNsTimeout);
     202#else
     203        rc = RTSemEventWaitNoResume((RTSEMEVENT)hEvent, (cNsTimeout + RT_NS_1MS - 1) / RT_NS_1MS);
     204#endif
     205    }
     206    return rc;
    151207}
    152208
     
    154210SUPDECL(uint32_t) SUPSemEventGetResolution(PSUPDRVSESSION pSession)
    155211{
    156     SUPSEMOP3 Req;
    157     int rc = supSemOp3(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)NIL_SUPSEMEVENT, SUPSEMOP3_GET_RESOLUTION, &Req);
    158     if (RT_SUCCESS(rc))
    159         return Req.u.Out.cNsResolution;
    160     return 1000 / 100;
     212    if (!g_supLibData.fDriverless)
     213    {
     214        SUPSEMOP3 Req;
     215        int rc = supSemOp3(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)NIL_SUPSEMEVENT, SUPSEMOP3_GET_RESOLUTION, &Req);
     216        if (RT_SUCCESS(rc))
     217            return Req.u.Out.cNsResolution;
     218        return 1000 / 100;
     219    }
     220#if 0
     221    return RTSemEventGetResolution();
     222#else
     223    return RT_NS_1MS;
     224#endif
    161225}
    162226
     
    169233    AssertPtrReturn(phEventMulti, VERR_INVALID_POINTER);
    170234
    171     SUPSEMOP3 Req;
    172     int rc = supSemOp3(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)NIL_SUPSEMEVENTMULTI, SUPSEMOP3_CREATE, &Req);
    173     if (RT_SUCCESS(rc))
    174         *phEventMulti = (SUPSEMEVENTMULTI)(uintptr_t)Req.u.Out.hSem;
     235    int rc;
     236    if (!g_supLibData.fDriverless)
     237    {
     238        SUPSEMOP3 Req;
     239        rc = supSemOp3(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)NIL_SUPSEMEVENTMULTI, SUPSEMOP3_CREATE, &Req);
     240        if (RT_SUCCESS(rc))
     241            *phEventMulti = (SUPSEMEVENTMULTI)(uintptr_t)Req.u.Out.hSem;
     242    }
     243    else
     244    {
     245        RTSEMEVENTMULTI hEventMulti;
     246        rc = RTSemEventMultiCreate(&hEventMulti);
     247        if (RT_SUCCESS(rc))
     248            *phEventMulti = (SUPSEMEVENTMULTI)hEventMulti;
     249    }
    175250    return rc;
    176251}
     
    181256    if (hEventMulti == NIL_SUPSEMEVENTMULTI)
    182257        return VINF_SUCCESS;
    183     return supSemOp2(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)hEventMulti, SUPSEMOP2_CLOSE, 0);
     258    int rc;
     259    if (!g_supLibData.fDriverless)
     260        rc = supSemOp2(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)hEventMulti, SUPSEMOP2_CLOSE, 0);
     261    else
     262        rc = RTSemEventMultiDestroy((RTSEMEVENTMULTI)hEventMulti);
     263    return rc;
    184264}
    185265
     
    187267SUPDECL(int) SUPSemEventMultiSignal(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti)
    188268{
    189     return supSemOp2(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)hEventMulti, SUPSEMOP2_SIGNAL, 0);
     269    int rc;
     270    if (!g_supLibData.fDriverless)
     271        rc = supSemOp2(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)hEventMulti, SUPSEMOP2_SIGNAL, 0);
     272    else
     273        rc = RTSemEventMultiSignal((RTSEMEVENTMULTI)hEventMulti);
     274    return rc;
    190275}
    191276
     
    193278SUPDECL(int) SUPSemEventMultiReset(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti)
    194279{
    195     return supSemOp2(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)hEventMulti, SUPSEMOP2_RESET, 0);
     280    int rc;
     281    if (!g_supLibData.fDriverless)
     282        rc = supSemOp2(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)hEventMulti, SUPSEMOP2_RESET, 0);
     283    else
     284        rc = RTSemEventMultiReset((RTSEMEVENTMULTI)hEventMulti);
     285    return rc;
    196286}
    197287
     
    199289SUPDECL(int) SUPSemEventMultiWaitNoResume(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti, uint32_t cMillies)
    200290{
    201     return supSemOp2(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)hEventMulti, SUPSEMOP2_WAIT_MS_REL, cMillies);
     291    int rc;
     292    if (!g_supLibData.fDriverless)
     293        supSemOp2(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)hEventMulti, SUPSEMOP2_WAIT_MS_REL, cMillies);
     294    else
     295        rc = RTSemEventMultiWaitNoResume((RTSEMEVENTMULTI)hEventMulti, cMillies);
     296    return rc;
    202297}
    203298
     
    205300SUPDECL(int) SUPSemEventMultiWaitNsAbsIntr(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti, uint64_t uNsTimeout)
    206301{
    207     return supSemOp2(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)hEventMulti, SUPSEMOP2_WAIT_NS_ABS, uNsTimeout);
     302    int rc;
     303    if (!g_supLibData.fDriverless)
     304        rc = supSemOp2(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)hEventMulti, SUPSEMOP2_WAIT_NS_ABS, uNsTimeout);
     305    else
     306    {
     307#if 0
     308        rc = RTSemEventMultiWaitEx((RTSEMEVENTMULTI)hEventMulti,
     309                                   RTSEMWAIT_FLAGS_ABSOLUTE | RTSEMWAIT_FLAGS_NANOSECS | RTSEMWAIT_FLAGS_NORESUME, uNsTimeout);
     310#else
     311        uint64_t nsNow = RTTimeNanoTS();
     312        if (nsNow < uNsTimeout)
     313            rc = RTSemEventMultiWaitNoResume((RTSEMEVENTMULTI)hEventMulti, (uNsTimeout - nsNow + RT_NS_1MS - 1) / RT_NS_1MS);
     314        else
     315            rc = VERR_TIMEOUT;
     316#endif
     317    }
     318    return rc;
    208319}
    209320
     
    211322SUPDECL(int) SUPSemEventMultiWaitNsRelIntr(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti, uint64_t cNsTimeout)
    212323{
    213     return supSemOp2(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)hEventMulti, SUPSEMOP2_WAIT_NS_REL, cNsTimeout);
     324    int rc;
     325    if (!g_supLibData.fDriverless)
     326        rc = supSemOp2(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)hEventMulti, SUPSEMOP2_WAIT_NS_REL, cNsTimeout);
     327    else
     328    {
     329#if 0
     330        rc = RTSemEventMultiWaitEx((RTSEMEVENTMULTI)hEventMulti,
     331                                   RTSEMWAIT_FLAGS_RELATIVE | RTSEMWAIT_FLAGS_NANOSECS | RTSEMWAIT_FLAGS_NORESUME, cNsTimeout);
     332#else
     333        rc = RTSemEventMultiWaitNoResume((RTSEMEVENTMULTI)hEventMulti, (cNsTimeout + RT_NS_1MS - 1) / RT_NS_1MS);
     334#endif
     335    }
     336    return rc;
    214337}
    215338
     
    217340SUPDECL(uint32_t) SUPSemEventMultiGetResolution(PSUPDRVSESSION pSession)
    218341{
    219     SUPSEMOP3 Req;
    220     int rc = supSemOp3(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)NIL_SUPSEMEVENTMULTI, SUPSEMOP3_GET_RESOLUTION, &Req);
    221     if (RT_SUCCESS(rc))
    222         return Req.u.Out.cNsResolution;
    223     return 1000 / 100;
    224 }
    225 
     342    if (!g_supLibData.fDriverless)
     343    {
     344        SUPSEMOP3 Req;
     345        int rc = supSemOp3(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)NIL_SUPSEMEVENTMULTI, SUPSEMOP3_GET_RESOLUTION, &Req);
     346        if (RT_SUCCESS(rc))
     347            return Req.u.Out.cNsResolution;
     348        return 1000 / 100;
     349    }
     350#if 0
     351    return RTSemEventMultiGetResolution();
     352#else
     353    return RT_NS_1MS;
     354#endif
     355}
     356
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