]> granicus.if.org Git - llvm/commitdiff
[libFuzzer] Properly use Handle instead of FD on Windows.
authorMarcos Pividori <mpividori@google.com>
Wed, 8 Feb 2017 00:03:18 +0000 (00:03 +0000)
committerMarcos Pividori <mpividori@google.com>
Wed, 8 Feb 2017 00:03:18 +0000 (00:03 +0000)
For Windows, sanitizers work with Handles, not with posix file descriptors,
because they use the windows-specific API. So we need to convert the fds to
handles before passing them to the sanitizer library.
After this change, close_fd_mask is fixed for Windows (this fix some tests too).

Differential Revision: https://reviews.llvm.org/D29548

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294388 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Fuzzer/FuzzerIO.cpp
lib/Fuzzer/FuzzerIO.h
lib/Fuzzer/FuzzerIOPosix.cpp
lib/Fuzzer/FuzzerIOWindows.cpp

index 45445fa3ba41af2602ea165d8178abd5b59fea91..e3f609ed8a80063f1aa062c900625f664016ce51 100644 (file)
@@ -96,7 +96,8 @@ void DupAndCloseStderr() {
     if (NewOutputFile) {
       OutputFile = NewOutputFile;
       if (EF->__sanitizer_set_report_fd)
-        EF->__sanitizer_set_report_fd(reinterpret_cast<void *>(OutputFd));
+        EF->__sanitizer_set_report_fd(
+            reinterpret_cast<void *>(GetHandleFromFd(OutputFd)));
       DiscardOutput(2);
     }
   }
index 28c6ba095864f2e155f812343d6472716b161c49..3b66a52d1a6492793ddad07faa057796919711bb 100644 (file)
@@ -69,6 +69,8 @@ void RemoveFile(const std::string &Path);
 
 void DiscardOutput(int Fd);
 
+intptr_t GetHandleFromFd(int fd);
+
 }  // namespace fuzzer
 
 #endif  // LLVM_FUZZER_IO_H
index 40209a034e37dd77e38ba200129e25401330507d..c5ebdbac467bfb771cba34f811a4ca3c8cf09db9 100644 (file)
@@ -83,6 +83,10 @@ void DiscardOutput(int Fd) {
   fclose(Temp);
 }
 
+intptr_t GetHandleFromFd(int fd) {
+  return static_cast<intptr_t>(fd);
+}
+
 std::string DirName(const std::string &FileName) {
   char *Tmp = new char[FileName.size() + 1];
   memcpy(Tmp, FileName.c_str(), FileName.size() + 1);
index 536e130672557b6ad2b0c77a215bffc2c8156a17..75d4e3a06071ecf32427896a75f6de1207277f7d 100644 (file)
@@ -149,6 +149,10 @@ void DiscardOutput(int Fd) {
   fclose(Temp);
 }
 
+intptr_t GetHandleFromFd(int fd) {
+  return _get_osfhandle(fd);
+}
+
 static bool IsSeparator(char C) {
   return C == '\\' || C == '/';
 }