6 #if not HAS_MSG_DONTWAIT
7 #include "recv.nonblock.c"
13 * The sysconf(_SC_PAGESIZE) is the necessary alignment for using
14 * mmap. Windows has another notion of page size (that corresponds to
15 * physical page size?). Just to be safe, we take the least common
16 * multiple of the sysconf and Windows notions of page size.
18 * Since sysconf(_SC_PAGESIZE) might not correspond to the physical
19 * page size, we can't use sysconf(_SC_PHYS_PAGES) to get physical
20 * memory. So, use the Windows function.
22 * See: http://cygwin.com/ml/cygwin/2006-06/msg00341.html
24 static size_t GC_pageSize_sysconf (void) {
28 pageSize
= sysconf (_SC_PAGESIZE
);
29 GetSystemInfo(&sysinfo
);
31 /* MLton_Platform_CygwinUseMmap is not set when this is called.
32 * Assume the worst; choose the larger allocation unit.
34 if ((size_t)pageSize
< (size_t)sysinfo
.dwAllocationGranularity
)
35 return (size_t)sysinfo
.dwAllocationGranularity
;
37 return (size_t)pageSize
;
40 static size_t GC_pageSize_windows (void) {
42 GetSystemInfo(&sysinfo
);
43 return (size_t)sysinfo
.dwPageSize
;
46 size_t GC_pageSize (void) {
47 size_t pageSize_sysconf
= GC_pageSize_sysconf ();
48 size_t pageSize_windows
= GC_pageSize_windows ();
50 size_t a
= pageSize_sysconf
;
51 size_t b
= pageSize_windows
;
60 size_t lcm
= (pageSize_sysconf
/ gcd
) * pageSize_windows
;
65 uintmax_t GC_physMem (void) {
68 memstat
.dwLength
= sizeof(memstat
);
69 GlobalMemoryStatus(&memstat
);
70 return (uintmax_t)memstat
.dwTotalPhys
;
73 void *GC_mmapAnon (void *start
, size_t length
) {
74 if (MLton_Platform_CygwinUseMmap
)
75 return mmapAnon (start
, length
);
77 return Windows_mmapAnon (start
, length
);
80 void GC_release (void *base
, size_t length
) {
81 if (MLton_Platform_CygwinUseMmap
)
82 munmap_safe (base
, length
);
84 Windows_release (base
, length
);
87 void* GC_extendHead (void *base
, size_t length
) {
88 if (MLton_Platform_CygwinUseMmap
)
89 return mmapAnon (base
, length
);
91 return Windows_mmapAnon (base
, length
);
94 void* GC_extendTail (void *base
, size_t length
) {
95 if (MLton_Platform_CygwinUseMmap
)
96 return mmapAnon (base
, length
);
98 return Windows_extend (base
, length
);
101 HANDLE
fileDesHandle (int fd
) {
102 // The temporary prevents a "cast does not match function type" warning.
105 t
= get_osfhandle (fd
);
109 /* ------------------------------------------------- */
111 /* ------------------------------------------------- */
113 C_String_t
Cygwin_toFullWindowsPath (NullString8_t path
) {
114 static char res
[MAX_PATH
];
116 #if ((CYGWIN_VERSION_API_MAJOR > 0) || (CYGWIN_VERSION_API_MINOR > 181))
117 cygwin_conv_path (CCP_POSIX_TO_WIN_A
| CCP_ABSOLUTE
,
118 (char*)path
, &res
[0], MAX_PATH
);
120 cygwin_conv_to_full_win32_path ((char*)path
, &res
[0]);
122 return (C_String_t
)&res
[0];
125 /* ------------------------------------------------- */
127 /* ------------------------------------------------- */
129 void Posix_IO_setbin (C_Fd_t fd
) {
130 /* cygwin has a different method for working with its fds */
131 setmode (fd
, O_BINARY
);
134 void Posix_IO_settext (C_Fd_t fd
) {
135 /* cygwin has a different method for working with its fds */
136 setmode (fd
, O_TEXT
);