2 * Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
7 // A collection of debugging related interfaces.
9 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_UTILITY_H_
10 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_UTILITY_H_
12 #include "native_client/src/include/nacl_macros.h"
13 #include "native_client/src/include/portability.h"
14 #include "native_client/src/shared/platform/nacl_threads.h"
15 #include "native_client/src/shared/platform/nacl_time.h"
16 #include "ppapi/c/private/pp_file_handle.h"
17 #include "ppapi/c/private/ppb_nacl_private.h"
19 #define SRPC_PLUGIN_DEBUG 1
23 // Tests that a string is a valid JavaScript identifier. According to the
24 // ECMAScript spec, this should be done in terms of unicode character
25 // categories. For now, we are simply limiting identifiers to the ASCII
26 // subset of that spec. If successful, it returns the length of the
27 // identifier in the location pointed to by length (if it is not NULL).
28 // TODO(sehr): add Unicode identifier support.
29 bool IsValidIdentifierString(const char* strval
, uint32_t* length
);
31 const PPB_NaCl_Private
* GetNaClInterface();
32 void SetNaClInterface(const PPB_NaCl_Private
* nacl_interface
);
34 void CloseFileHandle(PP_FileHandle file_handle
);
36 // Converts a PP_FileHandle to a POSIX file descriptor.
37 int32_t ConvertFileDescriptor(PP_FileHandle handle
, bool read_only
);
39 // Debugging print utility
40 extern int gNaClPluginDebugPrintEnabled
;
41 extern int NaClPluginPrintLog(const char *format
, ...);
42 extern int NaClPluginDebugPrintCheckEnv();
44 #define INIT_PLUGIN_LOGGING() do { \
45 if (-1 == ::plugin::gNaClPluginDebugPrintEnabled) { \
46 ::plugin::gNaClPluginDebugPrintEnabled = \
47 ::plugin::NaClPluginDebugPrintCheckEnv(); \
51 #define PLUGIN_PRINTF(args) do { \
52 INIT_PLUGIN_LOGGING(); \
53 if (0 != ::plugin::gNaClPluginDebugPrintEnabled) { \
54 ::plugin::NaClPluginPrintLog("PLUGIN %" NACL_PRIu64 ": ", \
55 NaClGetTimeOfDayMicroseconds()); \
56 ::plugin::NaClPluginPrintLog args; \
60 // MODULE_PRINTF is used in the module because PLUGIN_PRINTF uses a
61 // a timer that may not yet be initialized.
62 #define MODULE_PRINTF(args) do { \
63 INIT_PLUGIN_LOGGING(); \
64 if (0 != ::plugin::gNaClPluginDebugPrintEnabled) { \
65 ::plugin::NaClPluginPrintLog("MODULE: "); \
66 ::plugin::NaClPluginPrintLog args; \
70 # define PLUGIN_PRINTF(args) do { if (0) { printf args; } } while (0)
71 # define MODULE_PRINTF(args) do { if (0) { printf args; } } while (0)
72 /* allows DCE but compiler can still do format string checks */
77 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_UTILITY_H_