mux/src/alloc.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define POOL_LBUF   0
#define POOL_SBUF   1
#define POOL_MBUF   2
#define POOL_BOOL   3
#define POOL_DESC   4
#define POOL_QENTRY   5
#define POOL_PCACHE   6
#define NUM_POOLS   7
#define LBUF_SIZE   8000
#define GBUF_SIZE   1024
#define MBUF_SIZE   400
#define PBUF_SIZE   128
#define SBUF_SIZE   64
#define alloc_lbuf(s)   pool_alloc_lbuf(s, __FILE__, __LINE__)
#define free_lbuf(b)   pool_free_lbuf((char *)(b), __FILE__, __LINE__)
#define alloc_mbuf(s)   pool_alloc(POOL_MBUF,s, __FILE__, __LINE__)
#define free_mbuf(b)   pool_free(POOL_MBUF,(char *)(b), __FILE__, __LINE__)
#define alloc_sbuf(s)   pool_alloc(POOL_SBUF,s, __FILE__, __LINE__)
#define free_sbuf(b)   pool_free(POOL_SBUF,(char *)(b), __FILE__, __LINE__)
#define alloc_bool(s)   (struct boolexp *)pool_alloc(POOL_BOOL,s, __FILE__, __LINE__)
#define free_bool(b)   pool_free(POOL_BOOL,(char *)(b), __FILE__, __LINE__)
#define alloc_qentry(s)   (BQUE *)pool_alloc(POOL_QENTRY,s, __FILE__, __LINE__)
#define free_qentry(b)   pool_free(POOL_QENTRY,(char *)(b), __FILE__, __LINE__)
#define alloc_pcache(s)   (PCACHE *)pool_alloc(POOL_PCACHE,s, __FILE__, __LINE__)
#define free_pcache(b)   pool_free(POOL_PCACHE,(char *)(b), __FILE__, __LINE__)
#define safe_copy_chr(src, buff, bufp, nSizeOfBuffer)
#define safe_str(s, b, p)   safe_copy_str_lbuf(s,b,p)
#define safe_chr(c, b, p)   safe_copy_chr((unsigned char)(c),b,p,(LBUF_SIZE-1))
#define safe_bool(c, b, p)   safe_chr(((c) ? '1' : '0'),b,p)
#define safe_sb_str(s, b, p)   safe_copy_str(s,b,p,(SBUF_SIZE-1))
#define safe_sb_chr(c, b, p)   safe_copy_chr(c,b,p,(SBUF_SIZE-1))
#define safe_mb_str(s, b, p)   safe_copy_str(s,b,p,(MBUF_SIZE-1))
#define safe_mb_chr(c, b, p)   safe_copy_chr(c,b,p,(MBUF_SIZE-1))

Functions

void pool_init (int, int)
char * pool_alloc (int, const char *, const char *, int)
char * pool_alloc_lbuf (const char *, const char *, int)
void pool_free (int, char *, const char *, int)
void pool_free_lbuf (char *, const char *, int)
void list_bufstats (dbref)
void list_buftrace (dbref)
void pool_reset (void)


Define Documentation

#define alloc_bool (  )     (struct boolexp *)pool_alloc(POOL_BOOL,s, __FILE__, __LINE__)

Definition at line 43 of file alloc.h.

Referenced by dup_bool(), getboolexp1(), parse_boolexp_E(), parse_boolexp_F(), parse_boolexp_L(), parse_boolexp_T(), and test_atr().

#define alloc_lbuf (  )     pool_alloc_lbuf(s, __FILE__, __LINE__)

Definition at line 37 of file alloc.h.

Referenced by add_folder_name(), add_mail_message(), add_player_name(), add_prefix(), announce_connect(), announce_disconnect(), atr_get_LEN(), atr_pget_LEN(), badname_list(), BuildChannelMessage(), CF_HAND(), cf_log_syntax(), cf_set(), cf_status_from_succfail(), check_connect(), check_dead_refs(), check_filter(), Commer(), db_read(), debug_examine(), default_handler(), delete_player_name(), delim_check(), dflt_from_msg(), did_it(), display_flagtab(), display_nametab(), display_powertab(), do_cemit(), do_chboot(), do_chown(), do_command(), do_comsystem(), do_destroy(), do_dolist(), do_drop(), do_edit(), do_entrances(), do_examine(), do_hook(), do_icmd(), do_if(), do_inventory(), do_kill(), do_link(), do_log(), do_mail_cc(), do_mail_quick(), do_mail_read(), do_mail_reply(), do_malias_list(), do_mvattr(), do_newpassword(), do_page(), do_pemit_single(), do_postpend(), do_prepend(), do_prog(), do_search(), do_set(), do_shout(), do_switch(), do_think(), do_use(), edit_string(), edit_string_ansi(), encrypt_logindata(), eval_boolexp(), fcache_load(), fcache_read(), filter_handler(), fork_and_dump(), FUNCTION(), fwdlist_ck(), fwdlist_get(), fwdlist_load(), get_exit_dest(), get_folder_name(), get_folder_number(), get_handler(), get_list(), get_obj_and_lock(), get_slave_result(), getboolexp1(), give_thing(), grep_util(), handle_ears(), handle_sets(), Hearer(), help_helper(), help_write(), helpindex_read(), interp_nametab(), list_attrtable(), list_cmdtable(), list_df_flags(), list_functable(), list_vattrs(), CGuests::ListAll(), listset_nametab(), load_player_names(), load_restart_db(), look_contents(), look_exits(), look_in(), lookup_player(), mail_list_time(), mail_return(), mail_to_list(), main(), make_namelist(), make_numlist(), match_possessed(), modSpeech(), munge_space(), mux_atof(), mux_exec(), new_connection(), notify_check(), olist_add(), page_return(), parse_arglist(), parse_arglist_lite(), parse_attrib(), parse_attrib_wild(), parse_boolexp_L(), powers_list(), process_cmdent(), process_command(), process_hook(), process_input_helper(), process_preload(), PushIntegers(), PushPointers(), put_ConnectionInfoFields(), queue_write_LEN(), real_regmatch(), regexp_match(), replace_string(), replace_tokens(), ReportMatchedTopics(), ReportTopic(), save_global_regs(), save_match_state(), search_perform(), set_player_folder(), set_userstring(), show_a_desc(), show_vrml_url(), shutdownsock(), status_string(), sweep_check(), switch_handler(), Task_RunQueueEntry(), tcache_add(), test_atr(), trim_spaces(), u_comp(), unparse_object(), unparse_object_numonly(), whisper_pose(), and wild().

