int Image::Load(Team &team) { fProgramHeaderTable = new Elf32_Phdr[fHeader->e_phnum]; if (fProgramHeaderTable == 0) return E_NO_MEMORY; if (read_pos(fFileHandle, fHeader->e_phoff, fProgramHeaderTable, fHeader->e_phnum * fHeader->e_phentsize) != fHeader->e_phnum * fHeader->e_phentsize) { printf("Error reading program header\n"); return E_NOT_IMAGE; } const char *filename = fPath; for (const char *c = fPath; *c; c++) if (*c == '/') filename = c + 1; for (int segmentIndex = 0; segmentIndex < fHeader->e_phnum; segmentIndex++) { char areaName[OS_NAME_LENGTH]; snprintf(areaName, OS_NAME_LENGTH, "%.12s seg_%d", filename, segmentIndex); if (fProgramHeaderTable[segmentIndex].p_vaddr % PAGE_SIZE != fProgramHeaderTable[segmentIndex].p_offset % PAGE_SIZE) { printf("Unaligned Segment\n"); return E_NOT_IMAGE; } #if DISABLE_DEMAND_PAGE Area *seg = space->CreateArea(areaName, ((fProgramHeaderTable[segmentIndex].p_memsz + PAGE_SIZE - 1) / PAGE_SIZE) * PAGE_SIZE, AREA_NOT_LOCKED, USER_READ | SYSTEM_READ | SYSTEM_WRITE, WRITABLE_PAGE, static_cast<void*>(fProgramHeaderTable[segmentIndex].p_vaddr), EXACT_ADDRESS); if (seg == 0) return E_NOT_IMAGE; lseek(fFileHandle, fProgramHeaderTable[segmentIndex].p_offset, SEEK_SET); if (fProgramHeaderTable[segmentIndex].p_type == PT_LOAD && fProgramHeaderTable[segmentIndex].p_filesz > 0) read(fFileHandle, static_cast<void*>(fProgramHeaderTable[segmentIndex].p_vaddr), fProgramHeaderTable[segmentIndex].p_filesz); #else status_t error = CreateFileArea(areaName, fPath, fProgramHeaderTable[segmentIndex].p_vaddr & ~(PAGE_SIZE - 1), fProgramHeaderTable[segmentIndex].p_offset & ~(PAGE_SIZE - 1), ((fProgramHeaderTable[segmentIndex].p_memsz + PAGE_SIZE - 1) / PAGE_SIZE) * PAGE_SIZE, EXACT_ADDRESS | MAP_PRIVATE, ((fProgramHeaderTable[segmentIndex].p_flags & PF_W) ? (USER_WRITE | SYSTEM_WRITE) : 0) | USER_READ | USER_EXEC | SYSTEM_READ, team); if (error < 0) { printf("Failed to map image file\n"); return error; } #endif if (segmentIndex == 0) fBaseAddress = reinterpret_cast<void*>(fProgramHeaderTable[segmentIndex].p_vaddr); } return 0; }
/** * 创建所有区域. * @return 主窗体 */ GtkWidget *DialogPeer::CreateAllArea() { GtkWidget *box; GtkWidget *hpaned, *vpaned; gint position; box = gtk_vbox_new(FALSE, 0); /* 加入菜单条 */ gtk_box_pack_start(GTK_BOX(box), CreateMenuBar(), FALSE, FALSE, 0); /* 加入主区域 */ hpaned = gtk_hpaned_new(); g_datalist_set_data(&widset, "main-paned", hpaned); g_object_set_data(G_OBJECT(hpaned), "position-name", (gpointer)"main-paned-divide"); position = GPOINTER_TO_INT(g_datalist_get_data(&dtset, "main-paned-divide")); gtk_paned_set_position(GTK_PANED(hpaned), position); gtk_box_pack_start(GTK_BOX(box), hpaned, TRUE, TRUE, 0); g_signal_connect(hpaned, "notify::position", G_CALLBACK(PanedDivideChanged), &dtset); /*/* 加入聊天历史记录&输入区域 */ vpaned = gtk_vpaned_new(); g_object_set_data(G_OBJECT(vpaned), "position-name", (gpointer)"historyinput-paned-divide"); position = GPOINTER_TO_INT(g_datalist_get_data(&dtset, "historyinput-paned-divide")); gtk_paned_set_position(GTK_PANED(vpaned), position); gtk_paned_pack1(GTK_PANED(hpaned), vpaned, TRUE, TRUE); g_signal_connect(vpaned, "notify::position", G_CALLBACK(PanedDivideChanged), &dtset); gtk_paned_pack1(GTK_PANED(vpaned), CreateHistoryArea(), TRUE, TRUE); gtk_paned_pack2(GTK_PANED(vpaned), CreateInputArea(), FALSE, TRUE); /* 加入好友信息&附件区域 */ vpaned = gtk_vpaned_new(); g_object_set_data(G_OBJECT(vpaned), "position-name", (gpointer)"infoenclosure-paned-divide"); position = GPOINTER_TO_INT(g_datalist_get_data(&dtset, "infoenclosure-paned-divide")); gtk_paned_set_position(GTK_PANED(vpaned), position); gtk_paned_pack2(GTK_PANED(hpaned), vpaned, FALSE, TRUE); g_signal_connect(vpaned, "notify::position", G_CALLBACK(PanedDivideChanged), &dtset); gtk_paned_pack1(GTK_PANED(vpaned), CreateInfoArea(), TRUE, TRUE); gtk_paned_pack2(GTK_PANED(vpaned), CreateFileArea(), FALSE, TRUE); return box; }
int map_file(const char path[], unsigned int va, off_t offset, size_t size, int flags) { return CreateFileArea(path, path, va, offset, size, flags, USER_READ | USER_WRITE | SYSTEM_READ | SYSTEM_WRITE, *Thread::GetRunningThread()->GetTeam()); }