Skip to content

Commit fa7adfd

Browse files
committed
[mlibc] provide header files for mlibc compilation
1 parent 2d78d8c commit fa7adfd

File tree

13 files changed

+896
-0
lines changed

13 files changed

+896
-0
lines changed

Diff for: components/libc/compilers/common/include/sys/signal.h

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ extern "C" {
2828
#include <signal.h>
2929
#endif
3030

31+
#elif defined(RT_USING_MLIBC)
32+
#include <signal.h>
33+
3134
#else
3235

3336
#include <stdint.h>

Diff for: components/libc/compilers/mlibc/SConscript

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import os
2+
from building import *
3+
Import('rtconfig')
4+
5+
group = []
6+
7+
if rtconfig.PLATFORM == 'gcc':
8+
from gcc import *
9+
else:
10+
Return('group')
11+
12+
mlibc_version = "0.0.1"
13+
14+
if mlibc_version and GetDepend('PKG_USING_MLIBC'):
15+
print('mlibc version: ' + mlibc_version)
16+
17+
cwd = GetCurrentDir()
18+
src = Glob('*.c')
19+
20+
CPPPATH = [cwd]
21+
if GetDepend("RT_USING_SMART"):
22+
CPPPATH += [cwd + '/smart']
23+
CPPPATH += [cwd + '/smart/sys']
24+
CPPDEFINES = ['RT_USING_MLIBC', 'RT_USING_LIBC']
25+
AddDepend(['RT_USING_LIBC'])
26+
group = group + DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
27+
28+
list = os.listdir(cwd)
29+
for d in list:
30+
path = os.path.join(cwd, d)
31+
if os.path.isfile(os.path.join(path, 'SConscript')):
32+
group = group + SConscript(os.path.join(d, 'SConscript'))
33+
34+
Return('group')

Diff for: components/libc/compilers/mlibc/alltypes.h

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) mlibc & plct lab
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2023/06/16 bernard the first verison
9+
*/
10+
11+
#ifndef MLIBC_ALLTYPES_H__
12+
#define MLIBC_ALLTYPES_H__
13+
14+
#include <stdint.h>
15+
16+
typedef uint64_t fsblkcnt_t;
17+
typedef uint64_t fsfilcnt_t;
18+
19+
#define INT_FAST16_MIN INT32_MIN
20+
#define INT_FAST32_MIN INT32_MIN
21+
22+
#define INT_FAST16_MAX INT32_MAX
23+
#define INT_FAST32_MAX INT32_MAX
24+
25+
#define UINT_FAST16_MAX UINT32_MAX
26+
#define UINT_FAST32_MAX UINT32_MAX
27+
28+
#if (defined(__GNUC__) && (__SIZEOF_POINTER__ == 8))
29+
#define __LONG_MAX INT64_MAX
30+
#else
31+
#define __LONG_MAX INT32_MAX
32+
#endif /* __GNUC__ */
33+
34+
#endif

