Commit Graph

182 Commits

Author SHA1 Message Date
whitequark
a5d3430e63 Make Generator safe in presence of destructors. 2016-08-13 13:38:04 +02:00
whitequark
23cf17865d Remove workaround for rust-lang/rust#25544. 2016-08-13 13:38:04 +02:00
edef
ca43ba0498 Make fringe::Context private. 2016-08-13 13:38:04 +02:00
edef
b1a6b17d0a Move the Context tests and benches into src/
This concludes preparations for making Context private again.
2016-08-13 13:38:04 +02:00
whitequark
892a7696ec Allow unwinding to propagate across a context swap.
The main purpose of this is having nice backtraces in gdb, although
it also slightly simplifies poisoning state of the API consumers
after a panic.
2016-08-13 13:38:04 +02:00
whitequark
40fbfdde0c Kill impl StackPointer.
That was a silly idea for a silly abstraction, and it brought no
improvement, only confusion. So, revert it.
2016-08-13 13:38:04 +02:00
edef
bb699c0f6e Allow inlining Generator::state 2016-08-13 12:52:12 +02:00
edef
8c761d944f Fix Windows x64 ABI 2016-07-17 16:57:23 -04:00
whitequark
15d2fbaf51 Add an inline hint on Generator::next().
This improves the generate benchmark by about 1ns.
2016-07-17 13:56:03 -04:00
whitequark
16c674b4f4 Implement the GuardedStack marker trait. 2016-07-17 13:56:03 -04:00
whitequark
7ffad26cfd Implement the safe Generator abstraction.
close #24
2016-07-17 13:55:56 -04:00
whitequark
758088c673 Fix Stack::new(0). 2016-07-17 13:55:43 -04:00
whitequark
aa364056fd Add more documentation, and rephrase it elsewhere. 2016-07-16 20:54:47 -04:00
whitequark
ebd9ca8dec Allocate guard page under existing stack, not in it.
This fixes a segfault when the allocated stack is just one page long.

This also refactors the fringe::os module to use Result consistently.

close #22
2016-07-16 20:54:33 -04:00
John Ericson
75ca6f66e1 Move x86 trampoline to naked function
Close #19
2016-07-16 16:39:19 -04:00
John Ericson
1ea4b01eda Use mostly the same registers for consistency
The exception to this is %eax is used not %edi on x86 because its
caller-save
2016-07-16 16:39:14 -04:00
whitequark
cbe136b762 Completely rework fringe::Context and fringe::arch.
The new design concerns itself with one thing and exactly one thing:
passing values back and forth with an extern "C" function.
This allows to simplify fringe::arch into a single primitive, swap.

Close #21
2016-07-16 15:04:15 -04:00
edef
0d7b3d7091 add Windows support to OsStack
Fix #18
2016-04-16 07:51:10 +02:00
edef
6284a22caa add fpsr, eflags for good measure
courtesy of @whitequark
2016-04-16 07:41:00 +02:00
John Ericson
35fb046fb5 Factor out common code between x86 and x86_64
Fix #17
2016-04-14 13:37:15 +02:00
John Ericson
368fa9d3bf Remove unnecessary unsafety 2016-04-12 14:40:12 +02:00
edef
32fdbbb474 move OutStack's bound to a where clause 2016-04-03 20:07:45 +02:00
edef
daece1a8d3 Registers::{swap2 => swap}, to match Context::swap 2016-04-03 19:56:15 +02:00
edef
976b971436 get rid of the old Context::swap
The two-parameter version is the only necessary API.
2016-04-03 19:55:25 +02:00
edef
a50e6771b4 coerce rust_trampoline to a function pointer properly 2016-04-03 12:00:21 +02:00
edef
644cd81f9e fix parameter passing to arch/x86_64/swap.s 2016-04-03 11:59:14 +02:00
edef
3397e0bcf1 at least allow different lifetimes in Context::swap2
Really we should allow swapping between different stack types easily, so
we can easily swap between contexts with different stack types.
2016-03-22 08:46:27 +01:00
edef
b986931817 remove copyright years
They're obnoxious to update, and I'm told they have no legal value.
2016-03-22 08:25:23 +01:00
edef
709dad1c4a add Context::swap2, to allow distinct save/restore contexts
Fix #5

