Skip to content

Commit 8b294b2

Browse files
committed
Add missing files.2
1 parent 44374b5 commit 8b294b2

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

src/redirect/generate.cc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include "snmalloc.h"
2+
3+
#include <fstream>
4+
#include <iostream>
5+
6+
int main(int argc, char* argv[])
7+
{
8+
if (argc != 2)
9+
{
10+
std::cerr << "Call with output file name" << std::endl;
11+
return 1;
12+
}
13+
14+
// open a file in write mode.
15+
ofstream outfile;
16+
outfile.open(argv[1]);
17+
18+
for (size_t size = 1024; size > 0; size -= 16)
19+
{
20+
auto sizeclass = snmalloc::size_to_sizeclass(size);
21+
auto rsize = snmalloc::sizeclass_to_size(sizeclass);
22+
if (rsize == size)
23+
{
24+
outfile << "DEFINE_MALLOC_SIZE(malloc_size_" << size << ", " << size
25+
<< ");" << std::endl;
26+
}
27+
else
28+
{
29+
outfile << "REDIRECT_MALLOC_SIZE(malloc_size_" << size << ", malloc_size_"
30+
<< rsize << ");" << std::endl;
31+
}
32+
}
33+
34+
outfile.close();
35+
}

src/redirect/redirect.cc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
#include "snmalloc.h"
3+
4+
#define NAME(a) malloc_size_##a
5+
#define STRINGIFY(a) a
6+
#define NAME_STRING(a) NAME(a)
7+
8+
#ifdef WIN32
9+
# define REDIRECT_MALLOC_SIZE(a, b) \
10+
extern "C" void* NAME(a)(); \
11+
__pragma(comment(linker, "/alternatename:malloc_size_##a=malloc_size_##b"))
12+
#else
13+
# define REDIRECT_MALLOC_SIZE(a, b) \
14+
__attribute__((alias(#b))) extern "C" void* a()
15+
#endif
16+
17+
#define DEFINE_MALLOC_SIZE(a, s) \
18+
extern "C" void* a() \
19+
{ \
20+
return snmalloc::ThreadAlloc::get_noncachable()->template alloc<s>(); \
21+
}
22+
23+
#include "generated.cc"

0 commit comments

Comments
 (0)