Diff for: components/libc/compilers/mlibc/smart/sched.h

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/*
2+
* Copyright (c) mlibc & plct lab
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2024/8/8 0Bitbiscuits the first version
9+
*/
10+
#ifndef MLIBC_SCHED_H__
11+
#define MLIBC_SCHED_H__
12+
13+
#ifdef __cplusplus
14+
extern "C" {
15+
#endif
16+
17+
#include <features.h>
18+
#include <alltypes.h>
19+
20+
/* Defined a set of scheduling policies and a scheduling flag */
21+
#define SCHED_OTHER 0
22+
#define SCHED_FIFO 1
23+
#define SCHED_RR 2
24+
#define SCHED_BATCH 3
25+
#define SCHED_IDLE 5
26+
#define SCHED_DEADLINE 6
27+
#define SCHED_RESET_ON_FORK 0x40000000
28+
29+
/* Defined a set of flags for the clone system call,
30+
** which control how the new process (or thread)
31+
** inherits and shares the parent process's resources.
32+
**/
33+
#ifdef __GNUC__
34+
#define CSIGNAL 0x000000ff
35+
#define CLONE_NEWTIME 0x00000080
36+
#define CLONE_VM 0x00000100
37+
#define CLONE_FS 0x00000200
38+
#define CLONE_FILES 0x00000400
39+
#define CLONE_SIGHAND 0x00000800
40+
#define CLONE_PIDFD 0x00001000
41+
#define CLONE_PTRACE 0x00002000
42+
#define CLONE_VFORK 0x00004000
43+
#define CLONE_PARENT 0x00008000
44+
#define CLONE_THREAD 0x00010000
45+
#define CLONE_NEWNS 0x00020000
46+
#define CLONE_SYSVSEM 0x00040000
47+
#define CLONE_SETTLS 0x00080000
48+
#define CLONE_PARENT_SETTID 0x00100000
49+
#define CLONE_CHILD_CLEARTID 0x00200000
50+
#define CLONE_DETACHED 0x00400000
51+
#define CLONE_UNTRACED 0x00800000
52+
#define CLONE_CHILD_SETTID 0x01000000
53+
#define CLONE_NEWCGROUP 0x02000000
54+
#define CLONE_NEWUTS 0x04000000
55+
#define CLONE_NEWIPC 0x08000000
56+
#define CLONE_NEWUSER 0x10000000
57+
#define CLONE_NEWPID 0x20000000
58+
#define CLONE_NEWNET 0x40000000
59+
#define CLONE_IO 0x80000000
60+
#endif /* __GNUC__ */
61+
62+
struct sched_param {
63+
int sched_priority;
64+
int __reserved1;
65+
struct {
66+
time_t __reserved1;
67+
long __reserved2;
68+
} __reserved2[2];
69+
int __reserved3;
70+
};
71+
72+
int sched_get_priority_max(int);
73+
int sched_get_priority_min(int);
74+
int sched_getparam(pid_t, struct sched_param *);
75+
int sched_getscheduler(pid_t);
76+
int sched_rr_get_interval(pid_t, struct timespec *);
77+
int sched_setparam(pid_t, const struct sched_param *);
78+
int sched_setscheduler(pid_t, int, const struct sched_param *);
79+
int sched_yield(void);
80+
81+
int clone (int (*)(void *), void *, int, void *, ...);
82+
int unshare(int);
83+
int setns(int, int);
84+
85+
typedef struct cpu_set_t { unsigned long __bits[128/sizeof(long)]; } cpu_set_t;
86+
int __sched_cpucount(size_t, const cpu_set_t *);
87+
int sched_getcpu(void);
88+
int sched_getaffinity(pid_t, size_t, cpu_set_t *);
89+
int sched_setaffinity(pid_t, size_t, const cpu_set_t *);
90+
91+
#define __CPU_op_S(i, size, set, op) ( (i)/8U >= (size) ? 0 : \
92+
(((unsigned long *)(set))[(i)/8/sizeof(long)] op (1UL<<((i)%(8*sizeof(long))))) )
93+
94+
#define CPU_SET_S(i, size, set) __CPU_op_S(i, size, set, |=)
95+
#define CPU_CLR_S(i, size, set) __CPU_op_S(i, size, set, &=~)
96+
#define CPU_ISSET_S(i, size, set) __CPU_op_S(i, size, set, &)
97+
98+
#define __CPU_op_func_S(func, op) \
99+
static __inline void __CPU_##func##_S(size_t __size, cpu_set_t *__dest, \
100+
const cpu_set_t *__src1, const cpu_set_t *__src2) \
101+
{ \
102+
size_t __i; \
103+
for (__i=0; __i<__size/sizeof(long); __i++) \
104+
((unsigned long *)__dest)[__i] = ((unsigned long *)__src1)[__i] \
105+
op ((unsigned long *)__src2)[__i] ; \
106+
}
107+
108+
__CPU_op_func_S(AND, &)
109+
__CPU_op_func_S(OR, |)
110+
__CPU_op_func_S(XOR, ^)
111+
112+
#define CPU_AND_S(a,b,c,d) __CPU_AND_S(a,b,c,d)
113+
#define CPU_OR_S(a,b,c,d) __CPU_OR_S(a,b,c,d)
114+
#define CPU_XOR_S(a,b,c,d) __CPU_XOR_S(a,b,c,d)
115+
116+
#define CPU_COUNT_S(size,set) __sched_cpucount(size,set)
117+
#define CPU_ZERO_S(size,set) memset(set,0,size)
118+
#define CPU_EQUAL_S(size,set1,set2) (!memcmp(set1,set2,size))
119+
120+
#define CPU_ALLOC_SIZE(n) (sizeof(long) * ( (n)/(8*sizeof(long)) \
121+
+ ((n)%(8*sizeof(long)) + 8*sizeof(long)-1)/(8*sizeof(long)) ) )
122+
#define CPU_ALLOC(n) ((cpu_set_t *)calloc(1,CPU_ALLOC_SIZE(n)))
123+
#define CPU_FREE(set) free(set)
124+
125+
#define CPU_SETSIZE 1024
126+
127+
#define CPU_SET(i, set) CPU_SET_S(i,sizeof(cpu_set_t),set)
128+
#define CPU_CLR(i, set) CPU_CLR_S(i,sizeof(cpu_set_t),set)
129+
#define CPU_ISSET(i, set) CPU_ISSET_S(i,sizeof(cpu_set_t),set)
130+
#define CPU_AND(d,s1,s2) CPU_AND_S(sizeof(cpu_set_t),d,s1,s2)
131+
#define CPU_OR(d,s1,s2) CPU_OR_S(sizeof(cpu_set_t),d,s1,s2)
132+
#define CPU_XOR(d,s1,s2) CPU_XOR_S(sizeof(cpu_set_t),d,s1,s2)
133+
#define CPU_COUNT(set) CPU_COUNT_S(sizeof(cpu_set_t),set)
134+
#define CPU_ZERO(set) CPU_ZERO_S(sizeof(cpu_set_t),set)
135+
#define CPU_EQUAL(s1,s2) CPU_EQUAL_S(sizeof(cpu_set_t),s1,s2)
136+
137+
#ifdef __cplusplus
138+
}
139+
#endif
140+
141+
#endif

