int enum_symbols (FILE * fp, long size, int (*func) (const char *sym, void *param), void *param) { long end; struct dbuf_s buf; struct dbuf_s symname; assert (func != NULL); dbuf_init (&buf, 512); dbuf_init (&symname, 32); end = (size >= 0) ? ftell (fp) + size : -1; /* * Read in the object file. Look for lines that * begin with "S" and end with "D". These are * symbol table definitions. If we find one, see * if it is our symbol. Make sure we only read in * our object file and don't go into the next one. */ while (end < 0 || ftell (fp) < end) { const char *p; dbuf_set_length (&buf, 0); if (dbuf_getline (&buf, fp) == 0) break; p = dbuf_c_str (&buf); if ('T' == p[0]) break; /* * Skip everything that's not a symbol record. */ if ('S' == p[0] && ' ' == p[1]) { dbuf_set_length (&symname, 0); for (p += 2; *p && ' ' != *p; ++p) dbuf_append_char (&symname, *p); /* If it's an actual symbol, record it */ if (' ' == p[0] && 'D' == p[1]) if (func != NULL) if ((*func) (dbuf_c_str (&symname), NULL)) return 1; } } dbuf_destroy (&buf); dbuf_destroy (&symname); return 0; }
/*-----------------------------------------------------------------*/ const char * format_opcode (const char *inst, const char *fmt, va_list ap) { struct dbuf_s dbuf; dbuf_init (&dbuf, INITIAL_INLINEASM); if (inst && *inst) { dbuf_append_str (&dbuf, inst); if (fmt && *fmt) { dbuf_append_char (&dbuf, '\t'); dbuf_tvprintf (&dbuf, fmt, ap); } } else { if (fmt && *fmt) { dbuf_tvprintf (&dbuf, fmt, ap); } } return dbuf_detach_c_str (&dbuf); }
/* * Iterate over all memmaps and emit their contents (attributes, symbols). */ static void showAllMemmaps(FILE *of) { struct dbuf_s locBuf; memmap *maps[] = { xstack, istack, code, data, pdata, xdata, xidata, xinit, idata, bit, statsg, c_abs, x_abs, i_abs, d_abs, sfr, sfrbit, reg, generic, overlay, eeprom, home }; memmap * map; int i; DEBUGprintf ("---begin memmaps---\n"); if (!extBuf) extBuf = dbuf_new(1024); if (!gloBuf) gloBuf = dbuf_new(1024); if (!gloDefBuf) gloDefBuf = dbuf_new(1024); if (!ivalBuf) ivalBuf = dbuf_new(1024); dbuf_init(&locBuf, 1024); dbuf_printf (extBuf, "%s; external declarations\n%s", iComments2, iComments2); dbuf_printf (gloBuf, "%s; global declarations\n%s", iComments2, iComments2); dbuf_printf (gloDefBuf, "%s; global definitions\n%s", iComments2, iComments2); dbuf_printf (ivalBuf, "%s; initialized data\n%s", iComments2, iComments2); dbuf_printf (&locBuf, "%s; compiler-defined variables\n%s", iComments2, iComments2); for (i = 0; i < sizeof(maps) / sizeof (memmap *); i++) { map = maps[i]; //DEBUGprintf ("memmap %i: %p\n", i, map); if (map) { #if 0 fprintf (stdout, "; pageno %c, sname %s, dbName %c, ptrType %d, slbl %d, sloc %u, fmap %u, paged %u, direct %u, bitsp %u, codesp %u, regsp %u, syms %p\n", map->pageno, map->sname, map->dbName, map->ptrType, map->slbl, map->sloc, map->fmap, map->paged, map->direct, map->bitsp, map->codesp, map->regsp, map->syms); #endif emitSymbolSet(map->syms, 0); } // if (map) } // for i DEBUGprintf ("---end of memmaps---\n"); emitSymbolSet(publics, 1); emitSymbolSet(externs, 2); emitPseudoStack(gloBuf, extBuf); pic14_constructAbsMap(gloDefBuf, gloBuf); pic14printLocals (&locBuf); pic14_emitConfigWord(of); // must be done after all the rest dbuf_write_and_destroy(extBuf, of); dbuf_write_and_destroy(gloBuf, of); dbuf_write_and_destroy(gloDefBuf, of); dbuf_write_and_destroy(&locBuf, of); dbuf_write_and_destroy(ivalBuf, of); extBuf = gloBuf = gloDefBuf = ivalBuf = NULL; }
struct dbuf_s *dbuf_new(size_t size) { struct dbuf_s *dbuf; dbuf = (struct dbuf_s *)malloc(sizeof(struct dbuf_s)); if (dbuf != NULL) { if (dbuf_init(dbuf, size) == 0) { free(dbuf); return NULL; } } return dbuf; }
/* Mangling format: _fun_policy_params where: policy is the function policy params is the parameter format policy format: rsp where: r is 'r' for reentrant, 's' for static functions s is 'c' for callee saves, 'r' for caller saves f is 'f' for profiling on, 'x' for profiling off examples: rr - reentrant, caller saves params format: A combination of register short names and s to signify stack variables. examples: bds - first two args appear in BC and DE, the rest on the stack s - all arguments are on the stack. */ static const char * _mangleSupportFunctionName (const char *original) { struct dbuf_s dbuf; if (strstr (original, "longlong")) return (original); dbuf_init (&dbuf, 128); dbuf_printf (&dbuf, "%s_rr%s_%s", original, options.profile ? "f" : "x", options.noRegParams ? "s" : "bds" /* MB: but the library only has hds variants ??? */ ); return dbuf_detach_c_str (&dbuf); }
/*-----------------------------------------------------------------*/ FILE * createDumpFile (int id) { struct _dumpFiles *dumpFilesPtr = dumpFiles; static int dumpIndex = 0; static char dumpIndexStr[32]; while (dumpFilesPtr->id) { if (dumpFilesPtr->id == id) break; dumpFilesPtr++; } if (!dumpFilesPtr->id) { fprintf (stdout, "internal error: createDumpFile: unknown dump file.\n"); exit (1); } sprintf (dumpIndexStr, ".%d", dumpIndex); dumpIndex++; if (!dumpFilesPtr->filePtr) { // not used before, create it struct dbuf_s dumpFileName; dbuf_init (&dumpFileName, PATH_MAX); dbuf_append_str (&dumpFileName, dstFileName); #ifdef _DEBUG dbuf_append_str (&dumpFileName, dumpIndexStr); #endif dbuf_append_str (&dumpFileName, dumpFilesPtr->ext); if (!(dumpFilesPtr->filePtr = fopen (dbuf_c_str (&dumpFileName), "w"))) { werror (E_FILE_OPEN_ERR, dbuf_c_str (&dumpFileName)); dbuf_destroy (&dumpFileName); exit (1); } dbuf_destroy (&dumpFileName); } #if 0 fprintf (dumpFilesPtr->filePtr, "Dump file index: %d\n", dumpIndex); #endif return dumpFilesPtr->filePtr; }
int dbuf_set_length(struct dbuf_s *dbuf, size_t len) { if (!dbuf_is_initialized (dbuf)) dbuf_init (dbuf, len ? len : 1); assert(dbuf != NULL); assert(dbuf->alloc != 0); assert(len <= dbuf->len); if (len <= dbuf->len) { dbuf->len = len; return 1; } return 0; }
/** * construct new filename based on base_name and replace extension */ char * construct_filename( const char * base_name, const char * ext ) { char * pfile ; char * ppath ; struct dbuf_s dbuf ; char * ret ; pfile = filename( base_name ) ; ppath = dirname( base_name ) ; dbuf_init( &dbuf, 128 ) ; dbuf_append_str( &dbuf, ppath ) ; dbuf_append_str( &dbuf, pfile ) ; dbuf_append_str( &dbuf, ext ) ; ret = dbuf_detach( &dbuf ); free( ppath ) ; free( pfile ) ; return ret ; }
static void _gbz80_rgblink (void) { FILE *lnkfile; struct dbuf_s lnkFileName; char *buffer; dbuf_init (&lnkFileName, PATH_MAX); /* first we need to create the <filename>.lnk file */ dbuf_append_str (&lnkFileName, dstFileName); dbuf_append_str (&lnkFileName, ".lk"); if (!(lnkfile = fopen (dbuf_c_str (&lnkFileName), "w"))) { werror (E_FILE_OPEN_ERR, dbuf_c_str (&lnkFileName)); dbuf_destroy (&lnkFileName); exit (1); } dbuf_destroy (&lnkFileName); fprintf (lnkfile, "[Objects]\n"); fprintf (lnkfile, "%s.rel\n", dstFileName); fputStrSet (lnkfile, relFilesSet); fprintf (lnkfile, "\n[Libraries]\n"); /* additional libraries if any */ fputStrSet (lnkfile, libFilesSet); fprintf (lnkfile, "\n[Output]\n" "%s.gb", dstFileName); fclose (lnkfile); buffer = buildCmdLine (port->linker.cmd, dstFileName, NULL, NULL, NULL); /* call the linker */ if (sdcc_system (buffer)) { Safe_free (buffer); perror ("Cannot exec linker"); exit (1); } Safe_free (buffer); }
VOID DefineNoICE_Line (void) { struct dbuf_s dbuf; struct sym *pSym; /* * Symbol is FILE.nnn */ dbuf_init (&dbuf, NCPS); dbuf_printf (&dbuf, "%s.%u", BaseFileName (asmc, 0), srcline); pSym = lookup (dbuf_c_str (&dbuf)); dbuf_destroy (&dbuf); pSym->s_type = S_USER; pSym->s_area = dot.s_area; pSym->s_addr = laddr; pSym->s_flag |= S_GBL; }
VOID DefineSDCC_Line (void) { struct dbuf_s dbuf; struct sym *pSym; /* * Symbol is A$FILE$nnn */ dbuf_init (&dbuf, NCPS); dbuf_printf (&dbuf, "A$%s$%u", BaseFileName (cfile, 1), srcline[cfile]); pSym = lookup (dbuf_c_str (&dbuf)); dbuf_destroy (&dbuf); pSym->s_type = S_USER; pSym->s_area = dot.s_area; pSym->s_addr = laddr; pSym->s_flag |= S_GBL; }
/*-----------------------------------------------------------------*/ memmap * allocMap (char rspace, /* sfr space */ char farmap, /* far or near segment */ char paged, /* can this segment be paged */ char direct, /* directly addressable */ char bitaddr, /* bit addressable space */ char codemap, /* this is code space */ unsigned sloc, /* starting location */ const char *name, /* 8 character name */ char dbName, /* debug name */ int ptrType /* pointer type for this space */ ) { memmap *map; if (!name) return NULL; if (!(map = Safe_alloc (sizeof (memmap)))) { werror (E_OUT_OF_MEM, __FILE__, sizeof (memmap)); exit (1); } memset (map, ZERO, sizeof (memmap)); map->regsp = rspace; map->fmap = farmap; map->paged = paged; map->direct = direct; map->bitsp = bitaddr; map->codesp = codemap; map->sloc = sloc; map->sname = name; map->dbName = dbName; map->ptrType = ptrType; map->syms = NULL; dbuf_init(&map->oBuf, 4096); return map; }
static void _pic14_finaliseOptions (void) { struct dbuf_s dbuf; pCodeInitRegisters(); port->mem.default_local_map = data; port->mem.default_globl_map = data; dbuf_init (&dbuf, 512); dbuf_printf (&dbuf, "-D__SDCC_PROCESSOR=\"%s\"", port->processor); addSet (&preArgvSet, Safe_strdup (dbuf_detach_c_str (&dbuf))); { char *upperProc, *p1, *p2; int len; dbuf_set_length (&dbuf, 0); len = strlen (port->processor); upperProc = Safe_malloc (len); for (p1 = port->processor, p2 = upperProc; *p1; ++p1, ++p2) { *p2 = toupper (*p1); } dbuf_append (&dbuf, "-D__SDCC_PIC", sizeof ("-D__SDCC_PIC") - 1); dbuf_append (&dbuf, upperProc, len); addSet (&preArgvSet, dbuf_detach_c_str (&dbuf)); } if (!pic14_options.no_warn_non_free && !options.use_non_free) { fprintf(stderr, "WARNING: Command line option --use-non-free not present.\n" " When compiling for PIC14/PIC16, please provide --use-non-free\n" " to get access to device headers and libraries.\n" " If you do not use these, you may provide --no-warn-non-free\n" " to suppress this warning (not recommended).\n"); } // if }
int emcmotErrorPutfv(emcmot_error_t * errlog, const char *fmt, va_list ap) { struct dbuf errbuf; struct dbuf_iter it; if (errlog == 0 || errlog->num == EMCMOT_ERROR_NUM) { /* full */ return -1; } errlog->head++; dbuf_init(&errbuf, (unsigned char*)errlog->error[errlog->end], EMCMOT_ERROR_LEN); dbuf_iter_init(&it, &errbuf); vstashf(&it, fmt, ap); errlog->end = (errlog->end + 1) % EMCMOT_ERROR_NUM; errlog->num++; errlog->tail = errlog->head; return 0; }
int main (int argc, char *argv[]) { /* Check to see if the user is running * us as root, which is a nono */ if (geteuid () == 0) { fprintf (stderr, "Don't run ircd as root!!!\n"); return (-1); } /* save server boot time right away, so getrusage works correctly */ set_time (); /* Setup corefile size immediately after boot -kre */ setup_corefile (); /* set initialVMTop before we allocate any memory */ initialVMTop = get_vm_top (); ServerRunning = 0; /* It ain't random, but it ought to be a little harder to guess */ srand (SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid () << 20))); memset (&me, 0, sizeof (me)); memset (&meLocalUser, 0, sizeof (meLocalUser)); me.localClient = &meLocalUser; dlinkAdd (&me, &me.node, &global_client_list); /* Pointer to beginning of Client list */ memset (&ServerInfo, 0, sizeof (ServerInfo)); /* Initialise the channel capability usage counts... */ init_chcap_usage_counts (); ConfigFileEntry.dpath = DPATH; ConfigFileEntry.configfile = CPATH; /* Server configuration file */ ConfigFileEntry.klinefile = KPATH; /* Server kline file */ ConfigFileEntry.xlinefile = XPATH; /* Server xline file */ ConfigFileEntry.dlinefile = DLPATH; /* dline file */ ConfigFileEntry.cresvfile = CRESVPATH; /* channel resv file */ ConfigFileEntry.nresvfile = NRESVPATH; /* nick resv file */ myargv = argv; umask (077); /* better safe than sorry --SRB */ parseargs (&argc, &argv, myopts); build_version (); if (printVersion) { printf ("ircd: version %s\n", ircd_version); exit (EXIT_SUCCESS); } if (chdir (ConfigFileEntry.dpath)) { perror ("chdir"); exit (EXIT_FAILURE); } if (!server_state.foreground) make_daemon (); else print_startup (getpid ()); #ifdef HAVE_LIBCRYPTO dh_init(); fprintf(stderr, "SSL: Initialize\n"); SSL_load_error_strings(); SSLeay_add_ssl_algorithms(); ServerInfo.ctx = SSL_CTX_new(SSLv23_server_method()); if (!ServerInfo.ctx) { ERR_print_errors_fp(stderr); return 0; } fprintf(stderr, "SSL: Client based SSL connections are enabled.\n"); #endif setup_signals (); /* We need this to initialise the fd array before anything else */ fdlist_init (); if (!server_state.foreground) close_all_connections (); /* this needs to be before init_netio()! */ else check_can_use_v6 (); /* Done in close_all_connections normally */ init_log (logFileName); init_netio (); /* This needs to be setup early ! -- adrian */ /* Check if there is pidfile and daemon already running */ check_pidfile (pidFileName); /* Init the event subsystem */ eventInit (); init_sys (); #ifndef NOBALLOC initBlockHeap (); #endif init_dlink_nodes (); init_slink_nodes (); initialize_message_files (); dbuf_init (); init_hash (); init_ip_hash_table (); /* client host ip hash table */ init_host_hash (); /* Host-hashtable. */ clear_hash_parse (); init_client (); init_user (); init_channels (); init_class (); init_whowas (); init_stats (); init_hooks (); read_conf_files (1); /* cold start init conf files */ initServerMask (); init_uid (); init_auth (); /* Initialise the auth code */ init_resolver (); /* Needs to be setup before the io loop */ init_reject (); /* Set up the reject code. */ init_umodes (); /* Set up the usermode system. */ initialize_foundation_signals(); /* register things that modules need */ #ifdef HAVE_LIBCRYPTO bio_spare_fd = save_spare_fd ("SSL private key validation"); #endif /* HAVE_LIBCRYPTO */ initialize_server_capabs (); /* Set up default_server_capabs */ initialize_global_set_options (); if (ServerInfo.name == NULL) { fprintf (stderr, "ERROR: No server name specified in serverinfo block.\n"); ilog (L_CRIT, "No server name specified in serverinfo block."); exit (EXIT_FAILURE); } strlcpy (me.name, ServerInfo.name, sizeof (me.name)); /* serverinfo{} description must exist. If not, error out. */ if (ServerInfo.description == NULL) { fprintf (stderr, "ERROR: No server description specified in serverinfo block.\n"); ilog (L_CRIT, "ERROR: No server description specified in serverinfo block."); exit (EXIT_FAILURE); } strlcpy (me.info, ServerInfo.description, sizeof (me.info)); me.from = &me; me.servptr = &me; SetMe (&me); make_server (&me); strlcpy (me.serv->up, me.name, sizeof (me.serv->up)); me.lasttime = me.since = me.firsttime = CurrentTime; hash_add_client (&me); /* add ourselves to global_serv_list */ dlinkAdd (&me, make_dlink_node (), &global_serv_list); check_class (); #ifndef STATIC_MODULES if (chdir (MODPATH)) { ilog (L_CRIT, "Could not load core modules. Terminating!"); exit (EXIT_FAILURE); } mod_set_base (); load_all_modules (1); load_core_modules (1); /* Go back to DPATH after checking to see if we can chdir to MODPATH */ chdir (ConfigFileEntry.dpath); #else load_all_modules (1); #endif write_pidfile (pidFileName); ilog (L_NOTICE, "Server Ready"); eventAddIsh ("cleanup_tklines", cleanup_tklines, NULL, CLEANUP_TKLINES_TIME); /* We want try_connections to be called as soon as possible now! -- adrian */ /* No, 'cause after a restart it would cause all sorts of nick collides */ eventAddIsh ("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME); eventAddIsh ("collect_zipstats", collect_zipstats, NULL, ZIPSTATS_TIME); /* Setup the timeout check. I'll shift it later :) -- adrian */ eventAddIsh ("comm_checktimeouts", comm_checktimeouts, NULL, 1); if (splitmode) eventAddIsh ("check_splitmode", check_splitmode, NULL, 60); ServerRunning = 1; io_loop (); return (0); }
/*-----------------------------------------------------------------*/ void picglue () { FILE *asmFile; struct dbuf_s ovrBuf; struct dbuf_s vBuf; dbuf_init(&ovrBuf, 4096); dbuf_init(&vBuf, 4096); pCodeInitRegisters(); /* check for main() */ mainf = newSymbol ("main", 0); mainf->block = 0; mainf = findSymWithLevel (SymbolTab, mainf); if (!mainf || !IFFUNC_HASBODY(mainf->type)) { /* main missing -- import stack from main module */ //fprintf (stderr, "main() missing -- assuming we are NOT the main module\n"); pic14_options.isLibrarySource = 1; } /* At this point we've got all the code in the form of pCode structures */ /* Now it needs to be rearranged into the order it should be placed in the */ /* code space */ movepBlock2Head('P'); // Last movepBlock2Head(code->dbName); movepBlock2Head('X'); movepBlock2Head(statsg->dbName); // First /* print the global struct definitions */ if (options.debug) cdbStructBlock (0); /* do the overlay segments */ pic14emitOverlay(&ovrBuf); /* PENDING: this isnt the best place but it will do */ if (port->general.glue_up_main) { /* create the interrupt vector table */ pic14createInterruptVect (&vBuf); } AnalyzepCode('*'); ReuseReg(); // ReuseReg where call tree permits InlinepCode(); AnalyzepCode('*'); if (options.debug) pcode_test(); /* now put it all together into the assembler file */ /* create the assembler file name */ if ((noAssemble || options.c1mode) && fullDstFileName) { sprintf (buffer, "%s", fullDstFileName); } else { sprintf (buffer, "%s", dstFileName); strcat (buffer, ".asm"); } if (!(asmFile = fopen (buffer, "w"))) { werror (E_FILE_OPEN_ERR, buffer); exit (1); } /* prepare statistics */ resetpCodeStatistics (); /* initial comments */ pic14initialComments (asmFile); /* print module name */ fprintf (asmFile, "%s\t.file\t\"%s\"\n", options.debug ? "" : ";", fullSrcFileName); /* Let the port generate any global directives, etc. */ if (port->genAssemblerPreamble) { port->genAssemblerPreamble(asmFile); } /* Put all variables into a cblock */ AnalyzeBanking(); /* emit initialized data */ showAllMemmaps(asmFile); /* print the locally defined variables in this module */ writeUsedRegs(asmFile); /* create the overlay segments */ fprintf (asmFile, "%s", iComments2); fprintf (asmFile, "; overlayable items in internal ram \n"); fprintf (asmFile, "%s", iComments2); dbuf_write_and_destroy (&ovrBuf, asmFile); /* copy the interrupt vector table */ if (mainf && IFFUNC_HASBODY(mainf->type)) dbuf_write_and_destroy (&vBuf, asmFile); else dbuf_destroy(&vBuf); /* create interupt ventor handler */ pic14_emitInterruptHandler (asmFile); /* copy over code */ fprintf (asmFile, "%s", iComments2); fprintf (asmFile, "; code\n"); fprintf (asmFile, "%s", iComments2); fprintf (asmFile, "code_%s\t%s\n", moduleName, port->mem.code_name); /* unknown */ copypCode(asmFile, 'X'); /* _main function */ copypCode(asmFile, 'M'); /* other functions */ copypCode(asmFile, code->dbName); /* unknown */ copypCode(asmFile, 'P'); dumppCodeStatistics (asmFile); fprintf (asmFile,"\tend\n"); fclose (asmFile); pic14_debugLogClose(); }
/*-----------------------------------------------------------------*/ eBBlock * iCode2eBBlock (iCode * ic) { iCode *loop; eBBlock *ebb = neweBBlock (); /* allocate an entry */ /* put the first one unconditionally */ ebb->sch = ic; ic->seq = 0; /* if this is a label then */ if (ic->op == LABEL) ebb->entryLabel = ic->label; else { struct dbuf_s dbuf; dbuf_init (&dbuf, 128); dbuf_printf (&dbuf, "_eBBlock%d", eBBNum++); ebb->entryLabel = newSymbol (dbuf_c_str (&dbuf), 1); dbuf_destroy (&dbuf); ebb->entryLabel->key = labelKey++; } if (ic && (ic->op == GOTO || ic->op == JUMPTABLE || ic->op == IFX)) { ebb->ech = ebb->sch; return ebb; } /* if this is a function call */ if (ic->op == CALL || ic->op == PCALL) { sym_link *type = operandType (IC_LEFT (ic)); ebb->hasFcall = 1; if (currFunc) FUNC_HASFCALL (currFunc->type) = 1; if (IS_FUNCPTR (type)) type = type->next; if (type && FUNC_ISNORETURN (type)) { ebb->ech = ebb->sch; return ebb; } } if ((ic->next && ic->next->op == LABEL) || !ic->next) { ebb->ech = ebb->sch; return ebb; } /* loop thru till we find one with a label */ for (loop = ic->next; loop; loop = loop->next) { loop->seq = 0; /* if this is the last one */ if (!loop->next) break; /* if this is a function call */ if (loop->op == CALL || loop->op == PCALL) { sym_link *type = operandType (IC_LEFT (loop)); ebb->hasFcall = 1; if (currFunc) FUNC_HASFCALL (currFunc->type) = 1; if (IS_FUNCPTR (type)) type = type->next; if (type && FUNC_ISNORETURN (type)) break; } /* if the next one is a label */ /* if this is a goto or ifx */ if (loop->next->op == LABEL || loop->op == GOTO || loop->op == JUMPTABLE || loop->op == IFX) break; } /* mark the end of the chain */ ebb->ech = loop; return ebb; }
int enum_symbols (FILE * fp, long size, int (*func) (const char *sym, void *param), void *param) { long end; struct dbuf_s buf; struct dbuf_s symname; assert (func != NULL); dbuf_init (&buf, 512); dbuf_init (&symname, 32); end = (size >= 0) ? ftell (fp) + size : -1; /* * Read in the object file. Look for lines that * begin with "S" and end with "D". These are * symbol table definitions. If we find one, see * if it is our symbol. Make sure we only read in * our object file and don't go into the next one. */ while (end < 0 || ftell (fp) < end) { const char *p; dbuf_set_length (&buf, 0); if (dbuf_getline (&buf, fp) == 0) break; p = dbuf_c_str (&buf); /* Skip whitespace */ while (isspace (*p)) p++; /* Skip local symbols or directives */ if ('.' == p[0]) continue; /* * Skip everything that's not a symbol. */ if (isalpha (*p) || '_' == *p) { bool found = false; dbuf_set_length (&symname, 0); while (isalnum (*p) || '_' == *p) dbuf_append_char (&symname, *p++); if (':' == *p) /* a label */ { if (':' == *++p) /* a global label */ found = true; } else /* no label */ { size_t i; /* Skip whitespace */ while (isspace (*p)) p++; for (found = false, i = 0; !found && i < sizeof(directives) / sizeof(symbol_t); i++) { if (0 == strncmp(p, directives[i].text, strlen(directives[i].text))) { switch (directives[i].subtype) { case stEQU: case stBYTE: case stWORD_BE: case stWORD_LE: case stLONG_BE: case stLONG_LE: case stBUFFER: case stTEXT: case stDS: case stDSIN: case stDSOUT: case stDSIO: case stDSROM: case stDSRAM: /* It's a symbol */ found = true; break; default: break; } } } } /* If it's an actual symbol, record it */ if (found) if (func != NULL) if ((*func) (dbuf_c_str (&symname), NULL)) return 1; } } dbuf_destroy (&buf); dbuf_destroy (&symname); return 0; }
int main(int argc, char *argv[]) { int portarg = 0; uid_t uid, euid; time_t delay = 0; int fd; if((timeofday = time(NULL)) == -1) { (void)fprintf(stderr,"ERROR: Clock Failure (%d)\n", errno); exit(errno); } /* * We don't want to calculate these every time they are used :) */ R_do_dns = strlen(REPORT_DO_DNS); R_fin_dns = strlen(REPORT_FIN_DNS); R_fin_dnsc = strlen(REPORT_FIN_DNSC); R_fail_dns = strlen(REPORT_FAIL_DNS); R_do_id = strlen(REPORT_DO_ID); R_fin_id = strlen(REPORT_FIN_ID); R_fail_id = strlen(REPORT_FAIL_ID); Count.server = 1; /* us */ Count.oper = 0; Count.chan = 0; Count.local = 0; Count.total = 0; Count.invisi = 0; Count.unknown = 0; Count.max_loc = 0; Count.max_tot = 0; /* this code by [email protected] */ /* it is intended to keep the ircd from being swapped out. BSD swapping criteria do not match the requirements of ircd */ #ifdef SETUID_ROOT if(plock(TXTLOCK)<0) fprintf(stderr,"could not plock...\n"); if(setuid(IRCD_UID)<0)exit(-1); /* blah.. this should be done better */ #endif #ifdef INITIAL_DBUFS dbuf_init(); /* set up some dbuf stuff to control paging */ #endif sbrk0 = (char *)sbrk((size_t)0); uid = getuid(); euid = geteuid(); #ifdef PROFIL (void)monstartup(0, etext); (void)moncontrol(1); (void)signal(SIGUSR1, s_monitor); #endif #ifdef CHROOTDIR if (chdir(dpath)) { perror("chdir"); exit(-1); } res_init(); if (chroot(DPATH)) { (void)fprintf(stderr,"ERROR: Cannot chdir/chroot\n"); exit(5); } #endif /*CHROOTDIR*/ myargv = argv; (void)umask(077); /* better safe than sorry --SRB */ bzero((char *)&me, sizeof(me)); setup_signals(); /* ** All command line parameters have the syntax "-fstring" ** or "-f string" (e.g. the space is optional). String may ** be empty. Flag characters cannot be concatenated (like ** "-fxyz"), it would conflict with the form "-fstring". */ while (--argc > 0 && (*++argv)[0] == '-') { char *p = argv[0]+1; int flag = *p++; if (flag == '\0' || *p == '\0') if (argc > 1 && argv[1][0] != '-') { p = *++argv; argc -= 1; } else p = ""; switch (flag) { case 'a': bootopt |= BOOT_AUTODIE; break; case 'c': bootopt |= BOOT_CONSOLE; break; case 'q': bootopt |= BOOT_QUICK; break; case 'd' : (void)setuid((uid_t)uid); dpath = p; break; case 'o': /* Per user local daemon... */ (void)setuid((uid_t)uid); bootopt |= BOOT_OPER; break; #ifdef CMDLINE_CONFIG case 'f': (void)setuid((uid_t)uid); configfile = p; break; #ifdef KPATH case 'k': (void)setuid((uid_t)uid); klinefile = p; break; #endif #endif case 'h': strncpyzt(me.name, p, sizeof(me.name)); break; case 'i': bootopt |= BOOT_INETD|BOOT_AUTODIE; break; case 'p': if ((portarg = atoi(p)) > 0 ) portnum = portarg; break; case 's': bootopt |= BOOT_STDERR; break; case 't': (void)setuid((uid_t)uid); bootopt |= BOOT_TTY; break; case 'v': (void)printf("ircd %s\n", version); exit(0); case 'x': #ifdef DEBUGMODE (void)setuid((uid_t)uid); debuglevel = atoi(p); debugmode = *p ? p : "0"; bootopt |= BOOT_DEBUG; break; #else (void)fprintf(stderr, "%s: DEBUGMODE must be defined for -x y\n", myargv[0]); exit(0); #endif default: bad_command(); break; } } #ifndef CHROOT if (chdir(dpath)) { perror("chdir"); exit(-1); } #endif #ifndef IRC_UID if ((uid != euid) && !euid) { (void)fprintf(stderr, "ERROR: do not run ircd setuid root. Make it setuid a\ normal user.\n"); exit(-1); }
static bool _parseOptions (int *pargc, char **argv, int *i) { if (argv[*i][0] == '-') { if (IS_GB) { if (!strncmp (argv[*i], OPTION_BO, sizeof (OPTION_BO) - 1)) { /* ROM bank */ int bank = getIntArg (OPTION_BO, argv, i, *pargc); struct dbuf_s buffer; dbuf_init (&buffer, 16); dbuf_printf (&buffer, "CODE_%u", bank); dbuf_c_str (&buffer); /* ugly, see comment in src/port.h (borutr) */ gbz80_port.mem.code_name = dbuf_detach (&buffer); options.code_seg = (char *)gbz80_port.mem.code_name; return TRUE; } else if (!strncmp (argv[*i], OPTION_BA, sizeof (OPTION_BA) - 1)) { /* RAM bank */ int bank = getIntArg (OPTION_BA, argv, i, *pargc); struct dbuf_s buffer; dbuf_init (&buffer, 16); dbuf_printf (&buffer, "DATA_%u", bank); dbuf_c_str (&buffer); /* ugly, see comment in src/port.h (borutr) */ gbz80_port.mem.data_name = dbuf_detach (&buffer); return TRUE; } } else if (!strncmp (argv[*i], OPTION_ASM, sizeof (OPTION_ASM) - 1)) { char *asmblr = getStringArg (OPTION_ASM, argv, i, *pargc); if (!strcmp (asmblr, "rgbds")) { asm_addTree (&_rgbds_gb); gbz80_port.assembler.cmd = _gbz80_rgbasmCmd; gbz80_port.linker.cmd = _gbz80_rgblinkCmd; gbz80_port.linker.do_link = _gbz80_rgblink; _G.asmType = ASM_TYPE_RGBDS; return TRUE; } else if (!strcmp (asmblr, "asxxxx")) { _G.asmType = ASM_TYPE_ASXXXX; return TRUE; } else if (!strcmp (asmblr, "isas")) { asm_addTree (&_isas_gb); /* Munge the function prefix */ gbz80_port.fun_prefix = ""; _G.asmType = ASM_TYPE_ISAS; return TRUE; } else if (!strcmp (asmblr, "z80asm")) { port->assembler.externGlobal = TRUE; asm_addTree (&_z80asm_z80); _G.asmType = ASM_TYPE_ISAS; return TRUE; } } else if (!strncmp (argv[*i], OPTION_PORTMODE, sizeof (OPTION_PORTMODE) - 1)) { char *portmode = getStringArg (OPTION_ASM, argv, i, *pargc); if (!strcmp (portmode, "z80")) { z80_opts.port_mode = 80; return TRUE; } else if (!strcmp (portmode, "z180")) { z80_opts.port_mode = 180; return TRUE; } } } return FALSE; }
static void _pic14_do_link (void) { /* * link command format: * {linker} {incdirs} {lflags} -o {outfile} {spec_ofiles} {ofiles} {libs} * */ #define LFRM "{linker} {incdirs} {sysincdirs} {lflags} -w -r -o {outfile} {user_ofile} {spec_ofiles} {ofiles} {libs}" hTab *linkValues = NULL; char *lcmd; set *tSet = NULL; int ret; char * procName; shash_add (&linkValues, "linker", "gplink"); /* LIBRARY SEARCH DIRS */ mergeSets (&tSet, libPathsSet); mergeSets (&tSet, libDirsSet); shash_add (&linkValues, "incdirs", joinStrSet (processStrSet (tSet, "-I", NULL, shell_escape))); joinStrSet (processStrSet (libDirsSet, "-I", NULL, shell_escape)); shash_add (&linkValues, "sysincdirs", joinStrSet (processStrSet (libDirsSet, "-I", NULL, shell_escape))); shash_add (&linkValues, "lflags", joinStrSet (linkOptionsSet)); { char *s = shell_escape (fullDstFileName ? fullDstFileName : dstFileName); shash_add (&linkValues, "outfile", s); Safe_free (s); } if (fullSrcFileName) { struct dbuf_s dbuf; char *s; dbuf_init (&dbuf, 128); dbuf_append_str (&dbuf, fullDstFileName ? fullDstFileName : dstFileName); dbuf_append (&dbuf, ".o", 2); s = shell_escape (dbuf_c_str (&dbuf)); dbuf_destroy (&dbuf); shash_add (&linkValues, "user_ofile", s); Safe_free (s); } shash_add (&linkValues, "ofiles", joinStrSet (processStrSet (relFilesSet, NULL, NULL, shell_escape))); /* LIBRARIES */ procName = processor_base_name (); if (!procName) procName = "16f877"; addSet (&libFilesSet, Safe_strdup (pic14_getPIC()->isEnhancedCore ? "libsdcce.lib" : "libsdcc.lib")); { struct dbuf_s dbuf; dbuf_init (&dbuf, 128); dbuf_append (&dbuf, "pic", sizeof ("pic") - 1); dbuf_append_str (&dbuf, procName); dbuf_append (&dbuf, ".lib", sizeof (".lib") - 1); addSet (&libFilesSet, dbuf_detach_c_str (&dbuf)); } shash_add (&linkValues, "libs", joinStrSet (processStrSet (libFilesSet, NULL, NULL, shell_escape))); lcmd = msprintf(linkValues, LFRM); ret = sdcc_system (lcmd); Safe_free (lcmd); if (ret) exit (1); }
dbuf *dbuf_new(unsigned sz) { dbuf *d = malloc(sizeof(dbuf) + sz); if(d) dbuf_init(d, (unsigned char*)(d+1), sz); return d; }
int main(int argc, char *argv[]) { /* Check to see if the user is running us as root, which is a nono */ if (!geteuid()) { fprintf(stderr, "ERROR: This server won't run as root/superuser\n"); return -1; } /* Setup corefile size immediately after boot -kre */ setup_corefile(); /* Save server boot time right away, so getrusage works correctly */ set_time(); /* It's not random, but it ought to be a little harder to guess */ init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20))); dlinkAdd(&me, &me.node, &global_client_list); ConfigGeneral.dpath = DPATH; ConfigGeneral.spath = SPATH; ConfigGeneral.mpath = MPATH; ConfigGeneral.configfile = CPATH; /* Server configuration file */ ConfigGeneral.klinefile = KPATH; /* Server kline file */ ConfigGeneral.glinefile = GPATH; /* Server gline file */ ConfigGeneral.xlinefile = XPATH; /* Server xline file */ ConfigGeneral.dlinefile = DLPATH; /* dline file */ ConfigGeneral.resvfile = RESVPATH; /* resv file */ myargv = argv; umask(077); /* umask 077: u=rwx,g=,o= */ parseargs(&argc, &argv, myopts); if (printVersion) { printf("ircd: version %s(%s)\n", ircd_version, serno); exit(EXIT_SUCCESS); } if (chdir(ConfigGeneral.dpath)) { perror("chdir"); exit(EXIT_FAILURE); } ssl_init(); if (!server_state.foreground) { make_daemon(); close_standard_fds(); /* this needs to be before init_netio()! */ } else print_startup(getpid()); setup_signals(); /* We need this to initialise the fd array before anything else */ fdlist_init(); log_set_file(LOG_TYPE_IRCD, 0, logFileName); init_netio(); /* This needs to be setup early ! -- adrian */ /* Check if there is pidfile and daemon already running */ check_pidfile(pidFileName); mp_pool_init(); init_dlink_nodes(); init_isupport(); dbuf_init(); hash_init(); ipcache_init(); client_init(); class_init(); whowas_init(); watch_init(); auth_init(); /* Initialise the auth code */ init_resolver(); /* Needs to be setup before the io loop */ modules_init(); read_conf_files(1); /* cold start init conf files */ init_uid(); initialize_server_capabs(); /* Set up default_server_capabs */ initialize_global_set_options(); /* Has to be called after read_conf_files() */ channel_init(); read_links_file(); motd_init(); user_usermodes_init(); #ifdef HAVE_LIBGEOIP geoip_ctx = GeoIP_new(GEOIP_MEMORY_CACHE); #endif if (EmptyString(ConfigServerInfo.sid)) { ilog(LOG_TYPE_IRCD, "ERROR: No server id specified in serverinfo block."); exit(EXIT_FAILURE); } strlcpy(me.id, ConfigServerInfo.sid, sizeof(me.id)); if (EmptyString(ConfigServerInfo.name)) { ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block."); exit(EXIT_FAILURE); } strlcpy(me.name, ConfigServerInfo.name, sizeof(me.name)); /* serverinfo{} description must exist. If not, error out.*/ if (EmptyString(ConfigServerInfo.description)) { ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block."); exit(EXIT_FAILURE); } strlcpy(me.info, ConfigServerInfo.description, sizeof(me.info)); me.from = &me; me.servptr = &me; me.connection->lasttime = CurrentTime; me.connection->since = CurrentTime; me.connection->firsttime = CurrentTime; SetMe(&me); make_server(&me); hash_add_id(&me); hash_add_client(&me); dlinkAdd(&me, make_dlink_node(), &global_server_list); load_kline_database(); load_dline_database(); load_gline_database(); load_xline_database(); load_resv_database(); load_all_modules(1); load_conf_modules(); load_core_modules(1); write_pidfile(pidFileName); ilog(LOG_TYPE_IRCD, "Server Ready"); event_addish(&event_cleanup_glines, NULL); event_addish(&event_cleanup_tklines, NULL); /* We want try_connections to be called as soon as possible now! -- adrian */ /* No, 'cause after a restart it would cause all sorts of nick collides */ event_addish(&event_try_connections, NULL); /* Setup the timeout check. I'll shift it later :) -- adrian */ event_add(&event_comm_checktimeouts, NULL); event_addish(&event_save_all_databases, NULL); if (ConfigServerHide.links_delay > 0) { event_write_links_file.when = ConfigServerHide.links_delay; event_addish(&event_write_links_file, NULL); } else ConfigServerHide.links_disabled = 1; if (splitmode) event_addish(&splitmode_event, NULL); io_loop(); return 0; }
int main(int argc, char *argv[]) { uid_t uid, euid; int portarg = 0, fd; #ifdef SAVE_MAXCLIENT_STATS FILE *mcsfp; #endif memset(&me, 0, sizeof(aClient)); if ((timeofday = time(NULL)) == -1) { (void) fprintf(stderr, "ERROR: Clock Failure (%d)\n", errno); exit(errno); } build_version(); Count.server = 1; /* us */ Count.oper = 0; Count.chan = 0; Count.local = 0; Count.total = 0; Count.invisi = 0; Count.unknown = 0; Count.max_loc = 0; Count.max_tot = 0; Count.today = 0; Count.weekly = 0; Count.monthly = 0; Count.yearly = 0; Count.start = NOW; Count.day = NOW; Count.week = NOW; Count.month = NOW; Count.year = NOW; #ifdef SAVE_MAXCLIENT_STATS mcsfp=fopen(DPATH "/.maxclients", "r"); if(mcsfp!=NULL) { fscanf(mcsfp, "%d %d %li %li %li %ld %ld %ld %ld", &Count.max_loc, &Count.max_tot, &Count.weekly, &Count.monthly, &Count.yearly, &Count.start, &Count.week, &Count.month, &Count.year); fclose(mcsfp); } #endif /* * this code by [email protected] * it is intended to keep the ircd from being swapped out. BSD * swapping criteria do not match the requirements of ircd */ #ifdef INITIAL_DBUFS dbuf_init(); /* set up some dbuf stuff to control paging */ #endif sbrk0 = (char *) sbrk((size_t) 0); uid = getuid(); euid = geteuid(); #ifdef PROFIL (void) monstartup(0, etext); (void) moncontrol(1); (void) signal(SIGUSR1, s_monitor); #endif myargv = argv; (void) umask(077); /* better safe than sorry --SRB */ memset((char *) &me, '\0', sizeof(me)); setup_signals(); /* * * All command line parameters have the syntax "-fstring" or "-f * string" (e.g. the space is optional). String may be empty. Flag * characters cannot be concatenated (like "-fxyz"), it would * conflict with the form "-fstring". */ while (--argc > 0 && (*++argv)[0] == '-') { char *p = argv[0] + 1; int flag = *p++; if (flag == '\0' || *p == '\0') { if (argc > 1 && argv[1][0] != '-') { p = *++argv; argc -= 1; } else p = ""; } switch (flag) { case 'a': bootopt |= BOOT_AUTODIE; break; case 'c': bootopt |= BOOT_CONSOLE; break; case 'q': bootopt |= BOOT_QUICK; break; case 'd': (void) setuid((uid_t) uid); dpath = p; break; case 'o': /* Per user local daemon... */ (void) setuid((uid_t) uid); bootopt |= BOOT_OPER; break; #ifdef CMDLINE_CONFIG case 'f': (void) setuid((uid_t) uid); configfile = p; break; # ifdef KPATH case 'k': (void) setuid((uid_t) uid); klinefile = p; break; # endif #endif case 'h': strncpyzt(me.name, p, sizeof(me.name)); break; case 'i': bootopt |= BOOT_INETD | BOOT_AUTODIE; break; case 'p': if ((portarg = atoi(p)) > 0) portnum = portarg; break; case 's': bootopt |= BOOT_STDERR; break; case 't': (void) setuid((uid_t) uid); bootopt |= BOOT_TTY; break; case 'v': (void) printf("ircd %s\n", version); exit(0); case 'x': #ifdef DEBUGMODE (void) setuid((uid_t) uid); debuglevel = atoi(p); debugmode = *p ? p : "0"; bootopt |= BOOT_DEBUG; break; #else (void) fprintf(stderr, "%s: DEBUGMODE must be defined for -x y\n", myargv[0]); exit(0); #endif default: bad_command(); break; } } if (chdir(dpath)) { perror("chdir"); exit(-1); } if ((uid != euid) && !euid) { (void) fprintf(stderr, "ERROR: do not run ircd setuid root. Make it setuid a normal user.\n"); exit(-1); } if (argc > 0) return bad_command(); /* This should exit out */ initialize_ssl(); motd = (aMotd *) NULL; helpfile = (aMotd *) NULL; motd_tm = NULL; #ifdef SHORT_MOTD shortmotd = NULL; #endif read_motd(MOTD); read_help(HELPFILE); #ifdef SHORT_MOTD read_shortmotd(SHORTMOTD); #endif clear_client_hash_table(); clear_channel_hash_table(); clear_scache_hash_table(); /* server cache name table */ clear_ip_hash_table(); /* client host ip hash table */ initlists(); initclass(); initwhowas(); initstats(); init_tree_parse(msgtab); init_send(); NOW = time(NULL); open_debugfile(); NOW = time(NULL); init_fdlist(&serv_fdlist); init_fdlist(&oper_fdlist); init_fdlist(&listen_fdlist); #ifndef NO_PRIORITY init_fdlist(&busycli_fdlist); #endif init_fdlist(&default_fdlist); { int i; for (i = MAXCONNECTIONS + 1; i > 0; i--) { default_fdlist.entry[i] = i - 1; } } if ((timeofday = time(NULL)) == -1) { #ifdef USE_SYSLOG syslog(LOG_WARNING, "Clock Failure (%d), TS can be corrupted", errno); #endif sendto_ops("Clock Failure (%d), TS can be corrupted", errno); } #ifdef WINGATE_NOTICE strcpy(ProxyMonURL, "http://"); strncpyzt((ProxyMonURL + 7), DEFAULT_PROXY_INFO_URL, (TOPICLEN + 1) - 7); strncpyzt(ProxyMonHost, MONITOR_HOST, (HOSTLEN + 1)); #endif if (portnum < 0) portnum = PORTNUM; me.port = portnum; (void) init_sys(); me.flags = FLAGS_LISTEN; #ifndef _WIN32 if (bootopt & BOOT_INETD) { me.fd = 0; local[0] = &me; me.flags = FLAGS_LISTEN; } else #endif me.fd = -1; #ifdef USE_SYSLOG # define SYSLOG_ME "ircd" openlog(SYSLOG_ME, LOG_PID | LOG_NDELAY, LOG_FACILITY); #endif if ((fd = openconf(configfile)) == -1) { Debug((DEBUG_FATAL, "Failed in reading configuration file %s", configfile)); (void) printf("Couldn't open configuration file %s\n", configfile); exit(-1); } (void) initconf(bootopt, fd); /* comstuds SEPARATE_QUOTE_KLINES_BY_DATE code */ #ifdef SEPARATE_QUOTE_KLINES_BY_DATE { struct tm *tmptr; char timebuffer[20], filename[200]; tmptr = localtime(&NOW); (void) strftime(timebuffer, 20, "%y%m%d", tmptr); ircsprintf(filename, "%s.%s", klinefile, timebuffer); if ((fd = openconf(filename)) == -1) { Debug((DEBUG_ERROR, "Failed reading kline file %s", filename)); (void) printf("Couldn't open kline file %s\n", filename); } else (void) initconf(0, fd); } #else # ifdef KPATH if ((fd = openconf(klinefile)) == -1) { Debug((DEBUG_ERROR, "Failed reading kline file %s", klinefile)); (void) printf("Couldn't open kline file %s\n", klinefile); } else (void) initconf(0, fd); # endif #endif if (!(bootopt & BOOT_INETD)) { static char star[] = "*"; aConfItem *aconf; u_long vaddr; if ((aconf = find_me()) && portarg <= 0 && aconf->port > 0) portnum = aconf->port; Debug((DEBUG_ERROR, "Port = %d", portnum)); if ((aconf->passwd[0] != '\0') && (aconf->passwd[0] != '*')) vaddr = inet_addr(aconf->passwd); else vaddr = (u_long) NULL; if (inetport(&me, star, portnum, vaddr)) { if (bootopt & BOOT_STDERR) fprintf(stderr, "Couldn't bind to primary port %d\n", portnum); #ifdef USE_SYSLOG (void) syslog(LOG_CRIT, "Couldn't bind to primary port %d\n", portnum); #endif exit(1); } } else if (inetport(&me, "*", 0, 0)) { if (bootopt & BOOT_STDERR) fprintf(stderr, "Couldn't bind to port passed from inetd\n"); #ifdef USE_SYSLOG (void) syslog(LOG_CRIT, "Couldn't bind to port passed from inetd\n"); #endif exit(1); } (void) get_my_name(&me, me.sockhost, sizeof(me.sockhost) - 1); if (me.name[0] == '\0') strncpyzt(me.name, me.sockhost, sizeof(me.name)); me.hopcount = 0; me.authfd = -1; me.confs = NULL; me.next = NULL; me.user = NULL; me.from = &me; SetMe(&me); make_server(&me); me.serv->up = me.name; me.lasttime = me.since = me.firsttime = NOW; (void) add_to_client_hash_table(me.name, &me); /* We don't want to calculate these every time they are used :) */ sprintf(REPORT_DO_DNS, REPORT_DO_DNS_, me.name); sprintf(REPORT_FIN_DNS, REPORT_FIN_DNS_, me.name); sprintf(REPORT_FIN_DNSC, REPORT_FIN_DNSC_, me.name); sprintf(REPORT_FAIL_DNS, REPORT_FAIL_DNS_, me.name); sprintf(REPORT_DO_ID, REPORT_DO_ID_, me.name); sprintf(REPORT_FIN_ID, REPORT_FIN_ID_, me.name); sprintf(REPORT_FAIL_ID, REPORT_FAIL_ID_, me.name); R_do_dns = strlen(REPORT_DO_DNS); R_fin_dns = strlen(REPORT_FIN_DNS); R_fin_dnsc = strlen(REPORT_FIN_DNSC); R_fail_dns = strlen(REPORT_FAIL_DNS); R_do_id = strlen(REPORT_DO_ID); R_fin_id = strlen(REPORT_FIN_ID); R_fail_id = strlen(REPORT_FAIL_ID); check_class(); if (bootopt & BOOT_OPER) { aClient *tmp = add_connection(&me, 0); if (!tmp) exit(1); SetMaster(tmp); } else write_pidfile(); Debug((DEBUG_NOTICE, "Server ready...")); #ifdef USE_SYSLOG syslog(LOG_NOTICE, "Server Ready"); #endif NOW = time(NULL); #ifndef NO_PRIORITY check_fdlists(); #endif if ((timeofday = time(NULL)) == -1) { #ifdef USE_SYSLOG syslog(LOG_WARNING, "Clock Failure (%d), TS can be corrupted", errno); #endif sendto_ops("Clock Failure (%d), TS can be corrupted", errno); } #ifdef DUMP_DEBUG dumpfp=fopen("dump.log", "w"); #endif io_loop(); return 0; }
static void _setValues (void) { const char *s; struct dbuf_s dbuf; if (options.nostdlib == FALSE) { const char *s; char *path; struct dbuf_s dbuf; dbuf_init (&dbuf, PATH_MAX); for (s = setFirstItem (libDirsSet); s != NULL; s = setNextItem (libDirsSet)) { path = buildCmdLine2 ("-k\"%s" DIR_SEPARATOR_STRING "{port}\" ", s); dbuf_append_str (&dbuf, path); Safe_free (path); } path = buildCmdLine2 ("-l\"{port}.lib\"", s); dbuf_append_str (&dbuf, path); Safe_free (path); setMainValue ("z80libspec", dbuf_c_str (&dbuf)); dbuf_destroy (&dbuf); for (s = setFirstItem (libDirsSet); s != NULL; s = setNextItem (libDirsSet)) { struct stat stat_buf; path = buildCmdLine2 ("%s" DIR_SEPARATOR_STRING "{port}" DIR_SEPARATOR_STRING "crt0{objext}", s); if (stat (path, &stat_buf) == 0) { Safe_free (path); break; } else Safe_free (path); } if (s == NULL) setMainValue ("z80crt0", "\"crt0{objext}\""); else { struct dbuf_s dbuf; dbuf_init (&dbuf, 128); dbuf_printf (&dbuf, "\"%s\"", path); setMainValue ("z80crt0", dbuf_c_str (&dbuf)); dbuf_destroy (&dbuf); } } else { setMainValue ("z80libspec", ""); setMainValue ("z80crt0", ""); } setMainValue ("z80extralibfiles", (s = joinStrSet (libFilesSet))); Safe_free ((void *) s); setMainValue ("z80extralibpaths", (s = joinStrSet (libPathsSet))); Safe_free ((void *) s); if (IS_GB) { setMainValue ("z80outputtypeflag", "-Z"); setMainValue ("z80outext", ".gb"); } else { setMainValue ("z80outputtypeflag", "-i"); setMainValue ("z80outext", ".ihx"); } setMainValue ("stdobjdstfilename", "{dstfilename}{objext}"); setMainValue ("stdlinkdstfilename", "{dstfilename}{z80outext}"); setMainValue ("z80extraobj", (s = joinStrSet (relFilesSet))); Safe_free ((void *) s); dbuf_init (&dbuf, 128); dbuf_printf (&dbuf, "-b_CODE=0x%04X -b_DATA=0x%04X", options.code_loc, options.data_loc); setMainValue ("z80bases", dbuf_c_str (&dbuf)); dbuf_destroy (&dbuf); /* For the old register allocator (with the new one we decide to omit the frame pointer for each function individually) */ if (!IS_GB && options.omitFramePtr) port->stack.call_overhead = 2; }
int main(int argc, char *argv[]) { time_t delay = 0; aConfItem* aconf; if(geteuid() == 0) { fprintf(stderr, "ERROR: Don't run ircd as root!\n"); return -1; } /* * save server boot time right away, so getrusage works correctly */ if ((CurrentTime = time(0)) == -1) { fprintf(stderr, "ERROR: Clock Failure: %s\n", strerror(errno)); exit(errno); } /* * Setup corefile size immediately after boot */ setup_corefile(); /* * set initialVMTop before we allocate any memory */ initialVMTop = get_vm_top(); /* * Initialize the Blockheap allocator */ initBlockHeap(); ServerRunning = 0; memset(&me, 0, sizeof(me)); GlobalClientList = &me; /* Pointer to beginning of Client list */ cold_start = YES; /* set when server first starts up */ memset(&Count, 0, sizeof(Count)); Count.server = 1; /* us */ initialize_global_set_options(); #ifdef REJECT_HOLD reject_held_fds = 0; #endif ConfigFileEntry.dpath = DPATH; ConfigFileEntry.configfile = CPATH; /* Server configuration file */ #ifdef KPATH ConfigFileEntry.klinefile = KPATH; /* Server kline file */ #else ConfigFileEntry.klinefile = CPATH; #endif /* KPATH */ #ifdef DLPATH ConfigFileEntry.dlinefile = DLPATH; #else ConfigFileEntry.dlinefile = CPATH; #endif /* DLPATH */ #ifdef GLINES ConfigFileEntry.glinefile = GLINEFILE; #endif #ifdef ZIP_LINKS /* Make sure the include files match the library version number. */ /* configure takes care of looking for zlib and zlibVersion(). */ if (strcmp(zlibVersion(), ZLIB_VERSION) != 0) { fprintf(stderr, "WARNING: zlib include files differ from library.\n"); fprintf(stderr, "WARNING: ZIPLINKS may fail!\n"); fprintf(stderr, "WARNING: library %s, include files %s\n", zlibVersion(), ZLIB_VERSION); } #endif myargv = argv; umask(077); /* better safe than sorry --SRB */ parse_command_line(argc, argv); if (chdir(ConfigFileEntry.dpath)) { perror("chdir"); exit(-1); } /* * Check if daemon is already running */ check_pidfile(); init_sys(bootDaemon); init_log(logFileName); setup_signals(); initialize_message_files(); isupport = make_isupport(); dbuf_init(); /* set up some dbuf stuff to control paging */ init_hash(); clear_scache_hash_table(); /* server cache name table */ clear_ip_hash_table(); /* client host ip hash table */ clear_Dline_table(); /* d line tree */ initlists(); initclass(); initwhowas(); init_stats(); init_tree_parse(msgtab); /* tree parse code (orabidoo) */ fdlist_init(); init_netio(); read_conf_files(YES); /* cold start init conf files */ aconf = find_me(); if (EmptyString(me.name)) strncpy_irc(me.name, aconf->host, HOSTLEN); strncpy_irc(me.host, aconf->host, HOSTLEN); me.fd = -1; me.from = &me; me.servptr = &me; SetMe(&me); make_server(&me); me.serv->up = me.name; me.lasttime = me.since = me.firsttime = CurrentTime; add_to_client_hash_table(me.name, &me); check_class(); write_pidfile(); log(L_NOTICE, "Server Ready"); ServerRunning = 1; while (ServerRunning) { usleep(100000); do_adns_io(); delay = io_loop(delay); do_adns_io(); } return 0; }
/*-----------------------------------------------------------------*/ static symbol * createStackSpil (symbol * sym) { symbol *sloc = NULL; struct dbuf_s dbuf; D (D_ALLOC, ("createStackSpil: for sym %p %s\n", sym, sym->name)); /* first go try and find a free one that is already existing on the stack */ if (applyToSet (_G.stackSpil, isFreeSTM8, &sloc, sym)) { /* found a free one : just update & return */ sym->usl.spillLoc = sloc; sym->stackSpil = 1; sloc->isFree = 0; addSetHead (&sloc->usl.itmpStack, sym); D (D_ALLOC, ("createStackSpil: found existing\n")); return sym; } /* could not then have to create one , this is the hard part we need to allocate this on the stack : this is really a hack!! but cannot think of anything better at this time */ dbuf_init (&dbuf, 128); dbuf_printf (&dbuf, "sloc%d", _G.slocNum++); sloc = newiTemp (dbuf_c_str (&dbuf)); dbuf_destroy (&dbuf); /* set the type to the spilling symbol */ sloc->type = copyLinkChain (sym->type); sloc->etype = getSpec (sloc->type); SPEC_SCLS (sloc->etype) = S_AUTO; SPEC_EXTR (sloc->etype) = 0; SPEC_STAT (sloc->etype) = 0; SPEC_VOLATILE (sloc->etype) = 0; allocLocal (sloc); sloc->isref = 1; /* to prevent compiler warning */ wassertl (currFunc, "Local variable used outside of function."); /* if it is on the stack then update the stack */ if (IN_STACK (sloc->etype)) { if (currFunc) currFunc->stack += getSize (sloc->type); _G.stackExtend += getSize (sloc->type); } else { _G.dataExtend += getSize (sloc->type); } /* add it to the stackSpil set */ addSetHead (&_G.stackSpil, sloc); sym->usl.spillLoc = sloc; sym->stackSpil = 1; /* add it to the set of itempStack set of the spill location */ addSetHead (&sloc->usl.itmpStack, sym); D (D_ALLOC, ("createStackSpil: created new\n")); return sym; }
static void _setValues(void) { const char *s; if (options.nostdlib == FALSE) { const char *s; char path[PATH_MAX]; struct dbuf_s dbuf; dbuf_init(&dbuf, PATH_MAX); for (s = setFirstItem(libDirsSet); s != NULL; s = setNextItem(libDirsSet)) { buildCmdLine2(path, sizeof path, "-k\"%s" DIR_SEPARATOR_STRING "{port}\" ", s); dbuf_append_str(&dbuf, path); } buildCmdLine2(path, sizeof path, "-l\"{port}.lib\"", s); dbuf_append_str(&dbuf, path); setMainValue ("z80libspec", dbuf_c_str(&dbuf)); dbuf_destroy(&dbuf); for (s = setFirstItem(libDirsSet); s != NULL; s = setNextItem(libDirsSet)) { struct stat stat_buf; buildCmdLine2(path, sizeof path, "%s" DIR_SEPARATOR_STRING "{port}" DIR_SEPARATOR_STRING "crt0{objext}", s); if (stat(path, &stat_buf) == 0) break; } if (s == NULL) setMainValue ("z80crt0", "\"crt0{objext}\""); else { char *buf; size_t len = strlen(path) + 3; buf = Safe_alloc(len); SNPRINTF(buf, len, "\"%s\"", path); setMainValue("z80crt0", buf); Safe_free(buf); } } else { setMainValue ("z80libspec", ""); setMainValue ("z80crt0", ""); } setMainValue ("z80extralibfiles", (s = joinStrSet(libFilesSet))); Safe_free((void *)s); setMainValue ("z80extralibpaths", (s = joinStrSet(libPathsSet))); Safe_free((void *)s); if (IS_GB) { setMainValue ("z80outputtypeflag", "-Z"); setMainValue ("z80outext", ".gb"); } else { setMainValue ("z80outputtypeflag", "-i"); setMainValue ("z80outext", ".ihx"); } setMainValue ("stdobjdstfilename" , "{dstfilename}{objext}"); setMainValue ("stdlinkdstfilename", "{dstfilename}{z80outext}"); setMainValue ("z80extraobj", (s = joinStrSet(relFilesSet))); Safe_free((void *)s); sprintf (buffer, "-b_CODE=0x%04X -b_DATA=0x%04X", options.code_loc, options.data_loc); setMainValue ("z80bases", buffer); }
static int do_pragma(int id, const char *name, const char *cp) { struct pragma_token_s token; int err = 0; int processed = 1; init_pragma_token(&token); switch (id) { case P_BANK: { struct dbuf_s buffer; dbuf_init(&buffer, 128); cp = get_pragma_token(cp, &token); switch (token.type) { case TOKEN_EOL: err = 1; break; case TOKEN_INT: switch (_G.asmType) { case ASM_TYPE_ASXXXX: dbuf_printf (&buffer, "CODE_%d", token.val.int_val); break; case ASM_TYPE_RGBDS: dbuf_printf (&buffer, "CODE,BANK[%d]", token.val.int_val); break; case ASM_TYPE_ISAS: /* PENDING: what to use for ISAS? */ dbuf_printf (&buffer, "CODE,BANK(%d)", token.val.int_val); break; default: wassert (0); } break; default: { const char *str = get_pragma_string (&token); dbuf_append_str (&buffer, (0 == strcmp("BASE", str)) ? "HOME" : str); } break; } cp = get_pragma_token (cp, &token); if (TOKEN_EOL != token.type) { err = 1; break; } dbuf_c_str (&buffer); /* ugly, see comment in src/port.h (borutr) */ gbz80_port.mem.code_name = dbuf_detach (&buffer); code->sname = gbz80_port.mem.code_name; options.code_seg = (char *)gbz80_port.mem.code_name; } break; case P_PORTMODE: { /*.p.t.20030716 - adding pragma to manipulate z80 i/o port addressing modes */ const char *str; cp = get_pragma_token (cp, &token); if (TOKEN_EOL == token.type) { err = 1; break; } str = get_pragma_string (&token); cp = get_pragma_token (cp, &token); if (TOKEN_EOL != token.type) { err = 1; break; } if (!strcmp(str, "z80")) { z80_opts.port_mode = 80; } else if(!strcmp(str, "z180")) { z80_opts.port_mode = 180; } else if(!strcmp(str, "save")) { z80_opts.port_back = z80_opts.port_mode; } else if(!strcmp(str, "restore" )) { z80_opts.port_mode = z80_opts.port_back; } else err = 1; } break; case P_CODESEG: case P_CONSTSEG: { char *segname; cp = get_pragma_token (cp, &token); if (token.type == TOKEN_EOL) { err = 1; break; } segname = Safe_strdup (get_pragma_string(&token)); cp = get_pragma_token (cp, &token); if (token.type != TOKEN_EOL) { Safe_free (segname); err = 1; break; } if (id == P_CODESEG) { if (options.code_seg) Safe_free(options.code_seg); options.code_seg = segname; } else { if (options.const_seg) Safe_free(options.const_seg); options.const_seg = segname; } } break; default: processed = 0; break; } get_pragma_token(cp, &token); if (1 == err) werror(W_BAD_PRAGMA_ARGUMENTS, name); free_pragma_token(&token); return processed; }