From: why the lucky stiff Date: 2006-08-30T15:40:09+09:00 Subject: sandbox r47, exposing top_cref v. emulating require --xgyAXRrhYN0wYx8y Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Finally, some big developments for the sandbox. I've got it running RubyGems! box = Sandbox.new :init => [:all] box.eval %{ require 'rubygems' Gem.manage_gems p Gem.source_index } This revision requires you to patch 1.8.5 to expose top_cref. (see attached) svn co http://code.whytheluckystiff.net/svn/sandbox/trunk sandbox The reason for swapping top_cref is because it is placed into ruby_cref by Ruby when any rb_load happens. So, you end up with the right `main`. I had thought about emulating `require`, but it seems foolish to emulate some things and swap others. If I keep a list of everything that needs to be swapped, then the procedure for native sandboxes in Ruby is known. Anyway, emulating require isn't a good option, since the sandbox should be able to load shared objects, if initialized to allow it. Also, I'm using Object.module_eval(str) to do the initial eval. Because the only options are rb_obj_instance_eval and rb_mod_module_eval. I would like to be able to swap ruby_cref and then run rb_eval_string. _why --xgyAXRrhYN0wYx8y Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="ruby-1.8.5-top_cref_exposed.patch" diff -wur ruby-1.8.5/eval.c ruby-1.8.5-top_cref_exposed/eval.c --- ruby-1.8.5/eval.c Sun Aug 6 21:43:39 2006 +++ ruby-1.8.5-top_cref_exposed/eval.c Wed Aug 30 01:42:28 2006 @@ -1062,7 +1062,7 @@ } while (0) static NODE *ruby_cref = 0; -static NODE *top_cref; +NODE *top_cref; #define PUSH_CREF(c) ruby_cref = NEW_NODE(NODE_CREF,(c),0,ruby_cref) #define POP_CREF() ruby_cref = ruby_cref->nd_next diff -wur ruby-1.8.5/node.h ruby-1.8.5-top_cref_exposed/node.h --- ruby-1.8.5/node.h Mon Feb 13 02:10:53 2006 +++ ruby-1.8.5-top_cref_exposed/node.h Wed Aug 30 01:42:40 2006 @@ -151,6 +151,8 @@ } u3; } NODE; +extern NODE *top_cref; + #define RNODE(obj) (R_CAST(RNode)(obj)) #define nd_type(n) ((int)(((RNODE(n))->flags>>FL_USHIFT)&0xff)) --xgyAXRrhYN0wYx8y--