Index: trunk/openjdk/jdk/src/windows/hpi/src/sys_api_md.c
===================================================================
--- trunk/openjdk/jdk/src/windows/hpi/src/sys_api_md.c	(revision 37)
+++ trunk/openjdk/jdk/src/windows/hpi/src/sys_api_md.c	(revision 38)
@@ -32,4 +32,18 @@
 #include <limits.h>
 
+#ifdef __EMX__
+
+#ifdef __WIN32OS2__
+#include <os2wrap2.h>
+#endif
+#include <windows.h>
+#include <wincon.h>
+
+#define _stati64 stat
+#define _fstati64 fstat
+#define _lseeki64 lseek
+
+#endif /* EMX */
+
 #include "hpi_impl.h"
 
@@ -97,4 +111,17 @@
      *
      */
+#ifdef __WIN32OS2__
+    os2_AVAILDATA avail = { 0, 0 };
+    os2_ULONG pipeState;
+    os2_APIRET arc = DosPeekNPipe(0, NULL, 0, NULL, &avail, &pipeState);
+    // note that even if ERROR_INVALID_PARAMETER, it seems to return the
+    // correct values in avail and state (undocumented)
+    if (arc != NO_ERROR && arc != ERROR_INVALID_PARAMETER) {
+        *pbytes = avail.cbpipe;
+        return TRUE;
+    }
+
+    return FALSE;
+#else
     HANDLE han;
 
@@ -116,4 +143,5 @@
     }
     return TRUE;
+#endif
 }
 
@@ -183,4 +211,7 @@
 int
 sysSync(int fd) {
+#ifdef __EMX__
+    return fsync(fd);
+#else /* __EMX__ */
     /*
      * From the documentation:
@@ -208,4 +239,5 @@
     }
     return 0;
+#endif /* __EMX__ */
 }
 
@@ -213,4 +245,7 @@
 int
 sysSetLength(int fd, jlong length) {
+#ifdef __EMX__
+    return ftruncate(fd, length);
+#else /* __EMX__ */
     HANDLE h = (HANDLE)_get_osfhandle(fd);
     long high = (long)(length >> 32);
@@ -224,4 +259,5 @@
     if (SetEndOfFile(h) == FALSE) return -1;
     return 0;
+#endif /* __EMX__ */
 }
 
@@ -236,4 +272,5 @@
     (*size) = buf64.st_size;
 
+#ifndef __EMX__
     if (*size & 0xFFFFFFFF00000000) {
         /*
@@ -266,4 +303,5 @@
 
     }
+#endif /* !__EMX__ */
     return 0;
 }
Index: trunk/openjdk/jdk/src/windows/hpi/src/system_md.c
===================================================================
--- trunk/openjdk/jdk/src/windows/hpi/src/system_md.c	(revision 37)
+++ trunk/openjdk/jdk/src/windows/hpi/src/system_md.c	(revision 38)
@@ -29,4 +29,9 @@
 #include <time.h>               /* For _tzset() and _ftime() */
 #include <errno.h>
+
+#ifdef __EMX__
+#include <io.h>
+#include <memory.h>
+#endif /* __EMX__ */
 
 #include "hpi_impl.h"
@@ -109,5 +114,9 @@
      * to, but by doing this here we ensure other dll's don't override.
      */
+#ifdef __EMX__
+    _control87(MCW_EM | RC_NEAR | PC_53, MCW_EM | MCW_RC | MCW_PC);
+#else
     _control87(_MCW_EM | _RC_NEAR | _PC_53, _MCW_EM | _MCW_RC | _MCW_PC);
+#endif /* __EMX__ */
 
     InitializeMem();
Index: trunk/openjdk/jdk/src/windows/hpi/src/threads_md.c
===================================================================
--- trunk/openjdk/jdk/src/windows/hpi/src/threads_md.c	(revision 37)
+++ trunk/openjdk/jdk/src/windows/hpi/src/threads_md.c	(revision 38)
@@ -68,8 +68,14 @@
 #ifndef _WIN64
     PNT_TIB nt_tib;
+#ifdef __EMX__
+    asm("movl %%fs:0x18, %%eax\n\t"
+        "mov %%eax, %0\n\t"
+        : "=m" (nt_tib) : : "%eax");
+#else /* __EMX__ */
     __asm {
         mov eax, dword ptr fs:[18h];
         mov nt_tib, eax;
     }
+#endif /* __EMX__ */
     tid->nt_tib = nt_tib;
 #else
@@ -216,8 +222,14 @@
     }
 
+#ifdef __EMX__
+    asm("mov %%ss, %%ax\n\t"
+        "mov %%ax, %0\n\t"
+        : "=m" (__current_SS) : : "%ax");
+#else /* __EMX__ */
     __asm {
         mov ax, ss;
         mov __current_SS, ax;
     }
+#endif /* __EMX__ */
 
     if (context.SegSs == __current_SS &&
@@ -317,5 +329,10 @@
     tid->start_proc(tid->start_parm);
     sysThreadFree();
+#ifdef __EMX__
+    // @todo probably need to cause some per-thread LIBC termination routine
+    ExitThread(0);
+#else /* __EMX__ */
     _endthreadex(0);
+#endif /* __EMX__ */
     /* not reached */
     return 0;
@@ -342,6 +359,13 @@
      * Start the new thread.
      */
+#ifdef __EMX__
+    // @todo probably need to cause some per-thread LIBC initialization routine
+    tid->handle = CreateThread(NULL, stack_size, (LPTHREAD_START_ROUTINE)_start,
+                               tid, CREATE_SUSPENDED, (LPDWORD)&tid->id);
+
+#else /* __EMX__ */
     tid->handle = (HANDLE)_beginthreadex(NULL, stack_size, _start, tid,
                                          CREATE_SUSPENDED, &tid->id);
+#endif /* __EMX__ */
     if (tid->handle == 0) {
         return SYS_NORESOURCE;  /* Will be treated as though SYS_NOMEM */
