Fix bz#343523, OS X mach_ports_register: UNKNOWN task message [id 3403, to mach_task_self(), reply 0x30f]

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14952 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/NEWS b/NEWS
index afcfb81..14784fc 100644
--- a/NEWS
+++ b/NEWS
@@ -92,6 +92,8 @@
 343306  OS X 10.10: UNKNOWN mach_msg unhandled MACH_SEND_TRAILER option
 343332  Unhandled instruction 0x9E310021 (fcvtmu) on aarch64
 343335  unhandled instruction 0x1E638400 (fccmp) aarch64
+343523  OS X mach_ports_register: UNKNOWN task message [id 3403, to 
+        mach_task_self(), reply 0x30f]
 343732  Unhandled syscall 144 (setgid) on aarch64
 343733  Unhandled syscall 187 (msgctl and related) on aarch64
 343802  s390x: Fix false positives "conditional jump or move depends on
diff --git a/coregrind/m_syswrap/priv_syswrap-darwin.h b/coregrind/m_syswrap/priv_syswrap-darwin.h
index 1a40633..9351b81 100644
--- a/coregrind/m_syswrap/priv_syswrap-darwin.h
+++ b/coregrind/m_syswrap/priv_syswrap-darwin.h
@@ -593,6 +593,7 @@
 DECL_TEMPLATE(darwin, semaphore_create);
 DECL_TEMPLATE(darwin, semaphore_destroy);
 DECL_TEMPLATE(darwin, task_policy_set);
+DECL_TEMPLATE(darwin, mach_ports_register);
 DECL_TEMPLATE(darwin, mach_ports_lookup);
 DECL_TEMPLATE(darwin, task_threads);
 DECL_TEMPLATE(darwin, task_suspend);
diff --git a/coregrind/m_syswrap/syswrap-darwin.c b/coregrind/m_syswrap/syswrap-darwin.c
index 4da31a6..cd4043a 100644
--- a/coregrind/m_syswrap/syswrap-darwin.c
+++ b/coregrind/m_syswrap/syswrap-darwin.c
@@ -5781,6 +5781,46 @@
    }
 }
 
+
+PRE(mach_ports_register)
+{
+#pragma pack(4)
+    typedef struct {
+       mach_msg_header_t Head;
+       /* start of the kernel processed data */
+       mach_msg_body_t msgh_body;
+       mach_msg_ool_ports_descriptor_t init_port_set;
+       /* end of the kernel processed data */
+       NDR_record_t NDR;
+       mach_msg_type_number_t init_port_setCnt;
+    } Request;
+#pragma pack()
+    
+    // Request *req = (Request *)ARG1;
+    
+    PRINT("mach_ports_register(%s)", name_for_port(MACH_REMOTE));
+    
+    AFTER = POST_FN(mach_ports_register);
+}
+
+POST(mach_ports_register)
+{
+#pragma pack(4)
+    typedef struct {
+       mach_msg_header_t Head;
+       NDR_record_t NDR;
+       kern_return_t RetCode;
+    } Reply;
+#pragma pack()
+    
+    Reply *reply = (Reply *)ARG1;
+    if (!reply->RetCode) {
+    } else {
+        PRINT("mig return %d", reply->RetCode);
+    }
+}
+
+
 PRE(mach_ports_lookup)
 {
 #pragma pack(4)
@@ -7696,6 +7736,9 @@
    case 3402:
       CALL_PRE(task_threads);
       return;
+   case 3403:
+      CALL_PRE(mach_ports_register);
+      return;
    case 3404:
       CALL_PRE(mach_ports_lookup);
       return;