Skip to content

Commit c468aff

Browse files
PNaCl: Allow the standard crates to be built without optimizations. This purges
references to functions that PNaCl's Newlib doesn't support.
1 parent 9c051ef commit c468aff

File tree

3 files changed

+54
-14
lines changed

3 files changed

+54
-14
lines changed

src/liblibc/lib.rs

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
#![allow(non_uppercase_statics)]
7979
#![allow(missing_doc)]
8080
#![allow(uppercase_variables)]
81+
#![allow(unused_imports)]
8182

8283
#[cfg(test)] extern crate std;
8384
#[cfg(test)] extern crate test;
@@ -151,7 +152,9 @@ pub use funcs::posix88::stat_::{chmod, fstat, mkdir, stat};
151152
pub use funcs::posix88::stdio::{fdopen, fileno, pclose, popen};
152153
pub use funcs::posix88::unistd::{access, chdir, close, dup, dup2};
153154
pub use funcs::posix88::unistd::{execv, execve, execvp, getcwd};
154-
pub use funcs::posix88::unistd::{getpid, isatty, lseek, pipe, read};
155+
pub use funcs::posix88::unistd::{isatty, lseek, pipe, read};
156+
#[cfg(not(target_os = "nacl", target_libc = "newlib"))]
157+
pub use funcs::posix88::unistd::getpid;
155158
pub use funcs::posix88::unistd::{rmdir, unlink, write};
156159

