about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/at_vec.rs6
-rw-r--r--src/libcore/cleanup.rs2
-rw-r--r--src/libcore/cmath.rs189
-rw-r--r--src/libcore/f32.rs78
-rw-r--r--src/libcore/f64.rs89
-rw-r--r--src/libcore/flate.rs16
-rw-r--r--src/libcore/float.rs24
-rw-r--r--src/libcore/gc.rs8
-rw-r--r--src/libcore/io.rs193
-rw-r--r--src/libcore/libc.rs394
-rw-r--r--src/libcore/logging.rs16
-rw-r--r--src/libcore/oldcomm.rs171
-rw-r--r--src/libcore/os.rs400
-rw-r--r--src/libcore/path.rs20
-rw-r--r--src/libcore/pipes.rs88
-rw-r--r--src/libcore/private.rs31
-rw-r--r--src/libcore/ptr.rs18
-rw-r--r--src/libcore/rand.rs38
-rw-r--r--src/libcore/rt.rs21
-rw-r--r--src/libcore/run.rs273
-rw-r--r--src/libcore/stackwalk.rs10
-rw-r--r--src/libcore/sys.rs2
-rw-r--r--src/libcore/task/mod.rs12
-rw-r--r--src/libcore/vec.rs6
24 files changed, 1259 insertions, 846 deletions
diff --git a/src/libcore/at_vec.rs b/src/libcore/at_vec.rs
index d78d241d2b1..1b6ac13ceab 100644
--- a/src/libcore/at_vec.rs
+++ b/src/libcore/at_vec.rs
@@ -30,9 +30,9 @@ use vec;
 #[abi = "cdecl"]
 pub extern mod rustrt {
     #[legacy_exports];
-    fn vec_reserve_shared_actual(++t: *sys::TypeDesc,
-                                 ++v: **vec::raw::VecRepr,
-                                 ++n: libc::size_t);
+    unsafe fn vec_reserve_shared_actual(++t: *sys::TypeDesc,
+                                        ++v: **vec::raw::VecRepr,
+                                        ++n: libc::size_t);
 }
 
 #[abi = "rust-intrinsic"]
diff --git a/src/libcore/cleanup.rs b/src/libcore/cleanup.rs
index 9fd0a50a99c..92cddf77187 100644
--- a/src/libcore/cleanup.rs
+++ b/src/libcore/cleanup.rs
@@ -160,6 +160,6 @@ pub unsafe fn annihilate() {
 extern mod rustrt {
     #[legacy_exports];
     #[rust_stack]
-    /*priv*/ fn rust_get_task() -> *c_void;
+    /*priv*/ unsafe fn rust_get_task() -> *c_void;
 }
 
diff --git a/src/libcore/cmath.rs b/src/libcore/cmath.rs
index 284b1b88a3b..6341481809e 100644
--- a/src/libcore/cmath.rs
+++ b/src/libcore/cmath.rs
@@ -26,73 +26,74 @@ pub extern mod c_double_utils {
 
     // Alpabetically sorted by link_name
 
-    pure fn acos(n: c_double) -> c_double;
-    pure fn asin(n: c_double) -> c_double;
-    pure fn atan(n: c_double) -> c_double;
-    pure fn atan2(a: c_double, b: c_double) -> c_double;
-    pure fn cbrt(n: c_double) -> c_double;
-    pure fn ceil(n: c_double) -> c_double;
-    pure fn copysign(x: c_double, y: c_double) -> c_double;
-    pure fn cos(n: c_double) -> c_double;
-    pure fn cosh(n: c_double) -> c_double;
-    pure fn erf(n: c_double) -> c_double;
-    pure fn erfc(n: c_double) -> c_double;
-    pure fn exp(n: c_double) -> c_double;
-    pure fn expm1(n: c_double) -> c_double;
-    pure fn exp2(n: c_double) -> c_double;
-    #[link_name="fabs"] pure fn abs(n: c_double) -> c_double;
+    unsafe fn acos(n: c_double) -> c_double;
+    unsafe fn asin(n: c_double) -> c_double;
+    unsafe fn atan(n: c_double) -> c_double;
+    unsafe fn atan2(a: c_double, b: c_double) -> c_double;
+    unsafe fn cbrt(n: c_double) -> c_double;
+    unsafe fn ceil(n: c_double) -> c_double;
+    unsafe fn copysign(x: c_double, y: c_double) -> c_double;
+    unsafe fn cos(n: c_double) -> c_double;
+    unsafe fn cosh(n: c_double) -> c_double;
+    unsafe fn erf(n: c_double) -> c_double;
+    unsafe fn erfc(n: c_double) -> c_double;
+    unsafe fn exp(n: c_double) -> c_double;
+    unsafe fn expm1(n: c_double) -> c_double;
+    unsafe fn exp2(n: c_double) -> c_double;
+    #[link_name="fabs"] unsafe fn abs(n: c_double) -> c_double;
     // rename: for clarity and consistency with add/sub/mul/div
-    #[link_name="fdim"] pure fn abs_sub(a: c_double, b: c_double) -> c_double;
-    pure fn floor(n: c_double) -> c_double;
+    #[link_name="fdim"]
+    unsafe fn abs_sub(a: c_double, b: c_double) -> c_double;
+    unsafe fn floor(n: c_double) -> c_double;
     // rename: for clarity and consistency with add/sub/mul/div
-    #[link_name="fma"] pure fn mul_add(a: c_double, b: c_double,
+    #[link_name="fma"] unsafe fn mul_add(a: c_double, b: c_double,
                                        c: c_double) -> c_double;
-    #[link_name="fmax"] pure fn fmax(a: c_double, b: c_double) -> c_double;
-    #[link_name="fmin"] pure fn fmin(a: c_double, b: c_double) -> c_double;
-    pure fn nextafter(x: c_double, y: c_double) -> c_double;
-    pure fn frexp(n: c_double, value: &mut c_int) -> c_double;
-    pure fn hypot(x: c_double, y: c_double) -> c_double;
-    pure fn ldexp(x: c_double, n: c_int) -> c_double;
+    #[link_name="fmax"] unsafe fn fmax(a: c_double, b: c_double) -> c_double;
+    #[link_name="fmin"] unsafe fn fmin(a: c_double, b: c_double) -> c_double;
+    unsafe fn nextafter(x: c_double, y: c_double) -> c_double;
+    unsafe fn frexp(n: c_double, value: &mut c_int) -> c_double;
+    unsafe fn hypot(x: c_double, y: c_double) -> c_double;
+    unsafe fn ldexp(x: c_double, n: c_int) -> c_double;
     #[cfg(unix)]
-    #[link_name="lgamma_r"] pure fn lgamma(n: c_double,
+    #[link_name="lgamma_r"] unsafe fn lgamma(n: c_double,
                                            sign: &mut c_int) -> c_double;
     #[cfg(windows)]
-    #[link_name="__lgamma_r"] pure fn lgamma(n: c_double,
+    #[link_name="__lgamma_r"] unsafe fn lgamma(n: c_double,
                                              sign: &mut c_int) -> c_double;
     // renamed: log is a reserved keyword; ln seems more natural, too
-    #[link_name="log"] pure fn ln(n: c_double) -> c_double;
+    #[link_name="log"] unsafe fn ln(n: c_double) -> c_double;
     // renamed: "logb" /often/ is confused for log2 by beginners
-    #[link_name="logb"] pure fn log_radix(n: c_double) -> c_double;
+    #[link_name="logb"] unsafe fn log_radix(n: c_double) -> c_double;
     // renamed: to be consitent with log as ln
-    #[link_name="log1p"] pure fn ln1p(n: c_double) -> c_double;
-    pure fn log10(n: c_double) -> c_double;
-    pure fn log2(n: c_double) -> c_double;
-    #[link_name="ilogb"] pure fn ilog_radix(n: c_double) -> c_int;
-    pure fn modf(n: c_double, iptr: &mut c_double) -> c_double;
-    pure fn pow(n: c_double, e: c_double) -> c_double;
+    #[link_name="log1p"] unsafe fn ln1p(n: c_double) -> c_double;
+    unsafe fn log10(n: c_double) -> c_double;
+    unsafe fn log2(n: c_double) -> c_double;
+    #[link_name="ilogb"] unsafe fn ilog_radix(n: c_double) -> c_int;
+    unsafe fn modf(n: c_double, iptr: &mut c_double) -> c_double;
+    unsafe fn pow(n: c_double, e: c_double) -> c_double;
 // FIXME (#1379): enable when rounding modes become available
-//    pure fn rint(n: c_double) -> c_double;
-    pure fn round(n: c_double) -> c_double;
+//    unsafe fn rint(n: c_double) -> c_double;
+    unsafe fn round(n: c_double) -> c_double;
     // rename: for consistency with logradix
-    #[link_name="scalbn"] pure fn ldexp_radix(n: c_double, i: c_int) ->
+    #[link_name="scalbn"] unsafe fn ldexp_radix(n: c_double, i: c_int) ->
         c_double;
-    pure fn sin(n: c_double) -> c_double;
-    pure fn sinh(n: c_double) -> c_double;
-    pure fn sqrt(n: c_double) -> c_double;
-    pure fn tan(n: c_double) -> c_double;
-    pure fn tanh(n: c_double) -> c_double;
-    pure fn tgamma(n: c_double) -> c_double;
-    pure fn trunc(n: c_double) -> c_double;
+    unsafe fn sin(n: c_double) -> c_double;
+    unsafe fn sinh(n: c_double) -> c_double;
+    unsafe fn sqrt(n: c_double) -> c_double;
+    unsafe fn tan(n: c_double) -> c_double;
+    unsafe fn tanh(n: c_double) -> c_double;
+    unsafe fn tgamma(n: c_double) -> c_double;
+    unsafe fn trunc(n: c_double) -> c_double;
 
     // These are commonly only available for doubles
 
-    pure fn j0(n: c_double) -> c_double;
-    pure fn j1(n: c_double) -> c_double;
-    pure fn jn(i: c_int, n: c_double) -> c_double;
+    unsafe fn j0(n: c_double) -> c_double;
+    unsafe fn j1(n: c_double) -> c_double;
+    unsafe fn jn(i: c_int, n: c_double) -> c_double;
 
-    pure fn y0(n: c_double) -> c_double;
-    pure fn y1(n: c_double) -> c_double;
-    pure fn yn(i: c_int, n: c_double) -> c_double;
+    unsafe fn y0(n: c_double) -> c_double;
+    unsafe fn y1(n: c_double) -> c_double;
+    unsafe fn yn(i: c_int, n: c_double) -> c_double;
 }
 
 #[link_name = "m"]
@@ -101,64 +102,64 @@ pub extern mod c_float_utils {
 
     // Alpabetically sorted by link_name
 
-    #[link_name="acosf"] pure fn acos(n: c_float) -> c_float;
-    #[link_name="asinf"] pure fn asin(n: c_float) -> c_float;
-    #[link_name="atanf"] pure fn atan(n: c_float) -> c_float;
-    #[link_name="atan2f"] pure fn atan2(a: c_float, b: c_float) -> c_float;
-    #[link_name="cbrtf"] pure fn cbrt(n: c_float) -> c_float;
-    #[link_name="ceilf"] pure fn ceil(n: c_float) -> c_float;
-    #[link_name="copysignf"] pure fn copysign(x: c_float,
+    #[link_name="acosf"] unsafe fn acos(n: c_float) -> c_float;
+    #[link_name="asinf"] unsafe fn asin(n: c_float) -> c_float;
+    #[link_name="atanf"] unsafe fn atan(n: c_float) -> c_float;
+    #[link_name="atan2f"] unsafe fn atan2(a: c_float, b: c_float) -> c_float;
+    #[link_name="cbrtf"] unsafe fn cbrt(n: c_float) -> c_float;
+    #[link_name="ceilf"] unsafe fn ceil(n: c_float) -> c_float;
+    #[link_name="copysignf"] unsafe fn copysign(x: c_float,
                                               y: c_float) -> c_float;
-    #[link_name="cosf"] pure fn cos(n: c_float) -> c_float;
-    #[link_name="coshf"] pure fn cosh(n: c_float) -> c_float;
-    #[link_name="erff"] pure fn erf(n: c_float) -> c_float;
-    #[link_name="erfcf"] pure fn erfc(n: c_float) -> c_float;
-    #[link_name="expf"] pure fn exp(n: c_float) -> c_float;
-    #[link_name="expm1f"]pure fn expm1(n: c_float) -> c_float;
-    #[link_name="exp2f"] pure fn exp2(n: c_float) -> c_float;
-    #[link_name="fabsf"] pure fn abs(n: c_float) -> c_float;
-    #[link_name="fdimf"] pure fn abs_sub(a: c_float, b: c_float) -> c_float;
-    #[link_name="floorf"] pure fn floor(n: c_float) -> c_float;
-    #[link_name="frexpf"] pure fn frexp(n: c_float,
+    #[link_name="cosf"] unsafe fn cos(n: c_float) -> c_float;
+    #[link_name="coshf"] unsafe fn cosh(n: c_float) -> c_float;
+    #[link_name="erff"] unsafe fn erf(n: c_float) -> c_float;
+    #[link_name="erfcf"] unsafe fn erfc(n: c_float) -> c_float;
+    #[link_name="expf"] unsafe fn exp(n: c_float) -> c_float;
+    #[link_name="expm1f"]unsafe fn expm1(n: c_float) -> c_float;
+    #[link_name="exp2f"] unsafe fn exp2(n: c_float) -> c_float;
+    #[link_name="fabsf"] unsafe fn abs(n: c_float) -> c_float;
+    #[link_name="fdimf"] unsafe fn abs_sub(a: c_float, b: c_float) -> c_float;
+    #[link_name="floorf"] unsafe fn floor(n: c_float) -> c_float;
+    #[link_name="frexpf"] unsafe fn frexp(n: c_float,
                                         value: &mut c_int) -> c_float;
-    #[link_name="fmaf"] pure fn mul_add(a: c_float,
+    #[link_name="fmaf"] unsafe fn mul_add(a: c_float,
                                         b: c_float, c: c_float) -> c_float;
-    #[link_name="fmaxf"] pure fn fmax(a: c_float, b: c_float) -> c_float;
-    #[link_name="fminf"] pure fn fmin(a: c_float, b: c_float) -> c_float;
-    #[link_name="nextafterf"] pure fn nextafter(x: c_float,
+    #[link_name="fmaxf"] unsafe fn fmax(a: c_float, b: c_float) -> c_float;
+    #[link_name="fminf"] unsafe fn fmin(a: c_float, b: c_float) -> c_float;
+    #[link_name="nextafterf"] unsafe fn nextafter(x: c_float,
                                                 y: c_float) -> c_float;
-    #[link_name="hypotf"] pure fn hypot(x: c_float, y: c_float) -> c_float;
-    #[link_name="ldexpf"] pure fn ldexp(x: c_float, n: c_int) -> c_float;
+    #[link_name="hypotf"] unsafe fn hypot(x: c_float, y: c_float) -> c_float;
+    #[link_name="ldexpf"] unsafe fn ldexp(x: c_float, n: c_int) -> c_float;
 
     #[cfg(unix)]
-    #[link_name="lgammaf_r"] pure fn lgamma(n: c_float,
+    #[link_name="lgammaf_r"] unsafe fn lgamma(n: c_float,
                                             sign: &mut c_int) -> c_float;
 
     #[cfg(windows)]
-    #[link_name="__lgammaf_r"] pure fn lgamma(n: c_float,
+    #[link_name="__lgammaf_r"] unsafe fn lgamma(n: c_float,
                                               sign: &mut c_int) -> c_float;
 
-    #[link_name="logf"] pure fn ln(n: c_float) -> c_float;
-    #[link_name="logbf"] pure fn log_radix(n: c_float) -> c_float;
-    #[link_name="log1pf"] pure fn ln1p(n: c_float) -> c_float;
-    #[link_name="log2f"] pure fn log2(n: c_float) -> c_float;
-    #[link_name="log10f"] pure fn log10(n: c_float) -> c_float;
-    #[link_name="ilogbf"] pure fn ilog_radix(n: c_float) -> c_int;
-    #[link_name="modff"] pure fn modf(n: c_float,
+    #[link_name="logf"] unsafe fn ln(n: c_float) -> c_float;
+    #[link_name="logbf"] unsafe fn log_radix(n: c_float) -> c_float;
+    #[link_name="log1pf"] unsafe fn ln1p(n: c_float) -> c_float;
+    #[link_name="log2f"] unsafe fn log2(n: c_float) -> c_float;
+    #[link_name="log10f"] unsafe fn log10(n: c_float) -> c_float;
+    #[link_name="ilogbf"] unsafe fn ilog_radix(n: c_float) -> c_int;
+    #[link_name="modff"] unsafe fn modf(n: c_float,
                                       iptr: &mut c_float) -> c_float;
-    #[link_name="powf"] pure fn pow(n: c_float, e: c_float) -> c_float;
+    #[link_name="powf"] unsafe fn pow(n: c_float, e: c_float) -> c_float;
 // FIXME (#1379): enable when rounding modes become available
-//    #[link_name="rintf"] pure fn rint(n: c_float) -> c_float;
-    #[link_name="roundf"] pure fn round(n: c_float) -> c_float;
-    #[link_name="scalbnf"] pure fn ldexp_radix(n: c_float, i: c_int)
+//    #[link_name="rintf"] unsafe fn rint(n: c_float) -> c_float;
+    #[link_name="roundf"] unsafe fn round(n: c_float) -> c_float;
+    #[link_name="scalbnf"] unsafe fn ldexp_radix(n: c_float, i: c_int)
         -> c_float;
