@@ -25,10 +25,46 @@ 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"
3166#include "critnib.h"
67+ #include "libumf.h"
3268#include "utils_common.h"
3369#include "utils_concurrency.h"
3470#include "utils_log.h"
@@ -67,6 +103,13 @@ typedef struct file_memory_provider_t {
67103 critnib * fd_offset_map ;
68104} file_memory_provider_t ;
69105
106+ // File Memory Provider settings struct
107+ typedef struct umf_file_memory_provider_params_t {
108+ char * path ;
109+ unsigned protection ;
110+ umf_memory_visibility_t visibility ;
111+ } umf_file_memory_provider_params_t ;
112+
70113typedef struct file_last_native_error_t {
71114 int32_t native_error ;
72115 int errno_value ;
@@ -748,4 +791,108 @@ umf_memory_provider_ops_t *umfFileMemoryProviderOps(void) {
748791 return & UMF_FILE_MEMORY_PROVIDER_OPS ;
749792}
750793
794+ umf_result_t umfFileMemoryProviderParamsCreate (
795+ umf_file_memory_provider_params_handle_t * hParams , const char * path ) {
796+ libumfInit ();
797+ if (hParams == NULL ) {
798+ LOG_ERR ("File Memory Provider params handle is NULL" );
799+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
800+ }
801+
802+ if (path == NULL ) {
803+ LOG_ERR ("File path is NULL" );
804+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
805+ }
806+
807+ umf_file_memory_provider_params_handle_t params =
808+ umf_ba_global_alloc (sizeof (* params ));
809+ if (params == NULL ) {
810+ LOG_ERR ("allocating memory for File Memory Provider params failed" );
811+ return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY ;
812+ }
813+
814+ params -> path = NULL ;
815+ params -> protection = UMF_PROTECTION_READ | UMF_PROTECTION_WRITE ;
816+ params -> visibility = UMF_MEM_MAP_PRIVATE ;
817+
818+ umf_result_t res = umfFileMemoryProviderParamsSetPath (params , path );
819+ if (res != UMF_RESULT_SUCCESS ) {
820+ umf_ba_global_free (params );
821+ return res ;
822+ }
823+
824+ * hParams = params ;
825+
826+ return UMF_RESULT_SUCCESS ;
827+ }
828+
829+ umf_result_t umfFileMemoryProviderParamsDestroy (
830+ umf_file_memory_provider_params_handle_t hParams ) {
831+ if (hParams != NULL ) {
832+ umf_ba_global_free (hParams -> path );
833+ umf_ba_global_free (hParams );
834+ }
835+
836+ return UMF_RESULT_SUCCESS ;
837+ }
838+
839+ umf_result_t umfFileMemoryProviderParamsSetPath (
840+ umf_file_memory_provider_params_handle_t hParams , const char * path ) {
841+ if (hParams == NULL ) {
842+ LOG_ERR ("File Memory Provider params handle is NULL" );
843+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
844+ }
845+
846+ if (path == NULL ) {
847+ LOG_ERR ("File path is NULL" );
848+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
849+ }
850+
851+ size_t len = strlen (path );
852+ if (len == 0 ) {
853+ LOG_ERR ("File path is empty" );
854+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
855+ }
856+
857+ len += 1 ; // for the null terminator
858+ char * new_path = NULL ;
859+ new_path = umf_ba_global_alloc (len );
860+ if (new_path == NULL ) {
861+ LOG_ERR ("allocating memory for the file path failed" );
862+ return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY ;
863+ }
864+
865+ strncpy (new_path , path , len );
866+
867+ umf_ba_global_free (hParams -> path );
868+ hParams -> path = new_path ;
869+
870+ return UMF_RESULT_SUCCESS ;
871+ }
872+
873+ umf_result_t umfFileMemoryProviderParamsSetProtection (
874+ umf_file_memory_provider_params_handle_t hParams , unsigned protection ) {
875+ if (hParams == NULL ) {
876+ LOG_ERR ("File Memory Provider params handle is NULL" );
877+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
878+ }
879+
880+ hParams -> protection = protection ;
881+
882+ return UMF_RESULT_SUCCESS ;
883+ }
884+
885+ umf_result_t umfFileMemoryProviderParamsSetVisibility (
886+ umf_file_memory_provider_params_handle_t hParams ,
887+ umf_memory_visibility_t visibility ) {
888+ if (hParams == NULL ) {
889+ LOG_ERR ("File Memory Provider params handle is NULL" );
890+ return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
891+ }
892+
893+ hParams -> visibility = visibility ;
894+
895+ return UMF_RESULT_SUCCESS ;
896+ }
897+
751898#endif // !defined(_WIN32) && !defined(UMF_NO_HWLOC)
0 commit comments