@@ -1618,12 +1618,26 @@ void nvp_free_dr_mmaps()
16181618 unsigned long offset_in_page = 0 ;
16191619 struct free_dr_pool * temp_free_pool_of_dr_mmaps ;
16201620 int i = 0 ;
1621+ ssize_t file_name_size = 0 ;
16211622
16221623 while ( lfds711_queue_umm_dequeue (& qs , & qe ) ) {
16231624 temp_free_pool_of_dr_mmaps = LFDS711_QUEUE_UMM_GET_VALUE_FROM_ELEMENT ( * qe );
16241625 addr = temp_free_pool_of_dr_mmaps -> start_addr ;
16251626 munmap ((void * )addr , DR_SIZE );
1627+
1628+ // Fetch the name of the file before closing it.
1629+ char fd_str [256 ];
1630+ char new_path [256 ];
1631+ sprintf (fd_str , "/proc/self/fd/%d" , temp_free_pool_of_dr_mmaps -> dr_fd );
1632+ file_name_size = readlink (fd_str , new_path , sizeof (new_path ));
1633+ if (file_name_size == -1 )
1634+ assert (0 );
1635+ new_path [file_name_size ] = '\0' ;
1636+
16261637 close (temp_free_pool_of_dr_mmaps -> dr_fd );
1638+
1639+ // Remove the file.
1640+ _nvp_fileops -> UNLINK (new_path );
16271641 __atomic_fetch_sub (& num_drs_left , 1 , __ATOMIC_SEQ_CST );
16281642 }
16291643 lfds711_queue_umm_cleanup ( & qs , NULL );
@@ -1634,7 +1648,20 @@ void nvp_free_dr_mmaps()
16341648 temp_free_pool_of_dr_mmaps = LFDS711_QUEUE_UMM_GET_VALUE_FROM_ELEMENT ( * qe_over );
16351649 addr = temp_free_pool_of_dr_mmaps -> start_addr ;
16361650 munmap ((void * )addr , DR_OVER_SIZE );
1651+
1652+ // Fetch the name of the file before closing it.
1653+ char fd_str [256 ];
1654+ char new_path [256 ];
1655+ sprintf (fd_str , "/proc/self/fd/%d" , temp_free_pool_of_dr_mmaps -> dr_fd );
1656+ file_name_size = readlink (fd_str , new_path , sizeof (new_path ));
1657+ if (readlink (file_name_size == -1 )
1658+ assert (0 );
1659+ new_path [file_name_size ] = '\0' ;
1660+
16371661 close (temp_free_pool_of_dr_mmaps -> dr_fd );
1662+
1663+ // Remove the file.
1664+ _nvp_fileops -> UNLINK (new_path );
16381665 __atomic_fetch_sub (& num_drs_left , 1 , __ATOMIC_SEQ_CST );
16391666 }
16401667 lfds711_queue_umm_cleanup ( & qs_over , NULL );
@@ -4805,6 +4832,7 @@ RETT_EXECVE _nvp_EXECVE(INTF_EXECVE) {
48054832 assert (0 );
48064833 }
48074834
4835+ nvp_free_dr_mmaps ();
48084836 offset_in_map += (1024 * sizeof (struct StackNode ));
48094837
48104838 return _nvp_fileops -> EXECVE (CALL_EXECVE );
@@ -4883,10 +4911,89 @@ RETT_EXECVP _nvp_EXECVP(INTF_EXECVP) {
48834911 }
48844912
48854913 offset_in_map += (1024 * sizeof (struct StackNode ));
4886-
4914+
4915+ nvp_free_dr_mmaps ();
48874916 return _nvp_fileops -> EXECVP (CALL_EXECVP );
48884917}
48894918
4919+ RETT_EXECV _nvp_EXECV (INTF_EXECV ) {
4920+
4921+ int exec_ledger_fd = -1 , i = 0 ;
4922+ unsigned long offset_in_map = 0 ;
4923+ int pid = getpid ();
4924+ char exec_nvp_filename [BUF_SIZE ];
4925+
4926+ for (i = 0 ; i < 1024 ; i ++ ) {
4927+ if (_nvp_fd_lookup [i ].offset != NULL )
4928+ execve_fd_passing [i ] = * (_nvp_fd_lookup [i ].offset );
4929+ else
4930+ execve_fd_passing [i ] = 0 ;
4931+ }
4932+
4933+ for (i = 0 ; i < OPEN_MAX ; i ++ ) {
4934+ if (_nvp_fd_lookup [i ].node != NULL && _nvp_fd_lookup [i ].valid )
4935+ _nvp_FSYNC (_nvp_fd_lookup [i ].fd );
4936+ }
4937+
4938+ sprintf (exec_nvp_filename , "exec-ledger-%d" , pid );
4939+ exec_ledger_fd = shm_open (exec_nvp_filename , O_RDWR | O_CREAT , S_IRUSR | S_IWUSR );
4940+ if (exec_ledger_fd == -1 ) {
4941+ printf ("%s: %s\n" , __func__ , strerror (errno ));
4942+ assert (0 );
4943+ }
4944+
4945+ int res = _nvp_fileops -> FTRUNC64 (exec_ledger_fd , (10 * 1024 * 1024 ));
4946+ if (res == -1 ) {
4947+ printf ("%s: ftruncate failed. Err = %s\n" , __func__ , strerror (errno ));
4948+ assert (0 );
4949+ }
4950+
4951+ char * shm_area = mmap (NULL , 10 * 1024 * 1024 , PROT_READ | PROT_WRITE , MAP_SHARED , exec_ledger_fd , 0 );
4952+ if (shm_area == NULL ) {
4953+ printf ("%s: mmap failed. Err = %s\n" , __func__ , strerror (errno ));
4954+ assert (0 );
4955+ }
4956+
4957+ if (memcpy (shm_area + offset_in_map , _nvp_fd_lookup , 1024 * sizeof (struct NVFile )) == NULL ) {
4958+ printf ("%s: memcpy of fd lookup failed. Err = %s\n" , __func__ , strerror (errno ));
4959+ assert (0 );
4960+ }
4961+
4962+ offset_in_map += (1024 * sizeof (struct NVFile ));
4963+
4964+ if (memcpy (shm_area + offset_in_map , execve_fd_passing , 1024 * sizeof (int )) == NULL ) {
4965+ printf ("%s: memcpy of execve offset failed. Err = %s\n" , __func__ , strerror (errno ));
4966+ assert (0 );
4967+ }
4968+
4969+ offset_in_map += (1024 * sizeof (int ));
4970+
4971+
4972+ if (memcpy (shm_area + offset_in_map , _nvp_node_lookup [0 ], 1024 * sizeof (struct NVNode )) == NULL ) {
4973+ printf ("%s: memcpy of node lookup failed. Err = %s\n" , __func__ , strerror (errno ));
4974+ assert (0 );
4975+ }
4976+
4977+ offset_in_map += (1024 * sizeof (struct NVNode ));
4978+
4979+ if (memcpy (shm_area + offset_in_map , _nvp_ino_lookup , 1024 * sizeof (int )) == NULL ) {
4980+ printf ("%s: memcpy of ino lookup failed. Err = %s\n" , __func__ , strerror (errno ));
4981+ assert (0 );
4982+ }
4983+
4984+ offset_in_map += (1024 * sizeof (int ));
4985+
4986+ if (memcpy (shm_area + offset_in_map , _nvp_free_node_list [0 ], 1024 * sizeof (struct StackNode )) == NULL ) {
4987+ printf ("%s: memcpy of free node list failed. Err = %s\n" , __func__ , strerror (errno ));
4988+ assert (0 );
4989+ }
4990+
4991+ offset_in_map += (1024 * sizeof (struct StackNode ));
4992+
4993+ nvp_free_dr_mmaps ();
4994+ return _nvp_fileops -> EXECV (CALL_EXECV );
4995+ }
4996+
48904997#ifdef TRACE_FP_CALLS
48914998RETT_FCLOSE _nvp_FCLOSE (INTF_FCLOSE )
48924999{
0 commit comments