OLD | NEW |
1 //===- Unix/Process.cpp - Unix Process Implementation --------- -*- C++ -*-===// | 1 //===- Unix/Process.cpp - Unix Process Implementation --------- -*- C++ -*-===// |
2 // | 2 // |
3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // This file provides the generic Unix implementation of the Process class. | 10 // This file provides the generic Unix implementation of the Process class. |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 | 258 |
259 if (NullFD == StandardFD) | 259 if (NullFD == StandardFD) |
260 FDC.keepOpen(); | 260 FDC.keepOpen(); |
261 else if (dup2(NullFD, StandardFD) < 0) | 261 else if (dup2(NullFD, StandardFD) < 0) |
262 return std::error_code(errno, std::generic_category()); | 262 return std::error_code(errno, std::generic_category()); |
263 } | 263 } |
264 return std::error_code(); | 264 return std::error_code(); |
265 } | 265 } |
266 | 266 |
267 std::error_code Process::SafelyCloseFileDescriptor(int FD) { | 267 std::error_code Process::SafelyCloseFileDescriptor(int FD) { |
| 268 // @LOCALMOD-BEGIN: For NaCl, don't use pthread_sigmask, etc. |
| 269 // They are stubs and fail with ENOSYS, which make this return |
| 270 // an error. |
| 271 #ifdef __native_client__ |
| 272 int ErrnoFromClose = 0; |
| 273 if (::close(FD) < 0) |
| 274 ErrnoFromClose = errno; |
| 275 return std::error_code(ErrnoFromClose, std::generic_category()); |
| 276 #else |
| 277 |
268 // Create a signal set filled with *all* signals. | 278 // Create a signal set filled with *all* signals. |
269 sigset_t FullSet; | 279 sigset_t FullSet; |
270 if (sigfillset(&FullSet) < 0) | 280 if (sigfillset(&FullSet) < 0) |
271 return std::error_code(errno, std::generic_category()); | 281 return std::error_code(errno, std::generic_category()); |
272 // Atomically swap our current signal mask with a full mask. | 282 // Atomically swap our current signal mask with a full mask. |
273 sigset_t SavedSet; | 283 sigset_t SavedSet; |
274 #if LLVM_ENABLE_THREADS | 284 #if LLVM_ENABLE_THREADS |
275 if (int EC = pthread_sigmask(SIG_SETMASK, &FullSet, &SavedSet)) | 285 if (int EC = pthread_sigmask(SIG_SETMASK, &FullSet, &SavedSet)) |
276 return std::error_code(EC, std::generic_category()); | 286 return std::error_code(EC, std::generic_category()); |
277 #else | 287 #else |
(...skipping 12 matching lines...) Expand all Loading... |
290 EC = pthread_sigmask(SIG_SETMASK, &SavedSet, nullptr); | 300 EC = pthread_sigmask(SIG_SETMASK, &SavedSet, nullptr); |
291 #else | 301 #else |
292 if (sigprocmask(SIG_SETMASK, &SavedSet, nullptr) < 0) | 302 if (sigprocmask(SIG_SETMASK, &SavedSet, nullptr) < 0) |
293 EC = errno; | 303 EC = errno; |
294 #endif | 304 #endif |
295 // The error code from close takes precedence over the one from | 305 // The error code from close takes precedence over the one from |
296 // pthread_sigmask. | 306 // pthread_sigmask. |
297 if (ErrnoFromClose) | 307 if (ErrnoFromClose) |
298 return std::error_code(ErrnoFromClose, std::generic_category()); | 308 return std::error_code(ErrnoFromClose, std::generic_category()); |
299 return std::error_code(EC, std::generic_category()); | 309 return std::error_code(EC, std::generic_category()); |
| 310 #endif // @LOCALMOD-END |
300 } | 311 } |
301 | 312 |
302 bool Process::StandardInIsUserInput() { | 313 bool Process::StandardInIsUserInput() { |
303 return FileDescriptorIsDisplayed(STDIN_FILENO); | 314 return FileDescriptorIsDisplayed(STDIN_FILENO); |
304 } | 315 } |
305 | 316 |
306 bool Process::StandardOutIsDisplayed() { | 317 bool Process::StandardOutIsDisplayed() { |
307 return FileDescriptorIsDisplayed(STDOUT_FILENO); | 318 return FileDescriptorIsDisplayed(STDOUT_FILENO); |
308 } | 319 } |
309 | 320 |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 | 480 |
470 unsigned llvm::sys::Process::GetRandomNumber() { | 481 unsigned llvm::sys::Process::GetRandomNumber() { |
471 #if defined(HAVE_DECL_ARC4RANDOM) && HAVE_DECL_ARC4RANDOM | 482 #if defined(HAVE_DECL_ARC4RANDOM) && HAVE_DECL_ARC4RANDOM |
472 return arc4random(); | 483 return arc4random(); |
473 #else | 484 #else |
474 static int x = (::srand(GetRandomNumberSeed()), 0); | 485 static int x = (::srand(GetRandomNumberSeed()), 0); |
475 (void)x; | 486 (void)x; |
476 return ::rand(); | 487 return ::rand(); |
477 #endif | 488 #endif |
478 } | 489 } |
OLD | NEW |