Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/SoftEtherVPN/SoftEtherVPN_Stable.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/Mayaqua/Memory.h')
-rw-r--r--src/Mayaqua/Memory.h43
1 files changed, 31 insertions, 12 deletions
diff --git a/src/Mayaqua/Memory.h b/src/Mayaqua/Memory.h
index 1e71b72d..7ee137b3 100644
--- a/src/Mayaqua/Memory.h
+++ b/src/Mayaqua/Memory.h
@@ -109,16 +109,20 @@
#define MallocFast Malloc
#define ZeroMallocFast ZeroMalloc
+#define MAX_MALLOC_MEM_SIZE (0xffffffff - 64)
+
// Memory size that can be passed to the kernel at a time
#define MAX_SEND_BUF_MEM_SIZE (10 * 1024 * 1024)
-// The magic number for memory tag
-#define MEMTAG_MAGIC 0x49414449
+#define CALC_MALLOCSIZE(size) (((MAX(size, 1) + 7) / 8) * 8 + sizeof(MEMTAG1) + sizeof(MEMTAG2))
+#define MEMTAG1_TO_POINTER(p) ((void *)(((UCHAR *)(p)) + sizeof(MEMTAG1)))
+#define POINTER_TO_MEMTAG1(p) ((MEMTAG1 *)(((UCHAR *)(p)) - sizeof(MEMTAG1)))
+#define IS_NULL_POINTER(p) (((p) == NULL) || ((POINTER_TO_UINT64(p) == (UINT64)sizeof(MEMTAG1))))
-#define CALC_MALLOCSIZE(size) ((MAX(size, 1)) + sizeof(MEMTAG))
-#define MEMTAG_TO_POINTER(p) ((void *)(((UCHAR *)(p)) + sizeof(MEMTAG)))
-#define POINTER_TO_MEMTAG(p) ((MEMTAG *)(((UCHAR *)(p)) - sizeof(MEMTAG)))
-#define IS_NULL_POINTER(p) (((p) == NULL) || ((POINTER_TO_UINT64(p) == (UINT64)sizeof(MEMTAG))))
+// Golden Ratio Prime
+// From https://github.com/torvalds/linux/blob/88c5083442454e5e8a505b11fa16f32d2879651e/include/linux/hash.h
+#define GOLDEN_RATION_PRIME_U32 ((UINT32)0x61C88647)
+#define GOLDEN_RATION_PRIME_U64 ((UINT64)7046029254386353131ULL) // 0x61C8864680B583EB
// Fixed size of a block of memory pool
#define MEMPOOL_MAX_SIZE 3000
@@ -126,14 +130,18 @@
// Active patch
#define MAX_ACTIVE_PATCH 1024
-
-// Memory tag
-struct MEMTAG
+// Memory tag 1
+struct MEMTAG1
{
- UINT Magic;
+ UINT64 Magic;
UINT Size;
bool ZeroFree;
- UINT Padding;
+};
+
+// Memory tag 2
+struct MEMTAG2
+{
+ UINT64 Magic;
};
// Buffer
@@ -299,7 +307,8 @@ void *ZeroMalloc(UINT size);
void *ZeroMallocEx(UINT size, bool zero_clear_when_free);
void *ReAlloc(void *addr, UINT size);
void Free(void *addr);
-void CheckMemTag(MEMTAG *tag);
+void CheckMemTag1(MEMTAG1 *tag);
+void CheckMemTag2(MEMTAG2 *tag);
UINT GetMemSize(void *addr);
void *InternalMalloc(UINT size);
@@ -540,5 +549,15 @@ UINT* GenerateShuffleListWithSeed(UINT num, void* seed, UINT seed_size);
void Shuffle(UINT* array, UINT size);
void ShuffleWithSeed(UINT* array, UINT size, void* seed, UINT seed_size);
+#define NUM_CANARY_RAND 32
+#define CANARY_RAND_ID_MEMTAG_MAGIC 0
+#define CANARY_RAND_ID_PTR_KEY_HASH 1
+#define CANARY_RAND_SIZE 20
+
+
+
+void InitCanaryRand();
+UCHAR *GetCanaryRand(UINT id);
+
#endif // MEMORY_H