forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a crate for missing stubs from libcore
The core library in theory has 0 dependencies, but in practice it has some in order for it to be efficient. These dependencies are in the form of the basic memory operations provided by libc traditionally, such as memset, memcmp, etc. These functions are trivial to implement and themselves have 0 dependencies. This commit adds a new crate, librlibc, which will serve the purpose of providing these dependencies. The crate is never linked to by default, but is available to be linked to by downstream consumers. Normally these functions are provided by the system libc, but in other freestanding contexts a libc may not be available. In these cases, librlibc will suffice for enabling execution with libcore. cc rust-lang#10116
- Loading branch information
1 parent
700def2
commit cc0022e
Showing
10 changed files
with
138 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Copyright 2014 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. | ||
|
||
//! A bare-metal library supplying functions rustc may lower code to | ||
//! | ||
//! This library is not intended for general use, and is superseded by a system | ||
//! libc if one is available. In a freestanding context, however, common | ||
//! functions such as memset, memcpy, etc are not implemented. This library | ||
//! provides an implementation of these functions which are either required by | ||
//! libcore or called by rustc implicitly. | ||
//! | ||
//! This library is never included by default, and must be manually included if | ||
//! necessary. It is an error to include this library when also linking with | ||
//! the system libc library. | ||
#![crate_id = "rlibc#0.11.0-pre"] | ||
#![license = "MIT/ASL2"] | ||
#![crate_type = "rlib"] | ||
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", | ||
html_favicon_url = "http://www.rust-lang.org/favicon.ico", | ||
html_root_url = "http://static.rust-lang.org/doc/master")] | ||
|
||
#![no_std] | ||
#![experimental] | ||
|
||
// This library is definining the builtin functions, so it would be a shame for | ||
// LLVM to optimize these function calls to themselves! | ||
#![no_builtins] | ||
|
||
#[cfg(test)] extern crate std; | ||
#[cfg(test)] extern crate native; | ||
|
||
// Require the offset intrinsics for LLVM to properly optimize the | ||
// implementations below. If pointer arithmetic is done through integers the | ||
// optimizations start to break down. | ||
extern "rust-intrinsic" { | ||
fn offset<T>(dst: *T, offset: int) -> *T; | ||
} | ||
|
||
#[no_mangle] | ||
pub unsafe extern "C" fn memcpy(dest: *mut u8, src: *u8, n: uint) { | ||
let mut i = 0; | ||
while i < n { | ||
*(offset(dest as *u8, i as int) as *mut u8) = *offset(src, i as int); | ||
i += 1; | ||
} | ||
} | ||
|
||
#[no_mangle] | ||
pub unsafe extern "C" fn memmove(dest: *mut u8, src: *u8, n: uint) { | ||
if src < dest as *u8 { // copy from end | ||
let mut i = n; | ||
while i != 0 { | ||
i -= 1; | ||
*(offset(dest as *u8, i as int) as *mut u8) = *offset(src, i as int); | ||
} | ||
} else { // copy from beginning | ||
let mut i = 0; | ||
while i < n { | ||
*(offset(dest as *u8, i as int) as *mut u8) = *offset(src, i as int); | ||
i += 1; | ||
} | ||
} | ||
} | ||
|
||
#[no_mangle] | ||
pub unsafe extern "C" fn memset(s: *mut u8, c: i32, n: uint) { | ||
let mut i = 0; | ||
while i < n { | ||
*(offset(s as *u8, i as int) as *mut u8) = c as u8; | ||
i += 1; | ||
} | ||
} | ||
|
||
#[no_mangle] | ||
pub unsafe extern "C" fn memcmp(s1: *u8, s2: *u8, n: uint) -> i32 { | ||
let mut i = 0; | ||
while i < n { | ||
let a = *offset(s1, i as int); | ||
let b = *offset(s2, i as int); | ||
if a != b { | ||
return (a - b) as i32 | ||
} | ||
i += 1; | ||
} | ||
return 0; | ||
} | ||
|
||
#[test] fn work_on_windows() { } // FIXME #10872 needed for a happy windows |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters