VirtualBox

Ignore:
Timestamp:
Mar 4, 2007 8:52:45 PM (18 years ago)
Author:
vboxsync
Message:

Ported the support driver to OS/2.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/Support/os2/SUPLib-os2.cpp

    • Property svn:keywords changed from Author Date Id Revision to Id
    r1 r1193  
    2525*   Header Files                                                               *
    2626*******************************************************************************/
     27#define INCL_BASE
     28#define INCL_ERRORS
     29#include <os2.h>
     30#undef RT_MAX
     31
    2732#include <VBox/types.h>
    2833#include <VBox/sup.h>
     
    3540#include "SUPDRVIOC.h"
    3641
    37 #include <sys/fcntl.h>
    38 #include <sys/ioctl.h>
    3942#include <errno.h>
    4043#include <unistd.h>
    4144#include <stdlib.h>
    42 #include <string.h>
    4345
    4446
     
    4749*******************************************************************************/
    4850/** OS/2 Device name. */
    49 #define DEVICE_NAME     "/dev/$vboxdrv"
     51#define DEVICE_NAME     "/dev/vboxdrv$"
    5052
    5153
     
    5557*******************************************************************************/
    5658/** Handle to the open device. */
    57 static int      g_hDevice = -1;
    58 /** Flags whether or not we've loaded the kernel module. */
    59 static bool     g_fLoadedModule = false;
     59static HFILE    g_hDevice = (HFILE)-1;
    6060
    6161
     
    8080     * Check if already initialized.
    8181     */
    82     if (g_hDevice >= 0)
     82    if (g_hDevice != (HFILE)-1)
    8383        return 0;
    8484
    85 #if 0
    8685    /*
    8786     * Try open the device.
    8887     */
    89     g_hDevice = open(DEVICE_NAME, O_RDWR, 0);
    90     if (g_hDevice < 0)
    91     {
    92         /*
    93          * Try load the device.
    94          */
    95         //todo suplibOsLoadKernelModule();
    96         g_hDevice = open(DEVICE_NAME, O_RDWR, 0);
    97         if (g_hDevice < 0)
    98             return RTErrConvertFromErrno(errno);
    99     }
    100 
    101     /*
    102      * Check driver version.
    103      */
    104     /** @todo implement driver version checking. */
    105 
    106     /*
    107      * We're done.
    108      */
     88    ULONG ulAction = 0;
     89    HFILE hDevice = (HFILE)-1;
     90    APIRET rc = DosOpen((PCSZ)DEVICE_NAME,
     91                        &hDevice,
     92                        &ulAction,
     93                        0,
     94                        FILE_NORMAL,
     95                        OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
     96                        OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYNONE | OPEN_ACCESS_READWRITE,
     97                        NULL);
     98    if (rc)
     99        return RTErrConvertFromOS2(rc);
     100    g_hDevice = hDevice;
     101
    109102    NOREF(cbReserve);
    110     return 0;
    111 #else
    112     NOREF(cbReserve);
    113     return VERR_NOT_IMPLEMENTED;
    114 #endif
     103    return VINF_SUCCESS;
    115104}
    116105
     
    121110     * Check if we're initited at all.
    122111     */
    123     if (g_hDevice >= 0)
     112    if (g_hDevice != (HFILE)-1)
    124113    {
    125         if (close(g_hDevice))
    126             AssertFailed();
    127         g_hDevice = -1;
     114        APIRET rc = DosClose(g_hDevice);
     115        AssertMsg(rc == NO_ERROR, ("%d\n", rc)); NOREF(rc);
     116        g_hDevice = (HFILE)-1;
    128117    }
    129118
    130     /*
    131      * If we started the service we might consider stopping it too.
    132      *
    133      * Since this won't work unless the the process starting it is the
    134      * last user we might wanna skip this...
    135      */
    136     if (g_fLoadedModule)
    137     {
    138         //todo kernel module unloading.
    139         //suplibOsStopService();
    140         //g_fStartedService = false;
    141     }
    142 
    143119    return 0;
    144120}
    145121
    146122
    147 /**
    148  * Installs anything required by the support library.
    149  *
    150  * @returns 0 on success.
    151  * @returns error code on failure.
    152  */
    153123int suplibOsInstall(void)
    154124{
    155 //    int rc = mknod(DEVICE_NAME, S_IFCHR, );
    156 
    157     return VERR_NOT_IMPLEMENTED;
    158 }
    159 
    160 
    161 /**
    162  * Installs anything required by the support library.
    163  *
    164  * @returns 0 on success.
    165  * @returns error code on failure.
    166  */
     125    /** @remark OS/2: Not supported */
     126    return VERR_NOT_SUPPORTED;
     127}
     128
     129
    167130int suplibOsUninstall(void)
    168131{
    169 //    int rc = unlink(DEVICE_NAME);
    170 
    171     return VERR_NOT_IMPLEMENTED;
    172 }
    173 
    174 
    175 /**
    176  * Send a I/O Control request to the device.
    177  *
    178  * @returns 0 on success.
    179  * @returns VBOX error code on failure.
    180  * @param   uFunction   IO Control function.
    181  * @param   pvIn        Input data buffer.
    182  * @param   cbIn        Size of input data.
    183  * @param   pvOut       Output data buffer.
    184  * @param   cbOut       Size of output data.
    185  */
    186 int     suplibOsIOCtl(unsigned uFunction, void *pvIn, size_t cbIn, void *pvOut, size_t cbOut)
    187 {
    188 #if 0
    189     AssertMsg(g_hDevice != -1, ("SUPLIB not initiated successfully!\n"));
    190     /*
    191      * Issue device iocontrol.
    192      */
     132    /** @remark OS/2: Not supported */
     133    return VERR_NOT_SUPPORTED;
     134}
     135
     136
     137int suplibOsIOCtl(unsigned uFunction, void *pvIn, size_t cbIn, void *pvOut, size_t cbOut)
     138{
     139    AssertMsg(g_hDevice != (HFILE)-1, ("SUPLIB not initiated successfully!\n"));
     140
    193141    SUPDRVIOCTLDATA Args;
    194142    Args.pvIn = pvIn;
     
    196144    Args.pvOut = pvOut;
    197145    Args.cbOut = cbOut;
    198 
    199     if (ioctl(g_hDevice, uFunction, &Args) >= 0)
    200         return 0;
    201     /* This is the reverse operation of the one found in SUPDrv-linux.c */
    202     switch (errno)
     146    Args.rc = VERR_INTERNAL_ERROR;
     147
     148    ULONG cbReturned = sizeof(Args);
     149    int rc = DosDevIOCtl(g_hDevice, SUP_CTL_CATEGORY, uFunction,
     150                         &Args, sizeof(Args), &cbReturned,
     151                         NULL, 0, NULL);
     152    if (RT_LIKELY(rc == NO_ERROR))
     153        rc = Args.rc;
     154    else
     155        rc = RTErrConvertFromOS2(rc);
     156    return rc;
     157}
     158
     159
     160#ifdef VBOX_WITHOUT_IDT_PATCHING
     161int suplibOSIOCtlFast(unsigned uFunction)
     162{
     163    int32_t rcRet = VERR_INTERNAL_ERROR;
     164    ULONG cbRet = sizeof(rcRet);
     165    int rc = DosDevIOCtl(g_hDevice, SUP_CTL_CATEGORY_FAST, uFunction,
     166                         NULL, 0, NULL,
     167                         &rcRet, sizeof(rcRet), &cbRet);
     168    if (RT_LIKELY(rc == NO_ERROR))
     169        rc = rcRet;
     170    else
     171        rc = RTErrConvertFromOS2(rc);
     172    return rc;
     173}
     174#endif
     175
     176
     177int suplibOsPageAlloc(size_t cPages, void **ppvPages)
     178{
     179    *ppvPages = NULL;
     180    int rc = DosAllocMem(ppvPages, cPages << PAGE_SHIFT, PAG_READ | PAG_WRITE | PAG_EXECUTE | PAG_COMMIT | OBJ_ANY);
     181    if (rc == ERROR_INVALID_PARAMETER)
     182        rc = DosAllocMem(ppvPages, cPages << PAGE_SHIFT, PAG_READ | PAG_WRITE | PAG_EXECUTE | PAG_COMMIT | OBJ_ANY);
     183    if (!rc)
     184        rc = VINF_SUCCESS;
     185    else
     186        rc = RTErrConvertFromOS2(rc);
     187    return rc;
     188}
     189
     190
     191int suplibOsPageFree(void *pvPages)
     192{
     193    if (pvPages)
    203194    {
    204         case EACCES: return VERR_GENERAL_FAILURE;
    205         case EINVAL: return VERR_INVALID_PARAMETER;
    206         case ENOSYS: return VERR_INVALID_MAGIC;
    207         case ENXIO:  return VERR_INVALID_HANDLE;
    208         case EFAULT: return VERR_INVALID_POINTER;
    209         case ENOLCK: return VERR_LOCK_FAILED;
    210         case EEXIST: return VERR_ALREADY_LOADED;
     195        int rc = DosFreeMem(pvPages);
     196        Assert(!rc);
    211197    }
    212 
    213     return RTErrConvertFromErrno(errno);
    214 #else
    215     return VERR_NOT_IMPLEMENTED;
    216 #endif
    217 }
    218 
    219 
    220 /**
    221  * Allocate a number of zero-filled pages in user space.
    222  *
    223  * @returns VBox status code.
    224  * @param   cPages      Number of pages to allocate.
    225  * @param   ppvPages    Where to return the base pointer.
    226  */
    227 int     suplibOsPageAlloc(size_t cPages, void **ppvPages)
    228 {
    229     if (!posix_memalign(ppvPages, PAGE_SIZE, cPages << PAGE_SHIFT))
    230     {
    231         memset(*ppvPages, 0, cPages << PAGE_SHIFT);
    232         return VINF_SUCCESS;
    233     }
    234     return RTErrConvertFromErrno(errno);
    235 }
    236 
    237 
    238 /**
    239  * Frees pages allocated by suplibOsPageAlloc().
    240  *
    241  * @returns VBox status code.
    242  * @param   pvPages     Pointer to pages.
    243  */
    244 int     suplibOsPageFree(void *pvPages)
    245 {
    246     free(pvPages);
    247198    return VINF_SUCCESS;
    248199}
    249200
    250 
    251 
    252 
    253 
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