88#include <sys/stat.h>
99#include <fcntl.h>
1010#include <unistd.h>
11+ #include <errno.h>
1112
1213#include "memory.h"
1314#include "vmpl.h"
@@ -212,6 +213,7 @@ char* invoke_trustlet(const int trustlet_id, char* args, uint64_t output_size){
212213 struct guest_request_args * arg = invoke_data -> guest_request_args .ptr ;
213214 int fd = arg -> read2 .fd ;
214215 uint64_t read_size = arg -> read2 .count ;
216+ debug_printf ("read2: fd=%d, offset=%ld, count=%lu\n" , fd , arg -> read2 .offset , read_size );
215217 if (!read_buffer ) {
216218 read_buffer = aligned_alloc (4096 , read_size );
217219 if (!read_buffer ) {
@@ -229,6 +231,11 @@ char* invoke_trustlet(const int trustlet_id, char* args, uint64_t output_size){
229231 read_buffer_size = read_size ;
230232 }
231233 int read_bytes = pread (fd , read_buffer , read_size , arg -> read2 .offset );
234+ if (read_bytes == -1 ) {
235+ fprintf (stderr , "Failed to read file!: errno=%d\n" , errno );
236+ int is_fd_valid = fcntl (fd , F_GETFD ) != -1 || errno != EBADF ;
237+ fprintf (stderr , "fd=%d (valid=%d), read_buffer=%p, read_size=%lu, offset=%ld\n" , fd , is_fd_valid , read_buffer , read_size , arg -> read2 .offset );
238+ }
232239 arg -> read2 .ptr = (uint64_t )read_buffer ;
233240 arg -> read2 .bufsize = read_size ;
234241 arg -> read2 .count = read_bytes ;
@@ -258,8 +265,10 @@ char* invoke_trustlet(const int trustlet_id, char* args, uint64_t output_size){
258265exit :
259266
260267 free (mmap_read_buffer );
261- if (read_buffer )
268+ if (read_buffer ) {
262269 free (read_buffer );
270+ read_buffer = NULL ;
271+ }
263272 return return_buffer_address ;
264273}
265274
0 commit comments