Changeset 8b5690f in mainline for uspace/lib/c
- Timestamp:
- 2011-02-03T05:11:01Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ba38f72c
- Parents:
- 22027b6e (diff), 86d7bfa (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:
-
- 2 added
- 88 edited
- 6 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/Makefile
r22027b6e r8b5690f 83 83 generic/io/console.c \ 84 84 generic/io/screenbuffer.c \ 85 generic/ipc/ns.c \ 85 86 generic/malloc.c \ 86 87 generic/sysinfo.c \ … … 96 97 generic/adt/char_map.c \ 97 98 generic/time.c \ 98 generic/err.c \99 99 generic/stdlib.c \ 100 100 generic/mman.c \ -
uspace/lib/c/arch/abs32le/src/entry.c
r22027b6e r8b5690f 30 30 */ 31 31 32 #include <libc.h>33 32 #include <unistd.h> 34 33 #include <libarch/entry.h> 34 #include "../../../generic/private/libc.h" 35 35 36 36 void __entry(void) 37 37 { 38 38 __main(NULL); 39 __exit();40 39 } 41 40 -
uspace/lib/c/arch/abs32le/src/thread_entry.c
r22027b6e r8b5690f 31 31 32 32 #include <unistd.h> 33 #include <thread.h>33 #include "../../../generic/private/thread.h" 34 34 35 35 void __thread_entry(void) -
uspace/lib/c/arch/amd64/_link.ld.in
r22027b6e r8b5690f 5 5 text PT_LOAD FLAGS(5); 6 6 data PT_LOAD FLAGS(6); 7 debug PT_NOTE; 7 8 } 8 9 … … 13 14 *(.init); 14 15 } :text 16 15 17 .text : { 16 18 *(.text); 17 19 *(.rodata*); 18 20 } :text 19 21 20 22 . = . + 0x1000; 21 23 22 24 .data : { 23 25 *(.data); 24 26 } :data 27 25 28 .tdata : { 26 29 _tdata_start = .; … … 31 34 _tbss_end = .; 32 35 } :data 36 33 37 _tls_alignment = ALIGNOF(.tdata); 38 34 39 .bss : { 35 40 *(COMMON); 36 41 *(.bss); 37 42 } :data 38 43 39 44 . = ALIGN(0x1000); 40 45 _heap = .; 46 47 #ifdef CONFIG_LINE_DEBUG 48 .comment 0 : { *(.comment); } :debug 49 .debug_abbrev 0 : { *(.debug_abbrev); } :debug 50 .debug_aranges 0 : { *(.debug_aranges); } :debug 51 .debug_info 0 : { *(.debug_info); } :debug 52 .debug_line 0 : { *(.debug_line); } :debug 53 .debug_loc 0 : { *(.debug_loc); } :debug 54 .debug_pubnames 0 : { *(.debug_pubnames); } :debug 55 .debug_pubtypes 0 : { *(.debug_pubtypes); } :debug 56 .debug_ranges 0 : { *(.debug_ranges); } :debug 57 .debug_str 0 : { *(.debug_str); } :debug 58 #endif 41 59 42 60 /DISCARD/ : { -
uspace/lib/c/arch/amd64/src/entry.s
r22027b6e r8b5690f 47 47 # Pass PCB pointer to __main (no operation) 48 48 call __main 49 50 call __exit -
uspace/lib/c/arch/arm32/src/entry.s
r22027b6e r8b5690f 42 42 ldr r0, =ras_page 43 43 str r2, [r0] 44 44 45 45 # 46 46 # Create the first stack frame. … … 50 50 push {fp, ip, lr, pc} 51 51 sub fp, ip, #4 52 52 53 53 # Pass pcb_ptr to __main as the first argument (in r0) 54 54 mov r0, r1 55 55 bl __main 56 57 bl __exit58 56 59 57 .data … … 62 60 ras_page: 63 61 .long 0 64 -
uspace/lib/c/arch/ia32/_link.ld.in
r22027b6e r8b5690f 5 5 text PT_LOAD FLAGS(5); 6 6 data PT_LOAD FLAGS(6); 7 debug PT_NOTE; 7 8 } 8 9 … … 43 44 44 45 . = ALIGN(0x1000); 46 _heap = .; 45 47 46 _heap = .; 48 #ifdef CONFIG_LINE_DEBUG 49 .comment 0 : { *(.comment); } :debug 50 .debug_abbrev 0 : { *(.debug_abbrev); } :debug 51 .debug_aranges 0 : { *(.debug_aranges); } :debug 52 .debug_info 0 : { *(.debug_info); } :debug 53 .debug_line 0 : { *(.debug_line); } :debug 54 .debug_loc 0 : { *(.debug_loc); } :debug 55 .debug_pubnames 0 : { *(.debug_pubnames); } :debug 56 .debug_pubtypes 0 : { *(.debug_pubtypes); } :debug 57 .debug_ranges 0 : { *(.debug_ranges); } :debug 58 .debug_str 0 : { *(.debug_str); } :debug 59 #endif 47 60 48 61 /DISCARD/ : { -
uspace/lib/c/arch/ia32/src/entry.s
r22027b6e r8b5690f 46 46 mov %ax, %fs 47 47 # Do not set %gs, it contains descriptor that can see TLS 48 48 49 49 # Detect the mechanism used for making syscalls 50 50 movl $(INTEL_CPUID_STANDARD), %eax … … 58 58 # Create the first stack frame. 59 59 # 60 pushl $0 60 pushl $0 61 61 movl %esp, %ebp 62 62 63 63 # Pass the PCB pointer to __main as the first argument 64 64 pushl %edi 65 65 call __main 66 67 call __exit -
uspace/lib/c/arch/ia64/src/entry.s
r22027b6e r8b5690f 40 40 alloc loc0 = ar.pfs, 0, 1, 2, 0 41 41 movl gp = _gp 42 42 43 43 # Pass PCB pointer as the first argument to __main 44 44 mov out0 = r2 45 45 br.call.sptk.many b0 = __main 46 0:47 br.call.sptk.many b0 = __exit -
uspace/lib/c/arch/mips32/src/entry.s
r22027b6e r8b5690f 56 56 jal __main 57 57 nop 58 59 jal __exit60 nop61 58 .end 62 59 -
uspace/lib/c/arch/ppc32/src/entry.s
r22027b6e r8b5690f 44 44 stw %r3, 0(%r1) 45 45 stwu %r1, -16(%r1) 46 46 47 47 # Pass the PCB pointer to __main() as the first argument. 48 48 # The first argument is passed in r3. 49 49 mr %r3, %r6 50 50 bl __main 51 52 bl __exit -
uspace/lib/c/arch/sparc64/src/entry.s
r22027b6e r8b5690f 45 45 flushw 46 46 add %g0, -0x7ff, %fp 47 47 48 48 # Pass pcb_ptr as the first argument to __main() 49 49 mov %i1, %o0 … … 51 51 call __main 52 52 or %l7, %lo(_gp), %l7 53 54 call __exit55 nop -
uspace/lib/c/generic/async.c
r22027b6e r8b5690f 43 43 * framework will automatically take care of most synchronization problems. 44 44 * 45 * Default semantics:46 * - async_send_*(): Send asynchronously. If the kernel refuses to send47 * more messages, [ try to get responses from kernel, if48 * nothing found, might try synchronous ]49 *50 45 * Example of use (pseudo C): 51 46 * … … 58 53 * int fibril1(void *arg) 59 54 * { 60 * conn = ipc_connect_me_to();55 * conn = async_connect_me_to(); 61 56 * c1 = async_send(conn); 62 57 * c2 = async_send(conn); … … 77 72 * { 78 73 * if (want_refuse) { 79 * ipc_answer_0(icallid, ELIMIT);74 * async_answer_0(icallid, ELIMIT); 80 75 * return; 81 76 * } 82 * ipc_answer_0(icallid, EOK);77 * async_answer_0(icallid, EOK); 83 78 * 84 79 * callid = async_get_call(&call); 85 80 * somehow_handle_the_call(callid, call); 86 * ipc_answer_2(callid, 1, 2, 3);81 * async_answer_2(callid, 1, 2, 3); 87 82 * 88 83 * callid = async_get_call(&call); … … 92 87 */ 93 88 89 #define LIBC_ASYNC_C_ 90 #include <ipc/ipc.h> 91 #include <async.h> 92 #undef LIBC_ASYNC_C_ 93 94 94 #include <futex.h> 95 #include <async.h>96 #include <async_priv.h>97 95 #include <fibril.h> 98 96 #include <stdio.h> 99 97 #include <adt/hash_table.h> 100 98 #include <adt/list.h> 101 #include <ipc/ipc.h>102 99 #include <assert.h> 103 100 #include <errno.h> … … 105 102 #include <arch/barrier.h> 106 103 #include <bool.h> 104 #include "private/async.h" 107 105 108 106 atomic_t async_futex = FUTEX_INITIALIZER; … … 124 122 125 123 /** 126 * Structures of this type are used to group information about a call and a127 * message queue link.124 * Structures of this type are used to group information about 125 * a call and about a message queue link. 128 126 */ 129 127 typedef struct { … … 134 132 135 133 typedef struct { 134 sysarg_t in_task_hash; 135 link_t link; 136 int refcnt; 137 void *data; 138 } client_t; 139 140 typedef struct { 136 141 awaiter_t wdata; 137 142 … … 139 144 link_t link; 140 145 146 /** Incoming client task hash. */ 147 sysarg_t in_task_hash; 141 148 /** Incoming phone hash. */ 142 149 sysarg_t in_phone_hash; 150 151 /** Link to the client tracking structure. */ 152 client_t *client; 143 153 144 154 /** Messages that should be delivered to this fibril. */ … … 158 168 159 169 /** Identifier of the incoming connection handled by the current fibril. */ 160 fibril_local connection_t *FIBRIL_connection; 161 162 static void default_client_connection(ipc_callid_t callid, ipc_call_t *call); 163 static void default_interrupt_received(ipc_callid_t callid, ipc_call_t *call); 170 static fibril_local connection_t *FIBRIL_connection; 171 172 static void *default_client_data_constructor(void) 173 { 174 return NULL; 175 } 176 177 static void default_client_data_destructor(void *data) 178 { 179 } 180 181 static async_client_data_ctor_t async_client_data_create = 182 default_client_data_constructor; 183 static async_client_data_dtor_t async_client_data_destroy = 184 default_client_data_destructor; 185 186 void async_set_client_data_constructor(async_client_data_ctor_t ctor) 187 { 188 async_client_data_create = ctor; 189 } 190 191 void async_set_client_data_destructor(async_client_data_dtor_t dtor) 192 { 193 async_client_data_destroy = dtor; 194 } 195 196 void *async_client_data_get(void) 197 { 198 assert(FIBRIL_connection); 199 return FIBRIL_connection->client->data; 200 } 201 202 /** Default fibril function that gets called to handle new connection. 203 * 204 * This function is defined as a weak symbol - to be redefined in user code. 205 * 206 * @param callid Hash of the incoming call. 207 * @param call Data of the incoming call. 208 * 209 */ 210 static void default_client_connection(ipc_callid_t callid, ipc_call_t *call) 211 { 212 ipc_answer_0(callid, ENOENT); 213 } 164 214 165 215 /** … … 167 217 */ 168 218 static async_client_conn_t client_connection = default_client_connection; 219 220 /** Default fibril function that gets called to handle interrupt notifications. 221 * 222 * This function is defined as a weak symbol - to be redefined in user code. 223 * 224 * @param callid Hash of the incoming call. 225 * @param call Data of the incoming call. 226 * 227 */ 228 static void default_interrupt_received(ipc_callid_t callid, ipc_call_t *call) 229 { 230 } 169 231 170 232 /** … … 174 236 static async_client_conn_t interrupt_received = default_interrupt_received; 175 237 238 static hash_table_t client_hash_table; 176 239 static hash_table_t conn_hash_table; 177 240 static LIST_INITIALIZE(timeout_list); 178 241 179 #define CONN_HASH_TABLE_CHAINS 32 242 #define CLIENT_HASH_TABLE_BUCKETS 32 243 #define CONN_HASH_TABLE_BUCKETS 32 244 245 static hash_index_t client_hash(unsigned long key[]) 246 { 247 assert(key); 248 return (((key[0]) >> 4) % CLIENT_HASH_TABLE_BUCKETS); 249 } 250 251 static int client_compare(unsigned long key[], hash_count_t keys, link_t *item) 252 { 253 client_t *client = hash_table_get_instance(item, client_t, link); 254 return (key[0] == client->in_task_hash); 255 } 256 257 static void client_remove(link_t *item) 258 { 259 } 260 261 /** Operations for the client hash table. */ 262 static hash_table_operations_t client_hash_table_ops = { 263 .hash = client_hash, 264 .compare = client_compare, 265 .remove_callback = client_remove 266 }; 180 267 181 268 /** Compute hash into the connection hash table based on the source phone hash. … … 186 273 * 187 274 */ 188 static hash_index_t conn_hash(unsigned long *key)275 static hash_index_t conn_hash(unsigned long key[]) 189 276 { 190 277 assert(key); 191 return ((( *key) >> 4) % CONN_HASH_TABLE_CHAINS);278 return (((key[0]) >> 4) % CONN_HASH_TABLE_BUCKETS); 192 279 } 193 280 … … 203 290 static int conn_compare(unsigned long key[], hash_count_t keys, link_t *item) 204 291 { 205 connection_t * hs= hash_table_get_instance(item, connection_t, link);206 return (key[0] == hs->in_phone_hash);292 connection_t *conn = hash_table_get_instance(item, connection_t, link); 293 return (key[0] == conn->in_phone_hash); 207 294 } 208 295 … … 219 306 free(hash_table_get_instance(item, connection_t, link)); 220 307 } 221 222 308 223 309 /** Operations for the connection hash table. */ … … 240 326 link_t *tmp = timeout_list.next; 241 327 while (tmp != &timeout_list) { 242 awaiter_t *cur ;243 244 cur = list_get_instance(tmp, awaiter_t, to_event.link);328 awaiter_t *cur 329 = list_get_instance(tmp, awaiter_t, to_event.link); 330 245 331 if (tv_gteq(&cur->to_event.expires, &wd->to_event.expires)) 246 332 break; 333 247 334 tmp = tmp->next; 248 335 } … … 261 348 * 262 349 * @return False if the call doesn't match any connection. 263 * 350 * @return True if the call was passed to the respective connection fibril. 264 351 * 265 352 */ … … 352 439 353 440 fid_t fid = fibril_create(notification_fibril, msg); 441 if (fid == 0) { 442 free(msg); 443 futex_up(&async_futex); 444 return false; 445 } 446 354 447 fibril_add_ready(fid); 355 448 … … 398 491 * the first IPC_M_PHONE_HUNGUP call and continues to 399 492 * call async_get_call_timeout(). Repeat 400 * IPC_M_PHONE_HUNGUP until the caller notices. 493 * IPC_M_PHONE_HUNGUP until the caller notices. 401 494 */ 402 495 memset(call, 0, sizeof(ipc_call_t)); … … 405 498 return conn->close_callid; 406 499 } 407 500 408 501 if (usecs) 409 502 async_insert_timeout(&conn->wdata); … … 443 536 } 444 537 445 /** Default fibril function that gets called to handle new connection.446 *447 * This function is defined as a weak symbol - to be redefined in user code.448 *449 * @param callid Hash of the incoming call.450 * @param call Data of the incoming call.451 *452 */453 static void default_client_connection(ipc_callid_t callid, ipc_call_t *call)454 {455 ipc_answer_0(callid, ENOENT);456 }457 458 /** Default fibril function that gets called to handle interrupt notifications.459 *460 * This function is defined as a weak symbol - to be redefined in user code.461 *462 * @param callid Hash of the incoming call.463 * @param call Data of the incoming call.464 *465 */466 static void default_interrupt_received(ipc_callid_t callid, ipc_call_t *call)467 {468 }469 470 538 /** Wrapper for client connection fibril. 471 539 * … … 481 549 { 482 550 /* 483 * Setup fibril-local connection pointer and call client_connection(). 484 * 551 * Setup fibril-local connection pointer. 485 552 */ 486 553 FIBRIL_connection = (connection_t *) arg; 554 555 futex_down(&async_futex); 556 557 /* 558 * Add our reference for the current connection in the client task 559 * tracking structure. If this is the first reference, create and 560 * hash in a new tracking structure. 561 */ 562 563 unsigned long key = FIBRIL_connection->in_task_hash; 564 link_t *lnk = hash_table_find(&client_hash_table, &key); 565 566 client_t *client; 567 568 if (lnk) { 569 client = hash_table_get_instance(lnk, client_t, link); 570 client->refcnt++; 571 } else { 572 client = malloc(sizeof(client_t)); 573 if (!client) { 574 ipc_answer_0(FIBRIL_connection->callid, ENOMEM); 575 futex_up(&async_futex); 576 return 0; 577 } 578 579 client->in_task_hash = FIBRIL_connection->in_task_hash; 580 581 async_serialize_start(); 582 client->data = async_client_data_create(); 583 async_serialize_end(); 584 585 client->refcnt = 1; 586 hash_table_insert(&client_hash_table, &key, &client->link); 587 } 588 589 futex_up(&async_futex); 590 591 FIBRIL_connection->client = client; 592 593 /* 594 * Call the connection handler function. 595 */ 487 596 FIBRIL_connection->cfibril(FIBRIL_connection->callid, 488 597 &FIBRIL_connection->call); 489 598 490 /* Remove myself from the connection hash table */ 599 /* 600 * Remove the reference for this client task connection. 601 */ 602 bool destroy; 603 491 604 futex_down(&async_futex); 492 unsigned long key = FIBRIL_connection->in_phone_hash; 605 606 if (--client->refcnt == 0) { 607 hash_table_remove(&client_hash_table, &key, 1); 608 destroy = true; 609 } else 610 destroy = false; 611 612 futex_up(&async_futex); 613 614 if (destroy) { 615 if (client->data) 616 async_client_data_destroy(client->data); 617 618 free(client); 619 } 620 621 /* 622 * Remove myself from the connection hash table. 623 */ 624 futex_down(&async_futex); 625 key = FIBRIL_connection->in_phone_hash; 493 626 hash_table_remove(&conn_hash_table, &key, 1); 494 627 futex_up(&async_futex); 495 628 496 /* Answer all remaining messages with EHANGUP */ 629 /* 630 * Answer all remaining messages with EHANGUP. 631 */ 497 632 while (!list_empty(&FIBRIL_connection->msg_queue)) { 498 msg_t *msg ;499 500 msg = list_get_instance(FIBRIL_connection->msg_queue.next,501 msg_t, link);633 msg_t *msg = 634 list_get_instance(FIBRIL_connection->msg_queue.next, msg_t, 635 link); 636 502 637 list_remove(&msg->link); 503 638 ipc_answer_0(msg->callid, EHANGUP); … … 505 640 } 506 641 642 /* 643 * If the connection was hung-up, answer the last call, 644 * i.e. IPC_M_PHONE_HUNGUP. 645 */ 507 646 if (FIBRIL_connection->close_callid) 508 647 ipc_answer_0(FIBRIL_connection->close_callid, EOK); … … 517 656 * particular fibrils. 518 657 * 658 * @param in_task_hash Identification of the incoming connection. 519 659 * @param in_phone_hash Identification of the incoming connection. 520 660 * @param callid Hash of the opening IPC_M_CONNECT_ME_TO call. … … 529 669 * 530 670 */ 531 fid_t async_new_connection(sysarg_t in_phone_hash, ipc_callid_t callid, 532 ipc_call_t *call, void (*cfibril)(ipc_callid_t, ipc_call_t *)) 671 fid_t async_new_connection(sysarg_t in_task_hash, sysarg_t in_phone_hash, 672 ipc_callid_t callid, ipc_call_t *call, 673 void (*cfibril)(ipc_callid_t, ipc_call_t *)) 533 674 { 534 675 connection_t *conn = malloc(sizeof(*conn)); … … 536 677 if (callid) 537 678 ipc_answer_0(callid, ENOMEM); 679 538 680 return (uintptr_t) NULL; 539 681 } 540 682 683 conn->in_task_hash = in_task_hash; 541 684 conn->in_phone_hash = in_phone_hash; 542 685 list_initialize(&conn->msg_queue); … … 552 695 conn->wdata.fid = fibril_create(connection_fibril, conn); 553 696 554 if ( !conn->wdata.fid) {697 if (conn->wdata.fid == 0) { 555 698 free(conn); 699 556 700 if (callid) 557 701 ipc_answer_0(callid, ENOMEM); 702 558 703 return (uintptr_t) NULL; 559 704 } … … 582 727 static void handle_call(ipc_callid_t callid, ipc_call_t *call) 583 728 { 584 /* Unrouted call - do some default behaviour*/729 /* Unrouted call - take some default action */ 585 730 if ((callid & IPC_CALLID_NOTIFICATION)) { 586 731 process_notification(callid, call); 587 goto out;732 return; 588 733 } 589 734 … … 591 736 case IPC_M_CONNECT_ME: 592 737 case IPC_M_CONNECT_ME_TO: 593 /* Open new connection with fibril etc. */594 async_new_connection( IPC_GET_ARG5(*call), callid, call,595 c lient_connection);596 goto out;738 /* Open new connection with fibril, etc. */ 739 async_new_connection(call->in_task_hash, IPC_GET_ARG5(*call), 740 callid, call, client_connection); 741 return; 597 742 } 598 743 599 744 /* Try to route the call through the connection hash table */ 600 745 if (route_call(callid, call)) 601 goto out;746 return; 602 747 603 748 /* Unknown call from unknown phone - hang it up */ 604 749 ipc_answer_0(callid, EHANGUP); 605 return;606 607 out:608 ;609 750 } 610 751 … … 619 760 link_t *cur = timeout_list.next; 620 761 while (cur != &timeout_list) { 621 awaiter_t *waiter ;622 623 waiter = list_get_instance(cur, awaiter_t, to_event.link);762 awaiter_t *waiter = 763 list_get_instance(cur, awaiter_t, to_event.link); 764 624 765 if (tv_gt(&waiter->to_event.expires, &tv)) 625 766 break; 626 767 627 768 cur = cur->next; 628 769 629 770 list_remove(&waiter->to_event.link); 630 771 waiter->to_event.inlist = false; … … 653 794 while (true) { 654 795 if (fibril_switch(FIBRIL_FROM_MANAGER)) { 655 futex_up(&async_futex); 796 futex_up(&async_futex); 656 797 /* 657 798 * async_futex is always held when entering a manager … … 676 817 continue; 677 818 } else 678 timeout = tv_sub(&waiter->to_event.expires, 679 &tv); 819 timeout = tv_sub(&waiter->to_event.expires, &tv); 680 820 } else 681 821 timeout = SYNCH_NO_TIMEOUT; 682 822 683 823 futex_up(&async_futex); 684 824 685 825 atomic_inc(&threads_in_ipc_wait); 686 826 … … 690 830 691 831 atomic_dec(&threads_in_ipc_wait); 692 832 693 833 if (!callid) { 694 834 handle_expired_timeouts(); … … 729 869 { 730 870 fid_t fid = fibril_create(async_manager_fibril, NULL); 731 fibril_add_manager(fid); 871 if (fid != 0) 872 fibril_add_manager(fid); 732 873 } 733 874 … … 740 881 /** Initialize the async framework. 741 882 * 742 * @return Zero on success or an error code. 743 */ 744 int __async_init(void) 745 { 746 if (!hash_table_create(&conn_hash_table, CONN_HASH_TABLE_CHAINS, 1, 747 &conn_hash_table_ops)) { 748 printf("%s: Cannot create async hash table\n", "libc"); 749 return ENOMEM; 750 } 751 752 _async_sess_init(); 753 754 return 0; 883 */ 884 void __async_init(void) 885 { 886 if (!hash_table_create(&client_hash_table, CLIENT_HASH_TABLE_BUCKETS, 1, 887 &client_hash_table_ops)) 888 abort(); 889 890 if (!hash_table_create(&conn_hash_table, CONN_HASH_TABLE_BUCKETS, 1, 891 &conn_hash_table_ops)) 892 abort(); 755 893 } 756 894 … … 765 903 * @param retval Value returned in the answer. 766 904 * @param data Call data of the answer. 905 * 767 906 */ 768 907 static void reply_received(void *arg, int retval, ipc_call_t *data) … … 812 951 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, ipc_call_t *dataptr) 813 952 { 814 amsg_t *msg = malloc(sizeof( *msg));953 amsg_t *msg = malloc(sizeof(amsg_t)); 815 954 816 955 if (!msg) … … 821 960 822 961 msg->wdata.to_event.inlist = false; 823 /* We may sleep in the next method, but it will use its own mechanism */ 962 963 /* 964 * We may sleep in the next method, 965 * but it will use its own means 966 */ 824 967 msg->wdata.active = true; 825 968 … … 852 995 ipc_call_t *dataptr) 853 996 { 854 amsg_t *msg = malloc(sizeof( *msg));997 amsg_t *msg = malloc(sizeof(amsg_t)); 855 998 856 999 if (!msg) … … 861 1004 862 1005 msg->wdata.to_event.inlist = false; 863 /* We may sleep in next method, but it will use its own mechanism */ 1006 1007 /* 1008 * We may sleep in the next method, 1009 * but it will use its own means 1010 */ 864 1011 msg->wdata.active = true; 865 1012 … … 960 1107 void async_usleep(suseconds_t timeout) 961 1108 { 962 amsg_t *msg = malloc(sizeof( *msg));1109 amsg_t *msg = malloc(sizeof(amsg_t)); 963 1110 964 1111 if (!msg) … … 1103 1250 } 1104 1251 1252 void async_msg_0(int phone, sysarg_t imethod) 1253 { 1254 ipc_call_async_0(phone, imethod, NULL, NULL, true); 1255 } 1256 1257 void async_msg_1(int phone, sysarg_t imethod, sysarg_t arg1) 1258 { 1259 ipc_call_async_1(phone, imethod, arg1, NULL, NULL, true); 1260 } 1261 1262 void async_msg_2(int phone, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2) 1263 { 1264 ipc_call_async_2(phone, imethod, arg1, arg2, NULL, NULL, true); 1265 } 1266 1267 void async_msg_3(int phone, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, 1268 sysarg_t arg3) 1269 { 1270 ipc_call_async_3(phone, imethod, arg1, arg2, arg3, NULL, NULL, true); 1271 } 1272 1273 void async_msg_4(int phone, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, 1274 sysarg_t arg3, sysarg_t arg4) 1275 { 1276 ipc_call_async_4(phone, imethod, arg1, arg2, arg3, arg4, NULL, NULL, 1277 true); 1278 } 1279 1280 void async_msg_5(int phone, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, 1281 sysarg_t arg3, sysarg_t arg4, sysarg_t arg5) 1282 { 1283 ipc_call_async_5(phone, imethod, arg1, arg2, arg3, arg4, arg5, NULL, 1284 NULL, true); 1285 } 1286 1287 sysarg_t async_answer_0(ipc_callid_t callid, sysarg_t retval) 1288 { 1289 return ipc_answer_0(callid, retval); 1290 } 1291 1292 sysarg_t async_answer_1(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1) 1293 { 1294 return ipc_answer_1(callid, retval, arg1); 1295 } 1296 1297 sysarg_t async_answer_2(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1, 1298 sysarg_t arg2) 1299 { 1300 return ipc_answer_2(callid, retval, arg1, arg2); 1301 } 1302 1303 sysarg_t async_answer_3(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1, 1304 sysarg_t arg2, sysarg_t arg3) 1305 { 1306 return ipc_answer_3(callid, retval, arg1, arg2, arg3); 1307 } 1308 1309 sysarg_t async_answer_4(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1, 1310 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4) 1311 { 1312 return ipc_answer_4(callid, retval, arg1, arg2, arg3, arg4); 1313 } 1314 1315 sysarg_t async_answer_5(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1, 1316 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5) 1317 { 1318 return ipc_answer_5(callid, retval, arg1, arg2, arg3, arg4, arg5); 1319 } 1320 1321 int async_forward_fast(ipc_callid_t callid, int phoneid, sysarg_t imethod, 1322 sysarg_t arg1, sysarg_t arg2, unsigned int mode) 1323 { 1324 return ipc_forward_fast(callid, phoneid, imethod, arg1, arg2, mode); 1325 } 1326 1327 int async_forward_slow(ipc_callid_t callid, int phoneid, sysarg_t imethod, 1328 sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5, 1329 unsigned int mode) 1330 { 1331 return ipc_forward_slow(callid, phoneid, imethod, arg1, arg2, arg3, arg4, 1332 arg5, mode); 1333 } 1334 1335 /** Wrapper for making IPC_M_CONNECT_TO_ME calls using the async framework. 1336 * 1337 * Ask through phone for a new connection to some service. 1338 * 1339 * @param phone Phone handle used for contacting the other side. 1340 * @param arg1 User defined argument. 1341 * @param arg2 User defined argument. 1342 * @param arg3 User defined argument. 1343 * @param client_receiver Connection handing routine. 1344 * 1345 * @return New phone handle on success or a negative error code. 1346 * 1347 */ 1348 int async_connect_to_me(int phone, sysarg_t arg1, sysarg_t arg2, 1349 sysarg_t arg3, async_client_conn_t client_receiver) 1350 { 1351 sysarg_t task_hash; 1352 sysarg_t phone_hash; 1353 int rc = async_req_3_5(phone, IPC_M_CONNECT_TO_ME, arg1, arg2, arg3, 1354 NULL, NULL, NULL, &task_hash, &phone_hash); 1355 if (rc != EOK) 1356 return rc; 1357 1358 if (client_receiver != NULL) 1359 async_new_connection(task_hash, phone_hash, 0, NULL, 1360 client_receiver); 1361 1362 return EOK; 1363 } 1364 1105 1365 /** Wrapper for making IPC_M_CONNECT_ME_TO calls using the async framework. 1106 * 1366 * 1107 1367 * Ask through phone for a new connection to some service. 1108 1368 * 1109 * @param phone idPhone handle used for contacting the other side.1110 * @param arg1 1111 * @param arg2 1112 * @param arg3 1113 * 1114 * @return 1115 * /1116 int 1117 async_connect_me_to(int phoneid, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3) 1118 { 1119 int rc; 1369 * @param phone Phone handle used for contacting the other side. 1370 * @param arg1 User defined argument. 1371 * @param arg2 User defined argument. 1372 * @param arg3 User defined argument. 1373 * 1374 * @return New phone handle on success or a negative error code. 1375 * 1376 */ 1377 int async_connect_me_to(int phone, sysarg_t arg1, sysarg_t arg2, 1378 sysarg_t arg3) 1379 { 1120 1380 sysarg_t newphid; 1121 1122 rc = async_req_3_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3, NULL, 1123 NULL, NULL, NULL, &newphid); 1124 1125 if (rc != EOK) 1381 int rc = async_req_3_5(phone, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3, 1382 NULL, NULL, NULL, NULL, &newphid); 1383 1384 if (rc != EOK) 1126 1385 return rc; 1127 1386 1128 1387 return newphid; 1129 1388 } 1130 1389 1131 1390 /** Wrapper for making IPC_M_CONNECT_ME_TO calls using the async framework. 1132 * 1391 * 1133 1392 * Ask through phone for a new connection to some service and block until 1134 1393 * success. 1135 1394 * 1136 * @param phoneid 1137 * @param arg1 1138 * @param arg2 1139 * @param arg3 1140 * 1141 * @return 1142 * /1143 int 1144 async_connect_me_to_blocking(int phoneid, sysarg_t arg1, sysarg_t arg2,1395 * @param phoneid Phone handle used for contacting the other side. 1396 * @param arg1 User defined argument. 1397 * @param arg2 User defined argument. 1398 * @param arg3 User defined argument. 1399 * 1400 * @return New phone handle on success or a negative error code. 1401 * 1402 */ 1403 int async_connect_me_to_blocking(int phoneid, sysarg_t arg1, sysarg_t arg2, 1145 1404 sysarg_t arg3) 1146 1405 { 1147 int rc;1148 1406 sysarg_t newphid; 1149 1150 rc = async_req_4_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3, 1407 int rc = async_req_4_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3, 1151 1408 IPC_FLAG_BLOCKING, NULL, NULL, NULL, NULL, &newphid); 1152 1409 1153 if (rc != EOK) 1410 if (rc != EOK) 1154 1411 return rc; 1155 1412 1156 1413 return newphid; 1157 1414 } 1158 1415 1159 /** Wrapper for making IPC_M_SHARE_IN calls using the async framework. 1160 * 1161 * @param phoneid Phone that will be used to contact the receiving side. 1162 * @param dst Destination address space area base. 1163 * @param size Size of the destination address space area. 1164 * @param arg User defined argument. 1165 * @param flags Storage where the received flags will be stored. Can be 1166 * NULL. 1167 * 1168 * @return Zero on success or a negative error code from errno.h. 1416 /** Connect to a task specified by id. 1417 * 1418 */ 1419 int async_connect_kbox(task_id_t id) 1420 { 1421 return ipc_connect_kbox(id); 1422 } 1423 1424 /** Wrapper for ipc_hangup. 1425 * 1426 * @param phone Phone handle to hung up. 1427 * 1428 * @return Zero on success or a negative error code. 1429 * 1430 */ 1431 int async_hangup(int phone) 1432 { 1433 return ipc_hangup(phone); 1434 } 1435 1436 /** Interrupt one thread of this task from waiting for IPC. */ 1437 void async_poke(void) 1438 { 1439 ipc_poke(); 1440 } 1441 1442 /** Wrapper for IPC_M_SHARE_IN calls using the async framework. 1443 * 1444 * @param phoneid Phone that will be used to contact the receiving side. 1445 * @param dst Destination address space area base. 1446 * @param size Size of the destination address space area. 1447 * @param arg User defined argument. 1448 * @param flags Storage for the received flags. Can be NULL. 1449 * 1450 * @return Zero on success or a negative error code from errno.h. 1451 * 1169 1452 */ 1170 1453 int async_share_in_start(int phoneid, void *dst, size_t size, sysarg_t arg, 1171 int *flags) 1172 { 1173 int res; 1454 unsigned int *flags) 1455 { 1174 1456 sysarg_t tmp_flags; 1175 res = async_req_3_2(phoneid, IPC_M_SHARE_IN, (sysarg_t) dst,1457 int res = async_req_3_2(phoneid, IPC_M_SHARE_IN, (sysarg_t) dst, 1176 1458 (sysarg_t) size, arg, NULL, &tmp_flags); 1459 1177 1460 if (flags) 1178 *flags = tmp_flags; 1461 *flags = (unsigned int) tmp_flags; 1462 1179 1463 return res; 1180 1464 } … … 1182 1466 /** Wrapper for receiving the IPC_M_SHARE_IN calls using the async framework. 1183 1467 * 1184 * This wrapper only makes it more comfortable to receive IPC_M_SHARE_IN calls 1185 * so that the user doesn't have to remember the meaning of each IPC argument. 1468 * This wrapper only makes it more comfortable to receive IPC_M_SHARE_IN 1469 * calls so that the user doesn't have to remember the meaning of each IPC 1470 * argument. 1186 1471 * 1187 1472 * So far, this wrapper is to be used from within a connection fibril. 1188 1473 * 1189 * @param callid Storage where the hash of the IPC_M_SHARE_IN call will 1190 * be stored. 1191 * @param size Destination address space area size. 1192 * 1193 * @return Non-zero on success, zero on failure. 1194 */ 1195 int async_share_in_receive(ipc_callid_t *callid, size_t *size) 1196 { 1197 ipc_call_t data; 1198 1474 * @param callid Storage for the hash of the IPC_M_SHARE_IN call. 1475 * @param size Destination address space area size. 1476 * 1477 * @return True on success, false on failure. 1478 * 1479 */ 1480 bool async_share_in_receive(ipc_callid_t *callid, size_t *size) 1481 { 1199 1482 assert(callid); 1200 1483 assert(size); 1201 1484 1485 ipc_call_t data; 1202 1486 *callid = async_get_call(&data); 1487 1203 1488 if (IPC_GET_IMETHOD(data) != IPC_M_SHARE_IN) 1204 return 0; 1489 return false; 1490 1205 1491 *size = (size_t) IPC_GET_ARG2(data); 1206 return 1;1492 return true; 1207 1493 } 1208 1494 1209 1495 /** Wrapper for answering the IPC_M_SHARE_IN calls using the async framework. 1210 1496 * 1211 * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ calls 1212 * so that the user doesn't have to remember the meaning of each IPC argument. 1213 * 1214 * @param callid Hash of the IPC_M_DATA_READ call to answer. 1215 * @param src Source address space base. 1216 * @param flags Flags to be used for sharing. Bits can be only cleared. 1217 * 1218 * @return Zero on success or a value from @ref errno.h on failure. 1219 */ 1220 int async_share_in_finalize(ipc_callid_t callid, void *src, int flags) 1497 * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ 1498 * calls so that the user doesn't have to remember the meaning of each IPC 1499 * argument. 1500 * 1501 * @param callid Hash of the IPC_M_DATA_READ call to answer. 1502 * @param src Source address space base. 1503 * @param flags Flags to be used for sharing. Bits can be only cleared. 1504 * 1505 * @return Zero on success or a value from @ref errno.h on failure. 1506 * 1507 */ 1508 int async_share_in_finalize(ipc_callid_t callid, void *src, unsigned int flags) 1221 1509 { 1222 1510 return ipc_share_in_finalize(callid, src, flags); 1223 1511 } 1224 1512 1225 /** Wrapper for making IPC_M_SHARE_OUT calls using the async framework. 1226 * 1227 * @param phoneid Phone that will be used to contact the receiving side. 1228 * @param src Source address space area base address. 1229 * @param flags Flags to be used for sharing. Bits can be only cleared. 1230 * 1231 * @return Zero on success or a negative error code from errno.h. 1232 */ 1233 int async_share_out_start(int phoneid, void *src, int flags) 1513 /** Wrapper for IPC_M_SHARE_OUT calls using the async framework. 1514 * 1515 * @param phoneid Phone that will be used to contact the receiving side. 1516 * @param src Source address space area base address. 1517 * @param flags Flags to be used for sharing. Bits can be only cleared. 1518 * 1519 * @return Zero on success or a negative error code from errno.h. 1520 * 1521 */ 1522 int async_share_out_start(int phoneid, void *src, unsigned int flags) 1234 1523 { 1235 1524 return async_req_3_0(phoneid, IPC_M_SHARE_OUT, (sysarg_t) src, 0, … … 1239 1528 /** Wrapper for receiving the IPC_M_SHARE_OUT calls using the async framework. 1240 1529 * 1241 * This wrapper only makes it more comfortable to receive IPC_M_SHARE_OUT calls 1242 * so that the user doesn't have to remember the meaning of each IPC argument. 1530 * This wrapper only makes it more comfortable to receive IPC_M_SHARE_OUT 1531 * calls so that the user doesn't have to remember the meaning of each IPC 1532 * argument. 1243 1533 * 1244 1534 * So far, this wrapper is to be used from within a connection fibril. 1245 1535 * 1246 * @param callid Storage where the hash of the IPC_M_SHARE_OUT call will 1247 * be stored. 1248 * @param size Storage where the source address space area size will be 1249 * stored. 1250 * @param flags Storage where the sharing flags will be stored. 1251 * 1252 * @return Non-zero on success, zero on failure. 1253 */ 1254 int async_share_out_receive(ipc_callid_t *callid, size_t *size, int *flags) 1255 { 1256 ipc_call_t data; 1257 1536 * @param callid Storage for the hash of the IPC_M_SHARE_OUT call. 1537 * @param size Storage for the source address space area size. 1538 * @param flags Storage for the sharing flags. 1539 * 1540 * @return True on success, false on failure. 1541 * 1542 */ 1543 bool async_share_out_receive(ipc_callid_t *callid, size_t *size, unsigned int *flags) 1544 { 1258 1545 assert(callid); 1259 1546 assert(size); 1260 1547 assert(flags); 1261 1548 1549 ipc_call_t data; 1262 1550 *callid = async_get_call(&data); 1551 1263 1552 if (IPC_GET_IMETHOD(data) != IPC_M_SHARE_OUT) 1264 return 0; 1553 return false; 1554 1265 1555 *size = (size_t) IPC_GET_ARG2(data); 1266 *flags = ( int) IPC_GET_ARG3(data);1267 return 1;1556 *flags = (unsigned int) IPC_GET_ARG3(data); 1557 return true; 1268 1558 } 1269 1559 1270 1560 /** Wrapper for answering the IPC_M_SHARE_OUT calls using the async framework. 1271 1561 * 1272 * This wrapper only makes it more comfortable to answer IPC_M_SHARE_OUT calls 1273 * so that the user doesn't have to remember the meaning of each IPC argument. 1274 * 1275 * @param callid Hash of the IPC_M_DATA_WRITE call to answer. 1276 * @param dst Destination address space area base address. 1277 * 1278 * @return Zero on success or a value from @ref errno.h on failure. 1562 * This wrapper only makes it more comfortable to answer IPC_M_SHARE_OUT 1563 * calls so that the user doesn't have to remember the meaning of each IPC 1564 * argument. 1565 * 1566 * @param callid Hash of the IPC_M_DATA_WRITE call to answer. 1567 * @param dst Destination address space area base address. 1568 * 1569 * @return Zero on success or a value from @ref errno.h on failure. 1570 * 1279 1571 */ 1280 1572 int async_share_out_finalize(ipc_callid_t callid, void *dst) … … 1283 1575 } 1284 1576 1285 1286 /** Wrapper for making IPC_M_DATA_READ calls using the async framework. 1287 * 1288 * @param phoneid Phone that will be used to contact the receiving side.1289 * @param dst Address of the beginningof the destination buffer.1290 * @param size Size of the destination buffer.1291 * 1292 * @return Zero on success or a negative error code from errno.h.1577 /** Wrapper for IPC_M_DATA_READ calls using the async framework. 1578 * 1579 * @param phoneid Phone that will be used to contact the receiving side. 1580 * @param dst Address of the beginning of the destination buffer. 1581 * @param size Size of the destination buffer. 1582 * 1583 * @return Zero on success or a negative error code from errno.h. 1584 * 1293 1585 */ 1294 1586 int async_data_read_start(int phoneid, void *dst, size_t size) … … 1300 1592 /** Wrapper for receiving the IPC_M_DATA_READ calls using the async framework. 1301 1593 * 1302 * This wrapper only makes it more comfortable to receive IPC_M_DATA_READ calls 1303 * so that the user doesn't have to remember the meaning of each IPC argument. 1594 * This wrapper only makes it more comfortable to receive IPC_M_DATA_READ 1595 * calls so that the user doesn't have to remember the meaning of each IPC 1596 * argument. 1304 1597 * 1305 1598 * So far, this wrapper is to be used from within a connection fibril. 1306 1599 * 1307 * @param callid Storage where the hash of the IPC_M_DATA_READ call will 1308 * be stored. 1309 * @param size Storage where the maximum size will be stored. Can be 1310 * NULL. 1311 * 1312 * @return Non-zero on success, zero on failure. 1313 */ 1314 int async_data_read_receive(ipc_callid_t *callid, size_t *size) 1315 { 1600 * @param callid Storage for the hash of the IPC_M_DATA_READ. 1601 * @param size Storage for the maximum size. Can be NULL. 1602 * 1603 * @return True on success, false on failure. 1604 * 1605 */ 1606 bool async_data_read_receive(ipc_callid_t *callid, size_t *size) 1607 { 1608 assert(callid); 1609 1316 1610 ipc_call_t data; 1317 1318 assert(callid);1319 1320 1611 *callid = async_get_call(&data); 1612 1321 1613 if (IPC_GET_IMETHOD(data) != IPC_M_DATA_READ) 1322 return 0; 1614 return false; 1615 1323 1616 if (size) 1324 1617 *size = (size_t) IPC_GET_ARG2(data); 1325 return 1; 1618 1619 return true; 1326 1620 } 1327 1621 1328 1622 /** Wrapper for answering the IPC_M_DATA_READ calls using the async framework. 1329 1623 * 1330 * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ calls 1331 * so that the user doesn't have to remember the meaning of each IPC argument. 1332 * 1333 * @param callid Hash of the IPC_M_DATA_READ call to answer. 1334 * @param src Source address for the IPC_M_DATA_READ call. 1335 * @param size Size for the IPC_M_DATA_READ call. Can be smaller than 1336 * the maximum size announced by the sender. 1337 * 1338 * @return Zero on success or a value from @ref errno.h on failure. 1624 * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ 1625 * calls so that the user doesn't have to remember the meaning of each IPC 1626 * argument. 1627 * 1628 * @param callid Hash of the IPC_M_DATA_READ call to answer. 1629 * @param src Source address for the IPC_M_DATA_READ call. 1630 * @param size Size for the IPC_M_DATA_READ call. Can be smaller than 1631 * the maximum size announced by the sender. 1632 * 1633 * @return Zero on success or a value from @ref errno.h on failure. 1634 * 1339 1635 */ 1340 1636 int async_data_read_finalize(ipc_callid_t callid, const void *src, size_t size) … … 1344 1640 1345 1641 /** Wrapper for forwarding any read request 1346 *1347 1642 * 1348 1643 */ … … 1377 1672 } 1378 1673 1379 /** Wrapper for makingIPC_M_DATA_WRITE calls using the async framework.1674 /** Wrapper for IPC_M_DATA_WRITE calls using the async framework. 1380 1675 * 1381 1676 * @param phoneid Phone that will be used to contact the receiving side. … … 1394 1689 /** Wrapper for receiving the IPC_M_DATA_WRITE calls using the async framework. 1395 1690 * 1396 * This wrapper only makes it more comfortable to receive IPC_M_DATA_WRITE calls 1397 * so that the user doesn't have to remember the meaning of each IPC argument. 1691 * This wrapper only makes it more comfortable to receive IPC_M_DATA_WRITE 1692 * calls so that the user doesn't have to remember the meaning of each IPC 1693 * argument. 1398 1694 * 1399 1695 * So far, this wrapper is to be used from within a connection fibril. 1400 1696 * 1401 * @param callid Storage where the hash of the IPC_M_DATA_WRITE call will1402 * be stored.1403 * @param size Storage where the suggested size will be stored. May be1404 * NULL1405 * 1406 * @return Non-zero on success, zero on failure.1407 * 1408 */ 1409 int async_data_write_receive(ipc_callid_t *callid, size_t *size) 1410 { 1697 * @param callid Storage for the hash of the IPC_M_DATA_WRITE. 1698 * @param size Storage for the suggested size. May be NULL. 1699 * 1700 * @return True on success, false on failure. 1701 * 1702 */ 1703 bool async_data_write_receive(ipc_callid_t *callid, size_t *size) 1704 { 1705 assert(callid); 1706 1411 1707 ipc_call_t data; 1412 1413 assert(callid);1414 1415 1708 *callid = async_get_call(&data); 1709 1416 1710 if (IPC_GET_IMETHOD(data) != IPC_M_DATA_WRITE) 1417 return 0;1711 return false; 1418 1712 1419 1713 if (size) 1420 1714 *size = (size_t) IPC_GET_ARG2(data); 1421 1715 1422 return 1;1716 return true; 1423 1717 } 1424 1718 1425 1719 /** Wrapper for answering the IPC_M_DATA_WRITE calls using the async framework. 1426 1720 * 1427 * This wrapper only makes it more comfortable to answer IPC_M_DATA_WRITE calls 1428 * so that the user doesn't have to remember the meaning of each IPC argument. 1721 * This wrapper only makes it more comfortable to answer IPC_M_DATA_WRITE 1722 * calls so that the user doesn't have to remember the meaning of each IPC 1723 * argument. 1429 1724 * 1430 1725 * @param callid Hash of the IPC_M_DATA_WRITE call to answer. … … 1522 1817 * 1523 1818 */ 1524 void async_data_write_void( const int retval)1819 void async_data_write_void(sysarg_t retval) 1525 1820 { 1526 1821 ipc_callid_t callid; … … 1530 1825 1531 1826 /** Wrapper for forwarding any data that is about to be received 1532 *1533 1827 * 1534 1828 */ -
uspace/lib/c/generic/async_sess.c
r22027b6e r8b5690f 99 99 100 100 #include <async_sess.h> 101 #include <ipc/ipc.h>102 101 #include <fibril_synch.h> 103 102 #include <adt/list.h> … … 106 105 #include <errno.h> 107 106 #include <assert.h> 107 #include "private/async_sess.h" 108 108 109 109 /** An inactive open connection. */ 110 110 typedef struct { 111 111 link_t sess_link; /**< Link for the session list of inactive connections. */ 112 link_t global_link; /**< Link for the global list of inactive connecti nos. */112 link_t global_link; /**< Link for the global list of inactive connections. */ 113 113 int data_phone; /**< Connected data phone. */ 114 114 } conn_node_t; 115 115 116 116 /** 117 * Mutex protecting the inactive_conn_head list and the session list. 117 * Mutex protecting the inactive_conn_head list, the session list and the 118 * avail_phone condition variable. 118 119 */ 119 120 static fibril_mutex_t async_sess_mutex; … … 129 130 static LIST_INITIALIZE(session_list_head); 130 131 132 /** 133 * Condition variable used to wait for a phone to become available. 134 */ 135 static FIBRIL_CONDVAR_INITIALIZE(avail_phone_cv); 136 131 137 /** Initialize the async_sess subsystem. 132 138 * 133 139 * Needs to be called prior to any other interface in this file. 134 */ 135 void _async_sess_init(void) 140 * 141 */ 142 void __async_sess_init(void) 136 143 { 137 144 fibril_mutex_initialize(&async_sess_mutex); … … 194 201 list_remove(&conn->global_link); 195 202 196 ipc_hangup(conn->data_phone);203 async_hangup(conn->data_phone); 197 204 free(conn); 198 205 } 206 207 fibril_condvar_broadcast(&avail_phone_cv); 199 208 } 200 209 … … 252 261 data_phone = conn->data_phone; 253 262 free(conn); 254 ipc_hangup(data_phone);263 async_hangup(data_phone); 255 264 goto retry; 256 265 } else { 257 266 /* 258 * This is unfortunate. We failed both to find a cached 259 * connection or to create a new one even after cleaning up 260 * the cache. This is most likely due to too many 261 * open sessions (connected session phones). 267 * Wait for a phone to become available. 262 268 */ 263 data_phone = ELIMIT; 269 fibril_condvar_wait(&avail_phone_cv, &async_sess_mutex); 270 goto retry; 264 271 } 265 272 } … … 279 286 280 287 fibril_mutex_lock(&async_sess_mutex); 288 fibril_condvar_signal(&avail_phone_cv); 281 289 conn = (conn_node_t *) malloc(sizeof(conn_node_t)); 282 290 if (!conn) { … … 285 293 * means that we simply hang up. 286 294 */ 295 async_hangup(data_phone); 287 296 fibril_mutex_unlock(&async_sess_mutex); 288 ipc_hangup(data_phone);289 297 return; 290 298 } -
uspace/lib/c/generic/clipboard.c
r22027b6e r8b5690f 39 39 40 40 #include <clipboard.h> 41 #include <ipc/ns.h> 41 42 #include <ipc/services.h> 42 43 #include <ipc/clipboard.h> … … 54 55 { 55 56 while (clip_phone < 0) 56 clip_phone = ipc_connect_me_to_blocking(PHONE_NS,SERVICE_CLIPBOARD, 0, 0);57 clip_phone = service_connect_blocking(SERVICE_CLIPBOARD, 0, 0); 57 58 } 58 59 -
uspace/lib/c/generic/ddi.c
r22027b6e r8b5690f 96 96 } 97 97 98 /** Enable an interrupt.99 *100 * @param irq the interrupt.101 *102 * @return Zero on success, negative error code otherwise.103 */104 int interrupt_enable(int irq)105 {106 return __SYSCALL2(SYS_INTERRUPT_ENABLE, (sysarg_t) irq, 1);107 }108 109 /** Disable an interrupt.110 *111 * @param irq the interrupt.112 *113 * @return Zero on success, negative error code otherwise.114 */115 int interrupt_disable(int irq)116 {117 return __SYSCALL2(SYS_INTERRUPT_ENABLE, (sysarg_t) irq, 0);118 }119 120 98 /** Enable PIO for specified I/O range. 121 99 * … … 149 127 } 150 128 129 /** Register IRQ notification. 130 * 131 * @param inr IRQ number. 132 * @param devno Device number of the device generating inr. 133 * @param method Use this method for notifying me. 134 * @param ucode Top-half pseudocode handler. 135 * 136 * @return Value returned by the kernel. 137 * 138 */ 139 int register_irq(int inr, int devno, int method, irq_code_t *ucode) 140 { 141 return __SYSCALL4(SYS_REGISTER_IRQ, inr, devno, method, 142 (sysarg_t) ucode); 143 } 144 145 /** Unregister IRQ notification. 146 * 147 * @param inr IRQ number. 148 * @param devno Device number of the device generating inr. 149 * 150 * @return Value returned by the kernel. 151 * 152 */ 153 int unregister_irq(int inr, int devno) 154 { 155 return __SYSCALL2(SYS_UNREGISTER_IRQ, inr, devno); 156 } 157 151 158 /** @} 152 159 */ -
uspace/lib/c/generic/devman.c
r22027b6e r8b5690f 28 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 29 */ 30 31 30 31 /** @addtogroup libc 32 32 * @{ 33 33 */ … … 37 37 #include <str.h> 38 38 #include <stdio.h> 39 #include <ipc/ipc.h>40 39 #include <ipc/services.h> 41 40 #include <ipc/devman.h> 42 41 #include <devman.h> 43 42 #include <async.h> 43 #include <fibril_synch.h> 44 44 #include <errno.h> 45 45 #include <malloc.h> … … 50 50 static int devman_phone_client = -1; 51 51 52 static FIBRIL_MUTEX_INITIALIZE(devman_phone_mutex); 53 52 54 int devman_get_phone(devman_interface_t iface, unsigned int flags) 53 55 { 54 56 switch (iface) { 55 57 case DEVMAN_DRIVER: 56 if (devman_phone_driver >= 0) 58 fibril_mutex_lock(&devman_phone_mutex); 59 if (devman_phone_driver >= 0) { 60 fibril_mutex_unlock(&devman_phone_mutex); 57 61 return devman_phone_driver; 62 } 58 63 59 64 if (flags & IPC_FLAG_BLOCKING) … … 64 69 SERVICE_DEVMAN, DEVMAN_DRIVER, 0); 65 70 71 fibril_mutex_unlock(&devman_phone_mutex); 66 72 return devman_phone_driver; 67 73 case DEVMAN_CLIENT: 68 if (devman_phone_client >= 0) 74 fibril_mutex_lock(&devman_phone_mutex); 75 if (devman_phone_client >= 0) { 76 fibril_mutex_unlock(&devman_phone_mutex); 69 77 return devman_phone_client; 70 71 if (flags & IPC_FLAG_BLOCKING) 78 } 79 80 if (flags & IPC_FLAG_BLOCKING) { 72 81 devman_phone_client = async_connect_me_to_blocking( 73 82 PHONE_NS, SERVICE_DEVMAN, DEVMAN_CLIENT, 0); 74 else83 } else { 75 84 devman_phone_client = async_connect_me_to(PHONE_NS, 76 85 SERVICE_DEVMAN, DEVMAN_CLIENT, 0); 77 86 } 87 88 fibril_mutex_unlock(&devman_phone_mutex); 78 89 return devman_phone_client; 79 90 default: … … 104 115 async_set_client_connection(conn); 105 116 106 sysarg_t callback_phonehash; 107 ipc_connect_to_me(phone, 0, 0, 0, &callback_phonehash); 117 async_connect_to_me(phone, 0, 0, 0, NULL); 108 118 async_wait_for(req, &retval); 109 119 … … 210 220 case DEVMAN_DRIVER: 211 221 if (devman_phone_driver >= 0) { 212 ipc_hangup(devman_phone_driver);222 async_hangup(devman_phone_driver); 213 223 devman_phone_driver = -1; 214 224 } … … 216 226 case DEVMAN_CLIENT: 217 227 if (devman_phone_client >= 0) { 218 ipc_hangup(devman_phone_client);228 async_hangup(devman_phone_client); 219 229 devman_phone_client = -1; 220 230 } -
uspace/lib/c/generic/devmap.c
r22027b6e r8b5690f 29 29 30 30 #include <str.h> 31 #include <ipc/ipc.h>32 31 #include <ipc/services.h> 32 #include <ipc/ns.h> 33 33 #include <ipc/devmap.h> 34 34 #include <devmap.h> … … 50 50 51 51 if (flags & IPC_FLAG_BLOCKING) 52 devmap_phone_driver = ipc_connect_me_to_blocking(PHONE_NS,53 SERVICE_DEVMAP,DEVMAP_DRIVER, 0);52 devmap_phone_driver = service_connect_blocking(SERVICE_DEVMAP, 53 DEVMAP_DRIVER, 0); 54 54 else 55 devmap_phone_driver = ipc_connect_me_to(PHONE_NS,56 SERVICE_DEVMAP,DEVMAP_DRIVER, 0);55 devmap_phone_driver = service_connect(SERVICE_DEVMAP, 56 DEVMAP_DRIVER, 0); 57 57 58 58 return devmap_phone_driver; … … 62 62 63 63 if (flags & IPC_FLAG_BLOCKING) 64 devmap_phone_client = ipc_connect_me_to_blocking(PHONE_NS,65 SERVICE_DEVMAP,DEVMAP_CLIENT, 0);64 devmap_phone_client = service_connect_blocking(SERVICE_DEVMAP, 65 DEVMAP_CLIENT, 0); 66 66 else 67 devmap_phone_client = ipc_connect_me_to(PHONE_NS,68 SERVICE_DEVMAP,DEVMAP_CLIENT, 0);67 devmap_phone_client = service_connect(SERVICE_DEVMAP, 68 DEVMAP_CLIENT, 0); 69 69 70 70 return devmap_phone_client; … … 79 79 case DEVMAP_DRIVER: 80 80 if (devmap_phone_driver >= 0) { 81 ipc_hangup(devmap_phone_driver);81 async_hangup(devmap_phone_driver); 82 82 devmap_phone_driver = -1; 83 83 } … … 85 85 case DEVMAP_CLIENT: 86 86 if (devmap_phone_client >= 0) { 87 ipc_hangup(devmap_phone_client);87 async_hangup(devmap_phone_client); 88 88 devmap_phone_client = -1; 89 89 } … … 116 116 async_set_client_connection(conn); 117 117 118 sysarg_t callback_phonehash; 119 ipc_connect_to_me(phone, 0, 0, 0, &callback_phonehash); 118 async_connect_to_me(phone, 0, 0, 0, NULL); 120 119 async_wait_for(req, &retval); 121 120 -
uspace/lib/c/generic/event.c
r22027b6e r8b5690f 35 35 */ 36 36 /** @file 37 */ 37 */ 38 38 39 39 #include <libc.h> 40 40 #include <event.h> 41 41 #include <kernel/ipc/event_types.h> 42 #include <ipc/ipc.h>43 42 44 43 /** Subscribe for event notifications. -
uspace/lib/c/generic/fibril_synch.c
r22027b6e r8b5690f 36 36 #include <fibril.h> 37 37 #include <async.h> 38 #include <async_priv.h>39 38 #include <adt/list.h> 40 39 #include <futex.h> … … 44 43 #include <stacktrace.h> 45 44 #include <stdlib.h> 45 #include "private/async.h" 46 46 47 47 static void optimize_execution_power(void) … … 55 55 */ 56 56 if (atomic_get(&threads_in_ipc_wait) > 0) 57 ipc_poke();57 async_poke(); 58 58 } 59 59 … … 103 103 { 104 104 fibril_t *f = (fibril_t *) fibril_get_id(); 105 106 if (fibril_get_sercount() != 0) 107 abort(); 105 108 106 109 futex_down(&async_futex); … … 194 197 fibril_t *f = (fibril_t *) fibril_get_id(); 195 198 199 if (fibril_get_sercount() != 0) 200 abort(); 201 196 202 futex_down(&async_futex); 197 203 if (frw->writers) { … … 219 225 fibril_t *f = (fibril_t *) fibril_get_id(); 220 226 227 if (fibril_get_sercount() != 0) 228 abort(); 229 221 230 futex_down(&async_futex); 222 231 if (frw->writers || frw->readers) { -
uspace/lib/c/generic/io/io.c
r22027b6e r8b5690f 41 41 #include <bool.h> 42 42 #include <malloc.h> 43 #include <async.h> 43 44 #include <io/klog.h> 44 45 #include <vfs/vfs.h> 45 46 #include <ipc/devmap.h> 46 47 #include <adt/list.h> 48 #include "../private/io.h" 47 49 48 50 static void _ffillbuf(FILE *stream); … … 322 324 323 325 if (stream->phone >= 0) 324 ipc_hangup(stream->phone);326 async_hangup(stream->phone); 325 327 326 328 if (stream->fd >= 0) -
uspace/lib/c/generic/ipc.c
r22027b6e r8b5690f 45 45 #include <errno.h> 46 46 #include <adt/list.h> 47 #include <stdio.h>48 #include <unistd.h>49 47 #include <futex.h> 50 #include <kernel/synch/synch.h>51 #include <async.h>52 48 #include <fibril.h> 53 #include <assert.h>54 49 55 50 /** 56 * Structures of this type are used for keeping track of sent asynchronous calls57 * and queing unsent calls.51 * Structures of this type are used for keeping track 52 * of sent asynchronous calls and queing unsent calls. 58 53 */ 59 54 typedef struct { 60 55 link_t list; 61 56 62 57 ipc_async_callback_t callback; 63 58 void *private; 59 64 60 union { 65 61 ipc_callid_t callid; … … 69 65 } msg; 70 66 } u; 71 fid_t fid; /**< Fibril waiting for sending this call. */ 67 68 /** Fibril waiting for sending this call. */ 69 fid_t fid; 72 70 } async_call_t; 73 71 … … 76 74 /** List of asynchronous calls that were not accepted by kernel. 77 75 * 78 * It is protected by async_futex, because if the call cannot be sent into the 79 * kernel, the async framework is used automatically. 76 * Protected by async_futex, because if the call is not accepted 77 * by the kernel, the async framework is used automatically. 78 * 80 79 */ 81 80 LIST_INITIALIZE(queued_calls); … … 83 82 static atomic_t ipc_futex = FUTEX_INITIALIZER; 84 83 85 /** Make a fast synchronous call.86 * 87 * Only three payload arguments can be passed using this function. However, this88 * function is faster than the generic ipc_call_sync_slow() because the payload89 * is passed directly in registers.90 * 91 * @param phoneid 92 * @param method 93 * @param arg1 94 * @param arg2 95 * @param arg3 96 * @param result1 97 * @param result2 98 * @param result3 99 * @param result4 100 * @param result5 101 * 102 * @return Negative values represent errors returned by IPC.103 * Otherwise the RETVAL of the answer is returned.104 * /105 int 106 i pc_call_sync_fast(int phoneid, sysarg_t method, sysarg_t arg1, sysarg_t arg2,107 sysarg_t arg 3, sysarg_t *result1, sysarg_t *result2, sysarg_t *result3,108 sysarg_t *result 4, sysarg_t *result5)84 /** Fast synchronous call. 85 * 86 * Only three payload arguments can be passed using this function. However, 87 * this function is faster than the generic ipc_call_sync_slow() because 88 * the payload is passed directly in registers. 89 * 90 * @param phoneid Phone handle for the call. 91 * @param method Requested method. 92 * @param arg1 Service-defined payload argument. 93 * @param arg2 Service-defined payload argument. 94 * @param arg3 Service-defined payload argument. 95 * @param result1 If non-NULL, the return ARG1 will be stored there. 96 * @param result2 If non-NULL, the return ARG2 will be stored there. 97 * @param result3 If non-NULL, the return ARG3 will be stored there. 98 * @param result4 If non-NULL, the return ARG4 will be stored there. 99 * @param result5 If non-NULL, the return ARG5 will be stored there. 100 * 101 * @return Negative values representing IPC errors. 102 * @return Otherwise the RETVAL of the answer. 103 * 104 */ 105 int ipc_call_sync_fast(int phoneid, sysarg_t method, sysarg_t arg1, 106 sysarg_t arg2, sysarg_t arg3, sysarg_t *result1, sysarg_t *result2, 107 sysarg_t *result3, sysarg_t *result4, sysarg_t *result5) 109 108 { 110 109 ipc_call_t resdata; 111 int callres; 112 113 callres = __SYSCALL6(SYS_IPC_CALL_SYNC_FAST, phoneid, method, arg1, 110 int callres = __SYSCALL6(SYS_IPC_CALL_SYNC_FAST, phoneid, method, arg1, 114 111 arg2, arg3, (sysarg_t) &resdata); 115 112 if (callres) 116 113 return callres; 114 117 115 if (result1) 118 116 *result1 = IPC_GET_ARG1(resdata); … … 125 123 if (result5) 126 124 *result5 = IPC_GET_ARG5(resdata); 127 125 128 126 return IPC_GET_RETVAL(resdata); 129 127 } 130 128 131 /** Make a synchronous call transmitting 5 arguments of payload.129 /** Synchronous call transmitting 5 arguments of payload. 132 130 * 133 131 * @param phoneid Phone handle for the call. … … 144 142 * @param result5 If non-NULL, storage for the fifth return argument. 145 143 * 146 * @return Negative value means IPC error.147 * 148 * 149 */ 150 int 151 ipc_call_sync_slow(int phoneid, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2,152 sysarg_t arg3, sysarg_t arg4, sysarg_t arg5, sysarg_t *result1,153 sysarg_t *result 2, sysarg_t *result3, sysarg_t *result4, sysarg_t *result5)144 * @return Negative values representing IPC errors. 145 * @return Otherwise the RETVAL of the answer. 146 * 147 */ 148 int ipc_call_sync_slow(int phoneid, sysarg_t imethod, sysarg_t arg1, 149 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5, 150 sysarg_t *result1, sysarg_t *result2, sysarg_t *result3, sysarg_t *result4, 151 sysarg_t *result5) 154 152 { 155 153 ipc_call_t data; … … 181 179 } 182 180 183 /** S yscall to send asynchronous message.181 /** Send asynchronous message via syscall. 184 182 * 185 183 * @param phoneid Phone handle for the call. … … 189 187 * 190 188 */ 191 static ipc_callid_t _ipc_call_async(int phoneid, ipc_call_t *data)189 static ipc_callid_t ipc_call_async_internal(int phoneid, ipc_call_t *data) 192 190 { 193 191 return __SYSCALL2(SYS_IPC_CALL_ASYNC_SLOW, phoneid, (sysarg_t) data); 194 192 } 195 193 196 /** Prolog to ipc_call_async_*() functions. 197 * 198 * @param private Argument for the answer/error callback. 199 * @param callback Answer/error callback. 200 * 201 * @return New, partially initialized async_call structure or NULL. 194 /** Prolog for ipc_call_async_*() functions. 195 * 196 * @param private Argument for the answer/error callback. 197 * @param callback Answer/error callback. 198 * 199 * @return New, partially initialized async_call structure or NULL. 200 * 202 201 */ 203 202 static inline async_call_t *ipc_prepare_async(void *private, 204 203 ipc_async_callback_t callback) 205 204 { 206 async_call_t *call; 207 208 call = malloc(sizeof(*call)); 205 async_call_t *call = 206 (async_call_t *) malloc(sizeof(async_call_t)); 209 207 if (!call) { 210 208 if (callback) 211 209 callback(private, ENOMEM, NULL); 210 212 211 return NULL; 213 212 } 213 214 214 call->callback = callback; 215 215 call->private = private; 216 216 217 217 return call; 218 218 } 219 219 220 /** Epilogue of ipc_call_async_*() functions. 221 * 222 * @param callid Value returned by the SYS_IPC_CALL_ASYNC_* syscall. 223 * @param phoneid Phone handle through which the call was made. 224 * @param call async_call structure returned by ipc_prepare_async(). 225 * @param can_preempt If non-zero, the current fibril can be preempted in this 226 * call. 220 /** Epilog for ipc_call_async_*() functions. 221 * 222 * @param callid Value returned by the SYS_IPC_CALL_ASYNC_* syscall. 223 * @param phoneid Phone handle through which the call was made. 224 * @param call Structure returned by ipc_prepare_async(). 225 * @param can_preempt If true, the current fibril can be preempted 226 * in this call. 227 * 227 228 */ 228 229 static inline void ipc_finish_async(ipc_callid_t callid, int phoneid, 229 async_call_t *call, int can_preempt) 230 { 231 if (!call) { /* Nothing to do regardless if failed or not */ 230 async_call_t *call, bool can_preempt) 231 { 232 if (!call) { 233 /* Nothing to do regardless if failed or not */ 232 234 futex_up(&ipc_futex); 233 235 return; 234 236 } 235 237 236 238 if (callid == (ipc_callid_t) IPC_CALLRET_FATAL) { 237 239 futex_up(&ipc_futex); 240 238 241 /* Call asynchronous handler with error code */ 239 242 if (call->callback) 240 243 call->callback(call->private, ENOENT, NULL); 244 241 245 free(call); 242 246 return; 243 247 } 244 248 245 249 if (callid == (ipc_callid_t) IPC_CALLRET_TEMPORARY) { 246 250 futex_up(&ipc_futex); 247 251 248 252 call->u.msg.phoneid = phoneid; 249 253 250 254 futex_down(&async_futex); 251 255 list_append(&call->list, &queued_calls); 252 256 253 257 if (can_preempt) { 254 258 call->fid = fibril_get_id(); … … 259 263 futex_up(&async_futex); 260 264 } 265 261 266 return; 262 267 } 268 263 269 call->u.callid = callid; 270 264 271 /* Add call to the list of dispatched calls */ 265 272 list_append(&call->list, &dispatched_calls); 266 273 futex_up(&ipc_futex); 267 268 } 269 270 /** Make a fast asynchronous call. 274 } 275 276 /** Fast asynchronous call. 271 277 * 272 278 * This function can only handle four arguments of payload. It is, however, … … 274 280 * 275 281 * Note that this function is a void function. 276 * During normal opertation, answering this call will trigger the callback. 277 * In case of fatal error, call the callback handler with the proper error code. 278 * If the call cannot be temporarily made, queue it. 282 * 283 * During normal operation, answering this call will trigger the callback. 284 * In case of fatal error, the callback handler is called with the proper 285 * error code. If the call cannot be temporarily made, it is queued. 279 286 * 280 287 * @param phoneid Phone handle for the call. … … 286 293 * @param private Argument to be passed to the answer/error callback. 287 294 * @param callback Answer or error callback. 288 * @param can_preempt If non-zero, the current fibril will be preempted in295 * @param can_preempt If true, the current fibril will be preempted in 289 296 * case the kernel temporarily refuses to accept more 290 297 * asynchronous calls. … … 293 300 void ipc_call_async_fast(int phoneid, sysarg_t imethod, sysarg_t arg1, 294 301 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, void *private, 295 ipc_async_callback_t callback, intcan_preempt)302 ipc_async_callback_t callback, bool can_preempt) 296 303 { 297 304 async_call_t *call = NULL; … … 304 311 305 312 /* 306 * We need to make sure that we get callid before another thread307 * accesses the queue again.313 * We need to make sure that we get callid 314 * before another thread accesses the queue again. 308 315 */ 316 309 317 futex_down(&ipc_futex); 310 318 ipc_callid_t callid = __SYSCALL6(SYS_IPC_CALL_ASYNC_FAST, phoneid, … … 317 325 return; 318 326 } 327 319 328 IPC_SET_IMETHOD(call->u.msg.data, imethod); 320 329 IPC_SET_ARG1(call->u.msg.data, arg1); … … 322 331 IPC_SET_ARG3(call->u.msg.data, arg3); 323 332 IPC_SET_ARG4(call->u.msg.data, arg4); 333 324 334 /* 325 335 * To achieve deterministic behavior, we always zero out the 326 336 * arguments that are beyond the limits of the fast version. 327 337 */ 338 328 339 IPC_SET_ARG5(call->u.msg.data, 0); 329 340 } 341 330 342 ipc_finish_async(callid, phoneid, call, can_preempt); 331 343 } 332 344 333 /** Make an asynchronous call transmitting the entire payload.345 /** Asynchronous call transmitting the entire payload. 334 346 * 335 347 * Note that this function is a void function. 336 * During normal opertation, answering this call will trigger the callback. 337 * In case of fatal error, call the callback handler with the proper error code. 338 * If the call cannot be temporarily made, queue it. 348 * 349 * During normal operation, answering this call will trigger the callback. 350 * In case of fatal error, the callback handler is called with the proper 351 * error code. If the call cannot be temporarily made, it is queued. 339 352 * 340 353 * @param phoneid Phone handle for the call. … … 347 360 * @param private Argument to be passed to the answer/error callback. 348 361 * @param callback Answer or error callback. 349 * @param can_preempt If non-zero, the current fibril will be preempted in362 * @param can_preempt If true, the current fibril will be preempted in 350 363 * case the kernel temporarily refuses to accept more 351 364 * asynchronous calls. … … 354 367 void ipc_call_async_slow(int phoneid, sysarg_t imethod, sysarg_t arg1, 355 368 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5, void *private, 356 ipc_async_callback_t callback, int can_preempt) 357 { 358 async_call_t *call; 359 ipc_callid_t callid; 360 361 call = ipc_prepare_async(private, callback); 369 ipc_async_callback_t callback, bool can_preempt) 370 { 371 async_call_t *call = ipc_prepare_async(private, callback); 362 372 if (!call) 363 373 return; 364 374 365 375 IPC_SET_IMETHOD(call->u.msg.data, imethod); 366 376 IPC_SET_ARG1(call->u.msg.data, arg1); … … 369 379 IPC_SET_ARG4(call->u.msg.data, arg4); 370 380 IPC_SET_ARG5(call->u.msg.data, arg5); 381 371 382 /* 372 * We need to make sure that we get callid before another thread373 * accesses the queue again.383 * We need to make sure that we get callid 384 * before another threadaccesses the queue again. 374 385 */ 386 375 387 futex_down(&ipc_futex); 376 callid = _ipc_call_async(phoneid, &call->u.msg.data); 377 388 ipc_callid_t callid = 389 ipc_call_async_internal(phoneid, &call->u.msg.data); 390 378 391 ipc_finish_async(callid, phoneid, call, can_preempt); 379 392 } 380 393 381 382 /** Answer a received call - fast version. 394 /** Answer received call (fast version). 383 395 * 384 396 * The fast answer makes use of passing retval and first four arguments in 385 397 * registers. If you need to return more, use the ipc_answer_slow() instead. 386 398 * 387 * @param callid Hash of the call being answered. 388 * @param retval Return value. 389 * @param arg1 First return argument. 390 * @param arg2 Second return argument. 391 * @param arg3 Third return argument. 392 * @param arg4 Fourth return argument. 393 * 394 * @return Zero on success or a value from @ref errno.h on failure. 399 * @param callid Hash of the call being answered. 400 * @param retval Return value. 401 * @param arg1 First return argument. 402 * @param arg2 Second return argument. 403 * @param arg3 Third return argument. 404 * @param arg4 Fourth return argument. 405 * 406 * @return Zero on success. 407 * @return Value from @ref errno.h on failure. 408 * 395 409 */ 396 410 sysarg_t ipc_answer_fast(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1, … … 401 415 } 402 416 403 /** Answer a received call - slow full version. 404 * 405 * @param callid Hash of the call being answered. 406 * @param retval Return value. 407 * @param arg1 First return argument. 408 * @param arg2 Second return argument. 409 * @param arg3 Third return argument. 410 * @param arg4 Fourth return argument. 411 * @param arg5 Fifth return argument. 412 * 413 * @return Zero on success or a value from @ref errno.h on failure. 417 /** Answer received call (entire payload). 418 * 419 * @param callid Hash of the call being answered. 420 * @param retval Return value. 421 * @param arg1 First return argument. 422 * @param arg2 Second return argument. 423 * @param arg3 Third return argument. 424 * @param arg4 Fourth return argument. 425 * @param arg5 Fifth return argument. 426 * 427 * @return Zero on success. 428 * @return Value from @ref errno.h on failure. 429 * 414 430 */ 415 431 sysarg_t ipc_answer_slow(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1, … … 417 433 { 418 434 ipc_call_t data; 419 435 420 436 IPC_SET_RETVAL(data, retval); 421 437 IPC_SET_ARG1(data, arg1); … … 424 440 IPC_SET_ARG4(data, arg4); 425 441 IPC_SET_ARG5(data, arg5); 426 442 427 443 return __SYSCALL2(SYS_IPC_ANSWER_SLOW, callid, (sysarg_t) &data); 428 444 } 429 445 430 431 /** Try to dispatch queued calls from the async queue. */ 432 static void try_dispatch_queued_calls(void) 433 { 434 async_call_t *call; 435 ipc_callid_t callid; 436 446 /** Try to dispatch queued calls from the async queue. 447 * 448 */ 449 static void dispatch_queued_calls(void) 450 { 437 451 /** @todo 438 * Integrate intelligently ipc_futex ,so that it is locked during439 * ipc_call_async_*() ,until it is added to dispatched_calls.452 * Integrate intelligently ipc_futex so that it is locked during 453 * ipc_call_async_*() until it is added to dispatched_calls. 440 454 */ 455 441 456 futex_down(&async_futex); 457 442 458 while (!list_empty(&queued_calls)) { 443 call = list_get_instance(queued_calls.next, async_call_t, list); 444 callid = _ipc_call_async(call->u.msg.phoneid, 445 &call->u.msg.data); 446 if (callid == (ipc_callid_t) IPC_CALLRET_TEMPORARY) { 459 async_call_t *call = 460 list_get_instance(queued_calls.next, async_call_t, list); 461 ipc_callid_t callid = 462 ipc_call_async_internal(call->u.msg.phoneid, &call->u.msg.data); 463 464 if (callid == (ipc_callid_t) IPC_CALLRET_TEMPORARY) 447 465 break; 448 }466 449 467 list_remove(&call->list); 450 468 451 469 futex_up(&async_futex); 470 452 471 if (call->fid) 453 472 fibril_add_ready(call->fid); … … 456 475 if (call->callback) 457 476 call->callback(call->private, ENOENT, NULL); 477 458 478 free(call); 459 479 } else { 460 480 call->u.callid = callid; 481 461 482 futex_down(&ipc_futex); 462 483 list_append(&call->list, &dispatched_calls); 463 484 futex_up(&ipc_futex); 464 485 } 486 465 487 futex_down(&async_futex); 466 488 } 489 467 490 futex_up(&async_futex); 468 491 } 469 492 470 /** Handle areceived answer.493 /** Handle received answer. 471 494 * 472 495 * Find the hash of the answer and call the answer callback. 473 496 * 474 * @todo Make it use hash table. 475 * 476 * @param callid Hash of the received answer. 477 * The answer has the same hash as the request OR'ed with 478 * the IPC_CALLID_ANSWERED bit. 479 * @param data Call data of the answer. 497 * The answer has the same hash as the request OR'ed with 498 * the IPC_CALLID_ANSWERED bit. 499 * 500 * @todo Use hash table. 501 * 502 * @param callid Hash of the received answer. 503 * @param data Call data of the answer. 504 * 480 505 */ 481 506 static void handle_answer(ipc_callid_t callid, ipc_call_t *data) 482 507 { 508 callid &= ~IPC_CALLID_ANSWERED; 509 510 futex_down(&ipc_futex); 511 483 512 link_t *item; 484 async_call_t *call;485 486 callid &= ~IPC_CALLID_ANSWERED;487 488 futex_down(&ipc_futex);489 513 for (item = dispatched_calls.next; item != &dispatched_calls; 490 514 item = item->next) { 491 call = list_get_instance(item, async_call_t, list); 515 async_call_t *call = 516 list_get_instance(item, async_call_t, list); 517 492 518 if (call->u.callid == callid) { 493 519 list_remove(&call->list); 520 494 521 futex_up(&ipc_futex); 522 495 523 if (call->callback) 496 call->callback(call->private, 524 call->callback(call->private, 497 525 IPC_GET_RETVAL(*data), data); 526 498 527 free(call); 499 528 return; 500 529 } 501 530 } 531 502 532 futex_up(&ipc_futex); 503 533 } 504 534 505 506 /** Wait for a first call to come. 507 * 508 * @param call Storage where the incoming call data will be stored.509 * @param usec Timeout in microseconds510 * @param flags Flags passed to SYS_IPC_WAIT (blocking, nonblocking).511 * 512 * @return Hash of the call. Note that certain bits have special513 * meaning. IPC_CALLID_ANSWERED will be set in an answer514 * and IPC_CALLID_NOTIFICATION is used for notifications.515 * 516 */ 517 ipc_callid_t ipc_wait_cycle(ipc_call_t *call, uint32_t usec,int flags)518 { 519 ipc_callid_t callid ;520 521 callid = __SYSCALL3(SYS_IPC_WAIT, (sysarg_t) call, usec, flags);535 /** Wait for first IPC call to come. 536 * 537 * @param call Incoming call storage. 538 * @param usec Timeout in microseconds 539 * @param flags Flags passed to SYS_IPC_WAIT (blocking, nonblocking). 540 * 541 * @return Hash of the call. Note that certain bits have special 542 * meaning: IPC_CALLID_ANSWERED is set in an answer 543 * and IPC_CALLID_NOTIFICATION is used for notifications. 544 * 545 */ 546 ipc_callid_t ipc_wait_cycle(ipc_call_t *call, sysarg_t usec, 547 unsigned int flags) 548 { 549 ipc_callid_t callid = 550 __SYSCALL3(SYS_IPC_WAIT, (sysarg_t) call, usec, flags); 551 522 552 /* Handle received answers */ 523 553 if (callid & IPC_CALLID_ANSWERED) { 524 554 handle_answer(callid, call); 525 try_dispatch_queued_calls();555 dispatch_queued_calls(); 526 556 } 527 557 528 558 return callid; 529 559 } 530 560 531 /** Wait some time for an IPC call. 532 * 533 * The call will return after an answer is received. 534 * 535 * @param call Storage where the incoming call data will be stored. 536 * @param usec Timeout in microseconds. 537 * 538 * @return Hash of the answer. 539 */ 540 ipc_callid_t ipc_wait_for_call_timeout(ipc_call_t *call, uint32_t usec) 561 /** Interrupt one thread of this task from waiting for IPC. 562 * 563 */ 564 void ipc_poke(void) 565 { 566 __SYSCALL0(SYS_IPC_POKE); 567 } 568 569 /** Wait for first IPC call to come. 570 * 571 * Only requests are returned, answers are processed internally. 572 * 573 * @param call Incoming call storage. 574 * @param usec Timeout in microseconds 575 * 576 * @return Hash of the call. 577 * 578 */ 579 ipc_callid_t ipc_wait_for_call_timeout(ipc_call_t *call, sysarg_t usec) 541 580 { 542 581 ipc_callid_t callid; 543 582 544 583 do { 545 584 callid = ipc_wait_cycle(call, usec, SYNCH_FLAGS_NONE); 546 585 } while (callid & IPC_CALLID_ANSWERED); 547 586 548 587 return callid; 549 588 } … … 551 590 /** Check if there is an IPC call waiting to be picked up. 552 591 * 553 * @param call Storage where the incoming call will be stored. 554 * @return Hash of the answer. 592 * Only requests are returned, answers are processed internally. 593 * 594 * @param call Incoming call storage. 595 * 596 * @return Hash of the call. 597 * 555 598 */ 556 599 ipc_callid_t ipc_trywait_for_call(ipc_call_t *call) 557 600 { 558 601 ipc_callid_t callid; 559 602 560 603 do { 561 604 callid = ipc_wait_cycle(call, SYNCH_NO_TIMEOUT, 562 605 SYNCH_FLAGS_NON_BLOCKING); 563 606 } while (callid & IPC_CALLID_ANSWERED); 564 607 565 608 return callid; 566 609 } 567 610 568 /** Interrupt one thread of this task from waiting for IPC. */ 569 void ipc_poke(void) 570 { 571 __SYSCALL0(SYS_IPC_POKE); 572 } 573 574 /** Ask destination to do a callback connection. 575 * 576 * @param phoneid Phone handle used for contacting the other side. 577 * @param arg1 Service-defined argument. 578 * @param arg2 Service-defined argument. 579 * @param arg3 Service-defined argument. 580 * @param phonehash Storage where the library will store an opaque 581 * identifier of the phone that will be used for incoming 582 * calls. This identifier can be used for connection 583 * tracking. 584 * 585 * @return Zero on success or a negative error code. 586 */ 587 int ipc_connect_to_me(int phoneid, int arg1, int arg2, int arg3, 588 sysarg_t *phonehash) 611 /** Request callback connection. 612 * 613 * The @a taskhash and @a phonehash identifiers returned 614 * by the kernel can be used for connection tracking. 615 * 616 * @param phoneid Phone handle used for contacting the other side. 617 * @param arg1 User defined argument. 618 * @param arg2 User defined argument. 619 * @param arg3 User defined argument. 620 * @param taskhash Opaque identifier of the client task. 621 * @param phonehash Opaque identifier of the phone that will 622 * be used for incoming calls. 623 * 624 * @return Zero on success or a negative error code. 625 * 626 */ 627 int ipc_connect_to_me(int phoneid, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, 628 sysarg_t *taskhash, sysarg_t *phonehash) 589 629 { 590 630 return ipc_call_sync_3_5(phoneid, IPC_M_CONNECT_TO_ME, arg1, arg2, 591 arg3, NULL, NULL, NULL, NULL, phonehash); 592 } 593 594 /** Ask through phone for a new connection to some service. 595 * 596 * @param phoneid Phone handle used for contacting the other side. 597 * @param arg1 User defined argument. 598 * @param arg2 User defined argument. 599 * @param arg3 User defined argument. 600 * 601 * @return New phone handle on success or a negative error code. 602 */ 603 int ipc_connect_me_to(int phoneid, int arg1, int arg2, int arg3) 631 arg3, NULL, NULL, NULL, taskhash, phonehash); 632 } 633 634 /** Request new connection. 635 * 636 * @param phoneid Phone handle used for contacting the other side. 637 * @param arg1 User defined argument. 638 * @param arg2 User defined argument. 639 * @param arg3 User defined argument. 640 * 641 * @return New phone handle on success or a negative error code. 642 * 643 */ 644 int ipc_connect_me_to(int phoneid, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3) 604 645 { 605 646 sysarg_t newphid; 606 int res; 607 608 res = ipc_call_sync_3_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3, 647 int res = ipc_call_sync_3_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3, 609 648 NULL, NULL, NULL, NULL, &newphid); 610 649 if (res) 611 650 return res; 651 612 652 return newphid; 613 653 } 614 654 615 /** Ask through phone for a new connection to some service.655 /** Request new connection (blocking) 616 656 * 617 657 * If the connection is not available at the moment, the 618 * call will block. 619 * 620 * @param phoneid Phone handle used for contacting the other side. 621 * @param arg1 User defined argument. 622 * @param arg2 User defined argument. 623 * @param arg3 User defined argument. 624 * 625 * @return New phone handle on success or a negative error code. 626 */ 627 int ipc_connect_me_to_blocking(int phoneid, int arg1, int arg2, int arg3) 658 * call should block. This has to be, however, implemented 659 * on the server side. 660 * 661 * @param phoneid Phone handle used for contacting the other side. 662 * @param arg1 User defined argument. 663 * @param arg2 User defined argument. 664 * @param arg3 User defined argument. 665 * 666 * @return New phone handle on success or a negative error code. 667 * 668 */ 669 int ipc_connect_me_to_blocking(int phoneid, sysarg_t arg1, sysarg_t arg2, 670 sysarg_t arg3) 628 671 { 629 672 sysarg_t newphid; 630 int res; 631 632 res = ipc_call_sync_4_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3, 673 int res = ipc_call_sync_4_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3, 633 674 IPC_FLAG_BLOCKING, NULL, NULL, NULL, NULL, &newphid); 634 675 if (res) 635 676 return res; 677 636 678 return newphid; 637 679 } … … 639 681 /** Hang up a phone. 640 682 * 641 * @param phoneid Handle of the phone to be hung up. 642 * 643 * @return Zero on success or a negative error code. 683 * @param phoneid Handle of the phone to be hung up. 684 * 685 * @return Zero on success or a negative error code. 686 * 644 687 */ 645 688 int ipc_hangup(int phoneid) … … 648 691 } 649 692 650 /** Register IRQ notification.651 *652 * @param inr IRQ number.653 * @param devno Device number of the device generating inr.654 * @param method Use this method for notifying me.655 * @param ucode Top-half pseudocode handler.656 *657 * @return Value returned by the kernel.658 */659 int ipc_register_irq(int inr, int devno, int method, irq_code_t *ucode)660 {661 return __SYSCALL4(SYS_IPC_REGISTER_IRQ, inr, devno, method,662 (sysarg_t) ucode);663 }664 665 /** Unregister IRQ notification.666 *667 * @param inr IRQ number.668 * @param devno Device number of the device generating inr.669 *670 * @return Value returned by the kernel.671 */672 int ipc_unregister_irq(int inr, int devno)673 {674 return __SYSCALL2(SYS_IPC_UNREGISTER_IRQ, inr, devno);675 }676 677 693 /** Forward a received call to another destination. 694 * 695 * For non-system methods, the old method, arg1 and arg2 are rewritten 696 * by the new values. For system methods, the new method, arg1 and arg2 697 * are written to the old arg1, arg2 and arg3, respectivelly. Calls with 698 * immutable methods are forwarded verbatim. 678 699 * 679 700 * @param callid Hash of the call to forward. … … 686 707 * @return Zero on success or an error code. 687 708 * 688 * For non-system methods, the old method, arg1 and arg2 are rewritten by the 689 * new values. For system methods, the new method, arg1 and arg2 are written 690 * to the old arg1, arg2 and arg3, respectivelly. Calls with immutable 691 * methods are forwarded verbatim. 692 */ 693 int ipc_forward_fast(ipc_callid_t callid, int phoneid, int imethod, 694 sysarg_t arg1, sysarg_t arg2, int mode) 709 */ 710 int ipc_forward_fast(ipc_callid_t callid, int phoneid, sysarg_t imethod, 711 sysarg_t arg1, sysarg_t arg2, unsigned int mode) 695 712 { 696 713 return __SYSCALL6(SYS_IPC_FORWARD_FAST, callid, phoneid, imethod, arg1, … … 698 715 } 699 716 700 701 int ipc_forward_slow(ipc_callid_t callid, int phoneid, int imethod, 717 int ipc_forward_slow(ipc_callid_t callid, int phoneid, sysarg_t imethod, 702 718 sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5, 703 int mode)719 unsigned int mode) 704 720 { 705 721 ipc_call_t data; … … 712 728 IPC_SET_ARG5(data, arg5); 713 729 714 return __SYSCALL4(SYS_IPC_FORWARD_SLOW, callid, phoneid, (sysarg_t) &data, mode); 715 } 716 717 /** Wrapper for making IPC_M_SHARE_IN calls. 718 * 719 * @param phoneid Phone that will be used to contact the receiving side. 720 * @param dst Destination address space area base. 721 * @param size Size of the destination address space area. 722 * @param arg User defined argument. 723 * @param flags Storage where the received flags will be stored. Can be 724 * NULL. 725 * 726 * @return Zero on success or a negative error code from errno.h. 730 return __SYSCALL4(SYS_IPC_FORWARD_SLOW, callid, phoneid, (sysarg_t) &data, 731 mode); 732 } 733 734 /** Wrapper for IPC_M_SHARE_IN calls. 735 * 736 * @param phoneid Phone that will be used to contact the receiving side. 737 * @param dst Destination address space area base. 738 * @param size Size of the destination address space area. 739 * @param arg User defined argument. 740 * @param flags Storage for received flags. Can be NULL. 741 * 742 * @return Zero on success or a negative error code from errno.h. 743 * 727 744 */ 728 745 int ipc_share_in_start(int phoneid, void *dst, size_t size, sysarg_t arg, 729 int *flags)746 unsigned int *flags) 730 747 { 731 748 sysarg_t tmp_flags = 0; … … 734 751 735 752 if (flags) 736 *flags = tmp_flags;753 *flags = (unsigned int) tmp_flags; 737 754 738 755 return res; … … 741 758 /** Wrapper for answering the IPC_M_SHARE_IN calls. 742 759 * 743 * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ calls 744 * so that the user doesn't have to remember the meaning of each IPC argument. 745 * 746 * @param callid Hash of the IPC_M_DATA_READ call to answer. 747 * @param src Source address space base. 748 * @param flags Flags to be used for sharing. Bits can be only cleared. 749 * 750 * @return Zero on success or a value from @ref errno.h on failure. 751 */ 752 int ipc_share_in_finalize(ipc_callid_t callid, void *src, int flags) 760 * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ 761 * calls so that the user doesn't have to remember the meaning of each 762 * IPC argument. 763 * 764 * @param callid Hash of the IPC_M_DATA_READ call to answer. 765 * @param src Source address space base. 766 * @param flags Flags to be used for sharing. Bits can be only cleared. 767 * 768 * @return Zero on success or a value from @ref errno.h on failure. 769 * 770 */ 771 int ipc_share_in_finalize(ipc_callid_t callid, void *src, unsigned int flags) 753 772 { 754 773 return ipc_answer_2(callid, EOK, (sysarg_t) src, (sysarg_t) flags); 755 774 } 756 775 757 /** Wrapper for making IPC_M_SHARE_OUT calls. 758 * 759 * @param phoneid Phone that will be used to contact the receiving side. 760 * @param src Source address space area base address. 761 * @param flags Flags to be used for sharing. Bits can be only cleared. 762 * 763 * @return Zero on success or a negative error code from errno.h. 764 */ 765 int ipc_share_out_start(int phoneid, void *src, int flags) 776 /** Wrapper for IPC_M_SHARE_OUT calls. 777 * 778 * @param phoneid Phone that will be used to contact the receiving side. 779 * @param src Source address space area base address. 780 * @param flags Flags to be used for sharing. Bits can be only cleared. 781 * 782 * @return Zero on success or a negative error code from errno.h. 783 * 784 */ 785 int ipc_share_out_start(int phoneid, void *src, unsigned int flags) 766 786 { 767 787 return ipc_call_sync_3_0(phoneid, IPC_M_SHARE_OUT, (sysarg_t) src, 0, … … 771 791 /** Wrapper for answering the IPC_M_SHARE_OUT calls. 772 792 * 773 * This wrapper only makes it more comfortable to answer IPC_M_SHARE_OUT calls 774 * so that the user doesn't have to remember the meaning of each IPC argument. 775 * 776 * @param callid Hash of the IPC_M_DATA_WRITE call to answer. 777 * @param dst Destination address space area base address. 778 * 779 * @return Zero on success or a value from @ref errno.h on failure. 793 * This wrapper only makes it more comfortable to answer IPC_M_SHARE_OUT 794 * calls so that the user doesn't have to remember the meaning of each 795 * IPC argument. 796 * 797 * @param callid Hash of the IPC_M_DATA_WRITE call to answer. 798 * @param dst Destination address space area base address. 799 * 800 * @return Zero on success or a value from @ref errno.h on failure. 801 * 780 802 */ 781 803 int ipc_share_out_finalize(ipc_callid_t callid, void *dst) … … 784 806 } 785 807 786 787 /** Wrapper for making IPC_M_DATA_READ calls. 788 * 789 * @param phoneid Phone that will be used to contact the receiving side.790 * @param dst Address of the beginningof the destination buffer.791 * @param size Size of the destination buffer.792 * 793 * @return Zero on success or a negative error code from errno.h.808 /** Wrapper for IPC_M_DATA_READ calls. 809 * 810 * @param phoneid Phone that will be used to contact the receiving side. 811 * @param dst Address of the beginning of the destination buffer. 812 * @param size Size of the destination buffer. 813 * 814 * @return Zero on success or a negative error code from errno.h. 815 * 794 816 */ 795 817 int ipc_data_read_start(int phoneid, void *dst, size_t size) … … 801 823 /** Wrapper for answering the IPC_M_DATA_READ calls. 802 824 * 803 * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ calls 804 * so that the user doesn't have to remember the meaning of each IPC argument. 805 * 806 * @param callid Hash of the IPC_M_DATA_READ call to answer. 807 * @param src Source address for the IPC_M_DATA_READ call. 808 * @param size Size for the IPC_M_DATA_READ call. Can be smaller than 809 * the maximum size announced by the sender. 810 * 811 * @return Zero on success or a value from @ref errno.h on failure. 825 * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ 826 * calls so that the user doesn't have to remember the meaning of each 827 * IPC argument. 828 * 829 * @param callid Hash of the IPC_M_DATA_READ call to answer. 830 * @param src Source address for the IPC_M_DATA_READ call. 831 * @param size Size for the IPC_M_DATA_READ call. Can be smaller than 832 * the maximum size announced by the sender. 833 * 834 * @return Zero on success or a value from @ref errno.h on failure. 835 * 812 836 */ 813 837 int ipc_data_read_finalize(ipc_callid_t callid, const void *src, size_t size) … … 816 840 } 817 841 818 /** Wrapper for making IPC_M_DATA_WRITE calls. 819 * 820 * @param phoneid Phone that will be used to contact the receiving side. 821 * @param src Address of the beginning of the source buffer. 822 * @param size Size of the source buffer. 823 * 824 * @return Zero on success or a negative error code from errno.h. 842 /** Wrapper for IPC_M_DATA_WRITE calls. 843 * 844 * @param phoneid Phone that will be used to contact the receiving side. 845 * @param src Address of the beginning of the source buffer. 846 * @param size Size of the source buffer. 847 * 848 * @return Zero on success or a negative error code from errno.h. 849 * 825 850 */ 826 851 int ipc_data_write_start(int phoneid, const void *src, size_t size) … … 832 857 /** Wrapper for answering the IPC_M_DATA_WRITE calls. 833 858 * 834 * This wrapper only makes it more comfortable to answer IPC_M_DATA_WRITE calls 835 * so that the user doesn't have to remember the meaning of each IPC argument. 836 * 837 * @param callid Hash of the IPC_M_DATA_WRITE call to answer. 838 * @param dst Final destination address for the IPC_M_DATA_WRITE call. 839 * @param size Final size for the IPC_M_DATA_WRITE call. 840 * 841 * @return Zero on success or a value from @ref errno.h on failure. 859 * This wrapper only makes it more comfortable to answer IPC_M_DATA_WRITE 860 * calls so that the user doesn't have to remember the meaning of each 861 * IPC argument. 862 * 863 * @param callid Hash of the IPC_M_DATA_WRITE call to answer. 864 * @param dst Final destination address for the IPC_M_DATA_WRITE call. 865 * @param size Final size for the IPC_M_DATA_WRITE call. 866 * 867 * @return Zero on success or a value from @ref errno.h on failure. 868 * 842 869 */ 843 870 int ipc_data_write_finalize(ipc_callid_t callid, void *dst, size_t size) -
uspace/lib/c/generic/libc.c
r22027b6e r8b5690f 42 42 43 43 #include <libc.h> 44 #include <stdio.h> 45 #include <unistd.h> 46 #include <malloc.h> 44 #include <stdlib.h> 47 45 #include <tls.h> 48 #include <thread.h>49 46 #include <fibril.h> 50 #include <ipc/ipc.h> 51 #include <async.h> 52 #include <as.h> 47 #include <task.h> 53 48 #include <loader/pcb.h> 49 #include "private/libc.h" 50 #include "private/async.h" 51 #include "private/async_sess.h" 52 #include "private/malloc.h" 53 #include "private/io.h" 54 54 55 extern int main(int argc, char *argv[]); 56 57 void _exit(int status) 58 { 59 thread_exit(status); 60 } 55 static bool env_setup = false; 61 56 62 57 void __main(void *pcb_ptr) 63 58 { 64 59 /* Initialize user task run-time environment */ 65 __ heap_init();60 __malloc_init(); 66 61 __async_init(); 62 __async_sess_init(); 63 67 64 fibril_t *fibril = fibril_setup(); 65 if (fibril == NULL) 66 abort(); 67 68 68 __tcb_set(fibril->tcb); 69 69 … … 71 71 __pcb = (pcb_t *) pcb_ptr; 72 72 73 /* The basic run-time environment is setup */ 74 env_setup = true; 75 73 76 int argc; 74 77 char **argv; 75 78 76 /* Get command line arguments and initialize 77 standard input and output */ 79 /* 80 * Get command line arguments and initialize 81 * standard input and output 82 */ 78 83 if (__pcb == NULL) { 79 84 argc = 0; … … 87 92 } 88 93 89 /* Run main() and set task return value 90 according the result */ 91 (void) task_retval(main(argc, argv)); 94 /* 95 * Run main() and set task return value 96 * according the result 97 */ 98 int retval = main(argc, argv); 99 exit(retval); 92 100 } 93 101 94 void __exit(void)102 void exit(int status) 95 103 { 96 __stdio_done(); 97 fibril_teardown(__tcb_get()->fibril_data); 98 _exit(0); 104 if (env_setup) { 105 __stdio_done(); 106 task_retval(status); 107 fibril_teardown(__tcb_get()->fibril_data); 108 } 109 110 __SYSCALL1(SYS_TASK_EXIT, false); 111 112 /* Unreachable */ 113 while (1); 114 } 115 116 void abort(void) 117 { 118 __SYSCALL1(SYS_TASK_EXIT, true); 119 120 /* Unreachable */ 121 while (1); 99 122 } 100 123 -
uspace/lib/c/generic/loader.c
r22027b6e r8b5690f 33 33 */ 34 34 35 #include <ipc/ipc.h>36 35 #include <ipc/loader.h> 37 36 #include <ipc/services.h> 37 #include <ipc/ns.h> 38 38 #include <libc.h> 39 39 #include <task.h> … … 63 63 loader_t *loader_connect(void) 64 64 { 65 int phone_id = ipc_connect_me_to_blocking(PHONE_NS,SERVICE_LOAD, 0, 0);65 int phone_id = service_connect_blocking(SERVICE_LOAD, 0, 0); 66 66 if (phone_id < 0) 67 67 return NULL; … … 319 319 return rc; 320 320 321 ipc_hangup(ldr->phone_id);321 async_hangup(ldr->phone_id); 322 322 ldr->phone_id = 0; 323 323 return EOK; … … 337 337 void loader_abort(loader_t *ldr) 338 338 { 339 ipc_hangup(ldr->phone_id);339 async_hangup(ldr->phone_id); 340 340 ldr->phone_id = 0; 341 341 } -
uspace/lib/c/generic/malloc.c
r22027b6e r8b5690f 45 45 #include <futex.h> 46 46 #include <adt/gcdlcm.h> 47 #include "private/malloc.h" 47 48 48 49 /* Magic used in heap headers. */ … … 215 216 /** Initialize the heap allocator 216 217 * 217 * Find how much physical memory we have and create 218 * the heap management structures that mark the whole 219 * physical memory as a single free block. 220 * 221 */ 222 void __heap_init(void) 223 { 224 futex_down(&malloc_futex); 225 226 if (as_area_create((void *) &_heap, PAGE_SIZE, 227 AS_AREA_WRITE | AS_AREA_READ)) { 228 heap_pages = 1; 229 heap_start = (void *) ALIGN_UP((uintptr_t) &_heap, BASE_ALIGN); 230 heap_end = 231 (void *) ALIGN_DOWN(((uintptr_t) &_heap) + PAGE_SIZE, BASE_ALIGN); 232 233 /* Make the entire area one large block. */ 234 block_init(heap_start, heap_end - heap_start, true); 235 } 236 237 futex_up(&malloc_futex); 218 * Create initial heap memory area. This routine is 219 * only called from libc initialization, thus we do not 220 * take any locks. 221 * 222 */ 223 void __malloc_init(void) 224 { 225 if (!as_area_create((void *) &_heap, PAGE_SIZE, 226 AS_AREA_WRITE | AS_AREA_READ)) 227 abort(); 228 229 heap_pages = 1; 230 heap_start = (void *) ALIGN_UP((uintptr_t) &_heap, BASE_ALIGN); 231 heap_end = 232 (void *) ALIGN_DOWN(((uintptr_t) &_heap) + PAGE_SIZE, BASE_ALIGN); 233 234 /* Make the entire area one large block. */ 235 block_init(heap_start, heap_end - heap_start, true); 238 236 } 239 237 -
uspace/lib/c/generic/net/icmp_api.c
r22027b6e r8b5690f 41 41 #include <net/modules.h> 42 42 #include <net/ip_codes.h> 43 44 43 #include <async.h> 45 44 #include <sys/types.h> 46 45 #include <sys/time.h> 47 46 #include <errno.h> 48 49 #include <ipc/ipc.h>50 47 #include <ipc/services.h> 51 48 #include <ipc/icmp.h> -
uspace/lib/c/generic/net/icmp_common.c
r22027b6e r8b5690f 27 27 */ 28 28 29 /** @addtogroup libc 29 /** @addtogroup libc 30 30 * @{ 31 31 */ … … 38 38 #include <net/modules.h> 39 39 #include <net/icmp_common.h> 40 41 40 #include <ipc/services.h> 42 41 #include <ipc/icmp.h> 43 44 42 #include <sys/time.h> 45 43 #include <async.h> 46 44 47 /** Connect sto the ICMP module.45 /** Connect to the ICMP module. 48 46 * 49 * @param service The ICMP module service. Ignored parameter. 50 * @param[in] timeout The connection timeout in microseconds. No timeout if 51 * set to zero. 52 * @return The ICMP module phone on success. 53 * @return ETIMEOUT if the connection timeouted. 47 * @param[in] timeout Connection timeout in microseconds, zero 48 * for no timeout. 49 * 50 * @return ICMP module phone on success. 51 * @return ETIMEOUT if the connection timeouted. 52 * 54 53 */ 55 int icmp_connect_module(s ervices_t service, suseconds_t timeout)54 int icmp_connect_module(suseconds_t timeout) 56 55 { 57 int phone; 58 59 phone = connect_to_service_timeout(SERVICE_ICMP, timeout); 60 if (phone >= 0) 61 async_req_0_0(phone, NET_ICMP_INIT); 62 63 return phone; 56 return connect_to_service_timeout(SERVICE_ICMP, timeout); 64 57 } 65 58 -
uspace/lib/c/generic/net/modules.c
r22027b6e r8b5690f 32 32 33 33 /** @file 34 * Generic module functions implementation. 34 * Generic module functions implementation. 35 35 * 36 36 * @todo MAKE IT POSSIBLE TO REMOVE THIS FILE VIA EITHER REPLACING PART OF ITS … … 43 43 #include <errno.h> 44 44 #include <sys/time.h> 45 46 #include <ipc/ipc.h>47 45 #include <ipc/services.h> 48 49 46 #include <net/modules.h> 50 47 … … 52 49 #define MODULE_WAIT_TIME (10 * 1000) 53 50 54 /** Answer s thecall.55 * 56 * @param[in] callid The call identifier.57 * @param[in] result The message processing result.58 * @param[in] answer The message processing answer.59 * @param[in] answer_count The number of answer parameters.60 * /61 void 62 answer_call(ipc_callid_t callid, int result, ipc_call_t *answer,63 int answer_count)64 { 65 /* Choose the most efficient answerfunction */66 if ( answer || (!answer_count)) {67 switch ( answer_count) {51 /** Answer a call. 52 * 53 * @param[in] callid Call identifier. 54 * @param[in] result Message processing result. 55 * @param[in] answer Message processing answer. 56 * @param[in] count Number of answer parameters. 57 * 58 */ 59 void answer_call(ipc_callid_t callid, int result, ipc_call_t *answer, 60 size_t count) 61 { 62 /* Choose the most efficient function */ 63 if ((answer != NULL) || (count == 0)) { 64 switch (count) { 68 65 case 0: 69 ipc_answer_0(callid, (sysarg_t) result);66 async_answer_0(callid, (sysarg_t) result); 70 67 break; 71 68 case 1: 72 ipc_answer_1(callid, (sysarg_t) result,69 async_answer_1(callid, (sysarg_t) result, 73 70 IPC_GET_ARG1(*answer)); 74 71 break; 75 72 case 2: 76 ipc_answer_2(callid, (sysarg_t) result,73 async_answer_2(callid, (sysarg_t) result, 77 74 IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer)); 78 75 break; 79 76 case 3: 80 ipc_answer_3(callid, (sysarg_t) result,77 async_answer_3(callid, (sysarg_t) result, 81 78 IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer), 82 79 IPC_GET_ARG3(*answer)); 83 80 break; 84 81 case 4: 85 ipc_answer_4(callid, (sysarg_t) result,82 async_answer_4(callid, (sysarg_t) result, 86 83 IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer), 87 84 IPC_GET_ARG3(*answer), IPC_GET_ARG4(*answer)); … … 89 86 case 5: 90 87 default: 91 ipc_answer_5(callid, (sysarg_t) result,88 async_answer_5(callid, (sysarg_t) result, 92 89 IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer), 93 90 IPC_GET_ARG3(*answer), IPC_GET_ARG4(*answer), … … 137 134 sysarg_t arg3, async_client_conn_t client_receiver, suseconds_t timeout) 138 135 { 139 int rc;140 141 136 /* Connect to the needed service */ 142 137 int phone = connect_to_service_timeout(need, timeout); 143 138 if (phone >= 0) { 144 139 /* Request the bidirectional connection */ 145 sysarg_t phonehash; 146 147 rc = ipc_connect_to_me(phone, arg1, arg2, arg3, &phonehash); 140 int rc = async_connect_to_me(phone, arg1, arg2, arg3, client_receiver); 148 141 if (rc != EOK) { 149 ipc_hangup(phone);142 async_hangup(phone); 150 143 return rc; 151 144 } 152 async_new_connection(phonehash, 0, NULL, client_receiver);153 145 } 154 146 … … 228 220 } 229 221 230 /** Refreshes answer structure and parameters count. 231 * 232 * Erases all attributes. 233 * 234 * @param[in,out] answer The message processing answer structure. 235 * @param[in,out] answer_count The number of answer parameters. 236 */ 237 void refresh_answer(ipc_call_t *answer, int *answer_count) 238 { 239 if (answer_count) 240 *answer_count = 0; 241 242 if (answer) { 222 /** Refresh answer structure and argument count. 223 * 224 * Erase all arguments. 225 * 226 * @param[in,out] answer Message processing answer structure. 227 * @param[in,out] count Number of answer arguments. 228 * 229 */ 230 void refresh_answer(ipc_call_t *answer, size_t *count) 231 { 232 if (count != NULL) 233 *count = 0; 234 235 if (answer != NULL) { 243 236 IPC_SET_RETVAL(*answer, 0); 244 /* Just to be precise */245 237 IPC_SET_IMETHOD(*answer, 0); 246 238 IPC_SET_ARG1(*answer, 0); -
uspace/lib/c/generic/net/socket_client.c
r22027b6e r8b5690f 43 43 #include <stdlib.h> 44 44 #include <errno.h> 45 45 #include <task.h> 46 46 #include <ipc/services.h> 47 47 #include <ipc/socket.h> 48 49 48 #include <net/modules.h> 50 49 #include <net/in.h> … … 278 277 } 279 278 280 ipc_answer_0(callid, (sysarg_t) rc);279 async_answer_0(callid, (sysarg_t) rc); 281 280 goto loop; 282 281 } … … 687 686 688 687 /* Read address */ 689 ipc_data_read_start(socket->phone, cliaddr, *addrlen);688 async_data_read_start(socket->phone, cliaddr, *addrlen); 690 689 fibril_rwlock_write_unlock(&socket_globals.lock); 691 690 async_wait_for(message_id, &ipc_result); -
uspace/lib/c/generic/private/async.h
r22027b6e r8b5690f 33 33 */ 34 34 35 #ifndef LIBC_ ASYNC_PRIV_H_36 #define LIBC_ ASYNC_PRIV_H_35 #ifndef LIBC_PRIVATE_ASYNC_H_ 36 #define LIBC_PRIVATE_ASYNC_H_ 37 37 38 38 #include <adt/list.h> … … 51 51 /** If true, we have timed out. */ 52 52 bool occurred; 53 53 54 54 /** Expiration time. */ 55 55 struct timeval expires; … … 65 65 } wu_event_t; 66 66 67 68 67 /** Structures of this type represent a waiting fibril. */ 69 68 typedef struct { … … 73 72 /** If true, this fibril is currently active. */ 74 73 bool active; 75 74 76 75 /** Timeout wait data. */ 77 76 to_event_t to_event; … … 80 79 } awaiter_t; 81 80 82 extern void async_insert_timeout(awaiter_t *wd); 81 extern void __async_init(void); 82 extern void async_insert_timeout(awaiter_t *); 83 83 84 84 #endif -
uspace/lib/c/generic/private/async_sess.h
r22027b6e r8b5690f 1 1 /* 2 * Copyright (c) 20 06 Ondrej Palkovsky2 * Copyright (c) 2011 Martin Decky 3 3 * All rights reserved. 4 4 * … … 33 33 */ 34 34 35 #i nclude <stdio.h>36 # include <stdlib.h>35 #ifndef LIBC_PRIVATE_ASYNC_SESS_H_ 36 #define LIBC_PRIVATE_ASYNC_SESS_H_ 37 37 38 /* TODO 39 void errx(int __status, __const char *__format, ...) 40 { 41 _exit(0); 42 } 43 */ 38 extern void __async_sess_init(void); 39 40 #endif 44 41 45 42 /** @} -
uspace/lib/c/generic/private/io.h
r22027b6e r8b5690f 1 1 /* 2 * Copyright (c) 20 09 Lukas Mejdrech2 * Copyright (c) 2011 Martin Decky 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup ip29 /** @addtogroup libc 30 30 * @{ 31 31 */ 32 33 32 /** @file 34 * IP module functions.35 * The functions are used as IP module entry points.36 33 */ 37 34 38 #ifndef NET_IP_MODULE_H_39 #define NET_IP_MODULE_H_35 #ifndef LIBC_PRIVATE_IO_H_ 36 #define LIBC_PRIVATE_IO_H_ 40 37 41 #include < ipc/ipc.h>38 #include <vfs/vfs.h> 42 39 43 extern int ip_initialize(async_client_conn_t); 44 extern int ip_message_standalone(ipc_callid_t, ipc_call_t *, ipc_call_t *, 45 int *); 40 extern void __stdio_init(int filc, fdi_node_t *filv[]); 41 extern void __stdio_done(void); 46 42 47 43 #endif -
uspace/lib/c/generic/private/libc.h
r22027b6e r8b5690f 1 1 /* 2 * Copyright (c) 20 09 Lukas Mejdrech2 * Copyright (c) 2011 Martin Decky 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup arp29 /** @addtogroup libc 30 30 * @{ 31 31 */ 32 33 32 /** @file 34 * ARP module functions.35 * The functions are used as ARP module entry points.36 33 */ 37 34 38 #ifndef NET_ARP_MODULE_H_39 #define NET_ARP_MODULE_H_35 #ifndef LIBC_PRIVATE_LIBC_H_ 36 #define LIBC_PRIVATE_LIBC_H_ 40 37 41 #include <ipc/ipc.h> 42 #include <async.h> 43 44 extern int arp_initialize(async_client_conn_t); 45 extern int arp_message_standalone(ipc_callid_t, ipc_call_t *, ipc_call_t *, 46 int *); 38 extern int main(int, char *[]); 39 extern void __main(void *) __attribute__((noreturn)); 47 40 48 41 #endif -
uspace/lib/c/generic/private/thread.h
r22027b6e r8b5690f 1 1 /* 2 * Copyright (c) 20 08 Lukas Mejdrech2 * Copyright (c) 2011 Martin Decky 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup tcp29 /** @addtogroup libc 30 30 * @{ 31 31 */ 32 33 32 /** @file 34 * TCP module functions.35 * The functions are used as TCP module entry points.36 33 */ 37 34 38 #ifndef NET_TCP_MODULE_H_39 #define NET_TCP_MODULE_H_35 #ifndef LIBC_PRIVATE_THREAD_H_ 36 #define LIBC_PRIVATE_THREAD_H_ 40 37 41 #include <async.h> 42 #include <ipc/ipc.h> 38 #include <kernel/proc/uarg.h> 43 39 44 extern int tcp_initialize(async_client_conn_t); 45 extern int tcp_message_standalone(ipc_callid_t, ipc_call_t *, ipc_call_t *, 46 int *); 40 extern void __thread_entry(void); 41 extern void __thread_main(uspace_arg_t *); 47 42 48 43 #endif -
uspace/lib/c/generic/stats.c
r22027b6e r8b5690f 36 36 #include <stats.h> 37 37 #include <sysinfo.h> 38 #include <assert.h>39 38 #include <errno.h> 40 39 #include <stdio.h> 41 40 #include <inttypes.h> 41 #include <malloc.h> 42 42 43 43 #define SYSINFO_STATS_MAX_PATH 64 … … 71 71 (stats_cpu_t *) sysinfo_get_data("system.cpus", &size); 72 72 73 assert((size % sizeof(stats_cpu_t)) == 0); 73 if ((size % sizeof(stats_cpu_t)) != 0) { 74 if (stats_cpus != NULL) 75 free(stats_cpus); 76 *count = 0; 77 return NULL; 78 } 74 79 75 80 *count = size / sizeof(stats_cpu_t); … … 91 96 (stats_physmem_t *) sysinfo_get_data("system.physmem", &size); 92 97 93 assert((size == sizeof(stats_physmem_t)) || (size == 0)); 98 if (size != sizeof(stats_physmem_t)) { 99 if (stats_physmem != NULL) 100 free(stats_physmem); 101 return NULL; 102 } 94 103 95 104 return stats_physmem; … … 111 120 (stats_task_t *) sysinfo_get_data("system.tasks", &size); 112 121 113 assert((size % sizeof(stats_task_t)) == 0); 122 if ((size % sizeof(stats_task_t)) != 0) { 123 if (stats_tasks != NULL) 124 free(stats_tasks); 125 *count = 0; 126 return NULL; 127 } 114 128 115 129 *count = size / sizeof(stats_task_t); … … 135 149 (stats_task_t *) sysinfo_get_data(name, &size); 136 150 137 assert((size == sizeof(stats_task_t)) || (size == 0)); 151 if (size != sizeof(stats_task_t)) { 152 if (stats_task != NULL) 153 free(stats_task); 154 return NULL; 155 } 138 156 139 157 return stats_task; … … 155 173 (stats_thread_t *) sysinfo_get_data("system.threads", &size); 156 174 157 assert((size % sizeof(stats_thread_t)) == 0); 175 if ((size % sizeof(stats_thread_t)) != 0) { 176 if (stats_threads != NULL) 177 free(stats_threads); 178 *count = 0; 179 return NULL; 180 } 158 181 159 182 *count = size / sizeof(stats_thread_t); … … 179 202 (stats_thread_t *) sysinfo_get_data(name, &size); 180 203 181 assert((size == sizeof(stats_thread_t)) || (size == 0)); 204 if (size != sizeof(stats_thread_t)) { 205 if (stats_thread != NULL) 206 free(stats_thread); 207 return NULL; 208 } 182 209 183 210 return stats_thread; … … 199 226 (stats_exc_t *) sysinfo_get_data("system.exceptions", &size); 200 227 201 assert((size % sizeof(stats_exc_t)) == 0); 228 if ((size % sizeof(stats_exc_t)) != 0) { 229 if (stats_exceptions != NULL) 230 free(stats_exceptions); 231 *count = 0; 232 return NULL; 233 } 202 234 203 235 *count = size / sizeof(stats_exc_t); … … 217 249 { 218 250 char name[SYSINFO_STATS_MAX_PATH]; 219 snprintf(name, SYSINFO_STATS_MAX_PATH, "system.exceptions s.%u", excn);251 snprintf(name, SYSINFO_STATS_MAX_PATH, "system.exceptions.%u", excn); 220 252 221 253 size_t size = 0; … … 223 255 (stats_exc_t *) sysinfo_get_data(name, &size); 224 256 225 assert((size == sizeof(stats_exc_t)) || (size == 0)); 257 if (size != sizeof(stats_exc_t)) { 258 if (stats_exception != NULL) 259 free(stats_exception); 260 return NULL; 261 } 226 262 227 263 return stats_exception; … … 243 279 (load_t *) sysinfo_get_data("system.load", &size); 244 280 245 assert((size % sizeof(load_t)) == 0); 281 if ((size % sizeof(load_t)) != 0) { 282 if (load != NULL) 283 free(load); 284 *count = 0; 285 return NULL; 286 } 246 287 247 288 *count = size / sizeof(load_t); -
uspace/lib/c/generic/sysinfo.c
r22027b6e r8b5690f 96 96 void *sysinfo_get_data(const char *path, size_t *size) 97 97 { 98 /* The binary data size might change during time. 99 Unfortunatelly we cannot allocate the buffer 100 and transfer the data as a single atomic operation. 98 /* 99 * The binary data size might change during time. 100 * Unfortunatelly we cannot allocate the buffer 101 * and transfer the data as a single atomic operation. 102 */ 101 103 102 Let's hope that the number of iterations is bounded 103 in common cases. */ 104 105 void *data = NULL; 106 107 while (true) { 108 /* Get the binary data size */ 109 int ret = sysinfo_get_data_size(path, size); 110 if ((ret != EOK) || (size == 0)) { 111 /* Not a binary data item 112 or an empty item */ 113 break; 114 } 115 116 data = realloc(data, *size); 117 if (data == NULL) 118 break; 119 120 /* Get the data */ 121 ret = __SYSCALL4(SYS_SYSINFO_GET_DATA, (sysarg_t) path, 122 (sysarg_t) str_size(path), (sysarg_t) data, (sysarg_t) *size); 123 if (ret == EOK) 124 return data; 125 126 if (ret != ENOMEM) { 127 /* The failure to get the data was not caused 128 by wrong buffer size */ 129 break; 130 } 104 /* Get the binary data size */ 105 int ret = sysinfo_get_data_size(path, size); 106 if ((ret != EOK) || (size == 0)) { 107 /* 108 * Not a binary data item 109 * or an empty item. 110 */ 111 *size = 0; 112 return NULL; 131 113 } 132 114 133 if (data != NULL) 134 free(data); 115 void *data = malloc(*size); 116 if (data == NULL) { 117 *size = 0; 118 return NULL; 119 } 135 120 121 /* Get the data */ 122 size_t sz; 123 ret = __SYSCALL5(SYS_SYSINFO_GET_DATA, (sysarg_t) path, 124 (sysarg_t) str_size(path), (sysarg_t) data, (sysarg_t) *size, 125 (sysarg_t) &sz); 126 if (ret == EOK) { 127 *size = sz; 128 return data; 129 } 130 131 free(data); 136 132 *size = 0; 137 133 return NULL; -
uspace/lib/c/generic/thread.c
r22027b6e r8b5690f 31 31 */ 32 32 /** @file 33 */ 33 */ 34 34 35 35 #include <thread.h> … … 41 41 #include <str.h> 42 42 #include <async.h> 43 #include "private/thread.h" 43 44 44 45 #ifndef THREAD_INITIAL_STACK_PAGES_NO … … 50 51 * This function is called from __thread_entry() and is used 51 52 * to call the thread's implementing function and perform cleanup 52 * and exit when thread returns back. Do not call this function 53 * directly. 53 * and exit when thread returns back. 54 54 * 55 55 * @param uarg Pointer to userspace argument structure. 56 * 56 57 */ 57 58 void __thread_main(uspace_arg_t *uarg) 58 59 { 59 fibril_t *f; 60 61 f = fibril_setup(); 62 __tcb_set(f->tcb); 63 60 fibril_t *fibril = fibril_setup(); 61 if (fibril == NULL) 62 thread_exit(0); 63 64 __tcb_set(fibril->tcb); 65 64 66 uarg->uspace_thread_function(uarg->uspace_thread_arg); 65 /* XXX: we cannot free the userspace stack while running on it */ 66 // free(uarg->uspace_stack); 67 // free(uarg); 68 67 /* XXX: we cannot free the userspace stack while running on it 68 free(uarg->uspace_stack); 69 free(uarg); 70 */ 71 69 72 /* If there is a manager, destroy it */ 70 73 async_destroy_manager(); 71 fibril_teardown(f );72 74 fibril_teardown(fibril); 75 73 76 thread_exit(0); 74 77 } … … 127 130 * 128 131 * @param status Exit status. Currently not used. 132 * 129 133 */ 130 134 void thread_exit(int status) 131 135 { 132 136 __SYSCALL1(SYS_THREAD_EXIT, (sysarg_t) status); 133 for (;;) 134 ; 137 138 /* Unreachable */ 139 while (1); 135 140 } 136 141 -
uspace/lib/c/generic/time.c
r22027b6e r8b5690f 34 34 35 35 #include <sys/time.h> 36 #include <unistd.h> 37 #include <ipc/ipc.h> 38 #include <stdio.h> 36 #include <time.h> 37 #include <bool.h> 39 38 #include <arch/barrier.h> 40 #include <unistd.h> 41 #include <atomic.h> 42 #include <sysinfo.h> 43 #include <ipc/services.h> 44 #include <libc.h> 45 39 #include <macros.h> 40 #include <errno.h> 46 41 #include <sysinfo.h> 47 42 #include <as.h> 48 43 #include <ddi.h> 49 50 #include <time.h> 51 52 /* Pointers to public variables with time */ 44 #include <libc.h> 45 46 /** Pointer to kernel shared variables with time */ 53 47 struct { 54 48 volatile sysarg_t seconds1; … … 59 53 /** Add microseconds to given timeval. 60 54 * 61 * @param tv Destination timeval. 62 * @param usecs Number of microseconds to add. 55 * @param tv Destination timeval. 56 * @param usecs Number of microseconds to add. 57 * 63 58 */ 64 59 void tv_add(struct timeval *tv, suseconds_t usecs) … … 66 61 tv->tv_sec += usecs / 1000000; 67 62 tv->tv_usec += usecs % 1000000; 63 68 64 if (tv->tv_usec > 1000000) { 69 65 tv->tv_sec++; … … 74 70 /** Subtract two timevals. 75 71 * 76 * @param tv1 First timeval. 77 * @param tv2 Second timeval. 78 * 79 * @return Return difference between tv1 and tv2 (tv1 - tv2) in 80 * microseconds. 72 * @param tv1 First timeval. 73 * @param tv2 Second timeval. 74 * 75 * @return Difference between tv1 and tv2 (tv1 - tv2) in 76 * microseconds. 77 * 81 78 */ 82 79 suseconds_t tv_sub(struct timeval *tv1, struct timeval *tv2) 83 80 { 84 suseconds_t result; 85 86 result = tv1->tv_usec - tv2->tv_usec; 87 result += (tv1->tv_sec - tv2->tv_sec) * 1000000; 88 89 return result; 81 return (tv1->tv_usec - tv2->tv_usec) + 82 ((tv1->tv_sec - tv2->tv_sec) * 1000000); 90 83 } 91 84 92 85 /** Decide if one timeval is greater than the other. 93 86 * 94 * @param t1 First timeval. 95 * @param t2 Second timeval. 96 * 97 * @return Return true tv1 is greater than tv2. Otherwise return 98 * false. 87 * @param t1 First timeval. 88 * @param t2 Second timeval. 89 * 90 * @return True if tv1 is greater than tv2. 91 * @return False otherwise. 92 * 99 93 */ 100 94 int tv_gt(struct timeval *tv1, struct timeval *tv2) 101 95 { 102 96 if (tv1->tv_sec > tv2->tv_sec) 103 return 1; 104 if (tv1->tv_sec == tv2->tv_sec && tv1->tv_usec > tv2->tv_usec) 105 return 1; 106 return 0; 97 return true; 98 99 if ((tv1->tv_sec == tv2->tv_sec) && (tv1->tv_usec > tv2->tv_usec)) 100 return true; 101 102 return false; 107 103 } 108 104 109 105 /** Decide if one timeval is greater than or equal to the other. 110 106 * 111 * @param tv1 First timeval. 112 * @param tv2 Second timeval. 113 * 114 * @return Return true if tv1 is greater than or equal to tv2. 115 * Otherwise return false. 107 * @param tv1 First timeval. 108 * @param tv2 Second timeval. 109 * 110 * @return True if tv1 is greater than or equal to tv2. 111 * @return False otherwise. 112 * 116 113 */ 117 114 int tv_gteq(struct timeval *tv1, struct timeval *tv2) 118 115 { 119 116 if (tv1->tv_sec > tv2->tv_sec) 120 return 1; 121 if (tv1->tv_sec == tv2->tv_sec && tv1->tv_usec >= tv2->tv_usec) 122 return 1; 123 return 0; 124 } 125 126 127 /** POSIX gettimeofday 128 * 129 * The time variables are memory mapped(RO) from kernel, which updates 130 * them periodically. As it is impossible to read 2 values atomically, we 131 * use a trick: First read a seconds, then read microseconds, then 132 * read seconds again. If a second elapsed in the meantime, set it to zero. 133 * This provides assurance, that at least the 134 * sequence of subsequent gettimeofday calls is ordered. 117 return true; 118 119 if ((tv1->tv_sec == tv2->tv_sec) && (tv1->tv_usec >= tv2->tv_usec)) 120 return true; 121 122 return false; 123 } 124 125 /** Get time of day 126 * 127 * The time variables are memory mapped (read-only) from kernel which 128 * updates them periodically. 129 * 130 * As it is impossible to read 2 values atomically, we use a trick: 131 * First we read the seconds, then we read the microseconds, then we 132 * read the seconds again. If a second elapsed in the meantime, set 133 * the microseconds to zero. 134 * 135 * This assures that the values returned by two subsequent calls 136 * to gettimeofday() are monotonous. 137 * 135 138 */ 136 139 int gettimeofday(struct timeval *tv, struct timezone *tz) 137 140 { 138 void *mapping; 139 sysarg_t s1, s2; 140 int rights; 141 int res; 142 143 if (!ktime) { 144 mapping = as_get_mappable_page(PAGE_SIZE); 145 /* Get the mapping of kernel clock */ 146 res = ipc_share_in_start_1_1(PHONE_NS, mapping, PAGE_SIZE, 147 SERVICE_MEM_REALTIME, &rights); 148 if (res) { 149 printf("Failed to initialize timeofday memarea\n"); 150 _exit(1); 141 if (ktime == NULL) { 142 uintptr_t faddr; 143 int rc = sysinfo_get_value("clock.faddr", &faddr); 144 if (rc != EOK) { 145 errno = rc; 146 return -1; 151 147 } 152 if (!(rights & AS_AREA_READ)) {153 printf("Received bad rights on time area: %X\n",154 rights);155 as_area_destroy(mapping);156 _exit(1);148 149 void *addr = as_get_mappable_page(PAGE_SIZE); 150 if (addr == NULL) { 151 errno = ENOMEM; 152 return -1; 157 153 } 158 ktime = mapping; 159 } 154 155 rc = physmem_map((void *) faddr, addr, 1, 156 AS_AREA_READ | AS_AREA_CACHEABLE); 157 if (rc != EOK) { 158 as_area_destroy(addr); 159 errno = rc; 160 return -1; 161 } 162 163 ktime = addr; 164 } 165 160 166 if (tz) { 161 167 tz->tz_minuteswest = 0; 162 168 tz->tz_dsttime = DST_NONE; 163 169 } 164 165 s2 = ktime->seconds2; 170 171 sysarg_t s2 = ktime->seconds2; 172 166 173 read_barrier(); 167 174 tv->tv_usec = ktime->useconds; 175 168 176 read_barrier(); 169 s1 = ktime->seconds1; 177 sysarg_t s1 = ktime->seconds1; 178 170 179 if (s1 != s2) { 180 tv->tv_sec = max(s1, s2); 171 181 tv->tv_usec = 0; 172 tv->tv_sec = s1 > s2 ? s1 : s2;173 182 } else 174 183 tv->tv_sec = s1; 175 184 176 185 return 0; 177 186 } … … 180 189 { 181 190 struct timeval tv; 182 183 191 if (gettimeofday(&tv, NULL)) 184 192 return (time_t) -1; 193 185 194 if (tloc) 186 195 *tloc = tv.tv_sec; 196 187 197 return tv.tv_sec; 188 198 } 189 199 190 /** Wait unconditionally for specified number of microseconds */ 200 /** Wait unconditionally for specified number of microseconds 201 * 202 */ 191 203 int usleep(useconds_t usec) 192 204 { … … 195 207 } 196 208 197 /** Wait unconditionally for specified number of seconds */ 209 /** Wait unconditionally for specified number of seconds 210 * 211 */ 198 212 unsigned int sleep(unsigned int sec) 199 213 { 200 /* Sleep in 1000 second steps to support 201 full argument range */ 214 /* 215 * Sleep in 1000 second steps to support 216 * full argument range 217 */ 218 202 219 while (sec > 0) { 203 220 unsigned int period = (sec > 1000) ? 1000 : sec; 204 221 205 222 usleep(period * 1000000); 206 223 sec -= period; 207 224 } 225 208 226 return 0; 209 227 } -
uspace/lib/c/generic/udebug.c
r22027b6e r8b5690f 31 31 */ 32 32 /** @file 33 */ 33 */ 34 34 35 35 #include <udebug.h> 36 36 #include <sys/types.h> 37 #include <ipc/ipc.h>38 37 #include <async.h> 39 38 -
uspace/lib/c/generic/vfs/vfs.c
r22027b6e r8b5690f 1 1 /* 2 * Copyright (c) 2008 Jakub Jermar 2 * Copyright (c) 2008 Jakub Jermar 3 3 * All rights reserved. 4 4 * … … 43 43 #include <sys/stat.h> 44 44 #include <sys/types.h> 45 #include <ipc/ipc.h>46 45 #include <ipc/services.h> 46 #include <ipc/ns.h> 47 47 #include <async.h> 48 #include <atomic.h> 49 #include <futex.h> 48 #include <fibril_synch.h> 50 49 #include <errno.h> 50 #include <assert.h> 51 51 #include <str.h> 52 52 #include <devmap.h> … … 54 54 #include <ipc/devmap.h> 55 55 56 static async_sess_t vfs_session; 57 58 static FIBRIL_MUTEX_INITIALIZE(vfs_phone_mutex); 56 59 static int vfs_phone = -1; 57 static futex_t vfs_phone_futex = FUTEX_INITIALIZER; 58 static futex_t cwd_futex = FUTEX_INITIALIZER;60 61 static FIBRIL_MUTEX_INITIALIZE(cwd_mutex); 59 62 60 63 static int cwd_fd = -1; … … 67 70 char *ncwd_path_nc; 68 71 69 f utex_down(&cwd_futex);72 fibril_mutex_lock(&cwd_mutex); 70 73 size_t size = str_size(path); 71 74 if (*path != '/') { 72 75 if (!cwd_path) { 73 f utex_up(&cwd_futex);76 fibril_mutex_unlock(&cwd_mutex); 74 77 return NULL; 75 78 } 76 79 ncwd_path_nc = malloc(cwd_size + 1 + size + 1); 77 80 if (!ncwd_path_nc) { 78 f utex_up(&cwd_futex);81 fibril_mutex_unlock(&cwd_mutex); 79 82 return NULL; 80 83 } … … 85 88 ncwd_path_nc = malloc(size + 1); 86 89 if (!ncwd_path_nc) { 87 f utex_up(&cwd_futex);90 fibril_mutex_unlock(&cwd_mutex); 88 91 return NULL; 89 92 } … … 93 96 ncwd_path = canonify(ncwd_path_nc, retlen); 94 97 if (!ncwd_path) { 95 f utex_up(&cwd_futex);98 fibril_mutex_unlock(&cwd_mutex); 96 99 free(ncwd_path_nc); 97 100 return NULL; … … 105 108 free(ncwd_path_nc); 106 109 if (!ncwd_path) { 107 f utex_up(&cwd_futex);110 fibril_mutex_unlock(&cwd_mutex); 108 111 return NULL; 109 112 } 110 f utex_up(&cwd_futex);113 fibril_mutex_unlock(&cwd_mutex); 111 114 return ncwd_path; 112 115 } 113 116 117 /** Connect to VFS service and create session. */ 114 118 static void vfs_connect(void) 115 119 { 116 120 while (vfs_phone < 0) 117 vfs_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VFS, 0, 0); 121 vfs_phone = service_connect_blocking(SERVICE_VFS, 0, 0); 122 123 async_session_create(&vfs_session, vfs_phone, 0); 124 } 125 126 /** Start an async exchange on the VFS session. 127 * 128 * @return New phone to be used during the exchange. 129 */ 130 static int vfs_exchange_begin(void) 131 { 132 fibril_mutex_lock(&vfs_phone_mutex); 133 if (vfs_phone < 0) 134 vfs_connect(); 135 fibril_mutex_unlock(&vfs_phone_mutex); 136 137 return async_exchange_begin(&vfs_session); 138 } 139 140 /** End an async exchange on the VFS session. 141 * 142 * @param phone Phone used during the exchange. 143 */ 144 static void vfs_exchange_end(int phone) 145 { 146 async_exchange_end(&vfs_session, phone); 118 147 } 119 148 … … 154 183 } 155 184 156 futex_down(&vfs_phone_futex); 157 async_serialize_start(); 158 vfs_connect(); 159 185 int vfs_phone = vfs_exchange_begin(); 186 160 187 sysarg_t rc_orig; 161 188 aid_t req = async_send_2(vfs_phone, VFS_IN_MOUNT, devmap_handle, flags, NULL); 162 189 sysarg_t rc = async_data_write_start(vfs_phone, (void *) mpa, mpa_size); 163 190 if (rc != EOK) { 164 async_wait_for(req, &rc_orig); 165 async_serialize_end(); 166 futex_up(&vfs_phone_futex); 191 vfs_exchange_end(vfs_phone); 167 192 free(mpa); 193 async_wait_for(req, &rc_orig); 168 194 169 195 if (null_id != -1) … … 178 204 rc = async_data_write_start(vfs_phone, (void *) opts, str_size(opts)); 179 205 if (rc != EOK) { 180 async_wait_for(req, &rc_orig); 181 async_serialize_end(); 182 futex_up(&vfs_phone_futex); 206 vfs_exchange_end(vfs_phone); 183 207 free(mpa); 208 async_wait_for(req, &rc_orig); 184 209 185 210 if (null_id != -1) … … 194 219 rc = async_data_write_start(vfs_phone, (void *) fs_name, str_size(fs_name)); 195 220 if (rc != EOK) { 196 async_wait_for(req, &rc_orig); 197 async_serialize_end(); 198 futex_up(&vfs_phone_futex); 221 vfs_exchange_end(vfs_phone); 199 222 free(mpa); 223 async_wait_for(req, &rc_orig); 200 224 201 225 if (null_id != -1) … … 211 235 rc = async_req_0_0(vfs_phone, IPC_M_PING); 212 236 if (rc != EOK) { 213 async_wait_for(req, &rc_orig); 214 async_serialize_end(); 215 futex_up(&vfs_phone_futex); 237 vfs_exchange_end(vfs_phone); 216 238 free(mpa); 239 async_wait_for(req, &rc_orig); 217 240 218 241 if (null_id != -1) … … 225 248 } 226 249 227 async_wait_for(req, &rc); 228 async_serialize_end(); 229 futex_up(&vfs_phone_futex); 250 vfs_exchange_end(vfs_phone); 230 251 free(mpa); 252 async_wait_for(req, &rc); 231 253 232 254 if ((rc != EOK) && (null_id != -1)) … … 248 270 return ENOMEM; 249 271 250 futex_down(&vfs_phone_futex); 251 async_serialize_start(); 252 vfs_connect(); 272 int vfs_phone = vfs_exchange_begin(); 253 273 254 274 req = async_send_0(vfs_phone, VFS_IN_UNMOUNT, NULL); 255 275 rc = async_data_write_start(vfs_phone, (void *) mpa, mpa_size); 256 276 if (rc != EOK) { 257 async_wait_for(req, &rc_orig); 258 async_serialize_end(); 259 futex_up(&vfs_phone_futex); 277 vfs_exchange_end(vfs_phone); 260 278 free(mpa); 261 if (rc_orig == EOK) 262 return (int) rc; 263 else 264 return (int) rc_orig; 265 } 266 267 268 async_wait_for(req, &rc); 269 async_serialize_end(); 270 futex_up(&vfs_phone_futex); 279 async_wait_for(req, &rc_orig); 280 if (rc_orig == EOK) 281 return (int) rc; 282 else 283 return (int) rc_orig; 284 } 285 286 287 vfs_exchange_end(vfs_phone); 271 288 free(mpa); 289 async_wait_for(req, &rc); 272 290 273 291 return (int) rc; … … 276 294 static int open_internal(const char *abs, size_t abs_size, int lflag, int oflag) 277 295 { 278 futex_down(&vfs_phone_futex); 279 async_serialize_start(); 280 vfs_connect(); 296 int vfs_phone = vfs_exchange_begin(); 281 297 282 298 ipc_call_t answer; … … 285 301 286 302 if (rc != EOK) { 303 vfs_exchange_end(vfs_phone); 304 287 305 sysarg_t rc_orig; 288 306 async_wait_for(req, &rc_orig); 289 307 290 async_serialize_end(); 291 futex_up(&vfs_phone_futex); 292 293 if (rc_orig == EOK) 294 return (int) rc; 295 else 296 return (int) rc_orig; 297 } 298 299 async_wait_for(req, &rc); 300 async_serialize_end(); 301 futex_up(&vfs_phone_futex); 308 if (rc_orig == EOK) 309 return (int) rc; 310 else 311 return (int) rc_orig; 312 } 313 314 vfs_exchange_end(vfs_phone); 315 async_wait_for(req, &rc); 302 316 303 317 if (rc != EOK) … … 322 336 int open_node(fdi_node_t *node, int oflag) 323 337 { 324 futex_down(&vfs_phone_futex); 325 async_serialize_start(); 326 vfs_connect(); 338 int vfs_phone = vfs_exchange_begin(); 327 339 328 340 ipc_call_t answer; … … 330 342 node->devmap_handle, node->index, oflag, &answer); 331 343 332 sysarg_t rc;333 async_wait_for(req, &rc); 334 async_serialize_end();335 futex_up(&vfs_phone_futex);344 vfs_exchange_end(vfs_phone); 345 346 sysarg_t rc; 347 async_wait_for(req, &rc); 336 348 337 349 if (rc != EOK) … … 345 357 sysarg_t rc; 346 358 347 futex_down(&vfs_phone_futex); 348 async_serialize_start(); 349 vfs_connect(); 359 int vfs_phone = vfs_exchange_begin(); 350 360 351 361 rc = async_req_1_0(vfs_phone, VFS_IN_CLOSE, fildes); 352 362 353 async_serialize_end(); 354 futex_up(&vfs_phone_futex); 363 vfs_exchange_end(vfs_phone); 355 364 356 365 return (int)rc; … … 363 372 aid_t req; 364 373 365 futex_down(&vfs_phone_futex); 366 async_serialize_start(); 367 vfs_connect(); 374 int vfs_phone = vfs_exchange_begin(); 368 375 369 376 req = async_send_1(vfs_phone, VFS_IN_READ, fildes, &answer); 370 377 rc = async_data_read_start(vfs_phone, (void *)buf, nbyte); 371 378 if (rc != EOK) { 379 vfs_exchange_end(vfs_phone); 380 372 381 sysarg_t rc_orig; 373 374 async_wait_for(req, &rc_orig); 375 async_serialize_end(); 376 futex_up(&vfs_phone_futex); 382 async_wait_for(req, &rc_orig); 383 377 384 if (rc_orig == EOK) 378 385 return (ssize_t) rc; … … 380 387 return (ssize_t) rc_orig; 381 388 } 382 async_wait_for(req, &rc); 383 async_serialize_end(); 384 futex_up(&vfs_phone_futex); 389 vfs_exchange_end(vfs_phone); 390 async_wait_for(req, &rc); 385 391 if (rc == EOK) 386 392 return (ssize_t) IPC_GET_ARG1(answer); … … 395 401 aid_t req; 396 402 397 futex_down(&vfs_phone_futex); 398 async_serialize_start(); 399 vfs_connect(); 403 int vfs_phone = vfs_exchange_begin(); 400 404 401 405 req = async_send_1(vfs_phone, VFS_IN_WRITE, fildes, &answer); 402 406 rc = async_data_write_start(vfs_phone, (void *)buf, nbyte); 403 407 if (rc != EOK) { 408 vfs_exchange_end(vfs_phone); 409 404 410 sysarg_t rc_orig; 405 406 async_wait_for(req, &rc_orig); 407 async_serialize_end(); 408 futex_up(&vfs_phone_futex); 411 async_wait_for(req, &rc_orig); 412 409 413 if (rc_orig == EOK) 410 414 return (ssize_t) rc; … … 412 416 return (ssize_t) rc_orig; 413 417 } 414 async_wait_for(req, &rc); 415 async_serialize_end(); 416 futex_up(&vfs_phone_futex); 418 vfs_exchange_end(vfs_phone); 419 async_wait_for(req, &rc); 417 420 if (rc == EOK) 418 421 return (ssize_t) IPC_GET_ARG1(answer); … … 423 426 int fsync(int fildes) 424 427 { 425 futex_down(&vfs_phone_futex); 426 async_serialize_start(); 427 vfs_connect(); 428 int vfs_phone = vfs_exchange_begin(); 428 429 429 430 sysarg_t rc = async_req_1_0(vfs_phone, VFS_IN_SYNC, fildes); 430 431 431 async_serialize_end(); 432 futex_up(&vfs_phone_futex); 432 vfs_exchange_end(vfs_phone); 433 433 434 434 return (int) rc; … … 437 437 off64_t lseek(int fildes, off64_t offset, int whence) 438 438 { 439 futex_down(&vfs_phone_futex); 440 async_serialize_start(); 441 vfs_connect(); 439 int vfs_phone = vfs_exchange_begin(); 442 440 443 441 sysarg_t newoff_lo; … … 447 445 &newoff_lo, &newoff_hi); 448 446 449 async_serialize_end(); 450 futex_up(&vfs_phone_futex); 447 vfs_exchange_end(vfs_phone); 451 448 452 449 if (rc != EOK) … … 460 457 sysarg_t rc; 461 458 462 futex_down(&vfs_phone_futex); 463 async_serialize_start(); 464 vfs_connect(); 459 int vfs_phone = vfs_exchange_begin(); 465 460 466 461 rc = async_req_3_0(vfs_phone, VFS_IN_TRUNCATE, fildes, 467 462 LOWER32(length), UPPER32(length)); 468 async_serialize_end(); 469 futex_up(&vfs_phone_futex); 463 vfs_exchange_end(vfs_phone); 470 464 471 465 return (int) rc; … … 477 471 aid_t req; 478 472 479 futex_down(&vfs_phone_futex); 480 async_serialize_start(); 481 vfs_connect(); 473 int vfs_phone = vfs_exchange_begin(); 482 474 483 475 req = async_send_1(vfs_phone, VFS_IN_FSTAT, fildes, NULL); 484 476 rc = async_data_read_start(vfs_phone, (void *) stat, sizeof(struct stat)); 485 477 if (rc != EOK) { 478 vfs_exchange_end(vfs_phone); 479 486 480 sysarg_t rc_orig; 487 488 async_wait_for(req, &rc_orig); 489 async_serialize_end(); 490 futex_up(&vfs_phone_futex); 481 async_wait_for(req, &rc_orig); 482 491 483 if (rc_orig == EOK) 492 484 return (ssize_t) rc; … … 494 486 return (ssize_t) rc_orig; 495 487 } 496 async_wait_for(req, &rc); 497 async_serialize_end(); 498 futex_up(&vfs_phone_futex); 488 vfs_exchange_end(vfs_phone); 489 async_wait_for(req, &rc); 499 490 500 491 return rc; … … 512 503 return ENOMEM; 513 504 514 futex_down(&vfs_phone_futex); 515 async_serialize_start(); 516 vfs_connect(); 505 int vfs_phone = vfs_exchange_begin(); 517 506 518 507 req = async_send_0(vfs_phone, VFS_IN_STAT, NULL); 519 508 rc = async_data_write_start(vfs_phone, pa, pa_size); 520 509 if (rc != EOK) { 521 async_wait_for(req, &rc_orig); 522 async_serialize_end(); 523 futex_up(&vfs_phone_futex); 510 vfs_exchange_end(vfs_phone); 524 511 free(pa); 512 async_wait_for(req, &rc_orig); 525 513 if (rc_orig == EOK) 526 514 return (int) rc; … … 530 518 rc = async_data_read_start(vfs_phone, stat, sizeof(struct stat)); 531 519 if (rc != EOK) { 532 async_wait_for(req, &rc_orig); 533 async_serialize_end(); 534 futex_up(&vfs_phone_futex); 520 vfs_exchange_end(vfs_phone); 535 521 free(pa); 536 if (rc_orig == EOK) 537 return (int) rc; 538 else 539 return (int) rc_orig; 540 } 541 async_wait_for(req, &rc); 542 async_serialize_end(); 543 futex_up(&vfs_phone_futex); 522 async_wait_for(req, &rc_orig); 523 if (rc_orig == EOK) 524 return (int) rc; 525 else 526 return (int) rc_orig; 527 } 528 vfs_exchange_end(vfs_phone); 544 529 free(pa); 530 async_wait_for(req, &rc); 545 531 return rc; 546 532 } … … 601 587 return ENOMEM; 602 588 603 futex_down(&vfs_phone_futex); 604 async_serialize_start(); 605 vfs_connect(); 589 int vfs_phone = vfs_exchange_begin(); 606 590 607 591 req = async_send_1(vfs_phone, VFS_IN_MKDIR, mode, NULL); 608 592 rc = async_data_write_start(vfs_phone, pa, pa_size); 609 593 if (rc != EOK) { 594 vfs_exchange_end(vfs_phone); 595 free(pa); 596 610 597 sysarg_t rc_orig; 611 612 async_wait_for(req, &rc_orig); 613 async_serialize_end(); 614 futex_up(&vfs_phone_futex); 615 free(pa); 616 if (rc_orig == EOK) 617 return (int) rc; 618 else 619 return (int) rc_orig; 620 } 621 async_wait_for(req, &rc); 622 async_serialize_end(); 623 futex_up(&vfs_phone_futex); 598 async_wait_for(req, &rc_orig); 599 600 if (rc_orig == EOK) 601 return (int) rc; 602 else 603 return (int) rc_orig; 604 } 605 vfs_exchange_end(vfs_phone); 624 606 free(pa); 607 async_wait_for(req, &rc); 625 608 return rc; 626 609 } … … 636 619 return ENOMEM; 637 620 638 futex_down(&vfs_phone_futex); 639 async_serialize_start(); 640 vfs_connect(); 621 int vfs_phone = vfs_exchange_begin(); 641 622 642 623 req = async_send_0(vfs_phone, VFS_IN_UNLINK, NULL); 643 624 rc = async_data_write_start(vfs_phone, pa, pa_size); 644 625 if (rc != EOK) { 626 vfs_exchange_end(vfs_phone); 627 free(pa); 628 645 629 sysarg_t rc_orig; 646 647 async_wait_for(req, &rc_orig); 648 async_serialize_end(); 649 futex_up(&vfs_phone_futex); 650 free(pa); 651 if (rc_orig == EOK) 652 return (int) rc; 653 else 654 return (int) rc_orig; 655 } 656 async_wait_for(req, &rc); 657 async_serialize_end(); 658 futex_up(&vfs_phone_futex); 630 async_wait_for(req, &rc_orig); 631 632 if (rc_orig == EOK) 633 return (int) rc; 634 else 635 return (int) rc_orig; 636 } 637 vfs_exchange_end(vfs_phone); 659 638 free(pa); 639 async_wait_for(req, &rc); 660 640 return rc; 661 641 } … … 689 669 } 690 670 691 futex_down(&vfs_phone_futex); 692 async_serialize_start(); 693 vfs_connect(); 671 int vfs_phone = vfs_exchange_begin(); 694 672 695 673 req = async_send_0(vfs_phone, VFS_IN_RENAME, NULL); 696 674 rc = async_data_write_start(vfs_phone, olda, olda_size); 697 675 if (rc != EOK) { 698 async_wait_for(req, &rc_orig); 699 async_serialize_end(); 700 futex_up(&vfs_phone_futex); 676 vfs_exchange_end(vfs_phone); 701 677 free(olda); 702 678 free(newa); 679 async_wait_for(req, &rc_orig); 703 680 if (rc_orig == EOK) 704 681 return (int) rc; … … 708 685 rc = async_data_write_start(vfs_phone, newa, newa_size); 709 686 if (rc != EOK) { 710 async_wait_for(req, &rc_orig); 711 async_serialize_end(); 712 futex_up(&vfs_phone_futex); 687 vfs_exchange_end(vfs_phone); 713 688 free(olda); 714 689 free(newa); 715 if (rc_orig == EOK) 716 return (int) rc; 717 else 718 return (int) rc_orig; 719 } 720 async_wait_for(req, &rc); 721 async_serialize_end(); 722 futex_up(&vfs_phone_futex); 690 async_wait_for(req, &rc_orig); 691 if (rc_orig == EOK) 692 return (int) rc; 693 else 694 return (int) rc_orig; 695 } 696 vfs_exchange_end(vfs_phone); 723 697 free(olda); 724 698 free(newa); 699 async_wait_for(req, &rc); 725 700 return rc; 726 701 } … … 740 715 } 741 716 742 f utex_down(&cwd_futex);717 fibril_mutex_lock(&cwd_mutex); 743 718 744 719 if (cwd_fd >= 0) … … 753 728 cwd_size = abs_size; 754 729 755 f utex_up(&cwd_futex);730 fibril_mutex_unlock(&cwd_mutex); 756 731 return EOK; 757 732 } … … 762 737 return NULL; 763 738 764 f utex_down(&cwd_futex);739 fibril_mutex_lock(&cwd_mutex); 765 740 766 741 if ((cwd_size == 0) || (size < cwd_size + 1)) { 767 f utex_up(&cwd_futex);742 fibril_mutex_unlock(&cwd_mutex); 768 743 return NULL; 769 744 } 770 745 771 746 str_cpy(buf, size, cwd_path); 772 f utex_up(&cwd_futex);747 fibril_mutex_unlock(&cwd_mutex); 773 748 774 749 return buf; … … 806 781 int dup2(int oldfd, int newfd) 807 782 { 808 futex_down(&vfs_phone_futex); 809 async_serialize_start(); 810 vfs_connect(); 783 int vfs_phone = vfs_exchange_begin(); 811 784 812 785 sysarg_t ret; 813 786 sysarg_t rc = async_req_2_1(vfs_phone, VFS_IN_DUP, oldfd, newfd, &ret); 814 787 815 async_serialize_end(); 816 futex_up(&vfs_phone_futex); 788 vfs_exchange_end(vfs_phone); 817 789 818 790 if (rc == EOK) -
uspace/lib/c/include/adt/hash_table.h
r22027b6e r8b5690f 41 41 typedef unsigned long hash_count_t; 42 42 typedef unsigned long hash_index_t; 43 typedef struct hash_table hash_table_t; 44 typedef struct hash_table_operations hash_table_operations_t; 43 44 /** Set of operations for hash table. */ 45 typedef struct { 46 /** Hash function. 47 * 48 * @param key Array of keys needed to compute hash index. 49 * All keys must be passed. 50 * 51 * @return Index into hash table. 52 * 53 */ 54 hash_index_t (*hash)(unsigned long key[]); 55 56 /** Hash table item comparison function. 57 * 58 * @param key Array of keys that will be compared with item. It is 59 * not necessary to pass all keys. 60 * 61 * @return True if the keys match, false otherwise. 62 * 63 */ 64 int (*compare)(unsigned long key[], hash_count_t keys, link_t *item); 65 66 /** Hash table item removal callback. 67 * 68 * @param item Item that was removed from the hash table. 69 * 70 */ 71 void (*remove_callback)(link_t *item); 72 } hash_table_operations_t; 45 73 46 74 /** Hash table structure. */ 47 struct hash_table{75 typedef struct { 48 76 link_t *entry; 49 77 hash_count_t entries; 50 78 hash_count_t max_keys; 51 79 hash_table_operations_t *op; 52 }; 53 54 /** Set of operations for hash table. */ 55 struct hash_table_operations { 56 /** Hash function. 57 * 58 * @param key Array of keys needed to compute hash index. All keys 59 * must be passed. 60 * 61 * @return Index into hash table. 62 */ 63 hash_index_t (* hash)(unsigned long key[]); 64 65 /** Hash table item comparison function. 66 * 67 * @param key Array of keys that will be compared with item. It is 68 * not necessary to pass all keys. 69 * 70 * @return true if the keys match, false otherwise. 71 */ 72 int (*compare)(unsigned long key[], hash_count_t keys, link_t *item); 73 74 /** Hash table item removal callback. 75 * 76 * @param item Item that was removed from the hash table. 77 */ 78 void (*remove_callback)(link_t *item); 79 }; 80 } hash_table_t; 80 81 81 82 #define hash_table_get_instance(item, type, member) \ -
uspace/lib/c/include/async.h
r22027b6e r8b5690f 33 33 */ 34 34 35 #if ((defined(LIBC_IPC_H_)) && (!defined(LIBC_ASYNC_C_))) 36 #error Do not intermix low-level IPC interface and async framework 37 #endif 38 35 39 #ifndef LIBC_ASYNC_H_ 36 40 #define LIBC_ASYNC_H_ 37 41 38 #include <ipc/ ipc.h>42 #include <ipc/common.h> 39 43 #include <async_sess.h> 40 44 #include <fibril.h> … … 42 46 #include <atomic.h> 43 47 #include <bool.h> 48 #include <task.h> 44 49 45 50 typedef ipc_callid_t aid_t; 46 typedef void (*async_client_conn_t)(ipc_callid_t callid, ipc_call_t *call); 47 48 extern atomic_t async_futex; 51 52 typedef void *(*async_client_data_ctor_t)(void); 53 typedef void (*async_client_data_dtor_t)(void *); 54 55 typedef void (*async_client_conn_t)(ipc_callid_t, ipc_call_t *); 49 56 50 57 extern atomic_t threads_in_ipc_wait; 51 58 52 extern int __async_init(void); 53 extern ipc_callid_t async_get_call_timeout(ipc_call_t *call, suseconds_t usecs); 54 55 static inline ipc_callid_t async_get_call(ipc_call_t *data) 56 { 57 return async_get_call_timeout(data, 0); 58 } 59 60 static inline void async_manager(void) 61 { 62 fibril_switch(FIBRIL_TO_MANAGER); 63 } 59 #define async_manager() \ 60 fibril_switch(FIBRIL_TO_MANAGER) 61 62 #define async_get_call(data) \ 63 async_get_call_timeout(data, 0) 64 65 extern ipc_callid_t async_get_call_timeout(ipc_call_t *, suseconds_t); 64 66 65 67 /* … … 85 87 (arg5), (dataptr)) 86 88 87 extern aid_t async_send_fast(int phoneid, sysarg_t method, sysarg_t arg1, 88 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, ipc_call_t *dataptr); 89 extern aid_t async_send_slow(int phoneid, sysarg_t method, sysarg_t arg1, 90 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5, 91 ipc_call_t *dataptr); 92 extern void async_wait_for(aid_t amsgid, sysarg_t *result); 93 extern int async_wait_timeout(aid_t amsgid, sysarg_t *retval, 94 suseconds_t timeout); 95 96 extern fid_t async_new_connection(sysarg_t in_phone_hash, ipc_callid_t callid, 97 ipc_call_t *call, void (*cthread)(ipc_callid_t, ipc_call_t *)); 98 extern void async_usleep(suseconds_t timeout); 89 extern aid_t async_send_fast(int, sysarg_t, sysarg_t, sysarg_t, sysarg_t, 90 sysarg_t, ipc_call_t *); 91 extern aid_t async_send_slow(int, sysarg_t, sysarg_t, sysarg_t, sysarg_t, 92 sysarg_t, sysarg_t, ipc_call_t *); 93 extern void async_wait_for(aid_t, sysarg_t *); 94 extern int async_wait_timeout(aid_t, sysarg_t *, suseconds_t); 95 96 extern fid_t async_new_connection(sysarg_t, sysarg_t, ipc_callid_t, 97 ipc_call_t *, void (*)(ipc_callid_t, ipc_call_t *)); 98 extern void async_usleep(suseconds_t); 99 99 extern void async_create_manager(void); 100 100 extern void async_destroy_manager(void); 101 101 102 extern void async_set_client_connection(async_client_conn_t conn); 103 extern void async_set_interrupt_received(async_client_conn_t conn); 104 105 /* Wrappers for simple communication */ 106 #define async_msg_0(phone, method) \ 107 ipc_call_async_0((phone), (method), NULL, NULL, true) 108 #define async_msg_1(phone, method, arg1) \ 109 ipc_call_async_1((phone), (method), (arg1), NULL, NULL, \ 110 true) 111 #define async_msg_2(phone, method, arg1, arg2) \ 112 ipc_call_async_2((phone), (method), (arg1), (arg2), NULL, NULL, \ 113 true) 114 #define async_msg_3(phone, method, arg1, arg2, arg3) \ 115 ipc_call_async_3((phone), (method), (arg1), (arg2), (arg3), NULL, NULL, \ 116 true) 117 #define async_msg_4(phone, method, arg1, arg2, arg3, arg4) \ 118 ipc_call_async_4((phone), (method), (arg1), (arg2), (arg3), (arg4), NULL, \ 119 NULL, true) 120 #define async_msg_5(phone, method, arg1, arg2, arg3, arg4, arg5) \ 121 ipc_call_async_5((phone), (method), (arg1), (arg2), (arg3), (arg4), \ 122 (arg5), NULL, NULL, true) 102 extern void async_set_client_data_constructor(async_client_data_ctor_t); 103 extern void async_set_client_data_destructor(async_client_data_dtor_t); 104 105 extern void *async_client_data_get(void); 106 107 extern void async_set_client_connection(async_client_conn_t); 108 extern void async_set_interrupt_received(async_client_conn_t); 109 110 /* 111 * Wrappers for simple communication. 112 */ 113 114 extern void async_msg_0(int, sysarg_t); 115 extern void async_msg_1(int, sysarg_t, sysarg_t); 116 extern void async_msg_2(int, sysarg_t, sysarg_t, sysarg_t); 117 extern void async_msg_3(int, sysarg_t, sysarg_t, sysarg_t, sysarg_t); 118 extern void async_msg_4(int, sysarg_t, sysarg_t, sysarg_t, sysarg_t, sysarg_t); 119 extern void async_msg_5(int, sysarg_t, sysarg_t, sysarg_t, sysarg_t, sysarg_t, 120 sysarg_t); 121 122 /* 123 * Wrappers for answer routines. 124 */ 125 126 extern sysarg_t async_answer_0(ipc_callid_t, sysarg_t); 127 extern sysarg_t async_answer_1(ipc_callid_t, sysarg_t, sysarg_t); 128 extern sysarg_t async_answer_2(ipc_callid_t, sysarg_t, sysarg_t, sysarg_t); 129 extern sysarg_t async_answer_3(ipc_callid_t, sysarg_t, sysarg_t, sysarg_t, 130 sysarg_t); 131 extern sysarg_t async_answer_4(ipc_callid_t, sysarg_t, sysarg_t, sysarg_t, 132 sysarg_t, sysarg_t); 133 extern sysarg_t async_answer_5(ipc_callid_t, sysarg_t, sysarg_t, sysarg_t, 134 sysarg_t, sysarg_t, sysarg_t); 135 136 /* 137 * Wrappers for forwarding routines. 138 */ 139 140 extern int async_forward_fast(ipc_callid_t, int, sysarg_t, sysarg_t, sysarg_t, 141 unsigned int); 142 extern int async_forward_slow(ipc_callid_t, int, sysarg_t, sysarg_t, sysarg_t, 143 sysarg_t, sysarg_t, sysarg_t, unsigned int); 123 144 124 145 /* … … 128 149 * and slow verion based on m. 129 150 */ 151 130 152 #define async_req_0_0(phoneid, method) \ 131 153 async_req_fast((phoneid), (method), 0, 0, 0, 0, NULL, NULL, NULL, NULL, \ … … 243 265 (arg5), (rc1), (rc2), (rc3), (rc4), (rc5)) 244 266 245 extern sysarg_t async_req_fast(int phoneid, sysarg_t method, sysarg_t arg1, 246 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t *r1, sysarg_t *r2, 247 sysarg_t *r3, sysarg_t *r4, sysarg_t *r5); 248 extern sysarg_t async_req_slow(int phoneid, sysarg_t method, sysarg_t arg1, 249 sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5, sysarg_t *r1, 250 sysarg_t *r2, sysarg_t *r3, sysarg_t *r4, sysarg_t *r5); 267 extern sysarg_t async_req_fast(int, sysarg_t, sysarg_t, sysarg_t, sysarg_t, 268 sysarg_t, sysarg_t *, sysarg_t *, sysarg_t *, sysarg_t *, sysarg_t *); 269 extern sysarg_t async_req_slow(int, sysarg_t, sysarg_t, sysarg_t, sysarg_t, 270 sysarg_t, sysarg_t, sysarg_t *, sysarg_t *, sysarg_t *, sysarg_t *, 271 sysarg_t *); 251 272 252 273 static inline void async_serialize_start(void) … … 260 281 } 261 282 283 extern int async_connect_to_me(int, sysarg_t, sysarg_t, sysarg_t, 284 async_client_conn_t); 262 285 extern int async_connect_me_to(int, sysarg_t, sysarg_t, sysarg_t); 263 286 extern int async_connect_me_to_blocking(int, sysarg_t, sysarg_t, sysarg_t); 287 extern int async_connect_kbox(task_id_t); 288 extern int async_hangup(int); 289 extern void async_poke(void); 264 290 265 291 /* 266 292 * User-friendly wrappers for async_share_in_start(). 267 293 */ 294 268 295 #define async_share_in_start_0_0(phoneid, dst, size) \ 269 296 async_share_in_start((phoneid), (dst), (size), 0, NULL) … … 275 302 async_share_in_start((phoneid), (dst), (size), (arg), (flags)) 276 303 277 extern int async_share_in_start(int, void *, size_t, sysarg_t, int *); 278 extern int async_share_in_receive(ipc_callid_t *, size_t *); 279 extern int async_share_in_finalize(ipc_callid_t, void *, int ); 280 extern int async_share_out_start(int, void *, int); 281 extern int async_share_out_receive(ipc_callid_t *, size_t *, int *); 304 extern int async_share_in_start(int, void *, size_t, sysarg_t, unsigned int *); 305 extern bool async_share_in_receive(ipc_callid_t *, size_t *); 306 extern int async_share_in_finalize(ipc_callid_t, void *, unsigned int); 307 308 extern int async_share_out_start(int, void *, unsigned int); 309 extern bool async_share_out_receive(ipc_callid_t *, size_t *, unsigned int *); 282 310 extern int async_share_out_finalize(ipc_callid_t, void *); 283 311 … … 285 313 * User-friendly wrappers for async_data_read_forward_fast(). 286 314 */ 315 287 316 #define async_data_read_forward_0_0(phoneid, method, answer) \ 288 317 async_data_read_forward_fast((phoneid), (method), 0, 0, 0, 0, NULL) … … 312 341 313 342 extern int async_data_read_start(int, void *, size_t); 314 extern intasync_data_read_receive(ipc_callid_t *, size_t *);343 extern bool async_data_read_receive(ipc_callid_t *, size_t *); 315 344 extern int async_data_read_finalize(ipc_callid_t, const void *, size_t); 316 345 … … 321 350 * User-friendly wrappers for async_data_write_forward_fast(). 322 351 */ 352 323 353 #define async_data_write_forward_0_0(phoneid, method, answer) \ 324 354 async_data_write_forward_fast((phoneid), (method), 0, 0, 0, 0, NULL) … … 350 380 351 381 extern int async_data_write_start(int, const void *, size_t); 352 extern intasync_data_write_receive(ipc_callid_t *, size_t *);382 extern bool async_data_write_receive(ipc_callid_t *, size_t *); 353 383 extern int async_data_write_finalize(ipc_callid_t, void *, size_t); 354 384 355 385 extern int async_data_write_accept(void **, const bool, const size_t, 356 386 const size_t, const size_t, size_t *); 357 extern void async_data_write_void( const int);387 extern void async_data_write_void(sysarg_t); 358 388 359 389 extern int async_data_write_forward_fast(int, sysarg_t, sysarg_t, sysarg_t, -
uspace/lib/c/include/async_sess.h
r22027b6e r8b5690f 45 45 } async_sess_t; 46 46 47 extern void _async_sess_init(void);48 47 extern void async_session_create(async_sess_t *, int, sysarg_t); 49 48 extern void async_session_destroy(async_sess_t *); -
uspace/lib/c/include/byteorder.h
r22027b6e r8b5690f 80 80 #endif 81 81 82 #define htons(n) 83 #define htonl(n) 84 #define ntohs(n) 85 #define ntohl(n) 82 #define htons(n) host2uint16_t_be((n)) 83 #define htonl(n) host2uint32_t_be((n)) 84 #define ntohs(n) uint16_t_be2host((n)) 85 #define ntohl(n) uint32_t_be2host((n)) 86 86 87 87 static inline uint64_t uint64_t_byteorder_swap(uint64_t n) -
uspace/lib/c/include/ddi.h
r22027b6e r8b5690f 36 36 #define LIBC_DDI_H_ 37 37 38 #include <sys/types.h> 39 #include <kernel/ddi/irq.h> 38 40 #include <task.h> 39 41 … … 42 44 extern int iospace_enable(task_id_t, void *, unsigned long); 43 45 extern int pio_enable(void *, size_t, void **); 44 extern int interrupt_enable(int);45 extern int interrupt_disable(int);46 extern int register_irq(int, int, int, irq_code_t *); 47 extern int unregister_irq(int, int); 46 48 47 49 #endif -
uspace/lib/c/include/devman.h
r22027b6e r8b5690f 41 41 #include <bool.h> 42 42 43 44 43 extern int devman_get_phone(devman_interface_t, unsigned int); 45 44 extern void devman_hangup_phone(devman_interface_t); -
uspace/lib/c/include/err.h
r22027b6e r8b5690f 39 39 40 40 #define errx(status, fmt, ...) \ 41 { \41 do { \ 42 42 printf((fmt), ##__VA_ARGS__); \ 43 _exit(status); \44 } 43 exit(status); \ 44 } while (0) 45 45 46 46 #endif -
uspace/lib/c/include/errno.h
r22027b6e r8b5690f 39 39 #include <fibril.h> 40 40 41 #define errno _errno 42 41 43 extern int _errno; 42 43 #define errno _errno44 44 45 45 #define EMFILE (-18) … … 57 57 58 58 /** An API function is called while another blocking function is in progress. */ 59 #define EINPROGRESS 59 #define EINPROGRESS (-10036) 60 60 61 61 /** The socket identifier is not valid. */ 62 #define ENOTSOCK 62 #define ENOTSOCK (-10038) 63 63 64 64 /** The destination address required. */ 65 #define EDESTADDRREQ 65 #define EDESTADDRREQ (-10039) 66 66 67 67 /** Protocol is not supported. */ 68 #define EPROTONOSUPPORT 68 #define EPROTONOSUPPORT (-10043) 69 69 70 70 /** Socket type is not supported. */ 71 #define ESOCKTNOSUPPORT 71 #define ESOCKTNOSUPPORT (-10044) 72 72 73 73 /** Protocol family is not supported. */ 74 #define EPFNOSUPPORT 74 #define EPFNOSUPPORT (-10046) 75 75 76 76 /** Address family is not supported. */ 77 #define EAFNOSUPPORT 77 #define EAFNOSUPPORT (-10047) 78 78 79 79 /** Address is already in use. */ 80 #define EADDRINUSE 80 #define EADDRINUSE (-10048) 81 81 82 82 /** The socket is not connected or bound. */ 83 #define ENOTCONN 83 #define ENOTCONN (-10057) 84 84 85 85 /** The requested operation was not performed. Try again later. */ 86 #define EAGAIN 86 #define EAGAIN (-11002) 87 87 88 /** No data. 89 */ 90 #define NO_DATA (-11004) 88 /** No data. */ 89 #define NO_DATA (-11004) 91 90 92 91 #endif -
uspace/lib/c/include/event.h
r22027b6e r8b5690f 37 37 38 38 #include <kernel/ipc/event_types.h> 39 #include <ipc/ipc.h>40 39 41 40 extern int event_subscribe(event_type_t, sysarg_t); -
uspace/lib/c/include/io/console.h
r22027b6e r8b5690f 36 36 #define LIBC_IO_CONSOLE_H_ 37 37 38 #include <ipc/ipc.h>39 38 #include <bool.h> 40 39 -
uspace/lib/c/include/io/screenbuffer.h
r22027b6e r8b5690f 38 38 #include <stdint.h> 39 39 #include <sys/types.h> 40 #include <ipc/ipc.h>41 40 #include <bool.h> 42 41 -
uspace/lib/c/include/ipc/adb.h
r22027b6e r8b5690f 32 32 /** @file 33 33 * @brief ADB device interface. 34 */ 34 */ 35 35 36 36 #ifndef LIBC_IPC_ADB_H_ 37 37 #define LIBC_IPC_ADB_H_ 38 38 39 #include <ipc/ ipc.h>39 #include <ipc/common.h> 40 40 41 41 typedef enum { 42 42 ADB_REG_WRITE = IPC_FIRST_USER_METHOD 43 43 } adb_request_t; 44 45 44 46 45 typedef enum { -
uspace/lib/c/include/ipc/arp.h
r22027b6e r8b5690f 39 39 #define LIBC_ARP_MESSAGES_ 40 40 41 #include <ipc/ipc.h>42 41 #include <ipc/net.h> 43 42 … … 69 68 /*@{*/ 70 69 71 /** Returns the protocol service message parameter. 72 * @param[in] call The message call structure. 70 /** Return the protocol service message parameter. 71 * 72 * @param[in] call Message call structure. 73 * 73 74 */ 74 #define ARP_GET_NETIF(call) \ 75 ({ \ 76 services_t service = (services_t) IPC_GET_ARG2(*call); \ 77 service; \ 78 }) 75 #define ARP_GET_NETIF(call) ((services_t) IPC_GET_ARG2(call)) 79 76 80 77 /*@}*/ -
uspace/lib/c/include/ipc/bd.h
r22027b6e r8b5690f 31 31 */ 32 32 /** @file 33 */ 33 */ 34 34 35 35 #ifndef LIBC_IPC_BD_H_ 36 36 #define LIBC_IPC_BD_H_ 37 37 38 #include <ipc/ ipc.h>38 #include <ipc/common.h> 39 39 40 40 typedef enum { -
uspace/lib/c/include/ipc/char.h
r22027b6e r8b5690f 32 32 /** @file 33 33 * @brief Character device interface. 34 */ 34 */ 35 35 36 36 #ifndef LIBC_IPC_CHAR_H_ 37 37 #define LIBC_IPC_CHAR_H_ 38 38 39 #include <ipc/ ipc.h>39 #include <ipc/common.h> 40 40 41 41 typedef enum { 42 42 CHAR_WRITE_BYTE = IPC_FIRST_USER_METHOD 43 43 } char_request_t; 44 45 44 46 45 typedef enum { -
uspace/lib/c/include/ipc/clipboard.h
r22027b6e r8b5690f 36 36 #define LIBC_IPC_CLIPBOARD_H_ 37 37 38 #include <ipc/ipc.h>39 40 38 typedef enum { 41 39 CLIPBOARD_PUT_DATA = IPC_FIRST_USER_METHOD, -
uspace/lib/c/include/ipc/common.h
r22027b6e r8b5690f 1 1 /* 2 * Copyright (c) 20 08 Lukas Mejdrech2 * Copyright (c) 2011 Martin Decky 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup icmp29 /** @addtogroup libcipc 30 30 * @{ 31 31 */ 32 33 32 /** @file 34 * ICMP module functions.35 * The functions are used as ICMP module entry points.36 33 */ 37 34 38 #ifndef NET_ICMP_MODULE_H_39 #define NET_ICMP_MODULE_H_35 #ifndef LIBC_IPC_COMMON_H_ 36 #define LIBC_IPC_COMMON_H_ 40 37 41 #include <async.h> 42 #include <ipc/ipc.h> 38 #include <sys/types.h> 39 #include <atomic.h> 40 #include <kernel/ipc/ipc.h> 43 41 44 extern int icmp_initialize(async_client_conn_t); 45 extern int icmp_message_standalone(ipc_callid_t, ipc_call_t *, ipc_call_t *, 46 int *); 42 #define IPC_FLAG_BLOCKING 0x01 43 44 typedef struct { 45 sysarg_t args[IPC_CALL_LEN]; 46 sysarg_t in_task_hash; 47 sysarg_t in_phone_hash; 48 } ipc_call_t; 49 50 typedef sysarg_t ipc_callid_t; 51 52 extern atomic_t async_futex; 47 53 48 54 #endif -
uspace/lib/c/include/ipc/console.h
r22027b6e r8b5690f 36 36 #define LIBC_IPC_CONSOLE_H_ 37 37 38 #include <ipc/ipc.h>39 38 #include <ipc/vfs.h> 40 39 -
uspace/lib/c/include/ipc/dev_iface.h
r22027b6e r8b5690f 30 30 #define LIBC_IPC_DEV_IFACE_H_ 31 31 32 #include <ipc/ipc.h>33 32 #include <malloc.h> 34 33 #include <unistd.h> -
uspace/lib/c/include/ipc/devman.h
r22027b6e r8b5690f 30 30 * @{ 31 31 */ 32 32 33 33 #ifndef LIBC_IPC_DEVMAN_H_ 34 34 #define LIBC_IPC_DEVMAN_H_ 35 35 36 #include <ipc/common.h> 36 37 #include <adt/list.h> 37 #include <ipc/ipc.h> 38 #include <stdlib.h> 39 #include <stdio.h> 40 #include <str.h> 38 #include <malloc.h> 39 #include <mem.h> 41 40 42 #define DEVMAN_NAME_MAXLEN 25641 #define DEVMAN_NAME_MAXLEN 256 43 42 44 43 typedef sysarg_t devman_handle_t; … … 67 66 } match_id_list_t; 68 67 69 70 static inline match_id_t * create_match_id() 68 static inline match_id_t *create_match_id(void) 71 69 { 72 70 match_id_t *id = malloc(sizeof(match_id_t)); … … 85 83 } 86 84 87 static inline void add_match_id(match_id_list_t *ids, match_id_t *id) 85 static inline void add_match_id(match_id_list_t *ids, match_id_t *id) 88 86 { 89 87 match_id_t *mid = NULL; 90 link_t *link = ids->ids.next; 88 link_t *link = ids->ids.next; 91 89 92 90 while (link != &ids->ids) { … … 98 96 } 99 97 100 list_insert_before(&id->link, link); 98 list_insert_before(&id->link, link); 101 99 } 102 100 -
uspace/lib/c/include/ipc/devmap.h
r22027b6e r8b5690f 34 34 #define DEVMAP_DEVMAP_H_ 35 35 36 #include <atomic.h> 37 #include <ipc/ipc.h> 38 #include <adt/list.h> 36 #include <ipc/common.h> 39 37 40 38 #define DEVMAP_NAME_MAXLEN 255 -
uspace/lib/c/include/ipc/fb.h
r22027b6e r8b5690f 31 31 */ 32 32 /** @file 33 */ 33 */ 34 34 35 35 #ifndef LIBC_FB_H_ 36 36 #define LIBC_FB_H_ 37 37 38 #include <ipc/ ipc.h>38 #include <ipc/common.h> 39 39 40 40 typedef enum { -
uspace/lib/c/include/ipc/icmp.h
r22027b6e r8b5690f 33 33 /** @file 34 34 * ICMP module messages. 35 * @see icmp_ interface.h35 * @see icmp_remote.h 36 36 */ 37 37 … … 39 39 #define LIBC_ICMP_MESSAGES_ 40 40 41 #include <ipc/ipc.h>42 41 #include <ipc/net.h> 43 42 #include <sys/types.h> 44 43 #include <sys/time.h> 45 46 44 #include <net/icmp_codes.h> 47 45 48 46 /** ICMP module messages. */ 49 47 typedef enum { 50 /** Send secho request. @see icmp_echo() */48 /** Send echo request. @see icmp_echo() */ 51 49 NET_ICMP_ECHO = NET_ICMP_FIRST, 52 50 53 51 /** 54 * Send sdestination unreachable error message.52 * Send destination unreachable error message. 55 53 * @see icmp_destination_unreachable_msg() 56 54 */ … … 58 56 59 57 /** 60 * Send ssource quench error message.58 * Send source quench error message. 61 59 * @see icmp_source_quench_msg() 62 60 */ … … 64 62 65 63 /** 66 * Send stime exceeded error message.64 * Send time exceeded error message. 67 65 * @see icmp_time_exceeded_msg() 68 66 */ … … 70 68 71 69 /** 72 * Send sparameter problem error message.70 * Send parameter problem error message. 73 71 * @see icmp_parameter_problem_msg() 74 72 */ 75 NET_ICMP_PARAMETERPROB, 76 77 /** Initializes new connection. */ 78 NET_ICMP_INIT 79 } icmp_messages; 73 NET_ICMP_PARAMETERPROB 74 } icmp_messages_t; 80 75 81 76 /** @name ICMP specific message parameters definitions */ 82 77 /*@{*/ 83 78 84 /** Return sthe ICMP code message parameter.79 /** Return the ICMP code message parameter. 85 80 * 86 * @param[in] call The message call structure. 81 * @param[in] call Message call structure. 82 * 87 83 */ 88 #define ICMP_GET_CODE(call) \ 89 ({ \ 90 icmp_code_t code = (icmp_code_t) IPC_GET_ARG1(*call); \ 91 code; \ 92 }) 84 #define ICMP_GET_CODE(call) ((icmp_code_t) IPC_GET_ARG1(call)) 93 85 94 /** Return sthe ICMP link MTU message parameter.86 /** Return the ICMP link MTU message parameter. 95 87 * 96 * @param[in] call The message call structure. 88 * @param[in] call Message call structure. 89 * 97 90 */ 98 #define ICMP_GET_MTU(call) \ 99 ({ \ 100 icmp_param_t mtu = (icmp_param_t) IPC_GET_ARG3(*call); \ 101 mtu; \ 102 }) 91 #define ICMP_GET_MTU(call) ((icmp_param_t) IPC_GET_ARG3(call)) 103 92 104 /** Return sthe pointer message parameter.93 /** Return the pointer message parameter. 105 94 * 106 * @param[in] call The message call structure. 95 * @param[in] call Message call structure. 96 * 107 97 */ 108 #define ICMP_GET_POINTER(call) \ 109 ({ \ 110 icmp_param_t pointer = (icmp_param_t) IPC_GET_ARG3(*call); \ 111 pointer; \ 112 }) 98 #define ICMP_GET_POINTER(call) ((icmp_param_t) IPC_GET_ARG3(call)) 113 99 114 /** Return sthe size message parameter.100 /** Return the size message parameter. 115 101 * 116 * @param[in] call The message call structure. 102 * @param[in] call Message call structure. 103 * 117 104 */ 118 #define ICMP_GET_SIZE(call) \ 119 ({ \ 120 size_t size = (size_t) IPC_GET_ARG1(call); \ 121 size; \ 122 }) 105 #define ICMP_GET_SIZE(call) ((size_t) IPC_GET_ARG1(call)) 123 106 124 /** Return sthe timeout message parameter.107 /** Return the timeout message parameter. 125 108 * 126 * @param[in] call The message call structure. 109 * @param[in] call Message call structure. 110 * 127 111 */ 128 #define ICMP_GET_TIMEOUT(call) \ 129 ({ \ 130 suseconds_t timeout = (suseconds_t) IPC_GET_ARG2(call); \ 131 timeout; \ 132 }) 112 #define ICMP_GET_TIMEOUT(call) ((suseconds_t) IPC_GET_ARG2(call)) 133 113 134 /** Return sthe time to live message parameter.114 /** Return the time to live message parameter. 135 115 * 136 * @param[in] call The message call structure. 116 * @param[in] call Message call structure. 117 * 137 118 */ 138 #define ICMP_GET_TTL(call) \ 139 ({ \ 140 ip_ttl_t ttl = (ip_ttl_t) IPC_GET_ARG3(call); \ 141 ttl; \ 142 }) 119 #define ICMP_GET_TTL(call) ((ip_ttl_t) IPC_GET_ARG3(call)) 143 120 144 /** Return sthe type of service message parameter.121 /** Return the type of service message parameter. 145 122 * 146 * @param[in] call The message call structure. 123 * @param[in] call Message call structure. 124 * 147 125 */ 148 #define ICMP_GET_TOS(call) \ 149 ({ \ 150 ip_tos_t tos = (ip_tos_t) IPC_GET_ARG4(call); \ 151 tos; \ 152 }) 126 #define ICMP_GET_TOS(call) ((ip_tos_t) IPC_GET_ARG4(call)) 153 127 154 /** Return sthe dont fragment message parameter.128 /** Return the dont fragment message parameter. 155 129 * 156 * @param[in] call The message call structure.130 * @param[in] call Message call structure. 157 131 */ 158 #define ICMP_GET_DONT_FRAGMENT(call) \ 159 ({ \ 160 int dont_fragment = (int) IPC_GET_ARG5(call); \ 161 dont_fragment; \ 162 }) 132 #define ICMP_GET_DONT_FRAGMENT(call) ((int) IPC_GET_ARG5(call)) 163 133 164 134 /*@}*/ -
uspace/lib/c/include/ipc/il.h
r22027b6e r8b5690f 33 33 /** @file 34 34 * Internetwork layer modules messages. 35 * @see il_ interface.h35 * @see il_remote.h 36 36 * @see ip_interface.h 37 37 */ … … 40 40 #define LIBC_IL_MESSAGES_H_ 41 41 42 #include <ipc/ipc.h>43 42 #include <ipc/net.h> 44 43 45 44 /** Internet layer modules messages. */ 46 45 typedef enum { 47 /** New device message.48 * @see ip_device_req()49 */50 NET_IL_DEVICE = NET_IL_FIRST,51 46 /** Device state changed message. 52 47 * @see il_device_state_msg() 53 48 */ 54 NET_IL_DEVICE_STATE, 49 NET_IL_DEVICE_STATE = NET_IL_FIRST, 50 55 51 /** Device MTU changed message. 56 52 * @see il_mtu_changed_msg() 57 53 */ 58 54 NET_IL_MTU_CHANGED, 59 /** Packet size message. 60 * @see il_packet_size_req() 61 */ 62 NET_IL_PACKET_SPACE, 55 63 56 /** Packet received message. 64 57 * @see il_received_msg() 65 58 */ 66 NET_IL_RECEIVED, 67 /** Packet send message. 68 * @see il_send_msg() 69 */ 70 NET_IL_SEND 59 NET_IL_RECEIVED 71 60 } il_messages; 72 61 … … 75 64 76 65 /** Return the protocol number message parameter. 77 * @param[in] call The message call structure. 66 * 67 * @param[in] call Message call structure. 68 * 78 69 */ 79 #define IL_GET_PROTO(call) (int) IPC_GET_ARG1(*call)70 #define IL_GET_PROTO(call) ((int) IPC_GET_ARG1(call)) 80 71 81 72 /** Return the registering service message parameter. 82 * @param[in] call The message call structure. 73 * 74 * @param[in] call Message call structure. 75 * 83 76 */ 84 #define IL_GET_SERVICE(call) (services_t) IPC_GET_ARG2(*call)77 #define IL_GET_SERVICE(call) ((services_t) IPC_GET_ARG2(call)) 85 78 86 79 /*@}*/ -
uspace/lib/c/include/ipc/ip.h
r22027b6e r8b5690f 39 39 #define LIBC_IP_MESSAGES_H_ 40 40 41 #include <ipc/ipc.h>42 41 #include <ipc/net.h> 43 44 42 #include <net/in.h> 45 43 #include <net/ip_codes.h> … … 47 45 /** IP module messages. */ 48 46 typedef enum { 47 /** New device message. 48 * @see ip_device_req() 49 */ 50 NET_IP_DEVICE = NET_IP_FIRST, 51 49 52 /** Adds the routing entry. 50 53 * @see ip_add_route() 51 54 */ 52 NET_IP_ADD_ROUTE = NET_IP_FIRST, 55 NET_IP_ADD_ROUTE, 56 53 57 /** Gets the actual route information. 54 58 * @see ip_get_route() 55 59 */ 56 60 NET_IP_GET_ROUTE, 61 57 62 /** Processes the received error notification. 58 63 * @see ip_received_error_msg() 59 64 */ 60 65 NET_IP_RECEIVED_ERROR, 66 61 67 /** Sets the default gateway. 62 68 * @see ip_set_default_gateway() 63 69 */ 64 NET_IP_SET_GATEWAY 70 NET_IP_SET_GATEWAY, 71 72 /** Packet size message. 73 * @see ip_packet_size_req() 74 */ 75 NET_IP_PACKET_SPACE, 76 77 /** Packet send message. 78 * @see ip_send_msg() 79 */ 80 NET_IP_SEND 65 81 } ip_messages; 66 82 … … 68 84 /*@{*/ 69 85 70 /** Returns the address message parameter. 71 * @param[in] call The message call structure. 86 /** Return the address message parameter. 87 * 88 * @param[in] call Message call structure. 89 * 72 90 */ 73 91 #define IP_GET_ADDRESS(call) \ 74 92 ({ \ 75 93 in_addr_t addr; \ 76 addr.s_addr = IPC_GET_ARG3( *call); \94 addr.s_addr = IPC_GET_ARG3(call); \ 77 95 addr; \ 78 96 }) 79 97 80 /** Returns the gateway message parameter. 81 * @param[in] call The message call structure. 98 /** Return the gateway message parameter. 99 * 100 * @param[in] call Message call structure. 101 * 82 102 */ 83 103 #define IP_GET_GATEWAY(call) \ 84 104 ({ \ 85 105 in_addr_t addr; \ 86 addr.s_addr = IPC_GET_ARG2( *call); \106 addr.s_addr = IPC_GET_ARG2(call); \ 87 107 addr; \ 88 108 }) 89 109 90 /** Sets the header length in the message answer. 91 * @param[out] answer The message answer structure. 110 /** Set the header length in the message answer. 111 * 112 * @param[out] answer Message answer structure. 113 * 92 114 */ 93 #define IP_SET_HEADERLEN(answer, value) \ 94 do { \ 95 sysarg_t argument = (sysarg_t) (value); \ 96 IPC_SET_ARG2(*answer, argument); \ 97 } while (0) 115 #define IP_SET_HEADERLEN(answer, value) IPC_SET_ARG2(answer, (sysarg_t) (value)) 98 116 99 /** Returns the network mask message parameter. 100 * @param[in] call The message call structure. 117 /** Return the network mask message parameter. 118 * 119 * @param[in] call Message call structure. 120 * 101 121 */ 102 122 #define IP_GET_NETMASK(call) \ 103 123 ({ \ 104 124 in_addr_t addr; \ 105 addr.s_addr = IPC_GET_ARG4( *call); \125 addr.s_addr = IPC_GET_ARG4(call); \ 106 126 addr; \ 107 127 }) 108 128 109 /** Returns the protocol message parameter. 110 * @param[in] call The message call structure. 129 /** Return the protocol message parameter. 130 * 131 * @param[in] call Message call structure. 132 * 111 133 */ 112 #define IP_GET_PROTOCOL(call) \ 113 ({ \ 114 ip_protocol_t protocol = (ip_protocol_t) IPC_GET_ARG1(*call); \ 115 protocol; \ 116 }) 134 #define IP_GET_PROTOCOL(call) ((ip_protocol_t) IPC_GET_ARG1(call)) 117 135 118 136 /*@}*/ -
uspace/lib/c/include/ipc/ipc.h
r22027b6e r8b5690f 33 33 */ 34 34 35 #ifndef LIBIPC_IPC_H_ 36 #define LIBIPC_IPC_H_ 37 35 #if ((defined(LIBC_ASYNC_H_)) && (!defined(LIBC_ASYNC_C_))) 36 #error Do not intermix low-level IPC interface and async framework 37 #endif 38 39 #ifndef LIBC_IPC_H_ 40 #define LIBC_IPC_H_ 41 42 #include <sys/types.h> 43 #include <ipc/common.h> 44 #include <kernel/synch/synch.h> 38 45 #include <task.h> 39 #include <kernel/ipc/ipc.h> 40 #include <kernel/ddi/irq.h> 41 #include <sys/types.h> 42 #include <kernel/synch/synch.h> 43 44 #define IPC_FLAG_BLOCKING 0x01 45 46 typedef struct { 47 sysarg_t args[IPC_CALL_LEN]; 48 sysarg_t in_phone_hash; 49 } ipc_call_t; 50 51 typedef sysarg_t ipc_callid_t; 52 53 typedef void (* ipc_async_callback_t)(void *, int, ipc_call_t *); 46 47 typedef void (*ipc_async_callback_t)(void *, int, ipc_call_t *); 54 48 55 49 /* … … 59 53 * possible, the fast version is used. 60 54 */ 55 61 56 #define ipc_call_sync_0_0(phoneid, method) \ 62 57 ipc_call_sync_fast((phoneid), (method), 0, 0, 0, 0, 0, 0, 0, 0) … … 188 183 sysarg_t *); 189 184 190 extern ipc_callid_t ipc_wait_cycle(ipc_call_t *, uint32_t, int); 191 extern ipc_callid_t ipc_wait_for_call_timeout(ipc_call_t *, uint32_t); 185 extern ipc_callid_t ipc_wait_cycle(ipc_call_t *, sysarg_t, unsigned int); 192 186 extern void ipc_poke(void); 193 187 194 static inline ipc_callid_t ipc_wait_for_call(ipc_call_t *data) 195 { 196 return ipc_wait_for_call_timeout(data, SYNCH_NO_TIMEOUT); 197 } 198 188 #define ipc_wait_for_call(data) \ 189 ipc_wait_for_call_timeout(data, SYNCH_NO_TIMEOUT); 190 191 extern ipc_callid_t ipc_wait_for_call_timeout(ipc_call_t *, sysarg_t); 199 192 extern ipc_callid_t ipc_trywait_for_call(ipc_call_t *); 200 193 … … 205 198 * to m. 206 199 */ 200 207 201 #define ipc_answer_0(callid, retval) \ 208 202 ipc_answer_fast((callid), (retval), 0, 0, 0, 0) … … 229 223 * to m. 230 224 */ 225 231 226 #define ipc_call_async_0(phoneid, method, private, callback, can_preempt) \ 232 227 ipc_call_async_fast((phoneid), (method), 0, 0, 0, 0, (private), \ … … 254 249 255 250 extern void ipc_call_async_fast(int, sysarg_t, sysarg_t, sysarg_t, sysarg_t, 256 sysarg_t, void *, ipc_async_callback_t, int);251 sysarg_t, void *, ipc_async_callback_t, bool); 257 252 extern void ipc_call_async_slow(int, sysarg_t, sysarg_t, sysarg_t, sysarg_t, 258 sysarg_t, sysarg_t, void *, ipc_async_callback_t, int); 259 260 extern int ipc_connect_to_me(int, int, int, int, sysarg_t *); 261 extern int ipc_connect_me_to(int, int, int, int); 262 extern int ipc_connect_me_to_blocking(int, int, int, int); 253 sysarg_t, sysarg_t, void *, ipc_async_callback_t, bool); 254 255 extern int ipc_connect_to_me(int, sysarg_t, sysarg_t, sysarg_t, sysarg_t *, 256 sysarg_t *); 257 extern int ipc_connect_me_to(int, sysarg_t, sysarg_t, sysarg_t); 258 extern int ipc_connect_me_to_blocking(int, sysarg_t, sysarg_t, sysarg_t); 259 263 260 extern int ipc_hangup(int); 264 extern int ipc_register_irq(int, int, int, irq_code_t *); 265 extern int ipc_ unregister_irq(int, int);266 extern int ipc_forward_fast(ipc_callid_t, int, int, sysarg_t, sysarg_t,int);267 extern int ipc_forward_slow(ipc_callid_t, int, int, sysarg_t, sysarg_t,268 sysarg_t, sysarg_t, sysarg_t, int);261 262 extern int ipc_forward_fast(ipc_callid_t, int, sysarg_t, sysarg_t, sysarg_t, 263 unsigned int); 264 extern int ipc_forward_slow(ipc_callid_t, int, sysarg_t, sysarg_t, sysarg_t, 265 sysarg_t, sysarg_t, sysarg_t, unsigned int); 269 266 270 267 /* 271 268 * User-friendly wrappers for ipc_share_in_start(). 272 269 */ 270 273 271 #define ipc_share_in_start_0_0(phoneid, dst, size) \ 274 272 ipc_share_in_start((phoneid), (dst), (size), 0, NULL) … … 280 278 ipc_share_in_start((phoneid), (dst), (size), (arg), (flags)) 281 279 282 extern int ipc_share_in_start(int, void *, size_t, sysarg_t, int *);283 extern int ipc_share_in_finalize(ipc_callid_t, void *, int);284 extern int ipc_share_out_start(int, void *, int);280 extern int ipc_share_in_start(int, void *, size_t, sysarg_t, unsigned int *); 281 extern int ipc_share_in_finalize(ipc_callid_t, void *, unsigned int); 282 extern int ipc_share_out_start(int, void *, unsigned int); 285 283 extern int ipc_share_out_finalize(ipc_callid_t, void *); 286 284 extern int ipc_data_read_start(int, void *, size_t); -
uspace/lib/c/include/ipc/irc.h
r22027b6e r8b5690f 36 36 #define LIBC_IRC_H_ 37 37 38 #include <ipc/ ipc.h>38 #include <ipc/common.h> 39 39 40 40 typedef enum { -
uspace/lib/c/include/ipc/kbd.h
r22027b6e r8b5690f 38 38 #define LIBC_IPC_KBD_H_ 39 39 40 #include <ipc/ ipc.h>40 #include <ipc/common.h> 41 41 42 42 typedef enum { -
uspace/lib/c/include/ipc/loader.h
r22027b6e r8b5690f 31 31 */ 32 32 /** @file 33 */ 33 */ 34 34 35 35 #ifndef LIBC_IPC_LOADER_H_ 36 36 #define LIBC_IPC_LOADER_H_ 37 37 38 #include <ipc/ ipc.h>38 #include <ipc/common.h> 39 39 40 40 typedef enum { -
uspace/lib/c/include/ipc/mouse.h
r22027b6e r8b5690f 37 37 #define LIBC_IPC_MOUSE_H_ 38 38 39 #include <ipc/ ipc.h>39 #include <ipc/common.h> 40 40 41 41 typedef enum { -
uspace/lib/c/include/ipc/net.h
r22027b6e r8b5690f 38 38 #define LIBC_NET_MESSAGES_H_ 39 39 40 #include <ipc/ipc.h>41 40 #include <ipc/services.h> 42 43 41 #include <net/device.h> 44 42 #include <net/packet.h> 45 43 46 /** Returns a value indicating whether the value is in the interval. 47 * @param[in] item The value to be checked. 48 * @param[in] first_inclusive The first value in the interval inclusive. 49 * @param[in] last_exclusive The first value after the interval. 44 /** Return a value indicating whether the value is in the interval. 45 * 46 * @param[in] item Value to be checked. 47 * @param[in] first_inclusive First value in the interval inclusive. 48 * @param[in] last_exclusive First value after the interval. 49 * 50 50 */ 51 51 #define IS_IN_INTERVAL(item, first_inclusive, last_exclusive) \ … … 55 55 /*@{*/ 56 56 57 /** The number of ARP messages. */ 58 #define NET_ARP_COUNT 5 59 60 /** The number of Ethernet messages. */ 61 #define NET_ETH_COUNT 0 62 63 /** The number of ICMP messages. */ 64 #define NET_ICMP_COUNT 6 65 66 /** The number of inter-network messages. */ 67 #define NET_IL_COUNT 6 68 69 /** The number of IP messages. */ 70 #define NET_IP_COUNT 4 71 72 /** The number of general networking messages. */ 73 #define NET_NET_COUNT 3 74 75 /** The number of network interface driver messages. */ 76 #define NET_NETIF_COUNT 6 77 78 /** The number of network interface layer messages. */ 79 #define NET_NIL_COUNT 7 80 81 /** The number of packet management system messages. */ 82 #define NET_PACKET_COUNT 5 83 84 /** The number of socket messages. */ 85 #define NET_SOCKET_COUNT 14 86 87 /** The number of TCP messages. */ 88 #define NET_TCP_COUNT 0 89 90 /** The number of transport layer messages. */ 91 #define NET_TL_COUNT 1 92 93 /** The number of UDP messages. */ 94 #define NET_UDP_COUNT 0 57 #define NET_ARP_COUNT 5 /**< Number of ARP messages. */ 58 #define NET_ETH_COUNT 0 /**< Number of Ethernet messages. */ 59 #define NET_ICMP_COUNT 6 /**< Number of ICMP messages. */ 60 #define NET_IL_COUNT 6 /**< Number of inter-network messages. */ 61 #define NET_IP_COUNT 4 /**< Number of IP messages. */ 62 #define NET_NET_COUNT 3 /**< Number of general networking messages. */ 63 #define NET_NETIF_COUNT 6 /**< Number of network interface driver messages. */ 64 #define NET_NIL_COUNT 7 /**< Number of network interface layer messages. */ 65 #define NET_PACKET_COUNT 5 /**< Number of packet management system messages. */ 66 #define NET_SOCKET_COUNT 14 /**< Number of socket messages. */ 67 #define NET_TCP_COUNT 0 /**< Number of TCP messages. */ 68 #define NET_TL_COUNT 1 /**< Number of transport layer messages. */ 69 #define NET_UDP_COUNT 0 /**< Number of UDP messages. */ 95 70 96 71 /*@}*/ … … 100 75 /*@{*/ 101 76 102 /** The first networking message. */ 103 #define NET_FIRST 2000 104 105 /** The first network interface layer message. */ 106 #define NET_NETIF_FIRST NET_FIRST 107 108 /** The last network interface layer message. */ 109 #define NET_NETIF_LAST (NET_NETIF_FIRST + NET_NETIF_COUNT) 110 111 /** The first general networking message. */ 112 #define NET_NET_FIRST (NET_NETIF_LAST + 0) 113 114 /** The last general networking message. */ 115 #define NET_NET_LAST (NET_NET_FIRST + NET_NET_COUNT) 116 117 /** The first network interface layer message. */ 118 #define NET_NIL_FIRST (NET_NET_LAST + 0) 119 120 /** The last network interface layer message. */ 121 #define NET_NIL_LAST (NET_NIL_FIRST + NET_NIL_COUNT) 122 123 /** The first Ethernet message. */ 124 #define NET_ETH_FIRST (NET_NIL_LAST + 0) 125 126 /** The last Ethernet message. */ 127 #define NET_ETH_LAST (NET_ETH_FIRST + NET_ETH_COUNT) 128 129 /** The first inter-network message. */ 130 #define NET_IL_FIRST (NET_ETH_LAST + 0) 131 132 /** The last inter-network message. */ 133 #define NET_IL_LAST (NET_IL_FIRST + NET_IL_COUNT) 134 135 /** The first IP message. */ 136 #define NET_IP_FIRST (NET_IL_LAST + 0) 137 138 /** The last IP message. */ 139 #define NET_IP_LAST (NET_IP_FIRST + NET_IP_COUNT) 140 141 /** The first ARP message. */ 142 #define NET_ARP_FIRST (NET_IP_LAST + 0) 143 144 /** The last ARP message. */ 145 #define NET_ARP_LAST (NET_ARP_FIRST + NET_ARP_COUNT) 146 147 /** The first ICMP message. */ 148 #define NET_ICMP_FIRST (NET_ARP_LAST + 0) 149 150 /** The last ICMP message. */ 151 #define NET_ICMP_LAST (NET_ICMP_FIRST + NET_ICMP_COUNT) 152 153 /** The first ICMP message. */ 154 #define NET_TL_FIRST (NET_ICMP_LAST + 0) 155 156 /** The last ICMP message. */ 157 #define NET_TL_LAST (NET_TL_FIRST + NET_TL_COUNT) 158 159 /** The first UDP message. */ 160 #define NET_UDP_FIRST (NET_TL_LAST + 0) 161 162 /** The last UDP message. */ 163 #define NET_UDP_LAST (NET_UDP_FIRST + NET_UDP_COUNT) 164 165 /** The first TCP message. */ 166 #define NET_TCP_FIRST (NET_UDP_LAST + 0) 167 168 /** The last TCP message. */ 169 #define NET_TCP_LAST (NET_TCP_FIRST + NET_TCP_COUNT) 170 171 /** The first socket message. */ 172 #define NET_SOCKET_FIRST (NET_TCP_LAST + 0) 173 174 /** The last socket message. */ 175 #define NET_SOCKET_LAST (NET_SOCKET_FIRST + NET_SOCKET_COUNT) 176 177 /** The first packet management system message. */ 178 #define NET_PACKET_FIRST (NET_SOCKET_LAST + 0) 179 180 /** The last packet management system message. */ 181 #define NET_PACKET_LAST (NET_PACKET_FIRST + NET_PACKET_COUNT) 182 183 /** The last networking message. */ 184 #define NET_LAST NET_PACKET_LAST 185 186 /** The number of networking messages. */ 187 #define NET_COUNT (NET_LAST - NET_FIRST) 188 189 /** Returns a value indicating whether the IPC call is a generic networking 190 * message. 191 * @param[in] call The IPC call to be checked. 77 78 /** First networking message. */ 79 #define NET_FIRST 2000 80 81 /** First network interface layer message. */ 82 #define NET_NETIF_FIRST NET_FIRST 83 84 /** Last network interface layer message. */ 85 #define NET_NETIF_LAST (NET_NETIF_FIRST + NET_NETIF_COUNT) 86 87 /** First general networking message. */ 88 #define NET_NET_FIRST (NET_NETIF_LAST + 0) 89 90 /** Last general networking message. */ 91 #define NET_NET_LAST (NET_NET_FIRST + NET_NET_COUNT) 92 93 /** First network interface layer message. */ 94 #define NET_NIL_FIRST (NET_NET_LAST + 0) 95 96 /** Last network interface layer message. */ 97 #define NET_NIL_LAST (NET_NIL_FIRST + NET_NIL_COUNT) 98 99 /** First Ethernet message. */ 100 #define NET_ETH_FIRST (NET_NIL_LAST + 0) 101 102 /** Last Ethernet message. */ 103 #define NET_ETH_LAST (NET_ETH_FIRST + NET_ETH_COUNT) 104 105 /** First inter-network message. */ 106 #define NET_IL_FIRST (NET_ETH_LAST + 0) 107 108 /** Last inter-network message. */ 109 #define NET_IL_LAST (NET_IL_FIRST + NET_IL_COUNT) 110 111 /** First IP message. */ 112 #define NET_IP_FIRST (NET_IL_LAST + 0) 113 114 /** Last IP message. */ 115 #define NET_IP_LAST (NET_IP_FIRST + NET_IP_COUNT) 116 117 /** First ARP message. */ 118 #define NET_ARP_FIRST (NET_IP_LAST + 0) 119 120 /** Last ARP message. */ 121 #define NET_ARP_LAST (NET_ARP_FIRST + NET_ARP_COUNT) 122 123 /** First ICMP message. */ 124 #define NET_ICMP_FIRST (NET_ARP_LAST + 0) 125 126 /** Last ICMP message. */ 127 #define NET_ICMP_LAST (NET_ICMP_FIRST + NET_ICMP_COUNT) 128 129 /** First ICMP message. */ 130 #define NET_TL_FIRST (NET_ICMP_LAST + 0) 131 132 /** Last ICMP message. */ 133 #define NET_TL_LAST (NET_TL_FIRST + NET_TL_COUNT) 134 135 /** First UDP message. */ 136 #define NET_UDP_FIRST (NET_TL_LAST + 0) 137 138 /** Last UDP message. */ 139 #define NET_UDP_LAST (NET_UDP_FIRST + NET_UDP_COUNT) 140 141 /** First TCP message. */ 142 #define NET_TCP_FIRST (NET_UDP_LAST + 0) 143 144 /** Last TCP message. */ 145 #define NET_TCP_LAST (NET_TCP_FIRST + NET_TCP_COUNT) 146 147 /** First socket message. */ 148 #define NET_SOCKET_FIRST (NET_TCP_LAST + 0) 149 150 /** Last socket message. */ 151 #define NET_SOCKET_LAST (NET_SOCKET_FIRST + NET_SOCKET_COUNT) 152 153 /** First packet management system message. */ 154 #define NET_PACKET_FIRST (NET_SOCKET_LAST + 0) 155 156 /** Last packet management system message. */ 157 #define NET_PACKET_LAST (NET_PACKET_FIRST + NET_PACKET_COUNT) 158 159 /** Last networking message. */ 160 #define NET_LAST NET_PACKET_LAST 161 162 /** Number of networking messages. */ 163 #define NET_COUNT (NET_LAST - NET_FIRST) 164 165 /** Check if the IPC call is a generic networking message. 166 * 167 * @param[in] call IPC call to be checked. 168 * 192 169 */ 193 170 #define IS_NET_MESSAGE(call) \ 194 IS_IN_INTERVAL(IPC_GET_IMETHOD(*call), NET_FIRST, NET_LAST) 195 196 /** Returns a value indicating whether the IPC call is an ARP message. 197 * @param[in] call The IPC call to be checked. 171 IS_IN_INTERVAL(IPC_GET_IMETHOD(call), NET_FIRST, NET_LAST) 172 173 /** Check if the IPC call is an ARP message. 174 * 175 * @param[in] call IPC call to be checked. 176 * 198 177 */ 199 178 #define IS_NET_ARP_MESSAGE(call) \ 200 IS_IN_INTERVAL(IPC_GET_IMETHOD(*call), NET_ARP_FIRST, NET_ARP_LAST) 201 202 /** Returns a value indicating whether the IPC call is an Ethernet message. 203 * @param[in] call The IPC call to be checked. 179 IS_IN_INTERVAL(IPC_GET_IMETHOD(call), NET_ARP_FIRST, NET_ARP_LAST) 180 181 /** Check if the IPC call is an Ethernet message. 182 * 183 * @param[in] call IPC call to be checked. 184 * 204 185 */ 205 186 #define IS_NET_ETH_MESSAGE(call) \ 206 IS_IN_INTERVAL(IPC_GET_IMETHOD(*call), NET_ETH_FIRST, NET_ETH_LAST) 207 208 /** Returns a value indicating whether the IPC call is an ICMP message. 209 * @param[in] call The IPC call to be checked. 187 IS_IN_INTERVAL(IPC_GET_IMETHOD(call), NET_ETH_FIRST, NET_ETH_LAST) 188 189 /** Check if the IPC call is an ICMP message. 190 * 191 * @param[in] call IPC call to be checked. 192 * 210 193 */ 211 194 #define IS_NET_ICMP_MESSAGE(call) \ 212 IS_IN_INTERVAL(IPC_GET_IMETHOD(*call), NET_ICMP_FIRST, NET_ICMP_LAST) 213 214 /** Returns a value indicating whether the IPC call is an inter-network layer 215 * message. 216 * @param[in] call The IPC call to be checked. 195 IS_IN_INTERVAL(IPC_GET_IMETHOD(call), NET_ICMP_FIRST, NET_ICMP_LAST) 196 197 /** Check if the IPC call is an inter-network layer message. 198 * 199 * @param[in] call IPC call to be checked. 200 * 217 201 */ 218 202 #define IS_NET_IL_MESSAGE(call) \ 219 IS_IN_INTERVAL(IPC_GET_IMETHOD(*call), NET_IL_FIRST, NET_IL_LAST) 220 221 /** Returns a value indicating whether the IPC call is an IP message. 222 * @param[in] call The IPC call to be checked. 203 IS_IN_INTERVAL(IPC_GET_IMETHOD(call), NET_IL_FIRST, NET_IL_LAST) 204 205 /** Check if the IPC call is an IP message. 206 * 207 * @param[in] call IPC call to be checked. 208 * 223 209 */ 224 210 #define IS_NET_IP_MESSAGE(call) \ 225 IS_IN_INTERVAL(IPC_GET_IMETHOD(*call), NET_IP_FIRST, NET_IP_LAST) 226 227 /** Returns a value indicating whether the IPC call is a generic networking 228 * message. 229 * @param[in] call The IPC call to be checked. 211 IS_IN_INTERVAL(IPC_GET_IMETHOD(call), NET_IP_FIRST, NET_IP_LAST) 212 213 /** Check if the IPC call is a generic networking message. 214 * 215 * @param[in] call IPC call to be checked. 216 * 230 217 */ 231 218 #define IS_NET_NET_MESSAGE(call) \ 232 IS_IN_INTERVAL(IPC_GET_IMETHOD(*call), NET_NET_FIRST, NET_NET_LAST) 233 234 /** Returns a value indicating whether the IPC call is a network interface layer 235 * message. 236 * @param[in] call The IPC call to be checked. 219 IS_IN_INTERVAL(IPC_GET_IMETHOD(call), NET_NET_FIRST, NET_NET_LAST) 220 221 /** Check if the IPC call is a network interface layer message. 222 * 223 * @param[in] call IPC call to be checked. 224 * 237 225 */ 238 226 #define IS_NET_NIL_MESSAGE(call) \ 239 IS_IN_INTERVAL(IPC_GET_IMETHOD(*call), NET_NIL_FIRST, NET_NIL_LAST) 240 241 /** Returns a value indicating whether the IPC call is a packet manaagement 242 * system message. 243 * @param[in] call The IPC call to be checked. 227 IS_IN_INTERVAL(IPC_GET_IMETHOD(call), NET_NIL_FIRST, NET_NIL_LAST) 228 229 /** Check if the IPC call is a packet manaagement system message. 230 * 231 * @param[in] call IPC call to be checked. 232 * 244 233 */ 245 234 #define IS_NET_PACKET_MESSAGE(call) \ 246 IS_IN_INTERVAL(IPC_GET_IMETHOD(*call), NET_PACKET_FIRST, NET_PACKET_LAST) 247 248 /** Returns a value indicating whether the IPC call is a socket message. 249 * @param[in] call The IPC call to be checked. 235 IS_IN_INTERVAL(IPC_GET_IMETHOD(call), NET_PACKET_FIRST, NET_PACKET_LAST) 236 237 /** Check if the IPC call is a socket message. 238 * 239 * @param[in] call IPC call to be checked. 240 * 250 241 */ 251 242 #define IS_NET_SOCKET_MESSAGE(call) \ 252 IS_IN_INTERVAL(IPC_GET_IMETHOD(*call), NET_SOCKET_FIRST, NET_SOCKET_LAST) 253 254 /** Returns a value indicating whether the IPC call is a TCP message. 255 * @param[in] call The IPC call to be checked. 243 IS_IN_INTERVAL(IPC_GET_IMETHOD(call), NET_SOCKET_FIRST, NET_SOCKET_LAST) 244 245 /** Check if the IPC call is a TCP message. 246 * 247 * @param[in] call IPC call to be checked. 248 * 256 249 */ 257 250 #define IS_NET_TCP_MESSAGE(call) \ 258 IS_IN_INTERVAL(IPC_GET_IMETHOD(*call), NET_TCP_FIRST, NET_TCP_LAST) 259 260 /** Returns a value indicating whether the IPC call is a transport layer message. 261 * @param[in] call The IPC call to be checked. 251 IS_IN_INTERVAL(IPC_GET_IMETHOD(call), NET_TCP_FIRST, NET_TCP_LAST) 252 253 /** Check if the IPC call is a transport layer message. 254 * 255 * @param[in] call IPC call to be checked. 256 * 262 257 */ 263 258 #define IS_NET_TL_MESSAGE(call) \ 264 IS_IN_INTERVAL(IPC_GET_IMETHOD(*call), NET_TL_FIRST, NET_TL_LAST) 265 266 /** Returns a value indicating whether the IPC call is a UDP message. 267 * @param[in] call The IPC call to be checked. 259 IS_IN_INTERVAL(IPC_GET_IMETHOD(call), NET_TL_FIRST, NET_TL_LAST) 260 261 /** Check if the IPC call is a UDP message. 262 * 263 * @param[in] call IPC call to be checked. 264 * 268 265 */ 269 266 #define IS_NET_UDP_MESSAGE(call) \ 270 IS_IN_INTERVAL(IPC_GET_IMETHOD( *call), NET_UDP_FIRST, NET_UDP_LAST)267 IS_IN_INTERVAL(IPC_GET_IMETHOD(call), NET_UDP_FIRST, NET_UDP_LAST) 271 268 272 269 /*@}*/ … … 275 272 /*@{*/ 276 273 277 /** Returns the device identifier message argument. 278 * @param[in] call The message call structure. 279 */ 280 #define IPC_GET_DEVICE(call) \ 281 ({ \ 282 device_id_t device_id = (device_id_t) IPC_GET_ARG1(*call); \ 283 device_id; \ 284 }) 285 286 /** Returns the packet identifier message argument. 287 * @param[in] call The message call structure. 288 */ 289 #define IPC_GET_PACKET(call) \ 290 ({ \ 291 packet_id_t packet_id = (packet_id_t) IPC_GET_ARG2(*call); \ 292 packet_id; \ 293 }) 294 295 /** Returns the count message argument. 296 * @param[in] call The message call structure. 297 */ 298 #define IPC_GET_COUNT(call) \ 299 ({ \ 300 size_t size = (size_t) IPC_GET_ARG2(*call); \ 301 size; \ 302 }) 303 304 /** Returns the device state message argument. 305 * @param[in] call The message call structure. 306 */ 307 #define IPC_GET_STATE(call) \ 308 ({ \ 309 device_state_t state = (device_state_t) IPC_GET_ARG2(*call); \ 310 state; \ 311 }) 312 313 /** Returns the maximum transmission unit message argument. 314 * @param[in] call The message call structure. 315 */ 316 #define IPC_GET_MTU(call) \ 317 ({ \ 318 size_t size = (size_t) IPC_GET_ARG2(*call); \ 319 size; \ 320 }) 321 322 /** Returns the device driver service message argument. 323 * @param[in] call The message call structure. 324 */ 325 #define IPC_GET_SERVICE(call) \ 326 ({ \ 327 services_t service = (services_t) IPC_GET_ARG3(*call); \ 328 service; \ 329 }) 330 331 /** Returns the target service message argument. 332 * @param[in] call The message call structure. 333 */ 334 #define IPC_GET_TARGET(call) \ 335 ({ \ 336 services_t service = (services_t) IPC_GET_ARG3(*call); \ 337 service; \ 338 }) 339 340 /** Returns the sender service message argument. 341 * @param[in] call The message call structure. 342 */ 343 #define IPC_GET_SENDER(call) \ 344 ({ \ 345 services_t service = (services_t) IPC_GET_ARG3(*call); \ 346 service; \ 347 }) 348 349 /** Returns the error service message argument. 350 * @param[in] call The message call structure. 351 */ 352 #define IPC_GET_ERROR(call) \ 353 ({ \ 354 services_t service = (services_t) IPC_GET_ARG4(*call); \ 355 service; \ 356 }) 357 358 /** Returns the phone message argument. 359 * @param[in] call The message call structure. 360 */ 361 #define IPC_GET_PHONE(call) \ 362 ({ \ 363 int phone = (int) IPC_GET_ARG5(*call); \ 364 phone; \ 365 }) 366 367 /** Sets the device identifier in the message answer. 368 * @param[out] answer The message answer structure. 369 */ 370 #define IPC_SET_DEVICE(answer, value) \ 371 do { \ 372 sysarg_t argument = (sysarg_t) (value); \ 373 IPC_SET_ARG1(*answer, argument); \ 374 } while (0) 375 376 /** Sets the minimum address length in the message answer. 377 * @param[out] answer The message answer structure. 378 */ 379 #define IPC_SET_ADDR(answer, value) \ 380 do { \ 381 sysarg_t argument = (sysarg_t) (value); \ 382 IPC_SET_ARG1(*answer, argument); \ 383 } while (0) 384 385 /** Sets the minimum prefix size in the message answer. 386 * @param[out] answer The message answer structure. 387 */ 388 #define IPC_SET_PREFIX(answer, value) \ 389 do { \ 390 sysarg_t argument = (sysarg_t) (value); \ 391 IPC_SET_ARG2(*answer, argument); \ 392 } while (0) 393 394 /** Sets the maximum content size in the message answer. 395 * @param[out] answer The message answer structure. 396 */ 397 #define IPC_SET_CONTENT(answer, value) \ 398 do { \ 399 sysarg_t argument = (sysarg_t) (value); \ 400 IPC_SET_ARG3(*answer, argument); \ 401 } while (0) 402 403 /** Sets the minimum suffix size in the message answer. 404 * @param[out] answer The message answer structure. 405 */ 406 #define IPC_SET_SUFFIX(answer, value) \ 407 do { \ 408 sysarg_t argument = (sysarg_t) (value); \ 409 IPC_SET_ARG4(*answer, argument); \ 410 } while (0) 274 /** Return the device identifier message argument. 275 * 276 * @param[in] call Message call structure. 277 * 278 */ 279 #define IPC_GET_DEVICE(call) ((device_id_t) IPC_GET_ARG1(call)) 280 281 /** Return the packet identifier message argument. 282 * 283 * @param[in] call Message call structure. 284 * 285 */ 286 #define IPC_GET_PACKET(call) ((packet_id_t) IPC_GET_ARG2(call)) 287 288 /** Return the count message argument. 289 * 290 * @param[in] call Message call structure. 291 * 292 */ 293 #define IPC_GET_COUNT(call) ((size_t) IPC_GET_ARG2(call)) 294 295 /** Return the device state message argument. 296 * 297 * @param[in] call Message call structure. 298 * 299 */ 300 #define IPC_GET_STATE(call) ((device_state_t) IPC_GET_ARG2(call)) 301 302 /** Return the maximum transmission unit message argument. 303 * 304 * @param[in] call Message call structure. 305 * 306 */ 307 #define IPC_GET_MTU(call) ((size_t) IPC_GET_ARG2(call)) 308 309 /** Return the device driver service message argument. 310 * 311 * @param[in] call Message call structure. 312 * 313 */ 314 #define IPC_GET_SERVICE(call) ((services_t) IPC_GET_ARG3(call)) 315 316 /** Return the target service message argument. 317 * 318 * @param[in] call Message call structure. 319 * 320 */ 321 #define IPC_GET_TARGET(call) ((services_t) IPC_GET_ARG3(call)) 322 323 /** Return the sender service message argument. 324 * 325 * @param[in] call Message call structure. 326 * 327 */ 328 #define IPC_GET_SENDER(call) ((services_t) IPC_GET_ARG3(call)) 329 330 /** Return the error service message argument. 331 & 332 * @param[in] call Message call structure. 333 * 334 */ 335 #define IPC_GET_ERROR(call) ((services_t) IPC_GET_ARG4(call)) 336 337 /** Return the phone message argument. 338 * 339 * @param[in] call Message call structure. 340 * 341 */ 342 #define IPC_GET_PHONE(call) ((int) IPC_GET_ARG5(call)) 343 344 /** Set the device identifier in the message answer. 345 * 346 * @param[out] answer Message answer structure. 347 * @param[in] value Value to set. 348 * 349 */ 350 #define IPC_SET_DEVICE(answer, value) IPC_SET_ARG1(answer, (sysarg_t) (value)) 351 352 /** Set the minimum address length in the message answer. 353 * 354 * @param[out] answer Message answer structure. 355 * @param[in] value Value to set. 356 * 357 */ 358 #define IPC_SET_ADDR(answer, value) IPC_SET_ARG1(answer, (sysarg_t) (value)) 359 360 /** Set the minimum prefix size in the message answer. 361 * 362 * @param[out] answer Message answer structure. 363 * @param[in] value Value to set. 364 * 365 */ 366 #define IPC_SET_PREFIX(answer, value) IPC_SET_ARG2(answer, (sysarg_t) (value)) 367 368 /** Set the maximum content size in the message answer. 369 * 370 * @param[out] answer Message answer structure. 371 * @param[in] value Value to set. 372 * 373 */ 374 #define IPC_SET_CONTENT(answer, value) IPC_SET_ARG3(answer, (sysarg_t) (value)) 375 376 /** Set the minimum suffix size in the message answer. 377 * 378 * @param[out] answer Message answer structure. 379 * @param[in] value Value to set. 380 * 381 */ 382 #define IPC_SET_SUFFIX(answer, value) IPC_SET_ARG4(answer, (sysarg_t) (value)) 411 383 412 384 /*@}*/ -
uspace/lib/c/include/ipc/net_net.h
r22027b6e r8b5690f 39 39 #define LIBC_NET_NET_MESSAGES_H_ 40 40 41 #include <ipc/ipc.h>42 41 #include <ipc/net.h> 43 42 -
uspace/lib/c/include/ipc/netif.h
r22027b6e r8b5690f 38 38 #define LIBC_NETIF_MESSAGES_H_ 39 39 40 #include <ipc/ipc.h>41 40 #include <ipc/net.h> 42 41 … … 47 46 */ 48 47 NET_NETIF_PROBE = NET_NETIF_FIRST, 48 49 49 /** Send packet message. 50 50 * @see netif_send_msg() 51 51 */ 52 52 NET_NETIF_SEND, 53 53 54 /** Start device message. 54 55 * @see netif_start_req() 55 56 */ 56 57 NET_NETIF_START, 58 57 59 /** Get device usage statistics message. 58 60 * @see netif_stats_req() 59 61 */ 60 62 NET_NETIF_STATS, 63 61 64 /** Stop device message. 62 65 * @see netif_stop_req() 63 66 */ 64 67 NET_NETIF_STOP, 68 65 69 /** Get device address message. 66 70 * @see netif_get_addr_req() … … 73 77 74 78 /** Return the interrupt number message parameter. 75 * @param[in] call The message call structure. 79 * 80 * @param[in] call Mmessage call structure. 81 * 76 82 */ 77 #define NETIF_GET_IRQ(call) \ 78 ({ \ 79 int irq = (int) IPC_GET_ARG2(*call); \ 80 irq; \ 81 }) 83 #define NETIF_GET_IRQ(call) ((int) IPC_GET_ARG2(call)) 82 84 83 85 /** Return the input/output address message parameter. 84 * @param[in] call The message call structure. 86 * 87 * @param[in] call Message call structure. 88 * 85 89 */ 86 #define NETIF_GET_IO(call) \ 87 ({ \ 88 int io = (int) IPC_GET_ARG3(*call); \ 89 io; \ 90 }) 90 #define NETIF_GET_IO(call) ((void *) IPC_GET_ARG3(call)) 91 91 92 92 /*@}*/ -
uspace/lib/c/include/ipc/nil.h
r22027b6e r8b5690f 38 38 #define LIBC_NIL_MESSAGES_H_ 39 39 40 #include <ipc/ipc.h>41 40 #include <ipc/net.h> 42 41 … … 77 76 78 77 /** Return the protocol service message parameter. */ 79 #define NIL_GET_PROTO(call) \ 80 ({ \ 81 services_t service = (services_t) IPC_GET_ARG2(*call); \ 82 service; \ 83 }) 78 #define NIL_GET_PROTO(call) ((services_t) IPC_GET_ARG2(call)) 84 79 85 80 /*@}*/ -
uspace/lib/c/include/ipc/ns.h
r22027b6e r8b5690f 33 33 */ 34 34 35 #ifndef LIB IPC_NS_H_36 #define LIB IPC_NS_H_35 #ifndef LIBC_NS_H_ 36 #define LIBC_NS_H_ 37 37 38 #include <ipc/ipc.h> 38 #include <sys/types.h> 39 #include <ipc/common.h> 39 40 40 41 typedef enum { … … 45 46 } ns_request_t; 46 47 48 extern int service_register(sysarg_t); 49 extern int service_connect(sysarg_t, sysarg_t, sysarg_t); 50 extern int service_connect_blocking(sysarg_t, sysarg_t, sysarg_t); 51 47 52 #endif 48 53 -
uspace/lib/c/include/ipc/packet.h
r22027b6e r8b5690f 38 38 #define LIBC_PACKET_MESSAGES_ 39 39 40 #include <ipc/ipc.h>41 40 #include <ipc/net.h> 42 41 … … 70 69 } packet_messages; 71 70 72 /** Return sthe protocol service message parameter. */73 #define ARP_GET_PROTO(call) (services_t) IPC_GET_ARG2(*call)71 /** Return the protocol service message parameter. */ 72 #define ARP_GET_PROTO(call) ((services_t) IPC_GET_ARG2(call)) 74 73 75 /** Return sthe packet identifier message parameter. */76 #define IPC_GET_ID(call) (packet_id_t) IPC_GET_ARG1(*call)74 /** Return the packet identifier message parameter. */ 75 #define IPC_GET_ID(call) ((packet_id_t) IPC_GET_ARG1(call)) 77 76 78 /** Return sthe maximal content length message parameter. */79 #define IPC_GET_CONTENT(call) (size_t) IPC_GET_ARG1(*call)77 /** Return the maximal content length message parameter. */ 78 #define IPC_GET_CONTENT(call) ((size_t) IPC_GET_ARG1(call)) 80 79 81 /** Return sthe maximal address length message parameter. */82 #define IPC_GET_ADDR_LEN(call) (size_t) IPC_GET_ARG2(*call)80 /** Return the maximal address length message parameter. */ 81 #define IPC_GET_ADDR_LEN(call) ((size_t) IPC_GET_ARG2(call)) 83 82 84 /** Return sthe maximal prefix length message parameter. */85 #define IPC_GET_PREFIX(call) (size_t) IPC_GET_ARG3(*call)83 /** Return the maximal prefix length message parameter. */ 84 #define IPC_GET_PREFIX(call) ((size_t) IPC_GET_ARG3(call)) 86 85 87 /** Return sthe maximal suffix length message parameter. */88 #define IPC_GET_SUFFIX(call) (size_t) IPC_GET_ARG4(*call)86 /** Return the maximal suffix length message parameter. */ 87 #define IPC_GET_SUFFIX(call) ((size_t) IPC_GET_ARG4(call)) 89 88 90 89 #endif -
uspace/lib/c/include/ipc/services.h
r22027b6e r8b5690f 35 35 */ 36 36 37 #ifndef LIB IPC_SERVICES_H_38 #define LIB IPC_SERVICES_H_37 #ifndef LIBC_SERVICES_H_ 38 #define LIBC_SERVICES_H_ 39 39 40 40 typedef enum { … … 54 54 SERVICE_NETWORKING, 55 55 SERVICE_LO, 56 SERVICE_ DP8390,56 SERVICE_NE2000, 57 57 SERVICE_ETHERNET, 58 58 SERVICE_NILDUMMY, … … 66 66 } services_t; 67 67 68 /* Memory area to be received from NS */69 #define SERVICE_MEM_REALTIME 170 #define SERVICE_MEM_KLOG 271 72 68 #endif 73 69 -
uspace/lib/c/include/ipc/socket.h
r22027b6e r8b5690f 38 38 #define LIBC_SOCKET_MESSAGES_H_ 39 39 40 #include <ipc/ipc.h>41 40 #include <ipc/net.h> 42 41 -
uspace/lib/c/include/ipc/tl.h
r22027b6e r8b5690f 39 39 #define LIBC_TL_MESSAGES_H_ 40 40 41 #include <ipc/ipc.h>42 41 #include <ipc/net.h> 43 42 -
uspace/lib/c/include/ipc/vfs.h
r22027b6e r8b5690f 36 36 #define LIBC_IPC_VFS_H_ 37 37 38 #include <ipc/ ipc.h>38 #include <ipc/common.h> 39 39 #include <sys/types.h> 40 40 #include <bool.h> -
uspace/lib/c/include/libc.h
r22027b6e r8b5690f 62 62 __syscall6(p1, p2, p3, p4, p5, p6, id) 63 63 64 extern void __main(void *pcb_ptr);65 extern void __exit(void);66 67 64 #endif 68 65 -
uspace/lib/c/include/loader/pcb.h
r22027b6e r8b5690f 52 52 /** Program entry point. */ 53 53 entry_point_t entry; 54 54 55 55 /** Current working directory. */ 56 56 char *cwd; -
uspace/lib/c/include/malloc.h
r22027b6e r8b5690f 38 38 #include <sys/types.h> 39 39 40 extern void __heap_init(void);41 40 extern uintptr_t get_max_heap_addr(void); 42 41 -
uspace/lib/c/include/net/icmp_common.h
r22027b6e r8b5690f 41 41 #include <sys/time.h> 42 42 43 /** Default timeout for incoming connections in microseconds . */44 #define ICMP_CONNECT_TIMEOUT (1 * 1000 * 1000)43 /** Default timeout for incoming connections in microseconds (1 sec). */ 44 #define ICMP_CONNECT_TIMEOUT 1000000 45 45 46 extern int icmp_connect_module(s ervices_t, suseconds_t);46 extern int icmp_connect_module(suseconds_t); 47 47 48 48 #endif -
uspace/lib/c/include/net/in.h
r22027b6e r8b5690f 43 43 44 44 /** INET string address maximum length. */ 45 #define INET_ADDRSTRLEN 45 #define INET_ADDRSTRLEN (4 * 3 + 3 + 1) 46 46 47 47 /** Type definition of the INET address. 48 48 * @see in_addr 49 49 */ 50 typedef struct in_addr 50 typedef struct in_addr in_addr_t; 51 51 52 52 /** Type definition of the INET socket address. -
uspace/lib/c/include/net/modules.h
r22027b6e r8b5690f 43 43 44 44 #include <async.h> 45 46 #include <ipc/ipc.h>47 45 #include <ipc/services.h> 48 49 46 #include <sys/time.h> 50 47 51 48 /** Connect to the needed module function type definition. 52 49 * 53 * @param[in] need The needed module service. 54 * @return The phone of the needed service. 50 * @param[in] need The needed module service. 51 * 52 * @return The phone of the needed service. 53 * 55 54 */ 56 55 typedef int connect_module_t(services_t need); 57 56 58 extern void answer_call(ipc_callid_t, int, ipc_call_t *, int);57 extern void answer_call(ipc_callid_t, int, ipc_call_t *, size_t); 59 58 extern int bind_service(services_t, sysarg_t, sysarg_t, sysarg_t, 60 59 async_client_conn_t); … … 64 63 extern int connect_to_service_timeout(services_t, suseconds_t); 65 64 extern int data_reply(void *, size_t); 66 extern void refresh_answer(ipc_call_t *, int *);65 extern void refresh_answer(ipc_call_t *, size_t *); 67 66 68 67 #endif -
uspace/lib/c/include/setjmp.h
r22027b6e r8b5690f 41 41 42 42 extern int setjmp(jmp_buf env); 43 extern void longjmp(jmp_buf env, int val) __attribute__((__noreturn__));43 extern void longjmp(jmp_buf env, int val) __attribute__((noreturn)); 44 44 45 45 #endif -
uspace/lib/c/include/stdlib.h
r22027b6e r8b5690f 40 40 #include <stacktrace.h> 41 41 42 #define abort() \ 43 do { \ 44 stacktrace_print(); \ 45 _exit(1); \ 46 } while (0) 42 #define RAND_MAX 714025 47 43 48 #define core() \ 49 *((int *) 0) = 0xbadbad; 50 51 #define exit(status) _exit((status)) 52 53 #define RAND_MAX 714025 44 #define rand() random() 45 #define srand(seed) srandom(seed) 54 46 55 47 extern long int random(void); 56 48 extern void srandom(unsigned int seed); 57 49 58 static inline int rand(void) 59 { 60 return random(); 61 } 62 63 static inline void srand(unsigned int seed) 64 { 65 srandom(seed); 66 } 50 extern void abort(void) __attribute__((noreturn)); 67 51 68 52 #endif -
uspace/lib/c/include/syscall.h
r22027b6e r8b5690f 32 32 /** 33 33 * @file 34 * @brief 35 * 36 * 34 * @brief Syscall function declaration for architectures that don't 35 * inline syscalls or architectures that handle syscalls 36 * according to the number of arguments. 37 37 */ 38 38 … … 40 40 #define LIBC_SYSCALL_H_ 41 41 42 #ifndef 43 #error "You can't include this file directly." 42 #ifndef LIBARCH_SYSCALL_GENERIC 43 #error You cannot include this file directly 44 44 #endif 45 45 … … 47 47 #include <kernel/syscall/syscall.h> 48 48 49 #define __syscall0 50 #define __syscall1 51 #define __syscall2 52 #define __syscall3 53 #define __syscall4 54 #define __syscall5 55 #define __syscall6 49 #define __syscall0 __syscall 50 #define __syscall1 __syscall 51 #define __syscall2 __syscall 52 #define __syscall3 __syscall 53 #define __syscall4 __syscall 54 #define __syscall5 __syscall 55 #define __syscall6 __syscall 56 56 57 57 extern sysarg_t __syscall(const sysarg_t p1, const sysarg_t p2, -
uspace/lib/c/include/thread.h
r22027b6e r8b5690f 36 36 #define LIBC_THREAD_H_ 37 37 38 #include <kernel/proc/uarg.h>39 38 #include <libarch/thread.h> 40 39 #include <sys/types.h> … … 42 41 typedef uint64_t thread_id_t; 43 42 44 extern void __thread_entry(void);45 extern void __thread_main(uspace_arg_t *);46 47 43 extern int thread_create(void (*)(void *), void *, const char *, thread_id_t *); 48 extern void thread_exit(int) __attribute__ 44 extern void thread_exit(int) __attribute__((noreturn)); 49 45 extern void thread_detach(thread_id_t); 50 46 extern int thread_join(thread_id_t); -
uspace/lib/c/include/tls.h
r22027b6e r8b5690f 57 57 extern void tls_free_variant_1(tcb_t *, size_t); 58 58 #endif 59 59 60 #ifdef CONFIG_TLS_VARIANT_2 60 61 extern tcb_t *tls_alloc_variant_2(void **, size_t); -
uspace/lib/c/include/udebug.h
r22027b6e r8b5690f 38 38 #include <kernel/udebug/udebug.h> 39 39 #include <sys/types.h> 40 #include <libarch/types.h>41 40 42 41 typedef sysarg_t thash_t; 43 42 44 int udebug_begin(int phoneid); 45 int udebug_end(int phoneid); 46 int udebug_set_evmask(int phoneid, udebug_evmask_t mask); 47 int udebug_thread_read(int phoneid, void *buffer, size_t n, 48 size_t *copied, size_t *needed); 49 int udebug_name_read(int phoneid, void *buffer, size_t n, 50 size_t *copied, size_t *needed); 51 int udebug_areas_read(int phoneid, void *buffer, size_t n, 52 size_t *copied, size_t *needed); 53 int udebug_mem_read(int phoneid, void *buffer, uintptr_t addr, size_t n); 54 int udebug_args_read(int phoneid, thash_t tid, sysarg_t *buffer); 55 int udebug_regs_read(int phoneid, thash_t tid, void *buffer); 56 int udebug_go(int phoneid, thash_t tid, udebug_event_t *ev_type, 57 sysarg_t *val0, sysarg_t *val1); 58 int udebug_stop(int phoneid, thash_t tid); 43 int udebug_begin(int); 44 int udebug_end(int); 45 int udebug_set_evmask(int, udebug_evmask_t); 46 int udebug_thread_read(int, void *, size_t , size_t *, size_t *); 47 int udebug_name_read(int, void *, size_t, size_t *, size_t *); 48 int udebug_areas_read(int, void *, size_t, size_t *, size_t *); 49 int udebug_mem_read(int, void *, uintptr_t, size_t); 50 int udebug_args_read(int, thash_t, sysarg_t *); 51 int udebug_regs_read(int, thash_t, void *); 52 int udebug_go(int, thash_t, udebug_event_t *, sysarg_t *, sysarg_t *); 53 int udebug_stop(int, thash_t); 59 54 60 55 #endif -
uspace/lib/c/include/unistd.h
r22027b6e r8b5690f 41 41 42 42 #ifndef NULL 43 #define NULL 43 #define NULL ((void *) 0) 44 44 #endif 45 45 … … 74 74 extern int chdir(const char *); 75 75 76 extern void _exit(int) __attribute__((noreturn));76 extern void exit(int) __attribute__((noreturn)); 77 77 extern int usleep(useconds_t); 78 78 extern unsigned int sleep(unsigned int); -
uspace/lib/c/include/vfs/vfs.h
r22027b6e r8b5690f 57 57 extern int unmount(const char *); 58 58 59 extern void __stdio_init(int filc, fdi_node_t *filv[]);60 extern void __stdio_done(void);61 62 59 extern int open_node(fdi_node_t *, int); 63 60 extern int fd_phone(int);
Note:
See TracChangeset
for help on using the changeset viewer.