package DkSDKFFIOCaml_Std

  1. Overview
  2. Docs
DkSDK FFI for OCaml

Install

Dune Dependency

Authors

Maintainers

Sources

src-DkSDKFFIOCaml_Std.tar.gz
sha256=cfaee0952eddae71921bb98f76b5b2de9ebb1039bf196155ad405f54926196c3
sha512=f4b7aa7a8a158ab95d30124de73e27908d999cf64a5ffed8a9c536b86c84f694cd2bb0a46ce259d9e7c0c5276c02451ef077acdece3b2da7e8ddc9d754417047

Description

DkSDK FFI OCaml provides within-process communication from OCaml to another DkSDK FFI language (ex. DkSDK FFI Java). . Copyright 2023 Diskuv, Inc. . This open-source package downloads pre-built binaries for a limited set of platforms to avoid the C build tool differences between DkSDK and OCaml. . Full source code and other platforms are available with a "DkSDK SOFTWARE DEVELOPMENT KIT LICENSE AGREEMENT" from https://diskuv.com/pricing, and is free for security engineers, educators and related-field researchers (ex. programming language theory, memory and thread modeling) on request. . The DkSDK FFI OCaml source code, documentation and build scripts are also available under the Open Software License version 3.0, https://opensource.org/license/osl-3-0-php/, at your option. . A guide to the Open Software License version 3.0 is available at https://rosenlaw.com/OSL3.0-explained.htm. . The "DkSDK FFI OCaml Runtime Binaries" is the set of ".tar" and ".zip" archives distributed by Diskuv, Inc. and downloaded by the DkSDK FFI OCaml build scripts. DkSDK FFI OCaml Runtime Binaries © 2023 by Diskuv, Inc. is licensed under Attribution-NoDerivatives 4.0 International. To view a copy of this license, visit http://creativecommons.org/licenses/by-nd/4.0/.

Published: 03 Sep 2023

README

DkSDK FFI OCaml

Quick Start

Your C code must define a variable named dksdk_ffi_hosts that has been initialized with dksdk_ffi_init(...). Here is an example:

/*************************************************************************
 * File: dksdk-ffi-ocaml/tests/Units/generic-ffi-main.c                  *
 *                                                                       *
 * Copyright 2023 Diskuv, Inc.                                           *
 *                                                                       *
 * Licensed under the Open Software License version 3.0                  *
 * (the "License"); you may not use this file except in compliance       *
 * with the License. You may obtain a copy of the License at             *
 *                                                                       *
 *     https://opensource.org/license/osl-3-0-php/                       *
 *                                                                       *
 *************************************************************************/

#include "dksdk_ffi_c.h"
#include "dksdk_ffi_c_cls_icallable.h"
#include "dksdk_ffi_c_test.h"
#include "dksdk_ffi_ocaml_callback.h"
#include "dksdk_ffi_ocaml_instance.h"
#include <caml/callback.h>
#include <stdlib.h>

#ifdef _WIN32
#define portable_main wmain
#define portable_char wchar_t
#else
#define portable_main main
#define portable_char char
#endif

/**
 * Global FFI host array. Each FFI program must have this
 * array defined with all but the first item zeroed.
 */
struct dksdk_ffi *dksdk_ffi_hosts[DKSDK_FFI_HOST_SLOTS] = {0};

