4 * Copyright 1998 Ove Kåven
9 /* apparently ELF images are usually loaded high anyway */
11 /* if not, force dosmod at high addresses */
25 #include <sys/types.h>
26 #include <sys/ptrace.h>
29 /* FIXME: hack because libc vm86 may be the old syscall version */
33 static __inline__
int vm86plus( int func
, struct vm86plus_struct
*ptr
)
37 __asm__
__volatile__( "pushl %%ebx\n\t"
46 __asm__
__volatile__("int $0x80"
52 if (res
>= 0) return res
;
57 int main(int argc
,char**argv
)
59 int mfd
=open(argv
[0],O_RDWR
);
61 struct vm86plus_struct VM86
;
66 /* fprintf(stderr,"main is at %08lx, file is %s, fd=%d\n",(unsigned long)&main,argv[0],mfd); */
68 /* Map in our DOS image at the start of the process address space */
70 /* Ulrich Weigand suggested mapping in the DOS image directly from the Wine
73 /* linux currently only allows mapping a process memory if it's being ptraced */
74 /* Linus doesn't like it, so this probably won't work in the future */
75 /* it doesn't even work for me right now */
76 ptrace(PTRACE_ATTACH
,ppid
,0,0);
80 img
=mmap(NULL
,0x110000,PROT_EXEC
|PROT_READ
|PROT_WRITE
,MAP_FIXED
|MAP_SHARED
,mfd
,fofs
);
82 ptrace(PTRACE_DETACH
,ppid
,0,0);
86 fprintf(stderr
,"DOS memory map failed, error=%s\n",strerror(errno
));
87 fprintf(stderr
,"in attempt to map %s, offset %08lX, length 110000, to offset 0\n",argv
[0],fofs
);
90 /* fprintf(stderr,"Successfully mapped DOS memory, entering vm86 loop\n"); */
91 /* report back to the main program that we're ready */
93 write(1,&ret
,sizeof(ret
));
94 /* context exchange loop */
96 if (read(0,&func
,sizeof(func
))!=sizeof(func
)) return 1;
97 if (read(0,&VM86
,sizeof(VM86
))!=sizeof(VM86
)) return 1;
99 ret
=vm86plus(func
,&VM86
);
100 if (write(1,&ret
,sizeof(ret
))!=sizeof(ret
)) return 1;
101 if (write(1,&VM86
,sizeof(VM86
))!=sizeof(VM86
)) return 1;
107 int main(void) {return 1;}