xref: /freebsd/contrib/llvm-project/compiler-rt/lib/profile/WindowsMMap.h (revision e8d8bef961a50d4dc22501cde4fb9fb0be1b2532)
1 /*===- WindowsMMap.h - Support library for PGO instrumentation ------------===*\
2 |*
3 |* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 |* See https://llvm.org/LICENSE.txt for license information.
5 |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 |*
7 \*===----------------------------------------------------------------------===*/
8 
9 #ifndef PROFILE_INSTRPROFILING_WINDOWS_MMAP_H
10 #define PROFILE_INSTRPROFILING_WINDOWS_MMAP_H
11 
12 #if defined(_WIN32)
13 
14 #include <basetsd.h>
15 #include <io.h>
16 #include <sys/types.h>
17 
18 /*
19  * mmap() flags
20  */
21 #define PROT_READ     0x1
22 #define PROT_WRITE    0x2
23 #define PROT_EXEC     0x0
24 
25 #define MAP_FILE      0x00
26 #define MAP_SHARED    0x01
27 #define MAP_PRIVATE   0x02
28 #define MAP_ANONYMOUS 0x20
29 #define MAP_ANON      MAP_ANONYMOUS
30 #define MAP_FAILED    ((void *) -1)
31 
32 /*
33  * msync() flags
34  */
35 #define MS_ASYNC        0x0001  /* return immediately */
36 #define MS_INVALIDATE   0x0002  /* invalidate all cached data */
37 #define MS_SYNC         0x0010  /* msync synchronously */
38 
39 /*
40  * flock() operations
41  */
42 #define   LOCK_SH   1    /* shared lock */
43 #define   LOCK_EX   2    /* exclusive lock */
44 #define   LOCK_NB   4    /* don't block when locking */
45 #define   LOCK_UN   8    /* unlock */
46 
47 #ifdef __USE_FILE_OFFSET64
48 # define DWORD_HI(x) (x >> 32)
49 # define DWORD_LO(x) ((x) & 0xffffffff)
50 #else
51 # define DWORD_HI(x) (0)
52 # define DWORD_LO(x) (x)
53 #endif
54 
55 void *mmap(void *start, size_t length, int prot, int flags, int fd,
56            off_t offset);
57 
58 void munmap(void *addr, size_t length);
59 
60 int msync(void *addr, size_t length, int flags);
61 
62 int flock(int fd, int operation);
63 
64 #endif /* _WIN32 */
65 
66 #endif /* PROFILE_INSTRPROFILING_WINDOWS_MMAP_H */
67