Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support NIF code upgrades #13

Open
agelin opened this issue Apr 28, 2016 · 8 comments
Open

Support NIF code upgrades #13

agelin opened this issue Apr 28, 2016 · 8 comments

Comments

@agelin
Copy link

agelin commented Apr 28, 2016

Hello.Thanks for the great project.

I found the error when I reload nif module on iex.

The on_load function for module Elixir.Test returned {{:badmatch,
  {:error, {:upgrade, 'Upgrade not supported by this NIF library.'}}},

Is that has any way to add/edit/export the upgrade function?

Thank you.

@agelin agelin changed the title error when reload the module. "upgrade not supported" error when reload the module. Apr 28, 2016
@hansihe
Copy link
Member

hansihe commented Apr 28, 2016

Yeah, I did not implement module reloading, as I don't currently see a way to maintain memory safety when it comes to resource structs across reloads.

I could add the option of allowing upgrades, but it would invalidate memory safety if you modify resource structs and reload the nif library. If you are not using resource structs, it would probably not be a problem.

@agelin
Copy link
Author

agelin commented Apr 29, 2016

Ok, thanks for your reply!

@hansihe
Copy link
Member

hansihe commented Apr 29, 2016

I don't want to shut down the discussion around this or anything. If there is a need for this it should certainly be bumped up the feature priority list.

@agelin
Copy link
Author

agelin commented Apr 29, 2016

Last night I think about your answer. On reflection, I think you are right.

Of cause,“upgrade” may be abused.

Close(/hide)some danger options, to keep the safe mode. It's always effective.

If possible, can there be more a clear full marco of insecurity?like “rustler_export_nifs!!!”,😄. developers can have more choices and know the consequences.

Thanks for your great job.

@hansihe hansihe changed the title "upgrade not supported" error when reload the module. Support NIF code upgrades Jul 28, 2016
@jorendorff
Copy link
Collaborator

Upgrades probably can't be made safe. But we could probably add some kind of unsafe upgrade: my_upgrade_fn option to rustler_export_nifs. (Requiring the user to type in the unsafe keyword is good enough for me.)

@bigfish24
Copy link

Sorry if this is a basic question, but without support for NIF upgrades, what happens when you perform an upgrade?

@davydog187
Copy link
Member

I believe the module will fail to load @bigfish24

scrogson pushed a commit that referenced this issue Apr 2, 2019
Adds rebar3_rust and rustfromerl examples.
@hansihe
Copy link
Member

hansihe commented Nov 12, 2019

I believe what I wrote earlier in this thread is wrong.

As long as we always create resource types with the ERL_NIF_RT_CREATE flag, I believe we can do upgrades pretty safely.

Issues start to arise when we want to try supporting ERL_NIF_RT_TAKEOVER, since that's where we have the inability to prove that whatever is within the resource is identical between the two versions.

Having a basic version of NIF upgrading would certainly be better than having nothing at all

filmor pushed a commit to filmor/rustler that referenced this issue Oct 12, 2023
Set macOS rustflags on both x86 and ARM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants