summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2014-06-17 14:37:06 -0700
committerColin Cross <ccross@android.com>2014-06-17 14:50:25 -0700
commite2998ffe6f494f06b25aca372c1d35cd47390b98 (patch)
treef8186653a95d89214ca10cfa2f3a0d8a19c7abec
parentd6c0e17d4fc53db1d123134866d8ec610288221a (diff)
downloadextras-e2998ffe6f494f06b25aca372c1d35cd47390b98.tar.gz
libpagemap: support 64-bit kernel from 32-bit libpagemap
Use uint64_t and lseek64 to handle 64-bit virtual addresses when libpagemap is compiled as a 32-bit library. Change-Id: Ie4b6c7ef05aac604011f3ee28b059d9dfcd63edb
-rw-r--r--libpagemap/include/pagemap/pagemap.h12
-rw-r--r--libpagemap/pm_kernel.c12
-rw-r--r--libpagemap/pm_process.c12
3 files changed, 19 insertions, 17 deletions
diff --git a/libpagemap/include/pagemap/pagemap.h b/libpagemap/include/pagemap/pagemap.h
index 210bc815..9063b1e1 100644
--- a/libpagemap/include/pagemap/pagemap.h
+++ b/libpagemap/include/pagemap/pagemap.h
@@ -71,9 +71,9 @@ struct pm_process {
struct pm_map {
pm_process_t *proc;
- unsigned long start;
- unsigned long end;
- unsigned long offset;
+ uint64_t start;
+ uint64_t end;
+ uint64_t offset;
int flags;
char *name;
@@ -91,11 +91,11 @@ int pm_kernel_pids(pm_kernel_t *ker, pid_t **pids_out, size_t *len);
/* Get the map count (from /proc/kpagecount) of a physical frame.
* The count is returned through *count_out. */
-int pm_kernel_count(pm_kernel_t *ker, unsigned long pfn, uint64_t *count_out);
+int pm_kernel_count(pm_kernel_t *ker, uint64_t pfn, uint64_t *count_out);
/* Get the page flags (from /proc/kpageflags) of a physical frame.
* The count is returned through *flags_out. */
-int pm_kernel_flags(pm_kernel_t *ker, unsigned long pfn, uint64_t *flags_out);
+int pm_kernel_flags(pm_kernel_t *ker, uint64_t pfn, uint64_t *flags_out);
#define PM_PAGE_LOCKED (1 << 0)
#define PM_PAGE_ERROR (1 << 1)
@@ -153,7 +153,7 @@ int pm_process_workingset(pm_process_t *proc, pm_memusage_t *ws_out, int reset);
* The array of PFNs is returned through *range_out, and the caller has the
* responsibility to free it. */
int pm_process_pagemap_range(pm_process_t *proc,
- unsigned long low, unsigned long hi,
+ uint64_t low, uint64_t hi,
uint64_t **range_out, size_t *len);
#define _BITS(x, offset, bits) (((x) >> offset) & ((1LL << (bits)) - 1))
diff --git a/libpagemap/pm_kernel.c b/libpagemap/pm_kernel.c
index 3615f1ac..b9e4e698 100644
--- a/libpagemap/pm_kernel.c
+++ b/libpagemap/pm_kernel.c
@@ -113,13 +113,13 @@ int pm_kernel_pids(pm_kernel_t *ker, pid_t **pids_out, size_t *len) {
return 0;
}
-int pm_kernel_count(pm_kernel_t *ker, unsigned long pfn, uint64_t *count_out) {
- off_t off;
+int pm_kernel_count(pm_kernel_t *ker, uint64_t pfn, uint64_t *count_out) {
+ off64_t off;
if (!ker || !count_out)
return -1;
- off = lseek(ker->kpagecount_fd, pfn * sizeof(uint64_t), SEEK_SET);
+ off = lseek64(ker->kpagecount_fd, pfn * sizeof(uint64_t), SEEK_SET);
if (off == (off_t)-1)
return errno;
if (read(ker->kpagecount_fd, count_out, sizeof(uint64_t)) <
@@ -129,13 +129,13 @@ int pm_kernel_count(pm_kernel_t *ker, unsigned long pfn, uint64_t *count_out) {
return 0;
}
-int pm_kernel_flags(pm_kernel_t *ker, unsigned long pfn, uint64_t *flags_out) {
- off_t off;
+int pm_kernel_flags(pm_kernel_t *ker, uint64_t pfn, uint64_t *flags_out) {
+ off64_t off;
if (!ker || !flags_out)
return -1;
- off = lseek(ker->kpageflags_fd, pfn * sizeof(uint64_t), SEEK_SET);
+ off = lseek64(ker->kpageflags_fd, pfn * sizeof(uint64_t), SEEK_SET);
if (off == (off_t)-1)
return errno;
if (read(ker->kpageflags_fd, flags_out, sizeof(uint64_t)) <
diff --git a/libpagemap/pm_process.c b/libpagemap/pm_process.c
index e68263c6..50791ef9 100644
--- a/libpagemap/pm_process.c
+++ b/libpagemap/pm_process.c
@@ -16,6 +16,7 @@
#include <errno.h>
#include <fcntl.h>
+#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -100,11 +101,12 @@ int pm_process_usage(pm_process_t *proc, pm_memusage_t *usage_out) {
}
int pm_process_pagemap_range(pm_process_t *proc,
- unsigned long low, unsigned long high,
+ uint64_t low, uint64_t high,
uint64_t **range_out, size_t *len) {
- unsigned long firstpage, numpages;
+ uint64_t firstpage;
+ uint64_t numpages;
uint64_t *range;
- off_t off;
+ off64_t off;
int error;
if (!proc || (low > high) || !range_out || !len)
@@ -123,7 +125,7 @@ int pm_process_pagemap_range(pm_process_t *proc,
if (!range)
return errno;
- off = lseek(proc->pagemap_fd, firstpage * sizeof(uint64_t), SEEK_SET);
+ off = lseek64(proc->pagemap_fd, firstpage * sizeof(uint64_t), SEEK_SET);
if (off == (off_t)-1) {
error = errno;
free(range);
@@ -281,7 +283,7 @@ static int read_maps(pm_process_t *proc) {
map->proc = proc;
name[0] = '\0';
- sscanf(line, "%lx-%lx %s %lx %*s %*d %" S(MAX_LINE) "s",
+ sscanf(line, "%" SCNx64 "-%" SCNx64 " %s %" SCNx64 " %*s %*d %" S(MAX_LINE) "s",
&map->start, &map->end, perms, &map->offset, name);
map->name = malloc(strlen(name) + 1);