#define alloc_mbuf (  )     pool_alloc(POOL_MBUF,s, __FILE__, __LINE__)

Definition at line 39 of file alloc.h.

Referenced by announce_disconnect(), check_connect(), do_chanlist(), do_decomp(), do_link(), do_ps(), do_report(), do_toad(), do_version(), dump_database(), dump_users(), eval_boolexp(), failconn(), fcache_fill(), fcache_read(), flag_description(), list_cf_access(), list_costs(), list_options(), list_sites(), mux_exec(), new_connection(), shutdownsock(), and ValidateHelpFileIndex().

#define alloc_pcache (  )     (PCACHE *)pool_alloc(POOL_PCACHE,s, __FILE__, __LINE__)

Definition at line 47 of file alloc.h.

Referenced by pcache_find().

#define alloc_qentry (  )     (BQUE *)pool_alloc(POOL_QENTRY,s, __FILE__, __LINE__)

Definition at line 45 of file alloc.h.

Referenced by setup_que().

#define alloc_sbuf (  )     pool_alloc(POOL_SBUF,s, __FILE__, __LINE__)

Definition at line 41 of file alloc.h.

Referenced by ANSI_TruncateAndPad_sbuf(), atr_push(), CF_HAND(), create_obj(), decode_flags(), did_it(), do_apply_marked(), do_destroy(), do_dig(), do_function(), fcache_load(), find_power(), flag_rename(), FUNCTION(), function_add(), functions_add(), hook_name(), init_flagtab(), init_powertab(), list_attraccess(), list_cmdaccess(), list_cmdswitches(), list_sites(), make_port_ulist(), notify_check(), search_perform(), and tcache_add().

#define free_bool (  )     pool_free(POOL_BOOL,(char *)(b), __FILE__, __LINE__)

Definition at line 44 of file alloc.h.

Referenced by free_boolexp(), getboolexp1(), and parse_boolexp_L().

#define free_lbuf (  )     pool_free_lbuf((char *)(b), __FILE__, __LINE__)

Definition at line 38 of file alloc.h.

Referenced by add_folder_name(), add_mail_message(), add_player_name(), add_prefix(), add_quota(), add_to(), announce_connect(), announce_disconnect(), atr_chown(), atr_cpy(), atr_match1(), atr_set_flags(), badname_list(), bind_and_queue(), BuildChannelMessage(), CF_HAND(), cf_log_syntax(), cf_status_from_succfail(), check_attr(), check_connect(), check_dead_refs(), check_filter(), check_pass(), clearstrings(), cmdtest(), Commer(), connect_player(), could_doit(), create_obj(), create_player(), db_read(), db_write_object(), dbclean_RenumberAttributes(), debug_examine(), default_handler(), delete_player_name(), delim_check(), desc_reload(), destroy_player(), did_it(), display_flagtab(), display_powertab(), do_alias(), do_chanlist(), do_chanlog(), do_channelwho(), do_chboot(), do_chopen(), do_chown(), do_comlast(), do_command(), do_comsystem(), do_comwho_line(), do_decomp(), do_destroy(), do_dolist(), do_drop(), do_edit(), do_edit_msg(), do_entrances(), do_examine(), do_expmail_start(), do_expmail_stop(), do_find(), do_hook(), do_icmd(), do_if(), do_inventory(), do_kill(), do_last(), do_link(), do_log(), do_mail_cc(), do_mail_list(), do_mail_proof(), do_mail_quick(), do_mail_read(), do_mail_reply(), do_mail_review(), do_malias_create(), do_malias_list(), do_mvattr(), do_name(), do_newpassword(), do_page(), do_password(), do_pemit_single(), do_postpend(), do_prepend(), do_prog(), do_quitprog(), do_report(), do_say(), do_search(), do_set(), do_shout(), do_switch(), do_think(), do_toad(), do_ufun(), do_use(), do_verb(), encrypt_logindata(), eval_boolexp(), exam_wildattrs(), failconn(), fcache_load(), fcache_read(), fetch_ConnectionInfoField(), fetch_ConnectionInfoFields(), fetch_logouttime(), filter_handler(), fork_and_dump(), freeqs(), FUNCTION(), fwdlist_ck(), fwdlist_get(), fwdlist_load(), get_exit_dest(), get_folder_name(), get_folder_number(), get_gender(), get_handler(), get_list(), get_obj_and_lock(), get_slave_result(), getboolexp1(), give_money(), give_thing(), grep_handler(), grep_util(), handle_ears(), handle_prog(), handle_sets(), hasattr_handler(), Hearer(), help_helper(), help_write(), helpindex_read(), idle_timeout_val(), list_attrtable(), list_df_flags(), list_vattrs(), CGuests::ListAll(), listset_nametab(), load_player_names(), log_name(), look_atrs1(), look_contents(), look_exits(), look_in(), look_simple(), lookup_player(), mail_return(), mail_to_list(), make_namelist(), match_possessed(), modSpeech(), Moniker(), move_exit(), mung_quotas(), mux_atof(), mux_exec(), Name(), new_connection(), nfy_que(), notify_check(), olist_pop(), page_return(), parse_and_get_attrib(), parse_attrib(), parse_attrib_wild(), parse_boolexp_L(), pay_quota(), player_folder(), PopIntegers(), PopPointers(), process_cmdent(), process_command(), process_hook(), process_input_helper(), process_preload(), PureName(), put_ConnectionInfoFields(), queue_write_LEN(), record_login(), regexp_match(), ReportMatchedTopics(), ReportTopic(), restore_global_regs(), restore_match_state(), search_perform(), SendChannelMessage(), set_player_folder(), set_userstring(), show_a_desc(), show_desc(), show_quota(), show_vrml_url(), ShowPsLine(), shutdownsock(), stack_clr(), sweep_check(), switch_handler(), Task_ProcessCommand(), Task_RunQueueEntry(), tcache_add(), tcache_finish(), test_atr(), u_comp(), unparse_boolexp1(), whisper_pose(), and wild().

