Re-org platform APIs: move most platform APIs of iwasm to shared-lib (#45)
This commit is contained in:
@ -1,96 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
@ -1,104 +0,0 @@
|
||||
/*
|
||||
* 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 "wasm_config.h"
|
||||
#include "wasm_types.h"
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.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 "Linux"
|
||||
|
||||
#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>
|
||||
extern int fopen_s(FILE ** pFile, const char *filename, const char *mode);
|
||||
|
||||
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