This is an archive of the discontinued LLVM Phabricator instance.

[ASAN] Pass previous stack information through __sanitizer_finish_switch_fiber
ClosedPublic

Authored by andriigrynenko on Sep 15 2016, 1:58 PM.

Details

Summary

This patch extends __sanitizer_finish_switch_fiber method to optionally return previous stack base and size.

This solves the problem of coroutines/fibers library not knowing the original stack context from which the library is used. It's incorrect to assume that such context is always the default stack of current thread (e.g. one such library may be used from a fiber/coroutine created by another library). Bulding a separate stack tracking mechanism would not only duplicate AsanThread, but also require each coroutines/fibers library to integrate with it.

Diff Detail

Event Timeline

andriigrynenko retitled this revision from to [ASAN] Pass previous stack information through __sanitizer_finish_switch_fiber.
andriigrynenko updated this object.
andriigrynenko set the repository for this revision to rL LLVM.
andriigrynenko added a subscriber: cfe-commits.
blastrock edited edge metadata.Sep 15 2016, 2:15 PM

Seems fine to me, but I think you forgot to update the tests :)

andriigrynenko planned changes to this revision.Sep 15 2016, 2:34 PM
andriigrynenko edited edge metadata.

fix the unit test

test/asan/TestCases/Linux/swapcontext_annotation.cc
14

The test was actually broken in trunk (not updated for the fakestack argument). Apparently it was never run (considered unsupported) because of wrong targets here.

dvyukov edited edge metadata.Sep 16 2016, 12:11 PM

We need a test that passes non-NULL to these arguments and shows how to use the returned values.

test/asan/TestCases/Linux/swapcontext_annotation.cc
55–57

#include <stddef.h> for NULL

blastrock added inline comments.Sep 16 2016, 12:42 PM
test/asan/TestCases/Linux/swapcontext_annotation.cc
14

Indeed, my bad, I forgot to compile and run the tests after the last modification I made to that patch. Sorry for that.

I didn't need to change this line to run them on my computer though, but if you know what you are doing with this line, it's ok. And it's strange indeed that no buildfarm caught this...

andriigrynenko edited edge metadata.

update unit test to use non-null values

filcab edited edge metadata.Sep 16 2016, 2:19 PM

Please add some printf calls to the test, to show that you have the correct stack+size, too.

Thanks for working on this.
Filipe

lib/asan/asan_thread.cc
141

Please make sure you're accounting for this. It seems the test is always passing nullptr to start_switch, which shouldn't be done unless you're finishing up a fiber execution, IIRC.

162

I think the usual style is: one statement => no braces.

test/asan/TestCases/Linux/swapcontext_annotation.cc
14

They wouldn't catch tests not being run.
Test with LLVM_LIT_ARGS=-v (instead of -sv) on your cmake config and double-check that the tests are run.

55–57

nit: nullptr?

andriigrynenko edited edge metadata.

Addressing comments.

andriigrynenko added inline comments.Sep 16 2016, 5:45 PM
test/asan/TestCases/Linux/swapcontext_annotation.cc
181–204

This only checks the first iteration of the loop. Can I do it better with FileCheck ?

We need a test that passes non-NULL to these arguments and shows how to use the returned values.

test/asan/TestCases/Linux/swapcontext_annotation.cc
181–204

Yes, you can add CHECKs for the second iteration as well.

andriigrynenko added inline comments.Sep 26 2016, 1:29 PM
test/asan/TestCases/Linux/swapcontext_annotation.cc
181–204

@dvyukov: What I meant is that I didn't see a way to have some kind of loop in these CHECKs. I don't want to copy-paste these same CHECKs 30 times :)

Do CHECKs for all iterations of the loop.

LGTM

Any other comments? Or I will submit it tomorrow.

test/asan/TestCases/Linux/swapcontext_annotation.cc
7

nice

dvyukov accepted this revision.Sep 28 2016, 5:37 AM
dvyukov edited edge metadata.

Submitted in 282582.

This revision is now accepted and ready to land.Sep 28 2016, 5:37 AM
dvyukov closed this revision.Sep 28 2016, 5:37 AM