2 *------------------------------------------------------------------
3 * svm.h - shared VM allocation, mmap(...MAP_FIXED...)
6 * Copyright (c) 2009 Cisco and/or its affiliates.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at:
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *------------------------------------------------------------------
21 #ifndef __included_svm_h__
22 #define __included_svm_h__
25 #include <vppinfra/clib.h>
26 #include <vppinfra/mem.h>
27 #include <svm/svm_common.h>
29 #define MMAP_PAGESIZE (clib_mem_get_page_size())
32 svm_mem_alloc (svm_region_t * rp, uword size)
35 ASSERT (rp->flags & SVM_FLAGS_MHEAP);
38 pthread_mutex_lock (&rp->mutex);
39 oldheap = clib_mem_set_heap (rp->data_heap);
40 rv = clib_mem_alloc (size);
41 clib_mem_set_heap (oldheap);
42 pthread_mutex_unlock (&rp->mutex);
47 svm_mem_alloc_aligned_at_offset (svm_region_t * rp,
48 uword size, uword align, uword offset)
51 ASSERT (rp->flags & SVM_FLAGS_MHEAP);
54 pthread_mutex_lock (&rp->mutex);
55 oldheap = clib_mem_set_heap (rp->data_heap);
56 rv = clib_mem_alloc_aligned_at_offset (size, align, offset,
57 1 /* yes, call os_out_of_memory */ );
58 clib_mem_set_heap (oldheap);
59 pthread_mutex_unlock (&rp->mutex);
64 svm_mem_free (svm_region_t * rp, void *ptr)
67 ASSERT (rp->flags & SVM_FLAGS_MHEAP);
69 pthread_mutex_lock (&rp->mutex);
70 oldheap = clib_mem_set_heap (rp->data_heap);
72 clib_mem_set_heap (oldheap);
73 pthread_mutex_unlock (&rp->mutex);
78 svm_push_pvt_heap (svm_region_t * rp)
81 oldheap = clib_mem_set_heap (rp->region_heap);
82 return ((void *) oldheap);
86 svm_push_data_heap (svm_region_t * rp)
89 oldheap = clib_mem_set_heap (rp->data_heap);
90 return ((void *) oldheap);
94 svm_pop_heap (void *oldheap)
96 clib_mem_set_heap (oldheap);
99 #endif /* __included_svm_h__ */
102 * fd.io coding-style-patch-verification: ON
105 * eval: (c-set-style "gnu")