From fd910adc8613a5369a2354057e63bd30913c1e33 Mon Sep 17 00:00:00 2001 From: jgabaut <109908086+jgabaut@users.noreply.github.com> Date: Thu, 7 Sep 2023 12:21:38 +0200 Subject: [PATCH 1/3] feat: bump amboso to 1.6.4 --- amboso | 2 +- bin/stego.lock | 1 + bin/v0.1.20/.gitignore | 4 ++++ bin/v0.1.20/static | 1 + configure.ac | 4 ++-- docs/koliseo.doxyfile | 2 +- src/koliseo.h | 4 ++-- static/amboso.h | 2 +- 8 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 bin/v0.1.20/.gitignore create mode 120000 bin/v0.1.20/static diff --git a/amboso b/amboso index ca33168..14cff82 160000 --- a/amboso +++ b/amboso @@ -1 +1 @@ -Subproject commit ca331686a967f3d584e0e839d183526e12b74f13 +Subproject commit 14cff82de1f37cda4f2c4eaa37ab5d3e01a42987 diff --git a/bin/stego.lock b/bin/stego.lock index f3bad0a..286704f 100644 --- a/bin/stego.lock +++ b/bin/stego.lock @@ -23,3 +23,4 @@ tests# tests folder name 0.1.17# add kls_type_usage() 0.1.18# kls_push_zero_typed() expects int 0.1.19# add kls_print_title() +0.1.20# prune RegionList on kls_temp_end diff --git a/bin/v0.1.20/.gitignore b/bin/v0.1.20/.gitignore new file mode 100644 index 0000000..f915d8e --- /dev/null +++ b/bin/v0.1.20/.gitignore @@ -0,0 +1,4 @@ +#amboso compliant version folder, will ignore everything inside BUT the gitignore, to keep the clean dir +* +!.gitignore +!static diff --git a/bin/v0.1.20/static b/bin/v0.1.20/static new file mode 120000 index 0000000..382349a --- /dev/null +++ b/bin/v0.1.20/static @@ -0,0 +1 @@ +../../static/ \ No newline at end of file diff --git a/configure.ac b/configure.ac index 29fcbef..7c9139d 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ # Define the package name and version -AC_INIT([koliseo], [0.1.19], [jgabaut@github.com]) +AC_INIT([koliseo], [0.1.20], [jgabaut@github.com]) # Verify automake version and enable foreign option AM_INIT_AUTOMAKE([foreign -Wall]) @@ -24,7 +24,7 @@ fi # Set a default version number if not specified externally AC_ARG_VAR([VERSION], [Version number]) if test -z "$VERSION"; then - VERSION="0.1.19" + VERSION="0.1.20" fi # Output variables to the config.h header diff --git a/docs/koliseo.doxyfile b/docs/koliseo.doxyfile index 9a62d3d..02523e4 100644 --- a/docs/koliseo.doxyfile +++ b/docs/koliseo.doxyfile @@ -48,7 +48,7 @@ PROJECT_NAME = "koliseo" # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = "0.1.19" +PROJECT_NUMBER = "0.1.20" # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a diff --git a/src/koliseo.h b/src/koliseo.h index 3611407..4e39f2a 100644 --- a/src/koliseo.h +++ b/src/koliseo.h @@ -11,7 +11,7 @@ #define KLS_MAJOR 0 /**< Represents current major release.*/ #define KLS_MINOR 1 /**< Represents current minor release.*/ -#define KLS_PATCH 19 /**< Represents current patch release.*/ +#define KLS_PATCH 20 /**< Represents current patch release.*/ /** * Global variable for debug flag. @@ -28,7 +28,7 @@ extern int KOLISEO_AUTOSET_REGIONS; extern FILE* KOLISEO_DEBUG_FP; static const int KOLISEO_API_VERSION_INT = (KLS_MAJOR*1000000+KLS_MINOR*10000+KLS_PATCH*100); /**< Represents current version with numeric format.*/ -static const char KOLISEO_API_VERSION_STRING[] = "0.1.19"; /**< Represents current version with MAJOR.MINOR.PATCH format.*/ +static const char KOLISEO_API_VERSION_STRING[] = "0.1.20"; /**< Represents current version with MAJOR.MINOR.PATCH format.*/ const char* string_koliseo_version(void); diff --git a/static/amboso.h b/static/amboso.h index 57d0f9a..76badda 100644 --- a/static/amboso.h +++ b/static/amboso.h @@ -1,5 +1,5 @@ #ifndef AMBOSO_H #define AMBOSO_H -#define AMBOSO_CV "1.6.3" +#define AMBOSO_CV "1.6.4" char* getAmbosoVersion(void); #endif From c25e3a0755c2ee825dec3828c566f2b6ce28c826 Mon Sep 17 00:00:00 2001 From: jgabaut <109908086+jgabaut@users.noreply.github.com> Date: Thu, 7 Sep 2023 15:25:59 +0200 Subject: [PATCH 2/3] feat: add kls->has_temp Add kls_push_zero() with no autoregion check, to force Temp API pushes not to create Regions. kls_temp_start(): assert kls->has_temp == 0. All KLS_PUSH_T macros now resolve to kls_push_zero(), discarding the Region tagging arguments. --- src/koliseo.c | 42 ++++++++++++++++++++++++++++++++++++++++++ src/koliseo.h | 10 ++++++---- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/koliseo.c b/src/koliseo.c index be76916..c1a3237 100644 --- a/src/koliseo.c +++ b/src/koliseo.c @@ -133,6 +133,7 @@ Koliseo* kls_new(ptrdiff_t size) { kls->size = size; kls->offset = sizeof(*kls); kls->prev_offset = kls->offset; + kls->has_temp = 0; if (KOLISEO_AUTOSET_REGIONS == 1) { kls_log("KLS","Init of Region_List for kls."); Region* kls_header = (Region*) malloc(sizeof(Region)); @@ -228,6 +229,44 @@ void* kls_push(Koliseo* kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count) { * @return A void pointer to the start of memory just pushed to the Koliseo. */ void* kls_push_zero(Koliseo* kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count) { + ptrdiff_t available = kls->size - kls->offset; + ptrdiff_t padding = -kls->offset & (align -1); + if (count > PTRDIFF_MAX/size || (available - padding) < (size*count)) { + if (count > PTRDIFF_MAX/size) { + fprintf(stderr, "[KSL] count [%li] was bigger than PTRDIFF_MAX/size [%li].\n", count, PTRDIFF_MAX/size); + } else { + fprintf(stderr, "[KLS] Out of memory. size*count [%li] was bigger than available-padding [%li].\n", size*count, available-padding); + } + fprintf(stderr,"[KLS] Failed kls_push_zero() call.\n"); + abort(); + //return 0; + } + char* p = kls->data + kls->offset + padding; + //Zero new area + memset(p, 0, size*count); + kls->prev_offset = kls->offset; + kls->offset += padding + size*count; + char h_size[200]; + kls_formatSize(size,h_size,sizeof(h_size)); + //sprintf(msg,"Pushed zeroes, size (%li) for KLS.",size); + //kls_log("KLS",msg); + kls_log("KLS","API Level { %i } -> Pushed zeroes, size (%s) for KLS.",h_size); + if (KOLISEO_DEBUG == 1) { + print_kls_2file(KOLISEO_DEBUG_FP,kls); + } + return p; +} + +/** + * Takes a Koliseo pointer, and ptrdiff_t values for size, align and count. Tries pushing the specified amount of memory to the Koliseo data field, or goes to abort() if the operation fails. + * Notably, it zeroes the memory region. + * @param kls The Koliseo at hand. + * @param size The size for data to push. + * @param align The alignment for data to push. + * @param count The multiplicative quantity to scale data size to push for. + * @return A void pointer to the start of memory just pushed to the Koliseo. + */ +void* kls_push_zero_AR(Koliseo* kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count) { ptrdiff_t available = kls->size - kls->offset; ptrdiff_t padding = -kls->offset & (align -1); if (count > PTRDIFF_MAX/size || (available - padding) < (size*count)) { @@ -589,10 +628,12 @@ void kls_free(Koliseo* kls) { * @see Koliseo_Temp */ Koliseo_Temp kls_temp_start(Koliseo* kls) { + assert(kls->has_temp == 0); //TODO handle this more gracefully Koliseo_Temp tmp; tmp.kls = kls; tmp.prev_offset = kls->prev_offset; tmp.offset = kls->offset; + kls->has_temp = 1; kls_log("KLS","Prepared new Temp KLS."); return tmp; } @@ -606,6 +647,7 @@ void kls_temp_end(Koliseo_Temp tmp_kls) { tmp_kls.kls->prev_offset = tmp_kls.prev_offset; tmp_kls.kls->offset = tmp_kls.offset; kls_log("KLS","Ended Temp KLS."); + tmp_kls.kls->has_temp = 0; } diff --git a/src/koliseo.h b/src/koliseo.h index 4e39f2a..4bd9664 100644 --- a/src/koliseo.h +++ b/src/koliseo.h @@ -108,6 +108,7 @@ typedef struct Koliseo { ptrdiff_t offset; /**< Current position of memory pointer.*/ ptrdiff_t prev_offset; /**< Previous position of memory pointer.*/ Region_List regs; /**< List of allocated Regions*/ + int has_temp; /**< When == 1, a Koliseo_Temp is currently active on this Koliseo.*/ } Koliseo; /** @@ -129,11 +130,12 @@ Koliseo* kls_new(ptrdiff_t size); //void* kls_push(Koliseo* kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count); void* kls_push_zero(Koliseo* kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count); +void* kls_push_zero_AR(Koliseo* kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count); void* kls_push_zero_named(Koliseo* kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count, char* name, char* desc); void* kls_push_zero_typed(Koliseo* kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count, int type, char* name, char* desc); void* kls_pop(Koliseo* kls, ptrdiff_t size, ptrdiff_t align, ptrdiff_t count); -#define KLS_PUSH(kls, type, count) (type*)kls_push_zero(kls, sizeof(type), _Alignof(type), count) +#define KLS_PUSH(kls, type, count) (type*)kls_push_zero_AR(kls, sizeof(type), _Alignof(type), count) #define KLS_PUSH_NAMED(kls, type, count, name, desc) (type*)kls_push_zero_named(kls, sizeof(type), _Alignof(type), count, name, desc) #define KLS_PUSH_TYPED(kls, type, count, region_type, name, desc) (type*)kls_push_zero_typed(kls, sizeof(type), _Alignof(type), count, region_type, name, desc) #define KLS_POP(kls, type, count) (type*)kls_pop(kls, sizeof(type), _Alignof(type), count) @@ -159,9 +161,9 @@ void kls_showList_toWin(Koliseo* kls, WINDOW* win); Koliseo_Temp kls_temp_start(Koliseo* kls); void kls_temp_end(Koliseo_Temp tmp_kls); -#define KLS_PUSH_T(kls_temp, type, count) (type*)KLS_PUSH(kls_temp.kls, type, count) -#define KLS_PUSH_T_NAMED(kls_temp, type, count, name, desc) (type*)KLS_PUSH_NAMED(kls_temp.kls, type, count, name, desc) -#define KLS_PUSH_T_TYPED(kls_temp, type, count, region_type, name, desc) (type*)KLS_PUSH_TYPED(kls_temp.kls, type, count, region_type, name, desc) +#define KLS_PUSH_T(kls_temp, type, count) (type*)kls_push_zero(kls_temp.kls, sizeof(type), _Alignof(type), count) +#define KLS_PUSH_T_NAMED(kls_temp, type, count, name, desc) (type*)kls_push_zero(kls_temp.kls, sizeof(type), _Alignof(type), count) +#define KLS_PUSH_T_TYPED(kls_temp, type, count, region_type, name, desc) (type*)kls_push_zero(kls_temp.kls, sizeof(type), _Alignof(type), count) #define KLS_POP_T(kls_temp, type, count) (type*)KLS_POP(kls_temp.kls, type, count) Region_List kls_emptyList(void); From 9273dddc67186e723f340a10017044a06e027fc0 Mon Sep 17 00:00:00 2001 From: jgabaut <109908086+jgabaut@users.noreply.github.com> Date: Thu, 7 Sep 2023 15:30:01 +0200 Subject: [PATCH 3/3] chore: update stego.lock --- bin/stego.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/stego.lock b/bin/stego.lock index 286704f..b34b254 100644 --- a/bin/stego.lock +++ b/bin/stego.lock @@ -23,4 +23,4 @@ tests# tests folder name 0.1.17# add kls_type_usage() 0.1.18# kls_push_zero_typed() expects int 0.1.19# add kls_print_title() -0.1.20# prune RegionList on kls_temp_end +0.1.20# add kls->has_temp, KLS_PUSH_T doesn't account for AUTOREGION