Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
torvalds
GitHub Repository: torvalds/linux
Path: blob/master/tools/include/nolibc/sys/mman.h
49766 views
1
/* SPDX-License-Identifier: LGPL-2.1 OR MIT */
2
/*
3
* mm definition for NOLIBC
4
* Copyright (C) 2017-2021 Willy Tarreau <[email protected]>
5
*/
6
7
/* make sure to include all global symbols */
8
#include "../nolibc.h"
9
10
#ifndef _NOLIBC_SYS_MMAN_H
11
#define _NOLIBC_SYS_MMAN_H
12
13
#include "../arch.h"
14
#include "../sys.h"
15
16
#ifndef sys_mmap
17
static __attribute__((unused))
18
void *sys_mmap(void *addr, size_t length, int prot, int flags, int fd,
19
off_t offset)
20
{
21
int n;
22
23
#if defined(__NR_mmap2)
24
n = __NR_mmap2;
25
offset >>= 12;
26
#else
27
n = __NR_mmap;
28
#endif
29
30
return (void *)my_syscall6(n, addr, length, prot, flags, fd, offset);
31
}
32
#endif
33
34
static __attribute__((unused))
35
void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset)
36
{
37
void *ret = sys_mmap(addr, length, prot, flags, fd, offset);
38
39
if ((unsigned long)ret >= -4095UL) {
40
SET_ERRNO(-(long)ret);
41
ret = MAP_FAILED;
42
}
43
return ret;
44
}
45
46
static __attribute__((unused))
47
void *sys_mremap(void *old_address, size_t old_size, size_t new_size, int flags, void *new_address)
48
{
49
return (void *)my_syscall5(__NR_mremap, old_address, old_size,
50
new_size, flags, new_address);
51
}
52
53
static __attribute__((unused))
54
void *mremap(void *old_address, size_t old_size, size_t new_size, int flags, void *new_address)
55
{
56
void *ret = sys_mremap(old_address, old_size, new_size, flags, new_address);
57
58
if ((unsigned long)ret >= -4095UL) {
59
SET_ERRNO(-(long)ret);
60
ret = MAP_FAILED;
61
}
62
return ret;
63
}
64
65
static __attribute__((unused))
66
int sys_munmap(void *addr, size_t length)
67
{
68
return my_syscall2(__NR_munmap, addr, length);
69
}
70
71
static __attribute__((unused))
72
int munmap(void *addr, size_t length)
73
{
74
return __sysret(sys_munmap(addr, length));
75
}
76
77
#endif /* _NOLIBC_SYS_MMAN_H */
78
79