...
 
Commits (6)
*.o *.o
*.obj
*.a *.a
*.dcb *.dcb
.idea .idea
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#define __I_PROCDEF_ST_H #define __I_PROCDEF_ST_H
#include "instance_st.h" #include "instance_st.h"
#include <stdint.h>
/* Process definitions, more simple than in the compiler */ /* Process definitions, more simple than in the compiler */
...@@ -54,7 +55,7 @@ typedef struct _procdef { ...@@ -54,7 +55,7 @@ typedef struct _procdef {
int string_count; int string_count;
int pubstring_count; int pubstring_count;
int params; intptr_t params;
int id; int id;
int type; int type;
int flags; int flags;
...@@ -70,13 +71,13 @@ typedef struct _procdef { ...@@ -70,13 +71,13 @@ typedef struct _procdef {
/* System functions */ /* System functions */
typedef int SYSFUNC(INSTANCE *, int *); typedef int SYSFUNC(INSTANCE *, intptr_t *);
typedef struct _sysproc { typedef struct _sysproc {
int code; int code;
char *name; char *name;
char *paramtypes; char *paramtypes;
int type; int type;
int params; intptr_t params;
SYSFUNC *func; SYSFUNC *func;
int id; int id;
} SYSPROC; } SYSPROC;
......
...@@ -37,6 +37,8 @@ ...@@ -37,6 +37,8 @@
#define STACK_SIZE_MASK 0x7FFF #define STACK_SIZE_MASK 0x7FFF
#define STACK_SIZE 2048 #define STACK_SIZE 2048
#include <stdint.h>
/* Instancias. Una instancia se crea a partir de un proceso, pero en /* Instancias. Una instancia se crea a partir de un proceso, pero en
* realidad es independiente del proceso original */ * realidad es independiente del proceso original */
...@@ -88,8 +90,8 @@ typedef struct _instance { ...@@ -88,8 +90,8 @@ typedef struct _instance {
/* The first integer at the stack is the stack size, /* The first integer at the stack is the stack size,
with optional NO_RETURN_VALUE mask. The stack contents follows */ with optional NO_RETURN_VALUE mask. The stack contents follows */
int *stack; intptr_t *stack;
int *stack_ptr; intptr_t *stack_ptr;
/* For debugging */ /* For debugging */
......
...@@ -35,10 +35,10 @@ ...@@ -35,10 +35,10 @@
#ifdef _WIN32 #ifdef _WIN32
/* NEEDED FOR LOCALE DETECTION */ /* NEEDED FOR LOCALE DETECTION */
#include <Windows.h> #include <windows.h>
#include <windef.h> #include <windef.h>
#include <winnls.h> #include <winnls.h>
#include "Shlwapi.h" #include <shlwapi.h>
#endif #endif
#include "pxtb.h" #include "pxtb.h"
...@@ -141,16 +141,10 @@ int main(int argc, char *argv[]) { ...@@ -141,16 +141,10 @@ int main(int argc, char *argv[]) {
/* Allocate 3GB of RAM so that -hopefully- 64bit porting errors arise */ /* Allocate 3GB of RAM so that -hopefully- 64bit porting errors arise */
printf("WARNING!!! Allocating a lot of RAM!!\n"); printf("WARNING!!! Allocating a lot of RAM!!\n");
size_t allocated = 0; size_t limit = (size_t)(3 * 1024 * 1024) * 1024;
size_t limit = 3 * 1024 * 1024 * 1024; if(!malloc(limit)) {
size_t chunk_size = 100 * 1024 * 1024; printf("Could not allocated memory...\n");
printf("Limit: %zu\n", limit); exit(EXIT_FAILURE);
while(allocated < limit) {
if(!malloc(chunk_size)) {
printf("Could not allocate 100MB chunk (%zuGB allocated), quitting\n", allocated);
exit(EXIT_FAILURE);
}
allocated += chunk_size;
} }
srand(time(NULL)); srand(time(NULL));
......
...@@ -115,6 +115,14 @@ int main(int argc, char *argv[]) { ...@@ -115,6 +115,14 @@ int main(int argc, char *argv[]) {
/* add binary path */ /* add binary path */
file_addp(appexepath); file_addp(appexepath);
/* Allocate 3GB of RAM so that -hopefully- 64bit porting errors arise */
printf("WARNING!!! Allocating a lot of RAM!!\n");
size_t limit = (size_t)(4 * 1024 * 1024) * 1024;
if(!malloc(limit)) {
printf("Could not allocated memory...\n");
exit(EXIT_FAILURE);
}
if (!standalone) { if (!standalone) {
/* Hand-made interpreter: search for DCB at EOF */ /* Hand-made interpreter: search for DCB at EOF */
fp = file_open(argv[0], "rb0"); fp = file_open(argv[0], "rb0");
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdint.h>
#include <math.h> #include <math.h>
#include <time.h> #include <time.h>
...@@ -127,29 +128,32 @@ int copytypes(void *dst, void *src, DCB_TYPEDEF *var, int nvars, int reps) { ...@@ -127,29 +128,32 @@ int copytypes(void *dst, void *src, DCB_TYPEDEF *var, int nvars, int reps) {
*/ */
static int copytype(void *dst, void *src, DCB_TYPEDEF *var) { static int copytype(void *dst, void *src, DCB_TYPEDEF *var) {
int count = 1; size_t count = 1;
int result = 0; int result = 0;
int n = 0; int n = 0;
for (;;) { for (;;) {
switch (var->BaseType[n]) { switch (var->BaseType[n]) {
case TYPE_POINTER:
memcpy(dst, src, 8 * count);
return (int)(8 * count);
case TYPE_FLOAT: case TYPE_FLOAT:
case TYPE_INT: case TYPE_INT:
case TYPE_DWORD: case TYPE_DWORD:
case TYPE_POINTER:
memcpy(dst, src, 4 * count); memcpy(dst, src, 4 * count);
return 4 * count; return (int)(4 * count);
case TYPE_WORD: case TYPE_WORD:
case TYPE_SHORT: case TYPE_SHORT:
memcpy(dst, src, 2 * count); memcpy(dst, src, 2 * count);
return 2 * count; return (int)(2 * count);
case TYPE_BYTE: case TYPE_BYTE:
case TYPE_SBYTE: case TYPE_SBYTE:
case TYPE_CHAR: case TYPE_CHAR:
memcpy(dst, src, count); memcpy(dst, src, count);
return count; return (int)(count);
case TYPE_STRING: case TYPE_STRING:
while (count--) { while (count--) {
...@@ -192,21 +196,21 @@ static int copytype(void *dst, void *src, DCB_TYPEDEF *var) { ...@@ -192,21 +196,21 @@ static int copytype(void *dst, void *src, DCB_TYPEDEF *var) {
* Copy struct data from src to dst, using the information varspace given * Copy struct data from src to dst, using the information varspace given
**/ **/
int pxt_copy_struct(INSTANCE *my, int *params) { int pxt_copy_struct(INSTANCE *my, intptr_t *params) {
return copytypes((void *)params[0], (void *)params[1], (DCB_TYPEDEF *)params[2], params[3], return copytypes((void *)params[0], (void *)params[1], (DCB_TYPEDEF *)params[2], params[3],
params[4]); params[4]);
} }
int pxt_internal_memcopy(INSTANCE *my, int *params) { int pxt_internal_memcopy(INSTANCE *my, intptr_t *params) {
memmove((void *)params[0], (void *)params[1], params[2]); memmove((void *)params[0], (void *)params[1], (size_t)params[2]);
return 1; return 1;
} }
int pxt_internal_copy_string_array(INSTANCE *my, int *params) { int pxt_internal_copy_string_array(INSTANCE *my, intptr_t *params) {
int n = params[2]; intptr_t n = params[2];
while (n--) { while (n--) {
((int *)(params[0]))[n] = ((int *)(params[1]))[n]; ((intptr_t *)(params[0]))[n] = ((intptr_t *)(params[1]))[n];
string_use(((int *)(params[0]))[n]); string_use( ((int *)(params[0]))[n] );
} }
return 1; return 1;
......
...@@ -196,14 +196,15 @@ int instance_go_all() { ...@@ -196,14 +196,15 @@ int instance_go_all() {
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
int instance_go(INSTANCE *r) { int instance_go(INSTANCE *r) {
if (!r) if (!r) {
return 0; return 0;
}
register int *ptr = r->codeptr; register int *ptr = r->codeptr;
int n, return_value = LOCDWORD(r, PROCESS_ID); int n, return_value = LOCDWORD(r, PROCESS_ID);
SYSPROC *p = NULL; SYSPROC *p = NULL;
INSTANCE *i = NULL; INSTANCE *i = NULL;
static char buffer[16]; static char buffer[16];
char *str = NULL; char *str = NULL;
int status; int status;
...@@ -217,18 +218,21 @@ int instance_go(INSTANCE *r) { ...@@ -217,18 +218,21 @@ int instance_go(INSTANCE *r) {
if (debug_DCB > 0) { if (debug_DCB > 0) {
PXTRTM_LOG("\n>>> Instance:%s ProcID:%d StackUsed:%u/%d\n", r->proc->name, PXTRTM_LOG("\n>>> Instance:%s ProcID:%d StackUsed:%u/%d\n", r->proc->name,
LOCDWORD(r, PROCESS_ID), (r->stack_ptr - r->stack) / sizeof(r->stack[0]), LOCDWORD(r, PROCESS_ID), (r->stack_ptr - r->stack) / sizeof(r->stack[0]),
(r->stack[0] & ~STACK_RETURN_VALUE)); (r->stack[0] & ~STACK_RETURN_VALUE));
} }
/* Hook */ /* Hook */
if (instance_pre_execute_hook_count) if (instance_pre_execute_hook_count) {
for (n = 0; n < instance_pre_execute_hook_count; n++) for (n = 0; n < instance_pre_execute_hook_count; n++) {
instance_pre_execute_hook_list[n](r); instance_pre_execute_hook_list[n](r);
}
}
/* Hook */ /* Hook */
if ((r->proc->breakpoint || r->breakpoint) && trace_instance != r) if ((r->proc->breakpoint || r->breakpoint) && trace_instance != r) {
debug_next = 1; debug_next = 1;
}
trace_sentence = -1; trace_sentence = -1;
...@@ -253,10 +257,12 @@ int instance_go(INSTANCE *r) { ...@@ -253,10 +257,12 @@ int instance_go(INSTANCE *r) {
if (debug_DCB > 0) { if (debug_DCB > 0) {
if (debug_DCB > 2) { if (debug_DCB > 2) {
int c = 45 - stack_dump(r) * 9; int c = 45 - stack_dump(r) * 9;
if (debug_DCB > 1) if (debug_DCB > 1) {
PXTRTM_LOG("%*.*s[%4u] ", c, c, "", (ptr - r->code)); PXTRTM_LOG("%*.*s[%4u] ", c, c, "", (ptr - r->code));
} else if (debug_DCB > 1) }
} else if (debug_DCB > 1) {
PXTRTM_LOG("[%4u] ", (ptr - r->code)); PXTRTM_LOG("[%4u] ", (ptr - r->code));
}
mnemonic_dump(*ptr, ptr[1]); mnemonic_dump(*ptr, ptr[1]);
} }
...@@ -320,8 +326,9 @@ int instance_go(INSTANCE *r) { ...@@ -320,8 +326,9 @@ int instance_go(INSTANCE *r) {
assert(i); assert(i);
for (n = 0; n < proc->params; n++) for (n = 0; n < proc->params; n++) {
PRIDWORD(i, 4 * n) = r->stack_ptr[-proc->params + n]; PRIDWORD(i, 4 * n) = r->stack_ptr[-proc->params + n];
}
r->stack_ptr -= proc->params; r->stack_ptr -= proc->params;
...@@ -357,10 +364,11 @@ int instance_go(INSTANCE *r) { ...@@ -357,10 +364,11 @@ int instance_go(INSTANCE *r) {
r->codeptr = ptr; r->codeptr = ptr;
/* If it don't was a CALL, then I set a flag in "len" for no return value */ /* If it don't was a CALL, then I set a flag in "len" for no return value */
if (ptr[-2] == MN_CALL) if (ptr[-2] == MN_CALL) {
r->stack[0] |= STACK_RETURN_VALUE; r->stack[0] |= STACK_RETURN_VALUE;
else } else {
r->stack[0] &= ~STACK_RETURN_VALUE; r->stack[0] &= ~STACK_RETURN_VALUE;
}
if (debug_next && trace_sentence != -1) { if (debug_next && trace_sentence != -1) {
force_debug = 1; force_debug = 1;
...@@ -371,8 +379,9 @@ int instance_go(INSTANCE *r) { ...@@ -371,8 +379,9 @@ int instance_go(INSTANCE *r) {
/* Wake up! */ /* Wake up! */
LOCDWORD(r, STATUS) &= ~STATUS_WAITING_MASK; LOCDWORD(r, STATUS) &= ~STATUS_WAITING_MASK;
if (child_is_alive) if (child_is_alive) {
i->called_by = NULL; i->called_by = NULL;
}
break; break;
} }
......
...@@ -27,8 +27,9 @@ ...@@ -27,8 +27,9 @@
* *
*/ */
#include <loadlib.h> /* Must be fist include */ #include <loadlib.h> /* Must be first include */
#include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
...@@ -42,9 +43,9 @@ ...@@ -42,9 +43,9 @@
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
extern int pxt_copy_struct(INSTANCE *my, int *params); extern int pxt_copy_struct(INSTANCE *my, intptr_t *params);
extern int pxt_internal_memcopy(INSTANCE *my, int *params); extern int pxt_internal_memcopy(INSTANCE *my, intptr_t *params);
extern int pxt_internal_copy_string_array(INSTANCE *my, int *params); extern int pxt_internal_copy_string_array(INSTANCE *my, intptr_t *params);
#include "sysprocs.h" #include "sysprocs.h"
#include "sysprocs_p.h" #include "sysprocs_p.h"
......
...@@ -120,7 +120,7 @@ static int kernel_version_type(void) { ...@@ -120,7 +120,7 @@ static int kernel_version_type(void) {
* and may or may not be an approximation. * and may or may not be an approximation.
*/ */
int modmem_memory_free(INSTANCE *my, int *params) { int modmem_memory_free(INSTANCE *my, intptr_t *params) {
#ifdef WIN32 #ifdef WIN32
MEMORYSTATUS mem; MEMORYSTATUS mem;
GlobalMemoryStatus(&mem); GlobalMemoryStatus(&mem);
...@@ -154,7 +154,7 @@ int modmem_memory_free(INSTANCE *my, int *params) { ...@@ -154,7 +154,7 @@ int modmem_memory_free(INSTANCE *my, int *params) {
* Return total number of bytes of physical memory * Return total number of bytes of physical memory
*/ */
int modmem_memory_total(INSTANCE *my, int *params) { int modmem_memory_total(INSTANCE *my, intptr_t *params) {
#ifdef WIN32 #ifdef WIN32
MEMORYSTATUS mem; MEMORYSTATUS mem;
GlobalMemoryStatus(&mem); GlobalMemoryStatus(&mem);
...@@ -200,36 +200,37 @@ int modmem_memory_total(INSTANCE *my, int *params) { ...@@ -200,36 +200,37 @@ int modmem_memory_total(INSTANCE *my, int *params) {
#endif #endif
} }
int modmem_memcmp(INSTANCE *my, int *params) { int modmem_memcmp(INSTANCE *my, intptr_t *params) {
return (memcmp((void *)params[0], (void *)params[1], params[2])); return (memcmp((void *)params[0], (void *)params[1], (size_t)params[2]));
} }
int modmem_memmove(INSTANCE *my, int *params) { int modmem_memmove(INSTANCE *my, intptr_t *params) {
memmove((void *)params[0], (void *)params[1], params[2]); memmove((void *)params[0], (void *)params[1], (size_t)params[2]);
return 1; return 1;
} }
int modmem_memcopy(INSTANCE *my, int *params) { int modmem_memcopy(INSTANCE *my, intptr_t *params) {
memcpy((void *)params[0], (void *)params[1], params[2]); memcpy((void *)params[0], (void *)params[1], (size_t)params[2]);
return 1; return 1;
} }
int modmem_memset(INSTANCE *my, int *params) { int modmem_memset(INSTANCE *my, intptr_t *params) {
memset((void *)params[0], params[1], params[2]); memset((void *)params[0], params[1], (size_t)params[2]);
return 1; return 1;
} }
int modmem_memsetw(INSTANCE *my, int *params) { int modmem_memsetw(INSTANCE *my, intptr_t *params) {
uint16_t *ptr = (uint16_t *)params[0]; uint16_t *ptr = (uint16_t *)params[0];
const uint16_t b = params[1]; const uint16_t b = params[1];
int n; intptr_t n;
for (n = params[2]; n; n--) for (n = params[2]; n; n--) {
*ptr++ = b; *ptr++ = b;
}
return 1; return 1;
} }
int modmem_memseti(INSTANCE *my, int *params) { int modmem_memseti(INSTANCE *my, intptr_t *params) {
uint32_t *ptr = (uint32_t *)params[0]; uint32_t *ptr = (uint32_t *)params[0];
const uint32_t b = params[1]; const uint32_t b = params[1];
int n; int n;
...@@ -239,19 +240,19 @@ int modmem_memseti(INSTANCE *my, int *params) { ...@@ -239,19 +240,19 @@ int modmem_memseti(INSTANCE *my, int *params) {
return 1; return 1;
} }
int modmem_calloc(INSTANCE *my, int *params) { int modmem_calloc(INSTANCE *my, intptr_t *params) {
return ((int)calloc(params[0], params[1])); return ((int)calloc(params[0], params[1]));
} }
int modmem_alloc(INSTANCE *my, int *params) { int modmem_alloc(INSTANCE *my, intptr_t *params) {
return ((int)malloc(params[0])); return ((int)malloc(params[0]));
} }
int modmem_realloc(INSTANCE *my, int *params) { int modmem_realloc(INSTANCE *my, intptr_t *params) {
return ((int)realloc((void *)params[0], params[1])); return ((int)realloc((void *)params[0], params[1]));
} }
int modmem_free(INSTANCE *my, int *params) { int modmem_free(INSTANCE *my, intptr_t *params) {
free((void *)params[0]); free((void *)params[0]);
return 1; return 1;
} }
......
...@@ -33,34 +33,18 @@ ...@@ -33,34 +33,18 @@
#include <pxtdl.h> #include <pxtdl.h>
#ifndef __PXTB__ #ifndef __PXTB__
extern int modmem_calloc( INSTANCE * my, int * params ); extern int modmem_calloc( INSTANCE * my, intptr_t * params );
extern int modmem_alloc( INSTANCE * my, int * params ); extern int modmem_alloc( INSTANCE * my, intptr_t * params );
extern int modmem_free( INSTANCE * my, int * params ); extern int modmem_free( INSTANCE * my, intptr_t * params );
extern int modmem_realloc( INSTANCE * my, int * params ); extern int modmem_realloc( INSTANCE * my, intptr_t * params );
extern int modmem_memcmp( INSTANCE * my, int * params ); extern int modmem_memcmp( INSTANCE * my, intptr_t * params );
extern int modmem_memset( INSTANCE * my, int * params ); extern int modmem_memset( INSTANCE * my, intptr_t * params );
extern int modmem_memsetw( INSTANCE * my, int * params ); extern int modmem_memsetw( INSTANCE * my, intptr_t * params );
extern int modmem_memseti( INSTANCE * my, int * params ); extern int modmem_memseti( INSTANCE * my, intptr_t * params );
extern int modmem_memsetw( INSTANCE * my, int * params ); extern int modmem_memcopy( INSTANCE * my, intptr_t * params );
extern int modmem_memseti( INSTANCE * my, int * params ); extern int modmem_memmove( INSTANCE * my, intptr_t * params );
extern int modmem_memcopy( INSTANCE * my, int * params ); extern int modmem_memory_free( INSTANCE * my, intptr_t * params );
extern int modmem_memmove( INSTANCE * my, int * params ); extern int modmem_memory_total( INSTANCE * my, intptr_t * params );
extern int modmem_memory_free( INSTANCE * my, int * params );
extern int modmem_memory_total( INSTANCE * my, int * params );
extern int modmem_calloc( INSTANCE * my, int * params );
extern int modmem_alloc( INSTANCE * my, int * params );
extern int modmem_free( INSTANCE * my, int * params );
extern int modmem_realloc( INSTANCE * my, int * params );
extern int modmem_memcmp( INSTANCE * my, int * params );
extern int modmem_memset( INSTANCE * my, int * params );
extern int modmem_memsetw( INSTANCE * my, int * params );
extern int modmem_memseti( INSTANCE * my, int * params );
extern int modmem_memsetw( INSTANCE * my, int * params );
extern int modmem_memseti( INSTANCE * my, int * params );
extern int modmem_memcopy( INSTANCE * my, int * params );
extern int modmem_memmove( INSTANCE * my, int * params );
extern int modmem_memory_free( INSTANCE * my, int * params );
extern int modmem_memory_total( INSTANCE * my, int * params );
#endif #endif
DLSYSFUNCS __pxtexport( mod_mem, exported_functions )[] = { DLSYSFUNCS __pxtexport( mod_mem, exported_functions )[] = {
......
...@@ -84,8 +84,9 @@ int bgd_move_window(INSTANCE *my, int *params) { ...@@ -84,8 +84,9 @@ int bgd_move_window(INSTANCE *my, int *params) {
/* --------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------- */
int bgd_get_window_pos(INSTANCE *my, int *params) { int bgd_get_window_pos(INSTANCE *my, int *params) {
if (full_screen) if (full_screen) {
return -1; return -1;
}
int x, y; int x, y;
......
...@@ -5,6 +5,9 @@ if (${CMAKE_C_COMPILER_ID} MATCHES "GNU" OR ...@@ -5,6 +5,9 @@ if (${CMAKE_C_COMPILER_ID} MATCHES "GNU" OR
${CMAKE_C_COMPILER_ID} MATCHES "Clang" OR ${CMAKE_C_COMPILER_ID} MATCHES "Clang" OR
${CMAKE_C_COMPILER_ID} MATCHES "AppleClang") ${CMAKE_C_COMPILER_ID} MATCHES "AppleClang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11 -Wall -Wshadow -fno-strict-aliasing") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11 -Wall -Wshadow -fno-strict-aliasing")
if(WIN32)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--dynamicbase -Wl,--nxcompat -Wl,--high-entropy-va")
endif()
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_DEBUG} -g") set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_DEBUG} -g")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_RELEASE} -O2") set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_RELEASE} -O2")
elseif (MSVC) elseif (MSVC)
......