157160
pub use funcs::bsd43::{socket, setsockopt, bind, send, recv, recvfrom};
@@ -186,13 +189,17 @@ pub use funcs::bsd43::{shutdown};
186189
#[cfg(unix)] pub use types::os::arch::posix88::{uid_t, gid_t};
187190
#[cfg(unix)] pub use types::os::arch::posix01::{pthread_attr_t};
188191
#[cfg(unix)] pub use types::os::arch::posix01::{stat, utimbuf};
189-
#[cfg(unix)] pub use funcs::posix88::unistd::{sysconf, setgid, setsid, setuid, pread, pwrite};
192+
#[cfg(unix, not(target_os = "nacl", target_libc = "newlib"))]
193+
pub use funcs::posix88::unistd::setsid;
194+
#[cfg(unix)] pub use funcs::posix88::unistd::{sysconf, setgid, setuid, pread, pwrite};
190195
#[cfg(unix)] pub use funcs::posix88::unistd::{getgid, getuid};
191196
#[cfg(unix)] pub use funcs::posix88::unistd::{_PC_NAME_MAX, utime, nanosleep, link};
192197
#[cfg(unix, not(target_os = "nacl", target_libc = "newlib"))]
193198
pub use funcs::posix88::unistd::pathconf;
194199
#[cfg(unix)] pub use funcs::posix88::unistd::{chown};
195-
#[cfg(unix)] pub use funcs::posix88::mman::{mmap, munmap, mprotect};
200+
#[cfg(unix, not(target_os = "nacl", target_libc = "newlib"))]
201+
pub use funcs::posix88::mman::mprotect;
202+
#[cfg(unix)] pub use funcs::posix88::mman::{mmap, munmap};
196203
#[cfg(unix)] pub use funcs::posix88::dirent::{opendir, readdir_r, closedir};
197204
#[cfg(unix)] pub use funcs::posix88::fcntl::{fcntl};
198205
#[cfg(unix)] pub use funcs::posix01::stat_::{lstat};
@@ -4084,6 +4091,7 @@ pub mod funcs {
40844091
pub fn fstat(fildes: c_int, buf: *mut stat) -> c_int;
40854092

40864093
pub fn mkdir(path: *const c_char, mode: mode_t) -> c_int;
4094+
#[cfg(not(target_os = "nacl"))]
40874095
pub fn mkfifo(path: *const c_char, mode: mode_t) -> c_int;
40884096

40894097
#[cfg(target_os = "linux")]
@@ -4165,6 +4173,7 @@ pub mod funcs {
41654173

41664174
extern {
41674175
pub fn access(path: *const c_char, amode: c_int) -> c_int;
4176+
#[cfg(not(target_os = "nacl", target_libc = "newlib"))]
41684177
pub fn alarm(seconds: c_uint) -> c_uint;
41694178
pub fn chdir(dir: *const c_char) -> c_int;
41704179
pub fn chown(path: *const c_char, uid: uid_t,
@@ -4180,18 +4189,23 @@ pub mod funcs {
41804189
pub fn execvp(c: *const c_char,
41814190
argv: *mut *const c_char) -> c_int;
41824191
pub fn fork() -> pid_t;
4192+
#[cfg(not(target_os = "nacl", target_libc = "newlib"))]
41834193
pub fn fpathconf(filedes: c_int, name: c_int) -> c_long;
41844194
pub fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char;
41854195
pub fn getegid() -> gid_t;
41864196
pub fn geteuid() -> uid_t;
41874197
pub fn getgid() -> gid_t ;
4198+
#[cfg(not(target_os = "nacl", target_libc = "newlib"))]
41884199
pub fn getgroups(ngroups_max: c_int, groups: *mut gid_t)
41894200
-> c_int;
41904201
pub fn getlogin() -> *mut c_char;
41914202
pub fn getopt(argc: c_int, argv: *mut *const c_char,
41924203
optstr: *const c_char) -> c_int;
4204+
#[cfg(not(target_os = "nacl", target_libc = "newlib"))]
41934205
pub fn getpgrp() -> pid_t;
4206+
#[cfg(not(target_os = "nacl", target_libc = "newlib"))]
41944207
pub fn getpid() -> pid_t;
4208+
#[cfg(not(target_os = "nacl", target_libc = "newlib"))]
41954209
pub fn getppid() -> pid_t;
41964210
pub fn getuid() -> uid_t;
41974211
pub fn isatty(fd: c_int) -> c_int;
@@ -4200,20 +4214,24 @@ pub mod funcs {
42004214
-> off_t;
42014215
#[cfg(not(target_os = "nacl", target_libc = "newlib"))]
42024216
pub fn pathconf(path: *mut c_char, name: c_int) -> c_long;
4217+
#[cfg(not(target_os = "nacl", target_libc = "newlib"))]
42034218
pub fn pause() -> c_int;
42044219
pub fn pipe(fds: *mut c_int) -> c_int;
42054220
pub fn read(fd: c_int, buf: *mut c_void, count: size_t)
42064221
-> ssize_t;
42074222
pub fn rmdir(path: *const c_char) -> c_int;
42084223
pub fn setgid(gid: gid_t) -> c_int;
4224+
#[cfg(not(target_os = "nacl", target_libc = "newlib"))]
42094225
pub fn setpgid(pid: pid_t, pgid: pid_t) -> c_int;
4226+
#[cfg(not(target_os = "nacl", target_libc = "newlib"))]
42104227
pub fn setsid() -> pid_t;
42114228
pub fn setuid(uid: uid_t) -> c_int;
42124229
pub fn sleep(secs: c_uint) -> c_uint;
42134230
pub fn usleep(secs: c_uint) -> c_int;
42144231
pub fn nanosleep(rqtp: *const timespec,
42154232
rmtp: *mut timespec) -> c_int;
42164233
pub fn sysconf(name: c_int) -> c_long;
4234+
#[cfg(not(target_os = "nacl", target_libc = "newlib"))]
42174235
pub fn tcgetpgrp(fd: c_int) -> pid_t;
42184236
pub fn ttyname(fd: c_int) -> *mut c_char;
42194237
pub fn unlink(c: *const c_char) -> c_int;
@@ -4241,12 +4259,24 @@ pub mod funcs {
42414259
use types::os::arch::c95::{size_t, c_int, c_char};
42424260
use types::os::arch::posix88::{mode_t, off_t};
42434261

4262+
#[cfg(not(target_os = "nacl", target_libc = "newlib"))]
42444263
extern {
42454264
pub fn mlock(addr: *const c_void, len: size_t) -> c_int;
42464265
pub fn munlock(addr: *const c_void, len: size_t) -> c_int;
42474266
pub fn mlockall(flags: c_int) -> c_int;
42484267
pub fn munlockall() -> c_int;
42494268

4269+
pub fn mprotect(addr: *mut c_void, len: size_t, prot: c_int)
4270+
-> c_int;
4271+
4272+
pub fn msync(addr: *mut c_void, len: size_t, flags: c_int)
4273+
-> c_int;
4274+
pub fn shm_open(name: *const c_char, oflag: c_int, mode: mode_t)
4275+
-> c_int;
4276+
pub fn shm_unlink(name: *const c_char) -> c_int;
4277+
}
4278+
4279+
extern {
42504280
pub fn mmap(addr: *mut c_void,
42514281
len: size_t,
42524282
prot: c_int,
@@ -4256,14 +4286,6 @@ pub mod funcs {
42564286
-> *mut c_void;
42574287
pub fn munmap(addr: *mut c_void, len: size_t) -> c_int;
42584288

4259-
pub fn mprotect(addr: *mut c_void, len: size_t, prot: c_int)
4260-
-> c_int;
4261-
4262-
pub fn msync(addr: *mut c_void, len: size_t, flags: c_int)
4263-
-> c_int;
4264-
pub fn shm_open(name: *const c_char, oflag: c_int, mode: mode_t)
4265-
-> c_int;
4266-
pub fn shm_unlink(name: *const c_char) -> c_int;
42674289
}
42684290
}
42694291
}
@@ -4359,6 +4381,7 @@ pub mod funcs {
43594381
use types::common::c95::{c_void};
43604382
use types::os::arch::c95::{c_int, size_t};
43614383

4384+
#[cfg(not(target_os = "nacl", target_libc = "newlib"))]
43624385
extern {
43634386
pub fn posix_madvise(addr: *mut c_void,
43644387
len: size_t,
@@ -4509,7 +4532,6 @@ pub mod funcs {
45094532

45104533
#[cfg(target_os = "linux")]
45114534
#[cfg(target_os = "android")]
4512-
#[cfg(target_os = "nacl")]
45134535
pub mod bsd44 {
45144536
use types::common::c95::{c_void};
45154537
use types::os::arch::c95::{c_uchar, c_int, size_t};
@@ -4525,6 +4547,7 @@ pub mod funcs {
45254547

45264548

45274549
#[cfg(target_os = "win32")]
4550+
#[cfg(target_os = "nacl")]
45284551
pub mod bsd44 {
45294552
}
45304553

src/libstd/io/tempfile.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,18 @@ impl TempDir {
4444

4545
static mut CNT: atomics::AtomicUint = atomics::INIT_ATOMIC_UINT;
4646

47+
#[cfg(not(target_os = "nacl", target_libc = "newlib"))]
48+
fn getpid() -> libc::pid_t { unsafe { libc::getpid() } }
49+
#[cfg(target_os = "nacl", target_libc = "newlib")]
50+
fn getpid() -> libc::pid_t {
51+
use rand::random;
52+
random()
53+
}
54+
4755
for _ in range(0u, 1000) {
4856
let filename =
4957
format!("rs-{}-{}-{}",
50-
unsafe { libc::getpid() },
58+
getpid(),
5159
unsafe { CNT.fetch_add(1, atomics::SeqCst) },
5260
suffix);
5361
let p = tmpdir.join(filename);

src/libstd/io/test.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,21 @@ pub fn next_test_port() -> u16 {
6464
/// Get a temporary path which could be the location of a unix socket
6565
pub fn next_test_unix() -> Path {
6666
static mut COUNT: AtomicUint = INIT_ATOMIC_UINT;
67+
68+
#[cfg(not(target_os = "nacl", target_libc = "newlib"))]
69+
fn getpid() -> libc::pid_t { unsafe { libc::getpid() } }
70+
#[cfg(target_os = "nacl", target_libc = "newlib")]
71+
fn getpid() -> libc::pid_t {
72+
use rand::random;
73+
random()
74+
}
75+
6776
// base port and pid are an attempt to be unique between multiple
6877
// test-runners of different configurations running on one
6978
// buildbot, the count is to be unique within this executable.
7079
let string = format!("rust-test-unix-path-{}-{}-{}",
7180
base_port(),
72-
unsafe {libc::getpid()},
81+
getpid(),
7382
unsafe {COUNT.fetch_add(1, Relaxed)});
7483
if cfg!(unix) {
7584
os::tmpdir().join(string)

0 commit comments

Comments
 (0)