standalone erlang

Sean Hinde sean.hinde@REDACTED
Thu Feb 17 18:02:53 CET 2005


Hi,

On Thursday, February 17, 2005, at 01:13AM, Sean Hinde <sean.hinde@REDACTED> wrote:

>
>I'll post my patch to the linker which allows for own ring0.erl another 
>time
>

And here is the patch for the backdoor - exactly as originally written. The compiled ring0 must be called cli_ring0.beam and be located in the current directory. It should be quite straightforward to have this start up networking properly and whatever other services are required. In our case we just used prim_inet functions for the simple networking requirements of the app.



--- otp_src_R10B-3/erts/boot/src/elink.erl      Wed Oct  2 22:45:10 2002
+++ otp_src_R10B-1a/erts/boot/src/elink.erl     Wed Dec 15 00:21:15 2004
@@ -102,9 +102,17 @@
 mk_exec(dynamic, Os, Bin, Out, Start, Beams) ->
     {_StartMod, Dir, Bin1, _, BinSae} = binary_to_term(Bin), 
     Extra = boot_tools:pack_beams(Beams),
-    B = term_to_binary({Start, Dir, Bin1, Extra, BinSae}, [compressed]),
+    BinSae1 = case file:read_file("cli_ring0.beam") of
+                 {ok, Ring0_bin} ->
+                      erlang:display(using_ring0),
+                     Ring0_bin;
+                 _ ->
+                      erlang:display(using_normal),
+                     BinSae
+             end,
+    B = term_to_binary({Start, Dir, Bin1, Extra, BinSae1}, [compressed]),
     EarDir = ear_dir(Dir),
-    boot_linker:link(Os, Out, [{"ERLANG_EARS", EarDir}], BinSae, B),
+    boot_linker:link(Os, Out, [{"ERLANG_EARS", EarDir}], BinSae1, B),
     true.
 
 ear_dir(Dir) ->


<---------->

The current cli_ring0.erl we are playing with is below - it starts an alternative shell environment:

-module(cli_ring0).
-export([start/1]).

%% This is the first *ever* routine to get called. Taken from boot_tools.erl. Thanks Joe!
start(Args=[Bin,_|T]) ->
    {StartMod, _Dir, Mods1, Mods2, _} = binary_to_term(Bin),
    Loaded = load_mods(Mods1) ++ load_mods(Mods2),
    erlang:display({code,handler,starting1}),
    boot_code_loader:startMeUp(),
    boot_code_loader:prim_loaded(Loaded),
    boot_code_loader:ensure_loaded(erl_open_port),
    boot_code_loader:ensure_loaded(user),
    %% tricky bit, this sets up a file system and IO user server
    %% up and running
%%     user:start(),
%%     G = whereis(user), 
%%     group_leader(G, self()),
    %% io:format("IO is running ...\n"),
    file_server:start(),
    %% io:format("File server running ...\n"),
    erlang:display({"launching:",erlang:processes(), "with Args:",T,"~n"}),
    case (catch cli_user_drv:start()) of
        {'EXIT', _} ->
            erlang:halt();
        R ->
            R
    end.                

load_mods([{Mod,Code}|T]) ->
    erlang:display({loading,Mod}),
    case erlang:load_module(Mod, Code) of
        {module,Mod} ->
            [Mod|load_mods(T)];
        Other ->
            erlang:display({bad_module,Mod}),
            erlang:halt(-1)
    end;
load_mods([]) -> [].

<------------>
Sean




More information about the erlang-questions mailing list