static int dump_images_list(int argc, char **argv) { struct image *image = NULL; Team *team; if (argc > 1) { team_id id = strtol(argv[1], NULL, 0); team = team_get_team_struct_locked(id); if (team == NULL) { kprintf("No team with ID %" B_PRId32 " found\n", id); return 1; } } else team = thread_get_current_thread()->team; kprintf("Registered images of team %" B_PRId32 "\n", team->id); kprintf(" ID %-*s size %-*s size name\n", B_PRINTF_POINTER_WIDTH, "text", B_PRINTF_POINTER_WIDTH, "data"); while ((image = (struct image*)list_get_next_item(&team->image_list, image)) != NULL) { image_info *info = &image->info.basic_info; kprintf("%6" B_PRId32 " %p %-7" B_PRId32 " %p %-7" B_PRId32 " %s\n", info->id, info->text, info->text_size, info->data, info->data_size, info->name); } return 0; }
/*! Duplicates an FD from another team to this/the kernel team. \param fromTeam The team which owns the FD. \param fd The FD to duplicate. \param kernel If \c true, the new FD will be created in the kernel team, the current userland team otherwise. \return The newly created FD or an error code, if something went wrong. */ int dup_foreign_fd(team_id fromTeam, int fd, bool kernel) { // get the I/O context for the team in question InterruptsSpinLocker teamsLocker(gTeamSpinlock); struct team* team = team_get_team_struct_locked(fromTeam); if (team == NULL) return B_BAD_TEAM_ID; io_context* fromContext = team->io_context; vfs_get_io_context(fromContext); teamsLocker.Unlock(); CObjectDeleter<io_context> _(fromContext, vfs_put_io_context); // get the file descriptor file_descriptor* descriptor = get_fd(fromContext, fd); if (descriptor == NULL) return B_FILE_ERROR; CObjectDeleter<file_descriptor> descriptorPutter(descriptor, put_fd); // create a new FD in the target I/O context int result = new_fd(get_current_io_context(kernel), descriptor); if (result >= 0) { // the descriptor reference belongs to the slot, now descriptorPutter.Detach(); } return result; }
static int dump_images_list(int argc, char **argv) { struct image *image = NULL; Team *team; if (argc > 1) { team_id id = strtol(argv[1], NULL, 0); team = team_get_team_struct_locked(id); if (team == NULL) { kprintf("No team with ID %ld found\n", id); return 1; } } else team = thread_get_current_thread()->team; kprintf("Registered images of team %ld\n", team->id); kprintf(" ID text size data size name\n"); while ((image = (struct image*)list_get_next_item(&team->image_list, image)) != NULL) { image_info *info = &image->info; kprintf("%6ld %p %-7ld %p %-7ld %s\n", info->id, info->text, info->text_size, info->data, info->data_size, info->name); } return 0; }
status_t set_port_owner(port_id id, team_id newTeamID) { TRACE(("set_port_owner(id = %ld, team = %ld)\n", id, newTeamID)); if (id < 0) return B_BAD_PORT_ID; int32 slot = id % sMaxPorts; MutexLocker locker(sPorts[slot].lock); if (sPorts[slot].id != id) { TRACE(("set_port_owner: invalid port_id %ld\n", id)); return B_BAD_PORT_ID; } InterruptsSpinLocker teamLocker(gTeamSpinlock); struct team* team = team_get_team_struct_locked(newTeamID); if (team == NULL) { T(OwnerChange(sPorts[slot], newTeamID, B_BAD_TEAM_ID)); return B_BAD_TEAM_ID; } // transfer ownership to other team list_remove_link(&sPorts[slot].team_link); list_add_item(&team->port_list, &sPorts[slot].team_link); sPorts[slot].owner = newTeamID; T(OwnerChange(sPorts[slot], newTeamID, B_OK)); return B_OK; }