add simple sum example
This commit is contained in:
109
examples/Makefile
Normal file
109
examples/Makefile
Normal file
@ -0,0 +1,109 @@
|
||||
ARCH ?= bochs
|
||||
|
||||
BUILD_DIR := build-${ARCH}
|
||||
FAIL_BIN ?= /home/fail/bin
|
||||
FAIL_SERVER ?= ${FAIL_BIN}/generic-experiment-server
|
||||
FAIL_TRACE ?= ${FAIL_BIN}/generic-tracing-client
|
||||
FAIL_INJECT ?= ${FAIL_BIN}/generic-experiment-client
|
||||
FAIL_DUMP ?= ${FAIL_BIN}/dump-trace
|
||||
FAIL_IMPORT ?= ${FAIL_BIN}/import-trace --enable-sanitychecks
|
||||
FAIL_PRUNE ?= ${FAIL_BIN}/prune-trace
|
||||
BOCHS_RUNNER ?= ${FAIL_BIN}/bochs-experiment-runner.py
|
||||
RESULT_BROWSER ?= ${FAIL_BIN}/resultbrowser.py
|
||||
|
||||
EXPERIMENTS := $(patsubst %.c,%,$(shell echo *.c))
|
||||
|
||||
include arch/${ARCH}.mk
|
||||
|
||||
$(foreach element,$(EXPERIMENTS),$(eval $(call arch-make-targets,$(element))))
|
||||
|
||||
all: help
|
||||
|
||||
help:
|
||||
@echo "Small Playground for FAIL* Injections"
|
||||
@echo "-------------------------------------"
|
||||
@echo "Current Configuartion"
|
||||
@echo " ARCH=${ARCH}"
|
||||
|
||||
|
||||
clean:
|
||||
rm -f *.wasm
|
||||
rm -f *.aot
|
||||
rm -f *_wasm.c
|
||||
rm -f *.d
|
||||
rm -f *.o
|
||||
rm -f embed/*_host.c
|
||||
rm -f *_host.elf
|
||||
rm -rf ${BUILD_DIR}
|
||||
|
||||
clean-%:
|
||||
rm -rf ${BUILD_DIR}/$(patsubst clean-%,%,$@)
|
||||
contrib/clean-db '${ARCH}/$(patsubst clean-%,%,$@)'
|
||||
|
||||
|
||||
build-%:
|
||||
@echo "****************************************************************\n\
|
||||
* The next step is to trace a golden run. The golden run executes the\n\
|
||||
* system-under-test (SUT) within the emulator. A trace file is \n\
|
||||
* produced and saved as: ${BUILD_DIR}/main/trace.pb\n\
|
||||
*\n\
|
||||
* $ make trace-$(patsubst build-%,%,$@)\n\
|
||||
****************************************************************"
|
||||
|
||||
|
||||
trace-%:
|
||||
@echo "****************************************************************\n\
|
||||
* The trace is now generated. It can be viewed with\n\
|
||||
*\n\
|
||||
* $ make dump-$(patsubst trace-%,%,$@)\n\
|
||||
*\n\
|
||||
* Next, we have to import the trace into the database\n\
|
||||
*\n\
|
||||
* $ make import-$(patsubst trace-%,%,$@)\n\
|
||||
****************************************************************"
|
||||
|
||||
dump-%: ${BUILD_DIR}/%/trace.pb
|
||||
${FAIL_DUMP} $(shell dirname $<)/trace.pb
|
||||
|
||||
${HOME}/.my.cnf:
|
||||
@echo "[client]" > $@
|
||||
@echo "user=fail" >> $@
|
||||
@echo "database=fail" >> $@
|
||||
@echo "password=fail" >> $@
|
||||
@echo "host=db" >> $@
|
||||
@echo "port=3306" >> $@
|
||||
|
||||
import-%: import-arch-%
|
||||
@echo "****************************************************************\n\
|
||||
* The golden run sits now within the MySQL database. If you are interested,\n\
|
||||
* use the 'mysql' command to inspect the curent state of the DB. The tables\n\
|
||||
* trace, fsppilot, and fspgroup are of special interest.\n\
|
||||
*\n\
|
||||
* Next, we have to run the campaign sever and the injection client\n\
|
||||
*\n\
|
||||
* $ make server-$(patsubst import-%,%,$@) &\n\
|
||||
* $ make client-$(patsubst import-%,%,$@) \n\n\
|
||||
* Afterwards, the results can be viewd with\n\
|
||||
* $ make result-$(subst import-,,$@)\n\
|
||||
****************************************************************"
|
||||
|
||||
server-%:
|
||||
${FAIL_SERVER} -v ${ARCH}/$(subst server-,,$@) -b %
|
||||
|
||||
result-%:
|
||||
@echo "select variant, benchmark, resulttype, sum(t.time2 - t.time1 + 1) as faults\
|
||||
FROM variant v \
|
||||
JOIN trace t ON v.id = t.variant_id \
|
||||
JOIN fspgroup g ON g.variant_id = t.variant_id AND g.instr2 = t.instr2 AND g.data_address = t.data_address\
|
||||
JOIN result_GenericExperimentMessage r ON r.pilot_id = g.pilot_id \
|
||||
JOIN fsppilot p ON r.pilot_id = p.id \
|
||||
WHERE v.variant = \"${ARCH}/$(patsubst result-%,%,$@)\"\
|
||||
GROUP BY v.id, resulttype \
|
||||
ORDER BY variant, benchmark, resulttype;" |mysql -t
|
||||
|
||||
resultbrowser:
|
||||
${RESULT_BROWSER} --host=0.0.0.0 --port=5000
|
||||
|
||||
|
||||
# Do never remove implicitly generated stuff
|
||||
.SECONDARY:
|
||||
86
examples/Makefile_EmbedWASM
Normal file
86
examples/Makefile_EmbedWASM
Normal file
@ -0,0 +1,86 @@
|
||||
# This makefile embeds an application compiled to WASM into a native C program.
|
||||
# The WASM module will be loaded by the WASM runtime.
|
||||
|
||||
# Paths
|
||||
WAMR_ROOT := /opt/wamr
|
||||
WAMRC := /opt/wamr-wamrc/wamrc
|
||||
IWASM := /opt/wamr-iwasm/iwasm
|
||||
WAMRC_LIB := /opt/wamr-libvmlib
|
||||
IWASM_LIB := /opt/wamr-libiwasm
|
||||
|
||||
WASI_ROOT := /opt/wasi-sdk
|
||||
WASI_CC := $(WASI_ROOT)/bin/clang
|
||||
WASI_CFLAGS := --target=wasm32-wasi \
|
||||
--sysroot=$(WASI_ROOT)/share/wasi-sysroot \
|
||||
-O0 -g -Wall
|
||||
|
||||
# Embedding
|
||||
EMBED_CC := gcc
|
||||
EMBED_INCL := -I$(WAMR_ROOT)/core/iwasm/include \
|
||||
-I$(WAMR_ROOT)/core/iwasm/common \
|
||||
-I$(WAMR_ROOT)/core/shared/platform/linux \
|
||||
-I$(WAMR_ROOT)/core/shared/utils \
|
||||
-I$(WAMR_ROOT)/core/shared/utils/uncommon
|
||||
EMBED_SOURCES := $(WAMR_ROOT)/core/shared/utils/uncommon/bh_read_file.c # Not used when reading from buffer
|
||||
EMBED_CFLAGS := -O0 -g -Wall $(EMBED_INCL)
|
||||
AOT_LDFLAGS := -Wl,-rpath,$(WAMRC_LIB)
|
||||
AOT_LDLIBS := -L$(WAMRC_LIB) -lvmlib -lm
|
||||
INTER_LDFLAGS := -Wl,-rpath,$(IWASM_LIB)
|
||||
INTER_LDLIBS := -L$(IWASM_LIB) -liwasm -lm
|
||||
XXD := busybox xxd
|
||||
|
||||
# Files
|
||||
SRCS := $(wildcard *.c)
|
||||
WASMS := $(SRCS:.c=.wasm)
|
||||
CWASMS := $(SRCS:.c=_wasm.c)
|
||||
AOTS := $(SRCS:.c=.aot)
|
||||
OBJS := $(SRCS:.c=.o)
|
||||
DEPS := $(SRCS:.c=.d)
|
||||
HOSTS := $(SRCS:.c=_host.elf)
|
||||
|
||||
|
||||
.PHONY: all build-wasms build-aots build-cwasms build-hosts clean
|
||||
|
||||
all: build-wasms build-aots build-cwasms build-hosts
|
||||
|
||||
# Compile to wasm bytecode using wasi-sdk
|
||||
build-wasms: $(WASMS)
|
||||
|
||||
%.wasm: %.c
|
||||
$(WASI_CC) $(WASI_CFLAGS) $< -o $@
|
||||
|
||||
# Compile ahead-of-time module using wamrc
|
||||
build-aots: $(AOTS)
|
||||
|
||||
%.aot: %.wasm
|
||||
$(WAMRC) -o $@ $<
|
||||
|
||||
# Convert the .aot files to C-style arrays (to embed them into the resulting host binary)
|
||||
build-cwasms: $(CWASMS)
|
||||
|
||||
%_wasm.c: %.aot
|
||||
$(XXD) -i $< > $@
|
||||
|
||||
# Compile the host that will load and run the compiled wasm module
|
||||
# The compiled wasm module is embedded as C-style array
|
||||
build-hosts: $(HOSTS)
|
||||
|
||||
# The C-style array is called %_aot, e.g. test_aot
|
||||
# We have to modify the host to refer to that with the correct name
|
||||
%_host.elf: %_wasm.c
|
||||
cp embed/host.c embed/$*_host.c
|
||||
sed -i \
|
||||
-e "s@__WASM_ARRAY_FILE__@../$*_wasm.c@g" \
|
||||
-e "s@__WASM_ARRAY__@$*_aot@g" \
|
||||
-e "s@__WASM_ARRAY_LEN__@$*_aot_len@g" \
|
||||
embed/$*_host.c
|
||||
$(EMBED_CC) $(EMBED_CFLAGS) embed/$*_host.c -o $@ $(INTER_LDFLAGS) $(INTER_LDLIBS)
|
||||
|
||||
clean:
|
||||
rm -f *.wasm
|
||||
rm -f *.aot
|
||||
rm -f *_wasm.c
|
||||
rm -f *.d
|
||||
rm -f *.o
|
||||
rm -f embed/*_host.c
|
||||
rm -f *_host.elf
|
||||
154
examples/arch/bochs.mk
Normal file
154
examples/arch/bochs.mk
Normal file
@ -0,0 +1,154 @@
|
||||
# C -> WASM
|
||||
WASI_ROOT := /opt/wasi-sdk
|
||||
WASI_CC := ${WASI_ROOT}/bin/clang
|
||||
WASI_CFLAGS := --target=wasm32 \
|
||||
--sysroot=${WASI_ROOT}/share/wasi-sysroot \
|
||||
-z stack-size=4096 \
|
||||
-nostdlib \
|
||||
-O0 -g -Wall \
|
||||
-Wl,--no-entry \
|
||||
-Wl,--initial-memory=65536 \
|
||||
-Wl,--export-all \
|
||||
-Wl,--export=__heap_base \
|
||||
-Wl,--export=__data_end
|
||||
|
||||
# WASM -> Baremetal
|
||||
WAMR := /opt/wamr
|
||||
IWASM_LIB := /opt/wamr-libiwasm
|
||||
CC := gcc
|
||||
CFLAGS := -I. -include arch/${ARCH}/lib.c -O0 -g -m32 -fomit-frame-pointer
|
||||
LDFLAGS := -Wl,-T linker.ld $^ -Wl,--build-id=none -static -nostdlib -m32 \
|
||||
-Wl,-rpath,${IWASM_LIB} -L${IWASM_LIB} -liwasm
|
||||
INCL := -I${WAMR}/core/iwasm/include \
|
||||
-I${WAMR}/core/iwasm/common \
|
||||
-I${WAMR}/core/shared/platform/include \
|
||||
-I${WAMR}/core/shared/platform/linux \
|
||||
-I${WAMR}/core/shared/mem-alloc \
|
||||
-I${WAMR}/core/shared/utils \
|
||||
-I${WAMR}/core/shared/utils/uncommon
|
||||
WAMRC := /opt/wamr-wamrc/wamrc
|
||||
WAMRCFLAGS := --target=i386 --format=object
|
||||
XXD := busybox xxd
|
||||
WASM2C := wasm2c
|
||||
|
||||
|
||||
################################################################
|
||||
# C -> WASM
|
||||
${BUILD_DIR}/%/module.wasm: %.c
|
||||
mkdir -p $(shell dirname $@)
|
||||
${WASI_CC} ${WASI_CFLAGS} $< -o $@
|
||||
|
||||
|
||||
################################################################
|
||||
# WASM -> Native Object File
|
||||
# ${BUILD_DIR}/%/system.o: ${BUILD_DIR}/%/module.wasm
|
||||
# ${WAMRC} ${WAMRCFLAGS} -o ${BUILD_DIR}/$*/system.o ${BUILD_DIR}/$*/module.wasm
|
||||
#
|
||||
# ${BUILD_DIR}/startup.o: arch/bochs/startup.s
|
||||
# ${CC} $< ${CFLAGS} -c -ffunction-sections -o $@
|
||||
#
|
||||
# ${BUILD_DIR}/%/system.elf: ${BUILD_DIR}/%/system.o ${BUILD_DIR}/startup.o
|
||||
# ${CC} ${LDFLAGS} -o $@
|
||||
|
||||
|
||||
################################################################
|
||||
# WASM -> AOT -> Loaded by Runtime
|
||||
${BUILD_DIR}/%/module.aot: ${BUILD_DIR}/%/module.wasm
|
||||
${WAMRC} -o $@ $<
|
||||
|
||||
${BUILD_DIR}/%/module_wasm.c: ${BUILD_DIR}/%/module.aot
|
||||
${XXD} -i $< > $@
|
||||
|
||||
${BUILD_DIR}/%/system.o: ${BUILD_DIR}/%/module_wasm.c
|
||||
cp embed/host.c ${BUILD_DIR}/$*/module_host.c
|
||||
sed -i \
|
||||
-e "s/__WASM_ARRAY_FILE__/module_wasm.c/g" \
|
||||
-e "s/__WASM_ARRAY__/build_bochs_$*_module_aot/g" \
|
||||
-e "s/__WASM_ARRAY_LEN__/build_bochs_$*_module_aot_len/g" \
|
||||
${BUILD_DIR}/$*/module_host.c
|
||||
${CC} ${CFLAGS} ${INCL} -c -ffunction-sections ${BUILD_DIR}/$*/module_host.c -o $@
|
||||
|
||||
${BUILD_DIR}/startup.o: arch/bochs/startup.s
|
||||
${CC} $< ${CFLAGS} -c -ffunction-sections -o $@
|
||||
|
||||
${BUILD_DIR}/%/system.elf: ${BUILD_DIR}/%/system.o ${BUILD_DIR}/startup.o
|
||||
${CC} ${LDFLAGS} -o $@
|
||||
|
||||
################################################################
|
||||
# Bochs
|
||||
${BUILD_DIR}/%/system.iso: ${BUILD_DIR}/%/system.elf
|
||||
rm -rf $(shell dirname $<)/grub
|
||||
mkdir -p $(shell dirname $<)/grub/boot/grub
|
||||
cp arch/bochs/grub.cfg $(shell dirname $<)/grub/boot/grub
|
||||
cp $< $(shell dirname $<)/grub/boot/system.elf
|
||||
grub-mkrescue -o $@ $(shell dirname $<)/grub
|
||||
|
||||
|
||||
BOCHS_RUNNER_ARGS = \
|
||||
-V arch/bochs/vgabios.bin \
|
||||
-b arch/bochs/BIOS-bochs-latest \
|
||||
|
||||
${BUILD_DIR}/%/trace.pb: ${BUILD_DIR}/%/system.iso
|
||||
${BOCHS_RUNNER} ${BOCHS_RUNNER_ARGS} -1 \
|
||||
-f ${FAIL_TRACE} \
|
||||
-e $(shell dirname $<)/system.elf \
|
||||
-i $(shell dirname $<)/system.iso \
|
||||
-- \
|
||||
-Wf,--state-file=$(shell dirname $<)/state \
|
||||
-Wf,--trace-file=$(shell dirname $<)/trace.pb \
|
||||
-Wf,--start-symbol=start_trace \
|
||||
-Wf,--end-symbol=stop_trace \
|
||||
-Wf,--check-bounds
|
||||
|
||||
|
||||
client-%:
|
||||
${BOCHS_RUNNER} ${BOCHS_RUNNER_ARGS} \
|
||||
-f ${FAIL_INJECT} \
|
||||
-e ${BUILD_DIR}/$(subst client-,,$@)/system.elf \
|
||||
-i ${BUILD_DIR}/$(subst client-,,$@)/system.iso \
|
||||
-j $(shell getconf _NPROCESSORS_ONLN) \
|
||||
-- \
|
||||
-Wf,--state-dir=${BUILD_DIR}/$(subst client-,,$@)/state \
|
||||
-Wf,--trap \
|
||||
-Wf,--timeout=10 \
|
||||
-Wf,--ok-marker=ok_marker \
|
||||
-Wf,--fail-marker=fail_marker \
|
||||
-Wf,--catch-write-textsegment \
|
||||
-Wf,--catch-outerspace \
|
||||
2>/dev/null | grep -B 2 -A 8 'INJECT'
|
||||
|
||||
inject-%:
|
||||
${BOCHS_RUNNER} ${BOCHS_RUNNER_ARGS} -1 \
|
||||
-f ${FAIL_INJECT} \
|
||||
-e ${BUILD_DIR}/$(subst inject-,,$@)/system.elf \
|
||||
-i ${BUILD_DIR}/$(subst inject-,,$@)/system.iso \
|
||||
-j 1 -- \
|
||||
-Wf,--state-dir=${BUILD_DIR}/$(subst inject-,,$@)/state \
|
||||
-Wf,--trap \
|
||||
-Wf,--timeout=10 \
|
||||
-Wf,--ok-marker=ok_marker \
|
||||
-Wf,--fail-marker=fail_marker \
|
||||
-Wf,--catch-write-textsegment \
|
||||
-Wf,--catch-outerspace
|
||||
|
||||
# TODO: Command line interface changed
|
||||
import-arch-%: ${BUILD_DIR}/%/trace.pb ${HOME}/.my.cnf
|
||||
# ${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b mem -t $< -e $(shell dirname $<)/system.elf -i mem --memory-type ram
|
||||
# ${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b regs-trace -t $< -e $(shell dirname $<)/system.elf -i mem --memory-type register
|
||||
# ${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b regs -t $< -e $(shell dirname $<)/system.elf -i regs
|
||||
# ${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b ip -t $< -e $(shell dirname $<)/system.elf -i regs --no-gp --ip
|
||||
# ${FAIL_PRUNE} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b %% --overwrite
|
||||
${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b mem -t $< -e $(shell dirname $<)/system.elf -i MemoryImporter
|
||||
${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b regs-trace -t $< -e $(shell dirname $<)/system.elf -i MemoryImporter
|
||||
${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b regs -t $< -e $(shell dirname $<)/system.elf -i RegisterImporter
|
||||
${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b ip -t $< -e $(shell dirname $<)/system.elf -i RegisterImporter --no-gp --ip
|
||||
${FAIL_PRUNE} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b %% --overwrite
|
||||
|
||||
|
||||
define arch-make-targets
|
||||
|
||||
build-$1: ${BUILD_DIR}/$1/system.iso
|
||||
|
||||
trace-$1: ${BUILD_DIR}/$1/trace.pb
|
||||
|
||||
endef
|
||||
BIN
examples/arch/bochs/BIOS-bochs-latest
Normal file
BIN
examples/arch/bochs/BIOS-bochs-latest
Normal file
Binary file not shown.
7
examples/arch/bochs/grub.cfg
Normal file
7
examples/arch/bochs/grub.cfg
Normal file
@ -0,0 +1,7 @@
|
||||
set timeout=0
|
||||
set default=0
|
||||
|
||||
menuentry "CoRedOS" {
|
||||
multiboot /boot/system.elf
|
||||
boot
|
||||
}
|
||||
4
examples/arch/bochs/lib.c
Normal file
4
examples/arch/bochs/lib.c
Normal file
@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
#define ARCH_ASM_CLOBBER_ALL "eax", "ebx", "ecx", "edx", "esi", "edi", "ebp"
|
||||
|
||||
59
examples/arch/bochs/startup.s
Normal file
59
examples/arch/bochs/startup.s
Normal file
@ -0,0 +1,59 @@
|
||||
## Bare bone boot.s from wiki.osdev.org
|
||||
|
||||
# multiboot header
|
||||
.section .rodata.multiboot
|
||||
.align 4
|
||||
|
||||
# magic number
|
||||
.long 0x1BADB002
|
||||
|
||||
# flags: align, meminfo
|
||||
.long 0x3
|
||||
|
||||
# checksum: -(magic+flags)
|
||||
.long -(0x1BADB002 + 0x3)
|
||||
|
||||
|
||||
|
||||
# the initial kernel stack
|
||||
.section .kernel_stack
|
||||
.global os_stack
|
||||
.size os_stack, 4096
|
||||
#.Lstack_bottom:
|
||||
os_stack:
|
||||
.byte 0
|
||||
#.skip 16384 # 16 KiB
|
||||
.skip 4094 # 4 KiB
|
||||
.byte 0
|
||||
.Lstack_top:
|
||||
|
||||
|
||||
|
||||
# The linker script specifies _start as the entry point to the kernel and the
|
||||
# bootloader will jump to this position once the kernel has been loaded. It
|
||||
# doesn't make sense to return from this function as the bootloader is gone.
|
||||
.section .text.startup
|
||||
.global _start
|
||||
.type _start, @function
|
||||
_start:
|
||||
# Welcome to kernel mode!
|
||||
# To set up a stack, we simply set the esp register to point to the top of
|
||||
# our stack (as it grows downwards).
|
||||
movl $.Lstack_top, %esp
|
||||
# We are now ready to actually execute C code. (see ./startup.cc)
|
||||
call os_main
|
||||
|
||||
# In case the function returns, we'll want to put the computer into an
|
||||
# infinite loop. To do that, we use the clear interrupt ('cli') instruction
|
||||
# to disable interrupts, the halt instruction ('hlt') to stop the CPU until
|
||||
# the next interrupt arrives, and jumping to the halt instruction if it ever
|
||||
# continues execution, just to be safe. We will create a local label rather
|
||||
# than real symbol and jump to there endlessly.
|
||||
cli
|
||||
hlt
|
||||
.Lhang:
|
||||
jmp .Lhang
|
||||
|
||||
# Set the size of the _start symbol to the current location '.' minus its start.
|
||||
# This is useful when debugging or when you implement call tracing.
|
||||
.size _start, . - _start
|
||||
BIN
examples/arch/bochs/vgabios.bin
Normal file
BIN
examples/arch/bochs/vgabios.bin
Normal file
Binary file not shown.
BIN
examples/build-bochs/startup.o
Normal file
BIN
examples/build-bochs/startup.o
Normal file
Binary file not shown.
7
examples/build-bochs/sum/grub/boot/grub/grub.cfg
Normal file
7
examples/build-bochs/sum/grub/boot/grub/grub.cfg
Normal file
@ -0,0 +1,7 @@
|
||||
set timeout=0
|
||||
set default=0
|
||||
|
||||
menuentry "CoRedOS" {
|
||||
multiboot /boot/system.elf
|
||||
boot
|
||||
}
|
||||
BIN
examples/build-bochs/sum/grub/boot/system.elf
Executable file
BIN
examples/build-bochs/sum/grub/boot/system.elf
Executable file
Binary file not shown.
BIN
examples/build-bochs/sum/module.aot
Normal file
BIN
examples/build-bochs/sum/module.aot
Normal file
Binary file not shown.
BIN
examples/build-bochs/sum/module.wasm
Executable file
BIN
examples/build-bochs/sum/module.wasm
Executable file
Binary file not shown.
75
examples/build-bochs/sum/module_host.c
Normal file
75
examples/build-bochs/sum/module_host.c
Normal file
@ -0,0 +1,75 @@
|
||||
// https://github.com/bytecodealliance/wasm-micro-runtime/blob/WAMR-2.4.4/doc/embed_wamr.md
|
||||
|
||||
// #include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "lib.c"
|
||||
|
||||
// #include "bh_read_file.h"
|
||||
#include "bh_platform.h"
|
||||
#include "wasm_export.h"
|
||||
|
||||
#include "module_wasm.c"
|
||||
|
||||
#define STACK_SIZE (8 * 1024)
|
||||
#define HEAP_SIZE (8 * 1024)
|
||||
|
||||
// TODO: Set this up so the lsp actually finds the includes...
|
||||
|
||||
MAIN() {
|
||||
char error_buf[128];
|
||||
wasm_module_t module;
|
||||
wasm_module_inst_t module_inst;
|
||||
wasm_function_inst_t func;
|
||||
wasm_exec_env_t exec_env;
|
||||
uint32 stack_size = 8 * 1024;
|
||||
uint32 heap_size = 8 * 1024;
|
||||
|
||||
/* initialize the wasm runtime */
|
||||
RuntimeInitArgs init_args;
|
||||
memset(&init_args, 0, sizeof(init_args));
|
||||
|
||||
init_args.mem_alloc_type = Alloc_With_System_Allocator;
|
||||
if (!wasm_runtime_full_init(&init_args)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* parse the WASM file from buffer and create a WASM module */
|
||||
module = wasm_runtime_load(build_bochs_sum_module_aot, build_bochs_sum_module_aot_len, error_buf,
|
||||
sizeof(error_buf));
|
||||
|
||||
/* create an instance of the WASM module (WASM linear memory is ready) */
|
||||
module_inst = wasm_runtime_instantiate(module, stack_size, heap_size,
|
||||
error_buf, sizeof(error_buf));
|
||||
|
||||
/* lookup a WASM function by its name, the function signature can NULL here */
|
||||
func = wasm_runtime_lookup_function(module_inst, "wasm_module");
|
||||
|
||||
/* create an execution environment to execute arbitrary WASM functions */
|
||||
exec_env = wasm_runtime_create_exec_env(module_inst, stack_size);
|
||||
|
||||
/* arguments are always transferred in 32-bit element */
|
||||
uint32 args[1];
|
||||
|
||||
/* call an arbitrary WASM function */
|
||||
MARKER(start_trace);
|
||||
if (!wasm_runtime_call_wasm(exec_env, func, 0, args)) {
|
||||
/* function wasn't called correctly */
|
||||
POSIX_PRINTF("Failed to call function 'wasm_module'!\n");
|
||||
}
|
||||
MARKER(stop_trace);
|
||||
|
||||
POSIX_PRINTF("Sum: %d\n!", args[0]);
|
||||
|
||||
/* the return value is stored in args[0] */
|
||||
if (args[0] == 100) {
|
||||
MARKER(ok_marker);
|
||||
} else {
|
||||
MARKER(fail_marker);
|
||||
}
|
||||
|
||||
wasm_runtime_destroy_exec_env(exec_env);
|
||||
wasm_runtime_deinstantiate(module_inst);
|
||||
wasm_runtime_unload(module);
|
||||
wasm_runtime_destroy();
|
||||
}
|
||||
68
examples/build-bochs/sum/module_wasm.c
Normal file
68
examples/build-bochs/sum/module_wasm.c
Normal file
@ -0,0 +1,68 @@
|
||||
unsigned char build_bochs_sum_module_aot[] = {
|
||||
0x00, 0x61, 0x6f, 0x74, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x30, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x3e, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x78, 0x38, 0x36, 0x5f, 0x36, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x14, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x7f, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x7f, 0x01, 0x00, 0x00,
|
||||
0x41, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00,
|
||||
0x41, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00,
|
||||
0x41, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00,
|
||||
0x41, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00,
|
||||
0x41, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00,
|
||||
0x41, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00,
|
||||
0x41, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00,
|
||||
0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x7f, 0x00, 0x00, 0x00,
|
||||
0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00,
|
||||
0x41, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00,
|
||||
0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x02, 0x00, 0x00, 0x00,
|
||||
0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00,
|
||||
0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0xc3, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x2e,
|
||||
0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x8b, 0x47, 0x10,
|
||||
0x48, 0xba, 0x64, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x48, 0x8b,
|
||||
0x88, 0x78, 0x01, 0x00, 0x00, 0x8b, 0x80, 0xd0, 0x01, 0x00, 0x00, 0x83,
|
||||
0xc0, 0xf0, 0x48, 0x89, 0x54, 0x01, 0x08, 0xb8, 0x64, 0x00, 0x00, 0x00,
|
||||
0xc3, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x2a, 0x01, 0x00, 0x00,
|
||||
0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x07, 0x00,
|
||||
0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x12, 0x00, 0x5f, 0x5f, 0x77, 0x61, 0x73, 0x6d, 0x5f, 0x63,
|
||||
0x61, 0x6c, 0x6c, 0x5f, 0x63, 0x74, 0x6f, 0x72, 0x73, 0x00, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x77, 0x61, 0x73, 0x6d,
|
||||
0x5f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x03, 0x00, 0x0d, 0x00, 0x5f, 0x5f, 0x64, 0x73, 0x6f, 0x5f, 0x68, 0x61,
|
||||
0x6e, 0x64, 0x6c, 0x65, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
|
||||
0x03, 0x00, 0x0b, 0x00, 0x5f, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x65,
|
||||
0x6e, 0x64, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0c, 0x00,
|
||||
0x5f, 0x5f, 0x73, 0x74, 0x61, 0x63, 0x6b, 0x5f, 0x6c, 0x6f, 0x77, 0x00,
|
||||
0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0d, 0x00, 0x5f, 0x5f, 0x73, 0x74,
|
||||
0x61, 0x63, 0x6b, 0x5f, 0x68, 0x69, 0x67, 0x68, 0x00, 0x00, 0x00, 0x00,
|
||||
0x05, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0e, 0x00, 0x5f, 0x5f, 0x67, 0x6c,
|
||||
0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x62, 0x61, 0x73, 0x65, 0x00, 0x00, 0x00,
|
||||
0x06, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0c, 0x00, 0x5f, 0x5f, 0x68, 0x65,
|
||||
0x61, 0x70, 0x5f, 0x62, 0x61, 0x73, 0x65, 0x00, 0x07, 0x00, 0x00, 0x00,
|
||||
0x03, 0x00, 0x0b, 0x00, 0x5f, 0x5f, 0x68, 0x65, 0x61, 0x70, 0x5f, 0x65,
|
||||
0x6e, 0x64, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0e, 0x00,
|
||||
0x5f, 0x5f, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x5f, 0x62, 0x61, 0x73,
|
||||
0x65, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0d, 0x00,
|
||||
0x5f, 0x5f, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x62, 0x61, 0x73, 0x65,
|
||||
0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x03, 0x00, 0x16, 0x00,
|
||||
0x5f, 0x5f, 0x77, 0x61, 0x73, 0x6d, 0x5f, 0x66, 0x69, 0x72, 0x73, 0x74,
|
||||
0x5f, 0x70, 0x61, 0x67, 0x65, 0x5f, 0x65, 0x6e, 0x64, 0x00, 0x00, 0x00,
|
||||
0x05, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
unsigned int build_bochs_sum_module_aot_len = 776;
|
||||
BIN
examples/build-bochs/sum/system.elf
Executable file
BIN
examples/build-bochs/sum/system.elf
Executable file
Binary file not shown.
BIN
examples/build-bochs/sum/system.iso
Normal file
BIN
examples/build-bochs/sum/system.iso
Normal file
Binary file not shown.
BIN
examples/build-bochs/sum/system.o
Normal file
BIN
examples/build-bochs/sum/system.o
Normal file
Binary file not shown.
75
examples/embed/host.c
Normal file
75
examples/embed/host.c
Normal file
@ -0,0 +1,75 @@
|
||||
// https://github.com/bytecodealliance/wasm-micro-runtime/blob/WAMR-2.4.4/doc/embed_wamr.md
|
||||
|
||||
// #include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "lib.c"
|
||||
|
||||
// #include "bh_read_file.h"
|
||||
#include "bh_platform.h"
|
||||
#include "wasm_export.h"
|
||||
|
||||
#include "__WASM_ARRAY_FILE__"
|
||||
|
||||
#define STACK_SIZE (8 * 1024)
|
||||
#define HEAP_SIZE (8 * 1024)
|
||||
|
||||
// TODO: Set this up so the lsp actually finds the includes...
|
||||
|
||||
MAIN() {
|
||||
char error_buf[128];
|
||||
wasm_module_t module;
|
||||
wasm_module_inst_t module_inst;
|
||||
wasm_function_inst_t func;
|
||||
wasm_exec_env_t exec_env;
|
||||
uint32 stack_size = 8 * 1024;
|
||||
uint32 heap_size = 8 * 1024;
|
||||
|
||||
/* initialize the wasm runtime */
|
||||
RuntimeInitArgs init_args;
|
||||
memset(&init_args, 0, sizeof(init_args));
|
||||
|
||||
init_args.mem_alloc_type = Alloc_With_System_Allocator;
|
||||
if (!wasm_runtime_full_init(&init_args)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* parse the WASM file from buffer and create a WASM module */
|
||||
module = wasm_runtime_load(__WASM_ARRAY__, __WASM_ARRAY_LEN__, error_buf,
|
||||
sizeof(error_buf));
|
||||
|
||||
/* create an instance of the WASM module (WASM linear memory is ready) */
|
||||
module_inst = wasm_runtime_instantiate(module, stack_size, heap_size,
|
||||
error_buf, sizeof(error_buf));
|
||||
|
||||
/* lookup a WASM function by its name, the function signature can NULL here */
|
||||
func = wasm_runtime_lookup_function(module_inst, "wasm_module");
|
||||
|
||||
/* create an execution environment to execute arbitrary WASM functions */
|
||||
exec_env = wasm_runtime_create_exec_env(module_inst, stack_size);
|
||||
|
||||
/* arguments are always transferred in 32-bit element */
|
||||
uint32 args[1];
|
||||
|
||||
/* call an arbitrary WASM function */
|
||||
MARKER(start_trace);
|
||||
if (!wasm_runtime_call_wasm(exec_env, func, 0, args)) {
|
||||
/* function wasn't called correctly */
|
||||
POSIX_PRINTF("Failed to call function 'wasm_module'!\n");
|
||||
}
|
||||
MARKER(stop_trace);
|
||||
|
||||
POSIX_PRINTF("Sum: %d\n!", args[0]);
|
||||
|
||||
/* the return value is stored in args[0] */
|
||||
if (args[0] == 100) {
|
||||
MARKER(ok_marker);
|
||||
} else {
|
||||
MARKER(fail_marker);
|
||||
}
|
||||
|
||||
wasm_runtime_destroy_exec_env(exec_env);
|
||||
wasm_runtime_deinstantiate(module_inst);
|
||||
wasm_runtime_unload(module);
|
||||
wasm_runtime_destroy();
|
||||
}
|
||||
2503
examples/embed/wasm_export.h
Normal file
2503
examples/embed/wasm_export.h
Normal file
File diff suppressed because it is too large
Load Diff
31
examples/lib.c
Normal file
31
examples/lib.c
Normal file
@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#define INLINE __attribute__((always_inline)) inline
|
||||
#define NOINLINE __attribute__((noinline))
|
||||
|
||||
#define __QUOTE(x) #x
|
||||
#define QUOTE(x) __QUOTE(x)
|
||||
|
||||
#ifndef MARKER
|
||||
#define MARKER(str) \
|
||||
__asm__ volatile(QUOTE(str) ":" \
|
||||
: /* no inputs */ \
|
||||
: /* no outputs */ \
|
||||
: "memory", ARCH_ASM_CLOBBER_ALL)
|
||||
#endif
|
||||
|
||||
#ifndef MAIN
|
||||
#define MAIN() void os_main(void)
|
||||
#endif
|
||||
|
||||
#ifndef POSIX_PRINTF
|
||||
#define POSIX_PRINTF(...)
|
||||
#endif
|
||||
|
||||
typedef __UINT8_TYPE__ uint8_t;
|
||||
typedef __UINT16_TYPE__ uint16_t;
|
||||
typedef __UINT32_TYPE__ uint32_t;
|
||||
|
||||
typedef __INT8_TYPE__ int8_t;
|
||||
typedef __INT16_TYPE__ int16_t;
|
||||
typedef __INT32_TYPE__ int32_t;
|
||||
70
examples/linker.ld
Normal file
70
examples/linker.ld
Normal file
@ -0,0 +1,70 @@
|
||||
/* Kernel entry function */
|
||||
ENTRY(_start)
|
||||
|
||||
OUTPUT_FORMAT(elf32-i386)
|
||||
|
||||
SECTIONS {
|
||||
|
||||
/DISCARD/ : {
|
||||
*(".text.inlined*")
|
||||
*(.comment)
|
||||
*(.eh_frame)
|
||||
*(.note.gnu.build-id)
|
||||
}
|
||||
|
||||
/* Set kernel start address */
|
||||
. = 0x100000;
|
||||
|
||||
/* Code and readonly data */
|
||||
.text : {
|
||||
/* fill gaps with int3 opcode to detect invalid jumps */
|
||||
FILL(0xcc)
|
||||
|
||||
/* multiboot header */
|
||||
multiboot_header = .;
|
||||
KEEP (*(".rodata.multiboot"))
|
||||
|
||||
/* /\* fixed address for IRQ handlers *\/ */
|
||||
/* . = 0x1000; */
|
||||
|
||||
/* /\* start of interrupt handlers *\/ */
|
||||
/* _stext_irqs = .; */
|
||||
|
||||
/* /\* IRQ Handlers *\/ */
|
||||
/* KEEP (*(".text.irqhandlers*")) /\* ASM *\/ */
|
||||
/* KEEP (*(".text.irq_handler*")) /\* C *\/ */
|
||||
/* *(".text.isrs*") /\* C *\/ */
|
||||
/* *(".text.isr_*") /\* C *\/ */
|
||||
/* KEEP (*(".text.OSEKOS_ISR*")) */
|
||||
/* KEEP (*(".text.idt")) /\* ASM *\/ */
|
||||
|
||||
/* /\* sysenter handler *\/ */
|
||||
/* KEEP (*(".text.sysenter_syscall")) */
|
||||
|
||||
/* _etext_irqs = .; */
|
||||
/* . += 16; /\* padding after data, workaround for import-trace *\/ */
|
||||
|
||||
KEEP (*(".text.startup"))
|
||||
*(".text*")
|
||||
*(".rodata*")
|
||||
}
|
||||
|
||||
/* Data and Stacks */
|
||||
. = 0x200000;
|
||||
.data : {
|
||||
KEEP (*(".startup_stack"))
|
||||
KEEP (*(".kernel_stack"))
|
||||
*(".data*")
|
||||
*(COMMON);
|
||||
}
|
||||
|
||||
/* Memory-mapped I/O APIC */
|
||||
_sioapic = 0xFEC00000;
|
||||
ioapic = 0xFEC00000;
|
||||
_eioapic = 0xFEC00FFF;
|
||||
|
||||
/* Memory-mapped Local APIC */
|
||||
_slapic = 0xFEE00000;
|
||||
lapic = 0xFEE00000;
|
||||
_elapic = 0xFEE00FFF;
|
||||
}
|
||||
78
examples/stubs.c
Normal file
78
examples/stubs.c
Normal file
@ -0,0 +1,78 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// https://git.musl-libc.org/cgit/musl/tree/src/string/memcpy.c
|
||||
|
||||
void *memcpy(void *restrict dest, const void *restrict src, size_t n) {
|
||||
unsigned char *d = dest;
|
||||
const unsigned char *s = src;
|
||||
|
||||
for (; n; n--)
|
||||
*d++ = *s++;
|
||||
return dest;
|
||||
}
|
||||
|
||||
// https://git.musl-libc.org/cgit/musl/tree/src/string/memmove.c
|
||||
|
||||
void *memmove(void *dest, const void *src, size_t n) {
|
||||
char *d = dest;
|
||||
const char *s = src;
|
||||
|
||||
if (d == s)
|
||||
return d;
|
||||
if ((uintptr_t)s - (uintptr_t)d - n <= -2 * n)
|
||||
return memcpy(d, s, n);
|
||||
|
||||
if (d < s) {
|
||||
for (; n; n--)
|
||||
*d++ = *s++;
|
||||
} else {
|
||||
while (n)
|
||||
n--, d[n] = s[n];
|
||||
}
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
// https://git.musl-libc.org/cgit/musl/tree/src/string/memset.c
|
||||
|
||||
void *memset(void *dest, int c, size_t n) {
|
||||
unsigned char *s = dest;
|
||||
size_t k;
|
||||
|
||||
/* Fill head and tail with minimal branching. Each
|
||||
* conditional ensures that all the subsequently used
|
||||
* offsets are well-defined and in the dest region. */
|
||||
|
||||
if (!n)
|
||||
return dest;
|
||||
s[0] = c;
|
||||
s[n - 1] = c;
|
||||
if (n <= 2)
|
||||
return dest;
|
||||
s[1] = c;
|
||||
s[2] = c;
|
||||
s[n - 2] = c;
|
||||
s[n - 3] = c;
|
||||
if (n <= 6)
|
||||
return dest;
|
||||
s[3] = c;
|
||||
s[n - 4] = c;
|
||||
if (n <= 8)
|
||||
return dest;
|
||||
|
||||
/* Advance pointer to align it at a 4-byte boundary,
|
||||
* and truncate n to a multiple of 4. The previous code
|
||||
* already took care of any head/tail that get cut off
|
||||
* by the alignment. */
|
||||
|
||||
k = -(uintptr_t)s & 3;
|
||||
s += k;
|
||||
n -= k;
|
||||
n &= -4;
|
||||
|
||||
for (; n; n--, s++)
|
||||
*s = c;
|
||||
|
||||
return dest;
|
||||
}
|
||||
7
examples/sum.c
Normal file
7
examples/sum.c
Normal file
@ -0,0 +1,7 @@
|
||||
int wasm_module(void) {
|
||||
int sum = 0;
|
||||
for (int i = 0; i < 100; ++i) {
|
||||
sum += 1;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
Reference in New Issue
Block a user