Skip to content

Commit

Permalink
vkreplay: Fix issues replaying 32-bit large file
Browse files Browse the repository at this point in the history
On 32-bit Linux/Android, fseek and ftell only works well for trace file
smaller than 2GB which will cause problem when geting file length and
using portability table on a large trace file.

This change fixes the issue by:

* x86 version:
** Use fseeko and ftello instead of fseek and ftell.
"-D_FILE_OFFSET_BITS=64" has been defined in vktrace's CMakeList.txt to
make those functions support large file.

* 32-bit Android version:
** Implement vktrace_fseek and vktrace_ftell using lseek64 which is
available in NDK.

For the NDK problem of using fseeko and ftello, refer to
android/ndk#480
  • Loading branch information
Justus Wang committed Jul 17, 2018
1 parent e3cd939 commit c2f6e35
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
7 changes: 5 additions & 2 deletions vktrace/vktrace_common/vktrace_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,12 @@ static const uint32_t INVALID_BINDING_INDEX = UINT32_MAX;
#if defined(WIN32)
#define Ftell _ftelli64
#define Fseek _fseeki64
#elif defined(ANDROID)
#define Ftell vktrace_ftell
#define Fseek vktrace_fseek
#else
#define Ftell ftell
#define Fseek fseek
#define Ftell ftello
#define Fseek fseeko
#endif

// Enviroment variables used by vktrace/replay
Expand Down
26 changes: 26 additions & 0 deletions vktrace/vktrace_common/vktrace_platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,3 +498,29 @@ BOOL vktrace_platform_remote_load_library(vktrace_process_handle pProcessHandle,

return TRUE;
}

#if defined(ANDROID)
int vktrace_fseek(FILE* stream, int64_t offset, int whence) {
if (sizeof(void*) == 8) {
// use native fseek on 64 bit Android
return fseek(stream, offset, whence);
} else {
// disable buffering
setbuf(stream, NULL);
if (lseek64(fileno(stream), offset, whence) == -1) {
return -1;
}
return 0;
}
}
int64_t vktrace_ftell(FILE* stream) {
if (sizeof(void*) == 8) {
// use native ftell on 64 bit Android
return ftell(stream);
} else {
// disable buffering
setbuf(stream, NULL);
return lseek64(fileno(stream), 0L, SEEK_CUR);
}
}
#endif
6 changes: 6 additions & 0 deletions vktrace/vktrace_common/vktrace_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ void vktrace_delete_critical_section(VKTRACE_CRITICAL_SECTION* pCriticalSection)
BOOL vktrace_platform_remote_load_library(vktrace_process_handle pProcessHandle, const char* dllPath,
vktrace_thread* pTracingThread, char** ldPreload);

#if defined(ANDROID)
#include <stdio.h>
int vktrace_fseek(FILE* stream, int64_t offset, int whence);
int64_t vktrace_ftell(FILE* stream);
#endif

#if defined(__cplusplus)
}
#endif

0 comments on commit c2f6e35

Please sign in to comment.