Skip to content

Commit 0bcfcc0

Browse files
committed
Returned util
1 parent ab43cd3 commit 0bcfcc0

File tree

878 files changed

+120573
-242
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

878 files changed

+120573
-242
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ include(cmake/external_libs.cmake)
4040
add_subdirectory(tools)
4141
add_subdirectory(contrib)
4242
add_subdirectory(src)
43+
add_subdirectory(util)
4344

4445
if (YDB_SDK_EXAMPLES)
4546
add_subdirectory(examples)

cmake/public_headers.txt

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
util/datetime/base.h
2+
util/datetime/systime.h
3+
util/digest/multi.h
4+
util/digest/numeric.h
5+
util/digest/sequence.h
6+
util/generic/algorithm.h
7+
util/generic/array_size.h
8+
util/generic/bt_exception.h
9+
util/generic/cast.h
10+
util/generic/flags.h
11+
util/generic/function.h
12+
util/generic/fwd.h
13+
util/generic/is_in.h
14+
util/generic/iterator_range.h
15+
util/generic/noncopyable.h
16+
util/generic/ptr.h
17+
util/generic/refcount.h
18+
util/generic/singleton.h
19+
util/generic/size_literals.h
20+
util/generic/store_policy.h
21+
util/generic/string_hash.h
22+
util/generic/typelist.h
23+
util/generic/typetraits.h
24+
util/generic/utility.h
25+
util/generic/va_args.h
26+
util/generic/xrange.h
27+
util/generic/yexception.h
28+
util/generic/ylimits.h
29+
util/memory/alloc.h
30+
util/memory/blob.h
31+
util/memory/tempbuf.h
32+
util/network/address.h
33+
util/network/hostip.h
34+
util/network/init.h
35+
util/network/ip.h
36+
util/network/sock.h
37+
util/network/socket.h
38+
util/random/random.h
39+
util/stream/debug.h
40+
util/stream/fwd.h
41+
util/stream/input.h
42+
util/stream/mem.h
43+
util/stream/output.h
44+
util/stream/str.h
45+
util/stream/tempbuf.h
46+
util/stream/zerocopy_output.h
47+
util/stream/zerocopy.h
48+
util/string/ascii.h
49+
util/string/builder.h
50+
util/string/cast.h
51+
util/string/escape.h
52+
util/string/strip.h
53+
util/string/subst.h
54+
util/system/atexit.h
55+
util/system/backtrace.h
56+
util/system/byteorder.h
57+
util/system/compat.h
58+
util/system/compiler.h
59+
util/system/defaults.h
60+
util/system/error.h
61+
util/system/event.h
62+
util/system/fhandle.h
63+
util/system/file.h
64+
util/system/flock.h
65+
util/system/guard.h
66+
util/system/maxlen.h
67+
util/system/platform.h
68+
util/system/progname.h
69+
util/system/rwlock.h
70+
util/system/spin_wait.h
71+
util/system/spinlock.h
72+
util/system/src_location.h
73+
util/system/src_root.h
74+
util/system/sysstat.h
75+
util/system/type_name.h
76+
util/system/types.h
77+
util/system/unaligned_mem.h
78+
util/system/win_undef.h
79+
util/system/winint.h
80+
util/system/yassert.h
81+
util/thread/factory.h
82+
util/thread/pool.h
83+
util/str_stl.h
84+
util/ysaveload.h