#define free_mbuf (  )     pool_free(POOL_MBUF,(char *)(b), __FILE__, __LINE__)

Definition at line 40 of file alloc.h.

Referenced by announce_disconnect(), check_connect(), debug_examine(), do_examine(), do_link(), do_ps(), do_report(), do_toad(), do_version(), dump_database(), dump_users(), eval_boolexp(), failconn(), fcache_read(), list_costs(), list_options(), list_sites(), mux_exec(), new_connection(), shutdownsock(), and ValidateHelpFileIndex().

#define free_pcache (  )     pool_free(POOL_PCACHE,(char *)(b), __FILE__, __LINE__)

Definition at line 48 of file alloc.h.

Referenced by pcache_trim().

#define free_qentry (  )     pool_free(POOL_QENTRY,(char *)(b), __FILE__, __LINE__)

Definition at line 46 of file alloc.h.

Referenced by CallBack_HaltQueue(), and CallBack_NotifySemaphoreDrainOrAll().

#define free_sbuf (  )     pool_free(POOL_SBUF,(char *)(b), __FILE__, __LINE__)

Definition at line 42 of file alloc.h.

Referenced by atr_pop(), CF_HAND(), create_obj(), did_it(), do_apply_marked(), do_chanlist(), do_destroy(), do_dig(), do_function(), fcache_load(), find_power(), flag_rename(), FUNCTION(), function_add(), functions_add(), higcheck(), hook_fail(), list_attraccess(), list_df_flags(), list_sites(), make_port_ulist(), notify_check(), process_cmdent(), shutdownsock(), tcache_finish(), and unparse_object().

#define GBUF_SIZE   1024

Definition at line 23 of file alloc.h.

Referenced by do_motd().

#define LBUF_SIZE   8000

Definition at line 21 of file alloc.h.

Referenced by add_folder_name(), al_add(), ANSI_TransformTextReverseWithFunction(), ANSI_TransformTextWithTable(), atr_add_raw_LEN(), atr_match1(), BuildChannelMessage(), centerjustcombo(), CF_HAND(), cf_log_syntax(), crypt_code(), db_write(), dbconvert(), do_channelwho(), do_comsystem(), do_icmd(), do_listchannels(), do_logged_out_internal(), do_mail_read(), do_page(), do_postpend(), do_prepend(), encode_iac(), expand_tabs(), fcache_read(), FUNCTION(), get_folder_name(), get_slave_result(), getboolexp1(), getstring_noalloc(), handle_sets(), handle_vectors(), ItemToList_Init(), list_functable(), load_channels(), load_comsystem(), main(), make_numlist(), malias_read(), Moniker(), munge_space_for_match(), mux_exec(), Name(), new_mail_message(), normal_to_white(), parse_boolexp_L(), pool_alloc_lbuf(), pool_free_lbuf(), process_command(), process_input(), process_input_helper(), putstring(), raw_broadcast(), real_regmatch(), regexp_match(), RemoveSetOfCharacters(), ReportTopic(), safe_copy_buf(), safe_copy_str_lbuf(), safe_fill(), safe_tprintf_str(), SignalDesc(), strip_accents(), strip_ansi(), tcache_add(), tprintf(), translate_string(), unparse_object(), unparse_object_numonly(), and wild1().

#define MBUF_SIZE   400

Definition at line 24 of file alloc.h.

Referenced by db_read(), dbconvert(), do_mail_list(), do_mail_proof(), do_mail_read(), do_mail_review(), list_bufstats(), list_hashstat(), main(), MakeCanonicalExitName(), MakeCanonicalObjectName(), parse_connect(), trimmed_name(), and trimmed_site().

