vppinfra: fix AddressSanitizer
[vpp.git] / src / svm / svm_common.h
index 1f6d83c..c0581f2 100644 (file)
@@ -20,6 +20,8 @@
 
 #include <stdarg.h>
 #include <pthread.h>
+#include <sys/user.h>
+#include <vppinfra/clib.h>
 #include <vppinfra/types.h>
 
 #define SVM_VERSION ((1<<16) | 1)      /* set to declare region ready. */
@@ -66,7 +68,7 @@ typedef struct svm_map_region_args_
 {
   const char *root_path;       /* NULL means use the truly global arena */
   const char *name;
-  u64 baseva;
+  uword baseva;
   u64 size;
   u64 pvt_heap_size;
   uword flags;
@@ -77,15 +79,29 @@ typedef struct svm_map_region_args_
   int gid;
 } svm_map_region_args_t;
 
+/*
+ * Memory mapped to high addresses for session/vppcom/vcl/etc...
+ */
+#if __WORDSIZE == 64
+#ifdef CLIB_SANITIZE_ADDR
+#define HIGH_SEGMENT_BASEVA 0x300000000000     /* DO NOT CHANGE THIS: YOU'LL BREAK ASAN */
+#else /* CLIB_SANITIZE_ADDR */
+#define HIGH_SEGMENT_BASEVA (128ULL << 30)     /* 128GB */
+#endif /* CLIB_SANITIZE_ADDR */
+#elif __WORDSIZE == 32
+#define HIGH_SEGMENT_BASEVA (3584UL << 20)     /* 3.5GB */
+#else
+#error "unknown __WORDSIZE"
+#endif
 
 /*
  * Memory shared across all router instances. Packet buffers, etc
  * Base should be "out of the way," and size should be big enough to
  * cover everything we plan to put here.
  */
-#define SVM_GLOBAL_REGION_BASEVA  0x30000000
 #define SVM_GLOBAL_REGION_SIZE    (64<<20)
 #define SVM_GLOBAL_REGION_NAME "/global_vm"
+u64 svm_get_global_region_base_va ();
 
 /*
  * Memory shared across individual router instances.
@@ -105,16 +121,22 @@ typedef struct
   svm_subregion_t *subregions; /* subregion pool */
   uword *name_hash;
   u8 *root_path;
+  int uid;
+  int gid;
 } svm_main_region_t;
 
 
 void *svm_region_find_or_create (svm_map_region_args_t * a);
 void svm_region_init (void);
+void svm_region_init_mapped_region (svm_map_region_args_t * a,
+                                   svm_region_t * rp);
 int svm_region_init_chroot (const char *root_path);
 void svm_region_init_chroot_uid_gid (const char *root_path, int uid, int gid);
 void svm_region_init_args (svm_map_region_args_t * a);
 void svm_region_exit (void);
+void svm_region_exit_client (void);
 void svm_region_unmap (void *rp_arg);
+void svm_region_unmap_client (void *rp_arg);
 void svm_client_scan (const char *root_path);
 void svm_client_scan_this_region_nolock (svm_region_t * rp);
 u8 *shm_name_from_svm_map_region_args (svm_map_region_args_t * a);