Skip to content

Commit f14fe99

Browse files
committed
refactor Memory manager
1 parent 3b3868a commit f14fe99

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

Source/Library/MemoryManager.cpp

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <setjmp.h>
22

3-
#include "DetectOs.hpp"
43
#include "MemoryManager.hpp"
4+
#include "DetectOs.hpp"
55

66
#ifdef WINDOWS
77

@@ -10,15 +10,9 @@
1010
#include <processthreadsapi.h>
1111

1212
#endif
13-
1413
#ifdef LINUX
15-
#include <iostream>
14+
1615
#include <pthread.h>
17-
#include <stdio.h>
18-
#include <stdlib.h>
19-
#include <string.h>
20-
#include <termios.h>
21-
#include <unistd.h>
2216

2317
#endif
2418

@@ -34,35 +28,34 @@ namespace sd
3428
{
3529
intptr_t *rsp;
3630
__READ_RSP(rsp);
37-
return rsp;
31+
return (uint8_t *)rsp;
3832
}
3933

40-
auto makeStackInfo(uint8_t *top, uint8_t *bot) { return std::make_tuple(top, bot, (uint8_t *)getStackRsp()); }
4134
#ifdef WINDOWS
4235

4336
auto getStackBounds()
4437
{
38+
auto rsp = getStackRsp();
4539
ULONG_PTR lowLimit, highLimit;
4640
GetCurrentThreadStackLimits(&lowLimit, &highLimit);
4741

48-
return makeStackInfo((uint8_t *)highLimit - 10, (uint8_t *)lowLimit);
42+
return std::make_tuple((uint8_t *)highLimit - 10, (uint8_t *)lowLimit, rsp);
4943
}
50-
51-
#elif LINUX
44+
#endif
45+
#ifdef LINUX
5246

5347
auto getStackBounds()
5448
{
49+
auto rsp = getStackRsp();
5550
pthread_attr_t attrs;
5651
pthread_getattr_np(pthread_self(), &attrs);
5752
void *stack_ptr;
5853
size_t stack_size;
5954
pthread_attr_getstack(&attrs, &stack_ptr, &stack_size);
60-
void *lowLimit = stack_ptr, highLimit = stack_ptr + stack_size - 10;
6155

62-
return makeStackInfo((uint8_t *)highLimit, (uint8_t *)lowLimit);
56+
return std::make_tuple((uint8_t *)stack_ptr + stack_size - 10, (uint8_t *)stack_ptr, rsp);
6357
}
6458
#endif
65-
6659
} // namespace
6760

6861
MemoryManager &MemoryManager::instance()

0 commit comments

Comments
 (0)