wasm-micro-runtime/core/iwasm/lib/native-interface/shared_utils.h
wenyongh f8f61dc898 Add a switch to build simple sample without gui support (#126)
* 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
2019-09-25 03:42:56 -05:00

168 lines
3.8 KiB
C

/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _SHARED_UTILS_H_
#define _SHARED_UTILS_H_
#include "bh_platform.h"
#ifdef __cplusplus
extern "C" {
#endif
#define FMT_ATTR_CONTAINER 99
#define FMT_APP_RAW_BINARY 98
/* the request structure */
typedef struct request {
// message id
uint32 mid;
// url of the request
char *url;
// action of the request, can be PUT/GET/POST/DELETE
int action;
// payload format, currently only support attr_container_t type
int fmt;
// payload of the request, currently only support attr_container_t type
void *payload;
//length in bytes of the payload
int payload_len;
//sender of the request
unsigned long sender;
} request_t;
/* the response structure */
typedef struct response {
// message id
uint32 mid;
// status of the response
int status;
// payload format
int fmt;
// payload of the response,
void *payload;
//length in bytes of the payload
int payload_len;
//receiver of the response
unsigned long reciever;
} response_t;
int
check_url_start(const char* url, int url_len, const char * leading_str);
bool
match_url(char * pattern, char * matched);
char *
find_key_value(char * buffer, int buffer_len, char * key, char * value,
int value_len, char delimiter);
request_t *
clone_request(request_t *request);
void
request_cleaner(request_t *request);
response_t *
clone_response(response_t * response);
void
response_cleaner(response_t * response);
/**
* @brief Set fields of response.
*
* @param response pointer of the response to be set
* @param status status of response
* @param fmt format of the response payload
* @param payload payload of the response
* @param payload_len length in bytes of the response payload
*
* @return pointer to the response
*
* @warning the response pointer MUST NOT be NULL
*/
response_t *
set_response(response_t * response, int status, int fmt,
const char *payload, int payload_len);
/**
* @brief Make a response for a request.
*
* @param request pointer of the request
* @param response pointer of the response to be made
*
* @return pointer to the response
*
* @warning the request and response pointers MUST NOT be NULL
*/
response_t *
make_response_for_request(request_t * request, response_t * response);
/**
* @brief Initialize a request.
*
* @param request pointer of the request to be initialized
* @param url url of the request
* @param action action of the request
* @param fmt format of the request payload
* @param payload payload of the request
* @param payload_len length in bytes of the request payload
*
* @return pointer to the request
*
* @warning the request pointer MUST NOT be NULL
*/
request_t *
init_request(request_t * request, char *url, int action, int fmt,
void *payload, int payload_len);
char *
pack_request(request_t *request, int * size);
request_t *
unpack_request(char * packet, int size, request_t * request);
char *
pack_response(response_t *response, int * size);
response_t *
unpack_response(char * packet, int size, response_t * response);
void
free_req_resp_packet(char * packet);
#if WASM_ENABLE_GUI != 0
#include "wgl_shared_utils.h"
#endif
#ifdef __cplusplus
}
#endif
#endif /* end of _SHARED_UTILS_H_ */