-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathfake_fstat64.cc
33 lines (31 loc) · 1.02 KB
/
fake_fstat64.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "fake_fstat64.h"
#include "syscall_ext.h"
#include "hook_info.h"
#include "ashmem_utils.h"
EXPORT int fake_fstat64(int fd, kernel_stat64_compat* buf) {
auto* info = (HookInfo*) get_hook_info();
#if defined(__LP64__)
struct kernel_stat* stat = buf;
const int NR_fstat = __NR_fstat;
#else
struct kernel_stat64* stat = buf;
const int NR_fstat = __NR_fstat64;
#endif
uintptr_t res = syscall_ext(NR_fstat, fd, (uintptr_t) stat, 0, 0, 0, 0);
if (is_error(res)) {
// set errno and return -1
int* the_errno = info->fn_dl_errno();
*the_errno = -(int) (ssize_t) res;
return -1;
}
// check if the fd is an ashmem fd
if (stat->st_dev == info->ashmem_dev_v && info->ashmem_dev_v != 0 && stat->st_size == 0) {
// fake the stat.st_size with ashmem size
ssize_t ssize = ashmem_dev_get_size_region(fd);
if (!is_error(ssize)) {
// overwrite the st_size
stat->st_size = (kernel_off_t) (size_t) ssize;
}
}
return 0;
}