@@ -397,16 +397,21 @@ static umf_result_t file_alloc(void *provider, size_t size, size_t alignment,
397
397
return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
398
398
}
399
399
400
- // alignment must be a power of two and a multiple of sizeof(void *)
401
- if (alignment &&
402
- ((alignment & (alignment - 1 )) || (alignment % sizeof (void * )))) {
403
- LOG_ERR ("wrong alignment: %zu (not a power of 2 or a multiple of "
404
- "sizeof(void *))" ,
405
- alignment );
400
+ file_memory_provider_t * file_provider = (file_memory_provider_t * )provider ;
401
+
402
+ // alignment must be a power of two and a multiple or a divider of the page size
403
+ if (alignment && ((alignment & (alignment - 1 )) ||
404
+ ((alignment % file_provider -> page_size ) &&
405
+ (file_provider -> page_size % alignment )))) {
406
+ LOG_ERR ("wrong alignment: %zu (not a power of 2 or a multiple or a "
407
+ "divider of the page size (%zu))" ,
408
+ alignment , file_provider -> page_size );
406
409
return UMF_RESULT_ERROR_INVALID_ALIGNMENT ;
407
410
}
408
411
409
- file_memory_provider_t * file_provider = (file_memory_provider_t * )provider ;
412
+ if (IS_NOT_ALIGNED (alignment , file_provider -> page_size )) {
413
+ alignment = ALIGN_UP (alignment , file_provider -> page_size );
414
+ }
410
415
411
416
void * addr = NULL ;
412
417
size_t alloc_offset_fd ; // needed for critnib_insert()
@@ -578,6 +583,8 @@ typedef struct file_ipc_data_t {
578
583
char path [PATH_MAX ];
579
584
size_t offset_fd ;
580
585
size_t size ;
586
+ unsigned protection ; // combination of OS-specific protection flags
587
+ unsigned visibility ; // memory visibility mode
581
588
} file_ipc_data_t ;
582
589
583
590
static umf_result_t file_get_ipc_handle_size (void * provider , size_t * size ) {
@@ -623,6 +630,8 @@ static umf_result_t file_get_ipc_handle(void *provider, const void *ptr,
623
630
file_ipc_data -> size = size ;
624
631
strncpy (file_ipc_data -> path , file_provider -> path , PATH_MAX - 1 );
625
632
file_ipc_data -> path [PATH_MAX - 1 ] = '\0' ;
633
+ file_ipc_data -> protection = file_provider -> protection ;
634
+ file_ipc_data -> visibility = file_provider -> visibility ;
626
635
627
636
return UMF_RESULT_SUCCESS ;
628
637
}
@@ -672,16 +681,26 @@ static umf_result_t file_open_ipc_handle(void *provider, void *providerIpcData,
672
681
return UMF_RESULT_ERROR_INVALID_ARGUMENT ;
673
682
}
674
683
675
- * ptr = utils_mmap_file (NULL , file_ipc_data -> size , file_provider -> protection ,
676
- file_provider -> visibility , fd ,
677
- file_ipc_data -> offset_fd );
684
+ char * addr = utils_mmap_file (
685
+ NULL , file_ipc_data -> size , file_ipc_data -> protection ,
686
+ file_ipc_data -> visibility , fd , file_ipc_data -> offset_fd );
678
687
(void )utils_close_fd (fd );
679
- if (* ptr == NULL ) {
688
+ if (addr == NULL ) {
680
689
file_store_last_native_error (UMF_FILE_RESULT_ERROR_ALLOC_FAILED , errno );
681
- LOG_PERR ("memory mapping failed" );
682
- ret = UMF_RESULT_ERROR_MEMORY_PROVIDER_SPECIFIC ;
690
+ LOG_PERR ("file mapping failed (path: %s, size: %zu, protection: %i, "
691
+ "fd: %i, offset: %zu)" ,
692
+ file_ipc_data -> path , file_ipc_data -> size ,
693
+ file_ipc_data -> protection , fd , file_ipc_data -> offset_fd );
694
+ return UMF_RESULT_ERROR_MEMORY_PROVIDER_SPECIFIC ;
683
695
}
684
696
697
+ LOG_DEBUG ("file mapped (path: %s, size: %zu, protection: %i, fd: %i, "
698
+ "offset: %zu) at address %p" ,
699
+ file_ipc_data -> path , file_ipc_data -> size ,
700
+ file_ipc_data -> protection , fd , file_ipc_data -> offset_fd , addr );
701
+
702
+ * ptr = addr ;
703
+
685
704
return ret ;
686
705
}
687
706
0 commit comments