-    #[link_name="sinf"] pure fn sin(n: c_float) -> c_float;
-    #[link_name="sinhf"] pure fn sinh(n: c_float) -> c_float;
-    #[link_name="sqrtf"] pure fn sqrt(n: c_float) -> c_float;
-    #[link_name="tanf"] pure fn tan(n: c_float) -> c_float;
-    #[link_name="tanhf"] pure fn tanh(n: c_float) -> c_float;
-    #[link_name="tgammaf"] pure fn tgamma(n: c_float) -> c_float;
-    #[link_name="truncf"] pure fn trunc(n: c_float) -> c_float;
+    #[link_name="sinf"] unsafe fn sin(n: c_float) -> c_float;
+    #[link_name="sinhf"] unsafe fn sinh(n: c_float) -> c_float;
+    #[link_name="sqrtf"] unsafe fn sqrt(n: c_float) -> c_float;
+    #[link_name="tanf"] unsafe fn tan(n: c_float) -> c_float;
+    #[link_name="tanhf"] unsafe fn tanh(n: c_float) -> c_float;
+    #[link_name="tgammaf"] unsafe fn tgamma(n: c_float) -> c_float;
+    #[link_name="truncf"] unsafe fn trunc(n: c_float) -> c_float;
 }
 
 // PORT check these by running src/etc/machconsts.c for your architecture
diff --git a/src/libcore/f32.rs b/src/libcore/f32.rs
index ce90f757769..734cfc11080 100644
--- a/src/libcore/f32.rs
+++ b/src/libcore/f32.rs
@@ -14,12 +14,88 @@
 
 //! Operations and constants for `f32`
 
+use cmath;
 use cmp;
+use libc::{c_float, c_int};
 use num;
 
-pub use cmath::c_float_utils::*;
 pub use cmath::c_float_targ_consts::*;
 
+macro_rules! delegate(
+    (
+        fn $name:ident(
+            $(
+                $arg:ident : $arg_ty:ty
+            ),*
+        ) -> $rv:ty = $bound_name:path
+    ) => (
+        pub pure fn $name($( $arg : $arg_ty ),*) -> $rv {
+            unsafe {
+                $bound_name($( $arg ),*)
+            }
+        }
+    )
+)
+
+delegate!(fn acos(n: c_float) -> c_float = cmath::c_float_utils::acos)
+delegate!(fn asin(n: c_float) -> c_float = cmath::c_float_utils::asin)
+delegate!(fn atan(n: c_float) -> c_float = cmath::c_float_utils::atan)
+delegate!(fn atan2(a: c_float, b: c_float) -> c_float =
+    cmath::c_float_utils::atan2)
+delegate!(fn cbrt(n: c_float) -> c_float = cmath::c_float_utils::cbrt)
+delegate!(fn ceil(n: c_float) -> c_float = cmath::c_float_utils::ceil)
+delegate!(fn copysign(x: c_float, y: c_float) -> c_float =
+    cmath::c_float_utils::copysign)
+delegate!(fn cos(n: c_float) -> c_float = cmath::c_float_utils::cos)
+delegate!(fn cosh(n: c_float) -> c_float = cmath::c_float_utils::cosh)
+delegate!(fn erf(n: c_float) -> c_float = cmath::c_float_utils::erf)
+delegate!(fn erfc(n: c_float) -> c_float = cmath::c_float_utils::erfc)
+delegate!(fn exp(n: c_float) -> c_float = cmath::c_float_utils::exp)
+delegate!(fn expm1(n: c_float) -> c_float = cmath::c_float_utils::expm1)
+delegate!(fn exp2(n: c_float) -> c_float = cmath::c_float_utils::exp2)
+delegate!(fn abs(n: c_float) -> c_float = cmath::c_float_utils::abs)
+delegate!(fn abs_sub(a: c_float, b: c_float) -> c_float =
+    cmath::c_float_utils::abs_sub)
+delegate!(fn floor(n: c_float) -> c_float = cmath::c_float_utils::floor)
+delegate!(fn mul_add(a: c_float, b: c_float, c: c_float) -> c_float =
+    cmath::c_float_utils::mul_add)
+delegate!(fn fmax(a: c_float, b: c_float) -> c_float =
+    cmath::c_float_utils::fmax)
+delegate!(fn fmin(a: c_float, b: c_float) -> c_float =
+    cmath::c_float_utils::fmin)
+delegate!(fn nextafter(x: c_float, y: c_float) -> c_float =
+    cmath::c_float_utils::nextafter)
+delegate!(fn frexp(n: c_float, value: &mut c_int) -> c_float =
+    cmath::c_float_utils::frexp)
+delegate!(fn hypot(x: c_float, y: c_float) -> c_float =
+    cmath::c_float_utils::hypot)
+delegate!(fn ldexp(x: c_float, n: c_int) -> c_float =
+    cmath::c_float_utils::ldexp)
+delegate!(fn lgamma(n: c_float, sign: &mut c_int) -> c_float =
+    cmath::c_float_utils::lgamma)
+delegate!(fn ln(n: c_float) -> c_float = cmath::c_float_utils::ln)
+delegate!(fn log_radix(n: c_float) -> c_float =
+    cmath::c_float_utils::log_radix)
+delegate!(fn ln1p(n: c_float) -> c_float = cmath::c_float_utils::ln1p)
+delegate!(fn log10(n: c_float) -> c_float = cmath::c_float_utils::log10)
+delegate!(fn log2(n: c_float) -> c_float = cmath::c_float_utils::log2)
+delegate!(fn ilog_radix(n: c_float) -> c_int =
+    cmath::c_float_utils::ilog_radix)
+delegate!(fn modf(n: c_float, iptr: &mut c_float) -> c_float =
+    cmath::c_float_utils::modf)
+delegate!(fn pow(n: c_float, e: c_float) -> c_float =
+    cmath::c_float_utils::pow)
+delegate!(fn round(n: c_float) -> c_float = cmath::c_float_utils::round)
+delegate!(fn ldexp_radix(n: c_float, i: c_int) -> c_float =
+    cmath::c_float_utils::ldexp_radix)
+delegate!(fn sin(n: c_float) -> c_float = cmath::c_float_utils::sin)
+delegate!(fn sinh(n: c_float) -> c_float = cmath::c_float_utils::sinh)
+delegate!(fn sqrt(n: c_float) -> c_float = cmath::c_float_utils::sqrt)
+delegate!(fn tan(n: c_float) -> c_float = cmath::c_float_utils::tan)
+delegate!(fn tanh(n: c_float) -> c_float = cmath::c_float_utils::tanh)
+delegate!(fn tgamma(n: c_float) -> c_float = cmath::c_float_utils::tgamma)
+delegate!(fn trunc(n: c_float) -> c_float = cmath::c_float_utils::trunc)
+
 // These are not defined inside consts:: for consistency with
 // the integer types
 
diff --git a/src/libcore/f64.rs b/src/libcore/f64.rs
index 97d9e8e7584..e0c47b509f1 100644
--- a/src/libcore/f64.rs
+++ b/src/libcore/f64.rs
@@ -16,12 +16,95 @@
 
 use cmath;
 use cmp;
+use libc::{c_double, c_int};
 use libc;
 use num;
 
-pub use cmath::c_double_utils::*;
 pub use cmath::c_double_targ_consts::*;
 
+macro_rules! delegate(
+    (
+        fn $name:ident(
+            $(
+                $arg:ident : $arg_ty:ty
+            ),*
+        ) -> $rv:ty = $bound_name:path
+    ) => (
+        pub pure fn $name($( $arg : $arg_ty ),*) -> $rv {
+            unsafe {
+                $bound_name($( $arg ),*)
+            }
+        }
+    )
+)
+
+delegate!(fn acos(n: c_double) -> c_double = cmath::c_double_utils::acos)
+delegate!(fn asin(n: c_double) -> c_double = cmath::c_double_utils::asin)
+delegate!(fn atan(n: c_double) -> c_double = cmath::c_double_utils::atan)
+delegate!(fn atan2(a: c_double, b: c_double) -> c_double =
+    cmath::c_double_utils::atan2)
+delegate!(fn cbrt(n: c_double) -> c_double = cmath::c_double_utils::cbrt)
+delegate!(fn ceil(n: c_double) -> c_double = cmath::c_double_utils::ceil)
+delegate!(fn copysign(x: c_double, y: c_double) -> c_double =
+    cmath::c_double_utils::copysign)
+delegate!(fn cos(n: c_double) -> c_double = cmath::c_double_utils::cos)
+delegate!(fn cosh(n: c_double) -> c_double = cmath::c_double_utils::cosh)
+delegate!(fn erf(n: c_double) -> c_double = cmath::c_double_utils::erf)
+delegate!(fn erfc(n: c_double) -> c_double = cmath::c_double_utils::erfc)
+delegate!(fn exp(n: c_double) -> c_double = cmath::c_double_utils::exp)
+delegate!(fn expm1(n: c_double) -> c_double = cmath::c_double_utils::expm1)
+delegate!(fn exp2(n: c_double) -> c_double = cmath::c_double_utils::exp2)
+delegate!(fn abs(n: c_double) -> c_double = cmath::c_double_utils::abs)
+delegate!(fn abs_sub(a: c_double, b: c_double) -> c_double =
+    cmath::c_double_utils::abs_sub)
+delegate!(fn floor(n: c_double) -> c_double = cmath::c_double_utils::floor)
+delegate!(fn mul_add(a: c_double, b: c_double, c: c_double) -> c_double =
+    cmath::c_double_utils::mul_add)
+delegate!(fn fmax(a: c_double, b: c_double) -> c_double =
+    cmath::c_double_utils::fmax)
+delegate!(fn fmin(a: c_double, b: c_double) -> c_double =
+    cmath::c_double_utils::fmin)
+delegate!(fn nextafter(x: c_double, y: c_double) -> c_double =
+    cmath::c_double_utils::nextafter)
+delegate!(fn frexp(n: c_double, value: &mut c_int) -> c_double =
+    cmath::c_double_utils::frexp)
+delegate!(fn hypot(x: c_double, y: c_double) -> c_double =
+    cmath::c_double_utils::hypot)
+delegate!(fn ldexp(x: c_double, n: c_int) -> c_double =
+    cmath::c_double_utils::ldexp)
+delegate!(fn lgamma(n: c_double, sign: &mut c_int) -> c_double =
+    cmath::c_double_utils::lgamma)
+delegate!(fn ln(n: c_double) -> c_double = cmath::c_double_utils::ln)
+delegate!(fn log_radix(n: c_double) -> c_double =
+    cmath::c_double_utils::log_radix)
+delegate!(fn ln1p(n: c_double) -> c_double = cmath::c_double_utils::ln1p)
+delegate!(fn log10(n: c_double) -> c_double = cmath::c_double_utils::log10)
+delegate!(fn log2(n: c_double) -> c_double = cmath::c_double_utils::log2)
+delegate!(fn ilog_radix(n: c_double) -> c_int =
+    cmath::c_double_utils::ilog_radix)
+delegate!(fn modf(n: c_double, iptr: &mut c_double) -> c_double =
+    cmath::c_double_utils::modf)
+delegate!(fn pow(n: c_double, e: c_double) -> c_double =
+    cmath::c_double_utils::pow)
+delegate!(fn round(n: c_double) -> c_double = cmath::c_double_utils::round)
+delegate!(fn ldexp_radix(n: c_double, i: c_int) -> c_double =
+    cmath::c_double_utils::ldexp_radix)
+delegate!(fn sin(n: c_double) -> c_double = cmath::c_double_utils::sin)
+delegate!(fn sinh(n: c_double) -> c_double = cmath::c_double_utils::sinh)
+delegate!(fn sqrt(n: c_double) -> c_double = cmath::c_double_utils::sqrt)
+delegate!(fn tan(n: c_double) -> c_double = cmath::c_double_utils::tan)
+delegate!(fn tanh(n: c_double) -> c_double = cmath::c_double_utils::tanh)
+delegate!(fn tgamma(n: c_double) -> c_double = cmath::c_double_utils::tgamma)
+delegate!(fn trunc(n: c_double) -> c_double = cmath::c_double_utils::trunc)
+delegate!(fn j0(n: c_double) -> c_double = cmath::c_double_utils::j0)
+delegate!(fn j1(n: c_double) -> c_double = cmath::c_double_utils::j1)
+delegate!(fn jn(i: c_int, n: c_double) -> c_double =
+    cmath::c_double_utils::jn)
+delegate!(fn y0(n: c_double) -> c_double = cmath::c_double_utils::y0)
+delegate!(fn y1(n: c_double) -> c_double = cmath::c_double_utils::y1)
+delegate!(fn yn(i: c_int, n: c_double) -> c_double =
+    cmath::c_double_utils::yn)
+
 // FIXME (#1433): obtain these in a different way
 
 // These are not defined inside consts:: for consistency with
@@ -73,10 +156,6 @@ pub pure fn ge(x: f64, y: f64) -> bool { return x >= y; }
 
 pub pure fn gt(x: f64, y: f64) -> bool { return x > y; }
 
-pub pure fn sqrt(x: f64) -> f64 {
-    cmath::c_double_utils::sqrt(x as libc::c_double) as f64
-}
-
 /// Returns true if `x` is a positive number, including +0.0f640 and +Infinity
 pub pure fn is_positive(x: f64) -> bool
     { return x > 0.0f64 || (1.0f64/x) == infinity; }
diff --git a/src/libcore/flate.rs b/src/libcore/flate.rs
index 220b1a653af..39a3aa890df 100644
--- a/src/libcore/flate.rs
+++ b/src/libcore/flate.rs
@@ -25,15 +25,15 @@ use rand;
 use vec;
 
 extern mod rustrt {
-    fn tdefl_compress_mem_to_heap(psrc_buf: *const c_void,
-                                  src_buf_len: size_t,
-                                  pout_len: *size_t,
-                                  flags: c_int) -> *c_void;
+    unsafe fn tdefl_compress_mem_to_heap(psrc_buf: *const c_void,
+                                         src_buf_len: size_t,
+                                         pout_len: *size_t,
+                                         flags: c_int) -> *c_void;
 
-    fn tinfl_decompress_mem_to_heap(psrc_buf: *const c_void,
-                                    src_buf_len: size_t,
-                                    pout_len: *size_t,
-                                    flags: c_int) -> *c_void;
+    unsafe fn tinfl_decompress_mem_to_heap(psrc_buf: *const c_void,
+                                           src_buf_len: size_t,
+                                           pout_len: *size_t,
+                                           flags: c_int) -> *c_void;
 }
 
 const lz_none : c_int = 0x0;   // Huffman-coding only.
diff --git a/src/libcore/float.rs b/src/libcore/float.rs
index 3e521764723..92efe9c4981 100644
--- a/src/libcore/float.rs
+++ b/src/libcore/float.rs
@@ -409,12 +409,24 @@ pub pure fn is_infinite(x: float) -> bool { f64::is_infinite(x as f64) }
 pub pure fn is_finite(x: float) -> bool { f64::is_finite(x as f64) }
 pub pure fn is_NaN(x: float) -> bool { f64::is_NaN(x as f64) }
 
