Changeset 8707


Ignore:
Timestamp:
Mar 11, 2008, 4:35:36 PM (12 years ago)
Author:
andreas
Message:
  • Change type of all memory size parameters from int to natural
  • API for memory mapping files, with implementation for UNIX and a cheat for Windows
Location:
branches/win64/lisp-kernel
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/win64/lisp-kernel/image.c

    r8547 r8707  
    163163}
    164164
    165 #ifdef WINDOWS
    166 void
    167 load_image_section(int fd, openmcl_image_section_header *sect)
    168 {
    169 }
    170 #else
    171165void
    172166load_image_section(int fd, openmcl_image_section_header *sect)
     
    183177  switch(sect->code) {
    184178  case AREA_READONLY:
    185     addr = mmap(pure_space_active,
    186                 align_to_power_of_2(mem_size,log2_page_size),
    187                 PROT_READ | PROT_EXEC,
    188                 MAP_PRIVATE | MAP_FIXED,
    189                 fd,
    190                 pos);
    191     if (addr != pure_space_active) {
     179    if (!MapFile(pure_space_active,
     180                 pos,
     181                 align_to_power_of_2(mem_size,log2_page_size),
     182                 MEMPROTECT_RX,
     183                 fd)) {
    192184      return;
    193185    }
     
    199191
    200192  case AREA_STATIC:
    201     addr = mmap(static_space_active,
    202                 align_to_power_of_2(mem_size,log2_page_size),
    203                 PROT_READ | PROT_WRITE | PROT_EXEC,
    204                 MAP_PRIVATE | MAP_FIXED,
    205                 fd,
    206                 pos);
    207     if (addr != static_space_active) {
     193    if (!MapFile(static_space_active,
     194                 pos,
     195                 align_to_power_of_2(mem_size,log2_page_size),
     196                 MEMPROTECT_RWX,
     197                 fd)) {
    208198      return;
    209199    }
     
    216206  case AREA_DYNAMIC:
    217207    a = allocate_dynamic_area(mem_size);
    218     addr = mmap(a->low,
    219                 align_to_power_of_2(mem_size,log2_page_size),
    220                 PROT_READ | PROT_WRITE | PROT_EXEC,
    221                 MAP_PRIVATE | MAP_FIXED,
    222                 fd,
    223                 pos);
    224     if (addr != a->low) {
     208    if (!MapFile(a->low,
     209                 pos,
     210                 align_to_power_of_2(mem_size,log2_page_size),
     211                 MEMPROTECT_RWX,
     212                 fd)) {
    225213      return;
    226214    }
    227 
    228215
    229216    a->static_dnodes = sect->static_dnodes;
     
    242229  lseek(fd, pos+advance, SEEK_SET);
    243230}
    244 #endif
    245 
    246 #ifdef WINDOWS
    247 LispObj
    248 load_openmcl_image(int fd, openmcl_image_file_header *h)
    249 {
    250 }
    251 #else
     231
    252232LispObj
    253233load_openmcl_image(int fd, openmcl_image_file_header *h)
     
    332312  return image_nil;
    333313}
    334 #endif
    335314 
    336315void
  • branches/win64/lisp-kernel/memory.c

    r8696 r8707  
    157157
    158158LogicalAddress
    159 ReserveMemoryForHeap(LogicalAddress want, int totalsize)
     159ReserveMemoryForHeap(LogicalAddress want, natural totalsize)
    160160{
    161161  LogicalAddress start;
     
    208208
    209209int
    210 CommitMemory (LogicalAddress start, int len) {
     210CommitMemory (LogicalAddress start, natural len) {
    211211  LogicalAddress rc;
    212212#ifdef WINDOWS
     
    234234
    235235void
    236 UnCommitMemory (LogicalAddress start, int len) {
     236UnCommitMemory (LogicalAddress start, natural len) {
    237237#ifdef WINDOWS
    238238  int rc = VirtualFree(start, len, MEM_DECOMMIT);
     
    257257
    258258LogicalAddress
    259 MapMemory(LogicalAddress addr, int nbytes, int protection)
     259MapMemory(LogicalAddress addr, natural nbytes, int protection)
    260260{
    261261#ifdef WINDOWS
     
    267267
    268268LogicalAddress
    269 MapMemoryForStack(int nbytes)
     269MapMemoryForStack(natural nbytes)
    270270{
    271271#ifdef WINDOWS
     
    277277
    278278int
    279 UnMapMemory(LogicalAddress addr, int nbytes)
     279UnMapMemory(LogicalAddress addr, natural nbytes)
    280280{
    281281#ifdef WINDOWS
     
    288288
    289289int
    290 ProtectMemory(LogicalAddress addr, int nbytes)
     290ProtectMemory(LogicalAddress addr, natural nbytes)
    291291{
    292292#ifdef WINDOWS
     
    311311
    312312int
    313 UnProtectMemory(LogicalAddress addr, int nbytes)
     313UnProtectMemory(LogicalAddress addr, natural nbytes)
    314314{
    315315#ifdef WINDOWS
     
    318318#else
    319319  return mprotect(addr, nbytes, PROT_READ|PROT_WRITE|PROT_EXEC);
     320#endif
     321}
     322
     323int
     324MapFile(LogicalAddress addr, natural pos, natural nbytes, int permissions, int fd) {
     325#ifdef WINDOWS
     326#if 0
     327  /* Lots of hair in here: mostly alignment issues, but also address space reservation */
     328  HANDLE hFile, hFileMapping;
     329  LPVOID rc;
     330  DWORD desiredAccess;
     331
     332  if (permissions == MEMPROTECT_RWX) {
     333    permissions |= PAGE_WRITECOPY;
     334    desiredAccess = FILE_MAP_READ|FILE_MAP_WRITE|FILE_MAP_COPY|FILE_MAP_EXECUTE;
     335  } else {
     336    desiredAccess = FILE_MAP_READ|FILE_MAP_COPY|FILE_MAP_EXECUTE;
     337  }
     338
     339  hFile = _get_osfhandle(fd);
     340  hFileMapping = CreateFileMapping(hFile, NULL, permissions,
     341                                   (nbytes >> 32), (nbytes & 0xffffffff), NULL);
     342 
     343  if (!hFileMapping) {
     344    wperror("CreateFileMapping");
     345    return false;
     346  }
     347
     348  rc = MapViewOfFileEx(hFileMapping,
     349                       desiredAccess,
     350                       (pos >> 32),
     351                       (pos & 0xffffffff),
     352                       nbytes,
     353                       addr);
     354#else
     355  size_t count;
     356
     357  CommitMemory(addr, nbytes);
     358  lseek(fd, pos, SEEK_SET);
     359  count = read(fd, pos, nbytes);
     360 
     361  return count == nbytes;
     362#endif
     363#else
     364  return mmap(addr, nbytes, permissions, MAP_PRIVATE|MAP_FIXED, fd, pos) != MAP_FAILED;
    320365#endif
    321366}
  • branches/win64/lisp-kernel/memprotect.h

    r8696 r8707  
    5151
    5252LogicalAddress
    53 ReserveMemoryForHeap(LogicalAddress want, int totalsize);
     53ReserveMemoryForHeap(LogicalAddress want, natural totalsize);
    5454
    5555int
    56 CommitMemory (LogicalAddress start, int len);
     56CommitMemory (LogicalAddress start, natural len);
    5757
    5858void
    59 UnCommitMemory (LogicalAddress start, int len);
     59UnCommitMemory (LogicalAddress start, natural len);
    6060
    6161LogicalAddress
    62 MapMemory(LogicalAddress addr, int nbytes, int protection);
     62MapMemory(LogicalAddress addr, natural nbytes, int protection);
    6363
    6464LogicalAddress
    65 MapMemoryForStack(int nbytes);
     65MapMemoryForStack(natural nbytes);
    6666
    6767int
    68 UnMapMemory(LogicalAddress addr, int nbytes);
     68UnMapMemory(LogicalAddress addr, natural nbytes);
    6969
    7070int
    71 ProtectMemory(LogicalAddress, int);
     71ProtectMemory(LogicalAddress, natural);
    7272
    7373int
    74 UnProtectMemory(LogicalAddress, int);
     74UnProtectMemory(LogicalAddress, natural);
     75
     76int
     77MapFile(LogicalAddress addr, natural pos, natural nbytes, int permissions, int fd);
    7578
    7679typedef enum {
Note: See TracChangeset for help on using the changeset viewer.