Skip to content

Commit

Permalink
libc + tlibc works for memory mapping functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinaboos committed Jan 9, 2022
1 parent fffda85 commit d0fbcd0
Show file tree
Hide file tree
Showing 19 changed files with 1,184 additions and 44 deletions.
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions applications/test_libc/Cargo.toml
@@ -0,0 +1,14 @@
[package]
authors = ["Kevin Boos <kevinaboos@gmail.com>"]
name = "test_libc"
description = "A crate for testing tlibc with the libc Rust crate ported to Theseus"
version = "0.1.0"
build = "../../build.rs"

[dependencies]
log = "0.4.8"
libc = { version = "0.2", default-features = false }


[lib]
crate-type = ["rlib"]
39 changes: 39 additions & 0 deletions applications/test_libc/src/lib.rs
@@ -0,0 +1,39 @@
//! A simple test crate for trying to build and use libc from Rust in Theseus.
//!
//! This involves a ported version of the Rust libc crate that must be built in a way
//! that uses Theseus's `tlibc` as the underlying libc implementation.

#![no_std]

use core::ptr;

use alloc::{vec::Vec, string::String};

extern crate alloc;
#[macro_use] extern crate log;
extern crate libc;


pub fn main(_args: Vec<String>) -> isize {
test_mmap();
test_printf();
0
}

fn test_mmap() {
warn!("Hello from test_mmap()");
let ret = unsafe {
libc::mmap(ptr::null_mut(), 100, 0, 0, 0, 0)
};
warn!("test_mmap: mmap returned {:?}", ret);
}


fn test_printf() {
warn!("Hello from test_printf()");
let ret = unsafe {
libc::printf(b"%d".as_ptr() as *const i8, 17);
};
warn!("test_printf: printf returned {:?}", ret);
}

4 changes: 3 additions & 1 deletion cfg/x86_64-theseus.json
@@ -1,8 +1,10 @@
{
"llvm-target": "x86_64-unknown-none-gnu",
"__use_custom_libc_sysroot": "https://stackoverflow.com/questions/41901024/how-can-i-make-my-rust-program-link-to-another-glibc",
"llvm-target": "x86_64-unknown-none-elf",
"__data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128",
"data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
"linker-flavor": "gcc",
"env": "tlibc",
"target-endian": "little",
"target-pointer-width": "64",
"target-c-int-width": "32",
Expand Down
2 changes: 1 addition & 1 deletion ports/libc
Submodule libc updated 1 files
+72 −34 src/theseus/mod.rs
1 change: 1 addition & 0 deletions tlibc/.gitignore
@@ -0,0 +1 @@
target/

0 comments on commit d0fbcd0

Please sign in to comment.