Changeset 07b39338 in mainline for uspace/lib
- Timestamp:
- 2011-08-20T18:21:49Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6ab014d
- Parents:
- 0cf27ee (diff), f00af83 (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
- Files:
-
- 59 edited
- 1 moved
-
c/arch/abs32le/include/types.h (modified) (1 diff)
-
c/arch/amd64/include/types.h (modified) (1 diff)
-
c/arch/arm32/include/types.h (modified) (1 diff)
-
c/arch/ia32/Makefile.common (modified) (1 diff)
-
c/arch/ia32/Makefile.inc (modified) (1 diff)
-
c/arch/ia32/include/types.h (modified) (1 diff)
-
c/arch/ia32/src/entry.S (moved) (moved from uspace/lib/c/arch/ia32/src/entry.s ) (2 diffs)
-
c/arch/ia64/include/types.h (modified) (1 diff)
-
c/arch/mips32/include/types.h (modified) (1 diff)
-
c/arch/mips64/include/types.h (modified) (1 diff)
-
c/arch/ppc32/include/types.h (modified) (1 diff)
-
c/arch/sparc64/include/types.h (modified) (1 diff)
-
c/generic/async.c (modified) (17 diffs)
-
c/generic/devman.c (modified) (7 diffs)
-
c/generic/event.c (modified) (2 diffs)
-
c/generic/io/io.c (modified) (5 diffs)
-
c/generic/io/printf_core.c (modified) (2 diffs)
-
c/generic/libc.c (modified) (1 diff)
-
c/generic/loader.c (modified) (1 diff)
-
c/generic/loc.c (modified) (11 diffs)
-
c/generic/private/async.h (modified) (1 diff)
-
c/generic/private/io.h (modified) (1 diff)
-
c/generic/task.c (modified) (3 diffs)
-
c/generic/vfs/vfs.c (modified) (5 diffs)
-
c/include/async.h (modified) (3 diffs)
-
c/include/devman.h (modified) (3 diffs)
-
c/include/event.h (modified) (1 diff)
-
c/include/ipc/common.h (modified) (2 diffs)
-
c/include/ipc/devman.h (modified) (2 diffs)
-
c/include/ipc/loc.h (modified) (2 diffs)
-
c/include/ipc/vfs.h (modified) (2 diffs)
-
c/include/loader/loader.h (modified) (2 diffs)
-
c/include/loader/pcb.h (modified) (2 diffs)
-
c/include/loc.h (modified) (3 diffs)
-
c/include/task.h (modified) (2 diffs)
-
c/include/vfs/vfs.h (modified) (2 diffs)
-
drv/generic/driver.c (modified) (4 diffs)
-
drv/include/ddf/driver.h (modified) (1 diff)
-
posix/ctype.c (modified) (1 diff)
-
posix/errno.h (modified) (1 diff)
-
posix/fcntl.c (modified) (1 diff)
-
posix/fnmatch.c (modified) (15 diffs)
-
posix/locale.c (modified) (6 diffs)
-
posix/pwd.c (modified) (6 diffs)
-
posix/signal.c (modified) (20 diffs)
-
posix/stdbool.h (modified) (1 diff)
-
posix/stdint.h (modified) (1 diff)
-
posix/stdio.c (modified) (1 diff)
-
posix/stdio.h (modified) (1 diff)
-
posix/stdio/scanf.c (modified) (2 diffs)
-
posix/string.c (modified) (3 diffs)
-
posix/string.h (modified) (2 diffs)
-
posix/strings.h (modified) (1 diff)
-
posix/time.c (modified) (32 diffs)
-
posix/time.h (modified) (1 diff)
-
usb/include/usb/hc.h (modified) (2 diffs)
-
usb/include/usb/usb.h (modified) (1 diff)
-
usb/src/hc.c (modified) (1 diff)
-
usb/src/resolve.c (modified) (5 diffs)
-
usbvirt/src/device.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/arch/abs32le/include/types.h
r0cf27ee r07b39338 53 53 typedef int32_t intptr_t; 54 54 typedef uint32_t uintptr_t; 55 typedef int32_t intptr_t; 55 56 typedef uint32_t atomic_count_t; 56 57 typedef int32_t atomic_signed_t; -
uspace/lib/c/arch/amd64/include/types.h
r0cf27ee r07b39338 53 53 typedef int64_t intptr_t; 54 54 typedef uint64_t uintptr_t; 55 typedef int64_t intptr_t; 55 56 typedef uint64_t atomic_count_t; 56 57 typedef int64_t atomic_signed_t; -
uspace/lib/c/arch/arm32/include/types.h
r0cf27ee r07b39338 54 54 typedef int32_t intptr_t; 55 55 typedef uint32_t uintptr_t; 56 typedef int32_t intptr_t; 56 57 typedef uint32_t atomic_count_t; 57 58 typedef int32_t atomic_signed_t; -
uspace/lib/c/arch/ia32/Makefile.common
r0cf27ee r07b39338 28 28 29 29 CLANG_ARCH = i386 30 ifeq ($(PROCESSOR),i486) 31 GCC_CFLAGS += -march=i486 -fno-omit-frame-pointer 32 else 30 33 GCC_CFLAGS += -march=pentium -fno-omit-frame-pointer 34 endif 31 35 32 36 ENDIANESS = LE -
uspace/lib/c/arch/ia32/Makefile.inc
r0cf27ee r07b39338 28 28 29 29 ARCH_SOURCES = \ 30 arch/$(UARCH)/src/entry. s\30 arch/$(UARCH)/src/entry.S \ 31 31 arch/$(UARCH)/src/entryjmp.s \ 32 32 arch/$(UARCH)/src/thread_entry.s \ -
uspace/lib/c/arch/ia32/include/types.h
r0cf27ee r07b39338 53 53 typedef int32_t intptr_t; 54 54 typedef uint32_t uintptr_t; 55 typedef int32_t intptr_t; 55 56 typedef uint32_t atomic_count_t; 56 57 typedef int32_t atomic_signed_t; -
uspace/lib/c/arch/ia32/src/entry.S
r0cf27ee r07b39338 46 46 mov %ax, %fs 47 47 # Do not set %gs, it contains descriptor that can see TLS 48 48 49 #ifndef PROCESSOR_i486 49 50 # Detect the mechanism used for making syscalls 50 51 movl $(INTEL_CPUID_STANDARD), %eax … … 55 56 movl $__syscall_fast, (%eax) 56 57 0: 58 #endif 57 59 # 58 60 # Create the first stack frame. -
uspace/lib/c/arch/ia64/include/types.h
r0cf27ee r07b39338 63 63 typedef int64_t intptr_t; 64 64 typedef uint64_t uintptr_t; 65 typedef int64_t intptr_t; 65 66 typedef uint64_t atomic_count_t; 66 67 typedef int64_t atomic_signed_t; -
uspace/lib/c/arch/mips32/include/types.h
r0cf27ee r07b39338 54 54 typedef int32_t intptr_t; 55 55 typedef uint32_t uintptr_t; 56 typedef int32_t intptr_t; 56 57 typedef uint32_t atomic_count_t; 57 58 typedef int32_t atomic_signed_t; -
uspace/lib/c/arch/mips64/include/types.h
r0cf27ee r07b39338 53 53 54 54 typedef uint64_t uintptr_t; 55 typedef int64_t intptr_t; 55 56 typedef uint64_t atomic_count_t; 56 57 typedef int64_t atomic_signed_t; -
uspace/lib/c/arch/ppc32/include/types.h
r0cf27ee r07b39338 53 53 typedef int32_t intptr_t; 54 54 typedef uint32_t uintptr_t; 55 typedef int32_t intptr_t; 55 56 typedef uint32_t atomic_count_t; 56 57 typedef int32_t atomic_signed_t; -
uspace/lib/c/arch/sparc64/include/types.h
r0cf27ee r07b39338 53 53 typedef int64_t intptr_t; 54 54 typedef uint64_t uintptr_t; 55 typedef int64_t intptr_t; 55 56 typedef uint64_t atomic_count_t; 56 57 typedef int64_t atomic_signed_t; -
uspace/lib/c/generic/async.c
r0cf27ee r07b39338 112 112 #include <mem.h> 113 113 #include <stdlib.h> 114 #include <macros.h> 114 115 #include "private/async.h" 115 116 … … 138 139 link_t link; 139 140 140 sysarg_t in_task_hash;141 task_id_t in_task_id; 141 142 atomic_t refcnt; 142 143 void *data; … … 150 151 link_t link; 151 152 152 /** Incoming client task hash. */153 sysarg_t in_task_hash;153 /** Incoming client task ID. */ 154 task_id_t in_task_id; 154 155 155 156 /** Incoming phone hash. */ … … 203 204 } 204 205 205 void *async_get_client_data(void)206 {207 assert(fibril_connection);208 return fibril_connection->client->data;209 }210 211 206 /** Default fibril function that gets called to handle new connection. 212 207 * … … 289 284 { 290 285 assert(key); 286 assert(keys == 2); 291 287 assert(item); 292 288 293 289 client_t *client = hash_table_get_instance(item, client_t, link); 294 return (key[0] == client->in_task_hash); 290 return (key[0] == LOWER32(client->in_task_id) && 291 (key[1] == UPPER32(client->in_task_id))); 295 292 } 296 293 … … 580 577 } 581 578 579 static client_t *async_client_get(task_id_t client_id, bool create) 580 { 581 unsigned long key[2] = { 582 LOWER32(client_id), 583 UPPER32(client_id), 584 }; 585 client_t *client = NULL; 586 587 futex_down(&async_futex); 588 link_t *lnk = hash_table_find(&client_hash_table, key); 589 if (lnk) { 590 client = hash_table_get_instance(lnk, client_t, link); 591 atomic_inc(&client->refcnt); 592 } else if (create) { 593 client = malloc(sizeof(client_t)); 594 if (client) { 595 client->in_task_id = client_id; 596 client->data = async_client_data_create(); 597 598 atomic_set(&client->refcnt, 1); 599 hash_table_insert(&client_hash_table, key, &client->link); 600 } 601 } 602 603 futex_up(&async_futex); 604 return client; 605 } 606 607 static void async_client_put(client_t *client) 608 { 609 bool destroy; 610 unsigned long key[2] = { 611 LOWER32(client->in_task_id), 612 UPPER32(client->in_task_id) 613 }; 614 615 futex_down(&async_futex); 616 617 if (atomic_predec(&client->refcnt) == 0) { 618 hash_table_remove(&client_hash_table, key, 2); 619 destroy = true; 620 } else 621 destroy = false; 622 623 futex_up(&async_futex); 624 625 if (destroy) { 626 if (client->data) 627 async_client_data_destroy(client->data); 628 629 free(client); 630 } 631 } 632 633 void *async_get_client_data(void) 634 { 635 assert(fibril_connection); 636 return fibril_connection->client->data; 637 } 638 639 void *async_get_client_data_by_id(task_id_t client_id) 640 { 641 client_t *client = async_client_get(client_id, false); 642 if (!client) 643 return NULL; 644 if (!client->data) { 645 async_client_put(client); 646 return NULL; 647 } 648 649 return client->data; 650 } 651 652 void async_put_client_data_by_id(task_id_t client_id) 653 { 654 client_t *client = async_client_get(client_id, false); 655 656 assert(client); 657 assert(client->data); 658 659 /* Drop the reference we got in async_get_client_data_by_hash(). */ 660 async_client_put(client); 661 662 /* Drop our own reference we got at the beginning of this function. */ 663 async_client_put(client); 664 } 665 582 666 /** Wrapper for client connection fibril. 583 667 * … … 598 682 */ 599 683 fibril_connection = (connection_t *) arg; 600 601 futex_down(&async_futex);602 684 603 685 /* … … 606 688 * hash in a new tracking structure. 607 689 */ 608 609 unsigned long key = fibril_connection->in_task_hash; 610 link_t *lnk = hash_table_find(&client_hash_table, &key); 611 612 client_t *client; 613 614 if (lnk) { 615 client = hash_table_get_instance(lnk, client_t, link); 616 atomic_inc(&client->refcnt); 617 } else { 618 client = malloc(sizeof(client_t)); 619 if (!client) { 620 ipc_answer_0(fibril_connection->callid, ENOMEM); 621 futex_up(&async_futex); 622 return 0; 623 } 624 625 client->in_task_hash = fibril_connection->in_task_hash; 626 client->data = async_client_data_create(); 627 628 atomic_set(&client->refcnt, 1); 629 hash_table_insert(&client_hash_table, &key, &client->link); 630 } 631 632 futex_up(&async_futex); 633 690 691 client_t *client = async_client_get(fibril_connection->in_task_id, true); 692 if (!client) { 693 ipc_answer_0(fibril_connection->callid, ENOMEM); 694 return 0; 695 } 696 634 697 fibril_connection->client = client; 635 698 … … 643 706 * Remove the reference for this client task connection. 644 707 */ 645 bool destroy; 646 647 futex_down(&async_futex); 648 649 if (atomic_predec(&client->refcnt) == 0) { 650 hash_table_remove(&client_hash_table, &key, 1); 651 destroy = true; 652 } else 653 destroy = false; 654 655 futex_up(&async_futex); 656 657 if (destroy) { 658 if (client->data) 659 async_client_data_destroy(client->data); 660 661 free(client); 662 } 708 async_client_put(client); 663 709 664 710 /* … … 666 712 */ 667 713 futex_down(&async_futex); 668 key = fibril_connection->in_phone_hash;714 unsigned long key = fibril_connection->in_phone_hash; 669 715 hash_table_remove(&conn_hash_table, &key, 1); 670 716 futex_up(&async_futex); … … 700 746 * particular fibrils. 701 747 * 702 * @param in_task_ hashIdentification of the incoming connection.748 * @param in_task_id Identification of the incoming connection. 703 749 * @param in_phone_hash Identification of the incoming connection. 704 750 * @param callid Hash of the opening IPC_M_CONNECT_ME_TO call. … … 714 760 * 715 761 */ 716 fid_t async_new_connection( sysarg_t in_task_hash, sysarg_t in_phone_hash,762 fid_t async_new_connection(task_id_t in_task_id, sysarg_t in_phone_hash, 717 763 ipc_callid_t callid, ipc_call_t *call, 718 764 async_client_conn_t cfibril, void *carg) … … 726 772 } 727 773 728 conn->in_task_ hash = in_task_hash;774 conn->in_task_id = in_task_id; 729 775 conn->in_phone_hash = in_phone_hash; 730 776 list_initialize(&conn->msg_queue); … … 785 831 case IPC_M_CONNECT_ME_TO: 786 832 /* Open new connection with fibril, etc. */ 787 async_new_connection(call->in_task_ hash, IPC_GET_ARG5(*call),833 async_new_connection(call->in_task_id, IPC_GET_ARG5(*call), 788 834 callid, call, client_connection, NULL); 789 835 return; … … 933 979 { 934 980 if (!hash_table_create(&client_hash_table, CLIENT_HASH_TABLE_BUCKETS, 935 1, &client_hash_table_ops))981 2, &client_hash_table_ops)) 936 982 abort(); 937 983 … … 1426 1472 return ENOENT; 1427 1473 1428 sysarg_t task_hash; 1474 task_id_t task_id; 1475 sysarg_t task_id_lo; 1476 sysarg_t task_id_hi; 1429 1477 sysarg_t phone_hash; 1430 1478 int rc = async_req_3_5(exch, IPC_M_CONNECT_TO_ME, arg1, arg2, arg3, 1431 NULL, NULL, NULL, &task_hash, &phone_hash);1479 NULL, NULL, &task_id_lo, &task_id_hi, &phone_hash); 1432 1480 if (rc != EOK) 1433 1481 return rc; 1482 1483 task_id = (task_id_t) MERGE_LOUP32(task_id_lo, task_id_hi); 1434 1484 1435 1485 if (client_receiver != NULL) 1436 async_new_connection(task_ hash, phone_hash, 0, NULL,1486 async_new_connection(task_id, phone_hash, 0, NULL, 1437 1487 client_receiver, carg); 1438 1488 … … 2429 2479 } 2430 2480 2481 int async_state_change_start(async_exch_t *exch, sysarg_t arg1, sysarg_t arg2, 2482 sysarg_t arg3, async_exch_t *other_exch) 2483 { 2484 return async_req_5_0(exch, IPC_M_STATE_CHANGE_AUTHORIZE, 2485 arg1, arg2, arg3, 0, other_exch->phone); 2486 } 2487 2488 bool async_state_change_receive(ipc_callid_t *callid, sysarg_t *arg1, 2489 sysarg_t *arg2, sysarg_t *arg3) 2490 { 2491 assert(callid); 2492 2493 ipc_call_t call; 2494 *callid = async_get_call(&call); 2495 2496 if (IPC_GET_IMETHOD(call) != IPC_M_STATE_CHANGE_AUTHORIZE) 2497 return false; 2498 2499 if (arg1) 2500 *arg1 = IPC_GET_ARG1(call); 2501 if (arg2) 2502 *arg2 = IPC_GET_ARG2(call); 2503 if (arg3) 2504 *arg3 = IPC_GET_ARG3(call); 2505 2506 return true; 2507 } 2508 2509 int async_state_change_finalize(ipc_callid_t callid, async_exch_t *other_exch) 2510 { 2511 return ipc_answer_1(callid, EOK, other_exch->phone); 2512 } 2513 2431 2514 /** @} 2432 2515 */ -
uspace/lib/c/generic/devman.c
r0cf27ee r07b39338 1 1 /* 2 2 * Copyright (c) 2007 Josef Cejka 3 * Copyright (c) 20 09Jiri Svoboda3 * Copyright (c) 2011 Jiri Svoboda 4 4 * Copyright (c) 2010 Lenka Trochtova 5 5 * All rights reserved. … … 195 195 196 196 exch = devman_exchange_begin(DEVMAN_DRIVER); 197 async_connect_to_me(exch, 0, 0, 0, NULL, NULL);197 async_connect_to_me(exch, 0, 0, 0, conn, NULL); 198 198 devman_exchange_end(exch); 199 199 … … 271 271 } 272 272 273 int devman_add_device_to_c lass(devman_handle_t devman_handle,274 const char *c lass_name)273 int devman_add_device_to_category(devman_handle_t devman_handle, 274 const char *cat_name) 275 275 { 276 276 async_exch_t *exch = devman_exchange_begin_blocking(DEVMAN_DRIVER); 277 277 278 278 ipc_call_t answer; 279 aid_t req = async_send_1(exch, DEVMAN_ADD_DEVICE_TO_C LASS,279 aid_t req = async_send_1(exch, DEVMAN_ADD_DEVICE_TO_CATEGORY, 280 280 devman_handle, &answer); 281 sysarg_t retval = async_data_write_start(exch, c lass_name,282 str_size(c lass_name));281 sysarg_t retval = async_data_write_start(exch, cat_name, 282 str_size(cat_name)); 283 283 284 284 devman_exchange_end(exch); … … 308 308 } 309 309 310 /** Remove function from device. 311 * 312 * Request devman to remove function owned by this driver task. 313 * @param funh Devman handle of the function 314 * 315 * @return EOK on success or negative error code. 316 */ 317 int devman_remove_function(devman_handle_t funh) 318 { 319 async_exch_t *exch; 320 sysarg_t retval; 321 322 exch = devman_exchange_begin_blocking(DEVMAN_DRIVER); 323 retval = async_req_1_0(exch, DEVMAN_REMOVE_FUNCTION, (sysarg_t) funh); 324 devman_exchange_end(exch); 325 326 return (int) retval; 327 } 328 310 329 async_sess_t *devman_parent_device_connect(exch_mgmt_t mgmt, 311 330 devman_handle_t handle, unsigned int flags) … … 323 342 } 324 343 325 int devman_ device_get_handle(const char *pathname, devman_handle_t *handle,344 int devman_fun_get_handle(const char *pathname, devman_handle_t *handle, 326 345 unsigned int flags) 327 346 { … … 333 352 exch = devman_exchange_begin(DEVMAN_CLIENT); 334 353 if (exch == NULL) 335 return errno;354 return ENOMEM; 336 355 } 337 356 … … 364 383 } 365 384 366 int devman_device_get_handle_by_class(const char *classname,367 const char *devname, devman_handle_t *handle, unsigned int flags)385 static int devman_get_str_internal(sysarg_t method, sysarg_t arg1, char *buf, 386 size_t buf_size) 368 387 { 369 388 async_exch_t *exch; 370 371 if (flags & IPC_FLAG_BLOCKING) 372 exch = devman_exchange_begin_blocking(DEVMAN_CLIENT); 373 else { 374 exch = devman_exchange_begin(DEVMAN_CLIENT); 375 if (exch == NULL) 376 return errno; 377 } 389 ipc_call_t dreply; 390 size_t act_size; 391 sysarg_t dretval; 392 393 exch = devman_exchange_begin_blocking(LOC_PORT_CONSUMER); 378 394 379 395 ipc_call_t answer; 380 aid_t req = async_send_1(exch, DEVMAN_DEVICE_GET_HANDLE_BY_CLASS, 381 flags, &answer); 382 sysarg_t retval = async_data_write_start(exch, classname, 383 str_size(classname)); 396 aid_t req = async_send_1(exch, method, arg1, &answer); 397 aid_t dreq = async_data_read(exch, buf, buf_size - 1, &dreply); 398 async_wait_for(dreq, &dretval); 399 400 devman_exchange_end(exch); 401 402 if (dretval != EOK) { 403 async_wait_for(req, NULL); 404 return dretval; 405 } 406 407 sysarg_t retval; 408 async_wait_for(req, &retval); 409 410 if (retval != EOK) 411 return retval; 412 413 act_size = IPC_GET_ARG2(dreply); 414 assert(act_size <= buf_size - 1); 415 buf[act_size] = '\0'; 416 417 return EOK; 418 } 419 420 int devman_fun_get_path(devman_handle_t handle, char *buf, size_t buf_size) 421 { 422 return devman_get_str_internal(DEVMAN_FUN_GET_PATH, handle, buf, 423 buf_size); 424 } 425 426 int devman_fun_get_name(devman_handle_t handle, char *buf, size_t buf_size) 427 { 428 return devman_get_str_internal(DEVMAN_FUN_GET_NAME, handle, buf, 429 buf_size); 430 } 431 432 static int devman_get_handles_once(sysarg_t method, sysarg_t arg1, 433 devman_handle_t *handle_buf, size_t buf_size, size_t *act_size) 434 { 435 async_exch_t *exch = devman_exchange_begin_blocking(DEVMAN_CLIENT); 436 437 ipc_call_t answer; 438 aid_t req = async_send_1(exch, method, arg1, &answer); 439 int rc = async_data_read_start(exch, handle_buf, buf_size); 440 441 devman_exchange_end(exch); 442 443 if (rc != EOK) { 444 async_wait_for(req, NULL); 445 return rc; 446 } 447 448 sysarg_t retval; 449 async_wait_for(req, &retval); 384 450 385 451 if (retval != EOK) { 386 devman_exchange_end(exch); 387 async_wait_for(req, NULL); 388 return retval; 389 } 390 391 retval = async_data_write_start(exch, devname, 392 str_size(devname)); 393 394 devman_exchange_end(exch); 395 396 if (retval != EOK) { 397 async_wait_for(req, NULL); 398 return retval; 399 } 400 401 async_wait_for(req, &retval); 402 403 if (retval != EOK) { 404 if (handle != NULL) 405 *handle = (devman_handle_t) -1; 406 407 return retval; 408 } 409 410 if (handle != NULL) 411 *handle = (devman_handle_t) IPC_GET_ARG1(answer); 412 413 return retval; 414 } 415 416 int devman_get_device_path(devman_handle_t handle, char *path, size_t path_size) 452 return retval; 453 } 454 455 *act_size = IPC_GET_ARG1(answer); 456 return EOK; 457 } 458 459 /** Get list of handles. 460 * 461 * Returns an allocated array of handles. 462 * 463 * @param method IPC method 464 * @param arg1 IPC argument 1 465 * @param data Place to store pointer to array of handles 466 * @param count Place to store number of handles 467 * @return EOK on success or negative error code 468 */ 469 static int devman_get_handles_internal(sysarg_t method, sysarg_t arg1, 470 devman_handle_t **data, size_t *count) 471 { 472 devman_handle_t *handles; 473 size_t act_size; 474 size_t alloc_size; 475 int rc; 476 477 *data = NULL; 478 act_size = 0; /* silence warning */ 479 480 rc = devman_get_handles_once(method, arg1, NULL, 0, 481 &act_size); 482 if (rc != EOK) 483 return rc; 484 485 alloc_size = act_size; 486 handles = malloc(alloc_size); 487 if (handles == NULL) 488 return ENOMEM; 489 490 while (true) { 491 rc = devman_get_handles_once(method, arg1, handles, alloc_size, 492 &act_size); 493 if (rc != EOK) 494 return rc; 495 496 if (act_size <= alloc_size) 497 break; 498 499 alloc_size *= 2; 500 free(handles); 501 502 handles = malloc(alloc_size); 503 if (handles == NULL) 504 return ENOMEM; 505 } 506 507 *count = act_size / sizeof(devman_handle_t); 508 *data = handles; 509 return EOK; 510 } 511 512 int devman_fun_get_child(devman_handle_t funh, devman_handle_t *devh) 417 513 { 418 514 async_exch_t *exch = devman_exchange_begin(DEVMAN_CLIENT); 419 515 if (exch == NULL) 420 return errno;421 422 ipc_call_t answer;423 aid_t req = async_send_1(exch, DEVMAN_DEVICE_GET_DEVICE_PATH,424 handle, &answer);425 426 ipc_call_t data_request_call;427 aid_t data_request = async_data_read(exch, path, path_size,428 &data_request_call);429 430 devman_exchange_end(exch);431 432 if (data_request == 0) {433 async_wait_for(req, NULL);434 516 return ENOMEM; 435 } 436 437 sysarg_t data_request_rc; 438 async_wait_for(data_request, &data_request_rc); 439 440 sysarg_t opening_request_rc; 441 async_wait_for(req, &opening_request_rc); 442 443 if (data_request_rc != EOK) { 444 /* Prefer the return code of the opening request. */ 445 if (opening_request_rc != EOK) 446 return (int) opening_request_rc; 447 else 448 return (int) data_request_rc; 449 } 450 451 if (opening_request_rc != EOK) 452 return (int) opening_request_rc; 453 454 /* To be on the safe-side. */ 455 path[path_size - 1] = 0; 456 size_t transferred_size = IPC_GET_ARG2(data_request_call); 457 if (transferred_size >= path_size) 458 return ELIMIT; 459 460 /* Terminate the string (trailing 0 not send over IPC). */ 461 path[transferred_size] = 0; 462 return EOK; 517 518 sysarg_t retval = async_req_1_1(exch, DEVMAN_FUN_GET_CHILD, 519 funh, devh); 520 521 devman_exchange_end(exch); 522 return (int) retval; 523 } 524 525 int devman_dev_get_functions(devman_handle_t devh, devman_handle_t **funcs, 526 size_t *count) 527 { 528 return devman_get_handles_internal(DEVMAN_DEV_GET_FUNCTIONS, 529 devh, funcs, count); 530 } 531 532 int devman_fun_sid_to_handle(service_id_t sid, devman_handle_t *handle) 533 { 534 async_exch_t *exch = devman_exchange_begin(DEVMAN_CLIENT); 535 if (exch == NULL) 536 return ENOMEM; 537 538 sysarg_t retval = async_req_1_1(exch, DEVMAN_FUN_SID_TO_HANDLE, 539 sid, handle); 540 541 devman_exchange_end(exch); 542 return (int) retval; 463 543 } 464 544 -
uspace/lib/c/generic/event.c
r0cf27ee r07b39338 54 54 } 55 55 56 int event_task_subscribe(event_task_type_t evno, sysarg_t imethod) 57 { 58 return __SYSCALL2(SYS_EVENT_SUBSCRIBE, (sysarg_t) evno, 59 (sysarg_t) imethod); 60 } 61 56 62 /** Unmask event notifications. 57 63 * … … 66 72 } 67 73 74 int event_task_unmask(event_task_type_t evno) 75 { 76 return __SYSCALL1(SYS_EVENT_UNMASK, (sysarg_t) evno); 77 } 78 68 79 /** @} 69 80 */ -
uspace/lib/c/generic/io/io.c
r0cf27ee r07b39338 101 101 static LIST_INITIALIZE(files); 102 102 103 void __stdio_init(int filc , fdi_node_t *filv[])103 void __stdio_init(int filc) 104 104 { 105 105 if (filc > 0) { 106 stdin = f open_node(filv[0], "r");106 stdin = fdopen(0, "r"); 107 107 } else { 108 108 stdin = &stdin_null; … … 111 111 112 112 if (filc > 1) { 113 stdout = f open_node(filv[1], "w");113 stdout = fdopen(1, "w"); 114 114 } else { 115 115 stdout = &stdout_klog; … … 118 118 119 119 if (filc > 2) { 120 stderr = f open_node(filv[2], "w");120 stderr = fdopen(2, "w"); 121 121 } else { 122 122 stderr = &stderr_klog; … … 285 285 } 286 286 287 FILE *fopen_node(fdi_node_t *node, const char *mode)288 {289 int flags;290 if (!parse_mode(mode, &flags))291 return NULL;292 293 /* Open file. */294 FILE *stream = malloc(sizeof(FILE));295 if (stream == NULL) {296 errno = ENOMEM;297 return NULL;298 }299 300 stream->fd = open_node(node, flags);301 if (stream->fd < 0) {302 /* errno was set by open_node() */303 free(stream);304 return NULL;305 }306 307 stream->error = false;308 stream->eof = false;309 stream->klog = false;310 stream->sess = NULL;311 stream->need_sync = false;312 _setvbuf(stream);313 314 list_append(&stream->link, &files);315 316 return stream;317 }318 319 287 int fclose(FILE *stream) 320 288 { … … 780 748 } 781 749 782 int fnode(FILE *stream, fdi_node_t *node) 783 { 784 if (stream->fd >= 0) 785 return fd_node(stream->fd, node); 750 int fhandle(FILE *stream, int *handle) 751 { 752 if (stream->fd >= 0) { 753 *handle = stream->fd; 754 return EOK; 755 } 786 756 787 757 return ENOENT; -
uspace/lib/c/generic/io/printf_core.c
r0cf27ee r07b39338 206 206 } 207 207 208 return (int) (counter + 1);208 return (int) (counter); 209 209 } 210 210 … … 244 244 } 245 245 246 return (int) (counter + 1);246 return (int) (counter); 247 247 } 248 248 -
uspace/lib/c/generic/libc.c
r0cf27ee r07b39338 91 91 argc = 0; 92 92 argv = NULL; 93 __stdio_init(0 , NULL);93 __stdio_init(0); 94 94 } else { 95 95 argc = __pcb->argc; 96 96 argv = __pcb->argv; 97 __stdio_init(__pcb->filc , __pcb->filv);97 __stdio_init(__pcb->filc); 98 98 (void) chdir(__pcb->cwd); 99 99 } -
uspace/lib/c/generic/loader.c
r0cf27ee r07b39338 256 256 * 257 257 */ 258 int loader_set_files(loader_t *ldr, fdi_node_t *const files[]) 259 { 260 /* 261 * Serialize the arguments into a single array. First 262 * compute size of the buffer needed. 263 */ 264 fdi_node_t *const *ap = files; 265 size_t count = 0; 266 while (*ap != NULL) { 267 count++; 268 ap++; 269 } 270 271 fdi_node_t *files_buf; 272 files_buf = (fdi_node_t *) malloc(count * sizeof(fdi_node_t)); 273 if (files_buf == NULL) 274 return ENOMEM; 275 276 /* Fill the buffer */ 277 size_t i; 278 for (i = 0; i < count; i++) 279 files_buf[i] = *files[i]; 280 258 int loader_set_files(loader_t *ldr, int * const files[]) 259 { 281 260 /* Send serialized files to the loader */ 282 261 async_exch_t *exch = async_exchange_begin(ldr->sess); 283 284 ipc_call_t answer; 285 aid_t req = async_send_0(exch, LOADER_SET_FILES, &answer); 286 sysarg_t rc = async_data_write_start(exch, (void *) files_buf, 287 count * sizeof(fdi_node_t)); 288 289 async_exchange_end(exch); 290 free(files_buf); 291 262 async_exch_t *vfs_exch = vfs_exchange_begin(); 263 264 int i; 265 for (i = 0; files[i]; i++); 266 267 ipc_call_t answer; 268 aid_t req = async_send_1(exch, LOADER_SET_FILES, i, &answer); 269 270 sysarg_t rc = EOK; 271 272 for (i = 0; files[i]; i++) { 273 rc = async_state_change_start(exch, VFS_PASS_HANDLE, *files[i], 274 0, vfs_exch); 275 if (rc != EOK) 276 break; 277 } 278 279 vfs_exchange_end(vfs_exch); 280 async_exchange_end(exch); 281 292 282 if (rc != EOK) { 293 283 async_wait_for(req, NULL); -
uspace/lib/c/generic/loc.c
r0cf27ee r07b39338 45 45 static FIBRIL_MUTEX_INITIALIZE(loc_consumer_mutex); 46 46 47 static FIBRIL_MUTEX_INITIALIZE(loc_callback_mutex); 48 static bool loc_callback_created = false; 49 47 50 static async_sess_t *loc_supp_block_sess = NULL; 48 51 static async_sess_t *loc_cons_block_sess = NULL; … … 51 54 static async_sess_t *loc_consumer_sess = NULL; 52 55 56 static loc_cat_change_cb_t cat_change_cb = NULL; 57 58 static void loc_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg) 59 { 60 loc_cat_change_cb_t cb_fun; 61 62 while (true) { 63 ipc_call_t call; 64 ipc_callid_t callid = async_get_call(&call); 65 66 if (!IPC_GET_IMETHOD(call)) { 67 /* TODO: Handle hangup */ 68 return; 69 } 70 71 int retval; 72 73 switch (IPC_GET_IMETHOD(call)) { 74 case LOC_EVENT_CAT_CHANGE: 75 fibril_mutex_lock(&loc_callback_mutex); 76 cb_fun = cat_change_cb; 77 if (cb_fun != NULL) { 78 (*cb_fun)(); 79 } 80 fibril_mutex_unlock(&loc_callback_mutex); 81 retval = 0; 82 break; 83 default: 84 retval = ENOTSUP; 85 } 86 87 async_answer_0(callid, retval); 88 } 89 } 90 91 53 92 static void clone_session(fibril_mutex_t *mtx, async_sess_t *src, 54 93 async_sess_t **dst) … … 60 99 61 100 fibril_mutex_unlock(mtx); 101 } 102 103 static int loc_callback_create(void) 104 { 105 async_exch_t *exch; 106 sysarg_t retval; 107 int rc = EOK; 108 109 fibril_mutex_lock(&loc_callback_mutex); 110 111 if (!loc_callback_created) { 112 exch = loc_exchange_begin_blocking(LOC_PORT_CONSUMER); 113 114 ipc_call_t answer; 115 aid_t req = async_send_0(exch, LOC_CALLBACK_CREATE, &answer); 116 async_connect_to_me(exch, 0, 0, 0, loc_cb_conn, NULL); 117 loc_exchange_end(exch); 118 119 async_wait_for(req, &retval); 120 if (rc != EOK) 121 goto done; 122 123 if (retval != EOK) { 124 rc = retval; 125 goto done; 126 } 127 128 loc_callback_created = true; 129 } 130 131 rc = EOK; 132 done: 133 fibril_mutex_unlock(&loc_callback_mutex); 134 return rc; 62 135 } 63 136 … … 194 267 } 195 268 196 /** Register new device.197 * 198 * The @p interface is used when forwarding connection to the driver.269 /** Register new service. 270 * 271 * The @p interface is used when forwarding connection to the server. 199 272 * If not 0, the first argument is the interface and the second argument 200 273 * is the service ID. … … 203 276 * the handle (to ensure backward compatibility). 204 277 * 205 * @param fq dn Fully qualified device name.206 * @param[out] handle Handle to the created instance of device.207 * @param interface Interface when forwarding .208 * 209 */ 210 int loc_service_register_with_iface(const char *fq dn,211 service_id_t * handle, sysarg_t interface)278 * @param fqsn Fully qualified service name 279 * @param[out] sid Service ID of new service 280 * @param interface Interface when forwarding 281 * 282 */ 283 int loc_service_register_with_iface(const char *fqsn, 284 service_id_t *sid, sysarg_t interface) 212 285 { 213 286 async_exch_t *exch = loc_exchange_begin_blocking(LOC_PORT_SUPPLIER); … … 216 289 aid_t req = async_send_2(exch, LOC_SERVICE_REGISTER, interface, 0, 217 290 &answer); 218 sysarg_t retval = async_data_write_start(exch, fq dn, str_size(fqdn));291 sysarg_t retval = async_data_write_start(exch, fqsn, str_size(fqsn)); 219 292 220 293 loc_exchange_end(exch); … … 228 301 229 302 if (retval != EOK) { 230 if ( handle!= NULL)231 * handle= -1;232 233 return retval; 234 } 235 236 if ( handle!= NULL)237 * handle= (service_id_t) IPC_GET_ARG1(answer);303 if (sid != NULL) 304 *sid = -1; 305 306 return retval; 307 } 308 309 if (sid != NULL) 310 *sid = (service_id_t) IPC_GET_ARG1(answer); 238 311 239 312 return retval; 240 313 } 241 314 242 /** Register new device. 243 * 244 * @param fqdn Fully qualified device name. 245 * @param handle Output: Handle to the created instance of device. 246 * 247 */ 248 int loc_service_register(const char *fqdn, service_id_t *handle) 249 { 250 return loc_service_register_with_iface(fqdn, handle, 0); 315 /** Register new service. 316 * 317 * @param fqsn Fully qualified service name 318 * @param sid Output: ID of new service 319 * 320 */ 321 int loc_service_register(const char *fqdn, service_id_t *sid) 322 { 323 return loc_service_register_with_iface(fqdn, sid, 0); 324 } 325 326 /** Unregister service. 327 * 328 * @param sid Service ID 329 */ 330 int loc_service_unregister(service_id_t sid) 331 { 332 async_exch_t *exch; 333 sysarg_t retval; 334 335 exch = loc_exchange_begin_blocking(LOC_PORT_SUPPLIER); 336 retval = async_req_1_0(exch, LOC_SERVICE_UNREGISTER, sid); 337 loc_exchange_end(exch); 338 339 return (int)retval; 251 340 } 252 341 … … 291 380 } 292 381 293 /** Get service name. 294 * 295 * Provided ID of a service, return its name. 296 * 297 * @param svc_id Service ID 382 /** Get object name. 383 * 384 * Provided ID of an object, return its name. 385 * 386 * @param method IPC method 387 * @param id Object ID 298 388 * @param name Place to store pointer to new string. Caller should 299 389 * free it using free(). 300 390 * @return EOK on success or negative error code 301 391 */ 302 int loc_service_get_name(service_id_t svc_id, char **name)392 static int loc_get_name_internal(sysarg_t method, sysarg_t id, char **name) 303 393 { 304 394 async_exch_t *exch; … … 312 402 313 403 ipc_call_t answer; 314 aid_t req = async_send_1(exch, LOC_SERVICE_GET_NAME, svc_id, &answer);404 aid_t req = async_send_1(exch, method, id, &answer); 315 405 aid_t dreq = async_data_read(exch, name_buf, LOC_NAME_MAXLEN, 316 406 &dreply); … … 341 431 } 342 432 433 /** Get category name. 434 * 435 * Provided ID of a service, return its name. 436 * 437 * @param cat_id Category ID 438 * @param name Place to store pointer to new string. Caller should 439 * free it using free(). 440 * @return EOK on success or negative error code 441 */ 442 int loc_category_get_name(category_id_t cat_id, char **name) 443 { 444 return loc_get_name_internal(LOC_CATEGORY_GET_NAME, cat_id, name); 445 } 446 447 /** Get service name. 448 * 449 * Provided ID of a service, return its name. 450 * 451 * @param svc_id Service ID 452 * @param name Place to store pointer to new string. Caller should 453 * free it using free(). 454 * @return EOK on success or negative error code 455 */ 456 int loc_service_get_name(service_id_t svc_id, char **name) 457 { 458 return loc_get_name_internal(LOC_SERVICE_GET_NAME, svc_id, name); 459 } 343 460 344 461 int loc_namespace_get_id(const char *name, service_id_t *handle, … … 749 866 data, count); 750 867 } 868 869 int loc_register_cat_change_cb(loc_cat_change_cb_t cb_fun) 870 { 871 if (loc_callback_create() != EOK) 872 return EIO; 873 874 cat_change_cb = cb_fun; 875 return EOK; 876 } -
uspace/lib/c/generic/private/async.h
r0cf27ee r07b39338 36 36 #define LIBC_PRIVATE_ASYNC_H_ 37 37 38 #include <ipc/common.h> 38 39 #include <adt/list.h> 39 40 #include <fibril.h> -
uspace/lib/c/generic/private/io.h
r0cf27ee r07b39338 36 36 #define LIBC_PRIVATE_IO_H_ 37 37 38 #include <vfs/vfs.h> 39 40 extern void __stdio_init(int filc, fdi_node_t *filv[]); 38 extern void __stdio_init(int); 41 39 extern void __stdio_done(void); 42 40 -
uspace/lib/c/generic/task.c
r0cf27ee r07b39338 46 46 #include <libc.h> 47 47 #include "private/ns.h" 48 #include <vfs/vfs.h> 48 49 49 50 task_id_t task_get_id(void) … … 102 103 { 103 104 /* Send default files */ 104 fdi_node_t *files[4];105 fdi_node_t stdin_node;106 fdi_node_t stdout_node;107 fdi_node_t stderr_node;108 109 if ((stdin != NULL) && (f node(stdin, &stdin_node) == EOK))110 files[0] = & stdin_node;105 int *files[4]; 106 int fd_stdin; 107 int fd_stdout; 108 int fd_stderr; 109 110 if ((stdin != NULL) && (fhandle(stdin, &fd_stdin) == EOK)) 111 files[0] = &fd_stdin; 111 112 else 112 113 files[0] = NULL; 113 114 114 if ((stdout != NULL) && (f node(stdout, &stdout_node) == EOK))115 files[1] = & stdout_node;115 if ((stdout != NULL) && (fhandle(stdout, &fd_stdout) == EOK)) 116 files[1] = &fd_stdout; 116 117 else 117 118 files[1] = NULL; 118 119 119 if ((stderr != NULL) && (f node(stderr, &stderr_node) == EOK))120 files[2] = & stderr_node;120 if ((stderr != NULL) && (fhandle(stderr, &fd_stderr) == EOK)) 121 files[2] = &fd_stderr; 121 122 else 122 123 files[2] = NULL; … … 142 143 */ 143 144 int task_spawnvf(task_id_t *id, const char *path, const char *const args[], 144 fdi_node_t *const files[])145 int *const files[]) 145 146 { 146 147 /* Connect to a program loader. */ -
uspace/lib/c/generic/vfs/vfs.c
r0cf27ee r07b39338 69 69 * 70 70 */ 71 staticasync_exch_t *vfs_exchange_begin(void)71 async_exch_t *vfs_exchange_begin(void) 72 72 { 73 73 fibril_mutex_lock(&vfs_mutex); … … 87 87 * 88 88 */ 89 staticvoid vfs_exchange_end(async_exch_t *exch)89 void vfs_exchange_end(async_exch_t *exch) 90 90 { 91 91 async_exchange_end(exch); … … 329 329 } 330 330 331 int open_node(fdi_node_t *node, int oflag)332 {333 async_exch_t *exch = vfs_exchange_begin();334 335 ipc_call_t answer;336 aid_t req = async_send_4(exch, VFS_IN_OPEN_NODE, node->fs_handle,337 node->service_id, node->index, oflag, &answer);338 339 vfs_exchange_end(exch);340 341 sysarg_t rc;342 async_wait_for(req, &rc);343 344 if (rc != EOK)345 return (int) rc;346 347 return (int) IPC_GET_ARG1(answer);348 }349 350 331 int close(int fildes) 351 332 { … … 819 800 } 820 801 821 int fd_node(int fildes, fdi_node_t *node)822 {823 struct stat stat;824 int rc = fstat(fildes, &stat);825 826 if (rc == EOK) {827 node->fs_handle = stat.fs_handle;828 node->service_id = stat.service_id;829 node->index = stat.index;830 }831 832 return rc;833 }834 835 802 int dup2(int oldfd, int newfd) 836 803 { … … 848 815 } 849 816 817 int fd_wait(void) 818 { 819 async_exch_t *exch = vfs_exchange_begin(); 820 821 sysarg_t ret; 822 sysarg_t rc = async_req_0_1(exch, VFS_IN_WAIT_HANDLE, &ret); 823 824 vfs_exchange_end(exch); 825 826 if (rc == EOK) 827 return (int) ret; 828 829 return (int) rc; 830 } 831 850 832 /** @} 851 833 */ -
uspace/lib/c/include/async.h
r0cf27ee r07b39338 176 176 extern int async_wait_timeout(aid_t, sysarg_t *, suseconds_t); 177 177 178 extern fid_t async_new_connection( sysarg_t, sysarg_t, ipc_callid_t,178 extern fid_t async_new_connection(task_id_t, sysarg_t, ipc_callid_t, 179 179 ipc_call_t *, async_client_conn_t, void *); 180 180 … … 186 186 extern void async_set_client_data_destructor(async_client_data_dtor_t); 187 187 extern void *async_get_client_data(void); 188 extern void *async_get_client_data_by_id(task_id_t); 189 extern void async_put_client_data_by_id(task_id_t); 188 190 189 191 extern void async_set_client_connection(async_client_conn_t); … … 477 479 extern async_sess_t *async_callback_receive_start(exch_mgmt_t, ipc_call_t *); 478 480 481 extern int async_state_change_start(async_exch_t *, sysarg_t, sysarg_t, 482 sysarg_t, async_exch_t *); 483 extern bool async_state_change_receive(ipc_callid_t *, sysarg_t *, sysarg_t *, 484 sysarg_t *); 485 extern int async_state_change_finalize(ipc_callid_t, async_exch_t *); 486 479 487 #endif 480 488 -
uspace/lib/c/include/devman.h
r0cf27ee r07b39338 38 38 39 39 #include <ipc/devman.h> 40 #include <ipc/loc.h> 40 41 #include <async.h> 41 42 #include <bool.h> … … 48 49 extern int devman_add_function(const char *, fun_type_t, match_id_list_t *, 49 50 devman_handle_t, devman_handle_t *); 51 extern int devman_remove_function(devman_handle_t); 50 52 51 53 extern async_sess_t *devman_device_connect(exch_mgmt_t, devman_handle_t, … … 54 56 unsigned int); 55 57 56 extern int devman_ device_get_handle(const char *, devman_handle_t *,58 extern int devman_fun_get_handle(const char *, devman_handle_t *, 57 59 unsigned int); 58 extern int devman_device_get_handle_by_class(const char *, const char *, 59 devman_handle_t *, unsigned int); 60 extern int devman_get_device_path(devman_handle_t, char *, size_t); 60 extern int devman_fun_get_child(devman_handle_t, devman_handle_t *); 61 extern int devman_dev_get_functions(devman_handle_t, devman_handle_t **, 62 size_t *); 63 extern int devman_fun_get_name(devman_handle_t, char *, size_t); 64 extern int devman_fun_get_path(devman_handle_t, char *, size_t); 61 65 62 extern int devman_add_device_to_class(devman_handle_t, const char *); 66 extern int devman_add_device_to_category(devman_handle_t, const char *); 67 extern int devman_fun_sid_to_handle(service_id_t, devman_handle_t *); 63 68 64 69 #endif -
uspace/lib/c/include/event.h
r0cf27ee r07b39338 37 37 38 38 #include <abi/ipc/event.h> 39 #include <libarch/types.h> 39 40 40 41 extern int event_subscribe(event_type_t, sysarg_t); 42 extern int event_task_subscribe(event_task_type_t, sysarg_t); 41 43 extern int event_unmask(event_type_t); 44 extern int event_task_unmask(event_task_type_t); 42 45 43 46 #endif -
uspace/lib/c/include/ipc/common.h
r0cf27ee r07b39338 39 39 #include <abi/ipc/ipc.h> 40 40 #include <atomic.h> 41 #include <task.h> 41 42 42 43 #define IPC_FLAG_BLOCKING 0x01 … … 44 45 typedef struct { 45 46 sysarg_t args[IPC_CALL_LEN]; 46 sysarg_t in_task_hash;47 task_id_t in_task_id; 47 48 sysarg_t in_phone_hash; 48 49 } ipc_call_t; -
uspace/lib/c/include/ipc/devman.h
r0cf27ee r07b39338 138 138 DEVMAN_ADD_FUNCTION, 139 139 DEVMAN_ADD_MATCH_ID, 140 DEVMAN_ADD_DEVICE_TO_C LASS141 140 DEVMAN_ADD_DEVICE_TO_CATEGORY, 141 DEVMAN_REMOVE_FUNCTION 142 142 } driver_to_devman_t; 143 143 … … 149 149 typedef enum { 150 150 DEVMAN_DEVICE_GET_HANDLE = IPC_FIRST_USER_METHOD, 151 DEVMAN_DEVICE_GET_HANDLE_BY_CLASS, 152 DEVMAN_DEVICE_GET_DEVICE_PATH 151 DEVMAN_DEV_GET_FUNCTIONS, 152 DEVMAN_FUN_GET_CHILD, 153 DEVMAN_FUN_GET_NAME, 154 DEVMAN_FUN_GET_PATH, 155 DEVMAN_FUN_SID_TO_HANDLE 153 156 } client_to_devman_t; 154 157 -
uspace/lib/c/include/ipc/loc.h
r0cf27ee r07b39338 57 57 LOC_SERVICE_GET_NAME, 58 58 LOC_NAMESPACE_GET_ID, 59 LOC_CALLBACK_CREATE, 59 60 LOC_CATEGORY_GET_ID, 61 LOC_CATEGORY_GET_NAME, 60 62 LOC_CATEGORY_GET_SVCS, 61 63 LOC_ID_PROBE, … … 68 70 LOC_GET_SERVICES 69 71 } loc_request_t; 72 73 typedef enum { 74 LOC_EVENT_CAT_CHANGE = IPC_FIRST_USER_METHOD 75 } loc_event_t; 70 76 71 77 /** Ports provided by location service. -
uspace/lib/c/include/ipc/vfs.h
r0cf27ee r07b39338 62 62 typedef enum { 63 63 VFS_IN_OPEN = IPC_FIRST_USER_METHOD, 64 VFS_IN_OPEN_NODE,65 64 VFS_IN_READ, 66 65 VFS_IN_WRITE, … … 78 77 VFS_IN_RENAME, 79 78 VFS_IN_STAT, 80 VFS_IN_DUP 79 VFS_IN_DUP, 80 VFS_IN_WAIT_HANDLE, 81 81 } vfs_in_request_t; 82 82 -
uspace/lib/c/include/loader/loader.h
r0cf27ee r07b39338 38 38 39 39 #include <task.h> 40 #include <vfs/vfs.h>41 40 42 41 /** Forward declararion */ … … 50 49 extern int loader_set_pathname(loader_t *, const char *); 51 50 extern int loader_set_args(loader_t *, const char *const[]); 52 extern int loader_set_files(loader_t *, fdi_node_t *const[]);51 extern int loader_set_files(loader_t *, int *const[]); 53 52 extern int loader_load_program(loader_t *); 54 53 extern int loader_run(loader_t *); -
uspace/lib/c/include/loader/pcb.h
r0cf27ee r07b39338 38 38 39 39 #include <sys/types.h> 40 #include <vfs/vfs.h>41 40 42 41 typedef void (*entry_point_t)(void); … … 62 61 63 62 /** Number of preset files. */ 64 int filc; 65 /** Preset files. */ 66 fdi_node_t **filv; 63 unsigned int filc; 67 64 68 65 /* -
uspace/lib/c/include/loc.h
r0cf27ee r07b39338 40 40 #include <bool.h> 41 41 42 typedef void (*loc_cat_change_cb_t)(void); 43 42 44 extern async_exch_t *loc_exchange_begin_blocking(loc_interface_t); 43 45 extern async_exch_t *loc_exchange_begin(loc_interface_t); … … 48 50 extern int loc_service_register_with_iface(const char *, service_id_t *, 49 51 sysarg_t); 52 extern int loc_service_unregister(service_id_t); 50 53 extern int loc_service_add_to_cat(service_id_t, category_id_t); 51 54 … … 73 76 extern size_t loc_get_services(service_id_t, loc_sdesc_t **); 74 77 extern int loc_get_categories(category_id_t **, size_t *); 78 extern int loc_register_cat_change_cb(loc_cat_change_cb_t); 75 79 76 80 -
uspace/lib/c/include/task.h
r0cf27ee r07b39338 37 37 38 38 #include <sys/types.h> 39 #include <vfs/vfs.h>40 39 41 40 typedef uint64_t task_id_t; … … 53 52 extern int task_spawnv(task_id_t *, const char *path, const char *const []); 54 53 extern int task_spawnvf(task_id_t *, const char *path, const char *const [], 55 fdi_node_t *const []);54 int *const []); 56 55 extern int task_spawnl(task_id_t *, const char *path, ...); 57 56 -
uspace/lib/c/include/vfs/vfs.h
r0cf27ee r07b39338 40 40 #include <ipc/loc.h> 41 41 #include <stdio.h> 42 #include <async.h> 42 43 43 /** Libc version of the VFS triplet. 44 * 45 * Unique identification of a file system node 46 * within a file system instance. 47 * 48 */ 49 typedef struct { 50 fs_handle_t fs_handle; 51 service_id_t service_id; 52 fs_index_t index; 53 } fdi_node_t; 44 enum vfs_change_state_type { 45 VFS_PASS_HANDLE 46 }; 54 47 55 48 extern char *absolutize(const char *, size_t *); … … 59 52 extern int unmount(const char *); 60 53 61 extern int open_node(fdi_node_t *, int); 62 extern int fd_node(int, fdi_node_t *); 54 extern int fhandle(FILE *, int *); 63 55 64 extern FILE *fopen_node(fdi_node_t *, const char *); 65 extern int fnode(FILE *, fdi_node_t *); 56 extern int fd_wait(void); 57 58 extern async_exch_t *vfs_exchange_begin(void); 59 extern void vfs_exchange_end(async_exch_t *); 66 60 67 61 #endif -
uspace/lib/drv/generic/driver.c
r0cf27ee r07b39338 428 428 static void driver_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg) 429 429 { 430 sysarg_t conn_type; 431 432 if (iid == 0) { 433 /* Callback connection from devman */ 434 /* XXX Use separate handler for this type of connection */ 435 conn_type = DRIVER_DEVMAN; 436 } else { 437 conn_type = IPC_GET_ARG1(*icall); 438 } 439 430 440 /* Select interface */ 431 switch ( (sysarg_t) (IPC_GET_ARG1(*icall))) {441 switch (conn_type) { 432 442 case DRIVER_DEVMAN: 433 443 /* Handle request from device manager */ … … 582 592 int ddf_fun_bind(ddf_fun_t *fun) 583 593 { 594 assert(fun->bound == false); 584 595 assert(fun->name != NULL); 585 596 … … 598 609 } 599 610 611 /** Unbind a function node. 612 * 613 * Unbind the specified function from the system. This effectively makes 614 * the function invisible to the system. 615 * 616 * @param fun Function to bind 617 * @return EOK on success or negative error code 618 */ 619 int ddf_fun_unbind(ddf_fun_t *fun) 620 { 621 int res; 622 623 assert(fun->bound == true); 624 625 add_to_functions_list(fun); 626 res = devman_remove_function(fun->handle); 627 if (res != EOK) 628 return res; 629 630 remove_from_functions_list(fun); 631 632 fun->bound = false; 633 return EOK; 634 } 635 600 636 /** Add single match ID to inner function. 601 637 * … … 635 671 } 636 672 637 /** Add exposed function to c lass.673 /** Add exposed function to category. 638 674 * 639 675 * Must only be called when the function is bound. 640 676 */ 641 int ddf_fun_add_to_c lass(ddf_fun_t *fun, const char *class_name)677 int ddf_fun_add_to_category(ddf_fun_t *fun, const char *cat_name) 642 678 { 643 679 assert(fun->bound == true); 644 680 assert(fun->ftype == fun_exposed); 645 681 646 return devman_add_device_to_c lass(fun->handle, class_name);682 return devman_add_device_to_category(fun->handle, cat_name); 647 683 } 648 684 -
uspace/lib/drv/include/ddf/driver.h
r0cf27ee r07b39338 149 149 extern void ddf_fun_destroy(ddf_fun_t *); 150 150 extern int ddf_fun_bind(ddf_fun_t *); 151 extern int ddf_fun_unbind(ddf_fun_t *); 151 152 extern int ddf_fun_add_match_id(ddf_fun_t *, const char *, int); 152 153 153 extern int ddf_fun_add_to_c lass(ddf_fun_t *, const char *);154 extern int ddf_fun_add_to_category(ddf_fun_t *, const char *); 154 155 155 156 #endif -
uspace/lib/posix/ctype.c
r0cf27ee r07b39338 37 37 38 38 #include "ctype.h" 39 40 // TODO: propose for inclusion in libc41 39 42 40 /** -
uspace/lib/posix/errno.h
r0cf27ee r07b39338 57 57 * redefinition for such error codes. 58 58 * 59 * FIXME: maybe all HOS error codes should be redefined59 * XXX: maybe all HOS error codes should be redefined 60 60 * 61 61 * NOTE: This redefinition is slightly POSIX incompatible, since the -
uspace/lib/posix/fcntl.c
r0cf27ee r07b39338 52 52 int posix_fcntl(int fd, int cmd, ...) 53 53 { 54 int rc;55 54 int flags; 56 55 57 56 switch (cmd) { 58 57 case F_DUPFD: 59 case F_DUPFD_CLOEXEC: /* FD_CLOEXEC is not supported. */ 60 /* VFS does not provide means to express constraints on the new 61 * file descriptor so the third argument is ignored. */ 62 63 /* Retrieve node triplet corresponding to the file descriptor. */ 64 /* Empty statement after label. */; 65 fdi_node_t node; 66 rc = fd_node(fd, &node); 67 if (rc != EOK) { 68 errno = -rc; 69 return -1; 70 } 71 72 /* Reopen the node so the fresh file descriptor is generated. */ 73 int newfd = open_node(&node, 0); 74 if (newfd < 0) { 75 errno = -newfd; 76 return -1; 77 } 78 79 /* Associate the newly generated descriptor to the file description 80 * of the old file descriptor. Just reopened node will be automatically 81 * closed. */ 82 rc = dup2(fd, newfd); 83 if (rc != EOK) { 84 errno = -rc; 85 return -1; 86 } 87 88 return newfd; 58 case F_DUPFD_CLOEXEC: 59 /* VFS currently does not provide the functionality to duplicate 60 * opened file descriptor. */ 61 // FIXME: implement this once dup() is available 62 errno = ENOTSUP; 63 return -1; 89 64 case F_GETFD: 90 65 /* FD_CLOEXEC is not supported. There are no other flags. */ -
uspace/lib/posix/fnmatch.c
r0cf27ee r07b39338 66 66 #define COLL_ELM_INVALID -1 67 67 68 /** Get collating element matching a string. 69 * 70 * @param str 68 /** 69 * Get collating element matching a string. 70 * 71 * @param str String representation of the element. 71 72 * @return Matching collating element or COLL_ELM_INVALID. 72 73 */ … … 79 80 } 80 81 81 /** Get collating element matching a single character. 82 * 83 * @param c 84 * @return 82 /** 83 * Get collating element matching a single character. 84 * 85 * @param c Character representation of the element. 86 * @return Matching collating element. 85 87 */ 86 88 static coll_elm_t _coll_elm_char(int c) … … 89 91 } 90 92 91 /** Match collating element with a beginning of a string. 92 * 93 * @param elm 94 * @param str 93 /** 94 * Match collating element with a beginning of a string. 95 * 96 * @param elm Collating element to match. 97 * @param str String which beginning should match the element. 95 98 * @return 0 if the element doesn't match, or the number of characters matched. 96 99 */ … … 100 103 } 101 104 102 /** Checks whether a string begins with a collating element in the given range. 103 * Ordering depends on the locale (if locales are supported). 105 /** 106 * Checks whether a string begins with a collating element in the given range. 107 * Ordering depends on the locale (if locales are supported). 104 108 * 105 109 * @param first First element of the range. … … 114 118 } 115 119 116 /** Read a string delimited by [? and ?]. 120 /** 121 * Read a string delimited by [? and ?]. 117 122 * 118 123 * @param pattern Pointer to the string to read from. Its position is moved … … 189 194 }; 190 195 191 /** Compare function for binary search in the _char_classes array. 196 /** 197 * Compare function for binary search in the _char_classes array. 192 198 * 193 * @param key 194 * @param elem 195 * @return 199 * @param key Key of the searched element. 200 * @param elem Element of _char_classes array. 201 * @return Ordering indicator (-1 less than, 0 equal, 1 greater than). 196 202 */ 197 203 static int _class_compare(const void *key, const void *elem) … … 201 207 } 202 208 203 /** Returns whether the given character belongs to the specified character class. 209 /** 210 * Returns whether the given character belongs to the specified character class. 204 211 * 205 212 * @param cname Name of the character class. … … 223 230 } 224 231 225 /** Tries to parse an initial part of the pattern as a character class pattern, 226 * and if successful, matches the beginning of the given string against the class. 232 /** 233 * Tries to parse an initial part of the pattern as a character class pattern, 234 * and if successful, matches the beginning of the given string against the class. 227 235 * 228 236 * @param pattern Pointer to the pattern to match. Must begin with a class … … 248 256 /************** END CHARACTER CLASSES ****************/ 249 257 250 /** Reads the next collating element in the pattern, taking into account 251 * locale (if supported) and flags (see fnmatch()). 258 /** 259 * Reads the next collating element in the pattern, taking into account 260 * locale (if supported) and flags (see fnmatch()). 252 261 * 253 262 * @param pattern Pattern. … … 299 308 } 300 309 301 /** Matches the beginning of the given string against a bracket expression 302 * the pattern begins with. 310 /** 311 * Matches the beginning of the given string against a bracket expression 312 * the pattern begins with. 303 313 * 304 314 * @param pattern Pointer to the beginning of a bracket expression in a pattern. … … 394 404 } 395 405 396 /** Matches a portion of the pattern containing no asterisks (*) against 397 * the given string. 406 /** 407 * Matches a portion of the pattern containing no asterisks (*) against 408 * the given string. 398 409 * 399 410 * @param pattern Pointer to the unmatched portion of the pattern. … … 497 508 } 498 509 499 /** Match string against a pattern. 510 /** 511 * Match string against a pattern. 500 512 * 501 513 * @param pattern Pattern. … … 559 571 } 560 572 561 /** Transform the entire string to lowercase. 573 /** 574 * Transform the entire string to lowercase. 562 575 * 563 576 * @param s Input string. … … 578 591 * Filename pattern matching. 579 592 * 580 * @param pattern 581 * @param string 582 * @param flags 583 * @return 593 * @param pattern Pattern to match the string against. 594 * @param string Matched string. 595 * @param flags Flags altering the matching of special characters 596 * (mainly for dot and slash). 597 * @return Zero if the string matches the pattern, FNM_NOMATCH otherwise. 584 598 */ 585 599 int posix_fnmatch(const char *pattern, const char *string, int flags) … … 610 624 } 611 625 612 // FIXME: put the testcases somewhere else626 // FIXME: put the testcases to the app/tester after fnmatch is included into libc 613 627 614 628 #if 0 -
uspace/lib/posix/locale.c
r0cf27ee r07b39338 79 79 }; 80 80 81 /** Set program locale. 81 /** 82 * Set program locale. 82 83 * 83 84 * @param category What category to set. … … 95 96 } 96 97 97 /** Return locale-specific information. 98 /** 99 * Return locale-specific information. 98 100 * 99 101 * @return Information about the current locale. … … 105 107 } 106 108 107 /** Duplicate locale object. 109 /** 110 * Duplicate locale object. 108 111 * 109 112 * @param locobj Object to duplicate. … … 125 128 } 126 129 127 /** Free locale object. 130 /** 131 * Free locale object. 128 132 * 129 133 * @param locobj Object to free. … … 136 140 } 137 141 138 /** Create or modify a locale object. 142 /** 143 * Create or modify a locale object. 139 144 * 140 145 * @param category_mask Mask of categories to be set or modified. … … 163 168 } 164 169 165 /** Set locale for the current thread. 170 /** 171 * Set locale for the current thread. 166 172 * 167 173 * @param newloc Locale to use. -
uspace/lib/posix/pwd.c
r0cf27ee r07b39338 51 51 52 52 /** 53 * Retrieve next broken-down entry from the user database. 54 * 53 55 * Since HelenOS doesn't have user accounts, this always returns 54 56 * the same made-up entry. 55 57 * 56 * @return 58 * @return Next user database entry or NULL if not possible. Since HelenOS 59 * doesn't have user accounts, this always returns the same made-up entry. 57 60 */ 58 61 struct posix_passwd *posix_getpwent(void) … … 67 70 68 71 /** 69 * "Rewind the user list".72 * Rewind the user list. 70 73 */ 71 74 void posix_setpwent(void) … … 86 89 * 87 90 * @param name Name of the entry. 88 * @return 91 * @return Either found entry or NULL if no such entry exists. 89 92 */ 90 93 struct posix_passwd *posix_getpwnam(const char *name) … … 103 106 * 104 107 * @param name Name of the entry. 105 * @param pwd 106 * @param buffer 107 * @param bufsize 108 * @param result 109 * @return 108 * @param pwd Original structure. 109 * @param buffer Buffer for the strings referenced from the result structure. 110 * @param bufsize Length of the buffer. 111 * @param result Where to store updated structure. 112 * @return Zero on success (either found or not found, but without an error), 113 * non-zero error number if error occured. 110 114 */ 111 115 int posix_getpwnam_r(const char *name, struct posix_passwd *pwd, … … 129 133 * 130 134 * @param uid UID of the entry. 131 * @return 135 * @return Either found entry or NULL if no such entry exists. 132 136 */ 133 137 struct posix_passwd *posix_getpwuid(posix_uid_t uid) … … 144 148 * 145 149 * @param uid UID of the entry. 146 * @param pwd 147 * @param buffer 148 * @param bufsize 149 * @param result 150 * @return 150 * @param pwd Original structure. 151 * @param buffer Buffer for the strings referenced from the result structure. 152 * @param bufsize Length of the buffer. 153 * @param result Where to store updated structure. 154 * @return Zero on success (either found or not found, but without an error), 155 * non-zero error number if error occured. 151 156 */ 152 157 int posix_getpwuid_r(posix_uid_t uid, struct posix_passwd *pwd, -
uspace/lib/posix/signal.c
r0cf27ee r07b39338 136 136 } 137 137 138 /** Just an empty function to get an unique pointer value for comparison. 139 * 140 * @param signo 138 /** 139 * Just an empty function to get an unique pointer value for comparison. 140 * 141 * @param signo Signal number. 141 142 */ 142 143 void __posix_hold_signal_handler(int signo) … … 145 146 } 146 147 147 /** Empty function to be used as ignoring handler. 148 * 149 * @param signo 148 /** 149 * Empty function to be used as ignoring handler. 150 * 151 * @param signo Signal number. 150 152 */ 151 153 void __posix_ignore_signal_handler(int signo) … … 154 156 } 155 157 156 /** Clear the signal set. 158 /** 159 * Clear the signal set. 157 160 * 158 161 * @param set Pointer to the signal set. … … 167 170 } 168 171 169 /** Fill the signal set (i.e. add all signals). 172 /** 173 * Fill the signal set (i.e. add all signals). 170 174 * 171 175 * @param set Pointer to the signal set. … … 180 184 } 181 185 182 /** Add a signal to the set. 186 /** 187 * Add a signal to the set. 183 188 * 184 189 * @param set Pointer to the signal set. … … 194 199 } 195 200 196 /** Delete a signal from the set. 201 /** 202 * Delete a signal from the set. 197 203 * 198 204 * @param set Pointer to the signal set. … … 208 214 } 209 215 210 /** Inclusion test for a signal set. 216 /** 217 * Inclusion test for a signal set. 211 218 * 212 219 * @param set Pointer to the signal set. … … 221 228 } 222 229 223 /** Unsafe variant of the sigaction() function. 224 * Doesn't do any checking of its arguments and 225 * does not deal with thread-safety. 230 /** 231 * Unsafe variant of the sigaction() function. 232 * Doesn't do any checking of its arguments and 233 * does not deal with thread-safety. 226 234 * 227 235 * @param sig … … 243 251 } 244 252 245 /** Sets a new action for the given signal number. 253 /** 254 * Sets a new action for the given signal number. 246 255 * 247 256 * @param sig Signal number to set action for. … … 276 285 } 277 286 278 /** Sets a new handler for the given signal number. 287 /** 288 * Sets a new handler for the given signal number. 279 289 * 280 290 * @param sig Signal number to set handler for. … … 304 314 } signal_queue_item; 305 315 306 /** Queue blocked signal. 316 /** 317 * Queue blocked signal. 307 318 * 308 319 * @param signo Signal number. … … 322 333 323 334 324 /** Executes an action associated with the given signal. 335 /** 336 * Executes an action associated with the given signal. 325 337 * 326 338 * @param signo Signal number. … … 366 378 } 367 379 368 /** Raise all unblocked previously queued signals. 380 /** 381 * Raise all unblocked previously queued signals. 369 382 */ 370 383 static void _dequeue_unblocked_signals() … … 390 403 } 391 404 392 /** Raise a signal for the calling process. 405 /** 406 * Raise a signal for the calling process. 393 407 * 394 408 * @param sig Signal number. … … 409 423 } 410 424 411 /** Raises a signal for a selected process. 425 /** 426 * Raises a signal for a selected process. 412 427 * 413 428 * @param pid PID of the process for which the signal shall be raised. … … 446 461 } 447 462 448 /** Send a signal to a process group. Always fails at the moment because of 449 * lack of this functionality in HelenOS. 463 /** 464 * Send a signal to a process group. Always fails at the moment because of 465 * lack of this functionality in HelenOS. 450 466 * 451 467 * @param pid PID of the process group. … … 459 475 } 460 476 461 /** Outputs information about the signal to the standard error stream. 477 /** 478 * Outputs information about the signal to the standard error stream. 462 479 * 463 480 * @param pinfo SigInfo struct to write. … … 471 488 } 472 489 473 /** Outputs information about the signal to the standard error stream. 490 /** 491 * Outputs information about the signal to the standard error stream. 474 492 * 475 493 * @param signum Signal number. … … 486 504 } 487 505 488 /** Manipulate the signal mask of the calling thread. 506 /** 507 * Manipulate the signal mask of the calling thread. 489 508 * 490 509 * @param how What to do with the mask. … … 525 544 } 526 545 527 /** Manipulate the signal mask of the process. 546 /** 547 * Manipulate the signal mask of the process. 528 548 * 529 549 * @param how What to do with the mask. -
uspace/lib/posix/stdbool.h
r0cf27ee r07b39338 36 36 #define POSIX_STDBOOL_H_ 37 37 38 // TODO: propose for inclusion in libc and drop bool.h,39 // it's a very silly incompatibility with standard C40 41 38 #ifdef LIBC_BOOL_H_ 42 39 #error "You can't include bool.h and stdbool.h at the same time." -
uspace/lib/posix/stdint.h
r0cf27ee r07b39338 103 103 typedef uint64_t posix_uintmax_t; 104 104 105 // FIXME: should be integrated into build process similarly to uintptr_t106 typedef ssize_t posix_intptr_t;107 108 105 #ifndef LIBPOSIX_INTERNAL 109 106 #define intmax_t posix_intmax_t 110 107 #define uintmax_t posix_uintmax_t 111 112 #define intptr_t posix_intptr_t113 108 #endif 114 109 -
uspace/lib/posix/stdio.c
r0cf27ee r07b39338 257 257 assert(stream != NULL); 258 258 259 /* Retrieve the node. */260 struct stat st;261 int rc;262 263 259 if (filename == NULL) { 264 rc = fstat(stream->fd, &st); 265 } else { 266 rc = stat(filename, &st); 267 if (-rc == ENOENT) { 268 /* file does not exist, create new file */ 269 FILE* tmp = fopen(filename, mode); 270 if (tmp != NULL) { 271 fclose(tmp); 272 /* try again */ 273 rc = stat(filename, &st); 274 } 275 } 276 } 277 278 if (rc != EOK) { 279 fclose(stream); 280 errno = -rc; 281 return NULL; 282 } 283 284 fdi_node_t node = { 285 .fs_handle = st.fs_handle, 286 .service_id = st.service_id, 287 .index = st.index 288 }; 260 /* POSIX allows this to be imlementation-defined. HelenOS currently 261 * does not support changing the mode. */ 262 // FIXME: handle mode change once it is supported 263 return stream; 264 } 289 265 290 266 /* Open a new stream. */ 291 FILE* new = fopen _node(&node, mode);267 FILE* new = fopen(filename, mode); 292 268 if (new == NULL) { 293 269 fclose(stream); 294 /* fopen_node() sets errno.*/270 /* errno was set by fopen() */ 295 271 return NULL; 296 272 } -
uspace/lib/posix/stdio.h
r0cf27ee r07b39338 140 140 141 141 #define freopen posix_freopen 142 #define fmemopen posix_fmemopen143 #define open_memstream posix_open_memstream144 142 145 143 #define perror posix_perror -
uspace/lib/posix/stdio/scanf.c
r0cf27ee r07b39338 707 707 break; 708 708 case LMOD_t: ; 709 // FIXME: What is unsigned counterpart of the ptrdiff_t?709 // XXX: What is unsigned counterpart of the ptrdiff_t? 710 710 size_t *pt = va_arg(arg, size_t *); 711 711 *pt = (size_t) ures; … … 1221 1221 } 1222 1222 1223 // FIXME: put the testcases somewhere else1223 // FIXME: put the testcases to the app/tester after scanf is included into libc 1224 1224 1225 1225 #if 0 -
uspace/lib/posix/string.c
r0cf27ee r07b39338 48 48 49 49 /** 50 * Decides whether s2 is a prefix of s1.51 *52 * @param s1 String in which to look for a prefix.53 * @param s2 Prefix string to look for.54 * @return True if s2 is a prefix of s1, false otherwise.55 */56 static bool begins_with(const char *s1, const char *s2)57 {58 while (*s1 == *s2 && *s2 != '\0') {59 s1++;60 s2++;61 }62 63 /* true if the end was reached */64 return *s2 == '\0';65 }66 67 /**68 50 * The same as strpbrk, except it returns pointer to the nul terminator 69 51 * if no occurence is found. … … 471 453 472 454 /** 473 * Find a substring. 455 * Find a substring. Uses Knuth-Morris-Pratt algorithm. 474 456 * 475 457 * @param s1 String in which to look for a substring. … … 478 460 * not found. 479 461 */ 480 char *posix_strstr(const char *s1, const char *s2) 481 { 482 assert(s1 != NULL); 483 assert(s2 != NULL); 484 485 /* special case - needle is an empty string */ 486 if (*s2 == '\0') { 487 return (char *) s1; 488 } 489 490 // TODO: use faster algorithm 491 /* check for prefix from every position - quadratic complexity */ 492 while (*s1 != '\0') { 493 if (begins_with(s1, s2)) { 494 return (char *) s1; 495 } 462 char *posix_strstr(const char *haystack, const char *needle) 463 { 464 assert(haystack != NULL); 465 assert(needle != NULL); 466 467 /* Special case - needle is an empty string. */ 468 if (needle[0] == '\0') { 469 return (char *) haystack; 470 } 471 472 /* Preprocess needle. */ 473 size_t nlen = posix_strlen(needle); 474 size_t prefix_table[nlen + 1]; 475 476 { 477 size_t i = 0; 478 ssize_t j = -1; 496 479 497 s1++; 480 prefix_table[i] = j; 481 482 while (i < nlen) { 483 while (j >= 0 && needle[i] != needle[j]) { 484 j = prefix_table[j]; 485 } 486 i++; j++; 487 prefix_table[i] = j; 488 } 489 } 490 491 /* Search needle using the precomputed table. */ 492 size_t npos = 0; 493 494 for (size_t hpos = 0; haystack[hpos] != '\0'; ++hpos) { 495 while (npos != 0 && haystack[hpos] != needle[npos]) { 496 npos = prefix_table[npos]; 497 } 498 499 if (haystack[hpos] == needle[npos]) { 500 npos++; 501 502 if (npos == nlen) { 503 return (char *) (haystack + hpos - nlen + 1); 504 } 505 } 498 506 } 499 507 -
uspace/lib/posix/string.h
r0cf27ee r07b39338 51 51 * void *memmove(void *, const void *, size_t); 52 52 * 53 * unimplemented due to missing locales53 * TODO: not implemented due to missing locale support 54 54 * 55 55 * int strcoll_l(const char *, const char *, locale_t); 56 56 * char *strerror_l(int, locale_t); 57 57 * size_t strxfrm_l(char *restrict, const char *restrict, size_t, locale_t); 58 *59 58 */ 60 61 // TODO: provide *_l once there is locale.h62 59 63 60 #ifndef NULL … … 89 86 extern size_t posix_strcspn(const char *s1, const char *s2); 90 87 extern size_t posix_strspn(const char *s1, const char *s2); 91 extern char *posix_strstr(const char * s1, const char *s2);88 extern char *posix_strstr(const char *haystack, const char *needle); 92 89 93 90 /* Collation Functions */ -
uspace/lib/posix/strings.h
r0cf27ee r07b39338 48 48 #endif 49 49 50 /* TODO: not implemented due to missing locale .h50 /* TODO: not implemented due to missing locale support 51 51 * 52 52 * int strcasecmp_l(const char *, const char *, locale_t); -
uspace/lib/posix/time.c
r0cf27ee r07b39338 51 51 #include "libc/sys/time.h" 52 52 53 // TODO: documentation54 53 // TODO: test everything in this file 55 54 … … 72 71 #define SECS_PER_DAY (SECS_PER_HOUR * HOURS_PER_DAY) 73 72 74 /** Checks whether the year is a leap year. 73 /** 74 * Checks whether the year is a leap year. 75 75 * 76 76 * @param year Year since 1900 (e.g. for 1970, the value is 70). … … 90 90 } 91 91 92 /** Returns how many days there are in the given month of the given year. 93 * Note that year is only taken into account if month is February. 92 /** 93 * Returns how many days there are in the given month of the given year. 94 * Note that year is only taken into account if month is February. 94 95 * 95 96 * @param year Year since 1900 (can be negative). … … 113 114 } 114 115 115 /** For specified year, month and day of month, returns which day of that year 116 * it is. 116 /** 117 * For specified year, month and day of month, returns which day of that year 118 * it is. 117 119 * 118 120 * For example, given date 2011-01-03, the corresponding expression is: … … 134 136 } 135 137 136 /** Integer division that rounds to negative infinity. 137 * Used by some functions in this file. 138 * 139 * @param op1 140 * @param op2 141 * @return 138 /** 139 * Integer division that rounds to negative infinity. 140 * Used by some functions in this file. 141 * 142 * @param op1 Divident. 143 * @param op2 Divisor. 144 * @return Rounded quotient. 142 145 */ 143 146 static time_t _floor_div(time_t op1, time_t op2) … … 150 153 } 151 154 152 /** Modulo that rounds to negative infinity. 153 * Used by some functions in this file. 154 * 155 * @param op1 156 * @param op2 157 * @return 155 /** 156 * Modulo that rounds to negative infinity. 157 * Used by some functions in this file. 158 * 159 * @param op1 Divident. 160 * @param op2 Divisor. 161 * @return Remainder. 158 162 */ 159 163 static time_t _floor_mod(time_t op1, time_t op2) … … 174 178 } 175 179 176 /** Number of days since the Epoch. 177 * Epoch is 1970-01-01, which is also equal to day 0. 180 /** 181 * Number of days since the Epoch. 182 * Epoch is 1970-01-01, which is also equal to day 0. 178 183 * 179 184 * @param year Year (year 1900 = 0, may be negative). … … 189 194 } 190 195 191 /** Seconds since the Epoch. see also _days_since_epoch(). 196 /** 197 * Seconds since the Epoch. see also _days_since_epoch(). 192 198 * 193 199 * @param tm Normalized broken-down time. … … 201 207 } 202 208 203 /** Which day of week the specified date is. 209 /** 210 * Which day of week the specified date is. 204 211 * 205 212 * @param year Year (year 1900 = 0). … … 214 221 } 215 222 216 /** Normalizes the broken-down time and optionally adds specified amount of 217 * seconds. 223 /** 224 * Normalizes the broken-down time and optionally adds specified amount of 225 * seconds. 218 226 * 219 227 * @param tm Broken-down time to normalize. … … 297 305 } 298 306 299 /** Which day the week-based year starts on, relative to the first calendar day. 300 * E.g. if the year starts on December 31st, the return value is -1. 307 /** 308 * Which day the week-based year starts on, relative to the first calendar day. 309 * E.g. if the year starts on December 31st, the return value is -1. 301 310 * 302 311 * @param Year since 1900. … … 309 318 } 310 319 311 /** Returns week-based year of the specified time. 320 /** 321 * Returns week-based year of the specified time. 312 322 * 313 323 * @param tm Normalized broken-down time. … … 329 339 } 330 340 331 /** Week number of the year, assuming weeks start on sunday. 332 * The first Sunday of January is the first day of week 1; 333 * days in the new year before this are in week 0. 341 /** 342 * Week number of the year, assuming weeks start on sunday. 343 * The first Sunday of January is the first day of week 1; 344 * days in the new year before this are in week 0. 334 345 * 335 346 * @param tm Normalized broken-down time. … … 342 353 } 343 354 344 /** Week number of the year, assuming weeks start on monday. 345 * If the week containing January 1st has four or more days in the new year, 346 * then it is considered week 1. Otherwise, it is the last week of the previous 347 * year, and the next week is week 1. Both January 4th and the first Thursday 348 * of January are always in week 1. 355 /** 356 * Week number of the year, assuming weeks start on monday. 357 * If the week containing January 1st has four or more days in the new year, 358 * then it is considered week 1. Otherwise, it is the last week of the previous 359 * year, and the next week is week 1. Both January 4th and the first Thursday 360 * of January are always in week 1. 349 361 * 350 362 * @param tm Normalized broken-down time. … … 366 378 } 367 379 368 /** Week number of the year, assuming weeks start on monday. 369 * The first Monday of January is the first day of week 1; 370 * days in the new year before this are in week 0. 380 /** 381 * Week number of the year, assuming weeks start on monday. 382 * The first Monday of January is the first day of week 1; 383 * days in the new year before this are in week 0. 371 384 * 372 385 * @param tm Normalized broken-down time. … … 385 398 char *posix_tzname[2]; 386 399 387 /** Set timezone conversion information.388 * 400 /** 401 * Set timezone conversion information. 389 402 */ 390 403 void posix_tzset(void) … … 397 410 } 398 411 399 /** Calculate the difference between two times, in seconds. 400 * 401 * @param time1 402 * @param time0 412 /** 413 * Calculate the difference between two times, in seconds. 414 * 415 * @param time1 First time. 416 * @param time0 Second time. 403 417 * @return Time in seconds. 404 418 */ … … 408 422 } 409 423 410 /** This function first normalizes the provided broken-down time 411 * (moves all values to their proper bounds) and then tries to 412 * calculate the appropriate time_t representation. 424 /** 425 * This function first normalizes the provided broken-down time 426 * (moves all values to their proper bounds) and then tries to 427 * calculate the appropriate time_t representation. 413 428 * 414 429 * @param tm Broken-down time. 415 * @return time_t representation of the time, undefined value on overflow 430 * @return time_t representation of the time, undefined value on overflow. 416 431 */ 417 432 time_t posix_mktime(struct posix_tm *tm) … … 424 439 } 425 440 426 /** Converts a time value to a broken-down UTC time. 441 /** 442 * Converts a time value to a broken-down UTC time. 427 443 * 428 444 * @param timer Time to convert. … … 437 453 } 438 454 439 /** Converts a time value to a broken-down UTC time. 455 /** 456 * Converts a time value to a broken-down UTC time. 440 457 * 441 458 * @param timer Time to convert. … … 465 482 } 466 483 467 /** Converts a time value to a broken-down local time. 484 /** 485 * Converts a time value to a broken-down local time. 468 486 * 469 487 * @param timer Time to convert. … … 476 494 } 477 495 478 /** Converts a time value to a broken-down local time. 496 /** 497 * Converts a time value to a broken-down local time. 479 498 * 480 499 * @param timer Time to convert. … … 490 509 } 491 510 492 /** Converts broken-down time to a string in format 493 * "Sun Jan 1 00:00:00 1970\n". (Obsolete) 511 /** 512 * Converts broken-down time to a string in format 513 * "Sun Jan 1 00:00:00 1970\n". (Obsolete) 494 514 * 495 515 * @param timeptr Broken-down time structure. … … 502 522 } 503 523 504 /** Converts broken-down time to a string in format 505 * "Sun Jan 1 00:00:00 1970\n". (Obsolete) 524 /** 525 * Converts broken-down time to a string in format 526 * "Sun Jan 1 00:00:00 1970\n". (Obsolete) 506 527 * 507 528 * @param timeptr Broken-down time structure. … … 534 555 } 535 556 536 /** Equivalent to asctime(localtime(clock)). 557 /** 558 * Equivalent to asctime(localtime(clock)). 537 559 * 538 560 * @param timer Time to convert. … … 548 570 } 549 571 550 /** Reentrant variant of ctime(). 572 /** 573 * Reentrant variant of ctime(). 551 574 * 552 575 * @param timer Time to convert. … … 564 587 } 565 588 566 /** Convert time and date to a string, based on a specified format and 567 * current locale. 589 /** 590 * Convert time and date to a string, based on a specified format and 591 * current locale. 568 592 * 569 593 * @param s Buffer to write string to. … … 755 779 } 756 780 757 /** Get clock resolution. Only CLOCK_REALTIME is supported. 781 /** 782 * Get clock resolution. Only CLOCK_REALTIME is supported. 758 783 * 759 784 * @param clock_id Clock ID. … … 776 801 } 777 802 778 /** Get time. Only CLOCK_REALTIME is supported. 803 /** 804 * Get time. Only CLOCK_REALTIME is supported. 779 805 * 780 806 * @param clock_id ID of the clock to query. 781 807 * @param tp Pointer to the variable where the time is to be written. 782 * @return 808 * @return 0 on success, -1 with errno on failure. 783 809 */ 784 810 int posix_clock_gettime(posix_clockid_t clock_id, struct posix_timespec *tp) … … 800 826 } 801 827 802 /** Set time on a specified clock. As HelenOS doesn't support this yet, 803 * this function always fails. 828 /** 829 * Set time on a specified clock. As HelenOS doesn't support this yet, 830 * this function always fails. 804 831 * 805 832 * @param clock_id ID of the clock to set. … … 825 852 } 826 853 827 /** Sleep on a specified clock. 854 /** 855 * Sleep on a specified clock. 828 856 * 829 857 * @param clock_id ID of the clock to sleep on (only CLOCK_REALTIME supported). … … 855 883 } 856 884 857 /** Get CPU time used since the process invocation. 885 /** 886 * Get CPU time used since the process invocation. 858 887 * 859 888 * @return Consumed CPU cycles by this process or -1 if not available. -
uspace/lib/posix/time.h
r0cf27ee r07b39338 162 162 #define clock_settime posix_clock_settime 163 163 #define clock_nanosleep posix_clock_nanosleep 164 165 #define timer_create posix_timer_create 166 #define timer_delete posix_timer_delete 167 #define timer_getoverrun posix_timer_getoverrun 168 #define timer_gettime posix_timer_gettime 169 #define timer_settime posix_timer_settime 170 164 171 165 #define clock posix_clock 172 166 #endif -
uspace/lib/usb/include/usb/hc.h
r0cf27ee r07b39338 38 38 #include <sys/types.h> 39 39 #include <ipc/devman.h> 40 #include <ipc/loc.h> 40 41 #include <ddf/driver.h> 41 42 #include <bool.h> … … 68 69 devman_handle_t *); 69 70 70 int usb_ddf_get_hc_handle_by_ class(size_t, devman_handle_t *);71 int usb_ddf_get_hc_handle_by_sid(service_id_t, devman_handle_t *); 71 72 72 73 -
uspace/lib/usb/include/usb/usb.h
r0cf27ee r07b39338 174 174 } usb_packet_id; 175 175 176 /** C lass namefor USB host controllers. */177 #define USB_HC_ DDF_CLASS_NAME"usbhc"176 /** Category for USB host controllers. */ 177 #define USB_HC_CATEGORY "usbhc" 178 178 179 179 #endif -
uspace/lib/usb/src/hc.c
r0cf27ee r07b39338 201 201 /** Get host controller handle by its class index. 202 202 * 203 * @param class_index Class index for the host controller.203 * @param sid Service ID of the HC function. 204 204 * @param hc_handle Where to store the HC handle 205 205 * (can be NULL for existence test only). 206 206 * @return Error code. 207 207 */ 208 int usb_ddf_get_hc_handle_by_class(size_t class_index, 209 devman_handle_t *hc_handle) 210 { 211 char *class_index_str; 212 devman_handle_t hc_handle_tmp; 208 int usb_ddf_get_hc_handle_by_sid(service_id_t sid, devman_handle_t *hc_handle) 209 { 210 devman_handle_t handle; 213 211 int rc; 214 215 rc = asprintf(&class_index_str, "%zu", class_index); 216 if (rc < 0) { 217 return ENOMEM; 218 } 219 rc = devman_device_get_handle_by_class("usbhc", class_index_str, 220 &hc_handle_tmp, 0); 221 free(class_index_str); 222 if (rc != EOK) { 223 return rc; 224 } 225 226 if (hc_handle != NULL) { 227 *hc_handle = hc_handle_tmp; 228 } 229 230 return EOK; 212 213 rc = devman_fun_sid_to_handle(sid, &handle); 214 if (hc_handle != NULL) 215 *hc_handle = handle; 216 217 return rc; 231 218 } 232 219 -
uspace/lib/usb/src/resolve.c
r0cf27ee r07b39338 46 46 devman_handle_t *out_hc_handle, usb_address_t *out_device_address) 47 47 { 48 size_t class_index;48 uint64_t sid; 49 49 size_t address; 50 50 int rc; 51 51 char *ptr; 52 52 53 rc = str_ size_t(path, &ptr, 10, false, &class_index);53 rc = str_uint64(path, &ptr, 10, false, &sid); 54 54 if (rc != EOK) { 55 55 return false; … … 64 64 return false; 65 65 } 66 rc = usb_ddf_get_hc_handle_by_ class(class_index, out_hc_handle);66 rc = usb_ddf_get_hc_handle_by_sid(sid, out_hc_handle); 67 67 if (rc != EOK) { 68 68 return false; … … 152 152 if (str_length(func_start) > 0) { 153 153 char tmp_path[MAX_DEVICE_PATH ]; 154 rc = devman_ get_device_path(dev_handle,154 rc = devman_fun_get_path(dev_handle, 155 155 tmp_path, MAX_DEVICE_PATH); 156 156 if (rc != EOK) { … … 173 173 174 174 /* First try to get the device handle. */ 175 rc = devman_ device_get_handle(path, &dev_handle, 0);175 rc = devman_fun_get_handle(path, &dev_handle, 0); 176 176 if (rc != EOK) { 177 177 free(path); … … 184 184 /* Get device handle first. */ 185 185 devman_handle_t tmp_handle; 186 rc = devman_ device_get_handle(path, &tmp_handle, 0);186 rc = devman_fun_get_handle(path, &tmp_handle, 0); 187 187 if (rc != EOK) { 188 188 free(path); -
uspace/lib/usbvirt/src/device.c
r0cf27ee r07b39338 87 87 88 88 devman_handle_t handle; 89 int rc = devman_ device_get_handle(vhc_path, &handle, 0);89 int rc = devman_fun_get_handle(vhc_path, &handle, 0); 90 90 if (rc != EOK) 91 91 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.
