Skip to content

Commit 1e55105

Browse files
authored
Merge pull request #1065 from BernardXiong/master
[libc] Add mmap API.
2 parents c1f78f0 + 98786df commit 1e55105

File tree

9 files changed

+387
-3
lines changed

9 files changed

+387
-3
lines changed

bsp/qemu-vexpress-a9/.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ CONFIG_RT_USING_WDT=y
151151
CONFIG_RT_USING_LIBC=y
152152
CONFIG_RT_USING_PTHREADS=y
153153
CONFIG_RT_USING_POSIX=y
154-
# CONFIG_RT_USING_POSIX_MMAP is not set
154+
CONFIG_RT_USING_POSIX_MMAP=y
155155
CONFIG_RT_USING_POSIX_TERMIOS=y
156156

157157
#

bsp/qemu-vexpress-a9/rtconfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
#define RT_USING_LIBC
141141
#define RT_USING_PTHREADS
142142
#define RT_USING_POSIX
143-
/* RT_USING_POSIX_MMAP is not set */
143+
#define RT_USING_POSIX_MMAP
144144
#define RT_USING_POSIX_TERMIOS
145145

146146
/* Network stack */
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* File : mman.h
3+
* This file is part of RT-Thread RTOS
4+
* COPYRIGHT (C) 2017, RT-Thread Development Team
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License along
17+
* with this program; if not, write to the Free Software Foundation, Inc.,
18+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Change Logs:
21+
* Date Author Notes
22+
* 2017/11/30 Bernard The first version.
23+
*/
24+
25+
#ifndef _SYS_MMAN_H
26+
#define _SYS_MMAN_H
27+
28+
#ifdef __cplusplus
29+
extern "C" {
30+
#endif
31+
32+
#define MAP_FAILED ((void *) -1)
33+
34+
#define MAP_SHARED 0x01
35+
#define MAP_PRIVATE 0x02
36+
#define MAP_TYPE 0x0f
37+
#define MAP_FIXED 0x10
38+
#define MAP_ANON 0x20
39+
#define MAP_ANONYMOUS MAP_ANON
40+
#define MAP_NORESERVE 0x4000
41+
#define MAP_GROWSDOWN 0x0100
42+
#define MAP_DENYWRITE 0x0800
43+
#define MAP_EXECUTABLE 0x1000
44+
#define MAP_LOCKED 0x2000
45+
#define MAP_POPULATE 0x8000
46+
#define MAP_NONBLOCK 0x10000
47+
#define MAP_STACK 0x20000
48+
#define MAP_HUGETLB 0x40000
49+
#define MAP_FILE 0
50+
51+
#define PROT_NONE 0
52+
#define PROT_READ 1
53+
#define PROT_WRITE 2
54+
#define PROT_EXEC 4
55+
#define PROT_GROWSDOWN 0x01000000
56+
#define PROT_GROWSUP 0x02000000
57+
58+
#define MS_ASYNC 1
59+
#define MS_INVALIDATE 2
60+
#define MS_SYNC 4
61+
62+
#define MCL_CURRENT 1
63+
#define MCL_FUTURE 2
64+
#define MCL_ONFAULT 4
65+
66+
void *mmap (void *start, size_t len, int prot, int flags, int fd, off_t off);
67+
int munmap (void *start, size_t len);
68+
69+
#ifdef __cplusplus
70+
}
71+
#endif
72+
#endif
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* File : mman.h
3+
* This file is part of RT-Thread RTOS
4+
* COPYRIGHT (C) 2017, RT-Thread Development Team
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License along
17+
* with this program; if not, write to the Free Software Foundation, Inc.,
18+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Change Logs:
21+
* Date Author Notes
22+
* 2017/11/30 Bernard The first version.
23+
*/
24+
25+
#ifndef _SYS_MMAN_H
26+
#define _SYS_MMAN_H
27+
28+
#ifdef __cplusplus
29+
extern "C" {
30+
#endif
31+
32+
#define MAP_FAILED ((void *) -1)
33+
34+
#define MAP_SHARED 0x01
35+
#define MAP_PRIVATE 0x02
36+
#define MAP_TYPE 0x0f
37+
#define MAP_FIXED 0x10
38+
#define MAP_ANON 0x20
39+
#define MAP_ANONYMOUS MAP_ANON
40+
#define MAP_NORESERVE 0x4000
41+
#define MAP_GROWSDOWN 0x0100
42+
#define MAP_DENYWRITE 0x0800
43+
#define MAP_EXECUTABLE 0x1000
44+
#define MAP_LOCKED 0x2000
45+
#define MAP_POPULATE 0x8000
46+
#define MAP_NONBLOCK 0x10000
47+
#define MAP_STACK 0x20000
48+
#define MAP_HUGETLB 0x40000
49+
#define MAP_FILE 0
50+
51+
#define PROT_NONE 0
52+
#define PROT_READ 1
53+
#define PROT_WRITE 2
54+
#define PROT_EXEC 4
55+
#define PROT_GROWSDOWN 0x01000000
56+
#define PROT_GROWSUP 0x02000000
57+
58+
#define MS_ASYNC 1
59+
#define MS_INVALIDATE 2
60+
#define MS_SYNC 4
61+
62+
#define MCL_CURRENT 1
63+
#define MCL_FUTURE 2
64+
#define MCL_ONFAULT 4
65+
66+
void *mmap (void *start, size_t len, int prot, int flags, int fd, off_t off);
67+
int munmap (void *start, size_t len);
68+
69+
#ifdef __cplusplus
70+
}
71+
#endif
72+
#endif
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* File : mman.h
3+
* This file is part of RT-Thread RTOS
4+
* COPYRIGHT (C) 2017, RT-Thread Development Team
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License along
17+
* with this program; if not, write to the Free Software Foundation, Inc.,
18+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Change Logs:
21+
* Date Author Notes
22+
* 2017/11/30 Bernard The first version.
23+
*/
24+
25+
#ifndef _SYS_MMAN_H
26+
#define _SYS_MMAN_H
27+
28+
#ifdef __cplusplus
29+
extern "C" {
30+
#endif
31+
32+
#define MAP_FAILED ((void *) -1)
33+
34+
#define MAP_SHARED 0x01
35+
#define MAP_PRIVATE 0x02
36+
#define MAP_TYPE 0x0f
37+
#define MAP_FIXED 0x10
38+
#define MAP_ANON 0x20
39+
#define MAP_ANONYMOUS MAP_ANON
40+
#define MAP_NORESERVE 0x4000
41+
#define MAP_GROWSDOWN 0x0100
42+
#define MAP_DENYWRITE 0x0800
43+
#define MAP_EXECUTABLE 0x1000
44+
#define MAP_LOCKED 0x2000
45+
#define MAP_POPULATE 0x8000
46+
#define MAP_NONBLOCK 0x10000
47+
#define MAP_STACK 0x20000
48+
#define MAP_HUGETLB 0x40000
49+
#define MAP_FILE 0
50+
51+
#define PROT_NONE 0
52+
#define PROT_READ 1
53+
#define PROT_WRITE 2
54+
#define PROT_EXEC 4
55+
#define PROT_GROWSDOWN 0x01000000
56+
#define PROT_GROWSUP 0x02000000
57+
58+
#define MS_ASYNC 1
59+
#define MS_INVALIDATE 2
60+
#define MS_SYNC 4
61+
62+
#define MCL_CURRENT 1
63+
#define MCL_FUTURE 2
64+
#define MCL_ONFAULT 4
65+
66+
void *mmap (void *start, size_t len, int prot, int flags, int fd, off_t off);
67+
int munmap (void *start, size_t len);
68+
69+
#ifdef __cplusplus
70+
}
71+
#endif
72+
#endif
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* File : mman.h
3+
* This file is part of RT-Thread RTOS
4+
* COPYRIGHT (C) 2017, RT-Thread Development Team
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License along
17+
* with this program; if not, write to the Free Software Foundation, Inc.,
18+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Change Logs:
21+
* Date Author Notes
22+
* 2017/11/30 Bernard The first version.
23+
*/
24+
25+
#ifndef _SYS_MMAN_H
26+
#define _SYS_MMAN_H
27+
28+
#ifdef __cplusplus
29+
extern "C" {
30+
#endif
31+
32+
#define MAP_FAILED ((void *) -1)
33+
34+
#define MAP_SHARED 0x01
35+
#define MAP_PRIVATE 0x02
36+
#define MAP_TYPE 0x0f
37+
#define MAP_FIXED 0x10
38+
#define MAP_ANON 0x20
39+
#define MAP_ANONYMOUS MAP_ANON
40+
#define MAP_NORESERVE 0x4000
41+
#define MAP_GROWSDOWN 0x0100
42+
#define MAP_DENYWRITE 0x0800
43+
#define MAP_EXECUTABLE 0x1000
44+
#define MAP_LOCKED 0x2000
45+
#define MAP_POPULATE 0x8000
46+
#define MAP_NONBLOCK 0x10000
47+
#define MAP_STACK 0x20000
48+
#define MAP_HUGETLB 0x40000
49+
#define MAP_FILE 0
50+
51+
#define PROT_NONE 0
52+
#define PROT_READ 1
53+
#define PROT_WRITE 2
54+
#define PROT_EXEC 4
55+
#define PROT_GROWSDOWN 0x01000000
56+
#define PROT_GROWSUP 0x02000000
57+
58+
#define MS_ASYNC 1
59+
#define MS_INVALIDATE 2
60+
#define MS_SYNC 4
61+
62+
#define MCL_CURRENT 1
63+
#define MCL_FUTURE 2
64+
#define MCL_ONFAULT 4
65+
66+
void *mmap (void *start, size_t len, int prot, int flags, int fd, off_t off);
67+
int munmap (void *start, size_t len);
68+
69+
#ifdef __cplusplus
70+
}
71+
#endif
72+
#endif

components/libc/mmap/SConscript

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# RT-Thread building script for component
2+
3+
from building import *
4+
5+
cwd = GetCurrentDir()
6+
src = Glob('*.c') + Glob('*.cpp')
7+
CPPPATH = [cwd]
8+
9+
group = DefineGroup('libc', src,
10+
depend = ['RT_USING_DFS', 'RT_USING_POSIX_MMAP'],
11+
CPPPATH = CPPPATH)
12+
13+
Return('group')

0 commit comments

Comments
 (0)