shithub: riscv

Download patch

ref: 6104ebc9b6f1805a827c0a2acae8978a3fa33603
parent: 721160290f138f087d199ab79875eae3de5e61fc
author: aiju <devnull@localhost>
date: Thu Aug 24 09:02:27 EDT 2017

libmach: support disassembling from memory

--- a/sys/include/mach.h
+++ b/sys/include/mach.h
@@ -130,6 +130,7 @@
 	struct segment {		/* per-segment map */
 		char	*name;		/* the segment name */
 		int	fd;		/* file descriptor */
+		long	(*read)(int, void *, long, vlong);
 		int	inuse;		/* in use - not in use */
 		int	cache;		/* should cache reads? */
 		uvlong	b;		/* base */
--- a/sys/src/libmach/access.c
+++ b/sys/src/libmach/access.c
@@ -42,7 +42,7 @@
 		return -1;
 	}
 
-	if (map->nsegs == 1 && map->seg[0].fd < 0) {
+	if (map->nsegs == 1 && map->seg[0].fd < 0 && map->seg[0].read == nil) {
 		*x = addr;
 		return 1;
 	}
@@ -60,7 +60,7 @@
 		return -1;
 	}
 
-	if (map->nsegs == 1 && map->seg[0].fd < 0) {
+	if (map->nsegs == 1 && map->seg[0].fd < 0 && map->seg[0].read == nil) {
 		*x = addr;
 		return 1;
 	}
@@ -78,7 +78,7 @@
 		return -1;
 	}
 
-	if (map->nsegs == 1 && map->seg[0].fd < 0) {
+	if (map->nsegs == 1 && map->seg[0].fd < 0 && map->seg[0].read == nil) {
 		*x = addr;
 		return 1;
 	}
@@ -98,7 +98,7 @@
 		return -1;
 	}
 
-	if (map->nsegs == 1 && map->seg[0].fd < 0) {
+	if (map->nsegs == 1 && map->seg[0].fd < 0 && map->seg[0].read == nil) {
 		cp = (uchar*)&addr;
 		while (cp < (uchar*)(&addr+1) && size-- > 0)
 			*x++ = *cp++;
@@ -171,6 +171,9 @@
 		char a[8192];
 		uvlong off;
 	} cache;
+	
+	if(s->read != nil)
+		return s->read(s->fd, buf, n, off);
 
 	if(s->cache){
 		base = off&~(sizeof cache.a-1);
@@ -204,7 +207,7 @@
 	s = reloc(map, addr, (vlong*)&off);
 	if (!s)
 		return -1;
-	if (s->fd < 0) {
+	if (s->fd < 0 && s->read == nil) {
 		werrstr("unreadable map");
 		return -1;
 	}