contrib/libs/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
add_subdirectory(libc_compat)
12
add_subdirectory(lzmasdk)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
add_library(contrib-libs-libc_compat)
2+
3+
target_compile_options(contrib-libs-libc_compat PRIVATE
4+
$<IF:$<CXX_COMPILER_ID:MSVC>,,-Wno-everything>
5+
)
6+
7+
target_include_directories(contrib-libs-libc_compat PUBLIC
8+
${YDB_SDK_SOURCE_DIR}/contrib/libs/libc_compat/include/readpassphrase
9+
${YDB_SDK_SOURCE_DIR}/contrib/libs/libc_compat/reallocarray
10+
${YDB_SDK_SOURCE_DIR}/contrib/libs/libc_compat/random
11+
)
12+
13+
target_sources(contrib-libs-libc_compat PRIVATE
14+
${YDB_SDK_SOURCE_DIR}/contrib/libs/libc_compat/string.c
15+
${YDB_SDK_SOURCE_DIR}/contrib/libs/libc_compat/readpassphrase.c
16+
${YDB_SDK_SOURCE_DIR}/contrib/libs/libc_compat/explicit_bzero.c
17+
${YDB_SDK_SOURCE_DIR}/contrib/libs/libc_compat/memfd_create.c
18+
${YDB_SDK_SOURCE_DIR}/contrib/libs/libc_compat/strlcat.c
19+
${YDB_SDK_SOURCE_DIR}/contrib/libs/libc_compat/strlcpy.c
20+
${YDB_SDK_SOURCE_DIR}/contrib/libs/libc_compat/reallocarray/reallocarray.c
21+
${YDB_SDK_SOURCE_DIR}/contrib/libs/libc_compat/random/getrandom.c
22+
${YDB_SDK_SOURCE_DIR}/contrib/libs/libc_compat/random/getentropy.c
23+
)

