[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[win-pv-devel] [PATCH 4/4] Add Log IOCTL



Adds an IOCTL that sends a user defined message to Xen to log.

Signed-off-by: Owen Smith <owen.smith@xxxxxxxxxx>
---
 include/xeniface_ioctls.h | 15 ++++++++++++++
 src/xeniface/ioctls.c     | 51 +++++++++++++++++++++++++++++++++++++++++++++++
 src/xeniface/ioctls.h     |  8 ++++++++
 3 files changed, 74 insertions(+)

diff --git a/include/xeniface_ioctls.h b/include/xeniface_ioctls.h
index dcddb5e..86a6eea 100644
--- a/include/xeniface_ioctls.h
+++ b/include/xeniface_ioctls.h
@@ -369,4 +369,19 @@ typedef struct _XENIFACE_SUSPEND_REGISTER_OUT {
 #define IOCTL_XENIFACE_SHAREDINFO_GET_TIME \
     CTL_CODE(FILE_DEVICE_UNKNOWN, 0x840, METHOD_BUFFERED, FILE_ANY_ACCESS)
 
+/*! \brief Logs a message to Dom0
+
+    Input: NUL-terminated CHAR array containing the message to log
+           Must be less than XENIFACE_LOG_MAX_LENGTH long, and only contain
+           printable or newline characters ( isprint(x) || x == '\n' )
+
+    Output: None
+*/
+#define IOCTL_XENIFACE_LOG \
+    CTL_CODE(FILE_DEVICE_UNKNOWN, 0x84F, METHOD_BUFFERED, FILE_ANY_ACCESS)
+
+/*! \brief Maximum number of CHARs for IOCTL_XENIFACE_LOG, including NUL 
terminator
+*/
+#define XENIFACE_LOG_MAX_LENGTH         256
+
 #endif // _XENIFACE_IOCTLS_H_
diff --git a/src/xeniface/ioctls.c b/src/xeniface/ioctls.c
index 7092a56..639b015 100644
--- a/src/xeniface/ioctls.c
+++ b/src/xeniface/ioctls.c
@@ -85,6 +85,53 @@ __FreeCapturedBuffer(
     }
 }
 
+static FORCEINLINE
+BOOLEAN
+__IsValidStr(
+    __in  PCHAR             Str,
+    __in  ULONG             Len
+    )
+{
+    for ( ; Len--; ++Str) {
+        if (*Str == '\0')
+            return TRUE;
+        if (*Str == '\n' || *Str == '\r')
+            continue; // newline is allowed
+        if (!isprint((unsigned char)*Str))
+            break;
+    }
+    return FALSE;
+}
+
+DECLSPEC_NOINLINE
+NTSTATUS
+IoctlLog(
+    __in  PXENIFACE_FDO     Fdo,
+    __in  PCHAR             Buffer,
+    __in  ULONG             InLen,
+    __in  ULONG             OutLen
+    )
+{
+    NTSTATUS    status;
+
+    status = STATUS_INVALID_BUFFER_SIZE;
+    if (InLen == 0 || InLen > XENIFACE_LOG_MAX_LENGTH || OutLen != 0)
+        goto fail1;
+
+    status = STATUS_INVALID_PARAMETER;
+    if (!__IsValidStr(Buffer, InLen))
+        goto fail2;
+
+    XenIfaceDebugPrint(INFO, "USER: %s\n", Buffer);
+    return STATUS_SUCCESS;
+
+fail2:
+    XenIfaceDebugPrint(ERROR, "Fail2\n");
+fail1:
+    XenIfaceDebugPrint(ERROR, "Fail1 (%08x)\n", status);
+    return status;
+}
+
 // Cleanup store watches and event channels, called on file object close.
 _IRQL_requires_(PASSIVE_LEVEL) // EvtchnFree calls KeFlushQueuedDpcs
 VOID
@@ -262,6 +309,10 @@ XenIfaceIoctl(
         status = IoctlSharedInfoGetTime(Fdo, Buffer, InLen, OutLen, 
&Irp->IoStatus.Information);
         break;
 
+        // misc
+    case IOCTL_XENIFACE_LOG:
+        status = IoctlLog(Fdo, Buffer, InLen, OutLen);
+        break;
 
     default:
         status = STATUS_INVALID_DEVICE_REQUEST;
diff --git a/src/xeniface/ioctls.h b/src/xeniface/ioctls.h
index d06f6b5..14da674 100644
--- a/src/xeniface/ioctls.h
+++ b/src/xeniface/ioctls.h
@@ -418,5 +418,13 @@ IoctlSharedInfoGetTime(
     __out PULONG_PTR        Info
     );
 
+NTSTATUS
+IoctlLog(
+    __in  PXENIFACE_FDO     Fdo,
+    __in  PCHAR             Buffer,
+    __in  ULONG             InLen,
+    __in  ULONG             OutLen
+    );
+
 #endif // _IOCTLS_H_
 
-- 
1.9.4.msysgit.1


_______________________________________________
win-pv-devel mailing list
win-pv-devel@xxxxxxxxxxxxxxxxxxxx
http://lists.xenproject.org/cgi-bin/mailman/listinfo/win-pv-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.