VirtualBox

Changeset 6231 in vbox


Ignore:
Timestamp:
Jan 3, 2008 3:28:30 PM (17 years ago)
Author:
vboxsync
Message:

Guest Additions: add R3 backdoor logging for Linux guests

Location:
trunk/src/VBox
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3Lib.cpp

    r6118 r6231  
    9797    g_File = hf;
    9898
    99 #elif defined(RT_OS_SOLARIS)
     99#elif defined(RT_OS_SOLARIS) || defined(RT_OS_LINUX)
    100100    RTFILE File;
    101101    int rc = RTFileOpen(&File, VBOXGUEST_DEVICE_NAME, RTFILE_O_READWRITE);
     
    105105
    106106#else
     107# error port me  /** @note isn't it nicer to put a todo error here than to
     108                     put in a flag which will assert where no-one sees it? */
    107109    /* the default implemenation. */
    108110    RTFILE File;
     
    242244    return vbglR3DoIOCtl(VBOXGUEST_IOCTL_WAITEVENT_INTERRUPT_ALL, 0, 0);
    243245}
     246
     247/**
     248 * Write to the backdoor logger from ring 3 guest code.
     249 * @note this currently does not accept more than 255 bytes of data at
     250 * one time.  It should probably be rewritten to use pass a pointer
     251 * in the IOCtl.
     252 *
     253 * @returns IPRT status code
     254 */
     255VBGLR3DECL(int) VbglR3WriteLog(const char *pch, size_t cb)
     256{
     257    int rc = VINF_SUCCESS;
     258
     259    /* Solaris does not accept more than 255 bytes of data. */
     260#define STEP 128
     261    for (size_t iOffs = 0; (iOffs < cb) && (RT_SUCCESS(rc)); iOffs += STEP)
     262    {
     263        rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_LOG(cb), (void *) (pch + iOffs),
     264                           iOffs + STEP < cb ? STEP : cb - iOffs);
     265    }
     266#undef STEP
     267    return rc;
     268}
  • trunk/src/VBox/Additions/linux/module/vboxmod.c

    r6042 r6231  
    362362        int rc = 0;
    363363
    364         switch (cmd) {
    365         case IOCTL_VBOXGUEST_WAITEVENT:
    366                 rc = vboxadd_wait_event((void *) arg);
    367                 break;
    368 
    369         case VBOXGUEST_IOCTL_WAITEVENT_INTERRUPT_ALL:
    370                 ++vboxDev->u32GuestInterruptions;
    371                 break;
    372 
    373         case IOCTL_VBOXGUEST_VMMREQUEST: {
     364        /* Deal with variable size ioctls first. */
     365        if (VBOXGUEST_IOCTL_NUMBER(VBOXGUEST_IOCTL_LOG(0)) == VBOXGUEST_IOCTL_NUMBER(cmd)) {
     366                char *pszMessage = kmalloc(VBOXGUEST_IOCTL_SIZE(cmd), GFP_KERNEL);
     367                if (NULL == pszMessage) {
     368                        LogRelFunc(("VBOXGUEST_IOCTL_LOG: cannot allocate %d bytes of memory!\n",
     369                                    VBOXGUEST_IOCTL_SIZE(cmd)));
     370                        rc = -ENOMEM;
     371                }
     372                if (   (0 == rc)
     373                    && copy_from_user(pszMessage, (void*)arg, VBOXGUEST_IOCTL_SIZE(cmd))) {
     374                        LogRelFunc(("VBOXGUEST_IOCTL_LOG: copy_from_user failed!\n"));
     375                        rc = -EFAULT;
     376                }
     377                if (0 == rc) {
     378                    Log(("%.*s", VBOXGUEST_IOCTL_SIZE(cmd), pszMessage));
     379                }
     380                if (NULL != pszMessage) {
     381                    kfree(pszMessage);
     382                }
     383                return rc;
     384        }
     385
     386        if (   VBOXGUEST_IOCTL_NUMBER(VBOXGUEST_IOCTL_VMMREQUEST(0))
     387            == VBOXGUEST_IOCTL_NUMBER(cmd))  {
    374388            VMMDevRequestHeader reqHeader;
    375389            VMMDevRequestHeader *reqFull = NULL;
     
    446460            }
    447461            VbglGRFree(reqFull);
    448             break;
    449         }
     462            return rc;
     463        }
     464
     465        switch (cmd) {
     466        case IOCTL_VBOXGUEST_WAITEVENT:
     467                rc = vboxadd_wait_event((void *) arg);
     468                break;
     469
     470        case VBOXGUEST_IOCTL_WAITEVENT_INTERRUPT_ALL:
     471                ++vboxDev->u32GuestInterruptions;
     472                break;
    450473
    451474        case IOCTL_VBOXGUEST_HGCM_CALL:
  • trunk/src/VBox/Runtime/Makefile.kmk

    r6147 r6231  
    540540endif
    541541RuntimeLnx32GuestR3_SOURCES    = $(RuntimeR3_SOURCES.linux) $(RuntimeR3_SOURCES)
     542RuntimeLnx32GuestR3_SOURCES   += VBox/logbackdoor.cpp
    542543RuntimeLnx32GuestR3_INCS       = $(RuntimeR3_INCS.linux)    $(RuntimeR3_INCS)
    543544
  • trunk/src/VBox/Runtime/VBox/logbackdoor.cpp

    r5999 r6231  
    6868}
    6969
     70#ifdef IN_GUEST_R0
    7071
    7172RTDECL(void) RTLogWriteUser(const char *pch, size_t cb)
     
    8687}
    8788
     89#elif defined(RT_OS_LINUX) && defined(IN_GUEST_R3)
     90
     91#include <VBox/VBoxGuest.h>
     92
     93RTDECL(void) RTLogWriteUser(const char *pch, size_t cb)
     94{
     95    VbglR3WriteLog(pch, cb);
     96}
     97
     98#else
     99# error Port me!
     100#endif
    88101
    89102#if defined(RT_OS_LINUX) && defined(IN_MODULE)
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