Index: src/erlydb/erlydb.erl
===================================================================
--- src/erlydb/erlydb.erl	(revision 228)
+++ src/erlydb/erlydb.erl	(working copy)
@@ -365,43 +365,48 @@
 
 gen_module_code(ModulePath, DefaultDriverMod,
 	       DriversData, Options, IncludePaths) ->   
-    case smerl:for_module(ModulePath, IncludePaths) of
-	{ok, C1} ->
-	    C2 = preprocess_and_compile(C1),
-	    Module = smerl:get_module(C2),
+    case is_erts_module(ModulePath) of
+	{false, _} ->
+	    case smerl:for_module(ModulePath, IncludePaths) of
+		{ok, C1} ->
+		    C2 = preprocess_and_compile(C1),
+		    Module = smerl:get_module(C2),
+		    
+		    %% get the ErlyDB settings for the driver, taking the defaults
+		    %% into account
+		    {Driver, PoolsData, PoolId, DriverOptions} =
+			get_driver_settings(Module, DriversData, DefaultDriverMod),
+		    DriverMod = driver_mod(Driver),
+		    
+		    TablesData =
+			case gb_trees:lookup(PoolId, PoolsData) of
+			    {value, Val} ->
+				Val;
+			    _ ->
+				exit({invalid_erlydb_pool_option,
+				      {{module, Module},
+				       {pool_id, PoolId}}})
+			end,
 
-	    %% get the ErlyDB settings for the driver, taking the defaults
-	    %% into account
-	    {Driver, PoolsData, PoolId, DriverOptions} =
-		get_driver_settings(Module, DriversData, DefaultDriverMod),
-	    DriverMod = driver_mod(Driver),
-
-	    TablesData =
-		case gb_trees:lookup(PoolId, PoolsData) of
-		    {value, Val} ->
-			Val;
-		    _ ->
-			exit({invalid_erlydb_pool_option,
-			      {{module, Module},
-			       {pool_id, PoolId}}})
-		end,
-
-    	    case gb_trees:lookup(get_table(Module), TablesData) of
-		{value, Fields} ->
-		    ?Debug("Generating code for ~w", [Module]),
-		    Options2 = DriverOptions ++ Options,
-		    MetaMod =
-			make_module(DriverMod, C2, Fields,
-				    [{pool_id, PoolId} | Options2],
-				    TablesData),
-		    smerl:compile(MetaMod, Options);
-		none ->
-		    exit(
-		      {no_such_table, {{module, Module},
-				       {table, get_table(Module)}}})
+		    case gb_trees:lookup(get_table(Module), TablesData) of
+			{value, Fields} ->
+			    ?Debug("Generating code for ~w", [Module]),
+			    Options2 = DriverOptions ++ Options,
+			    MetaMod =
+				make_module(DriverMod, C2, Fields,
+					    [{pool_id, PoolId} | Options2],
+					    TablesData),
+			    smerl:compile(MetaMod, Options);
+			none ->
+			    exit(
+			      {no_such_table, {{module, Module},
+					       {table, get_table(Module)}}})
+		    end;
+		Err ->
+		    Err
 	    end;
-	Err ->
-	    Err
+	{true, CompilePath} ->
+	    exit({extending_system_module, {{module, ModulePath}, {compile_path, CompilePath}}})
     end.
 
 preprocess_and_compile(MetaMod) ->
@@ -1133,3 +1138,14 @@
 		  atom_to_list(Atom);
 	     (List) -> List
 	  end, Terms))).
+
+%% checks to see if the module is part of the Erlang runtime
+%% for now this is a hack where we check the compile path
+%% for the string "/otp_src_R"
+is_erts_module(Mod) ->
+    case smerl:get_module_compile_path(Mod) of
+	undefined ->
+	    {false, undefined};
+	Path ->
+	    {string:str(Path, "/otp_src_R") > 0, Path}
+    end.
Index: src/smerl/smerl.erl
===================================================================
--- src/smerl/smerl.erl	(revision 228)
+++ src/smerl/smerl.erl	(working copy)
@@ -108,7 +108,8 @@
 	 extend/3,
 	 extend/4,
 	 to_src/1,
-	 to_src/2
+	 to_src/2,
+	 get_module_compile_path/1
 	]).
 
 -define(L(Obj), io:format("LOG ~s ~w ~p\n", [?FILE, ?LINE, Obj])).
@@ -1034,3 +1035,39 @@
 to_src(MetaMod, FileName) ->
     Src = to_src(MetaMod),
     file:write_file(FileName, list_to_binary(Src)).
+
+%% @doc Extract the module's compile path its module_info()
+%%
+%% @spec get_module_compile_path(Mod::string() | Mod::atom()) ->
+%%    string() | undefined
+get_module_compile_path(Mod) when is_list(Mod) ->
+    get_module_compile_path(list_to_atom(Mod));
+
+get_module_compile_path(Mod) when is_atom(Mod)->
+    CompilePred = fun({Name, _Body}) ->
+			  Name =:= compile
+		  end,
+    SourcePred = fun(Item) ->
+			 if
+			     is_tuple(Item) ->
+				 {Name, _Body} = Item,
+				 Name =:= source;
+			     true ->
+				 false
+			 end
+		 end,
+    case lists:filter(CompilePred, Mod:module_info()) of
+	[] ->
+	    undefined;
+	[{compile, Options}] ->
+	    case lists:filter(SourcePred, Options) of
+		[] ->
+		    undefined;
+		[{source, Path}] ->
+		    Path;
+		_ ->
+		    undefined
+	    end;
+	_ ->
+	    undefined
+    end.