-pub pure fn abs(x: float) -> float { f64::abs(x as f64) as float }
-pub pure fn sqrt(x: float) -> float { f64::sqrt(x as f64) as float }
-pub pure fn atan(x: float) -> float { f64::atan(x as f64) as float }
-pub pure fn sin(x: float) -> float { f64::sin(x as f64) as float }
-pub pure fn cos(x: float) -> float { f64::cos(x as f64) as float }
-pub pure fn tan(x: float) -> float { f64::tan(x as f64) as float }
+pub pure fn abs(x: float) -> float {
+    unsafe { f64::abs(x as f64) as float }
+}
+pub pure fn sqrt(x: float) -> float {
+    unsafe { f64::sqrt(x as f64) as float }
+}
+pub pure fn atan(x: float) -> float {
+    unsafe { f64::atan(x as f64) as float }
+}
+pub pure fn sin(x: float) -> float {
+    unsafe { f64::sin(x as f64) as float }
+}
+pub pure fn cos(x: float) -> float {
+    unsafe { f64::cos(x as f64) as float }
+}
+pub pure fn tan(x: float) -> float {
+    unsafe { f64::tan(x as f64) as float }
+}
 
 #[cfg(notest)]
 impl float : Eq {
diff --git a/src/libcore/gc.rs b/src/libcore/gc.rs
index aed8ebd756f..8bb3610ffb4 100644
--- a/src/libcore/gc.rs
+++ b/src/libcore/gc.rs
@@ -61,12 +61,14 @@ struct StackSegment {
 extern mod rustrt {
     #[legacy_exports];
     #[rust_stack]
-    fn rust_call_tydesc_glue(root: *Word, tydesc: *Word, field: size_t);
+    unsafe fn rust_call_tydesc_glue(root: *Word,
+                                    tydesc: *Word,
+                                    field: size_t);
 
     #[rust_stack]
-    fn rust_gc_metadata() -> *Word;
+    unsafe fn rust_gc_metadata() -> *Word;
 
-    fn rust_get_stack_segment() -> *StackSegment;
+    unsafe fn rust_get_stack_segment() -> *StackSegment;
 }
 
 unsafe fn bump<T, U>(ptr: *T, count: uint) -> *U {
diff --git a/src/libcore/io.rs b/src/libcore/io.rs
index e0065f9c1e8..5cc1c9d583c 100644
--- a/src/libcore/io.rs
+++ b/src/libcore/io.rs
@@ -40,9 +40,9 @@ pub type fd_t = c_int;
 
 #[abi = "cdecl"]
 extern mod rustrt {
-    fn rust_get_stdin() -> *libc::FILE;
-    fn rust_get_stdout() -> *libc::FILE;
-    fn rust_get_stderr() -> *libc::FILE;
+    unsafe fn rust_get_stdin() -> *libc::FILE;
+    unsafe fn rust_get_stdout() -> *libc::FILE;
+    unsafe fn rust_get_stderr() -> *libc::FILE;
 }
 
 // Reading
@@ -420,22 +420,39 @@ fn convert_whence(whence: SeekStyle) -> i32 {
 
 impl *libc::FILE: Reader {
     fn read(&self, bytes: &[mut u8], len: uint) -> uint {
-        do vec::as_mut_buf(bytes) |buf_p, buf_len| {
-            assert buf_len >= len;
+        unsafe {
+            do vec::as_mut_buf(bytes) |buf_p, buf_len| {
+                assert buf_len >= len;
 
-            let count = libc::fread(buf_p as *mut c_void, 1u as size_t,
-                                    len as size_t, *self);
+                let count = libc::fread(buf_p as *mut c_void, 1u as size_t,
+                                        len as size_t, *self);
 
-            count as uint
+                count as uint
+            }
+        }
+    }
+    fn read_byte(&self) -> int {
+        unsafe {
+            libc::fgetc(*self) as int
+        }
+    }
+    fn eof(&self) -> bool {
+        unsafe {
+            return libc::feof(*self) != 0 as c_int;
         }
     }
-    fn read_byte(&self) -> int { return libc::fgetc(*self) as int; }
-    fn eof(&self) -> bool { return libc::feof(*self) != 0 as c_int; }
     fn seek(&self, offset: int, whence: SeekStyle) {
-        assert libc::fseek(*self, offset as c_long, convert_whence(whence))
-            == 0 as c_int;
+        unsafe {
+            assert libc::fseek(*self,
+                               offset as c_long,
+                               convert_whence(whence)) == 0 as c_int;
+        }
+    }
+    fn tell(&self) -> uint {
+        unsafe {
+            return libc::ftell(*self) as uint;
+        }
     }
-    fn tell(&self) -> uint { return libc::ftell(*self) as uint; }
 }
 
 // A forwarding impl of reader that also holds on to a resource for the
@@ -455,7 +472,11 @@ impl<T: Reader, C> {base: T, cleanup: C}: Reader {
 
 pub struct FILERes {
     f: *libc::FILE,
-    drop { libc::fclose(self.f); }
+    drop {
+        unsafe {
+            libc::fclose(self.f);
+        }
+    }
 }
 
 pub fn FILERes(f: *libc::FILE) -> FILERes {
@@ -476,18 +497,24 @@ pub fn FILE_reader(f: *libc::FILE, cleanup: bool) -> Reader {
 // top-level functions that take a reader, or a set of default methods on
 // reader (which can then be called reader)
 
-pub fn stdin() -> Reader { rustrt::rust_get_stdin() as Reader }
+pub fn stdin() -> Reader {
+    unsafe {
+        rustrt::rust_get_stdin() as Reader
+    }
+}
 
 pub fn file_reader(path: &Path) -> Result<Reader, ~str> {
-    let f = os::as_c_charp(path.to_str(), |pathbuf| {
-        os::as_c_charp("r", |modebuf|
-            libc::fopen(pathbuf, modebuf)
-        )
-    });
-    return if f as uint == 0u { result::Err(~"error opening "
-                                            + path.to_str()) }
-    else {
-        result::Ok(FILE_reader(f, true))
+    unsafe {
+        let f = os::as_c_charp(path.to_str(), |pathbuf| {
+            os::as_c_charp("r", |modebuf|
+                libc::fopen(pathbuf, modebuf)
+            )
+        });
+        return if f as uint == 0u { result::Err(~"error opening "
+                                                + path.to_str()) }
+        else {
+            result::Ok(FILE_reader(f, true))
+        }
     }
 }
 
@@ -570,25 +597,43 @@ impl<T: Writer, C> {base: T, cleanup: C}: Writer {
 
 impl *libc::FILE: Writer {
     fn write(&self, v: &[const u8]) {
-        do vec::as_const_buf(v) |vbuf, len| {
-            let nout = libc::fwrite(vbuf as *c_void, 1, len as size_t, *self);
-            if nout != len as size_t {
-                error!("error writing buffer");
-                log(error, os::last_os_error());
-                fail;
+        unsafe {
+            do vec::as_const_buf(v) |vbuf, len| {
+                let nout = libc::fwrite(vbuf as *c_void,
+                                        1,
+                                        len as size_t,
+                                        *self);
+                if nout != len as size_t {
+                    error!("error writing buffer");
+                    log(error, os::last_os_error());
+                    fail;
+                }
             }
         }
     }
     fn seek(&self, offset: int, whence: SeekStyle) {
-        assert libc::fseek(*self, offset as c_long, convert_whence(whence))
-            == 0 as c_int;
+        unsafe {
+            assert libc::fseek(*self,
+                               offset as c_long,
+                               convert_whence(whence)) == 0 as c_int;
+        }
+    }
+    fn tell(&self) -> uint {
+        unsafe {
+            libc::ftell(*self) as uint
+        }
+    }
+    fn flush(&self) -> int {
+        unsafe {
+            libc::fflush(*self) as int
+        }
     }
-    fn tell(&self) -> uint { libc::ftell(*self) as uint }
-    fn flush(&self) -> int { libc::fflush(*self) as int }
     fn get_type(&self) -> WriterType {
-        let fd = libc::fileno(*self);
-        if libc::isatty(fd) == 0 { File   }
-        else                     { Screen }
+        unsafe {
+            let fd = libc::fileno(*self);
+            if libc::isatty(fd) == 0 { File   }
+            else                     { Screen }
+        }
     }
 }
 
@@ -602,17 +647,19 @@ pub fn FILE_writer(f: *libc::FILE, cleanup: bool) -> Writer {
 
 impl fd_t: Writer {
     fn write(&self, v: &[const u8]) {
-        let mut count = 0u;
-        do vec::as_const_buf(v) |vbuf, len| {
-            while count < len {
-                let vb = ptr::const_offset(vbuf, count) as *c_void;
-                let nout = libc::write(*self, vb, len as size_t);
-                if nout < 0 as ssize_t {
-                    error!("error writing buffer");
-                    log(error, os::last_os_error());
-                    fail;
+        unsafe {
+            let mut count = 0u;
+            do vec::as_const_buf(v) |vbuf, len| {
+                while count < len {
+                    let vb = ptr::const_offset(vbuf, count) as *c_void;
+                    let nout = libc::write(*self, vb, len as size_t);
+                    if nout < 0 as ssize_t {
+                        error!("error writing buffer");
+                        log(error, os::last_os_error());
+                        fail;
+                    }
+                    count += nout as uint;
                 }
-                count += nout as uint;
             }
         }
     }
@@ -626,13 +673,19 @@ impl fd_t: Writer {
     }
     fn flush(&self) -> int { 0 }
     fn get_type(&self) -> WriterType {
-        if libc::isatty(*self) == 0 { File } else { Screen }
+        unsafe {
+            if libc::isatty(*self) == 0 { File } else { Screen }
+        }
     }
 }
 
 pub struct FdRes {
     fd: fd_t,
-    drop { libc::close(self.fd); }
+    drop {
+        unsafe {
+            libc::close(self.fd);
+        }
+    }
 }
 
 pub fn FdRes(fd: fd_t) -> FdRes {
@@ -668,9 +721,11 @@ pub fn mk_file_writer(path: &Path, flags: &[FileFlag])
           NoFlag => ()
         }
     }
-    let fd = do os::as_c_charp(path.to_str()) |pathbuf| {
-        libc::open(pathbuf, fflags,
-                   (S_IRUSR | S_IWUSR) as c_int)
+    let fd = unsafe {
+        do os::as_c_charp(path.to_str()) |pathbuf| {
+            libc::open(pathbuf, fflags,
+                       (S_IRUSR | S_IWUSR) as c_int)
+        }
     };
     if fd < (0 as c_int) {
         result::Err(fmt!("error opening %s: %s", path.to_str(),
@@ -913,14 +968,16 @@ pub fn file_writer(path: &Path, flags: &[FileFlag]) -> Result<Writer, ~str> {
 
 // FIXME: fileflags // #2004
 pub fn buffered_file_writer(path: &Path) -> Result<Writer, ~str> {
-    let f = do os::as_c_charp(path.to_str()) |pathbuf| {
-        do os::as_c_charp("w") |modebuf| {
-            libc::fopen(pathbuf, modebuf)
-        }
-    };
-    return if f as uint == 0u { result::Err(~"error opening "
-                                            + path.to_str()) }
-    else { result::Ok(FILE_writer(f, true)) }
+    unsafe {
+        let f = do os::as_c_charp(path.to_str()) |pathbuf| {
+            do os::as_c_charp("w") |modebuf| {
+                libc::fopen(pathbuf, modebuf)
+            }
+        };
+        return if f as uint == 0u { result::Err(~"error opening "
+                                                + path.to_str()) }
+        else { result::Ok(FILE_writer(f, true)) }
+    }
 }
 
 // FIXME (#2004) it would be great if this could be a const
@@ -1081,12 +1138,16 @@ pub mod fsync {
     // outer res
     pub fn FILE_res_sync(file: &FILERes, opt_level: Option<Level>,
                          blk: fn(v: Res<*libc::FILE>)) {
-        blk(move Res({
-            val: file.f, opt_level: opt_level,
-            fsync_fn: fn@(file: *libc::FILE, l: Level) -> int {
-                return os::fsync_fd(libc::fileno(file), l) as int;
-            }
-        }));
+        unsafe {
+            blk(move Res({
+                val: file.f, opt_level: opt_level,
+                fsync_fn: fn@(file: *libc::FILE, l: Level) -> int {
+                    unsafe {
+                        return os::fsync_fd(libc::fileno(file), l) as int;
+                    }
+                }
+            }));
+        }
     }
 
     // fsync fd after executing blk
diff --git a/src/libcore/libc.rs b/src/libcore/libc.rs
index c453490a261..cc9e4d1c5a9 100644
--- a/src/libcore/libc.rs
+++ b/src/libcore/libc.rs
@@ -1013,116 +1013,118 @@ pub mod funcs {
         #[nolink]
         #[abi = "cdecl"]
         pub extern mod ctype {
-            fn isalnum(c: c_int) -> c_int;
-            fn isalpha(c: c_int) -> c_int;
-            fn iscntrl(c: c_int) -> c_int;
-            fn isdigit(c: c_int) -> c_int;
-            fn isgraph(c: c_int) -> c_int;
-            fn islower(c: c_int) -> c_int;
-            fn isprint(c: c_int) -> c_int;
-            fn ispunct(c: c_int) -> c_int;
-            fn isspace(c: c_int) -> c_int;
-            fn isupper(c: c_int) -> c_int;
-            fn isxdigit(c: c_int) -> c_int;
-            fn tolower(c: c_char) -> c_char;
-            fn toupper(c: c_char) -> c_char;
+            unsafe fn isalnum(c: c_int) -> c_int;
+            unsafe fn isalpha(c: c_int) -> c_int;
+            unsafe fn iscntrl(c: c_int) -> c_int;
+            unsafe fn isdigit(c: c_int) -> c_int;
+            unsafe fn isgraph(c: c_int) -> c_int;
+            unsafe fn islower(c: c_int) -> c_int;
+            unsafe fn isprint(c: c_int) -> c_int;
+            unsafe fn ispunct(c: c_int) -> c_int;
+            unsafe fn isspace(c: c_int) -> c_int;
+            unsafe fn isupper(c: c_int) -> c_int;
+            unsafe fn isxdigit(c: c_int) -> c_int;
+            unsafe fn tolower(c: c_char) -> c_char;
+            unsafe fn toupper(c: c_char) -> c_char;
         }
 
         #[nolink]
         #[abi = "cdecl"]
         pub extern mod stdio {
-            fn fopen(filename: *c_char, mode: *c_char) -> *FILE;
-            fn freopen(filename: *c_char, mode: *c_char,
+            unsafe fn fopen(filename: *c_char, mode: *c_char) -> *FILE;
+            unsafe fn freopen(filename: *c_char, mode: *c_char,
                        file: *FILE) -> *FILE;
-            fn fflush(file: *FILE) -> c_int;
-            fn fclose(file: *FILE) -> c_int;
-            fn remove(filename: *c_char) -> c_int;
-            fn rename(oldname: *c_char, newname: *c_char) -> c_int;
-            fn tmpfile() -> *FILE;
-            fn setvbuf(stream: *FILE, buffer: *c_char,
+            unsafe fn fflush(file: *FILE) -> c_int;
+            unsafe fn fclose(file: *FILE) -> c_int;
+            unsafe fn remove(filename: *c_char) -> c_int;
+            unsafe fn rename(oldname: *c_char, newname: *c_char) -> c_int;
+            unsafe fn tmpfile() -> *FILE;
+            unsafe fn setvbuf(stream: *FILE, buffer: *c_char,
                        mode: c_int, size: size_t) -> c_int;
-            fn setbuf(stream: *FILE, buf: *c_char);
+            unsafe fn setbuf(stream: *FILE, buf: *c_char);
             // Omitted: printf and scanf variants.
-            fn fgetc(stream: *FILE) -> c_int;
-            fn fgets(buf: *mut c_char, n: c_int,
+            unsafe fn fgetc(stream: *FILE) -> c_int;
+            unsafe fn fgets(buf: *mut c_char, n: c_int,
                      stream: *FILE) -> *c_char;
-            fn fputc(c: c_int, stream: *FILE) -> c_int;
-            fn fputs(s: *c_char, stream: *FILE) -> *c_char;
+            unsafe fn fputc(c: c_int, stream: *FILE) -> c_int;
+            unsafe fn fputs(s: *c_char, stream: *FILE) -> *c_char;
             // Omitted: getc, getchar (might be macros).
 
             // Omitted: gets, so ridiculously unsafe that it should not
             // survive.
 
             // Omitted: putc, putchar (might be macros).
-            fn puts(s: *c_char) -> c_int;
-            fn ungetc(c: c_int, stream: *FILE) -> c_int;
-            fn fread(ptr: *mut c_void, size: size_t,
+            unsafe fn puts(s: *c_char) -> c_int;
+            unsafe fn ungetc(c: c_int, stream: *FILE) -> c_int;
+            unsafe fn fread(ptr: *mut c_void, size: size_t,
                      nobj: size_t, stream: *FILE) -> size_t;
-            fn fwrite(ptr: *c_void, size: size_t,
+            unsafe fn fwrite(ptr: *c_void, size: size_t,
                       nobj: size_t, stream: *FILE) -> size_t;
-            fn fseek(stream: *FILE, offset: c_long,
+            unsafe fn fseek(stream: *FILE, offset: c_long,
                      whence: c_int) -> c_int;
-            fn ftell(stream: *FILE) -> c_long;
-            fn rewind(stream: *FILE);
-            fn fgetpos(stream: *FILE, ptr: *fpos_t) -> c_int;
-            fn fsetpos(stream: *FILE, ptr: *fpos_t) -> c_int;
-            fn feof(stream: *FILE) -> c_int;
-            fn ferror(stream: *FILE) -> c_int;
-            fn perror(s: *c_char);
+            unsafe fn ftell(stream: *FILE) -> c_long;
+            unsafe fn rewind(stream: *FILE);
+            unsafe fn fgetpos(stream: *FILE, ptr: *fpos_t) -> c_int;
+            unsafe fn fsetpos(stream: *FILE, ptr: *fpos_t) -> c_int;
+            unsafe fn feof(stream: *FILE) -> c_int;
+            unsafe fn ferror(stream: *FILE) -> c_int;
+            unsafe fn perror(s: *c_char);
         }
 
 
         #[nolink]
         #[abi = "cdecl"]
         pub extern mod stdlib {
-            fn abs(i: c_int) -> c_int;
-            fn labs(i: c_long) -> c_long;
+            unsafe fn abs(i: c_int) -> c_int;
+            unsafe fn labs(i: c_long) -> c_long;
             // Omitted: div, ldiv (return pub type incomplete).
-            fn atof(s: *c_char) -> c_double;
-            fn atoi(s: *c_char) -> c_int;
-            fn strtod(s: *c_char, endp: **c_char) -> c_double;
-            fn strtol(s: *c_char, endp: **c_char, base: c_int) -> c_long;
-            fn strtoul(s: *c_char, endp: **c_char,
-                       base: c_int) -> c_ulong;
-            fn calloc(nobj: size_t, size: size_t) -> *c_void;
-            fn malloc(size: size_t) -> *c_void;
-            fn realloc(p: *c_void, size: size_t) -> *c_void;
-            fn free(p: *c_void);
-            fn abort() -> !;
-            fn exit(status: c_int) -> !;
+            unsafe fn atof(s: *c_char) -> c_double;
+            unsafe fn atoi(s: *c_char) -> c_int;
+            unsafe fn strtod(s: *c_char, endp: **c_char) -> c_double;
+            unsafe fn strtol(s: *c_char, endp: **c_char, base: c_int)
+                          -> c_long;
+            unsafe fn strtoul(s: *c_char, endp: **c_char, base: c_int)
+                           -> c_ulong;
+            unsafe fn calloc(nobj: size_t, size: size_t) -> *c_void;
+            unsafe fn malloc(size: size_t) -> *c_void;
+            unsafe fn realloc(p: *c_void, size: size_t) -> *c_void;
+            unsafe fn free(p: *c_void);
+            unsafe fn abort() -> !;
+            unsafe fn exit(status: c_int) -> !;
             // Omitted: atexit.
-            fn system(s: *c_char) -> c_int;
-            fn getenv(s: *c_char) -> *c_char;
+            unsafe fn system(s: *c_char) -> c_int;
+            unsafe fn getenv(s: *c_char) -> *c_char;
             // Omitted: bsearch, qsort
-            fn rand() -> c_int;
-            fn srand(seed: c_uint);
+            unsafe fn rand() -> c_int;
+            unsafe fn srand(seed: c_uint);
         }
 
         #[nolink]
         #[abi = "cdecl"]
         pub extern mod string {
-            fn strcpy(dst: *c_char, src: *c_char) -> *c_char;
-            fn strncpy(dst: *c_char, src: *c_char, n: size_t) -> *c_char;
-            fn strcat(s: *c_char, ct: *c_char) -> *c_char;
-            fn strncat(s: *c_char, ct: *c_char, n: size_t) -> *c_char;
-            fn strcmp(cs: *c_char, ct: *c_char) -> c_int;
-            fn strncmp(cs: *c_char, ct: *c_char, n: size_t) -> c_int;
-            fn strcoll(cs: *c_char, ct: *c_char) -> c_int;
-            fn strchr(cs: *c_char, c: c_int) -> *c_char;
-            fn strrchr(cs: *c_char, c: c_int) -> *c_char;
-            fn strspn(cs: *c_char, ct: *c_char) -> size_t;
-            fn strcspn(cs: *c_char, ct: *c_char) -> size_t;
-            fn strpbrk(cs: *c_char, ct: *c_char) -> *c_char;
-            fn strstr(cs: *c_char, ct: *c_char) -> *c_char;
-            fn strlen(cs: *c_char) -> size_t;
-            fn strerror(n: c_int) -> *c_char;
-            fn strtok(s: *c_char, t: *c_char) -> *c_char;
-            fn strxfrm(s: *c_char, ct: *c_char, n: size_t) -> size_t;
-            fn memcpy(s: *c_void, ct: *c_void, n: size_t) -> *c_void;
-            fn memmove(s: *c_void, ct: *c_void, n: size_t) -> *c_void;
-            fn memcmp(cx: *c_void, ct: *c_void, n: size_t) -> c_int;
-            fn memchr(cx: *c_void, c: c_int, n: size_t) -> *c_void;
-            fn memset(s: *c_void, c: c_int, n: size_t) -> *c_void;
+            unsafe fn strcpy(dst: *c_char, src: *c_char) -> *c_char;
+            unsafe fn strncpy(dst: *c_char, src: *c_char, n: size_t)
+                           -> *c_char;
+            unsafe fn strcat(s: *c_char, ct: *c_char) -> *c_char;
+            unsafe fn strncat(s: *c_char, ct: *c_char, n: size_t) -> *c_char;
+            unsafe fn strcmp(cs: *c_char, ct: *c_char) -> c_int;
+            unsafe fn strncmp(cs: *c_char, ct: *c_char, n: size_t) -> c_int;
+            unsafe fn strcoll(cs: *c_char, ct: *c_char) -> c_int;
+            unsafe fn strchr(cs: *c_char, c: c_int) -> *c_char;
+            unsafe fn strrchr(cs: *c_char, c: c_int) -> *c_char;
+            unsafe fn strspn(cs: *c_char, ct: *c_char) -> size_t;
+            unsafe fn strcspn(cs: *c_char, ct: *c_char) -> size_t;
+            unsafe fn strpbrk(cs: *c_char, ct: *c_char) -> *c_char;
+            unsafe fn strstr(cs: *c_char, ct: *c_char) -> *c_char;
+            unsafe fn strlen(cs: *c_char) -> size_t;
+            unsafe fn strerror(n: c_int) -> *c_char;
+            unsafe fn strtok(s: *c_char, t: *c_char) -> *c_char;
+            unsafe fn strxfrm(s: *c_char, ct: *c_char, n: size_t) -> size_t;
+            unsafe fn memcpy(s: *c_void, ct: *c_void, n: size_t) -> *c_void;
+            unsafe fn memmove(s: *c_void, ct: *c_void, n: size_t) -> *c_void;
+            unsafe fn memcmp(cx: *c_void, ct: *c_void, n: size_t) -> c_int;
+            unsafe fn memchr(cx: *c_void, c: c_int, n: size_t) -> *c_void;
+            unsafe fn memset(s: *c_void, c: c_int, n: size_t) -> *c_void;
         }
     }
 
@@ -1141,16 +1143,16 @@ pub mod funcs {
             use libc::types::os::arch::c95::{c_int, c_char};
 
             #[link_name = "_chmod"]
-            fn chmod(path: *c_char, mode: c_int) -> c_int;
+            unsafe fn chmod(path: *c_char, mode: c_int) -> c_int;
 
             #[link_name = "_mkdir"]
-            fn mkdir(path: *c_char) -> c_int;
+            unsafe fn mkdir(path: *c_char) -> c_int;
 
             #[link_name = "_fstat64"]
-            fn fstat(fildes: c_int, buf: *mut stat) -> c_int;
+            unsafe fn fstat(fildes: c_int, buf: *mut stat) -> c_int;
 
             #[link_name = "_stat64"]
-            fn stat(path: *c_char, buf: *mut stat) -> c_int;
+            unsafe fn stat(path: *c_char, buf: *mut stat) -> c_int;
         }
 
         #[nolink]
@@ -1160,16 +1162,16 @@ pub mod funcs {
             use libc::types::os::arch::c95::{c_int, c_char};
 
             #[link_name = "_popen"]
-            fn popen(command: *c_char, mode: *c_char) -> *FILE;
+            unsafe fn popen(command: *c_char, mode: *c_char) -> *FILE;
 
             #[link_name = "_pclose"]
-            fn pclose(stream: *FILE) -> c_int;
+            unsafe fn pclose(stream: *FILE) -> c_int;
 
             #[link_name = "_fdopen"]
-            fn fdopen(fd: c_int, mode: *c_char) -> *FILE;
+            unsafe fn fdopen(fd: c_int, mode: *c_char) -> *FILE;
 
             #[link_name = "_fileno"]
-            fn fileno(stream: *FILE) -> c_int;
+            unsafe fn fileno(stream: *FILE) -> c_int;
         }
 
         #[nolink]
@@ -1178,10 +1180,10 @@ pub mod funcs {
             use libc::types::os::arch::c95::{c_int, c_char};
 
             #[link_name = "_open"]
-            fn open(path: *c_char, oflag: c_int, mode: c_int) -> c_int;
+            unsafe fn open(path: *c_char, oflag: c_int, mode: c_int) -> c_int;
 
             #[link_name = "_creat"]
-            fn creat(path: *c_char, mode: c_int) -> c_int;
+            unsafe fn creat(path: *c_char, mode: c_int) -> c_int;
         }
 
         #[nolink]
@@ -1199,61 +1201,63 @@ pub mod funcs {
             use libc::types::os::arch::c99::intptr_t;
 
             #[link_name = "_access"]
-            fn access(path: *c_char, amode: c_int) -> c_int;
+            unsafe fn access(path: *c_char, amode: c_int) -> c_int;
 
             #[link_name = "_chdir"]
-            fn chdir(dir: *c_char) -> c_int;
+            unsafe fn chdir(dir: *c_char) -> c_int;
 
             #[link_name = "_close"]
-            fn close(fd: c_int) -> c_int;
+            unsafe fn close(fd: c_int) -> c_int;
 
             #[link_name = "_dup"]
-            fn dup(fd: c_int) -> c_int;
+            unsafe fn dup(fd: c_int) -> c_int;
 
             #[link_name = "_dup2"]
-            fn dup2(src: c_int, dst: c_int) -> c_int;
+            unsafe fn dup2(src: c_int, dst: c_int) -> c_int;
 
             #[link_name = "_execv"]
-            fn execv(prog: *c_char, argv: **c_char) -> intptr_t;
+            unsafe fn execv(prog: *c_char, argv: **c_char) -> intptr_t;
 
             #[link_name = "_execve"]
-            fn execve(prog: *c_char, argv: **c_char,
+            unsafe fn execve(prog: *c_char, argv: **c_char,
                       envp: **c_char) -> c_int;
 
             #[link_name = "_execvp"]
-            fn execvp(c: *c_char, argv: **c_char) -> c_int;
+            unsafe fn execvp(c: *c_char, argv: **c_char) -> c_int;
 
             #[link_name = "_execvpe"]
-            fn execvpe(c: *c_char, argv: **c_char,
+            unsafe fn execvpe(c: *c_char, argv: **c_char,
                        envp: **c_char) -> c_int;
 
             #[link_name = "_getcwd"]
-            fn getcwd(buf: *c_char, size: size_t) -> *c_char;
+            unsafe fn getcwd(buf: *c_char, size: size_t) -> *c_char;
 
             #[link_name = "_getpid"]
-            fn getpid() -> c_int;
+            unsafe fn getpid() -> c_int;
 
             #[link_name = "_isatty"]
-            fn isatty(fd: c_int) -> c_int;
+            unsafe fn isatty(fd: c_int) -> c_int;
 
             #[link_name = "_lseek"]
-            fn lseek(fd: c_int, offset: c_long, origin: c_int) -> c_long;
+            unsafe fn lseek(fd: c_int, offset: c_long, origin: c_int)
+                         -> c_long;
 
             #[link_name = "_pipe"]
-            fn pipe(fds: *mut c_int, psize: c_uint,
+            unsafe fn pipe(fds: *mut c_int, psize: c_uint,
                     textmode: c_int) -> c_int;
 
             #[link_name = "_read"]
-            fn read(fd: c_int, buf: *mut c_void, count: c_uint) -> c_int;
+            unsafe fn read(fd: c_int, buf: *mut c_void, count: c_uint)
+                        -> c_int;
 
             #[link_name = "_rmdir"]
-            fn rmdir(path: *c_char) -> c_int;
+            unsafe fn rmdir(path: *c_char) -> c_int;
 
             #[link_name = "_unlink"]
-            fn unlink(c: *c_char) -> c_int;
+            unsafe fn unlink(c: *c_char) -> c_int;
 
             #[link_name = "_write"]
-            fn write(fd: c_int, buf: *c_void, count: c_uint) -> c_int;
+            unsafe fn write(fd: c_int, buf: *c_void, count: c_uint) -> c_int;
 
         }
     }
@@ -1274,104 +1278,106 @@ pub mod funcs {
         #[nolink]
         #[abi = "cdecl"]
         pub extern mod stat_ {
-            fn chmod(path: *c_char, mode: mode_t) -> c_int;
-            fn fchmod(fd: c_int, mode: mode_t) -> c_int;
+            unsafe fn chmod(path: *c_char, mode: mode_t) -> c_int;
+            unsafe fn fchmod(fd: c_int, mode: mode_t) -> c_int;
 
             #[cfg(target_os = "linux")]
             #[cfg(target_os = "freebsd")]
-            fn fstat(fildes: c_int, buf: *mut stat) -> c_int;
+            unsafe fn fstat(fildes: c_int, buf: *mut stat) -> c_int;
 
             #[cfg(target_os = "macos")]
             #[link_name = "fstat64"]
-            fn fstat(fildes: c_int, buf: *mut stat) -> c_int;
+            unsafe fn fstat(fildes: c_int, buf: *mut stat) -> c_int;
 
-            fn mkdir(path: *c_char, mode: mode_t) -> c_int;
-            fn mkfifo(path: *c_char, mode: mode_t) -> c_int;
+            unsafe fn mkdir(path: *c_char, mode: mode_t) -> c_int;
+            unsafe fn mkfifo(path: *c_char, mode: mode_t) -> c_int;
 
             #[cfg(target_os = "linux")]
             #[cfg(target_os = "freebsd")]
-            fn stat(path: *c_char, buf: *mut stat) -> c_int;
+            unsafe fn stat(path: *c_char, buf: *mut stat) -> c_int;
 
             #[cfg(target_os = "macos")]
             #[link_name = "stat64"]
-            fn stat(path: *c_char, buf: *mut stat) -> c_int;
+            unsafe fn stat(path: *c_char, buf: *mut stat) -> c_int;
         }
 
         #[nolink]
         #[abi = "cdecl"]
         pub extern mod stdio {
-            fn popen(command: *c_char, mode: *c_char) -> *FILE;
-            fn pclose(stream: *FILE) -> c_int;
-            fn fdopen(fd: c_int, mode: *c_char) -> *FILE;
-            fn fileno(stream: *FILE) -> c_int;
+            unsafe fn popen(command: *c_char, mode: *c_char) -> *FILE;
+            unsafe fn pclose(stream: *FILE) -> c_int;
+            unsafe fn fdopen(fd: c_int, mode: *c_char) -> *FILE;
+            unsafe fn fileno(stream: *FILE) -> c_int;
         }
 
         #[nolink]
         #[abi = "cdecl"]
         pub extern mod fcntl {
-            fn open(path: *c_char, oflag: c_int, mode: c_int) -> c_int;
-            fn creat(path: *c_char, mode: mode_t) -> c_int;
-            fn fcntl(fd: c_int, cmd: c_int) -> c_int;
+            unsafe fn open(path: *c_char, oflag: c_int, mode: c_int) -> c_int;
+            unsafe fn creat(path: *c_char, mode: mode_t) -> c_int;
+            unsafe fn fcntl(fd: c_int, cmd: c_int) -> c_int;
         }
 
         #[nolink]
         #[abi = "cdecl"]
         pub extern mod dirent {
-            fn opendir(dirname: *c_char) -> *DIR;
-            fn closedir(dirp: *DIR) -> c_int;
-            fn readdir(dirp: *DIR) -> *dirent_t;
-            fn rewinddir(dirp: *DIR);
-            fn seekdir(dirp: *DIR, loc: c_long);
-            fn telldir(dirp: *DIR) -> c_long;
+            unsafe fn opendir(dirname: *c_char) -> *DIR;
+            unsafe fn closedir(dirp: *DIR) -> c_int;
+            unsafe fn readdir(dirp: *DIR) -> *dirent_t;
+            unsafe fn rewinddir(dirp: *DIR);
+            unsafe fn seekdir(dirp: *DIR, loc: c_long);
+            unsafe fn telldir(dirp: *DIR) -> c_long;
         }
 
         #[nolink]
         #[abi = "cdecl"]
         pub extern mod unistd {
-            fn access(path: *c_char, amode: c_int) -> c_int;
-            fn alarm(seconds: c_uint) -> c_uint;
-            fn chdir(dir: *c_char) -> c_int;
-            fn chown(path: *c_char, uid: uid_t, gid: gid_t) -> c_int;
-            fn close(fd: c_int) -> c_int;
-            fn dup(fd: c_int) -> c_int;
-            fn dup2(src: c_int, dst: c_int) -> c_int;
-            fn execv(prog: *c_char, argv: **c_char) -> c_int;
-            fn execve(prog: *c_char, argv: **c_char,
-                      envp: **c_char) -> c_int;
-            fn execvp(c: *c_char, argv: **c_char) -> c_int;
-            fn fork() -> pid_t;
-            fn fpathconf(filedes: c_int, name: c_int) -> c_long;
-            fn getcwd(buf: *c_char, size: size_t) -> *c_char;
-            fn getegid() -> gid_t;
-            fn geteuid() -> uid_t;
-            fn getgid() -> gid_t ;
-            fn getgroups(ngroups_max: c_int, groups: *mut gid_t) -> c_int;
-            fn getlogin() -> *c_char;
-            fn getopt(argc: c_int, argv: **c_char,
-                      optstr: *c_char) -> c_int;
-            fn getpgrp() -> pid_t;
-            fn getpid() -> pid_t;
-            fn getppid() -> pid_t;
-            fn getuid() -> uid_t;
-            fn isatty(fd: c_int) -> c_int;
-            fn link(src: *c_char, dst: *c_char) -> c_int;
-            fn lseek(fd: c_int, offset: off_t, whence: c_int) -> off_t;
-            fn pathconf(path: *c_char, name: c_int) -> c_long;
-            fn pause() -> c_int;
-            fn pipe(fds: *mut c_int) -> c_int;
-            fn read(fd: c_int, buf: *mut c_void,
+            unsafe fn access(path: *c_char, amode: c_int) -> c_int;
+            unsafe fn alarm(seconds: c_uint) -> c_uint;
+            unsafe fn chdir(dir: *c_char) -> c_int;
+            unsafe fn chown(path: *c_char, uid: uid_t, gid: gid_t) -> c_int;
+            unsafe fn close(fd: c_int) -> c_int;
+            unsafe fn dup(fd: c_int) -> c_int;
+            unsafe fn dup2(src: c_int, dst: c_int) -> c_int;
+            unsafe fn execv(prog: *c_char, argv: **c_char) -> c_int;
+            unsafe fn execve(prog: *c_char, argv: **c_char, envp: **c_char)
+                          -> c_int;
+            unsafe fn execvp(c: *c_char, argv: **c_char) -> c_int;
+            unsafe fn fork() -> pid_t;
+            unsafe fn fpathconf(filedes: c_int, name: c_int) -> c_long;
+            unsafe fn getcwd(buf: *c_char, size: size_t) -> *c_char;
+            unsafe fn getegid() -> gid_t;
+            unsafe fn geteuid() -> uid_t;
+            unsafe fn getgid() -> gid_t ;
+            unsafe fn getgroups(ngroups_max: c_int, groups: *mut gid_t)
+                             -> c_int;
+            unsafe fn getlogin() -> *c_char;
+            unsafe fn getopt(argc: c_int, argv: **c_char, optstr: *c_char)
+                          -> c_int;
+            unsafe fn getpgrp() -> pid_t;
+            unsafe fn getpid() -> pid_t;
+            unsafe fn getppid() -> pid_t;
+            unsafe fn getuid() -> uid_t;
+            unsafe fn isatty(fd: c_int) -> c_int;
+            unsafe fn link(src: *c_char, dst: *c_char) -> c_int;
+            unsafe fn lseek(fd: c_int, offset: off_t, whence: c_int) -> off_t;
+            unsafe fn pathconf(path: *c_char, name: c_int) -> c_long;
+            unsafe fn pause() -> c_int;
+            unsafe fn pipe(fds: *mut c_int) -> c_int;
+            unsafe fn read(fd: c_int, buf: *mut c_void,
                     count: size_t) -> ssize_t;
-            fn rmdir(path: *c_char) -> c_int;
-            fn setgid(gid: gid_t) -> c_int;
-            fn setpgid(pid: pid_t, pgid: pid_t) -> c_int;
-            fn setsid() -> pid_t;
-            fn setuid(uid: uid_t) -> c_int;
-            fn sleep(secs: c_uint) -> c_uint;
-            fn sysconf(name: c_int) -> c_long;
-            fn tcgetpgrp(fd: c_int) -> pid_t;
-            fn ttyname(fd: c_int) -> *c_char;
-            fn unlink(c: *c_char) -> c_int;
-            fn write(fd: c_int, buf: *c_void, count: size_t) -> ssize_t;
+            unsafe fn rmdir(path: *c_char) -> c_int;
+            unsafe fn setgid(gid: gid_t) -> c_int;
+            unsafe fn setpgid(pid: pid_t, pgid: pid_t) -> c_int;
+            unsafe fn setsid() -> pid_t;
+            unsafe fn setuid(uid: uid_t) -> c_int;
+            unsafe fn sleep(secs: c_uint) -> c_uint;
+            unsafe fn sysconf(name: c_int) -> c_long;
+            unsafe fn tcgetpgrp(fd: c_int) -> pid_t;
+            unsafe fn ttyname(fd: c_int) -> *c_char;
+            unsafe fn unlink(c: *c_char) -> c_int;
+            unsafe fn write(fd: c_int, buf: *c_void, count: size_t)
+                         -> ssize_t;
         }
     }
 
@@ -1388,36 +1394,36 @@ pub mod funcs {
         pub extern mod stat_ {
             #[cfg(target_os = "linux")]
             #[cfg(target_os = "freebsd")]
-            fn lstat(path: *c_char, buf: *mut stat) -> c_int;
+            unsafe fn lstat(path: *c_char, buf: *mut stat) -> c_int;
 
             #[cfg(target_os = "macos")]
             #[link_name = "lstat64"]
-            fn lstat(path: *c_char, buf: *mut stat) -> c_int;
+            unsafe fn lstat(path: *c_char, buf: *mut stat) -> c_int;
         }
 
         #[nolink]
         #[abi = "cdecl"]
         pub extern mod unistd {
-            fn readlink(path: *c_char, buf: *mut c_char,
+            unsafe fn readlink(path: *c_char, buf: *mut c_char,
                         bufsz: size_t) -> ssize_t;
 
-            fn fsync(fd: c_int) -> c_int;
+            unsafe fn fsync(fd: c_int) -> c_int;
 
             #[cfg(target_os = "linux")]
-            fn fdatasync(fd: c_int) -> c_int;
+            unsafe fn fdatasync(fd: c_int) -> c_int;
 
-            fn setenv(name: *c_char, val: *c_char,
+            unsafe fn setenv(name: *c_char, val: *c_char,
                       overwrite: c_int) -> c_int;
-            fn unsetenv(name: *c_char) -> c_int;
-            fn putenv(string: *c_char) -> c_int;
+            unsafe fn unsetenv(name: *c_char) -> c_int;
+            unsafe fn putenv(string: *c_char) -> c_int;
 
-            fn symlink(path1: *c_char, path2: *c_char) -> c_int;
+            unsafe fn symlink(path1: *c_char, path2: *c_char) -> c_int;
         }
 
         #[nolink]
         #[abi = "cdecl"]
         pub extern mod wait {
-            fn waitpid(pid: pid_t, status: *mut c_int,
+            unsafe fn waitpid(pid: pid_t, status: *mut c_int,
                        options: c_int) -> pid_t;
         }
     }
@@ -1453,15 +1459,15 @@ pub mod funcs {
         use libc::types::common::c95::{c_void};
         use libc::types::os::arch::c95::{c_char, c_int, c_uint, size_t};
 
-        fn sysctl(name: *c_int, namelen: c_uint,
+        unsafe fn sysctl(name: *c_int, namelen: c_uint,
                   oldp: *mut c_void, oldlenp: *mut size_t,
                   newp: *c_void, newlen: size_t) -> c_int;
 
-        fn sysctlbyname(name: *c_char,
+        unsafe fn sysctlbyname(name: *c_char,
                         oldp: *mut c_void, oldlenp: *mut size_t,
                         newp: *c_void, newlen: size_t) -> c_int;
 
-        fn sysctlnametomib(name: *c_char, mibp: *mut c_int,
+        unsafe fn sysctlnametomib(name: *c_char, mibp: *mut c_int,
                            sizep: *mut size_t) -> c_int;
     }
 
@@ -1477,7 +1483,7 @@ pub mod funcs {
     pub extern mod extra {
         use libc::types::os::arch::c95::{c_char, c_int};
 
-        fn _NSGetExecutablePath(buf: *mut c_char,
+        unsafe fn _NSGetExecutablePath(buf: *mut c_char,
                                 bufsize: *mut u32) -> c_int;
     }
 
@@ -1498,32 +1504,32 @@ pub mod funcs {
 
         #[abi = "stdcall"]
         pub extern mod kernel32 {
-            fn GetEnvironmentVariableW(n: LPCWSTR,
+            unsafe fn GetEnvironmentVariableW(n: LPCWSTR,
                                        v: LPWSTR,
                                        nsize: DWORD) -> DWORD;
-            fn SetEnvironmentVariableW(n: LPCWSTR, v: LPCWSTR) -> BOOL;
+            unsafe fn SetEnvironmentVariableW(n: LPCWSTR, v: LPCWSTR) -> BOOL;
 
-            fn GetModuleFileNameW(hModule: HMODULE,
+            unsafe fn GetModuleFileNameW(hModule: HMODULE,
                                   lpFilename: LPWSTR,
                                   nSize: DWORD) -> DWORD;
-            fn CreateDirectoryW(lpPathName: LPCWSTR,
+            unsafe fn CreateDirectoryW(lpPathName: LPCWSTR,
                                 lpSecurityAttributes:
                                 LPSECURITY_ATTRIBUTES) -> BOOL;
-            fn CopyFileW(lpExistingFileName: LPCWSTR,
+            unsafe fn CopyFileW(lpExistingFileName: LPCWSTR,
                          lpNewFileName: LPCWSTR,
                          bFailIfExists: BOOL) -> BOOL;
-            fn DeleteFileW(lpPathName: LPCWSTR) -> BOOL;
-            fn RemoveDirectoryW(lpPathName: LPCWSTR) -> BOOL;
-            fn SetCurrentDirectoryW(lpPathName: LPCWSTR) -> BOOL;
+            unsafe fn DeleteFileW(lpPathName: LPCWSTR) -> BOOL;
+            unsafe fn RemoveDirectoryW(lpPathName: LPCWSTR) -> BOOL;
+            unsafe fn SetCurrentDirectoryW(lpPathName: LPCWSTR) -> BOOL;
 
-            fn GetLastError() -> DWORD;
+            unsafe fn GetLastError() -> DWORD;
         }
 
         #[abi = "cdecl"]
         #[nolink]
         pub extern mod msvcrt {
             #[link_name = "_commit"]
-            pub fn commit(fd: c_int) -> c_int;
+            unsafe fn commit(fd: c_int) -> c_int;
         }
     }
 }
diff --git a/src/libcore/logging.rs b/src/libcore/logging.rs
index cb8f2b70886..922995a5af7 100644
--- a/src/libcore/logging.rs
+++ b/src/libcore/logging.rs
@@ -22,14 +22,18 @@ use vec;
 
 #[nolink]
 extern mod rustrt {
-    fn rust_log_console_on();
-    fn rust_log_console_off();
-    fn rust_log_str(level: u32, string: *libc::c_char, size: libc::size_t);
+    unsafe fn rust_log_console_on();
+    unsafe fn rust_log_console_off();
+    unsafe fn rust_log_str(level: u32,
+                           string: *libc::c_char,
+                           size: libc::size_t);
 }
 
 /// Turns on logging to stdout globally
 pub fn console_on() {
-    rustrt::rust_log_console_on();
+    unsafe {
+        rustrt::rust_log_console_on();
+    }
 }
 
 /**
@@ -40,7 +44,9 @@ pub fn console_on() {
  * the RUST_LOG environment variable
  */
 pub fn console_off() {
-    rustrt::rust_log_console_off();
+    unsafe {
+        rustrt::rust_log_console_off();
+    }
 }
 
 #[cfg(notest)]
diff --git a/src/libcore/oldcomm.rs b/src/libcore/oldcomm.rs
index 4425858bcff..65aaf1fe428 100644
--- a/src/libcore/oldcomm.rs
+++ b/src/libcore/oldcomm.rs
@@ -90,7 +90,9 @@ pub enum Chan<T: Owned> {
 
 /// Constructs a port
 pub fn Port<T: Owned>() -> Port<T> {
-    Port_(@PortPtr(rustrt::new_port(sys::size_of::<T>() as size_t)))
+    unsafe {
+        Port_(@PortPtr(rustrt::new_port(sys::size_of::<T>() as size_t)))
+    }
 }
 
 impl<T: Owned> Port<T> {
@@ -159,11 +161,13 @@ fn as_raw_port<T: Owned, U>(ch: Chan<T>, f: fn(*rust_port) -> U) -> U {
 
     struct PortRef {
         p: *rust_port,
-       drop {
-         if !ptr::is_null(self.p) {
-           rustrt::rust_port_drop(self.p);
-         }
-       }
+        drop {
+            unsafe {
+                if !ptr::is_null(self.p) {
+                    rustrt::rust_port_drop(self.p);
+                }
+            }
+        }
     }
 
     fn PortRef(p: *rust_port) -> PortRef {
@@ -172,15 +176,17 @@ fn as_raw_port<T: Owned, U>(ch: Chan<T>, f: fn(*rust_port) -> U) -> U {
         }
     }
 
-    let p = PortRef(rustrt::rust_port_take(*ch));
+    unsafe {
+        let p = PortRef(rustrt::rust_port_take(*ch));
 
-    if ptr::is_null(p.p) {
-        fail ~"unable to locate port for channel"
-    } else if rustrt::get_task_id() != rustrt::rust_port_task(p.p) {
-        fail ~"unable to access unowned port"
-    }
+        if ptr::is_null(p.p) {
+            fail ~"unable to locate port for channel"
+        } else if rustrt::get_task_id() != rustrt::rust_port_task(p.p) {
+            fail ~"unable to access unowned port"
+        }
 
-    f(p.p)
+        f(p.p)
+    }
 }
 
 /**
@@ -188,7 +194,9 @@ fn as_raw_port<T: Owned, U>(ch: Chan<T>, f: fn(*rust_port) -> U) -> U {
  * construct it.
  */
 pub fn Chan<T: Owned>(p: &Port<T>) -> Chan<T> {
-    Chan_(rustrt::get_port_id((**p).po))
+    unsafe {
+        Chan_(rustrt::get_port_id((**p).po))
+    }
 }
 
 /**
@@ -196,14 +204,16 @@ pub fn Chan<T: Owned>(p: &Port<T>) -> Chan<T> {
  * whereupon the caller loses access to it.
  */
 pub fn send<T: Owned>(ch: Chan<T>, data: T) {
-    let Chan_(p) = ch;
-    let data_ptr = ptr::addr_of(&data) as *();
-    let res = rustrt::rust_port_id_send(p, data_ptr);
-    if res != 0 unsafe {
-        // Data sent successfully
-        cast::forget(move data);
+    unsafe {
+        let Chan_(p) = ch;
+        let data_ptr = ptr::addr_of(&data) as *();
+        let res = rustrt::rust_port_id_send(p, data_ptr);
+        if res != 0 unsafe {
+            // Data sent successfully
+            cast::forget(move data);
+        }
+        task::yield();
     }
-    task::yield();
 }
 
 /**
@@ -226,61 +236,67 @@ fn peek_chan<T: Owned>(ch: Chan<T>) -> bool {
 
 /// Receive on a raw port pointer
 fn recv_<T: Owned>(p: *rust_port) -> T {
-    let yield = 0;
-    let yieldp = ptr::addr_of(&yield);
-    let mut res;
-    res = rusti::init::<T>();
-    rustrt::port_recv(ptr::addr_of(&res) as *uint, p, yieldp);
-
-    if yield != 0 {
-        // Data isn't available yet, so res has not been initialized.
-        task::yield();
-    } else {
-        // In the absence of compiler-generated preemption points
-        // this is a good place to yield
-        task::yield();
+    unsafe {
+        let yield = 0;
+        let yieldp = ptr::addr_of(&yield);
+        let mut res;
+        res = rusti::init::<T>();
+        rustrt::port_recv(ptr::addr_of(&res) as *uint, p, yieldp);
+
+        if yield != 0 {
+            // Data isn't available yet, so res has not been initialized.
+            task::yield();
+        } else {
+            // In the absence of compiler-generated preemption points
+            // this is a good place to yield
+            task::yield();
+        }
+        move res
     }
-    move res
 }
 
 fn peek_(p: *rust_port) -> bool {
-    // Yield here before we check to see if someone sent us a message
-    // FIXME #524, if the compiler generates yields, we don't need this
-    task::yield();
-    rustrt::rust_port_size(p) != 0 as libc::size_t
+    unsafe {
+        // Yield here before we check to see if someone sent us a message
+        // FIXME #524, if the compiler generates yields, we don't need this
+        task::yield();
+        rustrt::rust_port_size(p) != 0 as libc::size_t
+    }
 }
 
 /// Receive on one of two ports
 pub fn select2<A: Owned, B: Owned>(p_a: Port<A>, p_b: Port<B>)
     -> Either<A, B> {
-    let ports = ~[(**p_a).po, (**p_b).po];
-    let yield = 0, yieldp = ptr::addr_of(&yield);
-
-    let mut resport: *rust_port;
-    resport = rusti::init::<*rust_port>();
-    do vec::as_imm_buf(ports) |ports, n_ports| {
-        rustrt::rust_port_select(ptr::addr_of(&resport), ports,
-                                 n_ports as size_t, yieldp);
-    }
+    unsafe {
+        let ports = ~[(**p_a).po, (**p_b).po];
+        let yield = 0, yieldp = ptr::addr_of(&yield);
+
+        let mut resport: *rust_port;
+        resport = rusti::init::<*rust_port>();
+        do vec::as_imm_buf(ports) |ports, n_ports| {
+            rustrt::rust_port_select(ptr::addr_of(&resport), ports,
+                                     n_ports as size_t, yieldp);
+        }
 
-    if yield != 0 {
-        // Wait for data
-        task::yield();
-    } else {
-        // As in recv, this is a good place to yield anyway until
-        // the compiler generates yield calls
-        task::yield();
-    }
+        if yield != 0 {
+            // Wait for data
+            task::yield();
+        } else {
+            // As in recv, this is a good place to yield anyway until
+            // the compiler generates yield calls
+            task::yield();
+        }
 
-    // Now we know the port we're supposed to receive from
-    assert resport != ptr::null();
+        // Now we know the port we're supposed to receive from
+        assert resport != ptr::null();
 
-    if resport == (**p_a).po {
-        either::Left(recv(p_a))
-    } else if resport == (**p_b).po {
-        either::Right(recv(p_b))
-    } else {
-        fail ~"unexpected result from rust_port_select";
+        if resport == (**p_a).po {
+            either::Left(recv(p_a))
+        } else if resport == (**p_b).po {
+            either::Right(recv(p_b))
+        } else {
+            fail ~"unexpected result from rust_port_select";
+        }
     }
 }
 
@@ -295,24 +311,25 @@ type port_id = int;
 
 #[abi = "cdecl"]
 extern mod rustrt {
-    fn rust_port_id_send(target_port: port_id, data: *()) -> libc::uintptr_t;
+    unsafe fn rust_port_id_send(target_port: port_id, data: *())
+                             -> libc::uintptr_t;
 
-    fn new_port(unit_sz: libc::size_t) -> *rust_port;
-    fn del_port(po: *rust_port);
-    fn rust_port_begin_detach(po: *rust_port,
+    unsafe fn new_port(unit_sz: libc::size_t) -> *rust_port;
+    unsafe fn del_port(po: *rust_port);
+    unsafe fn rust_port_begin_detach(po: *rust_port,
                               yield: *libc::uintptr_t);
-    fn rust_port_end_detach(po: *rust_port);
-    fn get_port_id(po: *rust_port) -> port_id;
-    fn rust_port_size(po: *rust_port) -> libc::size_t;
-    fn port_recv(dptr: *uint, po: *rust_port,
+    unsafe fn rust_port_end_detach(po: *rust_port);
+    unsafe fn get_port_id(po: *rust_port) -> port_id;
+    unsafe fn rust_port_size(po: *rust_port) -> libc::size_t;
+    unsafe fn port_recv(dptr: *uint, po: *rust_port,
                  yield: *libc::uintptr_t);
-    fn rust_port_select(dptr: **rust_port, ports: **rust_port,
+    unsafe fn rust_port_select(dptr: **rust_port, ports: **rust_port,
                         n_ports: libc::size_t,
                         yield: *libc::uintptr_t);
-    fn rust_port_take(port_id: port_id) -> *rust_port;
-    fn rust_port_drop(p: *rust_port);
-    fn rust_port_task(p: *rust_port) -> libc::uintptr_t;
-    fn get_task_id() -> libc::uintptr_t;
+    unsafe fn rust_port_take(port_id: port_id) -> *rust_port;
+    unsafe fn rust_port_drop(p: *rust_port);
+    unsafe fn rust_port_task(p: *rust_port) -> libc::uintptr_t;
+    unsafe fn get_task_id() -> libc::uintptr_t;
 }
 
 #[abi = "rust-intrinsic"]
diff --git a/src/libcore/os.rs b/src/libcore/os.rs
index 6429d00fbc3..3a2b606e1ea 100644
--- a/src/libcore/os.rs
+++ b/src/libcore/os.rs
@@ -47,27 +47,35 @@ use task::TaskBuilder;
 use uint;
 use vec;
 
-pub use libc::{close, fclose};
+pub use libc::fclose;
 pub use os::consts::*;
 
 // FIXME: move these to str perhaps? #2620
 
+pub fn close(fd: c_int) -> c_int {
+    unsafe {
+        libc::close(fd)
+    }
+}
+
 extern mod rustrt {
-    fn rust_get_argc() -> c_int;
-    fn rust_get_argv() -> **c_char;
-    fn rust_getcwd() -> ~str;
-    fn rust_path_is_dir(path: *libc::c_char) -> c_int;
-    fn rust_path_exists(path: *libc::c_char) -> c_int;
-    fn rust_list_files2(&&path: ~str) -> ~[~str];
-    fn rust_process_wait(handle: c_int) -> c_int;
-    fn last_os_error() -> ~str;
-    fn rust_set_exit_status(code: libc::intptr_t);
+    unsafe fn rust_get_argc() -> c_int;
+    unsafe fn rust_get_argv() -> **c_char;
+    unsafe fn rust_getcwd() -> ~str;
+    unsafe fn rust_path_is_dir(path: *libc::c_char) -> c_int;
+    unsafe fn rust_path_exists(path: *libc::c_char) -> c_int;
+    unsafe fn rust_list_files2(&&path: ~str) -> ~[~str];
+    unsafe fn rust_process_wait(handle: c_int) -> c_int;
+    unsafe fn last_os_error() -> ~str;
+    unsafe fn rust_set_exit_status(code: libc::intptr_t);
 }
 
 pub const tmpbuf_sz : uint = 1000u;
 
 pub fn getcwd() -> Path {
-    Path(rustrt::rust_getcwd())
+    unsafe {
+        Path(rustrt::rust_getcwd())
+    }
 }
 
 pub fn as_c_charp<T>(s: &str, f: fn(*c_char) -> T) -> T {
@@ -152,7 +160,7 @@ mod global_env {
     use task;
 
     extern mod rustrt {
-        fn rust_global_env_chan_ptr() -> *libc::uintptr_t;
+        unsafe fn rust_global_env_chan_ptr() -> *libc::uintptr_t;
     }
 
     enum Msg {
@@ -186,8 +194,8 @@ mod global_env {
     }
 
     fn get_global_env_chan() -> oldcomm::Chan<Msg> {
-        let global_ptr = rustrt::rust_global_env_chan_ptr();
         unsafe {
+            let global_ptr = rustrt::rust_global_env_chan_ptr();
             private::chan_from_global_ptr(global_ptr, || {
                 // FIXME (#2621): This would be a good place to use a very
                 // small foreign stack
@@ -227,23 +235,25 @@ mod global_env {
         use vec;
 
         extern mod rustrt {
-            fn rust_env_pairs() -> ~[~str];
+            unsafe fn rust_env_pairs() -> ~[~str];
         }
 
         pub fn env() -> ~[(~str,~str)] {
-            let mut pairs = ~[];
-            for vec::each(rustrt::rust_env_pairs()) |p| {
-                let vs = str::splitn_char(*p, '=', 1u);
-                assert vec::len(vs) == 2u;
-                pairs.push((copy vs[0], copy vs[1]));
+            unsafe {
+                let mut pairs = ~[];
+                for vec::each(rustrt::rust_env_pairs()) |p| {
+                    let vs = str::splitn_char(*p, '=', 1u);
+                    assert vec::len(vs) == 2u;
+                    pairs.push((copy vs[0], copy vs[1]));
+                }
+                move pairs
             }
-            move pairs
         }
 
         #[cfg(unix)]
         pub fn getenv(n: &str) -> Option<~str> {
             unsafe {
-                let s = str::as_c_str(n, libc::getenv);
+                let s = str::as_c_str(n, |s| libc::getenv(s));
                 return if ptr::null::<u8>() == cast::reinterpret_cast(&s) {
                     option::None::<~str>
                 } else {
@@ -255,10 +265,12 @@ mod global_env {
 
         #[cfg(windows)]
         pub fn getenv(n: &str) -> Option<~str> {
-            use os::win32::{as_utf16_p, fill_utf16_buf_and_decode};
-            do as_utf16_p(n) |u| {
-                do fill_utf16_buf_and_decode() |buf, sz| {
-                    libc::GetEnvironmentVariableW(u, buf, sz)
+            unsafe {
+                use os::win32::{as_utf16_p, fill_utf16_buf_and_decode};
+                do as_utf16_p(n) |u| {
+                    do fill_utf16_buf_and_decode() |buf, sz| {
+                        libc::GetEnvironmentVariableW(u, buf, sz)
+                    }
                 }
             }
         }
@@ -266,9 +278,11 @@ mod global_env {
 
         #[cfg(unix)]
         pub fn setenv(n: &str, v: &str) {
-            do str::as_c_str(n) |nbuf| {
-                do str::as_c_str(v) |vbuf| {
-                    libc::funcs::posix01::unistd::setenv(nbuf, vbuf, 1i32);
+            unsafe {
+                do str::as_c_str(n) |nbuf| {
+                    do str::as_c_str(v) |vbuf| {
+                        libc::funcs::posix01::unistd::setenv(nbuf, vbuf, 1);
+                    }
                 }
             }
         }
@@ -276,10 +290,12 @@ mod global_env {
 
         #[cfg(windows)]
         pub fn setenv(n: &str, v: &str) {
-            use os::win32::as_utf16_p;
-            do as_utf16_p(n) |nbuf| {
-                do as_utf16_p(v) |vbuf| {
-                    libc::SetEnvironmentVariableW(nbuf, vbuf);
+            unsafe {
+                use os::win32::as_utf16_p;
+                do as_utf16_p(n) |nbuf| {
+                    do as_utf16_p(v) |vbuf| {
+                        libc::SetEnvironmentVariableW(nbuf, vbuf);
+                    }
                 }
             }
         }
@@ -288,9 +304,11 @@ mod global_env {
 }
 
 pub fn fdopen(fd: c_int) -> *FILE {
-    return do as_c_charp("r") |modebuf| {
-        libc::fdopen(fd, modebuf)
-    };
+    unsafe {
+        return do as_c_charp("r") |modebuf| {
+            libc::fdopen(fd, modebuf)
+        };
+    }
 }
 
 
@@ -314,74 +332,89 @@ pub fn fsync_fd(fd: c_int, level: io::fsync::Level) -> c_int {
 
 #[cfg(target_os = "macos")]
 pub fn fsync_fd(fd: c_int, level: io::fsync::Level) -> c_int {
-    use libc::consts::os::extra::*;
-    use libc::funcs::posix88::fcntl::*;
-    use libc::funcs::posix01::unistd::*;
-    match level {
-      io::fsync::FSync => return fsync(fd),
-      _ => {
-        // According to man fnctl, the ok retval is only specified to be !=-1
-        if (fcntl(F_FULLFSYNC as c_int, fd) == -1 as c_int)
-            { return -1 as c_int; }
-        else
-            { return 0 as c_int; }
-      }
+    unsafe {
+        use libc::consts::os::extra::*;
+        use libc::funcs::posix88::fcntl::*;
+        use libc::funcs::posix01::unistd::*;
+        match level {
+          io::fsync::FSync => return fsync(fd),
+          _ => {
+            // According to man fnctl, the ok retval is only specified to be
+            // !=-1
+            if (fcntl(F_FULLFSYNC as c_int, fd) == -1 as c_int)
+                { return -1 as c_int; }
+            else
+                { return 0 as c_int; }
+          }
+        }
     }
 }
 
 #[cfg(target_os = "freebsd")]
 pub fn fsync_fd(fd: c_int, _l: io::fsync::Level) -> c_int {
-    use libc::funcs::posix01::unistd::*;
-    return fsync(fd);
+    unsafe {
+        use libc::funcs::posix01::unistd::*;
+        return fsync(fd);
+    }
 }
 
 
 #[cfg(windows)]
 pub fn waitpid(pid: pid_t) -> c_int {
-    return rustrt::rust_process_wait(pid);
+    unsafe {
+        return rustrt::rust_process_wait(pid);
+    }
 }
 
 #[cfg(unix)]
 pub fn waitpid(pid: pid_t) -> c_int {
-    use libc::funcs::posix01::wait::*;
-    let status = 0 as c_int;
+    unsafe {
+        use libc::funcs::posix01::wait::*;
+        let status = 0 as c_int;
 
-    assert (waitpid(pid, ptr::mut_addr_of(&status),
-                    0 as c_int) != (-1 as c_int));
-    return status;
+        assert (waitpid(pid, ptr::mut_addr_of(&status),
+                        0 as c_int) != (-1 as c_int));
+        return status;
+    }
 }
 
 
 #[cfg(unix)]
 pub fn pipe() -> {in: c_int, out: c_int} {
-    let fds = {mut in: 0 as c_int,
-               mut out: 0 as c_int };
-    assert (libc::pipe(ptr::mut_addr_of(&(fds.in))) == (0 as c_int));
-    return {in: fds.in, out: fds.out};
+    unsafe {
+        let fds = {mut in: 0 as c_int,
+                   mut out: 0 as c_int };
+        assert (libc::pipe(ptr::mut_addr_of(&(fds.in))) == (0 as c_int));
+        return {in: fds.in, out: fds.out};
+    }
 }
 
 
 
 #[cfg(windows)]
 pub fn pipe() -> {in: c_int, out: c_int} {
-    // Windows pipes work subtly differently than unix pipes, and their
-    // inheritance has to be handled in a different way that I do not fully
-    // understand. Here we explicitly make the pipe non-inheritable, which
-    // means to pass it to a subprocess they need to be duplicated first, as
-    // in rust_run_program.
-    let fds = { mut in: 0 as c_int,
-                mut out: 0 as c_int };
-    let res = libc::pipe(ptr::mut_addr_of(&(fds.in)),
-                         1024 as c_uint,
-                         (libc::O_BINARY | libc::O_NOINHERIT) as c_int);
-    assert (res == 0 as c_int);
-    assert (fds.in != -1 as c_int && fds.in != 0 as c_int);
-    assert (fds.out != -1 as c_int && fds.in != 0 as c_int);
-    return {in: fds.in, out: fds.out};
+    unsafe {
+        // Windows pipes work subtly differently than unix pipes, and their
+        // inheritance has to be handled in a different way that I do not
+        // fully understand. Here we explicitly make the pipe non-inheritable,
+        // which means to pass it to a subprocess they need to be duplicated
+        // first, as in rust_run_program.
+        let fds = { mut in: 0 as c_int,
+                    mut out: 0 as c_int };
+        let res = libc::pipe(ptr::mut_addr_of(&(fds.in)),
+                             1024 as c_uint,
+                             (libc::O_BINARY | libc::O_NOINHERIT) as c_int);
+        assert (res == 0 as c_int);
+        assert (fds.in != -1 as c_int && fds.in != 0 as c_int);
+        assert (fds.out != -1 as c_int && fds.in != 0 as c_int);
+        return {in: fds.in, out: fds.out};
+    }
 }
 
 fn dup2(src: c_int, dst: c_int) -> c_int {
-    libc::dup2(src, dst)
+    unsafe {
+        libc::dup2(src, dst)
+    }
 }
 
 
@@ -411,27 +444,33 @@ pub fn self_exe_path() -> Option<Path> {
 
     #[cfg(target_os = "linux")]
     fn load_self() -> Option<~str> {
-        use libc::funcs::posix01::unistd::readlink;
-        do fill_charp_buf() |buf, sz| {
-            do as_c_charp("/proc/self/exe") |proc_self_buf| {
-                readlink(proc_self_buf, buf, sz) != (-1 as ssize_t)
+        unsafe {
+            use libc::funcs::posix01::unistd::readlink;
+            do fill_charp_buf() |buf, sz| {
+                do as_c_charp("/proc/self/exe") |proc_self_buf| {
+                    readlink(proc_self_buf, buf, sz) != (-1 as ssize_t)
+                }
             }
         }
     }
 
     #[cfg(target_os = "macos")]
     fn load_self() -> Option<~str> {
-        do fill_charp_buf() |buf, sz| {
-            libc::funcs::extra::_NSGetExecutablePath(
-                buf, ptr::mut_addr_of(&(sz as u32))) == (0 as c_int)
+        unsafe {
+            do fill_charp_buf() |buf, sz| {
+                libc::funcs::extra::_NSGetExecutablePath(
+                    buf, ptr::mut_addr_of(&(sz as u32))) == (0 as c_int)
+            }
         }
     }
 
     #[cfg(windows)]
     fn load_self() -> Option<~str> {
-        use os::win32::fill_utf16_buf_and_decode;
-        do fill_utf16_buf_and_decode() |buf, sz| {
-            libc::GetModuleFileNameW(0u as libc::DWORD, buf, sz)
+        unsafe {
+            use os::win32::fill_utf16_buf_and_decode;
+            do fill_utf16_buf_and_decode() |buf, sz| {
+                libc::GetModuleFileNameW(0u as libc::DWORD, buf, sz)
+            }
         }
     }
 
@@ -555,15 +594,19 @@ pub fn walk_dir(p: &Path, f: fn(&Path) -> bool) {
 
 /// Indicates whether a path represents a directory
 pub fn path_is_dir(p: &Path) -> bool {
-    do str::as_c_str(p.to_str()) |buf| {
-        rustrt::rust_path_is_dir(buf) != 0 as c_int
+    unsafe {
+        do str::as_c_str(p.to_str()) |buf| {
+            rustrt::rust_path_is_dir(buf) != 0 as c_int
+        }
     }
 }
 
 /// Indicates whether a path exists
 pub fn path_exists(p: &Path) -> bool {
-    do str::as_c_str(p.to_str()) |buf| {
-        rustrt::rust_path_exists(buf) != 0 as c_int
+    unsafe {
+        do str::as_c_str(p.to_str()) |buf| {
+            rustrt::rust_path_exists(buf) != 0 as c_int
+        }
     }
 }
 
@@ -592,20 +635,24 @@ pub fn make_dir(p: &Path, mode: c_int) -> bool {
 
     #[cfg(windows)]
     fn mkdir(p: &Path, _mode: c_int) -> bool {
-        use os::win32::as_utf16_p;
-        // FIXME: turn mode into something useful? #2623
-        do as_utf16_p(p.to_str()) |buf| {
-            libc::CreateDirectoryW(buf, unsafe {
-                cast::reinterpret_cast(&0)
-            })
-                != (0 as libc::BOOL)
+        unsafe {
+            use os::win32::as_utf16_p;
+            // FIXME: turn mode into something useful? #2623
+            do as_utf16_p(p.to_str()) |buf| {
+                libc::CreateDirectoryW(buf, unsafe {
+                    cast::reinterpret_cast(&0)
+                })
+                    != (0 as libc::BOOL)
+            }
         }
     }
 
     #[cfg(unix)]
     fn mkdir(p: &Path, mode: c_int) -> bool {
-        do as_c_charp(p.to_str()) |c| {
-            libc::mkdir(c, mode as mode_t) == (0 as c_int)
+        unsafe {
+            do as_c_charp(p.to_str()) |c| {
+                libc::mkdir(c, mode as mode_t) == (0 as c_int)
+            }
         }
     }
 }
@@ -613,15 +660,16 @@ pub fn make_dir(p: &Path, mode: c_int) -> bool {
 /// Lists the contents of a directory
 #[allow(non_implicitly_copyable_typarams)]
 pub fn list_dir(p: &Path) -> ~[~str] {
+    unsafe {
+        #[cfg(unix)]
+        fn star(p: &Path) -> Path { copy *p }
 
-    #[cfg(unix)]
-    fn star(p: &Path) -> Path { copy *p }
-
-    #[cfg(windows)]
-    fn star(p: &Path) -> Path { p.push("*") }
+        #[cfg(windows)]
+        fn star(p: &Path) -> Path { p.push("*") }
 
-    do rustrt::rust_list_files2(star(p).to_str()).filtered |filename| {
-        *filename != ~"." && *filename != ~".."
+        do rustrt::rust_list_files2(star(p).to_str()).filtered |filename| {
+            *filename != ~"." && *filename != ~".."
+        }
     }
 }
 
@@ -640,17 +688,21 @@ pub fn remove_dir(p: &Path) -> bool {
 
     #[cfg(windows)]
     fn rmdir(p: &Path) -> bool {
-        use os::win32::as_utf16_p;
-        return do as_utf16_p(p.to_str()) |buf| {
-            libc::RemoveDirectoryW(buf) != (0 as libc::BOOL)
-        };
+        unsafe {
+            use os::win32::as_utf16_p;
+            return do as_utf16_p(p.to_str()) |buf| {
+                libc::RemoveDirectoryW(buf) != (0 as libc::BOOL)
+            };
+        }
     }
 
     #[cfg(unix)]
     fn rmdir(p: &Path) -> bool {
-        return do as_c_charp(p.to_str()) |buf| {
-            libc::rmdir(buf) == (0 as c_int)
-        };
+        unsafe {
+            return do as_c_charp(p.to_str()) |buf| {
+                libc::rmdir(buf) == (0 as c_int)
+            };
+        }
     }
 }
 
@@ -659,17 +711,21 @@ pub fn change_dir(p: &Path) -> bool {
 
     #[cfg(windows)]
     fn chdir(p: &Path) -> bool {
-        use os::win32::as_utf16_p;
-        return do as_utf16_p(p.to_str()) |buf| {
-            libc::SetCurrentDirectoryW(buf) != (0 as libc::BOOL)
-        };
+        unsafe {
+            use os::win32::as_utf16_p;
+            return do as_utf16_p(p.to_str()) |buf| {
+                libc::SetCurrentDirectoryW(buf) != (0 as libc::BOOL)
+            };
+        }
     }
 
     #[cfg(unix)]
     fn chdir(p: &Path) -> bool {
-        return do as_c_charp(p.to_str()) |buf| {
-            libc::chdir(buf) == (0 as c_int)
-        };
+        unsafe {
+            return do as_c_charp(p.to_str()) |buf| {
+                libc::chdir(buf) == (0 as c_int)
+            };
+        }
     }
 }
 
@@ -679,57 +735,61 @@ pub fn copy_file(from: &Path, to: &Path) -> bool {
 
     #[cfg(windows)]
     fn do_copy_file(from: &Path, to: &Path) -> bool {
-        use os::win32::as_utf16_p;
-        return do as_utf16_p(from.to_str()) |fromp| {
-            do as_utf16_p(to.to_str()) |top| {
-                libc::CopyFileW(fromp, top, (0 as libc::BOOL)) !=
-                    (0 as libc::BOOL)
+        unsafe {
+            use os::win32::as_utf16_p;
+            return do as_utf16_p(from.to_str()) |fromp| {
+                do as_utf16_p(to.to_str()) |top| {
+                    libc::CopyFileW(fromp, top, (0 as libc::BOOL)) !=
+                        (0 as libc::BOOL)
+                }
             }
         }
     }
 
     #[cfg(unix)]
     fn do_copy_file(from: &Path, to: &Path) -> bool {
-        let istream = do as_c_charp(from.to_str()) |fromp| {
-            do as_c_charp("rb") |modebuf| {
-                libc::fopen(fromp, modebuf)
+        unsafe {
+            let istream = do as_c_charp(from.to_str()) |fromp| {
+                do as_c_charp("rb") |modebuf| {
+                    libc::fopen(fromp, modebuf)
+                }
+            };
+            if istream as uint == 0u {
+                return false;
             }
-        };
-        if istream as uint == 0u {
-            return false;
-        }
-        let ostream = do as_c_charp(to.to_str()) |top| {
-            do as_c_charp("w+b") |modebuf| {
-                libc::fopen(top, modebuf)
+            let ostream = do as_c_charp(to.to_str()) |top| {
+                do as_c_charp("w+b") |modebuf| {
+                    libc::fopen(top, modebuf)
+                }
+            };
+            if ostream as uint == 0u {
+                fclose(istream);
+                return false;
             }
-        };
-        if ostream as uint == 0u {
-            fclose(istream);
-            return false;
-        }
-        let bufsize = 8192u;
-        let mut buf = vec::with_capacity::<u8>(bufsize);
-        let mut done = false;
-        let mut ok = true;
-        while !done {
-            do vec::as_mut_buf(buf) |b, _sz| {
-              let nread = libc::fread(b as *mut c_void, 1u as size_t,
-                                      bufsize as size_t,
-                                      istream);
-              if nread > 0 as size_t {
-                  if libc::fwrite(b as *c_void, 1u as size_t, nread,
-                                  ostream) != nread {
-                      ok = false;
+            let bufsize = 8192u;
+            let mut buf = vec::with_capacity::<u8>(bufsize);
+            let mut done = false;
+            let mut ok = true;
+            while !done {
+                do vec::as_mut_buf(buf) |b, _sz| {
+                  let nread = libc::fread(b as *mut c_void, 1u as size_t,
+                                          bufsize as size_t,
+                                          istream);
+                  if nread > 0 as size_t {
+                      if libc::fwrite(b as *c_void, 1u as size_t, nread,
+                                      ostream) != nread {
+                          ok = false;
+                          done = true;
+                      }
+                  } else {
                       done = true;
                   }
-              } else {
-                  done = true;
               }
-          }
+            }
+            fclose(istream);
+            fclose(ostream);
+            return ok;
         }
-        fclose(istream);
-        fclose(ostream);
-        return ok;
     }
 }
 
@@ -739,23 +799,29 @@ pub fn remove_file(p: &Path) -> bool {
 
     #[cfg(windows)]
     fn unlink(p: &Path) -> bool {
-        use os::win32::as_utf16_p;
-        return do as_utf16_p(p.to_str()) |buf| {
-            libc::DeleteFileW(buf) != (0 as libc::BOOL)
-        };
+        unsafe {
+            use os::win32::as_utf16_p;
+            return do as_utf16_p(p.to_str()) |buf| {
+                libc::DeleteFileW(buf) != (0 as libc::BOOL)
+            };
+        }
     }
 
     #[cfg(unix)]
     fn unlink(p: &Path) -> bool {
-        return do as_c_charp(p.to_str()) |buf| {
-            libc::unlink(buf) == (0 as c_int)
-        };
+        unsafe {
+            return do as_c_charp(p.to_str()) |buf| {
+                libc::unlink(buf) == (0 as c_int)
+            };
+        }
     }
 }
 
 /// Get a string representing the platform-dependent last error
 pub fn last_os_error() -> ~str {
-    rustrt::last_os_error()
+    unsafe {
+        rustrt::last_os_error()
+    }
 }
 
 /**
@@ -767,7 +833,9 @@ pub fn last_os_error() -> ~str {
  * ignored and the process exits with the default failure status
  */
 pub fn set_exit_status(code: int) {
-    rustrt::rust_set_exit_status(code as libc::intptr_t);
+    unsafe {
+        rustrt::rust_set_exit_status(code as libc::intptr_t);
+    }
 }
 
 unsafe fn load_argc_and_argv(argc: c_int, argv: **c_char) -> ~[~str] {
diff --git a/src/libcore/path.rs b/src/libcore/path.rs
index d1d7d00bab8..cf1188b1f35 100644
--- a/src/libcore/path.rs
+++ b/src/libcore/path.rs
@@ -243,21 +243,25 @@ mod stat {
 
 impl Path {
     fn stat(&self) -> Option<libc::stat> {
-         do str::as_c_str(self.to_str()) |buf| {
-            let mut st = stat::arch::default_stat();
-            let r = libc::stat(buf, ptr::mut_addr_of(&st));
+        unsafe {
+             do str::as_c_str(self.to_str()) |buf| {
+                let mut st = stat::arch::default_stat();
+                let r = libc::stat(buf, ptr::mut_addr_of(&st));
 
-            if r == 0 { Some(move st) } else { None }
+                if r == 0 { Some(move st) } else { None }
+            }
         }
     }
 
     #[cfg(unix)]
     fn lstat(&self) -> Option<libc::stat> {
-         do str::as_c_str(self.to_str()) |buf| {
-            let mut st = stat::arch::default_stat();
-            let r = libc::lstat(buf, ptr::mut_addr_of(&st));
+        unsafe {
+            do str::as_c_str(self.to_str()) |buf| {
+                let mut st = stat::arch::default_stat();
+                let r = libc::lstat(buf, ptr::mut_addr_of(&st));
 
-            if r == 0 { Some(move st) } else { None }
+                if r == 0 { Some(move st) } else { None }
+            }
         }
     }
 
diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs
index 1df34b271bf..db730fb52b4 100644
--- a/src/libcore/pipes.rs
+++ b/src/libcore/pipes.rs
@@ -173,7 +173,11 @@ impl PacketHeader {
 
     unsafe fn unblock() {
         let old_task = swap_task(&mut self.blocked_task, ptr::null());
-        if !old_task.is_null() { rustrt::rust_task_deref(old_task) }
+        if !old_task.is_null() {
+            unsafe {
+                rustrt::rust_task_deref(old_task)
+            }
+        }
         match swap_state_acq(&mut self.state, Empty) {
           Empty | Blocked => (),
           Terminated => self.state = Terminated,
@@ -300,27 +304,30 @@ type rust_task = libc::c_void;
 #[doc(hidden)]
 extern mod rustrt {
     #[rust_stack]
-    fn rust_get_task() -> *rust_task;
+    unsafe fn rust_get_task() -> *rust_task;
     #[rust_stack]
-    fn rust_task_ref(task: *rust_task);
-    fn rust_task_deref(task: *rust_task);
+    unsafe fn rust_task_ref(task: *rust_task);
+    unsafe fn rust_task_deref(task: *rust_task);
 
     #[rust_stack]
-    fn task_clear_event_reject(task: *rust_task);
+    unsafe fn task_clear_event_reject(task: *rust_task);
 
-    fn task_wait_event(this: *rust_task, killed: &mut *libc::c_void) -> bool;
-    pure fn task_signal_event(target: *rust_task, event: *libc::c_void);
+    unsafe fn task_wait_event(this: *rust_task, killed: &mut *libc::c_void)
+                        -> bool;
+    unsafe fn task_signal_event(target: *rust_task, event: *libc::c_void);
 }
 
 #[doc(hidden)]
 fn wait_event(this: *rust_task) -> *libc::c_void {
-    let mut event = ptr::null();
+    unsafe {
+        let mut event = ptr::null();
 
-    let killed = rustrt::task_wait_event(this, &mut event);
-    if killed && !task::failing() {
-        fail ~"killed"
+        let killed = rustrt::task_wait_event(this, &mut event);
+        if killed && !task::failing() {
+            fail ~"killed"
+        }
+        event
     }
-    event
 }
 
 #[doc(hidden)]
@@ -397,9 +404,12 @@ pub fn send<T: Owned, Tbuffer: Owned>(p: SendPacketBuffered<T, Tbuffer>,
             debug!("waking up task for %?", p_);
             let old_task = swap_task(&mut p.header.blocked_task, ptr::null());
             if !old_task.is_null() {
-                rustrt::task_signal_event(
-                    old_task, ptr::addr_of(&(p.header)) as *libc::c_void);
-                rustrt::rust_task_deref(old_task);
+                unsafe {
+                    rustrt::task_signal_event(
+                        old_task,
+                        ptr::addr_of(&(p.header)) as *libc::c_void);
+                    rustrt::rust_task_deref(old_task);
+                }
             }
 
             // The receiver will eventually clean this up.
@@ -445,7 +455,9 @@ pub fn try_recv<T: Owned, Tbuffer: Owned>(p: RecvPacketBuffered<T, Tbuffer>)
                 let old_task = swap_task(&mut self.p.blocked_task,
                                          ptr::null());
                 if !old_task.is_null() {
-                    rustrt::rust_task_deref(old_task);
+                    unsafe {
+                        rustrt::rust_task_deref(old_task);
+                    }
                 }
             }
         }
@@ -466,9 +478,11 @@ pub fn try_recv<T: Owned, Tbuffer: Owned>(p: RecvPacketBuffered<T, Tbuffer>)
     }
 
     // regular path
-    let this = rustrt::rust_get_task();
-    rustrt::task_clear_event_reject(this);
-    rustrt::rust_task_ref(this);
+    let this = unsafe { rustrt::rust_get_task() };
+    unsafe {
+        rustrt::task_clear_event_reject(this);
+        rustrt::rust_task_ref(this);
+    };
     debug!("blocked = %x this = %x", p.header.blocked_task as uint,
            this as uint);
     let old_task = swap_task(&mut p.header.blocked_task, this);
@@ -479,7 +493,10 @@ pub fn try_recv<T: Owned, Tbuffer: Owned>(p: RecvPacketBuffered<T, Tbuffer>)
     let mut first = true;
     let mut count = SPIN_COUNT;
     loop {
-        rustrt::task_clear_event_reject(this);
+        unsafe {
+            rustrt::task_clear_event_reject(this);
+        }
+
         let old_state = swap_state_acq(&mut p.header.state,
                                        Blocked);
         match old_state {
@@ -507,7 +524,9 @@ pub fn try_recv<T: Owned, Tbuffer: Owned>(p: RecvPacketBuffered<T, Tbuffer>)
             payload <-> p.payload;
             let old_task = swap_task(&mut p.header.blocked_task, ptr::null());
             if !old_task.is_null() {
-                rustrt::rust_task_deref(old_task);
+                unsafe {
+                    rustrt::rust_task_deref(old_task);
+                }
             }
             p.header.state = Empty;
             return Some(option::unwrap(move payload))
@@ -519,7 +538,9 @@ pub fn try_recv<T: Owned, Tbuffer: Owned>(p: RecvPacketBuffered<T, Tbuffer>)
 
             let old_task = swap_task(&mut p.header.blocked_task, ptr::null());
             if !old_task.is_null() {
-                rustrt::rust_task_deref(old_task);
+                unsafe {
+                    rustrt::rust_task_deref(old_task);
+                }
             }
             return None;
           }
@@ -554,10 +575,12 @@ fn sender_terminate<T: Owned>(p: *Packet<T>) {
         // wake up the target
         let old_task = swap_task(&mut p.header.blocked_task, ptr::null());
         if !old_task.is_null() {
-            rustrt::task_signal_event(
-                old_task,
-                ptr::addr_of(&(p.header)) as *libc::c_void);
-            rustrt::rust_task_deref(old_task);
+            unsafe {
+                rustrt::task_signal_event(
+                    old_task,
+                    ptr::addr_of(&(p.header)) as *libc::c_void);
+                rustrt::rust_task_deref(old_task);
+            }
         }
         // The receiver will eventually clean up.
       }
@@ -583,8 +606,10 @@ fn receiver_terminate<T: Owned>(p: *Packet<T>) {
       Blocked => {
         let old_task = swap_task(&mut p.header.blocked_task, ptr::null());
         if !old_task.is_null() {
-            rustrt::rust_task_deref(old_task);
-            assert old_task == rustrt::rust_get_task();
+            unsafe {
+                rustrt::rust_task_deref(old_task);
+                assert old_task == rustrt::rust_get_task();
+            }
         }
       }
       Terminated | Full => {
@@ -605,9 +630,12 @@ closed by the sender or has a message waiting to be received.
 
 */
 fn wait_many<T: Selectable>(pkts: &[T]) -> uint {
-    let this = rustrt::rust_get_task();
+    let this = unsafe { rustrt::rust_get_task() };
+
+    unsafe {
+        rustrt::task_clear_event_reject(this);
+    }
 
-    rustrt::task_clear_event_reject(this);
     let mut data_avail = false;
     let mut ready_packet = pkts.len();
     for pkts.eachi |i, p| unsafe {
diff --git a/src/libcore/private.rs b/src/libcore/private.rs
index 00087347c88..b9b6f10a185 100644
--- a/src/libcore/private.rs
+++ b/src/libcore/private.rs
@@ -30,18 +30,17 @@ use uint;
 
 extern mod rustrt {
     #[legacy_exports];
-    fn rust_task_weaken(ch: rust_port_id);
-    fn rust_task_unweaken(ch: rust_port_id);
+    unsafe fn rust_task_weaken(ch: rust_port_id);
+    unsafe fn rust_task_unweaken(ch: rust_port_id);
 
-    fn rust_create_little_lock() -> rust_little_lock;
-    fn rust_destroy_little_lock(lock: rust_little_lock);
-    fn rust_lock_little_lock(lock: rust_little_lock);
-    fn rust_unlock_little_lock(lock: rust_little_lock);
+    unsafe fn rust_create_little_lock() -> rust_little_lock;
+    unsafe fn rust_destroy_little_lock(lock: rust_little_lock);
+    unsafe fn rust_lock_little_lock(lock: rust_little_lock);
+    unsafe fn rust_unlock_little_lock(lock: rust_little_lock);
 }
 
 #[abi = "rust-intrinsic"]
 extern mod rusti {
-
     fn atomic_cxchg(dst: &mut int, old: int, src: int) -> int;
     fn atomic_xadd(dst: &mut int, src: int) -> int;
     fn atomic_xsub(dst: &mut int, src: int) -> int;
@@ -490,12 +489,18 @@ type rust_little_lock = *libc::c_void;
 
 struct LittleLock {
     l: rust_little_lock,
-    drop { rustrt::rust_destroy_little_lock(self.l); }
+    drop {
+        unsafe {
+            rustrt::rust_destroy_little_lock(self.l);
+        }
+    }
 }
 
 fn LittleLock() -> LittleLock {
-    LittleLock {
-        l: rustrt::rust_create_little_lock()
+    unsafe {
+        LittleLock {
+            l: rustrt::rust_create_little_lock()
+        }
     }
 }
 
@@ -504,7 +509,11 @@ impl LittleLock {
     unsafe fn lock<T>(f: fn() -> T) -> T {
         struct Unlock {
             l: rust_little_lock,
-            drop { rustrt::rust_unlock_little_lock(self.l); }
+            drop {
+                unsafe {
+                    rustrt::rust_unlock_little_lock(self.l);
+                }
+            }
         }
 
         fn Unlock(l: rust_little_lock) -> Unlock {
diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs
index 0bca8729d97..d8c3c74ba2e 100644
--- a/src/libcore/ptr.rs
+++ b/src/libcore/ptr.rs
@@ -26,16 +26,22 @@ use vec;
 #[abi = "cdecl"]
 extern mod libc_ {
     #[rust_stack]
-    fn memcpy(dest: *mut c_void, src: *const c_void,
-              n: libc::size_t) -> *c_void;
+    unsafe fn memcpy(dest: *mut c_void,
+                     src: *const c_void,
+                     n: libc::size_t)
+                  -> *c_void;
 
     #[rust_stack]
-    fn memmove(dest: *mut c_void, src: *const c_void,
-               n: libc::size_t) -> *c_void;
+    unsafe fn memmove(dest: *mut c_void,
+                      src: *const c_void,
+                      n: libc::size_t)
+                   -> *c_void;
 
     #[rust_stack]
-    fn memset(dest: *mut c_void, c: libc::c_int,
-              len: libc::size_t) -> *c_void;
+    unsafe fn memset(dest: *mut c_void,
+                     c: libc::c_int,
+                     len: libc::size_t)
+                  -> *c_void;
 }
 
 #[abi = "rust-intrinsic"]
diff --git a/src/libcore/rand.rs b/src/libcore/rand.rs
index cf114f0b5bc..e2101e06bfa 100644
--- a/src/libcore/rand.rs
+++ b/src/libcore/rand.rs
@@ -28,11 +28,11 @@ enum rctx {}
 
 #[abi = "cdecl"]
 extern mod rustrt {
-    fn rand_seed() -> ~[u8];
-    fn rand_new() -> *rctx;
-    fn rand_new_seeded2(&&seed: ~[u8]) -> *rctx;
-    fn rand_next(c: *rctx) -> u32;
-    fn rand_free(c: *rctx);
+    unsafe fn rand_seed() -> ~[u8];
+    unsafe fn rand_new() -> *rctx;
+    unsafe fn rand_new_seeded2(&&seed: ~[u8]) -> *rctx;
+    unsafe fn rand_next(c: *rctx) -> u32;
+    unsafe fn rand_free(c: *rctx);
 }
 
 /// A random number generator
@@ -265,7 +265,11 @@ impl Rng {
 
 struct RandRes {
     c: *rctx,
-    drop { rustrt::rand_free(self.c); }
+    drop {
+        unsafe {
+            rustrt::rand_free(self.c);
+        }
+    }
 }
 
 fn RandRes(c: *rctx) -> RandRes {
@@ -275,17 +279,25 @@ fn RandRes(c: *rctx) -> RandRes {
 }
 
 impl @RandRes: Rng {
-    fn next() -> u32 { return rustrt::rand_next((*self).c); }
+    fn next() -> u32 {
+        unsafe {
+            return rustrt::rand_next((*self).c);
+        }
+    }
 }
 
 /// Create a new random seed for seeded_rng
 pub fn seed() -> ~[u8] {
-    rustrt::rand_seed()
+    unsafe {
+        rustrt::rand_seed()
+    }
 }
 
 /// Create a random number generator with a system specified seed
 pub fn Rng() -> Rng {
-    @RandRes(rustrt::rand_new()) as Rng
+    unsafe {
+        @RandRes(rustrt::rand_new()) as Rng
+    }
 }
 
 /**
@@ -295,7 +307,9 @@ pub fn Rng() -> Rng {
  * length.
  */
 pub fn seeded_rng(seed: &~[u8]) -> Rng {
-    @RandRes(rustrt::rand_new_seeded2(*seed)) as Rng
+    unsafe {
+        @RandRes(rustrt::rand_new_seeded2(*seed)) as Rng
+    }
 }
 
 type XorShiftState = {
@@ -343,11 +357,11 @@ pub fn task_rng() -> Rng {
     }
     match r {
         None => {
-            let rng = @RandRes(rustrt::rand_new());
             unsafe {
+                let rng = @RandRes(rustrt::rand_new());
                 task::local_data::local_data_set(tls_rng_state, rng);
+                rng as Rng
             }
-            rng as Rng
         }
         Some(rng) => rng as Rng
     }
diff --git a/src/libcore/rt.rs b/src/libcore/rt.rs
index ebe8746cfca..e0eb2fcfd83 100644
--- a/src/libcore/rt.rs
+++ b/src/libcore/rt.rs
@@ -26,16 +26,17 @@ pub type rust_task = c_void;
 
 extern mod rustrt {
     #[rust_stack]
-    fn rust_upcall_exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char;
+    unsafe fn rust_upcall_exchange_malloc(td: *c_char, size: uintptr_t)
+                                       -> *c_char;
 
     #[rust_stack]
-    fn rust_upcall_exchange_free(ptr: *c_char);
+    unsafe fn rust_upcall_exchange_free(ptr: *c_char);
 
     #[rust_stack]
-    fn rust_upcall_malloc(td: *c_char, size: uintptr_t) -> *c_char;
+    unsafe fn rust_upcall_malloc(td: *c_char, size: uintptr_t) -> *c_char;
 
     #[rust_stack]
-    fn rust_upcall_free(ptr: *c_char);
+    unsafe fn rust_upcall_free(ptr: *c_char);
 }
 
 #[rt(fail_)]
@@ -46,8 +47,8 @@ pub fn rt_fail_(expr: *c_char, file: *c_char, line: size_t) -> ! {
 
 #[rt(fail_bounds_check)]
 #[lang="fail_bounds_check"]
-pub fn rt_fail_bounds_check(file: *c_char, line: size_t,
-                        index: size_t, len: size_t) {
+pub unsafe fn rt_fail_bounds_check(file: *c_char, line: size_t,
+                                   index: size_t, len: size_t) {
     let msg = fmt!("index out of bounds: the len is %d but the index is %d",
                     len as int, index as int);
     do str::as_buf(msg) |p, _len| {
@@ -57,7 +58,7 @@ pub fn rt_fail_bounds_check(file: *c_char, line: size_t,
 
 #[rt(exchange_malloc)]
 #[lang="exchange_malloc"]
-pub fn rt_exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char {
+pub unsafe fn rt_exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char {
     return rustrt::rust_upcall_exchange_malloc(td, size);
 }
 
@@ -66,13 +67,13 @@ pub fn rt_exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char {
 // problem occurs, call exit instead.
 #[rt(exchange_free)]
 #[lang="exchange_free"]
-pub fn rt_exchange_free(ptr: *c_char) {
+pub unsafe fn rt_exchange_free(ptr: *c_char) {
     rustrt::rust_upcall_exchange_free(ptr);
 }
 
 #[rt(malloc)]
 #[lang="malloc"]
-pub fn rt_malloc(td: *c_char, size: uintptr_t) -> *c_char {
+pub unsafe fn rt_malloc(td: *c_char, size: uintptr_t) -> *c_char {
     return rustrt::rust_upcall_malloc(td, size);
 }
 
@@ -81,7 +82,7 @@ pub fn rt_malloc(td: *c_char, size: uintptr_t) -> *c_char {
 // problem occurs, call exit instead.
 #[rt(free)]
 #[lang="free"]
-pub fn rt_free(ptr: *c_char) {
+pub unsafe fn rt_free(ptr: *c_char) {
     rustrt::rust_upcall_free(ptr);
 }
 
diff --git a/src/libcore/run.rs b/src/libcore/run.rs
index 60fe54109d0..435feb16023 100644
--- a/src/libcore/run.rs
+++ b/src/libcore/run.rs
@@ -29,10 +29,10 @@ use vec;
 
 #[abi = "cdecl"]
 extern mod rustrt {
-    fn rust_run_program(argv: **libc::c_char, envp: *c_void,
-                        dir: *libc::c_char,
-                        in_fd: c_int, out_fd: c_int, err_fd: c_int)
-        -> pid_t;
+    unsafe fn rust_run_program(argv: **libc::c_char, envp: *c_void,
+                               dir: *libc::c_char,
+                               in_fd: c_int, out_fd: c_int, err_fd: c_int)
+                            -> pid_t;
 }
 
 /// A value representing a child process
@@ -84,12 +84,14 @@ pub fn spawn_process(prog: &str, args: &[~str],
                  env: &Option<~[(~str,~str)]>,
                  dir: &Option<~str>,
                  in_fd: c_int, out_fd: c_int, err_fd: c_int)
-   -> pid_t {
-    do with_argv(prog, args) |argv| {
-        do with_envp(env) |envp| {
-            do with_dirp(dir) |dirp| {
-                rustrt::rust_run_program(argv, envp, dirp,
-                                         in_fd, out_fd, err_fd)
+              -> pid_t {
+    unsafe {
+        do with_argv(prog, args) |argv| {
+            do with_envp(env) |envp| {
+                do with_dirp(dir) |dirp| {
+                    rustrt::rust_run_program(argv, envp, dirp,
+                                             in_fd, out_fd, err_fd)
+                }
             }
         }
     }
@@ -202,69 +204,83 @@ pub fn run_program(prog: &str, args: &[~str]) -> int {
  * A class with a <program> field
  */
 pub fn start_program(prog: &str, args: &[~str]) -> Program {
-    let pipe_input = os::pipe();
-    let pipe_output = os::pipe();
-    let pipe_err = os::pipe();
-    let pid =
-        spawn_process(prog, args, &None, &None,
-                      pipe_input.in, pipe_output.out,
-                      pipe_err.out);
+    unsafe {
+        let pipe_input = os::pipe();
+        let pipe_output = os::pipe();
+        let pipe_err = os::pipe();
+        let pid =
+            spawn_process(prog, args, &None, &None,
+                          pipe_input.in, pipe_output.out,
+                          pipe_err.out);
+
+        unsafe {
+            if pid == -1 as pid_t { fail; }
+            libc::close(pipe_input.in);
+            libc::close(pipe_output.out);
+            libc::close(pipe_err.out);
+        }
 
-    if pid == -1 as pid_t { fail; }
-    libc::close(pipe_input.in);
-    libc::close(pipe_output.out);
-    libc::close(pipe_err.out);
-
-    type ProgRepr = {pid: pid_t,
-                     mut in_fd: c_int,
-                     out_file: *libc::FILE,
-                     err_file: *libc::FILE,
-                     mut finished: bool};
-
-    fn close_repr_input(r: &ProgRepr) {
-        let invalid_fd = -1i32;
-        if r.in_fd != invalid_fd {
-            libc::close(r.in_fd);
-            r.in_fd = invalid_fd;
+        type ProgRepr = {pid: pid_t,
+                         mut in_fd: c_int,
+                         out_file: *libc::FILE,
+                         err_file: *libc::FILE,
+                         mut finished: bool};
+
+        fn close_repr_input(r: &ProgRepr) {
+            let invalid_fd = -1i32;
+            if r.in_fd != invalid_fd {
+                unsafe {
+                    libc::close(r.in_fd);
+                }
+                r.in_fd = invalid_fd;
+            }
+        }
+        fn finish_repr(r: &ProgRepr) -> int {
+            if r.finished { return 0; }
+            r.finished = true;
+            close_repr_input(r);
+            return waitpid(r.pid);
+        }
+        fn destroy_repr(r: &ProgRepr) {
+            unsafe {
+                finish_repr(r);
+                libc::fclose(r.out_file);
+                libc::fclose(r.err_file);
+            }
+        }
+        struct ProgRes {
+            r: ProgRepr,
+            drop { destroy_repr(&self.r); }
         }
-    }
-    fn finish_repr(r: &ProgRepr) -> int {
-        if r.finished { return 0; }
-        r.finished = true;
-        close_repr_input(r);
-        return waitpid(r.pid);
-    }
-    fn destroy_repr(r: &ProgRepr) {
-        finish_repr(r);
-       libc::fclose(r.out_file);
-       libc::fclose(r.err_file);
-    }
-    struct ProgRes {
-        r: ProgRepr,
-        drop { destroy_repr(&self.r); }
-    }
 
-    fn ProgRes(r: ProgRepr) -> ProgRes {
-        ProgRes {
-            r: move r
+        fn ProgRes(r: ProgRepr) -> ProgRes {
+            ProgRes {
+                r: move r
+            }
         }
-    }
 
-    impl ProgRes: Program {
-        fn get_id() -> pid_t { return self.r.pid; }
-        fn input() -> io::Writer { io::fd_writer(self.r.in_fd, false) }
-        fn output() -> io::Reader { io::FILE_reader(self.r.out_file, false) }
-        fn err() -> io::Reader { io::FILE_reader(self.r.err_file, false) }
-        fn close_input() { close_repr_input(&self.r); }
-        fn finish() -> int { finish_repr(&self.r) }
-        fn destroy() { destroy_repr(&self.r); }
+        impl ProgRes: Program {
+            fn get_id() -> pid_t { return self.r.pid; }
+            fn input() -> io::Writer {
+                io::fd_writer(self.r.in_fd, false)
+            }
+            fn output() -> io::Reader {
+                io::FILE_reader(self.r.out_file, false)
+            }
+            fn err() -> io::Reader {
+                io::FILE_reader(self.r.err_file, false)
+            }
+            fn close_input() { close_repr_input(&self.r); }
+            fn finish() -> int { finish_repr(&self.r) }
+            fn destroy() { destroy_repr(&self.r); }
+        }
+        let repr = {pid: pid,
+                    mut in_fd: pipe_input.out,
+                    out_file: os::fdopen(pipe_output.in),
+                    err_file: os::fdopen(pipe_err.in),
+                    mut finished: false};
+        return ProgRes(move repr) as Program;
     }
-    let repr = {pid: pid,
-                mut in_fd: pipe_input.out,
-                out_file: os::fdopen(pipe_output.in),
-                err_file: os::fdopen(pipe_err.in),
-                mut finished: false};
-    return ProgRes(move repr) as Program;
 }
 
 fn read_all(rd: io::Reader) -> ~str {
@@ -294,60 +310,61 @@ fn read_all(rd: io::Reader) -> ~str {
  */
 pub fn program_output(prog: &str, args: &[~str]) ->
    {status: int, out: ~str, err: ~str} {
+    unsafe {
+        let pipe_in = os::pipe();
+        let pipe_out = os::pipe();
+        let pipe_err = os::pipe();
+        let pid = spawn_process(prog, args, &None, &None,
+                                pipe_in.in, pipe_out.out, pipe_err.out);
 
-    let pipe_in = os::pipe();
-    let pipe_out = os::pipe();
-    let pipe_err = os::pipe();
-    let pid = spawn_process(prog, args, &None, &None,
-                            pipe_in.in, pipe_out.out, pipe_err.out);
+        os::close(pipe_in.in);
+        os::close(pipe_out.out);
+        os::close(pipe_err.out);
+        if pid == -1i32 {
+            os::close(pipe_in.out);
+            os::close(pipe_out.in);
+            os::close(pipe_err.in);
+            fail;
+        }
 
-    os::close(pipe_in.in);
-    os::close(pipe_out.out);
-    os::close(pipe_err.out);
-    if pid == -1i32 {
         os::close(pipe_in.out);
-        os::close(pipe_out.in);
-        os::close(pipe_err.in);
-        fail;
-    }
 
-    os::close(pipe_in.out);
-
-    // Spawn two entire schedulers to read both stdout and sterr
-    // in parallel so we don't deadlock while blocking on one
-    // or the other. FIXME (#2625): Surely there's a much more
-    // clever way to do this.
-    let p = oldcomm::Port();
-    let ch = oldcomm::Chan(&p);
-    do task::spawn_sched(task::SingleThreaded) {
-        let errput = readclose(pipe_err.in);
-        oldcomm::send(ch, (2, move errput));
-    };
-    do task::spawn_sched(task::SingleThreaded) {
-        let output = readclose(pipe_out.in);
-        oldcomm::send(ch, (1, move output));
-    };
-    let status = run::waitpid(pid);
-    let mut errs = ~"";
-    let mut outs = ~"";
-    let mut count = 2;
-    while count > 0 {
-        let stream = oldcomm::recv(p);
-        match stream {
-            (1, copy s) => {
-                outs = move s;
-            }
-            (2, copy s) => {
-                errs = move s;
-            }
-            (n, _) => {
-                fail(fmt!("program_output received an unexpected file \
-                           number: %u", n));
-            }
+        // Spawn two entire schedulers to read both stdout and sterr
+        // in parallel so we don't deadlock while blocking on one
+        // or the other. FIXME (#2625): Surely there's a much more
+        // clever way to do this.
+        let p = oldcomm::Port();
+        let ch = oldcomm::Chan(&p);
+        do task::spawn_sched(task::SingleThreaded) {
+            let errput = readclose(pipe_err.in);
+            oldcomm::send(ch, (2, move errput));
         };
-        count -= 1;
-    };
-    return {status: status, out: move outs, err: move errs};
+        do task::spawn_sched(task::SingleThreaded) {
+            let output = readclose(pipe_out.in);
+            oldcomm::send(ch, (1, move output));
+        };
+        let status = run::waitpid(pid);
+        let mut errs = ~"";
+        let mut outs = ~"";
+        let mut count = 2;
+        while count > 0 {
+            let stream = oldcomm::recv(p);
+            match stream {
+                (1, copy s) => {
+                    outs = move s;
+                }
+                (2, copy s) => {
+                    errs = move s;
+                }
+                (n, _) => {
+                    fail(fmt!("program_output received an unexpected file \
+                               number: %u", n));
+                }
+            };
+            count -= 1;
+        };
+        return {status: status, out: move outs, err: move errs};
+    }
 }
 
 pub fn writeclose(fd: c_int, s: ~str) {
@@ -361,17 +378,19 @@ pub fn writeclose(fd: c_int, s: ~str) {
 }
 
 pub fn readclose(fd: c_int) -> ~str {
-    let file = os::fdopen(fd);
-    let reader = io::FILE_reader(file, false);
-    let buf = io::with_bytes_writer(|writer| {
-        let mut bytes = [mut 0, ..4096];
-        while !reader.eof() {
-            let nread = reader.read(bytes, bytes.len());
-            writer.write(bytes.view(0, nread));
-        }
-    });
-    os::fclose(file);
-    str::from_bytes(buf)
+    unsafe {
+        let file = os::fdopen(fd);
+        let reader = io::FILE_reader(file, false);
+        let buf = io::with_bytes_writer(|writer| {
+            let mut bytes = [mut 0, ..4096];
+            while !reader.eof() {
+                let nread = reader.read(bytes, bytes.len());
+                writer.write(bytes.view(0, nread));
+            }
+        });
+        os::fclose(file);
+        str::from_bytes(buf)
+    }
 }
 
 /// Waits for a process to exit and returns the exit code
diff --git a/src/libcore/stackwalk.rs b/src/libcore/stackwalk.rs
index 0ff85e57a65..0395cc76542 100644
--- a/src/libcore/stackwalk.rs
+++ b/src/libcore/stackwalk.rs
@@ -85,16 +85,20 @@ fn test_simple_deep() {
 }
 
 fn breakpoint() {
-    rustrt::rust_dbg_breakpoint()
+    unsafe {
+        rustrt::rust_dbg_breakpoint()
+    }
 }
 
 fn frame_address(f: fn(++x: *u8)) {
-    rusti::frame_address(f)
+    unsafe {
+        rusti::frame_address(f)
+    }
 }
 
 extern mod rustrt {
     #[legacy_exports];
-    fn rust_dbg_breakpoint();
+    unsafe fn rust_dbg_breakpoint();
 }
 
 #[abi = "rust-intrinsic"]
diff --git a/src/libcore/sys.rs b/src/libcore/sys.rs
index 9ddbbb70b0a..ad9c3d1e51d 100644
--- a/src/libcore/sys.rs
+++ b/src/libcore/sys.rs
@@ -53,7 +53,7 @@ extern mod rusti {
 
 extern mod rustrt {
     #[rust_stack]
-    fn rust_upcall_fail(expr: *c_char, file: *c_char, line: size_t);
+    unsafe fn rust_upcall_fail(expr: *c_char, file: *c_char, line: size_t);
 }
 
 /// Compares contents of two pointers using the default method.
diff --git a/src/libcore/task/mod.rs b/src/libcore/task/mod.rs
index 760a92346d2..04ecf155362 100644
--- a/src/libcore/task/mod.rs
+++ b/src/libcore/task/mod.rs
@@ -947,12 +947,12 @@ fn test_spawn_sched_childs_on_same_sched() {
 #[nolink]
 #[cfg(test)]
 extern mod testrt {
-    fn rust_dbg_lock_create() -> *libc::c_void;
-    fn rust_dbg_lock_destroy(lock: *libc::c_void);
-    fn rust_dbg_lock_lock(lock: *libc::c_void);
-    fn rust_dbg_lock_unlock(lock: *libc::c_void);
-    fn rust_dbg_lock_wait(lock: *libc::c_void);
-    fn rust_dbg_lock_signal(lock: *libc::c_void);
+    unsafe fn rust_dbg_lock_create() -> *libc::c_void;
+    unsafe fn rust_dbg_lock_destroy(lock: *libc::c_void);
+    unsafe fn rust_dbg_lock_lock(lock: *libc::c_void);
+    unsafe fn rust_dbg_lock_unlock(lock: *libc::c_void);
+    unsafe fn rust_dbg_lock_wait(lock: *libc::c_void);
+    unsafe fn rust_dbg_lock_signal(lock: *libc::c_void);
 }
 
 #[test]
diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs
index cba0ba5d71c..b9cefa89aa7 100644
--- a/src/libcore/vec.rs
+++ b/src/libcore/vec.rs
@@ -30,9 +30,9 @@ use vec;
 
 #[abi = "cdecl"]
 pub extern mod rustrt {
-    fn vec_reserve_shared(++t: *sys::TypeDesc,
-                          ++v: **raw::VecRepr,
-                          ++n: libc::size_t);
+    unsafe fn vec_reserve_shared(++t: *sys::TypeDesc,
+                                 ++v: **raw::VecRepr,
+                                 ++n: libc::size_t);
 }
 
 #[abi = "rust-intrinsic"]