Ejemplo n.º 1
0
    static dynamic_link_handle global_symbols_link( const wchar_t* library, const dynamic_link_descriptor descriptors[], size_t required ) {
        ::tbb::internal::suppress_unused_warning( library );
        dynamic_link_handle library_handle;
#if _WIN32
        if ( GetModuleHandleEx( 0, library, &library_handle ) ) {
            if ( resolve_symbols( library_handle, descriptors, required ) )
                return library_handle;
            else
                FreeLibrary( library_handle );
        }
#else /* _WIN32 */
    #if !__TBB_DYNAMIC_LOAD_ENABLED /* only __TBB_WEAK_SYMBOLS_PRESENT is defined */
        if ( !dlopen ) return 0;
    #endif /* !__TBB_DYNAMIC_LOAD_ENABLED */
        library_handle = dlopen( NULL, RTLD_LAZY );
    #if !__ANDROID__
        // On Android dlopen( NULL ) returns NULL if it is called during dynamic module initialization.
        LIBRARY_ASSERT( library_handle, "The handle for the main program is NULL" );
    #endif
        // Check existence of the first symbol only, then use it to find the library and load all necessary symbols.
        pointer_to_handler handler;
        dynamic_link_descriptor desc;
        desc.name = descriptors[0].name;
        desc.handler = &handler;
        if ( resolve_symbols( library_handle, &desc, 1 ) )
            return pin_symbols( library_handle, desc, descriptors, required );
#endif /* _WIN32 */
        return 0;
    }
Ejemplo n.º 2
0
 dynamic_link_handle dynamic_load( const wchar_t* library, const dynamic_link_descriptor descriptors[], size_t required ) {
 ::tbb::internal::suppress_unused_warning( library, descriptors, required );
 #if __TBB_DYNAMIC_LOAD_ENABLED
 #if _XBOX
     return LoadLibrary (library);
 #else /* _XBOX */
     size_t const len = PATH_MAX + 1;
     wchar_t path[ len ];
     size_t rc = abs_path( library, path, len );
     if ( 0 < rc && rc < len ) {
 #if _WIN32
         // Prevent Windows from displaying silly message boxes if it fails to load library
         // (e.g. because of MS runtime problems - one of those crazy manifest related ones)
         UINT prev_mode = SetErrorMode (SEM_FAILCRITICALERRORS);
 #endif /* _WIN32 */
         dynamic_link_handle library_handle = dlopen( path, RTLD_LAZY );
 #if _WIN32
         SetErrorMode (prev_mode);
 #endif /* _WIN32 */
         if( library_handle ) {
             if( !resolve_symbols( library_handle, descriptors, required ) ) {
                 // The loaded library does not contain all the expected entry points
                 dynamic_unlink( library_handle );
                 library_handle = NULL;
             }
         } else
             DYNAMIC_LINK_WARNING( dl_lib_not_found, path, dlerror() );
         return library_handle;
     } else if ( rc>=len )
             DYNAMIC_LINK_WARNING( dl_buff_too_small );
             // rc == 0 means failing of init_ap_data so the warning has already been issued.
 #endif /* _XBOX */
 #endif /* __TBB_DYNAMIC_LOAD_ENABLED */
     return 0;
 }
Ejemplo n.º 3
0
    static dynamic_link_handle pin_symbols( dynamic_link_handle library_handle, dynamic_link_descriptor desc, const dynamic_link_descriptor* descriptors, size_t required ) {
        ::tbb::internal::suppress_unused_warning( desc, descriptors, required );
#if __TBB_DYNAMIC_LOAD_ENABLED
        // It is supposed that all symbols are from the only one library
        // The library has been loaded by another module and contains at least one requested symbol.
        // But after we obtained the symbol the library can be unloaded by another thread
        // invalidating our symbol. Therefore we need to pin the library in memory.
        Dl_info info;
        // Get library's name from earlier found symbol
        if ( dladdr( (void*)*desc.handler, &info ) ) {
            // Pin the library
            library_handle = dlopen( info.dli_fname, RTLD_LAZY );
            if ( library_handle ) {
                // If original library was unloaded before we pinned it
                // and then another module loaded in its place, the earlier
                // found symbol would become invalid. So revalidate them.
                if ( !resolve_symbols( library_handle, descriptors, required ) ) {
                    // Wrong library.
                    dynamic_unlink(library_handle);
                    library_handle = 0;
                }
            } else {
                char const * err = dlerror();
                DYNAMIC_LINK_WARNING( dl_lib_not_found, info.dli_fname, err );
            }
        }
        else {
            // The library have been unloaded by another thread
            library_handle = 0;
        }
#endif /* __TBB_DYNAMIC_LOAD_ENABLED */
        return library_handle;
    }
