Skip to content

Commit

Permalink
Merge pull request #3420 from eisenhauer/DillUpstream
Browse files Browse the repository at this point in the history
Dill upstream
  • Loading branch information
eisenhauer committed Dec 22, 2022
2 parents 5001279 + 9c08520 commit 83b798f
Show file tree
Hide file tree
Showing 9 changed files with 831 additions and 19 deletions.
12 changes: 6 additions & 6 deletions thirdparty/dill/dill/.github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ jobs:
matrix:
buildtype: [ release, debug ]
jobname: [
#windows2019-vs2019-clang,
#windows2022-vs2022-msvc,
windows2019-vs2019-clang,
windows2022-vs2022-msvc,
macos-clang ]
include:
#- jobname: windows2019-vs2019-clang
# vm: windows-2019
#- jobname: windows2022-vs2022-msvc
# vm: windows-2022
- jobname: windows2019-vs2019-clang
vm: windows-2019
- jobname: windows2022-vs2022-msvc
vm: windows-2022
- jobname: macos-clang
vm: macos-latest

Expand Down
2 changes: 2 additions & 0 deletions thirdparty/dill/dill/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ set(SRC_list
virtual.c
dill.c
vm.c
x86_64_disassembler.c
)

set(TARGET_DEP_INC)
Expand Down Expand Up @@ -153,6 +154,7 @@ if(CMAKE_SYSTEM_NAME MATCHES "Darwin|Linux")
set(USE_MMAP_CODE_SEG 1)
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows")
set(USE_VIRTUAL_PROTECT 1)
set(USE_WINDOWS_CALLS 1)
endif()

include(TestBigEndian)
Expand Down
4 changes: 3 additions & 1 deletion thirdparty/dill/dill/cmake/FindLibFFI.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ if(NOT (PC_LIBFFI_FOUND STREQUAL "IGNORE"))
set(_PF_TYPE _STATIC)
endif()
set(LIBFFI_INCLUDE_DIRS ${PC_LIBFFI${_PC_TYPE}_INCLUDE_DIRS})
set(LIBFFI_LIBRARIES ${PC_LIBFFI${_PC_TYPE}_LDFLAGS})
set(LIBFFI_LIBRARIES ${PC_LIBFFI${_PC_TYPE}_LIBRARIES})
set(LIBFFI_LIBRARY_DIRS ${PC_LIBFFI${_PC_TYPE}_LIBRARY_DIRS})
set(LIBFFI_DEFINITIONS ${PC_LIBFFI${PC_TYPE}_CFLAGS_OTHER})
endif()
endif()
Expand All @@ -57,6 +58,7 @@ if(LIBFFI_FOUND)
if(LIBFFI_LIBRARIES)
set_target_properties(libffi::libffi PROPERTIES
INTERFACE_LINK_LIBRARIES "${LIBFFI_LIBRARIES}"
INTERFACE_LINK_DIRECTORIES "${LIBFFI_LIBRARY_DIRS}"
)
endif()
endif()
Expand Down
7 changes: 5 additions & 2 deletions thirdparty/dill/dill/config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,15 @@
*/
#cmakedefine USE_MEMBAR

/* Define this is mmap should be used instead of malloc() for code memory */
/* Define this if mmap should be used instead of malloc() for code memory */
#cmakedefine USE_MMAP_CODE_SEG

/* Define this is VirtualProtect should be used to change memory protections */
/* Define this if VirtualProtect should be used to change memory protections */
#cmakedefine USE_VIRTUAL_PROTECT

/* Define this if windows calling convention should be used */
#cmakedefine USE_WINDOWS_CALLS

/* Define if byteorder is bigendian */
#cmakedefine WORDS_BIGENDIAN

