From 0e3cf0c12cedbf22018c0a24f1da3d683dbf15da Mon Sep 17 00:00:00 2001 From: mwinkel-dev <122583770+mwinkel-dev@users.noreply.github.com> Date: Wed, 12 Mar 2025 10:52:33 -0600 Subject: [PATCH 1/2] LibCallg: similar edits to LibCallgFfi --- mdsshr/librtl.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/mdsshr/librtl.c b/mdsshr/librtl.c index a561462886..c0c24a0b3d 100644 --- a/mdsshr/librtl.c +++ b/mdsshr/librtl.c @@ -168,9 +168,17 @@ EXPORT char *Now32(char *const buf) /// EXPORT void *LibCallg(void **const a, void *(*const routine)()) { - if (!routine) - abort(); // intercept definite stack corruption - switch (*(int *)a & 0xff) + assert(routine); // in DEBUG mode checks for stack corruption + + // The "a" parameter is the arglist for the "routine" and contains the following: + // arglist[0] = N (total number of args excluding first and last elements of vector) + // arglist[1] = expression + // arglist[2 .. N-1] = variable args (pointer to descriptors) + // arglist[N] = result xd1 descriptor + // arglist[N+1] = NULL + int num_args = *(int *)a & 0xff; + + switch (num_args) { case 0: return routine(); @@ -281,8 +289,7 @@ EXPORT void *LibCallg(void **const a, void *(*const routine)()) a[19], a[20], a[21], a[22], a[23], a[24], a[25], a[26], a[27], a[28], a[29], a[30], a[31], a[32]); default: - printf("Error - currently no more than 32 arguments supported on external " - "calls\n"); + printf("Error - currently no more than %d arguments supported on external calls\n", LIBCALLG_MAX_ARGS); } return 0; } From 39ea47200e8b408d6d2f54c184bd35ac4fbc0337 Mon Sep 17 00:00:00 2001 From: mwinkel-dev <122583770+mwinkel-dev@users.noreply.github.com> Date: Thu, 27 Mar 2025 16:12:42 -0600 Subject: [PATCH 2/2] Fix: assert() replaced with abort() in LibCallg* routines --- mdsshr/librtl.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mdsshr/librtl.c b/mdsshr/librtl.c index c0c24a0b3d..0293974ca8 100644 --- a/mdsshr/librtl.c +++ b/mdsshr/librtl.c @@ -168,7 +168,9 @@ EXPORT char *Now32(char *const buf) /// EXPORT void *LibCallg(void **const a, void *(*const routine)()) { - assert(routine); // in DEBUG mode checks for stack corruption + if (!routine) { + abort(); // intercept definite stack corruption + } // The "a" parameter is the arglist for the "routine" and contains the following: // arglist[0] = N (total number of args excluding first and last elements of vector) @@ -302,7 +304,9 @@ EXPORT void *LibCallg(void **const a, void *(*const routine)()) // If the external function does not fit that constraint, users will have to write a shim function. EXPORT void *LibCallgFfi(void **const a, void *(*const routine)(), int num_fixed_args, int rtype) { - assert(routine); // in DEBUG mode checks for stack corruption + if (!routine) { + abort(); // intercept definite stack corruption + } // The "a" parameter is the arglist for the "routine" and contains the following: // arglist[0] = N (total number of args excluding first and last elements of vector)