diff --git a/configure b/configure index aa46b1e5d97e77601f1906b1975236b18e055599..adf11972bc50c4476f7b80d835c3f9f6dab7dd79 100755 --- a/configure +++ b/configure @@ -590,9 +590,9 @@ ASFLAGS AS LD DIRS +OPTIMIZE LTLIBOBJS LIBOBJS -OPTIMIZE OBJEXT EXEEXT ac_ct_CC @@ -2553,22 +2553,12 @@ if test "${enable_inferfn+set}" = set; then : enableval=$enable_inferfn; fi -#AC_ARG_ENABLE([example], [ --enable-debugging enable -g when compiling]) # Check whether --enable-libc was given. if test "${enable_libc+set}" = set; then : enableval=$enable_libc; fi -OPTIMIZE="-O3" -if test "$enable_debugging" = yes; then - OPTIMIZE="-g -DDEBUG" -fi - -OPTIMIZE=$OPTIMIZE - - - enable_dir() { @@ -4901,10 +4891,17 @@ fi fi } +OPTIMIZE="-O3" +if test "$enable_debugging" = yes; then + OPTIMIZE="-g -DDEBUG" +fi + + + LIB=$ZIPR_CALLBACKS/lib/callbacks.a AR=ar CC=gcc -CFLAGS="$OPTIMIZE -nostdinc -fPIE -fPIC -I$ZIPR_CALLBACKS/libc/include -fno-stack-protector" +CFLAGS="$OPTIMIZE -nostdinc -fPIE -fPIC -I$ZIPR_CALLBACKS/libc/include -fno-stack-protector -fno-builtin" LD=gcc LDFLAGS="-r -nostdlib -fPIC -fPIE" AS=nasm @@ -7254,6 +7251,8 @@ $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} fi +OPTIMIZE=$OPTIMIZE + diff --git a/configure.in b/configure.in index 63faf14a21eadbda7fd1f300ebdcc97d12682c72..b591c245ce991edb43a2465dade0c24a14434cef 100644 --- a/configure.in +++ b/configure.in @@ -7,17 +7,8 @@ AC_PROG_CC AC_ARG_ENABLE([debugging], [ --enable-debugging enable -g when compiling]) AC_ARG_ENABLE([cgc], [ --enable-cgc enable -DCGC when compiling for CGC binaries]) AC_ARG_ENABLE([inferfn], [ --enable-inferfn enable -DCGC when compiling for CGC binaries]) -#AC_ARG_ENABLE([example], [ --enable-debugging enable -g when compiling]) AC_ARG_ENABLE([libc], [ --enable-libc enable $1 for building ]) -OPTIMIZE="-O3" -if test "$enable_debugging" = yes; then - OPTIMIZE="-g -DDEBUG" -fi - -AC_SUBST(OPTIMIZE, $OPTIMIZE) - - enable_dir() { @@ -37,10 +28,17 @@ enable_dir() fi } +OPTIMIZE="-O3" +if test "$enable_debugging" = yes; then + OPTIMIZE="-g -DDEBUG" +fi + + + LIB=$ZIPR_CALLBACKS/lib/callbacks.a AR=ar CC=gcc -CFLAGS="$OPTIMIZE -nostdinc -fPIE -fPIC -I$ZIPR_CALLBACKS/libc/include -fno-stack-protector" +CFLAGS="$OPTIMIZE -nostdinc -fPIE -fPIC -I$ZIPR_CALLBACKS/libc/include -fno-stack-protector -fno-builtin" LD=gcc LDFLAGS="-r -nostdlib -fPIC -fPIE" AS=nasm @@ -73,6 +71,7 @@ enable_dir rss AC_OUTPUT(Makefile) +AC_SUBST(OPTIMIZE, $OPTIMIZE) AC_SUBST(DIRS) AC_SUBST(CC) AC_SUBST(CFLAGS) diff --git a/configure_for_rss b/configure_for_rss index 159ad5b20d6af8e05cb686bbf01cf89d9e961017..c85966dc634aac11b3d16a6b421aa69fd79e8f4c 100755 --- a/configure_for_rss +++ b/configure_for_rss @@ -1,4 +1,4 @@ #!/bin/bash # pickup the CGC syscalls -./configure --enable-rss --enable-libc --prefix=$ZIPR_INSTALL +./configure --enable-rss --enable-libc --prefix=$ZIPR_INSTALL $* diff --git a/libc/include/stdint.h b/libc/include/stdint.h index 9b7f618b517f27a31f2648e1e06102b048cf6ffc..d7f0f9d90d473c22bf39c2e5e6a689d02a332df6 100644 --- a/libc/include/stdint.h +++ b/libc/include/stdint.h @@ -21,8 +21,14 @@ #ifndef stdint_h #define stdint_h -typedef signed long int ssize_t; -typedef unsigned long int size_t; -typedef unsigned long int uintptr_t; +#ifdef LINUX64 + typedef signed long long int ssize_t; + typedef unsigned long long int size_t; + typedef unsigned long long int uintptr_t; +#else + typedef signed long int ssize_t; + typedef unsigned long int size_t; + typedef unsigned long int uintptr_t; +#endif #endif diff --git a/libc/src/itoa.c b/libc/src/itoa.c index 6f326655dc87c2bc43ff6bb5e59da211c1930144..ee69424bd4d0ff5af3d0e2dc5bacc8c3aa1e7702 100644 --- a/libc/src/itoa.c +++ b/libc/src/itoa.c @@ -1,14 +1,17 @@ #include <strlen.h> +#include <stdint.h> -void itox(unsigned int i, char *s) +/* convert integer i into string of hex digits at string s. */ +void itox(uintptr_t i, char *s) { unsigned char n; - - s += 8; + + /* 4-byte integers print 8 chars, 8-byte integers print 16 bytes */ + s += 2*sizeof(void*); *s = '\0'; - for (n = 8; n != 0; --n) { + for (n = 2*sizeof(void*); n != 0; --n) { *--s = "0123456789ABCDEF"[i & 0x0F]; i >>= 4; } diff --git a/rss/rss_callbacks.c b/rss/rss_callbacks.c index 07770bd0896a8a6f37bd0a913963e549cb2cc7e0..94766302dbcba20d20c0d15480bb6a92a3fc3246 100644 --- a/rss/rss_callbacks.c +++ b/rss/rss_callbacks.c @@ -19,15 +19,77 @@ */ #include <stdint.h> +#include <strlen.h> -void zipr_push_stack(uintptr_t ret) + +#define MAX_ENTRIES 4096 + +uintptr_t ret_shadow_stack[MAX_ENTRIES]; +int rss_head_pointer=0; + +static void print_stack(char* s) { - char str[]="zipr_push_callback\n"; +#ifdef DEBUG + write(1,s,strlen(s)); + s=": rss_head_pointer="; + write(1,s,strlen(s)); + char rss_head_str[2*sizeof(void*)+1]; + itox(rss_head_pointer,rss_head_str); + write(1,rss_head_str,strlen(rss_head_str)); + write(1,"\n",1); + int i; + for(i=0;i<rss_head_pointer;i++) + { + char i_str[2*sizeof(void*)+1]; + char entry_str[2*sizeof(void*)+1]; + itox(i,i_str); + itox(ret_shadow_stack[i],entry_str); + write(1,i_str,strlen(i_str)); + write(1,",",1); + write(1,entry_str,strlen(entry_str)); + write(1,"\n",1); + + } +#endif +} + +void zipr_push_stack(uintptr_t app_ret_addr, uintptr_t stack_ret_addr) +{ +#ifdef DEBUG + char appret[2*sizeof(void*)+1]; + char stackret[2*sizeof(void*)+1]; + itox(app_ret_addr,appret); + itox(stack_ret_addr,stackret); + char str[]="zipr_push_callback, appret,stackret="; write(1,str,sizeof(str)); + write(1,appret,sizeof(appret)); + write(1,",",1); + write(1,stackret,sizeof(stackret)); + write(1,"\n",1); + + print_stack("push"); +#endif + ret_shadow_stack[rss_head_pointer++]=stack_ret_addr; } -void zipr_pop_stack(uintptr_t ret) +void zipr_pop_stack(uintptr_t app_ret_addr, uintptr_t stack_ret_addr) { - char str[]="zipr_pop_callback\n"; +#ifdef DEBUG + char appret[2*sizeof(void*)+1]; + char stackret[2*sizeof(void*)+1]; + itox(app_ret_addr,appret); + itox(stack_ret_addr,stackret); + char str[]="zipr_pop_callback, appret,stackret="; write(1,str,sizeof(str)); + write(1,appret,sizeof(appret)); + write(1,",",1); + write(1,stackret,sizeof(stackret)); + write(1,"\n",1); + print_stack("pop"); +#endif + + if(ret_shadow_stack[--rss_head_pointer]!=stack_ret_addr) + *(int*)(0)=0; + + }