int main(int argc, char ** argv) { ULONG afshortage = 0; IPTR pargs[5]; struct AvailFontsHeader *afh; struct AvailFonts *afptr; /* Try to guess how many bytes are needed */ ULONG afsize = 10000; if (!(DiskfontBase = OpenLibrary("diskfont.library", 0L))) { VPrintf ("Couldn't open diskfont.library\n", NULL); return (RETURN_FAIL); } do { afh = (struct AvailFontsHeader *)AllocMem(afsize, MEMF_ANY); if (afh) { afshortage = AvailFonts((STRPTR)afh, afsize, AFF_MEMORY|AFF_DISK); if (afshortage) { FreeMem(afh, afsize); afsize += afshortage; afh = (struct AvailFontsHeader*)(-1L); } } } while (afshortage && afh); if (afh) { /* Print some info about the fonts */ UWORD count; pargs[0] = afh->afh_NumEntries; VPrintf("Number of fonts found: %ld\n", pargs); /* Get pointer to the first AvailFonts item */ afptr = (struct AvailFonts*)&afh[1]; for (count = afh->afh_NumEntries; count; count --) { pargs[0] = afptr->af_Type; pargs[1] = (IPTR)afptr->af_Attr.ta_Name; pargs[2] = afptr->af_Attr.ta_YSize; pargs[3] = afptr->af_Attr.ta_Style; pargs[4] = afptr->af_Attr.ta_Flags; VPrintf ("[%ld] Font name: %-30.s Font YSize: %ld Style: 0x%lx Flags 0x%lx\n", pargs); afptr ++; } } CloseLibrary(DiskfontBase); return (RETURN_OK); }
bool processWorkingSetSigprocmask(int How, void *Set, void *OldSet) { VPrintf(2, "%s\n", __FUNCTION__); // All we need to do is ensure that SIGSEGV is not blocked. // FIXME: we are not fully transparent as we do not pretend that // SIGSEGV is still blocked on app queries: that would require // per-thread mask tracking. if (Set && (How == SIG_BLOCK || How == SIG_SETMASK)) { if (internal_sigismember((__sanitizer_sigset_t *)Set, SIGSEGV)) { VPrintf(1, "%s: removing SIGSEGV from the blocked set\n", __FUNCTION__); internal_sigdelset((__sanitizer_sigset_t *)Set, SIGSEGV); } } return true; }
static void registerStructInfo(CacheFragInfo *CacheFrag) { for (u32 i = 0; i < CacheFrag->NumStructs; ++i) { StructInfo *Struct = &CacheFrag->Structs[i]; StructHashMap::Handle H(&Ctx->StructMap, (uptr)Struct->FieldCounters); if (H.created()) { VPrintf(2, " Register %s: %u fields\n", Struct->StructName, Struct->NumFields); H->Struct = Struct; ++Ctx->NumStructs; } else { VPrintf(2, " Duplicated %s: %u fields\n", Struct->StructName, Struct->NumFields); } } }
//***************************************************************************** // void Printf( const char *pszString, ... ) { va_list ArgPtr; va_start( ArgPtr, pszString ); VPrintf( pszString, ArgPtr ); va_end( ArgPtr ); }
// Scan shadow memory to calculate the number of cache lines being accessed, // i.e., the number of non-zero bits indexed by BitIdx in each shadow byte. // We also clear the lowest bits (most recent working set snapshot). static u32 computeWorkingSizeAndReset(u32 BitIdx) { u32 WorkingSetSize = 0; MemoryMappingLayout MemIter(true/*cache*/); uptr Start, End, Prot; while (MemIter.Next(&Start, &End, nullptr/*offs*/, nullptr/*file*/, 0/*file size*/, &Prot)) { VPrintf(4, "%s: considering %p-%p app=%d shadow=%d prot=%u\n", __FUNCTION__, Start, End, Prot, isAppMem(Start), isShadowMem(Start)); if (isShadowMem(Start) && (Prot & MemoryMappingLayout::kProtectionWrite)) { VPrintf(3, "%s: walking %p-%p\n", __FUNCTION__, Start, End); WorkingSetSize += countAndClearShadowValues(BitIdx, Start, End); } } return WorkingSetSize; }
void ErrorF(char *Format,...) { void *Data; struct EasyStruct EasyStruct; ULONG IDCMPFlags; Data = &Format+1L; if (((struct Process *)FindTask(NULL))->pr_CLI) { VPrintf(Format,Data); FPutC(Output(),'\n'); Flush(Output()); } else { EasyStruct.es_StructSize = sizeof(struct EasyStruct); EasyStruct.es_Flags = 0L; EasyStruct.es_Title = "Error"; EasyStruct.es_TextFormat = Format; EasyStruct.es_GadgetFormat = "Ok"; IDCMPFlags = 0L; EasyRequestArgs(NULL,&EasyStruct,&IDCMPFlags,Data); } }
void registerMemoryFaultHandler() { // We do not use an alternate signal stack, as doing so would require // setting it up for each app thread. // FIXME: This could result in problems with emulating the app's signal // handling if the app relies on an alternate stack for SIGSEGV. // We require that SIGSEGV is not blocked. We use a sigprocmask // interceptor to ensure that in the future. Here we ensure it for // the current thread. We assume there are no other threads at this // point during initialization, or that at least they do not block // SIGSEGV. __sanitizer_sigset_t SigSet; internal_sigemptyset(&SigSet); internal_sigprocmask(SIG_BLOCK, &SigSet, nullptr); __sanitizer_sigaction SigAct; internal_memset(&SigAct, 0, sizeof(SigAct)); SigAct.sigaction = handleMemoryFault; // We want to handle nested signals b/c we need to handle a // shadow fault in an app signal handler. SigAct.sa_flags = SA_SIGINFO | SA_NODEFER; int Res = internal_sigaction(SIGSEGV, &SigAct, &AppSigAct); CHECK(Res == 0); VPrintf(1, "Registered for SIGSEGV handler\n"); }
void initializeLibrary(ToolType Tool) { // We assume there is only one thread during init. if (EsanIsInitialized) { CHECK(Tool == WhichTool); return; } WhichTool = Tool; SanitizerToolName = "EfficiencySanitizer"; initializeFlags(); // Intercepting libc _exit or exit via COMMON_INTERCEPTOR_ON_EXIT only // finalizes on an explicit exit call by the app. To handle a normal // exit we register an atexit handler. ::__cxa_atexit((void (*)())finalizeLibrary); VPrintf(1, "in esan::%s\n", __FUNCTION__); if (WhichTool != ESAN_CacheFrag) { Printf("ERROR: unknown tool %d requested\n", WhichTool); Die(); } initializeInterceptors(); EsanIsInitialized = true; }
void __showerror(char *format, const IPTR *args) { struct IntuitionBase *IntuitionBase; struct DosLibrary *DOSBase = NULL; const char *name = FindTask(NULL)->tc_Node.ln_Name; if ( !__forceerrorrequester && (DOSBase = (struct DosLibrary *)OpenLibrary("dos.library", 0)) != NULL && Cli() != NULL ) { if (name) { PutStr(name); PutStr(": "); } if (args) VPrintf(format, args); else PutStr(format); PutStr("\n"); } else if ((IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 0))) { struct EasyStruct es = { sizeof(struct EasyStruct), 0, name, format, "Exit" }; EasyRequestArgs(NULL, &es, NULL, args); CloseLibrary((struct Library *)IntuitionBase); } else { if (name) kprintf("%s: ", name); if (args) { vkprintf(format, args); kprintf("\n"); } else kprintf("%s\n", format); } if (DOSBase != NULL) CloseLibrary((struct Library *)DOSBase); }
void initializeCacheFrag() { VPrintf(2, "in esan::%s\n", __FUNCTION__); // We use placement new to initialize Ctx before C++ static initializaion. // We make CtxMem 8-byte aligned for atomic operations in AddrHashMap. static u64 CtxMem[sizeof(Context) / sizeof(u64) + 1]; Ctx = new (CtxMem) Context(); Ctx->NumStructs = 0; }
void Printf(const char* format, ...) { va_list vlist; va_start(vlist, format); VPrintf(format, vlist); va_end(vlist); }
static void reinstateDefaultHandler(int SigNum) { __sanitizer_sigaction SigAct; internal_memset(&SigAct, 0, sizeof(SigAct)); SigAct.sigaction = (decltype(SigAct.sigaction))SIG_DFL; int Res = internal_sigaction(SigNum, &SigAct, nullptr); CHECK(Res == 0); VPrintf(1, "Unregistered for %d handler\n", SigNum); }
void processRangeAccess(uptr PC, uptr Addr, int Size, bool IsWrite) { VPrintf(3, "in esan::%s %p: %c %p %d\n", __FUNCTION__, PC, IsWrite ? 'w' : 'r', Addr, Size); if (WhichTool == ESAN_CacheFrag) { // TODO(bruening): add shadow mapping and update shadow bits here. // We'll move this to cache_frag.cpp once we have something. } }
//***************************************************************************** // int Printf_NoTimestamp( const char *pszString, ... ) { va_list ArgPtr; va_start( ArgPtr, pszString ); VPrintf( false, pszString, ArgPtr ); va_end( ArgPtr ); return 0; }
//***************************************************************************** // int Printf( const char *pszString, ... ) { va_list ArgPtr; va_start( ArgPtr, pszString ); VPrintf( true, pszString, ArgPtr ); va_end( ArgPtr ); return 0; }
int lib_dos_f_VPrintf_2(emumsg_syscall_t *msg) { /* Make real syscall */ msg->arg[0]._long = VPrintf(msg->arg[0]._strptr,(IPTR *)msg->arg[1]._aptr); return HOOK_DONE; }
static bool verifyShadowScheme() { // Sanity checks for our shadow mapping scheme. uptr AppStart, AppEnd; if (Verbosity() >= 3) { for (int i = 0; getAppRegion(i, &AppStart, &AppEnd); ++i) { VPrintf(3, "App #%d: [%zx-%zx) (%zuGB)\n", i, AppStart, AppEnd, (AppEnd - AppStart) >> 30); } } for (int Scale = 0; Scale < 8; ++Scale) { Mapping.initialize(Scale); if (Verbosity() >= 3) { VPrintf(3, "\nChecking scale %d\n", Scale); uptr ShadowStart, ShadowEnd; for (int i = 0; getShadowRegion(i, &ShadowStart, &ShadowEnd); ++i) { VPrintf(3, "Shadow #%d: [%zx-%zx) (%zuGB)\n", i, ShadowStart, ShadowEnd, (ShadowEnd - ShadowStart) >> 30); } for (int i = 0; getShadowRegion(i, &ShadowStart, &ShadowEnd); ++i) { VPrintf(3, "Shadow(Shadow) #%d: [%zx-%zx)\n", i, appToShadow(ShadowStart), appToShadow(ShadowEnd - 1)+1); } } for (int i = 0; getAppRegion(i, &AppStart, &AppEnd); ++i) { DCHECK(isAppMem(AppStart)); DCHECK(!isAppMem(AppStart - 1)); DCHECK(isAppMem(AppEnd - 1)); DCHECK(!isAppMem(AppEnd)); DCHECK(!isShadowMem(AppStart)); DCHECK(!isShadowMem(AppEnd - 1)); DCHECK(isShadowMem(appToShadow(AppStart))); DCHECK(isShadowMem(appToShadow(AppEnd - 1))); // Double-shadow checks. DCHECK(!isShadowMem(appToShadow(appToShadow(AppStart)))); DCHECK(!isShadowMem(appToShadow(appToShadow(AppEnd - 1)))); } // Ensure no shadow regions overlap each other. uptr ShadowAStart, ShadowBStart, ShadowAEnd, ShadowBEnd; for (int i = 0; getShadowRegion(i, &ShadowAStart, &ShadowAEnd); ++i) { for (int j = 0; getShadowRegion(j, &ShadowBStart, &ShadowBEnd); ++j) { DCHECK(i == j || ShadowAStart >= ShadowBEnd || ShadowAEnd <= ShadowBStart); } } }
/*=========================================================================== * * Class CSrFile Method - bool Printf (pString, ...); * *=========================================================================*/ bool CSrFile::Printf (const SSCHAR* pString, ...) { va_list Args; bool Result; va_start(Args, pString); Result = VPrintf(pString, Args); va_end(Args); return (Result); }
int finalizeLibrary() { VPrintf(1, "in esan::%s\n", __FUNCTION__); if (WhichTool == ESAN_CacheFrag) { // FIXME NYI: we need to add sampling + callstack gathering and have a // strategy for how to generate a final report. // We'll move this to cache_frag.cpp once we have something. Report("%s is not finished: nothing yet to report\n", SanitizerToolName); } return 0; }
bool processWorkingSetSignal(int SigNum, void (*Handler)(int), void (**Result)(int)) { VPrintf(2, "%s: %d\n", __FUNCTION__, SigNum); if (SigNum == SIGSEGV) { *Result = AppSigAct.handler; AppSigAct.sigaction = (decltype(AppSigAct.sigaction))Handler; return false; // Skip real call. } return true; }
void Journalist::Printf( EJournalLevel level, EJournalCategory category, const char* pformat, ... ) const { // wrap the arguments and pass to VPrintf va_list ap; va_start(ap, pformat); VPrintf(level, category, pformat, ap); va_end(ap); }
int STACK_ARGS Printf (int printlevel, const char *format, ...) { va_list argptr; int count; va_start (argptr, format); count = VPrintf (printlevel, format, argptr); va_end (argptr); return count; }
int STACK_ARGS Printf_Bold (const char *format, ...) { va_list argptr; int count; printxormask = 0x80; va_start (argptr, format); count = VPrintf (PRINT_HIGH, format, argptr); va_end (argptr); return count; }
void Journalist::Printf( EJournalLevel level, EJournalCategory category, const char* pformat, ... ) const { // wrap the arguments and pass to VPrintf va_list ap; va_start(ap, pformat); VPrintf(level, category, pformat, ap); // TODO uncomment when done testing // vfprintf( stdout, pformat, ap ); va_end(ap); }
bool processWorkingSetSigaction(int SigNum, const void *ActVoid, void *OldActVoid) { VPrintf(2, "%s: %d\n", __FUNCTION__, SigNum); if (SigNum == SIGSEGV) { const struct sigaction *Act = (const struct sigaction *) ActVoid; struct sigaction *OldAct = (struct sigaction *) OldActVoid; if (OldAct) internal_memcpy(OldAct, &AppSigAct, sizeof(OldAct)); if (Act) internal_memcpy(&AppSigAct, Act, sizeof(AppSigAct)); return false; // Skip real call. } return true; }
bool _cdecl CScript::WriteSection( LPCTSTR pszSection, ... ) { ADDTOCALLSTACK_INTENSIVE("CScript::WriteSection"); // Write out the section header. va_list vargs; va_start( vargs, pszSection ); // EndSection(); // End any previous section. Printf( "\n["); VPrintf( pszSection, vargs ); Printf( "]\n" ); va_end( vargs ); return( true ); }
static void unregisterStructInfo(CacheFragInfo *CacheFrag) { // FIXME: if the library is unloaded before finalizeCacheFrag, we should // collect the result for later report. for (u32 i = 0; i < CacheFrag->NumStructs; ++i) { StructInfo *Struct = &CacheFrag->Structs[i]; StructHashMap::Handle H(&Ctx->StructMap, (uptr)Struct->FieldCounters, true); if (H.exists()) { VPrintf(2, " Unregister %s: %u fields\n", Struct->StructName, Struct->NumFields); // FIXME: we should move this call to finalizeCacheFrag once we can // iterate over the hash map there. computeStructRatio(H); --Ctx->NumStructs; } else { VPrintf(2, " Duplicated %s: %u fields\n", Struct->StructName, Struct->NumFields); } } static bool Reported = false; if (Ctx->NumStructs == 0 && !Reported) { Reported = true; reportStructSummary(); } }
bool fixMmapAddr(void **Addr, SIZE_T Size, int Flags) { if (*Addr) { if (!liesWithinSingleAppRegion((uptr)*Addr, Size)) { VPrintf(1, "mmap conflict: [%p-%p) is not in an app region\n", *Addr, (uptr)*Addr + Size); if (Flags & MAP_FIXED) { errno = EINVAL; return false; } else { *Addr = 0; } } } return true; }
static int printf_wrapper(FILE *f, const char *fmt, ...) { va_list argptr; int count; va_start(argptr, fmt); if (f == NULL) { count = VPrintf(PRINT_HIGH, fmt, argptr); } else { count = vfprintf(f, fmt, argptr); } va_end(argptr); return count; }
int STACK_ARGS DPrintf (const char *format, ...) { va_list argptr; int count; if (developer) { va_start (argptr, format); count = VPrintf (PRINT_HIGH, format, argptr); va_end (argptr); return count; } else { return 0; } }