-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmusl.patch
More file actions
142 lines (137 loc) · 3.63 KB
/
Copy pathmusl.patch
File metadata and controls
142 lines (137 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
diff --git a/Makefile b/Makefile
index e8cc4436..2fdd3564 100644
--- a/Makefile
+++ b/Makefile
@@ -42,7 +42,7 @@ LDFLAGS =
LDFLAGS_AUTO =
LIBCC = -lgcc
CPPFLAGS =
-CFLAGS =
+CFLAGS = -g
CFLAGS_AUTO = -Os -pipe
CFLAGS_C99FSE = -std=c99 -ffreestanding -nostdinc
diff --git a/ldso/dynlink.c b/ldso/dynlink.c
index ceca3c98..279ea426 100644
--- a/ldso/dynlink.c
+++ b/ldso/dynlink.c
@@ -1616,7 +1616,8 @@ static void do_init_fini(struct dso **queue)
void __libc_start_init(void)
{
- do_init_fini(main_ctor_queue);
+ if(main_ctor_queue)
+ do_init_fini(main_ctor_queue);
if (!__malloc_replaced && main_ctor_queue != builtin_ctor_queue)
free(main_ctor_queue);
main_ctor_queue = 0;
diff --git a/src/env/__stack_chk_fail.c b/src/env/__stack_chk_fail.c
index e5352602..35c5bde2 100644
--- a/src/env/__stack_chk_fail.c
+++ b/src/env/__stack_chk_fail.c
@@ -18,7 +18,7 @@ void __init_ssp(void *entropy)
((char *)&__stack_chk_guard)[1] = 0;
#endif
- __pthread_self()->canary = __stack_chk_guard;
+ // __pthread_self()->canary = __stack_chk_guard;
}
void __stack_chk_fail(void)
diff --git a/src/fcntl/fcntl.c b/src/fcntl/fcntl.c
index d3bff5c4..9c6a1be5 100644
--- a/src/fcntl/fcntl.c
+++ b/src/fcntl/fcntl.c
@@ -4,11 +4,9 @@
#include <errno.h>
#include "syscall.h"
-int fcntl(int fd, int cmd, ...)
+int vfcntl(int fd, int cmd, va_list ap)
{
unsigned long arg;
- va_list ap;
- va_start(ap, cmd);
arg = va_arg(ap, unsigned long);
va_end(ap);
if (cmd == F_SETFL) arg |= O_LARGEFILE;
@@ -46,3 +44,9 @@ int fcntl(int fd, int cmd, ...)
return syscall(SYS_fcntl, fd, cmd, arg);
}
}
+
+int fcntl(int fd, int cmd, ...) {
+ va_list ap;
+ va_start(ap, cmd);
+ return vfcntl(fd, cmd, ap);
+}
\ No newline at end of file
diff --git a/src/glib/glib.c b/src/glib/glib.c
new file mode 100644
index 00000000..d0e61719
--- /dev/null
+++ b/src/glib/glib.c
@@ -0,0 +1,68 @@
+#include "syscall.h"
+#include <dirent.h>
+#include <fcntl.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+FILE *fopen64(const char *filename, const char *mode) {
+ return fopen(filename, mode);
+}
+
+// Has to be rewritten as there is no vopen function to pass va_args to
+int open64(const char *filename, int flags, ...) {
+ mode_t mode = 0;
+
+ if ((flags & O_CREAT) || (flags & O_TMPFILE) == O_TMPFILE) {
+ va_list ap;
+ va_start(ap, flags);
+ mode = va_arg(ap, mode_t);
+ va_end(ap);
+ }
+
+ int fd = __sys_open_cp(filename, flags, mode);
+ if (fd >= 0 && (flags & O_CLOEXEC))
+ __syscall(SYS_fcntl, fd, F_SETFD, FD_CLOEXEC);
+
+ return __syscall_ret(fd);
+}
+
+int stat64(const char *restrict file, struct stat *restrict buf) {
+ return stat(file, buf);
+}
+
+int lstat64(const char *restrict file, struct stat *restrict buf) {
+ return lstat(file, buf);
+}
+
+int fstat64(int fd, struct stat *restrict buf) { return fstat(fd, buf); }
+
+struct dirent *readdir64(DIR *dir) { return readdir(dir); }
+
+ssize_t pread64(int fildes, void *buf, size_t nbyte, off_t offset) {
+ return pread(fildes, buf, nbyte, offset);
+}
+
+ssize_t pwrite64(int fildes, const void *buf, size_t nbyte, off_t offset) {
+ return pwrite(fildes, buf, nbyte, offset);
+}
+
+int ftruncate64(int fd, off_t length) { return ftruncate(fd, length); }
+
+int vfcntl(int fd, int cmd, va_list ap);
+int fcntl64(int fd, int op, ... /* arg */) {
+ va_list ap;
+ va_start(ap, op);
+ return vfcntl(fd, op, ap);
+}
+
+void *mmap64(void *addr, size_t length, int prot, int flags, int fd,
+ off_t offset) {
+ return mmap(addr, length, prot, flags, fd, offset);
+}
+
+off_t lseek64(int fd, off_t offset, int whence) {
+ return lseek(fd, offset, whence);
+}