-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
0001-Add-SerenityOS-platform-support.patch
190 lines (183 loc) Β· 6.08 KB
/
0001-Add-SerenityOS-platform-support.patch
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jan200101 <sentrycraft123@gmail.com>
Date: Wed, 13 Mar 2024 20:09:25 +0100
Subject: [PATCH] Add SerenityOS platform support
Signed-off-by: Jan200101 <sentrycraft123@gmail.com>
---
meson.build | 3 +-
src/api/dirmonitor/inodewatcher.cpp | 75 +++++++++++++++++++++++++++++
src/main.c | 7 ++-
src/meson.build | 17 ++++---
4 files changed, 93 insertions(+), 9 deletions(-)
create mode 100644 src/api/dirmonitor/inodewatcher.cpp
diff --git a/meson.build b/meson.build
index 3f88be37..70627782 100644
--- a/meson.build
+++ b/meson.build
@@ -4,7 +4,8 @@ project('lite-xl',
license : 'MIT',
meson_version : '>= 0.56',
default_options : [
- 'c_std=gnu11'
+ 'c_std=gnu11',
+ 'cpp_std=c++20'
]
)
diff --git a/src/api/dirmonitor/inodewatcher.cpp b/src/api/dirmonitor/inodewatcher.cpp
new file mode 100644
index 00000000..e749f5bd
--- /dev/null
+++ b/src/api/dirmonitor/inodewatcher.cpp
@@ -0,0 +1,75 @@
+#include <AK/NumericLimits.h>
+#include <Kernel/API/InodeWatcherEvent.h>
+#include <Kernel/API/InodeWatcherFlags.h>
+#include <cstring>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <poll.h>
+
+extern "C" {
+struct dirmonitor_internal* init_dirmonitor();
+void deinit_dirmonitor(struct dirmonitor_internal*);
+int get_changes_dirmonitor(struct dirmonitor_internal*, char*, int);
+int translate_changes_dirmonitor(struct dirmonitor_internal*, char*, int, int (*)(int, const char*, void*), void*);
+int add_dirmonitor(struct dirmonitor_internal*, const char*);
+void remove_dirmonitor(struct dirmonitor_internal*, int);
+int get_mode_dirmonitor();
+}
+
+struct dirmonitor_internal {
+ int fd;
+ // a pipe is used to wake the thread in case of exit
+ int sig[2];
+};
+
+
+struct dirmonitor_internal* init_dirmonitor() {
+ struct dirmonitor_internal* monitor = (struct dirmonitor_internal*)calloc(sizeof(struct dirmonitor_internal), 1);
+ monitor->fd = create_inode_watcher(0);
+ pipe(monitor->sig);
+ fcntl(monitor->sig[0], F_SETFD, FD_CLOEXEC);
+ fcntl(monitor->sig[1], F_SETFD, FD_CLOEXEC);
+ return monitor;
+}
+
+
+void deinit_dirmonitor(struct dirmonitor_internal* monitor) {
+ close(monitor->fd);
+ close(monitor->sig[0]);
+ close(monitor->sig[1]);
+}
+
+
+
+int get_changes_dirmonitor(struct dirmonitor_internal* monitor, char* buffer, int length) {
+ struct pollfd fds[2] = { { .fd = monitor->fd, .events = POLLIN | POLLERR, .revents = 0 }, { .fd = monitor->sig[0], .events = POLLIN | POLLERR, .revents = 0 } };
+ poll(fds, 2, -1);
+ return read(monitor->fd, buffer, length);
+}
+
+
+int translate_changes_dirmonitor(struct dirmonitor_internal* monitor, char* buffer, int length, int (*change_callback)(int, const char*, void*), void* data) {
+ InodeWatcherEvent* event = (InodeWatcherEvent*)buffer;
+ change_callback(event->watch_descriptor, NULL, data);
+ return 0;
+}
+
+
+int add_dirmonitor(struct dirmonitor_internal* monitor, const char* path) {
+ return inode_watcher_add_watch(monitor->fd, path, strlen(path),
+ static_cast<unsigned>(
+ InodeWatcherEvent::Type::MetadataModified |
+ InodeWatcherEvent::Type::ContentModified |
+ InodeWatcherEvent::Type::Deleted |
+ InodeWatcherEvent::Type::ChildCreated |
+ InodeWatcherEvent::Type::ChildDeleted
+ ));
+}
+
+
+void remove_dirmonitor(struct dirmonitor_internal* monitor, int fd) {
+ inode_watcher_remove_watch(monitor->fd, fd);
+}
+
+int get_mode_dirmonitor() { return 2; }
diff --git a/src/main.c b/src/main.c
index dca3cbd1..e11fb7ae 100644
--- a/src/main.c
+++ b/src/main.c
@@ -9,7 +9,7 @@
#ifdef _WIN32
#include <windows.h>
-#elif defined(__linux__)
+#elif defined(__linux__) || defined(__serenity__)
#include <unistd.h>
#elif defined(__APPLE__)
#include <mach-o/dyld.h>
@@ -34,7 +34,7 @@ static void get_exe_filename(char *buf, int sz) {
} else {
buf[0] = '\0';
}
-#elif __linux__
+#elif __linux__ || __serenity__
char path[] = "/proc/self/exe";
ssize_t len = readlink(path, buf, sz - 1);
if (len > 0)
@@ -110,6 +110,9 @@ void set_macos_bundle_resources(lua_State *L);
#define ARCH_PLATFORM "freebsd"
#elif __APPLE__
#define ARCH_PLATFORM "darwin"
+ #elif __serenity__
+ #define ARCH_PLATFORM "serenity"
+ #else
#endif
#if !defined(ARCH_PROCESSOR) || !defined(ARCH_PLATFORM)
diff --git a/src/meson.build b/src/meson.build
index a156ae3f..501914c8 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -11,20 +11,31 @@ lite_sources = [
'main.c',
]
+lite_sources += 'api/dirmonitor.c'
# dirmonitor backend
if get_option('dirmonitor_backend') == ''
if cc.has_function('inotify_init', prefix : '#include<sys/inotify.h>')
dirmonitor_backend = 'inotify'
+ lite_sources += 'api/dirmonitor/inotify.c'
elif host_machine.system() == 'darwin' and cc.check_header('CoreServices/CoreServices.h')
dirmonitor_backend = 'fsevents'
+ lite_sources += 'api/dirmonitor/fsevents.c'
elif cc.has_function('kqueue', prefix : '#include<sys/event.h>')
dirmonitor_backend = 'kqueue'
+ lite_sources += 'api/dirmonitor/kqueue.c'
+ elif cc.has_function('create_inode_watcher', prefix : '#include<fcntl.h>')
+ dirmonitor_backend = 'inodewatcher'
+ add_languages('cpp')
+ lite_sources += 'api/dirmonitor/inodewatcher.cpp'
elif dependency('libkqueue', required : false).found()
dirmonitor_backend = 'kqueue'
+ lite_sources += 'api/dirmonitor/kqueue.c'
elif host_machine.system() == 'windows'
dirmonitor_backend = 'win32'
+ lite_sources += 'api/dirmonitor/win32.c'
else
dirmonitor_backend = 'dummy'
+ lite_sources += 'api/dirmonitor/dummy.c'
warning('no suitable backend found, defaulting to dummy backend')
endif
else
@@ -40,12 +51,6 @@ if dirmonitor_backend == 'kqueue'
endif
endif
-lite_sources += [
- 'api/dirmonitor.c',
- 'api/dirmonitor/' + dirmonitor_backend + '.c',
-]
-
-
lite_rc = []
if host_machine.system() == 'windows'
windows = import('windows')