Changeset 42a619b in mainline for uspace/lib/c
- Timestamp:
- 2011-08-19T08:58:50Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7dcb7981, 903bac0a, c2cf033
- Parents:
- ef7052ec (diff), d894fbd (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- uspace/lib/c
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/async.c
ref7052ec r42a619b 201 201 { 202 202 async_client_data_destroy = dtor; 203 }204 205 void *async_get_client_data(void)206 {207 assert(fibril_connection);208 return fibril_connection->client->data;209 203 } 210 204 … … 580 574 } 581 575 576 static client_t *async_client_get(sysarg_t client_hash, bool create) 577 { 578 unsigned long key = client_hash; 579 client_t *client = NULL; 580 581 futex_down(&async_futex); 582 link_t *lnk = hash_table_find(&client_hash_table, &key); 583 if (lnk) { 584 client = hash_table_get_instance(lnk, client_t, link); 585 atomic_inc(&client->refcnt); 586 } else if (create) { 587 client = malloc(sizeof(client_t)); 588 if (client) { 589 client->in_task_hash = client_hash; 590 client->data = async_client_data_create(); 591 592 atomic_set(&client->refcnt, 1); 593 hash_table_insert(&client_hash_table, &key, &client->link); 594 } 595 } 596 597 futex_up(&async_futex); 598 return client; 599 } 600 601 static void async_client_put(client_t *client) 602 { 603 bool destroy; 604 unsigned long key = client->in_task_hash; 605 606 futex_down(&async_futex); 607 608 if (atomic_predec(&client->refcnt) == 0) { 609 hash_table_remove(&client_hash_table, &key, 1); 610 destroy = true; 611 } else 612 destroy = false; 613 614 futex_up(&async_futex); 615 616 if (destroy) { 617 if (client->data) 618 async_client_data_destroy(client->data); 619 620 free(client); 621 } 622 } 623 624 void *async_get_client_data(void) 625 { 626 assert(fibril_connection); 627 return fibril_connection->client->data; 628 } 629 630 void *async_get_client_data_by_hash(sysarg_t client_hash) 631 { 632 client_t *client = async_client_get(client_hash, false); 633 if (!client) 634 return NULL; 635 if (!client->data) { 636 async_client_put(client); 637 return NULL; 638 } 639 640 return client->data; 641 } 642 643 void async_put_client_data_by_hash(sysarg_t client_hash) 644 { 645 client_t *client = async_client_get(client_hash, false); 646 647 assert(client); 648 assert(client->data); 649 650 /* Drop the reference we got in async_get_client_data_by_hash(). */ 651 async_client_put(client); 652 653 /* Drop our own reference we got at the beginning of this function. */ 654 async_client_put(client); 655 } 656 582 657 /** Wrapper for client connection fibril. 583 658 * … … 598 673 */ 599 674 fibril_connection = (connection_t *) arg; 600 601 futex_down(&async_futex);602 675 603 676 /* … … 606 679 * hash in a new tracking structure. 607 680 */ 608 609 unsigned long key = fibril_connection->in_task_hash; 610 link_t *lnk = hash_table_find(&client_hash_table, &key); 611 612 client_t *client; 613 614 if (lnk) { 615 client = hash_table_get_instance(lnk, client_t, link); 616 atomic_inc(&client->refcnt); 617 } else { 618 client = malloc(sizeof(client_t)); 619 if (!client) { 620 ipc_answer_0(fibril_connection->callid, ENOMEM); 621 futex_up(&async_futex); 622 return 0; 623 } 624 625 client->in_task_hash = fibril_connection->in_task_hash; 626 client->data = async_client_data_create(); 627 628 atomic_set(&client->refcnt, 1); 629 hash_table_insert(&client_hash_table, &key, &client->link); 630 } 631 632 futex_up(&async_futex); 633 681 682 client_t *client = async_client_get(fibril_connection->in_task_hash, true); 683 if (!client) { 684 ipc_answer_0(fibril_connection->callid, ENOMEM); 685 return 0; 686 } 687 634 688 fibril_connection->client = client; 635 689 … … 643 697 * Remove the reference for this client task connection. 644 698 */ 645 bool destroy; 646 647 futex_down(&async_futex); 648 649 if (atomic_predec(&client->refcnt) == 0) { 650 hash_table_remove(&client_hash_table, &key, 1); 651 destroy = true; 652 } else 653 destroy = false; 654 655 futex_up(&async_futex); 656 657 if (destroy) { 658 if (client->data) 659 async_client_data_destroy(client->data); 660 661 free(client); 662 } 699 async_client_put(client); 663 700 664 701 /* … … 666 703 */ 667 704 futex_down(&async_futex); 668 key = fibril_connection->in_phone_hash;705 unsigned long key = fibril_connection->in_phone_hash; 669 706 hash_table_remove(&conn_hash_table, &key, 1); 670 707 futex_up(&async_futex); … … 2429 2466 } 2430 2467 2468 int async_state_change_start(async_exch_t *exch, sysarg_t arg1, sysarg_t arg2, 2469 sysarg_t arg3, async_exch_t *other_exch) 2470 { 2471 return async_req_5_0(exch, IPC_M_STATE_CHANGE_AUTHORIZE, 2472 arg1, arg2, arg3, 0, other_exch->phone); 2473 } 2474 2475 bool async_state_change_receive(ipc_callid_t *callid, sysarg_t *arg1, 2476 sysarg_t *arg2, sysarg_t *arg3) 2477 { 2478 assert(callid); 2479 2480 ipc_call_t call; 2481 *callid = async_get_call(&call); 2482 2483 if (IPC_GET_IMETHOD(call) != IPC_M_STATE_CHANGE_AUTHORIZE) 2484 return false; 2485 2486 if (arg1) 2487 *arg1 = IPC_GET_ARG1(call); 2488 if (arg2) 2489 *arg2 = IPC_GET_ARG2(call); 2490 if (arg3) 2491 *arg3 = IPC_GET_ARG3(call); 2492 2493 return true; 2494 } 2495 2496 int async_state_change_finalize(ipc_callid_t callid, async_exch_t *other_exch) 2497 { 2498 return ipc_answer_1(callid, EOK, other_exch->phone); 2499 } 2500 2431 2501 /** @} 2432 2502 */ -
uspace/lib/c/generic/event.c
ref7052ec r42a619b 54 54 } 55 55 56 int event_task_subscribe(event_task_type_t evno, sysarg_t imethod) 57 { 58 return __SYSCALL2(SYS_EVENT_SUBSCRIBE, (sysarg_t) evno, 59 (sysarg_t) imethod); 60 } 61 56 62 /** Unmask event notifications. 57 63 * … … 66 72 } 67 73 74 int event_task_unmask(event_task_type_t evno) 75 { 76 return __SYSCALL1(SYS_EVENT_UNMASK, (sysarg_t) evno); 77 } 78 68 79 /** @} 69 80 */ -
uspace/lib/c/generic/io/io.c
ref7052ec r42a619b 101 101 static LIST_INITIALIZE(files); 102 102 103 void __stdio_init(int filc , fdi_node_t *filv[])103 void __stdio_init(int filc) 104 104 { 105 105 if (filc > 0) { 106 stdin = f open_node(filv[0], "r");106 stdin = fdopen(0, "r"); 107 107 } else { 108 108 stdin = &stdin_null; … … 111 111 112 112 if (filc > 1) { 113 stdout = f open_node(filv[1], "w");113 stdout = fdopen(1, "w"); 114 114 } else { 115 115 stdout = &stdout_klog; … … 118 118 119 119 if (filc > 2) { 120 stderr = f open_node(filv[2], "w");120 stderr = fdopen(2, "w"); 121 121 } else { 122 122 stderr = &stderr_klog; … … 285 285 } 286 286 287 FILE *fopen_node(fdi_node_t *node, const char *mode)288 {289 int flags;290 if (!parse_mode(mode, &flags))291 return NULL;292 293 /* Open file. */294 FILE *stream = malloc(sizeof(FILE));295 if (stream == NULL) {296 errno = ENOMEM;297 return NULL;298 }299 300 stream->fd = open_node(node, flags);301 if (stream->fd < 0) {302 /* errno was set by open_node() */303 free(stream);304 return NULL;305 }306 307 stream->error = false;308 stream->eof = false;309 stream->klog = false;310 stream->sess = NULL;311 stream->need_sync = false;312 _setvbuf(stream);313 314 list_append(&stream->link, &files);315 316 return stream;317 }318 319 287 int fclose(FILE *stream) 320 288 { … … 780 748 } 781 749 782 int fnode(FILE *stream, fdi_node_t *node) 783 { 784 if (stream->fd >= 0) 785 return fd_node(stream->fd, node); 750 int fhandle(FILE *stream, int *handle) 751 { 752 if (stream->fd >= 0) { 753 *handle = stream->fd; 754 return EOK; 755 } 786 756 787 757 return ENOENT; -
uspace/lib/c/generic/libc.c
ref7052ec r42a619b 91 91 argc = 0; 92 92 argv = NULL; 93 __stdio_init(0 , NULL);93 __stdio_init(0); 94 94 } else { 95 95 argc = __pcb->argc; 96 96 argv = __pcb->argv; 97 __stdio_init(__pcb->filc , __pcb->filv);97 __stdio_init(__pcb->filc); 98 98 (void) chdir(__pcb->cwd); 99 99 } -
uspace/lib/c/generic/loader.c
ref7052ec r42a619b 256 256 * 257 257 */ 258 int loader_set_files(loader_t *ldr, fdi_node_t *const files[]) 259 { 260 /* 261 * Serialize the arguments into a single array. First 262 * compute size of the buffer needed. 263 */ 264 fdi_node_t *const *ap = files; 265 size_t count = 0; 266 while (*ap != NULL) { 267 count++; 268 ap++; 269 } 270 271 fdi_node_t *files_buf; 272 files_buf = (fdi_node_t *) malloc(count * sizeof(fdi_node_t)); 273 if (files_buf == NULL) 274 return ENOMEM; 275 276 /* Fill the buffer */ 277 size_t i; 278 for (i = 0; i < count; i++) 279 files_buf[i] = *files[i]; 280 258 int loader_set_files(loader_t *ldr, int * const files[]) 259 { 281 260 /* Send serialized files to the loader */ 282 261 async_exch_t *exch = async_exchange_begin(ldr->sess); 283 284 ipc_call_t answer; 285 aid_t req = async_send_0(exch, LOADER_SET_FILES, &answer); 286 sysarg_t rc = async_data_write_start(exch, (void *) files_buf, 287 count * sizeof(fdi_node_t)); 288 289 async_exchange_end(exch); 290 free(files_buf); 291 262 async_exch_t *vfs_exch = vfs_exchange_begin(); 263 264 int i; 265 for (i = 0; files[i]; i++) 266 ; 267 268 ipc_call_t answer; 269 aid_t req = async_send_1(exch, LOADER_SET_FILES, i, &answer); 270 271 sysarg_t rc = EOK; 272 273 for (i = 0; files[i]; i++) { 274 rc = async_state_change_start(exch, VFS_PASS_HANDLE, *files[i], 275 0, vfs_exch); 276 if (rc != EOK) 277 break; 278 } 279 280 vfs_exchange_end(vfs_exch); 281 async_exchange_end(exch); 282 292 283 if (rc != EOK) { 293 284 async_wait_for(req, NULL); -
uspace/lib/c/generic/private/async.h
ref7052ec r42a619b 36 36 #define LIBC_PRIVATE_ASYNC_H_ 37 37 38 #include <ipc/common.h> 38 39 #include <adt/list.h> 39 40 #include <fibril.h> -
uspace/lib/c/generic/private/io.h
ref7052ec r42a619b 36 36 #define LIBC_PRIVATE_IO_H_ 37 37 38 #include <vfs/vfs.h> 39 40 extern void __stdio_init(int filc, fdi_node_t *filv[]); 38 extern void __stdio_init(int); 41 39 extern void __stdio_done(void); 42 40 -
uspace/lib/c/generic/task.c
ref7052ec r42a619b 46 46 #include <libc.h> 47 47 #include "private/ns.h" 48 #include <vfs/vfs.h> 48 49 49 50 task_id_t task_get_id(void) … … 102 103 { 103 104 /* Send default files */ 104 fdi_node_t *files[4];105 fdi_node_t stdin_node;106 fdi_node_t stdout_node;107 fdi_node_t stderr_node;108 109 if ((stdin != NULL) && (f node(stdin, &stdin_node) == EOK))110 files[0] = & stdin_node;105 int *files[4]; 106 int fd_stdin; 107 int fd_stdout; 108 int fd_stderr; 109 110 if ((stdin != NULL) && (fhandle(stdin, &fd_stdin) == EOK)) 111 files[0] = &fd_stdin; 111 112 else 112 113 files[0] = NULL; 113 114 114 if ((stdout != NULL) && (f node(stdout, &stdout_node) == EOK))115 files[1] = & stdout_node;115 if ((stdout != NULL) && (fhandle(stdout, &fd_stdout) == EOK)) 116 files[1] = &fd_stdout; 116 117 else 117 118 files[1] = NULL; 118 119 119 if ((stderr != NULL) && (f node(stderr, &stderr_node) == EOK))120 files[2] = & stderr_node;120 if ((stderr != NULL) && (fhandle(stderr, &fd_stderr) == EOK)) 121 files[2] = &fd_stderr; 121 122 else 122 123 files[2] = NULL; … … 142 143 */ 143 144 int task_spawnvf(task_id_t *id, const char *path, const char *const args[], 144 fdi_node_t *const files[])145 int *const files[]) 145 146 { 146 147 /* Connect to a program loader. */ -
uspace/lib/c/generic/vfs/vfs.c
ref7052ec r42a619b 69 69 * 70 70 */ 71 staticasync_exch_t *vfs_exchange_begin(void)71 async_exch_t *vfs_exchange_begin(void) 72 72 { 73 73 fibril_mutex_lock(&vfs_mutex); … … 87 87 * 88 88 */ 89 staticvoid vfs_exchange_end(async_exch_t *exch)89 void vfs_exchange_end(async_exch_t *exch) 90 90 { 91 91 async_exchange_end(exch); … … 329 329 } 330 330 331 int open_node(fdi_node_t *node, int oflag)332 {333 async_exch_t *exch = vfs_exchange_begin();334 335 ipc_call_t answer;336 aid_t req = async_send_4(exch, VFS_IN_OPEN_NODE, node->fs_handle,337 node->service_id, node->index, oflag, &answer);338 339 vfs_exchange_end(exch);340 341 sysarg_t rc;342 async_wait_for(req, &rc);343 344 if (rc != EOK)345 return (int) rc;346 347 return (int) IPC_GET_ARG1(answer);348 }349 350 331 int close(int fildes) 351 332 { … … 819 800 } 820 801 821 int fd_node(int fildes, fdi_node_t *node)822 {823 struct stat stat;824 int rc = fstat(fildes, &stat);825 826 if (rc == EOK) {827 node->fs_handle = stat.fs_handle;828 node->service_id = stat.service_id;829 node->index = stat.index;830 }831 832 return rc;833 }834 835 802 int dup2(int oldfd, int newfd) 836 803 { … … 848 815 } 849 816 817 int fd_wait(void) 818 { 819 async_exch_t *exch = vfs_exchange_begin(); 820 821 sysarg_t ret; 822 sysarg_t rc = async_req_0_1(exch, VFS_IN_WAIT_HANDLE, &ret); 823 824 vfs_exchange_end(exch); 825 826 if (rc == EOK) 827 return (int) ret; 828 829 return (int) rc; 830 } 831 850 832 /** @} 851 833 */ -
uspace/lib/c/include/async.h
ref7052ec r42a619b 186 186 extern void async_set_client_data_destructor(async_client_data_dtor_t); 187 187 extern void *async_get_client_data(void); 188 extern void *async_get_client_data_by_hash(sysarg_t); 189 extern void async_put_client_data_by_hash(sysarg_t); 188 190 189 191 extern void async_set_client_connection(async_client_conn_t); … … 477 479 extern async_sess_t *async_callback_receive_start(exch_mgmt_t, ipc_call_t *); 478 480 481 extern int async_state_change_start(async_exch_t *, sysarg_t, sysarg_t, 482 sysarg_t, async_exch_t *); 483 extern bool async_state_change_receive(ipc_callid_t *, sysarg_t *, sysarg_t *, 484 sysarg_t *); 485 extern int async_state_change_finalize(ipc_callid_t, async_exch_t *); 486 479 487 #endif 480 488 -
uspace/lib/c/include/event.h
ref7052ec r42a619b 37 37 38 38 #include <abi/ipc/event.h> 39 #include <libarch/types.h> 39 40 40 41 extern int event_subscribe(event_type_t, sysarg_t); 42 extern int event_task_subscribe(event_task_type_t, sysarg_t); 41 43 extern int event_unmask(event_type_t); 44 extern int event_task_unmask(event_task_type_t); 42 45 43 46 #endif -
uspace/lib/c/include/ipc/vfs.h
ref7052ec r42a619b 62 62 typedef enum { 63 63 VFS_IN_OPEN = IPC_FIRST_USER_METHOD, 64 VFS_IN_OPEN_NODE,65 64 VFS_IN_READ, 66 65 VFS_IN_WRITE, … … 78 77 VFS_IN_RENAME, 79 78 VFS_IN_STAT, 80 VFS_IN_DUP 79 VFS_IN_DUP, 80 VFS_IN_WAIT_HANDLE, 81 81 } vfs_in_request_t; 82 82 -
uspace/lib/c/include/loader/loader.h
ref7052ec r42a619b 38 38 39 39 #include <task.h> 40 #include <vfs/vfs.h>41 40 42 41 /** Forward declararion */ … … 50 49 extern int loader_set_pathname(loader_t *, const char *); 51 50 extern int loader_set_args(loader_t *, const char *const[]); 52 extern int loader_set_files(loader_t *, fdi_node_t *const[]);51 extern int loader_set_files(loader_t *, int *const[]); 53 52 extern int loader_load_program(loader_t *); 54 53 extern int loader_run(loader_t *); -
uspace/lib/c/include/loader/pcb.h
ref7052ec r42a619b 38 38 39 39 #include <sys/types.h> 40 #include <vfs/vfs.h>41 40 42 41 typedef void (*entry_point_t)(void); … … 62 61 63 62 /** Number of preset files. */ 64 int filc; 65 /** Preset files. */ 66 fdi_node_t **filv; 63 unsigned int filc; 67 64 68 65 /* -
uspace/lib/c/include/task.h
ref7052ec r42a619b 37 37 38 38 #include <sys/types.h> 39 #include <vfs/vfs.h>40 39 41 40 typedef uint64_t task_id_t; … … 53 52 extern int task_spawnv(task_id_t *, const char *path, const char *const []); 54 53 extern int task_spawnvf(task_id_t *, const char *path, const char *const [], 55 fdi_node_t *const []);54 int *const []); 56 55 extern int task_spawnl(task_id_t *, const char *path, ...); 57 56 -
uspace/lib/c/include/vfs/vfs.h
ref7052ec r42a619b 40 40 #include <ipc/loc.h> 41 41 #include <stdio.h> 42 #include <async.h> 42 43 43 /** Libc version of the VFS triplet. 44 * 45 * Unique identification of a file system node 46 * within a file system instance. 47 * 48 */ 49 typedef struct { 50 fs_handle_t fs_handle; 51 service_id_t service_id; 52 fs_index_t index; 53 } fdi_node_t; 44 enum vfs_change_state_type { 45 VFS_PASS_HANDLE 46 }; 54 47 55 48 extern char *absolutize(const char *, size_t *); … … 59 52 extern int unmount(const char *); 60 53 61 extern int open_node(fdi_node_t *, int); 62 extern int fd_node(int, fdi_node_t *); 54 extern int fhandle(FILE *, int *); 63 55 64 extern FILE *fopen_node(fdi_node_t *, const char *); 65 extern int fnode(FILE *, fdi_node_t *); 56 extern int fd_wait(void); 57 58 extern async_exch_t *vfs_exchange_begin(void); 59 extern void vfs_exchange_end(async_exch_t *); 66 60 67 61 #endif
Note:
See TracChangeset
for help on using the changeset viewer.