VirtualBox

Changeset 70195 in vbox for trunk/src/VBox/Runtime/r3


Ignore:
Timestamp:
Dec 18, 2017 1:40:26 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
119769
Message:

IPRT/R3: Made the core work on NT 3.51 (still experimental).

Location:
trunk/src/VBox/Runtime/r3
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/nt/RTPathQueryInfo-nt.cpp

    r69705 r70195  
    4646    (   (a_UniStr)->Length == sizeof(a_wszType) - sizeof(RTUTF16) \
    4747     && memcmp((a_UniStr)->Buffer, a_wszType, sizeof(a_wszType) - sizeof(RTUTF16)) == 0)
     48
     49
     50/*********************************************************************************************************************************
     51*   Global Variables                                                                                                             *
     52*********************************************************************************************************************************/
     53extern decltype(NtQueryFullAttributesFile) *g_pfnNtQueryFullAttributesFile; /* init-win.cpp */
    4854
    4955
     
    378384     */
    379385    int rc = VINF_TRY_AGAIN;
    380     if (enmAddAttr != RTFSOBJATTRADD_UNIX)
     386    if (   enmAddAttr != RTFSOBJATTRADD_UNIX
     387        && g_pfnNtQueryFullAttributesFile)
    381388    {
    382389        InitializeObjectAttributes(&ObjAttr, pNtName, OBJ_CASE_INSENSITIVE, hRootDir, NULL);
    383         rcNt = NtQueryFullAttributesFile(&ObjAttr, &uBuf.NetOpenInfo);
     390        rcNt = g_pfnNtQueryFullAttributesFile(&ObjAttr, &uBuf.NetOpenInfo);
    384391        if (NT_SUCCESS(rcNt))
    385392        {
  • trunk/src/VBox/Runtime/r3/nt/pathint-nt.cpp

    r69705 r70195  
    3838#include <iprt/assert.h>
    3939
     40#include "../win/internal-r3-win.h"
     41
    4042
    4143/*********************************************************************************************************************************
    4244*   Global Variables                                                                                                             *
    4345*********************************************************************************************************************************/
    44 static char const g_szPrefixUnc[] = "\\??\\UNC\\";
    45 static char const g_szPrefix[]    = "\\??\\";
     46static char const g_szPrefixUnc[]      = "\\??\\UNC\\";
     47static char const g_szPrefix[]         = "\\??\\";
     48static char const g_szPrefixNt3xUnc[]  = "\\DosDevices\\UNC\\";
     49static char const g_szPrefixNt3x[]     = "\\DosDevices\\";
    4650
    4751
     
    6468        if (cwcLen < _32K - 1)
    6569        {
    66             pwszPath[0] = '\\';
    67             pwszPath[1] = '?';
    68             pwszPath[2] = '?';
    69             pwszPath[3] = '\\';
    70 
     70            *phRootDir = NULL;
     71            if (   g_enmWinVer >=  kRTWinOSType_NT4
     72                || g_enmWinVer == kRTWinOSType_UNKNOWN)
     73            {
     74                pwszPath[0] = '\\';
     75                pwszPath[1] = '?';
     76                pwszPath[2] = '?';
     77                pwszPath[3] = '\\';
     78
     79                pNtName->Buffer = pwszPath;
     80                pNtName->Length = (uint16_t)(cwcLen * sizeof(RTUTF16));
     81                pNtName->MaximumLength = pNtName->Length + sizeof(RTUTF16);
     82                return VINF_SUCCESS;
     83            }
     84
     85            rc = RTUtf16Realloc(&pwszPath, cwcLen + sizeof(g_szPrefixNt3x));
     86            if (RT_SUCCESS(rc))
     87            {
     88                memmove(&pwszPath[sizeof(g_szPrefixNt3x) - 1], &pwszPath[4], (cwcLen - 4 + 1) * sizeof(RTUTF16));
     89                for (uint32_t i = 0; i < sizeof(g_szPrefixNt3x) - 1; i++)
     90                    pwszPath[i] = g_szPrefixNt3x[i];
     91
     92                pNtName->Buffer = pwszPath;
     93                pNtName->Length = (uint16_t)((cwcLen - 4 + sizeof(g_szPrefixNt3x) - 1) * sizeof(RTUTF16));
     94                pNtName->MaximumLength = pNtName->Length + sizeof(RTUTF16);
     95                return VINF_SUCCESS;
     96            }
     97        }
     98
     99        RTUtf16Free(pwszPath);
     100        rc = VERR_FILENAME_TOO_LONG;
     101    }
     102    return rc;
     103}
     104
     105
     106/**
     107 * Handles the pass thru case for UTF-16 input.
     108 * Win32 path uses "\\?\" prefix which is converted to "\??\" NT prefix.
     109 *
     110 * @returns IPRT status code.
     111 * @param   pNtName             Where to return the NT name.
     112 * @param   phRootDir           Stores NULL here, as we don't use it.
     113 * @param   pwszWinPath         The UTF-16 windows-style path.
     114 * @param   cwcWinPath          The length of the windows-style input path.
     115 */
     116static int rtNtPathFromWinUtf16PassThru(struct _UNICODE_STRING *pNtName, PHANDLE phRootDir,
     117                                        PCRTUTF16 pwszWinPath, size_t cwcWinPath)
     118{
     119    /* Check length and allocate memory for it. */
     120    int rc;
     121    if (cwcWinPath < _32K - 1)
     122    {
     123        size_t const cwcExtraPrefix =  g_enmWinVer >=  kRTWinOSType_NT4 || g_enmWinVer == kRTWinOSType_UNKNOWN
     124                                    ? 0 : sizeof(g_szPrefixNt3x) - 1 - 4;
     125        PRTUTF16 pwszNtPath = (PRTUTF16)RTUtf16Alloc((cwcExtraPrefix + cwcWinPath + 1) * sizeof(RTUTF16));
     126        if (pwszNtPath)
     127        {
     128            /* Intialize the path. */
     129            if (!cwcExtraPrefix)
     130            {
     131                pwszNtPath[0] = '\\';
     132                pwszNtPath[1] = '?';
     133                pwszNtPath[2] = '?';
     134                pwszNtPath[3] = '\\';
     135            }
     136            else
     137                for (uint32_t i = 0; i < sizeof(g_szPrefixNt3x) - 1; i++)
     138                    pwszNtPath[i] = g_szPrefixNt3x[i];
     139            memcpy(pwszNtPath + cwcExtraPrefix + 4, pwszWinPath + 4, (cwcWinPath - 4) * sizeof(RTUTF16));
     140            pwszNtPath[cwcExtraPrefix + cwcWinPath] = '\0';
     141
     142            /* Initialize the return values. */
     143            pNtName->Buffer = pwszNtPath;
     144            pNtName->Length = (uint16_t)(cwcExtraPrefix + cwcWinPath * sizeof(RTUTF16));
     145            pNtName->MaximumLength = pNtName->Length + sizeof(RTUTF16);
     146            *phRootDir = NULL;
     147
     148            rc = VINF_SUCCESS;
     149        }
     150        else
     151            rc = VERR_NO_UTF16_MEMORY;
     152    }
     153    else
     154        rc = VERR_FILENAME_TOO_LONG;
     155    return rc;
     156}
     157
     158
     159
     160
     161
     162/**
     163 * Converts the path to UTF-16 and sets all the return values.
     164 *
     165 * @returns IPRT status code.
     166 * @param   pNtName             Where to return the NT name.
     167 * @param   phRootDir           Where to return the root handle, if applicable.
     168 * @param   pszPath             The UTF-8 path.
     169 */
     170static int rtNtPathUtf8ToUniStr(struct _UNICODE_STRING *pNtName, PHANDLE phRootDir, const char *pszPath)
     171{
     172    PRTUTF16 pwszPath = NULL;
     173    size_t   cwcLen;
     174    int rc = RTStrToUtf16Ex(pszPath, RTSTR_MAX, &pwszPath, 0, &cwcLen);
     175    if (RT_SUCCESS(rc))
     176    {
     177        if (cwcLen < _32K - 1)
     178        {
    71179            pNtName->Buffer = pwszPath;
    72180            pNtName->Length = (uint16_t)(cwcLen * sizeof(RTUTF16));
     
    84192
    85193/**
    86  * Handles the pass thru case for UTF-16 input.
    87  * Win32 path uses "\\?\" prefix which is converted to "\??\" NT prefix.
    88  *
    89  * @returns IPRT status code.
    90  * @param   pNtName             Where to return the NT name.
    91  * @param   phRootDir           Stores NULL here, as we don't use it.
    92  * @param   pwszWinPath         The UTF-16 windows-style path.
    93  * @param   cwcWinPath          The length of the windows-style input path.
    94  */
    95 static int rtNtPathFromWinUtf16PassThru(struct _UNICODE_STRING *pNtName, PHANDLE phRootDir,
    96                                         PCRTUTF16 pwszWinPath, size_t cwcWinPath)
    97 {
    98     /* Check length and allocate memory for it. */
    99     int rc;
    100     if (cwcWinPath < _32K - 1)
    101     {
    102         PRTUTF16 pwszNtPath = (PRTUTF16)RTUtf16Alloc((cwcWinPath + 1) * sizeof(RTUTF16));
    103         if (pwszNtPath)
    104         {
    105             /* Intialize the path. */
    106             pwszNtPath[0] = '\\';
    107             pwszNtPath[1] = '?';
    108             pwszNtPath[2] = '?';
    109             pwszNtPath[3] = '\\';
    110             memcpy(pwszNtPath + 4, pwszWinPath + 4, (cwcWinPath - 4) * sizeof(RTUTF16));
    111             pwszNtPath[cwcWinPath] = '\0';
    112 
    113             /* Initialize the return values. */
    114             pNtName->Buffer = pwszNtPath;
    115             pNtName->Length = (uint16_t)(cwcWinPath * sizeof(RTUTF16));
    116             pNtName->MaximumLength = pNtName->Length + sizeof(RTUTF16);
    117             *phRootDir = NULL;
    118 
    119             rc = VINF_SUCCESS;
    120         }
    121         else
    122             rc = VERR_NO_UTF16_MEMORY;
    123     }
    124     else
    125         rc = VERR_FILENAME_TOO_LONG;
    126     return rc;
    127 }
    128 
    129 
    130 
    131 
    132 
    133 /**
    134  * Converts the path to UTF-16 and sets all the return values.
    135  *
    136  * @returns IPRT status code.
    137  * @param   pNtName             Where to return the NT name.
    138  * @param   phRootDir           Where to return the root handle, if applicable.
    139  * @param   pszPath             The UTF-8 path.
    140  */
    141 static int rtNtPathUtf8ToUniStr(struct _UNICODE_STRING *pNtName, PHANDLE phRootDir, const char *pszPath)
    142 {
    143     PRTUTF16 pwszPath = NULL;
    144     size_t   cwcLen;
    145     int rc = RTStrToUtf16Ex(pszPath, RTSTR_MAX, &pwszPath, 0, &cwcLen);
    146     if (RT_SUCCESS(rc))
    147     {
    148         if (cwcLen < _32K - 1)
    149         {
    150             pNtName->Buffer = pwszPath;
    151             pNtName->Length = (uint16_t)(cwcLen * sizeof(RTUTF16));
    152             pNtName->MaximumLength = pNtName->Length + sizeof(RTUTF16);
    153             *phRootDir = NULL;
    154             return VINF_SUCCESS;
    155         }
    156 
    157         RTUtf16Free(pwszPath);
    158         rc = VERR_FILENAME_TOO_LONG;
    159     }
    160     return rc;
    161 }
    162 
    163 
    164 /**
    165194 * Converts a windows-style path to NT format and encoding.
    166195 *
     
    179208     * Very simple conversion of a win32-like path into an NT path.
    180209     */
    181     const char *pszPrefix = g_szPrefix;
    182     size_t      cchPrefix = sizeof(g_szPrefix) - 1;
     210    const char *pszPrefix;
     211    size_t      cchPrefix;
     212    if (   g_enmWinVer >=  kRTWinOSType_NT4
     213        || g_enmWinVer == kRTWinOSType_UNKNOWN)
     214    {
     215        pszPrefix = g_szPrefix;
     216        cchPrefix = sizeof(g_szPrefix) - 1;
     217    }
     218    else
     219    {
     220        pszPrefix = g_szPrefixNt3x;
     221        cchPrefix = sizeof(g_szPrefixNt3x) - 1;
     222    }
     223
    183224    size_t      cchSkip   = 0;
    184 
    185225    if (   RTPATH_IS_SLASH(pszPath[0])
    186226        && RTPATH_IS_SLASH(pszPath[1])
     
    211251        {
    212252            /* UNC */
    213             pszPrefix = g_szPrefixUnc;
    214             cchPrefix = sizeof(g_szPrefixUnc) - 1;
     253            if (   g_enmWinVer >=  kRTWinOSType_NT4
     254                || g_enmWinVer == kRTWinOSType_UNKNOWN)
     255            {
     256                pszPrefix = g_szPrefixUnc;
     257                cchPrefix = sizeof(g_szPrefixUnc) - 1;
     258            }
     259            else
     260            {
     261                pszPrefix = g_szPrefixNt3xUnc;
     262                cchPrefix = sizeof(g_szPrefixNt3xUnc) - 1;
     263            }
    215264            cchSkip   = 2;
    216265        }
  • trunk/src/VBox/Runtime/r3/socket.cpp

    r69111 r70195  
    7171#include "internal/socket.h"
    7272#include "internal/string.h"
     73#ifdef RT_OS_WINDOWS
     74# include "win/internal-r3-win.h"
     75#endif
    7376
    7477
     
    187190{
    188191#ifdef RT_OS_WINDOWS
    189     return RTErrConvertFromWin32(WSAGetLastError());
     192    if (g_pfnWSAGetLastError)
     193        return RTErrConvertFromWin32(g_pfnWSAGetLastError());
     194    return VERR_NET_IO_ERROR;
    190195#else
    191196    return RTErrConvertFromErrno(errno);
     
    200205{
    201206#ifdef RT_OS_WINDOWS
    202     WSASetLastError(0);
     207    if (g_pfnWSASetLastError)
     208        g_pfnWSASetLastError(0);
    203209#else
    204210    errno = 0;
     
    215221{
    216222#ifdef RT_OS_WINDOWS
    217     return RTErrConvertFromWin32(WSAGetLastError());
     223    if (g_pfnWSAGetLastError)
     224        return RTErrConvertFromWin32(g_pfnWSAGetLastError());
     225    return VERR_UNRESOLVED_ERROR;
    218226#else
    219227    switch (h_errno)
     
    355363{
    356364#ifdef RT_OS_WINDOWS
    357     u_long  uBlocking = fBlocking ? 0 : 1;
    358     if (ioctlsocket(pThis->hNative, FIONBIO, &uBlocking))
     365    AssertReturn(g_pfnioctlsocket, VERR_NOT_SUPPORTED);
     366    u_long uBlocking = fBlocking ? 0 : 1;
     367    if (g_pfnioctlsocket(pThis->hNative, FIONBIO, &uBlocking))
    359368        return rtSocketError();
    360369
    361370#else
    362     int     fFlags    = fcntl(pThis->hNative, F_GETFL, 0);
     371    int fFlags = fcntl(pThis->hNative, F_GETFL, 0);
    363372    if (fFlags == -1)
    364373        return rtSocketError();
     
    448457DECLHIDDEN(int) rtSocketCreate(PRTSOCKET phSocket, int iDomain, int iType, int iProtocol)
    449458{
     459#ifdef RT_OS_WINDOWS
     460    AssertReturn(g_pfnsocket, VERR_NOT_SUPPORTED);
     461    AssertReturn(g_pfnclosesocket, VERR_NOT_SUPPORTED);
     462#endif
     463
    450464    /*
    451465     * Create the socket.
    452466     */
     467#ifdef RT_OS_WINDOWS
     468    RTSOCKETNATIVE hNative = g_pfnsocket(iDomain, iType, iProtocol);
     469#else
    453470    RTSOCKETNATIVE hNative = socket(iDomain, iType, iProtocol);
     471#endif
    454472    if (hNative == NIL_RTSOCKETNATIVE)
    455473        return rtSocketError();
     
    462480    {
    463481#ifdef RT_OS_WINDOWS
    464         closesocket(hNative);
     482        g_pfnclosesocket(hNative);
    465483#else
    466484        close(hNative);
     
    510528
    511529#ifdef RT_OS_WINDOWS
    512             if (closesocket(hNative))
     530            AssertReturn(g_pfnclosesocket, VERR_NOT_SUPPORTED);
     531            if (g_pfnclosesocket(hNative))
    513532#else
    514533            if (close(hNative))
     
    532551        {
    533552            pThis->hEvent = WSA_INVALID_EVENT;
    534             WSACloseEvent(hEvent);
     553            Assert(g_pfnWSACloseEvent);
     554            if (g_pfnWSACloseEvent)
     555                g_pfnWSACloseEvent(hEvent);
    535556        }
    536557#endif
     
    644665    AssertPtrNullReturn(pszAddress, VERR_INVALID_POINTER);
    645666
    646 #ifdef RT_OS_WINDOWS
    647     /*
    648      * Initialize WinSock and check version.
    649      */
    650     WORD    wVersionRequested = MAKEWORD(1, 1);
    651     WSADATA wsaData;
    652     rc = WSAStartup(wVersionRequested, &wsaData);
    653     if (wsaData.wVersion != wVersionRequested)
    654     {
    655         AssertMsgFailed(("Wrong winsock version\n"));
    656         return VERR_NOT_SUPPORTED;
    657     }
    658 #endif
    659 
    660667    /*
    661668     * Resolve the address. Pretty crude at the moment, but we have to make
     
    676683    }
    677684
     685#ifdef RT_OS_WINDOWS
     686    /* Initialize WinSock and check version before we call gethostbyname. */
     687    if (   !g_pfnWSAStartup
     688        || !g_pfngethostbyname)
     689        return VERR_NOT_SUPPORTED;
     690    WORD    wVersionRequested = MAKEWORD(1, 1);
     691    WSADATA wsaData;
     692    RT_ZERO(wsaData);
     693    rc = g_pfnWSAStartup(wVersionRequested, &wsaData);
     694    if (wsaData.wVersion != wVersionRequested)
     695    {
     696        AssertMsgFailed(("Wrong winsock version\n"));
     697        return VERR_NOT_SUPPORTED;
     698    }
     699# define gethostbyname g_pfngethostbyname
     700#endif
     701
    678702    struct hostent *pHostEnt;
    679703    pHostEnt = gethostbyname(pszAddress);
     
    696720        return VERR_NET_ADDRESS_FAMILY_NOT_SUPPORTED;
    697721
     722#ifdef RT_OS_WINDOWS
     723# undef gethostbyname
     724#endif
    698725    return VINF_SUCCESS;
    699726}
     
    748775     * Winsock2 init
    749776     */
     777    if (   !g_pfnWSAStartup
     778        || !g_pfngetaddrinfo
     779        || !g_pfnfreeaddrinfo)
     780        return VERR_NOT_SUPPORTED;
    750781    /** @todo someone should check if we really need 2, 2 here */
    751782    WORD    wVersionRequested = MAKEWORD(2, 2);
    752783    WSADATA wsaData;
     784    RT_ZERO(wszData);
    753785    rc = WSAStartup(wVersionRequested, &wsaData);
    754786    if (wsaData.wVersion != wVersionRequested)
     
    757789        return VERR_NOT_SUPPORTED;
    758790    }
     791#  define getaddrinfo  g_pfngetaddrinfo
     792#  define freeaddrinfo g_pfnfreeaddrinfo
    759793# endif
    760794
    761795    /** @todo r=bird: getaddrinfo and freeaddrinfo breaks the additions on NT4. */
    762796    struct addrinfo *pgrResults = NULL;
    763     rc = getaddrinfo(pszHost, "", &grHints, &pgrResults);
     797    rc = g_pfngetaddrinfo(pszHost, "", &grHints, &pgrResults);
    764798    if (rc != 0)
    765799        return VERR_NET_ADDRESS_NOT_AVAILABLE;
     
    822856        *penmAddrType = enmAddrType;
    823857    return rc;
     858
     859# ifdef RT_OS_WINDOWS
     860#  undef getaddrinfo
     861#  undef freeaddrinfo
     862# endif
    824863#endif /* !RT_OS_OS2 */
    825864}
     
    836875    AssertReturn(cbBuffer > 0, VERR_INVALID_PARAMETER);
    837876    AssertPtr(pvBuffer);
     877#ifdef RT_OS_WINDOWS
     878    AssertReturn(g_pfnrecv, VERR_NOT_SUPPORTED);
     879# define recv g_pfnrecv
     880#endif
    838881    AssertReturn(rtSocketTryLock(pThis), VERR_CONCURRENT_ACCESS);
    839882
     
    890933
    891934    rtSocketUnlock(pThis);
     935#ifdef RT_OS_WINDOWS
     936# undef recv
     937#endif
    892938    return rc;
    893939}
     
    905951    AssertPtr(pvBuffer);
    906952    AssertPtr(pcbRead);
     953#ifdef RT_OS_WINDOWS
     954    AssertReturn(g_pfnrecvfrom, VERR_NOT_SUPPORTED);
     955# define recvfrom g_pfnrecvfrom
     956#endif
    907957    AssertReturn(rtSocketTryLock(pThis), VERR_CONCURRENT_ACCESS);
    908958
     
    944994
    945995    rtSocketUnlock(pThis);
     996#ifdef RT_OS_WINDOWS
     997# undef recvfrom
     998#endif
    946999    return rc;
    9471000}
     
    9561009    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
    9571010    AssertReturn(pThis->u32Magic == RTSOCKET_MAGIC, VERR_INVALID_HANDLE);
     1011#ifdef RT_OS_WINDOWS
     1012    AssertReturn(g_pfnsend, VERR_NOT_SUPPORTED);
     1013# define send g_pfnsend
     1014#endif
    9581015    AssertReturn(rtSocketTryLock(pThis), VERR_CONCURRENT_ACCESS);
    9591016
     
    10131070
    10141071    rtSocketUnlock(pThis);
     1072#ifdef RT_OS_WINDOWS
     1073# undef send
     1074#endif
    10151075    return rc;
    10161076}
     
    10251085    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
    10261086    AssertReturn(pThis->u32Magic == RTSOCKET_MAGIC, VERR_INVALID_HANDLE);
     1087#ifdef RT_OS_WINDOWS
     1088    AssertReturn(g_pfnsendto, VERR_NOT_SUPPORTED);
     1089# define sendto g_pfnsendto
     1090#endif
    10271091
    10281092    /* no locking since UDP reads may be done concurrently to writes, and
     
    10661130        rc = VERR_TOO_MUCH_DATA;
    10671131
    1068     rtSocketUnlock(pThis);
     1132    ///@todo rtSocketUnlock(pThis);
     1133#ifdef RT_OS_WINDOWS
     1134# undef sendto
     1135#endif
    10691136    return rc;
    10701137}
     
    10791146    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
    10801147    AssertReturn(pThis->u32Magic == RTSOCKET_MAGIC, VERR_INVALID_HANDLE);
     1148#ifdef RT_OS_WINDOWS
     1149    AssertReturn(g_pfnsendto, VERR_NOT_SUPPORTED);
     1150# define sendto g_pfnsendto
     1151#endif
    10811152
    10821153    /* no locking since UDP reads may be done concurrently to writes, and
     
    11201191        rc = VERR_TOO_MUCH_DATA;
    11211192
    1122     rtSocketUnlock(pThis);
     1193    /// @todo rtSocketUnlock(pThis);
     1194#ifdef RT_OS_WINDOWS
     1195# undef sendto
     1196#endif
    11231197    return rc;
    11241198}
     
    11461220    rc = VERR_NO_TMP_MEMORY;
    11471221#ifdef RT_OS_WINDOWS
    1148     AssertCompileSize(WSABUF, sizeof(RTSGSEG));
    1149     AssertCompileMemberSize(WSABUF, buf, RT_SIZEOFMEMB(RTSGSEG, pvSeg));
    1150 
    1151     LPWSABUF paMsg = (LPWSABUF)RTMemTmpAllocZ(pSgBuf->cSegs * sizeof(WSABUF));
    1152     if (paMsg)
    1153     {
    1154         for (unsigned i = 0; i < pSgBuf->cSegs; i++)
     1222    if (g_pfnWSASend)
     1223    {
     1224        AssertCompileSize(WSABUF, sizeof(RTSGSEG));
     1225        AssertCompileMemberSize(WSABUF, buf, RT_SIZEOFMEMB(RTSGSEG, pvSeg));
     1226
     1227        LPWSABUF paMsg = (LPWSABUF)RTMemTmpAllocZ(pSgBuf->cSegs * sizeof(WSABUF));
     1228        if (paMsg)
    11551229        {
    1156             paMsg[i].buf = (char *)pSgBuf->paSegs[i].pvSeg;
    1157             paMsg[i].len = (u_long)pSgBuf->paSegs[i].cbSeg;
     1230            for (unsigned i = 0; i < pSgBuf->cSegs; i++)
     1231            {
     1232                paMsg[i].buf = (char *)pSgBuf->paSegs[i].pvSeg;
     1233                paMsg[i].len = (u_long)pSgBuf->paSegs[i].cbSeg;
     1234            }
     1235
     1236            DWORD dwSent;
     1237            int hrc = g_pfnWSASend(pThis->hNative, paMsg, pSgBuf->cSegs, &dwSent, MSG_NOSIGNAL, NULL, NULL);
     1238            if (!hrc)
     1239                rc = VINF_SUCCESS;
     1240    /** @todo check for incomplete writes */
     1241            else
     1242                rc = rtSocketError();
     1243
     1244            RTMemTmpFree(paMsg);
    11581245        }
    1159 
    1160         DWORD dwSent;
    1161         int hrc = WSASend(pThis->hNative, paMsg, pSgBuf->cSegs, &dwSent,
    1162                           MSG_NOSIGNAL, NULL, NULL);
    1163         if (!hrc)
    1164             rc = VINF_SUCCESS;
    1165 /** @todo check for incomplete writes */
    1166         else
    1167             rc = rtSocketError();
    1168 
    1169         RTMemTmpFree(paMsg);
    1170     }
     1246    }
     1247    else if (g_pfnsend)
     1248    {
     1249        rc = VINF_SUCCESS;
     1250        for (uint32_t iSeg = 0; iSeg < pSgBuf->cSegs; iSeg++)
     1251        {
     1252            uint8_t const *pbSeg = (uint8_t const *)pSgBuf->paSegs[iSeg].pvSeg;
     1253            size_t         cbSeg = pSgBuf->paSegs[iSeg].cbSeg;
     1254            int            cbNow;
     1255            ssize_t        cbWritten;
     1256            for (;;)
     1257            {
     1258                cbNow = cbSeg >= RTSOCKET_MAX_WRITE ? RTSOCKET_MAX_WRITE : (int)cbSeg;
     1259                cbWritten = g_pfnsend(pThis->hNative, (const char *)pbSeg, cbNow, MSG_NOSIGNAL);
     1260                if ((size_t)cbWritten >= cbSeg || cbWritten < 0)
     1261                    break;
     1262                pbSeg += cbWritten;
     1263                cbSeg -= cbWritten;
     1264            }
     1265            if (cbWritten < 0)
     1266            {
     1267                rc = rtSocketError();
     1268                break;
     1269            }
     1270        }
     1271    }
     1272    else
     1273        rc = VERR_NOT_SUPPORTED;
    11711274
    11721275#else  /* !RT_OS_WINDOWS */
     
    12461349    AssertPtr(pvBuffer);
    12471350    AssertPtrReturn(pcbRead, VERR_INVALID_PARAMETER);
     1351#ifdef RT_OS_WINDOWS
     1352    AssertReturn(g_pfnrecv, VERR_NOT_SUPPORTED);
     1353#endif
    12481354    AssertReturn(rtSocketTryLock(pThis), VERR_CONCURRENT_ACCESS);
    12491355
     
    12601366
    12611367#ifdef RT_OS_WINDOWS
    1262     int cbRead = recv(pThis->hNative, (char *)pvBuffer, cbNow, MSG_NOSIGNAL);
     1368    int cbRead = g_pfnrecv(pThis->hNative, (char *)pvBuffer, cbNow, MSG_NOSIGNAL);
    12631369    if (cbRead >= 0)
    12641370    {
     
    13091415    AssertReturn(pThis->u32Magic == RTSOCKET_MAGIC, VERR_INVALID_HANDLE);
    13101416    AssertPtrReturn(pcbWritten, VERR_INVALID_PARAMETER);
     1417#ifdef RT_OS_WINDOWS
     1418    AssertReturn(g_pfnsend, VERR_NOT_SUPPORTED);
     1419#endif
    13111420    AssertReturn(rtSocketTryLock(pThis), VERR_CONCURRENT_ACCESS);
    13121421
     
    13221431    size_t cbNow = cbBuffer;
    13231432# endif
    1324     int cbWritten = send(pThis->hNative, (const char *)pvBuffer, cbNow, MSG_NOSIGNAL);
     1433    int cbWritten = g_pfnsend(pThis->hNative, (const char *)pvBuffer, cbNow, MSG_NOSIGNAL);
    13251434    if (cbWritten >= 0)
    13261435    {
     
    13811490    rc = VERR_NO_TMP_MEMORY;
    13821491#ifdef RT_OS_WINDOWS
    1383     LPWSABUF paMsg = NULL;
    1384 
    1385     RTSgBufMapToNative(paMsg, pSgBuf, WSABUF, buf, char *, len, u_long, cSegsToSend);
    1386     if (paMsg)
    1387     {
    1388         DWORD dwSent = 0;
    1389         int hrc = WSASend(pThis->hNative, paMsg, cSegsToSend, &dwSent,
    1390                           MSG_NOSIGNAL, NULL, NULL);
    1391         if (!hrc)
    1392             rc = VINF_SUCCESS;
    1393         else
    1394             rc = rtSocketError();
    1395 
    1396         *pcbWritten = dwSent;
    1397 
    1398         RTMemTmpFree(paMsg);
    1399     }
     1492    if (g_pfnWSASend)
     1493    {
     1494        LPWSABUF paMsg = NULL;
     1495        RTSgBufMapToNative(paMsg, pSgBuf, WSABUF, buf, char *, len, u_long, cSegsToSend);
     1496        if (paMsg)
     1497        {
     1498            DWORD dwSent = 0;
     1499            int hrc = g_pfnWSASend(pThis->hNative, paMsg, cSegsToSend, &dwSent, MSG_NOSIGNAL, NULL, NULL);
     1500            if (!hrc)
     1501                rc = VINF_SUCCESS;
     1502            else
     1503                rc = rtSocketError();
     1504
     1505            *pcbWritten = dwSent;
     1506
     1507            RTMemTmpFree(paMsg);
     1508        }
     1509    }
     1510    else if (g_pfnsend)
     1511    {
     1512        size_t cbWrittenTotal = 0;
     1513        rc = VINF_SUCCESS;
     1514        for (uint32_t iSeg = 0; iSeg < pSgBuf->cSegs; iSeg++)
     1515        {
     1516            uint8_t const *pbSeg = (uint8_t const *)pSgBuf->paSegs[iSeg].pvSeg;
     1517            size_t         cbSeg = pSgBuf->paSegs[iSeg].cbSeg;
     1518            int            cbNow;
     1519            ssize_t        cbWritten;
     1520            for (;;)
     1521            {
     1522                cbNow = cbSeg >= RTSOCKET_MAX_WRITE ? RTSOCKET_MAX_WRITE : (int)cbSeg;
     1523                cbWritten = g_pfnsend(pThis->hNative, (const char *)pbSeg, cbNow, MSG_NOSIGNAL);
     1524                if ((size_t)cbWritten >= cbSeg || cbWritten < 0)
     1525                    break;
     1526                cbWrittenTotal += cbWrittenTotal;
     1527                pbSeg += cbWritten;
     1528                cbSeg -= cbWritten;
     1529            }
     1530            if (cbWritten < 0)
     1531            {
     1532                rc = rtSocketError();
     1533                break;
     1534            }
     1535            if (cbWritten != cbNow)
     1536                break;
     1537        }
     1538        *pcbWritten = cbWrittenTotal;
     1539    }
     1540    else
     1541        rc = VERR_NOT_SUPPORTED;
    14001542
    14011543#else  /* !RT_OS_WINDOWS */
     
    14691611    int const fdMax = (int)pThis->hNative + 1;
    14701612    AssertReturn((RTSOCKETNATIVE)(fdMax - 1) == pThis->hNative, VERR_INTERNAL_ERROR_5);
     1613#ifdef RT_OS_WINDOWS
     1614    AssertReturn(g_pfnselect, VERR_NOT_SUPPORTED);
     1615# define select g_pfnselect
     1616#endif
    14711617
    14721618    /*
     
    14961642        rc = rtSocketError();
    14971643
     1644#ifdef RT_OS_WINDOWS
     1645# undef select
     1646#endif
    14981647    return rc;
    14991648}
     
    15231672    int const fdMax = (int)hNative + 1;
    15241673    AssertReturn((RTSOCKETNATIVE)(fdMax - 1) == hNative, VERR_INTERNAL_ERROR_5);
     1674#ifdef RT_OS_WINDOWS
     1675    AssertReturn(g_pfnselect, VERR_NOT_SUPPORTED);
     1676    AssertReturn(g_pfn__WSAFDIsSet, VERR_NOT_SUPPORTED);
     1677# define select         g_pfnselect
     1678# define __WSAFDIsSet   g_pfn__WSAFDIsSet
     1679#endif
    15251680
    15261681    *pfEvents = 0;
     
    15771732        rc = rtSocketError();
    15781733
     1734#ifdef RT_OS_WINDOWS
     1735# undef select
     1736# undef __WSAFDIsSet
     1737#endif
    15791738    return rc;
    15801739}
     
    15921751    AssertReturn(RTMemPoolRefCount(pThis) >= (pThis->cUsers ? 2U : 1U), VERR_CALLER_NO_REFERENCE);
    15931752    AssertReturn(fRead || fWrite, VERR_INVALID_PARAMETER);
     1753#ifdef RT_OS_WINDOWS
     1754    AssertReturn(g_pfnshutdown, VERR_NOT_SUPPORTED);
     1755# define shutdown g_pfnshutdown
     1756#endif
    15941757
    15951758    /*
     
    16071770        rc = rtSocketError();
    16081771
     1772#ifdef RT_OS_WINDOWS
     1773# undef shutdown
     1774#endif
    16091775    return rc;
    16101776}
     
    16201786    AssertReturn(pThis->u32Magic == RTSOCKET_MAGIC, VERR_INVALID_HANDLE);
    16211787    AssertReturn(RTMemPoolRefCount(pThis) >= (pThis->cUsers ? 2U : 1U), VERR_CALLER_NO_REFERENCE);
     1788#ifdef RT_OS_WINDOWS
     1789    AssertReturn(g_pfngetsockname, VERR_NOT_SUPPORTED);
     1790# define getsockname g_pfngetsockname
     1791#endif
    16221792
    16231793    /*
     
    16371807        rc = rtSocketError();
    16381808
     1809#ifdef RT_OS_WINDOWS
     1810# undef getsockname
     1811#endif
    16391812    return rc;
    16401813}
     
    16501823    AssertReturn(pThis->u32Magic == RTSOCKET_MAGIC, VERR_INVALID_HANDLE);
    16511824    AssertReturn(RTMemPoolRefCount(pThis) >= (pThis->cUsers ? 2U : 1U), VERR_CALLER_NO_REFERENCE);
     1825#ifdef RT_OS_WINDOWS
     1826    AssertReturn(g_pfngetpeername, VERR_NOT_SUPPORTED);
     1827# define getpeername g_pfngetpeername
     1828#endif
    16521829
    16531830    /*
     
    16671844        rc = rtSocketError();
    16681845
     1846#ifdef RT_OS_WINDOWS
     1847# undef getpeername
     1848#endif
    16691849    return rc;
    16701850}
     
    17081888    AssertReturn(pThis->u32Magic == RTSOCKET_MAGIC, VERR_INVALID_HANDLE);
    17091889    AssertPtrReturn(pvAddr, VERR_INVALID_POINTER);
     1890#ifdef RT_OS_WINDOWS
     1891    AssertReturn(g_pfnbind, VERR_NOT_SUPPORTED);
     1892# define bind g_pfnbind
     1893#endif
    17101894    AssertReturn(rtSocketTryLock(pThis), VERR_CONCURRENT_ACCESS);
    17111895
     
    17171901
    17181902    rtSocketUnlock(pThis);
     1903#ifdef RT_OS_WINDOWS
     1904# undef bind
     1905#endif
    17191906    return rc;
    17201907}
     
    17371924    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
    17381925    AssertReturn(pThis->u32Magic == RTSOCKET_MAGIC, VERR_INVALID_HANDLE);
     1926#ifdef RT_OS_WINDOWS
     1927    AssertReturn(g_pfnlisten, VERR_NOT_SUPPORTED);
     1928# define listen g_pfnlisten
     1929#endif
    17391930    AssertReturn(rtSocketTryLock(pThis), VERR_CONCURRENT_ACCESS);
    17401931
     
    17441935
    17451936    rtSocketUnlock(pThis);
     1937#ifdef RT_OS_WINDOWS
     1938# undef listen
     1939#endif
    17461940    return rc;
    17471941}
     
    17701964    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
    17711965    AssertReturn(pThis->u32Magic == RTSOCKET_MAGIC, VERR_INVALID_HANDLE);
     1966#ifdef RT_OS_WINDOWS
     1967    AssertReturn(g_pfnaccept, VERR_NOT_SUPPORTED);
     1968    AssertReturn(g_pfnclosesocket, VERR_NOT_SUPPORTED);
     1969# define accept g_pfnaccept
     1970#endif
    17721971    AssertReturn(rtSocketTryLock(pThis), VERR_CONCURRENT_ACCESS);
    17731972
     
    17941993        {
    17951994#ifdef RT_OS_WINDOWS
    1796             closesocket(hNativeClient);
     1995            g_pfnclosesocket(hNativeClient);
    17971996#else
    17981997            close(hNativeClient);
     
    18042003
    18052004    rtSocketUnlock(pThis);
     2005#ifdef RT_OS_WINDOWS
     2006# undef accept
     2007#endif
    18062008    return rc;
    18072009}
     
    18272029    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
    18282030    AssertReturn(pThis->u32Magic == RTSOCKET_MAGIC, VERR_INVALID_HANDLE);
     2031#ifdef RT_OS_WINDOWS
     2032    AssertReturn(g_pfnconnect, VERR_NOT_SUPPORTED);
     2033    AssertReturn(g_pfnselect, VERR_NOT_SUPPORTED);
     2034    AssertReturn(g_pfngetsockopt, VERR_NOT_SUPPORTED);
     2035# define connect        g_pfnconnect
     2036# define select         g_pfnselect
     2037# define getsockopt     g_pfngetsockopt
     2038#endif
    18292039    AssertReturn(rtSocketTryLock(pThis), VERR_CONCURRENT_ACCESS);
    18302040
     
    19042114
    19052115    rtSocketUnlock(pThis);
     2116#ifdef RT_OS_WINDOWS
     2117# undef connect
     2118# undef select
     2119# undef getsockopt
     2120#endif
    19062121    return rc;
    19072122}
     
    19242139    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
    19252140    AssertReturn(pThis->u32Magic == RTSOCKET_MAGIC, VERR_INVALID_HANDLE);
     2141#ifdef RT_OS_WINDOWS
     2142    AssertReturn(g_pfnconnect, VERR_NOT_SUPPORTED);
     2143# define connect        g_pfnconnect
     2144#endif
    19262145    AssertReturn(rtSocketTryLock(pThis), VERR_CONCURRENT_ACCESS);
    19272146
     
    19332152
    19342153    rtSocketUnlock(pThis);
     2154#ifdef RT_OS_WINDOWS
     2155# undef connect
     2156#endif
    19352157    return rc;
    19362158}
     
    19552177    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
    19562178    AssertReturn(pThis->u32Magic == RTSOCKET_MAGIC, VERR_INVALID_HANDLE);
     2179#ifdef RT_OS_WINDOWS
     2180    AssertReturn(g_pfnsetsockopt, VERR_NOT_SUPPORTED);
     2181# define setsockopt g_pfnsetsockopt
     2182#endif
    19572183    AssertReturn(rtSocketTryLock(pThis), VERR_CONCURRENT_ACCESS);
    19582184
     
    19622188
    19632189    rtSocketUnlock(pThis);
     2190#ifdef RT_OS_WINDOWS
     2191# undef setsockopt
     2192#endif
    19642193    return rc;
    19652194}
     
    19872216    if (pThis->hEvent != WSA_INVALID_EVENT)
    19882217        *phNative = (RTHCINTPTR)pThis->hEvent;
    1989     else
    1990     {
    1991         pThis->hEvent = WSACreateEvent();
     2218    else if (g_pfnWSACreateEvent)
     2219    {
     2220        pThis->hEvent = g_pfnWSACreateEvent();
    19922221        *phNative = (RTHCINTPTR)pThis->hEvent;
    19932222        if (pThis->hEvent == WSA_INVALID_EVENT)
    19942223            rc = rtSocketError();
    19952224    }
     2225    else
     2226        rc = VERR_NOT_SUPPORTED;
    19962227
    19972228    rtSocketUnlock(pThis);
     
    20172248    if (pThis->fSubscribedEvts)
    20182249    {
    2019         if (WSAEventSelect(pThis->hNative, WSA_INVALID_EVENT, 0) == 0)
     2250        if (g_pfnWSAEventSelect && g_pfnioctlsocket)
    20202251        {
    2021             pThis->fSubscribedEvts = 0;
    2022 
    2023             /*
    2024              * Switch back to blocking mode if that was the state before the
    2025              * operation.
    2026              */
    2027             if (pThis->fBlocking)
     2252            if (g_pfnWSAEventSelect(pThis->hNative, WSA_INVALID_EVENT, 0) == 0)
    20282253            {
    2029                 u_long fNonBlocking = 0;
    2030                 int rc2 = ioctlsocket(pThis->hNative, FIONBIO, &fNonBlocking);
    2031                 if (rc2 != 0)
     2254                pThis->fSubscribedEvts = 0;
     2255
     2256                /*
     2257                 * Switch back to blocking mode if that was the state before the
     2258                 * operation.
     2259                 */
     2260                if (pThis->fBlocking)
    20322261                {
    2033                     rc = rtSocketError();
    2034                     AssertMsgFailed(("%Rrc; rc2=%d\n", rc, rc2));
     2262                    u_long fNonBlocking = 0;
     2263                    int rc2 = g_pfnioctlsocket(pThis->hNative, FIONBIO, &fNonBlocking);
     2264                    if (rc2 != 0)
     2265                    {
     2266                        rc = rtSocketError();
     2267                        AssertMsgFailed(("%Rrc; rc2=%d\n", rc, rc2));
     2268                    }
    20352269                }
     2270            }
     2271            else
     2272            {
     2273                rc = rtSocketError();
     2274                AssertMsgFailed(("%Rrc\n", rc));
    20362275            }
    20372276        }
    20382277        else
    2039         {
    2040             rc = rtSocketError();
    2041             AssertMsgFailed(("%Rrc\n", rc));
    2042         }
     2278            rc = VERR_NOT_SUPPORTED;
    20432279    }
    20442280    return rc;
     
    20632299        fNetworkEvents |= FD_CLOSE;
    20642300    LogFlowFunc(("fNetworkEvents=%#x\n", fNetworkEvents));
    2065     if (WSAEventSelect(pThis->hNative, pThis->hEvent, fNetworkEvents) == 0)
    2066     {
    2067         pThis->fSubscribedEvts = fEvents;
    2068         return VINF_SUCCESS;
    2069     }
    2070 
    2071     int rc = rtSocketError();
    2072     AssertMsgFailed(("fNetworkEvents=%#x rc=%Rrc\n", fNetworkEvents, rtSocketError()));
     2301    int rc;
     2302    if (g_pfnWSAEventSelect)
     2303    {
     2304        if (g_pfnWSAEventSelect(pThis->hNative, pThis->hEvent, fNetworkEvents) == 0)
     2305        {
     2306            pThis->fSubscribedEvts = fEvents;
     2307            return VINF_SUCCESS;
     2308        }
     2309        rc = rtSocketError();
     2310        AssertMsgFailed(("fNetworkEvents=%#x rc=%Rrc\n", fNetworkEvents, rtSocketError()));
     2311    }
     2312    else
     2313        rc = VERR_NOT_SUPPORTED;
    20732314    return rc;
    20742315}
     
    20992340
    21002341    /* Get the event mask, ASSUMES that WSAEnumNetworkEvents doesn't clear stuff.  */
    2101     WSANETWORKEVENTS NetEvts;
    2102     RT_ZERO(NetEvts);
    2103     if (WSAEnumNetworkEvents(pThis->hNative, pThis->hEvent, &NetEvts) == 0)
    2104     {
    2105         if (    (NetEvts.lNetworkEvents & FD_READ)
    2106             &&  (fEvents & RTPOLL_EVT_READ)
    2107             &&  NetEvts.iErrorCode[FD_READ_BIT] == 0)
    2108             fRetEvents |= RTPOLL_EVT_READ;
    2109 
    2110         if (    (NetEvts.lNetworkEvents & FD_WRITE)
    2111             &&  (fEvents & RTPOLL_EVT_WRITE)
    2112             &&  NetEvts.iErrorCode[FD_WRITE_BIT] == 0)
    2113             fRetEvents |= RTPOLL_EVT_WRITE;
    2114 
    2115         if (fEvents & RTPOLL_EVT_ERROR)
     2342    if (g_pfnWSAEnumNetworkEvents)
     2343    {
     2344        WSANETWORKEVENTS NetEvts;
     2345        RT_ZERO(NetEvts);
     2346        if (g_pfnWSAEnumNetworkEvents(pThis->hNative, pThis->hEvent, &NetEvts) == 0)
    21162347        {
    2117             if (NetEvts.lNetworkEvents & FD_CLOSE)
    2118                 fRetEvents |= RTPOLL_EVT_ERROR;
    2119             else
    2120                 for (uint32_t i = 0; i < FD_MAX_EVENTS; i++)
    2121                     if (    (NetEvts.lNetworkEvents & (1L << i))
    2122                         &&  NetEvts.iErrorCode[i] != 0)
    2123                         fRetEvents |= RTPOLL_EVT_ERROR;
     2348            if (    (NetEvts.lNetworkEvents & FD_READ)
     2349                &&  (fEvents & RTPOLL_EVT_READ)
     2350                &&  NetEvts.iErrorCode[FD_READ_BIT] == 0)
     2351                fRetEvents |= RTPOLL_EVT_READ;
     2352
     2353            if (    (NetEvts.lNetworkEvents & FD_WRITE)
     2354                &&  (fEvents & RTPOLL_EVT_WRITE)
     2355                &&  NetEvts.iErrorCode[FD_WRITE_BIT] == 0)
     2356                fRetEvents |= RTPOLL_EVT_WRITE;
     2357
     2358            if (fEvents & RTPOLL_EVT_ERROR)
     2359            {
     2360                if (NetEvts.lNetworkEvents & FD_CLOSE)
     2361                    fRetEvents |= RTPOLL_EVT_ERROR;
     2362                else
     2363                    for (uint32_t i = 0; i < FD_MAX_EVENTS; i++)
     2364                        if (    (NetEvts.lNetworkEvents & (1L << i))
     2365                            &&  NetEvts.iErrorCode[i] != 0)
     2366                            fRetEvents |= RTPOLL_EVT_ERROR;
     2367            }
    21242368        }
    2125     }
    2126     else
    2127         rc = rtSocketError();
     2369        else
     2370            rc = rtSocketError();
     2371    }
     2372    else if (RT_SUCCESS(rc))
     2373        rc = VERR_NOT_SUPPORTED;
    21282374
    21292375    /* Fall back on select if we hit an error above. */
    21302376    if (RT_FAILURE(rc))
    21312377    {
    2132 
     2378        rc = RTSocketSelectOneEx(pThis, fEvents, &fRetEvents, 0);
     2379        if (RT_FAILURE(rc))
     2380            fRetEvents = 0;
    21332381    }
    21342382
  • trunk/src/VBox/Runtime/r3/win/errvars-win.cpp

    r69111 r70195  
    3737#include <iprt/assert.h>
    3838#include "internal/magics.h"
     39#include "internal-r3-win.h"
    3940
    4041
     
    4445    pVars->ai32Vars[0] = RTERRVARS_MAGIC;
    4546    pVars->ai32Vars[1] = GetLastError();
    46     pVars->ai32Vars[2] = WSAGetLastError();
     47    pVars->ai32Vars[2] = g_pfnWSAGetLastError ? g_pfnWSAGetLastError() : WSANOTINITIALISED;
    4748    pVars->ai32Vars[3] = errno;
    4849    return pVars;
     
    5455    AssertReturnVoid(pVars->ai32Vars[0] == RTERRVARS_MAGIC);
    5556    errno = pVars->ai32Vars[3];
    56     if (pVars->ai32Vars[2] != WSANOTINITIALISED) /* just an idea... */
    57         WSASetLastError(pVars->ai32Vars[2]);
     57    if (   pVars->ai32Vars[2] != WSANOTINITIALISED
     58        && g_pfnWSASetLastError)
     59        g_pfnWSASetLastError(pVars->ai32Vars[2]);
    5860    SetLastError(pVars->ai32Vars[1]);
    5961}
     
    7880    return pVars->ai32Vars[0] != RTERRVARS_MAGIC
    7981        || (uint32_t)pVars->ai32Vars[1] != GetLastError()
    80         || pVars->ai32Vars[2] != WSAGetLastError()
     82        || pVars->ai32Vars[2] != (g_pfnWSAGetLastError ? g_pfnWSAGetLastError() : WSANOTINITIALISED)
    8183        || pVars->ai32Vars[3] != errno;
    8284}
  • trunk/src/VBox/Runtime/r3/win/init-win.cpp

    r69434 r70195  
    4040#include <iprt/assert.h>
    4141#include <iprt/err.h>
     42#include <iprt/ldr.h>
    4243#include <iprt/log.h>
    4344#include <iprt/param.h>
     
    6364/** Extended windows version information. */
    6465DECLHIDDEN(OSVERSIONINFOEXW)    g_WinOsInfoEx;
     66
    6567/** The native kernel32.dll handle. */
    66 DECLHIDDEN(HMODULE)             g_hModKernel32 = NULL;
     68DECLHIDDEN(HMODULE)                         g_hModKernel32 = NULL;
     69/** GetSystemWindowsDirectoryW or GetWindowsDirectoryW (NT4). */
     70DECLHIDDEN(PFNGETWINSYSDIR)                 g_pfnGetSystemWindowsDirectoryW = NULL;
     71/** The GetCurrentThreadStackLimits API. */
     72static PFNGETCURRENTTHREADSTACKLIMITS       g_pfnGetCurrentThreadStackLimits = NULL;
     73/** SetUnhandledExceptionFilter. */
     74static PFNSETUNHANDLEDEXCEPTIONFILTER       g_pfnSetUnhandledExceptionFilter = NULL;
     75/** The previous unhandled exception filter. */
     76static LPTOP_LEVEL_EXCEPTION_FILTER         g_pfnUnhandledXcptFilter = NULL;
     77
    6778/** The native ntdll.dll handle. */
    68 DECLHIDDEN(HMODULE)             g_hModNtDll = NULL;
    69 /** GetSystemWindowsDirectoryW or GetWindowsDirectoryW (NT4). */
    70 DECLHIDDEN(PFNGETWINSYSDIR)     g_pfnGetSystemWindowsDirectoryW = NULL;
    71 /** The GetCurrentThreadStackLimits API. */
    72 static PFNGETCURRENTTHREADSTACKLIMITS g_pfnGetCurrentThreadStackLimits = NULL;
    73 /** SetUnhandledExceptionFilter. */
    74 static PFNSETUNHANDLEDEXCEPTIONFILTER g_pfnSetUnhandledExceptionFilter = NULL;
    75 /** The previous unhandled exception filter. */
    76 static LPTOP_LEVEL_EXCEPTION_FILTER   g_pfnUnhandledXcptFilter = NULL;
     79DECLHIDDEN(HMODULE)                         g_hModNtDll = NULL;
     80/** NtQueryFullAttributesFile   */
     81DECLHIDDEN(PFNNTQUERYFULLATTRIBUTESFILE)    g_pfnNtQueryFullAttributesFile = NULL;
     82/** NtDuplicateToken (NT 3.51). */
     83DECLHIDDEN(PFNNTDUPLICATETOKEN)             g_pfnNtDuplicateToken = NULL;
     84
     85/** Either ws2_32.dll (NT4+) or wsock32.dll (NT3.x). */
     86DECLHIDDEN(HMODULE)                         g_hModWinSock = NULL;
     87/** Set if we're dealing with old winsock.   */
     88DECLHIDDEN(bool)                            g_fOldWinSock = false;
     89/** WSAStartup   */
     90DECLHIDDEN(PFNWSASTARTUP)                   g_pfnWSAStartup = NULL;
     91/** WSACleanup */
     92DECLHIDDEN(PFNWSACLEANUP)                   g_pfnWSACleanup = NULL;
     93/** Pointner to WSAGetLastError (for RTErrVarsSave). */
     94DECLHIDDEN(PFNWSAGETLASTERROR)              g_pfnWSAGetLastError = NULL;
     95/** Pointner to WSASetLastError (for RTErrVarsRestore). */
     96DECLHIDDEN(PFNWSASETLASTERROR)              g_pfnWSASetLastError = NULL;
     97/** WSACreateEvent */
     98DECLHIDDEN(PFNWSACREATEEVENT)               g_pfnWSACreateEvent = NULL;
     99/** WSACloseEvent  */
     100DECLHIDDEN(PFNWSACLOSEEVENT)                g_pfnWSACloseEvent = NULL;
     101/** WSAEventSelect   */
     102DECLHIDDEN(PFNWSAEVENTSELECT)               g_pfnWSAEventSelect = NULL;
     103/** WSAEnumNetworkEvents */
     104DECLHIDDEN(PFNWSAENUMNETWORKEVENTS)         g_pfnWSAEnumNetworkEvents = NULL;
     105/** WSASend */
     106DECLHIDDEN(PFNWSASend)                      g_pfnWSASend = NULL;
     107/** socket */
     108DECLHIDDEN(PFNWINSOCKSOCKET)                g_pfnsocket = NULL;
     109/** closesocket */
     110DECLHIDDEN(PFNWINSOCKCLOSESOCKET)           g_pfnclosesocket = NULL;
     111/** recv */
     112DECLHIDDEN(PFNWINSOCKRECV)                  g_pfnrecv = NULL;
     113/** send */
     114DECLHIDDEN(PFNWINSOCKSEND)                  g_pfnsend = NULL;
     115/** recvfrom */
     116DECLHIDDEN(PFNWINSOCKRECVFROM)              g_pfnrecvfrom = NULL;
     117/** sendto */
     118DECLHIDDEN(PFNWINSOCKSENDTO)                g_pfnsendto = NULL;
     119/** bind */
     120DECLHIDDEN(PFNWINSOCKBIND)                  g_pfnbind = NULL;
     121/** listen  */
     122DECLHIDDEN(PFNWINSOCKLISTEN)                g_pfnlisten = NULL;
     123/** accept */
     124DECLHIDDEN(PFNWINSOCKACCEPT)                g_pfnaccept = NULL;
     125/** connect */
     126DECLHIDDEN(PFNWINSOCKCONNECT)               g_pfnconnect = NULL;
     127/** shutdown */
     128DECLHIDDEN(PFNWINSOCKSHUTDOWN)              g_pfnshutdown = NULL;
     129/** getsockopt */
     130DECLHIDDEN(PFNWINSOCKGETSOCKOPT)            g_pfngetsockopt = NULL;
     131/** setsockopt */
     132DECLHIDDEN(PFNWINSOCKSETSOCKOPT)            g_pfnsetsockopt = NULL;
     133/** ioctlsocket */
     134DECLHIDDEN(PFNWINSOCKIOCTLSOCKET)           g_pfnioctlsocket = NULL;
     135/** getpeername   */
     136DECLHIDDEN(PFNWINSOCKGETPEERNAME)           g_pfngetpeername = NULL;
     137/** getsockname */
     138DECLHIDDEN(PFNWINSOCKGETSOCKNAME)           g_pfngetsockname = NULL;
     139/** __WSAFDIsSet */
     140DECLHIDDEN(PFNWINSOCK__WSAFDISSET)          g_pfn__WSAFDIsSet = NULL;
     141/** select */
     142DECLHIDDEN(PFNWINSOCKSELECT)                g_pfnselect = NULL;
     143/** gethostbyname */
     144DECLHIDDEN(PFNWINSOCKGETHOSTBYNAME)         g_pfngethostbyname = NULL;
    77145
    78146
     
    153221    {
    154222        if (        dwMajorVersion == 3
     223                 && dwMinorVersion == 1)
     224            enmVer = kRTWinOSType_NT31;
     225        else if (   dwMajorVersion == 3
    155226                 && dwMinorVersion == 51)
    156227            enmVer = kRTWinOSType_NT351;
     
    271342
    272343
     344/**
     345 * Resolves the winsock error APIs.
     346 */
     347static void rtR3InitWinSockApis(void)
     348{
     349    /*
     350     * Try get ws2_32.dll, then try load it, then finally fall back to the old
     351     * wsock32.dll.  We use RTLdrLoadSystem to the loading as it has all the fancy
     352     * logic for safely doing that.
     353     */
     354    g_hModWinSock = GetModuleHandleW(L"ws2_32.dll");
     355    if (g_hModWinSock == NULL)
     356    {
     357        RTLDRMOD hLdrMod;
     358        int rc = RTLdrLoadSystem("ws2_32.dll", true /*fNoUnload*/, &hLdrMod);
     359        if (RT_FAILURE(rc))
     360        {
     361            rc = RTLdrLoadSystem("wsock32.dll", true /*fNoUnload*/, &hLdrMod);
     362            if (RT_FAILURE(rc))
     363            {
     364AssertMsgFailed(("rc=%Rrc\n", rc));
     365                return;
     366            }
     367            g_fOldWinSock = true;
     368        }
     369        g_hModWinSock = (HMODULE)RTLdrGetNativeHandle(hLdrMod);
     370        RTLdrClose(hLdrMod);
     371    }
     372RTAssertMsg2("g_hModWinSock=%p\n", g_hModWinSock);
     373
     374    g_pfnWSAStartup           = (decltype(g_pfnWSAStartup))         GetProcAddress(g_hModWinSock, "WSAStartup");
     375    g_pfnWSACleanup           = (decltype(g_pfnWSACleanup))         GetProcAddress(g_hModWinSock, "WSACleanup");
     376    g_pfnWSAGetLastError      = (decltype(g_pfnWSAGetLastError))    GetProcAddress(g_hModWinSock, "WSAGetLastError");
     377    g_pfnWSASetLastError      = (decltype(g_pfnWSASetLastError))    GetProcAddress(g_hModWinSock, "WSASetLastError");
     378    g_pfnWSACreateEvent       = (decltype(g_pfnWSACreateEvent))     GetProcAddress(g_hModWinSock, "WSACreateEvent");
     379    g_pfnWSACloseEvent        = (decltype(g_pfnWSACloseEvent))      GetProcAddress(g_hModWinSock, "WSACloseEvent");
     380    g_pfnWSAEventSelect       = (decltype(g_pfnWSAEventSelect))     GetProcAddress(g_hModWinSock, "WSAEventSelect");
     381    g_pfnWSAEnumNetworkEvents = (decltype(g_pfnWSAEnumNetworkEvents))GetProcAddress(g_hModWinSock,"WSAEnumNetworkEvents");
     382    g_pfnWSASend              = (decltype(g_pfnWSASend))            GetProcAddress(g_hModWinSock, "WSASend");
     383    g_pfnsocket               = (decltype(g_pfnsocket))             GetProcAddress(g_hModWinSock, "socket");
     384    g_pfnclosesocket          = (decltype(g_pfnclosesocket))        GetProcAddress(g_hModWinSock, "closesocket");
     385    g_pfnrecv                 = (decltype(g_pfnrecv))               GetProcAddress(g_hModWinSock, "recv");
     386    g_pfnsend                 = (decltype(g_pfnsend))               GetProcAddress(g_hModWinSock, "send");
     387    g_pfnrecvfrom             = (decltype(g_pfnrecvfrom))           GetProcAddress(g_hModWinSock, "recvfrom");
     388    g_pfnsendto               = (decltype(g_pfnsendto))             GetProcAddress(g_hModWinSock, "sendto");
     389    g_pfnbind                 = (decltype(g_pfnbind))               GetProcAddress(g_hModWinSock, "bind");
     390    g_pfnlisten               = (decltype(g_pfnlisten))             GetProcAddress(g_hModWinSock, "listen");
     391    g_pfnaccept               = (decltype(g_pfnaccept))             GetProcAddress(g_hModWinSock, "accept");
     392    g_pfnconnect              = (decltype(g_pfnconnect))            GetProcAddress(g_hModWinSock, "connect");
     393    g_pfnshutdown             = (decltype(g_pfnshutdown))           GetProcAddress(g_hModWinSock, "shutdown");
     394    g_pfngetsockopt           = (decltype(g_pfngetsockopt))         GetProcAddress(g_hModWinSock, "getsockopt");
     395    g_pfnsetsockopt           = (decltype(g_pfnsetsockopt))         GetProcAddress(g_hModWinSock, "setsockopt");
     396    g_pfnioctlsocket          = (decltype(g_pfnioctlsocket))        GetProcAddress(g_hModWinSock, "ioctlsocket");
     397    g_pfngetpeername          = (decltype(g_pfngetpeername))        GetProcAddress(g_hModWinSock, "getpeername");
     398    g_pfngetsockname          = (decltype(g_pfngetsockname))        GetProcAddress(g_hModWinSock, "getsockname");
     399    g_pfn__WSAFDIsSet         = (decltype(g_pfn__WSAFDIsSet))       GetProcAddress(g_hModWinSock, "__WSAFDIsSet");
     400    g_pfnselect               = (decltype(g_pfnselect))             GetProcAddress(g_hModWinSock, "select");
     401    g_pfngethostbyname        = (decltype(g_pfngethostbyname))      GetProcAddress(g_hModWinSock, "gethostbyname");
     402
     403    Assert(g_pfnWSAStartup);
     404    Assert(g_pfnWSACleanup);
     405    Assert(g_pfnWSAGetLastError);
     406    Assert(g_pfnWSASetLastError);
     407    Assert(g_pfnWSACreateEvent       || g_fOldWinSock);
     408    Assert(g_pfnWSACloseEvent        || g_fOldWinSock);
     409    Assert(g_pfnWSAEventSelect       || g_fOldWinSock);
     410    Assert(g_pfnWSAEnumNetworkEvents || g_fOldWinSock);
     411    Assert(g_pfnWSASend              || g_fOldWinSock);
     412    Assert(g_pfnsocket);
     413    Assert(g_pfnclosesocket);
     414    Assert(g_pfnrecv);
     415    Assert(g_pfnsend);
     416    Assert(g_pfnrecvfrom);
     417    Assert(g_pfnsendto);
     418    Assert(g_pfnbind);
     419    Assert(g_pfnlisten);
     420    Assert(g_pfnaccept);
     421    Assert(g_pfnconnect);
     422    Assert(g_pfnshutdown);
     423    Assert(g_pfngetsockopt);
     424    Assert(g_pfnsetsockopt);
     425    Assert(g_pfnioctlsocket);
     426    Assert(g_pfngetpeername);
     427    Assert(g_pfngetsockname);
     428    Assert(g_pfn__WSAFDIsSet);
     429    Assert(g_pfnselect);
     430    Assert(g_pfngethostbyname);
     431}
     432
     433
    273434static int rtR3InitNativeObtrusiveWorker(uint32_t fFlags)
    274435{
     
    362523    if (g_pfnGetSystemWindowsDirectoryW)
    363524        g_pfnGetSystemWindowsDirectoryW = (PFNGETWINSYSDIR)GetProcAddress(g_hModKernel32, "GetWindowsDirectoryW");
     525
     526    /*
     527     * Resolve some ntdll.dll APIs that weren't there in early NT versions.
     528     */
     529    g_pfnNtQueryFullAttributesFile = (PFNNTQUERYFULLATTRIBUTESFILE)GetProcAddress(g_hModNtDll, "NtQueryFullAttributesFile");
     530    g_pfnNtDuplicateToken          = (PFNNTDUPLICATETOKEN)GetProcAddress(         g_hModNtDll, "NtDuplicateToken");
     531
     532    /*
     533     * Resolve the winsock error getter and setter so assertions can save those too.
     534     */
     535    rtR3InitWinSockApis();
    364536
    365537    return rc;
  • trunk/src/VBox/Runtime/r3/win/internal-r3-win.h

    r69111 r70195  
    9898extern DECLHIDDEN(HMODULE)          g_hModKernel32;
    9999extern DECLHIDDEN(HMODULE)          g_hModNtDll;
     100
    100101extern DECLHIDDEN(OSVERSIONINFOEXW) g_WinOsInfoEx;
    101102typedef UINT (WINAPI *PFNGETWINSYSDIR)(LPWSTR,UINT);
    102103extern DECLHIDDEN(PFNGETWINSYSDIR)  g_pfnGetSystemWindowsDirectoryW;
     104typedef NTSTATUS (NTAPI *PFNNTQUERYFULLATTRIBUTESFILE)(struct _OBJECT_ATTRIBUTES *, struct _FILE_NETWORK_OPEN_INFORMATION *);
     105extern DECLHIDDEN(PFNNTQUERYFULLATTRIBUTESFILE) g_pfnNtQueryFullAttributesFile;
     106typedef NTSTATUS (NTAPI *PFNNTDUPLICATETOKEN)(HANDLE, ACCESS_MASK, struct _OBJECT_ATTRIBUTES *, BOOLEAN, TOKEN_TYPE, PHANDLE);
     107extern DECLHIDDEN(PFNNTDUPLICATETOKEN)          g_pfnNtDuplicateToken;
     108
     109extern DECLHIDDEN(HMODULE)                         g_hModWinSock;
     110
     111/** WSAStartup */
     112typedef int             (WINAPI *PFNWSASTARTUP)(WORD, struct WSAData *);
     113/** WSACleanup */
     114typedef int             (WINAPI *PFNWSACLEANUP)(void);
     115/** WSAGetLastError */
     116typedef int             (WINAPI *PFNWSAGETLASTERROR)(void);
     117/** WSASetLastError */
     118typedef int             (WINAPI *PFNWSASETLASTERROR)(int);
     119/** WSACreateEvent */
     120typedef HANDLE          (WINAPI *PFNWSACREATEEVENT)(void);
     121/** WSACloseEvent */
     122typedef BOOL            (WINAPI *PFNWSACLOSEEVENT)(HANDLE);
     123/** WSAEventSelect */
     124typedef BOOL            (WINAPI *PFNWSAEVENTSELECT)(UINT_PTR, HANDLE, LONG);
     125/** WSAEnumNetworkEvents */
     126typedef int             (WINAPI *PFNWSAENUMNETWORKEVENTS)(UINT_PTR, HANDLE, struct _WSANETWORKEVENTS *);
     127/** WSASend */
     128typedef int             (WINAPI *PFNWSASend)(UINT_PTR, struct _WSABUF *, DWORD, LPDWORD, DWORD dwFlags, struct _OVERLAPPED *, PFNRT /*LPWSAOVERLAPPED_COMPLETION_ROUTINE*/);
     129
     130/** socket */
     131typedef UINT_PTR        (WINAPI *PFNWINSOCKSOCKET)(int, int, int);
     132/** closesocket */
     133typedef int             (WINAPI *PFNWINSOCKCLOSESOCKET)(UINT_PTR);
     134/** recv */
     135typedef int             (WINAPI *PFNWINSOCKRECV)(UINT_PTR, char *, int, int);
     136/** send */
     137typedef int             (WINAPI *PFNWINSOCKSEND)(UINT_PTR, const char *, int, int);
     138/** recvfrom */
     139typedef int             (WINAPI *PFNWINSOCKRECVFROM)(UINT_PTR, char *, int, int, struct sockaddr *, int *);
     140/** sendto */
     141typedef int             (WINAPI *PFNWINSOCKSENDTO)(UINT_PTR, const char *, int, int, const struct sockaddr *, int);
     142/** bind */
     143typedef int             (WINAPI *PFNWINSOCKBIND)(UINT_PTR, const struct sockaddr *, int);
     144/** listen  */
     145typedef int             (WINAPI *PFNWINSOCKLISTEN)(UINT_PTR, int);
     146/** accept */
     147typedef UINT_PTR        (WINAPI *PFNWINSOCKACCEPT)(UINT_PTR, struct sockaddr *, int *);
     148/** connect */
     149typedef int             (WINAPI *PFNWINSOCKCONNECT)(UINT_PTR, const struct sockaddr *, int);
     150/** shutdown */
     151typedef int             (WINAPI *PFNWINSOCKSHUTDOWN)(UINT_PTR, int);
     152/** getsockopt */
     153typedef int             (WINAPI *PFNWINSOCKGETSOCKOPT)(UINT_PTR, int, int, char *, int *);
     154/** setsockopt */
     155typedef int             (WINAPI *PFNWINSOCKSETSOCKOPT)(UINT_PTR, int, int, const char *, int);
     156/** ioctlsocket */
     157typedef int             (WINAPI *PFNWINSOCKIOCTLSOCKET)(UINT_PTR, long, unsigned long *);
     158/** getpeername   */
     159typedef int             (WINAPI *PFNWINSOCKGETPEERNAME)(UINT_PTR, struct sockaddr *, int *);
     160/** getsockname */
     161typedef int             (WINAPI *PFNWINSOCKGETSOCKNAME)(UINT_PTR, struct sockaddr *, int *);
     162/** __WSAFDIsSet */
     163typedef int             (WINAPI *PFNWINSOCK__WSAFDISSET)(UINT_PTR, struct fd_set *);
     164/** select */
     165typedef int             (WINAPI *PFNWINSOCKSELECT)(int, struct fd_set *, struct fd_set *, struct fd_set *, const struct timeval *);
     166/** gethostbyname */
     167typedef struct hostent *(WINAPI *PFNWINSOCKGETHOSTBYNAME)(const char *);
     168
     169extern DECLHIDDEN(PFNWSASTARTUP)                   g_pfnWSAStartup;
     170extern DECLHIDDEN(PFNWSACLEANUP)                   g_pfnWSACleanup;
     171extern PFNWSAGETLASTERROR                          g_pfnWSAGetLastError;
     172extern PFNWSASETLASTERROR                          g_pfnWSASetLastError;
     173extern DECLHIDDEN(PFNWSACREATEEVENT)               g_pfnWSACreateEvent;
     174extern DECLHIDDEN(PFNWSACLOSEEVENT)                g_pfnWSACloseEvent;
     175extern DECLHIDDEN(PFNWSAEVENTSELECT)               g_pfnWSAEventSelect;
     176extern DECLHIDDEN(PFNWSAENUMNETWORKEVENTS)         g_pfnWSAEnumNetworkEvents;
     177extern DECLHIDDEN(PFNWSASend)                      g_pfnWSASend;
     178extern DECLHIDDEN(PFNWINSOCKSOCKET)                g_pfnsocket;
     179extern DECLHIDDEN(PFNWINSOCKCLOSESOCKET)           g_pfnclosesocket;
     180extern DECLHIDDEN(PFNWINSOCKRECV)                  g_pfnrecv;
     181extern DECLHIDDEN(PFNWINSOCKSEND)                  g_pfnsend;
     182extern DECLHIDDEN(PFNWINSOCKRECVFROM)              g_pfnrecvfrom;
     183extern DECLHIDDEN(PFNWINSOCKSENDTO)                g_pfnsendto;
     184extern DECLHIDDEN(PFNWINSOCKBIND)                  g_pfnbind;
     185extern DECLHIDDEN(PFNWINSOCKLISTEN)                g_pfnlisten;
     186extern DECLHIDDEN(PFNWINSOCKACCEPT)                g_pfnaccept;
     187extern DECLHIDDEN(PFNWINSOCKCONNECT)               g_pfnconnect;
     188extern DECLHIDDEN(PFNWINSOCKSHUTDOWN)              g_pfnshutdown;
     189extern DECLHIDDEN(PFNWINSOCKGETSOCKOPT)            g_pfngetsockopt;
     190extern DECLHIDDEN(PFNWINSOCKSETSOCKOPT)            g_pfnsetsockopt;
     191extern DECLHIDDEN(PFNWINSOCKIOCTLSOCKET)           g_pfnioctlsocket;
     192extern DECLHIDDEN(PFNWINSOCKGETPEERNAME)           g_pfngetpeername;
     193extern DECLHIDDEN(PFNWINSOCKGETSOCKNAME)           g_pfngetsockname;
     194extern DECLHIDDEN(PFNWINSOCK__WSAFDISSET)          g_pfn__WSAFDIsSet;
     195extern DECLHIDDEN(PFNWINSOCKSELECT)                g_pfnselect;
     196extern DECLHIDDEN(PFNWINSOCKGETHOSTBYNAME)         g_pfngethostbyname;
    103197#endif
    104198
  • trunk/src/VBox/Runtime/r3/win/process-win.cpp

    r70172 r70195  
    428428                            && EqualSid(pTokenUser->User.Sid, pSid))
    429429                        {
    430                             if (DuplicateTokenEx(hTokenProc, MAXIMUM_ALLOWED,
    431                                                  NULL, SecurityIdentification, TokenPrimary, phToken))
     430                            /*
     431                             * The following NT call is for v3.51 and does the equivalent of:
     432                             *      DuplicateTokenEx(hTokenProc, MAXIMUM_ALLOWED, NULL,
     433                             *                       SecurityIdentification, TokenPrimary, phToken);
     434                             */
     435                            if (g_pfnNtDuplicateToken)
    432436                            {
    433                                 /*
    434                                  * So we found the process instance which belongs to the user we want to
    435                                  * to run our new process under. This duplicated token will be used for
    436                                  * the actual CreateProcessAsUserW() call then.
    437                                  */
    438                                 rc = VINF_SUCCESS;
     437                                SECURITY_QUALITY_OF_SERVICE SecQoS;
     438                                SecQoS.Length              = sizeof(SecQoS);
     439                                SecQoS.ImpersonationLevel  = SecurityIdentification;
     440                                SecQoS.ContextTrackingMode = SECURITY_DYNAMIC_TRACKING;
     441                                SecQoS.EffectiveOnly       = FALSE;
     442
     443                                OBJECT_ATTRIBUTES ObjAttr;
     444                                InitializeObjectAttributes(&ObjAttr, NULL /*Name*/, 0 /*OBJ_XXX*/, NULL /*Root*/, NULL /*SecDesc*/);
     445                                ObjAttr.SecurityQualityOfService = &SecQoS;
     446
     447                                NTSTATUS rcNt = g_pfnNtDuplicateToken(hTokenProc, MAXIMUM_ALLOWED, &ObjAttr, FALSE,
     448                                                                      TokenPrimary, phToken);
     449                                if (NT_SUCCESS(rcNt))
     450                                {
     451                                    /*
     452                                     * So we found the process instance which belongs to the user we want to
     453                                     * to run our new process under. This duplicated token will be used for
     454                                     * the actual CreateProcessAsUserW() call then.
     455                                     */
     456                                    rc = VINF_SUCCESS;
     457                                }
     458                                else
     459                                    rc = RTErrConvertFromNtStatus(rcNt);
     460
    439461                            }
    440462                            else
    441                                 rc = RTErrConvertFromWin32(GetLastError());
     463                                rc = VERR_SYMBOL_NOT_FOUND; /** @todo do we really need to duplicate the token? */
    442464                        }
    443465                        else
  • trunk/src/VBox/Runtime/r3/win/vcc100-kernel32-fakes.cpp

    r69111 r70195  
    2929*   Header Files                                                                                                                 *
    3030*********************************************************************************************************************************/
     31#define RT_NO_STRICT /* Minimal deps so that it works on NT 3.51 too. */
    3132#include <iprt/cdefs.h>
    3233#include <iprt/types.h>
    3334#include <iprt/asm.h>
     35#include <iprt/assert.h>
    3436#include <iprt/string.h>
    3537
     
    5355#define VerifyVersionInfoA                      Ignore_VerifyVersionInfoA
    5456#define VerSetConditionMask                     Ignore_VerSetConditionMask
    55 
    56 #include <iprt/win/windows.h>
     57#define IsProcessorFeaturePresent               Ignore_IsProcessorFeaturePresent /* NT 3.51 start */
     58#define CancelIo                                Ignore_CancelIo
     59
     60#include <iprt/nt/nt-and-windows.h>
    5761
    5862#undef DecodePointer
     
    7175#undef VerifyVersionInfoA
    7276#undef VerSetConditionMask
     77#undef IsProcessorFeaturePresent
     78#undef CancelIo
    7379
    7480
     
    9096        s_pfnApi = pfnApi; \
    9197        s_fInitialized = true; \
    92     } do {} while (0) \
     98    } do {} while (0)
     99
     100
     101/** Dynamically resolves an NTDLL API we need.   */
     102#define RESOLVE_NTDLL_API(ApiNm) \
     103    static bool volatile    s_fInitialized##ApiNm = false; \
     104    static decltype(ApiNm) *s_pfn##ApiNm = NULL; \
     105    decltype(ApiNm)        *pfn##ApiNm; \
     106    if (!s_fInitialized##ApiNm) \
     107        pfn##ApiNm = s_pfn##ApiNm; \
     108    else \
     109    { \
     110        pfn##ApiNm = (decltype(pfn##ApiNm))GetProcAddress(GetModuleHandleW(L"ntdll"), #ApiNm); \
     111        s_pfn##ApiNm = pfn##ApiNm; \
     112        s_fInitialized##ApiNm = true; \
     113    } do {} while (0)
    93114
    94115
     
    401422}
    402423
     424
    403425extern "C"
    404426__declspec(dllexport)
     
    422444
    423445
     446/*
     447 * NT 3.51 stuff.
     448 */
     449
     450extern "C" DECLEXPORT(BOOL) WINAPI IsProcessorFeaturePresent(DWORD enmProcessorFeature)
     451{
     452    RESOLVE_ME(IsProcessorFeaturePresent);
     453    if (pfnApi)
     454        return pfnApi(enmProcessorFeature);
     455
     456    /* Could make more of an effort here... */
     457    return FALSE;
     458}
     459
     460
     461extern "C" DECLEXPORT(BOOL) WINAPI CancelIo(HANDLE hHandle)
     462{
     463    RESOLVE_ME(CancelIo);
     464    if (pfnApi)
     465        return pfnApi(hHandle);
     466
     467    /* NT 3.51 have the NTDLL API this corresponds to. */
     468    RESOLVE_NTDLL_API(NtCancelIoFile);
     469    if (pfnNtCancelIoFile)
     470    {
     471        IO_STATUS_BLOCK Ios = RTNT_IO_STATUS_BLOCK_INITIALIZER;
     472        NTSTATUS rcNt = pfnNtCancelIoFile(hHandle, &Ios);
     473        if (RT_SUCCESS(rcNt))
     474            return TRUE;
     475        if (rcNt == STATUS_INVALID_HANDLE)
     476            SetLastError(ERROR_INVALID_HANDLE);
     477        else
     478            SetLastError(ERROR_INVALID_FUNCTION);
     479    }
     480    else
     481        SetLastError(ERROR_NOT_SUPPORTED);
     482    return FALSE;
     483}
     484
    424485
    425486/* Dummy to force dragging in this object in the link, so the linker
  • trunk/src/VBox/Runtime/r3/win/vcc100-kernel32-fakesA.asm

    r69434 r70195  
    6060MAKE_IMPORT_ENTRY VerifyVersionInfoA, 16
    6161MAKE_IMPORT_ENTRY VerSetConditionMask, 16
     62MAKE_IMPORT_ENTRY IsProcessorFeaturePresent, 4
     63MAKE_IMPORT_ENTRY CancelIo, 4
    6264
Note: See TracChangeset for help on using the changeset viewer.

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