88 * segments, and copies them into guest memory.
99 */
1010
11+ #include <stdbool.h>
1112#include <stdio.h>
1213#include <stdlib.h>
1314#include <string.h>
1920#include "debug/log.h"
2021#include "utils.h"
2122
22- int elf_load (const char * path , elf_info_t * info )
23+ static int elf_load_impl (const char * path , elf_info_t * info , bool quiet )
2324{
2425 memset (info , 0 , sizeof (* info ));
2526
2627 FILE * f = fopen (path , "rb" );
2728 if (!f ) {
28- perror (path );
29+ if (!quiet )
30+ perror (path );
2931 return -1 ;
3032 }
3133
3234 elf64_ehdr_t ehdr ;
3335 if (fread (& ehdr , sizeof (ehdr ), 1 , f ) != 1 ) {
34- log_error ("%s: failed to read ELF header" , path );
36+ if (!quiet )
37+ log_error ("%s: failed to read ELF header" , path );
3538 fclose (f );
3639 return -1 ;
3740 }
3841
3942 /* Reject non-ELF inputs before interpreting the rest of the header. */
4043 if (ehdr .e_ident [0 ] != ELFMAG0 || ehdr .e_ident [1 ] != ELFMAG1 ||
4144 ehdr .e_ident [2 ] != ELFMAG2 || ehdr .e_ident [3 ] != ELFMAG3 ) {
42- log_error ("%s: not an ELF file" , path );
45+ if (!quiet )
46+ log_error ("%s: not an ELF file" , path );
4347 fclose (f );
4448 return -1 ;
4549 }
4650
4751 /* elfuse only implements the 64-bit Linux ABI. */
4852 if (ehdr .e_ident [EI_CLASS ] != ELFCLASS64 ) {
49- log_error ("%s: not a 64-bit ELF" , path );
53+ if (!quiet )
54+ log_error ("%s: not a 64-bit ELF" , path );
5055 fclose (f );
5156 return -1 ;
5257 }
5358
5459 /* aarch64-linux user binaries are little-endian in the supported mode. */
5560 if (ehdr .e_ident [EI_DATA ] != ELFDATA2LSB ) {
56- log_error ("%s: not little-endian" , path );
61+ if (!quiet )
62+ log_error ("%s: not little-endian" , path );
5763 fclose (f );
5864 return -1 ;
5965 }
@@ -62,8 +68,9 @@ int elf_load(const char *path, elf_info_t *info)
6268 * diagnostic instead of a generic parse failure.
6369 */
6470 if (ehdr .e_machine != EM_AARCH64 && ehdr .e_machine != EM_X86_64 ) {
65- log_error ("%s: unsupported architecture (e_machine=%u)" , path ,
66- ehdr .e_machine );
71+ if (!quiet )
72+ log_error ("%s: unsupported architecture (e_machine=%u)" , path ,
73+ ehdr .e_machine );
6774 fclose (f );
6875 return -1 ;
6976 }
@@ -72,7 +79,8 @@ int elf_load(const char *path, elf_info_t *info)
7279 * the load base that keeps them away from elfuse's reserved regions.
7380 */
7481 if (ehdr .e_type != ET_EXEC && ehdr .e_type != ET_DYN ) {
75- log_error ("%s: not an executable (e_type=%u)" , path , ehdr .e_type );
82+ if (!quiet )
83+ log_error ("%s: not an executable (e_type=%u)" , path , ehdr .e_type );
7684 fclose (f );
7785 return -1 ;
7886 }
@@ -204,6 +212,16 @@ int elf_load(const char *path, elf_info_t *info)
204212 return 0 ;
205213}
206214
215+ int elf_load (const char * path , elf_info_t * info )
216+ {
217+ return elf_load_impl (path , info , false);
218+ }
219+
220+ int elf_load_quiet (const char * path , elf_info_t * info )
221+ {
222+ return elf_load_impl (path , info , true);
223+ }
224+
207225int elf_map_segments (const elf_info_t * info ,
208226 const char * path ,
209227 void * guest_base ,
0 commit comments