mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-08 12:19:37 +03:00
146 lines
3.1 KiB
Diff
146 lines
3.1 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Ali Mohammad Pur <ali.mpfard@gmail.com>
|
|
Date: Fri, 9 Jul 2021 05:32:00 +0430
|
|
Subject: [PATCH] build: Add platform-specific stubs and implementations
|
|
|
|
---
|
|
CMakeLists.txt | 2 +
|
|
src/unix/serenity-core.c | 112 +++++++++++++++++++++++++++++++++++++++
|
|
2 files changed, 114 insertions(+)
|
|
create mode 100644 src/unix/serenity-core.c
|
|
|
|
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
|
index d285ed9..10fbd7f 100644
|
|
--- a/CMakeLists.txt
|
|
+++ b/CMakeLists.txt
|
|
@@ -387,9 +387,11 @@ if(CMAKE_SYSTEM_NAME STREQUAL "SerenityOS")
|
|
src/unix/posix-poll.c
|
|
src/unix/no-fsevents.c
|
|
src/unix/no-proctitle.c
|
|
+ src/unix/serenity-core.c
|
|
)
|
|
list(APPEND uv_libraries
|
|
dl
|
|
+ pthread
|
|
)
|
|
endif()
|
|
|
|
diff --git a/src/unix/serenity-core.c b/src/unix/serenity-core.c
|
|
new file mode 100644
|
|
index 0000000..5c34b75
|
|
--- /dev/null
|
|
+++ b/src/unix/serenity-core.c
|
|
@@ -0,0 +1,112 @@
|
|
+#include "uv.h"
|
|
+#include "internal.h"
|
|
+
|
|
+#include <errno.h>
|
|
+#include <stddef.h>
|
|
+
|
|
+#include <net/if.h>
|
|
+#include <unistd.h>
|
|
+
|
|
+static int uv__ifaddr_exclude(void *ent, int exclude_type) {
|
|
+ return 1;
|
|
+}
|
|
+
|
|
+int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
|
|
+ *count = 0;
|
|
+ *addresses = NULL;
|
|
+ return UV_ENOSYS;
|
|
+}
|
|
+
|
|
+
|
|
+void uv_free_interface_addresses(uv_interface_address_t* addresses,
|
|
+ int count) {
|
|
+ int i;
|
|
+
|
|
+ for (i = 0; i < count; i++) {
|
|
+ uv__free(addresses[i].name);
|
|
+ }
|
|
+
|
|
+ uv__free(addresses);
|
|
+}
|
|
+
|
|
+
|
|
+static uint64_t uv__read_proc_memstat(const char* what) {
|
|
+ uint64_t rc;
|
|
+ char* p;
|
|
+ char buf[4096]; /* Large enough to hold all of /sys/kernel/memstat. */
|
|
+
|
|
+ if (uv__slurp("/sys/kernel/memstat", buf, sizeof(buf)))
|
|
+ return 0;
|
|
+
|
|
+ p = strstr(buf, what);
|
|
+
|
|
+ if (p == NULL)
|
|
+ return 0;
|
|
+
|
|
+ p += strlen(what);
|
|
+
|
|
+ rc = 0;
|
|
+ sscanf(p, "%" PRIu64, &rc);
|
|
+
|
|
+ return rc;
|
|
+}
|
|
+
|
|
+uint64_t uv_get_free_memory(void) {
|
|
+ return uv__read_proc_memstat("physical_available\":") * PAGE_SIZE;
|
|
+}
|
|
+
|
|
+
|
|
+uint64_t uv_get_total_memory(void) {
|
|
+ return (uv__read_proc_memstat("physical_allocated\":") + uv__read_proc_memstat("physical_available\":")) * PAGE_SIZE;
|
|
+}
|
|
+
|
|
+void uv_loadavg(double avg[3]) {
|
|
+ avg[0] = 0.0f;
|
|
+ avg[1] = 0.0f;
|
|
+ avg[2] = 0.0f;
|
|
+}
|
|
+
|
|
+int uv_uptime(double* uptime) {
|
|
+ char buf[128];
|
|
+ struct timespec now;
|
|
+ int r;
|
|
+
|
|
+ /* Try /sys/kernel/uptime first, then fallback to clock_gettime(). */
|
|
+
|
|
+ if (0 == uv__slurp("/sys/kernel/uptime", buf, sizeof(buf)))
|
|
+ if (1 == sscanf(buf, "%lf", uptime))
|
|
+ return 0;
|
|
+
|
|
+ r = clock_gettime(CLOCK_MONOTONIC, &now);
|
|
+ if (r)
|
|
+ return UV__ERR(errno);
|
|
+
|
|
+ *uptime = now.tv_sec;
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+uint64_t uv_get_constrained_memory(void) {
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
|
|
+ *cpu_infos = NULL;
|
|
+ *count = 0;
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+int uv_exepath(char* buffer, size_t* size) {
|
|
+ if (buffer == NULL || size == NULL || *size == 0)
|
|
+ return UV_EINVAL;
|
|
+
|
|
+ int rc = readlink("/proc/self/exe", buffer, *size);
|
|
+ if (rc < 0)
|
|
+ return UV__ERR(errno);
|
|
+ *size = rc;
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+int uv_resident_set_memory(size_t* rss) {
|
|
+ *rss = 0;
|
|
+ return 0;
|
|
+}
|