コード例 #1
0
ファイル: sim_remote.cpp プロジェクト: kgnk/Halide
int initialize_kernels(const unsigned char *code, int codeLen, bool use_dlopenbuf, handle_t *module_ptr) {
    void *lib = NULL;
    if (use_dlopenbuf) {
        if (!dlopenbuf) {
            log_printf("dlopenbuf not available.\n");
            return -1;
        }
        // We need a unique soname, or dlopenbuf will return a
        // previously opened library.
        static int unique_id = 0;
        char soname[256];
        sprintf(soname, "libhalide_kernels%04d.so", __sync_fetch_and_add(&unique_id, 1));

        // Open the library
        dllib_init();
        // We need to use RTLD_NOW, the libraries we build for Hexagon
        // offloading do not support lazy bindin.
        lib = dlopenbuf(soname, (const char*)code, codeLen, RTLD_LOCAL | RTLD_NOW);
        if (!lib) {
            halide_print(NULL, "dlopenbuf failed\n");
            halide_print(NULL, dlerror());
            return -1;
        }
    } else {
        lib = mmap_dlopen(code, codeLen);
        if (!lib) {
            halide_print(NULL, "mmap_dlopen failed\n");
            return -1;
        }
    }

    *module_ptr = reinterpret_cast<handle_t>(lib);
    return 0;
}
コード例 #2
0
ファイル: halide_remote.cpp プロジェクト: halide/Halide
int halide_hexagon_remote_load_library(const char *soname, int sonameLen,
                                       const unsigned char *code, int codeLen,
                                       handle_t *module_ptr) {
    void *lib = NULL;
    if (use_dlopenbuf()) {
        // We need to use RTLD_NOW, the libraries we build for Hexagon
        // offloading do not support lazy binding.
        lib = dlopenbuf(soname, (const char*)code, codeLen, RTLD_GLOBAL | RTLD_NOW);
        if (!lib) {
            log_printf("dlopenbuf failed: %s\n", dlerror());
            return -1;
        }
    } else {
        lib = mmap_dlopen(code, codeLen);
        if (!lib) {
            log_printf("mmap_dlopen failed\n");
            return -1;
        }
    }

    *module_ptr = reinterpret_cast<handle_t>(lib);

    return 0;
}
コード例 #3
0
DWORD request_core_loadlib(Remote *remote, Packet *packet) {
	Packet *response = packet_create_response(packet);
	DWORD res = ERROR_SUCCESS;
	HMODULE library;
	PCHAR libraryPath;
	DWORD flags = 0;
	PCHAR targetPath;
	int local_error = 0;
	Command *command;
	Command *first = extensionCommands;

	do {
		Tlv dataTlv;

		libraryPath = packet_get_tlv_value_string(packet, TLV_TYPE_LIBRARY_PATH);
		flags = packet_get_tlv_value_uint(packet, TLV_TYPE_FLAGS);

		// Invalid library path?
		if (!libraryPath) {
			res = ERROR_INVALID_PARAMETER;
			break;
		}

		if (flags & LOAD_LIBRARY_FLAG_LOCAL) {
			// i'd be surprised if we could load
			// libraries off the remote system without breaking severely.
			res = ERROR_NOT_SUPPORTED;
			break;
		}

		// Get the library's file contents
		if ((packet_get_tlv(packet, TLV_TYPE_DATA,
			&dataTlv) != ERROR_SUCCESS) ||
			(!(targetPath = packet_get_tlv_value_string(packet,
			TLV_TYPE_TARGET_PATH)))) {
			res = ERROR_INVALID_PARAMETER;
			break;
		}

		dprintf("targetPath: %s", targetPath);

		library = dlopenbuf(targetPath, dataTlv.buffer, dataTlv.header.length);
		dprintf("dlopenbuf(%s): %08x / %s", targetPath, library, dlerror());
		if (!library) {
			res = ERROR_NOT_FOUND;
			break;
		}

		// If this library is supposed to be an extension library, try to
		// call its Init routine
		if (flags & LOAD_LIBRARY_FLAG_EXTENSION) {
			PEXTENSION pExtension = (PEXTENSION)malloc(sizeof(EXTENSION));
			if (!pExtension) {
				res = ERROR_NOT_ENOUGH_MEMORY;
				break;
			}
			//DWORD(*init)(Remote *remote);

			pExtension->init = dlsym(library, "InitServerExtension");

			// Call the init routine in the library
			if (pExtension->init) {
				dprintf("calling InitServerExtension");
				pExtension->end = first;
				res = pExtension->init(remote);
				pExtension->start = extensionCommands;
				pExtension->getname = dlsym(library, "GetExtensionName");
				pExtension->deinit = dlsym(library, "DeinitServerExtension");

				if (pExtension->getname) {
					pExtension->getname(pExtension->name, sizeof(pExtension->name));
				}
				list_push(gExtensionList, pExtension);
			}
			else {
				free(pExtension);
			}

			if (response) {
				for (command = pExtension->start; command != pExtension->end; command = command->next) {
					packet_add_tlv_string(response, TLV_TYPE_METHOD, command->method);
				}
			}
		}

	} while (0);

	if (response) {
		packet_add_tlv_uint(response, TLV_TYPE_RESULT, res);
		PACKET_TRANSMIT(remote, response, NULL);
	}

	return (res);
}