27
27
#define TLS_MSG_BUF_LEN 1024
28
28
29
29
typedef struct fixed_memory_provider_t {
30
- void * base ; // base address of memory
31
- size_t size ; // size of the memory region
32
- coarse_t * coarse ; // coarse library handle
30
+ void * base ; // base address of memory
31
+ size_t size ; // size of the memory region
32
+ unsigned int flags ; // flags of the memory region
33
+ coarse_t * coarse ; // coarse library handle
34
+
35
+ // used only when the UMF_FIXED_FLAG_CREATE_FROM_POOL_PTR flag is set
36
+ size_t ptr_orig_size ; // original size of the memory region in the tracker
33
37
} fixed_memory_provider_t ;
34
38
35
39
// Fixed Memory provider settings struct
36
40
typedef struct umf_fixed_memory_provider_params_t {
37
41
void * ptr ;
38
42
size_t size ;
43
+ unsigned int flags ;
39
44
} umf_fixed_memory_provider_params_t ;
40
45
41
46
typedef struct fixed_last_native_error_t {
@@ -83,6 +88,7 @@ static umf_result_t fixed_allocation_merge_cb(void *provider, void *lowPtr,
83
88
84
89
static umf_result_t fixed_initialize (void * params , void * * provider ) {
85
90
umf_result_t ret ;
91
+ size_t ptr_orig_size = 0 ;
86
92
87
93
if (params == NULL ) {
88
94
return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
@@ -91,6 +97,15 @@ static umf_result_t fixed_initialize(void *params, void **provider) {
91
97
umf_fixed_memory_provider_params_t * in_params =
92
98
(umf_fixed_memory_provider_params_t * )params ;
93
99
100
+ if (in_params -> flags & UMF_FIXED_FLAG_CREATE_FROM_POOL_PTR ) {
101
+ umf_memory_pool_handle_t pool = umfPoolByPtr (in_params -> ptr );
102
+ if (pool == NULL ) {
103
+ LOG_ERR ("The UMF_FIXED_FLAG_CREATE_FROM_POOL_PTR flag is set, but "
104
+ "the given pointer does not belong to any UMF pool" );
105
+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
106
+ }
107
+ }
108
+
94
109
fixed_memory_provider_t * fixed_provider =
95
110
umf_ba_global_alloc (sizeof (* fixed_provider ));
96
111
if (!fixed_provider ) {
@@ -122,6 +137,8 @@ static umf_result_t fixed_initialize(void *params, void **provider) {
122
137
123
138
fixed_provider -> base = in_params -> ptr ;
124
139
fixed_provider -> size = in_params -> size ;
140
+ fixed_provider -> flags = in_params -> flags ;
141
+ fixed_provider -> ptr_orig_size = ptr_orig_size ;
125
142
126
143
// add the entire memory as a single block
127
144
ret = coarse_add_memory_fixed (coarse , fixed_provider -> base ,
@@ -333,5 +350,26 @@ umf_result_t umfFixedMemoryProviderParamsSetMemory(
333
350
334
351
hParams -> ptr = ptr ;
335
352
hParams -> size = size ;
353
+ hParams -> flags = 0 ;
354
+
355
+ return UMF_RESULT_SUCCESS ;
356
+ }
357
+
358
+ umf_result_t umfFixedMemoryProviderParamsSetFlags (
359
+ umf_fixed_memory_provider_params_handle_t hParams , unsigned int flags ) {
360
+ if (hParams == NULL ) {
361
+ LOG_ERR ("Memory Provider params handle is NULL" );
362
+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
363
+ }
364
+
365
+ if ((flags & UMF_FIXED_FLAG_CREATE_FROM_POOL_PTR ) &&
366
+ (umfPoolByPtr (hParams -> ptr ) == NULL )) {
367
+ LOG_ERR ("Cannot set the UMF_FIXED_FLAG_CREATE_FROM_POOL_PTR, because "
368
+ "the given pointer does not belong to any UMF pool" );
369
+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
370
+ }
371
+
372
+ hParams -> flags = flags ;
373
+
336
374
return UMF_RESULT_SUCCESS ;
337
375
}
0 commit comments