Skip to content

Commit 6d5eee9

Browse files
committed
---
yaml --- r: 277044 b: refs/heads/try c: 112463a h: refs/heads/master
1 parent 70edb94 commit 6d5eee9

File tree

2 files changed

+19
-43
lines changed

2 files changed

+19
-43
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 6dbb0e86aec11050480beb76eade6fb805010ba7
33
refs/heads/snap-stage3: 235d77457d80b549dad3ac36d94f235208a1eafb
4-
refs/heads/try: abc3777c06abced90b415b920082a4814d9051d7
4+
refs/heads/try: 112463a3b1b1fc30c8f407e50e9ef692034ccb37
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
66
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
77
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try/src/libstd/sys/unix/thread.rs

Lines changed: 18 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -201,28 +201,17 @@ pub mod guard {
201201
current().map(|s| s as *mut libc::c_void)
202202
}
203203

204-
#[cfg(target_os = "freebsd")]
204+
#[cfg(any(target_os = "android", target_os = "freebsd",
205+
target_os = "linux", target_os = "netbsd"))]
205206
unsafe fn get_stack_start() -> Option<*mut libc::c_void> {
206207
let mut ret = None;
207208
let mut attr: libc::pthread_attr_t = ::mem::zeroed();
208209
assert_eq!(libc::pthread_attr_init(&mut attr), 0);
209-
if libc::pthread_attr_get_np(libc::pthread_self(), &mut attr) == 0 {
210-
let mut stackaddr = ::ptr::null_mut();
211-
let mut stacksize = 0;
212-
assert_eq!(libc::pthread_attr_getstack(&attr, &mut stackaddr,
213-
&mut stacksize), 0);
214-
ret = Some(stackaddr);
215-
}
216-
assert_eq!(libc::pthread_attr_destroy(&mut attr), 0);
217-
ret
218-
}
219-
220-
#[cfg(any(target_os = "linux", target_os = "android", target_os = "netbsd"))]
221-
unsafe fn get_stack_start() -> Option<*mut libc::c_void> {
222-
let mut ret = None;
223-
let mut attr: libc::pthread_attr_t = ::mem::zeroed();
224-
assert_eq!(libc::pthread_attr_init(&mut attr), 0);
225-
if libc::pthread_getattr_np(libc::pthread_self(), &mut attr) == 0 {
210+
#[cfg(target_os = "freebsd")]
211+
let e = libc::pthread_attr_get_np(libc::pthread_self(), &mut attr);
212+
#[cfg(not(target_os = "freebsd"))]
213+
let e = libc::pthread_getattr_np(libc::pthread_self(), &mut attr);
214+
if e == 0 {
226215
let mut stackaddr = ::ptr::null_mut();
227216
let mut stacksize = 0;
228217
assert_eq!(libc::pthread_attr_getstack(&attr, &mut stackaddr,
@@ -304,33 +293,18 @@ pub mod guard {
304293
})
305294
}
306295

307-
#[cfg(target_os = "freebsd")]
308-
pub unsafe fn current() -> Option<usize> {
309-
let mut ret = None;
310-
let mut attr: libc::pthread_attr_t = ::mem::zeroed();
311-
assert_eq!(libc::pthread_attr_init(&mut attr), 0);
312-
if libc::pthread_attr_get_np(libc::pthread_self(), &mut attr) == 0 {
313-
let mut guardsize = 0;
314-
assert_eq!(libc::pthread_attr_getguardsize(&attr, &mut guardsize), 0);
315-
if guardsize == 0 {
316-
panic!("there is no guard page");
317-
}
318-
let mut stackaddr = ::ptr::null_mut();
319-
let mut size = 0;
320-
assert_eq!(libc::pthread_attr_getstack(&attr, &mut stackaddr,
321-
&mut size), 0);
322-
ret = Some(stackaddr as usize - guardsize as usize);
323-
}
324-
assert_eq!(libc::pthread_attr_destroy(&mut attr), 0);
325-
ret
326-
}
327-
328-
#[cfg(any(target_os = "linux", target_os = "android", target_os = "netbsd"))]
296+
#[cfg(any(target_os = "android", target_os = "freebsd",
297+
target_os = "linux", target_os = "netbsd"))]
329298
pub unsafe fn current() -> Option<usize> {
330299
let mut ret = None;
331300
let mut attr: libc::pthread_attr_t = ::mem::zeroed();
332301
assert_eq!(libc::pthread_attr_init(&mut attr), 0);
333-
if libc::pthread_getattr_np(libc::pthread_self(), &mut attr) == 0 {
302+
#[cfg(target_os = "freebsd")]
303+
let e = libc::pthread_attr_get_np(libc::pthread_self(), &mut attr);
304+
#[cfg(not(target_os = "freebsd"))]
305+
let e = libc::pthread_getattr_np(libc::pthread_self(), &mut attr);
306+
if e == 0 {
307+
//if libc::pthread_getattr_np(libc::pthread_self(), &mut attr) == 0 {
334308
let mut guardsize = 0;
335309
assert_eq!(libc::pthread_attr_getguardsize(&attr, &mut guardsize), 0);
336310
if guardsize == 0 {
@@ -341,7 +315,9 @@ pub mod guard {
341315
assert_eq!(libc::pthread_attr_getstack(&attr, &mut stackaddr,
342316
&mut size), 0);
343317

344-
ret = if cfg!(target_os = "netbsd") {
318+
ret = if cfg!(target_os = "freebsd") {
319+
Some(stackaddr as usize - guardsize as usize)
320+
} else if cfg!(target_os = "netbsd") {
345321
Some(stackaddr as usize)
346322
} else {
347323
Some(stackaddr as usize + guardsize as usize)

0 commit comments

Comments
 (0)