Context::swap is now implemented in terms of Context::swap2, and it
might make sense to remove Context::swap entirely at some point.
2016-03-22 07:50:50 +01:00
edef
2b23083455 get rid of some minor warnings 2016-03-22 07:35:25 +01:00
edef
4ffdba3ea6 minor style fixes 2016-03-16 00:20:45 +01:00
edef
bb2b92bf6b remove feature attributes for stable stuff 2016-03-16 00:14:09 +01:00
edef
bc46941e89 use libvalgrind instead of valgrind.h
no more C!
2016-01-04 15:34:41 +01:00
edef
cd4fe1ecc8 remove obsolete support for Rust stack limits
rustc removed these in 7a3fdfbf674a08b7f6fd32c9124e52924a2f9a1c, and
this removes a Linux-specific TLS slot from our code.
2016-01-04 03:46:07 +01:00
John Ericson
a1f286bdaf don't drop uninitialised memory when pushing to stack 2015-08-26 20:42:33 +02:00
John Ericson
96a31d2443 remove stray import 2015-08-26 20:41:12 +02:00
John Ericson
878a6fefc3 simplify Valgrind wrapper 2015-08-26 00:51:19 +02:00
John Ericson
5411f10460 use Void to ensure closure diverges 2015-08-26 00:51:18 +02:00
edef
c83143511e core::atomic -> core::sync::atomic 2015-08-26 00:20:23 +02:00
edef
e290a8bbaf remove extern crate core and prelude imports
the latest Rust nightly makes this unnecessary
2015-08-26 00:19:53 +02:00
edef
189edae3cf add #![feature(core_prelude)] 2015-07-20 20:54:41 -04:00
edef
6d1c5d0df1 it's fine to inline a simple FFI call 2015-04-27 17:19:13 +02:00
edef
2736479db0 fix license header 2015-04-23 01:24:58 +02:00
edef
3f0ec83bf3 remove valgrind_stack_change
This is a leftover from when we exposed these APIs to consumers, we
don't actually use this function.
2015-04-23 01:24:04 +02:00
edef
d0ee592ba1 use the libc crate from cargo 2015-04-23 01:14:01 +02:00
edef
418c53797e x86 support
ref #1
2015-04-16 13:15:46 -04:00
edef
52325b07c0 comment fix: it's 8ns *faster* 2015-04-16 12:21:39 -04:00
edef
a1e4c2b745 add Syntastic ASM lint hints 2015-04-16 11:56:45 -04:00
edef
0bebfae21d more docs! 2015-04-16 10:15:00 -04:00
edef
d627f0d725 big rename — we're libfringe now 2015-04-16 08:11:12 -04:00
edef
af7e9ea67c add FreeBSD + DragonFlyBSD MAP_STACK workaround
http://lists.freebsd.org/pipermail/freebsd-bugs/2011-July/044840.html
according to libgreen, DragonFlyBSD suffers from this too
2015-04-16 07:59:59 -04:00
edef
68f70fb1c9 rename Context::destroy to Context::unwrap, in line with lang conventions 2015-04-16 07:49:13 -04:00
edef
01e57ce9f5 let os::Stack's docs shine through the facade 2015-04-16 07:47:23 -04:00
edef
2266da2f8d rejig lib.rs a little 2015-04-16 07:45:14 -04:00
edef
fe490275fa move os::Stack behind the facade, to OsStack 2015-04-16 07:44:07 -04:00
edef
ff25697444 remove StackSource
Nothing in this library took StackSources, and it's probably too
high-level a concept to include here. Maybe later.
2015-04-16 07:42:16 -04:00
edef
bdb6e0bd8b let StackSource::get_stack take &mut self 2015-04-16 07:35:29 -04:00
edef
9bb0ce483d derive Copy and Clone for os::StackSource 2015-04-16 07:33:27 -04:00
edef
a389576d0f document os 2015-04-16 07:30:53 -04:00
edef
f3ee07416d require Stack::Error to implement Debug + Display 2015-04-16 07:27:14 -04:00
edef
cbfb62e62f only expose context and stack through the facade
It's fairly pointless to have submodules when there are only three
items.
2015-04-16 07:25:05 -04:00
edef
0dd6c8bc32 pass STACK_ALIGN through without exposing it 2015-04-16 07:24:15 -04:00
edef
7adb9e7381 implement Debug for all components of Context 2015-04-16 07:24:07 -04:00
edef
519d86ca4c implement Send where applicable 2015-04-16 07:23:57 -04:00
edef
7271fe1724 there is no point in Registers being Copy + Clone 2015-04-16 07:23:56 -04:00
edef
222ab0eaa9 make Context::destroy inlineable 2015-04-16 06:43:09 -04:00
edef
6f750ab484 move all OS-related code into src/os 2015-04-16 06:42:31 -04:00
edef
f7ab28de4b move all the common arch stuff into a module of its own 2015-04-16 06:34:03 -04:00
edef
b7624aa49a uintptr_t is pointless when usize is the same anyway 2015-04-16 06:20:46 -04:00
edef
997a4a7765 move architecture specifics into arch directory 2015-04-16 06:17:03 -04:00
edef
f24e8e7911 add license headers to every file 2015-04-16 06:08:44 -04:00
edef
cbc10fd311 cache page_size
page_size is used in every nearly every pointer calculation in os.rs,
and the Stack methods are called fairly often. It's definitely not worth
spilling registers for to call out to a libc function.
With this change, page_size becomes effectively free. It is cached in an
atomic usize, with relaxed ordering, so no actual atomic operations are
involved.

