text: // Copyright (c) Microsoft Corporation. All rights reserved.
  // Licensed under the MIT License.
  
  #include <openenclave/bits/defs.h>
  #include <openenclave/edger8r/enclave.h>
  #include <openenclave/enclave.h>
  #include <openenclave/internal/calls.h>
  #include <openenclave/internal/raise.h>
  
  oe_result_t oe_call_host_function_by_table_id(
      uint64_t table_id,
      uint64_t function_id,
      const void* input_buffer,
      size_t input_buffer_size,
      void* output_buffer,
      size_t output_buffer_size,
      size_t* output_bytes_written)
  {
      oe_result_t result = OE_UNEXPECTED;
      oe_call_host_function_args_t args = {0};
  
      /* Reject invalid parameters */
      if (!input_buffer || input_buffer_size == 0)
          OE_RAISE(OE_INVALID_PARAMETER);
  
      /* Initialize the arguments */
      {
          args.table_id = table_id;
          args.function_id = function_id;
          args.input_buffer = input_buffer;
          args.input_buffer_size = input_buffer_size;
          args.output_buffer = output_buffer;
          args.output_buffer_size = output_buffer_size;
          args.result = OE_UNEXPECTED;
      }
  
      /* Call the host function with this address */
      OE_CHECK(oe_ocall(OE_OCALL_CALL_HOST_FUNCTION, (uint64_t)&args, NULL));
  
      /* Check the result */
      OE_CHECK(args.result);
  
      *output_bytes_written = args.output_bytes_written;
      result = OE_OK;
  
  done:
      return result;
  }
  
  oe_result_t oe_call_host_function(
      size_t function_id,
      const void* input_buffer,
      size_t input_buffer_size,
      void* output_buffer,
      size_t output_buffer_size,
      size_t* output_bytes_written)
  {
      return oe_call_host_function_by_table_id(
          OE_UINT64_MAX,
          function_id,
          input_buffer,
          input_buffer_size,
          output_buffer,
          output_buffer_size,
          output_bytes_written);
  }
  