Skip to content

Advice on embedding HashLink without access to stack_top? #752

@SomeRanDev

Description

@SomeRanDev

I would like to embed HashLink in a dynamic library that's loaded at runtime; a plugin for a software.

I've been encountering issues that appear to stem from my use of hl_register_thread. I first gave it the address to the highest stack variable in the library's initialization function, but this would result in crashes (my debugger would always point to some random pointer manipulation in GC). Sometimes the crashes would take a bit to occur, but once I started using hl.Gc.flags = hl.Gc.flags | ForceMajor; to force the GC to run, the crashes would always happen instantly.

After countless attempts, it was only after I modified the source code of the software itself, added my own custom variable to main, and gave my extension the address to THAT (just like how HashLink normally works)... things started working without crashes. 👍

Now, of course, I would prefer for users to not have to use a modified version of the software to get things working, but I can't seem to find any other way. Is it impossible to embed HashLink this way? Or is there a smart solution I'm not aware of?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions