Subversion Repositories Kolibri OS

Rev

Rev 5022 | Rev 6536 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5022 Rev 5190
Line 51... Line 51...
51
    char       *img_path;
51
    char       *img_path;
52
 
52
 
Line 53... Line 53...
53
    uint32_t    refcount;
53
    uint32_t    refcount;
Line 54... Line 54...
54
 
54
 
55
    void       *start;
55
    char       *start;
Line 56... Line 56...
56
    uint32_t    end;
56
    char       *end;
Line 57... Line 57...
57
 
57
 
58
    void       *entry;
58
    void       *entry;
Line 68... Line 68...
68
    char *path;
68
    char *path;
69
    int   path_len;
69
    int   path_len;
70
}dll_path_t;
70
}dll_path_t;
71
 
71
 
Line 72... Line -...
72
module_t* load_library(const char *name);
-
 
Line 73... Line 72...
73
 
72
 
Line 74... Line 73...
74
LIST_HEAD(path_list);
73
LIST_HEAD(path_list);
75
 
74
 
Line 229... Line 228...
229
    exp =  MakePtr(PIMAGE_EXPORT_DIRECTORY, libc_image,
228
    exp =  MakePtr(PIMAGE_EXPORT_DIRECTORY, libc_image,
230
                   nt->OptionalHeader.DataDirectory[0].VirtualAddress);
229
                   nt->OptionalHeader.DataDirectory[0].VirtualAddress);
231
 
230
 
Line 232... Line 231...
232
    libc_dll.start = libc_image;
231
    libc_dll.start = libc_image;
233
    libc_dll.end   = MakePtr(uint32_t,libc_image, nt->OptionalHeader.SizeOfImage);
232
    libc_dll.end   = MakePtr(char*,libc_image, nt->OptionalHeader.SizeOfImage);
Line 234... Line 233...
234
 
233
 
235
    libc_dll.img_hdr  = nt;
234
    libc_dll.img_hdr  = nt;
236
    libc_dll.img_sec  = MakePtr(PIMAGE_SECTION_HEADER,nt, sizeof(IMAGE_NT_HEADERS32));
235
    libc_dll.img_sec  = MakePtr(PIMAGE_SECTION_HEADER,nt, sizeof(IMAGE_NT_HEADERS32));
237
    libc_dll.img_exp  = MakePtr(PIMAGE_EXPORT_DIRECTORY,libc_image,
236
    libc_dll.img_exp  = MakePtr(PIMAGE_EXPORT_DIRECTORY,libc_image,
Line 340... Line 339...
340
    };
339
    };
341
    return img_base;
340
    return img_base;
342
};
341
};
343
 
342
 
Line 344... Line -...
344
//static jmp_buf loader_env;
-
 
345
//static loader_recursion;
-
 
Line 346... Line 343...
346
 
343
 
347
int link_image(void *img_base, PIMAGE_IMPORT_DESCRIPTOR imp)
344
int link_image(void *img_base, PIMAGE_IMPORT_DESCRIPTOR imp)
348
{
345
{
349
    static jmp_buf loader_env;
346
    static jmp_buf loader_env;
Line 455... Line 452...
455
                        continue;
452
                        continue;
456
                    };
453
                    };
457
                };
454
                };
458
 
455
 
Line 459... Line -...
459
 
-
 
460
                minn = 0;
456
                minn = 0;
461
                maxn = exp->NumberOfNames - 1;
457
                maxn = exp->NumberOfNames - 1;
462
                while (minn <= maxn)
458
                while (minn <= maxn)
463
                {
459
                {
464
                    int mid;
460
                    int mid;
Line 579... Line 575...
579
    return  MakePtr(void*, raw, nt->OptionalHeader.AddressOfEntryPoint);
575
    return  MakePtr(void*, raw, nt->OptionalHeader.AddressOfEntryPoint);
580
};
576
};
Line 581... Line 577...
581
 
577
 
582
 
578
 
Line -... Line 579...
-
 
