19#ifndef _POSIX_C_SOURCE
20#define _POSIX_C_SOURCE 200809L
28 .block_while_has_temp = 1,
29 .allow_zerocount_push = 0,
34#ifndef KOLISEO_HAS_LOCATE
39 .OOM_handler = &KLS_OOM_default_handler_dbg__,
40 .PTRDIFF_MAX_handler = &KLS_PTRDIFF_MAX_default_handler_dbg__,
41 .ZEROCOUNT_handler = &KLS_ZEROCOUNT_default_handler_dbg__,
53 .worst_pushcall_time = -1,
65 return KOLISEO_API_VERSION_STRING;
74 return KOLISEO_API_VERSION_INT;
77#if defined(__SANITIZE_ADDRESS__)
78#include <sanitizer/asan_interface.h>
79#define KLS_ASAN_POISON(addr, size) __asan_poison_memory_region((addr), (size))
80#define KLS_ASAN_UNPOISON(addr, size) __asan_unpoison_memory_region((addr), (size))
82#define KLS_ASAN_POISON(addr, size) ((void)0)
83#define KLS_ASAN_UNPOISON(addr, size) ((void)0)
95#ifndef KOLISEO_HAS_LOCATE
98void KLS_OOM_default_handler_dbg__(
Koliseo* kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size, ptrdiff_t count, Koliseo_Loc loc)
101#ifndef KOLISEO_HAS_LOCATE
103 "[KLS] Out of memory. size*count [%td] was bigger than available-padding [%td].\n",
104 size * count, available - padding);
107 "[KLS] " KLS_Loc_Fmt
"Out of memory. size*count [%td] was bigger than available-padding [%td].\n",
109 size * count, available - padding);
115#ifndef KOLISEO_HAS_LOCATE
118void KLS_PTRDIFF_MAX_default_handler_dbg__(
struct Koliseo* kls, ptrdiff_t size, ptrdiff_t count, Koliseo_Loc loc)
122#ifndef KOLISEO_HAS_LOCATE
124 "[KLS] count [%td] was bigger than PTRDIFF_MAX/size [%li].\n",
125 count, PTRDIFF_MAX / size);
128 "[KLS] " KLS_Loc_Fmt
"count [%td] was bigger than PTRDIFF_MAX/size [%li].\n",
130 count, PTRDIFF_MAX / size);
133#ifndef KOLISEO_HAS_LOCATE
135 "[KLS] count [%td] was bigger than PTRDIFF_MAX/size [%lli].\n",
136 count, PTRDIFF_MAX / size);
139 "[KLS] " KLS_Loc_Fmt
"count [%td] was bigger than PTRDIFF_MAX/size [%lli].\n",
141 count, PTRDIFF_MAX / size);
157#ifndef KOLISEO_HAS_LOCATE
160void KLS_ZEROCOUNT_default_handler_dbg__(
Koliseo* kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size, Koliseo_Loc loc)
163#ifndef KOLISEO_HAS_LOCATE
165 "[KLS] Doing a zero-count push. size [%td] padding [%td] available [%td].\n",
166 size, padding, available);
169 "[KLS] " KLS_Loc_Fmt
"Doing a zero-count push. size [%td] padding [%td] available [%td].\n",
171 size, padding, available);
196#ifndef KOLISEO_HAS_LOCATE
206#ifndef KOLISEO_HAS_LOCATE
216#ifndef KOLISEO_HAS_LOCATE
230KLS_Conf kls_conf_init(
int collect_stats,
int verbose_lvl,
int block_while_has_temp,
int allow_zerocount_push,
int growable, FILE* log_fp,
const char* log_filepath)
233 return kls_conf_init_handled(collect_stats, verbose_lvl, block_while_has_temp, allow_zerocount_push, growable, log_fp, log_filepath, err_handlers);
241#ifdef KOLISEO_HAS_LOCATE
242 bool kls_locate =
true;
244 bool kls_locate =
false;
247 bool kls_debug =
true;
249 bool kls_debug =
false;
251#ifdef KOLISEO_HAS_EXPER
252 bool kls_exper =
true;
254 bool kls_exper =
false;
261 int total_enabled = 0;
262 for (
int i=0; i<3; i++) {
267 fprintf(stderr,
"[KLS] Enabled features: {");
268 if (total_enabled == 0) {
269 fprintf(stderr,
"none}\n");
273 fprintf(stderr,
"debug%s", (total_enabled > 1 ?
", " :
""));
277 fprintf(stderr,
"locate%s", (total_enabled > 1 ?
", " :
""));
281 fprintf(stderr,
"exper");
283 fprintf(stderr,
"}\n");
309#ifndef KOLISEO_HAS_LOCATE
312void* kls__handle_push_result_dbg(
Koliseo* kls,
KLS_Push_Result r, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count, ptrdiff_t padding,
const char* caller_name, Koliseo_Loc loc)
315 if (!kls)
return NULL;
317 while (current->
next != NULL) {
318 current = current->
next;
321 const ptrdiff_t available = current->
size - current->
offset;
328#ifndef KOLISEO_HAS_LOCATE
330 "[KLS] %s(): size [%td] was < 1.\n",
335 "[KLS] " KLS_Loc_Fmt
"%s(): size [%td] was < 1.\n",
343#ifndef KOLISEO_HAS_LOCATE
345 "[KLS] %s(): align [%td] was < 1.\n",
350 "[KLS] " KLS_Loc_Fmt
"%s(): align [%td] was < 1.\n",
358#ifndef KOLISEO_HAS_LOCATE
360 "[KLS] %s(): align [%td] was not a power of 2.\n",
365 "[KLS] " KLS_Loc_Fmt
"%s(): align [%td] was not a power of 2.\n",
373#ifndef KOLISEO_HAS_LOCATE
375 "[KLS] %s(): count [%td] was < 0.\n",
380 "[KLS] " KLS_Loc_Fmt
"%s(): count [%td] was < 0.\n",
389#ifndef KOLISEO_HAS_LOCATE
395#ifndef KOLISEO_HAS_LOCATE
397 "[KLS] %s(): Doing a zero-count push. size [%td] padding [%td] available [%td].\n",
399 size, padding, available);
402 "[KLS] " KLS_Loc_Fmt
"%s(): Doing a zero-count push. size [%td] padding [%td] available [%td].\n",
405 size, padding, available);
413#ifndef KOLISEO_HAS_LOCATE
414 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo has an open Koliseo_Temp session.\n", caller_name);
416 fprintf(stderr,
"[ERROR] " KLS_Loc_Fmt
"[%s()]: Passed Koliseo has an open Koliseo_Temp session.\n", KLS_Loc_Arg(loc), caller_name);
417 kls_log(kls,
"ERROR", KLS_Loc_Fmt
"[%s()]: Passed Koliseo has an open Koliseo_Temp session.", KLS_Loc_Arg(loc), caller_name);
424#ifndef KOLISEO_HAS_LOCATE
431#ifndef KOLISEO_HAS_LOCATE
433 "[KLS] %s(): count [%td] was bigger than PTRDIFF_MAX/size [%li].\n",
435 count, PTRDIFF_MAX / size);
438 "[KLS] " KLS_Loc_Fmt
"%s(): count [%td] was bigger than PTRDIFF_MAX/size [%li].\n",
441 count, PTRDIFF_MAX / size);
444#ifndef KOLISEO_HAS_LOCATE
446 "[KLS] %s(): count [%td] was bigger than PTRDIFF_MAX/size [%lli].\n",
448 count, PTRDIFF_MAX / size);
451 "[KLS] " KLS_Loc_Fmt
"%s(): count [%td] was bigger than PTRDIFF_MAX/size [%lli].\n",
454 count, PTRDIFF_MAX / size);
462#ifndef KOLISEO_HAS_LOCATE
468#ifndef KOLISEO_HAS_LOCATE
470 "[KLS] %s(): Out of memory. size*count [%td] was bigger than available-padding [%td].\n",
472 size * count, available - padding);
475 "[KLS] " KLS_Loc_Fmt
"%s(): Out of memory. size*count [%td] was bigger than available-padding [%td].\n",
478 size * count, available - padding);
484 fprintf(stderr,
"[KLS] %s(): unexpected error code [%i]\n", __func__, r.
error);
502 fprintf(stderr,
"[KLS] %s(): Passed kls was NULL.\n", __func__);
508 va_start(args, format);
511 "[KLS] %s(): Failed opening file to print logs.\n",
514 time_t now = time(0);
515 const struct tm *mytime = localtime(&now);
516 char timeheader[500];
517 if (strftime(timeheader,
sizeof timeheader,
"%X", mytime)) {
518 fprintf(fp,
"[%-10.10s] [%s] [", tag, timeheader);
519 vfprintf(fp, format, args);
544#ifndef KOLISEO_HAS_LOCATE
550 if (size < (ptrdiff_t)
sizeof(
Koliseo)) {
551#ifndef KOLISEO_HAS_LOCATE
553 "[ERROR] at %s(): invalid requested kls size (%td). Min accepted is: (%td).\n",
554 __func__, size, (ptrdiff_t)
sizeof(
Koliseo));
557 "[ERROR] " KLS_Loc_Fmt
"%s(): invalid requested kls size (%td). Min accepted is: (%td).\n",
558 KLS_Loc_Arg(loc), __func__, size, (ptrdiff_t)
sizeof(
Koliseo));
563 void *p = alloc_func(size);
572 kls->
offset =
sizeof(*kls);
582 kls->
hooks = ext_handlers;
591 kls_log(kls,
"KLS",
"API Level { %i } -> Allocated (%s) for new KLS.",
593 kls_log(kls,
"KLS",
"KLS offset: { %p }.", kls);
594 kls_log(kls,
"KLS",
"Allocation begin offset: { %p }.",
603#ifndef KOLISEO_HAS_LOCATE
604 fprintf(stderr,
"[KLS] Failed %s() call.\n", __func__);
606 fprintf(stderr,
"[KLS] " KLS_Loc_Fmt
"Failed %s() call.\n", KLS_Loc_Arg(loc), __func__);
634#ifndef KOLISEO_HAS_LOCATE
640#ifndef KOLISEO_HAS_LOCATE
683 bool conf_res = kls_set_conf(k, conf);
686 "[ERROR] [%s()]: Failed to set config for new Koliseo.\n",
765#ifndef KLS_DEBUG_CORE
767 "[WARN] %s(): KLS_DEBUG_CORE is not defined. No tracing allowed.\n",
771 .collect_stats = 1,.verbose_lvl =
772 1,.log_filepath = output_path,
773#ifndef KOLISEO_HAS_LOCATE
777 .err_handlers.OOM_handler = (err_handlers.
OOM_handler != NULL ? err_handlers.
OOM_handler : &KLS_OOM_default_handler_dbg__),
888#ifndef KLS_DEBUG_CORE
890 "[WARN] %s(): KLS_DEBUG_CORE is not defined. No debugging support.\n",
894 .collect_stats = 1,.verbose_lvl = 0,
895#ifndef KOLISEO_HAS_LOCATE
899 .err_handlers.OOM_handler = ( err_handlers.
OOM_handler != NULL ? err_handlers.
OOM_handler : &KLS_OOM_default_handler_dbg__),
996 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
1004#ifdef KLS_DEBUG_CORE
1005#ifdef KLS_SETCONF_DEBUG
1007 "[%s()]: Preliminary set of conf.log_fp to stderr.",
1015 "[ERROR] at %s(): passed OOM_handler is NULL. Using default.\n",
1017#ifdef KLS_DEBUG_CORE
1018#ifdef KLS_SETCONF_DEBUG
1020 "[%s()]: Passed OOM_handler was NULL, using default.",
1024#ifndef KOLISEO_HAS_LOCATE
1033 "[ERROR] at %s(): passed PTRDIFF_MAX_handler is NULL. Using default.\n",
1035#ifdef KLS_DEBUG_CORE
1036#ifdef KLS_SETCONF_DEBUG
1038 "[%s()]: Passed PTRDIFF_MAX_handler was NULL, using default.",
1042#ifndef KOLISEO_HAS_LOCATE
1049#ifndef KLS_DEBUG_CORE
1052 "[WARN] [%s()]: KLS_DEBUG_CORE is not defined. Stats may not be collected in full.\n",
1059#ifdef KLS_DEBUG_CORE
1060#ifdef KLS_SETCONF_DEBUG
1062 "[%s()]: kls->conf.log_fp was not NULL. Overriding it.",
1068 FILE *log_fp = NULL;
1072 "[ERROR] [%s()]: Failed opening logfile at {\"%s\"} [write].\n",
1076 fprintf(log_fp,
"%s",
"");
1082 "[ERROR] [%s()]: Failed opening logfile at {\"%s\"} [append].\n",
1092static bool kls__try_grow(
Koliseo* kls, ptrdiff_t needed);
1105#ifndef KOLISEO_HAS_LOCATE
1108KLS_Push_Result kls__advance_dbg(
Koliseo* kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count, ptrdiff_t* padding,
const char* caller_name, Koliseo_Loc loc)
1111#ifdef KLS_DEBUG_CORE
1113 struct timespec start_time, end_time;
1114 clock_gettime(CLOCK_MONOTONIC, &start_time);
1116 LARGE_INTEGER start_time, end_time, frequency;
1117 QueryPerformanceFrequency(&frequency);
1118 QueryPerformanceCounter(&start_time);
1123 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", caller_name);
1133#ifndef KOLISEO_HAS_LOCATE
1136 KLS_Push_Error res = kls__check_available_dbg(kls, size, align, count, __func__, loc);
1145 while (current->
next != NULL) {
1146 current = current->
next;
1148 const ptrdiff_t pad = -current->
offset & (align - 1);
1150 char *p = current->
data + current->
offset + pad;
1152 current->
offset += pad + size * count;
1160#ifdef KLS_DEBUG_CORE
1161 kls_log(current,
"KLS",
"Pushed zeroes on KLS, size (%s). Curr offset: { %p }.", h_size, current->
data + current->
offset);
1164 clock_gettime(CLOCK_MONOTONIC, &end_time);
1165 double elapsed_time =
1166 (end_time.tv_sec - start_time.tv_sec) + (end_time.tv_nsec -
1167 start_time.tv_nsec) / 1e9;
1169 QueryPerformanceCounter(&end_time);
1170 double elapsed_time =
1171 (double)(end_time.QuadPart -
1172 start_time.QuadPart) / frequency.QuadPart;
1200#ifndef KOLISEO_HAS_LOCATE
1203KLS_Push_Error kls__check_available_dbg(
Koliseo* kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count,
const char* caller_name, Koliseo_Loc loc)
1206 assert(kls != NULL);
1207 assert(caller_name != NULL);
1217 if (! ((align & (align - 1)) == 0)) {
1221 while (current->
next != NULL) {
1222 current = current->
next;
1224 const ptrdiff_t available = current->
size - current->
offset;
1225 const ptrdiff_t padding = -current->
offset & (align - 1);
1230#ifdef KLS_DEBUG_CORE
1231 kls_log(current,
"DEBUG",
"Accepting zero-count push: conf.allow_zerocount_push was 1");
1236 if (count > PTRDIFF_MAX / size || available - padding < size * count) {
1237 if (count > PTRDIFF_MAX / size) {
1240 if (current->
conf.
growable == 1 && kls__try_grow(current, (size * count) + padding)) {
1260#ifndef KOLISEO_HAS_LOCATE
1263KLS_Push_Result kls__temp_advance_dbg(
Koliseo_Temp* kls_t, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count, ptrdiff_t* padding,
const char* caller_name, Koliseo_Loc loc)
1266#ifdef KLS_DEBUG_CORE
1268 struct timespec start_time, end_time;
1269 clock_gettime(CLOCK_MONOTONIC, &start_time);
1271 LARGE_INTEGER start_time, end_time, frequency;
1272 QueryPerformanceFrequency(&frequency);
1273 QueryPerformanceCounter(&start_time);
1277 if (kls_t == NULL) {
1278 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo_Temp was NULL.\n",
1284 fprintf(stderr,
"[ERROR] [%s()]: Referred Koliseo was NULL.\n",
1288#ifndef KOLISEO_HAS_LOCATE
1291 KLS_Push_Error res = kls__check_available_dbg(kls, size, align, count, __func__, loc);
1300 while (current->
next != NULL) {
1301 current = current->
next;
1303 ptrdiff_t pad = -current->
offset & (align - 1);
1304 char *p = current->
data + current->
offset + pad;
1307 current->
offset += pad + size * count;
1315#ifdef KLS_DEBUG_CORE
1318 clock_gettime(CLOCK_MONOTONIC, &end_time);
1319 double elapsed_time =
1320 (end_time.tv_sec - start_time.tv_sec) + (end_time.tv_nsec -
1321 start_time.tv_nsec) / 1e9;
1323 QueryPerformanceCounter(&end_time);
1324 double elapsed_time =
1325 (double)(end_time.QuadPart -
1326 start_time.QuadPart) / frequency.QuadPart;
1332 kls_log(current,
"KLS",
"Pushed zeroes on Temp_KLS, size (%s). Curr offset: { %p }.", h_size, current->
data + current->
offset);
1343bool kls__try_grow(
Koliseo* kls, ptrdiff_t needed)
1345 assert(kls->
next == NULL);
1346 ptrdiff_t new_size =
KLS_MAX(kls->
size * 2, needed);
1351 kls_log(kls,
"DEBUG",
"%s(): growing Koliseo, new size: {%td}", __func__, new_size);
1352 if (!new_kls)
return false;
1353 kls->
next = new_kls;
1369 ptrdiff_t padding = 0;
1370#ifndef KOLISEO_HAS_LOCATE
1374 KLS_Push_Result res = kls__advance_dbg(kls, size, align, count, &padding, __func__, KLS_HERE);
1375 return kls__handle_push_result_dbg(kls, res, size, align, count, padding, __func__, KLS_HERE);
1389#ifndef KOLISEO_HAS_LOCATE
1393void *kls_push_zero_dbg(
Koliseo *kls, ptrdiff_t size, ptrdiff_t align,
1394 ptrdiff_t count, Koliseo_Loc loc)
1397 ptrdiff_t padding = 0;
1398#ifndef KOLISEO_HAS_LOCATE
1402 KLS_Push_Result res = kls__advance_dbg(kls, size, align, count, &padding, __func__, loc);
1403 void* p = kls__handle_push_result_dbg(kls, res, size, align, count, padding, __func__, loc);
1405 if (!p)
return NULL;
1407 memset(p, 0, size * count);
1422#ifndef KOLISEO_HAS_LOCATE
1426void *kls_push_zero_ext_dbg(
Koliseo *kls, ptrdiff_t size, ptrdiff_t align,
1427 ptrdiff_t count, Koliseo_Loc loc)
1431 ptrdiff_t padding = 0;
1432#ifndef KOLISEO_HAS_LOCATE
1436 KLS_Push_Result res = kls__advance_dbg(kls, size, align, count, &padding, __func__, loc);
1437 void* p = kls__handle_push_result_dbg(kls, res, size, align, count, padding, __func__, loc);
1439 if (!p)
return NULL;
1441 memset(p, 0, size * count);
1444 while (current->
next != NULL) {
1445 current = current->
next;
1471#ifndef KOLISEO_HAS_LOCATE
1474char* kls_vsprintf_dbg(
Koliseo* kls, Koliseo_Loc loc,
const char* fmt, va_list args)
1478 va_copy(args_copy, args);
1479 int len = vsnprintf(NULL, 0, fmt, args);
1480#ifndef KOLISEO_HAS_LOCATE
1483 char* str = kls_push_zero_ext_dbg(kls,
sizeof(
char),
KLS_ALIGNOF(
char), len+1, loc);
1485 vsnprintf(str, len+1, fmt, args_copy);
1496#ifndef KOLISEO_HAS_LOCATE
1499char* kls_sprintf_dbg(
Koliseo* kls, Koliseo_Loc loc,
const char* fmt, ...)
1503 va_start(args, fmt);
1504#ifndef KOLISEO_HAS_LOCATE
1507 char* str = kls_vsprintf_dbg(kls, loc, fmt, args);
1524#ifndef KOLISEO_HAS_LOCATE
1526 ptrdiff_t align, ptrdiff_t count)
1528void *kls_temp_push_zero_ext_dbg(
Koliseo_Temp *t_kls, ptrdiff_t size,
1529 ptrdiff_t align, ptrdiff_t count, Koliseo_Loc loc)
1533 ptrdiff_t padding = 0;
1535#ifndef KOLISEO_HAS_LOCATE
1538 KLS_Push_Result res = kls__temp_advance_dbg(t_kls, size, align, count, &padding, __func__, loc);
1540 if (res.
error)
return NULL;
1542 memset(res.
p, 0, size * count);
1546 while (current->
next != NULL) {
1547 current = current->
next;
1557#ifndef KOLISEO_HAS_LOCATE
1560char* kls_temp_vsprintf_dbg(
Koliseo_Temp* kls_t, Koliseo_Loc loc,
const char* fmt, va_list args)
1564 va_copy(args_copy, args);
1565 int len = vsnprintf(NULL, 0, fmt, args);
1566#ifndef KOLISEO_HAS_LOCATE
1569 char* str = kls_temp_push_zero_ext_dbg(kls_t,
sizeof(
char),
KLS_ALIGNOF(
char), len+1, loc);
1571 vsnprintf(str, len+1, fmt, args_copy);
1583#ifndef KOLISEO_HAS_LOCATE
1586char* kls_temp_sprintf_dbg(
Koliseo_Temp* kls_t, Koliseo_Loc loc,
const char* fmt, ...)
1590 va_start(args, fmt);
1591#ifndef KOLISEO_HAS_LOCATE
1594 char* str = kls_temp_vsprintf_dbg(kls_t, loc, fmt, args);
1607 const char *p = ptr;
1609 for (
const Koliseo *cur = kls; cur; cur = cur->
next) {
1610 if (p >= cur->data &&
1611 p < cur->data + cur->offset) {
1630#ifndef KOLISEO_HAS_LOCATE
1632 ptrdiff_t old_count, ptrdiff_t new_count)
1634void *kls_repush_dbg(
Koliseo *kls,
void* old, ptrdiff_t size, ptrdiff_t align,
1635 ptrdiff_t old_count, ptrdiff_t new_count, Koliseo_Loc loc)
1639#ifndef KOLISEO_HAS_LOCATE
1641 "[KLS] %s(): old was NULL.\n",
1645 "[KLS] " KLS_Loc_Fmt
"%s(): old was NULL.\n",
1653 "[KLS] %s(): pointer %p does not belong to this Koliseo.\n",
1658 if (old_count < 0) {
1659#ifndef KOLISEO_HAS_LOCATE
1661 "[KLS] %s(): old_count [%td] was < 0.\n",
1666 "[KLS] " KLS_Loc_Fmt
"%s(): old_count [%td] was < 0.\n",
1673 if (new_count < 0) {
1674#ifndef KOLISEO_HAS_LOCATE
1676 "[KLS] %s(): new_count [%td] was < 0.\n",
1681 "[KLS] " KLS_Loc_Fmt
"%s(): new_count [%td] was < 0.\n",
1689#ifndef KOLISEO_HAS_LOCATE
1691 "[KLS] %s(): size [%td] was < 1.\n",
1696 "[KLS] " KLS_Loc_Fmt
"%s(): size [%td] was < 1.\n",
1704#ifndef KOLISEO_HAS_LOCATE
1706 "[KLS] %s(): align [%td] was < 1.\n",
1711 "[KLS] " KLS_Loc_Fmt
"%s(): align [%td] was < 1.\n",
1718 if (! ((align & (align - 1)) == 0)) {
1719#ifndef KOLISEO_HAS_LOCATE
1721 "[KLS] %s(): align [%td] was not a power of 2.\n",
1726 "[KLS] " KLS_Loc_Fmt
"%s(): align [%td] was not a power of 2.\n",
1734 fprintf(stderr,
"%s(): kls has an active temp\n", __func__);
1737 if (old_count >= new_count)
return old;
1739 ptrdiff_t growth = new_count - old_count;
1741 if ((
size_t)old_count > SIZE_MAX / (
size_t)size)
return NULL;
1743 if ((
size_t)new_count > SIZE_MAX / (
size_t)size)
return NULL;
1745 size_t old_size = (size_t)old_count * (
size_t)size;
1746 size_t new_size = (size_t)new_count * (
size_t)size;
1749 while (current->
next != NULL) {
1750 current = current->
next;
1753 ptrdiff_t padding = 0;
1756 void* new_ptr = NULL;
1757 if (is_last_alloc) {
1761 const ptrdiff_t saved_prev_offset = current->
prev_offset;
1762#ifndef KOLISEO_HAS_LOCATE
1766 KLS_Push_Result res = kls__advance_dbg(current, size, align, growth, &padding, __func__, loc);
1767 void* p = kls__handle_push_result_dbg(current, res, size, align, growth, padding, __func__, loc);
1769 if (!p)
return NULL;
1770 size_t added_size = new_size - old_size;
1772 memset(p, 0, added_size);
1775 Koliseo* new_current = current;
1776 while (new_current->
next != NULL) {
1777 new_current = new_current->
next;
1780#ifdef KLS_DEBUG_CORE
1781 const ptrdiff_t new_byte_slice_len = new_current->
offset - new_current->
prev_offset + padding;
1782 kls_log(new_current,
"KLS",
"Extended last allocation on KLS, new_byte_slice_len (%td), padding (%td). Curr offset: { %p } Old: { %p }, New: { %p }.", new_byte_slice_len, padding, new_current->
data + new_current->
offset, old, new_ptr);
1788#ifdef KLS_DEBUG_CORE
1789 kls_log(current,
"KLS",
"%s(): pushed new memory", __func__);
1792 if (new_ptr && old_size > 0) {
1793 memcpy(new_ptr, old, old_size);
1810#ifndef KOLISEO_HAS_LOCATE
1812 ptrdiff_t old_count, ptrdiff_t new_count)
1814void *kls_temp_repush_dbg(
Koliseo_Temp *t_kls,
void* old, ptrdiff_t size, ptrdiff_t align,
1815 ptrdiff_t old_count, ptrdiff_t new_count, Koliseo_Loc loc)
1819#ifndef KOLISEO_HAS_LOCATE
1821 "[KLS] %s(): old was NULL.\n",
1825 "[KLS] " KLS_Loc_Fmt
"%s(): old was NULL.\n",
1833 "[KLS] %s(): pointer %p does not belong to this Koliseo.\n",
1838 if (old_count < 0) {
1839#ifndef KOLISEO_HAS_LOCATE
1841 "[KLS] %s(): old_count [%td] was < 0.\n",
1846 "[KLS] " KLS_Loc_Fmt
"%s(): old_count [%td] was < 0.\n",
1853 if (new_count < 0) {
1854#ifndef KOLISEO_HAS_LOCATE
1856 "[KLS] %s(): new_count [%td] was < 0.\n",
1861 "[KLS] " KLS_Loc_Fmt
"%s(): new_count [%td] was < 0.\n",
1869#ifndef KOLISEO_HAS_LOCATE
1871 "[KLS] %s(): size [%td] was < 1.\n",
1876 "[KLS] " KLS_Loc_Fmt
"%s(): size [%td] was < 1.\n",
1884#ifndef KOLISEO_HAS_LOCATE
1886 "[KLS] %s(): align [%td] was < 1.\n",
1891 "[KLS] " KLS_Loc_Fmt
"%s(): align [%td] was < 1.\n",
1898 if (! ((align & (align - 1)) == 0)) {
1899#ifndef KOLISEO_HAS_LOCATE
1901 "[KLS] %s(): align [%td] was not a power of 2.\n",
1906 "[KLS] " KLS_Loc_Fmt
"%s(): align [%td] was not a power of 2.\n",
1914 if (old_count >= new_count)
return old;
1916 ptrdiff_t growth = new_count - old_count;
1918 if ((
size_t)old_count > SIZE_MAX / (
size_t)size)
return NULL;
1920 if ((
size_t)new_count > SIZE_MAX / (
size_t)size)
return NULL;
1922 size_t old_size = (size_t)old_count * (
size_t)size;
1923 size_t new_size = (size_t)new_count * (
size_t)size;
1926 while (current->
next != NULL) {
1927 current = current->
next;
1930 ptrdiff_t padding = 0;
1933 void* new_ptr = NULL;
1934 if (is_last_alloc) {
1938 const ptrdiff_t saved_prev_offset = current->
prev_offset;
1939#ifndef KOLISEO_HAS_LOCATE
1943 KLS_Push_Result res = kls__temp_advance_dbg(t_kls, size, align, growth, &padding, __func__, loc);
1944 void* p = kls__handle_push_result_dbg(current, res, size, align, growth, padding, __func__, loc);
1946 if (!p)
return NULL;
1947 size_t added_size = new_size - old_size;
1949 memset(p, 0, added_size);
1952 Koliseo* new_current = current;
1953 while (new_current->
next != NULL) {
1954 new_current = new_current->
next;
1957#ifdef KLS_DEBUG_CORE
1958 const ptrdiff_t new_byte_slice_len = new_current->
offset - new_current->
prev_offset + padding;
1959 kls_log(new_current,
"KLS",
"Extended last allocation on Temp_KLS, new_byte_slice_len (%td), padding (%td). Curr offset: { %p } Old: { %p }, New: { %p }.", new_byte_slice_len, padding, new_current->
data + new_current->
offset, old, new_ptr);
1965#ifdef KLS_DEBUG_CORE
1966 kls_log(current,
"KLS",
"%s(): pushed new memory", __func__);
1969 if (new_ptr && old_size > 0) {
1970 memcpy(new_ptr, old, old_size);
1984 fprintf(stderr,
"print_kls_2file(): fp was NULL.\n");
1988 fprintf(fp,
"[KLS] kls was NULL.\n");
1995 fprintf(fp,
"\n[KLS] Size: { %td }\n", kls->
size);
1996 char human_size[200];
1997 char curr_size[200];
1999 fprintf(fp,
"[KLS] Size (Human): { %s }\n", human_size);
2001 fprintf(fp,
"[KLS] Used (Human): { %s }\n", curr_size);
2002 fprintf(fp,
"[KLS] Offset: { %td }\n", kls->
offset);
2003 fprintf(fp,
"[KLS] Prev_Offset: { %td }\n", kls->
prev_offset);
2015 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
2029 fprintf(stderr,
"print_temp_kls_2file(): fp was NULL.\n");
2032 if (t_kls == NULL) {
2033 fprintf(fp,
"[KLS_T] t_kls was NULL.");
2034 }
else if (t_kls->
kls == NULL) {
2035 fprintf(fp,
"[KLS_T] [%s()]: Referred Koliseo was NULL.\n", __func__);
2039 fprintf(fp,
"\n[KLS_T] Temp Size: { %td }\n",
2041 fprintf(fp,
"\n[KLS_T] Refer Size: { %td }\n", kls->
size);
2042 char human_size[200];
2043 char curr_size[200];
2045 sizeof(human_size));
2046 fprintf(fp,
"[KLS_T] Temp Size Human: { %s }\n", human_size);
2048 fprintf(fp,
"[KLS_T] Refer Size Human: { %s }\n", human_size);
2050 fprintf(fp,
"[KLS_T] Inner Used (Human): { %s }\n", curr_size);
2052 fprintf(fp,
"[KLS_T] Temp Used (Human): { %s }\n", curr_size);
2053 fprintf(fp,
"[KLS_T] Inner Offset: { %td }\n", kls->
offset);
2054 fprintf(fp,
"[KLS_T] Temp Offset: { %td }\n", t_kls->
offset);
2055 fprintf(fp,
"[KLS_T] Inner Prev_Offset: { %td }\n", kls->
prev_offset);
2056 fprintf(fp,
"[KLS_T] Temp Prev_Offset: { %td }\n\n",
2079 static const char *units[] = {
2080 "bytes",
"KB",
"MB",
"GB",
"TB",
"PB",
"EB",
"ZB",
"YB"
2083 const int numUnits =
sizeof(units) /
sizeof(units[0]);
2085 size_t unitIndex = 0;
2086 long double sizeValue = (
long double)size;
2088 while (sizeValue >= 1000 && unitIndex < numUnits - 1) {
2093 snprintf(outputBuffer, bufferSize,
"%.2Lf %s", sizeValue, units[unitIndex]);
2104 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
2109 kls->
offset =
sizeof(*kls);
2122#ifdef KLS_DEBUG_CORE
2123 kls_log(kls,
"KLS",
"API Level { %i } -> Cleared offsets for KLS.",
2136 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
2142#ifdef KLS_DEBUG_CORE
2144 "API Level { %i } -> KLS had an active Koliseo_Temp.",
2155 k->extension_data = NULL;
2159 current->
next = NULL;
2161#ifdef KLS_DEBUG_CORE
2162 kls_log(current,
"KLS",
"API Level { %i } -> Freeing KLS.",
2167#ifdef KLS_DEBUG_CORE
2168 kls_log(current,
"KLS",
"Closing kls log file. Path: {\"%s\"}.",
2171 int close_res = fclose(current->
conf.
log_fp);
2172 if (close_res != 0) {
2174 "[ERROR] %s(): Failed fclose() on log_fp. Path: {\"%s\"}.",
2180 "[INFO] %s(): kls->conf.log_fp is %s. Not closing it.\n",
2182 (current->
conf.
log_fp == stdout ?
"stdout" :
"stderr"));
2187 "[ERROR] %s(): free function was NULL.\n", __func__);
2202#ifndef KOLISEO_HAS_LOCATE
2209 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
2213 while (current->
next != NULL) {
2214 current = current->
next;
2218 "[ERROR] [%s()]: Passed Koliseo->has_temp is not 0. {%i}\n",
2220#ifdef KLS_DEBUG_CORE
2221 kls_log(current,
"ERROR",
"[%s()]: Passed Koliseo->has_temp != 0 . {%i}",
2227 ptrdiff_t off = current->
offset;
2233#ifdef KLS_DEBUG_CORE
2239 current->
t_kls = tmp;
2244#ifdef KLS_DEBUG_CORE
2245 kls_log(current,
"KLS",
"Prepared new Temp KLS.");
2256 if (tmp_kls == NULL) {
2257 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo_Temp was NULL.\n",
2263 if (kls_ref == NULL) {
2264 fprintf(stderr,
"[ERROR] [%s()]: Referred Koliseo was NULL.\n",
2274#ifdef KLS_DEBUG_CORE
2275 kls_log(kls_ref,
"KLS",
"Ended Temp KLS.");
2279#if defined(__SANITIZE_ADDRESS__)
2280 ptrdiff_t old_offset = tmp_kls->
kls->
offset;
2281 ptrdiff_t new_offset = tmp_kls->
offset;
2288 if (to_free != NULL) {
2301#ifdef KOLISEO_HAS_EXPER
2313 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
2316 ptrdiff_t padding = -kls->
offset & (align - 1);
2317 if (count > PTRDIFF_MAX / size
2318 || (kls->
size + kls->
offset) < (size * count)) {
2319 fprintf(stderr,
"[KLS] Failed %s() call.\n", __func__);
2323 char *p = kls->
data + kls->
offset - padding - size * count;
2325 kls->
offset -= padding + size * count;
2326#ifdef KLS_DEBUG_CORE
2327 kls_log(kls,
"KLS",
"Popped (%td) for KLS. Curr offset: { %p }",
2347 if (t_kls == NULL) {
2348 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo_Temp was NULL.\n",
2354 fprintf(stderr,
"[ERROR] [%s()]: Referred Koliseo was NULL.\n",
2358 ptrdiff_t padding = -kls->
offset & (align - 1);
2359 if (count > PTRDIFF_MAX / size
2360 || (kls->
size + kls->
offset) < (size * count)) {
2361 fprintf(stderr,
"[KLS] Failed %s() call.\n", __func__);
2365 char *p = kls->
data + kls->
offset - padding - size * count;
2367 kls->
offset -= padding + size * count;
2368#ifdef KLS_DEBUG_CORE
2369 kls_log(kls,
"KLS",
"Popped (%td) for Temp_KLS. Curr offset: { %p }.", size, kls->
data + kls->
offset);
2398 char** strings = NULL;
2400 for (
int i=0; i < count; i++) {
2427 char** strings = NULL;
2429 for (
int i=0; i < count; i++) {
#define KLS_DEFAULT_HOOKS
Definition kls_region.h:162
Koliseo * kls_new_traced(ptrdiff_t size, const char *output_path)
Takes a ptrdiff_t size and a filepath for the trace output file.
Definition koliseo.c:851
Koliseo * kls_new(ptrdiff_t size)
Takes a ptrdiff_t size.
Definition koliseo.c:659
char * kls_strdup(Koliseo *kls, char *source)
Function to dupe a C string to a Koliseo, and return a pointer to the allocated string.
Definition koliseo.c:2383
void * kls_temp_pop(Koliseo_Temp *t_kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count)
Takes a Koliseo_Temp, and ptrdiff_t values for size, align and count.
Definition koliseo.c:2344
Koliseo_Temp * kls_temp_start(Koliseo *kls)
Starts a new savestate for the passed Koliseo pointer, by initialising its Koliseo_Temp pointer and r...
Definition koliseo.c:2203
void print_dbg_temp_kls(const Koliseo_Temp *t_kls)
Prints header fields from the passed Koliseo_Temp pointer, to stderr.
Definition koliseo.c:2065
void * kls_temp_repush(Koliseo_Temp *t_kls, void *old, ptrdiff_t size, ptrdiff_t align, ptrdiff_t old_count, ptrdiff_t new_count)
Takes a Koliseo_Temp pointer, and a void pointer to the old allocation, ptrdiff_t values for size,...
Definition koliseo.c:1811
Koliseo * kls_new_dbg_alloc(ptrdiff_t size, kls_alloc_func alloc_func, kls_free_func free_func)
Takes a ptrdiff_t size, an allocation function pointer and a free function pointer,...
Definition koliseo.c:952
void print_temp_kls_2file(FILE *fp, const Koliseo_Temp *t_kls)
Prints header fields from the passed Koliseo_Temp pointer, to the passed FILE pointer.
Definition koliseo.c:2026
char * kls_t_strdup(Koliseo_Temp *t_kls, char *source)
Function to dupe a C string to a Koliseo_Temp, and return a pointer to the allocated string.
Definition koliseo.c:2412
Koliseo * kls_new_traced_alloc_handled(ptrdiff_t size, const char *output_path, kls_alloc_func alloc_func, kls_free_func free_func, KLS_Err_Handlers err_handlers)
Takes a ptrdiff_t size, a filepath for the trace output file, an allocation function pointer and a fr...
Definition koliseo.c:798
void kls_formatSize(size_t size, char *outputBuffer, size_t bufferSize)
Converts a ptrdiff_t size to human-readable SI units (modulo 1000).
Definition koliseo.c:2077
KLS_Stats KLS_STATS_DEFAULT
Default KLS_Stats values, used by kls_new().
Definition koliseo.c:46
void kls_log(Koliseo *kls, const char *tag, const char *format,...)
Logs a message to the log_fp FILE field of the passed Koliseo pointer, if its conf....
Definition koliseo.c:499
char * kls_vsprintf(Koliseo *kls, const char *fmt, va_list args)
Definition koliseo.c:1472
void kls_temp_end(Koliseo_Temp *tmp_kls)
Ends passed Koliseo_Temp pointer.
Definition koliseo.c:2254
void kls_dbg_features(void)
Prints enabled Koliseo features to stderr.
Definition koliseo.c:239
char ** kls_strdup_arr(Koliseo *kls, size_t count, char **source)
Function to dupe a C string array to a Koliseo, and return a pointer to the allocated array.
Definition koliseo.c:2396
void * kls_temp_push_zero_ext(Koliseo_Temp *t_kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count)
Takes a Koliseo_Temp, and ptrdiff_t values for size, align and count.
Definition koliseo.c:1525
void print_dbg_kls(const Koliseo *kls)
Prints header fields from the passed Koliseo pointer, to stderr.
Definition koliseo.c:2012
const char * string_koliseo_version(void)
Returns the constant string representing current version for Koliseo.
Definition koliseo.c:63
void * kls_repush(Koliseo *kls, void *old, ptrdiff_t size, ptrdiff_t align, ptrdiff_t old_count, ptrdiff_t new_count)
Takes a Koliseo pointer, and a void pointer to the old allocation, ptrdiff_t values for size,...
Definition koliseo.c:1631
KLS_Push_Result kls__advance(Koliseo *kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count, ptrdiff_t *padding, const char *caller_name)
Takes a Koliseo pointer, and ptrdiff_t values for size, align and count.
Definition koliseo.c:1106
char * kls_temp_vsprintf(Koliseo_Temp *kls_t, const char *fmt, va_list args)
Definition koliseo.c:1558
ptrdiff_t kls_get_pos(const Koliseo *kls)
Returns the current offset (position of pointer bumper) for the passed Koliseo.
Definition koliseo.c:292
Koliseo * kls_new_dbg_alloc_handled_ext(ptrdiff_t size, kls_alloc_func alloc_func, kls_free_func free_func, KLS_Err_Handlers err_handlers, KLS_Hooks ext_handlers, void *user)
Takes a ptrdiff_t size, an allocation function pointer and a free function pointer,...
Definition koliseo.c:886
#define KLS_ASAN_UNPOISON(addr, size)
Definition koliseo.c:83
void kls_free(Koliseo *kls)
Calls kls_clear() on the passed Koliseo pointer and the frees the actual Koliseo.
Definition koliseo.c:2133
KLS_Conf kls_conf_init_handled(int collect_stats, int verbose_lvl, int block_while_has_temp, int allow_zerocount_push, int growable, FILE *log_fp, const char *log_filepath, KLS_Err_Handlers err_handlers)
Used to prepare a KLS_Conf without caring about KOLISEO_HAS_REGIONS.
Definition koliseo.c:182
bool kls_contains_pointer(const Koliseo *kls, const void *ptr)
Takes a Koliseo pointer, and a void pointer to a memory region.
Definition koliseo.c:1605
Koliseo * kls_new_dbg_ext(ptrdiff_t size, KLS_Hooks ext_handlers, void *user)
Takes a ptrdiff_t size.
Definition koliseo.c:935
char * kls_temp_sprintf(Koliseo_Temp *kls_t, const char *fmt,...)
Takes a Koliseo_Temp pointer, and a format cstring, plus varargs.
Definition koliseo.c:1584
char ** kls_t_strdup_arr(Koliseo_Temp *t_kls, size_t count, char **source)
Function to dupe a C string array to a Koliseo_Temp, and return a pointer to the allocated array.
Definition koliseo.c:2425
void * kls_push(Koliseo *kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count)
Takes a Koliseo pointer, and ptrdiff_t values for size, align and count.
Definition koliseo.c:1367
Koliseo * kls_new_dbg_alloc_handled(ptrdiff_t size, kls_alloc_func alloc_func, kls_free_func free_func, KLS_Err_Handlers err_handlers)
Takes a ptrdiff_t size, an allocation function pointer and a free function pointer,...
Definition koliseo.c:920
KLS_Push_Error kls__check_available(Koliseo *kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count, const char *caller_name)
Takes a Koliseo, a ptrdiff_t size, align and count, and a caller name.
Definition koliseo.c:1201
#define KLS_ASAN_POISON(addr, size)
Definition koliseo.c:82
void * kls_push_zero(Koliseo *kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count)
Takes a Koliseo pointer, and ptrdiff_t values for size, align and count.
Definition koliseo.c:1390
Koliseo * kls_new_alloc(ptrdiff_t size, kls_alloc_func alloc_func, kls_free_func free_func)
Takes a ptrdiff_t size and a function pointer to the allocation function.
Definition koliseo.c:635
Koliseo * kls_new_dbg(ptrdiff_t size)
Takes a ptrdiff_t size and returns a pointer to the prepared Koliseo.
Definition koliseo.c:967
Koliseo * kls_new_traced_alloc(ptrdiff_t size, const char *output_path, kls_alloc_func alloc_func, kls_free_func free_func)
Takes a ptrdiff_t size, a filepath for the trace output file, an allocation function pointer and a fr...
Definition koliseo.c:834
char * kls_sprintf(Koliseo *kls, const char *fmt,...)
Takes a Koliseo pointer, and a format cstring, plus varargs.
Definition koliseo.c:1497
Koliseo * kls_new_traced_handled(ptrdiff_t size, const char *output_path, KLS_Err_Handlers err_handlers)
Takes a ptrdiff_t size and a filepath for the trace output file.
Definition koliseo.c:868
void * kls_pop(Koliseo *kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count)
Takes a Koliseo pointer, and ptrdiff_t values for size, align and count.
Definition koliseo.c:2310
Koliseo * kls_new_conf_alloc_ext(ptrdiff_t size, KLS_Conf conf, kls_alloc_func alloc_func, kls_free_func free_func, KLS_Hooks ext_handlers, void *user)
Takes a ptrdiff_t size, a KLS_Conf to configure the new Koliseo, an allocation function pointer and a...
Definition koliseo.c:680
void KLS_PTRDIFF_MAX_default_handler__(struct Koliseo *kls, ptrdiff_t size, ptrdiff_t count)
Used by default when no handler is passed.
Definition koliseo.c:116
KLS_Conf KLS_DEFAULT_CONF
Config used by any new Koliseo by default.
Definition koliseo.c:25
KLS_Conf kls_conf_init(int collect_stats, int verbose_lvl, int block_while_has_temp, int allow_zerocount_push, int growable, FILE *log_fp, const char *log_filepath)
Used to prepare a KLS_Conf without caring about KOLISEO_HAS_REGIONS.
Definition koliseo.c:230
void KLS_ZEROCOUNT_default_handler__(Koliseo *kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size)
Used internally for handling zero-count in push calls when no user handler is provided.
Definition koliseo.c:158
void * kls__handle_push_result(Koliseo *kls, KLS_Push_Result r, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count, ptrdiff_t padding, const char *caller_name)
Handles a KLS_Push_Result.
Definition koliseo.c:310
Koliseo * kls_new_alloc_ext(ptrdiff_t size, kls_alloc_func alloc_func, kls_free_func free_func, KLS_Hooks ext_handlers, void *user)
Takes a ptrdiff_t size and a function pointer to the allocation function.
Definition koliseo.c:545
void print_kls_2file(FILE *fp, const Koliseo *kls)
Prints header fields from the passed Koliseo pointer, to the passed FILE pointer.
Definition koliseo.c:1981
Koliseo * kls_new_traced_alloc_handled_ext(ptrdiff_t size, const char *output_path, kls_alloc_func alloc_func, kls_free_func free_func, KLS_Err_Handlers err_handlers, KLS_Hooks ext_handlers, void *user)
Takes a ptrdiff_t size, a filepath for the trace output file, an allocation function pointer and a fr...
Definition koliseo.c:762
Koliseo * kls_new_dbg_handled(ptrdiff_t size, KLS_Err_Handlers err_handlers)
Takes a ptrdiff_t size and returns a pointer to the prepared Koliseo.
Definition koliseo.c:982
void kls_clear(Koliseo *kls)
Resets the offset field for the passed Koliseo pointer.
Definition koliseo.c:2101
void * kls_push_zero_ext(Koliseo *kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count)
Takes a Koliseo pointer, and ptrdiff_t values for size, align and count.
Definition koliseo.c:1423
void KLS_OOM_default_handler__(Koliseo *kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size, ptrdiff_t count)
Used internally for handling Out-Of-Memory in push calls when no user handler is provided.
Definition koliseo.c:96
Koliseo * kls_new_conf_alloc(ptrdiff_t size, KLS_Conf conf, kls_alloc_func alloc_func, kls_free_func free_func)
Takes a ptrdiff_t size, a KLS_Conf to configure the new Koliseo, an allocation function pointer and a...
Definition koliseo.c:709
KLS_Push_Result kls__temp_advance(Koliseo_Temp *kls_t, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count, ptrdiff_t *padding, const char *caller_name)
Takes a Koliseo_Temp, and ptrdiff_t values for size, align and count.
Definition koliseo.c:1261
int int_koliseo_version(void)
Returns the constant int representing current version for Koliseo.
Definition koliseo.c:72
Koliseo * kls_new_traced_ext(ptrdiff_t size, const char *output_path, KLS_Hooks ext_handlers, void *user)
Takes a ptrdiff_t size and a filepath for the trace output file.
Definition koliseo.c:815
Koliseo * kls_new_conf(ptrdiff_t size, KLS_Conf conf)
Takes a ptrdiff_t size and a KLS_Conf to configure the new Koliseo.
Definition koliseo.c:742
Koliseo * kls_new_conf_ext(ptrdiff_t size, KLS_Conf conf, KLS_Hooks ext_handlers, void *user)
Takes a ptrdiff_t size and a KLS_Conf to configure the new Koliseo.
Definition koliseo.c:726
void kls_free_func(void *)
Used to select a free function for the arena's backing memory.
Definition koliseo.h:92
#define KLS_PUSH_STR_T(kls_temp, cstr)
Macro to request memory for a C string from a Koliseo_Temp.
Definition koliseo.h:649
#define KLS_Stats_Fmt
Defines a format string for KLS_Stats.
Definition koliseo.h:293
#define KLS_PUSH_STR(kls, cstr)
Macro to request memory for a C string from a Koliseo.
Definition koliseo.h:532
#define KLS_Conf_Arg(conf)
Defines a format macro for KLS_Conf args.
Definition koliseo.h:286
#define KLS_DEFAULT_FREEF
Defines the default free function.
Definition koliseo.h:414
#define KLS_DEFAULT_ALLOCF
Defines the default allocation function.
Definition koliseo.h:410
#define KLS_PUSH(kls, type)
Macro used to request memory from a Koliseo.
Definition koliseo.h:569
#define KLS__STRCPY(dest, source)
Macro to copy a C string from a source buffer to a destination buffer.
Definition koliseo.h:753
#define KLS_ALIGNOF
Definition koliseo.h:24
#define KLS_DEFAULT_EXTENSION_DATA
Defines default hooks that are loaded on kls_new() variants lacking explicit set of KLS_Hooks.
Definition koliseo.h:220
void * kls_alloc_func(size_t)
Used to select an allocation function for the arena's backing memory.
Definition koliseo.h:91
#define KLS_MAX(a, b)
Definition koliseo.h:98
#define KLS_STRDUP(kls, source)
Definition koliseo.h:762
KLS_Push_Error
Defines the result for kls__check_available().
Definition koliseo.h:366
@ KLS_PUSH_NEGATIVE_COUNT
Definition koliseo.h:371
@ KLS_PUSH_ZEROCOUNT
Definition koliseo.h:372
@ KLS_PUSH_ALIGN_NOT_POW2
Definition koliseo.h:370
@ KLS_PUSH_WITH_TEMP_ACTIVE
Definition koliseo.h:373
@ KLS_PUSH_OOM
Definition koliseo.h:375
@ KLS_PUSH_PTRDIFF_MAX
Definition koliseo.h:374
@ KLS_PUSH_SIZE_LT1
Definition koliseo.h:368
@ KLS_PUSH_ALIGN_LT1
Definition koliseo.h:369
@ KLS_PUSH_OK
Definition koliseo.h:367
#define KLS_Stats_Arg(stats)
Defines a format macro for KLS_Stats args.
Definition koliseo.h:303
#define KLS_Conf_Fmt
Defines a format string for KLS_Conf.
Definition koliseo.h:280
#define KLS_PUSH_ARR_T(kls_temp, type, count)
Macro used to request memory for an array of type values from a Koliseo_Temp.
Definition koliseo.h:637
#define KLS_STRDUP_T(t_kls, source)
Definition koliseo.h:772
#define KLS_DEFAULT_ERR_HANDLERS
Definition koliseo.h:178
#define KLS_PUSH_ARR(kls, type, count)
Macro used to request memory for an array of type values from a Koliseo.
Definition koliseo.h:520
Defines flags for Koliseo.
Definition koliseo.h:227
int growable
If set to 1, make the Koliseo grow when a out of memory for a push call.
Definition koliseo.h:234
int verbose_lvl
If > 0, makes the Koliseo try to acquire kls_log_fp from kls_log_filepath.
Definition koliseo.h:229
const char * log_filepath
String representing the path to the Koliseo logfile.
Definition koliseo.h:231
FILE * log_fp
FILE pointer used by the Koliseo to print its kls_log() output.
Definition koliseo.h:230
int allow_zerocount_push
If set to 1, make the Koliseo accept push calls with a count of 0.
Definition koliseo.h:233
int collect_stats
If set to 1, make the Koliseo collect performance stats.
Definition koliseo.h:228
KLS_Err_Handlers err_handlers
Used to pass custom error handlers for push calls.
Definition koliseo.h:235
int block_while_has_temp
If set to 1, make the Koliseo reject push calls while it has an open Koliseo_Temp.
Definition koliseo.h:232
Defines the handlers used for errors in push calls.
Definition koliseo.h:171
KLS_OOM_Handler * OOM_handler
Pointer to handler for Out-Of-Memory errors in push calls.
Definition koliseo.h:172
KLS_ZEROCOUNT_Handler * ZEROCOUNT_handler
Pointer to handler for zero-count errors in push calls.
Definition koliseo.h:174
KLS_PTRDIFF_MAX_Handler * PTRDIFF_MAX_handler
Pointer to handler for count > (PTRDIFF_MAX / size) errors in push calls.
Definition koliseo.h:173
KLS_hook_on_temp_start * on_temp_start_handler
Used to pass custom start handler for kls_temp_start calls.
Definition koliseo.h:199
KLS_hook_on_free * on_free_handler
Used to pass custom free handler for kls_free calls.
Definition koliseo.h:197
KLS_hook_on_temp_free * on_temp_free_handler
Used to pass custom free handler for kls_temp_end calls.
Definition koliseo.h:200
KLS_hook_on_push * on_push_handler
Used to pass custom push handler for kls_push calls.
Definition koliseo.h:198
KLS_hook_on_new * on_new_handler
Used to pass custom new handler for kls_new_alloc calls.
Definition koliseo.h:196
KLS_hook_on_temp_push * on_temp_push_handler
Used to pass custom push handler for kls_temp_push calls.
Definition koliseo.h:201
Defines the result for kls__advance() and kls__temp_advance().
Definition koliseo.h:383
KLS_Push_Error error
Definition koliseo.h:385
void * p
Definition koliseo.h:384
Defines a stat struct for Koliseo.
Definition koliseo.h:248
int tot_pops
Total POP calls done.
Definition koliseo.h:251
double worst_pushcall_time
DEPRECATED: support for timing will be dropped in the next release.
Definition koliseo.h:258
int tot_temp_pushes
Total PUSH_T calls done.
Definition koliseo.h:250
int tot_pushes
Total PUSH calls done.
Definition koliseo.h:249
int tot_temp_pops
Total POP_T calls done.
Definition koliseo.h:252
Represents a savestate for a Koliseo.
Definition koliseo.h:355
ptrdiff_t offset
Current position of memory pointer.
Definition koliseo.h:357
ptrdiff_t prev_offset
Previous position of memory pointer.
Definition koliseo.h:358
Koliseo * kls
Reference to the actual Koliseo we're saving.
Definition koliseo.h:356
Represents the initialised arena allocator struct.
Definition koliseo.h:316
ptrdiff_t size
Size of data field.
Definition koliseo.h:318
ptrdiff_t offset
Current position of memory pointer.
Definition koliseo.h:319
ptrdiff_t prev_offset
Previous position of memory pointer.
Definition koliseo.h:320
KLS_Conf conf
Contains flags to change the Koliseo behaviour.
Definition koliseo.h:322
struct Koliseo_Temp * t_kls
Points to related active Kolieo_Temp, when has_temp == 1.
Definition koliseo.h:324
KLS_Hooks hooks
Contains handlers for extensions.
Definition koliseo.h:325
char * data
Points to data field.
Definition koliseo.h:317
struct Koliseo * next
Points to the next Koliseo when conf.growable == 1.
Definition koliseo.h:329
void * extension_data
Points to data for extensions.
Definition koliseo.h:326
int has_temp
When == 1, a Koliseo_Temp is currently active on this Koliseo.
Definition koliseo.h:321
KLS_Stats stats
Contains stats for Koliseo performance analysis.
Definition koliseo.h:323
kls_free_func * free_func
Points to the free function for the arena's backing memory.
Definition koliseo.h:328