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