Skip to content

Commit 568a451

Browse files
committed
openbsd: incoporate remarks
- consolidate target_record_sp_limit and target_get_sp_limit functions for aarch64, powerpc, arm-ios and openbsd as there are all without segmented stacks (no need to duplicate functions). - rename __load_self function to rust_load_self - use a mutex inner load_self() as underline implementation is not thread-safe
1 parent 3096784 commit 568a451

File tree

3 files changed

+27
-40
lines changed

3 files changed

+27
-40
lines changed

src/libstd/sys/common/stack.rs

Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -227,24 +227,14 @@ pub unsafe fn record_sp_limit(limit: uint) {
227227
}
228228

229229
// aarch64 - FIXME(AARCH64): missing...
230-
#[cfg(target_arch = "aarch64")]
231-
unsafe fn target_record_sp_limit(_: uint) {
232-
}
233-
234230
// powerpc - FIXME(POWERPC): missing...
235-
#[cfg(target_arch = "powerpc")]
236-
unsafe fn target_record_sp_limit(_: uint) {
237-
}
238-
239-
240-
// iOS segmented stack is disabled for now, see related notes
241-
#[cfg(all(target_arch = "arm", target_os = "ios"))] #[inline(always)]
242-
unsafe fn target_record_sp_limit(_: uint) {
243-
}
244-
245-
#[cfg(target_os = "openbsd")] #[inline(always)]
231+
// arm-ios - iOS segmented stack is disabled for now, see related notes
232+
// openbsd - segmented stack is disabled
233+
#[cfg(any(target_arch = "aarch64",
234+
target_arch = "powerpc",
235+
all(target_arch = "arm", target_os = "ios"),
236+
target_os = "openbsd"))]
246237
unsafe fn target_record_sp_limit(_: uint) {
247-
// segmented stack is disabled
248238
}
249239
}
250240

@@ -332,28 +322,18 @@ pub unsafe fn get_sp_limit() -> uint {
332322
}
333323

334324
// aarch64 - FIXME(AARCH64): missing...
335-
#[cfg(target_arch = "aarch64")]
336-
unsafe fn target_get_sp_limit() -> uint {
337-
1024
338-
}
339-
340-
// powepc - FIXME(POWERPC): missing...
341-
#[cfg(target_arch = "powerpc")]
342-
unsafe fn target_get_sp_limit() -> uint {
343-
1024
344-
}
345-
346-
// iOS doesn't support segmented stacks yet. This function might
347-
// be called by runtime though so it is unsafe to mark it as
348-
// unreachable, let's return a fixed constant.
349-
#[cfg(all(target_arch = "arm", target_os = "ios"))] #[inline(always)]
350-
unsafe fn target_get_sp_limit() -> uint {
351-
1024
352-
}
353-
354-
#[cfg(target_os = "openbsd")] #[inline(always)]
325+
// powerpc - FIXME(POWERPC): missing...
326+
// arm-ios - iOS doesn't support segmented stacks yet.
327+
// openbsd - OpenBSD doesn't support segmented stacks.
328+
//
329+
// This function might be called by runtime though
330+
// so it is unsafe to unreachable, let's return a fixed constant.
331+
#[cfg(any(target_arch = "aarch64",
332+
target_arch = "powerpc",
333+
all(target_arch = "arm", target_os = "ios"),
334+
target_os = "openbsd"))]
335+
#[inline(always)]
355336
unsafe fn target_get_sp_limit() -> uint {
356-
// segmented stack is disabled
357337
1024
358338
}
359339
}

src/libstd/sys/unix/os.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,18 @@ pub fn load_self() -> Option<Vec<u8>> {
217217

218218
#[cfg(target_os = "openbsd")]
219219
pub fn load_self() -> Option<Vec<u8>> {
220+
use sync::{StaticMutex, MUTEX_INIT};
221+
222+
static LOCK: StaticMutex = MUTEX_INIT;
223+
220224
extern {
221-
fn __load_self() -> *const c_char;
225+
fn rust_load_self() -> *const c_char;
222226
}
227+
228+
let _guard = LOCK.lock();
229+
223230
unsafe {
224-
let v = __load_self();
231+
let v = rust_load_self();
225232
if v.is_null() {
226233
None
227234
} else {

src/rt/rust_builtin.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ int *__dfly_error(void) { return __error(); }
204204
#include <sys/sysctl.h>
205205
#include <limits.h>
206206

207-
const char * __load_self() {
207+
const char * rust_load_self() {
208208
static char *self = NULL;
209209

210210
if (self == NULL) {

0 commit comments

Comments
 (0)