Diff for: components/libc/compilers/mlibc/smart/sys/epoll.h

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (c) mlibc & plct lab
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2024/8/8 0Bitbiscuits the first version
9+
*/
10+
#ifndef MLIBC_EPOLL_H__
11+
#define MLIBC_EPOLL_H__
12+
13+
#ifdef __cplusplus
14+
extern "C" {
15+
#endif
16+
17+
#include <stdint.h>
18+
#include <sys/types.h>
19+
#include <fcntl.h>
20+
21+
#include <alltypes.h>
22+
23+
/* The flag of file descriptor */
24+
#define EPOLL_CLOEXEC O_CLOEXEC
25+
#define EPOLL_NONBLOCK O_NONBLOCK
26+
27+
/* The event of file descriptor */
28+
enum EPOLL_EVENTS { __EPOLL_DUMMY };
29+
#define EPOLLIN 0x001
30+
#define EPOLLPRI 0x002
31+
#define EPOLLOUT 0x004
32+
#define EPOLLRDNORM 0x040
33+
#define EPOLLNVAL 0x020
34+
#define EPOLLRDBAND 0x080
35+
#define EPOLLWRNORM 0x100
36+
#define EPOLLWRBAND 0x200
37+
#define EPOLLMSG 0x400
38+
#define EPOLLERR 0x008
39+
#define EPOLLHUP 0x010
40+
#define EPOLLRDHUP 0x2000
41+
#define EPOLLEXCLUSIVE (1U<<28)
42+
#define EPOLLWAKEUP (1U<<29)
43+
#define EPOLLONESHOT (1U<<30)
44+
#define EPOLLET (1U<<31)
45+
46+
/* The control type of file descriptor */
47+
#define EPOLL_CTL_ADD 1
48+
#define EPOLL_CTL_DEL 2
49+
#define EPOLL_CTL_MOD 3
50+
51+
typedef union epoll_data {
52+
void *ptr;
53+
int fd;
54+
uint32_t u32;
55+
uint64_t u64;
56+
} epoll_data_t;
57+
58+
struct epoll_event {
59+
uint32_t events;
60+
epoll_data_t data;
61+
};
62+
63+
int epoll_create(int);
64+
int epoll_create1(int);
65+
int epoll_ctl(int, int, int, struct epoll_event *);
66+
int epoll_wait(int, struct epoll_event *, int, int);
67+
int epoll_pwait(int, struct epoll_event *, int, int, const sigset_t *);
68+
69+
#ifdef __cplusplus
70+
}
71+
#endif
72+
73+
#endif /* MLIBC_SYS_EPOLL_H__ */

Diff for: components/libc/compilers/mlibc/smart/sys/eventfd.h

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (c) mlibc & plct lab
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2024/8/8 0Bitbiscuits the first version
9+
*/
10+
#ifndef MLIBC_SYS_EVENTFD_H__
11+
#define MLIBC_SYS_EVENTFD_H__
12+
13+
#ifdef __cplusplus
14+
extern "C" {
15+
#endif
16+
17+
#include <stdint.h>
18+
#include <fcntl.h>
19+
20+
typedef uint64_t eventfd_t;
21+
22+
/* The type of file descriptor */
23+
#define EFD_SEMAPHORE 1
24+
#define EFD_CLOEXEC O_CLOEXEC
25+
#define EFD_NONBLOCK O_NONBLOCK
26+
27+
int eventfd(unsigned int, int);
28+
int eventfd_read(int, eventfd_t *);
29+
int eventfd_write(int, eventfd_t);
30+
31+
#ifdef __cplusplus
32+
}
33+
#endif
34+
35+
#endif /* sys/eventfd.h */

0 commit comments

Comments
 (0)