]> gitweb.factorcode.org Git - factor.git/commitdiff
vm: code_block_for_address method -> code_heap
authorJoe Groff <arcata@gmail.com>
Wed, 26 Oct 2011 22:45:01 +0000 (15:45 -0700)
committerJoe Groff <arcata@gmail.com>
Fri, 28 Oct 2011 04:18:20 +0000 (21:18 -0700)
vm/callstack.cpp
vm/code_heap.cpp
vm/code_heap.hpp

index b26ddc206c7852046b88017a724e35ea0c6744b7..22dbf97589820c93b45cce1efc237cee58127db2 100755 (executable)
@@ -18,35 +18,6 @@ callstack *factor_vm::allot_callstack(cell size)
        return stack;
 }
 
-// XXX move somewhere more appropriate
-struct entry_point_finder {
-       cell address;
-       cell found_entry_point;
-
-       entry_point_finder(cell address)
-               : address(address), found_entry_point(0) {}
-
-       // XXX keep a map of code blocks in the code heap so we don't need this
-       void operator()(code_block *block, cell size)
-       {
-               if ((cell)block->entry_point() <= address
-                       && address - (cell)block->entry_point() < block->size())
-               {
-                       assert(found_entry_point == 0);
-                       found_entry_point = (cell)block->entry_point();
-               }
-       }
-};
-
-static cell find_entry_point_for_address(factor_vm *vm, cell pc)
-{
-       std::cout << "seeking " << std::hex << pc << std::endl;
-       entry_point_finder finder(pc);
-       vm->code->allocator->iterate(finder);
-       assert(finder.found_entry_point != 0);
-       return finder.found_entry_point;
-}
-
 void factor_vm::dispatch_signal_handler(cell *sp, cell *pc, cell handler)
 {
        if (!code->seg->in_segment_p(*pc) || *sp < ctx->callstack_seg->start + stack_reserved)
@@ -96,12 +67,13 @@ void factor_vm::dispatch_signal_handler(cell *sp, cell *pc, cell handler)
                else if (offset == 16 - sizeof(cell))
                {
                        // Make a fake frame for the leaf procedure
-                       cell leaf_word = find_entry_point_for_address(this, *pc);
+                       code_block *leaf_block = code->code_block_for_address(*pc);
+                       assert(leaf_block != NULL);
 
                        // XXX get platform-appropriate stack frame size
                        cell newsp = *sp - 32;
                        *(cell*)(newsp + 32 -   sizeof(cell)) = 32;
-                       *(cell*)(newsp + 32 - 2*sizeof(cell)) = leaf_word;
+                       *(cell*)(newsp + 32 - 2*sizeof(cell)) = (cell)leaf_block->entry_point();
                        *(cell*) newsp                        = *pc;
                        *sp = newsp;
                        handler_word = tagged<word>(special_objects[LEAF_SIGNAL_HANDLER_WORD]);
index 1d978f243967d2ce35ae4441890421f3ac3a348f..f8b78eabde17f7ddd9014e4d3ee62f90303fec07 100755 (executable)
@@ -71,6 +71,31 @@ void code_heap::flush_icache()
        factor::flush_icache(seg->start,seg->size);
 }
 
+struct address_finder {
+       cell address;
+       code_block *found_code_block;
+
+       address_finder(cell address)
+               : address(address), found_code_block(NULL) {}
+
+       void operator()(code_block *block, cell size)
+       {
+               if ((cell)block->entry_point() <= address
+                       && address - (cell)block->entry_point() < block->size())
+               {
+                       assert(found_code_block == NULL);
+                       found_code_block = block;
+               }
+       }
+};
+
+code_block *code_heap::code_block_for_address(cell address)
+{
+       address_finder finder(address);
+       allocator->iterate(finder);
+       return finder.found_code_block;
+}
+
 /* Allocate a code heap during startup */
 void factor_vm::init_code_heap(cell size)
 {
index 75f19e2b7cfb5d1036638ef77e751c345a8d6bda..a1a8386c25363953b30a86122b3703d9054a7167 100755 (executable)
@@ -44,6 +44,8 @@ struct code_heap {
        void guard_safepoint();
        void unguard_safepoint();
 
+       code_block *code_block_for_address(cell address);
+
        bool safepoint_p(cell addr)
        {
                cell page_mask = ~(getpagesize() - 1);