PR_ASSERT(_PR_TRI_UNKNOWN != fd->secret->inheritable);
_PR_MD_READ(PRFileDesc *fd, void *buf, PRInt32 len){    PRInt32 f = fd->secret->md.osfd;    PRUint32 bytes;    int rv, err;    LONG hiOffset = 0;    LONG loOffset;    PR_ASSERT(_PR_TRI_UNKNOWN != fd->secret->inheritable);    if (!fd->secret->md.sync_file_io) {        PRThread *me = _PR_MD_CURRENT_THREAD();        if (me->io_suspended) {            PR_SetError(PR_INVALID_STATE_ERROR, 0);            return -1;        }        memset(&(me->md.overlapped.overlapped), 0, sizeof(OVERLAPPED));        me->md.overlapped.overlapped.Offset = SetFilePointer((HANDLE)f, 0, &me->md.overlapped.overlapped.OffsetHigh, FILE_CURRENT);        PR_ASSERT((me->md.overlapped.overlapped.Offset != 0xffffffff) || (GetLastError() == NO_ERROR));        if (fd->secret->inheritable) {            rv = ReadFile((HANDLE)f,                           (LPVOID)buf,                           len,                           &bytes,                           &me->md.overlapped.overlapped);            if (rv != 0) {                loOffset = SetFilePointer((HANDLE)f, bytes, &hiOffset, FILE_CURRENT);                PR_ASSERT((loOffset != 0xffffffff) || (GetLastError() == NO_ERROR));                return bytes;            }            err = GetLastError();            if (err == ERROR_IO_PENDING) {                rv = GetOverlappedResult((HANDLE)f,                        &me->md.overlapped.overlapped, &bytes, TRUE);                if (rv != 0) {                    loOffset = SetFilePointer((HANDLE)f, bytes, &hiOffset, FILE_CURRENT);                    PR_ASSERT((loOffset != 0xffffffff) || (GetLastError() == NO_ERROR));                    return bytes;                }                err = GetLastError();            }            if (err == ERROR_HANDLE_EOF) {                return 0;            } else {                _PR_MD_MAP_READ_ERROR(err);                return -1;            }        } else {            if (!fd->secret->md.io_model_committed) {                rv = _md_Associate((HANDLE)f);                PR_ASSERT(rv != 0);                fd->secret->md.io_model_committed = PR_TRUE;            }			if (_native_threads_only)        		me->md.overlapped.overlapped.hEvent = me->md.thr_event;			_PR_THREAD_LOCK(me);			if (_PR_PENDING_INTERRUPT(me)) {				me->flags &= ~_PR_INTERRUPT;				PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);				_PR_THREAD_UNLOCK(me);				return -1;			}			me->io_pending = PR_TRUE;			me->state = _PR_IO_WAIT;			_PR_THREAD_UNLOCK(me);			me->io_fd = f;            rv = ReadFile((HANDLE)f,                           (LPVOID)buf,                           len,                           &bytes,                           &me->md.overlapped.overlapped);            if ( (rv == 0) && ((err = GetLastError()) != ERROR_IO_PENDING) ) {				_PR_THREAD_LOCK(me);				me->io_pending = PR_FALSE;				me->state = _PR_RUNNING;				if (_PR_PENDING_INTERRUPT(me)) {					me->flags &= ~_PR_INTERRUPT;					PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);					_PR_THREAD_UNLOCK(me);					return -1;				}				_PR_THREAD_UNLOCK(me);                if (err == ERROR_HANDLE_EOF) {                    return 0;                }                _PR_MD_MAP_READ_ERROR(err);                return -1;            }            if (_native_threads_only && rv) {                _native_thread_io_nowait(me, rv, bytes);            } else if (_NT_IO_WAIT(me, PR_INTERVAL_NO_TIMEOUT) == PR_FAILURE) {                PR_ASSERT(0);                return -1;            }            PR_ASSERT(me->io_pending == PR_FALSE || me->io_suspended == PR_TRUE);            if (me->io_suspended) {                if (_PR_PENDING_INTERRUPT(me)) {                    me->flags &= ~_PR_INTERRUPT;                    PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);                } else {                    PR_SetError(PR_IO_TIMEOUT_ERROR, 0);                }                return -1;            }            if (me->md.blocked_io_status == 0) {                if (me->md.blocked_io_error == ERROR_HANDLE_EOF) {                    return 0;                }                _PR_MD_MAP_READ_ERROR(me->md.blocked_io_error);                return -1;            }            SetFilePointer((HANDLE)f, me->md.blocked_io_bytes, 0, FILE_CURRENT);                PR_ASSERT(me->io_pending == PR_FALSE);            return me->md.blocked_io_bytes;        }    } else {        rv = ReadFile((HANDLE)f,                      (LPVOID)buf,                      len,                      &bytes,                      NULL);        if (rv == 0) {            err = GetLastError();            /* ERROR_HANDLE_EOF can only be returned by async io */            PR_ASSERT(err != ERROR_HANDLE_EOF);            if (err == ERROR_BROKEN_PIPE) {                /* The write end of the pipe has been closed. */                 return 0;            }            _PR_MD_MAP_READ_ERROR(err);            return -1;        }        return bytes;    }}