/*************************** Re-Allocate a block *****************************/ void *memralloc( MEM *pMEM, void *ptr, unsigned int sz ) { MEMCELL *pCell; char *rptr; int found=0; if( !MEM_initialized(pMEM) ) return NULL; #ifdef DEBUG printf( "Trying to reallocate block at %x of size:%d \n", ptr, sz ); printf( "Memory Manager Before Allocation: \n" ); meminfo( pMEM ); #endif /* Find block */ pCell = MEM_cells(pMEM); while( pCell != NULL ) { if( MEMCELL_pointer(pCell) == ptr ) { /* reallocate */ rptr = (void*) realloc(ptr,sz) ; if( rptr ) { MEM_usage(pMEM) -= MEMCELL_size(pCell); MEMCELL_size(pCell) = sz; MEMCELL_pointer(pCell) = rptr; MEM_usage(pMEM) += sz; } else { printf( "***Error*** Out of Heap Memory\n" ); exit( -1 ); } found = 1; break; /* from while loop */ } pCell = MEMCELL_next(pCell); } #ifdef DEBUG printf( "Success in reallocation of block of size:%d new loc: %x\n", sz, rptr ); printf( "Memory Manager After Allocation: \n" ); meminfo( pMEM ); #endif if( !found ) { printf( "***Error*** Invalid pointer passed to be reallocated.\n" ); } return( rptr ); }
/***************************** Allocate a block *****************************/ void *memalloc( MEM *pMEM, unsigned int sz ) { MEMCELL *pCell; char *rptr; if( !MEM_initialized(pMEM) ) return( NULL ); #ifdef DEBUG printf( "Trying to allocate block of size:%d \n", sz ); printf( "Memory Manager Before Allocation: \n" ); meminfo( pMEM ); #endif /* allocate on heap */ rptr = (char *) malloc( sz ); if( rptr == NULL ) { printf( "***Error*** Out of Heap Memory\n" ); exit( -1 ); } memset(rptr,0,sz); pCell = (MEMCELL *) malloc(sizeof(MEMCELL)); if( pCell ) { memset(MEMCELL_name(pCell),0,sizeof(MEMCELL_name(pCell))); MEMCELL_size(pCell) = sz; MEMCELL_pointer(pCell) = rptr; MEMCELL_next(pCell) = NULL; MEM_usage(pMEM) += sz; if( MEM_cells(pMEM) == NULL ) { MEM_cells(pMEM) = pCell; } else { MEMCELL_next(pCell) = MEM_cells(pMEM); MEM_cells(pMEM) = pCell; } } else { printf( "***Error*** Out of Heap Memory\n" ); exit( -1 ); } #ifdef DEBUG printf( "Success in allocation of block of size:%d \n", sz ); printf( "Memory Manager After Allocation: \n" ); meminfo( pMEM ); #endif return( rptr ); }
static int cmd_test(int ac, char **av) { __console_alloc(); if (ac==1) { cpuinfo(); meminfo(); uartinfo(); netinfo(); } else if(!strcmp(av[1],"cpu")) cpuinfo(); else if(!strcmp(av[1],"mem")) meminfo(); else if(!strcmp(av[1],"uart")) uartinfo(); else if(!strcmp(av[1],"net")) netinfo(); pause1(); }
gint settime(gpointer data) { char lt[100],lm[100],ltip[200],cr[10],ct[10],crs[10],cts[10],hms[10],cmu[10],cmt[10],cpusage[20]; int rs,ts,memusage=0; uptime(hms); cpustat(cpusage); meminfo(); mu=mt-mf; memusage=mu*100/mt; strcpy(cmt,B2G(mt*1024)); strcpy(cmu,B2G(mu*1024)); netdev(); strcpy(cr,B2G(r1)); strcpy(ct,B2G(t1)); rs=r1-r0; ts=t1-t0; strcpy(crs,B2G(rs)); strcpy(cts,B2G(ts)); sprintf(lt,"D:%s/s\nU:%s/s",crs,cts); sprintf(lm,"<span foreground='white'>D:%s/s\nU:%s/s</span>",crs,cts); sprintf(ltip,"开机: %s\nCPU: %s\n内存: %s/%s=%d%%\n下载: %s , %s/s\n上传: %s , %s/s",hms,cpusage,cmu,cmt,memusage,cr,crs,ct,cts); g_message(lt); //gtk_label_set_text(GTK_LABEL(label),lt); gtk_label_set_markup(GTK_LABEL(label), lm); gtk_tooltips_set_tip(tooltips,label,ltip,NULL); r0=r1; t0=t1; return TRUE; }
void MemoryWidget::updateFreeMemory() { #ifdef __linux__ meminfo(); unsigned long mi = S(kb_main_free + kb_main_buffers + kb_main_cached); setText(tr("%1 MB available").arg(mi / (1024 * 1024))); #endif }
/* * Reads the memory info and displays it. Returns the total memory * available, for use in percent memory usage calculations. */ unsigned show_meminfo(void) { unsigned **mem; if (!(mem = meminfo()) || /* read+parse /proc/meminfo */ mem[meminfo_main][meminfo_total] == 0) { /* cannot normalize mem usage */ fprintf(stderr, "Cannot get size of memory from /proc/meminfo\n"); error_end(1); } if (show_memory) { printf("Mem: %5dK av, %5dK used, %5dK free, %5dK shrd, %5dK buff", mem[meminfo_main][meminfo_total] >> 10, mem[meminfo_main][meminfo_used] >> 10, mem[meminfo_main][meminfo_free] >> 10, mem[meminfo_main][meminfo_shared] >> 10, mem[meminfo_main][meminfo_buffers] >> 10); PUTP(top_clrtoeol); putchar('\n'); printf("Swap: %5dK av, %5dK used, %5dK free %5dK cached", mem[meminfo_swap][meminfo_total] >> 10, mem[meminfo_swap][meminfo_used] >> 10, mem[meminfo_swap][meminfo_free] >> 10, mem[meminfo_total][meminfo_cached] >> 10); PUTP(top_clrtoeol); putchar('\n'); } PUTP(me); PUTP(top_clrtoeol); putchar('\n'); return mem[meminfo_main][meminfo_total]; }
qint64 OSTools::getTotalSystemMemory() { qint64 result = UNSTABLE_DEFAULT_MEMORY; // working fine for nix #ifdef Q_WS_X11 QFile meminfo("/proc/meminfo"); meminfo.open(QFile::ReadOnly); QString nextLine = meminfo.readLine(); while (nextLine != QString::null) { QTextStream in(&nextLine); QString paramName; in >> paramName; if (paramName == "MemTotal:") { in >> result; return result * 1024; } nextLine = meminfo.readLine(); }
COligoFarApp::COligoFarApp( int argc, char ** argv ) : CApp( argc, argv ), m_hashPass( 0 ), m_strands( 0x03 ), m_readsPerRun( 250000 ), m_minRun(0), m_maxRun( numeric_limits<int>::max() ), m_topCnt( 10 ), m_topPct( 99 ), m_minPctid( 60 ), m_identityScore( 1.0 ), m_mismatchScore( -1.0 ), m_gapOpeningScore( -3.0 ), m_gapExtentionScore( -1.5 ), m_extentionPenaltyDropoff( -100 ), m_qualityChannels( 0 ), m_qualityBase( 33 ), m_minBlockLength( 1000 ), // m_guideFilemaxMismatch( 0 ), m_memoryLimit( Uint8( sizeof(void*) == 4 ? 3 : 8 ) * int(kGigaByte) ), m_performTests( false ), m_colorSpace( false ), m_sodiumBisulfiteCuration( false ), m_outputSam( true ), m_printStatistics( false ), m_fastaParseIDs( false ), #ifdef _WIN32 //m_guideFile( "nul:" ), m_outputFile( "con:" ), #else m_guideFile( "/dev/null" ), m_outputFile( "/dev/stdout" ), #endif m_outputFlags( "z" ), m_geometry( "p" ) { m_passParam.push_back( CPassParam() ); #ifndef _WIN32 ifstream meminfo( "/proc/meminfo" ); string buff; if( !meminfo.fail() ) { m_memoryLimit = 0; while( getline( meminfo, buff ) ) { istringstream line(buff); string name, units; Uint8 value; line >> name >> value >> units; if( units.length() ) { switch( tolower( units[0] ) ) { case 'g': value *= kKiloByte; case 'm': value *= kKiloByte; case 'k': value *= kKiloByte; } } if( name == "MemFree:" || name == "Buffers:" || name == "Cached:" || name == "SwapCached:" ) { m_memoryLimit += value; } } }
void sysinfo(void) { os_printf("SDK version: %s Chip ID=%u\n", system_get_sdk_version(), system_get_chip_id()); system_print_meminfo(); meminfo(); }
void *KST::malloc(size_t size) { #ifdef HAVE_LINUX QMutexLocker ml(&bigLock); meminfo(); unsigned long bFree = S(kb_main_free + kb_main_buffers + kb_main_cached); if (size > bFree) { const unsigned long sz = size; qDebug("Tried to allocate too much memory! (Wanted %lu, had %lu)", sz, bFree); return 0L; } #endif return ::malloc(size); }
/************************ Release all blocks *******************************/ void memrel(MEM *pMEM) { MEMCELL *tofree; MEMCELL *pCell; if( !MEM_initialized(pMEM) ) return; #ifdef DEBUG printf( "Freeing all Memory Blocks \n" ); printf( "Memory Manager Before: \n" ); meminfo( pMEM ); #endif /* free cells */ pCell = MEM_cells(pMEM); while( pCell != NULL ) { tofree = pCell; pCell = MEMCELL_next(pCell); if( MEMCELL_pointer(tofree) != NULL ) free(MEMCELL_pointer(tofree)); free(tofree); } MEM_usage(pMEM) = 0; MEM_cells(pMEM) = NULL; MEM_initialized(pMEM) = 0; #ifdef DEBUG printf( "Memory Manager After: \n" ); meminfo( pMEM ); #endif }
int main () { char *p; for (p = "In exec'd program!\n"; *p; p++) putchar (*p); printf ("memory = %d\n", meminfo ()); return 0; }
void read_proc(PROC_INFO *pidinfo,const char *c_pid) { string temp,pidname; char filename[18]; sprintf(filename,"/proc/%s/stat",c_pid); std::ifstream meminfo(filename); meminfo>>(pidinfo->pid)>>pidname>>temp>>(pidinfo->ppid)>>temp>>temp; meminfo>>temp>>temp>>temp>>temp>>temp>>temp; meminfo>>temp>>temp>>temp>>temp>>temp>>(pidinfo->priority); meminfo>>temp>>temp>>temp>>temp>>temp>>(pidinfo->rss); pidinfo->name=pidname.substr(1,pidname.find(')')-1);//remove"()" meminfo.close(); }
int main (int argc, char *argv[]) { int i; if (argc < 2) { usage(); exit (1); } for (i=1; i<argc; i++) { if (!strncmp(argv[i], "--version", 10)) { version(); exit (0); } } if (!strncmp (argv[1], "query", 6)) { query (); } else if (!strncmp (argv[1], "info", 5)) { info (); } else if (!strncmp (argv[1], "meminfo", 8)) { meminfo (); } else if (!strncmp (argv[1], "reset", 6)) { reset (); } else if (!strncmp (argv[1], "destroy", 8)) { destroy (); } else if (!strncmp (argv[1], "alloc", 6)) { alloc (argc, argv); } else { usage(); exit (1); } exit (0); }
int memory(int argc, char *argv[]){ int i; int count = 0; int shift = 10; int pause_length = 0; int show_high = 0; int show_total = 0; int old_fmt = 0; while( (i = getopt(argc, argv, "bkmglotc:s:V") ) != -1 ) switch (i) { case 'b': shift = 0; break; case 'k': shift = 10; break; case 'm': shift = 20; break; case 'g': shift = 30; break; case 'l': show_high = 1; break; case 'o': old_fmt = 1; break; case 't': show_total = 1; break; case 's': pause_length = 1000000 * atof(optarg); break; case 'c': count = strtoul(optarg, NULL, 10); break; case 'V':exit(0); exit(0); default: fwrite(help,1,strlen(help),stderr); return 1; } do { meminfo(); printf(" total used free shared buffers cached\n"); printf( "%-7s %10Lu %10Lu %10Lu %10Lu %10Lu %10Lu\n", "Mem:", S(kb_main_total), S(kb_main_used), S(kb_main_free), S(kb_main_shared), S(kb_main_buffers), S(kb_main_cached) ); if (show_high) { printf( "%-7s %10Lu %10Lu %10Lu\n", "Low:", S(kb_low_total), S(kb_low_total - kb_low_free), S(kb_low_free) ); printf( "%-7s %10Lu %10Lu %10Lu\n", "High:", S(kb_high_total), S(kb_high_total - kb_high_free), S(kb_high_free) ); } if(!old_fmt){ unsigned KLONG buffers_plus_cached = kb_main_buffers + kb_main_cached; printf( "-/+ buffers/cache: %10Lu %10Lu\n", S(kb_main_used - buffers_plus_cached), S(kb_main_free + buffers_plus_cached) ); } printf( "%-7s %10Lu %10Lu %10Lu\n", "Swap:", S(kb_swap_total), S(kb_swap_used), S(kb_swap_free) ); if(show_total){ printf( "%-7s %10Lu %10Lu %10Lu\n", "Total:", S(kb_main_total + kb_swap_total), S(kb_main_used + kb_swap_used), S(kb_main_free + kb_swap_free) ); } if(pause_length){ fputc('\n', stdout); fflush(stdout); if (count != 1) usleep(pause_length); } } while(pause_length && --count); return 0; }
unsigned hardware_corrupted(void) { return (meminfo("HardwareCorrupted: %u") * 1024) / PS; }
/****************** Free a block ********************************************/ void memfree(MEM *pMEM, void *ptr ) { MEMCELL *pCell; MEMCELL *prev; MEMCELL *next; if( !MEM_initialized(pMEM) ) return; #ifdef DEBUG printf( "Trying to free cell for address: %x \n", ptr ); printf( "Memory Manager Before Free: \n" ); meminfo( pMEM ); #endif if( ptr == NULL ) { return; } /* search for pointer */ pCell = MEM_cells(pMEM); while( pCell != NULL ) { if( MEMCELL_pointer(pCell) == ptr ) { free(MEMCELL_pointer(pCell)); MEM_usage(pMEM) -= MEMCELL_size(pCell); MEMCELL_pointer( pCell ) = NULL; if( pCell == MEM_cells(pMEM) ) { MEM_cells(pMEM) = MEMCELL_next( pCell ); free( pCell ); } else { prev = findPrev( MEM_cells(pMEM), pCell ); next = MEMCELL_next( pCell ); if( prev != NULL ) { MEMCELL_next( prev ) = next; free( pCell ); } } break; /* from while loop */ } pCell = MEMCELL_next(pCell); } #ifdef DEBUG printf( "Memory Manager After Free: \n" ); meminfo( pMEM ); #endif }
void shell::start() { cout<<"Starting shell : Type help for available commands\n"; char *cmd=new char[128] ; while(1) { //memset(cmd,0,128); cout.SetColour(GREEN,BLACK,0); cout<<"NanOS-#>"; cout.SetColour(WHITE,BLACK,0); cin>>cmd; //cout<<" \nCommand : "<<cmd<<"\n"; if(String::strncmp((const char*)cmd,"about",5)==0) about(); else if(String::strncmp((const char*)cmd,"help",4)==0) help(); else if(String::strncmp((const char*)cmd,"clear",5)==0) cout.clear(); else if(String::strncmp((const char*)cmd,"date",4)==0) get_cmos_date_time(); else if(String::strncmp((const char*)cmd,"hello",5)==0) cout<<"Hi, how do you do???"<<"\n"; else if(String::strncmp((const char*)cmd,"cpuinfo",7)==0) cpuinfo(); else if(String::strncmp((const char*)cmd,"meminfo",7)==0) meminfo(); else if(String::strncmp((const char*)cmd,"pci",3)==0) { pci_bus *sys_pci=pci_bus::Instance(); sys_pci->list_dev(); } else if(String::strncmp((const char*)cmd,"devclass",8)==0) { pci_bus *sys_pci=pci_bus::Instance(); unsigned short x=atoi(cmd+9); pci_dev *device=sys_pci->get_dev_by_class(x); int i=0; while(device) { cout.flags(hex|showbase); cout<<device->bus<<":"<<device->dev<<":"<<device->func<<":"; cout<<vendor_to_string(device->common->vendor_id)<<":"<<vendor_device_to_string(device->common->vendor_id,device->common->device_id)<<":"; cout<<class_to_string(device->common->classcode,device->common->subclass)<<":"; cout<<(int)device->common->classcode<<":"<<(int)device->common->subclass<<":"; cout<<(int)(device->common->Prog_if)<<":"<<(int)device->common->header_type<<"\n"; i++; device=device->next; } cout.flags(dec); cout<<"Total devices="<<i<<"\n"; } else if(String::strncmp((const char*)cmd,"bootdev",7)==0) { extern char *boot_dev; cout<<(char *)boot_dev<<"\n"; } else if(String::strncmp((const char*)cmd,"tasks",5)==0) { all_tasks(); } else if(String::strncmp((const char*)cmd,"ide",3)==0) { display_slot_info(); } else if(String::strncmp((const char*)cmd,"hdinfo",6)==0) { for(int i=0;i<4;i++) //if(disks[i]) { //disks[i]->disk_info(); } } else if(String::strncmp((const char*)cmd,"sysdriveinfo",12)==0) { display_sysdrive_info(); } else if(String::strcmp((const char*)cmd, "")==0); else cout<<"Unknown Command\n For available commands type help\n"; } }
int main(void) { struct api_signature *sig = NULL; int diskdev, i, netdev, usedev; struct open_file f; const char * loaderdev; if (!api_search_sig(&sig)) return (-1); syscall_ptr = sig->syscall; if (syscall_ptr == NULL) return (-2); if (sig->version > API_SIG_VERSION) return (-3); /* Clear BSS sections */ bzero(__sbss_start, __sbss_end - __sbss_start); bzero(__bss_start, _end - __bss_start); /* * Set up console. */ cons_probe(); printf("Compatible API signature found @%x\n", (uint32_t)sig); dump_sig(sig); dump_addr_info(); /* * Initialise the heap as early as possible. Once this is done, * alloc() is usable. The stack is buried inside us, so this is * safe. */ setheap((void *)end, (void *)(end + 512 * 1024)); /* * Enumerate U-Boot devices */ if ((devs_no = ub_dev_enum()) == 0) panic("no U-Boot devices found"); printf("Number of U-Boot devices: %d\n", devs_no); printf("\n"); printf("%s, Revision %s\n", bootprog_name, bootprog_rev); printf("(%s, %s)\n", bootprog_maker, bootprog_date); meminfo(); /* * March through the device switch probing for things -- sort of. * * The devsw array will have one or two items in it. If * LOADER_DISK_SUPPORT is defined the first item will be a disk (which * may not actually work if u-boot didn't supply one). If * LOADER_NET_SUPPORT is defined the next item will be a network * interface. Again it may not actually work at the u-boot level. * * The original logic was to always use a disk if it could be * successfully opened, otherwise use the network interface. Now that * logic is amended to first check whether the u-boot environment * contains a loaderdev variable which tells us which device to use. If * it does, we use it and skip the original (second) loop which "probes" * for a device. We still loop over the devsw just in case it ever gets * expanded to hold more than 2 devices (but then unit numbers, which * don't currently exist, may come into play). If the device named by * loaderdev isn't found, fall back using to the old "probe" loop. * * The original probe loop still effectively behaves as it always has: * the first usable disk device is choosen, and a network device is used * only if no disk device is found. The logic has been reworked so that * it examines (and thus lists) every potential device along the way * instead of breaking out of the loop when the first device is found. */ loaderdev = ub_env_get("loaderdev"); usedev = -1; if (loaderdev != NULL) { for (i = 0; devsw[i] != NULL; i++) { if (strcmp(loaderdev, devsw[i]->dv_name) == 0) { if (devsw[i]->dv_init == NULL) continue; if ((devsw[i]->dv_init)() != 0) continue; usedev = i; goto have_device; } } printf("U-Boot env contains 'loaderdev=%s', " "device not found.\n", loaderdev); } printf("Probing for bootable devices...\n"); diskdev = -1; netdev = -1; for (i = 0; devsw[i] != NULL; i++) { if (devsw[i]->dv_init == NULL) continue; if ((devsw[i]->dv_init)() != 0) continue; printf("Bootable device: %s\n", devsw[i]->dv_name); if (strncmp(devsw[i]->dv_name, "disk", strlen(devsw[i]->dv_name)) == 0) { f.f_devdata = &currdev; currdev.d_dev = devsw[i]; currdev.d_type = currdev.d_dev->dv_type; currdev.d_unit = 0; currdev.d_disk.slice = 0; if (devsw[i]->dv_open(&f, &currdev) == 0) { devsw[i]->dv_close(&f); if (diskdev == -1) diskdev = i; } } else if (strncmp(devsw[i]->dv_name, "net", strlen(devsw[i]->dv_name)) == 0) { if (netdev == -1) netdev = i; } } if (diskdev != -1) usedev = diskdev; else if (netdev != -1) usedev = netdev; else panic("No bootable devices found!\n"); have_device: currdev.d_dev = devsw[usedev]; currdev.d_type = devsw[usedev]->dv_type; currdev.d_unit = 0; if (currdev.d_type == DEV_TYP_STOR) currdev.d_disk.slice = 0; printf("Current device: %s\n", currdev.d_dev->dv_name); env_setenv("currdev", EV_VOLATILE, uboot_fmtdev(&currdev), uboot_setcurrdev, env_nounset); env_setenv("loaddev", EV_VOLATILE, uboot_fmtdev(&currdev), env_noset, env_nounset); setenv("LINES", "24", 1); /* optional */ setenv("prompt", "loader>", 1); archsw.arch_getdev = uboot_getdev; archsw.arch_copyin = uboot_copyin; archsw.arch_copyout = uboot_copyout; archsw.arch_readin = uboot_readin; archsw.arch_autoload = uboot_autoload; interact(); /* doesn't return */ return (0); }
// return TRUE if command has been processed to half further processing BOOL Plugin_ProcessChannelCommand(int ServerID, int ChannelID, char **Command, char **Args) { BOOL Processed = FALSE; char *NewCommand = NULL; char *NewArgs = NULL; HIRC_ChannelInfo_t CI; HydraIRC_GetChannelInfo(ChannelID,&CI); if (stricmp(*Command,"MODE") == 0) { if (CI.Mask & HIRC_CI_NAME) // Got channel name ? { NewCommand = HydraIRC_BuildString(MAX_COMMAND_BUFFER,"RAW"); if (*Args && (**Args == '+' || **Args == '-')) NewArgs = HydraIRC_BuildString(MAX_COMMAND_BUFFER,"MODE %s %s",CI.Name,*Args ? *Args : ""); else NewArgs = HydraIRC_BuildString(MAX_COMMAND_BUFFER,"MODE %s",*Args ? *Args : ""); } } else if (stricmp(*Command,"TOPIC") == 0) { if (CI.Mask & HIRC_CI_NAME) // Got channel name ? { NewCommand = HydraIRC_BuildString(MAX_COMMAND_BUFFER,"RAW"); if (*Args && **Args) NewArgs = HydraIRC_BuildString(MAX_COMMAND_BUFFER,"TOPIC %s :%s",CI.Name,*Args); else NewArgs = HydraIRC_BuildString(MAX_COMMAND_BUFFER,"TOPIC %s",CI.Name); } } else if (stricmp(*Command,"PIMP") == 0) { NewCommand = HydraIRC_BuildString(MAX_COMMAND_BUFFER,"ME"); #ifdef RELEASE_VERSION NewArgs = HydraIRC_BuildString(MAX_COMMAND_BUFFER,"is using HydraIRC " VERSIONSTRING " - Grab it from www.HydraIRC.com"); #else NewArgs = HydraIRC_BuildString(MAX_COMMAND_BUFFER,"is using HydraIRC " VERSIONSTRING " - Grab it from #HydraIRC on EFNet"); #endif } else if (stricmp(*Command,"KR") == 0) { Processed = TRUE; if (!*Args || !**Args) HydraIRC_ChannelPrintf(ChannelID,BIC_ERROR,"ERROR: <kick reason>"); else { if (g_KickReason) free(g_KickReason); g_KickReason = strdup(*Args); } } else if (stricmp(*Command,"KICK") == 0) { Processed = TRUE; // set it to TRUE, in case of errors if (CI.Mask & HIRC_CI_NAME) // Got channel name ? { char *ArgsCpy = NULL; char *Nick = NULL; char *Message = NULL; if (*Args) { ArgsCpy = strdup(*Args); if (ArgsCpy) { Nick = strtok(ArgsCpy," "); Message = strtok(NULL,""); } } if (Nick && *Nick) { if (!Message) { if (g_KickReason) Message = g_KickReason; else Message = "Kick!"; // supply a default kick message } NewCommand = HydraIRC_BuildString(MAX_COMMAND_BUFFER,"RAW"); NewArgs = HydraIRC_BuildString(MAX_COMMAND_BUFFER,"KICK %s %s :%s",CI.Name,Nick,Message); Processed = FALSE; } else HydraIRC_ChannelPrintf(ChannelID,BIC_ERROR,"ERROR: <nick> [<message>]"); if (ArgsCpy) free(ArgsCpy); } } else if (stricmp(*Command,"SLAP") == 0) { Processed = TRUE; // set it to TRUE, in case of errors if (CI.Mask & HIRC_CI_NAME) // Got channel name ? { if (*Args && **Args) { NewCommand = HydraIRC_BuildString(MAX_COMMAND_BUFFER,"ME"); NewArgs = HydraIRC_BuildString(MAX_COMMAND_BUFFER,PickRandomString(g_SlapMessages,sizeof (g_SlapMessages) / sizeof(char *)),*Args); Processed = FALSE; } else HydraIRC_ChannelPrintf(ChannelID,BIC_ERROR,"ERROR: <nick>"); } } else if (stricmp(*Command,"SYSINFO") == 0) { NewCommand = HydraIRC_BuildString(MAX_COMMAND_BUFFER,"ME"); NewArgs = HydraIRC_BuildString(MAX_COMMAND_BUFFER,"is using \x02%s\x02 || \x02%s\x02 || \x02%s\x02", osversion(), cpuinfo(), meminfo()); Processed = FALSE; } if (NewCommand != NULL) { sys_Free(*Command); // Free the old command, and then replace it... *Command = NewCommand; // Note: NewCommand will eventually be sys_Free()'d by HydraIRC // then do the same for the args if (NewArgs != NULL) { sys_Free(*Args); *Args = NewArgs; } } return Processed; }
int main(void) { struct api_signature *sig = NULL; int load_type, load_unit, load_slice, load_partition; int i; const char * loaderdev; /* * If we can't find the magic signature and related info, exit with a * unique error code that U-Boot reports as "## Application terminated, * rc = 0xnnbadab1". Hopefully 'badab1' looks enough like "bad api" to * provide a clue. It's better than 0xffffffff anyway. */ if (!api_search_sig(&sig)) return (0x01badab1); syscall_ptr = sig->syscall; if (syscall_ptr == NULL) return (0x02badab1); if (sig->version > API_SIG_VERSION) return (0x03badab1); /* Clear BSS sections */ bzero(__sbss_start, __sbss_end - __sbss_start); bzero(__bss_start, _end - __bss_start); /* * Initialise the heap as early as possible. Once this is done, * alloc() is usable. The stack is buried inside us, so this is safe. */ uboot_heap_start = round_page((uintptr_t)end); uboot_heap_end = uboot_heap_start + 512 * 1024; setheap((void *)uboot_heap_start, (void *)uboot_heap_end); /* * Set up console. */ cons_probe(); printf("Compatible U-Boot API signature found @%x\n", (uint32_t)sig); printf("\n"); printf("%s, Revision %s\n", bootprog_name, bootprog_rev); printf("(%s, %s)\n", bootprog_maker, bootprog_date); printf("\n"); dump_sig(sig); dump_addr_info(); meminfo(); /* * Enumerate U-Boot devices */ if ((devs_no = ub_dev_enum()) == 0) panic("no U-Boot devices found"); printf("Number of U-Boot devices: %d\n", devs_no); get_load_device(&load_type, &load_unit, &load_slice, &load_partition); /* * March through the device switch probing for things. */ for (i = 0; devsw[i] != NULL; i++) { if (devsw[i]->dv_init == NULL) continue; if ((devsw[i]->dv_init)() != 0) continue; printf("Found U-Boot device: %s\n", devsw[i]->dv_name); currdev.d_dev = devsw[i]; currdev.d_type = currdev.d_dev->dv_type; currdev.d_unit = 0; if ((load_type == -1 || (load_type & DEV_TYP_STOR)) && strcmp(devsw[i]->dv_name, "disk") == 0) { if (probe_disks(i, load_type, load_unit, load_slice, load_partition) == 0) break; } if ((load_type == -1 || (load_type & DEV_TYP_NET)) && strcmp(devsw[i]->dv_name, "net") == 0) break; } /* * If we couldn't find a boot device, return an error to u-boot. * U-boot may be running a boot script that can try something different * so returning an error is better than forcing a reboot. */ if (devsw[i] == NULL) { printf("No boot device found!\n"); return (0xbadef1ce); } env_setenv("currdev", EV_VOLATILE, uboot_fmtdev(&currdev), uboot_setcurrdev, env_nounset); env_setenv("loaddev", EV_VOLATILE, uboot_fmtdev(&currdev), env_noset, env_nounset); setenv("LINES", "24", 1); /* optional */ setenv("prompt", "loader>", 1); archsw.arch_loadaddr = uboot_loadaddr; archsw.arch_getdev = uboot_getdev; archsw.arch_copyin = uboot_copyin; archsw.arch_copyout = uboot_copyout; archsw.arch_readin = uboot_readin; archsw.arch_autoload = uboot_autoload; interact(); /* doesn't return */ return (0); }
int main(void) { struct api_signature *sig = NULL; int i; struct open_file f; if (!api_search_sig(&sig)) return (-1); syscall_ptr = sig->syscall; if (syscall_ptr == NULL) return (-2); if (sig->version > API_SIG_VERSION) return (-3); /* Clear BSS sections */ bzero(__sbss_start, __sbss_end - __sbss_start); bzero(__bss_start, _end - __bss_start); /* * Set up console. */ cons_probe(); printf("Compatible API signature found @%x\n", (uint32_t)sig); dump_sig(sig); dump_addr_info(); /* * Initialise the heap as early as possible. Once this is done, * alloc() is usable. The stack is buried inside us, so this is * safe. */ setheap((void *)end, (void *)(end + 512 * 1024)); /* * Enumerate U-Boot devices */ if ((devs_no = ub_dev_enum()) == 0) panic("no U-Boot devices found"); printf("Number of U-Boot devices: %d\n", devs_no); printf("\n"); printf("%s, Revision %s\n", bootprog_name, bootprog_rev); printf("(%s, %s)\n", bootprog_maker, bootprog_date); meminfo(); /* * March through the device switch probing for things. */ for (i = 0; devsw[i] != NULL; i++) { if (devsw[i]->dv_init == NULL) continue; if ((devsw[i]->dv_init)() != 0) continue; printf("\nDevice: %s\n", devsw[i]->dv_name); currdev.d_dev = devsw[i]; currdev.d_type = currdev.d_dev->dv_type; currdev.d_unit = 0; if (strncmp(devsw[i]->dv_name, "disk", strlen(devsw[i]->dv_name)) == 0) { f.f_devdata = &currdev; currdev.d_disk.slice = 0; if (devsw[i]->dv_open(&f,&currdev) == 0) break; } if (strncmp(devsw[i]->dv_name, "net", strlen(devsw[i]->dv_name)) == 0) break; } if (devsw[i] == NULL) panic("No boot device found!"); env_setenv("currdev", EV_VOLATILE, uboot_fmtdev(&currdev), uboot_setcurrdev, env_nounset); env_setenv("loaddev", EV_VOLATILE, uboot_fmtdev(&currdev), env_noset, env_nounset); setenv("LINES", "24", 1); /* optional */ setenv("prompt", "loader>", 1); archsw.arch_getdev = uboot_getdev; archsw.arch_copyin = uboot_copyin; archsw.arch_copyout = uboot_copyout; archsw.arch_readin = uboot_readin; archsw.arch_autoload = uboot_autoload; interact(); /* doesn't return */ return (0); }