#define NUM_POOLS   7

Definition at line 16 of file alloc.h.

Referenced by list_bufstats(), list_buftrace(), pool_check(), and pool_reset().

#define PBUF_SIZE   128

Definition at line 25 of file alloc.h.

#define POOL_BOOL   3

Definition at line 12 of file alloc.h.

Referenced by dbconvert(), and main().

#define POOL_DESC   4

Definition at line 13 of file alloc.h.

Referenced by main().

#define POOL_LBUF   0

Definition at line 9 of file alloc.h.

Referenced by dbconvert(), main(), pool_alloc_lbuf(), and pool_free_lbuf().

#define POOL_MBUF   2

Definition at line 11 of file alloc.h.

Referenced by dbconvert(), and main().

#define POOL_PCACHE   6

Definition at line 15 of file alloc.h.

Referenced by pcache_init().

#define POOL_QENTRY   5

Definition at line 14 of file alloc.h.

Referenced by main().

#define POOL_SBUF   1

Definition at line 10 of file alloc.h.

Referenced by dbconvert(), and main().

#define safe_bool ( c,
b,
 )     safe_chr(((c) ? '1' : '0'),b,p)

Definition at line 61 of file alloc.h.

Referenced by FUNCTION(), hasattr_handler(), and real_regmatch().

#define safe_chr ( c,
b,
 )     safe_copy_chr((unsigned char)(c),b,p,(LBUF_SIZE-1))

Definition at line 60 of file alloc.h.

Referenced by add_prefix(), badname_list(), BuildChannelMessage(), cf_display(), debug_examine(), dflt_from_msg(), display_flagtab(), display_nametab(), display_powertab(), do_inventory(), do_itemfuns(), do_mail_cc(), do_mail_reply(), do_malias_list(), do_page(), do_postpend(), do_prepend(), do_search(), do_shout(), expand_tabs(), FUNCTION(), give_thing(), grep_util(), html_escape(), interp_nametab(), lattr_handler(), list_functable(), listset_nametab(), look_exits(), make_namelist(), notify_check(), powers_list(), process_cmdent(), replace_string(), replace_tokens(), ReportMatchedTopics(), ShowPsLine(), SignalDesc(), CSpellNum::StartWord(), translate_string(), unparse_boolexp1(), unparse_object(), and unparse_object_numonly().

#define safe_copy_chr ( src,
buff,
bufp,
nSizeOfBuffer   ) 

Value:

{ \
    if ((*bufp - buff) < nSizeOfBuffer) \
    { \
        **bufp = src; \
        (*bufp)++; \
    } \
}

Definition at line 50 of file alloc.h.

#define safe_mb_chr ( c,
b,
 )     safe_copy_chr(c,b,p,(MBUF_SIZE-1))

Definition at line 65 of file alloc.h.

Referenced by flag_description(), and MakeCanonicalExitName().

#define safe_mb_str ( s,
b,
 )     safe_copy_str(s,b,p,(MBUF_SIZE-1))

Definition at line 64 of file alloc.h.

Referenced by flag_description(), and MakeCanonicalExitName().

#define safe_sb_chr ( c,
b,
 )     safe_copy_chr(c,b,p,(SBUF_SIZE-1))

Definition at line 63 of file alloc.h.

Referenced by decode_flags(), and FUNCTION().

#define safe_sb_str ( s,
b,
 )     safe_copy_str(s,b,p,(SBUF_SIZE-1))

Definition at line 62 of file alloc.h.

Referenced by do_function(), FUNCTION(), function_add(), and functions_add().

#define safe_str ( s,
b,
 )     safe_copy_str_lbuf(s,b,p)

Definition at line 59 of file alloc.h.

Referenced by add_player_name(), add_prefix(), CSpellNum::AddWord(), arr2list(), badname_list(), BuildChannelMessage(), debug_examine(), default_handler(), delete_player_name(), delim_check(), dflt_from_msg(), did_it(), display_flagtab(), display_nametab(), display_powertab(), do_chboot(), do_chown(), do_inventory(), do_itemfuns(), do_link(), do_mail_cc(), do_mail_reply(), do_malias_list(), do_page(), do_pemit_single(), do_postpend(), do_prepend(), do_search(), do_shout(), edit_string(), edit_string_ansi(), fcache_load(), filter_handler(), FUNCTION(), fval(), get_obj_and_lock(), give_thing(), grep_handler(), grep_util(), handle_sets(), handle_vectors(), help_helper(), html_escape(), interp_nametab(), iter_value(), lattr_handler(), list_functable(), listset_nametab(), look_contents(), look_exits(), lookup_player(), make_namelist(), mux_exec(), notify_check(), powers_list(), process_cmdent(), raw_notify(), raw_notify_html(), raw_notify_newline(), real_regmatch(), real_regrab(), replace_string(), replace_tokens(), ReportMatchedTopics(), ReportTopic(), scan_zone(), show_a_desc(), show_hook(), show_vrml_url(), ShowPsLine(), SignalDesc(), CSpellNum::SpellNum(), sweep_check(), translate_string(), unparse_boolexp1(), unparse_object(), and unparse_object_numonly().

#define SBUF_SIZE   64

Definition at line 26 of file alloc.h.

