diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2014-02-08 03:50:41 +0100 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2014-02-08 03:50:41 +0100 |
commit | 6b146c70c2863bf1e9d5c4a35cbd8426c5a161e7 (patch) | |
tree | 0c683fb3d4ab300d91acfe33415974a152212ab4 /sys/src/libmach | |
parent | 43212f64320c2e136eb3d4adb5d3e8c31c637386 (diff) |
pc64: handle negative file offsets when accessing kernel memory with devproc
file offset is 64 bit signed integer, negative offsets
are invalid and rejected by the kernel. to still access
kernel memory on amd64, we unconditionally clear the sign
bit of the 64 bit offset in libmach and devproc sign
extends the offset back to a 64 bit address.
Diffstat (limited to 'sys/src/libmach')
-rw-r--r-- | sys/src/libmach/access.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/sys/src/libmach/access.c b/sys/src/libmach/access.c index 784ee6158..6d8ed1f3e 100644 --- a/sys/src/libmach/access.c +++ b/sys/src/libmach/access.c @@ -263,7 +263,17 @@ reloc(Map *map, uvlong addr, vlong *offp) for (i = 0; i < map->nsegs; i++) { if (map->seg[i].inuse) if (map->seg[i].b <= addr && addr < map->seg[i].e) { - *offp = addr + map->seg[i].f - map->seg[i].b; + addr += map->seg[i].f - map->seg[i].b; + + /* + * avoid negative file offsets for kernel + * addresses by clearing the sign bit. + * devproc sign extends back to 64 bit. + */ + addr <<= 1; + addr >>= 1; + + *offp = addr; return &map->seg[i]; } } |