Ejemplo n.º 4
0
 static dynamic_link_handle global_symbols_link( const char* library, const dynamic_link_descriptor descriptors[], size_t required ) {
     dynamic_link_handle library_handle;
     if ( GetModuleHandleExA( 0, library, &library_handle ) ) {
         if ( resolve_symbols( library_handle, descriptors, required ) )
             return library_handle;
         else
             FreeLibrary( library_handle );
     }
     return 0;
 }
Ejemplo n.º 5
0
 bool dynamic_link( const char*  library, const dynamic_link_descriptor descriptors[], size_t required, dynamic_link_handle*, int flags ) {
     dynamic_link_handle tmp_handle = NULL;
     TCHAR wlibrary[256];
     if ( MultiByteToWideChar(CP_UTF8, 0, library, -1, wlibrary, 255) == 0 ) return false;
     if ( flags & DYNAMIC_LINK_LOAD )
         tmp_handle = LoadPackagedLibrary( wlibrary, 0 );
     if (tmp_handle != NULL){
         return resolve_symbols(tmp_handle, descriptors, required);
     }else{
         return false;
     }
 }
Ejemplo n.º 6
0
kern_return_t
kxld_kext_relocate(KXLDKext *kext, kxld_addr_t link_address,
    KXLDDict *patched_vtables, const KXLDDict *defined_symbols, 
    const KXLDDict *obsolete_symbols, const KXLDDict *defined_cxx_symbols)
{
    kern_return_t rval = KERN_FAILURE;

    check(kext);
    check(patched_vtables);
    check(defined_symbols);
    check(obsolete_symbols);

    /* Kexts that are being relocated need symbols indexed by value for vtable
     * creation and patching. Note that we don't need to index by value for
     * dependencies that have already been linked because their symbols are
     * already in the global cxx value table. It's important to index the
     * symbols by value before we relocate the symbols because the vtable
     * entries will still have unrelocated values.
     */
    rval = kxld_object_index_cxx_symbols_by_value(kext->kext);
    require_noerr(rval, finish);

    rval = kxld_object_index_symbols_by_name(kext->kext);
    require_noerr(rval, finish);

    rval = kxld_object_relocate(kext->kext, link_address);
    require_noerr(rval, finish);

    rval = resolve_symbols(kext, defined_symbols, obsolete_symbols);
    require_noerr(rval, finish);

    rval = create_vtables(kext, defined_cxx_symbols, /* defined_symbols */ NULL);
    require_noerr(rval, finish);

    rval = patch_vtables(kext, patched_vtables, defined_symbols);
    require_noerr(rval, finish);
    
    rval = validate_symbols(kext);
    require_noerr(rval, finish);

    rval = kxld_object_process_relocations(kext->kext, patched_vtables);
    require_noerr(rval, finish);

    rval = KERN_SUCCESS;
finish:
    return rval;
}
Ejemplo n.º 7
0
 static dynamic_link_handle global_symbols_link( const char*, const dynamic_link_descriptor descriptors[], size_t required ) {
 #if __TBB_WEAK_SYMBOLS_PRESENT
     if ( !dlopen ) return 0;
 #endif /* __TBB_WEAK_SYMBOLS_PRESENT */
     dynamic_link_handle library_handle = dlopen( NULL, RTLD_LAZY );
 #if __ANDROID__
     // On Android dlopen( NULL ) returns NULL if it is called during dynamic module initialization.
     if ( !library_handle )
         return 0;
 #endif
     // Check existence of only the first symbol, then use it to find the library and load all necessary symbols
     pointer_to_handler handler;
     dynamic_link_descriptor desc = { descriptors[0].name, &handler };
     if ( resolve_symbols( library_handle, &desc, 1 ) )
             return pin_symbols( desc, descriptors, required );
     return 0;
 }
Ejemplo n.º 8
0
/*
 * Finish building grammar
 */
