Changeset 925a21e in mainline for uspace/lib/c/generic
- Timestamp:
- 2011-09-24T14:20:29Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5bf76c1
- Parents:
- 867e2555 (diff), 1ab4aca (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/generic
- Files:
-
- 2 added
- 3 deleted
- 26 edited
-
adt/hash_table.c (modified) (4 diffs)
-
adt/list.c (modified) (2 diffs)
-
as.c (modified) (1 diff)
-
async.c (modified) (28 diffs)
-
async_obsolete.c (deleted)
-
cfg.c (added)
-
ddi.c (modified) (2 diffs)
-
devman.c (modified) (9 diffs)
-
devmap.c (deleted)
-
event.c (modified) (3 diffs)
-
fibril.c (modified) (1 diff)
-
io/console.c (modified) (4 diffs)
-
io/io.c (modified) (7 diffs)
-
io/printf_core.c (modified) (5 diffs)
-
io/screenbuffer.c (deleted)
-
ipc.c (modified) (4 diffs)
-
libc.c (modified) (1 diff)
-
loader.c (modified) (1 diff)
-
loc.c (added)
-
malloc.c (modified) (1 diff)
-
ns.c (modified) (2 diffs)
-
private/async.h (modified) (2 diffs)
-
private/io.h (modified) (1 diff)
-
private/thread.h (modified) (1 diff)
-
str.c (modified) (6 diffs)
-
sysinfo.c (modified) (1 diff)
-
task.c (modified) (3 diffs)
-
thread.c (modified) (1 diff)
-
time.c (modified) (1 diff)
-
udebug.c (modified) (1 diff)
-
vfs/vfs.c (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/adt/hash_table.c
r867e2555 r925a21e 152 152 153 153 if (keys == h->max_keys) { 154 link_t *cur;155 156 154 /* 157 155 * All keys are known, hash_table_find() can be used to find the … … 159 157 */ 160 158 161 cur = hash_table_find(h, key);159 link_t *cur = hash_table_find(h, key); 162 160 if (cur) { 163 161 list_remove(cur); … … 174 172 hash_index_t chain; 175 173 for (chain = 0; chain < h->entries; chain++) { 176 link_t *cur; 177 178 for (cur = h->entry[chain].head.next; cur != &h->entry[chain].head; 174 for (link_t *cur = h->entry[chain].head.next; 175 cur != &h->entry[chain].head; 179 176 cur = cur->next) { 180 177 if (h->op->compare(key, keys, cur)) { … … 193 190 } 194 191 195 /** Apply fu cntion to all items in hash table.192 /** Apply function to all items in hash table. 196 193 * 197 194 * @param h Hash table. -
uspace/lib/c/generic/adt/list.c
r867e2555 r925a21e 33 33 /** 34 34 * @file 35 * @brief Functions completing doubly linked circular list implementa ion.35 * @brief Functions completing doubly linked circular list implementation. 36 36 * 37 37 * This file contains some of the functions implementing doubly linked circular lists. … … 50 50 * @param list List to look in. 51 51 * 52 * @return true if link is contained in head, false otherwise.52 * @return true if link is contained in list, false otherwise. 53 53 * 54 54 */ -
uspace/lib/c/generic/as.c
r867e2555 r925a21e 123 123 * @retval ENOENT Mapping not found. 124 124 */ 125 int as_get_physical_mapping( void *address, uintptr_t *frame)125 int as_get_physical_mapping(const void *address, uintptr_t *frame) 126 126 { 127 127 uintptr_t tmp_frame; -
uspace/lib/c/generic/async.c
r867e2555 r925a21e 98 98 #include <ipc/ipc.h> 99 99 #include <async.h> 100 #include "private/async.h" 100 101 #undef LIBC_ASYNC_C_ 101 102 … … 107 108 #include <errno.h> 108 109 #include <sys/time.h> 109 #include < arch/barrier.h>110 #include <libarch/barrier.h> 110 111 #include <bool.h> 111 112 #include <malloc.h> 112 113 #include <mem.h> 113 114 #include <stdlib.h> 114 #include "private/async.h"115 #include <macros.h> 115 116 116 117 #define CLIENT_HASH_TABLE_BUCKETS 32 117 118 #define CONN_HASH_TABLE_BUCKETS 32 119 120 /** Session data */ 121 struct async_sess { 122 /** List of inactive exchanges */ 123 list_t exch_list; 124 125 /** Exchange management style */ 126 exch_mgmt_t mgmt; 127 128 /** Session identification */ 129 int phone; 130 131 /** First clone connection argument */ 132 sysarg_t arg1; 133 134 /** Second clone connection argument */ 135 sysarg_t arg2; 136 137 /** Third clone connection argument */ 138 sysarg_t arg3; 139 140 /** Exchange mutex */ 141 fibril_mutex_t mutex; 142 143 /** Number of opened exchanges */ 144 atomic_t refcnt; 145 146 /** Mutex for stateful connections */ 147 fibril_mutex_t remote_state_mtx; 148 149 /** Data for stateful connections */ 150 void *remote_state_data; 151 }; 152 153 /** Exchange data */ 154 struct async_exch { 155 /** Link into list of inactive exchanges */ 156 link_t sess_link; 157 158 /** Link into global list of inactive exchanges */ 159 link_t global_link; 160 161 /** Session pointer */ 162 async_sess_t *sess; 163 164 /** Exchange identification */ 165 int phone; 166 }; 118 167 119 168 /** Async framework global futex */ … … 134 183 } msg_t; 135 184 185 /** Message data */ 186 typedef struct { 187 awaiter_t wdata; 188 189 /** If reply was received. */ 190 bool done; 191 192 /** Pointer to where the answer data is stored. */ 193 ipc_call_t *dataptr; 194 195 sysarg_t retval; 196 } amsg_t; 197 136 198 /* Client connection data */ 137 199 typedef struct { 138 200 link_t link; 139 201 140 sysarg_t in_task_hash;202 task_id_t in_task_id; 141 203 atomic_t refcnt; 142 204 void *data; … … 150 212 link_t link; 151 213 152 /** Incoming client task hash. */153 sysarg_t in_task_hash;214 /** Incoming client task ID. */ 215 task_id_t in_task_id; 154 216 155 217 /** Incoming phone hash. */ … … 203 265 } 204 266 205 void *async_get_client_data(void)206 {207 assert(fibril_connection);208 return fibril_connection->client->data;209 }210 211 267 /** Default fibril function that gets called to handle new connection. 212 268 * … … 289 345 { 290 346 assert(key); 347 assert(keys == 2); 291 348 assert(item); 292 349 293 350 client_t *client = hash_table_get_instance(item, client_t, link); 294 return (key[0] == client->in_task_hash); 351 return (key[0] == LOWER32(client->in_task_id) && 352 (key[1] == UPPER32(client->in_task_id))); 295 353 } 296 354 … … 580 638 } 581 639 640 static client_t *async_client_get(task_id_t client_id, bool create) 641 { 642 unsigned long key[2] = { 643 LOWER32(client_id), 644 UPPER32(client_id), 645 }; 646 client_t *client = NULL; 647 648 futex_down(&async_futex); 649 link_t *lnk = hash_table_find(&client_hash_table, key); 650 if (lnk) { 651 client = hash_table_get_instance(lnk, client_t, link); 652 atomic_inc(&client->refcnt); 653 } else if (create) { 654 client = malloc(sizeof(client_t)); 655 if (client) { 656 client->in_task_id = client_id; 657 client->data = async_client_data_create(); 658 659 atomic_set(&client->refcnt, 1); 660 hash_table_insert(&client_hash_table, key, &client->link); 661 } 662 } 663 664 futex_up(&async_futex); 665 return client; 666 } 667 668 static void async_client_put(client_t *client) 669 { 670 bool destroy; 671 unsigned long key[2] = { 672 LOWER32(client->in_task_id), 673 UPPER32(client->in_task_id) 674 }; 675 676 futex_down(&async_futex); 677 678 if (atomic_predec(&client->refcnt) == 0) { 679 hash_table_remove(&client_hash_table, key, 2); 680 destroy = true; 681 } else 682 destroy = false; 683 684 futex_up(&async_futex); 685 686 if (destroy) { 687 if (client->data) 688 async_client_data_destroy(client->data); 689 690 free(client); 691 } 692 } 693 694 void *async_get_client_data(void) 695 { 696 assert(fibril_connection); 697 return fibril_connection->client->data; 698 } 699 700 void *async_get_client_data_by_id(task_id_t client_id) 701 { 702 client_t *client = async_client_get(client_id, false); 703 if (!client) 704 return NULL; 705 if (!client->data) { 706 async_client_put(client); 707 return NULL; 708 } 709 710 return client->data; 711 } 712 713 void async_put_client_data_by_id(task_id_t client_id) 714 { 715 client_t *client = async_client_get(client_id, false); 716 717 assert(client); 718 assert(client->data); 719 720 /* Drop the reference we got in async_get_client_data_by_hash(). */ 721 async_client_put(client); 722 723 /* Drop our own reference we got at the beginning of this function. */ 724 async_client_put(client); 725 } 726 582 727 /** Wrapper for client connection fibril. 583 728 * … … 598 743 */ 599 744 fibril_connection = (connection_t *) arg; 600 601 futex_down(&async_futex);602 745 603 746 /* … … 606 749 * hash in a new tracking structure. 607 750 */ 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 751 752 client_t *client = async_client_get(fibril_connection->in_task_id, true); 753 if (!client) { 754 ipc_answer_0(fibril_connection->callid, ENOMEM); 755 return 0; 756 } 757 634 758 fibril_connection->client = client; 635 759 … … 643 767 * Remove the reference for this client task connection. 644 768 */ 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 } 769 async_client_put(client); 663 770 664 771 /* … … 666 773 */ 667 774 futex_down(&async_futex); 668 key = fibril_connection->in_phone_hash;775 unsigned long key = fibril_connection->in_phone_hash; 669 776 hash_table_remove(&conn_hash_table, &key, 1); 670 777 futex_up(&async_futex); … … 700 807 * particular fibrils. 701 808 * 702 * @param in_task_ hashIdentification of the incoming connection.809 * @param in_task_id Identification of the incoming connection. 703 810 * @param in_phone_hash Identification of the incoming connection. 704 811 * @param callid Hash of the opening IPC_M_CONNECT_ME_TO call. … … 714 821 * 715 822 */ 716 fid_t async_new_connection( sysarg_t in_task_hash, sysarg_t in_phone_hash,823 fid_t async_new_connection(task_id_t in_task_id, sysarg_t in_phone_hash, 717 824 ipc_callid_t callid, ipc_call_t *call, 718 825 async_client_conn_t cfibril, void *carg) … … 726 833 } 727 834 728 conn->in_task_ hash = in_task_hash;835 conn->in_task_id = in_task_id; 729 836 conn->in_phone_hash = in_phone_hash; 730 837 list_initialize(&conn->msg_queue); … … 785 892 case IPC_M_CONNECT_ME_TO: 786 893 /* Open new connection with fibril, etc. */ 787 async_new_connection(call->in_task_ hash, IPC_GET_ARG5(*call),894 async_new_connection(call->in_task_id, IPC_GET_ARG5(*call), 788 895 callid, call, client_connection, NULL); 789 896 return; … … 933 1040 { 934 1041 if (!hash_table_create(&client_hash_table, CLIENT_HASH_TABLE_BUCKETS, 935 1, &client_hash_table_ops))1042 2, &client_hash_table_ops)) 936 1043 abort(); 937 1044 … … 949 1056 session_ns->arg2 = 0; 950 1057 session_ns->arg3 = 0; 1058 1059 fibril_mutex_initialize(&session_ns->remote_state_mtx); 1060 session_ns->remote_state_data = NULL; 951 1061 952 1062 list_initialize(&session_ns->exch_list); … … 1426 1536 return ENOENT; 1427 1537 1428 sysarg_t task_hash;1429 1538 sysarg_t phone_hash; 1430 int rc = async_req_3_5(exch, IPC_M_CONNECT_TO_ME, arg1, arg2, arg3, 1431 NULL, NULL, NULL, &task_hash, &phone_hash); 1539 sysarg_t rc; 1540 1541 aid_t req; 1542 ipc_call_t answer; 1543 req = async_send_3(exch, IPC_M_CONNECT_TO_ME, arg1, arg2, arg3, 1544 &answer); 1545 async_wait_for(req, &rc); 1432 1546 if (rc != EOK) 1433 return rc; 1434 1547 return (int) rc; 1548 1549 phone_hash = IPC_GET_ARG5(answer); 1550 1435 1551 if (client_receiver != NULL) 1436 async_new_connection( task_hash, phone_hash, 0, NULL,1552 async_new_connection(answer.in_task_id, phone_hash, 0, NULL, 1437 1553 client_receiver, carg); 1438 1554 … … 1509 1625 sess->arg3 = 0; 1510 1626 1627 fibril_mutex_initialize(&sess->remote_state_mtx); 1628 sess->remote_state_data = NULL; 1629 1511 1630 list_initialize(&sess->exch_list); 1512 1631 fibril_mutex_initialize(&sess->mutex); … … 1590 1709 sess->arg3 = arg3; 1591 1710 1711 fibril_mutex_initialize(&sess->remote_state_mtx); 1712 sess->remote_state_data = NULL; 1713 1592 1714 list_initialize(&sess->exch_list); 1593 1715 fibril_mutex_initialize(&sess->mutex); … … 1595 1717 1596 1718 return sess; 1719 } 1720 1721 /** Set arguments for new connections. 1722 * 1723 * FIXME This is an ugly hack to work around the problem that parallel 1724 * exchanges are implemented using parallel connections. When we create 1725 * a callback session, the framework does not know arguments for the new 1726 * connections. 1727 * 1728 * The proper solution seems to be to implement parallel exchanges using 1729 * tagging. 1730 */ 1731 void async_sess_args_set(async_sess_t *sess, sysarg_t arg1, sysarg_t arg2, 1732 sysarg_t arg3) 1733 { 1734 sess->arg1 = arg1; 1735 sess->arg2 = arg2; 1736 sess->arg3 = arg3; 1597 1737 } 1598 1738 … … 1640 1780 sess->arg3 = arg3; 1641 1781 1782 fibril_mutex_initialize(&sess->remote_state_mtx); 1783 sess->remote_state_data = NULL; 1784 1642 1785 list_initialize(&sess->exch_list); 1643 1786 fibril_mutex_initialize(&sess->mutex); … … 1671 1814 sess->arg3 = 0; 1672 1815 1816 fibril_mutex_initialize(&sess->remote_state_mtx); 1817 sess->remote_state_data = NULL; 1818 1673 1819 list_initialize(&sess->exch_list); 1674 1820 fibril_mutex_initialize(&sess->mutex); … … 1692 1838 int async_hangup(async_sess_t *sess) 1693 1839 { 1840 async_exch_t *exch; 1841 1694 1842 assert(sess); 1695 1843 1696 1844 if (atomic_get(&sess->refcnt) > 0) 1697 1845 return EBUSY; 1846 1847 fibril_mutex_lock(&async_sess_mutex); 1698 1848 1699 1849 int rc = async_hangup_internal(sess->phone); 1700 1850 if (rc == EOK) 1701 1851 free(sess); 1852 1853 while (!list_empty(&sess->exch_list)) { 1854 exch = (async_exch_t *) 1855 list_get_instance(list_first(&sess->exch_list), 1856 async_exch_t, sess_link); 1857 1858 list_remove(&exch->sess_link); 1859 list_remove(&exch->global_link); 1860 async_hangup_internal(exch->phone); 1861 free(exch); 1862 } 1863 1864 fibril_mutex_unlock(&async_sess_mutex); 1702 1865 1703 1866 return rc; … … 2334 2497 sess->arg3 = 0; 2335 2498 2499 fibril_mutex_initialize(&sess->remote_state_mtx); 2500 sess->remote_state_data = NULL; 2501 2336 2502 list_initialize(&sess->exch_list); 2337 2503 fibril_mutex_initialize(&sess->mutex); … … 2380 2546 sess->arg3 = 0; 2381 2547 2548 fibril_mutex_initialize(&sess->remote_state_mtx); 2549 sess->remote_state_data = NULL; 2550 2382 2551 list_initialize(&sess->exch_list); 2383 2552 fibril_mutex_initialize(&sess->mutex); … … 2422 2591 sess->arg3 = 0; 2423 2592 2593 fibril_mutex_initialize(&sess->remote_state_mtx); 2594 sess->remote_state_data = NULL; 2595 2424 2596 list_initialize(&sess->exch_list); 2425 2597 fibril_mutex_initialize(&sess->mutex); … … 2429 2601 } 2430 2602 2603 int async_state_change_start(async_exch_t *exch, sysarg_t arg1, sysarg_t arg2, 2604 sysarg_t arg3, async_exch_t *other_exch) 2605 { 2606 return async_req_5_0(exch, IPC_M_STATE_CHANGE_AUTHORIZE, 2607 arg1, arg2, arg3, 0, other_exch->phone); 2608 } 2609 2610 bool async_state_change_receive(ipc_callid_t *callid, sysarg_t *arg1, 2611 sysarg_t *arg2, sysarg_t *arg3) 2612 { 2613 assert(callid); 2614 2615 ipc_call_t call; 2616 *callid = async_get_call(&call); 2617 2618 if (IPC_GET_IMETHOD(call) != IPC_M_STATE_CHANGE_AUTHORIZE) 2619 return false; 2620 2621 if (arg1) 2622 *arg1 = IPC_GET_ARG1(call); 2623 if (arg2) 2624 *arg2 = IPC_GET_ARG2(call); 2625 if (arg3) 2626 *arg3 = IPC_GET_ARG3(call); 2627 2628 return true; 2629 } 2630 2631 int async_state_change_finalize(ipc_callid_t callid, async_exch_t *other_exch) 2632 { 2633 return ipc_answer_1(callid, EOK, other_exch->phone); 2634 } 2635 2636 /** Lock and get session remote state 2637 * 2638 * Lock and get the local replica of the remote state 2639 * in stateful sessions. The call should be paired 2640 * with async_remote_state_release*(). 2641 * 2642 * @param[in] sess Stateful session. 2643 * 2644 * @return Local replica of the remote state. 2645 * 2646 */ 2647 void *async_remote_state_acquire(async_sess_t *sess) 2648 { 2649 fibril_mutex_lock(&sess->remote_state_mtx); 2650 return sess->remote_state_data; 2651 } 2652 2653 /** Update the session remote state 2654 * 2655 * Update the local replica of the remote state 2656 * in stateful sessions. The remote state must 2657 * be already locked. 2658 * 2659 * @param[in] sess Stateful session. 2660 * @param[in] state New local replica of the remote state. 2661 * 2662 */ 2663 void async_remote_state_update(async_sess_t *sess, void *state) 2664 { 2665 assert(fibril_mutex_is_locked(&sess->remote_state_mtx)); 2666 sess->remote_state_data = state; 2667 } 2668 2669 /** Release the session remote state 2670 * 2671 * Unlock the local replica of the remote state 2672 * in stateful sessions. 2673 * 2674 * @param[in] sess Stateful session. 2675 * 2676 */ 2677 void async_remote_state_release(async_sess_t *sess) 2678 { 2679 assert(fibril_mutex_is_locked(&sess->remote_state_mtx)); 2680 2681 fibril_mutex_unlock(&sess->remote_state_mtx); 2682 } 2683 2684 /** Release the session remote state and end an exchange 2685 * 2686 * Unlock the local replica of the remote state 2687 * in stateful sessions. This is convenience function 2688 * which gets the session pointer from the exchange 2689 * and also ends the exchange. 2690 * 2691 * @param[in] exch Stateful session's exchange. 2692 * 2693 */ 2694 void async_remote_state_release_exchange(async_exch_t *exch) 2695 { 2696 if (exch == NULL) 2697 return; 2698 2699 async_sess_t *sess = exch->sess; 2700 assert(fibril_mutex_is_locked(&sess->remote_state_mtx)); 2701 2702 async_exchange_end(exch); 2703 fibril_mutex_unlock(&sess->remote_state_mtx); 2704 } 2705 2431 2706 /** @} 2432 2707 */ -
uspace/lib/c/generic/ddi.c
r867e2555 r925a21e 31 31 */ 32 32 /** @file 33 */ 33 */ 34 34 35 #include <sys/types.h> 36 #include <abi/ddi/arg.h> 35 37 #include <ddi.h> 36 38 #include <libarch/ddi.h> … … 40 42 #include <align.h> 41 43 #include <libarch/config.h> 42 #include <kernel/ddi/ddi_arg.h>43 44 44 45 /** Return unique device number. -
uspace/lib/c/generic/devman.c
r867e2555 r925a21e 1 1 /* 2 2 * Copyright (c) 2007 Josef Cejka 3 * Copyright (c) 20 09Jiri Svoboda3 * Copyright (c) 2011 Jiri Svoboda 4 4 * Copyright (c) 2010 Lenka Trochtova 5 5 * All rights reserved. … … 89 89 if (devman_driver_block_sess == NULL) 90 90 devman_driver_block_sess = 91 service_connect_blocking(EXCHANGE_ SERIALIZE,91 service_connect_blocking(EXCHANGE_PARALLEL, 92 92 SERVICE_DEVMAN, DEVMAN_DRIVER, 0); 93 93 } … … 138 138 if (devman_driver_sess == NULL) 139 139 devman_driver_sess = 140 service_connect(EXCHANGE_ SERIALIZE, SERVICE_DEVMAN,140 service_connect(EXCHANGE_PARALLEL, SERVICE_DEVMAN, 141 141 DEVMAN_DRIVER, 0); 142 142 … … 195 195 196 196 exch = devman_exchange_begin(DEVMAN_DRIVER); 197 async_connect_to_me(exch, 0, 0, 0, NULL, NULL);197 async_connect_to_me(exch, 0, 0, 0, conn, NULL); 198 198 devman_exchange_end(exch); 199 199 … … 271 271 } 272 272 273 int devman_add_device_to_c lass(devman_handle_t devman_handle,274 const char *c lass_name)273 int devman_add_device_to_category(devman_handle_t devman_handle, 274 const char *cat_name) 275 275 { 276 276 async_exch_t *exch = devman_exchange_begin_blocking(DEVMAN_DRIVER); 277 277 278 278 ipc_call_t answer; 279 aid_t req = async_send_1(exch, DEVMAN_ADD_DEVICE_TO_C LASS,279 aid_t req = async_send_1(exch, DEVMAN_ADD_DEVICE_TO_CATEGORY, 280 280 devman_handle, &answer); 281 sysarg_t retval = async_data_write_start(exch, c lass_name,282 str_size(c lass_name));281 sysarg_t retval = async_data_write_start(exch, cat_name, 282 str_size(cat_name)); 283 283 284 284 devman_exchange_end(exch); … … 308 308 } 309 309 310 /** Remove function from device. 311 * 312 * Request devman to remove function owned by this driver task. 313 * @param funh Devman handle of the function 314 * 315 * @return EOK on success or negative error code. 316 */ 317 int devman_remove_function(devman_handle_t funh) 318 { 319 async_exch_t *exch; 320 sysarg_t retval; 321 322 exch = devman_exchange_begin_blocking(DEVMAN_DRIVER); 323 retval = async_req_1_0(exch, DEVMAN_REMOVE_FUNCTION, (sysarg_t) funh); 324 devman_exchange_end(exch); 325 326 return (int) retval; 327 } 328 329 int devman_drv_fun_online(devman_handle_t funh) 330 { 331 async_exch_t *exch = devman_exchange_begin(DEVMAN_DRIVER); 332 if (exch == NULL) 333 return ENOMEM; 334 335 sysarg_t retval = async_req_1_0(exch, DEVMAN_DRV_FUN_ONLINE, funh); 336 337 devman_exchange_end(exch); 338 return (int) retval; 339 } 340 341 int devman_drv_fun_offline(devman_handle_t funh) 342 { 343 async_exch_t *exch = devman_exchange_begin(DEVMAN_DRIVER); 344 if (exch == NULL) 345 return ENOMEM; 346 347 sysarg_t retval = async_req_1_0(exch, DEVMAN_DRV_FUN_OFFLINE, funh); 348 349 devman_exchange_end(exch); 350 return (int) retval; 351 } 352 310 353 async_sess_t *devman_parent_device_connect(exch_mgmt_t mgmt, 311 354 devman_handle_t handle, unsigned int flags) … … 323 366 } 324 367 325 int devman_ device_get_handle(const char *pathname, devman_handle_t *handle,368 int devman_fun_get_handle(const char *pathname, devman_handle_t *handle, 326 369 unsigned int flags) 327 370 { … … 333 376 exch = devman_exchange_begin(DEVMAN_CLIENT); 334 377 if (exch == NULL) 335 return errno;378 return ENOMEM; 336 379 } 337 380 … … 364 407 } 365 408 366 int devman_device_get_handle_by_class(const char *classname,367 const char *devname, devman_handle_t *handle, unsigned int flags)409 static int devman_get_str_internal(sysarg_t method, sysarg_t arg1, char *buf, 410 size_t buf_size) 368 411 { 369 412 async_exch_t *exch; 370 371 if (flags & IPC_FLAG_BLOCKING) 372 exch = devman_exchange_begin_blocking(DEVMAN_CLIENT); 373 else { 374 exch = devman_exchange_begin(DEVMAN_CLIENT); 375 if (exch == NULL) 376 return errno; 377 } 413 ipc_call_t dreply; 414 size_t act_size; 415 sysarg_t dretval; 416 417 exch = devman_exchange_begin_blocking(LOC_PORT_CONSUMER); 378 418 379 419 ipc_call_t answer; 380 aid_t req = async_send_1(exch, DEVMAN_DEVICE_GET_HANDLE_BY_CLASS,381 flags, &answer);382 sysarg_t retval = async_data_write_start(exch, classname,383 str_size(classname));384 385 if (retval != EOK) {386 devman_exchange_end(exch);420 aid_t req = async_send_1(exch, method, arg1, &answer); 421 aid_t dreq = async_data_read(exch, buf, buf_size - 1, &dreply); 422 async_wait_for(dreq, &dretval); 423 424 devman_exchange_end(exch); 425 426 if (dretval != EOK) { 387 427 async_wait_for(req, NULL); 388 return retval; 389 } 390 391 retval = async_data_write_start(exch, devname, 392 str_size(devname)); 393 394 devman_exchange_end(exch); 395 396 if (retval != EOK) { 397 async_wait_for(req, NULL); 398 return retval; 399 } 400 428 return dretval; 429 } 430 431 sysarg_t retval; 401 432 async_wait_for(req, &retval); 402 433 403 if (retval != EOK) { 404 if (handle != NULL) 405 *handle = (devman_handle_t) -1; 406 407 return retval; 408 } 409 410 if (handle != NULL) 411 *handle = (devman_handle_t) IPC_GET_ARG1(answer); 412 413 return retval; 414 } 415 416 int devman_get_device_path(devman_handle_t handle, char *path, size_t path_size) 434 if (retval != EOK) 435 return retval; 436 437 act_size = IPC_GET_ARG2(dreply); 438 assert(act_size <= buf_size - 1); 439 buf[act_size] = '\0'; 440 441 return EOK; 442 } 443 444 int devman_fun_get_path(devman_handle_t handle, char *buf, size_t buf_size) 445 { 446 return devman_get_str_internal(DEVMAN_FUN_GET_PATH, handle, buf, 447 buf_size); 448 } 449 450 int devman_fun_get_name(devman_handle_t handle, char *buf, size_t buf_size) 451 { 452 return devman_get_str_internal(DEVMAN_FUN_GET_NAME, handle, buf, 453 buf_size); 454 } 455 456 int devman_fun_online(devman_handle_t funh) 417 457 { 418 458 async_exch_t *exch = devman_exchange_begin(DEVMAN_CLIENT); 419 459 if (exch == NULL) 420 return errno; 421 460 return ENOMEM; 461 462 sysarg_t retval = async_req_1_0(exch, DEVMAN_FUN_ONLINE, funh); 463 464 devman_exchange_end(exch); 465 return (int) retval; 466 } 467 468 int devman_fun_offline(devman_handle_t funh) 469 { 470 async_exch_t *exch = devman_exchange_begin(DEVMAN_CLIENT); 471 if (exch == NULL) 472 return ENOMEM; 473 474 sysarg_t retval = async_req_1_0(exch, DEVMAN_FUN_OFFLINE, funh); 475 476 devman_exchange_end(exch); 477 return (int) retval; 478 } 479 480 static int devman_get_handles_once(sysarg_t method, sysarg_t arg1, 481 devman_handle_t *handle_buf, size_t buf_size, size_t *act_size) 482 { 483 async_exch_t *exch = devman_exchange_begin_blocking(DEVMAN_CLIENT); 484 422 485 ipc_call_t answer; 423 aid_t req = async_send_1(exch, DEVMAN_DEVICE_GET_DEVICE_PATH, 424 handle, &answer); 425 426 ipc_call_t data_request_call; 427 aid_t data_request = async_data_read(exch, path, path_size, 428 &data_request_call); 429 430 devman_exchange_end(exch); 431 432 if (data_request == 0) { 486 aid_t req = async_send_1(exch, method, arg1, &answer); 487 int rc = async_data_read_start(exch, handle_buf, buf_size); 488 489 devman_exchange_end(exch); 490 491 if (rc != EOK) { 433 492 async_wait_for(req, NULL); 434 return ENOMEM; 435 } 436 437 sysarg_t data_request_rc; 438 async_wait_for(data_request, &data_request_rc); 439 440 sysarg_t opening_request_rc; 441 async_wait_for(req, &opening_request_rc); 442 443 if (data_request_rc != EOK) { 444 /* Prefer the return code of the opening request. */ 445 if (opening_request_rc != EOK) 446 return (int) opening_request_rc; 447 else 448 return (int) data_request_rc; 449 } 450 451 if (opening_request_rc != EOK) 452 return (int) opening_request_rc; 453 454 /* To be on the safe-side. */ 455 path[path_size - 1] = 0; 456 size_t transferred_size = IPC_GET_ARG2(data_request_call); 457 if (transferred_size >= path_size) 458 return ELIMIT; 459 460 /* Terminate the string (trailing 0 not send over IPC). */ 461 path[transferred_size] = 0; 493 return rc; 494 } 495 496 sysarg_t retval; 497 async_wait_for(req, &retval); 498 499 if (retval != EOK) { 500 return retval; 501 } 502 503 *act_size = IPC_GET_ARG1(answer); 462 504 return EOK; 463 505 } 464 506 507 /** Get list of handles. 508 * 509 * Returns an allocated array of handles. 510 * 511 * @param method IPC method 512 * @param arg1 IPC argument 1 513 * @param data Place to store pointer to array of handles 514 * @param count Place to store number of handles 515 * @return EOK on success or negative error code 516 */ 517 static int devman_get_handles_internal(sysarg_t method, sysarg_t arg1, 518 devman_handle_t **data, size_t *count) 519 { 520 devman_handle_t *handles; 521 size_t act_size; 522 size_t alloc_size; 523 int rc; 524 525 *data = NULL; 526 act_size = 0; /* silence warning */ 527 528 rc = devman_get_handles_once(method, arg1, NULL, 0, 529 &act_size); 530 if (rc != EOK) 531 return rc; 532 533 alloc_size = act_size; 534 handles = malloc(alloc_size); 535 if (handles == NULL) 536 return ENOMEM; 537 538 while (true) { 539 rc = devman_get_handles_once(method, arg1, handles, alloc_size, 540 &act_size); 541 if (rc != EOK) 542 return rc; 543 544 if (act_size <= alloc_size) 545 break; 546 547 alloc_size *= 2; 548 free(handles); 549 550 handles = malloc(alloc_size); 551 if (handles == NULL) 552 return ENOMEM; 553 } 554 555 *count = act_size / sizeof(devman_handle_t); 556 *data = handles; 557 return EOK; 558 } 559 560 int devman_fun_get_child(devman_handle_t funh, devman_handle_t *devh) 561 { 562 async_exch_t *exch = devman_exchange_begin(DEVMAN_CLIENT); 563 if (exch == NULL) 564 return ENOMEM; 565 566 sysarg_t retval = async_req_1_1(exch, DEVMAN_FUN_GET_CHILD, 567 funh, devh); 568 569 devman_exchange_end(exch); 570 return (int) retval; 571 } 572 573 int devman_dev_get_functions(devman_handle_t devh, devman_handle_t **funcs, 574 size_t *count) 575 { 576 return devman_get_handles_internal(DEVMAN_DEV_GET_FUNCTIONS, 577 devh, funcs, count); 578 } 579 580 int devman_fun_sid_to_handle(service_id_t sid, devman_handle_t *handle) 581 { 582 async_exch_t *exch = devman_exchange_begin(DEVMAN_CLIENT); 583 if (exch == NULL) 584 return ENOMEM; 585 586 sysarg_t retval = async_req_1_1(exch, DEVMAN_FUN_SID_TO_HANDLE, 587 sid, handle); 588 589 devman_exchange_end(exch); 590 return (int) retval; 591 } 592 465 593 /** @} 466 594 */ -
uspace/lib/c/generic/event.c
r867e2555 r925a21e 39 39 #include <libc.h> 40 40 #include <event.h> 41 #include <kernel/ipc/event_types.h>42 41 43 42 /** Subscribe event notifications. … … 50 49 */ 51 50 int event_subscribe(event_type_t evno, sysarg_t imethod) 51 { 52 return __SYSCALL2(SYS_EVENT_SUBSCRIBE, (sysarg_t) evno, 53 (sysarg_t) imethod); 54 } 55 56 int event_task_subscribe(event_task_type_t evno, sysarg_t imethod) 52 57 { 53 58 return __SYSCALL2(SYS_EVENT_SUBSCRIBE, (sysarg_t) evno, … … 67 72 } 68 73 74 int event_task_unmask(event_task_type_t evno) 75 { 76 return __SYSCALL1(SYS_EVENT_UNMASK, (sysarg_t) evno); 77 } 78 69 79 /** @} 70 80 */ -
uspace/lib/c/generic/fibril.c
r867e2555 r925a21e 41 41 #include <unistd.h> 42 42 #include <stdio.h> 43 #include < arch/barrier.h>43 #include <libarch/barrier.h> 44 44 #include <libarch/faddr.h> 45 45 #include <futex.h> -
uspace/lib/c/generic/io/console.c
r867e2555 r925a21e 87 87 { 88 88 async_exch_t *exch = async_exchange_begin(ctrl->output_sess); 89 async_ msg_0(exch, CONSOLE_CLEAR);89 async_req_0_0(exch, CONSOLE_CLEAR); 90 90 async_exchange_end(exch); 91 91 } … … 103 103 { 104 104 async_exch_t *exch = async_exchange_begin(ctrl->output_sess); 105 async_ msg_1(exch, CONSOLE_SET_STYLE, style);106 async_exchange_end(exch); 107 } 108 109 void console_set_color(console_ctrl_t *ctrl, uint8_t fg_color, uint8_t bg_color,105 async_req_1_0(exch, CONSOLE_SET_STYLE, style); 106 async_exchange_end(exch); 107 } 108 109 void console_set_color(console_ctrl_t *ctrl, uint8_t bgcolor, uint8_t fgcolor, 110 110 uint8_t flags) 111 111 { 112 112 async_exch_t *exch = async_exchange_begin(ctrl->output_sess); 113 async_ msg_3(exch, CONSOLE_SET_COLOR, fg_color, bg_color, flags);114 async_exchange_end(exch); 115 } 116 117 void console_set_rgb_color(console_ctrl_t *ctrl, uint32_t fg_color,118 uint32_t bg_color)119 { 120 async_exch_t *exch = async_exchange_begin(ctrl->output_sess); 121 async_ msg_2(exch, CONSOLE_SET_RGB_COLOR, fg_color, bg_color);113 async_req_3_0(exch, CONSOLE_SET_COLOR, bgcolor, fgcolor, flags); 114 async_exchange_end(exch); 115 } 116 117 void console_set_rgb_color(console_ctrl_t *ctrl, uint32_t bgcolor, 118 uint32_t fgcolor) 119 { 120 async_exch_t *exch = async_exchange_begin(ctrl->output_sess); 121 async_req_2_0(exch, CONSOLE_SET_RGB_COLOR, bgcolor, fgcolor); 122 122 async_exchange_end(exch); 123 123 } … … 126 126 { 127 127 async_exch_t *exch = async_exchange_begin(ctrl->output_sess); 128 async_ msg_1(exch, CONSOLE_CURSOR_VISIBILITY, (show != false));128 async_req_1_0(exch, CONSOLE_CURSOR_VISIBILITY, (show != false)); 129 129 async_exchange_end(exch); 130 130 } … … 151 151 { 152 152 async_exch_t *exch = async_exchange_begin(ctrl->output_sess); 153 async_ msg_2(exch, CONSOLE_GOTO, col, row);153 async_req_2_0(exch, CONSOLE_GOTO, col, row); 154 154 async_exchange_end(exch); 155 155 } -
uspace/lib/c/generic/io/io.c
r867e2555 r925a21e 45 45 #include <vfs/vfs.h> 46 46 #include <vfs/vfs_sess.h> 47 #include <ipc/ devmap.h>47 #include <ipc/loc.h> 48 48 #include <adt/list.h> 49 49 #include "../private/io.h" … … 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 { … … 450 418 451 419 bytes_used = stream->buf_head - stream->buf_tail; 452 if (bytes_used == 0)453 return;454 420 455 421 /* If buffer has prefetched read data, we need to seek back. */ 456 if ( stream->buf_state == _bs_read)422 if (bytes_used > 0 && stream->buf_state == _bs_read) 457 423 lseek(stream->fd, - (ssize_t) bytes_used, SEEK_CUR); 458 424 459 425 /* If buffer has unwritten data, we need to write them out. */ 460 if ( stream->buf_state == _bs_write)426 if (bytes_used > 0 && stream->buf_state == _bs_write) 461 427 (void) _fwrite(stream->buf_tail, 1, bytes_used, stream); 462 428 … … 780 746 } 781 747 782 int fnode(FILE *stream, fdi_node_t *node) 783 { 784 if (stream->fd >= 0) 785 return fd_node(stream->fd, node); 748 int fhandle(FILE *stream, int *handle) 749 { 750 if (stream->fd >= 0) { 751 *handle = stream->fd; 752 return EOK; 753 } 786 754 787 755 return ENOENT; -
uspace/lib/c/generic/io/printf_core.c
r867e2555 r925a21e 74 74 #define PRINT_NUMBER_BUFFER_SIZE (64 + 5) 75 75 76 /** Get signed or unsigned integer argument */ 77 #define PRINTF_GET_INT_ARGUMENT(type, ap, flags) \ 78 ({ \ 79 unsigned type res; \ 80 \ 81 if ((flags) & __PRINTF_FLAG_SIGNED) { \ 82 signed type arg = va_arg((ap), signed type); \ 83 \ 84 if (arg < 0) { \ 85 res = -arg; \ 86 (flags) |= __PRINTF_FLAG_NEGATIVE; \ 87 } else \ 88 res = arg; \ 89 } else \ 90 res = va_arg((ap), unsigned type); \ 91 \ 92 res; \ 93 }) 94 76 95 /** Enumeration of possible arguments types. 77 96 */ … … 206 225 } 207 226 208 return (int) (counter + 1);227 return (int) (counter); 209 228 } 210 229 … … 244 263 } 245 264 246 return (int) (counter + 1);265 return (int) (counter); 247 266 } 248 267 … … 831 850 size_t size; 832 851 uint64_t number; 852 833 853 switch (qualifier) { 834 854 case PrintfQualifierByte: 835 855 size = sizeof(unsigned char); 836 number = (uint64_t) va_arg(ap, unsigned int);856 number = PRINTF_GET_INT_ARGUMENT(int, ap, flags); 837 857 break; 838 858 case PrintfQualifierShort: 839 859 size = sizeof(unsigned short); 840 number = (uint64_t) va_arg(ap, unsigned int);860 number = PRINTF_GET_INT_ARGUMENT(int, ap, flags); 841 861 break; 842 862 case PrintfQualifierInt: 843 863 size = sizeof(unsigned int); 844 number = (uint64_t) va_arg(ap, unsigned int);864 number = PRINTF_GET_INT_ARGUMENT(int, ap, flags); 845 865 break; 846 866 case PrintfQualifierLong: 847 867 size = sizeof(unsigned long); 848 number = (uint64_t) va_arg(ap, unsigned long);868 number = PRINTF_GET_INT_ARGUMENT(long, ap, flags); 849 869 break; 850 870 case PrintfQualifierLongLong: 851 871 size = sizeof(unsigned long long); 852 number = (uint64_t) va_arg(ap, unsigned long long);872 number = PRINTF_GET_INT_ARGUMENT(long long, ap, flags); 853 873 break; 854 874 case PrintfQualifierPointer: … … 865 885 counter = -counter; 866 886 goto out; 867 }868 869 if (flags & __PRINTF_FLAG_SIGNED) {870 if (number & (0x1 << (size * 8 - 1))) {871 flags |= __PRINTF_FLAG_NEGATIVE;872 873 if (size == sizeof(uint64_t)) {874 number = -((int64_t) number);875 } else {876 number = ~number;877 number &=878 ~(0xFFFFFFFFFFFFFFFFll <<879 (size * 8));880 number++;881 }882 }883 887 } 884 888 -
uspace/lib/c/generic/ipc.c
r867e2555 r925a21e 47 47 #include <futex.h> 48 48 #include <fibril.h> 49 #include <macros.h> 49 50 50 51 /** … … 611 612 /** Request callback connection. 612 613 * 613 * The @a task hashand @a phonehash identifiers returned614 * The @a task_id and @a phonehash identifiers returned 614 615 * by the kernel can be used for connection tracking. 615 616 * … … 618 619 * @param arg2 User defined argument. 619 620 * @param arg3 User defined argument. 620 * @param task hash Opaque identifier of the client task.621 * @param task_id Identifier of the client task. 621 622 * @param phonehash Opaque identifier of the phone that will 622 623 * be used for incoming calls. … … 626 627 */ 627 628 int ipc_connect_to_me(int phoneid, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, 628 sysarg_t *taskhash, sysarg_t *phonehash) 629 { 630 return ipc_call_sync_3_5(phoneid, IPC_M_CONNECT_TO_ME, arg1, arg2, 631 arg3, NULL, NULL, NULL, taskhash, phonehash); 629 task_id_t *task_id, sysarg_t *phonehash) 630 { 631 ipc_call_t data; 632 int rc = __SYSCALL6(SYS_IPC_CALL_SYNC_FAST, phoneid, 633 IPC_M_CONNECT_TO_ME, arg1, arg2, arg3, (sysarg_t) &data); 634 if (rc == EOK) { 635 *task_id = data.in_task_id; 636 *phonehash = IPC_GET_ARG5(data); 637 } 638 return rc; 632 639 } 633 640 -
uspace/lib/c/generic/libc.c
r867e2555 r925a21e 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
r867e2555 r925a21e 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 ipc_call_t answer; 268 aid_t req = async_send_1(exch, LOADER_SET_FILES, i, &answer); 269 270 sysarg_t rc = EOK; 271 272 for (i = 0; files[i]; i++) { 273 rc = async_state_change_start(exch, VFS_PASS_HANDLE, *files[i], 274 0, vfs_exch); 275 if (rc != EOK) 276 break; 277 } 278 279 vfs_exchange_end(vfs_exch); 280 async_exchange_end(exch); 281 292 282 if (rc != EOK) { 293 283 async_wait_for(req, NULL); -
uspace/lib/c/generic/malloc.c
r867e2555 r925a21e 873 873 void free(const void *addr) 874 874 { 875 if (addr == NULL) 876 return; 877 875 878 futex_down(&malloc_futex); 876 879 -
uspace/lib/c/generic/ns.c
r867e2555 r925a21e 52 52 { 53 53 async_exch_t *exch = async_exchange_begin(session_ns); 54 if (!exch) 55 return NULL; 54 56 async_sess_t *sess = 55 57 async_connect_me_to(mgmt, exch, service, arg2, arg3); 56 58 async_exchange_end(exch); 59 60 if (!sess) 61 return NULL; 62 63 /* 64 * FIXME Ugly hack to work around limitation of implementing 65 * parallel exchanges using multiple connections. Shift out 66 * first argument for non-initial connections. 67 */ 68 async_sess_args_set(sess, arg2, arg3, 0); 57 69 58 70 return sess; … … 66 78 async_connect_me_to_blocking(mgmt, exch, service, arg2, arg3); 67 79 async_exchange_end(exch); 80 81 /* 82 * FIXME Ugly hack to work around limitation of implementing 83 * parallel exchanges using multiple connections. Shift out 84 * first argument for non-initial connections. 85 */ 86 async_sess_args_set(sess, arg2, arg3, 0); 68 87 69 88 return sess; -
uspace/lib/c/generic/private/async.h
r867e2555 r925a21e 36 36 #define LIBC_PRIVATE_ASYNC_H_ 37 37 38 #include <async.h> 38 39 #include <adt/list.h> 39 40 #include <fibril.h> 41 #include <fibril_synch.h> 40 42 #include <sys/time.h> 41 43 #include <bool.h> … … 79 81 } awaiter_t; 80 82 81 /** Message data */82 typedef struct {83 awaiter_t wdata;84 85 /** If reply was received. */86 bool done;87 88 /** Pointer to where the answer data is stored. */89 ipc_call_t *dataptr;90 91 sysarg_t retval;92 } amsg_t;93 94 83 extern void __async_init(void); 95 84 extern void async_insert_timeout(awaiter_t *); -
uspace/lib/c/generic/private/io.h
r867e2555 r925a21e 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/private/thread.h
r867e2555 r925a21e 36 36 #define LIBC_PRIVATE_THREAD_H_ 37 37 38 #include < kernel/proc/uarg.h>38 #include <abi/proc/uarg.h> 39 39 40 40 extern void __thread_entry(void); -
uspace/lib/c/generic/str.c
r867e2555 r925a21e 2 2 * Copyright (c) 2005 Martin Decky 3 3 * Copyright (c) 2008 Jiri Svoboda 4 * Copyright (c) 2011 Martin Sucha 5 * Copyright (c) 2011 Oleg Romanenko 4 6 * All rights reserved. 5 7 * … … 549 551 * 550 552 * Common legacy text encoding in hardware is 7-bit ASCII fitted into 551 * a fixed-wi th byte buffer (bit 7 always zero), right-padded with spaces553 * a fixed-width byte buffer (bit 7 always zero), right-padded with spaces 552 554 * (ASCII 0x20). Convert space-padded ascii to string representation. 553 555 * … … 639 641 } 640 642 643 /** Convert UTF16 string to string. 644 * 645 * Convert utf16 string @a src to string. The output is written to the buffer 646 * specified by @a dest and @a size. @a size must be non-zero and the string 647 * written will always be well-formed. Surrogate pairs also supported. 648 * 649 * @param dest Destination buffer. 650 * @param size Size of the destination buffer. 651 * @param src Source utf16 string. 652 * 653 * @return EOK, if success, negative otherwise. 654 */ 655 int utf16_to_str(char *dest, size_t size, const uint16_t *src) 656 { 657 size_t idx = 0, dest_off = 0; 658 wchar_t ch; 659 int rc = EOK; 660 661 /* There must be space for a null terminator in the buffer. */ 662 assert(size > 0); 663 664 while (src[idx]) { 665 if ((src[idx] & 0xfc00) == 0xd800) { 666 if (src[idx + 1] && (src[idx + 1] & 0xfc00) == 0xdc00) { 667 ch = 0x10000; 668 ch += (src[idx] & 0x03FF) << 10; 669 ch += (src[idx + 1] & 0x03FF); 670 idx += 2; 671 } 672 else 673 break; 674 } else { 675 ch = src[idx]; 676 idx++; 677 } 678 rc = chr_encode(ch, dest, &dest_off, size - 1); 679 if (rc != EOK) 680 break; 681 } 682 dest[dest_off] = '\0'; 683 return rc; 684 } 685 686 int str_to_utf16(uint16_t *dest, size_t size, const char *src) 687 { 688 int rc = EOK; 689 size_t offset = 0; 690 size_t idx = 0; 691 wchar_t c; 692 693 assert(size > 0); 694 695 while ((c = str_decode(src, &offset, STR_NO_LIMIT)) != 0) { 696 if (c > 0x10000) { 697 if (idx + 2 >= size - 1) { 698 rc = EOVERFLOW; 699 break; 700 } 701 c = (c - 0x10000); 702 dest[idx] = 0xD800 | (c >> 10); 703 dest[idx + 1] = 0xDC00 | (c & 0x3FF); 704 idx++; 705 } else { 706 dest[idx] = c; 707 } 708 709 idx++; 710 if (idx >= size - 1) { 711 rc = EOVERFLOW; 712 break; 713 } 714 } 715 716 dest[idx] = '\0'; 717 return rc; 718 } 719 720 641 721 /** Convert wide string to new string. 642 722 * … … 718 798 719 799 dest[dlen - 1] = '\0'; 800 } 801 802 /** Convert string to wide string. 803 * 804 * Convert string @a src to wide string. A new wide NULL-terminated 805 * string will be allocated on the heap. 806 * 807 * @param src Source string. 808 */ 809 wchar_t *str_to_awstr(const char *str) 810 { 811 size_t len = str_length(str); 812 813 wchar_t *wstr = calloc(len+1, sizeof(wchar_t)); 814 if (wstr == NULL) 815 return NULL; 816 817 str_to_wstr(wstr, len + 1, str); 818 return wstr; 720 819 } 721 820 … … 1016 1115 return dest; 1017 1116 } 1018 1019 1117 1020 1118 /** Convert initial part of string to unsigned long according to given base. … … 1193 1291 } 1194 1292 1293 /** Convert string to uint8_t. 1294 * 1295 * @param nptr Pointer to string. 1296 * @param endptr If not NULL, pointer to the first invalid character 1297 * is stored here. 1298 * @param base Zero or number between 2 and 36 inclusive. 1299 * @param strict Do not allow any trailing characters. 1300 * @param result Result of the conversion. 1301 * 1302 * @return EOK if conversion was successful. 1303 * 1304 */ 1305 int str_uint8_t(const char *nptr, char **endptr, unsigned int base, 1306 bool strict, uint8_t *result) 1307 { 1308 assert(result != NULL); 1309 1310 bool neg; 1311 char *lendptr; 1312 uint64_t res; 1313 int ret = str_uint(nptr, &lendptr, base, &neg, &res); 1314 1315 if (endptr != NULL) 1316 *endptr = (char *) lendptr; 1317 1318 if (ret != EOK) 1319 return ret; 1320 1321 /* Do not allow negative values */ 1322 if (neg) 1323 return EINVAL; 1324 1325 /* Check whether we are at the end of 1326 the string in strict mode */ 1327 if ((strict) && (*lendptr != 0)) 1328 return EINVAL; 1329 1330 /* Check for overflow */ 1331 uint8_t _res = (uint8_t) res; 1332 if (_res != res) 1333 return EOVERFLOW; 1334 1335 *result = _res; 1336 1337 return EOK; 1338 } 1339 1340 /** Convert string to uint16_t. 1341 * 1342 * @param nptr Pointer to string. 1343 * @param endptr If not NULL, pointer to the first invalid character 1344 * is stored here. 1345 * @param base Zero or number between 2 and 36 inclusive. 1346 * @param strict Do not allow any trailing characters. 1347 * @param result Result of the conversion. 1348 * 1349 * @return EOK if conversion was successful. 1350 * 1351 */ 1352 int str_uint16_t(const char *nptr, char **endptr, unsigned int base, 1353 bool strict, uint16_t *result) 1354 { 1355 assert(result != NULL); 1356 1357 bool neg; 1358 char *lendptr; 1359 uint64_t res; 1360 int ret = str_uint(nptr, &lendptr, base, &neg, &res); 1361 1362 if (endptr != NULL) 1363 *endptr = (char *) lendptr; 1364 1365 if (ret != EOK) 1366 return ret; 1367 1368 /* Do not allow negative values */ 1369 if (neg) 1370 return EINVAL; 1371 1372 /* Check whether we are at the end of 1373 the string in strict mode */ 1374 if ((strict) && (*lendptr != 0)) 1375 return EINVAL; 1376 1377 /* Check for overflow */ 1378 uint16_t _res = (uint16_t) res; 1379 if (_res != res) 1380 return EOVERFLOW; 1381 1382 *result = _res; 1383 1384 return EOK; 1385 } 1386 1387 /** Convert string to uint32_t. 1388 * 1389 * @param nptr Pointer to string. 1390 * @param endptr If not NULL, pointer to the first invalid character 1391 * is stored here. 1392 * @param base Zero or number between 2 and 36 inclusive. 1393 * @param strict Do not allow any trailing characters. 1394 * @param result Result of the conversion. 1395 * 1396 * @return EOK if conversion was successful. 1397 * 1398 */ 1399 int str_uint32_t(const char *nptr, char **endptr, unsigned int base, 1400 bool strict, uint32_t *result) 1401 { 1402 assert(result != NULL); 1403 1404 bool neg; 1405 char *lendptr; 1406 uint64_t res; 1407 int ret = str_uint(nptr, &lendptr, base, &neg, &res); 1408 1409 if (endptr != NULL) 1410 *endptr = (char *) lendptr; 1411 1412 if (ret != EOK) 1413 return ret; 1414 1415 /* Do not allow negative values */ 1416 if (neg) 1417 return EINVAL; 1418 1419 /* Check whether we are at the end of 1420 the string in strict mode */ 1421 if ((strict) && (*lendptr != 0)) 1422 return EINVAL; 1423 1424 /* Check for overflow */ 1425 uint32_t _res = (uint32_t) res; 1426 if (_res != res) 1427 return EOVERFLOW; 1428 1429 *result = _res; 1430 1431 return EOK; 1432 } 1433 1195 1434 /** Convert string to uint64_t. 1196 1435 * -
uspace/lib/c/generic/sysinfo.c
r867e2555 r925a21e 47 47 * 48 48 */ 49 sysinfo_item_ tag_t sysinfo_get_tag(const char *path)49 sysinfo_item_val_type_t sysinfo_get_val_type(const char *path) 50 50 { 51 return (sysinfo_item_ tag_t) __SYSCALL2(SYS_SYSINFO_GET_TAG,51 return (sysinfo_item_val_type_t) __SYSCALL2(SYS_SYSINFO_GET_VAL_TYPE, 52 52 (sysarg_t) path, (sysarg_t) str_size(path)); 53 53 } -
uspace/lib/c/generic/task.c
r867e2555 r925a21e 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/thread.c
r867e2555 r925a21e 37 37 #include <stdlib.h> 38 38 #include <libarch/faddr.h> 39 #include < kernel/proc/uarg.h>39 #include <abi/proc/uarg.h> 40 40 #include <fibril.h> 41 41 #include <str.h> -
uspace/lib/c/generic/time.c
r867e2555 r925a21e 36 36 #include <time.h> 37 37 #include <bool.h> 38 #include < arch/barrier.h>38 #include <libarch/barrier.h> 39 39 #include <macros.h> 40 40 #include <errno.h> -
uspace/lib/c/generic/udebug.c
r867e2555 r925a21e 35 35 #include <udebug.h> 36 36 #include <sys/types.h> 37 #include < kernel/ipc/ipc_methods.h>37 #include <abi/ipc/methods.h> 38 38 #include <async.h> 39 39 -
uspace/lib/c/generic/vfs/vfs.c
r867e2555 r925a21e 51 51 #include <assert.h> 52 52 #include <str.h> 53 #include < devmap.h>53 #include <loc.h> 54 54 #include <ipc/vfs.h> 55 #include <ipc/ devmap.h>55 #include <ipc/loc.h> 56 56 57 57 static FIBRIL_MUTEX_INITIALIZE(vfs_mutex); … … 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); … … 142 142 } 143 143 144 int mount(const char *fs_name, const char *mp, const char *fq dn,145 const char *opts, unsigned int flags )144 int mount(const char *fs_name, const char *mp, const char *fqsn, 145 const char *opts, unsigned int flags, unsigned int instance) 146 146 { 147 147 int null_id = -1; 148 char null[ DEVMAP_NAME_MAXLEN];149 150 if (str_cmp(fq dn, "") == 0) {148 char null[LOC_NAME_MAXLEN]; 149 150 if (str_cmp(fqsn, "") == 0) { 151 151 /* No device specified, create a fresh 152 152 null/%d device instead */ 153 null_id = devmap_null_create();153 null_id = loc_null_create(); 154 154 155 155 if (null_id == -1) 156 156 return ENOMEM; 157 157 158 snprintf(null, DEVMAP_NAME_MAXLEN, "null/%d", null_id);159 fq dn = null;160 } 161 162 devmap_handle_t devmap_handle;163 int res = devmap_device_get_handle(fqdn, &devmap_handle, flags);158 snprintf(null, LOC_NAME_MAXLEN, "null/%d", null_id); 159 fqsn = null; 160 } 161 162 service_id_t service_id; 163 int res = loc_service_get_id(fqsn, &service_id, flags); 164 164 if (res != EOK) { 165 165 if (null_id != -1) 166 devmap_null_destroy(null_id);166 loc_null_destroy(null_id); 167 167 168 168 return res; … … 173 173 if (!mpa) { 174 174 if (null_id != -1) 175 devmap_null_destroy(null_id);175 loc_null_destroy(null_id); 176 176 177 177 return ENOMEM; … … 181 181 182 182 sysarg_t rc_orig; 183 aid_t req = async_send_2(exch, VFS_IN_MOUNT, devmap_handle, flags, NULL); 183 aid_t req = async_send_3(exch, VFS_IN_MOUNT, service_id, flags, 184 instance, NULL); 184 185 sysarg_t rc = async_data_write_start(exch, (void *) mpa, mpa_size); 185 186 if (rc != EOK) { … … 189 190 190 191 if (null_id != -1) 191 devmap_null_destroy(null_id);192 loc_null_destroy(null_id); 192 193 193 194 if (rc_orig == EOK) … … 204 205 205 206 if (null_id != -1) 206 devmap_null_destroy(null_id);207 loc_null_destroy(null_id); 207 208 208 209 if (rc_orig == EOK) … … 219 220 220 221 if (null_id != -1) 221 devmap_null_destroy(null_id);222 loc_null_destroy(null_id); 222 223 223 224 if (rc_orig == EOK) … … 235 236 236 237 if (null_id != -1) 237 devmap_null_destroy(null_id);238 loc_null_destroy(null_id); 238 239 239 240 if (rc_orig == EOK) … … 248 249 249 250 if ((rc != EOK) && (null_id != -1)) 250 devmap_null_destroy(null_id);251 loc_null_destroy(null_id); 251 252 252 253 return (int) rc; … … 327 328 328 329 return ret; 329 }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->devmap_handle, 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 330 } 349 331 … … 673 655 async_exch_t *exch = vfs_exchange_begin(); 674 656 675 req = async_send_ 0(exch, VFS_IN_UNLINK, NULL);657 req = async_send_1(exch, VFS_IN_UNLINK, lflag, NULL); 676 658 rc = async_data_write_start(exch, pa, pa_size); 677 659 if (rc != EOK) { … … 811 793 } 812 794 813 if (!stat. device) {795 if (!stat.service) { 814 796 errno = ENOENT; 815 797 return NULL; 816 798 } 817 799 818 return devmap_device_connect(mgmt, stat.device, 0); 819 } 820 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->devmap_handle = stat.devmap_handle; 829 node->index = stat.index; 830 } 831 832 return rc; 800 return loc_service_connect(mgmt, stat.service, 0); 833 801 } 834 802 … … 848 816 } 849 817 818 int fd_wait(void) 819 { 820 async_exch_t *exch = vfs_exchange_begin(); 821 822 sysarg_t ret; 823 sysarg_t rc = async_req_0_1(exch, VFS_IN_WAIT_HANDLE, &ret); 824 825 vfs_exchange_end(exch); 826 827 if (rc == EOK) 828 return (int) ret; 829 830 return (int) rc; 831 } 832 850 833 /** @} 851 834 */
Note:
See TracChangeset
for help on using the changeset viewer.
