aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrobot-piglet <robot-piglet@yandex-team.com>2024-12-13 03:38:20 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2024-12-13 03:55:10 +0300
commita864d36d55be6929a4740bb959e3b26494c6ec38 (patch)
tree0dbde31c2bd1d527a0a14f8d74450654f781fd71
parent13699b122802fe0561998ebdf36e6eb97cdcad13 (diff)
downloadydb-a864d36d55be6929a4740bb959e3b26494c6ec38.tar.gz
Intermediate changes
commit_hash:7261fd77a0ee849dc03daf29163ac3a7780ec1d6
-rw-r--r--yql/essentials/utils/oom_helper/inject.cpp48
-rw-r--r--yql/essentials/utils/oom_helper/ya.make8
-rw-r--r--yql/essentials/utils/ya.make1
3 files changed, 57 insertions, 0 deletions
diff --git a/yql/essentials/utils/oom_helper/inject.cpp b/yql/essentials/utils/oom_helper/inject.cpp
new file mode 100644
index 0000000000..089d1a3b24
--- /dev/null
+++ b/yql/essentials/utils/oom_helper/inject.cpp
@@ -0,0 +1,48 @@
+#include <unistd.h>
+#include <sys/mman.h>
+#include <errno.h>
+#include <stdint.h>
+#include <limits.h>
+#include <stdio.h>
+#include <sys/syscall.h>
+
+
+#define SYSCALL_MMAP2_UNIT 4096ULL
+#define UNIT SYSCALL_MMAP2_UNIT
+#define OFF_MASK ((-0x2000ULL << (8*sizeof(long)-1)) | (UNIT-1))
+
+void *__mmap(void *start, size_t len, int prot, int flags, int fd, off_t off)
+{
+ void* ret = (void*)-1;
+ if (off & OFF_MASK) {
+ errno = EINVAL;
+ return ret;
+ }
+ if (len >= PTRDIFF_MAX) {
+ errno = ENOMEM;
+ return ret;
+ }
+#ifdef SYS_mmap2
+ ret = (void*)syscall(SYS_mmap2, start, len, prot, flags, fd, off/UNIT);
+#else
+ ret = (void*)syscall(SYS_mmap, start, len, prot, flags, fd, off);
+#endif
+ /* Fixup incorrect EPERM from kernel. */
+ if (ret == (void*)-1 && errno == EPERM && !start && (flags & MAP_ANON) && !(flags & MAP_FIXED)) {
+ errno = ENOMEM;
+ return (void*)-1;
+ }
+
+ return ret;
+}
+
+
+void *mmap(void *start, size_t len, int prot, int flags, int fd, off_t off)
+{
+ auto res = __mmap(start, len, prot, flags, fd, off);
+ if (res == (void*) -1 && errno == ENOMEM) {
+ fprintf(stderr, "mmap failed with ENOMEM\n");
+ _exit(2);
+ }
+ return res;
+}
diff --git a/yql/essentials/utils/oom_helper/ya.make b/yql/essentials/utils/oom_helper/ya.make
new file mode 100644
index 0000000000..6049debee4
--- /dev/null
+++ b/yql/essentials/utils/oom_helper/ya.make
@@ -0,0 +1,8 @@
+IF (OS_LINUX)
+ LIBRARY(oom_helper)
+ SRCS(inject.cpp)
+ END()
+ELSE()
+ LIBRARY()
+ END()
+ENDIF()
diff --git a/yql/essentials/utils/ya.make b/yql/essentials/utils/ya.make
index 768c5538b9..e42fe3e369 100644
--- a/yql/essentials/utils/ya.make
+++ b/yql/essentials/utils/ya.make
@@ -63,6 +63,7 @@ IF (OPENSOURCE_PROJECT != "yt")
log
memory_profiling
network
+ oom_helper
signals
sys
test_http_server