Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. #ifndef LIBRARY_H
  2. #define LIBRARY_H
  3.  
  4. #pragma pack(push,1)
  5.         typedef struct
  6.         {
  7.                 char    *name;
  8.                 void    *data;
  9.         } struct_import_lib_init;
  10. #pragma pack(pop)
  11.  
  12. typedef struct
  13. {
  14.         int (*load)(char *path);
  15.         unsigned int (*get)(char *name);
  16. } OBJECT_LIBRARY;
  17.  
  18. static char init_load_obj = 0;
  19.  
  20. static int (* _stdcall _ptr_load_dll_)(char *path);
  21. static unsigned int (* _stdcall _ptr_get_dll_)(char *path);
  22.  
  23. static inline int _OBJECT__LOAD_(char *path)
  24. {
  25.         struct_import_lib_init *imp;
  26.         if(!init_load_obj)
  27.         {
  28.                 asm("int $0x40":"=a"(imp):"a"(68), "b"(19), "c"("/sys/lib/library.obj"));
  29.                 _ptr_load_dll_ = imp[0].data;
  30.                 _ptr_get_dll_ = imp[1].data;
  31.                 init_load_obj = 1;
  32.         }
  33.         return _ptr_load_dll_(path);
  34. }
  35.  
  36. static inline unsigned int _OBJECT__GET_(char *name)
  37. {
  38.         return _ptr_get_dll_(name);
  39. }
  40.  
  41. static inline OBJECT_LIBRARY library = {&_OBJECT__LOAD_,&_OBJECT__GET_};
  42.  
  43. /*
  44.         Example:
  45.         void*(* stdcall name_func)(...);
  46.         library.load("/sys/lib/... .obj");
  47.         name_func = library.get("name_function");
  48.         name_func(...);
  49. */
  50.  
  51. #endif