Skip to content

Commit

Permalink
fix(xsnap): bounds checking in release builds
Browse files Browse the repository at this point in the history
 - chore: update moddable sdk to get stack overflow updates
 - feat: mxBoundsCheck (makefiles)

based on Feb 12 xsnap update
Moddable-OpenSource/agoric@8b127bc
  • Loading branch information
dckc committed Feb 23, 2021
1 parent df02134 commit c36f040
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 24 deletions.
4 changes: 2 additions & 2 deletions packages/xsnap/makefiles/lin/xsnap.mk
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ C_OPTIONS += \
-Wno-misleading-indentation \
-Wno-implicit-fallthrough
ifeq ($(GOAL),debug)
C_OPTIONS += -g -O0 -Wall -Wextra -Wno-missing-field-initializers -Wno-unused-parameter -DmxDebug=1
C_OPTIONS += -DmxDebug=1 -g -O0 -Wall -Wextra -Wno-missing-field-initializers -Wno-unused-parameter
else
C_OPTIONS += -O3
C_OPTIONS += -DmxBoundsCheck=1 -O3
endif

LIBRARIES = -ldl -lm -lpthread
Expand Down
4 changes: 2 additions & 2 deletions packages/xsnap/makefiles/mac/xsnap.mk
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ ifneq ("x$(SDKROOT)", "x")
C_OPTIONS += -isysroot $(SDKROOT)
endif
ifeq ($(GOAL),debug)
C_OPTIONS += -g -O0 -Wall -Wextra -Wno-missing-field-initializers -Wno-unused-parameter -DmxDebug=1
C_OPTIONS += -DmxDebug=1 -g -O0 -Wall -Wextra -Wno-missing-field-initializers -Wno-unused-parameter
else
C_OPTIONS += -O3
C_OPTIONS += -DmxBoundsCheck=1 -O3
endif

LIBRARIES = -framework CoreServices
Expand Down
1 change: 1 addition & 0 deletions packages/xsnap/makefiles/win/xsnap.mak
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ C_OPTIONS = $(C_OPTIONS) \
!ELSE
C_OPTIONS = $(C_OPTIONS) \
/D NDEBUG \
/D mxBoundsCheck=1 \
/Fp$(TMP_DIR_RLS)\ \
/O2 \
/W0
Expand Down
2 changes: 1 addition & 1 deletion packages/xsnap/moddable
Submodule moddable updated 160 files
59 changes: 40 additions & 19 deletions packages/xsnap/src/xsnap.c
Original file line number Diff line number Diff line change
Expand Up @@ -969,39 +969,61 @@ void fx_setTimer(txMachine* the, txNumber interval, txBoolean repeat)

void fx_setTimerCallback(txJob* job)
{
txMachine* the = job->the;
fxBeginHost(the);
xsMachine* the = job->the;
xsBeginHost(the);
{
mxTry(the) {
/* THIS */
mxPushUndefined();
/* FUNCTION */
mxPush(job->function);
mxCall();
mxPush(job->argument);
/* ARGC */
mxRunCount(1);
mxPop();
xsCallFunction1(job->function, xsUndefined, job->argument);
}
mxCatch(the) {
fprintf(stderr, "exception in setTimerCallback: %s\n", xsToString(xsException));
}
}
fxEndHost(the);
xsEndHost(the);
}

/* PLATFORM */

void fxAbort(txMachine* the, int status)
{
if (status == XS_NOT_ENOUGH_MEMORY_EXIT)
mxUnknownError("not enough memory");
else if (status == XS_STACK_OVERFLOW_EXIT)
mxUnknownError("stack overflow");
else if (status == XS_TOO_MUCH_COMPUTATION_EXIT)
switch (status) {
case XS_STACK_OVERFLOW_EXIT:
xsLog("stack overflow\n");
#ifdef mxDebug
fxDebugger(the, (char *)__FILE__, __LINE__);
#endif
fxExitToHost(the);
break;
case XS_NOT_ENOUGH_MEMORY_EXIT:
xsLog("memory full\n");
#ifdef mxDebug
fxDebugger(the, (char *)__FILE__, __LINE__);
#endif
fxExitToHost(the);
else
break;
case XS_NO_MORE_KEYS_EXIT:
xsLog("not enough keys\n");
#ifdef mxDebug
fxDebugger(the, (char *)__FILE__, __LINE__);
#endif
fxExitToHost(the);
break;
case XS_TOO_MUCH_COMPUTATION_EXIT:
xsLog("too much computation\n");
#ifdef mxDebug
fxDebugger(the, (char *)__FILE__, __LINE__);
#endif
fxExitToHost(the);
break;
case XS_UNHANDLED_EXCEPTION_EXIT:
case XS_UNHANDLED_REJECTION_EXIT:
xsLog("%s\n", xsToString(xsException));
xsException = xsUndefined;
break;
default:
c_exit(status);
break;
}
}

void fxCreateMachinePlatform(txMachine* the)
Expand Down Expand Up @@ -1062,7 +1084,6 @@ void fxRunLoop(txMachine* the)
else {
*address = job->next;
c_free(job);

}
}
}
Expand Down

0 comments on commit c36f040

Please sign in to comment.