Plan 9 from Bell Labs’s /usr/web/sources/contrib/rsc/linuxemu/elfdump.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include <u.h>
#include <libc.h>
#include "linux.h"

void *bss;
int debug;
/*
 * crummy mmap.  should be handled by kernel.
 */
static void*
mmap(int fd)
{
	void *v;
	Dir *d;

	d = dirfstat(fd);
	if(d->length == 0)
		return nil;
	v = malloc(d->length);
	if(v == nil)
		return nil;

	if(readn(fd, v, d->length) != d->length) {
		free(v);
		return nil;
	}
	return v;
}

void
main(int argc, char **argv)
{
	char *argv0 = argv[0];
	int fd;
	long entry = 0;
	void *file;

	if(argc > 1 && strcmp(argv[1], "-d") == 0)
		debug++, argc--, argv++;

	if(argc < 2) {
		fprint(2, "usage: %s [-d] linuxprog args...\n", argv0);
		exits("usage");
	}

	if((fd = open(argv[1], OREAD)) < 0) {
		fprint(2, "open fails: %r\n");
		exits("open");
	}

	if((file = mmap(fd)) == nil) {
		fprint(2, "mmap failed: %r\n");
		exits("mmap");
	}
	elfdump(file);
}


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].