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