• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright Joyent, Inc. and other Node contributors.
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a
4 // copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to permit
8 // persons to whom the Software is furnished to do so, subject to the
9 // following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included
12 // in all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 // USE OR OTHER DEALINGS IN THE SOFTWARE.
21 
22 #ifndef SRC_NODE_DTRACE_H_
23 #define SRC_NODE_DTRACE_H_
24 
25 #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
26 
27 #include "v8.h"
28 
29 extern "C" {
30 /*
31  * The following structures are passed directly to DTrace when probes are fired.
32  * Translators in node.d translate these structures into the corresponding D
33  * structures, taking care of dealing with the user process data model (32-bit
34  * or 64-bit) and structure versions (see node_dtrace_http_server_request_t
35  * below).
36  */
37 
38 typedef struct {
39   int32_t fd;
40   int32_t port;
41   char* remote;
42   int32_t buffered;
43 } node_dtrace_connection_t;
44 
45 typedef struct {
46   char* url;
47   char* method;
48 } node_dtrace_http_client_request_t;
49 
50 /*
51  * The original version of this structure contained only a url and method, just
52  * like the client request above.  To add the new forwardedFor field, the
53  * structure layout was changed to begin with an integer version.  The
54  * translator knows whether it's looking at an old- or new-version structure
55  * based on whether the version field's value is a reasonable pointer (i.e.
56  * address greater than 4K).  No doubt this is filthy, but there's not much else
57  * we can do, and it works reliably.
58  *
59  * This version of the structure also contains padding that should be zeroed out
60  * by the consumer so that future versions of the translator can simply check if
61  * a field is present by checking it against nullptr.
62  */
63 typedef struct {
64   union {
65     uint32_t version;
66     uintptr_t unused;  /* for compat. with old 64-bit struct */
67   } _un;
68   char* url;
69   char* method;
70   char* forwardedFor;
71   char* _pad[8];
72 } node_dtrace_http_server_request_t;
73 
74 }  // extern "C"
75 
76 namespace node {
77 
78 class Environment;
79 
80 void InitDTrace(Environment* env);
81 
82 }  // namespace node
83 
84 #endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
85 
86 #endif  // SRC_NODE_DTRACE_H_
87