void
grammar_complete(struct grammar *grammar)
{
    resolve_symbols(grammar);
    determine_start(grammar);
    add_sentinel_rule(grammar);
    count_symbols(grammar);
    /* At this point we have complete symbol graph */

    if (print_opt(P_GRAMMAR))
        dump_grammar(grammar);
    if (print_opt(P_SYMBOLS))
        dump_symbols(grammar);

    nullable_find(grammar);

    if (print_opt(P_NULLABLE))
        nullable_dump(grammar);
}
Ejemplo n.º 9
0
    static dynamic_link_handle pin_symbols( dynamic_link_handle library_handle, dynamic_link_descriptor desc, const dynamic_link_descriptor* descriptors, size_t required ) {
        ::tbb::internal::suppress_unused_warning( desc, descriptors, required );
#if __TBB_DYNAMIC_LOAD_ENABLED
        // It is supposed that all symbols are from the only one library
        // The library has been loaded by another module and contains at least one requested symbol.
        // But after we obtained the symbol the library can be unloaded by another thread
        // invalidating our symbol. Therefore we need to pin the library in memory.
        const char * dli_fname;
    #ifdef __CYGWIN__
        MEMORY_BASIC_INFORMATION mbi;
        char path[MAX_PATH];
        VirtualQuery((void*)&dynamic_link, &mbi, sizeof(mbi));
        if(GetModuleFileNameA((HINSTANCE)mbi.AllocationBase, path, MAX_PATH)) {
        char posix_path[MAX_PATH];
        cygwin_conv_path(CCP_WIN_A_TO_POSIX | CCP_RELATIVE, path, posix_path, MAX_PATH);
        dli_fname = posix_path;

    #else
        Dl_info info;
        // Get library's name from earlier found symbol
        if ( dladdr( (void*)*desc.handler, &info ) ) {
            dli_fname = info.dli_fname;
    #endif
            // Pin the library
            library_handle = dlopen( dli_fname, RTLD_LAZY );
            if ( library_handle ) {
                // If original library was unloaded before we pinned it
                // and then another module loaded in its place, the earlier
                // found symbol would become invalid. So revalidate them.
                if ( !resolve_symbols( library_handle, descriptors, required ) ) {
                    // Wrong library.
                    dynamic_unlink(library_handle);
                    library_handle = 0;
                }
            } else {
                char const * err = dlerror();
                DYNAMIC_LINK_WARNING( dl_lib_not_found, dli_fname, err );
            }
        }
        else {
            // The library have been unloaded by another thread
            library_handle = 0;
        }
#endif /* __TBB_DYNAMIC_LOAD_ENABLED */
        return library_handle;
    }
#endif /* !_WIN32 */

    static dynamic_link_handle global_symbols_link( const char* library, const dynamic_link_descriptor descriptors[], size_t required ) {
        ::tbb::internal::suppress_unused_warning( library );
        dynamic_link_handle library_handle;
#if _WIN32
        if ( GetModuleHandleEx( 0, library, &library_handle ) ) {
            if ( resolve_symbols( library_handle, descriptors, required ) )
                return library_handle;
            else
                FreeLibrary( library_handle );
        }
#else /* _WIN32 */
    #if !__TBB_DYNAMIC_LOAD_ENABLED /* only __TBB_WEAK_SYMBOLS_PRESENT is defined */
        if ( !dlopen ) return 0;
    #endif /* !__TBB_DYNAMIC_LOAD_ENABLED */
        library_handle = dlopen( NULL, RTLD_LAZY );
    #if !__ANDROID__
        // On Android dlopen( NULL ) returns NULL if it is called during dynamic module initialization.
        LIBRARY_ASSERT( library_handle, "The handle for the main program is NULL" );
    #endif
        // Check existence of the first symbol only, then use it to find the library and load all necessary symbols.
        pointer_to_handler handler;
        dynamic_link_descriptor desc;
        desc.name = descriptors[0].name;
        desc.handler = &handler;
        if ( resolve_symbols( library_handle, &desc, 1 ) )
            return pin_symbols( library_handle, desc, descriptors, required );
#endif /* _WIN32 */
        return 0;
    }
Ejemplo n.º 10
0
int
main(int argc, char **argv)
{
	pid_t pid;
	list_t *list;
	element_t *element;
	char buf[1024];
	int i, fd, ret;
	struct user_regs_struct regs;

	memset(buf, 0, sizeof(buf));

	if(argc < 2) {
		printf("usage: %s <pid>\n", argv[0]);
		exit(-1);
	}

	pid = atoi(argv[1]);

	snprintf(buf, sizeof(buf) - 1, "/proc/%d/exe", pid);

	fd = open(buf, O_RDONLY);
	if(fd < 0) {
		perror("open");
		exit(-1);
	}

	list = list_new();

	resolve_symbols(fd, list);

	if(list_size(list) <= 0) {
		printf("no symbols..\n");
		exit(-1);
	}

	ret = ptrace(PTRACE_ATTACH, pid, NULL, NULL);

	if(ret < 0) {
		perror("ptrace");
		exit(-1);
	}

	waitpid(pid, NULL, 0);

	/* 
	 * iterate through addresses, setting breakpoints
	 */

	element = list_head(list);
	
	for(i = 0; i < list_size(list); i++) {
		bpx_t *bpx;

		bpx = list_data(element);

		printf("setting breakpoint on 0x%x (%s)\n", (int)bpx->addr, bpx->name);

		bpx->value = breakpoint_set(pid, bpx->addr);

		element = list_next(element);
	}
	 
	while(1) {
	 	ret = ptrace(PTRACE_CONT, pid, NULL, NULL);
		if(ret < 0) {
			perror("ptrace");
			exit(-1);
		}

		wait(NULL);

 		ret = ptrace(PTRACE_GETREGS, pid, NULL, &regs);
		if(ret < 0) {
			perror("ptrace");
			exit(-1);
		}

		element = list_head(list);

		while(element) {
			bpx_t *bpx;

			bpx = list_data(element);

			if(bpx->addr + 2 == regs.eip) {
				printf("removing breakpoint on 0x%x (%s)\n", (int)bpx->addr, bpx->name);
				breakpoint_rem(pid, bpx->addr, bpx->value);
				set_eip(pid, bpx->addr);
			} 

			element = list_next(element);
		}
	}
	
	ret = ptrace(PTRACE_DETACH, pid, NULL, NULL);
	if(ret < 0) {
		perror("ptrace");
		exit(-1);
	}

	exit(0);
}
Ejemplo n.º 11
0
Archivo: mttest.c Proyecto: dhaley/dcp
int
main(int argc, char **argv, char **envp)
{
	int	i;

	scale_init(argc, argv);

#define ALIGNMENTOFFSET 2 /* adjust alignment */
        i = sizeof(workStruct_t)*
            (narrays+ALIGNMENTOFFSET);
        element = memalign(64, i);
	if ( element == NULL ) {
	    perror("calloc( narrays, sizeof(workStruct_t) )");
	    exit(1);
	}
        compute_set(element);
        memset(element, 0, i);
        element+=ALIGNMENTOFFSET;

#ifdef SELFTEST
	start_prof();
#endif

	fid = open_output("mttest.acct");
	if (job_index == -1) {
		i = (sizeof(scripttab)/sizeof( struct scripttab) -1 );
	} else {
		i = 1;
	}
	fprintf(fid, "Number of tests: %d  Repeat count: %d\n",
		i, repeat_count);

	fprintf(fid, "MHz: %d\n", get_clock_rate() );

	fprintf(fid,
	    "X    Incl. Total   Incl. CPU   Incl. Sync. Wait   Name (%s)\n",
		model);
	fflush(fid);
  
	name = strdup(argv[0]);

	init_micro_acct();
#if OS(Solaris) 
	if(uniprocessor != 0) {
	    /* call processor_bind to force single CPU */
	    processor_bind(P_PID, P_MYID, cpuid, NULL);
	}
#endif /* OS(Solaris) */

#ifdef SOLARIS
	sema_init(&global_sema_lock, count, USYNC_THREAD, NULL);
#endif
#ifdef POSIX
	pthread_attr_init(&attr);

    #ifdef BOUND
	pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
    #endif

	sem_init(&global_sema_lock, 0, count);
#endif

#if 0
	if ((s5_sema_id = semget(IPC_PRIVATE, 1, 0600)) == -1)
		perror("semget: IPC_PRIVATE");

	arg.val = count;
	if (semctl(s5_sema_id, 0, SETVAL, arg) == -1)
		perror("semctl: SETVAL");
#endif

	resolve_symbols();

	i = locktest();
#if 0
	if (semctl(s5_sema_id, 0, IPC_RMID) == -1)
		perror("semctl: IPC_RMID");
#endif

	close_file(fid);

#ifdef SELFTEST
        finish_prof();
#endif

	return 0;
}