@@ -27,8 +27,8 @@ static int CTL_SUBTREE_HANDLER(by_handle_provider)(
27
27
umf_ctl_query_type_t queryType ) {
28
28
(void )indexes , (void )source ;
29
29
umf_memory_provider_handle_t hProvider = (umf_memory_provider_handle_t )ctx ;
30
- hProvider -> ops .ctl (hProvider -> provider_priv , /*unused*/ 0 , extra_name , arg ,
31
- queryType );
30
+ hProvider -> ops .ext_ctl (hProvider -> provider_priv , /*unused*/ 0 , extra_name ,
31
+ arg , queryType );
32
32
return 0 ;
33
33
}
34
34
@@ -120,67 +120,78 @@ static umf_result_t umfDefaultCtlHandle(void *provider, int operationType,
120
120
}
121
121
122
122
void assignOpsExtDefaults (umf_memory_provider_ops_t * ops ) {
123
- if (!ops -> ext . purge_lazy ) {
124
- ops -> ext . purge_lazy = umfDefaultPurgeLazy ;
123
+ if (!ops -> ext_purge_lazy ) {
124
+ ops -> ext_purge_lazy = umfDefaultPurgeLazy ;
125
125
}
126
- if (!ops -> ext . purge_force ) {
127
- ops -> ext . purge_force = umfDefaultPurgeForce ;
126
+ if (!ops -> ext_purge_force ) {
127
+ ops -> ext_purge_force = umfDefaultPurgeForce ;
128
128
}
129
- if (!ops -> ext . allocation_split ) {
130
- ops -> ext . allocation_split = umfDefaultAllocationSplit ;
129
+ if (!ops -> ext_allocation_split ) {
130
+ ops -> ext_allocation_split = umfDefaultAllocationSplit ;
131
131
}
132
- if (!ops -> ext . allocation_merge ) {
133
- ops -> ext . allocation_merge = umfDefaultAllocationMerge ;
132
+ if (!ops -> ext_allocation_merge ) {
133
+ ops -> ext_allocation_merge = umfDefaultAllocationMerge ;
134
134
}
135
135
}
136
136
137
137
void assignOpsIpcDefaults (umf_memory_provider_ops_t * ops ) {
138
- if (!ops -> ipc . get_ipc_handle_size ) {
139
- ops -> ipc . get_ipc_handle_size = umfDefaultGetIPCHandleSize ;
138
+ if (!ops -> ext_get_ipc_handle_size ) {
139
+ ops -> ext_get_ipc_handle_size = umfDefaultGetIPCHandleSize ;
140
140
}
141
- if (!ops -> ipc . get_ipc_handle ) {
142
- ops -> ipc . get_ipc_handle = umfDefaultGetIPCHandle ;
141
+ if (!ops -> ext_get_ipc_handle ) {
142
+ ops -> ext_get_ipc_handle = umfDefaultGetIPCHandle ;
143
143
}
144
- if (!ops -> ipc . put_ipc_handle ) {
145
- ops -> ipc . put_ipc_handle = umfDefaultPutIPCHandle ;
144
+ if (!ops -> ext_put_ipc_handle ) {
145
+ ops -> ext_put_ipc_handle = umfDefaultPutIPCHandle ;
146
146
}
147
- if (!ops -> ipc . open_ipc_handle ) {
148
- ops -> ipc . open_ipc_handle = umfDefaultOpenIPCHandle ;
147
+ if (!ops -> ext_open_ipc_handle ) {
148
+ ops -> ext_open_ipc_handle = umfDefaultOpenIPCHandle ;
149
149
}
150
- if (!ops -> ipc . close_ipc_handle ) {
151
- ops -> ipc . close_ipc_handle = umfDefaultCloseIPCHandle ;
150
+ if (!ops -> ext_close_ipc_handle ) {
151
+ ops -> ext_close_ipc_handle = umfDefaultCloseIPCHandle ;
152
152
}
153
- if (!ops -> ctl ) {
154
- ops -> ctl = umfDefaultCtlHandle ;
153
+ if (!ops -> ext_ctl ) {
154
+ ops -> ext_ctl = umfDefaultCtlHandle ;
155
155
}
156
156
}
157
157
158
- static bool validateOpsMandatory (const umf_memory_provider_ops_t * ops ) {
159
- // Mandatory ops should be non-NULL
160
- return ops -> alloc && ops -> free && ops -> get_recommended_page_size &&
161
- ops -> get_min_page_size && ops -> initialize && ops -> finalize &&
162
- ops -> get_last_native_error && ops -> get_name ;
163
- }
158
+ #define CHECK_OP (ops , fn ) \
159
+ if (!(ops)->fn) { \
160
+ LOG_ERR("Error: missing function pointer: %s\n", #fn); \
161
+ return false; \
162
+ }
164
163
165
- static bool validateOpsExt (const umf_memory_provider_ext_ops_t * ext ) {
166
- // split and merge functions should be both NULL or both non-NULL
167
- return (ext -> allocation_split && ext -> allocation_merge ) ||
168
- (!ext -> allocation_split && !ext -> allocation_merge );
169
- }
164
+ static bool validateOps (const umf_memory_provider_ops_t * ops ) {
165
+ // Validate mandatory operations one by one
166
+ CHECK_OP (ops , alloc );
167
+ CHECK_OP (ops , free );
168
+ CHECK_OP (ops , get_recommended_page_size );
169
+ CHECK_OP (ops , get_min_page_size );
170
+ CHECK_OP (ops , initialize );
171
+ CHECK_OP (ops , finalize );
172
+ CHECK_OP (ops , get_last_native_error );
173
+ CHECK_OP (ops , get_name );
174
+
175
+ if ((ops -> ext_allocation_split == NULL ) !=
176
+ (ops -> ext_allocation_merge == NULL )) {
177
+ LOG_ERR ("Error: ext_allocation_split and ext_allocation_merge must be "
178
+ "both set or both NULL\n" );
179
+ return false;
180
+ }
170
181
171
- static bool validateOpsIpc (const umf_memory_provider_ipc_ops_t * ipc ) {
172
- // valid if all ops->ipc.* are non-NULL or all are NULL
173
- return (ipc -> get_ipc_handle_size && ipc -> get_ipc_handle &&
174
- ipc -> put_ipc_handle && ipc -> open_ipc_handle &&
175
- ipc -> close_ipc_handle ) ||
176
- (!ipc -> get_ipc_handle_size && !ipc -> get_ipc_handle &&
177
- !ipc -> put_ipc_handle && !ipc -> open_ipc_handle &&
178
- !ipc -> close_ipc_handle );
179
- }
182
+ bool ipcAllSet = ops -> ext_get_ipc_handle_size && ops -> ext_get_ipc_handle &&
183
+ ops -> ext_put_ipc_handle && ops -> ext_open_ipc_handle &&
184
+ ops -> ext_close_ipc_handle ;
185
+ bool ipcAllNull = !ops -> ext_get_ipc_handle_size &&
186
+ !ops -> ext_get_ipc_handle && !ops -> ext_put_ipc_handle &&
187
+ !ops -> ext_open_ipc_handle && !ops -> ext_close_ipc_handle ;
188
+ if (!ipcAllSet && !ipcAllNull ) {
189
+ LOG_ERR ("Error: IPC function pointers must be either all set or all "
190
+ "NULL\n" );
191
+ return false;
192
+ }
180
193
181
- static bool validateOps (const umf_memory_provider_ops_t * ops ) {
182
- return validateOpsMandatory (ops ) && validateOpsExt (& (ops -> ext )) &&
183
- validateOpsIpc (& (ops -> ipc ));
194
+ return true;
184
195
}
185
196
186
197
umf_result_t umfMemoryProviderCreate (const umf_memory_provider_ops_t * ops ,
@@ -300,7 +311,7 @@ umf_result_t umfMemoryProviderPurgeLazy(umf_memory_provider_handle_t hProvider,
300
311
UMF_CHECK ((hProvider != NULL ), UMF_RESULT_ERROR_INVALID_ARGUMENT );
301
312
UMF_CHECK ((ptr != NULL ), UMF_RESULT_ERROR_INVALID_ARGUMENT );
302
313
umf_result_t res =
303
- hProvider -> ops .ext . purge_lazy (hProvider -> provider_priv , ptr , size );
314
+ hProvider -> ops .ext_purge_lazy (hProvider -> provider_priv , ptr , size );
304
315
checkErrorAndSetLastProvider (res , hProvider );
305
316
return res ;
306
317
}
@@ -310,7 +321,7 @@ umf_result_t umfMemoryProviderPurgeForce(umf_memory_provider_handle_t hProvider,
310
321
UMF_CHECK ((hProvider != NULL ), UMF_RESULT_ERROR_INVALID_ARGUMENT );
311
322
UMF_CHECK ((ptr != NULL ), UMF_RESULT_ERROR_INVALID_ARGUMENT );
312
323
umf_result_t res =
313
- hProvider -> ops .ext . purge_force (hProvider -> provider_priv , ptr , size );
324
+ hProvider -> ops .ext_purge_force (hProvider -> provider_priv , ptr , size );
314
325
checkErrorAndSetLastProvider (res , hProvider );
315
326
return res ;
316
327
}
@@ -329,7 +340,7 @@ umfMemoryProviderAllocationSplit(umf_memory_provider_handle_t hProvider,
329
340
UMF_RESULT_ERROR_INVALID_ARGUMENT );
330
341
UMF_CHECK ((firstSize < totalSize ), UMF_RESULT_ERROR_INVALID_ARGUMENT );
331
342
332
- umf_result_t res = hProvider -> ops .ext . allocation_split (
343
+ umf_result_t res = hProvider -> ops .ext_allocation_split (
333
344
hProvider -> provider_priv , ptr , totalSize , firstSize );
334
345
checkErrorAndSetLastProvider (res , hProvider );
335
346
return res ;
@@ -347,7 +358,7 @@ umfMemoryProviderAllocationMerge(umf_memory_provider_handle_t hProvider,
347
358
UMF_CHECK (((uintptr_t )highPtr - (uintptr_t )lowPtr < totalSize ),
348
359
UMF_RESULT_ERROR_INVALID_ARGUMENT );
349
360
350
- umf_result_t res = hProvider -> ops .ext . allocation_merge (
361
+ umf_result_t res = hProvider -> ops .ext_allocation_merge (
351
362
hProvider -> provider_priv , lowPtr , highPtr , totalSize );
352
363
checkErrorAndSetLastProvider (res , hProvider );
353
364
return res ;
@@ -358,7 +369,7 @@ umfMemoryProviderGetIPCHandleSize(umf_memory_provider_handle_t hProvider,
358
369
size_t * size ) {
359
370
UMF_CHECK ((hProvider != NULL ), UMF_RESULT_ERROR_INVALID_ARGUMENT );
360
371
UMF_CHECK ((size != NULL ), UMF_RESULT_ERROR_INVALID_ARGUMENT );
361
- return hProvider -> ops .ipc . get_ipc_handle_size (hProvider -> provider_priv ,
372
+ return hProvider -> ops .ext_get_ipc_handle_size (hProvider -> provider_priv ,
362
373
size );
363
374
}
364
375
@@ -369,7 +380,7 @@ umfMemoryProviderGetIPCHandle(umf_memory_provider_handle_t hProvider,
369
380
UMF_CHECK ((hProvider != NULL ), UMF_RESULT_ERROR_INVALID_ARGUMENT );
370
381
UMF_CHECK ((ptr != NULL ), UMF_RESULT_ERROR_INVALID_ARGUMENT );
371
382
UMF_CHECK ((providerIpcData != NULL ), UMF_RESULT_ERROR_INVALID_ARGUMENT );
372
- return hProvider -> ops .ipc . get_ipc_handle (hProvider -> provider_priv , ptr ,
383
+ return hProvider -> ops .ext_get_ipc_handle (hProvider -> provider_priv , ptr ,
373
384
size , providerIpcData );
374
385
}
375
386
@@ -378,7 +389,7 @@ umfMemoryProviderPutIPCHandle(umf_memory_provider_handle_t hProvider,
378
389
void * providerIpcData ) {
379
390
UMF_CHECK ((hProvider != NULL ), UMF_RESULT_ERROR_INVALID_ARGUMENT );
380
391
UMF_CHECK ((providerIpcData != NULL ), UMF_RESULT_ERROR_INVALID_ARGUMENT );
381
- return hProvider -> ops .ipc . put_ipc_handle (hProvider -> provider_priv ,
392
+ return hProvider -> ops .ext_put_ipc_handle (hProvider -> provider_priv ,
382
393
providerIpcData );
383
394
}
384
395
@@ -388,7 +399,7 @@ umfMemoryProviderOpenIPCHandle(umf_memory_provider_handle_t hProvider,
388
399
UMF_CHECK ((hProvider != NULL ), UMF_RESULT_ERROR_INVALID_ARGUMENT );
389
400
UMF_CHECK ((providerIpcData != NULL ), UMF_RESULT_ERROR_INVALID_ARGUMENT );
390
401
UMF_CHECK ((ptr != NULL ), UMF_RESULT_ERROR_INVALID_ARGUMENT );
391
- return hProvider -> ops .ipc . open_ipc_handle (hProvider -> provider_priv ,
402
+ return hProvider -> ops .ext_open_ipc_handle (hProvider -> provider_priv ,
392
403
providerIpcData , ptr );
393
404
}
394
405
@@ -397,6 +408,6 @@ umfMemoryProviderCloseIPCHandle(umf_memory_provider_handle_t hProvider,
397
408
void * ptr , size_t size ) {
398
409
UMF_CHECK ((hProvider != NULL ), UMF_RESULT_ERROR_INVALID_ARGUMENT );
399
410
UMF_CHECK ((ptr != NULL ), UMF_RESULT_ERROR_INVALID_ARGUMENT );
400
- return hProvider -> ops .ipc . close_ipc_handle (hProvider -> provider_priv , ptr ,
411
+ return hProvider -> ops .ext_close_ipc_handle (hProvider -> provider_priv , ptr ,
401
412
size );
402
413
}
0 commit comments