]> git.saurik.com Git - apple/xnu.git/blobdiff - iokit/Kernel/IOSharedDataQueue.cpp
xnu-2782.10.72.tar.gz
[apple/xnu.git] / iokit / Kernel / IOSharedDataQueue.cpp
index 0ad0f3cdec1a96a7d0c7bee8ec71e1d605fb3341..71daaa6b449ae17a5ee5c881ae8c96b706a7a240 100644 (file)
@@ -99,10 +99,11 @@ Boolean IOSharedDataQueue::initWithCapacity(UInt32 size)
     if (dataQueue == 0) {
         return false;
     }
+    bzero(dataQueue, allocSize);
 
     dataQueue->queueSize    = size;
-    dataQueue->head         = 0;
-    dataQueue->tail         = 0;
+//  dataQueue->head         = 0;
+//  dataQueue->tail         = 0;
 
     if (!setQueueSize(size)) {
         return false;
@@ -110,7 +111,14 @@ Boolean IOSharedDataQueue::initWithCapacity(UInt32 size)
     
     appendix            = (IODataQueueAppendix *)((UInt8 *)dataQueue + size + DATA_QUEUE_MEMORY_HEADER_SIZE);
     appendix->version   = 0;
-    notifyMsg           = &(appendix->msgh);
+
+    if (!notifyMsg) {
+        notifyMsg = IOMalloc(sizeof(mach_msg_header_t));
+        if (!notifyMsg)
+            return false;
+    }
+    bzero(notifyMsg, sizeof(mach_msg_header_t));
+
     setNotificationPort(MACH_PORT_NULL);
 
     return true;
@@ -121,6 +129,10 @@ void IOSharedDataQueue::free()
     if (dataQueue) {
         IOFreeAligned(dataQueue, round_page(getQueueSize() + DATA_QUEUE_MEMORY_HEADER_SIZE + DATA_QUEUE_MEMORY_APPENDIX_SIZE));
         dataQueue = NULL;
+        if (notifyMsg) {
+            IOFree(notifyMsg, sizeof(mach_msg_header_t));
+            notifyMsg = NULL;
+        }
     }
 
     if (_reserved) {
@@ -192,7 +204,7 @@ Boolean IOSharedDataQueue::enqueue(void * data, UInt32 dataSize)
         return false;
     }
     // Check for underflow of (getQueueSize() - tail)
-    if (getQueueSize() < tail) {
+    if (getQueueSize() < tail || getQueueSize() < head) {
         return false;
     }