rentzsch / mach_override

runtime function overriding for Mac OS X
428 stars 88 forks source link

allocateBranchIsland is slow #1

Open rentzsch opened 12 years ago

rentzsch commented 12 years ago

See https://github.com/rentzsch/mach_star/pull/38 for an attempt to address this.

Alexander Potapenko has enhancements that's part of llvm's AddressSanitizer, but unfortunately the link he gave me is now broken.

ramosian-glider commented 12 years ago

Citing my own letter:

Next, allocateBranchIsland() is very slow on 64 bits -- mainly because of the necessity to scan the memory page by page with vm_allocate(). Some information about that is at http://code.google.com/p/address-sanitizer/issues/detail?id=24, basically our tests made 3M calls to vm_allocate in order to override 26 functions. In order to fix that, we need to: -- search for empty memory in a more efficient way (e.g. look for holes in the process address space) -- map several pages with a single mmap/vm_allocate call, so that further mach_overrideptr() invocations can avoid searching and mapping memory. Because AddressSanitizer adds some limitations on the placement of the mappings, I chose to externalize the branch island allocator to let ASan decide where to place the islands. (see http://llvm.org/viewvc/llvm-project?view=rev&revision=148115) I'm a bit dissatisfied with the resulting code, mainly because of casts between BranchIsland* and void. To cope with that it's better to pass the islands as void_ everywhere and modify allocateBranchIsland so that it keeps track of additional flags itself (it may still store them in the same location)

The LLVM version of mach_override resides at http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/interception/mach_override/ I'll try to find some time and prepare a patch.

rentzsch commented 12 years ago

@ramosian-glider thanks for the link, I'll take a look

Fl0ri4n commented 11 years ago

The link above is dead, but I assume this one is the same: https://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/mach_override/?diff_format=l&sortby=log&pathrev=146166

I had to use the linked version to successfully override functions (in my case: CGLFlushDrawable) on 10.8 using 32bit clang, the mach_override in the stable branch didn't work for me. I think it should be merged into this project, at least in the unstable branch, it took me quite a while to find that patch.

rentzsch commented 11 years ago

@Fl0ri4n unfortunately I'm too busy with other projects to look into this. How does the stable branch not work for you? Crash? Just doesn't override?

Fl0ri4n commented 11 years ago

It just didn't override. I didn't debug it in more detail because I was overriding a function in a foreign precess using mach_inject. The last working compile using the stable branch was on 10.7 using gcc 4.2 (not LLVM), but I‘ve got neither of them installed at the moment, so I can't test if a 32bit gcc-compile using the stable branch would work on Mountain Lion.