|
21 | 21 |
|
22 | 22 | #include <inttypes.h> |
23 | 23 | #include <libhexagonrpc/error.h> |
24 | | -#include <libhexagonrpc/fastrpc.h> |
25 | 24 | #include <libhexagonrpc/hexagonrpc.h> |
26 | 25 | #include <stddef.h> |
27 | 26 | #include <stdint.h> |
@@ -425,83 +424,6 @@ static struct fastrpc_io_buffer *alloc_outbufs4(const struct hrpc_method_def_int |
425 | 424 | return NULL; |
426 | 425 | } |
427 | 426 |
|
428 | | -static struct fastrpc_io_buffer *allocate_outbufs(const struct fastrpc_function_def_interp2 *def, |
429 | | - uint32_t *first_inbuf) |
430 | | -{ |
431 | | - struct fastrpc_io_buffer *out; |
432 | | - size_t out_count; |
433 | | - size_t i, j; |
434 | | - off_t off; |
435 | | - uint32_t *sizes; |
436 | | - |
437 | | - out_count = def->out_bufs + (def->out_nums && 1); |
438 | | - /* |
439 | | - * POSIX allows malloc to return a non-NULL pointer to a zero-size area |
440 | | - * in memory. Since the code below assumes non-zero size if the pointer |
441 | | - * is non-NULL, exit early if we do not need to allocate anything. |
442 | | - */ |
443 | | - if (out_count == 0) |
444 | | - return NULL; |
445 | | - |
446 | | - out = malloc(sizeof(struct fastrpc_io_buffer) * out_count); |
447 | | - if (out == NULL) |
448 | | - return NULL; |
449 | | - |
450 | | - out[0].s = def->out_nums * 4; |
451 | | - if (out[0].s) { |
452 | | - out[0].p = malloc(def->out_nums * 4); |
453 | | - if (out[0].p == NULL) |
454 | | - goto err_free_out; |
455 | | - } |
456 | | - |
457 | | - off = def->out_nums && 1; |
458 | | - sizes = &first_inbuf[def->in_nums + def->in_bufs]; |
459 | | - |
460 | | - for (i = 0; i < def->out_bufs; i++) { |
461 | | - out[off + i].s = sizes[i]; |
462 | | - out[off + i].p = malloc(sizes[i]); |
463 | | - if (out[off + i].p == NULL) |
464 | | - goto err_free_prev; |
465 | | - } |
466 | | - |
467 | | - return out; |
468 | | - |
469 | | -err_free_prev: |
470 | | - for (j = 0; j < i; j++) |
471 | | - free(out[off + j].p); |
472 | | - |
473 | | -err_free_out: |
474 | | - free(out); |
475 | | - return NULL; |
476 | | -} |
477 | | - |
478 | | -static int check_inbuf_sizes(const struct fastrpc_function_def_interp2 *def, |
479 | | - const struct fastrpc_io_buffer *inbufs) |
480 | | -{ |
481 | | - uint8_t i; |
482 | | - const uint32_t *sizes = &((const uint32_t *) inbufs[0].p)[def->in_nums]; |
483 | | - |
484 | | - if (inbufs[0].s != 4U * (def->in_nums |
485 | | - + def->in_bufs |
486 | | - + def->out_bufs)) { |
487 | | - fprintf(stderr, "Invalid number of input numbers: %zu (expected %u)\n", |
488 | | - inbufs[0].s, |
489 | | - 4 * (def->in_nums |
490 | | - + def->in_bufs |
491 | | - + def->out_bufs)); |
492 | | - return -1; |
493 | | - } |
494 | | - |
495 | | - for (i = 0; i < def->in_bufs; i++) { |
496 | | - if (inbufs[i + 1].s != sizes[i]) { |
497 | | - fprintf(stderr, "Invalid buffer size\n"); |
498 | | - return -1; |
499 | | - } |
500 | | - } |
501 | | - |
502 | | - return 0; |
503 | | -} |
504 | | - |
505 | 427 | static int return_for_next_invoke(int fd, |
506 | 428 | uint32_t result, |
507 | 429 | uint32_t *rctx, |
@@ -583,8 +505,6 @@ static int invoke_requested_procedure(size_t n_ifaces, |
583 | 505 | struct fastrpc_io_buffer **returned) |
584 | 506 | { |
585 | 507 | const struct fastrpc_function_impl *impl; |
586 | | - uint8_t in_count; |
587 | | - uint8_t out_count; |
588 | 508 | uint32_t method = REMOTE_SCALARS_METHOD(sc); |
589 | 509 | int ret; |
590 | 510 |
|
@@ -616,53 +536,26 @@ static int invoke_requested_procedure(size_t n_ifaces, |
616 | 536 |
|
617 | 537 | impl = &ifaces[handle]->procs[method]; |
618 | 538 |
|
619 | | - if ((impl->def == NULL && impl->def4 == NULL) || impl->impl == NULL) { |
| 539 | + if (impl->def == NULL || impl->impl == NULL) { |
620 | 540 | fprintf(stderr, "Unsupported method: %u (%08x)\n", method, sc); |
621 | 541 | *result = AEE_EUNSUPPORTED; |
622 | 542 | return 1; |
623 | 543 | } |
624 | 544 |
|
625 | | - if (impl->def4) { |
626 | | - ret = count_sizes4(impl->def4, REMOTE_SCALARS_INBUFS(sc), |
627 | | - REMOTE_SCALARS_OUTBUFS(sc), decoded); |
628 | | - if (ret) { |
629 | | - fprintf(stderr, "Inconsistent buffer sizes\n"); |
630 | | - *result = AEE_EBADPARM; |
631 | | - return 1; |
632 | | - } |
633 | | - |
634 | | - *returned = alloc_outbufs4(impl->def4, decoded, |
635 | | - REMOTE_SCALARS_OUTBUFS(sc)); |
636 | | - if (*returned == NULL && impl->def4->n_args > 0) { |
637 | | - perror("Could not allocate output buffers"); |
638 | | - *result = AEE_ENOMEMORY; |
639 | | - return 1; |
640 | | - } |
641 | | - } else { |
642 | | - in_count = impl->def->in_bufs + ((impl->def->in_nums |
643 | | - || impl->def->in_bufs |
644 | | - || impl->def->out_bufs) && 1); |
645 | | - out_count = impl->def->out_bufs + (impl->def->out_nums && 1); |
646 | | - |
647 | | - if (REMOTE_SCALARS_INBUFS(sc) != in_count |
648 | | - || REMOTE_SCALARS_OUTBUFS(sc) != out_count) { |
649 | | - fprintf(stderr, "Unexpected buffer count: %08x\n", sc); |
650 | | - *result = AEE_EBADPARM; |
651 | | - return 1; |
652 | | - } |
653 | | - |
654 | | - ret = check_inbuf_sizes(impl->def, decoded); |
655 | | - if (ret) { |
656 | | - *result = AEE_EBADPARM; |
657 | | - return 1; |
658 | | - } |
| 545 | + ret = count_sizes4(impl->def, REMOTE_SCALARS_INBUFS(sc), |
| 546 | + REMOTE_SCALARS_OUTBUFS(sc), decoded); |
| 547 | + if (ret) { |
| 548 | + fprintf(stderr, "Inconsistent buffer sizes\n"); |
| 549 | + *result = AEE_EBADPARM; |
| 550 | + return 1; |
| 551 | + } |
659 | 552 |
|
660 | | - *returned = allocate_outbufs(impl->def, decoded[0].p); |
661 | | - if (*returned == NULL && out_count > 0) { |
662 | | - perror("Could not allocate output buffers"); |
663 | | - *result = AEE_ENOMEMORY; |
664 | | - return 1; |
665 | | - } |
| 553 | + *returned = alloc_outbufs4(impl->def, decoded, |
| 554 | + REMOTE_SCALARS_OUTBUFS(sc)); |
| 555 | + if (*returned == NULL && impl->def->n_args > 0) { |
| 556 | + perror("Could not allocate output buffers"); |
| 557 | + *result = AEE_ENOMEMORY; |
| 558 | + return 1; |
666 | 559 | } |
667 | 560 |
|
668 | 561 | *result = impl->impl(ifaces[handle]->data, decoded, *returned); |
|
0 commit comments