Expand Down
9 changes: 5 additions & 4 deletions thirdparty/dill/dill/dill_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1532,10 +1532,11 @@ dill_dump(dill_stream s)
printf("No code to dump\n");
return;
}
if ((s->j != s->p->virtual.mach_jump) && native_missing) {
printf("No native disassembler available\n");
return;
}
/* if ((s->j != s->p->virtual.mach_jump) && native_missing) { */
/* printf("No native disassembler available\n"); */
/* return; */
/* } */
(void) native_missing;
if (s->j->init_disassembly(s, &info) == 0) {
printf("No native disassembler available\n");
} else {
Expand Down
44 changes: 43 additions & 1 deletion thirdparty/dill/dill/tests/t1.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
#include "dill.h"
#include <stdlib.h>

#ifdef TESTING
unsigned int x86_64_disassemble(unsigned char *bytes, unsigned int max, int offset, char *output);

int test (int val)
{
return val;
}
#endif

int main(int argc, char **argv)
{
dill_stream s = dill_create_raw_stream();
Expand All @@ -29,6 +38,39 @@ int main(int argc, char **argv)
exit(1);
}
}

#ifdef TESTING
{
dill_stream s = dill_create_raw_stream();
dill_reg param0;
dill_exec_handle h;
int result;
int (*proc)(int);
int s2i = 0xdeadbeef;
dill_start_proc(s, "param1_i", DILL_I, "%i");
param0 = dill_param_reg(s, 0);
dill_reti(s, param0);
h = dill_finalize(s);
proc = (int (*)(int)) dill_get_fp(h);
result = proc(s2i);
dill_dump(s);
if (result != s2i) {
printf("test for 1 arguments of type \"i\" failed, expected %x, got %x\n",
s2i, result);
dill_dump(s);
printf("\n*************\n\n");
}
}
{
printf("\nDisassembly of Test *************\n\n");
unsigned char *tmp = (unsigned char*) &test;
int i = 0;
for (i = 0; i < 40; ) {
char out[128];
int ret = x86_64_disassemble(tmp + i, sizeof(out), 0, out);
printf("%s\n", out);
i += ret;
}
}
#endif
return 0;
}
20 changes: 16 additions & 4 deletions thirdparty/dill/dill/x86_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,8 @@ x86_64_save_restore_op(dill_stream s, int save_restore, int type, int reg)
}

/*
* This is linux convention. Windows is different.
*
* register use preserved across function calls
* %rax temporary register; with variable arguments
* passes information about the
Expand Down Expand Up @@ -758,7 +760,11 @@ Register Offset
%xmm15 288
*/
#ifndef USE_WINDOWS_CALLS
static int arg_regs[] = {RDI, RSI, RDX, RCX, R8, R9};
#else
static int arg_regs[] = {RCX, RDX, R8, R9};
#endif

static void
save_required_regs(dill_stream s, int force)
Expand Down Expand Up @@ -2250,7 +2256,7 @@ static void internal_push(dill_stream s, int type, int immediate,
}
}
if ((arg.type != DILL_D) && (arg.type != DILL_F)) {
if (smi->int_arg_count < 6) {
if (smi->int_arg_count < sizeof(arg_regs) / sizeof(arg_regs[0])) {
arg.is_register = 1;
arg.in_reg = arg.out_reg = arg_regs[smi->int_arg_count];
smi->int_arg_count++;
Expand Down Expand Up @@ -2604,7 +2610,7 @@ x86_64_flush(void *base, void *limit)
asm volatile ("clflush (%0)" : /* */ : "r" (ptr));
#endif
#else
_mm_clflush(ptr);
_mm_clflush((const void *) ptr);
#endif
ptr = (char *)ptr + 8;
}
Expand Down Expand Up @@ -2854,8 +2860,14 @@ x86_64_count_insn(dill_stream s, int start, int end)
return end - start;
}
extern int
x86_64_init_disassembly_info(dill_stream s, void * ptr){return 0;}
extern int x86_64_print_insn(dill_stream s, void *info_ptr, void *insn){return 0;}
x86_64_init_disassembly_info(dill_stream s, void * ptr){return 1;}
unsigned int x86_64_disassemble(unsigned char *bytes, unsigned int max, int offset, char *output);
extern int x86_64_print_insn(dill_stream s, void *info_ptr, void *insn){
char out[128] = "";
int ret = x86_64_disassemble(insn, sizeof(out), 0, out);
printf("%s", out);
return ret;
}
#endif

extern void
Expand Down

0 comments on commit 83b798f

Please sign in to comment.