Changeset 1453 for trunk/src


Ignore:
Timestamp:
Mar 30, 2008, 4:06:49 PM (17 years ago)
Author:
bird
Message:

ported to unix.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/electric.c

    r915 r1453  
    2929# else
    3030#  include <sys/mman.h>
     31#  include <errno.h>
    3132# endif
    3233# include <string.h>
     
    4748static void fatal_error (const char *msg)
    4849{
     50#ifdef _MSC_VER
    4951  fprintf (stderr, "electric heap error: %s\n", msg);
    5052  __debugbreak ();
     53#else
     54  fprintf (stderr, "electric heap error: %s (errno=%d)\n", msg, errno);
     55  __asm__ ("int3"); /* not portable... */
     56#endif
    5157  abort ();
    5258  exit (1);
     
    5965    fatal_error ("VirtualFree failed");
    6066# else
     67  if (munmap(ptr, aligned))
     68    fatal_error ("munmap failed");
    6169# endif
    6270}
     
    99107    fatal_error ("failed to protect freed memory");
    100108# else
     109  if (mprotect(hdr, aligned - 0x1000, PROT_NONE))
     110    fatal_error ("failed to protect freed memory");
    101111# endif
    102112
     
    124134        fatal_error ("failed to set guard page protection");
    125135# else
     136      hdr = mmap(NULL, aligned, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
     137      if (hdr == MAP_FAILED)
     138        hdr = 0;
     139      if (hdr
     140       && mprotect((char *)hdr + aligned - 0x1000, 0x1000, PROT_NONE))
     141        fatal_error ("failed to set guard page protection");
    126142# endif
    127143      if (hdr)
Note: See TracChangeset for help on using the changeset viewer.