parent
c12d76686e
commit
1bf796d69a
|
@ -92,17 +92,6 @@ CUSTOM_ADA_INCLUDE ?= -I- $(INCLUDES)
|
||||||
$(VERBOSE)$(CUSTOM_ADA_CC) $(CUSTOM_ADA_FLAGS) $(CUSTOM_ADA_OPT) $(CUSTOM_ADA_INCLUDE) -c $<
|
$(VERBOSE)$(CUSTOM_ADA_CC) $(CUSTOM_ADA_FLAGS) $(CUSTOM_ADA_OPT) $(CUSTOM_ADA_INCLUDE) -c $<
|
||||||
$(VERBOSE)$(ALI2DEP) $(dir $<) $(ALL_INC_DIR) $*.ali
|
$(VERBOSE)$(ALI2DEP) $(dir $<) $(ALL_INC_DIR) $*.ali
|
||||||
|
|
||||||
#
|
|
||||||
# Compiling Rust sources
|
|
||||||
#
|
|
||||||
%.rlib: %.rs
|
|
||||||
$(MSG_COMP)$@
|
|
||||||
$(VERBOSE)rustc $(CC_RUSTC_OPT) --crate-type rlib -o $@ $<
|
|
||||||
|
|
||||||
%.o: %.rlib
|
|
||||||
$(MSG_CONVERT)$@
|
|
||||||
$(VERBOSE)ar p $< $*.0.o > $@
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Assembler files that must be preprocessed are fed to the C compiler.
|
# Assembler files that must be preprocessed are fed to the C compiler.
|
||||||
#
|
#
|
||||||
|
|
|
@ -176,14 +176,6 @@ CC_CXX_OPT += $(CC_OPT) $(CC_CXX_WARN)
|
||||||
CC_C_OPT += $(CC_OPT)
|
CC_C_OPT += $(CC_OPT)
|
||||||
CC_ADA_OPT += $(filter-out -fno-builtin-cos -fno-builtin-sin -fno-builtin-cosf -fno-builtin-sinf ,$(CC_OPT)) -fexceptions
|
CC_ADA_OPT += $(filter-out -fno-builtin-cos -fno-builtin-sin -fno-builtin-cosf -fno-builtin-sinf ,$(CC_OPT)) -fexceptions
|
||||||
|
|
||||||
#
|
|
||||||
# Rust-specific arguments
|
|
||||||
#
|
|
||||||
# Use the correct linker, include dependencies.
|
|
||||||
#
|
|
||||||
CC_RUSTC_OPT += -C linker=$(LD)
|
|
||||||
CC_RUSTC_OPT += $(foreach lib,$(LIBS),-L$(LIB_CACHE_DIR)/$(lib))
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Enable C++11 by default
|
# Enable C++11 by default
|
||||||
#
|
#
|
||||||
|
|
|
@ -167,28 +167,6 @@ $(LIB_TAG) $(OBJECTS): $(HOST_TOOLS)
|
||||||
$(LIB_TAG): $(LIB_A) $(LIB_SO) $(LIB_CHECKED) $(ABI_SO) $(INSTALL_SO) $(DEBUG_SO)
|
$(LIB_TAG): $(LIB_A) $(LIB_SO) $(LIB_CHECKED) $(ABI_SO) $(INSTALL_SO) $(DEBUG_SO)
|
||||||
@touch $@
|
@touch $@
|
||||||
|
|
||||||
#
|
|
||||||
# Rust support
|
|
||||||
#
|
|
||||||
# For a rust library, we create both an actual library (lib.a or lib.so) that
|
|
||||||
# is used for linking the final binary, and an rlib file that is required for
|
|
||||||
# compiling rust source codes that use the library. As the rlib is created from
|
|
||||||
# the file specified at 'SRC_RS' via the pattern rule '%.rlib: %.rs', its name
|
|
||||||
# corresponds to the source file, not the library name. To enable rustc to find
|
|
||||||
# the library when compiling dependent compilation units, we create an
|
|
||||||
# appropriately named symlink that points to the rlib file.
|
|
||||||
#
|
|
||||||
ifneq ($(SRC_RS),)
|
|
||||||
ifneq ($(words $(SRC_RS)),1)
|
|
||||||
$(error 'SRC_RC' of library $(LIB) has more than one element: $(SRC_RC))
|
|
||||||
endif
|
|
||||||
$(LIB_A): $(LIB).rlib
|
|
||||||
endif
|
|
||||||
|
|
||||||
.PRECIOUS: $(SRC_RC:.rs=.rlib)
|
|
||||||
$(LIB).rlib: $(SRC_RS:.rs=.rlib)
|
|
||||||
$(VERBOSE)ln -s $< $@
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Rule to build the <libname>.lib.a file
|
# Rule to build the <libname>.lib.a file
|
||||||
#
|
#
|
||||||
|
|
|
@ -710,7 +710,6 @@ set default_test_pkgs {
|
||||||
test-rm_stress
|
test-rm_stress
|
||||||
test-rom_block
|
test-rom_block
|
||||||
test-rom_filter
|
test-rom_filter
|
||||||
test-rust
|
|
||||||
test-sanitizer
|
test-sanitizer
|
||||||
test-sequence
|
test-sequence
|
||||||
test-signal
|
test-signal
|
||||||
|
@ -771,7 +770,6 @@ set skip_test(test-solo5) [expr ![have_spec x86_64]]
|
||||||
set skip_test(test-spark_exception) [expr [have_spec arm]]
|
set skip_test(test-spark_exception) [expr [have_spec arm]]
|
||||||
set skip_test(test-tcp_bulk_lwip) [expr ![have_spec x86] && ![have_include "power_on/qemu"]]
|
set skip_test(test-tcp_bulk_lwip) [expr ![have_spec x86] && ![have_include "power_on/qemu"]]
|
||||||
set skip_test(test-tcp_bulk_lxip) [expr ![have_spec x86] && ![have_include "power_on/qemu"]]
|
set skip_test(test-tcp_bulk_lxip) [expr ![have_spec x86] && ![have_include "power_on/qemu"]]
|
||||||
set skip_test(test-rust) [expr [have_spec arm_v8a]]
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# FIXME
|
# FIXME
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
TARGET_DIR = src/lib/rust-targets/spec
|
|
||||||
ifeq ($(filter-out $(SPECS),x86),)
|
|
||||||
ifeq ($(filter-out $(SPECS),32bit),)
|
|
||||||
CC_RUSTC_OPT += --target $(call select_from_repositories,$(TARGET_DIR)/x86_32/target.json)
|
|
||||||
endif # 32bit
|
|
||||||
|
|
||||||
ifeq ($(filter-out $(SPECS),64bit),)
|
|
||||||
CC_RUSTC_OPT += --target $(call select_from_repositories,$(TARGET_DIR)/x86_64/target.json)
|
|
||||||
endif # 64bit
|
|
||||||
endif # x86
|
|
||||||
|
|
||||||
ifeq ($(filter-out $(SPECS),arm_v6),)
|
|
||||||
CC_RUSTC_OPT += --target $(call select_from_repositories,$(TARGET_DIR)/armv6/target.json)
|
|
||||||
else ifeq ($(filter-out $(SPECS),arm_v7),)
|
|
||||||
CC_RUSTC_OPT += --target $(call select_from_repositories,$(TARGET_DIR)/armv7/target.json)
|
|
||||||
endif # ARM
|
|
||||||
|
|
||||||
ifeq ($(filter-out $(SPECS),riscv),)
|
|
||||||
CC_RUSTC_OPT += --target $(call select_from_repositories,$(TARGET_DIR)/riscv/target.json)
|
|
||||||
endif # RISCV
|
|
||||||
|
|
||||||
#
|
|
||||||
# Circular dependencies
|
|
||||||
#
|
|
||||||
LIBS += libunwind-rust builtins-rust
|
|
|
@ -1,6 +0,0 @@
|
||||||
LIBS = libcore-rust
|
|
||||||
SRC_RS += lib.rs
|
|
||||||
|
|
||||||
vpath % $(REP_DIR)/src/lib/rust/builtins-rust
|
|
||||||
|
|
||||||
CC_CXX_WARN_STRICT =
|
|
|
@ -1,5 +0,0 @@
|
||||||
LIBS = libcore-rust liballoc_system-rust
|
|
||||||
RLIB = liballoc
|
|
||||||
include $(REP_DIR)/lib/mk/rust.inc
|
|
||||||
|
|
||||||
CC_CXX_WARN_STRICT =
|
|
|
@ -1,7 +0,0 @@
|
||||||
LIBS = libcore-rust liblibc-rust
|
|
||||||
CC_RUSTC_OPT += --allow unused_features
|
|
||||||
RLIB = liballoc_genode
|
|
||||||
SRC_RS = lib.rs
|
|
||||||
vpath % $(REP_DIR)/src/lib/rust/$(RLIB)
|
|
||||||
|
|
||||||
CC_CXX_WARN_STRICT =
|
|
|
@ -1,5 +0,0 @@
|
||||||
LIBS = libcore-rust liballoc-rust librustc_unicode-rust
|
|
||||||
RLIB = libcollections
|
|
||||||
include $(REP_DIR)/lib/mk/rust.inc
|
|
||||||
|
|
||||||
CC_CXX_WARN_STRICT =
|
|
|
@ -1,10 +0,0 @@
|
||||||
RLIB=libcore
|
|
||||||
include $(REP_DIR)/lib/mk/rust.inc
|
|
||||||
include $(REP_DIR)/lib/import/import-libcore-rust.mk
|
|
||||||
|
|
||||||
#
|
|
||||||
# Prevent circular dependency
|
|
||||||
#
|
|
||||||
LIBS =
|
|
||||||
|
|
||||||
CC_CXX_WARN_STRICT =
|
|
|
@ -1,6 +0,0 @@
|
||||||
LIBS = libcore-rust libc
|
|
||||||
RLIB = liblibc/src
|
|
||||||
CC_RUSTC_OPT += --cfg 'target_os = "freebsd"'
|
|
||||||
include $(REP_DIR)/lib/mk/rust.inc
|
|
||||||
|
|
||||||
CC_CXX_WARN_STRICT =
|
|
|
@ -1,5 +0,0 @@
|
||||||
LIBS = libcore-rust
|
|
||||||
RLIB = librand
|
|
||||||
include $(REP_DIR)/lib/mk/rust.inc
|
|
||||||
|
|
||||||
CC_CXX_WARN_STRICT =
|
|
|
@ -1,5 +0,0 @@
|
||||||
LIBS = libcore-rust
|
|
||||||
RLIB = librustc_unicode
|
|
||||||
include $(REP_DIR)/lib/mk/rust.inc
|
|
||||||
|
|
||||||
CC_CXX_WARN_STRICT =
|
|
|
@ -1,21 +0,0 @@
|
||||||
SRC_RS = lib.rs
|
|
||||||
LIBS = libcore-rust
|
|
||||||
vpath % $(REP_DIR)/src/lib/rust/libunwind
|
|
||||||
|
|
||||||
CC_CXX_WARN_STRICT =
|
|
||||||
|
|
||||||
#
|
|
||||||
# libunwind contains the public symbol '_Unwind_Resume', which clashes with
|
|
||||||
# the symbol provided by the cxx library. The aliasing can lead to unexpected
|
|
||||||
# symbol resolutions by the dynamic linker at runtime, i.e., a C++ exception
|
|
||||||
# thrown in the libc ending up in the '_Unwind_Resume' code of libunwind-rust.
|
|
||||||
#
|
|
||||||
# This rule solves this uncertainty by making the symbol private to the
|
|
||||||
# libunwind library.
|
|
||||||
#
|
|
||||||
ifeq ($(called_from_lib_mk),yes)
|
|
||||||
$(LIB).lib.a: hide_cxx_symbols
|
|
||||||
hide_cxx_symbols: lib.o
|
|
||||||
$(VERBOSE)cp $< $<.tmp
|
|
||||||
$(VERBOSE)$(OBJCOPY) --localize-symbol=_Unwind_Resume $<.tmp $<
|
|
||||||
endif
|
|
|
@ -1,4 +0,0 @@
|
||||||
SRC_RS = lib.rs
|
|
||||||
vpath % $(call select_from_ports,rust)/src/lib/rust/src/$(RLIB)
|
|
||||||
|
|
||||||
# vi: set ft=make :
|
|
|
@ -1 +0,0 @@
|
||||||
2a52d20b9441484521c8bed10fea2302ceeab062
|
|
|
@ -1,10 +0,0 @@
|
||||||
LICENSE := MIT
|
|
||||||
VERSION := nightly
|
|
||||||
DATE := 2016-03-03
|
|
||||||
DOWNLOADS := rust.archive
|
|
||||||
|
|
||||||
URL(rust) := http://static.rust-lang.org/dist/$(DATE)/rustc-$(VERSION)-src.tar.gz
|
|
||||||
SHA(rust) := 044069447d4700f273d7f038c3ee2fac66f2ab36b987125db2108c2daa030fdd
|
|
||||||
DIR(rust) := src/lib/rust
|
|
||||||
|
|
||||||
PATCHES := src/lib/rust/freebsd.patch
|
|
|
@ -1,32 +0,0 @@
|
||||||
PORT_DIR := $(call port_dir,$(REP_DIR)/ports/rust)
|
|
||||||
|
|
||||||
PORT_LIBS := libcore liblibc liballoc libcollections librustc_unicode \
|
|
||||||
liballoc_system librand
|
|
||||||
|
|
||||||
RUST_LIBS := $(addsuffix -rust,$(PORT_LIBS)) libunwind-rust builtins-rust
|
|
||||||
|
|
||||||
MIRROR_FROM_REP_DIR := src/lib/rust-targets
|
|
||||||
|
|
||||||
content: lib/mk src/lib/rust lib/import LICENSE \
|
|
||||||
$(MIRROR_FROM_REP_DIR)
|
|
||||||
|
|
||||||
$(MIRROR_FROM_REP_DIR):
|
|
||||||
$(mirror_from_rep_dir)
|
|
||||||
|
|
||||||
src/lib/rust:
|
|
||||||
mkdir -p $@/src
|
|
||||||
cp -r $(addprefix $(PORT_DIR)/$@/src/,$(PORT_LIBS)) $@/src/
|
|
||||||
cp -r $(REP_DIR)/$@/* $@
|
|
||||||
rm -rf $@/mk/target.mk
|
|
||||||
|
|
||||||
lib/import:
|
|
||||||
mkdir -p $@
|
|
||||||
cp $(addprefix $(REP_DIR)/$@/,import-libcore-rust.mk) $@
|
|
||||||
|
|
||||||
lib/mk:
|
|
||||||
mkdir -p $@
|
|
||||||
cp $(addprefix $(REP_DIR)/$@/,$(addsuffix .mk,$(RUST_LIBS))) $@
|
|
||||||
cp $(addprefix $(REP_DIR)/$@/,rust.inc) $@
|
|
||||||
|
|
||||||
LICENSE:
|
|
||||||
cp $(PORT_DIR)/src/lib/rust/COPYRIGHT $@
|
|
|
@ -1 +0,0 @@
|
||||||
2019-08-27 27eb08a36c0cfdba84559b05285e5b4328dabdf1
|
|
|
@ -1 +0,0 @@
|
||||||
Basic test for Rust language support.
|
|
|
@ -1,5 +0,0 @@
|
||||||
_/src/init
|
|
||||||
_/src/test-rust
|
|
||||||
_/src/libc
|
|
||||||
_/src/vfs
|
|
||||||
_/src/posix
|
|
|
@ -1 +0,0 @@
|
||||||
2020-04-16 57f5f43e19b9fd3f9bfdda9bf25197de25c338ea
|
|
|
@ -1,32 +0,0 @@
|
||||||
<runtime ram="32M" caps="1000" binary="init">
|
|
||||||
|
|
||||||
<events>
|
|
||||||
<timeout meaning="failed" sec="20" />
|
|
||||||
<log meaning="succeeded">[init -> test-rust] Number from rust: 42</log>
|
|
||||||
</events>
|
|
||||||
|
|
||||||
<content>
|
|
||||||
<rom label="ld.lib.so"/>
|
|
||||||
<rom label="libc.lib.so"/>
|
|
||||||
<rom label="libm.lib.so"/>
|
|
||||||
<rom label="vfs.lib.so"/>
|
|
||||||
<rom label="posix.lib.so"/>
|
|
||||||
<rom label="test-rust"/>
|
|
||||||
</content>
|
|
||||||
|
|
||||||
<config>
|
|
||||||
<parent-provides>
|
|
||||||
<service name="LOG"/>
|
|
||||||
<service name="PD"/>
|
|
||||||
<service name="ROM"/>
|
|
||||||
<service name="CPU"/>
|
|
||||||
</parent-provides>
|
|
||||||
<default-route>
|
|
||||||
<any-service> <parent/> </any-service>
|
|
||||||
</default-route>
|
|
||||||
<default caps="100"/>
|
|
||||||
<start name="test-rust">
|
|
||||||
<resource name="RAM" quantum="10M"/>
|
|
||||||
</start>
|
|
||||||
</config>
|
|
||||||
</runtime>
|
|
|
@ -1,2 +0,0 @@
|
||||||
SRC_DIR = src/test/rust
|
|
||||||
include $(GENODE_DIR)/repos/base/recipes/src/content.inc
|
|
|
@ -1 +0,0 @@
|
||||||
2020-04-16 63a0ffdcd955755f51c6162c33df2b9f064a2bd9
|
|
|
@ -1,4 +0,0 @@
|
||||||
base
|
|
||||||
libc
|
|
||||||
rust
|
|
||||||
posix
|
|
|
@ -1,11 +0,0 @@
|
||||||
{
|
|
||||||
"llvm-target": "armv6-pc-genode-gnueabi",
|
|
||||||
"target-endian": "little",
|
|
||||||
"target-pointer-width": "32",
|
|
||||||
"arch": "arm",
|
|
||||||
"os": "genode",
|
|
||||||
"cpu": "generic",
|
|
||||||
"env": "armv6",
|
|
||||||
"no_compiler_rt": true,
|
|
||||||
"features": "+v6"
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
{
|
|
||||||
"llvm-target": "armv7-pc-genode-gnueabi",
|
|
||||||
"target-endian": "little",
|
|
||||||
"target-pointer-width": "32",
|
|
||||||
"arch": "arm",
|
|
||||||
"os": "genode",
|
|
||||||
"cpu": "generic",
|
|
||||||
"env": "armv7",
|
|
||||||
"no_compiler_rt": true,
|
|
||||||
"features": "+v7"
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
{
|
|
||||||
"pre-link-args": ["-mriscv=RV64IAMFD"],
|
|
||||||
"llvm-target": "riscv-pc-genode-elf",
|
|
||||||
"target-endian": "little",
|
|
||||||
"target-pointer-width": "64",
|
|
||||||
"arch": "riscv",
|
|
||||||
"os": "genode",
|
|
||||||
"no_compiler_rt": true
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
{
|
|
||||||
"llvm-target": "i686-pc-genode-elf",
|
|
||||||
"target-endian": "little",
|
|
||||||
"target-pointer-width": "32",
|
|
||||||
"arch": "x86",
|
|
||||||
"os": "genode",
|
|
||||||
"no_compiler_rt": true
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
{
|
|
||||||
"pre-link-args": ["-m64"],
|
|
||||||
"llvm-target": "x86_64-pc-genode-elf",
|
|
||||||
"target-endian": "little",
|
|
||||||
"target-pointer-width": "64",
|
|
||||||
"arch": "x86_64",
|
|
||||||
"os": "genode",
|
|
||||||
"no_compiler_rt": true
|
|
||||||
}
|
|
|
@ -1,46 +0,0 @@
|
||||||
#[cfg(target_env = "armv7")]
|
|
||||||
macro_rules! dmb {
|
|
||||||
() => {{
|
|
||||||
asm!("dmb");
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_env = "armv6")]
|
|
||||||
macro_rules! dmb {
|
|
||||||
() => {{
|
|
||||||
asm!("MCR p15,0,r0,c7,c10,4");
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! sync_val_compare_and_swap {
|
|
||||||
($ptr:expr, $oldval:expr, $newval:expr) => {{
|
|
||||||
unsafe {
|
|
||||||
dmb!();
|
|
||||||
let tmp = *$ptr;
|
|
||||||
dmb!();
|
|
||||||
if tmp == $oldval {
|
|
||||||
dmb!();
|
|
||||||
*$ptr = $newval;
|
|
||||||
dmb!();
|
|
||||||
}
|
|
||||||
tmp
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub extern fn __sync_val_compare_and_swap_1(ptr: *mut u8,oldval: u8,newval: u8) -> u8 {
|
|
||||||
sync_val_compare_and_swap!(ptr,oldval,newval)
|
|
||||||
}
|
|
||||||
#[no_mangle]
|
|
||||||
pub extern fn __sync_val_compare_and_swap_2(ptr: *mut u16,oldval: u16,newval: u16) -> u16 {
|
|
||||||
sync_val_compare_and_swap!(ptr,oldval,newval)
|
|
||||||
}
|
|
||||||
#[no_mangle]
|
|
||||||
pub extern fn __sync_val_compare_and_swap_4(ptr: *mut u32,oldval: u32,newval: u32) -> u32 {
|
|
||||||
sync_val_compare_and_swap!(ptr,oldval,newval)
|
|
||||||
}
|
|
||||||
#[no_mangle]
|
|
||||||
pub extern fn __sync_val_compare_and_swap_8(ptr: *mut u64,oldval: u64,newval: u64) -> u64 {
|
|
||||||
sync_val_compare_and_swap!(ptr,oldval,newval)
|
|
||||||
}
|
|
|
@ -1,5 +0,0 @@
|
||||||
#![no_std]
|
|
||||||
#![feature(asm,cfg_target_feature)]
|
|
||||||
|
|
||||||
#[cfg(target_arch = "arm")]
|
|
||||||
pub mod atomics;
|
|
|
@ -1,13 +0,0 @@
|
||||||
*** src/lib/rust/src/liblibc/src/unix/bsd/freebsdlike/freebsd/mod2.rs 2016-03-05 19:12:50.388857026 -0800
|
|
||||||
--- src/lib/rust/src/liblibc/src/unix/bsd/freebsdlike/freebsd/mod.rs 2016-03-05 19:10:14.606459559 -0800
|
|
||||||
***************
|
|
||||||
*** 81,86 ****
|
|
||||||
--- 81,88 ----
|
|
||||||
mod x86_64;
|
|
||||||
pub use self::x86_64::*;
|
|
||||||
} else {
|
|
||||||
+ mod x86;
|
|
||||||
+ pub use self::x86::*;
|
|
||||||
// ...
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,217 +0,0 @@
|
||||||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
#![crate_name = "alloc_system"]
|
|
||||||
#![crate_type = "rlib"]
|
|
||||||
#![no_std]
|
|
||||||
#![allocator]
|
|
||||||
#![cfg_attr(not(stage0), deny(warnings))]
|
|
||||||
#![unstable(feature = "alloc_system",
|
|
||||||
reason = "this library is unlikely to be stabilized in its current \
|
|
||||||
form or name",
|
|
||||||
issue = "27783")]
|
|
||||||
#![feature(allocator)]
|
|
||||||
#![feature(libc)]
|
|
||||||
#![feature(staged_api)]
|
|
||||||
|
|
||||||
extern crate libc;
|
|
||||||
|
|
||||||
// The minimum alignment guaranteed by the architecture. This value is used to
|
|
||||||
// add fast paths for low alignment values. In practice, the alignment is a
|
|
||||||
// constant at the call site and the branch will be optimized out.
|
|
||||||
//#[cfg(all(any(target_arch = "x86",
|
|
||||||
// target_arch = "arm",
|
|
||||||
// target_arch = "mips",
|
|
||||||
// target_arch = "powerpc",
|
|
||||||
// target_arch = "powerpc64",
|
|
||||||
// target_arch = "asmjs")))]
|
|
||||||
//const MIN_ALIGN: usize = 8;
|
|
||||||
//#[cfg(all(any(target_arch = "x86_64",
|
|
||||||
// target_arch = "aarch64")))]
|
|
||||||
//const MIN_ALIGN: usize = 16;
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub extern "C" fn __rust_allocate(size: usize, align: usize) -> *mut u8 {
|
|
||||||
unsafe { imp::allocate(size, align) }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub extern "C" fn __rust_deallocate(ptr: *mut u8, old_size: usize, align: usize) {
|
|
||||||
unsafe { imp::deallocate(ptr, old_size, align) }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub extern "C" fn __rust_reallocate(ptr: *mut u8,
|
|
||||||
old_size: usize,
|
|
||||||
size: usize,
|
|
||||||
align: usize)
|
|
||||||
-> *mut u8 {
|
|
||||||
unsafe { imp::reallocate(ptr, old_size, size, align) }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub extern "C" fn __rust_reallocate_inplace(ptr: *mut u8,
|
|
||||||
old_size: usize,
|
|
||||||
size: usize,
|
|
||||||
align: usize)
|
|
||||||
-> usize {
|
|
||||||
unsafe { imp::reallocate_inplace(ptr, old_size, size, align) }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub extern "C" fn __rust_usable_size(size: usize, align: usize) -> usize {
|
|
||||||
imp::usable_size(size, align)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(unix)]
|
|
||||||
mod imp {
|
|
||||||
//use core::cmp;
|
|
||||||
//use core::ptr;
|
|
||||||
use libc;
|
|
||||||
//use MIN_ALIGN;
|
|
||||||
|
|
||||||
pub unsafe fn allocate(size: usize, _align: usize) -> *mut u8 {
|
|
||||||
//if align <= MIN_ALIGN {
|
|
||||||
libc::malloc(size as libc::size_t) as *mut u8
|
|
||||||
/*} else {
|
|
||||||
let mut out = ptr::null_mut();
|
|
||||||
let ret = libc::posix_memalign(&mut out, align as libc::size_t, size as libc::size_t);
|
|
||||||
if ret != 0 {
|
|
||||||
ptr::null_mut()
|
|
||||||
} else {
|
|
||||||
out as *mut u8
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
|
|
||||||
pub unsafe fn reallocate(ptr: *mut u8, _old_size: usize, size: usize, _align: usize) -> *mut u8 {
|
|
||||||
// if align <= MIN_ALIGN {
|
|
||||||
libc::realloc(ptr as *mut libc::c_void, size as libc::size_t) as *mut u8
|
|
||||||
/*} else {
|
|
||||||
let new_ptr = allocate(size, align);
|
|
||||||
ptr::copy(ptr, new_ptr, cmp::min(size, old_size));
|
|
||||||
deallocate(ptr, old_size, align);
|
|
||||||
new_ptr
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
|
|
||||||
pub unsafe fn reallocate_inplace(_ptr: *mut u8,
|
|
||||||
old_size: usize,
|
|
||||||
_size: usize,
|
|
||||||
_align: usize)
|
|
||||||
-> usize {
|
|
||||||
old_size
|
|
||||||
}
|
|
||||||
|
|
||||||
pub unsafe fn deallocate(ptr: *mut u8, _old_size: usize, _align: usize) {
|
|
||||||
libc::free(ptr as *mut libc::c_void)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn usable_size(size: usize, _align: usize) -> usize {
|
|
||||||
size
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(windows)]
|
|
||||||
#[allow(bad_style)]
|
|
||||||
mod imp {
|
|
||||||
use MIN_ALIGN;
|
|
||||||
|
|
||||||
type LPVOID = *mut u8;
|
|
||||||
type HANDLE = LPVOID;
|
|
||||||
type SIZE_T = usize;
|
|
||||||
type DWORD = u32;
|
|
||||||
type BOOL = i32;
|
|
||||||
|
|
||||||
extern "system" {
|
|
||||||
fn GetProcessHeap() -> HANDLE;
|
|
||||||
fn HeapAlloc(hHeap: HANDLE, dwFlags: DWORD, dwBytes: SIZE_T) -> LPVOID;
|
|
||||||
fn HeapReAlloc(hHeap: HANDLE, dwFlags: DWORD, lpMem: LPVOID, dwBytes: SIZE_T) -> LPVOID;
|
|
||||||
fn HeapFree(hHeap: HANDLE, dwFlags: DWORD, lpMem: LPVOID) -> BOOL;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
struct Header(*mut u8);
|
|
||||||
|
|
||||||
const HEAP_REALLOC_IN_PLACE_ONLY: DWORD = 0x00000010;
|
|
||||||
|
|
||||||
unsafe fn get_header<'a>(ptr: *mut u8) -> &'a mut Header {
|
|
||||||
&mut *(ptr as *mut Header).offset(-1)
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe fn align_ptr(ptr: *mut u8, align: usize) -> *mut u8 {
|
|
||||||
let aligned = ptr.offset((align - (ptr as usize & (align - 1))) as isize);
|
|
||||||
*get_header(aligned) = Header(ptr);
|
|
||||||
aligned
|
|
||||||
}
|
|
||||||
|
|
||||||
pub unsafe fn allocate(size: usize, align: usize) -> *mut u8 {
|
|
||||||
if align <= MIN_ALIGN {
|
|
||||||
HeapAlloc(GetProcessHeap(), 0, size as SIZE_T) as *mut u8
|
|
||||||
} else {
|
|
||||||
let ptr = HeapAlloc(GetProcessHeap(), 0, (size + align) as SIZE_T) as *mut u8;
|
|
||||||
if ptr.is_null() {
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
align_ptr(ptr, align)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub unsafe fn reallocate(ptr: *mut u8, _old_size: usize, size: usize, align: usize) -> *mut u8 {
|
|
||||||
if align <= MIN_ALIGN {
|
|
||||||
HeapReAlloc(GetProcessHeap(), 0, ptr as LPVOID, size as SIZE_T) as *mut u8
|
|
||||||
} else {
|
|
||||||
let header = get_header(ptr);
|
|
||||||
let new = HeapReAlloc(GetProcessHeap(),
|
|
||||||
0,
|
|
||||||
header.0 as LPVOID,
|
|
||||||
(size + align) as SIZE_T) as *mut u8;
|
|
||||||
if new.is_null() {
|
|
||||||
return new;
|
|
||||||
}
|
|
||||||
align_ptr(new, align)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub unsafe fn reallocate_inplace(ptr: *mut u8,
|
|
||||||
old_size: usize,
|
|
||||||
size: usize,
|
|
||||||
align: usize)
|
|
||||||
-> usize {
|
|
||||||
if align <= MIN_ALIGN {
|
|
||||||
let new = HeapReAlloc(GetProcessHeap(),
|
|
||||||
HEAP_REALLOC_IN_PLACE_ONLY,
|
|
||||||
ptr as LPVOID,
|
|
||||||
size as SIZE_T) as *mut u8;
|
|
||||||
if new.is_null() {
|
|
||||||
old_size
|
|
||||||
} else {
|
|
||||||
size
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
old_size
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub unsafe fn deallocate(ptr: *mut u8, _old_size: usize, align: usize) {
|
|
||||||
if align <= MIN_ALIGN {
|
|
||||||
let err = HeapFree(GetProcessHeap(), 0, ptr as LPVOID);
|
|
||||||
debug_assert!(err != 0);
|
|
||||||
} else {
|
|
||||||
let header = get_header(ptr);
|
|
||||||
let err = HeapFree(GetProcessHeap(), 0, header.0 as LPVOID);
|
|
||||||
debug_assert!(err != 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn usable_size(size: usize, _align: usize) -> usize {
|
|
||||||
size
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,57 +0,0 @@
|
||||||
#![no_std]
|
|
||||||
#[no_mangle]
|
|
||||||
pub extern fn rust_begin_unwind(_args: ::core::fmt::Arguments, _file: &str, _line: usize) -> !
|
|
||||||
{
|
|
||||||
loop {}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#[allow(non_camel_case_types)]
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Clone,Copy)]
|
|
||||||
pub enum _Unwind_Reason_Code
|
|
||||||
{
|
|
||||||
_URC_NO_REASON = 0,
|
|
||||||
_URC_FOREIGN_EXCEPTION_CAUGHT = 1,
|
|
||||||
_URC_FATAL_PHASE2_ERROR = 2,
|
|
||||||
_URC_FATAL_PHASE1_ERROR = 3,
|
|
||||||
_URC_NORMAL_STOP = 4,
|
|
||||||
_URC_END_OF_STACK = 5,
|
|
||||||
_URC_HANDLER_FOUND = 6,
|
|
||||||
_URC_INSTALL_CONTEXT = 7,
|
|
||||||
_URC_CONTINUE_UNWIND = 8,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(non_camel_case_types)]
|
|
||||||
#[derive(Clone,Copy)]
|
|
||||||
pub struct _Unwind_Context;
|
|
||||||
|
|
||||||
#[allow(non_camel_case_types)]
|
|
||||||
pub type _Unwind_Action = u32;
|
|
||||||
static _UA_SEARCH_PHASE: _Unwind_Action = 1;
|
|
||||||
|
|
||||||
#[allow(non_camel_case_types)]
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Clone,Copy)]
|
|
||||||
pub struct _Unwind_Exception
|
|
||||||
{
|
|
||||||
exception_class: u64,
|
|
||||||
exception_cleanup: fn(_Unwind_Reason_Code,*const _Unwind_Exception),
|
|
||||||
private: [u64; 2],
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub extern fn rust_eh_personality(
|
|
||||||
_version: isize, _actions: _Unwind_Action, _exception_class: u64,
|
|
||||||
_exception_object: &_Unwind_Exception, _context: &_Unwind_Context
|
|
||||||
) -> _Unwind_Reason_Code
|
|
||||||
{
|
|
||||||
loop{}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
#[allow(non_snake_case)]
|
|
||||||
pub extern fn _Unwind_Resume()
|
|
||||||
{
|
|
||||||
loop{}
|
|
||||||
}
|
|
|
@ -1,24 +0,0 @@
|
||||||
#![no_std]
|
|
||||||
#![feature(lang_items,collections,alloc)]
|
|
||||||
extern crate collections;
|
|
||||||
extern crate alloc;
|
|
||||||
extern crate libc;
|
|
||||||
use alloc::boxed::Box;
|
|
||||||
extern "C"{
|
|
||||||
fn print_num(num: libc::c_int);
|
|
||||||
}
|
|
||||||
#[no_mangle]
|
|
||||||
pub fn main() -> libc::c_int{
|
|
||||||
let n = Box::new(42);
|
|
||||||
unsafe {
|
|
||||||
print_num(*n);
|
|
||||||
}
|
|
||||||
0
|
|
||||||
}
|
|
||||||
#[lang="panic_fmt"]
|
|
||||||
#[no_mangle]
|
|
||||||
pub fn panic_fmt() -> ! { loop{} }
|
|
||||||
|
|
||||||
#[lang="eh_personality"]
|
|
||||||
#[no_mangle]
|
|
||||||
pub fn eh_personality() -> ! { loop{} }
|
|
|
@ -1,4 +0,0 @@
|
||||||
#include <base/log.h>
|
|
||||||
extern "C" void print_num(int num) {
|
|
||||||
Genode::log("Number from rust: ", num);
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
TARGET = test-rust
|
|
||||||
SRC_RS = main.rs
|
|
||||||
SRC_CC = printf.cc
|
|
||||||
LIBS = libcore-rust libcollections-rust base librustc_unicode-rust \
|
|
||||||
liballoc-rust liblibc-rust liballoc_system-rust posix
|
|
||||||
|
|
||||||
CC_CXX_WARN_STRICT =
|
|
Loading…
Reference in New Issue
Block a user