Debian Codegraph @

runtime/dyninst/transport.h

raw
1 // stapdyn transport functions
2 // Copyright (C) 2013 Red Hat Inc.
3 //
4 // This file is part of systemtap, and is free software. You can
5 // redistribute it and/or modify it under the terms of the GNU General
6 // Public License (GPL); either version 2, or (at your option) any
7 // later version.
8
9 #ifndef TRANSPORT_H
10 #define TRANSPORT_H
11
12 #define STP_DYN_EXIT 0x0001
13 #define STP_DYN_NORMAL_DATA 0x0002
14 #define STP_DYN_OOB_DATA 0x0004
15 #define STP_DYN_SYSTEM 0x0008
16 #define STP_DYN_REQUEST_EXIT 0x0010
17
18 #define STP_DYN_OOB_DATA_MASK (STP_DYN_OOB_DATA | STP_DYN_SYSTEM)
19
20 // The size of print buffers. This limits the maximum amount of data a
21 // print can send. Note that it must be a power of 2 (which is why
22 // we're using a bit shift). For reference sake, here are the
23 // resulting sizes with various shifts: 13 (8kB), 14 (16kB), 15 (32kB),
24 // 16 (64kB), 17 (128kB), 18 (256kB), 19 (512kB), and 20 (1MB).
25 #ifndef STP_BUFFER_SIZE_SHIFT
26 #define STP_BUFFER_SIZE_SHIFT 20
27 #endif
28 #define _STP_DYNINST_BUFFER_SIZE (1 << STP_BUFFER_SIZE_SHIFT)
29
30 // The size of an individual log message.
31 #ifndef STP_LOG_BUF_LEN
32 #define STP_LOG_BUF_LEN 256
33 #endif
34 #if (STP_LOG_BUF_LEN < 10) /* sizeof(WARN_STRING) */
35 #error "STP_LOG_BUF_LEN is too short"
36 #endif
37
38 // The maximum number of log messages the buffer can hold. Note that
39 // it must be a power of 2 (which is why we're using a bit shift).
40 #ifndef STP_LOG_BUF_ENTRIES_SHIFT
41 #define STP_LOG_BUF_ENTRIES_SHIFT 4
42 #endif
43 #define _STP_LOG_BUF_ENTRIES (1 << STP_LOG_BUF_ENTRIES_SHIFT)
44
45 // The total size of the log buffer
46 #define _STP_DYNINST_LOG_BUF_LEN (STP_LOG_BUF_LEN * _STP_LOG_BUF_ENTRIES)
47
48 // The maximum number of queue items each transport queue can
49 // hold.
50 #ifndef STP_DYNINST_QUEUE_ITEMS
51 #define STP_DYNINST_QUEUE_ITEMS 64
52 #endif
53
54 struct _stp_transport_queue_item {
55 // The type variable lets the thread know what it needs to do.
56 unsigned type;
57
58 // 'data_index' indicates which context structure we're
59 // working on. */
60 int data_index;
61
62 // When 'type' indicates that normal or oob data needs to be
63 // output, this is the data offset.
64 size_t offset;
65
66 // When 'type' indicates that normal or oob data needs to be
67 // output, this is the number of bytes to output.
68 size_t bytes;
69 };
70
71 struct _stp_transport_queue {
72 size_t items;
73 struct _stp_transport_queue_item queue[STP_DYNINST_QUEUE_ITEMS];
74 };
75
76 // This structure is stored in the session data.
77 struct _stp_transport_session_data {
78 unsigned write_queue;
79 struct _stp_transport_queue queues[2];
80 pthread_mutex_t queue_mutex;
81 pthread_cond_t queue_space_avail;
82 pthread_cond_t queue_data_avail;
83 };
84
85 // This structure is stored in every context structure.
86 struct _stp_transport_context_data {
87 /* The buffer and variables used for print messages */
88 size_t read_offset;
89 size_t write_offset;
90 size_t write_bytes;
91 char print_buf[_STP_DYNINST_BUFFER_SIZE];
92 /* The condition variable is used to signal our thread. */
93 pthread_cond_t print_space_avail;
94 /* The lock for this print state. */
95 pthread_mutex_t print_mutex;
96
97 /*
98 * The buffer and variables used for log (warn/error)
99 * messages. Note that 'log_buf' is a true circular buffer
100 * (unlike print_buf). Also note that 'log_start' and
101 * 'log_end' are entry numbers (not offsets).
102 */
103 size_t log_start; /* index of oldest entry */
104 size_t log_end; /* where to write new entry */
105 char log_buf[_STP_DYNINST_LOG_BUF_LEN];
106 /* The condition variable is used to signal space available. */
107 pthread_cond_t log_space_avail;
108 /* The lock for 'log_space_avail'. */
109 pthread_mutex_t log_mutex;
110 };
111
112 static int _stp_dyninst_transport_session_init(void);
113
114 static int _stp_dyninst_transport_session_start(void);
115
116 static int _stp_dyninst_transport_write_oob_data(char *buffer, size_t bytes);
117
118 static int _stp_dyninst_transport_write(void);
119
120 static char *_stp_dyninst_transport_log_buffer(void);
121
122 static void _stp_dyninst_transport_shutdown(void);
123
124 static void _stp_dyninst_transport_request_exit(void);
125
126 #endif // TRANSPORT_H