LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Save/Load data segment of Dynamically loaded Shared Object library (https://www.linuxquestions.org/questions/programming-9/save-load-data-segment-of-dynamically-loaded-shared-object-library-828471/)

vragukumar 08-25-2010 04:26 PM

Save/Load data segment of Dynamically loaded Shared Object library
 
All,

Our application uses a dynamically loaded shared object library (codec library) to compress and decompress audio streams.

There happens to be several static and global variables in this shared object library. Hence it is not possible to process two interleaved unrelated media streams using this shared object codec library because each stream corrupts/changes the contents of these static/global variables.

Is there a way through which a context save (save contents of data segment of shared object) and a context load (load previously saved contents of data segment of shared object)operation can be performed on the shared object library. This way the context for each media stream can be saved and loaded before and after processing the "other" media stream respectively.

Thanks in advance.
Regards,
Vikram.

Sergei Steshenko 08-25-2010 05:18 PM

Quote:

Originally Posted by vragukumar (Post 4077676)
All,

Our application uses a dynamically loaded shared object library (codec library) to compress and decompress audio streams.

There happens to be several static and global variables in this shared object library. Hence it is not possible to process two interleaved unrelated media streams using this shared object codec library because each stream corrupts/changes the contents of these static/global variables.

Is there a way through which a context save (save contents of data segment of shared object) and a context load (load previously saved contents of data segment of shared object)operation can be performed on the shared object library. This way the context for each media stream can be saved and loaded before and after processing the "other" media stream respectively.

Thanks in advance.
Regards,
Vikram.

Why not save/load just the modified global/static data ?

vragukumar 08-26-2010 10:26 AM

Sergei,

Thank you for your response.

Yes that is a possibility, but it turns out that what you are suggesting is a rather cumbersome solution for us. These shared objects are generated from third party code. Not all global symbols are exported by the shared object. And it is rather tedious to go through 50+ files to determined all global/ static declarations and export them.

This is the reason why we are looking for an approach where the entire data segment of the shared object can be saved/reloaded.

Thanks and Regards,
Vikram.

johnsfine 08-26-2010 11:29 AM

You could read /proc/self/smaps to find the writable 4KB pages that were mapped by the act of loading the .so.

Those are effectively what you seem to mean by "data segment" of the shared object, but

If the code in the shared object allocates and deallocates any objects from the heap, the shared objects "data segment" would contain only pointers to those heap objects. If you saved/restored/swapped just the "data segment" you would be corrupting the heap any time you save/restore across a boundary of allocate or deallocate on the heap.


All times are GMT -5. The time now is 08:50 AM.