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