Changeset 832

Show
Ignore:
Timestamp:
08/06/08 14:47:12 (4 years ago)
Author:
mwhitworth
Message:

Map module into SysMemoryMap, rather than SysRead.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • Whitix/trunk/user/system/moduleadd.c

    r551 r832  
    1717        FILE* file=fopen(name, "r"); 
    1818        unsigned int size; 
    19         char* buf; 
    2019        int ret; 
     20        DWORD address; 
    2121 
    2222        if (!file) 
     23        { 
     24                printf("moduleadd: Could not open %s\n", name); 
    2325                return 1; 
     26        } 
    2427 
     28        /* Get the file size. */ 
    2529        fseek(file, 0, SEEK_END); 
    26  
    2730        size=ftell(file); 
    28  
    2931        fseek(file, 0, SEEK_SET); 
    3032 
    31         buf=(char*)malloc(size); 
    32         if (!buf) 
     33        address=SysMemoryMap(0, size, 5, file->fd, 0, _SYS_MMAP_PRIVATE); 
     34 
     35        if (!address) 
    3336        { 
    34                 printf("Could not allocate memory. Exiting.\n"); 
    35                 return 2; 
     37                printf("Could not read %s\n", name); 
     38                return 1; 
    3639        } 
    3740 
    38         fread(buf, size, 1, file); 
     41        ret=SysModuleAdd(address, size); 
    3942 
    40         ret=SysModuleAdd(buf, size); 
    41  
    42         free(buf); 
     43        SysMemoryUnmap(address, size); 
    4344 
    4445        /* Check ret. */ 
    4546        if (ret) 
    4647                printf("moduleadd: Error adding module %s to kernel: %s\n", name, strerror(ret)); 
     48 
     49        fclose(file); 
    4750 
    4851        return ret;