579
void *get_proc_address(void *handle, const char *proc_name)
583
void *get_proc_address(module_t *module, char *proc_name)
580
{
584
{
581
 
585
 
582
    module_t *module = handle;
Line 586... Line 583...
586
    PIMAGE_DOS_HEADER        expdos;
583
    PIMAGE_DOS_HEADER        expdos;
Line 680... Line 677...
680
 
677
 
Line 681... Line 678...
681
    return img_base;
678
    return img_base;
682
}
679
}
Line 683... Line 680...
683
 
680
 
684
module_t* load_library(const char *name)
681
void* load_library(const char *name)
685
{
682
{
686
    PIMAGE_DOS_HEADER        dos;
683
    PIMAGE_DOS_HEADER        dos;
687
    PIMAGE_NT_HEADERS32      nt;
684
    PIMAGE_NT_HEADERS32      nt;
Line 736... Line 733...
736
 
733
 
Line 737... Line 734...
737
    if( unlikely(img_base == NULL) )
734
    if( unlikely(img_base == NULL) )
738
    {
735
    {
739
        printf("unable to load %s\n", name);
736
        printf("unable to load %s\n", name);
740
        return NULL;
737
        return 0;
741
    };
738
    };
Line 742... Line 739...
742
 
739
 
Line 743... Line 740...
743
    module = (module_t*)malloc(sizeof(module_t));
740
    module = malloc(sizeof(module_t));
744
 
741
 
745
    if(unlikely(module == NULL))
742
    if(unlikely(module == NULL))
746
    {
743
    {
Line 760... Line 757...
760
    nt  =  MakePtr( PIMAGE_NT_HEADERS32, dos, dos->e_lfanew);
757
    nt  =  MakePtr( PIMAGE_NT_HEADERS32, dos, dos->e_lfanew);
761
    exp =  MakePtr(PIMAGE_EXPORT_DIRECTORY, img_base,
758
    exp =  MakePtr(PIMAGE_EXPORT_DIRECTORY, img_base,
762
               nt->OptionalHeader.DataDirectory[0].VirtualAddress);
759
               nt->OptionalHeader.DataDirectory[0].VirtualAddress);
763
 
760
 
Line 764... Line 761...
764
    module->end   = MakePtr(uint32_t,img_base, nt->OptionalHeader.SizeOfImage);
761
    module->end   = MakePtr(char*,img_base, nt->OptionalHeader.SizeOfImage);
Line 765... Line 762...
765
 
762
 
766
    module->img_hdr  = nt;
763
    module->img_hdr  = nt;
767
    module->img_sec  = MakePtr(PIMAGE_SECTION_HEADER,nt, sizeof(IMAGE_NT_HEADERS32));
764
    module->img_sec  = MakePtr(PIMAGE_SECTION_HEADER,nt, sizeof(IMAGE_NT_HEADERS32));
768
    module->img_exp  = MakePtr(PIMAGE_EXPORT_DIRECTORY, img_base,
765
    module->img_exp  = MakePtr(PIMAGE_EXPORT_DIRECTORY, img_base,
Line 800... Line 797...
800
    free(module);
797
    free(module);
801
err1:
798
err1:
802
    user_free(img_base);
799
    user_free(img_base);
803
    return NULL;
800
    return NULL;
804
 
801
};
805
};
-
 
806
802
 
Line -... Line 803...
-
 
803
void enumerate_libraries(int (*callback)(void *handle, const char* name,
-
 
804
                                         uint32_t base, uint32_t size, void *user_data),
-
 
805
                         void *user_data)
-
 
806
{
-
 
807
    module_t *mod = &libc_dll;
Line -... Line 808...
-
 
808
 
-
 
809
    do
-
 
810
    {
-
 
811
        if(0 == callback(mod, mod->img_name, (uint32_t)mod->start,
-
 
812
                         mod->end - mod->start, user_data))
-
 
813
            break;
-
 
814
        mod = (module_t*)mod->list.next;
-
 
815
    }while(mod != &libc_dll);