@@ -19,140 +19,24 @@ extern "C" {
1919/// @brief Version of the Memory Provider ops structure.
2020/// NOTE: This is equal to the latest UMF version, in which the ops structure
2121/// has been modified.
22- #define UMF_PROVIDER_OPS_VERSION_CURRENT UMF_MAKE_VERSION(0, 11)
23-
24- ///
25- /// @brief This structure comprises optional function pointers used
26- /// by corresponding umfMemoryProvider* calls. A memory provider implementation
27- /// can keep them NULL.
28- ///
29- typedef struct umf_memory_provider_ext_ops_0_11_t {
30- ///
31- /// @brief Discard physical pages within the virtual memory mapping associated at the given addr
32- /// and \p size. This call is asynchronous and may delay purging the pages indefinitely.
33- /// @param provider pointer to the memory provider
34- /// @param ptr beginning of the virtual memory range
35- /// @param size size of the virtual memory range
36- /// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
37- /// UMF_RESULT_ERROR_INVALID_ALIGNMENT if ptr or size is not page-aligned.
38- /// UMF_RESULT_ERROR_NOT_SUPPORTED if operation is not supported by this provider.
39- ///
40- umf_result_t (* purge_lazy )(void * provider , void * ptr , size_t size );
41-
42- ///
43- /// @brief Discard physical pages within the virtual memory mapping associated at the given addr and \p size.
44- /// This call is synchronous and if it succeeds, pages are guaranteed to be zero-filled on the next access.
45- /// @param provider pointer to the memory provider
46- /// @param ptr beginning of the virtual memory range
47- /// @param size size of the virtual memory range
48- /// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure
49- /// UMF_RESULT_ERROR_INVALID_ALIGNMENT if ptr or size is not page-aligned.
50- /// UMF_RESULT_ERROR_NOT_SUPPORTED if operation is not supported by this provider.
51- ///
52- umf_result_t (* purge_force )(void * provider , void * ptr , size_t size );
53-
54- ///
55- /// @brief Merges two coarse grain allocations into a single allocation that
56- /// can be managed (freed) as a whole.
57- /// allocation_split and allocation_merge should be both set or both NULL.
58- /// allocation_merge should NOT be called concurrently with allocation_split()
59- /// with the same pointer.
60- /// @param hProvider handle to the memory provider
61- /// @param lowPtr pointer to the first allocation
62- /// @param highPtr pointer to the second allocation (should be > lowPtr)
63- /// @param totalSize size of a new merged allocation. Should be equal
64- /// to the sum of sizes of allocations beginning at lowPtr and highPtr
65- /// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure
66- ///
67- umf_result_t (* allocation_merge )(void * hProvider , void * lowPtr ,
68- void * highPtr , size_t totalSize );
69-
70- ///
71- /// @brief Splits a coarse grain allocation into 2 adjacent allocations that
72- /// can be managed (freed) separately.
73- /// allocation_split and allocation_merge should be both set or both NULL.
74- /// allocation_split should NOT be called concurrently with allocation_merge()
75- /// with the same pointer.
76- /// @param hProvider handle to the memory provider
77- /// @param ptr pointer to the beginning of the allocation
78- /// @param totalSize total size of the allocation to be split
79- /// @param firstSize size of the first new allocation, second allocation
80- // has a size equal to totalSize - firstSize
81- /// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure
82- ///
83- umf_result_t (* allocation_split )(void * hProvider , void * ptr ,
84- size_t totalSize , size_t firstSize );
85-
86- } umf_memory_provider_ext_ops_0_11_t ;
87- typedef umf_memory_provider_ext_ops_0_11_t umf_memory_provider_ext_ops_t ;
88-
89- ///
90- /// @brief This structure comprises optional IPC API. The API allows sharing of
91- /// memory objects across different processes. A memory provider implementation can keep them NULL.
92- ///
93- typedef struct umf_memory_provider_ipc_ops_0_11_t {
94- ///
95- /// @brief Retrieve the size of opaque data structure required to store IPC data.
96- /// @param provider pointer to the memory provider.
97- /// @param size [out] pointer to the size.
98- /// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
99- /// UMF_RESULT_ERROR_NOT_SUPPORTED if IPC functionality is not supported by this provider.
100- umf_result_t (* get_ipc_handle_size )(void * provider , size_t * size );
101-
102- ///
103- /// @brief Retrieve an IPC memory handle for the specified allocation.
104- /// @param provider pointer to the memory provider.
105- /// @param ptr beginning of the virtual memory range.
106- /// @param size size of the memory address range.
107- /// @param providerIpcData [out] pointer to the preallocated opaque data structure to store IPC handle.
108- /// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
109- /// UMF_RESULT_ERROR_INVALID_ARGUMENT if ptr was not allocated by this provider.
110- /// UMF_RESULT_ERROR_NOT_SUPPORTED if IPC functionality is not supported by this provider.
111- umf_result_t (* get_ipc_handle )(void * provider , const void * ptr , size_t size ,
112- void * providerIpcData );
113-
114- ///
115- /// @brief Release IPC handle retrieved with get_ipc_handle function.
116- /// @param provider pointer to the memory provider.
117- /// @param providerIpcData pointer to the IPC opaque data structure.
118- /// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
119- /// UMF_RESULT_ERROR_INVALID_ARGUMENT if providerIpcData was not created by this provider.
120- /// UMF_RESULT_ERROR_NOT_SUPPORTED if IPC functionality is not supported by this provider.
121- umf_result_t (* put_ipc_handle )(void * provider , void * providerIpcData );
122-
123- ///
124- /// @brief Open IPC handle.
125- /// @param provider pointer to the memory provider.
126- /// @param providerIpcData pointer to the IPC opaque data structure.
127- /// @param ptr [out] pointer to the memory to be used in the current process.
128- /// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
129- /// UMF_RESULT_ERROR_INVALID_ARGUMENT if providerIpcData cannot be handled by the provider.
130- /// UMF_RESULT_ERROR_NOT_SUPPORTED if IPC functionality is not supported by this provider.
131- umf_result_t (* open_ipc_handle )(void * provider , void * providerIpcData ,
132- void * * ptr );
133-
134- ///
135- /// @brief Closes an IPC memory handle.
136- /// @param provider pointer to the memory provider.
137- /// @param ptr pointer to the memory retrieved with open_ipc_handle function.
138- /// @param size size of the memory address range.
139- /// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
140- /// UMF_RESULT_ERROR_INVALID_ARGUMENT if invalid \p ptr is passed.
141- /// UMF_RESULT_ERROR_NOT_SUPPORTED if IPC functionality is not supported by this provider.
142- umf_result_t (* close_ipc_handle )(void * provider , void * ptr , size_t size );
143- } umf_memory_provider_ipc_ops_0_11_t ;
144- typedef umf_memory_provider_ipc_ops_0_11_t umf_memory_provider_ipc_ops_t ;
22+ #define UMF_PROVIDER_OPS_VERSION_CURRENT UMF_MAKE_VERSION(0, 12)
14523
14624///
14725/// @brief This structure comprises function pointers used by corresponding
14826/// umfMemoryProvider* calls. Each memory provider implementation should
14927/// initialize all function pointers.
15028///
151- typedef struct umf_memory_provider_ops_0_11_t {
29+ typedef struct umf_memory_provider_ops_0_12_t {
15230 /// Version of the ops structure.
15331 /// Should be initialized using UMF_PROVIDER_OPS_VERSION_CURRENT.
15432 uint32_t version ;
15533
34+ // Size of this structure.
35+ // Note: Using sizeof() to get the size of this structure may return an
36+ // invalid size due to optional functions possibly added to the "extra[]"
37+ // variadic member.
38+ size_t size ;
39+
15640 ///
15741 /// @brief Initializes memory provider.
15842 /// @param params provider-specific params
@@ -244,16 +128,116 @@ typedef struct umf_memory_provider_ops_0_11_t {
244128 const char * (* get_name )(void * provider );
245129
246130 ///
247- /// @brief Optional ops
131+ /// @brief Discard physical pages within the virtual memory mapping associated at the given addr
132+ /// and \p size. This call is asynchronous and may delay purging the pages indefinitely.
133+ /// @param provider pointer to the memory provider
134+ /// @param ptr beginning of the virtual memory range
135+ /// @param size size of the virtual memory range
136+ /// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
137+ /// UMF_RESULT_ERROR_INVALID_ALIGNMENT if ptr or size is not page-aligned.
138+ /// UMF_RESULT_ERROR_NOT_SUPPORTED if operation is not supported by this provider.
139+ ///
140+ umf_result_t (* ext_purge_lazy )(void * provider , void * ptr , size_t size );
141+
142+ ///
143+ /// @brief Discard physical pages within the virtual memory mapping associated at the given addr and \p size.
144+ /// This call is synchronous and if it succeeds, pages are guaranteed to be zero-filled on the next access.
145+ /// @param provider pointer to the memory provider
146+ /// @param ptr beginning of the virtual memory range
147+ /// @param size size of the virtual memory range
148+ /// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure
149+ /// UMF_RESULT_ERROR_INVALID_ALIGNMENT if ptr or size is not page-aligned.
150+ /// UMF_RESULT_ERROR_NOT_SUPPORTED if operation is not supported by this provider.
151+ ///
152+ umf_result_t (* ext_purge_force )(void * provider , void * ptr , size_t size );
153+
154+ ///
155+ /// @brief Merges two coarse grain allocations into a single allocation that
156+ /// can be managed (freed) as a whole.
157+ /// ext_allocation_split and allocation_merge should be both set or both NULL.
158+ /// ext_allocation_merge() should NOT be called concurrently with ext_allocation_split()
159+ /// with the same pointer.
160+ /// @param hProvider handle to the memory provider
161+ /// @param lowPtr pointer to the first allocation
162+ /// @param highPtr pointer to the second allocation (should be > lowPtr)
163+ /// @param totalSize size of a new merged allocation. Should be equal
164+ /// to the sum of sizes of allocations beginning at lowPtr and highPtr
165+ /// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure
166+ ///
167+ umf_result_t (* ext_allocation_merge )(void * hProvider , void * lowPtr ,
168+ void * highPtr , size_t totalSize );
169+
170+ ///
171+ /// @brief Splits a coarse grain allocation into 2 adjacent allocations that
172+ /// can be managed (freed) separately.
173+ /// ext_allocation_split() and ext_allocation_merge() should be both set or both NULL.
174+ /// ext_allocation_split() should NOT be called concurrently with allocation_merge()
175+ /// with the same pointer.
176+ /// @param hProvider handle to the memory provider
177+ /// @param ptr pointer to the beginning of the allocation
178+ /// @param totalSize total size of the allocation to be split
179+ /// @param firstSize size of the first new allocation, second allocation
180+ // has a size equal to totalSize - firstSize
181+ /// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure
182+ ///
183+ umf_result_t (* ext_allocation_split )(void * hProvider , void * ptr ,
184+ size_t totalSize , size_t firstSize );
185+
186+ ///
187+ /// @brief Retrieve the size of opaque data structure required to store IPC data.
188+ /// @param provider pointer to the memory provider.
189+ /// @param size [out] pointer to the size.
190+ /// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
191+ /// UMF_RESULT_ERROR_NOT_SUPPORTED if IPC functionality is not supported by this provider.
192+ umf_result_t (* ipc_get_handle_size )(void * provider , size_t * size );
193+
248194 ///
249- umf_memory_provider_ext_ops_t ext ;
195+ /// @brief Retrieve an IPC memory handle for the specified allocation.
196+ /// @param provider pointer to the memory provider.
197+ /// @param ptr beginning of the virtual memory range.
198+ /// @param size size of the memory address range.
199+ /// @param providerIpcData [out] pointer to the preallocated opaque data structure to store IPC handle.
200+ /// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
201+ /// UMF_RESULT_ERROR_INVALID_ARGUMENT if ptr was not allocated by this provider.
202+ /// UMF_RESULT_ERROR_NOT_SUPPORTED if IPC functionality is not supported by this provider.
203+ umf_result_t (* ipc_get_handle )(void * provider , const void * ptr , size_t size ,
204+ void * providerIpcData );
250205
251206 ///
252- /// @brief Optional IPC ops. The API allows sharing of memory objects across different processes.
207+ /// @brief Release IPC handle retrieved with ipc_get_handle function.
208+ /// @param provider pointer to the memory provider.
209+ /// @param providerIpcData pointer to the IPC opaque data structure.
210+ /// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
211+ /// UMF_RESULT_ERROR_INVALID_ARGUMENT if providerIpcData was not created by this provider.
212+ /// UMF_RESULT_ERROR_NOT_SUPPORTED if IPC functionality is not supported by this provider.
213+ umf_result_t (* ipc_put_handle )(void * provider , void * providerIpcData );
214+
215+ ///
216+ /// @brief Open IPC handle.
217+ /// @param provider pointer to the memory provider.
218+ /// @param providerIpcData pointer to the IPC opaque data structure.
219+ /// @param ptr [out] pointer to the memory to be used in the current process.
220+ /// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
221+ /// UMF_RESULT_ERROR_INVALID_ARGUMENT if providerIpcData cannot be handled by the provider.
222+ /// UMF_RESULT_ERROR_NOT_SUPPORTED if IPC functionality is not supported by this provider.
223+ umf_result_t (* ipc_open_handle )(void * provider , void * providerIpcData ,
224+ void * * ptr );
225+
226+ ///
227+ /// @brief Closes an IPC memory handle.
228+ /// @param provider pointer to the memory provider.
229+ /// @param ptr pointer to the memory retrieved with ipc_open_handle function.
230+ /// @param size size of the memory address range.
231+ /// @return UMF_RESULT_SUCCESS on success or appropriate error code on failure.
232+ /// UMF_RESULT_ERROR_INVALID_ARGUMENT if invalid \p ptr is passed.
233+ /// UMF_RESULT_ERROR_NOT_SUPPORTED if IPC functionality is not supported by this provider.
234+ umf_result_t (* ipc_close_handle )(void * provider , void * ptr , size_t size );
235+
253236 ///
254- umf_memory_provider_ipc_ops_t ipc ;
255- } umf_memory_provider_ops_0_11_t ;
256- typedef umf_memory_provider_ops_0_11_t umf_memory_provider_ops_t ;
237+ /// @brief Extra function pointers for future extensions.
238+ void * extra [];
239+ } umf_memory_provider_ops_0_12_t ;
240+ typedef umf_memory_provider_ops_0_12_t umf_memory_provider_ops_t ;
257241
258242#ifdef __cplusplus
259243}
0 commit comments