#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);
}
|