contrib/libs/libc_compat/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
This library implements a compatibility layer between various libc implementations.
2+
3+
The rationale for the library implementation is described in https://st.yandex-team.ru/IGNIETFERRO-1439.
4+
5+
The code is taken from multiple sources, thus both LICENSE() and VERSION() tags are not very representative.
6+
7+
8+
During development one can make use of the following mapping of `OS_SDK` into glibc version.
9+
10+
| Ubuntu | glibc |
11+
| ------ | ----- |
12+
| 20.04 | 2.30 |
13+
| 18.04 | 2.27 |
14+
| 16.04 | 2.23 |
15+
| 14.04 | 2.18 |
16+
| 12.04 | 2.15 |
17+
| 10.04 | 2.11 |
18+
19+
Use the following commands to update the table above:
20+
21+
1. `ya make util -DOS_SDK=ubuntu-xx -G | grep OS_SDK_ROOT | head -n 1`
22+
2. `cd ~/.ya/tools/v4/$RESOURCE_ID`
23+
3. `readelf -V $(find . -name 'libc.so.6')`
24+
4. Take the latest version from `.gnu.version_d` section prior to `GLIBC_PRIVATE`
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* explicit_bzero.c
4+
*
5+
* Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
6+
* Portions Copyright (c) 1994, Regents of the University of California
7+
*
8+
*
9+
* IDENTIFICATION
10+
* src/port/explicit_bzero.c
11+
*
12+
*-------------------------------------------------------------------------
13+
*/
14+
15+
#include <stddef.h>
16+
#include <string.h>
17+
18+
#if defined(HAVE_MEMSET_S)
19+
20+
void
21+
explicit_bzero(void *buf, size_t len)
22+
{
23+
(void) memset_s(buf, len, 0, len);
24+
}
25+
26+
#elif defined(WIN32)
27+
28+
#include <Windows.h>
29+
30+
void
31+
explicit_bzero(void *buf, size_t len)
32+
{
33+
(void) SecureZeroMemory(buf, len);
34+
}
35+
36+
#else
37+
38+
/*
39+
* Indirect call through a volatile pointer to hopefully avoid dead-store
40+
* optimisation eliminating the call. (Idea taken from OpenSSH.) We can't
41+
* assume bzero() is present either, so for simplicity we define our own.
42+
*/
43+
44+
static void
45+
bzero2(void *buf, size_t len)
46+
{
47+
memset(buf, 0, len);
48+
}
49+
50+
static void (*volatile bzero_p) (void *, size_t) = bzero2;
51+
52+
void
53+
explicit_bzero(void *buf, size_t len)
54+
{
55+
bzero_p(buf, len);
56+
}
57+
58+
#endif
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <netdb.h>
2+
3+
struct servent *getservbyname(const char *name, const char *prots)
4+
{
5+
static struct servent se;
6+
static char *buf[2];
7+
struct servent *res;
8+
if (getservbyname_r(name, prots, &se, (void *)buf, sizeof buf, &res))
9+
return 0;
10+
return &se;
11+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#define _GNU_SOURCE
2+
#include <sys/socket.h>
3+
#include <netinet/in.h>
4+
#include <netdb.h>
5+
#include <inttypes.h>
6+
#include <errno.h>
7+
#include <string.h>
8+
#include <stdlib.h>
9+
#include "lookup.h"
10+
11+
#define ALIGN (sizeof(struct { char a; char *b; }) - sizeof(char *))
12+
13+
int getservbyname_r(const char *name, const char *prots,
14+
struct servent *se, char *buf, size_t buflen, struct servent **res)
15+
{
16+
struct service servs[MAXSERVS];
17+
int cnt, proto, align;
18+
19+
*res = 0;
20+
21+
/* Don't treat numeric port number strings as service records. */
22+
char *end = "";
23+
strtoul(name, &end, 10);
24+
if (!*end) return ENOENT;
25+
26+
/* Align buffer */
27+
align = -(uintptr_t)buf & ALIGN-1;
28+
if (buflen < 2*sizeof(char *)+align)
29+
return ERANGE;
30+
buf += align;
31+
32+
if (!prots) proto = 0;
33+
else if (!strcmp(prots, "tcp")) proto = IPPROTO_TCP;
34+
else if (!strcmp(prots, "udp")) proto = IPPROTO_UDP;
35+
else return EINVAL;
36+
37+
cnt = __lookup_serv(servs, name, proto, 0, 0);
38+
if (cnt<0) switch (cnt) {
39+
case EAI_MEMORY:
40+
case EAI_SYSTEM:
41+
return ENOMEM;
42+
default:
43+
return ENOENT;
44+
}
45+
46+
se->s_name = (char *)name;
47+
se->s_aliases = (void *)buf;
48+
se->s_aliases[0] = se->s_name;
49+
se->s_aliases[1] = 0;
50+
se->s_port = htons(servs[0].port);
51+
se->s_proto = servs[0].proto == IPPROTO_TCP ? "tcp" : "udp";
52+
53+
*res = se;
54+
return 0;
55+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#ifndef LOOKUP_H
2+
#define LOOKUP_H
3+
4+
#include <stdint.h>
5+
#include <stddef.h>
6+
#include <features.h>
7+
#include <netinet/in.h>
8+
#include <netdb.h>
9+
10+
#define hidden __attribute__((__visibility__("hidden")))
11+
12+
struct aibuf {
13+
struct addrinfo ai;
14+
union sa {
15+
struct sockaddr_in sin;
16+
struct sockaddr_in6 sin6;
17+
} sa;
18+
volatile int lock[1];
19+
short slot, ref;
20+
};
21+
22+
struct address {
23+
int family;
24+
unsigned scopeid;
25+
uint8_t addr[16];
26+
int sortkey;
27+
};
28+
29+
struct service {
30+
uint16_t port;
31+
unsigned char proto, socktype;
32+
};
33+
34+
#define MAXNS 3
35+
36+
struct resolvconf {
37+
struct address ns[MAXNS];
38+
unsigned nns, attempts, ndots;
39+
unsigned timeout;
40+
};
41+
42+
/* The limit of 48 results is a non-sharp bound on the number of addresses
43+
* that can fit in one 512-byte DNS packet full of v4 results and a second
44+
* packet full of v6 results. Due to headers, the actual limit is lower. */
45+
#define MAXADDRS 48
46+
#define MAXSERVS 2
47+
48+
hidden int __lookup_serv(struct service buf[static MAXSERVS], const char *name, int proto, int socktype, int flags);
49+
hidden int __lookup_name(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family, int flags);
50+
hidden int __lookup_ipliteral(struct address buf[static 1], const char *name, int family);
51+
52+
hidden int __get_resolv_conf(struct resolvconf *, char *, size_t);
53+
hidden int __res_msend_rc(int, const unsigned char *const *, const int *, unsigned char *const *, int *, int, const struct resolvconf *);
54+
55+
hidden int __dns_parse(const unsigned char *, int, int (*)(void *, int, const void *, int, const void *), void *);
56+
57+
#endif

0 commit comments

Comments
 (0)