@@ -99,50 +99,65 @@ bundle_executable_path (const char* executable, const char* bundle_path, const c
9999}
100100
101101static bool
102- external_assembly_probe (const char * relative_assembly_path , void * * data , int64_t * size )
102+ try_map_assembly (const char * dir , const char * name , void * * data , int64_t * size )
103103{
104- if (g_mapped_files_count >= MAX_MAPPED_COUNT )
105- {
106- LOG_ERROR ("Too many mapped files, cannot map %s" , relative_assembly_path );
107- return false;
108- }
109-
110- // Look in the bundle path where the files were extracted
111104 char full_path [1024 ];
112- size_t path_len = strlen (g_bundle_path ) + strlen (relative_assembly_path ) + 1 ; // +1 for '/'
113- size_t res = snprintf (full_path , path_len + 1 , "%s/%s" , g_bundle_path , relative_assembly_path );
114- if (res < 0 || res != path_len )
115- return false;
105+ size_t path_len = strlen (dir ) + strlen (name ) + 1 ;
106+ size_t res = snprintf (full_path , path_len + 1 , "%s/%s" , dir , name );
107+ if (res < 0 || res != path_len ) return false;
116108
117109 int fd = open (full_path , O_RDONLY );
118- if (fd == -1 )
119- return false;
110+ if (fd == -1 ) return false;
120111
121112 struct stat buf ;
122- if (fstat (fd , & buf ) == -1 )
123- {
124- close (fd );
125- return false;
126- }
113+ if (fstat (fd , & buf ) == -1 ) { close (fd ); return false; }
127114
128115 int64_t size_local = buf .st_size ;
129116 void * mapped = mmap (NULL , size_local , PROT_READ , MAP_PRIVATE , fd , 0 );
130- if (mapped == MAP_FAILED )
131- {
132- close (fd );
133- return false;
134- }
117+ if (mapped == MAP_FAILED ) { close (fd ); return false; }
135118
136- LOG_INFO ("Mapped %s -> %s" , relative_assembly_path , full_path );
137119 g_mapped_files [g_mapped_files_count ] = mapped ;
138120 g_mapped_file_sizes [g_mapped_files_count ] = size_local ;
139121 g_mapped_files_count ++ ;
140122 close (fd );
141123 * data = mapped ;
142124 * size = size_local ;
125+ LOG_INFO ("Mapped %s -> %s" , name , full_path );
143126 return true;
144127}
145128
129+ static bool
130+ external_assembly_probe (const char * relative_assembly_path , void * * data , int64_t * size )
131+ {
132+ if (g_mapped_files_count >= MAX_MAPPED_COUNT )
133+ {
134+ LOG_ERROR ("Too many mapped files, cannot map %s" , relative_assembly_path );
135+ return false;
136+ }
137+
138+ // 1) Try g_bundle_path (dotnet root)
139+ if (try_map_assembly (g_bundle_path , relative_assembly_path , data , size ))
140+ return true;
141+
142+ // 2) Try each APP_PATHS directory
143+ const char * app_paths = getenv ("APP_PATHS" );
144+ if (app_paths ) {
145+ char * paths = strdup (app_paths );
146+ char * tok = strtok (paths , ":" );
147+ while (tok ) {
148+ if (strcmp (tok , g_bundle_path ) != 0 && // skip g_bundle_path (already tried)
149+ try_map_assembly (tok , relative_assembly_path , data , size )) {
150+ free (paths );
151+ return true;
152+ }
153+ tok = strtok (NULL , ":" );
154+ }
155+ free (paths );
156+ }
157+
158+ return false;
159+ }
160+
146161static void
147162free_resources ()
148163{
0 commit comments