System.ServiceProcess: Implement ServiceBase.Run for Win32 services.
[mono-project.git] / support / sys-mman.c
blobce804ef6fb5761f85393591ba8562ca9df08df57
1 /*
2 * <sys/mman.h> wrapper functions.
4 * Authors:
5 * Jonathan Pryor (jonpryor@vt.edu)
7 * Copyright (C) 2004-2006 Jonathan Pryor
8 */
10 #include <config.h>
12 #define _XOPEN_SOURCE 600
14 #ifdef PLATFORM_MACOSX
15 /* For mincore () */
16 #define _DARWIN_C_SOURCE
17 #endif
18 #ifdef __FreeBSD__
19 /* For mincore () */
20 #define __BSD_VISIBLE 1
21 #endif
23 #include <sys/types.h>
24 #include <sys/mman.h>
25 #include <errno.h>
27 #include "map.h"
28 #include "mph.h"
30 G_BEGIN_DECLS
32 void*
33 Mono_Posix_Syscall_mmap (void *start, mph_size_t length, int prot, int flags,
34 int fd, mph_off_t offset)
36 int _prot, _flags;
38 mph_return_val_if_size_t_overflow (length, MAP_FAILED);
39 mph_return_val_if_off_t_overflow (offset, MAP_FAILED);
41 if (Mono_Posix_FromMmapProts (prot, &_prot) == -1)
42 return MAP_FAILED;
43 if (Mono_Posix_FromMmapFlags (flags, &_flags) == -1)
44 return MAP_FAILED;
46 return mmap (start, (size_t) length, _prot, _flags, fd, (off_t) offset);
49 int
50 Mono_Posix_Syscall_munmap (void *start, mph_size_t length)
52 mph_return_if_size_t_overflow (length);
54 return munmap (start, (size_t) length);
57 int
58 Mono_Posix_Syscall_mprotect (void *start, mph_size_t len, int prot)
60 int _prot;
61 mph_return_if_size_t_overflow (len);
63 if (Mono_Posix_FromMmapProts (prot, &_prot) == -1)
64 return -1;
66 return mprotect (start, (size_t) len, _prot);
69 int
70 Mono_Posix_Syscall_msync (void *start, mph_size_t len, int flags)
72 int _flags;
73 mph_return_if_size_t_overflow (len);
75 if (Mono_Posix_FromMsyncFlags (flags, &_flags) == -1)
76 return -1;
78 return msync (start, (size_t) len, _flags);
81 int
82 Mono_Posix_Syscall_mlock (void *start, mph_size_t len)
84 mph_return_if_size_t_overflow (len);
86 return mlock (start, (size_t) len);
89 int
90 Mono_Posix_Syscall_munlock (void *start, mph_size_t len)
92 mph_return_if_size_t_overflow (len);
94 return munlock (start, (size_t) len);
97 #ifdef HAVE_MREMAP
98 void*
99 Mono_Posix_Syscall_mremap (void *old_address, mph_size_t old_size,
100 mph_size_t new_size, guint64 flags)
102 guint64 _flags;
104 mph_return_val_if_size_t_overflow (old_size, MAP_FAILED);
105 mph_return_val_if_size_t_overflow (new_size, MAP_FAILED);
107 if (Mono_Posix_FromMremapFlags (flags, &_flags) == -1)
108 return MAP_FAILED;
110 return mremap (old_address, (size_t) old_size, (size_t) new_size,
111 (unsigned long) _flags);
113 #endif /* def HAVE_MREMAP */
116 Mono_Posix_Syscall_mincore (void *start, mph_size_t length, unsigned char *vec)
118 mph_return_if_size_t_overflow (length);
120 return mincore (start, (size_t) length, (void*)vec);
123 #ifdef HAVE_POSIX_MADVISE
124 gint32
125 Mono_Posix_Syscall_posix_madvise (void *addr, mph_size_t len, gint32 advice)
127 mph_return_if_size_t_overflow (len);
129 if (Mono_Posix_FromPosixMadviseAdvice (advice, &advice) == -1)
130 return -1;
132 return posix_madvise (addr, (size_t) len, advice);
134 #endif /* def HAVE_POSIX_MADVISE */
136 #ifdef HAVE_REMAP_FILE_PAGES
138 Mono_Posix_Syscall_remap_file_pages (void *start, mph_size_t size,
139 int prot, mph_ssize_t pgoff, int flags)
141 int _prot, _flags;
143 mph_return_if_size_t_overflow (size);
144 mph_return_if_ssize_t_overflow (pgoff);
146 if (Mono_Posix_FromMmapProts (prot, &_prot) == -1)
147 return -1;
148 if (Mono_Posix_FromMmapFlags (flags, &_flags) == -1)
149 return -1;
151 return remap_file_pages (start, (size_t) size, _prot, (ssize_t) pgoff, _flags);
153 #endif /* def HAVE_REMAP_FILE_PAGES */
155 G_END_DECLS
158 * vim: noexpandtab