int main(int argc, char **argv) { prefix = get_unused_env_prefix(); prefixset = alloc_cat(prefix, "s"); prefixunset = alloc_cat(prefix, "u"); char *prog_path = get_program_path(); // <bundle>/Contents/MacOS/<filename> char *macos = dirname_wrapper(prog_path); // <bundle>/Contents/MacOS char *contents = dirname_wrapper(macos); // <bundle>/Contents // char *bundle = dirname_wrapper(contents); // <bundle> char *resources = alloc_cat(contents, "/Resources"); // char *bin = alloc_cat(resources, "/bin"); char *etc = alloc_cat(resources, "/etc"); char *lib = alloc_cat(resources, "/lib"); char *share = alloc_cat(resources, "/share"); char *xdg = alloc_cat(etc, "/xdg"); // char *gtkrc = alloc_cat(etc, "/gtk-2.0/gtkrc"); char *locale = alloc_cat(share, "/locale"); char *realbin = alloc_cat(prog_path, "-bin"); overwrite_env("DYLD_LIBRARY_PATH", lib); overwrite_env("XDG_CONFIG_DIRS", xdg); overwrite_env("XDG_DATA_DIRS", share); overwrite_env("GTK_DATA_PREFIX", resources); overwrite_env("GTK_EXE_PREFIX", resources); overwrite_env("GTK_PATH", resources); overwrite_env("PANGO_LIBDIR", lib); overwrite_env("PANGO_SYSCONFDIR", etc); overwrite_env("I18NDIR", locale); overwrite_env("LANG", NULL); overwrite_env("LC_MESSAGES", NULL); overwrite_env("LC_MONETARY", NULL); overwrite_env("LC_COLLATE", NULL); char **new_argv = malloc((argc + 16) * sizeof(const char *)); if (!new_argv) { fprintf(stderr, "out of memory\n"); exit(1); } int j = 0; new_argv[j++] = realbin; { int i = 1; if (i < argc && !strncmp(argv[i], "-psn_", 5)) i++; for (; i < argc; i++) new_argv[j++] = argv[i]; } new_argv[j++] = prefix; new_argv[j++] = NULL; execv(realbin, new_argv); perror("execv"); free(new_argv); free(contents); free(macos); return 127; }
const std::string get_prefix () { std::string pp = get_program_path (); if (rld::path::basename (pp) == "bin") return rld::path::dirname (pp); return pp; }
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { char bufor[256], bufor2[256]; if(key(bufor)!=1) get_program_path(bufor,256); chdir(bufor); strcat(bufor, "\\python\\pythonw.exe"); strcpy(bufor2, "pytigon "); strcat(bufor2, lpCmdLine); execl(bufor, bufor, bufor2, NULL); return 0; }
BC_COREPLATFORMIMP_DLL void bc_platform_path<g_api_win32>::get_absolute_path(const bcECHAR* p_relative_path, bcECHAR* p_buffer, bcSIZE p_buffer_size) { bcECHAR l_buffer[MAX_PATH] = { '\0' }; get_program_path(l_buffer, MAX_PATH); bc_path l_path = bc_path(l_buffer); l_path.set_filename(p_relative_path); #ifdef BC_UNICODE wcscpy_s(p_buffer, p_buffer_size, l_path.m_pack.m_path.c_str()); #else strcpy_s(p_buffer, p_buffer_size, l_path.m_pack.m_path.c_str()); #endif }
status_t load_image(char const* name, image_type type, const char* rpath, const char* requestingObjectPath, image_t** _image) { int32 pheaderSize, sheaderSize; char path[PATH_MAX]; ssize_t length; char pheaderBuffer[4096]; int32 numRegions; image_t* found; image_t* image; status_t status; int fd; elf_ehdr eheader; // Have we already loaded that image? Don't check for add-ons -- we always // reload them. if (type != B_ADD_ON_IMAGE) { found = find_loaded_image_by_name(name, APP_OR_LIBRARY_TYPE); if (found == NULL && type != B_APP_IMAGE && gProgramImage != NULL) { // Special case for add-ons that link against the application // executable, with the executable not having a soname set. if (const char* lastSlash = strrchr(name, '/')) { if (strcmp(gProgramImage->name, lastSlash + 1) == 0) found = gProgramImage; } } if (found) { atomic_add(&found->ref_count, 1); *_image = found; KTRACE("rld: load_container(\"%s\", type: %d, rpath: \"%s\") " "already loaded", name, type, rpath); return B_OK; } } KTRACE("rld: load_container(\"%s\", type: %d, rpath: \"%s\")", name, type, rpath); strlcpy(path, name, sizeof(path)); // find and open the file fd = open_executable(path, type, rpath, get_program_path(), requestingObjectPath, sSearchPathSubDir); if (fd < 0) { FATAL("Cannot open file %s: %s\n", name, strerror(fd)); KTRACE("rld: load_container(\"%s\"): failed to open file", name); return fd; } // normalize the image path status = _kern_normalize_path(path, true, path); if (status != B_OK) goto err1; // Test again if this image has been registered already - this time, // we can check the full path, not just its name as noted. // You could end up loading an image twice with symbolic links, else. if (type != B_ADD_ON_IMAGE) { found = find_loaded_image_by_name(path, APP_OR_LIBRARY_TYPE); if (found) { atomic_add(&found->ref_count, 1); *_image = found; _kern_close(fd); KTRACE("rld: load_container(\"%s\"): already loaded after all", name); return B_OK; } } length = _kern_read(fd, 0, &eheader, sizeof(eheader)); if (length != sizeof(eheader)) { status = B_NOT_AN_EXECUTABLE; FATAL("%s: Troubles reading ELF header\n", path); goto err1; } status = parse_elf_header(&eheader, &pheaderSize, &sheaderSize); if (status < B_OK) { FATAL("%s: Incorrect ELF header\n", path); goto err1; } // ToDo: what to do about this restriction?? if (pheaderSize > (int)sizeof(pheaderBuffer)) { FATAL("%s: Cannot handle program headers bigger than %lu\n", path, sizeof(pheaderBuffer)); status = B_UNSUPPORTED; goto err1; } length = _kern_read(fd, eheader.e_phoff, pheaderBuffer, pheaderSize); if (length != pheaderSize) { FATAL("%s: Could not read program headers: %s\n", path, strerror(length)); status = B_BAD_DATA; goto err1; } numRegions = count_regions(path, pheaderBuffer, eheader.e_phnum, eheader.e_phentsize); if (numRegions <= 0) { FATAL("%s: Troubles parsing Program headers, numRegions = %" B_PRId32 "\n", path, numRegions); status = B_BAD_DATA; goto err1; } image = create_image(name, path, numRegions); if (image == NULL) { FATAL("%s: Failed to allocate image_t object\n", path); status = B_NO_MEMORY; goto err1; } status = parse_program_headers(image, pheaderBuffer, eheader.e_phnum, eheader.e_phentsize); if (status < B_OK) goto err2; if (!assert_dynamic_loadable(image)) { FATAL("%s: Dynamic segment must be loadable (implementation " "restriction)\n", image->path); status = B_UNSUPPORTED; goto err2; } status = map_image(fd, path, image, eheader.e_type == ET_EXEC); if (status < B_OK) { FATAL("%s: Could not map image: %s\n", image->path, strerror(status)); status = B_ERROR; goto err2; } if (!parse_dynamic_segment(image)) { FATAL("%s: Troubles handling dynamic section\n", image->path); status = B_BAD_DATA; goto err3; } if (eheader.e_entry != 0) image->entry_point = eheader.e_entry + image->regions[0].delta; analyze_image_haiku_version_and_abi(fd, image, eheader, sheaderSize, pheaderBuffer, sizeof(pheaderBuffer)); // If this is the executable image, we init the search path // subdir, if the compiler version doesn't match ours. if (type == B_APP_IMAGE) { #if __GNUC__ == 2 if ((image->abi & B_HAIKU_ABI_MAJOR) == B_HAIKU_ABI_GCC_4) sSearchPathSubDir = "x86"; #elif __GNUC__ >= 4 if ((image->abi & B_HAIKU_ABI_MAJOR) == B_HAIKU_ABI_GCC_2) sSearchPathSubDir = "x86_gcc2"; #endif } set_abi_version(image->abi); // init gcc version dependent image flags // symbol resolution strategy if (image->abi == B_HAIKU_ABI_GCC_2_ANCIENT) image->find_undefined_symbol = find_undefined_symbol_beos; // init version infos status = init_image_version_infos(image); image->type = type; register_image(image, fd, path); image_event(image, IMAGE_EVENT_LOADED); _kern_close(fd); enqueue_loaded_image(image); *_image = image; KTRACE("rld: load_container(\"%s\"): done: id: %" B_PRId32 " (ABI: %#" B_PRIx32 ")", name, image->id, image->abi); return B_OK; err3: unmap_image(image); err2: delete_image_struct(image); err1: _kern_close(fd); KTRACE("rld: load_container(\"%s\"): failed: %s", name, strerror(status)); return status; }
int main(int argc, char *argv[]) { char pipe[2048]; MSG msg; STARTUPINFO si = { 0, }; PROCESS_INFORMATION pi = { 0, }; gchar *program_path = get_program_path(); gchar *command; int rv = 0; argv[0] = "gdb -ex run --args"; command = g_strjoinv(" ", argv); snprintf(pipe, sizeof(pipe), "\\\\.\\pipe\\SpiceController-%lu", GetCurrentProcessId()); SetEnvironmentVariable("SPICE_DEBUG", "1"); SetEnvironmentVariable("G_MESSAGES_DEBUG", "all"); SetEnvironmentVariable("SPICE_XPI_NAMEDPIPE", pipe); si.cb = sizeof(si); if (!CreateProcess(NULL, command, NULL, NULL, FALSE, 0, NULL, program_path, &si, &pi)) { printf("CreateProcess failed (%ld).\n", GetLastError()); rv = 1; goto end; } while (1) { DWORD reason = MsgWaitForMultipleObjects(1, &pi.hProcess, FALSE, INFINITE, QS_ALLINPUT); if (reason == WAIT_OBJECT_0) break; else { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } } } // Close process and thread handles CloseHandle(pi.hProcess); CloseHandle(pi.hThread); end: g_free(program_path); g_free(command); exit(rv); return rv; }