2727#define TLS_MSG_BUF_LEN 1024
2828
2929typedef 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
3337} fixed_memory_provider_t ;
3438
3539// Fixed Memory provider settings struct
3640typedef struct umf_fixed_memory_provider_params_t {
3741 void * ptr ;
3842 size_t size ;
43+ unsigned int flags ;
3944} umf_fixed_memory_provider_params_t ;
4045
4146typedef struct fixed_last_native_error_t {
@@ -83,6 +88,7 @@ static umf_result_t fixed_allocation_merge_cb(void *provider, void *lowPtr,
8388
8489static umf_result_t fixed_initialize (void * params , void * * provider ) {
8590 umf_result_t ret ;
91+ size_t ptr_orig_size = 0 ;
8692
8793 if (params == NULL ) {
8894 return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
@@ -91,6 +97,15 @@ static umf_result_t fixed_initialize(void *params, void **provider) {
9197 umf_fixed_memory_provider_params_t * in_params =
9298 (umf_fixed_memory_provider_params_t * )params ;
9399
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+
94109 fixed_memory_provider_t * fixed_provider =
95110 umf_ba_global_alloc (sizeof (* fixed_provider ));
96111 if (!fixed_provider ) {
@@ -122,6 +137,8 @@ static umf_result_t fixed_initialize(void *params, void **provider) {
122137
123138 fixed_provider -> base = in_params -> ptr ;
124139 fixed_provider -> size = in_params -> size ;
140+ fixed_provider -> flags = in_params -> flags ;
141+ fixed_provider -> ptr_orig_size = ptr_orig_size ;
125142
126143 // add the entire memory as a single block
127144 ret = coarse_add_memory_fixed (coarse , fixed_provider -> base ,
@@ -333,5 +350,26 @@ umf_result_t umfFixedMemoryProviderParamsSetMemory(
333350
334351 hParams -> ptr = ptr ;
335352 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+
336374 return UMF_RESULT_SUCCESS ;
337375}
0 commit comments