@@ -25,6 +25,41 @@ umf_memory_provider_ops_t *umfFileMemoryProviderOps(void) {
2525 return NULL ;
2626}
2727
28+ umf_result_t umfFileMemoryProviderParamsCreate (
29+ umf_file_memory_provider_params_handle_t * hParams , const char * path ) {
30+ (void )hParams ;
31+ (void )path ;
32+ return UMF_RESULT_ERROR_NOT_SUPPORTED ;
33+ }
34+
35+ umf_result_t umfFileMemoryProviderParamsDestroy (
36+ umf_file_memory_provider_params_handle_t hParams ) {
37+ (void )hParams ;
38+ return UMF_RESULT_ERROR_NOT_SUPPORTED ;
39+ }
40+
41+ umf_result_t umfFileMemoryProviderParamsSetPath (
42+ umf_file_memory_provider_params_handle_t hParams , const char * path ) {
43+ (void )hParams ;
44+ (void )path ;
45+ return UMF_RESULT_ERROR_NOT_SUPPORTED ;
46+ }
47+
48+ umf_result_t umfFileMemoryProviderParamsSetProtection (
49+ umf_file_memory_provider_params_handle_t hParams , unsigned protection ) {
50+ (void )hParams ;
51+ (void )protection ;
52+ return UMF_RESULT_ERROR_NOT_SUPPORTED ;
53+ }
54+
55+ umf_result_t umfFileMemoryProviderParamsSetVisibility (
56+ umf_file_memory_provider_params_handle_t hParams ,
57+ umf_memory_visibility_t visibility ) {
58+ (void )hParams ;
59+ (void )visibility ;
60+ return UMF_RESULT_ERROR_NOT_SUPPORTED ;
61+ }
62+
2863#else // !defined(_WIN32) && !defined(UMF_NO_HWLOC)
2964
3065#include "base_alloc_global.h"
@@ -67,6 +102,13 @@ typedef struct file_memory_provider_t {
67102 critnib * fd_offset_map ;
68103} file_memory_provider_t ;
69104
105+ // File Memory Provider settings struct
106+ typedef struct umf_file_memory_provider_params_t {
107+ char * path ;
108+ unsigned protection ;
109+ umf_memory_visibility_t visibility ;
110+ } umf_file_memory_provider_params_t ;
111+
70112typedef struct file_last_native_error_t {
71113 int32_t native_error ;
72114 int errno_value ;
@@ -748,4 +790,107 @@ umf_memory_provider_ops_t *umfFileMemoryProviderOps(void) {
748790 return & UMF_FILE_MEMORY_PROVIDER_OPS ;
749791}
750792
793+ umf_result_t umfFileMemoryProviderParamsCreate (
794+ umf_file_memory_provider_params_handle_t * hParams , const char * path ) {
795+ if (hParams == NULL ) {
796+ LOG_ERR ("File Memory Provider params handle is NULL" );
797+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
798+ }
799+
800+ if (path == NULL ) {
801+ LOG_ERR ("File path is NULL" );
802+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
803+ }
804+
805+ umf_file_memory_provider_params_handle_t params =
806+ umf_ba_global_alloc (sizeof (* params ));
807+ if (params == NULL ) {
808+ LOG_ERR ("allocating memory for File Memory Provider params failed" );
809+ return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY ;
810+ }
811+
812+ params -> path = NULL ;
813+ params -> protection = UMF_PROTECTION_READ | UMF_PROTECTION_WRITE ;
814+ params -> visibility = UMF_MEM_MAP_PRIVATE ;
815+
816+ umf_result_t res = umfFileMemoryProviderParamsSetPath (params , path );
817+ if (res != UMF_RESULT_SUCCESS ) {
818+ umf_ba_global_free (params );
819+ return res ;
820+ }
821+
822+ * hParams = params ;
823+
824+ return UMF_RESULT_SUCCESS ;
825+ }
826+
827+ umf_result_t umfFileMemoryProviderParamsDestroy (
828+ umf_file_memory_provider_params_handle_t hParams ) {
829+ if (hParams != NULL ) {
830+ umf_ba_global_free (hParams -> path );
831+ umf_ba_global_free (hParams );
832+ }
833+
834+ return UMF_RESULT_SUCCESS ;
835+ }
836+
837+ umf_result_t umfFileMemoryProviderParamsSetPath (
838+ umf_file_memory_provider_params_handle_t hParams , const char * path ) {
839+ if (hParams == NULL ) {
840+ LOG_ERR ("File Memory Provider params handle is NULL" );
841+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
842+ }
843+
844+ if (path == NULL ) {
845+ LOG_ERR ("File path is NULL" );
846+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
847+ }
848+
849+ size_t len = strlen (path );
850+ if (len == 0 ) {
851+ LOG_ERR ("File path is empty" );
852+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
853+ }
854+
855+ char * new_path = NULL ;
856+ new_path = umf_ba_global_alloc (len + 1 );
857+ if (new_path == NULL ) {
858+ LOG_ERR ("allocating memory for the file path failed" );
859+ return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY ;
860+ }
861+
862+ strncpy (new_path , path , len );
863+ new_path [len ] = '\0' ;
864+
865+ umf_ba_global_free (hParams -> path );
866+ hParams -> path = new_path ;
867+
868+ return UMF_RESULT_SUCCESS ;
869+ }
870+
871+ umf_result_t umfFileMemoryProviderParamsSetProtection (
872+ umf_file_memory_provider_params_handle_t hParams , unsigned protection ) {
873+ if (hParams == NULL ) {
874+ LOG_ERR ("File Memory Provider params handle is NULL" );
875+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
876+ }
877+
878+ hParams -> protection = protection ;
879+
880+ return UMF_RESULT_SUCCESS ;
881+ }
882+
883+ umf_result_t umfFileMemoryProviderParamsSetVisibility (
884+ umf_file_memory_provider_params_handle_t hParams ,
885+ umf_memory_visibility_t visibility ) {
886+ if (hParams == NULL ) {
887+ LOG_ERR ("File Memory Provider params handle is NULL" );
888+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
889+ }
890+
891+ hParams -> visibility = visibility ;
892+
893+ return UMF_RESULT_SUCCESS ;
894+ }
895+
751896#endif // !defined(_WIN32) && !defined(UMF_NO_HWLOC)
0 commit comments