Skip to content

Commit

Permalink
r-linux: recombine into one crate
Browse files Browse the repository at this point in the history
Recombine the structure into a single crate, possibly gating with
configuration features. This also pulls in all the recent changes to
the native rust inline assembly.

Signed-off-by: David Rheinsberg <david.rheinsberg@gmail.com>
  • Loading branch information
dvdhrm committed Aug 2, 2022
1 parent aaa930d commit 1d2a0bc
Show file tree
Hide file tree
Showing 25 changed files with 835 additions and 599 deletions.
27 changes: 24 additions & 3 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
LICENSE:
This project is dual-licensed under both the Apache License, Version
2.0, and the GNU Lesser General Public License, Version 2.1+.
This project is triple-licensed under the MIT License, the Apache
License, Version 2.0, and the GNU Lesser General Public License,
Version 2.1+.

AUTHORS-MIT:
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

AUTHORS-ASL:
Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -30,7 +51,7 @@ AUTHORS-LGPL:
along with this program; If not, see <http://www.gnu.org/licenses/>.

COPYRIGHT: (ordered alphabetically)
Copyright (C) 2019-2021 Red Hat, Inc.
Copyright (C) 2019-2022 Red Hat, Inc.

AUTHORS: (ordered alphabetically)
David Rheinsberg <david.rheinsberg@gmail.com>
36 changes: 29 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
[workspace]
members = [
"src/r-linux-syscall",
[package]
name = "r-linux"
version = "0.1.0"

authors = [
"David Rheinsberg <david.rheinsberg@gmail.com>",
]
categories = [
"no-std",
"os",
]
description = "Capability-based Linux Runtime"
edition = "2021"
homepage = "https://github.com/bus1/r-linux"
keywords = [
"api",
"kernel",
"linux",
"runtime",
"syscall",
]
license = "MIT OR Apache-2.0 OR LGPL-2.1-or-later"
readme = "README.md"
repository = "https://github.com/bus1/r-linux"

[profile.dev]
panic = "abort"
[features]
freestanding = []
unstable = []

[profile.release]
panic = "abort"
[[example]]
name = "freestanding-syscall"
required-features = ["freestanding"]
54 changes: 24 additions & 30 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@
BUILDDIR ?= .
SRCDIR ?= .

CARGO ?= cargo
CLANG ?= clang-11
LLD ?= lld
MKDIR ?= mkdir
OBJDUMP ?= objdump
PYTHON3 ?= python3
RST2MAN ?= rst2man
TAR ?= tar
WGET ?= wget
BIN_CARGO ?= cargo
BIN_CLANG ?= clang-11
BIN_LLD ?= lld
BIN_MKDIR ?= mkdir
BIN_OBJDUMP ?= objdump

SHELL = /bin/bash

Expand Down Expand Up @@ -52,18 +48,18 @@ help:
@echo " help: Print this usage information."

$(BUILDDIR)/:
$(MKDIR) -p "$@"
$(BIN_MKDIR) -p "$@"

$(BUILDDIR)/%/:
$(MKDIR) -p "$@"
$(BIN_MKDIR) -p "$@"

#
# Test: syscall xLTO
#
# This provides 2 test targets for the `freestanding-syscall` example of the
# `r-linux-syscall` crate. It compiles the target as freestanding binary with
# and without `xLTO` (cross-language link-time-optimization). It then verifies
# that the disassembly correctly reflects the inlined or non-inlined syscall.
# This provides 2 test targets for the `freestanding-syscall` example. It
# compiles the target as freestanding binary with and without `xLTO`
# (cross-language link-time-optimization). It then verifies that the
# disassembly correctly reflects the inlined or non-inlined syscall.
#

TEST_SYSCALL_FILTER_SYMBOLS = \
Expand All @@ -77,26 +73,25 @@ TEST_SYSCALL_FILTER_SYMBOLS = \
.PHONY: test-syscall-xlto
test-syscall-xlto: | $(BUILDDIR)/
( \
cd $(SRCDIR_ABS)/src/r-linux-syscall ; \
CC=$(CLANG) \
CC=$(BIN_CLANG) \
CFLAGS=-flto=thin \
$(CARGO) rustc \
--example="syscall-freestanding" \
--features="freestanding-example" \
$(BIN_CARGO) +nightly rustc \
--example="freestanding-syscall" \
--features="freestanding,unstable" \
--release \
--target-dir="$(BUILDDIR_ABS)/target-syscall-xlto" \
-vv \
-- \
-C "linker=$(CLANG)" \
-C "link-arg=-fuse-ld=$(LLD)" \
-C "linker=$(BIN_CLANG)" \
-C "link-arg=-fuse-ld=$(BIN_LLD)" \
-C "link-arg=-nostartfiles" \
-C "linker-plugin-lto=yes" \
)
( \
SYMS_REAL="$$( \
$(OBJDUMP) \
$(BIN_OBJDUMP) \
-d \
"$(BUILDDIR)/target-syscall-xlto/release/examples/syscall-freestanding" \
"$(BUILDDIR)/target-syscall-xlto/release/examples/freestanding-syscall" \
| $(TEST_SYSCALL_FILTER_SYMBOLS) \
)" ; \
SYMS_EXPECTED="<_start>:" ; \
Expand All @@ -108,20 +103,19 @@ test-syscall-xlto: | $(BUILDDIR)/
.PHONY: test-syscall-no-xlto
test-syscall-no-xlto: | $(BUILDDIR)/
( \
cd $(SRCDIR_ABS)/src/r-linux-syscall ; \
$(CARGO) rustc \
--example="syscall-freestanding" \
--features="freestanding-example" \
$(BIN_CARGO) +nightly rustc \
--example="freestanding-syscall" \
--features="freestanding,unstable" \
--target-dir="$(BUILDDIR_ABS)/target-syscall-no-xlto" \
-vv \
-- \
-C link-arg=-nostartfiles \
)
( \
SYMS_REAL="$$( \
$(OBJDUMP) \
$(BIN_OBJDUMP) \
-d \
"$(BUILDDIR)/target-syscall-no-xlto/debug/examples/syscall-freestanding" \
"$(BUILDDIR)/target-syscall-no-xlto/debug/examples/freestanding-syscall" \
| $(TEST_SYSCALL_FILTER_SYMBOLS) | grep "r_linux" \
)" ; \
SYMS_EXPECTED="<r_linux_asm_syscall1>:" ; \
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# r-linux - Linux Kernel API Bindings
# r-linux - Capability-based Linux Runtime

## CHANGES WITH 0.1.0:

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
r-linux
=======

Linux Kernel API Bindings
Capability-based Linux Runtime

The r-linux project provides direct access to the application programming
interfaces of the linux kernel. This includes direct unprotected accessors to
the kernel API, as well as rustified traits and functions to access the kernel
API in a safer manner.
API in a safe, capability-based way.

### Project

* **Website**: <https://github.com/bus1/r-linux/wiki>
* **Website**: <https://github.com/bus1/r-linux>
* **Bug Tracker**: <https://github.com/bus1/r-linux/issues>

### Requirements

The requirements for this project are:

* `rustc >= 1.31.0`
* `rustc >= 1.56.0`

### Build

Expand All @@ -35,5 +35,5 @@ cargo build

### License:

- **Apache-2.0** OR **LGPL-2.1-or-later**
- **MIT** OR **Apache-2.0** OR **LGPL-2.1-or-later**
- See AUTHORS file for details.
54 changes: 54 additions & 0 deletions examples/freestanding-syscall.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//! Freestanding Syscall
//!
//! This example shows a freestanding linux application with no runtime nor
//! standard library linked. It directly provides the `_start` entry-point
//! picked by the linux linker as ELF entry-point. It then simply invokes the
//! `EXIT` syscall with an exit-code of 71.
//!
//! We need to provide a panic-handler for rust-core to link successfully. For
//! simplicity we just loop in case of panic. Since no core-symbols are called,
//! anyway, this is just about linking successfully. In case you did not
//! specify `abort` as panic-strategy, we also need to provide the exception
//! handler personality routine. Similarly to the panic-handler, we also just
//! provide a dummy, since we never raise exceptions. Note that the exception
//! handler requires unstable rust, so you need to compile via nightly or
//! specify `panic-strategy = "abort"`.
//!
//! Note that our test-suite uses this example to check for cross-language
//! link-time-optimization. It uses the exported symbol-list as reference, so
//! be careful not to pull in symbols from this example other than the ones
//! already there.
//!
//! Note that this example is guarded by the `freestanding` flag, since it
//! cannot be linked with the standard runtime (crt0), as we do not provide the
//! necessary hooks. Instead, you must compile it with `-nostartfiles`. Make
//! sure to provide this when enabling the `freestanding` feature.
#![cfg_attr(feature = "unstable", feature(lang_items))]

#![no_main]
#![no_std]

use r_linux;

#[cfg(feature = "unstable")]
#[lang = "eh_personality"]
extern "C" fn eh_personality() {
loop {}
}

#[panic_handler]
fn panic_handler(_info: &core::panic::PanicInfo) -> ! {
loop {}
}

#[export_name = "_start"]
pub extern "C" fn entrypoint() -> ! {
unsafe {
r_linux::syscall::arch::native::syscall::syscall1(
r_linux::syscall::arch::native::nr::EXIT,
71,
);
}
loop {}
}
11 changes: 11 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//! Capability-based Linux Runtime
//!
//! XXX
#![no_std]

#[cfg(test)]
#[macro_use]
extern crate std;

pub mod syscall;
35 changes: 0 additions & 35 deletions src/r-linux-syscall/Cargo.toml

This file was deleted.

6 changes: 0 additions & 6 deletions src/r-linux-syscall/api.rs

This file was deleted.

Loading

0 comments on commit 1d2a0bc

Please sign in to comment.