3 Copyright 2006 Red Hat, Inc.
5 This file is part of Cygwin.
7 This software is a copyrighted work licensed under the terms of the
8 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
11 #ifndef _MMAP_HELPER_H
12 #define _MMAP_HELPER_H
13 #define _MMIOWRAP(__ptr, __len, __func) \
16 for (int __i = 0; __i < 2; __i++) \
19 if (__res || __i > 0) \
21 DWORD __errcode = GetLastError (); \
22 if (__errcode != ERROR_NOACCESS) \
24 switch (mmap_is_attached_or_noreserve (__ptr, __len)) \
26 case MMAP_NORESERVE_COMMITED: \
28 case MMAP_RAISE_SIGBUS: \
38 #define _MMSOCKWRAP(__ptr, __count, __func) \
41 for (int __i = 0; __i < 2; __i++) \
44 if (!__res || __i > 0) \
46 DWORD __errcode = WSAGetLastError (); \
47 if (__errcode != WSAEFAULT) \
49 for (unsigned __j = 0; __j < __count; __j++) \
50 switch (mmap_is_attached_or_noreserve (__ptr[__j].buf, __ptr[__j].len)) \
52 case MMAP_NORESERVE_COMMITED: \
54 case MMAP_RAISE_SIGBUS: \
67 mmReadFile (HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
68 LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped)
70 return _MMIOWRAP (lpBuffer, nNumberOfBytesToRead,
71 (ReadFile (hFile, lpBuffer, nNumberOfBytesToRead,
72 lpNumberOfBytesRead, lpOverlapped)));
77 mmWSARecvFrom (SOCKET s, LPWSABUF lpBuffers, DWORD dwBufferCount,
78 LPDWORD lpNumberOfBytesRecvd, LPDWORD lpFlags,
79 struct sockaddr* lpFrom,
80 LPINT lpFromlen, LPWSAOVERLAPPED lpOverlapped,
81 LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
83 return _MMSOCKWRAP (lpBuffers, dwBufferCount,
84 (mmWSARecvFrom(s, lpBuffers, dwBufferCount,
85 lpNumberOfBytesRecvd, lpFlags, lpFrom,
86 lpFromlen, lpOverlapped,
87 lpCompletionRoutine)));
91 #endif /*_MMAP_HELPER_H*/