svm: Include stdint on FreeBSD
[vpp.git] / src / svm / svm_common.h
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2009 Cisco and/or its affiliates.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *------------------------------------------------------------------
16  */
17
18 #ifndef __included_svm_common_h__
19 #define __included_svm_common_h__
20
21 #include <stdarg.h>
22 #ifdef __FreeBSD__
23 #include <stdint.h>
24 #endif /* __FreeBSD__ */
25 #include <pthread.h>
26 #include <sys/user.h>
27 #include <vppinfra/clib.h>
28 #include <vppinfra/types.h>
29
30 #define SVM_VERSION ((1<<16) | 1)       /* set to declare region ready. */
31
32 #define SVM_FLAGS_MHEAP (1<<0)  /* region contains an mheap */
33 #define SVM_FLAGS_FILE  (1<<1)  /* region backed by one or more files */
34 #define SVM_FLAGS_NODATA (1<<2) /* region will be further subdivided */
35 #define SVM_FLAGS_NEED_DATA_INIT (1<<3)
36
37 #define SVM_PVT_MHEAP_SIZE (128<<10)    /* region's private mheap (128k) */
38
39 typedef struct svm_region_
40 {
41   volatile uword version;
42   pthread_mutex_t mutex;
43   pthread_cond_t condvar;
44   int mutex_owner_pid;          /* in case of trouble */
45   int mutex_owner_tag;
46   uword flags;
47   uword virtual_base;           /* base of the region object */
48   uword virtual_size;
49   void *region_heap;
50   void *data_base;              /* data portion base address */
51   void *data_heap;              /* data heap, if any */
52   volatile void *user_ctx;      /* user context pointer */
53   /* stuff allocated in the region's heap */
54   uword bitmap_size;            /* nbits in virtual alloc bitmap */
55   uword *bitmap;                /* the bitmap */
56   char *region_name;
57   char *backing_file;
58   char **filenames;
59   uword *client_pids;
60   /* pad */
61
62   /* next page:
63    * (64K) clib heap for the region itself
64    *
65    * data_base -> whatever is in this region
66    */
67
68 } svm_region_t;
69
70 typedef struct svm_map_region_args_
71 {
72   const char *root_path;        /* NULL means use the truly global arena */
73   const char *name;
74   uword baseva;
75   u64 size;
76   u64 pvt_heap_size;
77   uword flags;
78   char *backing_file;
79   uword backing_mmap_size;
80   /* uid, gid to own the svm region(s) */
81   int uid;
82   int gid;
83 } svm_map_region_args_t;
84
85 /*
86  * Memory mapped to high addresses for session/vppcom/vcl/etc...
87  */
88 #if __WORDSIZE == 64
89 #ifdef CLIB_SANITIZE_ADDR
90 #define HIGH_SEGMENT_BASEVA 0x300000000000      /* DO NOT CHANGE THIS: YOU'LL BREAK ASAN */
91 #else /* CLIB_SANITIZE_ADDR */
92 #define HIGH_SEGMENT_BASEVA (128ULL << 30)      /* 128GB */
93 #endif /* CLIB_SANITIZE_ADDR */
94 #elif __WORDSIZE == 32
95 #define HIGH_SEGMENT_BASEVA (3584UL << 20)      /* 3.5GB */
96 #else
97 #error "unknown __WORDSIZE"
98 #endif
99
100 /*
101  * Memory shared across all router instances. Packet buffers, etc
102  * Base should be "out of the way," and size should be big enough to
103  * cover everything we plan to put here.
104  */
105 #define SVM_GLOBAL_REGION_SIZE    (64<<20)
106 #define SVM_GLOBAL_REGION_NAME "/global_vm"
107 u64 svm_get_global_region_base_va ();
108
109 /*
110  * Memory shared across individual router instances.
111  */
112 #define SVM_OVERLAY_REGION_BASEVA \
113                (SVM_GLOBAL_REGION_BASEVA + SVM_GLOBAL_REGION_SIZE)
114 #define SVM_OVERLAY_REGION_SIZE   (1<<20)
115 #define SVM_OVERLAY_REGION_BASENAME "/overlay_vm"
116
117 typedef struct
118 {
119   u8 *subregion_name;
120 } svm_subregion_t;
121
122 typedef struct
123 {
124   svm_subregion_t *subregions;  /* subregion pool */
125   uword *name_hash;
126   u8 *root_path;
127   int uid;
128   int gid;
129 } svm_main_region_t;
130
131
132 void *svm_region_find_or_create (svm_map_region_args_t * a);
133 void svm_region_init (void);
134 void svm_region_init_mapped_region (svm_map_region_args_t * a,
135                                     svm_region_t * rp);
136 int svm_region_init_chroot (const char *root_path);
137 void svm_region_init_chroot_uid_gid (const char *root_path, int uid, int gid);
138 void svm_region_init_args (svm_map_region_args_t * a);
139 void svm_region_exit (void);
140 void svm_region_exit_client (void);
141 void svm_region_unmap (void *rp_arg);
142 void svm_region_unmap_client (void *rp_arg);
143 void svm_client_scan (const char *root_path);
144 void svm_client_scan_this_region_nolock (svm_region_t * rp);
145 u8 *shm_name_from_svm_map_region_args (svm_map_region_args_t * a);
146 u8 *format_svm_region (u8 * s, va_list * args);
147
148 svm_region_t *svm_get_root_rp (void);
149
150 #endif /* __included_svm_common_h__ */
151
152 /*
153  * fd.io coding-style-patch-verification: ON
154  *
155  * Local Variables:
156  * eval: (c-set-style "gnu")
157  * End:
158  */