Quantcast

reloading a linked in driver

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

reloading a linked in driver

Vance Shipley-2

While writing a dynamically linked driver it occurred
to me that it might be possible to reload a new version
of the driver without first stopping it.  This was a
natural thing to want to do as I had an Erlang shell in
one window and in another window I was making changes
to the driver code.  To be able to do live code change
on a driver would be very advantageous in real life.

I found that it worked.  Sort of.  If I make changes
that keep the size consistent it works but if I make a
change which would alter the offsets it crashes.  I
wonder if someone with a better knowledge of how this
works could comment on the possibilities.

An example:

$ erl
Erlang (BEAM) emulator version 5.0.1.1 [source]

Eshell V5.0.1.1  (abort with ^G)
1> erl_ddll:load_driver("./", foo_drv).
ok
2> Port = open_port({spawn, foo_drv}, []).
#Port<0.8>
3> port_control(Port, 2, <<0>>).
"foo"

Now I make a simple change to the driver code so that
it will return "bar" instead of "foo".  Things work as
hoped:

4> erl_ddll:load_driver("./", foo_drv).
ok
5> port_control(Port, 2, <<0>>).
"bar"

Now I change the driver so that it returns "foobar"
instead.  This adds three bytes to the code.

6> erl_ddll:load_driver("./", foo_drv).
ok
7> port_control(Port, 2, <<0>>).
Segmentation Fault(coredump)
$

It would really be very cool if there was a way to
make this work.  I have been very happy with the ability
to make frequent code changes on live systems with Erlang.
To be able to extend this benefit to the C language drivers
would be a boon to us.

        -Vance




Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

reloading a linked in driver

Jakob Praher
At the very least, you can give the new version another name. If the loaded
driver is already loaded, it won't relink when you do load_driver/2.
Unloading the driver first seems to work, but I suspect you don't want to
do that.

/Jakob



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

reloading a linked in driver

Vance Shipley-2
In reply to this post by Vance Shipley-2

I found that NOT loading the driver again worked:

3> port_control(Port, 2, <<0>>).
"bar"

Now copy new version of foo_drv.so over top of the old one.

4> port_control(Port, 2, <<0>>).
"foobar"


I'm happy now, although there is still much magic involved
for me as I don't quite understand what is going on here. :)

        -Vance


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

reloading a linked in driver

Jakob Praher
At 15:03 2001-02-05 -0500, you wrote:

>I found that NOT loading the driver again worked:
This requires both your functions to be at the same place in the jump
table, and all your global (and static) variables to be at the same place.
Probably better to avoid it...

/Jakob



Loading...