aboutsummaryrefslogtreecommitdiffstats
path: root/vlib/vlib/node.h
diff options
context:
space:
mode:
authorAndrew Yourtchenko <ayourtch@gmail.com>2016-05-10 10:51:34 +0000
committerDave Barach <openvpp@barachs.net>2016-05-10 17:13:00 +0000
commit716d9593497388c48593f818748faf705ac7169e (patch)
tree50dd1adea16bcff1ab80494532c5603bcf44de5e /vlib/vlib/node.h
parent46d4e36792e829ef96b43dbc6eec344700d54f13 (diff)
Avoid clobbering output_function by concurrent CLI sessions doing vlib_process_wait_for_event*.
A problem is easily reproducible by taking the test harness code from the commit, and launching it in two terminals with some time overlap - the outputs will be sent to the wrong session. This commit moves the output_function and argument from a global structure into the process structure, thus the output_function is not clobbered anymore and each session gets only its own output. To ensure the callers can redirect the outputs to different destinations (e.g. the API calls via shared memory, etc.) the existing logic for vlib_cli_input() was retained. To avoid the magic numbers usage in the logic that does the page-alignment of the process stack, there are changes around the stack[] member of vlib_process_t. Also added a compile-time assert to ensure that the stack does indeed start on the page size multiple boundary. Change-Id: I128680ac480735e5f214f81a884e414268e5d652 Signed-off-by: Andrew Yourtchenko <ayourtch@gmail.com>
Diffstat (limited to 'vlib/vlib/node.h')
-rw-r--r--vlib/vlib/node.h19
1 files changed, 17 insertions, 2 deletions
diff --git a/vlib/vlib/node.h b/vlib/vlib/node.h
index 348ad1f3b8c..2caede6e411 100644
--- a/vlib/vlib/node.h
+++ b/vlib/vlib/node.h
@@ -496,17 +496,32 @@ typedef struct {
/* When suspending saves cpu cycle counter when process is to be resumed. */
u64 resume_cpu_time;
+ /* Default output function and its argument for any CLI outputs
+ within the process. */
+ vlib_cli_output_function_t *output_function;
+ uword output_function_arg;
+
#ifdef CLIB_UNIX
/* Pad to a multiple of the page size so we can mprotect process stacks */
- CLIB_PAD_FROM_TO (0x140, 0x1000);
+#define PAGE_SIZE_MULTIPLE 0x1000
+#define ALIGN_ON_MULTIPLE_PAGE_BOUNDARY_FOR_MPROTECT __attribute__ ((aligned (PAGE_SIZE_MULTIPLE)))
+#else
+#define ALIGN_ON_MULTIPLE_PAGE_BOUNDARY_FOR_MPROTECT
#endif
+
/* Process stack. Starts here and extends 2^log2_n_stack_bytes
bytes. */
#define VLIB_PROCESS_STACK_MAGIC (0xdead7ead)
- u32 stack[0];
+ u32 stack[0] ALIGN_ON_MULTIPLE_PAGE_BOUNDARY_FOR_MPROTECT;
} vlib_process_t __attribute__ ((aligned (CLIB_CACHE_LINE_BYTES)));
+#ifdef CLIB_UNIX
+ /* Ensure that the stack is aligned on the multiple of the page size */
+typedef char assert_process_stack_must_be_aligned_exactly_to_page_size_multiple
+ [(sizeof(vlib_process_t) - PAGE_SIZE_MULTIPLE) == 0 ? 0 : -1];
+#endif
+
typedef struct {
u32 node_index;