21 .kls_collect_stats = 0,
23 .kls_block_while_has_temp = 1,
24 .kls_allow_zerocount_push = 0,
27 .kls_log_filepath =
"",
29#ifndef KOLISEO_HAS_LOCATE
34 .OOM_handler = &KLS_OOM_default_handler_dbg__,
35 .PTRDIFF_MAX_handler = &KLS_PTRDIFF_MAX_default_handler_dbg__,
36 .ZEROCOUNT_handler = &KLS_ZEROCOUNT_default_handler_dbg__,
49 .worst_pushcall_time = -1,
53static bool kls_set_conf(Koliseo * kls, KLS_Conf conf);
61 return KOLISEO_API_VERSION_STRING;
70 return KOLISEO_API_VERSION_INT;
82#ifndef KOLISEO_HAS_LOCATE
85void KLS_OOM_default_handler_dbg__(Koliseo* kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size, ptrdiff_t count, Koliseo_Loc loc)
88#ifndef KOLISEO_HAS_LOCATE
90 "[KLS] Out of memory. size*count [%td] was bigger than available-padding [%td].\n",
91 size * count, available - padding);
94 "[KLS] " KLS_Loc_Fmt
"Out of memory. size*count [%td] was bigger than available-padding [%td].\n",
96 size * count, available - padding);
102#ifndef KOLISEO_HAS_LOCATE
105void KLS_PTRDIFF_MAX_default_handler_dbg__(
struct Koliseo* kls, ptrdiff_t size, ptrdiff_t count, Koliseo_Loc loc)
109#ifndef KOLISEO_HAS_LOCATE
111 "[KLS] count [%td] was bigger than PTRDIFF_MAX/size [%li].\n",
112 count, PTRDIFF_MAX / size);
115 "[KLS] " KLS_Loc_Fmt
"count [%td] was bigger than PTRDIFF_MAX/size [%li].\n",
117 count, PTRDIFF_MAX / size);
120#ifndef KOLISEO_HAS_LOCATE
122 "[KLS] count [%td] was bigger than PTRDIFF_MAX/size [%lli].\n",
123 count, PTRDIFF_MAX / size);
126 "[KLS] " KLS_Loc_Fmt
"count [%td] was bigger than PTRDIFF_MAX/size [%lli].\n",
128 count, PTRDIFF_MAX / size);
144#ifndef KOLISEO_HAS_LOCATE
147void KLS_ZEROCOUNT_default_handler_dbg__(Koliseo* kls, ptrdiff_t available, ptrdiff_t padding, ptrdiff_t size, Koliseo_Loc loc)
150#ifndef KOLISEO_HAS_LOCATE
152 "[KLS] Doing a zero-count push. size [%td] padding [%td] available [%td].\n",
153 size, padding, available);
156 "[KLS] " KLS_Loc_Fmt
"Doing a zero-count push. size [%td] padding [%td] available [%td].\n",
158 size, padding, available);
169KLS_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)
172 res.kls_collect_stats = collect_stats;
173 res.kls_verbose_lvl = verbose_lvl;
174 res.kls_block_while_has_temp = block_while_has_temp;
175 res.kls_allow_zerocount_push = allow_zerocount_push;
176 res.kls_growable = growable;
177 res.kls_log_fp = log_fp;
178 res.kls_log_filepath = log_filepath;
180 if (err_handlers.OOM_handler != NULL) {
181 res.err_handlers.OOM_handler = err_handlers.OOM_handler;
183#ifndef KOLISEO_HAS_LOCATE
186 res.err_handlers.OOM_handler = &KLS_OOM_default_handler_dbg__;
190 if (err_handlers.PTRDIFF_MAX_handler != NULL) {
191 res.err_handlers.PTRDIFF_MAX_handler = err_handlers.PTRDIFF_MAX_handler;
193#ifndef KOLISEO_HAS_LOCATE
196 res.err_handlers.PTRDIFF_MAX_handler = &KLS_PTRDIFF_MAX_default_handler_dbg__;
200 if (err_handlers.ZEROCOUNT_handler != NULL) {
201 res.err_handlers.ZEROCOUNT_handler = err_handlers.ZEROCOUNT_handler;
203#ifndef KOLISEO_HAS_LOCATE
206 res.err_handlers.ZEROCOUNT_handler = &KLS_ZEROCOUNT_default_handler_dbg__;
217KLS_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)
219 KLS_Err_Handlers err_handlers = KLS_DEFAULT_ERR_HANDLERS;
220 return kls_conf_init_handled(collect_stats, verbose_lvl, block_while_has_temp, allow_zerocount_push, growable, log_fp, log_filepath, err_handlers);
228#ifdef KOLISEO_HAS_LOCATE
229 bool kls_locate =
true;
231 bool kls_locate =
false;
234 bool kls_debug =
true;
236 bool kls_debug =
false;
238#ifdef KOLISEO_HAS_EXPER
239 bool kls_exper =
true;
241 bool kls_exper =
false;
248 int total_enabled = 0;
249 for (
int i=0; i<3; i++) {
254 fprintf(stderr,
"[KLS] Enabled features: {");
255 if (total_enabled == 0) {
256 fprintf(stderr,
"none}\n");
260 fprintf(stderr,
"debug%s", (total_enabled > 1 ?
", " :
""));
264 fprintf(stderr,
"locate%s", (total_enabled > 1 ?
", " :
""));
268 fprintf(stderr,
"exper");
270 fprintf(stderr,
"}\n");
290void kls_log(Koliseo *kls,
const char *tag,
const char *format, ...)
293 fprintf(stderr,
"[KLS] %s(): Passed kls was NULL.\n", __func__);
296 if (kls->conf.kls_verbose_lvl > 0) {
298 FILE *fp = kls->conf.kls_log_fp;
299 va_start(args, format);
302 "[KLS] %s(): Failed opening file to print logs.\n",
305 time_t now = time(0);
306 const struct tm *mytime = localtime(&now);
307 char timeheader[500];
308 if (strftime(timeheader,
sizeof timeheader,
"%X", mytime)) {
309 fprintf(fp,
"[%-10.10s] [%s] [", tag, timeheader);
310 vfprintf(fp, format, args);
335#ifndef KOLISEO_HAS_LOCATE
336Koliseo *
kls_new_alloc_ext(ptrdiff_t size, kls_alloc_func alloc_func, kls_free_func free_func, KLS_Hooks ext_handlers,
void* user)
338Koliseo *kls_new_alloc_ext_dbg(ptrdiff_t size, kls_alloc_func alloc_func, kls_free_func free_func, KLS_Hooks ext_handlers,
void* user, Koliseo_Loc loc)
341 if (size < (ptrdiff_t)
sizeof(Koliseo)) {
342#ifndef KOLISEO_HAS_LOCATE
344 "[ERROR] at %s(): invalid requested kls size (%td). Min accepted is: (%td).\n",
345 __func__, size, (ptrdiff_t)
sizeof(Koliseo));
348 "[ERROR] " KLS_Loc_Fmt
"%s(): invalid requested kls size (%td). Min accepted is: (%td).\n",
349 KLS_Loc_Arg(loc), __func__, size, (ptrdiff_t)
sizeof(Koliseo));
354 void *p = alloc_func(size);
363 kls->offset =
sizeof(*kls);
364 kls->prev_offset = kls->offset;
369 kls->conf.kls_log_fp = stderr;
370 kls->hooks = ext_handlers;
371 kls->extension_data = user;
372 kls->free_func = free_func;
375 kls_log(kls,
"KLS",
"API Level { %i } -> Allocated (%s) for new KLS.",
377 kls_log(kls,
"KLS",
"KLS offset: { %p }.", kls);
378 kls_log(kls,
"KLS",
"Allocation begin offset: { %p }.",
382 if (kls->hooks.on_new_handler != NULL) {
384 kls->hooks.on_new_handler(kls);
387#ifndef KOLISEO_HAS_LOCATE
388 fprintf(stderr,
"[KLS] Failed %s() call.\n", __func__);
390 fprintf(stderr,
"[KLS] " KLS_Loc_Fmt
"Failed %s() call.\n", KLS_Loc_Arg(loc), __func__);
395 Koliseo *kls_ref = p;
396 if (kls_ref->conf.kls_verbose_lvl > 0) {
418#ifndef KOLISEO_HAS_LOCATE
419Koliseo *
kls_new_alloc(ptrdiff_t size, kls_alloc_func alloc_func, kls_free_func free_func)
421Koliseo *kls_new_alloc_dbg(ptrdiff_t size, kls_alloc_func alloc_func, kls_free_func free_func, Koliseo_Loc loc)
424#ifndef KOLISEO_HAS_LOCATE
427 return kls_new_alloc_ext_dbg(size, alloc_func, free_func,
KLS_DEFAULT_HOOKS, KLS_DEFAULT_EXTENSION_DATA, loc);
447Koliseo *
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)
450 bool conf_res = kls_set_conf(k, conf);
453 "[ERROR] [%s()]: Failed to set config for new Koliseo.\n",
476Koliseo *
kls_new_conf_alloc(ptrdiff_t size, KLS_Conf conf, kls_alloc_func alloc_func, kls_free_func free_func)
496Koliseo *
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)
499#ifndef KLS_DEBUG_CORE
501 "[WARN] %s(): KLS_DEBUG_CORE is not defined. No tracing allowed.\n",
504 KLS_Conf k = (KLS_Conf) {
505 .kls_collect_stats = 1,.kls_verbose_lvl =
506 1,.kls_log_filepath = output_path,
507#ifndef KOLISEO_HAS_LOCATE
511 .err_handlers.OOM_handler = (err_handlers.OOM_handler != NULL ? err_handlers.OOM_handler : &KLS_OOM_default_handler_dbg__),
512 .err_handlers.PTRDIFF_MAX_handler = ( err_handlers.PTRDIFF_MAX_handler != NULL ? err_handlers.PTRDIFF_MAX_handler : &KLS_PTRDIFF_MAX_default_handler_dbg__),
532Koliseo *
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)
549Koliseo *
kls_new_traced_ext(ptrdiff_t size,
const char *output_path, KLS_Hooks ext_handlers,
void* user)
551 KLS_Err_Handlers err_handlers = KLS_DEFAULT_ERR_HANDLERS;
568Koliseo *
kls_new_traced_alloc(ptrdiff_t size,
const char *output_path, kls_alloc_func alloc_func, kls_free_func free_func)
570 KLS_Err_Handlers err_handlers = KLS_DEFAULT_ERR_HANDLERS;
587Koliseo *
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)
589#ifndef KLS_DEBUG_CORE
591 "[WARN] %s(): KLS_DEBUG_CORE is not defined. No debugging support.\n",
594 KLS_Conf k = (KLS_Conf) {
595 .kls_collect_stats = 1,.kls_verbose_lvl = 0,
596#ifndef KOLISEO_HAS_LOCATE
600 .err_handlers.OOM_handler = ( err_handlers.OOM_handler != NULL ? err_handlers.OOM_handler : &KLS_OOM_default_handler_dbg__),
601 .err_handlers.PTRDIFF_MAX_handler = ( err_handlers.PTRDIFF_MAX_handler != NULL ? err_handlers.PTRDIFF_MAX_handler : &KLS_PTRDIFF_MAX_default_handler_dbg__),
605 kls->conf.kls_verbose_lvl = 1;
638 KLS_Err_Handlers err_handlers = KLS_DEFAULT_ERR_HANDLERS;
655 KLS_Err_Handlers err_handlers = KLS_DEFAULT_ERR_HANDLERS;
665bool kls_set_conf(Koliseo *kls, KLS_Conf conf)
668 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
674 if (kls->conf.kls_log_fp == NULL) {
675 kls->conf.kls_log_fp = stderr;
677#ifdef KLS_SETCONF_DEBUG
679 "[%s()]: Preliminary set of conf.kls_log_fp to stderr.",
685 if (conf.err_handlers.OOM_handler == NULL) {
687 "[ERROR] at %s(): passed OOM_handler is NULL. Using default.\n",
690#ifdef KLS_SETCONF_DEBUG
692 "[%s()]: Passed OOM_handler was NULL, using default.",
696#ifndef KOLISEO_HAS_LOCATE
699 kls->conf.err_handlers.OOM_handler = &KLS_OOM_default_handler_dbg__;
703 if (conf.err_handlers.PTRDIFF_MAX_handler == NULL) {
705 "[ERROR] at %s(): passed PTRDIFF_MAX_handler is NULL. Using default.\n",
708#ifdef KLS_SETCONF_DEBUG
710 "[%s()]: Passed PTRDIFF_MAX_handler was NULL, using default.",
714#ifndef KOLISEO_HAS_LOCATE
717 kls->conf.err_handlers.PTRDIFF_MAX_handler = &KLS_PTRDIFF_MAX_default_handler_dbg__;
721#ifndef KLS_DEBUG_CORE
722 if (kls->conf.kls_collect_stats == 1) {
724 "[WARN] [%s()]: KLS_DEBUG_CORE is not defined. Stats may not be collected in full.\n",
729 if (kls->conf.kls_verbose_lvl > 0) {
730 if (kls->conf.kls_log_fp != NULL) {
732#ifdef KLS_SETCONF_DEBUG
734 "[%s()]: kls->conf.kls_log_fp was not NULL. Overriding it.",
738 if (kls->conf.kls_collect_stats == 1) {
739 kls->stats.tot_hiccups += 1;
744 log_fp = fopen(kls->conf.kls_log_filepath,
"w");
747 "[ERROR] [%s()]: Failed opening logfile at {\"%s\"} [write].\n",
748 __func__, kls->conf.kls_log_filepath);
751 fprintf(log_fp,
"%s",
"");
754 log_fp = fopen(kls->conf.kls_log_filepath,
"a");
757 "[ERROR] [%s()]: Failed opening logfile at {\"%s\"} [append].\n",
758 __func__, kls->conf.kls_log_filepath);
761 kls->conf.kls_log_fp = log_fp;
767static bool kls__try_grow(Koliseo* kls, ptrdiff_t needed);
781#ifndef KOLISEO_HAS_LOCATE
784int kls__check_available_failable_dbg(Koliseo* kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count,
const char* caller_name, Koliseo_Loc loc)
788 assert(caller_name != NULL);
790#ifndef KOLISEO_HAS_LOCATE
792 "[KLS] %s(): count [%td] was < 0.\n",
797 "[KLS] " KLS_Loc_Fmt
"%s(): count [%td] was < 0.\n",
805#ifndef KOLISEO_HAS_LOCATE
807 "[KLS] %s(): size [%td] was < 1.\n",
812 "[KLS] " KLS_Loc_Fmt
"%s(): size [%td] was < 1.\n",
820#ifndef KOLISEO_HAS_LOCATE
822 "[KLS] %s(): align [%td] was < 1.\n",
827 "[KLS] " KLS_Loc_Fmt
"%s(): align [%td] was < 1.\n",
834 if (! ((align & (align - 1)) == 0)) {
835#ifndef KOLISEO_HAS_LOCATE
837 "[KLS] %s(): align [%td] was not a power of 2.\n",
842 "[KLS] " KLS_Loc_Fmt
"%s(): align [%td] was not a power of 2.\n",
849 Koliseo* current = kls;
850 while (current->next != NULL) {
851 current = current->next;
853 const ptrdiff_t available = current->size - current->offset;
854 const ptrdiff_t padding = -current->offset & (align - 1);
855 bool ZEROCOUNT_happened =
false;
856 bool ZEROCOUNT_handled =
false;
858 if (current->conf.kls_allow_zerocount_push != 1) {
859 ZEROCOUNT_happened =
true;
860 if (current->conf.err_handlers.ZEROCOUNT_handler != NULL) {
861#ifndef KOLISEO_HAS_LOCATE
862 current->conf.err_handlers.ZEROCOUNT_handler(current, available, padding, size);
864 current->conf.err_handlers.ZEROCOUNT_handler(current, available, padding, size, loc);
866 ZEROCOUNT_handled =
true;
868#ifndef KOLISEO_HAS_LOCATE
870 "[KLS] %s(): Doing a zero-count push. size [%td] padding [%td] available [%td].\n",
872 size, padding, available);
875 "[KLS] " KLS_Loc_Fmt
"%s(): Doing a zero-count push. size [%td] padding [%td] available [%td].\n",
878 size, padding, available);
885 kls_log(current,
"DEBUG",
"Accepting zero-count push: conf.kls_allow_zerocount_push was 1");
890 if (ZEROCOUNT_happened && ZEROCOUNT_handled) {
892 kls_log(current,
"DEBUG",
"Requested a zero-count push while kls_allow_zerocount_push is not 1, but the error handler returned instead of exiting.");
894#ifndef KOLISEO_HAS_LOCATE
896 "[KLS] %s(): Doing a zero-count push. size [%td] padding [%td] available [%td].\n",
898 size, padding, available);
901 "[KLS] " KLS_Loc_Fmt
"%s(): Doing a zero-count push. size [%td] padding [%td] available [%td].\n",
904 size, padding, available);
910 bool OOM_happened =
false;
911 bool OOM_handled =
false;
912 bool PTRDIFF_MAX_happened =
false;
913 bool PTRDIFF_MAX_handled =
false;
914 if (count > PTRDIFF_MAX / size || available - padding < size * count) {
915 if (count > PTRDIFF_MAX / size) {
916 PTRDIFF_MAX_happened =
true;
917 if (current->conf.err_handlers.PTRDIFF_MAX_handler != NULL) {
918#ifndef KOLISEO_HAS_LOCATE
919 current->conf.err_handlers.PTRDIFF_MAX_handler(current, size, count);
921 current->conf.err_handlers.PTRDIFF_MAX_handler(current, size, count, loc);
923 PTRDIFF_MAX_handled =
true;
926#ifndef KOLISEO_HAS_LOCATE
928 "[KLS] %s(): count [%td] was bigger than PTRDIFF_MAX/size [%li].\n",
930 count, PTRDIFF_MAX / size);
933 "[KLS] " KLS_Loc_Fmt
"%s(): count [%td] was bigger than PTRDIFF_MAX/size [%li].\n",
936 count, PTRDIFF_MAX / size);
939#ifndef KOLISEO_HAS_LOCATE
941 "[KLS] %s(): count [%td] was bigger than PTRDIFF_MAX/size [%lli].\n",
943 count, PTRDIFF_MAX / size);
946 "[KLS] " KLS_Loc_Fmt
"%s(): count [%td] was bigger than PTRDIFF_MAX/size [%lli].\n",
949 count, PTRDIFF_MAX / size);
954 if (current->conf.kls_growable == 1 && kls__try_grow(current, size + count + padding)) {
958 if (current->conf.err_handlers.OOM_handler != NULL) {
959#ifndef KOLISEO_HAS_LOCATE
960 current->conf.err_handlers.OOM_handler(current, available, padding, size, count);
962 current->conf.err_handlers.OOM_handler(current, available, padding, size, count, loc);
966#ifndef KOLISEO_HAS_LOCATE
968 "[KLS] %s(): Out of memory. size*count [%td] was bigger than available-padding [%td].\n",
970 size * count, available - padding);
973 "[KLS] " KLS_Loc_Fmt
"%s(): Out of memory. size*count [%td] was bigger than available-padding [%td].\n",
976 size * count, available - padding);
980 if (PTRDIFF_MAX_happened) {
981 if (current->conf.err_handlers.PTRDIFF_MAX_handler && PTRDIFF_MAX_handled) {
982#ifndef KOLISEO_HAS_LOCATE
983 fprintf(stderr,
"[KLS] %s(): PTRDIFF_MAX fault happened and was handled.\n", caller_name);
985 kls_log(current,
"DEBUG",
"%s(): PTRDIFF_MAX fault happened and was handled.", caller_name);
988 fprintf(stderr,
"[KLS] " KLS_Loc_Fmt
"%s(): PTRDIFF_MAX fault happened and was handled.\n", KLS_Loc_Arg(loc), caller_name);
990 kls_log(current,
"DEBUG", KLS_Loc_Fmt
"%s(): PTRDIFF_MAX fault happened and was handled.", KLS_Loc_Arg(loc), caller_name);
995 }
else if (OOM_happened) {
996 if (current->conf.err_handlers.PTRDIFF_MAX_handler && OOM_handled) {
997#ifndef KOLISEO_HAS_LOCATE
998 fprintf(stderr,
"[KLS] %s(): OOM fault happened and was handled.\n", caller_name);
1000 kls_log(current,
"DEBUG",
"%s(): OOM fault happened and was handled.", caller_name);
1003 fprintf(stderr,
"[KLS] " KLS_Loc_Fmt
"%s(): OOM fault happened and was handled.\n", KLS_Loc_Arg(loc), caller_name);
1004#ifdef KLS_DEBUG_CORE
1005 kls_log(current,
"DEBUG", KLS_Loc_Fmt
"%s(): OOM fault happened and was handled.", KLS_Loc_Arg(loc), caller_name);
1011#ifndef KOLISEO_HAS_LOCATE
1012 fprintf(stderr,
"[KLS] Failed %s() call.\n", caller_name);
1014 fprintf(stderr,
"[KLS] " KLS_Loc_Fmt
"Failed %s() call.\n", KLS_Loc_Arg(loc), caller_name);
1022bool kls__try_grow(Koliseo* kls, ptrdiff_t needed)
1024 ptrdiff_t new_size = KLS_MAX(kls->size * 2, needed);
1025 Koliseo* new_kls =
kls_new_conf_alloc_ext(new_size, kls->conf, KLS_DEFAULT_ALLOCF, KLS_DEFAULT_FREEF, kls->hooks, kls->extension_data);
1026 kls_log(kls,
"DEBUG",
"%s(): growing Koliseo, new size: {%td}", __func__, new_size);
1027 if (!new_kls)
return false;
1028 kls->next = new_kls;
1041void *
kls_push(Koliseo *kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count)
1044#ifdef KLS_DEBUG_CORE
1046 struct timespec start_time, end_time;
1047 clock_gettime(CLOCK_MONOTONIC, &start_time);
1049 LARGE_INTEGER start_time, end_time, frequency;
1050 QueryPerformanceFrequency(&frequency);
1051 QueryPerformanceCounter(&start_time);
1056 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
1059 if ((kls->has_temp == 1) && (kls->conf.kls_block_while_has_temp == 1)) {
1060 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo has an open Koliseo_Temp session.\n", __func__);
1061#ifdef KLS_DEBUG_CORE
1062 kls_log(kls,
"ERROR",
"[%s()]: Passed Koliseo has an open Koliseo_Temp session.", __func__);
1067#ifndef KOLISEO_HAS_LOCATE
1068 kls__check_available(kls, size, align, count);
1070 kls__check_available_dbg(kls, size, align, count, KLS_HERE);
1072 Koliseo* current = kls;
1073 while (current->next != NULL) {
1074 current = current->next;
1076 ptrdiff_t padding = -current->offset & (align - 1);
1077 char *p = current->data + current->offset + padding;
1078 current->prev_offset = current->offset;
1079 current->offset += padding + size * count;
1084#ifdef KLS_DEBUG_CORE
1085 kls_log(current,
"KLS",
"Curr offset: { %p }.", current + current->offset);
1086 kls_log(current,
"KLS",
"API Level { %i } -> Pushed size (%s) for KLS.",
1088 if (current->conf.kls_verbose_lvl > 0) {
1091 if (current->conf.kls_collect_stats == 1) {
1093 clock_gettime(CLOCK_MONOTONIC, &end_time);
1094 double elapsed_time =
1095 (end_time.tv_sec - start_time.tv_sec) + (end_time.tv_nsec -
1096 start_time.tv_nsec) / 1e9;
1098 QueryPerformanceCounter(&end_time);
1099 double elapsed_time =
1100 (double)(end_time.QuadPart -
1101 start_time.QuadPart) / frequency.QuadPart;
1103 if (elapsed_time > current->stats.worst_pushcall_time) {
1104 current->stats.worst_pushcall_time = elapsed_time;
1108 if (current->conf.kls_collect_stats == 1) {
1109 current->stats.tot_pushes += 1;
1123#ifndef KOLISEO_HAS_LOCATE
1127void *kls_push_zero_dbg(Koliseo *kls, ptrdiff_t size, ptrdiff_t align,
1128 ptrdiff_t count, Koliseo_Loc loc)
1132#ifdef KLS_DEBUG_CORE
1134 struct timespec start_time, end_time;
1135 clock_gettime(CLOCK_MONOTONIC, &start_time);
1137 LARGE_INTEGER start_time, end_time, frequency;
1138 QueryPerformanceFrequency(&frequency);
1139 QueryPerformanceCounter(&start_time);
1144 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
1147 if ((kls->has_temp == 1) && (kls->conf.kls_block_while_has_temp == 1)) {
1148#ifndef KOLISEO_HAS_LOCATE
1149 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo has an open Koliseo_Temp session.\n", __func__);
1151 fprintf(stderr,
"[ERROR] " KLS_Loc_Fmt
"[%s()]: Passed Koliseo has an open Koliseo_Temp session.\n", KLS_Loc_Arg(loc), __func__);
1152 kls_log(kls,
"ERROR", KLS_Loc_Fmt
"[%s()]: Passed Koliseo has an open Koliseo_Temp session.", KLS_Loc_Arg(loc), __func__);
1157#ifndef KOLISEO_HAS_LOCATE
1158 kls__check_available(kls, size, align, count);
1160 kls__check_available_dbg(kls, size, align, count, loc);
1162 Koliseo* current = kls;
1163 while (current->next != NULL) {
1164 current = current->next;
1166 ptrdiff_t padding = -current->offset & (align - 1);
1167 char *p = current->data + current->offset + padding;
1169 memset(p, 0, size * count);
1170 current->prev_offset = current->offset;
1171 current->offset += padding + size * count;
1176#ifdef KLS_DEBUG_CORE
1177 kls_log(current,
"KLS",
"Curr offset: { %p }.", current + current->offset);
1178 kls_log(current,
"KLS",
"API Level { %i } -> Pushed zeroes, size (%s) for KLS.",
1180 if (current->conf.kls_verbose_lvl > 0) {
1183 if (current->conf.kls_collect_stats == 1) {
1185 clock_gettime(CLOCK_MONOTONIC, &end_time);
1186 double elapsed_time =
1187 (end_time.tv_sec - start_time.tv_sec) + (end_time.tv_nsec -
1188 start_time.tv_nsec) / 1e9;
1190 QueryPerformanceCounter(&end_time);
1191 double elapsed_time =
1192 (double)(end_time.QuadPart -
1193 start_time.QuadPart) / frequency.QuadPart;
1195 if (elapsed_time > current->stats.worst_pushcall_time) {
1196 current->stats.worst_pushcall_time = elapsed_time;
1200 if (current->conf.kls_collect_stats == 1) {
1201 current->stats.tot_pushes += 1;
1215#ifndef KOLISEO_HAS_LOCATE
1219void *kls_push_zero_ext_dbg(Koliseo *kls, ptrdiff_t size, ptrdiff_t align,
1220 ptrdiff_t count, Koliseo_Loc loc)
1224#ifdef KLS_DEBUG_CORE
1226 struct timespec start_time, end_time;
1227 clock_gettime(CLOCK_MONOTONIC, &start_time);
1229 LARGE_INTEGER start_time, end_time, frequency;
1230 QueryPerformanceFrequency(&frequency);
1231 QueryPerformanceCounter(&start_time);
1236 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
1239 if ((kls->has_temp == 1) && (kls->conf.kls_block_while_has_temp == 1)) {
1240#ifndef KOLISEO_HAS_LOCATE
1241 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo has an open Koliseo_Temp session.\n", __func__);
1243 fprintf(stderr,
"[ERROR] " KLS_Loc_Fmt
"[%s()]: Passed Koliseo has an open Koliseo_Temp session.\n", KLS_Loc_Arg(loc), __func__);
1244 kls_log(kls,
"ERROR", KLS_Loc_Fmt
"[%s()]: Passed Koliseo has an open Koliseo_Temp session.", KLS_Loc_Arg(loc), __func__);
1250#ifndef KOLISEO_HAS_LOCATE
1251 kls__check_available(kls, size, align, count);
1253 kls__check_available_dbg(kls, size, align, count, loc);
1255 Koliseo* current = kls;
1256 while (current->next != NULL) {
1257 current = current->next;
1259 ptrdiff_t padding = -current->offset & (align - 1);
1260 char *p = current->data + current->offset + padding;
1262 memset(p, 0, size * count);
1263 current->prev_offset = current->offset;
1264 current->offset += padding + size * count;
1266 if (current->hooks.on_push_handler != NULL) {
1284 current->hooks.on_push_handler(current, padding, __func__, NULL);
1291#ifdef KLS_DEBUG_CORE
1292 kls_log(current,
"KLS",
"Curr offset: { %p }.", current + current->offset);
1293 kls_log(current,
"KLS",
"API Level { %i } -> Pushed zeroes, size (%s) for KLS.",
1295 if (current->conf.kls_verbose_lvl > 0) {
1298 if (current->conf.kls_collect_stats == 1) {
1300 clock_gettime(CLOCK_MONOTONIC, &end_time);
1301 double elapsed_time =
1302 (end_time.tv_sec - start_time.tv_sec) + (end_time.tv_nsec -
1303 start_time.tv_nsec) / 1e9;
1305 QueryPerformanceCounter(&end_time);
1306 double elapsed_time =
1307 (double)(end_time.QuadPart -
1308 start_time.QuadPart) / frequency.QuadPart;
1310 if (elapsed_time > current->stats.worst_pushcall_time) {
1311 current->stats.worst_pushcall_time = elapsed_time;
1315 if (current->conf.kls_collect_stats == 1) {
1316 current->stats.tot_pushes += 1;
1331#ifndef KOLISEO_HAS_LOCATE
1333 ptrdiff_t align, ptrdiff_t count)
1335void *kls_temp_push_zero_ext_dbg(Koliseo_Temp *t_kls, ptrdiff_t size,
1336 ptrdiff_t align, ptrdiff_t count, Koliseo_Loc loc)
1340#ifdef KLS_DEBUG_CORE
1342 struct timespec start_time, end_time;
1343 clock_gettime(CLOCK_MONOTONIC, &start_time);
1345 LARGE_INTEGER start_time, end_time, frequency;
1346 QueryPerformanceFrequency(&frequency);
1347 QueryPerformanceCounter(&start_time);
1351 if (t_kls == NULL) {
1352 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo_Temp was NULL.\n",
1356 Koliseo *kls = t_kls->kls;
1358 fprintf(stderr,
"[ERROR] [%s()]: Referred Koliseo was NULL.\n",
1362#ifndef KOLISEO_HAS_LOCATE
1363 kls__check_available(kls, size, align, count);
1365 kls__check_available_dbg(kls, size, align, count, loc);
1367 Koliseo* current = kls;
1368 while (current->next != NULL) {
1369 current = current->next;
1371 ptrdiff_t padding = -current->offset & (align - 1);
1372 char *p = current->data + current->offset + padding;
1374 memset(p, 0, size * count);
1375 current->prev_offset = current->offset;
1376 current->offset += padding + size * count;
1378 if (current->hooks.on_temp_push_handler != NULL) {
1380 current->hooks.on_temp_push_handler(t_kls, padding, __func__, NULL);
1387#ifdef KLS_DEBUG_CORE
1388 if (current->conf.kls_collect_stats == 1) {
1390 clock_gettime(CLOCK_MONOTONIC, &end_time);
1391 double elapsed_time =
1392 (end_time.tv_sec - start_time.tv_sec) + (end_time.tv_nsec -
1393 start_time.tv_nsec) / 1e9;
1395 QueryPerformanceCounter(&end_time);
1396 double elapsed_time =
1397 (double)(end_time.QuadPart -
1398 start_time.QuadPart) / frequency.QuadPart;
1400 if (elapsed_time > current->stats.worst_pushcall_time) {
1401 current->stats.worst_pushcall_time = elapsed_time;
1404 kls_log(current,
"KLS",
"Curr offset: { %p }.", current + current->offset);
1406 "API Level { %i } -> Pushed zeroes, size (%s) for Temp_KLS.",
1408 if (current->conf.kls_verbose_lvl > 0) {
1412 if (current->conf.kls_collect_stats == 1) {
1413 current->stats.tot_temp_pushes += 1;
1426 fprintf(stderr,
"print_kls_2file(): fp was NULL.\n");
1430 fprintf(fp,
"[KLS] kls was NULL.\n");
1433 fprintf(fp,
"\n[INFO] Conf: { " KLS_Conf_Fmt
" }\n",
1434 KLS_Conf_Arg(kls->conf));
1435 fprintf(fp,
"\n[INFO] Stats: { " KLS_Stats_Fmt
" }\n",
1436 KLS_Stats_Arg(kls->stats));
1437 fprintf(fp,
"\n[KLS] Size: { %td }\n", kls->size);
1438 char human_size[200];
1439 char curr_size[200];
1441 fprintf(fp,
"[KLS] Size (Human): { %s }\n", human_size);
1443 fprintf(fp,
"[KLS] Used (Human): { %s }\n", curr_size);
1444 fprintf(fp,
"[KLS] Offset: { %td }\n", kls->offset);
1445 fprintf(fp,
"[KLS] Prev_Offset: { %td }\n", kls->prev_offset);
1457 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
1471 fprintf(stderr,
"print_temp_kls_2file(): fp was NULL.\n");
1474 if (t_kls == NULL) {
1475 fprintf(fp,
"[KLS_T] t_kls was NULL.");
1476 }
else if (t_kls->kls == NULL) {
1477 fprintf(fp,
"[KLS_T] [%s()]: Referred Koliseo was NULL.\n", __func__);
1479 const Koliseo *kls = t_kls->kls;
1481 fprintf(fp,
"\n[KLS_T] Temp Size: { %td }\n",
1482 kls->size - t_kls->offset);
1483 fprintf(fp,
"\n[KLS_T] Refer Size: { %td }\n", kls->size);
1484 char human_size[200];
1485 char curr_size[200];
1487 sizeof(human_size));
1488 fprintf(fp,
"[KLS_T] Temp Size Human: { %s }\n", human_size);
1490 fprintf(fp,
"[KLS_T] Refer Size Human: { %s }\n", human_size);
1492 fprintf(fp,
"[KLS_T] Inner Used (Human): { %s }\n", curr_size);
1494 fprintf(fp,
"[KLS_T] Temp Used (Human): { %s }\n", curr_size);
1495 fprintf(fp,
"[KLS_T] Inner Offset: { %td }\n", kls->offset);
1496 fprintf(fp,
"[KLS_T] Temp Offset: { %td }\n", t_kls->offset);
1497 fprintf(fp,
"[KLS_T] Inner Prev_Offset: { %td }\n", kls->prev_offset);
1498 fprintf(fp,
"[KLS_T] Temp Prev_Offset: { %td }\n\n",
1499 t_kls->prev_offset);
1521 const char *units[] =
1522 {
"bytes",
"KB",
"MB",
"GB",
"TB",
"PB",
"EB",
"ZB",
"YB" };
1523 const int numUnits =
sizeof(units) /
sizeof(units[0]);
1526 double sizeValue = (double)size;
1528 while (sizeValue >= 1000 && unitIndex < numUnits - 1) {
1533 snprintf(outputBuffer, bufferSize,
"%.2f %s", sizeValue, units[unitIndex]);
1544 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
1548 kls->prev_offset = kls->offset;
1549 kls->offset =
sizeof(*kls);
1550#ifdef KLS_DEBUG_CORE
1551 kls_log(kls,
"KLS",
"API Level { %i } -> Cleared offsets for KLS.",
1564 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
1567 Koliseo* current = kls;
1569 Koliseo* next = current->next;
1570 current->next = NULL;
1571 if (current->hooks.on_free_handler != NULL) {
1573 current->hooks.on_free_handler(current);
1575 if (current->has_temp == 1) {
1576#ifdef KLS_DEBUG_CORE
1578 "API Level { %i } -> KLS had an active Koliseo_Temp.",
1584#ifdef KLS_DEBUG_CORE
1585 kls_log(current,
"KLS",
"API Level { %i } -> Freeing KLS.",
1588 if (current->conf.kls_log_fp != NULL && current->conf.kls_log_fp != stdout
1589 && current->conf.kls_log_fp != stderr) {
1590#ifdef KLS_DEBUG_CORE
1591 kls_log(current,
"KLS",
"Closing kls log file. Path: {\"%s\"}.",
1592 kls->conf.kls_log_filepath);
1594 int close_res = fclose(current->conf.kls_log_fp);
1595 if (close_res != 0) {
1597 "[ERROR] %s(): Failed fclose() on log_fp. Path: {\"%s\"}.",
1598 __func__, current->conf.kls_log_filepath);
1600 }
else if (current->conf.kls_log_fp == stdout || current->conf.kls_log_fp == stderr) {
1601 if (current->conf.kls_verbose_lvl > 1) {
1603 "[INFO] %s(): kls->conf.kls_log_fp is %s. Not closing it.\n",
1605 (current->conf.kls_log_fp == stdout ?
"stdout" :
"stderr"));
1608 if (current->free_func == NULL) {
1610 "[ERROR] %s(): free function was NULL.\n", __func__);
1613 current->free_func(current);
1625#ifndef KOLISEO_HAS_LOCATE
1628Koliseo_Temp *kls_temp_start_dbg(Koliseo *kls, Koliseo_Loc loc)
1632 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
1635 Koliseo* current = kls;
1636 while (current->next != NULL) {
1637 current = current->next;
1639 if (current->has_temp != 0) {
1641 "[ERROR] [%s()]: Passed Koliseo->has_temp is not 0. {%i}\n",
1642 __func__, current->has_temp);
1643#ifdef KLS_DEBUG_CORE
1644 kls_log(current,
"ERROR",
"[%s()]: Passed Koliseo->has_temp != 0 . {%i}",
1645 __func__, current->has_temp);
1647 if (current->conf.kls_collect_stats == 1) {
1648 current->stats.tot_hiccups += 1;
1652 ptrdiff_t prev = current->prev_offset;
1653 ptrdiff_t off = current->offset;
1655 Koliseo_Temp *tmp = KLS_PUSH(current, Koliseo_Temp);
1657 tmp->prev_offset = prev;
1659#ifdef KLS_DEBUG_CORE
1660 kls_log(current,
"INFO",
"Passed kls conf: " KLS_Conf_Fmt
"\n",
1661 KLS_Conf_Arg(current->conf));
1664 current->has_temp = 1;
1665 current->t_kls = tmp;
1666 if (current->hooks.on_temp_start_handler != NULL) {
1668 current->hooks.on_temp_start_handler(tmp);
1670#ifdef KLS_DEBUG_CORE
1671 kls_log(current,
"KLS",
"Prepared new Temp KLS.");
1682 if (tmp_kls == NULL) {
1683 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo_Temp was NULL.\n",
1688 Koliseo *kls_ref = tmp_kls->kls;
1689 if (kls_ref == NULL) {
1690 fprintf(stderr,
"[ERROR] [%s()]: Referred Koliseo was NULL.\n",
1695 if (kls_ref->hooks.on_temp_free_handler != NULL) {
1697 kls_ref->hooks.on_temp_free_handler(tmp_kls);
1700#ifdef KLS_DEBUG_CORE
1701 kls_log(kls_ref,
"KLS",
"Ended Temp KLS.");
1703 tmp_kls->kls->has_temp = 0;
1704 tmp_kls->kls->t_kls = NULL;
1705 tmp_kls->kls->prev_offset = tmp_kls->prev_offset;
1706 tmp_kls->kls->offset = tmp_kls->offset;
1709 Koliseo* to_free = tmp_kls->kls->next;
1710 if (to_free != NULL) {
1712 tmp_kls->kls->next = NULL;
1716 if (kls_ref->conf.kls_collect_stats == 1) {
1717 kls_ref->stats.tot_temp_pushes = 0;
1718 kls_ref->stats.tot_temp_pops = 0;
1722#ifdef KOLISEO_HAS_EXPER
1731void *
kls_pop(Koliseo *kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count)
1734 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
1737 ptrdiff_t padding = -kls->offset & (align - 1);
1738 if (count > PTRDIFF_MAX / size
1739 || (kls->size + kls->offset) < (size * count)) {
1740 fprintf(stderr,
"[KLS] Failed %s() call.\n", __func__);
1744 char *p = kls->data + kls->offset - padding - size * count;
1745 kls->prev_offset = kls->offset;
1746 kls->offset -= padding + size * count;
1747#ifdef KLS_DEBUG_CORE
1748 kls_log(kls,
"KLS",
"API Level { %i } -> Popped (%li) for KLS.",
1750 if (kls->conf.kls_verbose_lvl > 0) {
1754 if (kls->conf.kls_collect_stats == 1) {
1755 kls->stats.tot_pops += 1;
1768void *
kls_pop_AR(Koliseo *kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count)
1771 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo was NULL.\n", __func__);
1774 ptrdiff_t padding = -kls->offset & (align - 1);
1775 if (count > PTRDIFF_MAX / size
1776 || (kls->size + kls->offset) < (size * count)) {
1777 fprintf(stderr,
"[KLS] Failed %s() call.\n", __func__);
1781 char *p = kls->data + kls->offset - padding - size * count;
1782 kls->prev_offset = kls->offset;
1783 kls->offset -= padding + size * count;
1784#ifdef KLS_DEBUG_CORE
1785 kls_log(kls,
"KLS",
"API Level { %i } -> Popped (%li) for KLS.",
1787 if (kls->conf.kls_verbose_lvl > 0) {
1791 if (kls->conf.kls_collect_stats == 1) {
1792 kls->stats.tot_pops += 1;
1808 if (t_kls == NULL) {
1809 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo_Temp was NULL.\n",
1813 Koliseo *kls = t_kls->kls;
1815 fprintf(stderr,
"[ERROR] [%s()]: Referred Koliseo was NULL.\n",
1819 ptrdiff_t padding = -kls->offset & (align - 1);
1820 if (count > PTRDIFF_MAX / size
1821 || (kls->size + kls->offset) < (size * count)) {
1822 fprintf(stderr,
"[KLS] Failed %s() call.\n", __func__);
1826 char *p = kls->data + kls->offset - padding - size * count;
1827 kls->prev_offset = kls->offset;
1828 kls->offset -= padding + size * count;
1829#ifdef KLS_DEBUG_CORE
1830 kls_log(kls,
"KLS",
"Curr offset: { %p }.", kls + kls->offset);
1831 kls_log(kls,
"KLS",
"API Level { %i } -> Popped (%li) for Temp_KLS.",
1833 if (kls->conf.kls_verbose_lvl > 0) {
1837 if (kls->conf.kls_collect_stats == 1) {
1838 kls->stats.tot_temp_pops += 1;
1851void *
kls_temp_pop_AR(Koliseo_Temp *t_kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count)
1853 if (t_kls == NULL) {
1854 fprintf(stderr,
"[ERROR] [%s()]: Passed Koliseo_Temp was NULL.\n",
1858 Koliseo *kls = t_kls->kls;
1860 fprintf(stderr,
"[ERROR] [%s()]: Referred Koliseo was NULL.\n",
1864 ptrdiff_t padding = -kls->offset & (align - 1);
1865 if (count > PTRDIFF_MAX / size
1866 || (kls->size + kls->offset) < (size * count)) {
1867 fprintf(stderr,
"[KLS] Failed %s() call.\n", __func__);
1871 char *p = kls->data + kls->offset - padding - size * count;
1872 kls->prev_offset = kls->offset;
1873 kls->offset -= padding + size * count;
1874#ifdef KLS_DEBUG_CORE
1875 kls_log(kls,
"KLS",
"Curr offset: { %p }.", kls + kls->offset);
1876 kls_log(kls,
"KLS",
"API Level { %i } -> Popped (%li) for Temp_KLS.",
1878 if (kls->conf.kls_verbose_lvl > 0) {
1882 if (kls->conf.kls_collect_stats == 1) {
1883 kls->stats.tot_temp_pops += 1;
1896 char* dest = KLS_PUSH_STR(kls, source);
1897 KLS__STRCPY(dest, source);
1909 char** strings = NULL;
1910 strings = KLS_PUSH_ARR(kls,
char*, count);
1911 for (
int i=0; i < count; i++) {
1912 strings[i] = KLS_STRDUP(kls, source[i]);
1925 char* dest = KLS_PUSH_STR_T(t_kls, source);
1926 KLS__STRCPY(dest, source);
1938 char** strings = NULL;
1939 strings = KLS_PUSH_ARR_T(t_kls,
char*, count);
1940 for (
int i=0; i < count; i++) {
1941 strings[i] = KLS_STRDUP_T(t_kls, source[i]);
#define KLS_DEFAULT_HOOKS
Definition kls_region.h:162
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:1894
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:1805
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:1626
void print_dbg_temp_kls(const Koliseo_Temp *t_kls)
Prints header fields from the passed Koliseo_Temp pointer, to stderr.
Definition koliseo.c:1507
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:653
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:1468
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:1923
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:532
KLS_Stats KLS_STATS_DEFAULT
Definition koliseo.c:41
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:290
void kls_temp_end(Koliseo_Temp *tmp_kls)
Ends passed Koliseo_Temp pointer.
Definition koliseo.c:1680
void kls_dbg_features(void)
Prints enabled Koliseo features to stderr.
Definition koliseo.c:226
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:1907
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:1332
void print_dbg_kls(const Koliseo *kls)
Prints header fields from the passed Koliseo pointer, to stderr.
Definition koliseo.c:1454
const char * string_koliseo_version(void)
Returns the constant string representing current version for Koliseo.
Definition koliseo.c:59
ptrdiff_t kls_get_pos(const Koliseo *kls)
Returns the current offset (position of pointer bumper) for the passed Koliseo.
Definition koliseo.c:279
void * kls_temp_pop_AR(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:1851
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:587
void * kls_pop_AR(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:1768
void kls_free(Koliseo *kls)
Calls kls_clear() on the passed Koliseo pointer and the frees the actual Koliseo.
Definition koliseo.c:1561
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:169
Koliseo * kls_new_dbg_ext(ptrdiff_t size, KLS_Hooks ext_handlers, void *user)
Takes a ptrdiff_t size.
Definition koliseo.c:636
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:1936
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:1041
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:621
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:1124
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:419
int kls__check_available_failable(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:782
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:568
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:1731
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:447
void KLS_PTRDIFF_MAX_default_handler__(struct Koliseo *kls, ptrdiff_t size, ptrdiff_t count)
Definition koliseo.c:103
KLS_Conf KLS_DEFAULT_CONF
Config used by any new Koliseo by default.
Definition koliseo.c:20
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:217
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:145
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:336
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:1423
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:496
void kls_clear(Koliseo *kls)
Resets the offset field for the passed Koliseo pointer.
Definition koliseo.c:1541
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:1216
void kls_formatSize(ptrdiff_t size, char *outputBuffer, size_t bufferSize)
Converts a ptrdiff_t size to human-readable SI units (modulo 1000).
Definition koliseo.c:1519
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:83
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:476
int int_koliseo_version(void)
Returns the constant int representing current version for Koliseo.
Definition koliseo.c:68
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:549