DrvHostSerial.cpp revision fbf08fabb4c4b383d6aa2830c2bd5b943a26f10c
/* $Id$ */
/** @file
* VBox stream I/O devices: Host serial driver
*/
/*
* Copyright (C) 2006-2010 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_DRV_HOST_SERIAL
#include <iprt/semaphore.h>
#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
# include <errno.h>
# ifdef RT_OS_SOLARIS
# else
# include <termios.h>
# endif
# include <fcntl.h>
# include <string.h>
# include <unistd.h>
# ifdef RT_OS_DARWIN
# else
# endif
# include <pthread.h>
# ifdef RT_OS_LINUX
/*
* But inclusion of this file however leads to compilation errors because of redefinition of some
* structs. Thatswhy it is defined here until a better solution is found.
*/
# ifndef TIOCM_LOOP
# define TIOCM_LOOP 0x8000
# endif
/* For linux custom baudrate code we also need serial_struct */
# endif /* linux */
#elif defined(RT_OS_WINDOWS)
# include <Windows.h>
#endif
#include "../Builtins.h"
/** Size of the send fifo queue (in bytes) */
#ifdef RT_OS_DARWIN
/** @todo This is really desperate, but it seriously looks like
* the data is arriving way too fast for us to push over. 9600
# define CHAR_MAX_SEND_QUEUE 0x400
# define CHAR_MAX_SEND_QUEUE_MASK 0x3ff
#else
# define CHAR_MAX_SEND_QUEUE 0x80
# define CHAR_MAX_SEND_QUEUE_MASK 0x7f
#endif
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/**
* Char driver instance data.
*
* @implements PDMICHARCONNECTOR
*/
typedef struct DRVHOSTSERIAL
{
/** Pointer to the driver instance structure. */
/** Our char interface. */
/** Receive thread. */
/** Send thread. */
/** Status lines monitor thread. */
/** Send event semephore */
/** the device path */
char *pszDevicePath;
#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
/** the device handle */
# ifdef RT_OS_DARWIN
/** The device handle used for reading.
* Used to prevent the read selecto from blocking the writes. */
# endif
/** The read end of the control pipe */
/** The write end of the control pipe */
# ifndef RT_OS_LINUX
/** The current line status.
* Used by the polling version of drvHostSerialMonitorThread. */
int fStatusLines;
# endif
#elif defined(RT_OS_WINDOWS)
/** the device handle */
/** The event semaphore for waking up the receive thread */
/** The event semaphore for overlapped receiving */
/** For overlapped receiving */
/** The event semaphore for overlapped sending */
/** For overlapped sending */
#endif
/** Internal send FIFO queue */
uint32_t volatile iSendQueueHead;
uint32_t volatile iSendQueueTail;
#ifdef RT_OS_DARWIN
/** The number of bytes we've dropped because the send queue
* was full. */
#endif
/** Converts a pointer to DRVCHAR::ICharConnector to a PDRVHOSTSERIAL. */
#define PDMICHAR_2_DRVHOSTSERIAL(pInterface) RT_FROM_MEMBER(pInterface, DRVHOSTSERIAL, ICharConnector)
/* -=-=-=-=- IBase -=-=-=-=- */
/**
* @interface_method_impl{PDMIBASE,pfnQueryInterface}
*/
{
return NULL;
}
/* -=-=-=-=- ICharConnector -=-=-=-=- */
/** @copydoc PDMICHARCONNECTOR::pfnWrite */
static DECLCALLBACK(int) drvHostSerialWrite(PPDMICHARCONNECTOR pInterface, const void *pvBuf, size_t cbWrite)
{
{
#ifdef RT_OS_DARWIN /* don't wanna break the others here. */
if (cbAvail <= 0)
{
# ifdef DEBUG
# endif
Log(("%s: dropping %d chars (cbAvail=%d iHead=%d iTail=%d)\n", __FUNCTION__, cbWrite - i , cbAvail, iHead, iTail));
break;
}
{
}
#else /* old code */
#endif /* old code */
}
return VINF_SUCCESS;
}
static DECLCALLBACK(int) drvHostSerialSetParameters(PPDMICHARCONNECTOR pInterface, unsigned Bps, char chParity, unsigned cDataBits, unsigned cStopBits)
{
#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
struct termios *termiosSetup;
int baud_rate;
#elif defined(RT_OS_WINDOWS)
#endif
LogFlow(("%s: Bps=%u chParity=%c cDataBits=%u cStopBits=%u\n", __FUNCTION__, Bps, chParity, cDataBits, cStopBits));
/* Enable receiver */
switch (Bps) {
case 50:
break;
case 75:
break;
case 110:
break;
case 134:
break;
case 150:
break;
case 200:
break;
case 300:
break;
case 600:
break;
case 1200:
break;
case 1800:
break;
case 2400:
break;
case 4800:
break;
case 9600:
break;
case 19200:
break;
case 38400:
break;
case 57600:
break;
case 115200:
break;
default:
#ifdef RT_OS_LINUX
struct serial_struct serialStruct;
{
if (!serialStruct.custom_divisor)
}
else
#else /* !RT_OS_LINUX */
#endif /* !RT_OS_LINUX */
}
switch (chParity) {
case 'E':
break;
case 'O':
break;
case 'N':
break;
default:
break;
}
switch (cDataBits) {
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
break;
default:
break;
}
switch (cStopBits) {
case 2:
default:
break;
}
/* set serial port to raw input */
#elif defined(RT_OS_WINDOWS)
switch (Bps) {
case 110:
break;
case 300:
break;
case 600:
break;
case 1200:
break;
case 2400:
break;
case 4800:
break;
case 9600:
break;
case 14400:
break;
case 19200:
break;
case 38400:
break;
case 57600:
break;
case 115200:
break;
default:
}
switch (chParity) {
case 'E':
break;
case 'O':
break;
case 'N':
break;
default:
break;
}
switch (cStopBits) {
case 1:
break;
case 2:
break;
default:
break;
}
#endif /* RT_OS_WINDOWS */
return VINF_SUCCESS;
}
/* -=-=-=-=- receive thread -=-=-=-=- */
/**
* Send thread loop.
*
* @returns VINF_SUCCESS.
* @param ThreadSelf Thread handle to this thread.
* @param pvUser User argument.
*/
{
return VINF_SUCCESS;
#ifdef RT_OS_WINDOWS
/* Make sure that the halt event semaphore is reset. */
#endif
{
if (RT_FAILURE(rc))
break;
/*
* Write the character to the host device.
*/
#ifdef RT_OS_DARWIN
{
/* copy the send queue so we get a linear buffer with the maximal size. */
break;
do
{
/* write it. */
# ifdef DEBUG
# endif
# if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
if (rc == VERR_TRY_AGAIN)
cbWritten = 0;
{
/* ok, block till the device is ready for more (O_NONBLOCK) effect. */
rc = VINF_SUCCESS;
{
/* advance */
/* wait */
/** @todo check rc? */
/* try write more */
if (rc == VERR_TRY_AGAIN)
cbWritten = 0;
else if (RT_FAILURE(rc))
break;
break;
rc = VINF_SUCCESS;
}
# elif defined(RT_OS_WINDOWS)
/* perform an overlapped write operation. */
{
dwRet = GetLastError();
if (dwRet == ERROR_IO_PENDING)
{
/*
* write blocked, wait for completion or wakeup...
*/
if (dwRet != WAIT_OBJECT_0)
{
AssertMsg(pThread->enmState != PDMTHREADSTATE_RUNNING, ("The halt event sempahore is set but the thread is still in running state\n"));
break;
}
}
else
}
# endif /* RT_OS_WINDOWS */
if (RT_FAILURE(rc))
{
LogRel(("HostSerial#%d: Serial Write failed with %Rrc; terminating send thread\n", pDrvIns->iInstance, rc));
return rc;
}
} /* write loop */
#else /* old code */
&& (iTail = ASMAtomicUoReadU32(&pThis->iSendQueueTail)) != ASMAtomicUoReadU32(&pThis->iSendQueueHead))
{
/** @todo process more than one byte? */
unsigned cbProcessed = 1;
# if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
# elif defined(RT_OS_WINDOWS)
{
dwRet = GetLastError();
if (dwRet == ERROR_IO_PENDING)
{
/*
* write blocked, wait ...
*/
if (dwRet != WAIT_OBJECT_0)
{
AssertMsg(pThread->enmState != PDMTHREADSTATE_RUNNING, ("The halt event sempahore is set but the thread is still in running state\n"));
break;
}
}
else
}
# endif
if (RT_SUCCESS(rc))
{
}
else if (RT_FAILURE(rc))
{
LogRel(("HostSerial#%d: Serial Write failed with %Rrc; terminating send thread\n", pDrvIns->iInstance, rc));
return rc;
}
}
#endif /* old code */
}
return VINF_SUCCESS;
}
/**
* Unblock the send thread so it can respond to a state change.
*
* @returns a VBox status code.
* @param pDrvIns The driver instance.
* @param pThread The send thread.
*/
{
int rc;
if (RT_FAILURE(rc))
return rc;
#ifdef RT_OS_WINDOWS
return RTErrConvertFromWin32(GetLastError());
#endif
return VINF_SUCCESS;
}
/* -=-=-=-=- receive thread -=-=-=-=- */
/**
* Receive thread loop.
*
* This thread pushes data from the host serial device up the driver
* chain toward the serial device.
*
* @returns VINF_SUCCESS.
* @param ThreadSelf Thread handle to this thread.
* @param pvUser User argument.
*/
{
int rc = VINF_SUCCESS;
int rcThread = VINF_SUCCESS;
return VINF_SUCCESS;
#ifdef RT_OS_WINDOWS
/* Make sure that the halt event semaphore is reset. */
#endif
{
if (!cbRemaining)
{
/* Get a block of data from the host serial device. */
#if defined(RT_OS_DARWIN) /* poll is broken on x86 darwin, returns POLLNVAL. */
# if 1 /* it seems like this select is blocking the write... */
# else
# endif
if (rc == -1)
{
LogRel(("HostSerial#%d: select failed with errno=%d / %Rrc, terminating the worker thread.\n", pDrvIns->iInstance, err, rcThread));
break;
}
/* this might have changed in the meantime */
break;
if (rc == 0)
continue;
/* drain the wakeup pipe */
{
if (RT_FAILURE(rc))
{
LogRel(("HostSerial#%d: draining the wakekup pipe failed with %Rrc, terminating the worker thread.\n", pDrvIns->iInstance, rc));
break;
}
continue;
}
/* read data from the serial port. */
if (RT_FAILURE(rc))
{
LogRel(("HostSerial#%d: (1) Read failed with %Rrc, terminating the worker thread.\n", pDrvIns->iInstance, rc));
break;
}
if (rc < 0)
{
LogRel(("HostSerial#%d: poll failed with errno=%d / %Rrc, terminating the worker thread.\n", pDrvIns->iInstance, err, rcThread));
break;
}
/* this might have changed in the meantime */
break;
{
break;
/* notification to terminate -- drain the pipe */
continue;
}
if (RT_FAILURE(rc))
{
/* don't terminate worker thread when data unavailable */
if (rc == VERR_TRY_AGAIN)
continue;
LogRel(("HostSerial#%d: (2) Read failed with %Rrc, terminating the worker thread.\n", pDrvIns->iInstance, rc));
break;
}
#elif defined(RT_OS_WINDOWS)
DWORD dwEventMask = 0;
{
dwRet = GetLastError();
if (dwRet == ERROR_IO_PENDING)
{
if (dwRet != WAIT_OBJECT_0)
{
/* notification to terminate */
AssertMsg(pThread->enmState != PDMTHREADSTATE_RUNNING, ("The halt event sempahore is set but the thread is still in running state\n"));
break;
}
}
else
{
LogRel(("HostSerial#%d: Wait failed with error %Rrc; terminating the worker thread.\n", pDrvIns->iInstance, rcThread));
break;
}
}
/* this might have changed in the meantime */
break;
/* Check the event */
if (dwEventMask & EV_RXCHAR)
{
if (!ReadFile(pThis->hDeviceFile, abBuffer, sizeof(abBuffer), &dwNumberOfBytesTransferred, &pThis->overlappedRecv))
{
LogRel(("HostSerial#%d: Read failed with error %Rrc; terminating the worker thread.\n", pDrvIns->iInstance, rcThread));
break;
}
}
else if (dwEventMask & EV_BREAK)
{
Log(("HostSerial#%d: Detected break\n"));
}
else
{
/* The status lines have changed. Notify the device. */
/* Get the new state */
{
if (dwNewStatusLinesState & MS_RLSD_ON)
if (dwNewStatusLinesState & MS_RING_ON)
if (dwNewStatusLinesState & MS_DSR_ON)
if (dwNewStatusLinesState & MS_CTS_ON)
if (RT_FAILURE(rc))
{
/* Notifying device failed, continue but log it */
LogRel(("HostSerial#%d: Notifying device failed with error %Rrc; continuing.\n", pDrvIns->iInstance, rc));
}
}
else
{
/* Getting new state failed, continue but log it */
LogRel(("HostSerial#%d: Getting status lines state failed with error %Rrc; continuing.\n", pDrvIns->iInstance, RTErrConvertFromWin32(GetLastError())));
}
}
#endif
}
else
{
/* Send data to the guest. */
if (RT_SUCCESS(rc))
{
pbBuffer += cbProcessed;
}
else if (rc == VERR_TIMEOUT)
{
/* Normal case, just means that the guest didn't accept a new
* character before the timeout elapsed. Just retry. */
rc = VINF_SUCCESS;
}
else
{
LogRel(("HostSerial#%d: NotifyRead failed with %Rrc, terminating the worker thread.\n", pDrvIns->iInstance, rc));
break;
}
}
}
return rcThread;
}
/**
* Unblock the send thread so it can respond to a state change.
*
* @returns a VBox status code.
* @param pDrvIns The driver instance.
* @param pThread The send thread.
*/
{
#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
#elif defined(RT_OS_WINDOWS)
return RTErrConvertFromWin32(GetLastError());
return VINF_SUCCESS;
#else
#endif
}
#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
/* -=-=-=-=- Monitor thread -=-=-=-=- */
/**
* Monitor thread loop.
*
* This thread monitors the status lines and notifies the device
* if they change.
*
* @returns VINF_SUCCESS.
* @param ThreadSelf Thread handle to this thread.
* @param pvUser User argument.
*/
{
int rc = VINF_SUCCESS;
unsigned uStatusLinesToCheck = 0;
return VINF_SUCCESS;
{
uint32_t newStatusLine = 0;
unsigned int statusLines;
# ifdef RT_OS_LINUX
/*
* Wait for status line change.
*/
break;
if (rc < 0)
{
N_("Ioctl failed for serial host device '%s' (%Rrc). The device will not work properly"),
break;
}
if (rc < 0)
goto ioctl_error;
# else /* !RT_OS_LINUX */
/*
* Poll for the status line change.
*/
if (rc < 0)
{
N_("Ioctl failed for serial host device '%s' (%Rrc). The device will not work properly"),
break;
}
{
continue;
}
# endif /* !RT_OS_LINUX */
if (statusLines & TIOCM_CAR)
if (statusLines & TIOCM_RNG)
if (statusLines & TIOCM_LE)
if (statusLines & TIOCM_CTS)
}
return VINF_SUCCESS;
}
/**
* Unblock the monitor thread so it can respond to a state change.
* We need to execute this code exactly once during initialization.
* But we don't want to block --- therefore this dedicated thread.
*
* @returns a VBox status code.
* @param pDrvIns The driver instance.
* @param pThread The send thread.
*/
{
# ifdef RT_OS_LINUX
int rc = VINF_SUCCESS;
# if 0
unsigned int uSerialLineFlags;
unsigned int uSerialLineStatus;
unsigned int uIoctl;
# endif
/*
* Linux is a bit difficult as the thread is sleeping in an ioctl call.
* So there is no way to have a wakeup pipe.
*
* 1. Thatswhy we set the serial device into loopback mode and change one of the
* modem control bits.
* This should make the ioctl call return.
*
* 2. We still got reports about long shutdown times. It may bepossible
* that the loopback mode is not implemented on all devices.
* The next possible solution is to close the device file to make the ioctl
* return with EBADF and be able to suspend the thread.
*
* 3. The second approach doesn't work too, the ioctl doesn't return.
* But it seems that the ioctl is interruptible (return code in errno is EINTR).
*/
# if 0 /* Disabled because it does not work for all. */
/* Get current status of control lines. */
if (rc < 0)
goto ioctl_error;
if (rc < 0)
goto ioctl_error;
/*
* Change current level on the RTS pin to make the ioctl call return in the
* monitor thread.
*/
if (rc < 0)
goto ioctl_error;
/* Change RTS back to the previous level. */
if (rc < 0)
goto ioctl_error;
/*
* Set serial device into normal state.
*/
if (rc >= 0)
return VINF_SUCCESS;
N_("Ioctl failed for serial host device '%s' (%Rrc). The device will not work properly"),
# endif
# if 0
/* Close file to make ioctl return. */
/* Open again to make use after suspend possible again. */
if (RT_FAILURE(rc))
N_("Opening failed for serial host device '%s' (%Rrc). The device will not work"),
# endif
if (RT_FAILURE(rc))
N_("Suspending serial monitor thread failed for serial device '%s' (%Rrc). The shutdown may take longer than expected"),
# else /* !RT_OS_LINUX*/
/* In polling mode there is nobody to wake up (PDMThread will cancel the sleep). */
# endif /* RT_OS_LINUX */
return VINF_SUCCESS;
}
#endif /* RT_OS_LINUX || RT_OS_DARWIN || RT_OS_SOLARIS */
/**
* Set the modem lines.
*
* @returns VBox status code
* @param pInterface Pointer to the interface structure.
* @param RequestToSend Set to true if this control line should be made active.
* @param DataTerminalReady Set to true if this control line should be made active.
*/
static DECLCALLBACK(int) drvHostSerialSetModemLines(PPDMICHARCONNECTOR pInterface, bool RequestToSend, bool DataTerminalReady)
{
#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
int modemStateSet = 0;
int modemStateClear = 0;
if (RequestToSend)
else
if (DataTerminalReady)
else
if (modemStateSet)
if (modemStateClear)
#elif defined(RT_OS_WINDOWS)
if (RequestToSend)
else
if (DataTerminalReady)
else
#endif
return VINF_SUCCESS;
}
/**
* Sets the TD line into break condition.
*
* @returns VBox status code.
* @param pInterface Pointer to the interface structure containing the called function pointer.
* @param fBreak Set to true to let the device send a break false to put into normal operation.
* @thread Any thread.
*/
{
#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
if (fBreak)
else
#elif defined(RT_OS_WINDOWS)
if (fBreak)
else
#endif
return VINF_SUCCESS;
}
/* -=-=-=-=- driver interface -=-=-=-=- */
/**
* Destruct a char driver instance.
*
* Most VM resources are freed by the VM. This callback is provided so that
* any non-VM resources can be freed correctly.
*
* @param pDrvIns The driver instance data.
*/
{
/* Empty the send queue */
#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
{
}
{
}
# if defined(RT_OS_DARWIN)
{
{
}
}
# endif
{
}
#elif defined(RT_OS_WINDOWS)
#endif
}
/**
* Construct a char driver instance.
*
* @copydoc FNPDMDRVCONSTRUCT
*/
static DECLCALLBACK(int) drvHostSerialConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
{
/*
* Init basic data members and interfaces.
*/
#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
# ifdef RT_OS_DARWIN
# endif
#endif
/* IBase. */
/* ICharConnector. */
/** @todo Initialize all members with NIL values!! The destructor is ALWAYS called. */
/*
* Query configuration.
*/
/* Device */
if (RT_FAILURE(rc))
{
return rc;
}
/*
* Open the device
*/
#ifdef RT_OS_WINDOWS
0, // must be opened with exclusive access
NULL, // no SECURITY_ATTRIBUTES structure
OPEN_EXISTING, // must use OPEN_EXISTING
FILE_FLAG_OVERLAPPED, // overlapped I/O
NULL); // no template file
if (hFile == INVALID_HANDLE_VALUE)
else
{
/* for overlapped read */
{
return VERR_FILE_IO_ERROR;
}
rc = VINF_SUCCESS;
}
#else
rc = RTFileOpen(&pThis->DeviceFile, pThis->pszDevicePath, RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE);
# ifdef RT_OS_DARWIN
if (RT_SUCCESS(rc))
rc = RTFileOpen(&pThis->DeviceFileR, pThis->pszDevicePath, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE);
# endif
#endif
if (RT_FAILURE(rc))
{
switch (rc)
{
case VERR_ACCESS_DENIED:
#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
"the group settings of the current user"),
#else
"of that device"),
#endif
default:
N_("Failed to open host device '%s'"),
}
}
/* Set to non blocking I/O */
#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
# ifdef RT_OS_DARWIN
# endif
int aFDs[2];
{
return rc;
}
#elif defined(RT_OS_WINDOWS)
/* Set the COMMTIMEOUTS to get non blocking I/O */
#endif
/*
*/
if (!pThis->pDrvCharPort)
return PDMDrvHlpVMSetError(pDrvIns, VERR_PDM_MISSING_INTERFACE_ABOVE, RT_SRC_POS, N_("HostSerial#%d has no char port interface above"), pDrvIns->iInstance);
/*
* Create the receive, send and monitor threads pluss the related send semaphore.
*/
rc = PDMDrvHlpThreadCreate(pDrvIns, &pThis->pRecvThread, pThis, drvHostSerialRecvThread, drvHostSerialWakeupRecvThread, 0, RTTHREADTYPE_IO, "SerRecv");
if (RT_FAILURE(rc))
return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, N_("HostSerial#%d cannot create receive thread"), pDrvIns->iInstance);
rc = PDMDrvHlpThreadCreate(pDrvIns, &pThis->pSendThread, pThis, drvHostSerialSendThread, drvHostSerialWakeupSendThread, 0, RTTHREADTYPE_IO, "SerSend");
if (RT_FAILURE(rc))
return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, N_("HostSerial#%d cannot create send thread"), pDrvIns->iInstance);
#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
/* Linux & darwin needs a separate thread which monitors the status lines. */
# ifndef RT_OS_LINUX
# endif
rc = PDMDrvHlpThreadCreate(pDrvIns, &pThis->pMonitorThread, pThis, drvHostSerialMonitorThread, drvHostSerialWakeupMonitorThread, 0, RTTHREADTYPE_IO, "SerMon");
if (RT_FAILURE(rc))
return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, N_("HostSerial#%d cannot create monitor thread"), pDrvIns->iInstance);
#endif
/*
* Register release statistics.
*/
PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatBytesWritten, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_BYTES, "Nr of bytes written", "/Devices/HostSerial%d/Written", pDrvIns->iInstance);
PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatBytesRead, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_BYTES, "Nr of bytes read", "/Devices/HostSerial%d/Read", pDrvIns->iInstance);
#ifdef RT_OS_DARWIN /* new Write code, not darwin specific. */
PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatSendOverflows, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_BYTES, "Nr of bytes overflowed", "/Devices/HostSerial%d/SendOverflow", pDrvIns->iInstance);
#endif
return VINF_SUCCESS;
}
/**
* Char driver registration record.
*/
const PDMDRVREG g_DrvHostSerial =
{
/* u32Version */
/* szName */
"Host Serial",
/* szRCMod */
"",
/* szR0Mod */
"",
/* pszDescription */
"Host serial driver.",
/* fFlags */
/* fClass. */
/* cMaxInstances */
~0,
/* cbInstance */
sizeof(DRVHOSTSERIAL),
/* pfnConstruct */
/* pfnDestruct */
/* pfnRelocate */
NULL,
/* pfnIOCtl */
NULL,
/* pfnPowerOn */
NULL,
/* pfnReset */
NULL,
/* pfnSuspend */
NULL,
/* pfnResume */
NULL,
/* pfnAttach */
NULL,
/* pfnDetach */
NULL,
/* pfnPowerOff */
NULL,
/* pfnSoftReset */
NULL,
/* u32EndVersion */
};