Fix unhandled syscall: unix:132 (mkfifo) on OS X. bz#212291.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15242 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/NEWS b/NEWS
index 40cf7ce..b3e2c4c 100644
--- a/NEWS
+++ b/NEWS
@@ -76,6 +76,8 @@
 201435  Fix Darwin: -v does not show kernel version
 211256  Fixed an outdated comment regarding the default platform.
 211926  Avoid compilation warnings in valgrind.h with -pedantic
+212291  Fix unhandled syscall: unix:132 (mkfifo) on OS X
+        == 263119
 226609  Crediting upstream authors in man page
 231257  Valgrind omits path when executing script from shebang line
 254164  OS X task_info: UNKNOWN task message [id 3405, to mach_task_self(), 
diff --git a/coregrind/m_syswrap/priv_syswrap-darwin.h b/coregrind/m_syswrap/priv_syswrap-darwin.h
index e6cff5e..d2c7f0e 100644
--- a/coregrind/m_syswrap/priv_syswrap-darwin.h
+++ b/coregrind/m_syswrap/priv_syswrap-darwin.h
@@ -189,7 +189,7 @@
 // old truncate
 // old ftruncate
 // GEN flock 131
-// NYI mkfifo 132
+DECL_TEMPLATE(darwin, mkfifo);                  // 132
 DECL_TEMPLATE(darwin, sendto);                  // 133
 DECL_TEMPLATE(darwin, shutdown);                // 134
 DECL_TEMPLATE(darwin, socketpair);              // 135
diff --git a/coregrind/m_syswrap/syswrap-darwin.c b/coregrind/m_syswrap/syswrap-darwin.c
index 299e7be..1ce574e 100644
--- a/coregrind/m_syswrap/syswrap-darwin.c
+++ b/coregrind/m_syswrap/syswrap-darwin.c
@@ -3590,6 +3590,25 @@
    SET_STATUS_from_SysRes(r);
 }
 
+PRE(mkfifo)
+{
+   *flags |= SfMayBlock;
+   PRINT("mkfifo ( %#lx(%s), %ld )",ARG1,(char *)ARG1,(vki_mode_t)ARG2);
+   PRE_REG_READ2(long, "mkfifo", const char *, path, vki_mode_t, mode);
+   PRE_MEM_RASCIIZ( "mkfifo(path)", ARG1 );
+}
+
+POST(mkfifo)
+{
+   vg_assert(SUCCESS);
+   if (!ML_(fd_allowed)(RES, "mkfifo", tid, True)) {
+      VG_(close)(RES);
+      SET_STATUS_Failure( VKI_EMFILE );
+   } else {
+      if (VG_(clo_track_fds))
+         ML_(record_fd_open_with_given_name)(tid, RES, (Char*)ARG1);
+   }
+}
 
 PRE(sendto)
 {
@@ -9479,7 +9498,7 @@
    _____(VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(129)),   // old truncate
    _____(VG_DARWIN_SYSCALL_CONSTRUCT_UNIX(130)),   // old ftruncate
    GENX_(__NR_flock,       sys_flock), 
-// _____(__NR_mkfifo), 
+   MACX_(__NR_mkfifo,      mkfifo),
    MACX_(__NR_sendto,      sendto), 
    MACX_(__NR_shutdown,    shutdown), 
    MACXY(__NR_socketpair,  socketpair), 
diff --git a/memcheck/tests/darwin/scalar.c b/memcheck/tests/darwin/scalar.c
index 6834e28..1304a7d 100644
--- a/memcheck/tests/darwin/scalar.c
+++ b/memcheck/tests/darwin/scalar.c
@@ -259,7 +259,10 @@
    GO_UNIMP(130, "old ftruncate");
 
    // __NR_flock 131
-   // __NR_mkfifo 132
+
+   GO(__NR_mkfifo, 132, "2s 1m");
+   SY(__NR_mkfifo, x0, x0); FAIL;
+
    // __NR_sendto 133
    // __NR_shutdown 134
    // __NR_socketpair 135
diff --git a/memcheck/tests/darwin/scalar.stderr.exp b/memcheck/tests/darwin/scalar.stderr.exp
index 001cc73..f8b547c 100644
--- a/memcheck/tests/darwin/scalar.stderr.exp
+++ b/memcheck/tests/darwin/scalar.stderr.exp
@@ -386,6 +386,19 @@
 (130):           old ftruncate
 -----------------------------------------------------
 -----------------------------------------------------
+x2000084(132):         __NR_mkfifo 2s 1m
+-----------------------------------------------------
+Syscall param mkfifo(mode) contains uninitialised byte(s)
+   ...
+   by 0x........: main (in ./scalar)
+
+Syscall param mkfifo(path) points to unaddressable byte(s)
+   ...
+   by 0x........: main (in ./scalar)
+ Address 0x........ is not stack'd, malloc'd or (recently) free'd
+
+-----------------------------------------------------
+-----------------------------------------------------
 (141):           old getpeername
 -----------------------------------------------------
 -----------------------------------------------------