aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/malloc/api
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/malloc/api
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/malloc/api')
-rw-r--r--library/cpp/malloc/api/helpers/io.cpp10
-rw-r--r--library/cpp/malloc/api/helpers/ya.make13
-rw-r--r--library/cpp/malloc/api/malloc.cpp37
-rw-r--r--library/cpp/malloc/api/malloc.h32
-rw-r--r--library/cpp/malloc/api/ut/ut.cpp10
-rw-r--r--library/cpp/malloc/api/ut/ya.make13
-rw-r--r--library/cpp/malloc/api/ya.make11
7 files changed, 126 insertions, 0 deletions
diff --git a/library/cpp/malloc/api/helpers/io.cpp b/library/cpp/malloc/api/helpers/io.cpp
new file mode 100644
index 0000000000..5177969f4d
--- /dev/null
+++ b/library/cpp/malloc/api/helpers/io.cpp
@@ -0,0 +1,10 @@
+#include <library/cpp/malloc/api/malloc.h>
+
+#include <util/stream/output.h>
+
+using namespace NMalloc;
+
+template <>
+void Out<TMallocInfo>(IOutputStream& out, const TMallocInfo& info) {
+ out << "malloc (name = " << info.Name << ")";
+}
diff --git a/library/cpp/malloc/api/helpers/ya.make b/library/cpp/malloc/api/helpers/ya.make
new file mode 100644
index 0000000000..62875bca0e
--- /dev/null
+++ b/library/cpp/malloc/api/helpers/ya.make
@@ -0,0 +1,13 @@
+LIBRARY()
+
+OWNER(pg)
+
+PEERDIR(
+ library/cpp/malloc/api
+)
+
+SRCS(
+ io.cpp
+)
+
+END()
diff --git a/library/cpp/malloc/api/malloc.cpp b/library/cpp/malloc/api/malloc.cpp
new file mode 100644
index 0000000000..eed1c58a38
--- /dev/null
+++ b/library/cpp/malloc/api/malloc.cpp
@@ -0,0 +1,37 @@
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "malloc.h"
+
+namespace {
+ bool SetEmptyParam(const char*, const char*) {
+ return false;
+ }
+
+ const char* GetEmptyParam(const char*) {
+ return nullptr;
+ }
+
+ bool CheckEmptyParam(const char*, bool defaultValue) {
+ return defaultValue;
+ }
+}
+
+namespace NMalloc {
+ volatile bool IsAllocatorCorrupted = false;
+
+ TMallocInfo::TMallocInfo()
+ : Name()
+ , SetParam(SetEmptyParam)
+ , GetParam(GetEmptyParam)
+ , CheckParam(CheckEmptyParam)
+ {
+ }
+
+ void AbortFromCorruptedAllocator(const char* errorMessage) {
+ errorMessage = errorMessage ? errorMessage : "<unspecified>";
+ fprintf(stderr, "Allocator error: %s\n", errorMessage);
+ IsAllocatorCorrupted = true;
+ abort();
+ }
+}
diff --git a/library/cpp/malloc/api/malloc.h b/library/cpp/malloc/api/malloc.h
new file mode 100644
index 0000000000..ebd545d6dd
--- /dev/null
+++ b/library/cpp/malloc/api/malloc.h
@@ -0,0 +1,32 @@
+#pragma once
+
+#include <string.h>
+#include <util/system/compiler.h>
+
+namespace NMalloc {
+ struct TMallocInfo {
+ TMallocInfo();
+
+ const char* Name;
+
+ bool (*SetParam)(const char* param, const char* value);
+ const char* (*GetParam)(const char* param);
+
+ bool (*CheckParam)(const char* param, bool defaultValue);
+ };
+
+ extern volatile bool IsAllocatorCorrupted;
+ void AbortFromCorruptedAllocator(const char* errorMessage = nullptr);
+
+ // this function should be implemented by malloc implementations
+ TMallocInfo MallocInfo();
+
+ struct TAllocHeader {
+ void* Block;
+ size_t AllocSize;
+ void Y_FORCE_INLINE Encode(void* block, size_t size, size_t signature) {
+ Block = block;
+ AllocSize = size | signature;
+ }
+ };
+}
diff --git a/library/cpp/malloc/api/ut/ut.cpp b/library/cpp/malloc/api/ut/ut.cpp
new file mode 100644
index 0000000000..7eccd0bf8d
--- /dev/null
+++ b/library/cpp/malloc/api/ut/ut.cpp
@@ -0,0 +1,10 @@
+#include <library/cpp/testing/unittest/registar.h>
+
+#include <library/cpp/malloc/api/malloc.h>
+
+Y_UNIT_TEST_SUITE(MallocApi) {
+ Y_UNIT_TEST(ToStream) {
+ TStringStream ss;
+ ss << NMalloc::MallocInfo();
+ }
+}
diff --git a/library/cpp/malloc/api/ut/ya.make b/library/cpp/malloc/api/ut/ya.make
new file mode 100644
index 0000000000..e57225b45d
--- /dev/null
+++ b/library/cpp/malloc/api/ut/ya.make
@@ -0,0 +1,13 @@
+UNITTEST()
+
+OWNER(nga)
+
+PEERDIR(
+ library/cpp/malloc/api/helpers
+)
+
+SRCS(
+ ut.cpp
+)
+
+END()
diff --git a/library/cpp/malloc/api/ya.make b/library/cpp/malloc/api/ya.make
new file mode 100644
index 0000000000..0ebaa0c589
--- /dev/null
+++ b/library/cpp/malloc/api/ya.make
@@ -0,0 +1,11 @@
+LIBRARY()
+
+NO_UTIL()
+
+OWNER(nga)
+
+SRCS(
+ malloc.cpp
+)
+
+END()