Referenced by add_helpfile(), ANSI_TruncateAndPad_sbuf(), centerjustcombo(), CF_HAND(), db_write_object(), dbclean_CheckATtoANH(), dbconvert(), do_attribute(), find_power(), GetLineTrunc(), getref(), helpindex_read(), init_flagtab(), init_powertab(), ItemToList_AddInteger(), main(), MakeCanonicalAttributeCommand(), MakeCanonicalAttributeName(), MakeCanonicalFlagName(), mux_exec(), process_input_helper(), putref(), ReportTopic(), and unparse_object_quiet().


Function Documentation

void list_bufstats ( dbref   ) 

Definition at line 518 of file alloc.cpp.

References MBUF_SIZE, mux_i64toa(), notify, NUM_POOLS, poolnames, and pools.

Referenced by do_list().

00519 {
00520     char buff[MBUF_SIZE];
00521 
00522     notify(player, "Buffer Stats  Size     InUse     Total        Allocs   Lost");
00523 
00524     int i;
00525     for (i = 0; i < NUM_POOLS; i++)
00526     {
00527         char szNumAlloc[22];
00528         char szMaxAlloc[22];
00529         char szTotAlloc[22];
00530         char szNumLost[22];
00531 
00532         mux_i64toa(pools[i].num_alloc, szNumAlloc);
00533         mux_i64toa(pools[i].max_alloc, szMaxAlloc);
00534         mux_i64toa(pools[i].tot_alloc, szTotAlloc);
00535         mux_i64toa(pools[i].num_lost,  szNumLost);
00536 
00537         sprintf(buff, "%-12s %5d%10s%10s%14s%7s",
00538             poolnames[i], (int)pools[i].pool_size,
00539             szNumAlloc, szMaxAlloc, szTotAlloc, szNumLost);
00540         notify(player, buff);
00541     }
00542 }

void list_buftrace ( dbref   ) 

Definition at line 544 of file alloc.cpp.

References NUM_POOLS, pool_trace(), and poolnames.

Referenced by do_list().

00545 {
00546     int i;
00547     for (i = 0; i < NUM_POOLS; i++)
00548     {
00549         pool_trace(player, i, poolnames[i]);
00550     }
00551 }

char* pool_alloc ( int  ,
const char *  ,
const char *  ,
int   
)

Definition at line 162 of file alloc.cpp.

References pool_header::buf_tag, pooldata::chain_head, statedata::debug_cmd, end_log(), pooldata::free_head, ISOUTOFMEMORY, Log, LOG_ALLOCATE, LOG_ALWAYS, confdata::log_options, LOG_PROBLEMS, statedata::logging, pool_footer::magicnum, pool_header::magicnum, pooldata::max_alloc, MEMALLOC, mudconf, mudstate, pool_header::next, pooldata::num_alloc, pooldata::num_lost, pool_header::nxtfree, confdata::paranoid_alloc, pool_check(), pool_err(), pooldata::pool_size, pool_header::pool_size, pooldata::poolmagic, pools, start_log(), CLogFile::tinyprintf(), and pooldata::tot_alloc.

00163 {
00164     if (mudconf.paranoid_alloc)
00165     {
00166         pool_check(tag, file, line);
00167     }
00168 
00169     char *p;
00170     POOLFTR *pf;
00171     POOLHDR *ph = (POOLHDR *)pools[poolnum].free_head;
00172     if (  ph
00173        && ph->magicnum == pools[poolnum].poolmagic)
00174     {
00175         p = (char *)(ph + 1);
00176         pf = (POOLFTR *)(p + pools[poolnum].pool_size);
00177         pools[poolnum].free_head = ph->nxtfree;
00178 
00179         // Check for corrupted footer, just report and fix it.
00180         //
00181         if (pf->magicnum != pools[poolnum].poolmagic)
00182         {
00183             pool_err("BUG", LOG_ALWAYS, poolnum, tag, ph, "Alloc",
00184                 "corrupted buffer footer", file, line);
00185             pf->magicnum = pools[poolnum].poolmagic;
00186         }
00187     }
00188     else
00189     {
00190         if (ph)
00191         {
00192             // Header is corrupt. Throw away the freelist and start a new
00193             // one.
00194             pool_err("BUG", LOG_ALWAYS, poolnum, tag, ph, "Alloc",
00195                 "corrupted buffer header", file, line);
00196 
00197             // Start a new free list and record stats.
00198             //
00199             pools[poolnum].free_head = NULL;
00200             pools[poolnum].num_lost += (pools[poolnum].tot_alloc
00201                                      -  pools[poolnum].num_alloc);
00202             pools[poolnum].tot_alloc = pools[poolnum].num_alloc;
00203         }
00204 
00205         ph = (POOLHDR *)MEMALLOC(pools[poolnum].pool_size + sizeof(POOLHDR)
00206            + sizeof(POOLFTR));
00207         ISOUTOFMEMORY(ph);
00208         p = (char *)(ph + 1);
00209         pf = (POOLFTR *)(p + pools[poolnum].pool_size);
00210 
00211         // Initialize.
00212         //
00213         ph->next = pools[poolnum].chain_head;
00214         ph->nxtfree = NULL;
00215         ph->magicnum = pools[poolnum].poolmagic;
00216         ph->pool_size = pools[poolnum].pool_size;
00217         pf->magicnum = pools[poolnum].poolmagic;
00218         *((unsigned int *)p) = pools[poolnum].poolmagic;
00219         pools[poolnum].chain_head = ph;
00220         pools[poolnum].max_alloc++;
00221     }
00222 
00223     ph->buf_tag = (char *)tag;
00224     pools[poolnum].tot_alloc++;
00225     pools[poolnum].num_alloc++;
00226 
00227     if (  (LOG_ALLOCATE & mudconf.log_options)
00228        && mudstate.logging == 0
00229        && start_log("DBG", "ALLOC"))
00230     {
00231         Log.tinyprintf("Alloc[%d] (tag %s) in %s line %d buffer at %lx. (%s)",
00232             pools[poolnum].pool_size, tag, file, line, (long)ph, mudstate.debug_cmd);
00233         end_log();
00234     }
00235 
00236     // If the buffer was modified after it was last freed, log it.
00237     //
00238     unsigned int *pui = (unsigned int *)p;
00239     if (*pui != pools[poolnum].poolmagic)
00240     {
00241         pool_err("BUG", LOG_PROBLEMS, poolnum, tag, ph, "Alloc",
00242             "buffer modified after free", file, line);
00243     }
00244     *pui = 0;
00245     return p;
00246 }

