pike.git / src / program.c

version» Context lines:

pike.git/src/program.c:1840:   #define MAXVARS(NUMTYPE) \    (NUMTYPE)(sizeof(NUMTYPE)==1?254: (sizeof(NUMTYPE)==2?65534:4294967294U))   #endif      #ifdef PIKE_USE_MACHINE_CODE   /* Special cases for low_add_to_program and add_to_program since    * many OSes require us to use mmap to allocate memory for our    * machine code. For decoding efficiency we also want a multi copy    * variant to be used by decode().    */ + #if !defined(HAVE_PTHREAD_JIT_WRITE_PROTECT_NP) && !defined(pthread_jit_write_protect_np) + #define phtread_jit_write_protect_np(enable) do{}while(0) + #endif   #define BAR(NUMTYPE,TYPE,ARGTYPE,NAME) \   void PIKE_CONCAT(low_add_to_,NAME) (struct program_state *state, \    TYPE ARG) { \    NUMTYPE m = state->malloc_size_program->PIKE_CONCAT(num_,NAME); \    CHECK_FOO(NUMTYPE,TYPE,NAME); \    if(m == state->new_program->PIKE_CONCAT(num_,NAME)) { \    TYPE *tmp; \    if(m==MAXVARS(NUMTYPE)) { \    yyerror("Too many " #NAME "."); \    return; \    } \    m = MINIMUM(m*2+1,MAXVARS(NUMTYPE)); \    tmp = mexec_realloc(state->new_program->NAME, sizeof(TYPE) * m); \    if(!tmp) Pike_fatal("Out of memory.\n"); \    PIKE_CONCAT(RELOCATE_,NAME)(state->new_program, tmp); \    state->malloc_size_program->PIKE_CONCAT(num_,NAME)=m; \    state->new_program->NAME=tmp; \    } \ -  +  pthread_jit_write_protect_np(0); \    state->new_program-> \    NAME[state->new_program->PIKE_CONCAT(num_,NAME)++]=(ARG); \ -  +  pthread_jit_write_protect_np(1); \   } \   void PIKE_CONCAT(low_add_many_to_,NAME) (struct program_state *state, \    TYPE *ARG, NUMTYPE cnt) { \    NUMTYPE m = state->malloc_size_program->PIKE_CONCAT(num_,NAME); \    CHECK_FOO(NUMTYPE,TYPE,NAME); \    if((m + cnt) > state->new_program->PIKE_CONCAT(num_,NAME)) { \    TYPE *tmp; \    NUMTYPE n = m; \    do { \    if(n==MAXVARS(NUMTYPE)) { \
pike.git/src/program.c:1882:    } \    n = MINIMUM(n*2+1,MAXVARS(NUMTYPE)); \    } while (m + cnt > n); \    m = n; \    tmp = mexec_realloc(state->new_program->NAME, sizeof(TYPE) * m); \    if(!tmp) Pike_fatal("Out of memory.\n"); \    PIKE_CONCAT(RELOCATE_,NAME)(state->new_program, tmp); \    state->malloc_size_program->PIKE_CONCAT(num_,NAME)=m; \    state->new_program->NAME=tmp; \    } \ +  pthread_jit_write_protect_np(0); \    memcpy(state->new_program->NAME + \    state->new_program->PIKE_CONCAT(num_,NAME), \    ARG, sizeof(TYPE) * cnt); \ -  +  pthread_jit_write_protect_np(1); \    state->new_program->PIKE_CONCAT(num_,NAME) += cnt; \   } \   void PIKE_CONCAT(add_to_,NAME) (ARGTYPE ARG) { \    PIKE_CONCAT(low_add_to_,NAME) ( Pike_compiler, ARG ); \   }   #else /* !PIKE_USE_MACHINE_CODE */   #define BAR(NUMTYPE,TYPE,ARGTYPE,NAME) \    FOO(NUMTYPE,TYPE,ARGTYPE,NAME) \    void PIKE_CONCAT(low_add_many_to_,NAME) (struct program_state *state, \    TYPE *ARG, NUMTYPE cnt) { \
pike.git/src/program.c:5304:      /**    * Set a callback to be called when this program is cloned.    *    * This function is obsolete; see pike_set_prog_event_callback for    * details.    */   PMOD_EXPORT void set_init_callback(void (*init)(struct object *))   {    add_compat_event_handler(); + #ifdef HAVE_PTHREAD_JIT_WRITE_PROTECT_NP +  pthread_jit_write_protect_np(0); + #endif    ((oldhandlertype *)Pike_compiler->new_program->program)[PROG_EVENT_INIT]=init; -  + #ifdef HAVE_PTHREAD_JIT_WRITE_PROTECT_NP +  pthread_jit_write_protect_np(1); + #endif   }      /**    * Set a callback to be called when clones of this program are    * destructed.    *    * This function is obsolete; see pike_set_prog_event_callback for    * details.    *    * Note: If the callback only does very trivial stuff, like freeing or
pike.git/src/program.c:5327:    * Pike_compiler->new_program->flags &= ~PROGRAM_LIVE_OBJ;    *    * after the set_exit_callback call. That allows the gc to operate    * more efficiently, but the effect is that the callback might be    * called out of order for PROG_EVENT_EXIT events; see the docs for    * PROGRAM_LIVE_OBJ in program.h for further details.    */   PMOD_EXPORT void set_exit_callback(void (*exit)(struct object *))   {    add_compat_event_handler(); + #ifdef HAVE_PTHREAD_JIT_WRITE_PROTECT_NP +  pthread_jit_write_protect_np(0); + #endif    ((oldhandlertype *)Pike_compiler->new_program->program)[PROG_EVENT_EXIT]=exit; -  + #ifdef HAVE_PTHREAD_JIT_WRITE_PROTECT_NP +  pthread_jit_write_protect_np(1); + #endif    Pike_compiler->new_program->flags |= PROGRAM_LIVE_OBJ;   }      /**    * This callback is used by the gc to traverse all references to    * things in memory. It should call some gc_recurse_* function exactly    * once for each reference that the pike internals doesn't know about.    *    * If a reference is shared between objects, it should be traversed    * once for every instance sharing it.
pike.git/src/program.c:5363:    * If the allocated memory is shared between objects then it gets more    * complicated and you need to write visit_thing_fn callbacks. See    * e.g. visit_mapping and visit_mapping_data for how to do that.    *    * This function is obsolete; see pike_set_prog_event_callback for    * details.    */   PMOD_EXPORT void set_gc_recurse_callback(void (*m)(struct object *))   {    add_compat_event_handler(); + #ifdef HAVE_PTHREAD_JIT_WRITE_PROTECT_NP +  pthread_jit_write_protect_np(0); + #endif    ((oldhandlertype *)Pike_compiler->new_program->program)[PROG_EVENT_GC_RECURSE]=m; -  + #ifdef HAVE_PTHREAD_JIT_WRITE_PROTECT_NP +  pthread_jit_write_protect_np(1); + #endif   }      /**    * This callback is used by the gc to count all references to things    * in memory. It should call gc_check, gc_check_(weak_)svalues or    * gc_check_(weak_)short_svalue exactly once for each reference that    * the pike internals don't know about.    *    * If a reference is shared between objects, it should be counted once    * for all shared instances. The return value from gc_check is useful
pike.git/src/program.c:5385:    * argument (it is perfectly fine to use gc_check on things that the    * pike core doesn't know about, but they must have an INT32 refcount    * first).    *    * This function is obsolete; see pike_set_prog_event_callback for    * details.    */   PMOD_EXPORT void set_gc_check_callback(void (*m)(struct object *))   {    add_compat_event_handler(); + #ifdef HAVE_PTHREAD_JIT_WRITE_PROTECT_NP +  pthread_jit_write_protect_np(0); + #endif    ((oldhandlertype *)Pike_compiler->new_program->program)[PROG_EVENT_GC_CHECK]=m; -  + #ifdef HAVE_PTHREAD_JIT_WRITE_PROTECT_NP +  pthread_jit_write_protect_np(1); + #endif   }      /**    * Set a callback to be called when any of the special program events    * occur. The event type is sent as an integer argument. The events    * include, but might not be limited to, the following:    *    * PROG_EVENT_INIT    * An object is being cloned from the program. See set_init_callback    * for details.