/****f* libAfterImage/tutorials/create_top_level_window() * NAME * create_top_level_window() * SYNOPSIS * Window create_top_level_window( ASVisual *asv, Window root, * int x, int y, * unsigned int width, * unsigned int height, * unsigned int border_width, * unsigned long attr_mask, * XSetWindowAttributes *attr, * char *app_class ); * INPUTS * asv - pointer to valid preinitialized ASVisual structure. * root - root window of the screen on which to create window. * x, y - desired position of the window * width, height - desired window size. * border_width - desired initial border width of the window (may not * have any effect due to Window Manager intervention. * attr_mask - mask of the attributes that has to be set on the * window * attr - values of the attributes to be set. * app_class - title of the application to be used as its window * Title and resources class. * RETURN VALUE * ID of the created window. * DESCRIPTION * create_top_level_window() is autyomating process of creating top * level application window. It creates window for specified ASVisual, * and then sets up basic ICCCM hints for that window, such as WM_NAME, * WM_ICON_NAME, WM_CLASS and WM_PROTOCOLS. * SOURCE */ Window create_top_level_window( ASVisual *asv, Window root, int x, int y, unsigned int width, unsigned int height, unsigned int border_width, unsigned long attr_mask, XSetWindowAttributes *attr, const char *app_class, const char *app_name ) { Window w = None; #ifndef X_DISPLAY_MISSING char *tmp ; XTextProperty name; XClassHint class1; w = create_visual_window(asv, root, x, y, width, height, border_width, InputOutput, attr_mask, attr ); tmp = (app_name==NULL)?(char*)get_application_name():(char*)app_name; XStringListToTextProperty (&tmp, 1, &name); class1.res_name = tmp; /* for future use */ class1.res_class = (char*)app_class; XSetWMProtocols (asv->dpy, w, &_XA_WM_DELETE_WINDOW, 1); XSetWMProperties (asv->dpy, w, &name, &name, NULL, 0, NULL, NULL, &class1); /* final cleanup */ XFree ((char *) name.value); #endif /* X_DISPLAY_MISSING */ return w; }
void asim_nonGNUC_debugout( const char *format, ...) { va_list ap; fprintf (stderr, "%s: ", get_application_name() ); va_start (ap, format); vfprintf (stderr, format, ap); va_end (ap); fprintf (stderr, "\n" ); }
static void display_error_helper(wchar_t *msg) { wchar_t title_buf[MAX_PATH + 64]; _snwprintf(title_buf, BUFFER_SIZE_ELEMENTS(title_buf), L_PRODUCT_NAME L" Notice: %hs(%hs)", get_application_name(), get_application_pid()); NULL_TERMINATE_BUFFER(title_buf); nt_messagebox(msg, title_buf); }
Bool asim_show_debug( const char *file, const char *func, int line, const char *msg_format, ...) { if( OUTPUT_LEVEL_DEBUG <= get_output_threshold()) { va_list ap; fprintf (stderr, "%s debug msg: %s:%s():%d: ", get_application_name(), file, func, line ); va_start (ap, msg_format); vfprintf (stderr, msg_format, ap); va_end (ap); fprintf (stderr, "\n" ); return True; } return False; }
Bool asim_show_progress( const char *msg_format, ...) { if( OUTPUT_LEVEL_PROGRESS <= get_output_threshold()) { va_list ap; fprintf (stderr, "%s : ", get_application_name() ); va_start (ap, msg_format); vfprintf (stderr, msg_format, ap); va_end (ap); fprintf (stderr, "\n" ); return True; } return False; }
Bool asim_show_warning( const char *warning_format, ...) { if( OUTPUT_LEVEL_WARNING <= get_output_threshold()) { va_list ap; fprintf (stderr, "%s warning: ", get_application_name() ); va_start (ap, warning_format); vfprintf (stderr, warning_format, ap); va_end (ap); fprintf (stderr, "\n" ); return True; } return False; }
/* from libAfterBase/output.c : */ Bool asim_show_error( const char *error_format, ...) { if( OUTPUT_LEVEL_ERROR <= get_output_threshold()) { va_list ap; fprintf (stderr, "%s ERROR: ", get_application_name() ); va_start (ap, error_format); vfprintf (stderr, error_format, ap); va_end (ap); fprintf (stderr, "\n" ); return True; } return False; }
void loader_init(void) { uint i; privmod_t *mod; acquire_recursive_lock(&privload_lock); VMVECTOR_ALLOC_VECTOR(modlist_areas, GLOBAL_DCONTEXT, VECTOR_SHARED | VECTOR_NEVER_MERGE /* protected by privload_lock */ | VECTOR_NO_LOCK, modlist_areas); /* os specific loader initialization prologue before finalize the load */ os_loader_init_prologue(); /* Process client libs we loaded early but did not finalize */ for (i = 0; i < privmod_static_idx; i++) { /* Transfer to real list so we can do normal processing */ char name_copy[MAXIMUM_PATH]; mod = privload_insert(NULL, privmod_static[i].base, privmod_static[i].size, privmod_static[i].name, privmod_static[i].path); LOG(GLOBAL, LOG_LOADER, 1, "%s: processing imports for %s\n", __FUNCTION__, mod->name); /* save a copy for error msg, b/c mod will be unloaded (i#643) */ snprintf(name_copy, BUFFER_SIZE_ELEMENTS(name_copy), "%s", mod->name); NULL_TERMINATE_BUFFER(name_copy); if (!privload_load_finalize(mod)) { mod = NULL; /* it's been unloaded! */ #ifdef CLIENT_INTERFACE SYSLOG(SYSLOG_ERROR, CLIENT_LIBRARY_UNLOADABLE, 5, get_application_name(), get_application_pid(), name_copy, "\n\tUnable to locate imports of client library"); #endif os_terminate(NULL, TERMINATE_PROCESS); ASSERT_NOT_REACHED(); } } /* os specific loader initialization epilogue after finalize the load */ os_loader_init_epilogue(); /* FIXME i#338: call loader_thread_init here once get * loader_init called after dynamo_thread_init but in a way that * works with Windows */ release_recursive_lock(&privload_lock); }
static void display_error_helper(wchar_t *msg) { wchar_t title_buf[MAX_PATH + 64]; _snwprintf(title_buf, BUFFER_SIZE_ELEMENTS(title_buf), L_PRODUCT_NAME L" Notice: %hs(%hs)", get_application_name(), get_application_pid()); NULL_TERMINATE_BUFFER(title_buf); /* for unit tests: assume that if a limit is set, we are in a * script so it's ok to just display to stderr. avoids hangs when * an error is encountered. */ if (limit <= 0) nt_messagebox(msg, title_buf); else { fprintf(FP, "\n\n%ls\n%ls\n\n", title_buf, msg); fflush(FP); } }
void windowbox_parse (char *tline, FILE * fd, char **unused1, int *unused2) { FilePtrAndData fpd ; ConfigDef *ConfigReader ; FreeStorageElem *Storage = NULL, *more_stuff = NULL; ASWindowBox **aswbox_list = &(ASDefaultScr->Feel.window_boxes); unsigned int *count = &(ASDefaultScr->Feel.window_boxes_num); ASWindowBox *new_box ; ConfigData cd ; fpd.fp = fd ; fpd.data = safemalloc( 12+1+strlen(tline)+1+1 ) ; sprintf( fpd.data, "WindowBox %s\n", tline ); LOCAL_DEBUG_OUT( "fd(%p)->tline(\"%s\")->fpd.data(\"%s\")", fd, tline, fpd.data ); cd.fileptranddata = &fpd ; ConfigReader = InitConfigReader ((char*)get_application_name(), &WindowBoxSyntax, CDT_FilePtrAndData, cd, NULL); free( fpd.data ); if (!ConfigReader) return ; PrintConfigReader (ConfigReader); ParseConfig (ConfigReader, &Storage); /* getting rid of all the crap first */ StorageCleanUp (&Storage, &more_stuff, CF_DISABLED_OPTION); DestroyFreeStorage (&more_stuff); if( (new_box = ProcessWindowBoxOptions (Storage)) != NULL ) { int i = *count ; ++(*count) ; *aswbox_list = realloc( *aswbox_list, sizeof(ASWindowBox)*(i+1)); (*aswbox_list)[i] = *new_box ; free( new_box ); } DestroyConfig (ConfigReader); DestroyFreeStorage (&Storage); }
static void sigsegv_handler (int signum #if defined(HAVE_SIGCONTEXT) , struct sigcontext sc #endif ) { static int level = 0; const char *MyName = get_application_name(); if (signum == SIGSEGV) { fprintf (stderr, "Segmentation Fault trapped"); if (level > 0) exit (1); /* sigsegv in sigsegv */ level++; fprintf (stderr, " in %s.\n", MyName); } else fprintf (stderr, "Non-critical Signal %d trapped in %s.\n", signum, MyName); #if defined(HAVE_SIGCONTEXT) print_diag_info (&sc); #else print_simple_backtrace (); #endif if (signum == SIGSEGV) { fprintf (stderr, "Please collect all the listed information and submit a bug report to <*****@*****.**>.\n"); fprintf (stderr, "If core dump was generated by this fault, please examine it with gdb and attach results to your report.\n"); fprintf (stderr, " You can use the following sequence to do so :\n"); fprintf (stderr, " gdb -core core /usr/bin/afterstep\n"); fprintf (stderr, " gdb>backtrace\n"); fprintf (stderr, " gdb>info frame\n"); fprintf (stderr, " gdb>info all-registers\n"); fprintf (stderr, " gdb>disassemble\n"); exit (1); } }
void CheckConfigSanity() { char buf[256]; if( Config == NULL ) Config = CreateIdentConfig (); if( Config->geometry.width <= 10 ) Config->geometry.width = 512; if( Config->geometry.height <= 10 ) Config->geometry.height = 512; mystyle_get_property (Scr.wmprops); sprintf( buf, "*%sTile", get_application_name() ); LOCAL_DEBUG_OUT("Attempting to use style \"%s\"", buf); Scr.Look.MSWindow[BACK_UNFOCUSED] = mystyle_find_or_default( buf ); LOCAL_DEBUG_OUT("Will use style \"%s\", overlay = %p.", Scr.Look.MSWindow[BACK_UNFOCUSED]->name, Scr.Look.MSWindow[BACK_UNFOCUSED]->overlay ); }
static void desktop_active_window_changed(WnckScreen* screen, WnckWindow *previous_window, MacMenu* mmb) { WnckWindow* awin = wnck_screen_get_active_window(screen); GtkWidget* sck = NULL; if (awin != NULL && wnck_window_get_window_type(awin) != WNCK_WINDOW_DESKTOP) { long inout[2] = {0, 0}; inout[0] = wnck_window_get_xid(awin); if (inout[0]) { g_hash_table_foreach(mmb->mbars_scks, find_mbar_by_mwin, inout); if (inout[1]) sck = g_hash_table_lookup(mmb->mbars_scks, (gpointer) inout[1]); } if (sck == NULL) { sck = mmb->dummysck; gtk_label_set_max_width_chars(mmb->label, MAX_LABEL_WIDTH_N_CHARS * 10); } else { gtk_label_set_max_width_chars(mmb->label, MAX_LABEL_WIDTH_N_CHARS); } gtk_label_set_text(mmb->label, get_application_name(awin, mmb)); } else { sck = mmb->mainsck; gtk_label_set_max_width_chars(mmb->label, MAX_LABEL_WIDTH_N_CHARS * 10); gtk_label_set_text(mmb->label, MAIN_LABEL_TEXT); } gtk_notebook_set_current_page( mmb->notebook, gtk_notebook_page_num(mmb->notebook, sck) ); }
int main(int argc, char* argv[]) { Display *dpy = NULL; ASVisual *asv ; int screen = 0, depth = 0; int dummy, geom_flags = 0; unsigned int to_width, to_height ; ASGradient grad ; ASGradient default_grad = { 1, 11, &(default_colors[0]), &(default_offsets[0])} ; ASImage *grad_im = NULL; /* see ASView.1 : */ set_application_name( argv[0] ); #if (HAVE_AFTERBASE_FLAG==1) set_output_threshold(OUTPUT_LEVEL_DEBUG); #endif if( argc > 1 ) { if( strcmp( argv[1], "-h") == 0 ) { usage(); return 0; } /* see ASScale.1 : */ geom_flags = XParseGeometry( argv[1], &dummy, &dummy, &to_width, &to_height ); }else usage(); memset( &grad, 0x00, sizeof(ASGradient)); #ifndef X_DISPLAY_MISSING dpy = XOpenDisplay(NULL); _XA_WM_DELETE_WINDOW = XInternAtom( dpy, "WM_DELETE_WINDOW", False); screen = DefaultScreen(dpy); depth = DefaultDepth( dpy, screen ); #endif if( argc >= 5 ) { int i = 2; /* see ASGrad.1 : */ grad.type = atoi( argv[2] ); grad.npoints = 0 ; grad.color = safemalloc( ((argc-2)/2)*sizeof(ARGB32)); grad.offset = safemalloc( ((argc-2)/2)*sizeof(double)); while( ++i < argc ) { if( grad.npoints > 0 ) { if( i == argc-1 ) grad.offset[grad.npoints] = 1.0; else grad.offset[grad.npoints] = atof( argv[i] ); ++i ; } /* see ASTile.1 : */ if( parse_argb_color( argv[i], &(grad.color[grad.npoints])) != argv[i] ) if( grad.offset[grad.npoints] >= 0. && grad.offset[grad.npoints]<= 1.0 ) grad.npoints++ ; } }else { grad = default_grad ; if( argc >= 3 ) grad.type = atoi( argv[2] ); } if( grad.npoints <= 0 ) { show_error( " not enough gradient points specified."); return 1; } /* Making sure tiling geometry is sane : */ #ifndef X_DISPLAY_MISSING if( !get_flags(geom_flags, WidthValue ) ) to_width = DisplayWidth(dpy, screen)*2/3 ; if( !get_flags(geom_flags, HeightValue ) ) to_height = DisplayHeight(dpy, screen)*2/3 ; #else if( !get_flags(geom_flags, WidthValue ) ) to_width = 500 ; if( !get_flags(geom_flags, HeightValue ) ) to_height = 500 ; #endif printf( "%s: rendering gradient of type %d to %dx%d\n", get_application_name(), grad.type&GRADIENT_TYPE_MASK, to_width, to_height ); /* see ASView.3 : */ asv = create_asvisual( dpy, screen, depth, NULL ); /* see ASGrad.2 : */ grad_im = make_gradient( asv, &grad, to_width, to_height, SCL_DO_ALL, #ifndef X_DISPLAY_MISSING ASA_XImage, #else ASA_ASImage, #endif 0, ASIMAGE_QUALITY_DEFAULT ); if( grad_im ) { #ifndef X_DISPLAY_MISSING /* see ASView.4 : */ Window w = create_top_level_window( asv, DefaultRootWindow(dpy), 32, 32, to_width, to_height, 1, 0, NULL, "ASGradient", NULL ); if( w != None ) { Pixmap p ; XMapRaised (dpy, w); /* see ASView.5 : */ p = asimage2pixmap( asv, DefaultRootWindow(dpy), grad_im, NULL, True ); destroy_asimage( &grad_im ); /* see common.c: set_window_background_and_free() : */ p = set_window_background_and_free( w, p ); /* see common.c: wait_closedown() : */ } wait_closedown(w); dpy = NULL; #else ASImage2file( grad_im, NULL, "asgrad.jpg", ASIT_Jpeg, NULL ); destroy_asimage( &grad_im ); #endif } return 0 ; }
void tls_thread_init(os_local_state_t *os_tls, byte *segment) { /* We have four different ways to obtain TLS, each with its own limitations: * * 1) Piggyback on the threading system (like we do on Windows): here that would * be pthreads, which uses a segment since at least RH9, and uses gdt-based * segments for NPTL. The advantage is we won't run out of ldt or gdt entries * (except when the app itself would). The disadvantage is we're stealing * application slots and we rely on user mode interfaces. * * 2) Steal an ldt entry via SYS_modify_ldt. This suffers from the 8K ldt entry * limit and requires that we update manually on a new thread. For 64-bit * we're limited here to a 32-bit base. (Strangely, the kernel's * include/asm-x86_64/ldt.h implies that the base is ignored: but it doesn't * seem to be.) * * 3) Steal a gdt entry via SYS_set_thread_area. There is a 3rd unused entry * (after pthreads and wine) we could use. The kernel swaps for us, and with * CLONE_TLS the kernel will set up the entry for a new thread for us. Xref * PR 192231 and PR 285898. This system call is disabled on 64-bit 2.6 * kernels (though the man page for arch_prctl implies it isn't for 2.5 * kernels?!?) * * 4) Use SYS_arch_prctl. This is only implemented on 64-bit kernels, and can * only be used to set the gdt entries that fs and gs select for. Faster to * use <4GB base (obtain with mmap MAP_32BIT) since can use gdt; else have to * use wrmsr. The man pages say "ARCH_SET_GS is disabled in some kernels". */ uint selector; int index = -1; int res; #ifdef X64 /* First choice is gdt, which means arch_prctl. Since this may fail * on some kernels, we require -heap_in_lower_4GB so we can fall back * on modify_ldt. */ byte *cur_gs; res = dynamorio_syscall(SYS_arch_prctl, 2, ARCH_GET_GS, &cur_gs); if (res >= 0) { LOG(GLOBAL, LOG_THREADS, 1, "os_tls_init: cur gs base is "PFX"\n", cur_gs); /* If we're a non-initial thread, gs will be set to the parent thread's value */ if (cur_gs == NULL || is_dynamo_address(cur_gs) || /* By resolving i#107, we can handle gs conflicts between app and dr. */ INTERNAL_OPTION(mangle_app_seg)) { res = dynamorio_syscall(SYS_arch_prctl, 2, ARCH_SET_GS, segment); if (res >= 0) { os_tls->tls_type = TLS_TYPE_ARCH_PRCTL; LOG(GLOBAL, LOG_THREADS, 1, "os_tls_init: arch_prctl successful for base "PFX"\n", segment); res = dynamorio_syscall(SYS_arch_prctl, 2, ARCH_GET_GS, &cur_gs); if (res >= 0 && cur_gs != segment && !on_WSL) { /* XXX i#1896: on WSL, ARCH_GET_GS is broken and does not return * the true value. (Plus, fs and gs start out equal to ss (0x2b) * and are not set by ARCH_SET_*). i#2089's safe read TLS * solution solves this, but we still warn as we haven't fixed * later issues. Without the safe read we have to abort. */ on_WSL = true; LOG(GLOBAL, LOG_THREADS, 1, "os_tls_init: running on WSL\n"); if (INTERNAL_OPTION(safe_read_tls_init)) { SYSLOG_INTERNAL_WARNING ("Support for the Windows Subsystem for Linux is still " "preliminary, due to missing kernel features. " "Continuing, but please report any problems encountered."); } else { SYSLOG(SYSLOG_ERROR, WSL_UNSUPPORTED_FATAL, 2, get_application_name(), get_application_pid()); os_terminate(NULL, TERMINATE_PROCESS); ASSERT_NOT_REACHED(); } } /* Kernel should have written %gs for us if using GDT */ if (!dynamo_initialized && /* We assume that WSL is using MSR */ (on_WSL || read_thread_register(SEG_TLS) == 0)) { LOG(GLOBAL, LOG_THREADS, 1, "os_tls_init: using MSR\n"); tls_using_msr = true; } if (IF_CLIENT_INTERFACE_ELSE(INTERNAL_OPTION(private_loader), false)) { res = dynamorio_syscall(SYS_arch_prctl, 2, ARCH_SET_FS, os_tls->os_seg_info.priv_lib_tls_base); /* Assuming set fs must be successful if set gs succeeded. */ ASSERT(res >= 0); } } else { /* we've found a kernel where ARCH_SET_GS is disabled */ ASSERT_CURIOSITY(false && "arch_prctl failed on set but not get"); LOG(GLOBAL, LOG_THREADS, 1, "os_tls_init: arch_prctl failed: error %d\n", res); } } else { /* FIXME PR 205276: we don't currently handle it: fall back on ldt, but * we'll have the same conflict w/ the selector... */ ASSERT_BUG_NUM(205276, cur_gs == NULL); } } #endif if (os_tls->tls_type == TLS_TYPE_NONE) { /* Second choice is set_thread_area */ /* PR 285898: if we added CLONE_SETTLS to all clone calls (and emulated vfork * with clone) we could avoid having to set tls up for each thread (as well * as solve race PR 207903), at least for kernel 2.5.32+. For now we stick * w/ manual setup. */ our_modify_ldt_t desc; /* Pick which GDT slots we'll use for DR TLS and for library TLS if * using the private loader. */ choose_gdt_slots(os_tls); if (tls_gdt_index > -1) { /* Now that we know which GDT slot to use, install the per-thread base * into it. */ /* Base here must be 32-bit */ IF_X64(ASSERT(DYNAMO_OPTION(heap_in_lower_4GB) && segment <= (byte*)UINT_MAX)); initialize_ldt_struct(&desc, segment, PAGE_SIZE, tls_gdt_index); res = dynamorio_syscall(SYS_set_thread_area, 1, &desc); LOG(GLOBAL, LOG_THREADS, 3, "%s: set_thread_area %d => %d res, %d index\n", __FUNCTION__, tls_gdt_index, res, desc.entry_number); ASSERT(res < 0 || desc.entry_number == tls_gdt_index); } else { res = -1; /* fall back on LDT */ } if (res >= 0) { LOG(GLOBAL, LOG_THREADS, 1, "os_tls_init: set_thread_area successful for base "PFX" @index %d\n", segment, tls_gdt_index); os_tls->tls_type = TLS_TYPE_GDT; index = tls_gdt_index; selector = GDT_SELECTOR(index); WRITE_DR_SEG(selector); /* macro needs lvalue! */ } else { IF_VMX86(ASSERT_NOT_REACHED()); /* since no modify_ldt */ LOG(GLOBAL, LOG_THREADS, 1, "os_tls_init: set_thread_area failed: error %d\n", res); } #ifdef CLIENT_INTERFACE /* Install the library TLS base. */ if (INTERNAL_OPTION(private_loader) && res >= 0) { app_pc base = os_tls->os_seg_info.priv_lib_tls_base; /* lib_tls_gdt_index is picked in choose_gdt_slots. */ ASSERT(lib_tls_gdt_index >= gdt_entry_tls_min); initialize_ldt_struct(&desc, base, GDT_NO_SIZE_LIMIT, lib_tls_gdt_index); res = dynamorio_syscall(SYS_set_thread_area, 1, &desc); LOG(GLOBAL, LOG_THREADS, 3, "%s: set_thread_area %d => %d res, %d index\n", __FUNCTION__, lib_tls_gdt_index, res, desc.entry_number); if (res >= 0) { /* i558 update lib seg reg to enforce the segment changes */ selector = GDT_SELECTOR(lib_tls_gdt_index); LOG(GLOBAL, LOG_THREADS, 2, "%s: setting %s to selector 0x%x\n", __FUNCTION__, reg_names[LIB_SEG_TLS], selector); WRITE_LIB_SEG(selector); } } #endif } if (os_tls->tls_type == TLS_TYPE_NONE) { /* Third choice: modify_ldt, which should be available on kernel 2.3.99+ */ /* Base here must be 32-bit */ IF_X64(ASSERT(DYNAMO_OPTION(heap_in_lower_4GB) && segment <= (byte*)UINT_MAX)); /* we have the thread_initexit_lock so no race here */ index = find_unused_ldt_index(); selector = LDT_SELECTOR(index); ASSERT(index != -1); create_ldt_entry((void *)segment, PAGE_SIZE, index); os_tls->tls_type = TLS_TYPE_LDT; WRITE_DR_SEG(selector); /* macro needs lvalue! */ LOG(GLOBAL, LOG_THREADS, 1, "os_tls_init: modify_ldt successful for base "PFX" w/ index %d\n", segment, index); } os_tls->ldt_index = index; }
/* Implementation of svn_auth__password_set_t that stores the password in KWallet. */ static svn_error_t * kwallet_password_set(svn_boolean_t *done, apr_hash_t *creds, const char *realmstring, const char *username, const char *password, apr_hash_t *parameters, svn_boolean_t non_interactive, apr_pool_t *pool) { QString wallet_name = get_wallet_name(parameters); *done = FALSE; if (! dbus_bus_get(DBUS_BUS_SESSION, NULL)) { return SVN_NO_ERROR; } if (non_interactive) { if (!KWallet::Wallet::isOpen(wallet_name)) return SVN_NO_ERROR; /* There is a race here: the wallet was open just now, but will it still be open when we come to use it below? */ } QCoreApplication *app; if (! qApp) { int argc = q_argc; app = new QCoreApplication(argc, q_argv); } KCmdLineArgs::init(q_argc, q_argv, get_application_name(parameters, pool), "subversion", ki18n(get_application_name(parameters, pool)), SVN_VER_NUMBER, ki18n("Version control system"), KCmdLineArgs::CmdLineArgKDE); KComponentData component_data(KCmdLineArgs::aboutData()); QString q_password = QString::fromUtf8(password); QString folder = QString::fromUtf8("Subversion"); KWallet::Wallet *wallet = get_wallet(wallet_name, parameters); if (wallet) { if (! wallet->hasFolder(folder)) { wallet->createFolder(folder); } if (wallet->setFolder(folder)) { QString key = QString::fromUtf8(username) + "@" + QString::fromUtf8(realmstring); if (wallet->writePassword(key, q_password) == 0) { *done = TRUE; } } } return SVN_NO_ERROR; }
static bool load_dynamorio_lib(IF_NOT_X64(bool x64_in_wow64)) { HMODULE dll = NULL; char path[MAX_PATH]; #ifdef DEBUG char msg[3 * MAX_PATH]; #endif int retval = -1; /* failure */ #ifndef X64 bool wow64 = is_wow64_process(NT_CURRENT_PROCESS); if (x64_in_wow64) { ASSERT(wow64); retval = get_parameter_64(PARAM_STR(DYNAMORIO_VAR_AUTOINJECT), path, MAX_PATH); } else #endif retval = get_parameter(PARAM_STR(DYNAMORIO_VAR_AUTOINJECT), path, MAX_PATH); if (IS_GET_PARAMETER_SUCCESS(retval)) { dr_marker_t mark; VERBOSE_MESSAGE("Loading \"%hs\"", path); /* The read_and_verify_dr_marker is the canonical check for dr in a * process, we double check against GetModuleHandle here just to be * extra safe (in case dr failed to initialize before). Note that * GetModuleHandle won't find dr's dll if we implement certian -hide * or early_injection proposals. */ if (read_and_verify_dr_marker(GetCurrentProcess(), &mark) != DR_MARKER_FOUND && GetModuleHandle(DYNAMORIO_LIBRARY_NAME) == NULL #ifndef X64 /* these ifdefs are rather ugly: just export all routines in x64 builds? */ && /* check for 64-bit as well */ (!wow64 || read_and_verify_dr_marker_64(GetCurrentProcess(), &mark) != DR_MARKER_FOUND) /* FIXME PR 251677: need 64-bit early injection to fully test * read_and_verify_dr_marker_64 */ #endif ) { /* OK really going to load dr now, verify that we are injecting * early enough (i.e. user32.dll is statically linked). This * presumes preinject is only used with app_init injection which is * currently the case. FIXME - should we also check_sole_thread * here? We can't really handle more then one thread when dr is * loading, but this can happen with early remote injected threads * many of which (CTRL) are relatively harmless. */ LDR_MODULE *mod = get_ldr_module_by_name(L"user32.dll"); ASSERT(mod != NULL); if (ldr_module_statically_linked(mod)) { #ifndef X64 if (x64_in_wow64) dll = load_library_64(path); else #endif dll = LoadLibrary(path); } else { /* FIXME - would be really nice to communicate this back to * the controller. */ #ifdef DEBUG _snprintf(msg, BUFFER_SIZE_ELEMENTS(msg), PRODUCT_NAME " Error: improper injection - " PRODUCT_NAME " (%s) can't inject into process %s (%s) (user32.dll " "not statically linked)\n", path, get_application_name(), get_application_pid()); NULL_TERMINATE_BUFFER(msg); display_error(msg); #endif } } else { /* notify failure only in debug builds, otherwise just return */ #ifdef DEBUG /* with early injection this becomes even more likely */ if (read_and_verify_dr_marker(GetCurrentProcess(), &mark) == DR_MARKER_FOUND # ifndef X64 || (wow64 && read_and_verify_dr_marker_64(GetCurrentProcess(), &mark) == DR_MARKER_FOUND) # endif ) { /* ok, early injection should always beat this */ # if VERBOSE /* can't readily tell what was expected */ _snprintf(msg, BUFFER_SIZE_ELEMENTS(msg), PRODUCT_NAME " ok if early injection, otherwise ERROR: " "double injection, " PRODUCT_NAME " (%s) is already loaded " "in process %s (%s), continuing\n", path, get_application_name(), get_application_pid()); NULL_TERMINATE_BUFFER(msg); display_error(msg); # endif /* VERBOSE */ } else { /* if GetModuleHandle finds us but we don't have a marker * we may have failed somehow */ _snprintf(msg, BUFFER_SIZE_ELEMENTS(msg), PRODUCT_NAME " Error: failed injection, " PRODUCT_NAME " (%s) is " "loaded but not initialized in process %s (%s), continuing\n", path, get_application_name(), get_application_pid()); NULL_TERMINATE_BUFFER(msg); display_error(msg); } #endif /* DEBUG */ return false; } } else path[0] = 0; if (dll == NULL) { #ifdef DEBUG int err = GetLastError(); _snprintf(msg, BUFFER_SIZE_ELEMENTS(msg), PRODUCT_NAME " Error %d loading %s\n", err, path); NULL_TERMINATE_BUFFER(msg); display_error(msg); #endif return false; } else { int_func_t init_func; void_func_t take_over_func; int res; #ifndef X64 if (x64_in_wow64) { init_func = (int_func_t)(ptr_uint_t) /*we know <4GB*/ get_proc_address_64((uint64)dll, "dynamorio_app_init"); take_over_func = (void_func_t)(ptr_uint_t) /*we know <4GB*/ get_proc_address_64((uint64)dll, "dynamorio_app_take_over"); VERBOSE_MESSAGE("dynamorio_app_init: 0x%08x; dynamorio_app_take_over: " "0x%08x\n", init_func, take_over_func); } else { #endif init_func = (int_func_t)GetProcAddress(dll, "dynamorio_app_init"); take_over_func = (void_func_t)GetProcAddress(dll, "dynamorio_app_take_over"); #ifndef X64 } #endif if (init_func == NULL || take_over_func == NULL) { /* unload the library so that it's clear DR is not in control * (o/w the DR library is in the process and it's not clear * what's going on) */ #ifndef X64 if (x64_in_wow64) { # ifdef DEBUG bool ok = # endif free_library_64(dll); ASSERT(ok); } else #endif FreeLibrary(dll); #ifdef DEBUG display_error("Error getting " PRODUCT_NAME " functions\n"); #endif return false; } VERBOSE_MESSAGE("about to inject dynamorio"); #ifndef X64 if (x64_in_wow64) res = switch_modes_and_call(init_func, NULL, NULL, NULL); else #endif res = (*init_func)(); VERBOSE_MESSAGE("dynamorio_app_init() returned %d\n", res); #ifndef X64 if (x64_in_wow64) switch_modes_and_call(take_over_func, NULL, NULL, NULL); else #endif (*take_over_func)(); VERBOSE_MESSAGE("inside " PRODUCT_NAME " now\n"); } return true; }
void stackdump(void) { int pid, core_pid; /* get name now -- will be same for children */ char *exec_name = get_application_name(); char core_name[128]; char tmp_name[128]; snprintf(tmp_name, 128, "%s.%d", TEMPORARY_FILENAME, get_process_id()); #ifdef VMX86_SERVER if (os_in_vmkernel_userworld()) { return; /* no local gdb, no multithreaded fork */ } #endif #if VERBOSE SYSLOG_INTERNAL_ERROR("about to fork parent %d to dump core", get_process_id()); #endif /* Fork a child to dump core */ pid = fork_syscall(); if (pid == 0) { /* child */ #if VERBOSE SYSLOG_INTERNAL_ERROR("about to dump core in process %d parent %d thread " TIDFMT "", get_process_id(), get_parent_id(), get_thread_id()); #endif /* We used to use abort here, but that had lots of complications with * pthreads and libc, so now we just dereference NULL. */ if (!set_default_signal_action(SIGSEGV)) { SYSLOG_INTERNAL_ERROR("ERROR in setting handler"); exit_process_syscall(1); } *(volatile int *)NULL = 0; #if VERBOSE SYSLOG_INTERNAL_ERROR("about to exit process %d", get_process_id()); #endif exit_process_syscall(0); } else if (pid == -1) { SYSLOG_INTERNAL_ERROR("ERROR: could not fork to dump core"); exit_process_syscall(1); } #if VERBOSE SYSLOG_INTERNAL_ERROR("parent %d %d waiting for child %d", get_process_id(), get_thread_id(), pid); #endif /* Parent continues */ core_pid = pid; while (wait_syscall(NULL) != pid) { /* wait for core to be dumped */ } #if VERBOSE SYSLOG_INTERNAL_ERROR("about to fork 2nd child to run gdb"); #endif /* Fork a 2nd child to run gdb */ pid = fork_syscall(); if (pid == 0) { /* child */ file_t fp; int fd; const char *argv[16]; int i; int execve_errno; /* Open a temporary file for the input: the "where" command */ fp = os_open(tmp_name, OS_OPEN_REQUIRE_NEW | OS_OPEN_WRITE); os_write(fp, DEBUGGER_COMMAND, strlen(DEBUGGER_COMMAND)); os_close(fp); fd = open_syscall(tmp_name, O_RDONLY, 0); if (fd < 0) { SYSLOG_INTERNAL_ERROR("ERROR: open failed on temporary file"); exit_process_syscall(1); } #if !BATCH_MODE /* Redirect stdin from the temporary file */ close_syscall(0); /* close stdin */ dup_syscall(fd); /* replace file descriptor 0 with reference to temp file */ #endif close_syscall(fd); /* close the other reference to temporary file */ /* Find the core file */ strncpy(core_name, CORE_NAME, 127); core_name[127] = '\0'; /* if max no null */ fd = open_syscall(core_name, O_RDONLY, 0); if (fd < 0) { snprintf(core_name, 128, "%s.%d", CORE_NAME, core_pid); SYSLOG_INTERNAL_ERROR("core not found, trying %s", core_name); fd = open_syscall(core_name, O_RDONLY, 0); if (fd < 0) { SYSLOG_INTERNAL_ERROR("ERROR: no core file found!"); exit_process_syscall(1); } } close_syscall(fd); /* avoid running the debugger under us! * FIXME: just remove our libraries, instead of entire env var? */ unsetenv("LD_PRELOAD"); SYSLOG_INTERNAL_ERROR("-------------------------------------------"); SYSLOG_INTERNAL_ERROR("stackdump: --- now running the debugger ---"); SYSLOG_INTERNAL_ERROR("%s %s %s %s", DEBUGGER, QUIET_MODE, exec_name, core_name); SYSLOG_INTERNAL_ERROR("-------------------------------------------"); i = 0; /* We rely on /usr/bin/env to do the PATH search for gdb on our behalf. */ argv[i++] = "/usr/bin/env"; argv[i++] = DEBUGGER; argv[i++] = QUIET_MODE; #if BATCH_MODE argv[i++] = "-x"; argv[i++] = tmp_name; argv[i++] = "-batch"; #endif argv[i++] = exec_name; argv[i++] = core_name; argv[i++] = NULL; execve_errno = execve_syscall("/usr/bin/env", argv, our_environ); SYSLOG_INTERNAL_ERROR("ERROR: execve failed for debugger: %d", -execve_errno); exit_process_syscall(1); } else if (pid == -1) { SYSLOG_INTERNAL_ERROR("ERROR: could not fork to run debugger"); exit_process_syscall(1); } /* Parent continues */ /* while(wait(NULL)>0) waits for all children, and could hang, so: */ while (wait_syscall(NULL) != pid) { /* empty loop */ } /* Wait for these children to complete before returning */ while (wait_syscall(NULL) > 0) { /* empty loop */ } os_delete_file(tmp_name); /* clean up the temporary file */ SYSLOG_INTERNAL_ERROR("-------------------------------------------"); }