2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
5 Desc: Host-side hepler code for Windows emul.handler
9 #define _WIN32_IE 0x0500
16 #include "emul_host.h"
18 #define DWINAPI(x) /* WinAPI calls debug */
19 #define DASYNC(x) /* Asynchronous I/O thread debug */
22 void (*CauseIRQ
)(unsigned char irq
, void *data
);
24 /*********************************************************************************************/
26 unsigned long __declspec(dllexport
) __aros
EmulGetHome(const char *name
, char *home
)
30 /* TODO: currently username is ignored, however we should acquire an access token for it */
31 DWINAPI(printf("[EmulHandler] SHGetFolderPath()\n"));
33 res
= SHGetFolderPath(NULL
, CSIDL_PERSONAL
, NULL
, SHGFP_TYPE_DEFAULT
, home
);
34 return res
? ERROR_FILE_NOT_FOUND
: 0;
37 static DWORD WINAPI
EmulThread(struct AsyncReaderControl
*emsg
)
41 DASYNC(printf("[EmulHandler I/O] Thread started, handle 0x%08lX, host handle 0x%08lX, host ID %lu\n", THandle
, THandle
->handle
, THandle
->id
));
44 WaitForSingleObject(emsg
->CmdEvent
, INFINITE
);
45 DASYNC(printf("[EmulHandler I/O] Got command: 0xu\n", emsg
->cmd
));
48 case ASYNC_CMD_SHUTDOWN
:
49 DASYNC(printf("[EmulHandler I/O] shutting down thread\n"));
53 DASYNC(printf("[EmulHandler I/O] READ %lu bytes at 0x%p, file 0x%p\n", emsg
->len
, emsg
->addr
, emsg
->fh
));
55 res
= ReadFile(emsg
->fh
, emsg
->addr
, emsg
->len
, &actual
, NULL
);
56 emsg
->actual
= actual
;
57 emsg
->error
= res
? 0 : GetLastError();
58 DASYNC(printf("[EmulHandler I/O] %lu bytes transferred, result %ld, error %lu\n", emsg
->actual
, res
, emsg
->error
));
59 KrnCauseSystemIRQ(emsg
->IrqNum
);
64 struct AsyncReaderControl ControlStruct
;
66 struct AsyncReaderControl
* __declspec(dllexport
) __aros
Emul_Init_Native(void)
72 irq
= KrnAllocSystemIRQ();
75 ControlStruct
.IrqNum
= irq
;
76 ControlStruct
.CmdEvent
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
77 if (ControlStruct
.CmdEvent
)
79 thread
= CreateThread(NULL
, 0, (LPTHREAD_START_ROUTINE
)EmulThread
, &ControlStruct
, 0, &id
);
83 return &ControlStruct
;
85 CloseHandle(ControlStruct
.CmdEvent
);