char* pool_alloc_lbuf ( const char *  ,
const char *  ,
int   
)

Definition at line 248 of file alloc.cpp.

References pool_header::buf_tag, pooldata::chain_head, statedata::debug_cmd, end_log(), pooldata::free_head, ISOUTOFMEMORY, LBUF_SIZE, Log, LOG_ALLOCATE, LOG_ALWAYS, confdata::log_options, LOG_PROBLEMS, statedata::logging, pool_footer::magicnum, pool_header::magicnum, pooldata::max_alloc, MEMALLOC, mudconf, mudstate, pool_header::next, pooldata::num_alloc, pooldata::num_lost, pool_header::nxtfree, confdata::paranoid_alloc, pool_check(), pool_err(), POOL_LBUF, pool_header::pool_size, pooldata::poolmagic, pools, start_log(), CLogFile::tinyprintf(), and pooldata::tot_alloc.

Referenced by atr_get_real(), and atr_pget_real().

00249 {
00250     if (mudconf.paranoid_alloc)
00251     {
00252         pool_check(tag, file, line);
00253     }
00254 
00255     char *p;
00256     POOLFTR *pf;
00257     POOLHDR *ph = (POOLHDR *)pools[POOL_LBUF].free_head;
00258     if (  ph
00259        && ph->magicnum == pools[POOL_LBUF].poolmagic)
00260     {
00261         p = (char *)(ph + 1);
00262         pf = (POOLFTR *)(p + LBUF_SIZE);
00263         pools[POOL_LBUF].free_head = ph->nxtfree;
00264 
00265         // Check for corrupted footer, just report and fix it.
00266         //
00267         if (pf->magicnum != pools[POOL_LBUF].poolmagic)
00268         {
00269             pool_err("BUG", LOG_ALWAYS, POOL_LBUF, tag, ph, "Alloc",
00270                 "corrupted buffer footer", file, line);
00271             pf->magicnum = pools[POOL_LBUF].poolmagic;
00272         }
00273     }
00274     else
00275     {
00276         if (ph)
00277         {
00278             // Header is corrupt. Throw away the freelist and start a new
00279             // one.
00280             pool_err("BUG", LOG_ALWAYS, POOL_LBUF, tag, ph, "Alloc",
00281                 "corrupted buffer header", file, line);
00282 
00283             // Start a new free list and record stats.
00284             //
00285             pools[POOL_LBUF].free_head = NULL;
00286             pools[POOL_LBUF].num_lost += (pools[POOL_LBUF].tot_alloc
00287                                      -  pools[POOL_LBUF].num_alloc);
00288             pools[POOL_LBUF].tot_alloc = pools[POOL_LBUF].num_alloc;
00289         }
00290 
00291         ph = (POOLHDR *)MEMALLOC(LBUF_SIZE + sizeof(POOLHDR)
00292            + sizeof(POOLFTR));
00293         ISOUTOFMEMORY(ph);
00294         p = (char *)(ph + 1);
00295         pf = (POOLFTR *)(p + LBUF_SIZE);
00296 
00297         // Initialize.
00298         //
00299         ph->next = pools[POOL_LBUF].chain_head;
00300         ph->nxtfree = NULL;
00301         ph->magicnum = pools[POOL_LBUF].poolmagic;
00302         ph->pool_size = LBUF_SIZE;
00303         pf->magicnum = pools[POOL_LBUF].poolmagic;
00304         *((unsigned int *)p) = pools[POOL_LBUF].poolmagic;
00305         pools[POOL_LBUF].chain_head = ph;
00306         pools[POOL_LBUF].max_alloc++;
00307     }
00308 
00309     ph->buf_tag = (char *)tag;
00310     pools[POOL_LBUF].tot_alloc++;
00311     pools[POOL_LBUF].num_alloc++;
00312 
00313     if (  (LOG_ALLOCATE & mudconf.log_options)
00314        && mudstate.logging == 0
00315        && start_log("DBG", "ALLOC"))
00316     {
00317         Log.tinyprintf("Alloc[%d] (tag %s) in %s line %d buffer at %lx. (%s)",
00318             LBUF_SIZE, tag, file, line, (long)ph, mudstate.debug_cmd);
00319         end_log();
00320     }
00321 
00322     // If the buffer was modified after it was last freed, log it.
00323     //
00324     unsigned int *pui = (unsigned int *)p;
00325     if (*pui != pools[POOL_LBUF].poolmagic)
00326     {
00327         pool_err("BUG", LOG_PROBLEMS, POOL_LBUF, tag, ph, "Alloc",
00328             "buffer modified after free", file, line);
00329     }
00330     *pui = 0;
00331     return p;
00332 }

