This repository has been archived on 2023-11-05. You can view files and clone it, but cannot push or open issues or pull requests.
wasm-micro-runtime/core/shared/include/bni.h
wenyongh 46b93b9d22 Enable AoT and wamr-sdk, and change arguments of call wasm API (#157)
* Implement memory profiler, optimize memory usage, modify code indent

* Implement memory.grow and limit heap space base offset to 1G; modify iwasm build type to Release and 64 bit by default

* Add a new extension library: connection

* Fix bug of reading magic number and version in big endian platform

* Re-org platform APIs: move most platform APIs from iwasm to shared-lib

* Enhance wasm loader to fix some security issues

* Fix issue about illegal load of EXC_RETURN into PC on stm32 board

* Updates that let a restricted version of the interpreter run in SGX

* Enable native/app address validation and conversion for wasm app

* Remove wasm_application_exectue_* APIs from wasm_export.h which makes confused

* Refine binary size and fix several minor issues

Optimize interpreter LOAD/STORE opcodes to decrease the binary size
Fix issues when using iwasm library: _bh_log undefined, bh_memory.h not found
Remove unused _stdin/_stdout/_stderr global variables resolve in libc wrapper
Add macros of global heap size, stack size, heap size for Zephyr main.c
Clear compile warning of wasm_application.c

* Add more strict security checks for libc wrapper API's

* Use one libc wrapper copy for sgx and other platforms; remove bh_printf macro for other platform header files

* Enhance security of libc strcpy/sprintf wrapper function

* Fix issue of call native for x86_64/arm/mips, add module inst parameter for native wrapper functions

* Remove get_module_inst() and fix issue of call native

* Refine wgl lib: remove module_inst parameter from widget functions; move function index check to runtime instantiate

* Refine interpreter call native process, refine memory boudary check

* Fix issues of invokeNative function of arm/mips/general version

* Add a switch to build simple sample without gui support

* Add BUILD_TARGET setting in makefile to replace cpu compiler flags in source code

* Re-org shared lib header files, remove unused info; fix compile issues of vxworks

* Add build target general

* Remove unused files

* Update license header

* test push

* Restore file

* Sync up with internal/feature

* Sync up with internal/feature

* Rename build_wamr_app to build_wasm_app

* Fix small issues of README

* Enhance malformed wasm file checking
Fix issue of print hex int and implement utf8 string check
Fix wasi file read/write right issue
Fix minor issue of build wasm app doc

* Sync up with internal/feature

* Sync up with internal/feature: fix interpreter arm issue, fix read leb issue

* Sync up with internal/feature

* Fix bug of config.h and rename wasi config.h to ssp_config.h

* Sync up with internal/feature

* Import wamr aot

* update document

* update document

* Update document, disable WASI in 32bit

* update document

* remove files

* update document

* Update document

* update document

* update document

* update samples

* Sync up with internal repo
2020-01-21 13:26:14 +08:00

226 lines
4.8 KiB
C

/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
/**
* @file bni.h
* @date Mon Jul 2 16:54:58 2012
*
* @brief Beihai native interface.
*/
#ifndef BNI_H
#define BNI_H
#include "bh_types.h"
/* Primitive types */
typedef uint8 jboolean;
typedef int8 jbyte;
typedef uint16 jchar;
typedef int16 jshort;
typedef int32 jint;
typedef int64 jlong;
typedef float jfloat;
typedef double jdouble;
typedef jint jsize;
/* Predefined Java class types. */
struct _jobject;
typedef struct _jobject *jobject;
struct _jclass;
typedef struct _jclass *jclass;
struct _jstring;
typedef struct _jstring *jstring;
/* Values of jboolean: */
#define BNI_FALSE 0
#define BNI_TRUE 1
/**
* Return the length of the array object.
*
* @param array Java array object
*
* @return the length of the Java array
*/
#define bni_array_length(array) ((jsize)((uint32)(array)->__length >> 2))
/**
* Return the address of the first element of array object.
*
* @param array Java array object
*
* @return the address of the first element of array object
*/
#define bni_array_elem(array) ((array)->__elem)
/**
* Find the Java class with given class name.
*
* @param name Java class name
*
* @return class object of the Java class if found, NULL otherwise
*
* @throws OutOfMemoryError if VM runs out of memory.
*/
jclass
bni_find_class(const char *name);
/**
* Throw an exception of given class with message.
*
* @param clazz class object of a subclass of java.lang.Throwable
* @param msg message for the exception or NULL if no message
*
* @return 0 if succeeds, nonzero otherwise
*/
jint
bni_throw_new(jclass clazz, const char *msg);
/**
* Throw a NullPointerException.
*
* @throws NullPointerException
*/
void
bni_throw_npe(void);
/**
* Throw an ArrayIndexOutOfBoundsException
*
* @param index the index used to access the array
*
* @throws ArrayIndexOutOfBoundsException
*/
void
bni_throw_aioobe(int index);
/**
* Determine whether an exception is being thrown.
*
* @return exception object if exception is thrown, NULL otherwise
*/
jobject
bni_exception_occurred(void);
/**
* Print the current exception to error-reporting channel.
*/
void
bni_exception_describe(void);
/**
* Clear the currently thrown exception.
*/
void
bni_exception_clear(void);
/**
* Return the Unicode character number of a string.
*
* @param str Java string object
*
* @return the Unicode character number of the string
*/
jsize
bni_string_length(jstring str);
/**
* Return the length in bytes of the modified UTF-8 representation of
* a string.
*
* @param str Java string object
* @param start start offset in the string
* @param len number of Unicode characters
*
* @return the UTF-8 length of the string
*
* @throws StringIndexOutOfBoundsException on index overflow.
*/
jsize
bni_string_utf_length(jstring str, jsize start, jsize len);
/**
* Copies len number of Unicode characters beginning at offset start
* to the given buffer buf.
*
* @param str Java string object
* @param start start offset in the string
* @param len number of Unicode characters to copy
* @param buf buffer for storing the result
*/
void
bni_string_region(jstring str, jsize start, jsize len, jchar *buf);
/**
* Translates len number of Unicode characters beginning at offset
* start into modified UTF-8 encoding and place the result in the
* given buffer buf.
*
* @param str Java string object
* @param start start offset in the string
* @param len number of Unicode characters to copy
* @param buf buffer for storing the result
*
* @throws StringIndexOutOfBoundsException on index overflow.
*/
void
bni_string_utf_region(jstring str, jsize start, jsize len, char *buf);
/**
* Translate Unicode characters into modified UTF-8 encoding and return
* the result.
*
* @param str Java string object
*
* @return the UTF-8 encoding string if succeeds, NULL otherwise
*/
char *
bni_string_get_utf_chars(jstring str);
/**
* Get the given Java object's class index.
*
* @param obj Java object
*
* @return -1 if obj is an array, class index of the object otherwise
*/
jint
bni_object_class_index(jobject obj);
/**
* Allocate memory from the current instance's private heap.
*
* @param size bytes to allocate
*
* @return pointer to the allocated memory
*
* @throws OutOfMemoryError if VM runs out of memory.
*/
void*
bni_malloc(unsigned size);
/**
* Allocate memory from the current instance's private heap and clear
* to zero.
*
* @param size bytes to allocate
*
* @return pointer to the allocated memory
*
* @throws OutOfMemoryError if VM runs out of memory.
*/
void*
bni_calloc(unsigned size);
/**
* Free the memory allocated from the current instance's private heap.
*
* @param ptr pointer to the memory in current instance's private heap
*/
void
bni_free(void *ptr);
#endif