]> xenbits.xensource.com Git - people/pauldu/xeniface.git/commitdiff
Add Log IOCTL
authorOwen Smith <owen.smith@citrix.com>
Mon, 27 Jun 2016 11:02:06 +0000 (12:02 +0100)
committerPaul Durrant <paul.durrant@citrix.com>
Tue, 5 Jul 2016 16:55:34 +0000 (17:55 +0100)
Adds an IOCTL that sends a user defined message to Xen to log.

Signed-off-by: Owen Smith <owen.smith@citrix.com>
include/xeniface_ioctls.h
src/xeniface/ioctls.c
src/xeniface/ioctls.h

index 857bf49f61b48fa3279775af6e721d83fdbb6660..dfb91dad0c530181c8e4bd22ea3d58729299ff43 100644 (file)
@@ -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_
index 7092a56566cf39762089370987ffcaee5a7f5088..639b015af2472ef808d65f8c30c31f9b7fe11c8b 100644 (file)
@@ -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;
index d06f6b524b229489e7945fcf6a335ac0685f1b9b..14da674761ef1048fe732a005ea1d945b29f94f7 100644 (file)
@@ -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_