void pool_free ( int  ,
char *  ,
const char *  ,
int   
)

Definition at line 334 of file alloc.cpp.

References pool_header::buf_tag, statedata::debug_cmd, end_log(), ENDLOG, pooldata::free_head, Log, LOG_ALLOCATE, LOG_ALWAYS, LOG_BUGS, confdata::log_options, LOG_PROBLEMS, log_text(), statedata::logging, pool_footer::magicnum, pool_header::magicnum, mudconf, mudstate, pooldata::num_alloc, pooldata::num_lost, pool_header::nxtfree, confdata::paranoid_alloc, pool_check(), pool_err(), pooldata::pool_size, pool_header::pool_size, pooldata::poolmagic, pools, start_log(), STARTLOG, CLogFile::tinyprintf(), pooldata::tot_alloc, and tprintf().

00335 {
00336     if (buf == NULL)
00337     {
00338         STARTLOG(LOG_PROBLEMS, "BUG", "ALLOC")
00339         log_text(tprintf("Attempt to free null pointer in %s line %d.", file, line));
00340         ENDLOG
00341         return;
00342     }
00343     POOLHDR *ph = ((POOLHDR *)(buf)) - 1;
00344     POOLFTR *pf = (POOLFTR *)(buf + pools[poolnum].pool_size);
00345     unsigned int *pui = (unsigned int *)buf;
00346 
00347     if (mudconf.paranoid_alloc)
00348     {
00349         pool_check(ph->buf_tag, file, line);
00350     }
00351 
00352     // Make sure the buffer header is good.  If it isn't, log the error and
00353     // throw away the buffer.
00354     //
00355     if (ph->magicnum != pools[poolnum].poolmagic)
00356     {
00357         pool_err("BUG", LOG_ALWAYS, poolnum, ph->buf_tag, ph, "Free",
00358                  "corrupted buffer header", file, line);
00359         pools[poolnum].num_lost++;
00360         pools[poolnum].num_alloc--;
00361         pools[poolnum].tot_alloc--;
00362         return;
00363     }
00364 
00365     // Verify the buffer footer.  Don't unlink if damaged, just repair.
00366     //
00367     if (pf->magicnum != pools[poolnum].poolmagic)
00368     {
00369         pool_err("BUG", LOG_ALWAYS, poolnum, ph->buf_tag, ph, "Free",
00370              "corrupted buffer footer", file, line);
00371         pf->magicnum = pools[poolnum].poolmagic;
00372     }
00373 
00374     // Verify that we are not trying to free someone else's buffer.
00375     //
00376     if (ph->pool_size != pools[poolnum].pool_size)
00377     {
00378         pool_err("BUG", LOG_ALWAYS, poolnum, ph->buf_tag, ph, "Free",
00379                  "Attempt to free into a different pool.", file, line);
00380         return;
00381     }
00382 
00383     if (  (LOG_ALLOCATE & mudconf.log_options)
00384        && mudstate.logging == 0
00385        && start_log("DBG", "ALLOC"))
00386     {
00387         Log.tinyprintf("Free[%d] (tag %s) in %s line %d buffer at %lx. (%s)",
00388             pools[poolnum].pool_size, ph->buf_tag, file, line, (long)ph,
00389             mudstate.debug_cmd);
00390         end_log();
00391     }
00392 
00393     // Make sure we aren't freeing an already free buffer.  If we are, log an
00394     // error, otherwise update the pool header and stats.
00395     //
00396     if (*pui == pools[poolnum].poolmagic)
00397     {
00398         pool_err("BUG", LOG_BUGS, poolnum, ph->buf_tag, ph, "Free",
00399                  "buffer already freed", file, line);
00400     }
00401     else
00402     {
00403         *pui = pools[poolnum].poolmagic;
00404         ph->nxtfree = pools[poolnum].free_head;
00405         pools[poolnum].free_head = ph;
00406         pools[poolnum].num_alloc--;
00407     }
00408 }

void pool_free_lbuf ( char *  ,
const char *  ,
int   
)

Definition at line 410 of file alloc.cpp.

References pool_header::buf_tag, statedata::debug_cmd, end_log(), ENDLOG, pooldata::free_head, LBUF_SIZE, Log, LOG_ALLOCATE, LOG_ALWAYS, LOG_BUGS, confdata::log_options, LOG_PROBLEMS, log_text(), statedata::logging, pool_footer::magicnum, pool_header::magicnum, mudconf, mudstate, pooldata::num_alloc, pooldata::num_lost, pool_header::nxtfree, confdata::paranoid_alloc, pool_check(), pool_err(), POOL_LBUF, pool_header::pool_size, pooldata::poolmagic, pools, start_log(), STARTLOG, CLogFile::tinyprintf(), pooldata::tot_alloc, and tprintf().

