Changeset bb9ec2d in mainline for uspace/srv
- Timestamp:
- 2017-03-07T20:47:35Z (9 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a737667e
- Parents:
- e796dc8
- git-author:
- Jiri Zarevucky <zarevucky.jiri@…> (2017-03-07 20:47:35)
- git-committer:
- Jakub Jermar <jakub@…> (2017-03-07 20:47:35)
- Location:
- uspace/srv
- Files:
-
- 4 edited
-
loader/main.c (modified) (8 diffs)
-
vfs/vfs.h (modified) (1 diff)
-
vfs/vfs_file.c (modified) (7 diffs)
-
vfs/vfs_ops.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/loader/main.c
re796dc8 rbb9ec2d 62 62 #include <elf/elf_load.h> 63 63 #include <vfs/vfs.h> 64 #include <vfs/inbox.h> 64 65 65 66 #define DPRINTF(...) 66 67 67 /** Pathname of the file that will be loaded */ 68 static char *pathname = NULL; 68 /** File that will be loaded */ 69 static char *progname = NULL; 70 static int program_fd = -1; 69 71 70 72 /** The Program control block */ … … 81 83 static char *arg_buf = NULL; 82 84 83 /** Number of preset files */ 84 static unsigned int filc = 0; 85 /** Inbox entries. */ 86 static struct pcb_inbox_entry inbox[INBOX_MAX_ENTRIES]; 87 static int inbox_entries = 0; 85 88 86 89 static elf_info_t prog_info; … … 130 133 } 131 134 132 /** Receive a call setting pathname of the program to execute. 133 * 134 * @param rid 135 * @param request 136 */ 137 static void ldr_set_pathname(ipc_callid_t rid, ipc_call_t *request) 138 { 139 char *buf; 140 int rc = async_data_write_accept((void **) &buf, true, 0, 0, 0, NULL); 141 142 if (rc == EOK) { 143 if (pathname != NULL) 144 free(pathname); 145 146 pathname = buf; 147 } 148 149 async_answer_0(rid, rc); 135 /** Receive a call setting the program to execute. 136 * 137 * @param rid 138 * @param request 139 */ 140 static void ldr_set_program(ipc_callid_t rid, ipc_call_t *request) 141 { 142 ipc_callid_t writeid; 143 size_t namesize; 144 if (!async_data_write_receive(&writeid, &namesize)) { 145 async_answer_0(rid, EINVAL); 146 return; 147 } 148 149 char* name = malloc(namesize); 150 int rc = async_data_write_finalize(writeid, name, namesize); 151 if (rc != EOK) { 152 async_answer_0(rid, EINVAL); 153 return; 154 } 155 156 int file = vfs_receive_handle(true); 157 if (file < 0) { 158 async_answer_0(rid, EINVAL); 159 return; 160 } 161 162 progname = name; 163 program_fd = file; 164 async_answer_0(rid, EOK); 150 165 } 151 166 … … 215 230 } 216 231 217 /** Receive a call setting preset files of the program to execute. 218 * 219 * @param rid 220 * @param request 221 */ 222 static void ldr_set_files(ipc_callid_t rid, ipc_call_t *request) 223 { 224 size_t count = IPC_GET_ARG1(*request); 225 226 for (filc = 0; filc < count; filc++) { 227 int fd = vfs_receive_handle(); 228 if (fd < 0) { 229 break; 230 } 231 assert(fd == (int) filc); 232 } 233 232 /** Receive a call setting inbox files of the program to execute. 233 * 234 * @param rid 235 * @param request 236 */ 237 static void ldr_add_inbox(ipc_callid_t rid, ipc_call_t *request) 238 { 239 if (inbox_entries == INBOX_MAX_ENTRIES) { 240 async_answer_0(rid, ERANGE); 241 } 242 243 ipc_callid_t writeid; 244 size_t namesize; 245 if (!async_data_write_receive(&writeid, &namesize)) { 246 async_answer_0(rid, EINVAL); 247 return; 248 } 249 250 char* name = malloc(namesize); 251 int rc = async_data_write_finalize(writeid, name, namesize); 252 if (rc != EOK) { 253 async_answer_0(rid, EINVAL); 254 return; 255 } 256 257 int file = vfs_receive_handle(true); 258 if (file < 0) { 259 async_answer_0(rid, EINVAL); 260 return; 261 } 262 263 inbox[inbox_entries].name = name; 264 inbox[inbox_entries].file = file; 265 inbox_entries++; 234 266 async_answer_0(rid, EOK); 235 267 } … … 243 275 static int ldr_load(ipc_callid_t rid, ipc_call_t *request) 244 276 { 245 int rc; 246 247 rc = elf_load(pathname, &prog_info); 277 int rc = elf_load(program_fd, &prog_info); 248 278 if (rc != EE_OK) { 249 DPRINTF("Failed to load executable '%s'.\n", pathname);279 DPRINTF("Failed to load executable for '%s'.\n", progname); 250 280 async_answer_0(rid, EINVAL); 251 281 return 1; … … 259 289 pcb.argv = argv; 260 290 261 pcb.filc = filc; 291 pcb.inbox = inbox; 292 pcb.inbox_entries = inbox_entries; 262 293 263 294 async_answer_0(rid, rc); … … 273 304 static void ldr_run(ipc_callid_t rid, ipc_call_t *request) 274 305 { 275 const char *cp;276 277 306 DPRINTF("Set task name\n"); 278 307 279 308 /* Set the task name. */ 280 cp = str_rchr(pathname, '/'); 281 cp = (cp == NULL) ? pathname : (cp + 1); 282 task_set_name(cp); 309 task_set_name(progname); 283 310 284 311 /* Run program */ … … 327 354 ldr_set_cwd(callid, &call); 328 355 continue; 329 case LOADER_SET_P ATHNAME:330 ldr_set_p athname(callid, &call);356 case LOADER_SET_PROGRAM: 357 ldr_set_program(callid, &call); 331 358 continue; 332 359 case LOADER_SET_ARGS: 333 360 ldr_set_args(callid, &call); 334 361 continue; 335 case LOADER_ SET_FILES:336 ldr_ set_files(callid, &call);362 case LOADER_ADD_INBOX: 363 ldr_add_inbox(callid, &call); 337 364 continue; 338 365 case LOADER_LOAD: -
uspace/srv/vfs/vfs.h
re796dc8 rbb9ec2d 197 197 198 198 extern void vfs_op_pass_handle(task_id_t, task_id_t, int); 199 extern int vfs_wait_handle_internal( void);199 extern int vfs_wait_handle_internal(bool); 200 200 201 201 extern vfs_file_t *vfs_file_get(int); -
uspace/srv/vfs/vfs_file.c
re796dc8 rbb9ec2d 59 59 typedef struct { 60 60 link_t link; 61 int handle; 61 vfs_node_t *node; 62 int permissions; 62 63 } vfs_boxed_handle_t; 63 64 … … 365 366 vfs_client_data_t *acceptor_data = NULL; 366 367 vfs_file_t *donor_file = NULL; 367 vfs_file_t *acceptor_file = NULL;368 368 vfs_boxed_handle_t *bh; 369 int acceptor_fd;370 369 371 370 acceptor_data = async_get_client_data_by_id(acceptor_id); … … 377 376 378 377 link_initialize(&bh->link); 379 bh-> handle = -1;378 bh->node = NULL; 380 379 381 380 donor_data = async_get_client_data_by_id(donor_id); … … 386 385 if (!donor_file) 387 386 goto out; 388 389 acceptor_fd = _vfs_fd_alloc(acceptor_data, &acceptor_file, false);390 if (acceptor_fd < 0)391 goto out;392 393 bh->handle = acceptor_fd;394 387 395 388 /* … … 397 390 */ 398 391 vfs_node_addref(donor_file->node); 399 400 assert(acceptor_file); 401 402 /* 403 * Inherit attributes from the donor. 404 */ 405 acceptor_file->node = donor_file->node; 406 acceptor_file->permissions = donor_file->permissions; 407 408 // TODO: The file should not inherit its open status, but clients depend on this. 409 acceptor_file->pos = donor_file->pos; 410 acceptor_file->append = donor_file->append; 411 acceptor_file->open_read = donor_file->open_read; 412 acceptor_file->open_write = donor_file->open_write; 413 414 if (acceptor_file->open_read || acceptor_file->open_write) { 415 (void) vfs_open_node_remote(acceptor_file->node); 416 } 392 bh->node = donor_file->node; 393 bh->permissions = donor_file->permissions; 417 394 418 395 out: … … 428 405 if (donor_file) 429 406 _vfs_file_put(donor_data, donor_file); 430 if (acceptor_file) 431 _vfs_file_put(acceptor_data, acceptor_file); 432 433 } 434 435 int vfs_wait_handle_internal(void) 407 } 408 409 int vfs_wait_handle_internal(bool high_fd) 436 410 { 437 411 vfs_client_data_t *vfs_data = VFS_DATA; 438 int fd;439 412 440 413 fibril_mutex_lock(&vfs_data->lock); … … 446 419 447 420 vfs_boxed_handle_t *bh = list_get_instance(lnk, vfs_boxed_handle_t, link); 448 fd = bh->handle; 421 422 vfs_file_t *file; 423 int fd = _vfs_fd_alloc(vfs_data, &file, high_fd); 424 if (fd < 0) { 425 vfs_node_delref(bh->node); 426 free(bh); 427 return fd; 428 } 429 430 file->node = bh->node; 431 file->permissions = bh->permissions; 432 vfs_file_put(file); 449 433 free(bh); 450 451 434 return fd; 452 435 } -
uspace/srv/vfs/vfs_ops.c
re796dc8 rbb9ec2d 1248 1248 void vfs_wait_handle(ipc_callid_t rid, ipc_call_t *request) 1249 1249 { 1250 int fd = vfs_wait_handle_internal(); 1250 bool high_fd = IPC_GET_ARG1(*request); 1251 int fd = vfs_wait_handle_internal(high_fd); 1251 1252 async_answer_1(rid, EOK, fd); 1252 1253 }
Note:
See TracChangeset
for help on using the changeset viewer.
