Skip to content

Commit 310b81c

Browse files
mlibc: pthread_attr_setscope
Signed-off-by: Andy-Python-Programmer <[email protected]>
1 parent f5c447c commit 310b81c

File tree

1 file changed

+153
-10
lines changed

1 file changed

+153
-10
lines changed

patches/mlibc/mlibc.patch

Lines changed: 153 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
From a1c97a1acc4f67a2add919e2dbf8a7f35d1a107a Mon Sep 17 00:00:00 2001
1+
From 8849f6b4ee27ecbb6f80b18ab61036bb40637da6 Mon Sep 17 00:00:00 2001
22
From: Matt Taylor <[email protected]>
33
Date: Fri, 17 Jun 2022 15:28:34 +0100
44
Subject: [PATCH] abi-bits: add domainname to utsname
55

66
---
7-
ABI_BREAKS.md | 1 +
8-
abis/linux/utsname.h | 1 +
9-
options/ansi/generic/stdlib-stubs.cpp | 100 ++++++++++++++++++++++----
10-
options/glibc/generic/execinfo.cpp | 6 +-
11-
options/rtdl/generic/linker.cpp | 2 +-
12-
sysdeps/aero/generic/aero.cpp | 10 ++-
13-
sysdeps/aero/generic/filesystem.cpp | 19 ++++-
14-
sysdeps/aero/include/aero/syscall.h | 2 +
15-
8 files changed, 122 insertions(+), 19 deletions(-)
7+
ABI_BREAKS.md | 1 +
8+
abis/linux/utsname.h | 1 +
9+
options/ansi/generic/stdlib-stubs.cpp | 100 +++++++++++++++++++++---
10+
options/glibc/generic/execinfo.cpp | 6 +-
11+
options/posix/generic/pthread-stubs.cpp | 11 ++-
12+
options/posix/include/pthread.h | 51 +++++++++---
13+
options/rtdl/generic/linker.cpp | 2 +-
14+
sysdeps/aero/generic/aero.cpp | 10 ++-
15+
sysdeps/aero/generic/filesystem.cpp | 19 ++++-
16+
sysdeps/aero/generic/sockets.cpp | 4 +-
17+
sysdeps/aero/include/aero/syscall.h | 2 +
18+
11 files changed, 174 insertions(+), 33 deletions(-)
1619

1720
diff --git a/ABI_BREAKS.md b/ABI_BREAKS.md
1821
index 0cd3993b..d2a0bb7d 100644
@@ -164,6 +167,131 @@ index 3474615e..c0081e30 100644
164167
}
165168

