2 * <sys/mman.h> wrapper functions.
5 * Jonathan Pryor (jonpryor@vt.edu)
7 * Copyright (C) 2004-2006 Jonathan Pryor
13 #define _XOPEN_SOURCE 600
16 #ifdef PLATFORM_MACOSX
18 #define _DARWIN_C_SOURCE
22 #define __BSD_VISIBLE 1
25 #include <sys/types.h>
35 Mono_Posix_Syscall_mmap (void *start
, mph_size_t length
, int prot
, int flags
,
36 int fd
, mph_off_t offset
)
40 mph_return_val_if_size_t_overflow (length
, MAP_FAILED
);
41 mph_return_val_if_off_t_overflow (offset
, MAP_FAILED
);
43 if (Mono_Posix_FromMmapProts (prot
, &_prot
) == -1)
45 if (Mono_Posix_FromMmapFlags (flags
, &_flags
) == -1)
48 return mmap (start
, (size_t) length
, _prot
, _flags
, fd
, (off_t
) offset
);
52 Mono_Posix_Syscall_munmap (void *start
, mph_size_t length
)
54 mph_return_if_size_t_overflow (length
);
56 return munmap (start
, (size_t) length
);
60 Mono_Posix_Syscall_mprotect (void *start
, mph_size_t len
, int prot
)
63 mph_return_if_size_t_overflow (len
);
65 if (Mono_Posix_FromMmapProts (prot
, &_prot
) == -1)
68 return mprotect (start
, (size_t) len
, _prot
);
72 Mono_Posix_Syscall_msync (void *start
, mph_size_t len
, int flags
)
75 mph_return_if_size_t_overflow (len
);
77 if (Mono_Posix_FromMsyncFlags (flags
, &_flags
) == -1)
80 return msync (start
, (size_t) len
, _flags
);
84 Mono_Posix_Syscall_mlock (void *start
, mph_size_t len
)
86 mph_return_if_size_t_overflow (len
);
88 return mlock (start
, (size_t) len
);
92 Mono_Posix_Syscall_munlock (void *start
, mph_size_t len
)
94 mph_return_if_size_t_overflow (len
);
96 return munlock (start
, (size_t) len
);
101 Mono_Posix_Syscall_mremap (void *old_address
, mph_size_t old_size
,
102 mph_size_t new_size
, guint64 flags
)
106 mph_return_val_if_size_t_overflow (old_size
, MAP_FAILED
);
107 mph_return_val_if_size_t_overflow (new_size
, MAP_FAILED
);
109 if (Mono_Posix_FromMremapFlags (flags
, &_flags
) == -1)
112 return mremap (old_address
, (size_t) old_size
, (size_t) new_size
,
113 (unsigned long) _flags
);
115 #endif /* def HAVE_MREMAP */
118 Mono_Posix_Syscall_mincore (void *start
, mph_size_t length
, unsigned char *vec
)
120 mph_return_if_size_t_overflow (length
);
122 return mincore (start
, (size_t) length
, (void*)vec
);
125 #ifdef HAVE_POSIX_MADVISE
127 Mono_Posix_Syscall_posix_madvise (void *addr
, mph_size_t len
, gint32 advice
)
129 mph_return_if_size_t_overflow (len
);
131 if (Mono_Posix_FromPosixMadviseAdvice (advice
, &advice
) == -1)
134 return posix_madvise (addr
, (size_t) len
, advice
);
136 #endif /* def HAVE_POSIX_MADVISE */
138 #ifdef HAVE_REMAP_FILE_PAGES
140 Mono_Posix_Syscall_remap_file_pages (void *start
, mph_size_t size
,
141 int prot
, mph_ssize_t pgoff
, int flags
)
145 mph_return_if_size_t_overflow (size
);
146 mph_return_if_ssize_t_overflow (pgoff
);
148 if (Mono_Posix_FromMmapProts (prot
, &_prot
) == -1)
150 if (Mono_Posix_FromMmapFlags (flags
, &_flags
) == -1)
153 return remap_file_pages (start
, (size_t) size
, _prot
, (ssize_t
) pgoff
, _flags
);
155 #endif /* def HAVE_REMAP_FILE_PAGES */