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