166169
char **backtrace_symbols(void *const *, int) {
170+
diff --git a/options/posix/generic/pthread-stubs.cpp b/options/posix/generic/pthread-stubs.cpp
171+
index be6eeecf..2e60b7d0 100644
172+
--- a/options/posix/generic/pthread-stubs.cpp
173+
+++ b/options/posix/generic/pthread-stubs.cpp
174+
@@ -111,9 +111,14 @@ int pthread_attr_getscope(const pthread_attr_t *, int) {
175+
__builtin_unreachable();
176+
}
177+
178+
-int pthread_attr_setscope(pthread_attr_t *, int) {
179+
- __ensure(!"Not implemented");
180+
- __builtin_unreachable();
181+
+int pthread_attr_setscope(pthread_attr_t *attr, int scope) {
182+
+ if (scope != PTHREAD_SCOPE_SYSTEM &&
183+
+ scope != PTHREAD_SCOPE_PROCESS)
184+
+ return EINVAL;
185+
+ if (scope == PTHREAD_SCOPE_PROCESS)
186+
+ return ENOTSUP;
187+
+ attr->__mlibc_scope = scope;
188+
+ return 0;
189+
}
190+
191+
int pthread_attr_getschedpolicy(const pthread_attr_t *__restrict, int *__restrict) {
192+
diff --git a/options/posix/include/pthread.h b/options/posix/include/pthread.h
193+
index 4476a199..44dc5f95 100644
194+
--- a/options/posix/include/pthread.h
195+
+++ b/options/posix/include/pthread.h
196+
@@ -1,4 +1,3 @@
197+
-
198+
#ifndef _PTHREAD_H
199+
#define _PTHREAD_H
200+
201+
@@ -7,6 +6,7 @@
202+
#include <bits/size_t.h>
203+
#include <bits/posix/pthread_t.h>
204+
205+
+#include <signal.h>
206+
#include <stdint.h>
207+
208+
// pthread.h is required to include sched.h and time.h
209+
@@ -25,6 +25,10 @@ extern "C" {
210+
#define PTHREAD_SCOPE_SYSTEM 0
211+
#define PTHREAD_SCOPE_PROCESS 1
212+
213+
+// Values for pthread_attr_{get,set}inheritsched
214+
+#define PTHREAD_INHERIT_SCHED 0
215+
+#define PTHREAD_EXPLICIT_SCHED 1
216+
+
217+
// values for pthread_{get,set}canceltype().
218+
#define PTHREAD_CANCEL_DEFERRED 0
219+
#define PTHREAD_CANCEL_ASYNCHRONOUS 1
220+
@@ -66,11 +70,24 @@ extern "C" {
221+
#define PTHREAD_INHERIT_SCHED 0
222+
#define PTHREAD_EXPLICIT_SCHED 1
223+
224+
+#define PTHREAD_STACK_MIN 16384
225+
+
226+
+#define PTHREAD_ATTR_NO_SIGMASK_NP (-1)
227+
+
228+
// TODO: move to own file and include in sys/types.h
229+
struct __mlibc_threadattr {
230+
- // TODO: the guardsize attribute needs to be supported here.
231+
-
232+
- int __mlibc_deatchstate;
233+
+ size_t __mlibc_guardsize;
234+
+ size_t __mlibc_stacksize;
235+
+ void *__mlibc_stackaddr;
236+
+ int __mlibc_detachstate;
237+
+ int __mlibc_scope;
238+
+ int __mlibc_inheritsched;
239+
+ struct sched_param __mlibc_schedparam;
240+
+ int __mlibc_schedpolicy;
241+
+ cpu_set_t *__mlibc_cpuset;
242+
+ size_t __mlibc_cpusetsize;
243+
+ sigset_t __mlibc_sigmask;
244+
+ int __mlibc_sigmaskset;
245+
};
246+
typedef struct __mlibc_threadattr pthread_attr_t;
247+
248+
@@ -141,20 +158,37 @@ int pthread_attr_setdetachstate(pthread_attr_t *, int);
249+
int pthread_attr_getstacksize(const pthread_attr_t *__restrict, size_t *__restrict);
250+
int pthread_attr_setstacksize(pthread_attr_t *, size_t);
251+
252+
+int pthread_attr_getstackaddr(const pthread_attr_t *, void **);
253+
+int pthread_attr_setstackaddr(pthread_attr_t *, void *);
254+
+
255+
+int pthread_attr_getstack(const pthread_attr_t *, void **, size_t*);
256+
+int pthread_attr_setstack(pthread_attr_t *, void *, size_t);
257+
+
258+
int pthread_attr_getguardsize(const pthread_attr_t *__restrict, size_t *__restrict);
259+
int pthread_attr_setguardsize(pthread_attr_t *, size_t);
260+
261+
-int pthread_attr_getscope(const pthread_attr_t *, int);
262+
+int pthread_attr_getscope(const pthread_attr_t *, int*);
263+
int pthread_attr_setscope(pthread_attr_t *, int);
264+
265+
+int pthread_attr_getschedparam(const pthread_attr_t *__restrict, struct sched_param *__restrict);
266+
+int pthread_attr_setschedparam(pthread_attr_t *__restrict, const struct sched_param *__restrict);
267+
+
268+
int pthread_attr_getschedpolicy(const pthread_attr_t *__restrict, int *__restrict);
269+
-int pthread_attr_setschedpolicy(pthread_attr_t *, int);
270+
+int pthread_attr_setschedpolicy(pthread_attr_t *__restrict, int);
271+
+
272+
+int pthread_attr_getinheritsched(const pthread_attr_t *__restrict, int *__restrict);
273+
+int pthread_attr_setinheritsched(pthread_attr_t *__restrict, int);
274+
275+
int pthread_attr_getschedparam(const pthread_attr_t *__restrict, struct sched_param *__restrict);
276+
int pthread_attr_setschedparam(pthread_attr_t *__restrict, const struct sched_param *__restrict);
277+
278+
-int pthread_attr_getinheritsched(const pthread_attr_t *__restrict, int *__restrict);
279+
-int pthread_attr_setinheritsched(pthread_attr_t *, int);
280+
+int pthread_attr_getaffinity_np(const pthread_attr_t *__restrict, size_t, cpu_set_t *__restrict);
281+
+int pthread_attr_setaffinity_np(pthread_attr_t *__restrict, size_t, const cpu_set_t *__restrict);
282+
+
283+
+int pthread_attr_getsigmask_np(const pthread_attr_t *__restrict, sigset_t *__restrict);
284+
+int pthread_attr_setsigmask_np(pthread_attr_t *__restrict, const sigset_t *__restrict);
285+
+
286+
+int pthread_getattr_np(pthread_t, pthread_attr_t *);
287+
288+
// pthread functions.
289+
int pthread_create(pthread_t *__restrict, const pthread_attr_t *__restrict,
290+
@@ -287,4 +321,3 @@ int pthread_rwlock_unlock(pthread_rwlock_t *);
291+
#endif
292+
293+
#endif // _PTHREAD_H
294+
-
167295
diff --git a/options/rtdl/generic/linker.cpp b/options/rtdl/generic/linker.cpp
168296
index c2eceff6..d2d91b13 100644
169297
--- a/options/rtdl/generic/linker.cpp
@@ -238,6 +366,21 @@ index a3e2aca2..a56438f0 100644
238366
int sys_mkdir(const char *path, mode_t) {
239367
auto result = syscall(SYS_MKDIR, path, strlen(path));
240368

369+
diff --git a/sysdeps/aero/generic/sockets.cpp b/sysdeps/aero/generic/sockets.cpp
370+
index b6b18fe7..111dc570 100644
371+
--- a/sysdeps/aero/generic/sockets.cpp
372+
+++ b/sysdeps/aero/generic/sockets.cpp
373+
@@ -46,8 +46,8 @@ int sys_listen(int fd, int backlog) {
374+
return 0;
375+
}
376+
377+
-int sys_accept(int fd, int *newfd) {
378+
- auto result = syscall(SYS_ACCEPT, fd);
379+
+int sys_accept(int fd, int *newfd, struct sockaddr *addr_ptr, socklen_t *addr_length) {
380+
+ auto result = syscall(SYS_ACCEPT, fd, addr_ptr, addr_length);
381+
382+
if (result < 0) {
383+
return -result;
241384
diff --git a/sysdeps/aero/include/aero/syscall.h b/sysdeps/aero/include/aero/syscall.h
242385
index 12f8dc61..fcc219a9 100644
243386
--- a/sysdeps/aero/include/aero/syscall.h

0 commit comments

Comments
 (0)