00411 {
00412     if (buf == NULL)
00413     {
00414         STARTLOG(LOG_PROBLEMS, "BUG", "ALLOC")
00415         log_text(tprintf("Attempt to free_lbuf null pointer in %s line %d.", file, line));
00416         ENDLOG
00417         return;
00418     }
00419     POOLHDR *ph = ((POOLHDR *)(buf)) - 1;
00420     POOLFTR *pf = (POOLFTR *)(buf + LBUF_SIZE);
00421     unsigned int *pui = (unsigned int *)buf;
00422 
00423     if (mudconf.paranoid_alloc)
00424     {
00425         pool_check(ph->buf_tag, file, line);
00426     }
00427 
00428     if (  ph->magicnum != pools[POOL_LBUF].poolmagic
00429        || pf->magicnum != pools[POOL_LBUF].poolmagic
00430        || ph->pool_size != LBUF_SIZE
00431        || *pui == pools[POOL_LBUF].poolmagic)
00432     {
00433         if (ph->magicnum != pools[POOL_LBUF].poolmagic)
00434         {
00435             // The buffer header is damaged. Log the error and throw away the
00436             // buffer.
00437             //
00438             pool_err("BUG", LOG_ALWAYS, POOL_LBUF, ph->buf_tag, ph, "Free",
00439                      "corrupted buffer header", file, line);
00440             pools[POOL_LBUF].num_lost++;
00441             pools[POOL_LBUF].num_alloc--;
00442             pools[POOL_LBUF].tot_alloc--;
00443             return;
00444         }
00445         else if (pf->magicnum != pools[POOL_LBUF].poolmagic)
00446         {
00447             // The buffer footer is damaged.  Don't unlink, just repair.
00448             //
00449             pool_err("BUG", LOG_ALWAYS, POOL_LBUF, ph->buf_tag, ph, "Free",
00450                 "corrupted buffer footer", file, line);
00451             pf->magicnum = pools[POOL_LBUF].poolmagic;
00452         }
00453         else if (ph->pool_size != LBUF_SIZE)
00454         {
00455             // We are trying to free someone else's buffer.
00456             //
00457             pool_err("BUG", LOG_ALWAYS, POOL_LBUF, ph->buf_tag, ph, "Free",
00458                 "Attempt to free into a different pool.", file, line);
00459             return;
00460         }
00461 
00462         // If we are freeing a buffer that was already free, report an error.
00463         //
00464         if (*pui == pools[POOL_LBUF].poolmagic)
00465         {
00466             pool_err("BUG", LOG_BUGS, POOL_LBUF, ph->buf_tag, ph, "Free",
00467                      "buffer already freed", file, line);
00468             return;
00469         }
00470     }
00471 
00472     if (  (LOG_ALLOCATE & mudconf.log_options)
00473        && mudstate.logging == 0
00474        && start_log("DBG", "ALLOC"))
00475     {
00476         Log.tinyprintf("Free[%d] (tag %s) in %s line %d buffer at %lx. (%s)",
00477             LBUF_SIZE, ph->buf_tag, file, line, (long)ph, mudstate.debug_cmd);
00478         end_log();
00479     }
00480 
00481     // Update the pool header and stats.
00482     //
00483     *pui = pools[POOL_LBUF].poolmagic;
00484     ph->nxtfree = pools[POOL_LBUF].free_head;
00485     pools[POOL_LBUF].free_head = ph;
00486     pools[POOL_LBUF].num_alloc--;
00487 }

void pool_init ( int  ,
int   
)

Definition at line 61 of file alloc.cpp.

References pooldata::chain_head, CRC32_ProcessInteger2(), pooldata::free_head, pooldata::max_alloc, pooldata::num_alloc, pooldata::num_lost, pooldata::pool_size, pooldata::poolmagic, pools, and pooldata::tot_alloc.

Referenced by dbconvert(), main(), and pcache_init().

00062 {
00063     pools[poolnum].pool_size = poolsize;
00064     pools[poolnum].poolmagic = CRC32_ProcessInteger2(poolnum, poolsize);
00065     pools[poolnum].free_head = NULL;
00066     pools[poolnum].chain_head = NULL;
00067     pools[poolnum].tot_alloc = 0;
00068     pools[poolnum].num_alloc = 0;
00069     pools[poolnum].max_alloc = 0;
00070     pools[poolnum].num_lost = 0;
00071 }

void pool_reset ( void   ) 

Definition at line 553 of file alloc.cpp.

References pooldata::chain_head, pooldata::free_head, pooldata::max_alloc, MEMFREE, pool_header::next, pooldata::num_alloc, NUM_POOLS, pool_header::nxtfree, and pools.

Referenced by dispatch_FreeListReconstruction().

00554 {
00555     int i;
00556     for (i = 0; i < NUM_POOLS; i++)
00557     {
00558         POOLHDR *newchain = NULL;
00559         POOLHDR *phnext;
00560         POOLHDR *ph;
00561         for (ph = pools[i].chain_head; ph != NULL; ph = phnext)
00562         {
00563             char *h = (char *)ph;
00564             phnext = ph->next;
00565             h += sizeof(POOLHDR);
00566             unsigned int *ibuf = (unsigned int *)h;
00567             if (*ibuf == pools[i].poolmagic)
00568             {
00569                 MEMFREE(ph);
00570                 ph = NULL;
00571             }
00572             else
00573             {
00574                 ph->next = newchain;
00575                 newchain = ph;
00576                 ph->nxtfree = NULL;
00577             }
00578         }
00579         pools[i].chain_head = newchain;
00580         pools[i].free_head = NULL;
00581         pools[i].max_alloc = pools[i].num_alloc;
00582     }
00583 }


Generated on Mon May 28 04:40:12 2007 for MUX by  doxygen 1.4.7