Ignore:
Timestamp:
Oct 14, 2008, 6:30:00 PM (13 years ago)
Author:
gz
Message:

Merge/bootstrap assorted low level stuff from trunk - kernel, syscall stuff, lowmem-bias, formatting tweaks, a few bug fixes included

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/working-0711/ccl/lisp-kernel/pmcl-kernel.c

    r10944 r11089  
    116116
    117117#include <fenv.h>
     118#include <sys/stat.h>
    118119
    119120#ifndef MAP_NORESERVE
     
    407408#endif
    408409#ifdef WINDOWS
     410#define MAXIMUM_MAPPABLE_MEMORY (1U<<30)
     411#endif
     412#ifdef FREEBSD
    409413#define MAXIMUM_MAPPABLE_MEMORY (1U<<30)
    410414#endif
     
    794798
    795799
    796 #if defined(DARWIN) || defined(WINDOWS)
     800/* Check for the existence of a file named by 'path'; return true
     801   if it seems to exist, without checking size, permissions, or
     802   anything else. */
     803Boolean
     804probe_file(char *path)
     805{
     806  struct stat st;
     807
     808  return (stat(path,&st) == 0);
     809}
     810
     811
    797812#ifdef WINDOWS
    798813/* Chop the trailing ".exe" from the kernel image name */
     
    812827#endif
    813828
     829char *
     830path_by_appending_image(char *path)
     831{
     832  int len = strlen(path) + strlen(".image") + 1;
     833  char *copy = (char *) malloc(len);
     834
     835  if (copy) {
     836    strcpy(copy, path);
     837    strcat(copy, ".image");
     838  }
     839  return copy;
     840}
     841
     842char *
     843case_inverted_path(char *path)
     844{
     845  char *copy = strdup(path), *base = copy, *work = copy, c;
     846  if (copy == NULL) {
     847    return NULL;
     848  }
     849  while(*work) {
     850    if (*work++ == '/') {
     851      base = work;
     852    }
     853  }
     854  work = base;
     855  while ((c = *work) != '\0') {
     856    if (islower(c)) {
     857      *work++ = toupper(c);
     858    } else {
     859      *work++ = tolower(c);
     860    }
     861  }
     862  return copy;
     863}
    814864/*
    815865   The underlying file system may be case-insensitive (e.g., HFS),
     
    825875  char *path = orig;
    826876#endif
    827   int len = strlen(path) + strlen(".image") + 1;
    828   char *copy = (char *) malloc(len);
    829 
    830   if (copy) {
    831     strcpy(copy, path);
    832     strcat(copy, ".image");
    833   }
    834   return copy;
    835 }
    836 
    837 #else
    838 char *
    839 default_image_name(char *orig)
    840 {
    841   char *copy = strdup(orig), *base = copy, *work = copy, c;
    842   if (copy == NULL) {
    843     return NULL;
    844   }
    845   while(*work) {
    846     if (*work++ == '/') {
    847       base = work;
    848     }
    849   }
    850   work = base;
    851   while ((c = *work) != '\0') {
    852     if (islower(c)) {
    853       *work++ = toupper(c);
    854     } else {
    855       *work++ = tolower(c);
    856     }
    857   }
    858   return copy;
    859 }
    860 #endif
     877  char *image_name = path_by_appending_image(path);
     878#if !defined(WINDOWS) && !defined(DARWIN)
     879  if (!probe_file(image_name)) {
     880    char *legacy = case_inverted_path(path);
     881    if (probe_file(legacy)) {
     882      image_name = legacy;
     883    }
     884  }
     885#endif
     886  return image_name;
     887}
     888
    861889
    862890
     
    11451173terminate_lisp()
    11461174{
    1147   ExitProcess(EXIT_FAILURE);
     1175  _exit(EXIT_FAILURE);
    11481176}
    11491177#else
     
    11591187
    11601188#ifdef DARWIN
    1161 #ifdef PPC64
    11621189#define min_os_version "8.0"    /* aka Tiger */
    1163 #else
    1164 #define min_os_version "7.0"    /* aka Panther */
    1165 #endif
    11661190#endif
    11671191#ifdef LINUX
     
    12011225  int disp;
    12021226 
    1203   if (old != (pc)0x5000) {
    1204     new = mmap((pc) 0x5000,
     1227  if (old != (pc)SPJUMP_TARGET_ADDRESS) {
     1228    new = mmap((pc) SPJUMP_TARGET_ADDRESS,
    12051229               0x1000,
    12061230               PROT_READ | PROT_WRITE | PROT_EXEC,
     
    12081232               -1,
    12091233               0);
    1210     if (new != (pc) 0x5000) {
     1234    if (new != (pc) SPJUMP_TARGET_ADDRESS) {
     1235      perror("remap spjump");
    12111236      _exit(1);
    12121237    }
     
    12391264  DWORD old_protect;
    12401265
    1241   if (!VirtualProtect((pc) 0x15000,
    1242                       0x1000,
    1243                       PAGE_EXECUTE_READWRITE,
    1244                       &old_protect)) {
    1245     wperror("VirtualProtect spjump");
    1246     _exit(1);
    1247   }
    1248   memmove((pc) 0x15000, &spjump_start, 0x1000);
     1266  if ((void *)(&spjump_start) != (void *) SPJUMP_TARGET_ADDRESS) {
     1267    if (!VirtualProtect((pc) SPJUMP_TARGET_ADDRESS,
     1268                        0x1000,
     1269                        PAGE_EXECUTE_READWRITE,
     1270                        &old_protect)) {
     1271      wperror("VirtualProtect spjump");
     1272      _exit(1);
     1273    }
     1274    memmove((pc) SPJUMP_TARGET_ADDRESS, &spjump_start, 0x1000);
     1275  }
    12491276}
    12501277#else
     
    12531280{
    12541281  extern opcode spjump_start;
    1255   pc new = mmap((pc) 0x15000,
     1282  pc new = mmap((pc) SPJUMP_TARGET_ADDRESS,
    12561283                0x1000,
    12571284                PROT_READ | PROT_WRITE | PROT_EXEC,
     
    18731900load_image(char *path)
    18741901{
    1875   int fd = open(path, O_RDONLY, 0666);
     1902  int fd = open(path, O_RDONLY, 0666), err;
    18761903  LispObj image_nil = 0;
     1904
     1905  errno = 0;
    18771906  if (fd > 0) {
    18781907    openmcl_image_file_header ih;
     
    18821911       we'll instead keep the original file open.
    18831912    */
     1913    err = errno;
    18841914    if (!image_nil) {
    18851915      close(fd);
    18861916    }
     1917#ifdef WINDOWS
     1918    /* We currently don't actually map the image, and leaving the file
     1919       open seems to make it difficult to write to reliably. */
     1920    if (image_nil) {
     1921      close(fd);
     1922    }
     1923#endif
     1924  } else {
     1925    err = errno;
    18871926  }
    18881927  if (image_nil == 0) {
    1889     fprintf(stderr, "Couldn't load lisp heap image from %s:\n%s\n", path, strerror(errno));
     1928    if (err == 0) {
     1929      fprintf(stderr, "Couldn't load lisp heap image from %s\n", path);
     1930    } else {
     1931      fprintf(stderr, "Couldn't load lisp heap image from %s:\n%s\n", path, strerror(err));
     1932    }
    18901933    exit(-1);
    18911934  }
Note: See TracChangeset for help on using the changeset viewer.