-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsdrad_heap_mng.c
571 lines (460 loc) · 18.8 KB
/
sdrad_heap_mng.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
/**
* @file sdrad_heap_mng.c
* @author Merve Gulmez
* @brief This folder contains the memory management of SDRaD
* @version 0.1
* @date 2022-02-07
*
* @copyright © Ericsson AB 2022-2023
*
* SPDX-License-Identifier: BSD 3-Clause
*/
#define _GNU_SOURCE
#include <unistd.h>
#include <sys/syscall.h>
#include <sys/mman.h>
#include <assert.h>
#include "stdbool.h"
#include <setjmp.h>
#include <stddef.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <signal.h>
#include <sys/param.h>
#include <sys/resource.h>
#include <sys/uio.h>
#include <ctype.h>
#include <stdarg.h>
#include <string.h>
#include <pthread.h>
#include <sys/resource.h>
#include "sdrad.h"
#include "sdrad_pkey.h"
#include "sdrad_thread.h"
#include "tlsf.h"
#include "sdrad_heap_mng.h"
#include "sdrad_api.h"
#ifdef SDRAD_MULTITHREAD
__thread tlsf_t tlsf_structure;
#else
tlsf_t tlsf_structure;
#endif
/* Wrapping glibc realloc with tlsf version */
void *realloc(void *ptr, size_t size)
{
sdrad_thread_metadata_t *stm_ptr;
sdrad_d_info_t *sdi_ptr;
sdrad_global_manager_t *sgm_ptr;
int32_t active_domain;
if (tlsf_structure == NULL){
sdrad_store_pkru_config(PKRU_ALL_UNSET); //can access all domain
sgm_ptr = (sdrad_global_manager_t *)&sdrad_global_manager;
//Get STI from TDI
int32_t thread_index = sdrad_get_sti(sgm_ptr);
stm_ptr = sgm_ptr -> stm_ptr[thread_index];
// Get the active domain
active_domain = stm_ptr -> active_domain;
sdi_ptr = (sdrad_d_info_t *)&stm_ptr -> sdrad_d_info[active_domain];
sdrad_heap_domain_init(sdi_ptr, sgm_ptr-> pdi[active_domain]);
tlsf_structure = sdi_ptr -> sdi_tlsf;
sdrad_store_pkru_config(stm_ptr-> pkru_config[active_domain]);
}
ptr = tlsf_realloc(tlsf_structure, ptr, size);
return ptr;
}
void free(void *ptr)
{
sdrad_d_info_t *sdi_ptr;
sdrad_global_manager_t *sgm_ptr;
sdrad_thread_metadata_t *stm_ptr;
int32_t active_domain;
if (tlsf_structure == NULL){
sdrad_store_pkru_config(PKRU_ALL_UNSET); //can access all domain
sgm_ptr = (sdrad_global_manager_t *)&sdrad_global_manager;
//Get STI from TDI
int32_t thread_index = sdrad_get_sti(sgm_ptr);
stm_ptr = sgm_ptr -> stm_ptr[thread_index];
// Get the active domain
active_domain = stm_ptr -> active_domain;
sdi_ptr = (sdrad_d_info_t *)&stm_ptr -> sdrad_d_info[active_domain];
sdrad_heap_domain_init(sdi_ptr, sgm_ptr-> pdi[active_domain]);
tlsf_structure = sdi_ptr -> sdi_tlsf;
sdrad_store_pkru_config(stm_ptr-> pkru_config[active_domain]);
}
tlsf_free(tlsf_structure, ptr);
}
int posix_memalign(void **memptr, size_t alignment, size_t size)
{
sdrad_global_manager_t *sgm_ptr;
sdrad_thread_metadata_t *stm_ptr, *stm_parent_ptr;
sdrad_d_info_t *sdi_ptr, *shm_parent_ptr;
int32_t parent_domain_sti;
void *ptr;
int32_t sdi;
int32_t active_domain;
if (tlsf_structure == NULL){
sdrad_store_pkru_config(PKRU_ALL_UNSET); //can access all domain
sgm_ptr = (sdrad_global_manager_t *)&sdrad_global_manager;
//Get STI from TDI
int32_t thread_index = sdrad_get_sti(sgm_ptr);
stm_ptr = sgm_ptr -> stm_ptr[thread_index];
// Get the active domain
active_domain = stm_ptr -> active_domain;
sdi_ptr = (sdrad_d_info_t *)&stm_ptr -> sdrad_d_info[active_domain];
sdrad_heap_domain_init(sdi_ptr, sgm_ptr-> pdi[active_domain]);
tlsf_structure = sdi_ptr -> sdi_tlsf;
sdrad_store_pkru_config(stm_ptr-> pkru_config[active_domain]);
}
ptr = tlsf_memalign(tlsf_structure, alignment, size);
*memptr = ptr;
return 0; //tlsf_memalign doesn't have any zero code
}
/*
void *malloc(size_t size);
void *malloc(size_t size)
{
sdrad_thread_metadata_t *stm_ptr;
sdrad_d_info_t *sdi_ptr;
sdrad_global_manager_t *sgm_ptr;
int32_t active_domain;
void *ptr;
void *mmap_new_area;
sdrad_store_pkru_config(PKRU_ALL_UNSET); //can access all domain
sgm_ptr = (sdrad_global_manager_t *)&sdrad_global_manager;
//Get STI from TDI
int32_t thread_index = sdrad_get_sti(sgm_ptr);
stm_ptr = sgm_ptr -> stm_ptr[thread_index];
// Get the active domain
active_domain = stm_ptr -> active_domain;
sdi_ptr = (sdrad_d_info_t *)&stm_ptr -> sdrad_d_info[active_domain];
if (sdi_ptr -> sdi_init_heap_flag == false){
sdrad_heap_domain_init(sdi_ptr, sgm_ptr-> pdi[active_domain]);
}
ptr = tlsf_malloc(sdi_ptr -> sdi_tlsf, size);
// return to old pkru value
sdrad_store_pkru_config(stm_ptr-> pkru_config[active_domain]);
return ptr;
}
*/
void* (*real_malloc)(size_t) = NULL;
void *malloc(size_t size);
void *malloc(size_t size)
{
sdrad_thread_metadata_t *stm_ptr;
sdrad_d_info_t *sdi_ptr;
sdrad_global_manager_t *sgm_ptr;
sdrad_monitor_domain_t *smd_ptr;
int32_t active_domain;
void *ptr;
void *mmap_new_area;
if (tlsf_structure == NULL){ // RUST IMPLEMENTATION
sdrad_store_pkru_config(PKRU_ALL_UNSET); //can access all domain
sgm_ptr = (sdrad_global_manager_t *)&sdrad_global_manager;
if(sdrad_constructor_flag == false){
smd_ptr = (sdrad_monitor_domain_t *)&sgm_ptr -> sdrad_monitor_domain;
/* Create Monitor Data Domain */
smd_ptr -> smd_monitor_sdi = sdrad_create_monitor_domain();
/* Mapping TID (Thread ID) to STI (SDRoB Thread Index). */
sgm_ptr -> sgm_thread_id[ROOT_DOMAIN] = pthread_self();
sgm_ptr -> sgm_sdi_to_tdi[ROOT_DOMAIN] = ROOT_DOMAIN;
sgm_ptr -> sgm_total_thread = ROOT_DOMAIN;
sgm_ptr -> stm_ptr[sgm_ptr -> sgm_total_thread] = sdrad_malloc_mdd(sizeof(sdrad_thread_metadata_t));
stm_ptr = sgm_ptr -> stm_ptr[sgm_ptr -> sgm_total_thread];
stm_ptr -> active_domain = ROOT_DOMAIN;
sdrad_constructor_flag = true;
}
//Get STI from TDI
int32_t thread_index = sdrad_get_sti(sgm_ptr);
stm_ptr = sgm_ptr -> stm_ptr[thread_index];
// Get the active domain
active_domain = stm_ptr -> active_domain;
sdi_ptr = (sdrad_d_info_t *)&stm_ptr -> sdrad_d_info[active_domain];
sdrad_heap_domain_init(sdi_ptr, sgm_ptr-> pdi[active_domain]);
tlsf_structure = sdi_ptr -> sdi_tlsf;
sdrad_store_pkru_config(stm_ptr-> pkru_config[active_domain]);
}
ptr = tlsf_malloc(tlsf_structure, size);
return ptr;
}
void *__malloc(size_t size)
{
return malloc(size);
}
char *strdup (const char *s)
{
size_t len = strlen (s) + 1;
void *new = __malloc (len);
if (new == NULL){
return NULL;
}
return (char *) memcpy (new, s, len);
}
void *calloc (size_t nelem, size_t elsize)
{
register void *ptr;
if (nelem == 0 || elsize == 0)
nelem = elsize = 1;
ptr = __malloc(nelem * elsize); //sdradmalloc
if (ptr) bzero (ptr, nelem * elsize);
return ptr;
}
/* Memory management related API */
void sdrad_free(udi_t udi, void *ptr)
{
sdrad_global_manager_t *sgm_ptr;
sdrad_thread_metadata_t *stm_ptr, *stm_parent_ptr;
sdrad_d_info_t *sdi_ptr, *shm_parent_ptr;
tlsf_t *tlsf;
int32_t parent_domain_sti;
int32_t sdi;
sdrad_store_pkru_config(PKRU_ALL_UNSET); //can access all domain
sgm_ptr = (sdrad_global_manager_t *)&sdrad_global_manager;
// Get STI from TDI
int32_t thread_index = sdrad_get_sti(sgm_ptr);
stm_ptr = sgm_ptr -> stm_ptr[thread_index];
SDRAD_MUTEX_LOCK();
#ifdef SDRAD_MULTITHREAD
sdi = sdrad_search_udi_control(udi, sgm_ptr -> udi_control_head);
sdi_ptr = (sdrad_d_info_t *)&stm_ptr -> sdrad_d_info[sdi];
if (sdi_ptr -> sdi_init_heap_flag == false ){
parent_domain_sti = sgm_ptr -> sgm_sdi_to_tdi[sdi];
if(parent_domain_sti != thread_index){
stm_parent_ptr = sgm_ptr -> stm_ptr[parent_domain_sti]; // get parent thread
shm_parent_ptr = (sdrad_d_info_t *)&stm_parent_ptr -> sdrad_d_info[sdi]; // parent domain info
memcpy(sdi_ptr, shm_parent_ptr, sizeof(sdrad_d_info_t));
sdi_ptr -> sdi_init_heap_flag = true;
}
}
tlsf = sdi_ptr -> sdi_tlsf;
#else
tlsf = (tlsf_t *)sdrad_search_tlsf_control(ptr, sgm_ptr);
#endif
tlsf_free(tlsf, ptr);
SDRAD_MUTEX_UNLOCK();
sdrad_store_pkru_config(stm_ptr-> pkru_config[stm_ptr-> active_domain]);
}
void *sdrad_realloc(udi_t udi, void *ptr, size_t size)
{
sdrad_global_manager_t *sgm_ptr;
sdrad_thread_metadata_t *stm_ptr, *stm_parent_ptr;
sdrad_d_info_t *sdi_ptr, *shm_parent_ptr;
int32_t sdi;
sdrad_domain_t active_domain;
int32_t parent_domain_sti;
sdrad_store_pkru_config(PKRU_ALL_UNSET); //can access all domain
sgm_ptr = (sdrad_global_manager_t *)&sdrad_global_manager;
// Get STI from TDI
int32_t thread_index = sdrad_get_sti(sgm_ptr);
stm_ptr = sgm_ptr -> stm_ptr[thread_index];
sdi = sdrad_search_udi_control(udi, sgm_ptr -> udi_control_head);
if (sdi == SDRAD_ERROR_DOMAIN_NO_MAP){
assert(sdi != SDRAD_ERROR_DOMAIN_NO_MAP);
return (void *)SDRAD_ERROR_NO_DOMAIN;
}
sdi_ptr = (sdrad_d_info_t *)&stm_ptr -> sdrad_d_info[sdi];
SDRAD_MUTEX_LOCK();
if (sdi_ptr -> sdi_init_heap_flag == false ){
parent_domain_sti = sgm_ptr -> sgm_sdi_to_tdi[sdi];
if(parent_domain_sti != thread_index){
stm_parent_ptr = sgm_ptr -> stm_ptr[parent_domain_sti]; // get parent thread
shm_parent_ptr = (sdrad_d_info_t *)&stm_parent_ptr -> sdrad_d_info[sdi]; // parent domain info
memcpy(sdi_ptr, shm_parent_ptr, sizeof(sdrad_d_info_t));
sdi_ptr -> sdi_init_heap_flag = true;
if(shm_parent_ptr -> sdi_init_heap_flag == false){
sdrad_heap_domain_init(shm_parent_ptr, sgm_ptr-> pdi[sdi]);
}
}else{
sdrad_heap_domain_init(sdi_ptr, sgm_ptr-> pdi[sdi]);
}
}
ptr = tlsf_realloc(sdi_ptr -> sdi_tlsf, ptr, size);
SDRAD_MUTEX_UNLOCK();
active_domain = stm_ptr -> active_domain;
// return to old pkru value
sdrad_store_pkru_config(stm_ptr-> pkru_config[active_domain]);
return ptr;
}
int sdrad_memalign(udi_t udi, void **memptr, size_t alignment, size_t size)
{
sdrad_global_manager_t *sgm_ptr;
sdrad_thread_metadata_t *stm_ptr, *stm_parent_ptr;
sdrad_d_info_t *sdi_ptr, *shm_parent_ptr;
sdrad_domain_t active_domain;
void *ptr;
int32_t sdi;
int32_t parent_domain_sti;
sdrad_store_pkru_config(PKRU_ALL_UNSET); //can access all domain
sgm_ptr = (sdrad_global_manager_t *)&sdrad_global_manager;
// Get STI from TDI
int32_t thread_index = sdrad_get_sti(sgm_ptr);
stm_ptr = sgm_ptr -> stm_ptr[thread_index];
sdi = sdrad_search_udi_control(udi, sgm_ptr -> udi_control_head);
if (sdi == SDRAD_ERROR_DOMAIN_NO_MAP){
assert(sdi != SDRAD_ERROR_DOMAIN_NO_MAP);
return SDRAD_ERROR_NO_DOMAIN;
}
sdi_ptr = (sdrad_d_info_t *)&stm_ptr -> sdrad_d_info[sdi];
SDRAD_MALLOC_LOCK();
if (sdi_ptr -> sdi_init_heap_flag == false){
sdrad_heap_domain_init(sdi_ptr, sgm_ptr-> pdi[sdi]);
}
ptr = tlsf_memalign(sdi_ptr -> sdi_tlsf, alignment, size);
SDRAD_MALLOC_UNLOCK();
*memptr = ptr;
// return to old pkru value
active_domain = stm_ptr -> active_domain;
sdrad_store_pkru_config(stm_ptr-> pkru_config[active_domain]);
return 0; //tlsf_memalign doesn't have any zero code
}
void *sdrad_malloc(udi_t udi, size_t size)
{
sdrad_global_manager_t *sgm_ptr;
sdrad_thread_metadata_t *stm_ptr, *stm_parent_ptr;
sdrad_d_info_t *sdi_ptr, *shm_parent_ptr;
udi_t parent_domain_sti;
void *ptr;
int32_t sdi;
sdrad_domain_t active_domain;
sdrad_store_pkru_config(PKRU_ALL_UNSET); //can access all domain
sgm_ptr = (sdrad_global_manager_t *)&sdrad_global_manager;
// Get STI from TDI
int32_t thread_index = sdrad_get_sti(sgm_ptr);
assert(thread_index != -1);
stm_ptr = sgm_ptr -> stm_ptr[thread_index];
sdi = sdrad_search_udi_control(udi, sgm_ptr -> udi_control_head);
if (sdi == SDRAD_ERROR_DOMAIN_NO_MAP){
assert(sdi != SDRAD_ERROR_DOMAIN_NO_MAP);
return (void *)SDRAD_ERROR_NO_DOMAIN;
}
SDRAD_MUTEX_LOCK();
sdi_ptr = (sdrad_d_info_t *)&stm_ptr -> sdrad_d_info[sdi];
if (sdi_ptr -> sdi_init_heap_flag == false){
parent_domain_sti = sgm_ptr -> sgm_sdi_to_tdi[sdi];
if(parent_domain_sti != thread_index){
stm_parent_ptr = sgm_ptr -> stm_ptr[parent_domain_sti]; // get parent thread
shm_parent_ptr = (sdrad_d_info_t *)&stm_parent_ptr -> sdrad_d_info[sdi]; // parent domain info
if(shm_parent_ptr -> sdi_init_heap_flag == false){
sdrad_heap_domain_init(shm_parent_ptr, sgm_ptr-> pdi[sdi]);
}
memcpy(sdi_ptr, shm_parent_ptr, sizeof(sdrad_d_info_t));
sdi_ptr -> sdi_init_heap_flag = true;
}else{
sdrad_heap_domain_init(sdi_ptr, sgm_ptr-> pdi[sdi]);
}
}
if(sdi_ptr -> sdi_tlsf == NULL){
assert(sdi_ptr -> sdi_tlsf != NULL);
}
ptr = tlsf_malloc(sdi_ptr -> sdi_tlsf, size);
SDRAD_MUTEX_UNLOCK();
active_domain = stm_ptr -> active_domain;
// return to old pkru value
sdrad_store_pkru_config(stm_ptr-> pkru_config[active_domain]);
return ptr;
}
void *sdrad_calloc(udi_t udi, size_t nelem, size_t elsize)
{
sdrad_global_manager_t *sgm_ptr;
sdrad_thread_metadata_t *stm_ptr, *stm_parent_ptr;
sdrad_d_info_t *sdi_ptr,*shm_parent_ptr;;
int32_t sdi;
sdrad_domain_t active_domain;
udi_t parent_domain_sti;
sdrad_store_pkru_config(PKRU_ALL_UNSET); //can access all domain
sgm_ptr = (sdrad_global_manager_t *)&sdrad_global_manager;
//Get STI from TDI
int32_t thread_index = sdrad_get_sti(sgm_ptr);
stm_ptr = sgm_ptr -> stm_ptr[thread_index];
sdi = sdrad_search_udi_control(udi, sgm_ptr -> udi_control_head);
if (sdi == SDRAD_ERROR_DOMAIN_NO_MAP){
assert(sdi != SDRAD_ERROR_DOMAIN_NO_MAP);
return (void *)SDRAD_ERROR_NO_DOMAIN;
}
sdi_ptr = (sdrad_d_info_t *)&stm_ptr -> sdrad_d_info[sdi];
SDRAD_MUTEX_LOCK();
if (sdi_ptr -> sdi_init_heap_flag == false){
parent_domain_sti = sgm_ptr -> sgm_sdi_to_tdi[sdi];
if(parent_domain_sti != thread_index){
stm_parent_ptr = sgm_ptr -> stm_ptr[parent_domain_sti]; // get parent thread
shm_parent_ptr = (sdrad_d_info_t *)&stm_parent_ptr -> sdrad_d_info[sdi]; // parent domain info
memcpy(sdi_ptr, shm_parent_ptr, sizeof(sdrad_d_info_t));
sdi_ptr -> sdi_init_heap_flag = true;
}else{
sdrad_heap_domain_init(sdi_ptr, sgm_ptr-> pdi[sdi]);
}
}
register void *ptr;
if (nelem == 0 || elsize == 0)
nelem = elsize = 1;
ptr = tlsf_malloc(sdi_ptr -> sdi_tlsf, nelem * elsize); //sdradmalloc
SDRAD_MUTEX_UNLOCK();
if (ptr) bzero (ptr, nelem * elsize);
active_domain = stm_ptr -> active_domain;
// return to old pkru value
sdrad_store_pkru_config(stm_ptr-> pkru_config[active_domain]);
return ptr;
}
void sdrad_heap_domain_init(sdrad_d_info_t *sdi_ptr, int32_t pkey)
{
int32_t status;
sdrad_domain_size_t heap_size;
sdrad_da_t address;
sdi_ptr -> sdi_size_of_heap = SDRAD_DEFAULT_HEAP_SIZE;
sdi_ptr -> sdi_address_of_heap = (sdrad_da_t)mmap(NULL, sdi_ptr -> sdi_size_of_heap,
PROT_READ | PROT_WRITE,
MAP_PRIVATE |
MAP_ANONYMOUS,
-1,
0);
//mprotect((void *)sdi_ptr -> sdi_address_of_heap, 4096, PROT_NONE);
//mprotect((void *)(sdi_ptr -> sdi_address_of_heap+sdi_ptr -> sdi_size_of_heap-4096), 4096, PROT_NONE);
//sdi_ptr -> sdi_address_of_heap = sdi_ptr -> sdi_address_of_heap + 4096;
//sdi_ptr -> sdi_size_of_heap = sdi_ptr -> sdi_size_of_heap - 2*4096;
status = pkey_mprotect((void *)sdi_ptr -> sdi_address_of_heap,
sdi_ptr -> sdi_size_of_heap,
PROT_READ | PROT_WRITE,
pkey);
assert(status != -1);
if(sdi_ptr -> sdi_size_of_heap <= SDRAD_TLSF_MAX_HEAP_SIZE){
sdi_ptr -> sdi_tlsf = tlsf_create_with_pool((void *)sdi_ptr -> sdi_address_of_heap,
sdi_ptr -> sdi_size_of_heap);
}else{
sdi_ptr -> sdi_tlsf = tlsf_create_with_pool((void *)sdi_ptr -> sdi_address_of_heap,
SDRAD_TLSF_MAX_HEAP_SIZE);
heap_size = sdi_ptr -> sdi_size_of_heap - SDRAD_TLSF_MAX_HEAP_SIZE;
address = sdi_ptr -> sdi_address_of_heap + SDRAD_TLSF_MAX_HEAP_SIZE;
while (heap_size > SDRAD_TLSF_MAX_HEAP_SIZE)
{
tlsf_add_pool(sdi_ptr -> sdi_tlsf,
(void *)address,
SDRAD_TLSF_MAX_HEAP_SIZE);
heap_size = heap_size - SDRAD_TLSF_MAX_HEAP_SIZE;
address = address + SDRAD_TLSF_MAX_HEAP_SIZE;
}
tlsf_add_pool(sdi_ptr -> sdi_tlsf,
(void *)address,
heap_size);
}
sdi_ptr -> sdi_init_heap_flag = true;
SDRAD_DEBUG_PRINT("[SDRAD] Heap Domain %d Initialized %p \n",
stm_ptr->active_domain,
sdi_ptr->sdi_address_of_heap);
}
/**
* @brief get memory area from Monitor Data Domain area
*
* @param size
* @return void*
*/
void *sdrad_malloc_mdd(size_t size)
{
sdrad_global_manager_t *sgm_ptr;
sdrad_monitor_domain_t *smd_ptr;
void *ptr;
sgm_ptr = (sdrad_global_manager_t *)&sdrad_global_manager;
smd_ptr = (sdrad_monitor_domain_t *)&sgm_ptr -> sdrad_monitor_domain;
ptr = tlsf_malloc(smd_ptr -> smd_tlsf, size);
return ptr;
}