From b9527f04a9dda7efb7eea9136c5a38edd7843c6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Mon, 5 Apr 2021 11:15:47 +0000 Subject: [PATCH 01/67] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1f88b33..ec09feb 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,7 @@ Later projects, like *gevent/greenlet* have taken that idea and provided additio with a different implementation, making the switching code itself incompatible. Our work on additional stack-manipulating libraries prompted us to try to distill this functionality in its -rawest form into a separate, low-level, library. Such that any project, withing to implement *co-routine*-like +rawest form into a separate, low-level, library. Such that any project, wishing to implement *co-routine*-like behaviour on the C-stack level, could make use of simple, stable code, that can be easily extended for additional platforms as they come along. From 49e8dbc5d27b504db70faa8dd0923ae525f948ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Mon, 5 Apr 2021 12:08:24 +0000 Subject: [PATCH 02/67] use lf line endings for source files --- .gitattributes | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..3340c6f --- /dev/null +++ b/.gitattributes @@ -0,0 +1,6 @@ +# use unix lf line ending for everything except windows bat files +* text=auto eol=lf +*.asm text eol=lf +*.h text eol=lf +*.{cmd,[cC][mM][dD]} text eol=crlf +*.{bat,[bB][aA][tT]} text eol=crlf From 958731e86f596d659dd5f82f5dab47fea539b6a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Mon, 5 Apr 2021 12:38:46 +0000 Subject: [PATCH 03/67] renormalize line endings --- src/platforms/switch_x64_msvc.asm | 268 +++++++++++++++--------------- src/platforms/switch_x64_msvc.h | 16 +- src/platforms/switch_x86_msvc.asm | 124 +++++++------- src/platforms/switch_x86_msvc.h | 76 ++++----- 4 files changed, 242 insertions(+), 242 deletions(-) diff --git a/src/platforms/switch_x64_msvc.asm b/src/platforms/switch_x64_msvc.asm index f4bd70f..f2351af 100644 --- a/src/platforms/switch_x64_msvc.asm +++ b/src/platforms/switch_x64_msvc.asm @@ -1,135 +1,135 @@ -; -; stack switching code for MASM on x64 -; Kristjan Valur Jonsson, apr 2011 -; Modified for stackman, dec 2019 -; Added stackman_call, dec 2020 -; - -include macamd64.inc - -pop_reg MACRO reg - pop reg -ENDM - -load_xmm128 macro Reg, Offset - movdqa Reg, Offset[rsp] -endm - -.code - -;arguments callback, context, are passed in rcx, rdx, respectively -;stackman_switch PROC FRAME -NESTED_ENTRY stackman_switch, _TEXT$00 - ; save all registers that the x64 ABI specifies as non-volatile. - ; This includes some mmx registers. May not always be necessary, - ; unless our application is doing 3D, but better safe than sorry. - alloc_stack 168; 10 * 16 bytes, plus 8 bytes to make stack 16 byte aligned - save_xmm128 xmm15, 144 - save_xmm128 xmm14, 128 - save_xmm128 xmm13, 112 - save_xmm128 xmm12, 96 - save_xmm128 xmm11, 80 - save_xmm128 xmm10, 64 - save_xmm128 xmm9, 48 - save_xmm128 xmm8, 32 - save_xmm128 xmm7, 16 - save_xmm128 xmm6, 0 - - push_reg r15 - push_reg r14 - push_reg r13 - push_reg r12 - - push_reg rbp - push_reg rbx - push_reg rdi - push_reg rsi - - sub rsp, 20h ;allocate shadow stack space for callee arguments - .allocstack 20h -.endprolog - - ;save argments in nonvolatile registers - mov r12, rcx ;callback - mov r13, rdx ;context - - ; load stack base that we are saving minus the callee argument - ; shadow stack. We don't want that clobbered - mov rcx, r13 ;arg1, context - mov rdx, 0 ;arg2, opcode STACKMAN_OP_SAVE - lea r8, [rsp+20h] ;arg3, stack pointer - mov rbx, rsp; ; keep old stack pointer - call r12 ; - - ;actual stack switch (and re-allocating the shadow stack): - lea rsp, [rax-20h] - ;re-adjust base pointer - sub rbx, rsp; - sub rbp, rbx; - - mov rcx, r13 ;arg1, context - mov rdx, 1 ;arg2, opcode STACKMAN_OP_RESTORE - mov r8, rax ;arg3, new stack pointer - call r12 - ;return the rax - - add rsp, 20h - pop_reg rsi - pop_reg rdi - pop_reg rbx - pop_reg rbp - - pop_reg r12 - pop_reg r13 - pop_reg r14 - pop_reg r15 - - load_xmm128 xmm15, 144 - load_xmm128 xmm14, 128 - load_xmm128 xmm13, 112 - load_xmm128 xmm12, 96 - load_xmm128 xmm11, 80 - load_xmm128 xmm10, 64 - load_xmm128 xmm9, 48 - load_xmm128 xmm8, 32 - load_xmm128 xmm7, 16 - load_xmm128 xmm6, 0 - add rsp, 168 - ret - -NESTED_END stackman_switch, _TEXT$00 -;stackman_switch ENDP - -; based on template from https://docs.microsoft.com/en-us/cpp/build/exception-handling-x64?view=msvc-160 -stackman_call PROC FRAME - push rbp - .pushreg rbp - ; now our stack is 16 byte aligned. don't need additional spacle - ;sub rsp, 040h - ;.allocstack 040h - lea rbp, [rsp+00h] - .setframe rbp, 00h - .endprolog - - ; suffle arguments into volatile registers - mov rax, rcx ; callback - mov rcx, rdx ; context into first arg - mov r9, r8 ; and stack pointer in volatile registers - - ; set up call - mov r8, rsp - mov edx, 2 - ; rcx already set up with context - - ; modify stack pointer before call - mov rsp, r9 - sub rsp, 32 ;pre-allocate parameter stack for the callee - call rax - - ; officialepilog - lea rsp, [rbp+0h] - pop rbp - ret 0 -stackman_call ENDP - +; +; stack switching code for MASM on x64 +; Kristjan Valur Jonsson, apr 2011 +; Modified for stackman, dec 2019 +; Added stackman_call, dec 2020 +; + +include macamd64.inc + +pop_reg MACRO reg + pop reg +ENDM + +load_xmm128 macro Reg, Offset + movdqa Reg, Offset[rsp] +endm + +.code + +;arguments callback, context, are passed in rcx, rdx, respectively +;stackman_switch PROC FRAME +NESTED_ENTRY stackman_switch, _TEXT$00 + ; save all registers that the x64 ABI specifies as non-volatile. + ; This includes some mmx registers. May not always be necessary, + ; unless our application is doing 3D, but better safe than sorry. + alloc_stack 168; 10 * 16 bytes, plus 8 bytes to make stack 16 byte aligned + save_xmm128 xmm15, 144 + save_xmm128 xmm14, 128 + save_xmm128 xmm13, 112 + save_xmm128 xmm12, 96 + save_xmm128 xmm11, 80 + save_xmm128 xmm10, 64 + save_xmm128 xmm9, 48 + save_xmm128 xmm8, 32 + save_xmm128 xmm7, 16 + save_xmm128 xmm6, 0 + + push_reg r15 + push_reg r14 + push_reg r13 + push_reg r12 + + push_reg rbp + push_reg rbx + push_reg rdi + push_reg rsi + + sub rsp, 20h ;allocate shadow stack space for callee arguments + .allocstack 20h +.endprolog + + ;save argments in nonvolatile registers + mov r12, rcx ;callback + mov r13, rdx ;context + + ; load stack base that we are saving minus the callee argument + ; shadow stack. We don't want that clobbered + mov rcx, r13 ;arg1, context + mov rdx, 0 ;arg2, opcode STACKMAN_OP_SAVE + lea r8, [rsp+20h] ;arg3, stack pointer + mov rbx, rsp; ; keep old stack pointer + call r12 ; + + ;actual stack switch (and re-allocating the shadow stack): + lea rsp, [rax-20h] + ;re-adjust base pointer + sub rbx, rsp; + sub rbp, rbx; + + mov rcx, r13 ;arg1, context + mov rdx, 1 ;arg2, opcode STACKMAN_OP_RESTORE + mov r8, rax ;arg3, new stack pointer + call r12 + ;return the rax + + add rsp, 20h + pop_reg rsi + pop_reg rdi + pop_reg rbx + pop_reg rbp + + pop_reg r12 + pop_reg r13 + pop_reg r14 + pop_reg r15 + + load_xmm128 xmm15, 144 + load_xmm128 xmm14, 128 + load_xmm128 xmm13, 112 + load_xmm128 xmm12, 96 + load_xmm128 xmm11, 80 + load_xmm128 xmm10, 64 + load_xmm128 xmm9, 48 + load_xmm128 xmm8, 32 + load_xmm128 xmm7, 16 + load_xmm128 xmm6, 0 + add rsp, 168 + ret + +NESTED_END stackman_switch, _TEXT$00 +;stackman_switch ENDP + +; based on template from https://docs.microsoft.com/en-us/cpp/build/exception-handling-x64?view=msvc-160 +stackman_call PROC FRAME + push rbp + .pushreg rbp + ; now our stack is 16 byte aligned. don't need additional spacle + ;sub rsp, 040h + ;.allocstack 040h + lea rbp, [rsp+00h] + .setframe rbp, 00h + .endprolog + + ; suffle arguments into volatile registers + mov rax, rcx ; callback + mov rcx, rdx ; context into first arg + mov r9, r8 ; and stack pointer in volatile registers + + ; set up call + mov r8, rsp + mov edx, 2 + ; rcx already set up with context + + ; modify stack pointer before call + mov rsp, r9 + sub rsp, 32 ;pre-allocate parameter stack for the callee + call rax + + ; officialepilog + lea rsp, [rbp+0h] + pop rbp + ret 0 +stackman_call ENDP + END \ No newline at end of file diff --git a/src/platforms/switch_x64_msvc.h b/src/platforms/switch_x64_msvc.h index 0b4d1c5..d1dc6ac 100644 --- a/src/platforms/switch_x64_msvc.h +++ b/src/platforms/switch_x64_msvc.h @@ -1,8 +1,8 @@ -/* The actual stack saving function, which just stores the stack, - * this declared in an .asm file - */ -#ifndef STACKMAN_ASSEMBLY_SRC -#define STACKMAN_ASSEMBLY_SRC switch_x64_msvc.asm -#define STACKMAN_HAVE_CALL 1 -#define STACKMAN_STACK_ALIGN 16 -#endif +/* The actual stack saving function, which just stores the stack, + * this declared in an .asm file + */ +#ifndef STACKMAN_ASSEMBLY_SRC +#define STACKMAN_ASSEMBLY_SRC switch_x64_msvc.asm +#define STACKMAN_HAVE_CALL 1 +#define STACKMAN_STACK_ALIGN 16 +#endif diff --git a/src/platforms/switch_x86_msvc.asm b/src/platforms/switch_x86_msvc.asm index ce5a42b..1884987 100644 --- a/src/platforms/switch_x86_msvc.asm +++ b/src/platforms/switch_x86_msvc.asm @@ -1,62 +1,62 @@ - -.386 -.model flat, c - -.code - -stackman_switch_raw PROC callback:DWORD, context:DWORD - ;Assembler has already pushed the basepointer and saved it. - ;save registers. EAX ECX and EDX are available for function use and thus - ;do not have to be stored. - push ebx - push esi - push edi - - mov esi, callback ; /* save 'callback' for later */ - mov edi, context ; /* save 'context' for later */ - - mov eax, esp - - push eax ; /* arg 3: current (old) stack pointer */ - push 0; /* arg 2: opcode STACKMAN_OP_SAVE */ - push edi ; /* arg 1: context */ - call esi ; /* call callback() */ - add esp, 12; - - mov ecx, eax; /* change stack pointer to eax, preserving */ - sub ecx, esp; /* base pointer offset from esp */ - mov esp, eax; - add ebp, ecx; - - - push eax ; /* arg 3: current (new) stack pointer */ - push 1; /* arg 2: opcode STACKMAN_OP_RESTORE */ - push edi ; /* arg 1: context */ - call esi ; /* call callback() */ - add esp, 12 - - pop edi - pop esi - pop ebx - ret -stackman_switch_raw ENDP - - -stackman_call PROC callback:DWORD, context:DWORD, stack_pointer:DWORD - ;enter prolog has pushed ebp and saved esp in ebp - - mov eax, callback - mov ecx, context - mov edx, stack_pointer - - ; switch stack pointer - mov esp, stack_pointer - push ebp ;old stack pointer - push 2 ;STACKMAN_OP_CALL - push ecx ;context - call eax ;callback - ret ; this assembles a LEAVE instruction which restores esp to ebp, then pops the ebp -stackman_call ENDP - - -end + +.386 +.model flat, c + +.code + +stackman_switch_raw PROC callback:DWORD, context:DWORD + ;Assembler has already pushed the basepointer and saved it. + ;save registers. EAX ECX and EDX are available for function use and thus + ;do not have to be stored. + push ebx + push esi + push edi + + mov esi, callback ; /* save 'callback' for later */ + mov edi, context ; /* save 'context' for later */ + + mov eax, esp + + push eax ; /* arg 3: current (old) stack pointer */ + push 0; /* arg 2: opcode STACKMAN_OP_SAVE */ + push edi ; /* arg 1: context */ + call esi ; /* call callback() */ + add esp, 12; + + mov ecx, eax; /* change stack pointer to eax, preserving */ + sub ecx, esp; /* base pointer offset from esp */ + mov esp, eax; + add ebp, ecx; + + + push eax ; /* arg 3: current (new) stack pointer */ + push 1; /* arg 2: opcode STACKMAN_OP_RESTORE */ + push edi ; /* arg 1: context */ + call esi ; /* call callback() */ + add esp, 12 + + pop edi + pop esi + pop ebx + ret +stackman_switch_raw ENDP + + +stackman_call PROC callback:DWORD, context:DWORD, stack_pointer:DWORD + ;enter prolog has pushed ebp and saved esp in ebp + + mov eax, callback + mov ecx, context + mov edx, stack_pointer + + ; switch stack pointer + mov esp, stack_pointer + push ebp ;old stack pointer + push 2 ;STACKMAN_OP_CALL + push ecx ;context + call eax ;callback + ret ; this assembles a LEAVE instruction which restores esp to ebp, then pops the ebp +stackman_call ENDP + + +end diff --git a/src/platforms/switch_x86_msvc.h b/src/platforms/switch_x86_msvc.h index ca176d0..e30824e 100644 --- a/src/platforms/switch_x86_msvc.h +++ b/src/platforms/switch_x86_msvc.h @@ -1,38 +1,38 @@ -/* The actual stack saving function, which just stores the stack, - * this declared in an .asm file - * The C function defined here, saves and restores the structured - * exception handling state. - */ -#if !defined(STACKMAN_ASSEMBLY_SRC) -#define STACKMAN_ASSEMBLY_SRC switch_x86_msvc.asm -#define STACKMAN_SWITCH_C 1 /* contains a C implementation */ -#define STACKMAN_HAVE_CALL 1 -#define STACKMAN_STACK_ALIGN 4 -#endif - - -#ifdef STACKMAN_SWITCH_IMPL -#include "../stackman_switch.h" - -extern void *stackman_switch_raw(stackman_cb_t callback, void *context); - -#define WIN32_LEAN_AND_MEAN -#include - -/* Store any other runtime information on the local stack */ -#pragma optimize("", off) /* so that autos are stored on the stack */ -#pragma warning(disable:4733) /* disable warning about modifying FS[0] */ - -STACKMAN_LINKAGE_SWITCH -void *stackman_switch(stackman_cb_t callback, void *context) -{ - /* store the structured exception state for this stack */ - DWORD seh_state = __readfsdword(FIELD_OFFSET(NT_TIB, ExceptionList)); - void * result = stackman_switch_raw(callback, context); - __writefsdword(FIELD_OFFSET(NT_TIB, ExceptionList), seh_state); - return result; -} -#pragma warning(default:4733) /* disable warning about modifying FS[0] */ -#pragma optimize("", on) - -#endif +/* The actual stack saving function, which just stores the stack, + * this declared in an .asm file + * The C function defined here, saves and restores the structured + * exception handling state. + */ +#if !defined(STACKMAN_ASSEMBLY_SRC) +#define STACKMAN_ASSEMBLY_SRC switch_x86_msvc.asm +#define STACKMAN_SWITCH_C 1 /* contains a C implementation */ +#define STACKMAN_HAVE_CALL 1 +#define STACKMAN_STACK_ALIGN 4 +#endif + + +#ifdef STACKMAN_SWITCH_IMPL +#include "../stackman_switch.h" + +extern void *stackman_switch_raw(stackman_cb_t callback, void *context); + +#define WIN32_LEAN_AND_MEAN +#include + +/* Store any other runtime information on the local stack */ +#pragma optimize("", off) /* so that autos are stored on the stack */ +#pragma warning(disable:4733) /* disable warning about modifying FS[0] */ + +STACKMAN_LINKAGE_SWITCH +void *stackman_switch(stackman_cb_t callback, void *context) +{ + /* store the structured exception state for this stack */ + DWORD seh_state = __readfsdword(FIELD_OFFSET(NT_TIB, ExceptionList)); + void * result = stackman_switch_raw(callback, context); + __writefsdword(FIELD_OFFSET(NT_TIB, ExceptionList), seh_state); + return result; +} +#pragma warning(default:4733) /* disable warning about modifying FS[0] */ +#pragma optimize("", on) + +#endif From ccda28ef4fe66fc60f5bdc59a925b67f0a95e801 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Tue, 6 Apr 2021 16:38:19 +0000 Subject: [PATCH 04/67] Rename 'src' folder to 'stackman' This allows client libraries to avoid include ambiguities by adding an include path for the root, and then include the libraries using #include --- Makefile | 6 ++--- abiname.sh | 4 +-- {src => stackman}/abiname.c | 0 {src => stackman}/extras/slp_switch.h | 0 {src => stackman}/platforms/gen_asm.c | 0 {src => stackman}/platforms/platform.h | 0 .../platforms/switch_aarch64_gcc.S | 0 .../platforms/switch_aarch64_gcc.h | 0 .../platforms/switch_arm64_msvc.asm | 0 .../platforms/switch_arm64_msvc.h | 0 {src => stackman}/platforms/switch_arm_gcc.S | 0 {src => stackman}/platforms/switch_arm_gcc.h | 0 .../platforms/switch_arm_msvc.asm | 0 {src => stackman}/platforms/switch_arm_msvc.h | 0 {src => stackman}/platforms/switch_template.h | 0 .../platforms/switch_x64_msvc.asm | 0 {src => stackman}/platforms/switch_x64_msvc.h | 0 .../platforms/switch_x86_64_gcc.S | 0 .../platforms/switch_x86_64_gcc.h | 0 {src => stackman}/platforms/switch_x86_gcc.S | 0 {src => stackman}/platforms/switch_x86_gcc.h | 0 .../platforms/switch_x86_msvc.asm | 0 {src => stackman}/platforms/switch_x86_msvc.h | 0 {src => stackman}/stackman.c | 0 {src => stackman}/stackman.h | 0 {src => stackman}/stackman_impl.h | 0 {src => stackman}/stackman_s.S | 0 {src => stackman}/stackman_s.asm | 0 {src => stackman}/stackman_switch.h | 0 vs2017/stackman/stackman.vcxproj | 26 +++++++++---------- vs2017/stackman/stackman.vcxproj.filters | 26 +++++++++---------- vs2017/stackman/template.c | 2 +- vs2019/stackman/stackman.vcxproj | 26 +++++++++---------- vs2019/stackman/stackman.vcxproj.filters | 26 +++++++++---------- vs2019/stackman/template.c | 2 +- 35 files changed, 59 insertions(+), 59 deletions(-) rename {src => stackman}/abiname.c (100%) rename {src => stackman}/extras/slp_switch.h (100%) rename {src => stackman}/platforms/gen_asm.c (100%) rename {src => stackman}/platforms/platform.h (100%) rename {src => stackman}/platforms/switch_aarch64_gcc.S (100%) rename {src => stackman}/platforms/switch_aarch64_gcc.h (100%) rename {src => stackman}/platforms/switch_arm64_msvc.asm (100%) rename {src => stackman}/platforms/switch_arm64_msvc.h (100%) rename {src => stackman}/platforms/switch_arm_gcc.S (100%) rename {src => stackman}/platforms/switch_arm_gcc.h (100%) rename {src => stackman}/platforms/switch_arm_msvc.asm (100%) rename {src => stackman}/platforms/switch_arm_msvc.h (100%) rename {src => stackman}/platforms/switch_template.h (100%) rename {src => stackman}/platforms/switch_x64_msvc.asm (100%) rename {src => stackman}/platforms/switch_x64_msvc.h (100%) rename {src => stackman}/platforms/switch_x86_64_gcc.S (100%) rename {src => stackman}/platforms/switch_x86_64_gcc.h (100%) rename {src => stackman}/platforms/switch_x86_gcc.S (100%) rename {src => stackman}/platforms/switch_x86_gcc.h (100%) rename {src => stackman}/platforms/switch_x86_msvc.asm (100%) rename {src => stackman}/platforms/switch_x86_msvc.h (100%) rename {src => stackman}/stackman.c (100%) rename {src => stackman}/stackman.h (100%) rename {src => stackman}/stackman_impl.h (100%) rename {src => stackman}/stackman_s.S (100%) rename {src => stackman}/stackman_s.asm (100%) rename {src => stackman}/stackman_switch.h (100%) diff --git a/Makefile b/Makefile index 14e3240..d688059 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ -CPPFLAGS += -Isrc $(PLATFORMFLAGS) +CPPFLAGS += -Istackman $(PLATFORMFLAGS) CFLAGS += -fPIC -g $(PLATFORMFLAGS) CXXFLAGS += -fPIC -g $(PLATFORMFLAGS) LDFLAGS += -L$(LIB) -g $(PLATFORMFLAGS) @@ -29,7 +29,7 @@ LIB := lib/$(ABI) all: $(LIB)/libstackman.a -obj = src/stackman.o src/stackman_s.o +obj = stackman/stackman.o stackman/stackman_s.o $(LIB)/libstackman.a: lib $(obj) @@ -40,7 +40,7 @@ lib: mkdir -p $(LIB) bin clean: - rm -f src/*.o tests/*.o + rm -f stackman/*.o tests/*.o rm -f bin/* rm -rf tmp diff --git a/abiname.sh b/abiname.sh index 8894471..390d9ae 100755 --- a/abiname.sh +++ b/abiname.sh @@ -1,6 +1,6 @@ #!/bin/sh -# this script compiles and runs src/abiname.c which merely prints +# this script compiles and runs stackman/abiname.c which merely prints # out the name of the abi. This can be used by makefiles to identify # the correct library path to use to link the library # Instead of just compiling and running, we will use the provided compiler @@ -16,7 +16,7 @@ tmp=$(mktemp "${here}/tmp/abinameXXX.c") #1 create the preprocessed file CC=${1:-cc} CFLAGS=${2:-} -${CC} ${CFLAGS} -E -I "${here}/src" -o "${tmp}" "${here}/src/abiname.c" +${CC} ${CFLAGS} -E -o "${tmp}" "${here}/stackman/abiname.c" #2 compile resulting file cc -o "${tmp}.out" "${tmp}" #3 run it diff --git a/src/abiname.c b/stackman/abiname.c similarity index 100% rename from src/abiname.c rename to stackman/abiname.c diff --git a/src/extras/slp_switch.h b/stackman/extras/slp_switch.h similarity index 100% rename from src/extras/slp_switch.h rename to stackman/extras/slp_switch.h diff --git a/src/platforms/gen_asm.c b/stackman/platforms/gen_asm.c similarity index 100% rename from src/platforms/gen_asm.c rename to stackman/platforms/gen_asm.c diff --git a/src/platforms/platform.h b/stackman/platforms/platform.h similarity index 100% rename from src/platforms/platform.h rename to stackman/platforms/platform.h diff --git a/src/platforms/switch_aarch64_gcc.S b/stackman/platforms/switch_aarch64_gcc.S similarity index 100% rename from src/platforms/switch_aarch64_gcc.S rename to stackman/platforms/switch_aarch64_gcc.S diff --git a/src/platforms/switch_aarch64_gcc.h b/stackman/platforms/switch_aarch64_gcc.h similarity index 100% rename from src/platforms/switch_aarch64_gcc.h rename to stackman/platforms/switch_aarch64_gcc.h diff --git a/src/platforms/switch_arm64_msvc.asm b/stackman/platforms/switch_arm64_msvc.asm similarity index 100% rename from src/platforms/switch_arm64_msvc.asm rename to stackman/platforms/switch_arm64_msvc.asm diff --git a/src/platforms/switch_arm64_msvc.h b/stackman/platforms/switch_arm64_msvc.h similarity index 100% rename from src/platforms/switch_arm64_msvc.h rename to stackman/platforms/switch_arm64_msvc.h diff --git a/src/platforms/switch_arm_gcc.S b/stackman/platforms/switch_arm_gcc.S similarity index 100% rename from src/platforms/switch_arm_gcc.S rename to stackman/platforms/switch_arm_gcc.S diff --git a/src/platforms/switch_arm_gcc.h b/stackman/platforms/switch_arm_gcc.h similarity index 100% rename from src/platforms/switch_arm_gcc.h rename to stackman/platforms/switch_arm_gcc.h diff --git a/src/platforms/switch_arm_msvc.asm b/stackman/platforms/switch_arm_msvc.asm similarity index 100% rename from src/platforms/switch_arm_msvc.asm rename to stackman/platforms/switch_arm_msvc.asm diff --git a/src/platforms/switch_arm_msvc.h b/stackman/platforms/switch_arm_msvc.h similarity index 100% rename from src/platforms/switch_arm_msvc.h rename to stackman/platforms/switch_arm_msvc.h diff --git a/src/platforms/switch_template.h b/stackman/platforms/switch_template.h similarity index 100% rename from src/platforms/switch_template.h rename to stackman/platforms/switch_template.h diff --git a/src/platforms/switch_x64_msvc.asm b/stackman/platforms/switch_x64_msvc.asm similarity index 100% rename from src/platforms/switch_x64_msvc.asm rename to stackman/platforms/switch_x64_msvc.asm diff --git a/src/platforms/switch_x64_msvc.h b/stackman/platforms/switch_x64_msvc.h similarity index 100% rename from src/platforms/switch_x64_msvc.h rename to stackman/platforms/switch_x64_msvc.h diff --git a/src/platforms/switch_x86_64_gcc.S b/stackman/platforms/switch_x86_64_gcc.S similarity index 100% rename from src/platforms/switch_x86_64_gcc.S rename to stackman/platforms/switch_x86_64_gcc.S diff --git a/src/platforms/switch_x86_64_gcc.h b/stackman/platforms/switch_x86_64_gcc.h similarity index 100% rename from src/platforms/switch_x86_64_gcc.h rename to stackman/platforms/switch_x86_64_gcc.h diff --git a/src/platforms/switch_x86_gcc.S b/stackman/platforms/switch_x86_gcc.S similarity index 100% rename from src/platforms/switch_x86_gcc.S rename to stackman/platforms/switch_x86_gcc.S diff --git a/src/platforms/switch_x86_gcc.h b/stackman/platforms/switch_x86_gcc.h similarity index 100% rename from src/platforms/switch_x86_gcc.h rename to stackman/platforms/switch_x86_gcc.h diff --git a/src/platforms/switch_x86_msvc.asm b/stackman/platforms/switch_x86_msvc.asm similarity index 100% rename from src/platforms/switch_x86_msvc.asm rename to stackman/platforms/switch_x86_msvc.asm diff --git a/src/platforms/switch_x86_msvc.h b/stackman/platforms/switch_x86_msvc.h similarity index 100% rename from src/platforms/switch_x86_msvc.h rename to stackman/platforms/switch_x86_msvc.h diff --git a/src/stackman.c b/stackman/stackman.c similarity index 100% rename from src/stackman.c rename to stackman/stackman.c diff --git a/src/stackman.h b/stackman/stackman.h similarity index 100% rename from src/stackman.h rename to stackman/stackman.h diff --git a/src/stackman_impl.h b/stackman/stackman_impl.h similarity index 100% rename from src/stackman_impl.h rename to stackman/stackman_impl.h diff --git a/src/stackman_s.S b/stackman/stackman_s.S similarity index 100% rename from src/stackman_s.S rename to stackman/stackman_s.S diff --git a/src/stackman_s.asm b/stackman/stackman_s.asm similarity index 100% rename from src/stackman_s.asm rename to stackman/stackman_s.asm diff --git a/src/stackman_switch.h b/stackman/stackman_switch.h similarity index 100% rename from src/stackman_switch.h rename to stackman/stackman_switch.h diff --git a/vs2017/stackman/stackman.vcxproj b/vs2017/stackman/stackman.vcxproj index ef5a64e..b27234a 100644 --- a/vs2017/stackman/stackman.vcxproj +++ b/vs2017/stackman/stackman.vcxproj @@ -165,17 +165,17 @@ - - - - - - - - + + + + + + + + - + false Default @@ -199,24 +199,24 @@ - + false true true true - + Document true true true - + true true true - + true true true diff --git a/vs2017/stackman/stackman.vcxproj.filters b/vs2017/stackman/stackman.vcxproj.filters index 6db744f..9f57a1f 100644 --- a/vs2017/stackman/stackman.vcxproj.filters +++ b/vs2017/stackman/stackman.vcxproj.filters @@ -15,33 +15,33 @@ - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Source Files @@ -49,18 +49,18 @@ - + Source Files - + Source Files - + Source Files - + Source Files diff --git a/vs2017/stackman/template.c b/vs2017/stackman/template.c index ca9b63f..2fe7dbd 100644 --- a/vs2017/stackman/template.c +++ b/vs2017/stackman/template.c @@ -1,4 +1,4 @@ -#include "..\..\src\stackman.h" +#include "..\..\stackman\stackman.h" /* * template file to create assembly code (template.asm) to modify and add to real assembler. diff --git a/vs2019/stackman/stackman.vcxproj b/vs2019/stackman/stackman.vcxproj index 1d48cb8..5a6a77a 100644 --- a/vs2019/stackman/stackman.vcxproj +++ b/vs2019/stackman/stackman.vcxproj @@ -165,17 +165,17 @@ - - - - - - - - + + + + + + + + - + false Default @@ -199,24 +199,24 @@ - + false true true true - + Document true true true - + true true true - + true true true diff --git a/vs2019/stackman/stackman.vcxproj.filters b/vs2019/stackman/stackman.vcxproj.filters index 6db744f..9f57a1f 100644 --- a/vs2019/stackman/stackman.vcxproj.filters +++ b/vs2019/stackman/stackman.vcxproj.filters @@ -15,33 +15,33 @@ - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Source Files @@ -49,18 +49,18 @@ - + Source Files - + Source Files - + Source Files - + Source Files diff --git a/vs2019/stackman/template.c b/vs2019/stackman/template.c index ca9b63f..2fe7dbd 100644 --- a/vs2019/stackman/template.c +++ b/vs2019/stackman/template.c @@ -1,4 +1,4 @@ -#include "..\..\src\stackman.h" +#include "..\..\stackman\stackman.h" /* * template file to create assembly code (template.asm) to modify and add to real assembler. From 4a96e0f8197ad8cbd9e22ffaab59ce910d92a755 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Tue, 6 Apr 2021 22:41:44 +0000 Subject: [PATCH 05/67] Add workflow --- .github/workflows/test.yml | 74 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..2c64813 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,74 @@ +name: C/C++ CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + test-amd64: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: make + run: make && make test + + test-linux-x86: + runs-on: ubuntu-latest + strategy: + matrix: + platformflags: ["", "-m32"] + env: + PLATFORMFLAGS: ${{platformflags}} + steps: + - uses: actions/checkout@v2 + - name: install multilib + run: sudo apt-get install --no-install-recommends -y gcc-multilib g++-multilib + - name: make + run: make && make test + + test-linux-arm: + runs-on: ubuntu-latest + strategy: + matrix: + include: + - arch: arm + emulator: qemu-arm + abi: arm-linux-gnueabi + - arch: aarch64 + emulator: qemu-aarch64 + abi: aarch64-linux-gnu + env: + PLATFORM_PREFIX: ${{matrix.abi}}- + EMULATOR: ${{matrix.emulator}} + steps: + - uses: actions/checkout@v2 + - name: install qemu + run: sudo apt-get install --no-install-recommends -y qemu-user + - name: install abi lib + run: sudo apt-get install --no-install-recommends -y gcc-${{matrix.abi}} g++-${{matrix.abi}} + - name: make + run: make && make test + + test-windows: + runs-on: windows-2019 + strategy: + matrix: + platform: [x86, x64, ARM, ARM64] + include: + - platform: x86 + folder: Win32 + native: yes + - platform: x64 + folder: x64 + native: yes + steps: + - uses: actions/checkout@v2 + - name: Add msbuild to PATH + uses: microsoft/setup-msbuild@v1.0.2 + - name: build + run: msbuild.exe vs2019\stackman.sln /p:Platform=${{matrix.platform}} + - name: test + if: ${{ matrix.native == 'yes' }} + run: vs2019\${{matrix.folder}}\Debug\test.exe From 34e56103ee6bd65f073cb7d90cd3d2166f243f35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Tue, 6 Apr 2021 22:42:12 +0000 Subject: [PATCH 06/67] Fix documentation --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ec09feb..30c1706 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,7 @@ platforms as they come along. ## Cross-compilation Linux on x86-64 can be used to cross compile for x86 and ARM targets. This is most useful to generate assembly code, e.g. when compiling -src/platform/gen_asm.c +stackman/platform/gen_asm.c - x86 requires the -m32 flag to compilers and linkers. - arm32 requires to use the arm-linux-gnueabi-* tools, including cc and linker - aarch64 requires the aarch64-linux-gnu-* tools. @@ -138,4 +138,4 @@ platforms may need to be done independently. - install **gcc-aarch64-linux-gnu** and **g++-aarch64-linux-gnu** - install __qemu-user__ for hardware emulation - *compile* using `aarch64-linux-gnu-gcc` - - *make* using `make PLATFORM_PREFIX=aarch64-linux-gnu- EMULATOR=qemu-arm64 test` + - *make* using `make PLATFORM_PREFIX=aarch64-linux-gnu- EMULATOR=qemu-aarch64 test` From c917cd8f619b156b5b7d7d7f0b384c1649388a90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Tue, 6 Apr 2021 22:45:01 +0000 Subject: [PATCH 07/67] Remove travis, migrating to GH Actions. --- .travis.yml | 40 ---------------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 18997f7..0000000 --- a/.travis.yml +++ /dev/null @@ -1,40 +0,0 @@ -language: c -dist: bionic -script: make && make test -jobs: - include: - - name: x86_64_gcc - - name: x86_gcc - before_install: sudo apt install -y gcc-multilib g++-multilib - env: PLATFORMFLAGS=-m32 - - arch: arm64 - - name: arm32_xcompile - before_install: - - sudo apt update - - sudo apt install -y gcc-arm-linux-gnueabi g++-arm-linux-gnueabi - - sudo apt install -y qemu-user - env: - - PLATFORM_PREFIX=arm-linux-gnueabi- - - EMULATOR=qemu-arm - - os: windows - name: x64_msvc - script: - - cd vs2017 - - ./build.cmd x64 && x64/Debug/test.exe - - os: windows - name: x86_msvc - script: - - cd vs2017 - - ./build.cmd x86 && Win32/Debug/test.exe - - os: windows - name: arm_msvc - before_install: choco install --force VisualStudio2017-workload-vctools --params"--add Microsoft.VisualStudio.Component.VC.Tools.ARM" - script: - - cd vs2017 - - ./build.cmd ARM - - os: windows - name: arm64_msvc - before_install: choco install --force VisualStudio2017-workload-vctools --params"--add Microsoft.VisualStudio.Component.VC.Tools.ARM64" - script: - - cd vs2017 - - ./build.cmd ARM64 \ No newline at end of file From 4da83cd36c97c6a58a6866c16d10d17875fe9a2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Tue, 6 Apr 2021 22:58:23 +0000 Subject: [PATCH 08/67] Fix workflow --- .github/workflows/test.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2c64813..026130b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,20 +7,19 @@ on: branches: [ master ] jobs: - test-amd64: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: make - run: make && make test - + test-linux-x86: runs-on: ubuntu-latest strategy: matrix: - platformflags: ["", "-m32"] + include: + - platformflags: "" + name: "AMD64" + - platformflags: -m32 + name: "i386" + name: test-linux-x86 (${{matrix.name}}) env: - PLATFORMFLAGS: ${{platformflags}} + PLATFORMFLAGS: ${{matrix.platformflags}} steps: - uses: actions/checkout@v2 - name: install multilib @@ -39,6 +38,7 @@ jobs: - arch: aarch64 emulator: qemu-aarch64 abi: aarch64-linux-gnu + name: test-linux-arm (${{matrix.arch}}) env: PLATFORM_PREFIX: ${{matrix.abi}}- EMULATOR: ${{matrix.emulator}} From 518aff7b712d87cb49ced4433db2f8437be86a6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Tue, 6 Apr 2021 23:17:59 +0000 Subject: [PATCH 09/67] Fix include path on windows --- vs2017/test/test.vcxproj | 8 ++++---- vs2019/test/test.vcxproj | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/vs2017/test/test.vcxproj b/vs2017/test/test.vcxproj index 9a03733..9d14c4b 100644 --- a/vs2017/test/test.vcxproj +++ b/vs2017/test/test.vcxproj @@ -88,7 +88,7 @@ true WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true - ..\..\src + ..\..\stackman Console @@ -104,7 +104,7 @@ true _DEBUG;_CONSOLE;%(PreprocessorDefinitions) true - ..\..\src + ..\..\stackman Console @@ -119,7 +119,7 @@ true _DEBUG;_CONSOLE;%(PreprocessorDefinitions) true - ..\..\src + ..\..\stackman Console @@ -134,7 +134,7 @@ true _DEBUG;_CONSOLE;%(PreprocessorDefinitions) true - ..\..\src + ..\..\stackman Console diff --git a/vs2019/test/test.vcxproj b/vs2019/test/test.vcxproj index 2559e40..93dc2cf 100644 --- a/vs2019/test/test.vcxproj +++ b/vs2019/test/test.vcxproj @@ -88,7 +88,7 @@ true WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true - ..\..\src + ..\..\stackman Console @@ -104,7 +104,7 @@ true _DEBUG;_CONSOLE;%(PreprocessorDefinitions) true - ..\..\src + ..\..\stackman Console @@ -119,7 +119,7 @@ true _DEBUG;_CONSOLE;%(PreprocessorDefinitions) true - ..\..\src + ..\..\stackman Console @@ -134,7 +134,7 @@ true _DEBUG;_CONSOLE;%(PreprocessorDefinitions) true - ..\..\src + ..\..\stackman Console From 2fbe1a75722d0efe01243178a4d994b2a3825c95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Wed, 7 Apr 2021 13:45:36 +0000 Subject: [PATCH 10/67] update line ending attributes --- .gitattributes | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/.gitattributes b/.gitattributes index 3340c6f..85dd98f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,6 +1,23 @@ # use unix lf line ending for everything except windows bat files * text=auto eol=lf -*.asm text eol=lf -*.h text eol=lf -*.{cmd,[cC][mM][dD]} text eol=crlf -*.{bat,[bB][aA][tT]} text eol=crlf + +# libraries are bin +*.o binary +*.obj binary +*.a binary +*.so binary +*.lib binary +*.dll binary +*.pdb binary + + +# source files explicitly +*.{c,h,asm,S} text eol=lf + +*.cmd text eol=crlf +*.bat text eol=crlf + +# Visulal studio is happier with crlf +*.sln text eol=crlf +*.vcxproj text eol=crlf +*.vcxproj.filters text eol=crlf From e7878f9ebc21f50b19aba3937d2aadecc3d8b683 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Sun, 11 Apr 2021 16:00:13 +0000 Subject: [PATCH 11/67] Update test.yml --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 026130b..45a401b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,7 +2,7 @@ name: C/C++ CI on: push: - branches: [ master ] + branches: [ master, dev ] pull_request: branches: [ master ] From 82d424ed6e13abb4223d3b66e981138aa350b819 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Sun, 11 Apr 2021 13:59:38 +0000 Subject: [PATCH 12/67] Update documentation --- README.md | 102 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 74 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 30c1706..1ff9766 100644 --- a/README.md +++ b/README.md @@ -30,16 +30,13 @@ platforms so that no assembly steps are required by users. ## Features - Simple api - - `stackman_switch()` is the main function. + - `stackman_switch()` and `stackman_call()` are the only functions. - The caller provides a callback and context pointer to customize behaviour. - - The callback can save the stack and provide the new stack pointer. - - After the switch, the callback can restore contents of new stack. - - Application behaviour is entirely defined by the callback. -- Simple implementation + Simple implementation - The code involving assembly is as simple as possible, allowing for straightforward implementation on most platforms. - Complex logic and branching is delegated to the C callback. - - Custom platform code must only do three things: + - Custom platform assembly code must only do three things: 1. Save and restore volatile registers and stack state on the stack 2. Call the callback twice with the current stack pointer 3. Set the stack pointer to the value returned by the first callback. @@ -62,6 +59,7 @@ standardizing the api. A number of ABI specifications is supported, meaning arc calling convention, plus archive format: - win_x86 (32 bits) - win_x64 + - win_ARM64 (experimental) - sysv_i386 (linux) - sysv_amd64 (linux) - AAPCS (32 bit arm) @@ -75,13 +73,46 @@ Supported toolchains: Other platforms can be easily adapted from both existing implementations for other projects as well as from example code provided. -### Intel CET -Intel's Conontrol-Flow Enforcement Technology is incompatible with stack switching -because it imploys a secondary Shadow Stack, that the user-mode program cannot -modify. Unexpected return flow after a stack switch would cause the processor -to fault. Because of this, we need to mark any assembly code as not CET compatible. Modern compilers are beginning to generate CET compatible objects and -once supporting CPUs start to arrive, processes which consist entirely of CET compatible code may be run in such a protected environment. See https://software.intel.com/content/www/us/en/develop/articles/technical-look-control-flow-enforcement-technology.html for more information - +## API +There are two functions that make up the stackman library: `stakman_switch()` and `stackman_call()` who +both take a `stackman_cb_t` callback: +```C +typedef void *(*stackman_cb_t)( + void *context, int opcode, void *stack_pointer); +void *stackman_switch(stackman_cb_t callback, void *context); +void *stackman_call(stackman_cb_t callback, void *context, void *stack); +``` +### stackman_switch() +This is the main _stack manipulation_ API. When called, it will call `callback` function twice: +1. First it calls it with the current opcode `STACKMAN_OP_SAVE`, passing the current `stack_pointer` to +the callback. This gives the callback the opportunity to _save_ the stack data somewhere. The callback +can then return a **different** stack pointer. +2. It takes the returned value from the calback and replaces the CPU _stack pointer_ with it. +3. It calls the callback a second time, with the opcode `STACKMAN_OP_RESTORE` and the new stack pointer. +This gives the callback the opportunity to replace the data on the stack with previously saved data. +4. It returns the return value from the second call to the callback function. + +The `context` pointer is passed as-is to the callback, allowing it access to user-defined data. + +Depending on how the callback function is implemented, this API can be used for a number of things, like +saving a copy of the stack, perform a stack switch, query the stack pointer, and so on. + +### stackman_call() +This is a helper function to call a callback function, optionally providing it with a different stack to +use. +1. It saves the current CPU stack pointer. If `stack` is non-zero, it will replace the stackpointer +with that value. +2. It calls the callback function with the opcode `STACKMAN_OP_CALL`. +3. It replaces the stack pointer with the previously saved value and returns the return value from the callback. + +This function is useful for at least three things: +- To move the call chain into a custom stack area, some heap-allocated block, for example. +- To query the current stack pointer +- To enforce an actual function call with stack pointer information. + +The last feature is useful to bypass any in-lining that a compiler may do, when one really wants +a proper function call with stack, for example, when setting up a new stack entry point. + ## Usage - Include `stackman.h` for a decleration of the `stackman_switch()` function and the definition of various platform specific macros. See the documentation @@ -100,19 +131,15 @@ There are two basic ways to add the library to your project: In the case of inlined code, it can be specified to prefer in-line assembly and static linkage over separate assembly language source. -## History -This works was originally inspired by *Stackless Python* by [Christian Tismer](https://github.com/ctismer), where the original switching code was -developed. - -Later projects, like *gevent/greenlet* have taken that idea and provided additional platform compatibility but -with a different implementation, making the switching code itself incompatible. - -Our work on additional stack-manipulating libraries prompted us to try to distill this functionality in its -rawest form into a separate, low-level, library. Such that any project, wishing to implement *co-routine*-like -behaviour on the C-stack level, could make use of simple, stable code, that can be easily extended for additional -platforms as they come along. +## Development +### Adding new platforms +1. Modify `platform.h` to identif the platform environment. Define an ABI name and + include custom header files. +2. Use the `switch_template.h` to help build a `switch_ABI.h` file for your ABI. +3. Provide an assembler version, `switch_ABI.S` by compiling the `gen_asm.c` file for your platform. +4. Provide cross-compilation tools for linux if possible, by modifying the `Makefile` -## Cross-compilation +### Cross-compilation Linux on x86-64 can be used to cross compile for x86 and ARM targets. This is most useful to generate assembly code, e.g. when compiling stackman/platform/gen_asm.c - x86 requires the -m32 flag to compilers and linkers. @@ -123,19 +150,38 @@ The x86 tools require the **gcc-multilib** and **g++-multilib** packages to be i **gcc-aarch64-linux-gnu** packages on some distributions, and so development for these platforms may need to be done independently. -### Cross compiling for x86 (32 bit) on Linux +#### Cross compiling for x86 (32 bit) on Linux - install __gcc-multilib__ and __g++-multilib__ - *compile* **gen_asm.c** using `gcc -m32` - *make* using `make PLATFORMFLAGS=-m32 test` -### Cross compiling for ARM (32 bit) on Linux +#### Cross compiling for ARM (32 bit) on Linux - install __gcc-arm-linux-gnueabi__ and __g++-arm-linux-gnueabi__ - install __qemu-user__ for hardware emulation - *compile* **gen_asm.c** using `arm-linux-gnueabi-gcc` - *make* using `make PLATFORM_PREFIX=arm-linux-gnueabi- EMULATOR=qemu-arm test` -### Cross compiling for Arm64 on Linux +#### Cross compiling for Arm64 on Linux - install **gcc-aarch64-linux-gnu** and **g++-aarch64-linux-gnu** - install __qemu-user__ for hardware emulation - *compile* using `aarch64-linux-gnu-gcc` - *make* using `make PLATFORM_PREFIX=aarch64-linux-gnu- EMULATOR=qemu-aarch64 test` + +## A note about Intel CET +Intel's Conontrol-Flow Enforcement Technology is incompatible with stack switching +because it imploys a secondary Shadow Stack, that the user-mode program cannot +modify. Unexpected return flow after a stack switch would cause the processor +to fault. Because of this, we need to mark any assembly code as not CET compatible. Modern compilers are beginning to generate CET compatible objects and +once supporting CPUs start to arrive, processes which consist entirely of CET compatible code may be run in such a protected environment. See https://software.intel.com/content/www/us/en/develop/articles/technical-look-control-flow-enforcement-technology.html for more information + +## History +This works was originally inspired by *Stackless Python* by [Christian Tismer](https://github.com/ctismer), where the original switching code was +developed. + +Later projects, like *gevent/greenlet* have taken that idea and provided additional platform compatibility but +with a different implementation, making the switching code itself incompatible. + +Our work on additional stack-manipulating libraries prompted us to try to distill this functionality in its +rawest form into a separate, low-level, library. Such that any project, wishing to implement *co-routine*-like +behaviour on the C-stack level, could make use of simple, stable code, that can be easily extended for additional +platforms as they come along. \ No newline at end of file From 89dc67c311fb0c9513e5a15440a2b10d69d5741f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Sun, 11 Apr 2021 17:00:01 +0000 Subject: [PATCH 13/67] Add test case for calling stackman_call() with null pointer --- tests/test.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/tests/test.c b/tests/test.c index 6ed3cb0..e6b726e 100644 --- a/tests/test.c +++ b/tests/test.c @@ -206,6 +206,8 @@ void *test_04_cb(void* context, int _opcode, void *old_sp) c->sp[1] = old_sp; return 0; } + +/* test stackman_call() with a non-null stack pointer */ void test_04(void) { char *block, *stack, *stack2; @@ -247,15 +249,32 @@ void test_04(void) for(i=0; i<64; i++) cnt += stack2[-i] == '\x7f'; assert(cnt != 64); +} + +/* test stackman_call() with a null stack pointer */ +void test_05(void) +{ + char *block, *stack, *stack2; + int i, cnt; + ctxt01 ctxt; + + assert(STACKMAN_STACK_FULL_DESCENDING); + /* perform the call */ + stackman_call(test_04_cb, &ctxt, 0); + /* verify that it was passed a stack */ + assert(ctxt.sp[1]); + assert(STACKMAN_SP_LE(ctxt.sp[0], ctxt.sp[1])); + /* and that it was passed valid lower stack pointer */ + assert(STACKMAN_SP_LE(ctxt.sp[1], &ctxt)); } #endif /* Test our various macros */ -void test_05() +void test_06() { int local=0; @@ -286,8 +305,10 @@ int main(int argc, char*argv[]) #ifdef TEST_04 test_04(); printf("test_04 ok\n"); -#endif test_05(); printf("test_05 ok\n"); +#endif + test_06(); + printf("test_06 ok\n"); return 0; } From 9c8b64a21b8e0509ca69d4d6057a0655e50bd8ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Sun, 11 Apr 2021 17:01:05 +0000 Subject: [PATCH 14/67] Add stackman_call to switch_template.h --- stackman/platforms/switch_template.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/stackman/platforms/switch_template.h b/stackman/platforms/switch_template.h index d3f11d4..149209f 100644 --- a/stackman/platforms/switch_template.h +++ b/stackman/platforms/switch_template.h @@ -44,6 +44,25 @@ void *STACKMAN_SWITCH_INASM_NAME(stackman_cb_t callback, void *context) /* __asm__("pop volatile registers") */ return stack_pointer; } + +STACKMAN_LINKAGE_SWITCH +void *stackman_call(stackman_cb_t callback, void *context, void *stack_pointer) +{ + void *old_sp, *result; + /* sp = store stack pointer in rbx */ + /*__asm__ ("movq %%rsp, %%rbx" : : : "rbx");*/ + /*__asm__ ("movq %%rsp, %[sp]" : [sp] "=r" (old_sp));*/ + + /* if non-null, set stack pointer as provided using assembly */ + if (stack_pointer != 0) + /*__asm__ ("movq %[sp], %%rsp" :: [sp] "r" (stack_pointer))*/; + + result = callback(context, STACKMAN_OP_CALL, old_sp); + /* restore stack pointer */ + /*__asm__ ("movq %%rbx, %%rsp" :::); */ + + return result; +} #endif #if __ASSEMBLER__ && defined(STACKMAN_ASSEMBLY_SRC) From 182c35b85e38041aff549a1eeedc4b2f8bf7b8bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Sun, 11 Apr 2021 17:01:32 +0000 Subject: [PATCH 15/67] stackman_call-nullptr for x64-linux --- stackman/platforms/switch_x86_64_gcc.S | 11 ++++++++--- stackman/platforms/switch_x86_64_gcc.h | 3 ++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/stackman/platforms/switch_x86_64_gcc.S b/stackman/platforms/switch_x86_64_gcc.S index 02304df..aca7168 100644 --- a/stackman/platforms/switch_x86_64_gcc.S +++ b/stackman/platforms/switch_x86_64_gcc.S @@ -116,15 +116,20 @@ stackman_call: # 93 "../platforms/switch_x86_64_gcc.h" 1 movq %rsp, %rcx # 0 "" 2 -# 96 "../platforms/switch_x86_64_gcc.h" 1 +#NO_APP + testq %rdx, %rdx + je .L4 +#APP +# 97 "../platforms/switch_x86_64_gcc.h" 1 movq %rdx, %rsp # 0 "" 2 #NO_APP +.L4: movq %rcx, %rdx movl $2, %esi call *%rax #APP -# 100 "../platforms/switch_x86_64_gcc.h" 1 +# 101 "../platforms/switch_x86_64_gcc.h" 1 movq %rbx, %rsp # 0 "" 2 #NO_APP @@ -136,5 +141,5 @@ stackman_call: .cfi_endproc .LFE1: .size stackman_call, .-stackman_call - .ident "GCC: (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0" + .ident "GCC: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0" .section .note.GNU-stack,"",@progbits diff --git a/stackman/platforms/switch_x86_64_gcc.h b/stackman/platforms/switch_x86_64_gcc.h index a958f93..50f566a 100644 --- a/stackman/platforms/switch_x86_64_gcc.h +++ b/stackman/platforms/switch_x86_64_gcc.h @@ -93,7 +93,8 @@ void *stackman_call(stackman_cb_t callback, void *context, void *stack_pointer) __asm__ ("movq %%rsp, %[sp]" : [sp] "=r" (old_sp)); /* set stack pointer from provided using assembly */ - __asm__ ("movq %[sp], %%rsp" :: [sp] "r" (stack_pointer)); + if (stack_pointer != 0) + __asm__ ("movq %[sp], %%rsp" :: [sp] "r" (stack_pointer)); result = callback(context, STACKMAN_OP_CALL, old_sp); /* restore stack pointer */ From 65eb17cd7d0d3344ae1e9dd833cea001a1473dc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Sun, 11 Apr 2021 17:05:39 +0000 Subject: [PATCH 16/67] disable fail-fast on matrix jobs --- .github/workflows/test.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 45a401b..2086164 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,6 +11,7 @@ jobs: test-linux-x86: runs-on: ubuntu-latest strategy: + fail-fast: false matrix: include: - platformflags: "" @@ -24,12 +25,14 @@ jobs: - uses: actions/checkout@v2 - name: install multilib run: sudo apt-get install --no-install-recommends -y gcc-multilib g++-multilib + if: ${{ matrix.name == 'i386' }} - name: make run: make && make test test-linux-arm: runs-on: ubuntu-latest strategy: + fail-fast: false matrix: include: - arch: arm @@ -54,6 +57,7 @@ jobs: test-windows: runs-on: windows-2019 strategy: + fail-fast: false matrix: platform: [x86, x64, ARM, ARM64] include: @@ -72,3 +76,4 @@ jobs: - name: test if: ${{ matrix.native == 'yes' }} run: vs2019\${{matrix.folder}}\Debug\test.exe + From 71e02069e3212b24f64e52008a4c88f5154a4280 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Sun, 11 Apr 2021 17:43:08 +0000 Subject: [PATCH 17/67] add zero-stack arg support for linux x86 --- lib/sysv_amd64/libstackman.a | Bin 3766 -> 3838 bytes lib/sysv_i386/libstackman.a | Bin 2702 -> 2774 bytes stackman/platforms/gen_asm.c | 2 +- stackman/platforms/switch_x86_gcc.S | 25 +++++++++++++------------ stackman/platforms/switch_x86_gcc.h | 17 ++++++++++++----- 5 files changed, 26 insertions(+), 18 deletions(-) diff --git a/lib/sysv_amd64/libstackman.a b/lib/sysv_amd64/libstackman.a index 6d668b6f96772901441cc24e4d79ec1fc2786a29..242351971c987a86d26aca3ceeef286a659c8ccc 100644 GIT binary patch delta 566 zcmdlc`%iX)H|s41298@30|J;V%_bk?FkmuZnRum#k$G|=qXf6RU#Nn!p}B&kp7G>~ zjN0|dX}SeP`6a2zC7Jnowt4w^sS3JjiN%$9$r(lYdHJQqx}|yLnRzL?C5cHnsl`Ca z;*!MVY?!9}BHiK=pu%*xL~>4IaRy8pXeL8xUU6o6UTTU$W?l&cSaWV-o<5Y}oTrz} zpkJO}lw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)u-$>eyp+X5V& zk9%EISh_<6IVyoC2)NfjYG&Uk1ut1dH);od5up CK3uf` diff --git a/stackman/platforms/gen_asm.c b/stackman/platforms/gen_asm.c index 9858b27..bd5785a 100644 --- a/stackman/platforms/gen_asm.c +++ b/stackman/platforms/gen_asm.c @@ -2,7 +2,7 @@ * of assembly code under e.g. Gcc. * use by calling, for example: * cc -S -m32 -fcf-protection=none gen_asm.c - * and examinine the generated test.s assembly code. + * and examinine the generated gen_asm.s assembly code. * -m32 selects 32 bit mode, use other directives to select a different platform. * The -fcf-protection flag disables generation of intel CET compatible code, but stack switching * is not compatible with the proposed shadow stack. Only the latest compilers have it. diff --git a/stackman/platforms/switch_x86_gcc.S b/stackman/platforms/switch_x86_gcc.S index fc4689f..671a6b5 100644 --- a/stackman/platforms/switch_x86_gcc.S +++ b/stackman/platforms/switch_x86_gcc.S @@ -76,31 +76,32 @@ stackman_call: movl %esp, %ebp .cfi_def_cfa_register 5 pushl %ebx - subl $8, %esp + subl $4, %esp .cfi_offset 3, -12 + movl 16(%ebp), %eax #APP # 108 "../platforms/switch_x86_gcc.h" 1 movl %esp, %ebx # 0 "" 2 -# 110 "../platforms/switch_x86_gcc.h" 1 - leal 4(%esp), %eax +# 111 "../platforms/switch_x86_gcc.h" 1 + movl %esp, %edx # 0 "" 2 #NO_APP - movl 16(%ebp), %edx + testl %eax, %eax + je .L4 #APP -# 113 "../platforms/switch_x86_gcc.h" 1 - movl %edx, %esp -# 0 "" 2 -# 115 "../platforms/switch_x86_gcc.h" 1 - subl $4, %esp +# 117 "../platforms/switch_x86_gcc.h" 1 + movl %eax, %esp # 0 "" 2 #NO_APP - pushl %eax +.L4: + subl $4, %esp + pushl %edx pushl $2 pushl 12(%ebp) call *8(%ebp) #APP -# 119 "../platforms/switch_x86_gcc.h" 1 +# 124 "../platforms/switch_x86_gcc.h" 1 movl %ebx, %esp # 0 "" 2 #NO_APP @@ -113,5 +114,5 @@ stackman_call: .cfi_endproc .LFE1: .size stackman_call, .-stackman_call - .ident "GCC: (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0" + .ident "GCC: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0" .section .note.GNU-stack,"",@progbits diff --git a/stackman/platforms/switch_x86_gcc.h b/stackman/platforms/switch_x86_gcc.h index 1a1635c..38fbee8 100644 --- a/stackman/platforms/switch_x86_gcc.h +++ b/stackman/platforms/switch_x86_gcc.h @@ -107,12 +107,19 @@ void *stackman_call(stackman_cb_t callback, void *context, void *stack_pointer) /* sp = store stack pointer in ebx */ __asm__ ("movl %%esp, %%ebx" : : : "ebx"); /* save old stack pointer at same offset as new stack pointer */ - __asm__ ("leal 4(%%esp), %[sp]" : [sp] "=r" (old_sp)); - + /* (adjustment of stack pointer not required now) + /*__asm__ ("leal 4(%%esp), %[sp]" : [sp] "=r" (old_sp)); */ + __asm__ ("movl %%esp, %[sp]" : [sp] "=r" (old_sp)); + + /* set stack pointer from provided using assembly */ - __asm__ ("movl %[sp], %%esp" :: [sp] "r" (stack_pointer)); - /* subtract 4 bytes to make it 16 byte alighed after pushing 3 args */ - __asm__ ("subl $4, %esp"); + if (stack_pointer != 0) + { + __asm__ ("movl %[sp], %%esp" :: [sp] "r" (stack_pointer)); + /* subtract 4 bytes to make it 16 byte alighed after pushing 3 args */ + /* (adjustment of stack pointer not required now) + /* __asm__ ("subl $4, %esp"); */ + } result = callback(context, STACKMAN_OP_CALL, old_sp); /* restore stack pointer */ From 1c3cfc1a2085a12d958e078137c76cd1090eecc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Sun, 11 Apr 2021 17:58:16 +0000 Subject: [PATCH 18/67] add nullptr support for x86 msvc --- stackman/platforms/switch_x86_msvc.asm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/stackman/platforms/switch_x86_msvc.asm b/stackman/platforms/switch_x86_msvc.asm index 1884987..2f28cf9 100644 --- a/stackman/platforms/switch_x86_msvc.asm +++ b/stackman/platforms/switch_x86_msvc.asm @@ -50,7 +50,10 @@ stackman_call PROC callback:DWORD, context:DWORD, stack_pointer:DWORD mov edx, stack_pointer ; switch stack pointer + test edx, edx + je nullptr mov esp, stack_pointer +nullptr: push ebp ;old stack pointer push 2 ;STACKMAN_OP_CALL push ecx ;context From dc8cd2e408254e1bd67aba916b233b484aa4dec0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Sun, 11 Apr 2021 18:07:22 +0000 Subject: [PATCH 19/67] add nullptr support for stackman_call, msvc-amd64 --- stackman/platforms/switch_x64_msvc.asm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/stackman/platforms/switch_x64_msvc.asm b/stackman/platforms/switch_x64_msvc.asm index f2351af..5143276 100644 --- a/stackman/platforms/switch_x64_msvc.asm +++ b/stackman/platforms/switch_x64_msvc.asm @@ -122,7 +122,10 @@ stackman_call PROC FRAME ; rcx already set up with context ; modify stack pointer before call + test r9, r9 + je nullptr mov rsp, r9 +nullptr: sub rsp, 32 ;pre-allocate parameter stack for the callee call rax From 0da13232845aa4a3d12ae5fe5829cb9c56118063 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Sun, 11 Apr 2021 18:15:26 +0000 Subject: [PATCH 20/67] stackman_call nullptr support for ARM --- stackman/platforms/switch_arm_gcc.S | 28 +++++++++++++++++----------- stackman/platforms/switch_arm_gcc.h | 3 ++- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/stackman/platforms/switch_arm_gcc.S b/stackman/platforms/switch_arm_gcc.S index a10b063..8e11645 100644 --- a/stackman/platforms/switch_arm_gcc.S +++ b/stackman/platforms/switch_arm_gcc.S @@ -32,7 +32,7 @@ stackman_switch: mov r3, r0 mov r0, r1 .syntax divided -@ 82 "switch_arm_gcc.h" 1 +@ 84 "../platforms/switch_arm_gcc.h" 1 mov r2, sp @ 0 "" 2 .arm @@ -43,7 +43,7 @@ stackman_switch: blx r3 mov r2, r0 .syntax divided -@ 86 "switch_arm_gcc.h" 1 +@ 88 "../platforms/switch_arm_gcc.h" 1 mov sp, r0 @ 0 "" 2 .arm @@ -64,30 +64,36 @@ stackman_call: @ frame_needed = 1, uses_anonymous_args = 0 push {r4, r5, fp, lr} add fp, sp, #12 - mov r3, r0 + mov r5, r0 mov r0, r1 - mov r1, r2 + mov r3, r2 .syntax divided -@ 102 "switch_arm_gcc.h" 1 +@ 104 "../platforms/switch_arm_gcc.h" 1 mov r4, sp @ 0 "" 2 -@ 103 "switch_arm_gcc.h" 1 +@ 105 "../platforms/switch_arm_gcc.h" 1 mov r2, sp @ 0 "" 2 -@ 106 "switch_arm_gcc.h" 1 - mov sp, r1 + .arm + .syntax unified + cmp r3, #0 + beq .L4 + .syntax divided +@ 109 "../platforms/switch_arm_gcc.h" 1 + mov sp, r3 @ 0 "" 2 .arm .syntax unified +.L4: mov r1, #2 - blx r3 + blx r5 .syntax divided -@ 110 "switch_arm_gcc.h" 1 +@ 113 "../platforms/switch_arm_gcc.h" 1 mov sp, r4 @ 0 "" 2 .arm .syntax unified pop {r4, r5, fp, pc} .size stackman_call, .-stackman_call - .ident "GCC: (Ubuntu 9.3.0-10ubuntu1) 9.3.0" + .ident "GCC: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0" .section .note.GNU-stack,"",%progbits diff --git a/stackman/platforms/switch_arm_gcc.h b/stackman/platforms/switch_arm_gcc.h index 1dafafb..5fd867c 100644 --- a/stackman/platforms/switch_arm_gcc.h +++ b/stackman/platforms/switch_arm_gcc.h @@ -105,7 +105,8 @@ void *stackman_call(stackman_cb_t callback, void *context, void *stack_pointer) __asm__ ("mov %[var], sp" : [var] "=r" (old_sp)); /* set stack pointer from provided using assembly */ - __asm__ ("mov sp, %[var]" :: [var] "r" (stack_pointer)); + if (stack_pointer != 0) + __asm__ ("mov sp, %[var]" :: [var] "r" (stack_pointer)); result = callback(context, STACKMAN_OP_CALL, old_sp); /* restore stack pointer */ From 9f60afd3a153073b3c60d211a009c3fdeebd8f47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Sun, 11 Apr 2021 18:18:49 +0000 Subject: [PATCH 21/67] stackman_call nullptr support for AARCH64 --- stackman/platforms/switch_aarch64_gcc.S | 26 ++++++++++++++----------- stackman/platforms/switch_aarch64_gcc.h | 3 ++- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/stackman/platforms/switch_aarch64_gcc.S b/stackman/platforms/switch_aarch64_gcc.S index 642ec58..5b0406a 100644 --- a/stackman/platforms/switch_aarch64_gcc.S +++ b/stackman/platforms/switch_aarch64_gcc.S @@ -53,7 +53,7 @@ stackman_switch: mov x3, x0 mov x0, x1 #APP -// 57 "switch_aarch64_gcc.h" 1 +// 59 "../platforms/switch_aarch64_gcc.h" 1 mov x2, sp // 0 "" 2 #NO_APP @@ -63,7 +63,7 @@ stackman_switch: blr x3 mov x2, x0 #APP -// 61 "switch_aarch64_gcc.h" 1 +// 63 "../platforms/switch_aarch64_gcc.h" 1 mov sp, x0 // 0 "" 2 #NO_APP @@ -118,24 +118,28 @@ stackman_call: mov x29, sp str x19, [sp, 16] .cfi_offset 19, -16 - mov x3, x0 + mov x4, x0 mov x0, x1 - mov x1, x2 + mov x3, x2 #APP -// 77 "switch_aarch64_gcc.h" 1 +// 78 "../platforms/switch_aarch64_gcc.h" 1 mov x19, sp // 0 "" 2 -// 78 "switch_aarch64_gcc.h" 1 +// 79 "../platforms/switch_aarch64_gcc.h" 1 mov x2, sp // 0 "" 2 -// 82 "switch_aarch64_gcc.h" 1 - mov sp, x1 +#NO_APP + cbz x3, .L4 +#APP +// 84 "../platforms/switch_aarch64_gcc.h" 1 + mov sp, x3 // 0 "" 2 #NO_APP +.L4: mov w1, 2 - blr x3 + blr x4 #APP -// 86 "switch_aarch64_gcc.h" 1 +// 88 "../platforms/switch_aarch64_gcc.h" 1 mov sp, x19 // 0 "" 2 #NO_APP @@ -149,5 +153,5 @@ stackman_call: .cfi_endproc .LFE1: .size stackman_call, .-stackman_call - .ident "GCC: (Ubuntu 9.3.0-10ubuntu1) 9.3.0" + .ident "GCC: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0" .section .note.GNU-stack,"",@progbits diff --git a/stackman/platforms/switch_aarch64_gcc.h b/stackman/platforms/switch_aarch64_gcc.h index b6e7739..87d2a45 100644 --- a/stackman/platforms/switch_aarch64_gcc.h +++ b/stackman/platforms/switch_aarch64_gcc.h @@ -80,7 +80,8 @@ void *stackman_call(stackman_cb_t callback, void *context, void *stack_pointer) /* set stack pointer from provided using assembly */ - __asm__ ("mov sp, %[var]" :: [var] "r" (stack_pointer)); + if(stack_pointer != 0) + __asm__ ("mov sp, %[var]" :: [var] "r" (stack_pointer)); result = callback(context, STACKMAN_OP_CALL, old_sp); /* restore stack pointer */ From aab9dc57597cb088dddaa213da9ca489ca6eb393 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Sun, 11 Apr 2021 18:32:27 +0000 Subject: [PATCH 22/67] Add stackman_call() nullptr support for msvc arm/aarch64 --- stackman/platforms/switch_arm64_msvc.asm | 9 ++++++--- stackman/platforms/switch_arm_msvc.asm | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/stackman/platforms/switch_arm64_msvc.asm b/stackman/platforms/switch_arm64_msvc.asm index 3095592..b4b1f13 100644 --- a/stackman/platforms/switch_arm64_msvc.asm +++ b/stackman/platforms/switch_arm64_msvc.asm @@ -83,12 +83,15 @@ mov x1, x2 ;stack ; store current sp in nv register mov x18, sp - mov x2, sp ; new stack - ; change stack + mov x2, sp ; old stack + + ; change stack, if provided non-zero + cbz x1, nullptr mov sp, x1 +nullptr mov x1, #2 ; callback opcode - blr x3 ; call callback, with context, opcode, new stack + blr x3 ; call callback, with context, opcode, old stack ; restore stack (could do: sub sp, fp #12) mov sp, x18 diff --git a/stackman/platforms/switch_arm_msvc.asm b/stackman/platforms/switch_arm_msvc.asm index 84fa732..f002dfa 100644 --- a/stackman/platforms/switch_arm_msvc.asm +++ b/stackman/platforms/switch_arm_msvc.asm @@ -54,12 +54,15 @@ mov r1, r2 ;stack ; store current sp in nv register mov r4, sp - mov r2, sp ; new stack + mov r2, sp ; old stack - ; change stack + ; change stack if non-zero + cmp r1, #0 + beq nullptr mov sp, r1 +nullptr mov r1, #2 ; callback opcode - blx r3 ; call callback, with context, opcode, new stack + blx r3 ; call callback, with context, opcode, old stack ; restore stack (could do: sub sp, fp #12) mov sp, r4 ; return From 71bf16d9f88e5d0b0d4043506253a8f18d163349 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Sun, 11 Apr 2021 19:17:26 +0000 Subject: [PATCH 23/67] Ad build workflow --- .github/workflows/buildcommit.yml | 88 +++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 .github/workflows/buildcommit.yml diff --git a/.github/workflows/buildcommit.yml b/.github/workflows/buildcommit.yml new file mode 100644 index 0000000..1d2e568 --- /dev/null +++ b/.github/workflows/buildcommit.yml @@ -0,0 +1,88 @@ +name: build and commit + +on: + push: + branches: [ master, dev ] + + workflow_dispatch: + +jobs: + + build-linux-x86: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - platformflags: "" + name: "AMD64" + - platformflags: -m32 + name: "i386" + name: test-linux-x86 (${{matrix.name}}) + env: + PLATFORMFLAGS: ${{matrix.platformflags}} + steps: + - uses: actions/checkout@v2 + - name: install multilib + run: sudo apt-get install --no-install-recommends -y gcc-multilib g++-multilib + if: ${{ matrix.name == 'i386' }} + - name: make + run: make all + - name: Commit libraries + run: | + git config --global user.name 'Build Runner' + git config --global user.email 'buildrunner@users.noreply.github.com' + git add lib/*.a + git commit -m "Automated build" + git push + + build-linux-arm: + if: 0 + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - arch: arm + emulator: qemu-arm + abi: arm-linux-gnueabi + - arch: aarch64 + emulator: qemu-aarch64 + abi: aarch64-linux-gnu + name: test-linux-arm (${{matrix.arch}}) + env: + PLATFORM_PREFIX: ${{matrix.abi}}- + EMULATOR: ${{matrix.emulator}} + steps: + - uses: actions/checkout@v2 + - name: install qemu + run: sudo apt-get install --no-install-recommends -y qemu-user + - name: install abi lib + run: sudo apt-get install --no-install-recommends -y gcc-${{matrix.abi}} g++-${{matrix.abi}} + - name: make + run: make && make test + + build-windows: + if: 0 + runs-on: windows-2019 + strategy: + fail-fast: false + matrix: + platform: [x86, x64, ARM, ARM64] + include: + - platform: x86 + folder: Win32 + native: yes + - platform: x64 + folder: x64 + native: yes + steps: + - uses: actions/checkout@v2 + - name: Add msbuild to PATH + uses: microsoft/setup-msbuild@v1.0.2 + - name: build + run: msbuild.exe vs2019\stackman.sln /p:Platform=${{matrix.platform}} + - name: test + if: ${{ matrix.native == 'yes' }} + run: vs2019\${{matrix.folder}}\Debug\test.exe + From f1fb0c892a0ec0886135cb0e2f68b25633ed119d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Sun, 11 Apr 2021 19:21:02 +0000 Subject: [PATCH 24/67] Update buildcommit.yml --- .github/workflows/buildcommit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/buildcommit.yml b/.github/workflows/buildcommit.yml index 1d2e568..3f1fc44 100644 --- a/.github/workflows/buildcommit.yml +++ b/.github/workflows/buildcommit.yml @@ -29,7 +29,7 @@ jobs: - name: make run: make all - name: Commit libraries - run: | + run: | git config --global user.name 'Build Runner' git config --global user.email 'buildrunner@users.noreply.github.com' git add lib/*.a From 6b8c7a43a7afbacaa293bd990ca6204367097d01 Mon Sep 17 00:00:00 2001 From: Build Runner Date: Sun, 11 Apr 2021 19:21:13 +0000 Subject: [PATCH 25/67] Automated build --- lib/sysv_amd64/libstackman.a | Bin 3838 -> 3854 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/lib/sysv_amd64/libstackman.a b/lib/sysv_amd64/libstackman.a index 242351971c987a86d26aca3ceeef286a659c8ccc..3025f8151273979fa68938024aa0871fd4eec71a 100644 GIT binary patch delta 158 zcmew-+b1`{oAng~1IMe$6S?Ik<{2^?PUhh>VszMeIe}3!BR@A)zo;}XFSSU&JijPg zzqlkZIXgEoZ?Y|u@8q>y>6{0hiC!8o~*No?{y r9)ZbP91@HtCOdQ3bG~3=00W-M>-o$%7cfJ3{gc=8$Zvkdp~40LB5*46 From 573c15a7ee84920b48e71ba845ab0faf2e39fa9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Sun, 11 Apr 2021 19:33:27 +0000 Subject: [PATCH 26/67] Update buildcommit.yml Update buildcommit.yml Update buildcommit.yml --- .github/workflows/buildcommit.yml | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/.github/workflows/buildcommit.yml b/.github/workflows/buildcommit.yml index 3f1fc44..1da69e7 100644 --- a/.github/workflows/buildcommit.yml +++ b/.github/workflows/buildcommit.yml @@ -28,6 +28,8 @@ jobs: if: ${{ matrix.name == 'i386' }} - name: make run: make all + - name: test + run: make test - name: Commit libraries run: | git config --global user.name 'Build Runner' @@ -37,10 +39,9 @@ jobs: git push build-linux-arm: - if: 0 runs-on: ubuntu-latest strategy: - fail-fast: false + fail-fast: true matrix: include: - arch: arm @@ -60,13 +61,21 @@ jobs: - name: install abi lib run: sudo apt-get install --no-install-recommends -y gcc-${{matrix.abi}} g++-${{matrix.abi}} - name: make - run: make && make test + run: make all + - name: test + run: make test + - name: Commit libraries + run: | + git config --global user.name 'Build Runner' + git config --global user.email 'buildrunner@users.noreply.github.com' + git add lib/*.a + git commit -m "Automated build" + git push build-windows: - if: 0 runs-on: windows-2019 strategy: - fail-fast: false + fail-fast: true matrix: platform: [x86, x64, ARM, ARM64] include: @@ -85,4 +94,11 @@ jobs: - name: test if: ${{ matrix.native == 'yes' }} run: vs2019\${{matrix.folder}}\Debug\test.exe + - name: Commit libraries + run: | + git config --global user.name 'Build Runner' + git config --global user.email 'buildrunner@users.noreply.github.com' + git add lib/*.lib + git commit -m "Automated build" + git push From 69ad2c53864c043b2e2cd5a675e5c2f2dfce4082 Mon Sep 17 00:00:00 2001 From: Build Runner Date: Sun, 11 Apr 2021 19:33:51 +0000 Subject: [PATCH 27/67] Automated build --- lib/sysv_i386/libstackman.a | Bin 2774 -> 2790 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/lib/sysv_i386/libstackman.a b/lib/sysv_i386/libstackman.a index c71c0c7bd7c1595a322dab03887ada12110a951b..d5e977120323b9c8dc373f67db9902697b342880 100644 GIT binary patch delta 121 zcmV-<0EYk873LL?O9h4i00xGUP)`CiFq5eUDFIxu%U1yzXm4$0FLHHmZe?;WcW-iQ zFLQKZV{2_;Zj&qmMw9&qPqV-R4gvv`lg|Wq0mPF>1ycdwlbZ!20h^P*1t$W=0h2HU b7L)!35CO=O4+bXzh?6%4Cjrc}Uj}ys10X2+ delta 107 zcmV-x0F?jc71kAyO9gfS00wrEP)`FiI5d;G1}FhcvCCHh3U_aEYjbd6V`X!bI|4?N z4hT-O&;kwu0fdv^1a|?nlUD^(0nwAI1tS5Blg|Yw0=EH^Km-<(4h9ebxRW0SCjoeq NM+PSWyt8ixcLZ7*A*cWV From e1cec3b7f4da6331eb31d636cf6e443e5bebbc99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Sun, 11 Apr 2021 19:46:34 +0000 Subject: [PATCH 28/67] Update buildcommit.yml --- .github/workflows/buildcommit.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/buildcommit.yml b/.github/workflows/buildcommit.yml index 1da69e7..f04036c 100644 --- a/.github/workflows/buildcommit.yml +++ b/.github/workflows/buildcommit.yml @@ -35,7 +35,7 @@ jobs: git config --global user.name 'Build Runner' git config --global user.email 'buildrunner@users.noreply.github.com' git add lib/*.a - git commit -m "Automated build" + git diff-index --quiet HEAD || git commit -m "Automated build" git push build-linux-arm: @@ -69,7 +69,7 @@ jobs: git config --global user.name 'Build Runner' git config --global user.email 'buildrunner@users.noreply.github.com' git add lib/*.a - git commit -m "Automated build" + git diff-index --quiet HEAD || git commit -m "Automated build" git push build-windows: @@ -99,6 +99,6 @@ jobs: git config --global user.name 'Build Runner' git config --global user.email 'buildrunner@users.noreply.github.com' git add lib/*.lib - git commit -m "Automated build" + git diff-index --quiet HEAD || git commit -m "Automated build" git push From d252a4d45cefd1157ab19bb2c85c0920307a9359 Mon Sep 17 00:00:00 2001 From: Build Runner Date: Sun, 11 Apr 2021 19:47:05 +0000 Subject: [PATCH 29/67] Automated build --- lib/aarch64/libstackman.a | Bin 3902 -> 3990 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/lib/aarch64/libstackman.a b/lib/aarch64/libstackman.a index e4874e12bedddfa8500ef019a513a84f6a8fca02..a2316bd9d5f35c8a4aec2547e6848b4b9d240317 100644 GIT binary patch delta 607 zcmdldH%)$mH|r|~298$~1N@l`4JR%%WO87cc%_Gtd2%A7s(f)tVsdtFVxB&Xp_k0y z?iZ@yY-p}vsb@TSBBN$~a++>IQGQ8ka!F=>o^4)!UaEp_T4Hf!UUEiJeqMfQv2JNz zd1hXUZb@QNPHHhw5^NYuQ+|!n^Aj1&iLIwtRXJ;z~jnJghypmFoAe$G;7ey1_zIivZITI5H^W-nA`xs|T-ptm{czg1E zUiryU>=K--fVx3I8!R%5U4rQ<<77i7vB`S80+VmCOEBJ;{F&XJ^9K_|8PDYVeCC`R zm?6CW$?`yBW^ouZT1-C2VZgXy@_&xiicgpsRy|;5T=kflY1LwNZ{5m0Z0fV=?! DK}M;t delta 474 zcmbOxzfW$0H|s10298-11N@l`j3+KMWct87@k$RP)8s@(Rc?2`Pz7g0Lj`j^)5%L2 zH77BN#V`~XCF>WLBqnF)Cg$lSGw5gJ=cejs7iAWgWF_Y5r)QSHWf>UUot>=|G(wX~ z^GZtfeKPYBi}FEc=^5x6mx2Wi>kKXQ3`{g3qLV+e$Zej*(PJ_*dpl$Elh|Y_ z4h_bR$<7@1j4LKL1IdKRhdH7c4JONR8URK7IakX*W@cFRfSGaCLuRH`pP3mZJ_2HU z28M}_3=KgElcl*d1P!1*&{VM0GuAU;V3-`i)hA*DvdfWAVJ^!&W~a$a-uLca<^y_5 zX7Vhigvn*x3m9!Si}T1cG9H<1&TG!Z0&&hPRt*?aicMtlEnX2$7O1mTfu4|`EXF6n qqzO?Q#VRm4j86jS*nB>FMuo}if#ikB?}6lp$@={Ei~*DL`PBhW4S68| From cf5d06e270d99873027b9cb3b91fdfde07a9c6cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Mon, 12 Apr 2021 10:29:19 +0000 Subject: [PATCH 30/67] makefile can echo the abiname --- Makefile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index d688059..1120222 100644 --- a/Makefile +++ b/Makefile @@ -21,18 +21,22 @@ endif ABI := $(shell ./abiname.sh "$(CC)" "$(CFLAGS)") ifndef ABI $(error Could not determine platform) -else -$(info ABI is $(ABI)) endif LIB := lib/$(ABI) all: $(LIB)/libstackman.a +# echo the abiname, for build tools. +.PHONY: abiname +abiname: + @echo $(ABI) + obj = stackman/stackman.o stackman/stackman_s.o $(LIB)/libstackman.a: lib $(obj) + $(info ABI is $(ABI)) $(AR) $(ARFLAGS) -s $@ $(obj) .PHONY: lib clean From d43e84a1cc8211f66d9bb4443e4046b5cbe3c100 Mon Sep 17 00:00:00 2001 From: Build Runner Date: Mon, 12 Apr 2021 10:31:16 +0000 Subject: [PATCH 31/67] Automated build --- lib/arm32/libstackman.a | Bin 2722 -> 2774 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/lib/arm32/libstackman.a b/lib/arm32/libstackman.a index e2b3efb0bb87c1ca22b1a876c2ac0c33ef381bcf..ce4199d5e791616603e51ac93b275c510600e043 100644 GIT binary patch delta 553 zcmZ1^dQEhKH|s412DV!h0|J;VOeVi#(_rkFcv_yzm4ShQhZjgFPW%$V$UNDXQPs7$ zBr!QVH!)8i#?VV<(9g)vP1P?d&C5$I(l5_1%7#nA84T`zp$g81<_ea2#(D;mdl^;h za}$el6?B1Qa)vFCS!Pyj1R?h_R0n7{(5VatKnwy)fLMF-aiFU6Kvm+Rph#tAU?>2|fxvkn eM)>Q`WNR*UrZtR{53q<$26~G12GFcfkQV_Pu delta 393 zcmca6x=3__H|sVA2DWVz0|J;#EGF}@YcQrvJT1?~%fP_ElLsVfCw_@wWSZ>Ds4DI5 z7pmZFXsBSWXR2qQpqraml$>FkSd?34S~7V%qbhs4f^J%Xr}JbUCaK8cqGbKzlEmcf z+{8S+WCs0={M=Oi?4r!#lB~o${q)QdxGV#MyR);Ef<|akXov#Vw0`d1Q=T)L z519lOJmhr%Vg(@o0+|2Uc=CF71r7tKOD5lCcb?qGPL}6VXFA9**@sPy@y+CXE}$gPp*oZ2vney4 Jn7p4$8~|(|czyr? From cdef453a2aeb52f652dd42b43a11aa429829bea6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Mon, 12 Apr 2021 11:45:40 +0000 Subject: [PATCH 32/67] Update buildcommit.yml --- .github/workflows/buildcommit.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/buildcommit.yml b/.github/workflows/buildcommit.yml index 72384fc..850a174 100644 --- a/.github/workflows/buildcommit.yml +++ b/.github/workflows/buildcommit.yml @@ -23,10 +23,10 @@ jobs: - name: arm platformtools: arm-linux-gnueabi emulator: qemu-arm - name: build-linux-gnu (${{matrix.name}}) + # name: build-linux-gnu (${{matrix.name}}) env: PLATFORMFLAGS: ${{matrix.platformflags}} - PLATFORM_PREFIX: ${{matrix.platformtools}}- + PLATFORM_PREFIX: ${{matrix.platformtools}} EMULATOR: ${{matrix.emulator}} steps: - uses: actions/checkout@v2 @@ -52,7 +52,7 @@ jobs: path: lib/${{ env.abiname }}/libstackman.a build-linux-arm: - if: 0 + if: false runs-on: ubuntu-latest strategy: fail-fast: true @@ -87,7 +87,7 @@ jobs: git push build-windows: - if: 0 + if: false runs-on: windows-2019 strategy: fail-fast: true From 464c90fa08aa7ff1bb1953912c68bf813f558348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Mon, 12 Apr 2021 10:39:01 +0000 Subject: [PATCH 33/67] Update buildcommit.yml --- .github/workflows/buildcommit.yml | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/workflows/buildcommit.yml b/.github/workflows/buildcommit.yml index f04036c..fec0fba 100644 --- a/.github/workflows/buildcommit.yml +++ b/.github/workflows/buildcommit.yml @@ -18,7 +18,7 @@ jobs: name: "AMD64" - platformflags: -m32 name: "i386" - name: test-linux-x86 (${{matrix.name}}) + name: build-linux-x86 (${{matrix.name}}) env: PLATFORMFLAGS: ${{matrix.platformflags}} steps: @@ -30,15 +30,16 @@ jobs: run: make all - name: test run: make test - - name: Commit libraries - run: | - git config --global user.name 'Build Runner' - git config --global user.email 'buildrunner@users.noreply.github.com' - git add lib/*.a - git diff-index --quiet HEAD || git commit -m "Automated build" - git push + - name: set abi name + run: echo abiname=$(make abiname) >> $GITHUB_ENV + - name: Upload build artifacts + uses: actions/upload-artifact@v2 + with: + name: ${{ env.abiname }} + path: lib/${{ env.abiname }}/libstackman.a build-linux-arm: + if: 0 runs-on: ubuntu-latest strategy: fail-fast: true @@ -73,6 +74,7 @@ jobs: git push build-windows: + if: 0 runs-on: windows-2019 strategy: fail-fast: true From 66de59a56191336d90f944e0291ae72a62f251ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Mon, 12 Apr 2021 11:56:50 +0000 Subject: [PATCH 34/67] Update buildcommit.yml --- .github/workflows/buildcommit.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/buildcommit.yml b/.github/workflows/buildcommit.yml index 850a174..f8757e7 100644 --- a/.github/workflows/buildcommit.yml +++ b/.github/workflows/buildcommit.yml @@ -14,9 +14,6 @@ jobs: fail-fast: false matrix: name: [AMD64, i386, arm] - platformflags: [""] - platformtools: [""] - emulator: [""] include: - name: i386 platformflags: -m32 From 390006ae02c2ad9723cf601329032d82bdfc1a3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Mon, 12 Apr 2021 11:27:57 +0000 Subject: [PATCH 35/67] Update buildcommit.yml --- .github/workflows/buildcommit.yml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/buildcommit.yml b/.github/workflows/buildcommit.yml index fec0fba..9326858 100644 --- a/.github/workflows/buildcommit.yml +++ b/.github/workflows/buildcommit.yml @@ -8,24 +8,36 @@ on: jobs: - build-linux-x86: + build-linux-gnu: runs-on: ubuntu-latest strategy: fail-fast: false matrix: + name: [AMD64, i386, arm] + platformflags: ["", "-m32"] + platformtools: ["", "", "arm-linux-gnueabi"] + emulator: ["", "", "qemu-arm"] include: - platformflags: "" name: "AMD64" - platformflags: -m32 name: "i386" - name: build-linux-x86 (${{matrix.name}}) + name: build-linux-gnu (${{matrix.name}}) env: PLATFORMFLAGS: ${{matrix.platformflags}} + PLATFORM_PREFIX: ${{matrix.platformtools}}- + EMULATOR: ${{matrix.emulator}} steps: - uses: actions/checkout@v2 - name: install multilib run: sudo apt-get install --no-install-recommends -y gcc-multilib g++-multilib if: ${{ matrix.name == 'i386' }} + - name: install qemu + if: matrix.emulator + run: sudo apt-get install --no-install-recommends -y qemu-user + - name: install abi lib + if: matrix.platformtools + run: sudo apt-get install --no-install-recommends -y gcc-${{matrix.platformtools}} g++-${{matrix.platformtools}} - name: make run: make all - name: test From 004a2483a0bd3a135f2c8e41926347144a65f7e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Mon, 12 Apr 2021 12:07:14 +0000 Subject: [PATCH 36/67] Update buildcommit.yml --- .github/workflows/buildcommit.yml | 63 ++++++++----------------------- 1 file changed, 16 insertions(+), 47 deletions(-) diff --git a/.github/workflows/buildcommit.yml b/.github/workflows/buildcommit.yml index f8757e7..07871ba 100644 --- a/.github/workflows/buildcommit.yml +++ b/.github/workflows/buildcommit.yml @@ -13,13 +13,16 @@ jobs: strategy: fail-fast: false matrix: - name: [AMD64, i386, arm] + name: [AMD64, i386, arm, aarch64] include: - name: i386 platformflags: -m32 - name: arm platformtools: arm-linux-gnueabi emulator: qemu-arm + - name: aarch64 + platformtools: aarch64-linux-gnue + emulator: qemu-aarch64 # name: build-linux-gnu (${{matrix.name}}) env: PLATFORMFLAGS: ${{matrix.platformflags}} @@ -48,48 +51,13 @@ jobs: name: ${{ env.abiname }} path: lib/${{ env.abiname }}/libstackman.a - build-linux-arm: - if: false - runs-on: ubuntu-latest - strategy: - fail-fast: true - matrix: - include: - - arch: arm - emulator: qemu-arm - abi: arm-linux-gnueabi - - arch: aarch64 - emulator: qemu-aarch64 - abi: aarch64-linux-gnu - name: test-linux-arm (${{matrix.arch}}) - env: - PLATFORM_PREFIX: ${{matrix.abi}}- - EMULATOR: ${{matrix.emulator}} - steps: - - uses: actions/checkout@v2 - - name: install qemu - run: sudo apt-get install --no-install-recommends -y qemu-user - - name: install abi lib - run: sudo apt-get install --no-install-recommends -y gcc-${{matrix.abi}} g++-${{matrix.abi}} - - name: make - run: make all - - name: test - run: make test - - name: Commit libraries - run: | - git config --global user.name 'Build Runner' - git config --global user.email 'buildrunner@users.noreply.github.com' - git add lib/*.a - git diff-index --quiet HEAD || git commit -m "Automated build" - git push - build-windows: if: false runs-on: windows-2019 strategy: fail-fast: true matrix: - platform: [x86, x64, ARM, ARM64] + platform: [x86, x64, arm, arm64] include: - platform: x86 folder: Win32 @@ -97,20 +65,21 @@ jobs: - platform: x64 folder: x64 native: yes + - platform: arm + folder: arm + - platform: arm64 + folder: arm64 + steps: - uses: actions/checkout@v2 - - name: Add msbuild to PATH - uses: microsoft/setup-msbuild@v1.0.2 + - uses: microsoft/setup-msbuild@v1.0.2 - name: build run: msbuild.exe vs2019\stackman.sln /p:Platform=${{matrix.platform}} - name: test if: ${{ matrix.native == 'yes' }} run: vs2019\${{matrix.folder}}\Debug\test.exe - - name: Commit libraries - run: | - git config --global user.name 'Build Runner' - git config --global user.email 'buildrunner@users.noreply.github.com' - git add lib/*.lib - git diff-index --quiet HEAD || git commit -m "Automated build" - git push - + - name: Upload build artifacts + uses: actions/upload-artifact@v2 + with: + name: win-${{ matrix.platform }} + path: vs2019/${{matrix.folder}}/Debug/stackman.lib From 5b8dbac03d592baebf6639a1099938b8ab7fbf73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Mon, 12 Apr 2021 11:33:37 +0000 Subject: [PATCH 37/67] Update buildcommit.yml --- .github/workflows/buildcommit.yml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/buildcommit.yml b/.github/workflows/buildcommit.yml index 9326858..72384fc 100644 --- a/.github/workflows/buildcommit.yml +++ b/.github/workflows/buildcommit.yml @@ -14,14 +14,15 @@ jobs: fail-fast: false matrix: name: [AMD64, i386, arm] - platformflags: ["", "-m32"] - platformtools: ["", "", "arm-linux-gnueabi"] - emulator: ["", "", "qemu-arm"] + platformflags: [""] + platformtools: [""] + emulator: [""] include: - - platformflags: "" - name: "AMD64" - - platformflags: -m32 - name: "i386" + - name: i386 + platformflags: -m32 + - name: arm + platformtools: arm-linux-gnueabi + emulator: qemu-arm name: build-linux-gnu (${{matrix.name}}) env: PLATFORMFLAGS: ${{matrix.platformflags}} From 3fc91ae512506a33aa2fb85579e344f5278e14a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Mon, 12 Apr 2021 12:08:45 +0000 Subject: [PATCH 38/67] Update buildcommit.yml --- .github/workflows/buildcommit.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/buildcommit.yml b/.github/workflows/buildcommit.yml index 07871ba..6b080ea 100644 --- a/.github/workflows/buildcommit.yml +++ b/.github/workflows/buildcommit.yml @@ -21,7 +21,7 @@ jobs: platformtools: arm-linux-gnueabi emulator: qemu-arm - name: aarch64 - platformtools: aarch64-linux-gnue + platformtools: aarch64-linux-gnu emulator: qemu-aarch64 # name: build-linux-gnu (${{matrix.name}}) env: @@ -52,7 +52,6 @@ jobs: path: lib/${{ env.abiname }}/libstackman.a build-windows: - if: false runs-on: windows-2019 strategy: fail-fast: true From e607b7e402e5db7e174ade6eda439d5dd5340c9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Mon, 12 Apr 2021 11:44:41 +0000 Subject: [PATCH 39/67] don't include final hyphen in PLATFORM_PREFIX --- Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 1120222..6fea2f6 100644 --- a/Makefile +++ b/Makefile @@ -12,10 +12,10 @@ CXXFLAGS += $(NO_CET) OLDCC := $(CC) ifdef PLATFORM_PREFIX -CC = $(PLATFORM_PREFIX)gcc -CXX = $(PLATFORM_PREFIX)g++ -LD = $(PLATFORM_PREFIX)ld -AR = $(PLATFORM_PREFIX)ar +CC = $(PLATFORM_PREFIX)-gcc +CXX = $(PLATFORM_PREFIX)-g++ +LD = $(PLATFORM_PREFIX)-ld +AR = $(PLATFORM_PREFIX)-ar endif # run c preprocessor with any cflags to get cross compilation result, then run regular compile in native ABI := $(shell ./abiname.sh "$(CC)" "$(CFLAGS)") From ea143175b4e2f27d0ba286fe9b189368722793ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Mon, 12 Apr 2021 12:13:36 +0000 Subject: [PATCH 40/67] Update buildcommit.yml --- .github/workflows/buildcommit.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/buildcommit.yml b/.github/workflows/buildcommit.yml index 6b080ea..b3b6573 100644 --- a/.github/workflows/buildcommit.yml +++ b/.github/workflows/buildcommit.yml @@ -80,5 +80,5 @@ jobs: - name: Upload build artifacts uses: actions/upload-artifact@v2 with: - name: win-${{ matrix.platform }} - path: vs2019/${{matrix.folder}}/Debug/stackman.lib + name: win_${{ matrix.platform }} + path: lib/win_${{matrix.platform}}/stackman.lib From d77e9d559f6b08cad8870eaa311dfb81dce2951c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Mon, 12 Apr 2021 15:21:18 +0000 Subject: [PATCH 41/67] Move the abiname discovery stuff into "tools" --- Makefile | 4 ++-- {stackman => tools}/abiname.c | 0 abiname.sh => tools/abiname.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename {stackman => tools}/abiname.c (100%) rename abiname.sh => tools/abiname.sh (91%) mode change 100755 => 100644 diff --git a/Makefile b/Makefile index 6fea2f6..a7c1309 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ LD = $(PLATFORM_PREFIX)-ld AR = $(PLATFORM_PREFIX)-ar endif # run c preprocessor with any cflags to get cross compilation result, then run regular compile in native -ABI := $(shell ./abiname.sh "$(CC)" "$(CFLAGS)") +ABI := $(shell tools/abiname.sh "$(CC)" "$(CFLAGS)") ifndef ABI $(error Could not determine platform) endif @@ -46,7 +46,7 @@ lib: clean: rm -f stackman/*.o tests/*.o rm -f bin/* - rm -rf tmp + rm -rf tmp tools/tmp DEBUG = #-DDEBUG_DUMP diff --git a/stackman/abiname.c b/tools/abiname.c similarity index 100% rename from stackman/abiname.c rename to tools/abiname.c diff --git a/abiname.sh b/tools/abiname.sh old mode 100755 new mode 100644 similarity index 91% rename from abiname.sh rename to tools/abiname.sh index 390d9ae..e899f05 --- a/abiname.sh +++ b/tools/abiname.sh @@ -16,7 +16,7 @@ tmp=$(mktemp "${here}/tmp/abinameXXX.c") #1 create the preprocessed file CC=${1:-cc} CFLAGS=${2:-} -${CC} ${CFLAGS} -E -o "${tmp}" "${here}/stackman/abiname.c" +${CC} ${CFLAGS} -I${here}/../stackman -E -o "${tmp}" "${here}/abiname.c" #2 compile resulting file cc -o "${tmp}.out" "${tmp}" #3 run it From b1f01c2c0f2c1ad8620535e95bf29884aa42faa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Mon, 12 Apr 2021 12:25:44 +0000 Subject: [PATCH 42/67] Update buildcommit.yml --- .github/workflows/buildcommit.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.github/workflows/buildcommit.yml b/.github/workflows/buildcommit.yml index b3b6573..39520ac 100644 --- a/.github/workflows/buildcommit.yml +++ b/.github/workflows/buildcommit.yml @@ -82,3 +82,20 @@ jobs: with: name: win_${{ matrix.platform }} path: lib/win_${{matrix.platform}}/stackman.lib + + commit-artifacts: + runs-on: ubuntu-latest + needs: [build-linux-gnu, build-windows] + steps: + - uses: actions/checkout@v2 + - uses: actions/download-artifact@v2 + with: + path: lib + + - name: Commit changes + run: | + git config --global user.name 'Automation tool' + git config --global user.email 'automation-tool@users.noreply.github.com' + git add lib/*.a lib/*.lib + git diff-index --quiet HEAD || git commit -m "Automated build" + From bde6ceb4e9bcb2ea2b38ac97ed984c1cfba0575a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Mon, 12 Apr 2021 15:21:54 +0000 Subject: [PATCH 43/67] A tool to strip timestamps from windows .lib files --- tools/strip-lib.py | 266 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 266 insertions(+) create mode 100644 tools/strip-lib.py diff --git a/tools/strip-lib.py b/tools/strip-lib.py new file mode 100644 index 0000000..8d8ee6f --- /dev/null +++ b/tools/strip-lib.py @@ -0,0 +1,266 @@ +# nulls the timestamp filed in a windows .lib archive, +# making the lib reproducable. +# the time is the TimeDateStamp in the COFF file header, four bytes at offset 4 +# See https://blog.conan.io/2019/09/02/Deterministic-builds-with-C-C++.html +# also: https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#archive-library-file-format + +import sys +import struct + +libheader = b"!\n" + +def main(): + infilename = sys.argv[1] + if len(sys.argv) > 2: + outfilename = sys.argv[2] + else: + outfilename = infilename + + with open(infilename, "rb") as fp: + lib = read_lib(fp, True) + strip_lib_timestamp(lib) + with open(outfilename, "wb") as fp: + write_lib(fp, lib) + + +def read_lib(fp, verbose=False): + """ + read microsoft .lib file, + """ + # lib file header + h = fp.read(len(libheader)) + assert h == libheader + + # read first and second link members + h1 = header_read(fp) + p = fp.tell() + if verbose: + print("header", h1) + m1 = first_lm_read(fp) + assert fp.tell() - p == h1["size"] + if verbose: + print("first linker member", m1) + + h2 = header_read(fp) + if verbose: + print("header", h2) + p = fp.tell() + m2 = second_lm_read(fp) + assert fp.tell() - p == h2["size"] + if verbose: + print("second linker member", m2) + + result = { + "h1": h1, + "m1": m1, + "h2": h2, + "m2": m2, + "hl": None, + "longnames": [], + "ho": [], + "o": [], + } + + # now we might have an optional longnames member + h = header_read(fp) + if not h: + return result + + if h['name'] == "//": + result["hl"] = h + p = fp.tell() + while fp.tell() < p + h["size"]: + result["longnames"].append(readcstr(fp)) + h = None + if verbose: + print('header', h) + print('longnames', result['longnames']) + + # now read the headers, possibly we alread read one above. + while True: + if h is None: + h = header_read(fp) + if h is None: + return result + + result["ho"].append(h) + result["o"].append(fp.read(h['size'])) + if verbose: + print("header:", result['ho'][-1]) + print("coff:", len(result['o'][-1])) + h = None + + return result + + +def write_lib(fp, lib): + fp.write(libheader) + header_write(fp, lib["h1"]) + first_lm_write(fp, lib["m1"]) + header_write(fp, lib["h2"]) + second_lm_write(fp, lib["m2"]) + + if lib["hl"]: + header_write(fp, lib["hl"]) + for s in lib["longnames"]: + writecstr(fp, s) + + for h, c in zip(lib["ho"], lib["o"]): + header_write(fp, h) + fp.write(c) + +def strip_lib_timestamp(lib): + def fix_header(h): + h['date'] = "-1" + fix_header(lib['h1']) + fix_header(lib['h2']) + if lib['hl']: + fix_header(lib['hl']) + for h in lib['ho']: + fix_header(h) + lib['o'] = [strip_coff_timestamp(c) for c in lib['o']] + + +def header_read(fp): + """ + read a header entry from a microsoft archive + """ + + #header can start with optional newline + optnl = read_optional_nl(fp) + + name = fp.read(16) + if len(name) < 16: + return None # eof + name = name.decode("ascii").strip() + date = fp.read(12).decode("ascii").strip() + uid = fp.read(6).decode("ascii").strip() + gid = fp.read(6).decode("ascii").strip() + mode = fp.read(8).decode("ascii").strip() + size = fp.read(10).decode("ascii").strip() + size = eval(size) + eoh = fp.read(2) + assert eoh == b"\x60\x0a" + return { + "optnl": optnl, + "name": name, + "date": date, + "uid": uid, + "gid": gid, + "mode": mode, + "size": size, + } + + +def header_write(fp, h): + def writestr(s, n): + """helper to write space padded string of fixed length""" + e = s.encode("ascii") + b" " * n + fp.write(e[:n]) + + if h["optnl"]: + fp.write(h['optnl']) + writestr(h["name"], 16) + writestr(h["date"], 12) + writestr(h["uid"], 6) + writestr(h["gid"], 6) + writestr(h["mode"], 8) + writestr(str(h["size"]), 10) + fp.write(b"\x60\x0a") + + +def first_lm_read(fp): + nos = fp.read(4) + nos = struct.unpack(">L", nos)[0] # unsigned long, big-endian + + offsets = [] + strings = [] + for i in range(nos): + offset = fp.read(4) + offsets.append(struct.unpack(">L", offset)[0]) + for i in range(nos): + strings.append(readcstr(fp)) + return {"offsets": offsets, "strings": strings} + # sometimes there is an extra \0a after the strings + p = peek(fp) + return zip(offsets, strings) + + +def first_lm_write(fp, lm): + nos = len(lm["offsets"]) + fp.write(struct.pack(">L", nos)) + for o in lm["offsets"]: + fp.write(struct.pack(">L", o)) + for s in lm["strings"]: + writecstr(fp, s) + + +def second_lm_read(fp): + # number of members + m = struct.unpack(" Date: Mon, 12 Apr 2021 15:24:02 +0000 Subject: [PATCH 44/67] Ad vscode devcontainer config --- .devcontainer/Dockerfile | 11 +++++++++++ .devcontainer/devcontainer.json | 29 +++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..067d9a2 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,11 @@ +# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.166.1/containers/ubuntu/.devcontainer/base.Dockerfile + +# [Choice] Ubuntu version: bionic, focal +ARG VARIANT="focal" +FROM mcr.microsoft.com/vscode/devcontainers/base:0-${VARIANT} + +# [Optional] Uncomment this section to install additional OS packages. +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install --no-install-recommends build-essential + + diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..3521ef9 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,29 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: +// https://github.com/microsoft/vscode-dev-containers/tree/v0.166.1/containers/ubuntu +{ + "name": "Ubuntu", + "build": { + "dockerfile": "Dockerfile", + // Update 'VARIANT' to pick an Ubuntu version: focal, bionic + "args": { "VARIANT": "focal" } + }, + + // Set *default* container specific settings.json values on container create. + "settings": { + "terminal.integrated.shell.linux": "/bin/bash" + }, + + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "ms-vscode.cpptools" + ], + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "uname -a", + + // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. + "remoteUser": "vscode" +} \ No newline at end of file From 627c5f5ed61777ba39ef45b5ef4612adeba574bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Mon, 12 Apr 2021 15:28:27 +0000 Subject: [PATCH 45/67] update build step to strip timestamps from libs --- .github/workflows/buildcommit.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/buildcommit.yml b/.github/workflows/buildcommit.yml index 39520ac..9bde293 100644 --- a/.github/workflows/buildcommit.yml +++ b/.github/workflows/buildcommit.yml @@ -74,6 +74,10 @@ jobs: - uses: microsoft/setup-msbuild@v1.0.2 - name: build run: msbuild.exe vs2019\stackman.sln /p:Platform=${{matrix.platform}} + - name: strip timestamps from lib + run: python tools/strip-lib.py lib/win_${{matrix.platform}}/stackman.lib + - name: rebuild after stripping + run: msbuild.exe vs2019\stackman.sln /p:Platform=${{matrix.platform}} - name: test if: ${{ matrix.native == 'yes' }} run: vs2019\${{matrix.folder}}\Debug\test.exe From a4f499669f94bba54d88652a9b202c9a06fafb4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Mon, 12 Apr 2021 15:37:29 +0000 Subject: [PATCH 46/67] invoke shell on abiname.sh --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index a7c1309..20518c2 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ LD = $(PLATFORM_PREFIX)-ld AR = $(PLATFORM_PREFIX)-ar endif # run c preprocessor with any cflags to get cross compilation result, then run regular compile in native -ABI := $(shell tools/abiname.sh "$(CC)" "$(CFLAGS)") +ABI := $(shell sh tools/abiname.sh "$(CC)" "$(CFLAGS)") ifndef ABI $(error Could not determine platform) endif From d82671354e35060d3efebbd3aff1dc2bdc0431ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Mon, 12 Apr 2021 15:53:26 +0000 Subject: [PATCH 47/67] fix fix fix update workflows. Delete old 'test' and commit only on commit to main --- .github/workflows/buildcommit.yml | 8 ++-- .github/workflows/test.yml | 79 ------------------------------- 2 files changed, 5 insertions(+), 82 deletions(-) delete mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/buildcommit.yml b/.github/workflows/buildcommit.yml index 9bde293..6bef733 100644 --- a/.github/workflows/buildcommit.yml +++ b/.github/workflows/buildcommit.yml @@ -1,10 +1,11 @@ -name: build and commit +name: build test and commit on: push: branches: [ master, dev ] - workflow_dispatch: + pull_request: + branches: [ master ] jobs: @@ -90,6 +91,7 @@ jobs: commit-artifacts: runs-on: ubuntu-latest needs: [build-linux-gnu, build-windows] + if: ${{ github.event_name == 'push' }} steps: - uses: actions/checkout@v2 - uses: actions/download-artifact@v2 @@ -102,4 +104,4 @@ jobs: git config --global user.email 'automation-tool@users.noreply.github.com' git add lib/*.a lib/*.lib git diff-index --quiet HEAD || git commit -m "Automated build" - + git push diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 2086164..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,79 +0,0 @@ -name: C/C++ CI - -on: - push: - branches: [ master, dev ] - pull_request: - branches: [ master ] - -jobs: - - test-linux-x86: - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - include: - - platformflags: "" - name: "AMD64" - - platformflags: -m32 - name: "i386" - name: test-linux-x86 (${{matrix.name}}) - env: - PLATFORMFLAGS: ${{matrix.platformflags}} - steps: - - uses: actions/checkout@v2 - - name: install multilib - run: sudo apt-get install --no-install-recommends -y gcc-multilib g++-multilib - if: ${{ matrix.name == 'i386' }} - - name: make - run: make && make test - - test-linux-arm: - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - include: - - arch: arm - emulator: qemu-arm - abi: arm-linux-gnueabi - - arch: aarch64 - emulator: qemu-aarch64 - abi: aarch64-linux-gnu - name: test-linux-arm (${{matrix.arch}}) - env: - PLATFORM_PREFIX: ${{matrix.abi}}- - EMULATOR: ${{matrix.emulator}} - steps: - - uses: actions/checkout@v2 - - name: install qemu - run: sudo apt-get install --no-install-recommends -y qemu-user - - name: install abi lib - run: sudo apt-get install --no-install-recommends -y gcc-${{matrix.abi}} g++-${{matrix.abi}} - - name: make - run: make && make test - - test-windows: - runs-on: windows-2019 - strategy: - fail-fast: false - matrix: - platform: [x86, x64, ARM, ARM64] - include: - - platform: x86 - folder: Win32 - native: yes - - platform: x64 - folder: x64 - native: yes - steps: - - uses: actions/checkout@v2 - - name: Add msbuild to PATH - uses: microsoft/setup-msbuild@v1.0.2 - - name: build - run: msbuild.exe vs2019\stackman.sln /p:Platform=${{matrix.platform}} - - name: test - if: ${{ matrix.native == 'yes' }} - run: vs2019\${{matrix.folder}}\Debug\test.exe - From b418d13a9bba850ae531457c71948a11d73aa0b0 Mon Sep 17 00:00:00 2001 From: Automation tool Date: Mon, 12 Apr 2021 15:55:15 +0000 Subject: [PATCH 48/67] Automated build --- lib/win_arm/stackman.lib | Bin 3002 -> 3110 bytes lib/win_arm64/stackman.lib | Bin 6178 -> 6338 bytes lib/win_x64/stackman.lib | Bin 5082 -> 5216 bytes lib/win_x86/stackman.lib | Bin 10042 -> 10160 bytes 4 files changed, 0 insertions(+), 0 deletions(-) diff --git a/lib/win_arm/stackman.lib b/lib/win_arm/stackman.lib index 1fd6413ba3a58e068a86ae32053bcebecd95f872..0e1d687de8cb0213acb9999eb370390c8ce5d3a0 100644 GIT binary patch delta 883 zcmZ`%O=uHA6n?Wm`D-i*rfE{e#DowuxJ_v+*_uLs(r8K5s0DM_gX?az!6Z$S4aJjK z5Cj!k=8~g7sFy;~;zhJxJP3O5T14^SL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~KH>T)9_ zXEOO{z+cl|Y`wzKo|gLtx_c4>ioa$%;A=6z!_hcE2u*zsBRw~;>% zbv5(`|9WxkdEb#Q^pn=5Nv4TIscz!%HfJaE;YH^tH!Wg^YecGz)kRBG6!KJ@HsPPH z7Iq2Oxr3%CQSJo8r(!_#Q?1*0(!F7R+UY2mG2rq1n|7G=luH&Oj($!49|>v+)@25w zp-_Szx^l()N8F_Ny9sgaOj(fq7vwd##k*)0vP8ipM8QN->r+0L6RE<H zn|M%wH!3x+EuyZY7a;gL)&5>JsesO8L86Nc0v&@$Y9i&BC@r8BH%rw;j#x_^!H=Z) z`+4E~Cog93&SGEKOeLS?j;``fY~bCGCd?0iKHud!>)NzsO1`XSsfWDGp~WToXZdi@ Lw~$5gYhUaQ714Sr diff --git a/lib/win_x64/stackman.lib b/lib/win_x64/stackman.lib index 6422336802506c79b8f5d113e7c0248ee403e6df..881bad84be7a5653437904f9be68f236b35ff62e 100644 GIT binary patch delta 1209 zcmZ`&ZAep57=F*)u5EXl?QVW8^CMm9mb-0W;=(MlqOxeEM8!p#bCl)gns+w(QiB;$ zl<`9JqY$GX{RpIjpkGEr5cQ*eR2T*I$EZM>RKE&(@AVp{cJ9aXoafwg&U4=Py>F{N zR1e*?-m(I40Kn+F94fo~{)WH4wys=j2ZWA66O93Q%>YFj1CW$xT5-qXdKbJn%39cI zG;me?aaw8+S8Cbm%j8})x-A6F*IJirnIK=1T|V8v0ckZ+(xCh-~P;df-7Du#RC zxnhQP<6-8-6Gor=lDfynHF8+)QNocUv2c7o!H33HW6)n4z#@Ky^IWvDV5LOco5_$;F-uuCS zVy@o|pc$A*%D)aVVOx$)lZP8uu+g-v;5DojA#$u^-d8R>YYGaR;z~4`NOtx_(Qhv_ z1OtAYFfCuCAD0eShBfBZjKg-bWK*3}9JLb|@w&OFPXu1GKw>=A)s;|^l+7IK!8>~L z>9N2Eoe6M~Oc!Wczs>}BWCU<(+7q1#Fh$IvX+L!)fR8rL)3kuj1lYWfXrU%<)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~D= z}Bf5 z2(Rp6b`J*&&yCpBH*A@^!+XqoaCL-zp`u1#xjg*v?x8!oy7g(116y(Ld?3ahr^m~W zjZQ}#XBVq&1J^eL{4U0&8C5g6UhIAgAPbGFC__ur z`mG-h4(-1`V0y}*oCDA*#>Z1nG>%?@JWoZa_dDo01#nV~+mDo0MKjcAKiScBP3BM6 z0Q@G#_w`>r-Boz<-i5-ZW2?`|w(#gwLMBu?M%eCOkd#!1)NZvcC%01@Vqze*HYSSI zl`-+Ax+*3vs-5$M#+IdAXFIpk+tCqvS8b2gMKtkl+clN>vyIyMc3)tZ%kQ;p`=4{Q zfIO{TrJd>F4um+jFTf)=?<76yH8VBAZLR?C;aXflJ{0tj_qFQ^&A2W4@hubxIb4e? zCEScF7DB>i!hcE#N3=SYHq1;DcaNqflR>7F<46j`T}z~Net@F1B$ECE{cCaLK*m7{ zZK#c8X3-SQZ;oW^r>NNbrWp#7bAi#}=#QO91-u-K5m)Mb(!eZy;&|5K@#I>(9bAns z7}{dDabZMxy@e0+5S`45k7%)Q_`{3m(Jf?g!&G##Z0?K{yF~8yv*_J>*$4w72eAmpFd`FEZjLiLnE?_V z0}C*aiCBopLYNTI$-QRnw{?<~+o62sqfyxL&Bo_WEIRdP^?UNWLl26Kn<|B+5z1p1 bRDZ5hDcmyn?GOrnKGcNHTTf|7V_x&Wmjt{j From d965c83d7b19e825d39d4b2914a2a7888eaabe49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Mon, 12 Apr 2021 15:59:52 +0000 Subject: [PATCH 49/67] update status badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1ff9766..713339c 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://travis-ci.org/kristjanvalur/stackman.svg?branch=master)](https://travis-ci.org/kristjanvalur/stackman) +[![build test and commit](https://github.com/kristjanvalur/stackman/actions/workflows/buildcommit.yml/badge.svg)](https://github.com/kristjanvalur/stackman/actions/workflows/buildcommit.yml) # stackman Simple low-level stack manipulation API and implementation for common platforms From bc6dd501222e7afe96f9c373115d48f2b8f40de3 Mon Sep 17 00:00:00 2001 From: Automation tool Date: Mon, 12 Apr 2021 16:02:19 +0000 Subject: [PATCH 50/67] Automated build --- lib/win_arm64/stackman.lib | Bin 6338 -> 6338 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/lib/win_arm64/stackman.lib b/lib/win_arm64/stackman.lib index 96c356e7aeb06cd295311988a1e20aede83f815d..47c1c3e4eb6e98de9d48e2dbeb4250adbb650b39 100644 GIT binary patch delta 16 YcmX?Pc*t;M1& delta 16 YcmX?Pc*t Date: Mon, 12 Apr 2021 17:15:19 +0000 Subject: [PATCH 51/67] Add features to the windows lib stripper. --- tools/strip-lib.py | 107 +++++++++++++++++++++++++++++++++------------ 1 file changed, 79 insertions(+), 28 deletions(-) diff --git a/tools/strip-lib.py b/tools/strip-lib.py index 8d8ee6f..a64aa97 100644 --- a/tools/strip-lib.py +++ b/tools/strip-lib.py @@ -3,12 +3,18 @@ # the time is the TimeDateStamp in the COFF file header, four bytes at offset 4 # See https://blog.conan.io/2019/09/02/Deterministic-builds-with-C-C++.html # also: https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#archive-library-file-format +# +# There are some additional fixes added for reproducability, such as fixing the zero-padding of names in the coff +# section headers. import sys import struct +verbose = True + libheader = b"!\n" + def main(): infilename = sys.argv[1] if len(sys.argv) > 2: @@ -17,13 +23,13 @@ def main(): outfilename = infilename with open(infilename, "rb") as fp: - lib = read_lib(fp, True) + lib = read_lib(fp) strip_lib_timestamp(lib) with open(outfilename, "wb") as fp: write_lib(fp, lib) -def read_lib(fp, verbose=False): +def read_lib(fp): """ read microsoft .lib file, """ @@ -40,7 +46,7 @@ def read_lib(fp, verbose=False): assert fp.tell() - p == h1["size"] if verbose: print("first linker member", m1) - + h2 = header_read(fp) if verbose: print("header", h2) @@ -66,15 +72,15 @@ def read_lib(fp, verbose=False): if not h: return result - if h['name'] == "//": + if h["name"] == "//": result["hl"] = h p = fp.tell() while fp.tell() < p + h["size"]: result["longnames"].append(readcstr(fp)) - h = None if verbose: - print('header', h) - print('longnames', result['longnames']) + print("header", h) + print("longnames", result["longnames"]) + h = None # now read the headers, possibly we alread read one above. while True: @@ -84,10 +90,10 @@ def read_lib(fp, verbose=False): return result result["ho"].append(h) - result["o"].append(fp.read(h['size'])) + result["o"].append(fp.read(h["size"])) if verbose: - print("header:", result['ho'][-1]) - print("coff:", len(result['o'][-1])) + print("header:", result["ho"][-1]) + print("coff length:", len(result["o"][-1])) h = None return result @@ -109,16 +115,19 @@ def write_lib(fp, lib): header_write(fp, h) fp.write(c) + def strip_lib_timestamp(lib): def fix_header(h): - h['date'] = "-1" - fix_header(lib['h1']) - fix_header(lib['h2']) - if lib['hl']: - fix_header(lib['hl']) - for h in lib['ho']: + h["date"] = "-1" + + fix_header(lib["h1"]) + fix_header(lib["h2"]) + if lib["hl"]: + fix_header(lib["hl"]) + for h in lib["ho"]: fix_header(h) - lib['o'] = [strip_coff_timestamp(c) for c in lib['o']] + lib["o"] = [strip_coff_timestamp(c) for c in lib["o"]] + lib["o"] = [fix_coff_null_padding(c) for c in lib["o"]] def header_read(fp): @@ -126,7 +135,7 @@ def header_read(fp): read a header entry from a microsoft archive """ - #header can start with optional newline + # header can start with optional newline optnl = read_optional_nl(fp) name = fp.read(16) @@ -159,7 +168,7 @@ def writestr(s, n): fp.write(e[:n]) if h["optnl"]: - fp.write(h['optnl']) + fp.write(h["optnl"]) writestr(h["name"], 16) writestr(h["date"], 12) writestr(h["uid"], 6) @@ -193,7 +202,7 @@ def first_lm_write(fp, lm): fp.write(struct.pack(">L", o)) for s in lm["strings"]: writecstr(fp, s) - + def second_lm_read(fp): # number of members @@ -210,7 +219,7 @@ def second_lm_read(fp): strings = [] for i in range(n): strings.append(readcstr(fp)) - + return {"offsets": offsets, "indices": indices, "strings": strings} @@ -225,7 +234,7 @@ def second_lm_write(fp, lm): fp.write(struct.pack("= 0: + # everything after first null is null + shortname = name[:i] + namenew = (shortname + b"\0" * 8)[:8] + if name != namenew: + sections[n] = namenew + s[8:] + modified = True + if verbose: + print( + "Fixed null padding of COFF section header name %r" % shortname + ) + if modified: + start = header + b"".join(sections) + coff = start + coff[len(start) :] + return coff +if __name__ == "__main__": + main() From 689c45c576e619052feb796ddbb058201063f40e Mon Sep 17 00:00:00 2001 From: Automation tool Date: Mon, 12 Apr 2021 17:18:47 +0000 Subject: [PATCH 52/67] Automated build --- lib/win_arm/stackman.lib | Bin 3110 -> 3110 bytes lib/win_arm64/stackman.lib | Bin 6338 -> 6338 bytes 2 files changed, 0 insertions(+), 0 deletions(-) diff --git a/lib/win_arm/stackman.lib b/lib/win_arm/stackman.lib index 0e1d687de8cb0213acb9999eb370390c8ce5d3a0..0713cfacf44ab54df4467e41af1908ce65542f9d 100644 GIT binary patch delta 17 XcmZ1`u}osaB1RSlAlST&v4IN!FMtHN delta 17 YcmZ1`u}osaB1V>Q&j{Pi%NQHD0647$?EnA( diff --git a/lib/win_arm64/stackman.lib b/lib/win_arm64/stackman.lib index 47c1c3e4eb6e98de9d48e2dbeb4250adbb650b39..96c356e7aeb06cd295311988a1e20aede83f815d 100644 GIT binary patch delta 16 YcmX?Pc*t;M1& From fe3e2c6f8b8c061f5bc6837932f1a87f421882e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Mon, 12 Apr 2021 17:23:03 +0000 Subject: [PATCH 53/67] more info for git commit --- .github/workflows/buildcommit.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/buildcommit.yml b/.github/workflows/buildcommit.yml index 6bef733..cfc7faf 100644 --- a/.github/workflows/buildcommit.yml +++ b/.github/workflows/buildcommit.yml @@ -103,5 +103,6 @@ jobs: git config --global user.name 'Automation tool' git config --global user.email 'automation-tool@users.noreply.github.com' git add lib/*.a lib/*.lib + git status git diff-index --quiet HEAD || git commit -m "Automated build" git push From 63bb64b37d7720230e6579e3a266e62a1f66fe31 Mon Sep 17 00:00:00 2001 From: Anselm Kruis Date: Tue, 22 Jun 2021 23:23:08 +0200 Subject: [PATCH 54/67] Fix a typo in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 30c1706..e63d8ad 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ Other platforms can be easily adapted from both existing implementations for oth projects as well as from example code provided. ### Intel CET -Intel's Conontrol-Flow Enforcement Technology is incompatible with stack switching +Intel's Control-Flow Enforcement Technology is incompatible with stack switching because it imploys a secondary Shadow Stack, that the user-mode program cannot modify. Unexpected return flow after a stack switch would cause the processor to fault. Because of this, we need to mark any assembly code as not CET compatible. Modern compilers are beginning to generate CET compatible objects and From c572d4d07cc8507bc5a519dbab6e461f718547d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Mon, 12 Apr 2021 10:29:19 +0000 Subject: [PATCH 55/67] makefile can echo the abiname (cherry picked from commit cf5d06e270d99873027b9cb3b91fdfde07a9c6cc) --- Makefile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index d688059..1120222 100644 --- a/Makefile +++ b/Makefile @@ -21,18 +21,22 @@ endif ABI := $(shell ./abiname.sh "$(CC)" "$(CFLAGS)") ifndef ABI $(error Could not determine platform) -else -$(info ABI is $(ABI)) endif LIB := lib/$(ABI) all: $(LIB)/libstackman.a +# echo the abiname, for build tools. +.PHONY: abiname +abiname: + @echo $(ABI) + obj = stackman/stackman.o stackman/stackman_s.o $(LIB)/libstackman.a: lib $(obj) + $(info ABI is $(ABI)) $(AR) $(ARFLAGS) -s $@ $(obj) .PHONY: lib clean From 4606e73300507fb01ae8d468ba1981fc4487d01f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Sun, 25 Jul 2021 17:48:44 +0000 Subject: [PATCH 56/67] Fix readme --- README.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a7699a0..4ab8b04 100644 --- a/README.md +++ b/README.md @@ -168,11 +168,15 @@ platforms may need to be done independently. - *make* using `make PLATFORM_PREFIX=aarch64-linux-gnu- EMULATOR=qemu-aarch64 test` ## A note about Intel CET -Intel's Conontrol-Flow Enforcement Technology is incompatible with stack switching -because it imploys a secondary Shadow Stack, that the user-mode program cannot +Intel's *Control-Flow Enforcement Technology* is incompatible with stack switching +because it employs a secondary *Shadow Stack*, that the user-mode program cannot modify. Unexpected return flow after a stack switch would cause the processor -to fault. Because of this, we need to mark any assembly code as not CET compatible. Modern compilers are beginning to generate CET compatible objects and -once supporting CPUs start to arrive, processes which consist entirely of CET compatible code may be run in such a protected environment. See https://software.intel.com/content/www/us/en/develop/articles/technical-look-control-flow-enforcement-technology.html for more information +to fault. Because of this, we need to mark any assembly code as **not CET compatible** by +adding special compiler flags to supporting compilers (currently modern GNU C). +Modern compilers are beginning to generate CET compatible objects and +once supporting CPUs start to arrive, processes which consist entirely of CET compatible +code may be run in such a protected environment. +See https://software.intel.com/content/www/us/en/develop/articles/technical-look-control-flow-enforcement-technology.html for more information ## History This works was originally inspired by *Stackless Python* by [Christian Tismer](https://github.com/ctismer), where the original switching code was From fa40e7ec7cda3ad0b2d78557368f712dbd89fd64 Mon Sep 17 00:00:00 2001 From: Automation tool Date: Sun, 25 Jul 2021 17:50:53 +0000 Subject: [PATCH 57/67] Automated build --- lib/win_arm/stackman.lib | Bin 3110 -> 3978 bytes lib/win_arm64/stackman.lib | Bin 6338 -> 8066 bytes lib/win_x64/stackman.lib | Bin 5216 -> 6118 bytes lib/win_x86/stackman.lib | Bin 10160 -> 11040 bytes 4 files changed, 0 insertions(+), 0 deletions(-) diff --git a/lib/win_arm/stackman.lib b/lib/win_arm/stackman.lib index 0713cfacf44ab54df4467e41af1908ce65542f9d..2b515b5ef4c3f3470456d7528f02ee271b48bd20 100644 GIT binary patch delta 655 zcmZ1`(Ivm(2otL;Ls%)}jZX7J!1m{WAn*%Y&MK$li#z-N#RccfsmkkkX^m3SCFfBMM8 z2(fCiKZl_bOhaNxPHtK<4t*|@eK^IDY_jFDlPXOvDp6wi_zBb9lY!EFrMW0}1BHZ& zGZKqZQ_zH6L>RcB?m>1dP`yZUK>;wlfVQAYs7)5(mYST*DLL7e%}NyJewc?r9{e=< zKZoz+3^sl~m@LG1lOs4)fSR;{zA@)!`1BDL=96Q&_E%`#GF9P1;o>UKIaC~lN-6RC-ZSDF@BzGz%60G0~Gr7u}M|* ygg3L`%c?f^{o%STi@D$KJnncoB?A=2AmEUkpIe}pnG#kyxq`a{l&0QsTL1tTjk;0* delta 374 zcmeB@Una5P2otLe!_5+g$tRg~nQoSB{=pQ+C}wDBX{G=M30y}QSr|Y-gne=fOBPcK z>*Nb8T1;QqCjVhszzf#OAj|+UVkN6BBiH2TtP|KR^o%Sm4GkvOvDq-XO@7a+J9z>V z4_`@Qa&~TFo?byp62qsDlRvTj;9z286$6<*S&l<{ax-@@T;~QJmC3ejR#H%tViHSo za?_GyGV_viN>fsm7(V`*{F>W$ax16!uF|de%e8wWcz`zQ`Y(UHo#9Bb@96)+7KkkD26+es9Fp^M U3-mHmZk9~G!&d?dx*&cF09GSpg#Z8m diff --git a/lib/win_arm64/stackman.lib b/lib/win_arm64/stackman.lib index 96c356e7aeb06cd295311988a1e20aede83f815d..68c06e032ad94c4fc53776b089e24794a9b111ee 100644 GIT binary patch delta 1464 zcmbW0T}V@57{}kU?QA<|=WKIxn_22wX{60&i<&cX!!Il|i(FCzTic4+w$|E8kP5;s z@*)-wK_3(pT|^h9cvT?T$3;+Rgm}?~8B|agN7H z;D}5Q4T>{p`%H0{%7-4Mn;L>4rB(a0=kcv!Y3I0bb~Tx#1|^J%QdC#kZ8rNxFtaww z3Fn#OqHt)x_joAU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)>N~a+;rW;X{ z*kR{&2PrsMv~FWlTmAPA{zVA0v)xX2a!+IPrc1z;6sMQE|Xx(krvw9m#)prq0DI znyi6VlBX^1z#v$qlPn!gWaq8e|)?6r;o{b z=PsU>{sDMHH@Zt4?sHGiJ$2o-;4hYGm~qwP@#49x9G@5ei9;p#n3dd#V5g?wWB*#g zoUxe8s2ao5ei_%OifI_`(GvNYiP*0pvvTNvjZGq=7ZTS!Jj2|jK_OhCqnA z8H7^8ClI`4v}2z;h)-Qs?2R?zeb0DIkCX84n2TZ$c7LJQsla&!&`7Ei0)!wTOn5!A zJyLvc0q1<)+cV?g?4|lwOO~C9UwbvL$8%`bqmFCFdg_^9wJX=PuCHuaHQ0`P{JQz{ IZpWAX2d^Cewg3PC From ebfb17b318292f3ceb9a89f0cf60fced87b724b6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 3 Sep 2024 21:04:38 +0000 Subject: [PATCH 58/67] Bump actions/download-artifact from 2 to 4.1.7 in /.github/workflows Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 2 to 4.1.7. - [Release notes](https://github.com/actions/download-artifact/releases) - [Commits](https://github.com/actions/download-artifact/compare/v2...v4.1.7) --- updated-dependencies: - dependency-name: actions/download-artifact dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- .github/workflows/buildcommit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/buildcommit.yml b/.github/workflows/buildcommit.yml index cfc7faf..06e53bb 100644 --- a/.github/workflows/buildcommit.yml +++ b/.github/workflows/buildcommit.yml @@ -94,7 +94,7 @@ jobs: if: ${{ github.event_name == 'push' }} steps: - uses: actions/checkout@v2 - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v4.1.7 with: path: lib From c59a1f07fc423cac707bae2bb27ff11030e5827b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Thu, 5 Sep 2024 10:44:29 +0000 Subject: [PATCH 59/67] Update buildcommit.yml use @v4 for upload/download artifacts --- .github/workflows/buildcommit.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/buildcommit.yml b/.github/workflows/buildcommit.yml index 06e53bb..7834d97 100644 --- a/.github/workflows/buildcommit.yml +++ b/.github/workflows/buildcommit.yml @@ -47,7 +47,7 @@ jobs: - name: set abi name run: echo abiname=$(make abiname) >> $GITHUB_ENV - name: Upload build artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: ${{ env.abiname }} path: lib/${{ env.abiname }}/libstackman.a @@ -83,7 +83,7 @@ jobs: if: ${{ matrix.native == 'yes' }} run: vs2019\${{matrix.folder}}\Debug\test.exe - name: Upload build artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: win_${{ matrix.platform }} path: lib/win_${{matrix.platform}}/stackman.lib @@ -94,7 +94,7 @@ jobs: if: ${{ github.event_name == 'push' }} steps: - uses: actions/checkout@v2 - - uses: actions/download-artifact@v4.1.7 + - uses: actions/download-artifact@v4 with: path: lib From 7ce4a674d541433e9ea357ca06a225cda5dcaef7 Mon Sep 17 00:00:00 2001 From: Automation tool Date: Thu, 5 Sep 2024 10:46:48 +0000 Subject: [PATCH 60/67] Automated build --- lib/aarch64/libstackman.a | Bin 3990 -> 4318 bytes lib/arm32/libstackman.a | Bin 2774 -> 2774 bytes lib/sysv_amd64/libstackman.a | Bin 3854 -> 3926 bytes lib/sysv_i386/libstackman.a | Bin 2790 -> 2838 bytes lib/win_arm/stackman.lib | Bin 3978 -> 3938 bytes lib/win_arm64/stackman.lib | Bin 8066 -> 7998 bytes lib/win_x64/stackman.lib | Bin 6118 -> 6090 bytes lib/win_x86/stackman.lib | Bin 11040 -> 11074 bytes 8 files changed, 0 insertions(+), 0 deletions(-) diff --git a/lib/aarch64/libstackman.a b/lib/aarch64/libstackman.a index a2316bd9d5f35c8a4aec2547e6848b4b9d240317..c30dcd0259965b9601e523027e70c6044d69eeb4 100644 GIT binary patch delta 896 zcmZva-D(p-6vt;~Ke|bq#x__(MK|k5P1S66<4TJKlah;y1r?-tBcy4vlwiArCX0fg zh=LdKBH@U>Kz)Kff|t4S1@yuj-=SW3W_CtG=z-nyKfnF&nK{FJv41+lhi1A$NV+n5 z@>mN34=$&?o0dWTM@^_2StJW&6}3UA#S!JNOQX}Pntjm*hi+{82n=Egmrm*Fe1=er z#EZga{1+Y!byhT>TaR`Mb$_kk`)&Z==wL36dY%0!Y!^CFAIj`{uGeq2UK}=~vJ!5K z^QtO|5^jr-t$O`lp}4abNBvmzbiI-vi_(8nskmOSDlxoczhJ24pge29D=kmw;Rm}w zGceMew_-xEQ9?|y<>Zx-n&IYC6MS)kr%_*%_0klVC0U-}YAueOgs1U@k_EoPhHh_O znXvQr>#|;%;?HI6P4N(3&IRyMzq4`_9yHx{xEJp?4mwdtr0(^Pl;jx3dIN44ziA0( z&9#NDmh>CSwpn;;mgyn9H>(ujyICy}J^7SZ4$L$7sM!>6Bcpioxzvet-i2+$ZZ@#u zEozdgl$U)UNRY+M&waXY7a6}#YH*Yy{>Xd`gBja-jn!GMPaI-&g=>K7EZ1M@y3Jk2 tXYS&Yup+~>1j|H~4o zT^y0P1qbjvvL0iJR;KQ`IOar(QW2lHB zH292?%m#1>Y=pT3Q^96VpC)7ov`?iMXdKKyDfug^T+50 zru=Doj01l7Z$ot+51TN)Y<{e!9 diff --git a/lib/arm32/libstackman.a b/lib/arm32/libstackman.a index ce4199d5e791616603e51ac93b275c510600e043..426030f1261033db9afd5265a6304f3469b6467e 100644 GIT binary patch delta 213 zcmca6dQEh~J#kG21_o9JMiwB&z^Di$WO;$ayop~X@woeiDmWXOD;OH;nM~fwSU9?gmfdOPL z6DI?M5R?{!(o!HAs7P^hGjlQ{qweJAEZ&TXlZ{!`8QUjEv-&g6pS+q?opldT*`dkT jS(RDq7#SFJCjVzuW?IEKxq(S+vK5;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~8A^r#Yj)=FvQ{Ea23?$G<`)H}Vf|)Nb(r diff --git a/lib/sysv_i386/libstackman.a b/lib/sysv_i386/libstackman.a index d5e977120323b9c8dc373f67db9902697b342880..1d91d87d0631057b92a0d6d3acae7e872c27a291 100644 GIT binary patch delta 842 zcmYjPJ8u&~5T3c0AHgq3EFcD7NP=x3htC)=G$6UKM52%;5(Nm^i4|GIC*+3&1#t<5 z3(QD}4k0S)P$2jNDP4d>k9bIkUqHjmX;)#S+3(x$o1NX;y&rQgv(Ili5eFdROg3(t zS1L97=oHt+CWKK9$08hs43wDLfR;#@;NjGgP!)z15oTI;Cm3)+2A7k^X3YG2p62k< zy3d{sR@ej)|0WZ_fUI&d$s0B1cR3B_DQt@~4Emj&puO!%%f|YqTlcTJzVB6Og72w^ zv$S9=-RKXRTMxR;05tKo02=lBb+@?L8U}-5xWp^3_``7O?^P;Zxmr>(Wvp3BMo-h! za9^0|(G2f=7$zKn{~JfyLcSdNezbuvhLNu?tMH^CU(tf{*#a~G&M5z^!m>i}`j5MV zW{Yvq6QtkK9KALD=o}KT~qYa%43rv zb^)K#MY}LMU`NiK;*>{{7nFIEQ(i#FYbKZVgi(9P>*56Rysaw}-Wmo=x%-M-S%s94?J*k-Psxpzy+u=)-KjK%06FU^VuZ;l=cOA+H~Vh04(BoIF$3k;gHHW zefP3(FvJ$|I4rP5l)$}P@kX~3w_A}c-Pl}hK76zqPo|*Wggf*1quHsM=vIB2UgJkP z@F(c28l;^dinvQ(JWzcsz~hJZRULgYUZs^iL*~!KIq2`sn_6a(jZ|R z;eH@vm0`-PC0=5cVWskx!AKggPq}V_rMt){*8c($kvdVn9_Q1#H=LXRpi;It_$1-j zIr)zCSeI$X4itWJ*%wZRta*BGhjE*J*sA%>$9_hKc2-X{Zo0n**Y}$K98S6pi8=3T rPV*t$J8bDB3C{EBJ^7r diff --git a/lib/win_arm/stackman.lib b/lib/win_arm/stackman.lib index 2b515b5ef4c3f3470456d7528f02ee271b48bd20..63ddf917bfe985bdaf34ba6afa939d34d0e3e0f9 100644 GIT binary patch delta 468 zcmeB@e&Ijf?@JBJ{3i_D_bt+>D` DSIB~+ delta 497 zcmaDP*CoH<7!z|?DdXgmOuCF=o4+$fG76iSD1bo%*AYe*1`w#2oXnEVcw+K-7H!6e z$-h|^a|5+72s6ksfV8e;y~J!_Y`(dUEr(J47XzypNQ;7QYDGzEQC?z>Rcc*P=D7L%3vlqM_iXitvk7Ul*T5R;jgoKu>TI(Z?lDo~u0hvD<5 zk4%gZ^CoZPFa_B%`3?70aYIW36GJ_Nn9}5;5+#O@pP+V5R^&6B9LpuZ0+OHnhsOiL z@Zj}<>nP9618L!cnF`gx4Kp#hpkVSGUc<=(Tx^qna7j&O;dB8xPY}s@N+4%_n*5v- z?s$HXY+^}HZdx+f50n3KG_o*!`uJ<|Z5~;O8)kAka>48<&7HiE(-I=C#pTQg6Nk8M z@>yP0wrM~gaSKd-!)XPV1-cBVVDfxUZIHuQBS5a0oX4l4Sk=b9KU}wEG56b@#~m-H cWPm~+1RRp{a|`q`Q^F>1<|_q8o+iH~08=-T$^ZZW diff --git a/lib/win_arm64/stackman.lib b/lib/win_arm64/stackman.lib index 68c06e032ad94c4fc53776b089e24794a9b111ee..2b0340bbf6d25d1ed2e55438b7cbdc167d0a0ede 100644 GIT binary patch delta 817 zcmZp&-)A@B9Me1DjTa6vF`p`Bm^_tPm+{o*!^{zkBIXvx3Sf}Hm9mPB0R)mJ>$C1= z44M3zRh!XhvN+pPZlE3pVFpQ&RxyyVlLdG!ChN%vgCzw8tS2W(8cpsJFcUX2GBYyN zGl(foE-F!C`1pf>0xA$0 zD>?tk=2A+N4S4Lp7JlGS;9~gr4Q4j7TVx~;K=eG2^nx(-q&y&uDk+P}5rQflr-1r| z1b}`}lojKExp%UbwE5%>0s;`FANe9ChYG11+F2@ zcxKIf|L?8Llq^tCfPh1Cer|zYX3D9_YlS`oLwlj{Y+++FL|m|dRmDv97s+N^GkLd& zHlxkt=OQR^F?qV^1(4@9XN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SSs!59LoBWyGn?CwIT6LNY?&K)KY)3Xd++l;=XsxV z&U@c4nRl2|SL8A#Mev$@LguOPa)%XjgfQG-W`G#H)gF@=-Rb~QfDpD)fNZ>?d`zX) z0%!?<0i7zdq9qGp0C%d4iZl)I3Z_(cYRQDhRpT1o9cU;4{>yDwcMwv;y{Gv}j_>Ot zn4MEU)YKX(yxO_AP8Bb{JXCe(48SG6kdB=1zi@W>*2rStA!7meT2}@@IbTjk{Il+c zFRCv6i2a{kI5JiLHNcA^-#*lJ@uZoad$&Ae?z(Yy9AHM|$I{uaKjLevI6ZB6YU=E^ zVt^b<@R76Tsj+eM(2mi~t_kME?dJi)V&cYF@8t9k^!BE#{d&5vnG+gGx z9i;4k?qWyo=U^clGV~f9e}njEU;{T?m>|@#4Y*kJGj;e;?z`eQWR&s=jx|w)>hHwv z(xbxV#HG?CnaAF;?_J^83qF76F8`CQ4T0Uwt&M^9t$x$`a5@=I#DYD(jtWo{g`V#g zaEsZA#9_fUMV)9;Yd2xkktM8Y-jod{d!l(5%ch4`ZBqQND}$TZW47Wsx Date: Tue, 13 Aug 2024 11:28:34 +0000 Subject: [PATCH 61/67] Format readme --- README.md | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4ab8b04..36e4c46 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,11 @@ [![build test and commit](https://github.com/kristjanvalur/stackman/actions/workflows/buildcommit.yml/badge.svg)](https://github.com/kristjanvalur/stackman/actions/workflows/buildcommit.yml) # stackman + Simple low-level stack manipulation API and implementation for common platforms ## Purpose + This library aims to provide a basic API to perfom stack manipulation on various platforms. Stack manipulation involves changing the machine stack pointer while optionally saving and restoring the stack contents. @@ -29,10 +31,14 @@ Additionally, it provides a set of pre-assembled libraries for the most common platforms so that no assembly steps are required by users. ## Features + - Simple api + - `stackman_switch()` and `stackman_call()` are the only functions. - The caller provides a callback and context pointer to customize behaviour. - Simple implementation + +- Simple implementation + - The code involving assembly is as simple as possible, allowing for straightforward implementation on most platforms. - Complex logic and branching is delegated to the C callback. @@ -40,23 +46,33 @@ platforms so that no assembly steps are required by users. 1. Save and restore volatile registers and stack state on the stack 2. Call the callback twice with the current stack pointer 3. Set the stack pointer to the value returned by the first callback. -- Assembly support + +- Assembly support + The straightforward and application-agnostic switching allows the switching function to be implemented in full assembler. This removes the risk of inline-assembler doing any sort of unexpected things such as in-lining the function or otherwise change the assumptions that the function makes about its environment. This assembly code can be created by the in-line assembler in a controlled environment. + - No dependencies + The library merely provides stack switching. It consist only of a couple of functions with no dependencies. + - Stable + There is no need to add or modify functionality. + - Libraries provided. + The aim is to provide pre-assembled libraries for the most popular platforms. This relieves other tools that want to do stack manipulation from doing any sort of assembly or complex linkage. Just include the headers and link to the appropriate library. ## Supported platforms + The current code is distilled out of other work, with the aim of simplifying and standardizing the api. A number of ABI specifications is supported, meaning architecture and calling convention, plus archive format: + - win_x86 (32 bits) - win_x64 - win_ARM64 (experimental) @@ -65,7 +81,8 @@ calling convention, plus archive format: - AAPCS (32 bit arm) - AAPCS64 (64 bit arm) -Supported toolchains: +### Supported toolchains: + - Gnu C - clang - Microsoft Visual Studio @@ -74,16 +91,21 @@ Other platforms can be easily adapted from both existing implementations for oth projects as well as from example code provided. ## API + There are two functions that make up the stackman library: `stakman_switch()` and `stackman_call()` who both take a `stackman_cb_t` callback: + ```C typedef void *(*stackman_cb_t)( void *context, int opcode, void *stack_pointer); void *stackman_switch(stackman_cb_t callback, void *context); void *stackman_call(stackman_cb_t callback, void *context, void *stack); ``` + ### stackman_switch() + This is the main _stack manipulation_ API. When called, it will call `callback` function twice: + 1. First it calls it with the current opcode `STACKMAN_OP_SAVE`, passing the current `stack_pointer` to the callback. This gives the callback the opportunity to _save_ the stack data somewhere. The callback can then return a **different** stack pointer. @@ -98,14 +120,17 @@ Depending on how the callback function is implemented, this API can be used for saving a copy of the stack, perform a stack switch, query the stack pointer, and so on. ### stackman_call() + This is a helper function to call a callback function, optionally providing it with a different stack to use. + 1. It saves the current CPU stack pointer. If `stack` is non-zero, it will replace the stackpointer with that value. 2. It calls the callback function with the opcode `STACKMAN_OP_CALL`. 3. It replaces the stack pointer with the previously saved value and returns the return value from the callback. This function is useful for at least three things: + - To move the call chain into a custom stack area, some heap-allocated block, for example. - To query the current stack pointer - To enforce an actual function call with stack pointer information. @@ -114,17 +139,21 @@ The last feature is useful to bypass any in-lining that a compiler may do, when a proper function call with stack, for example, when setting up a new stack entry point. ## Usage + - Include `stackman.h` for a decleration of the `stackman_switch()` function and the definition of various platform specific macros. See the documentation in the header file for the various macros. - Implement switching semantics via the callback and call `stackman_switch()` from your program as appropriate. See tests/test.c for examples. -There are two basic ways to add the library to your project: +There are two basic ways to add the library to your project: Using a static library or inlining the code. + ### static library (preferred) + - You link with the `libstackman.a` or `stackman.lib` libraries provided for your platform. ### inlined code + - You inlude `stackman_impl.h` in one of your .c source files to provide inline assembly. - You include `stackman_impl.h` in an assembly (.S) file in your project to include assembly code. - (windows) You include `stackman_s.asm` in an assemby (.asm) file in your project. @@ -132,7 +161,9 @@ There are two basic ways to add the library to your project: over separate assembly language source. ## Development + ### Adding new platforms + 1. Modify `platform.h` to identif the platform environment. Define an ABI name and include custom header files. 2. Use the `switch_template.h` to help build a `switch_ABI.h` file for your ABI. @@ -140,8 +171,10 @@ There are two basic ways to add the library to your project: 4. Provide cross-compilation tools for linux if possible, by modifying the `Makefile` ### Cross-compilation + Linux on x86-64 can be used to cross compile for x86 and ARM targets. This is most useful to generate assembly code, e.g. when compiling stackman/platform/gen_asm.c + - x86 requires the -m32 flag to compilers and linkers. - arm32 requires to use the arm-linux-gnueabi-* tools, including cc and linker - aarch64 requires the aarch64-linux-gnu-* tools. @@ -151,23 +184,27 @@ The x86 tools require the **gcc-multilib** and **g++-multilib** packages to be i platforms may need to be done independently. #### Cross compiling for x86 (32 bit) on Linux + - install __gcc-multilib__ and __g++-multilib__ - *compile* **gen_asm.c** using `gcc -m32` - *make* using `make PLATFORMFLAGS=-m32 test` #### Cross compiling for ARM (32 bit) on Linux + - install __gcc-arm-linux-gnueabi__ and __g++-arm-linux-gnueabi__ - install __qemu-user__ for hardware emulation - *compile* **gen_asm.c** using `arm-linux-gnueabi-gcc` - *make* using `make PLATFORM_PREFIX=arm-linux-gnueabi- EMULATOR=qemu-arm test` #### Cross compiling for Arm64 on Linux + - install **gcc-aarch64-linux-gnu** and **g++-aarch64-linux-gnu** - install __qemu-user__ for hardware emulation - *compile* using `aarch64-linux-gnu-gcc` - *make* using `make PLATFORM_PREFIX=aarch64-linux-gnu- EMULATOR=qemu-aarch64 test` ## A note about Intel CET + Intel's *Control-Flow Enforcement Technology* is incompatible with stack switching because it employs a secondary *Shadow Stack*, that the user-mode program cannot modify. Unexpected return flow after a stack switch would cause the processor @@ -179,6 +216,7 @@ code may be run in such a protected environment. See https://software.intel.com/content/www/us/en/develop/articles/technical-look-control-flow-enforcement-technology.html for more information ## History + This works was originally inspired by *Stackless Python* by [Christian Tismer](https://github.com/ctismer), where the original switching code was developed. From 87ef6417a605de4499fffa42ca2a0c5350f074f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Tue, 13 Aug 2024 11:28:44 +0000 Subject: [PATCH 62/67] fix typo --- stackman/platforms/switch_x64_msvc.asm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stackman/platforms/switch_x64_msvc.asm b/stackman/platforms/switch_x64_msvc.asm index 5143276..998eb24 100644 --- a/stackman/platforms/switch_x64_msvc.asm +++ b/stackman/platforms/switch_x64_msvc.asm @@ -104,7 +104,7 @@ NESTED_END stackman_switch, _TEXT$00 stackman_call PROC FRAME push rbp .pushreg rbp - ; now our stack is 16 byte aligned. don't need additional spacle + ; now our stack is 16 byte aligned. don't need additional space ;sub rsp, 040h ;.allocstack 040h lea rbp, [rsp+00h] From 278103bdb635fc091e085191edcdec7bf1424744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Tue, 13 Aug 2024 11:28:51 +0000 Subject: [PATCH 63/67] Remove unused vars --- tests/test.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/test.c b/tests/test.c index e6b726e..a8beffc 100644 --- a/tests/test.c +++ b/tests/test.c @@ -254,8 +254,6 @@ void test_04(void) /* test stackman_call() with a null stack pointer */ void test_05(void) { - char *block, *stack, *stack2; - int i, cnt; ctxt01 ctxt; assert(STACKMAN_STACK_FULL_DESCENDING); From 4d5e4c215c2dc5d48bd36d461fe94e357afc73f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Tue, 13 Aug 2024 11:29:27 +0000 Subject: [PATCH 64/67] format python helper --- tools/strip-lib.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/tools/strip-lib.py b/tools/strip-lib.py index a64aa97..f783d81 100644 --- a/tools/strip-lib.py +++ b/tools/strip-lib.py @@ -7,8 +7,8 @@ # There are some additional fixes added for reproducability, such as fixing the zero-padding of names in the coff # section headers. -import sys import struct +import sys verbose = True @@ -96,8 +96,6 @@ def read_lib(fp): print("coff length:", len(result["o"][-1])) h = None - return result - def write_lib(fp, lib): fp.write(libheader) @@ -184,15 +182,13 @@ def first_lm_read(fp): offsets = [] strings = [] - for i in range(nos): + for _ in range(nos): offset = fp.read(4) offsets.append(struct.unpack(">L", offset)[0]) - for i in range(nos): + for _ in range(nos): strings.append(readcstr(fp)) return {"offsets": offsets, "strings": strings} # sometimes there is an extra \0a after the strings - p = peek(fp) - return zip(offsets, strings) def first_lm_write(fp, lm): @@ -208,16 +204,16 @@ def second_lm_read(fp): # number of members m = struct.unpack(" Date: Tue, 13 Aug 2024 11:32:58 +0000 Subject: [PATCH 65/67] Add solution files for VS2022 --- vs2022/stackman.sln | 44 +++++ vs2022/stackman/stackman.vcxproj | 230 +++++++++++++++++++++++ vs2022/stackman/stackman.vcxproj.filters | 67 +++++++ vs2022/stackman/template.c | 15 ++ vs2022/test/test.vcxproj | 152 +++++++++++++++ vs2022/test/test.vcxproj.filters | 22 +++ 6 files changed, 530 insertions(+) create mode 100644 vs2022/stackman.sln create mode 100644 vs2022/stackman/stackman.vcxproj create mode 100644 vs2022/stackman/stackman.vcxproj.filters create mode 100644 vs2022/stackman/template.c create mode 100644 vs2022/test/test.vcxproj create mode 100644 vs2022/test/test.vcxproj.filters diff --git a/vs2022/stackman.sln b/vs2022/stackman.sln new file mode 100644 index 0000000..6dff39b --- /dev/null +++ b/vs2022/stackman.sln @@ -0,0 +1,44 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30717.126 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test", "test\test.vcxproj", "{CAFDBD3E-9D0D-4E90-BB6D-6C2A19F5EF53}" + ProjectSection(ProjectDependencies) = postProject + {BF7D0638-AC4F-4206-B426-66CDDD468281} = {BF7D0638-AC4F-4206-B426-66CDDD468281} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "stackman", "stackman\stackman.vcxproj", "{BF7D0638-AC4F-4206-B426-66CDDD468281}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|ARM = Debug|ARM + Debug|ARM64 = Debug|ARM64 + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {CAFDBD3E-9D0D-4E90-BB6D-6C2A19F5EF53}.Debug|ARM.ActiveCfg = Debug|ARM + {CAFDBD3E-9D0D-4E90-BB6D-6C2A19F5EF53}.Debug|ARM.Build.0 = Debug|ARM + {CAFDBD3E-9D0D-4E90-BB6D-6C2A19F5EF53}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {CAFDBD3E-9D0D-4E90-BB6D-6C2A19F5EF53}.Debug|ARM64.Build.0 = Debug|ARM64 + {CAFDBD3E-9D0D-4E90-BB6D-6C2A19F5EF53}.Debug|x64.ActiveCfg = Debug|x64 + {CAFDBD3E-9D0D-4E90-BB6D-6C2A19F5EF53}.Debug|x64.Build.0 = Debug|x64 + {CAFDBD3E-9D0D-4E90-BB6D-6C2A19F5EF53}.Debug|x86.ActiveCfg = Debug|Win32 + {CAFDBD3E-9D0D-4E90-BB6D-6C2A19F5EF53}.Debug|x86.Build.0 = Debug|Win32 + {BF7D0638-AC4F-4206-B426-66CDDD468281}.Debug|ARM.ActiveCfg = Debug|ARM + {BF7D0638-AC4F-4206-B426-66CDDD468281}.Debug|ARM.Build.0 = Debug|ARM + {BF7D0638-AC4F-4206-B426-66CDDD468281}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {BF7D0638-AC4F-4206-B426-66CDDD468281}.Debug|ARM64.Build.0 = Debug|ARM64 + {BF7D0638-AC4F-4206-B426-66CDDD468281}.Debug|x64.ActiveCfg = Debug|x64 + {BF7D0638-AC4F-4206-B426-66CDDD468281}.Debug|x64.Build.0 = Debug|x64 + {BF7D0638-AC4F-4206-B426-66CDDD468281}.Debug|x86.ActiveCfg = Debug|Win32 + {BF7D0638-AC4F-4206-B426-66CDDD468281}.Debug|x86.Build.0 = Debug|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A71982F0-A89C-45AB-9F23-149A1983A11B} + EndGlobalSection +EndGlobal diff --git a/vs2022/stackman/stackman.vcxproj b/vs2022/stackman/stackman.vcxproj new file mode 100644 index 0000000..cb9614a --- /dev/null +++ b/vs2022/stackman/stackman.vcxproj @@ -0,0 +1,230 @@ + + + + + Debug + ARM + + + Debug + ARM64 + + + Debug + Win32 + + + Debug + x64 + + + + 16.0 + Win32Proj + {bf7d0638-ac4f-4206-b426-66cddd468281} + stackman + 10.0 + stackman + + + + StaticLibrary + true + v143 + Unicode + + + StaticLibrary + true + v143 + Unicode + + + StaticLibrary + true + v143 + Unicode + + + StaticLibrary + true + v143 + Unicode + + + + + + + + + + + + + + + + + + + + + + + true + $(SolutionDir)\..\lib\win_x86\ + $(Platform)\$(Configuration)\ + + + true + $(SolutionDir)\..\lib\win_x64\ + + + true + $(SolutionDir)\..\lib\win_arm\ + + + true + $(SolutionDir)\..\lib\win_arm64\ + + + + Level3 + true + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + NotUsing + pch.h + OldStyle + + + + + true + + + /Brepro %(AdditionalOptions) + + + + + Level3 + true + _DEBUG;_LIB;%(PreprocessorDefinitions) + true + NotUsing + pch.h + OldStyle + + + + + true + + + /Brepro %(AdditionalOptions) + + + + + Level3 + true + _DEBUG;_LIB;%(PreprocessorDefinitions) + true + NotUsing + pch.h + OldStyle + + + + + true + + + /Brepro %(AdditionalOptions) + + + + + Level3 + true + _DEBUG;_LIB;%(PreprocessorDefinitions) + true + NotUsing + pch.h + OldStyle + + + + + true + + + /Brepro %(AdditionalOptions) + + + + + + + + + + + + + + + false + Default + + + AssemblyCode + AssemblyCode + AssemblyCode + false + false + false + Default + Default + Default + false + false + false + true + true + false + true + + + + + false + true + true + true + + + Document + true + true + true + + + true + true + true + + + true + true + true + + + + + + + + \ No newline at end of file diff --git a/vs2022/stackman/stackman.vcxproj.filters b/vs2022/stackman/stackman.vcxproj.filters new file mode 100644 index 0000000..9f57a1f --- /dev/null +++ b/vs2022/stackman/stackman.vcxproj.filters @@ -0,0 +1,67 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + Source Files + + + Source Files + + + + + Source Files + + + Source Files + + + + + Source Files + + + Source Files + + + \ No newline at end of file diff --git a/vs2022/stackman/template.c b/vs2022/stackman/template.c new file mode 100644 index 0000000..2fe7dbd --- /dev/null +++ b/vs2022/stackman/template.c @@ -0,0 +1,15 @@ +#include "..\..\stackman\stackman.h" + +/* + * template file to create assembly code (template.asm) to modify and add to real assembler. + */ + +void* stackman_call_templ(stackman_cb_t callback, void* context, void* stack) +{ + // We use this variabl here for the template generation. Int the modified assembly + // code, we will store the ebp (base pointer) in that place on the stack, + // before storing the original unmodified stack pointer there. + void* localvar = stack; + return callback(context, 2, localvar); + +} \ No newline at end of file diff --git a/vs2022/test/test.vcxproj b/vs2022/test/test.vcxproj new file mode 100644 index 0000000..266eb72 --- /dev/null +++ b/vs2022/test/test.vcxproj @@ -0,0 +1,152 @@ + + + + + Debug + ARM + + + Debug + ARM64 + + + Debug + Win32 + + + Debug + x64 + + + + 16.0 + Win32Proj + {cafdbd3e-9d0d-4e90-bb6d-6c2a19f5ef53} + test + 10.0 + + + + Application + true + v143 + Unicode + + + Application + true + v143 + Unicode + + + Application + true + v143 + Unicode + + + Application + true + v143 + Unicode + + + + + + + + + + + + + + + + + + + + + true + $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ + + + true + + + true + + + true + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + ..\..\stackman + + + Console + true + ..\..\lib\win_x86;%(AdditionalLibraryDirectories) + stackman.lib;%(AdditionalDependencies) + + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + ..\..\stackman + + + Console + true + stackman.lib;%(AdditionalDependencies) + ..\..\lib\win_x64;%(AdditionalLibraryDirectories) + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + ..\..\stackman + + + Console + true + stackman.lib;%(AdditionalDependencies) + ..\..\lib\win_arm;%(AdditionalLibraryDirectories) + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + ..\..\stackman + + + Console + true + stackman.lib;%(AdditionalDependencies) + ..\..\lib\win_arm64;%(AdditionalLibraryDirectories) + + + + + + + + + \ No newline at end of file diff --git a/vs2022/test/test.vcxproj.filters b/vs2022/test/test.vcxproj.filters new file mode 100644 index 0000000..154d04b --- /dev/null +++ b/vs2022/test/test.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + \ No newline at end of file From f9f82c9b0288594e3ae5e09636fe22cee8271be7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Tue, 13 Aug 2024 11:53:10 +0000 Subject: [PATCH 66/67] update build workflow --- .github/workflows/buildcommit.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/buildcommit.yml b/.github/workflows/buildcommit.yml index 7834d97..d858b1f 100644 --- a/.github/workflows/buildcommit.yml +++ b/.github/workflows/buildcommit.yml @@ -30,7 +30,7 @@ jobs: PLATFORM_PREFIX: ${{matrix.platformtools}} EMULATOR: ${{matrix.emulator}} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: install multilib run: sudo apt-get install --no-install-recommends -y gcc-multilib g++-multilib if: ${{ matrix.name == 'i386' }} @@ -53,7 +53,7 @@ jobs: path: lib/${{ env.abiname }}/libstackman.a build-windows: - runs-on: windows-2019 + runs-on: windows-latest strategy: fail-fast: true matrix: @@ -71,17 +71,17 @@ jobs: folder: arm64 steps: - - uses: actions/checkout@v2 - - uses: microsoft/setup-msbuild@v1.0.2 + - uses: actions/checkout@v4 + - uses: microsoft/setup-msbuild@v2 - name: build - run: msbuild.exe vs2019\stackman.sln /p:Platform=${{matrix.platform}} + run: msbuild.exe vs2022\stackman.sln /p:Platform=${{matrix.platform}} - name: strip timestamps from lib run: python tools/strip-lib.py lib/win_${{matrix.platform}}/stackman.lib - name: rebuild after stripping - run: msbuild.exe vs2019\stackman.sln /p:Platform=${{matrix.platform}} + run: msbuild.exe vs2022\stackman.sln /p:Platform=${{matrix.platform}} - name: test if: ${{ matrix.native == 'yes' }} - run: vs2019\${{matrix.folder}}\Debug\test.exe + run: vs2022\${{matrix.folder}}\Debug\test.exe - name: Upload build artifacts uses: actions/upload-artifact@v4 with: @@ -93,7 +93,7 @@ jobs: needs: [build-linux-gnu, build-windows] if: ${{ github.event_name == 'push' }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: actions/download-artifact@v4 with: path: lib From cbf4e149a41f6c6ac553b1d17adff1526de54fc3 Mon Sep 17 00:00:00 2001 From: Automation tool Date: Sun, 8 Sep 2024 10:29:30 +0000 Subject: [PATCH 67/67] Automated build --- lib/win_arm/stackman.lib | Bin 3938 -> 4982 bytes lib/win_arm64/stackman.lib | Bin 7998 -> 9414 bytes lib/win_x64/stackman.lib | Bin 6090 -> 7150 bytes lib/win_x86/stackman.lib | Bin 11074 -> 21610 bytes 4 files changed, 0 insertions(+), 0 deletions(-) diff --git a/lib/win_arm/stackman.lib b/lib/win_arm/stackman.lib index 63ddf917bfe985bdaf34ba6afa939d34d0e3e0f9..0b34d1112c5d1b186516bcad8db92f2e81c23f19 100644 GIT binary patch delta 1712 zcmaJ>eMnnZ6hC<{N%Q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