| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright 2008 The Native Client Authors. All rights reserved. | |
| 3 * Use of this source code is governed by a BSD-style license that can | |
| 4 * be found in the LICENSE file. | |
| 5 */ | |
| 6 | |
| 7 // A collection of debugging related interfaces. | |
| 8 | |
| 9 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_SRPC_UTILITY_H_ | |
| 10 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_SRPC_UTILITY_H_ | |
| 11 | |
| 12 #include <setjmp.h> | |
| 13 #include <signal.h> | |
| 14 #include "native_client/src/include/nacl_macros.h" | |
| 15 #include "native_client/src/include/portability.h" | |
| 16 #include "native_client/src/shared/platform/nacl_threads.h" | |
| 17 | |
| 18 #define SRPC_PLUGIN_DEBUG 1 | |
| 19 | |
| 20 namespace plugin { | |
| 21 | |
| 22 // CatchSignals encapsulates the setup and removal of application-defined | |
| 23 // signal handlers. | |
| 24 // TODO(sehr): need to revisit thread-specific, etc., signal handling | |
| 25 | |
| 26 class ScopedCatchSignals { | |
| 27 public: | |
| 28 typedef void (*SigHandlerType)(int signal_number); | |
| 29 // Installs handler as the signal handler for SIGPIPE. | |
| 30 explicit ScopedCatchSignals(SigHandlerType handler) { | |
| 31 #ifndef _MSC_VER | |
| 32 prev_pipe_handler_ = signal(SIGPIPE, handler); | |
| 33 #endif | |
| 34 } | |
| 35 // Restores the previous signal handler | |
| 36 ~ScopedCatchSignals() { | |
| 37 #ifndef _MSC_VER | |
| 38 signal(SIGPIPE, prev_pipe_handler_); | |
| 39 #endif | |
| 40 } | |
| 41 | |
| 42 private: | |
| 43 NACL_DISALLOW_COPY_AND_ASSIGN(ScopedCatchSignals); | |
| 44 #ifndef _MSC_VER | |
| 45 SigHandlerType prev_pipe_handler_; | |
| 46 #endif | |
| 47 }; | |
| 48 | |
| 49 // Tests that a string is a valid JavaScript identifier. According to the | |
| 50 // ECMAScript spec, this should be done in terms of unicode character | |
| 51 // categories. For now, we are simply limiting identifiers to the ASCII | |
| 52 // subset of that spec. If successful, it returns the length of the | |
| 53 // identifier in the location pointed to by length (if it is not NULL). | |
| 54 // TODO(sehr): add Unicode identifier support. | |
| 55 bool IsValidIdentifierString(const char* strval, uint32_t* length); | |
| 56 | |
| 57 // Platform abstraction for setjmp and longjmp | |
| 58 // TODO(sehr): move to portability.h | |
| 59 #ifdef _MSC_VER | |
| 60 #define PLUGIN_SETJMP(buf, mask) setjmp(buf) | |
| 61 #define PLUGIN_LONGJMP(buf, value) longjmp(buf, value) | |
| 62 #define PLUGIN_JMPBUF jmp_buf | |
| 63 #else | |
| 64 #define PLUGIN_SETJMP(buf, mask) sigsetjmp(buf, mask) | |
| 65 #define PLUGIN_LONGJMP(buf, value) siglongjmp(buf, value) | |
| 66 #define PLUGIN_JMPBUF sigjmp_buf | |
| 67 #endif // _MSC_VER | |
| 68 | |
| 69 // Debugging print utility | |
| 70 extern int gNaClPluginDebugPrintEnabled; | |
| 71 extern int NaClPluginDebugPrintCheckEnv(); | |
| 72 #if SRPC_PLUGIN_DEBUG | |
| 73 # define PLUGIN_PRINTF(args) do { \ | |
| 74 if (-1 == ::plugin::gNaClPluginDebugPrintEnabled) { \ | |
| 75 ::plugin::gNaClPluginDebugPrintEnabled = \ | |
| 76 ::plugin::NaClPluginDebugPrintCheckEnv(); \ | |
| 77 } \ | |
| 78 if (0 != ::plugin::gNaClPluginDebugPrintEnabled) { \ | |
| 79 printf("%08"NACL_PRIx32": ", NaClThreadId()); \ | |
| 80 printf args; \ | |
| 81 fflush(stdout); \ | |
| 82 } \ | |
| 83 } while (0) | |
| 84 #else | |
| 85 # define PLUGIN_PRINTF(args) do { if (0) { printf args; } } while (0) | |
| 86 /* allows DCE but compiler can still do format string checks */ | |
| 87 #endif | |
| 88 | |
| 89 } // namespace plugin | |
| 90 | |
| 91 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_SRPC_UTILITY_H_ | |
| OLD | NEW |