ptrdiff_t insert_opcode2(unsigned int f, INT32 b, INT32 c, INT32 current_line, struct pike_string *current_file) { p_instr *p; #ifdef PIKE_DEBUG if(!hasarg2(f) && c) Pike_fatal("hasarg2(%d) is wrong!\n",f); #endif p=(p_instr *)low_make_buf_space(sizeof(p_instr), &instrbuf); #ifdef PIKE_DEBUG if(!instrbuf.s.len) Pike_fatal("Low make buf space failed!!!!!!\n"); #endif p->opcode=f; p->line=current_line; copy_shared_string(p->file, dmalloc_touch_named(struct pike_string *, current_file, "insert_opcode")); p->arg=b; p->arg2=c; return p - (p_instr *)instrbuf.s.str; }
void sparc_debug_check_registers(int state, struct Pike_interpreter_struct *cached_ip, struct pike_frame *cached_fp, struct svalue *cached_sp, struct svalue **cached_mark_sp) { if (((state & SPARC_CODEGEN_IP_IS_SET) && (cached_ip != Pike_interpreter_pointer)) || ((state & SPARC_CODEGEN_FP_IS_SET) && (cached_fp != Pike_interpreter.frame_pointer)) || ((state & SPARC_CODEGEN_SP_IS_SET) && (cached_sp != Pike_interpreter.stack_pointer)) || ((state & SPARC_CODEGEN_MARK_SP_IS_SET) && (cached_mark_sp != Pike_interpreter.mark_stack_pointer))) { Pike_fatal("Bad machine code cache key (0x%04x):\n" "Cached: ip:0x%08x, fp:0x%08x, sp:0x%08x, m_sp:0x%08x\n" " Real: ip:0x%08x, fp:0x%08x, sp:0x%08x, m_sp:0x%08x\n", state, (INT32)cached_ip, (INT32)cached_fp, (INT32)cached_sp, (INT32)cached_mark_sp, (INT32)Pike_interpreter_pointer, (INT32)Pike_interpreter.frame_pointer, (INT32)Pike_interpreter.stack_pointer, (INT32)Pike_interpreter.mark_stack_pointer); } }
HCHAR *NameNH(boyer_moore_hubbe)(struct boyer_moore_hubbe_searcher *s, HCHAR *haystack, ptrdiff_t haystacklen) { ptrdiff_t i=s->plen-1; ptrdiff_t hlen=haystacklen; if(NEEDLELEN > s->plen) hlen -= NEEDLELEN-s->plen; restart: while(i<hlen) { ptrdiff_t k,j; if((k=s->d1[ NameNH(BMHASH)( haystack[i] ) ])) i+=k; else { #if NSHIFT == 0 j=s->plen-1; #ifdef PIKE_DEBUG if(NEEDLE[j] != haystack[i]) Pike_fatal("T2BM failed!\n"); #endif #else i++; j=s->plen; #endif while(NEEDLE[--j] == haystack[--i]) { if(!j) { if(NEEDLELEN > s->plen) { if(!NameNH(MEMCMP)(NEEDLE+s->plen, haystack+i+s->plen, NEEDLELEN-s->plen)) { return haystack+i; }else{ /* this can be optimized... */ i+=s->plen; goto restart; } }else{ return haystack+i; } } } i+= (s->d1[ NameNH(BMHASH)(haystack[i]) ] >= s->d2[j]) ? (s->d1[ NameNH(BMHASH)(haystack[i]) ]): (s->d2[j]); } } return 0; }
ptrdiff_t insert_opcode0(int f,int current_line, struct pike_string *current_file) { #ifdef PIKE_DEBUG if(hasarg(f)) Pike_fatal("hasarg(%d) is wrong!\n",f); #endif return insert_opcode1(f,0,current_line, current_file); }
ptrdiff_t insert_opcode(p_instr *opcode) { /* Note: Steals references from opcode. */ p_instr *p = (p_instr *)low_make_buf_space(sizeof(p_instr), &instrbuf); if (!p) Pike_fatal("Out of memory in peep.\n"); *p = *opcode; num_instrs++; return p - (p_instr *)instrbuf.s.str; }
static void bootstrap_push_int64 (INT64 i) { if(i == DO_NOT_WARN((INT_TYPE)i)) { push_int(DO_NOT_WARN((INT_TYPE)i)); } else Pike_fatal ("Failed to convert large integer (Gmp.bignum not loaded).\n"); }
void update_arg(int instr,INT32 arg) { p_instr *p; #ifdef PIKE_DEBUG if(instr > (long)instrbuf.s.len / (long)sizeof(p_instr) || instr < 0) Pike_fatal("update_arg outside known space.\n"); #endif p=(p_instr *)instrbuf.s.str; p[instr].arg=arg; }
static int got_port_event (struct fd_callback_box *box, int DEBUGUSED(event)) { struct port *p = (struct port *) box; #ifdef PIKE_DEBUG #ifndef __NT__ if(!query_nonblocking(p->box.fd)) Pike_fatal("Port is in blocking mode in port accept callback!!!\n"); #endif if (event != PIKE_FD_READ) Pike_fatal ("Got unexpected event %d.\n", event); #endif p->my_errno = errno; /* Propagate backend setting. */ p->immediate_cnt++; push_svalue (&p->id); apply_svalue(& p->accept_callback, 1); pop_stack(); return 0; }
void init_opcodes(void) { unsigned int i; #ifdef PIKE_DEBUG int fatal_later=0; #ifdef INSTR_PROFILING instr_counter_storage=init_instr_storage_pointers(p_flag); #endif #endif for(i=0; i<NELEM(instr_names);i++) { #ifdef PIKE_DEBUG if(instr_names[i].token >= F_MAX_INSTR) { fprintf(stderr,"Error in instr_names[%u]\n\n",i); fatal_later++; } if(instrs[instr_names[i].token - F_OFFSET].name) { fprintf(stderr,"Duplicate name for %s\n",instr_names[i].word); fatal_later++; } #endif instrs[instr_names[i].token - F_OFFSET].name = instr_names[i].word; instrs[instr_names[i].token - F_OFFSET].flags=instr_names[i].flags; #ifdef PIKE_USE_MACHINE_CODE instrs[instr_names[i].token - F_OFFSET].address=instr_names[i].address; #endif } #ifdef PIKE_USE_MACHINE_CODE instrs_checksum = hashmem((const unsigned char*)instrs, sizeof(instrs), sizeof(struct instr)); /* fprintf(stderr, "Instruction checksum: %d\n", instrs_checksum); */ #endif /* PIKE_USE_MACHINE_CODE */ #ifdef PIKE_DEBUG for(i=1; i<F_MAX_OPCODE-F_OFFSET;i++) { if(!instrs[i].name) { fprintf(stderr,"Opcode %d does not have a name.\n",i); fatal_later++; } } if(fatal_later) Pike_fatal("Found %d errors in instrs.\n",fatal_later); #endif }
ptrdiff_t insert_opcode1(unsigned int f, INT32 b, INT32 current_line, struct pike_string *current_file) { #ifdef PIKE_DEBUG if(!hasarg(f) && b) Pike_fatal("hasarg(%d) is wrong!\n",f); #endif return insert_opcode2(f,b,0,current_line,current_file); }
/* Unload all the dynamically loaded modules. */ void free_dynamic_load(void) { #ifdef USE_DYNAMIC_MODULES while(dynamic_module_list) { struct module_list *tmp=dynamic_module_list; dynamic_module_list=tmp->next; #ifndef DEBUG_MALLOC dlclose(tmp->module); #endif #ifdef PIKE_DEBUG if (tmp->module_prog) Pike_fatal ("There's still a program for a dynamic module.\n"); #endif free((char *)tmp); } #endif }
PMOD_EXPORT SearchMojt compile_memsearcher(PCHARP needle, ptrdiff_t needlelen, int max_haystacklen, struct pike_string *hashkey) { switch(needle.shift) { case 0: return compile_memsearcher0((p_wchar0*)needle.ptr, needlelen, max_haystacklen,hashkey); case 1: return compile_memsearcher1((p_wchar1*)needle.ptr, needlelen, max_haystacklen,hashkey); case 2: return compile_memsearcher2((p_wchar2*)needle.ptr, needlelen, max_haystacklen,hashkey); } #ifdef PIKE_DEBUG Pike_fatal("Illegal shift\n"); #endif /* NOTREACHED */ }
PMOD_EXPORT void pike_init_memsearch(struct pike_mem_searcher *s, PCHARP needle, ptrdiff_t needlelen, ptrdiff_t max_haystacklen) { switch(needle.shift) { case 0: init_memsearch0(s,(p_wchar0*)needle.ptr, needlelen, max_haystacklen); return; case 1: init_memsearch1(s,(p_wchar1*)needle.ptr, needlelen, max_haystacklen); return; case 2: init_memsearch2(s,(p_wchar2*)needle.ptr, needlelen, max_haystacklen); return; } #ifdef PIKE_DEBUG Pike_fatal("Illegal shift\n"); #endif }
/* Read some data from the blocking object. * */ static int read_some_data(void) { struct pipe *this = THIS; struct input * i = this->firstinput; if (!i || i->type != I_BLOCKING_OBJ) { Pike_fatal("PIPE: read_some_data(): Bad input type!\n"); return -1; } push_int(8192); push_int(1); /* We don't care if we don't get all 8192 bytes. */ apply(i->u.obj, "read", 2); if ((sp[-1].type == T_STRING) && (sp[-1].u.string->len > 0)) { append_buffer(sp[-1].u.string); pop_stack(); THIS->sleeping = 1; return(1); /* Success */ } /* FIXME: Should we check the return value here? */ pop_stack(); /* EOF */ return(0); /* EOF */ }
static void make_colors(void) { static struct color { int r,g,b; char *name; struct pike_string *pname; } c[]={ #define COLOR(name,R,G,B) \ {R,G,B,name,NULL}, #include "colors.h" #undef COLOR }; int i; const int n=sizeof(c)/sizeof(c[0]); for (i=0; (size_t)i<sizeof(html_color)/sizeof(html_color[0]); i++) html_color[i].pname=make_shared_string(html_color[i].name); for (i=0;i<n;i++) { struct color_struct *cs; push_text(c[i].name); copy_shared_string(c[i].pname,sp[-1].u.string); push_object(clone_object(image_color_program,0)); cs=get_storage(sp[-1].u.object,image_color_program); cs->rgb.r=(COLORTYPE)c[i].r; cs->rgb.g=(COLORTYPE)c[i].g; cs->rgb.b=(COLORTYPE)c[i].b; RGB_TO_RGBL(cs->rgbl,cs->rgb); copy_shared_string(cs->name,c[i].pname); } f_aggregate_mapping(n*2); colors=sp[-1].u.mapping; sp--; dmalloc_touch_svalue(sp); for (i=0;i<n;i++) { push_int(c[i].r); push_int(c[i].g); push_int(c[i].b); f_aggregate(3); } f_aggregate(n); colortable=clone_object(image_colortable_program,1); if (!colortable) Pike_fatal("couldn't create colortable\n"); push_int(12); push_int(12); push_int(12); push_int(1); safe_apply(colortable,"cubicles",4); pop_stack(); for (i=0;i<n;i++) push_string(c[i].pname); f_aggregate(n); colornames=sp[-1].u.array; sp--; dmalloc_touch_svalue(sp); }
INT32 assemble(int store_linenumbers) { INT32 entry_point; INT32 max_label=-1,tmp; INT32 *labels, *jumps, *uses, *aliases; ptrdiff_t e, length; p_instr *c; #ifdef PIKE_PORTABLE_BYTECODE struct pike_string *tripples = NULL; #endif /* PIKE_PORTABLE_BYTECODE */ #ifdef PIKE_DEBUG INT32 max_pointer=-1; int synch_depth = 0; size_t fun_start = Pike_compiler->new_program->num_program; #endif int relabel; int reoptimize = relabel = !(debug_options & NO_PEEP_OPTIMIZING); c=(p_instr *)instrbuf.s.str; length=instrbuf.s.len / sizeof(p_instr); #ifdef PIKE_DEBUG if((a_flag > 1 && store_linenumbers) || a_flag > 2) { for (e = 0; e < length; e++) { if (c[e].opcode == F_POP_SYNCH_MARK) synch_depth--; fprintf(stderr, "~~~%4d %4lx %*s", c[e].line, DO_NOT_WARN((unsigned long)e), synch_depth, ""); dump_instr(c+e); fprintf(stderr,"\n"); if (c[e].opcode == F_SYNCH_MARK) synch_depth++; } if (synch_depth) { Pike_fatal("Unbalanced sync_mark/pop_sync_mark: %d\n", synch_depth); } } #endif #ifdef PIKE_PORTABLE_BYTECODE /* No need to do this for constant evaluations. */ if (store_linenumbers) { p_wchar2 *current_tripple; struct pike_string *previous_file = NULL; int previous_line = 0; ptrdiff_t num_linedirectives = 0; /* Count the number of F_FILENAME/F_LINE pseudo-ops we need to add. */ for (e=0; e < length; e++) { if (c[e].file != previous_file) { previous_file = dmalloc_touch_named(struct pike_string *, c[e].file, "prev_file"); num_linedirectives++; } if (c[e].line != previous_line) { previous_line = c[e].line; num_linedirectives++; } } /* fprintf(stderr, "length:%d directives:%d\n", * length, num_linedirectives); */ if (!(tripples = begin_wide_shared_string(3*(length+num_linedirectives), 2))) { Pike_fatal("Failed to allocate wide string of length %d 3*(%d + %d).\n", 3*(length+num_linedirectives), length, num_linedirectives); } previous_file = NULL; previous_line = 0; current_tripple = STR2(tripples); for (e = 0; e < length; e++) { if (c[e].file != previous_file) { current_tripple[0] = F_FILENAME; current_tripple[1] = store_prog_string(dmalloc_touch_named(struct pike_string *, c[e].file, "store_prog_string")); current_tripple[2] = 0; current_tripple += 3; previous_file = dmalloc_touch_named(struct pike_string *, c[e].file, "prev_file"); } if (c[e].line != previous_line) { current_tripple[0] = F_LINE; current_tripple[1] = c[e].line; current_tripple[2] = 0; current_tripple += 3; previous_line = c[e].line; } current_tripple[0] = c[e].opcode; current_tripple[1] = c[e].arg; current_tripple[2] = c[e].arg2; current_tripple += 3; }
/*! @decl program load_module(string module_name) *! *! Load a binary module. *! *! This function loads a module written in C or some other language *! into Pike. The module is initialized and any programs or constants *! defined will immediately be available. *! *! When a module is loaded the C function @tt{pike_module_init()@} will *! be called to initialize it. When Pike exits @tt{pike_module_exit()@} *! will be called. These two functions @b{must@} be available in the module. *! *! @note *! The current working directory is normally not searched for *! dynamic modules. Please use @expr{"./name.so"@} instead of just *! @expr{"name.so"@} to load modules from the current directory. */ void f_load_module(INT32 args) { extern int global_callable_flags; void *module; modfun init, exit; struct module_list *new_module; struct pike_string *module_name; ONERROR err; module_name = Pike_sp[-args].u.string; if((Pike_sp[-args].type != T_STRING) || (module_name->size_shift) || string_has_null(module_name)) { Pike_error("Bad argument 1 to load_module()\n"); } { struct module_list *mp; for (mp = dynamic_module_list; mp; mp = mp->next) if (mp->name == module_name && mp->module_prog) { pop_n_elems(args); ref_push_program(mp->module_prog); return; } } /* Removing RTLD_GLOBAL breaks some PiGTK themes - Hubbe */ /* Using RTLD_LAZY is faster, but makes it impossible to * detect linking problems at runtime.. */ module=dlopen(module_name->str, RTLD_NOW /*|RTLD_GLOBAL*/ ); if(!module) { struct object *err_obj = low_clone (module_load_error_program); #define LOADERR_STRUCT(OBJ) \ ((struct module_load_error_struct *) (err_obj->storage + module_load_error_offset)) const char *err = dlerror(); if (err) { if (err[strlen (err) - 1] == '\n') push_string (make_shared_binary_string (err, strlen (err) - 1)); else push_text (err); } else push_constant_text ("Unknown reason"); add_ref (LOADERR_STRUCT (err_obj)->path = Pike_sp[-args - 1].u.string); add_ref (LOADERR_STRUCT (err_obj)->reason = Pike_sp[-1].u.string); if (Pike_sp[-args].u.string->len < 1024) { throw_error_object (err_obj, "load_module", Pike_sp - args - 1, args, "load_module(\"%s\") failed: %s\n", module_name->str, Pike_sp[-1].u.string->str); } else { throw_error_object (err_obj, "load_module", Pike_sp - args - 1, args, "load_module() failed: %s\n", Pike_sp[-1].u.string->str); } } #ifdef PIKE_DEBUG { struct module_list *mp; for (mp = dynamic_module_list; mp; mp = mp->next) if (mp->module == module && mp->module_prog) { fprintf(stderr, "load_module(): Module loaded twice:\n" "Old name: %s\n" "New name: %s\n", mp->name->str, module_name->str); pop_n_elems(args); ref_push_program(mp->module_prog); return; } } #endif /* PIKE_DEBUG */ init = CAST_TO_FUN(dlsym(module, "pike_module_init")); if (!init) { init = CAST_TO_FUN(dlsym(module, "_pike_module_init")); if (!init) { dlclose(module); Pike_error("pike_module_init missing in dynamic module \"%S\".\n", module_name); } } exit = CAST_TO_FUN(dlsym(module, "pike_module_exit")); if (!exit) { exit = CAST_TO_FUN(dlsym(module, "_pike_module_exit")); if (!exit) { dlclose(module); Pike_error("pike_module_exit missing in dynamic module \"%S\".\n", module_name); } } #if defined(__NT__) && defined(_M_IA64) { fprintf(stderr, "pike_module_init: 0x%p\n" " func: 0x%p\n" " gp: 0x%p\n", init, ((void **)init)[0], ((void **)init)[1]); fprintf(stderr, "pike_module_exit: 0x%p\n" " func: 0x%p\n" " gp: 0x%p\n", exit, ((void **)exit)[0], ((void **)exit)[1]); } #endif /* __NT__ && _M_IA64 */ new_module=ALLOC_STRUCT(module_list); new_module->next=dynamic_module_list; dynamic_module_list=new_module; new_module->module=module; copy_shared_string(new_module->name, Pike_sp[-args].u.string); new_module->module_prog = NULL; new_module->init=init; new_module->exit=exit; enter_compiler(new_module->name, 1); start_new_program(); global_callable_flags|=CALLABLE_DYNAMIC; #ifdef PIKE_DEBUG { struct svalue *save_sp=Pike_sp; #endif SET_ONERROR(err, cleanup_compilation, NULL); #if defined(__NT__) && defined(_M_IA64) fprintf(stderr, "Calling pike_module_init()...\n"); #endif /* __NT__ && _M_IA64 */ (*(modfun)init)(); #if defined(__NT__) && defined(_M_IA64) fprintf(stderr, "pike_module_init() done.\n"); #endif /* __NT__ && _M_IA64 */ UNSET_ONERROR(err); #ifdef PIKE_DEBUG if(Pike_sp != save_sp) Pike_fatal("load_module(%s) left %ld droppings on stack!\n", module_name->str, PTRDIFF_T_TO_LONG(Pike_sp - save_sp)); } #endif pop_n_elems(args); { struct program *p = end_program(); exit_compiler(); if (p) { if ( #if 0 p->num_identifier_references #else /* !0 */ 1 #endif /* 0 */ ) { push_program(p); add_ref(new_module->module_prog = Pike_sp[-1].u.program); } else { /* No identifier references -- Disabled module. */ free_program(p); push_undefined(); } } else { /* Initialization failed. */ new_module->exit(); dlclose(module); dynamic_module_list = new_module->next; free_string(new_module->name); free(new_module); Pike_error("Failed to initialize dynamic module \"%S\".\n", module_name); } } }