25
core/iwasm/runtime/platform/vxworks/platform.cmake
Normal file
25
core/iwasm/runtime/platform/vxworks/platform.cmake
Normal file
@ -0,0 +1,25 @@
|
||||
# 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.
|
||||
|
||||
add_definitions (-D__POSIX__ -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=199309L)
|
||||
|
||||
set (PLATFORM_LIB_DIR ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
include_directories(${PLATFORM_LIB_DIR})
|
||||
include_directories(${PLATFORM_LIB_DIR}/../include)
|
||||
|
||||
file (GLOB_RECURSE source_all ${PLATFORM_LIB_DIR}/*.c)
|
||||
|
||||
set (WASM_PLATFORM_LIB_SOURCE ${source_all})
|
||||
|
||||
26
core/iwasm/runtime/platform/vxworks/wasm_native.c
Normal file
26
core/iwasm/runtime/platform/vxworks/wasm_native.c
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "wasm_native.h"
|
||||
|
||||
|
||||
void*
|
||||
wasm_platform_native_func_lookup(const char *module_name,
|
||||
const char *func_name)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
96
core/iwasm/runtime/platform/vxworks/wasm_platform.c
Normal file
96
core/iwasm/runtime/platform/vxworks/wasm_platform.c
Normal file
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "wasm_log.h"
|
||||
#include "wasm_platform.h"
|
||||
#include "wasm_memory.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
bool is_little_endian = false;
|
||||
|
||||
bool __is_little_endian()
|
||||
{
|
||||
union w
|
||||
{
|
||||
int a;
|
||||
char b;
|
||||
}c;
|
||||
|
||||
c.a = 1;
|
||||
return (c.b == 1);
|
||||
}
|
||||
|
||||
int
|
||||
wasm_platform_init()
|
||||
{
|
||||
if (__is_little_endian())
|
||||
is_little_endian = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
char*
|
||||
wasm_read_file_to_buffer(const char *filename, int *ret_size)
|
||||
{
|
||||
char *buffer;
|
||||
int file;
|
||||
int file_size, read_size;
|
||||
struct stat stat_buf;
|
||||
|
||||
if (!filename || !ret_size) {
|
||||
LOG_ERROR("Read file to buffer failed: invalid filename or ret size.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((file = open(filename, O_RDONLY, 0)) == -1) {
|
||||
LOG_ERROR("Read file to buffer failed: open file %s failed.\n",
|
||||
filename);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (fstat(file, &stat_buf) != 0) {
|
||||
LOG_ERROR("Read file to buffer failed: fstat file %s failed.\n",
|
||||
filename);
|
||||
close(file);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
file_size = stat_buf.st_size;
|
||||
|
||||
if (!(buffer = wasm_malloc(file_size))) {
|
||||
LOG_ERROR("Read file to buffer failed: alloc memory failed.\n");
|
||||
close(file);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
read_size = read(file, buffer, file_size);
|
||||
close(file);
|
||||
|
||||
if (read_size < file_size) {
|
||||
LOG_ERROR("Read file to buffer failed: read file content failed.\n");
|
||||
wasm_free(buffer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*ret_size = file_size;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
104
core/iwasm/runtime/platform/vxworks/wasm_platform.h
Normal file
104
core/iwasm/runtime/platform/vxworks/wasm_platform.h
Normal file
@ -0,0 +1,104 @@
|
||||
/*
|
||||
* 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 _WASM_PLATFORM_H
|
||||
#define _WASM_PLATFORM_H
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
#include "wasm_config.h"
|
||||
#include "wasm_types.h"
|
||||
|
||||
typedef uint64_t uint64;
|
||||
typedef int64_t int64;
|
||||
typedef float float32;
|
||||
typedef double float64;
|
||||
|
||||
#ifndef NULL
|
||||
# define NULL ((void*) 0)
|
||||
#endif
|
||||
|
||||
#define WASM_PLATFORM "VxWorks"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <ctype.h>
|
||||
#include <pthread.h>
|
||||
#include <limits.h>
|
||||
#include <semaphore.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
/**
|
||||
* Return the offset of the given field in the given type.
|
||||
*
|
||||
* @param Type the type containing the filed
|
||||
* @param field the field in the type
|
||||
*
|
||||
* @return the offset of field in Type
|
||||
*/
|
||||
#ifndef offsetof
|
||||
#define offsetof(Type, field) ((size_t)(&((Type *)0)->field))
|
||||
#endif
|
||||
|
||||
typedef pthread_t korp_tid;
|
||||
typedef pthread_mutex_t korp_mutex;
|
||||
|
||||
int wasm_platform_init();
|
||||
|
||||
extern bool is_little_endian;
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/* The following operations declared in string.h may be defined as
|
||||
macros on Linux, so don't declare them as functions here. */
|
||||
/* memset */
|
||||
/* memcpy */
|
||||
/* memmove */
|
||||
|
||||
/* #include <stdio.h> */
|
||||
|
||||
/* Unit test framework is based on C++, where the declaration of
|
||||
snprintf is different. */
|
||||
#ifndef __cplusplus
|
||||
int snprintf(char *buffer, size_t count, const char *format, ...);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* #include <math.h> */
|
||||
|
||||
#ifndef __cplusplus
|
||||
double sqrt(double x);
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
char*
|
||||
wasm_read_file_to_buffer(const char *filename, int *ret_size);
|
||||
|
||||
void*
|
||||
wasm_dlsym(void *handle, const char *symbol);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user