/** Convenience error handling */
#define ON_ERROR(MSG)                                           \
  if (ret != DKSDK_FFI_OK) {                                    \
    fprintf(stderr, "FATAL: " #MSG ". Error code = %d\n", ret); \
    exit(1);                                                    \
  }

int(portable_main)(int argc, portable_char **argv) {
  int ret;
  char *dklogfilevar;

  /* Do some logging */
  dklogfilevar = getenv("DKSDK_FFI_LOG_CONF_FILE");
  if (argc >= 2 && argv[1][0] != '-') {
    ret = dksdk_ffi_c_log_configure(argv[1]);
    ON_ERROR("dksdk_ffi_c_log_configure");
  } else if (dklogfilevar != NULL) {
    ret = dksdk_ffi_c_log_configure(dklogfilevar);
    ON_ERROR("dksdk_ffi_c_log_configure");
  }

  /* Initialize FFI using the host at slot 0. Other slots are reserved. */
  const int slot = 0;
  ret = dksdk_ffi_init(dksdk_ffi_c_test_oid_generate_DO_NOT_USE_IN_PRODUCTION,
                       NULL, NULL, NULL, 32768, &dksdk_ffi_hosts[slot]);
  ON_ERROR("dksdk_ffi_init");
  struct dksdk_ffi *ffi = dksdk_ffi_hosts[slot];

  /* Register classes */
  ret = dksdk_ffi_c_cls_icallable_register(ffi);
  ON_ERROR("dk_cls_ICallable_register");
  ret = dksdk_ffi_ocaml_cls_callback_register(ffi);
  ON_ERROR("dksdk_ffi_ocaml_cls_callback_register");
  ret = dksdk_ffi_c_test_POSIX_FILE_register(ffi);
  ON_ERROR("dksdk_ffi_c_test_POSIX_FILE_register");
  ret = dksdk_ffi_c_test_ToyCalculations_register(ffi);
  ON_ERROR("dksdk_ffi_c_test_ToyCalculations_register");

  /* Run module initializers of OCaml and wait for them to finish */
  caml_startup(argv);

  /* Release OCaml resources */
  caml_shutdown();

  /* Unregister classes */
  ret = dksdk_ffi_c_test_ToyCalculations_unregister(ffi);
  ON_ERROR("dksdk_ffi_c_test_ToyCalculations_unregister");
  ret = dksdk_ffi_c_test_POSIX_FILE_unregister(ffi);
  ON_ERROR("dksdk_ffi_c_test_POSIX_FILE_unregister");
  ret = dksdk_ffi_ocaml_cls_callback_unregister(ffi);
  ON_ERROR("dksdk_ffi_ocaml_cls_callback_unregister");
  ret = dksdk_ffi_c_cls_icallable_unregister(ffi);
  ON_ERROR("dk_cls_ICallable_unregister");

  /* Release DkSDK FFI resources */
  ret = dksdk_ffi_terminate(ffi);
  if (ret != DKSDK_FFI_OK) {
    fprintf(stderr, "FATAL: dksdk_ffi_terminate() = %d\n", ret);
    exit(1);
  }

  return 0;
}

/* This C function is called by FFI OCaml test code to initialize FFI
   if it hasn't been already. */
value caml_dksdk_ffi_ocaml_init_if_needed(value v_logfile_opt) {
  return Val_unit;
}

Licensing

Full source code and other platforms are available with a "DkSDK SOFTWARE DEVELOPMENT KIT LICENSE AGREEMENT" from https://diskuv.com/pricing, and is free for security engineers, educators and related-field researchers (ex. programming language theory, memory and thread modeling) on request.

The DkSDK FFI OCaml source code, documentation and build scripts are also available under the Open Software License version 3.0, https://opensource.org/license/osl-3-0-php/, at your option.

A guide to the Open Software License version 3.0 is available at https://rosenlaw.com/OSL3.0-explained.htm.

The "DkSDK FFI OCaml Runtime Binaries" is the set of .tar and .zip archives distributed by Diskuv, Inc. and downloaded by the DkSDK FFI OCaml build scripts. DkSDK FFI OCaml Runtime Binaries © 2023 by Diskuv, Inc. is licensed under Attribution-NoDerivatives 4.0 International .

Dependencies (7)

  1. uuidm >= "0.9.8"
  2. lwt
  3. dum >= "1.0.3"
  4. capnp >= "3.5.0"
  5. ocaml >= "4.14.0"
  6. dune >= "3.8"
  7. DkSDKFFIOCaml_StdExport-linux_x86_64 arch = "x86_64" & os = "linux" & os-distribution != "alpine" & = "1.0.0~1"

Dev Dependencies (1)

  1. odoc with-doc

Used by

None

Conflicts

None