Benchmark:
```
test bench_page_size        ... bench:         5 ns/iter (+/- 1)
test bench_page_size_cached ... bench:         0 ns/iter (+/- 0)
```
2015-04-16 05:52:56 -04:00
edef
52c0c92cd8 move OS specifics into sys 2015-04-16 05:49:34 -04:00
edef
2c3a203f57 rearrange the os::{Stack, StackSource} code a little 2015-04-16 05:34:09 -04:00
edef
8dd3044da5 don't re-export os::unix internals 2015-04-16 05:34:09 -04:00
edef
cf33440503 include valgrind.h, so we don't depend on Valgrind at build time 2015-04-16 04:32:56 -04:00
edef
b8211689fa return a Result from StackSource::get_stack with an associated Error
fix #7
2015-04-16 04:14:18 -04:00
edef
42db0ee5b1 loosen the lifetime bounds on Context
fix #6
ref #3
2015-04-16 04:01:02 -04:00
edef
195350863a make Valgrind optional 2015-04-16 03:22:57 -04:00
edef
2760a0a7aa move Valgrind handling into Context
fix #3
This takes all Valgrind functionality private again.
Valgrind stack registrations are now associated with a Context, not with
a Stack. This makes sense, since it's only actually a stack when a
Context is running on it. Perhaps Valgrind will even be able to detect
early stack frees now.
2015-04-16 02:59:58 -04:00
edef
a04117f955 use Display for displaying IoErrors 2015-04-16 02:16:08 -04:00
edef
7e0b126f42 separate all the libc interaction out per OS
We're now handling more of this ourselves, and leaving less to libstd.
Hopefully, we'll eventually break free of libstd, leaving a
highly-focused low-level library that retains all its conveniences in
freestanding environments.
2015-04-16 02:16:08 -04:00
edef
46b2a4007b improve the assembly documentation 2015-04-16 00:22:50 -04:00
edef
d25f43d4d5 add license headers to the assembly files 2015-04-16 00:16:23 -04:00
edef
5c252bdef5 document Stack and StackSource 2015-04-15 23:38:07 -04:00
edef
5b6aa23731 pass os::Stack addresses to Valgrind in the right order 2015-04-15 22:48:42 -04:00
edef
04bbeb88f4 add valgrind_stack_change
Unlike valgrind_stack_register, this won't automatically swap
if `start > end`. It's probably wiser to pretend it doesn't swap at all.
2015-04-15 22:45:50 -04:00
edef
476a63b817 move the Valgrind doc-comments to Rust-land, where they actually matter 2015-04-15 22:41:34 -04:00
edef
14887b4dd0 Valgrind doesn't actually care about the order 2015-04-15 22:40:16 -04:00
edef
9cbb2819ca match the internal Valgrind function names to the macro names 2015-04-15 22:30:07 -04:00
edef
db6a2ff89b factor Valgrind support out and expose it
Now other Stack / StackSource implementations can use the same Valgrind
code. Ref #3.
2015-04-15 22:25:52 -04:00
edef
904da1a1c8 use Rust types for Valgrind, and use u32 for stack IDs 2015-04-15 22:22:02 -04:00
edef
7167b0b570 add Context::destroy 2015-04-15 21:54:56 -04:00
edef
31652d7b8f limit compilation of arch to x86_64
the current code only supports x86_64 (#1), and we want to fail hard on
any other architecture for now.
2015-04-15 21:52:08 -04:00
edef
6d56cc593e feature-flag os, but leave it enabled by default 2015-04-15 21:51:37 -04:00
edef
54b34383e3 parametrise Context on Stack 2015-04-15 21:51:37 -04:00
edef
8dc53c3125 make Context::new take a stack, instead of creating one 2015-04-15 19:35:27 -04:00
edef
27318bc271 rename platform to os 2015-04-15 19:35:27 -04:00
edef
5ae54da9c2 make context public 2015-04-15 19:35:27 -04:00
edef
9855084890 make stack public 2015-04-15 19:35:27 -04:00