Dynamically Linking of libraries

Creating, porting and using libraries with Ultibo
pjde
Posts: 443
Joined: Tue Feb 09, 2016 6:21 am
Location: Sydney, Australia

Dynamically Linking of libraries

Postby pjde » Sat Feb 17, 2018 8:28 pm

Hi Garry

Is support for dynamically linking libraries still being developed?

The reason for asking is that there is a number of libraries I would like to use but their licenses only support dynamic linking.

Regards

Paul
User avatar
Ultibo
Site Admin
Posts: 2208
Joined: Sat Dec 19, 2015 3:49 am
Location: Australia

Re: Dynamically Linking of libraries

Postby Ultibo » Sat Feb 17, 2018 11:33 pm

pjde wrote:Is support for dynamically linking libraries still being developed?

Yes, we have had a working prototype for some time but have not pushed to complete it for various reasons.

One of the missing elements is an importable interface to allow libraries to access the Ultibo API, this is coming with the changes to add a C API (it will support either static or dynamic libraries) and the need for dynamic libraries will be further driven by work on porting one or more of the interpreted languages to run on top of Ultibo since they are often designed to import external functionality dynamically.

It will still be several steps down the track before this is available since the C API etc will come first. One thing that will be important for people to remember is that this will not make it instantly possible to use any randomly chosen DLL or SO file from Windows or Linux, dynamic libraries will still need to be recompiled to support Ultibo before they can be used.
Ultibo.org | Make something amazing
https://ultibo.org
pjde
Posts: 443
Joined: Tue Feb 09, 2016 6:21 am
Location: Sydney, Australia

Re: Dynamically Linking of libraries

Postby pjde » Sun Feb 18, 2018 1:08 am

Thats good to know.

Its one of my ongoing projects. I can probably test it by statically linking, and wait for this to release it to the forum and outside world.

Regards

Paul
mark
Posts: 1325
Joined: Mon Oct 03, 2016 2:12 am
Location: Indianapolis, US

Re: Dynamically Linking of libraries

Postby mark » Tue Feb 26, 2019 11:00 pm

Ultibo wrote:
pjde wrote:Is support for dynamically linking libraries still being developed?

Yes, we have had a working prototype for some time but have not pushed to complete it for various reasons.

One of the missing elements is an importable interface to allow libraries to access the Ultibo API, this is coming with the changes to add a C API (it will support either static or dynamic libraries) and the need for dynamic libraries will be further driven by work on porting one or more of the interpreted languages to run on top of Ultibo since they are often designed to import external functionality dynamically.

It will still be several steps down the track before this is available since the C API etc will come first. One thing that will be important for people to remember is that this will not make it instantly possible to use any randomly chosen DLL or SO file from Windows or Linux, dynamic libraries will still need to be recompiled to support Ultibo before they can be used.


Garry, I am thinking about loading a zig object file into some memory that has the right execute protection and calling it. To start out, it doesn’t call back to ultibo and just returns an integer based on its arguments. So it should be straightforward. No symbol resolution needed and I can use a constant for the entry point offset. Then only the four kernel binary images would be needed to get started with zig/ultibo, on top of that an updated zig module could be sent to a running kernel for quicker development cycles. (I’ve found that ultibo kernels don’t generally crash, just threads.) Two questions:

1. Is it worth trying this in light of where your progress is in dynamic linking?

2. If dynamic linking is a ways off, can you tell me how to change some allocated heap to read-only/executable?

Thanks,
Mark
User avatar
Ultibo
Site Admin
Posts: 2208
Joined: Sat Dec 19, 2015 3:49 am
Location: Australia

Re: Dynamically Linking of libraries

Postby Ultibo » Wed Feb 27, 2019 10:47 am

mark wrote:1. Is it worth trying this in light of where your progress is in dynamic linking?

We can't really say when we'll make dynamic linking available, it depends on a number of things being completed, so if you have an idea in mind and are willing to try you should go ahead.

mark wrote:2. If dynamic linking is a ways off, can you tell me how to change some allocated heap to read-only/executable?

In a very broad sense you don't need to do much more than read the page table flags, update them and write the modified flags back again.

Something like this would change a normal page to a read only/executable page.

Code: Select all

var
  PageTableEntry:TPageTableEntry;

begin
 //Get the page table entry for the page
 PageTableEntry:=PageTableGetEntry(PtrUInt(Buffer));
 
 //Remove the read write flag from the entry
  PageTableEntry.Flags:=PageTableEntry.Flags and not(PAGE_TABLE_FLAG_READWRITE);
 
 //Add the read only and executable flags to the entry
 PageTableEntry.Flags:=PageTableEntry.Flags or PAGE_TABLE_FLAG_READONLY or PAGE_TABLE_FLAG_EXECUTABLE;

 //And write the entry back with the new flags
 PageTableSetEntry(PageTableEntry); 

Remember that in general a PageTableEntry represents 4KB of memory so if you want to change a larger area you need to update each page in the range of memory to be changed.

We have discussed this previously along with some additional info and ideas which might be helpful as well
Ultibo.org | Make something amazing
https://ultibo.org

Return to “Libraries”

Who is online

Users browsing this forum: No registered users and 1 guest