Changeset 93266c5 in git


Ignore:
Timestamp:
Dec 7, 1998, 9:48:27 AM (25 years ago)
Author:
Hans Schönemann <hannes@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
a8213b0b8b3ace6b1fef40b50aac8147ab7b4381
Parents:
7f0e6fea6bba489a550307279a2809c1dd27d593
Message:
* hannes: added support for page.c (define PAGE_TEST)


git-svn-id: file:///usr/local/Singular/svn/trunk@2722 2c84dea3-7e68-4137-9b89-c4e89433aadc
Location:
Singular
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • Singular/Makefile.in

    r7f0e6f r93266c5  
    8686
    8787CSOURCES=gmalloc.c mmalloc.c mmheap.c mmpage.c mmcheck.c  mmisc.c mmtables.c \
    88     mmbt.c weight0.c find_exec.c getopt.c fereadl.c
     88    mmbt.c weight0.c find_exec.c getopt.c fereadl.c page.c
    8989
    9090SOURCES=${CSOURCES} ${CXXSOURCES} grammar.y scanner.l libparse.l spSpolyLoop.pl
     
    9696        cntrlc.h ipprint.h ring.h timer.h \
    9797        febase.h ipshell.h shortfl.h tok.h \
    98         mmemory.h mmprivate.h mmheap.h mmpage.h \
     98        mmemory.h mmprivate.h mmheap.h mmpage.h page.h \
    9999        ffields.h khstd.h silink.h \
    100100        fglm.h comm.h kstd1.h modulop.h sing_dbm.h weight.h \
     
    124124     ipid.o ipshell.o iplib.o ipassign.o ipconv.o ipprint.o\
    125125     polys.o polys0.o polys1.o polys-impl.o extra.o\
    126      mminit.o mmtables.o mmalloc.o mmheap.o mmpage.o \
     126     mminit.o mmtables.o mmalloc.o mmheap.o mmpage.o page.o \
    127127     mmisc.o mmcheck.o mmbt.o sing_dld.o sing_dbm.o silink.o \
    128128     sing_mp.o fglm.o fglmzero.o fglmvec.o fglmhom.o fglmgauss.o cntrlc.o \
     
    349349        pcv.og
    350350
    351 OBJG2= mmalloc.og mmheap.og mmpage.og mmcheck.og mmbt.og \
     351OBJG2= mmalloc.og mmheap.og mmpage.og mmcheck.og mmbt.og page.og \
    352352     mmisc.og mmtables.og weight0.og find_exec.og getopt.og fereadl.og
    353353
     
    425425        pcv.op
    426426
    427 OBJP2= mmalloc.op mmheap.op mmpage.op mmcheck.op mmbt.op \
     427OBJP2= mmalloc.op mmheap.op mmpage.op mmcheck.op mmbt.op page.op \
    428428     mmisc.op mmtables.op weight0.op find_exec.op getopt.op fereadl.op
    429429
     
    451451        pcv.ob
    452452
    453 OBJB2= mmalloc.ob mmheap.ob mmpage.ob mmcheck.ob mmbt.ob \
     453OBJB2= mmalloc.ob mmheap.ob mmpage.ob mmcheck.ob mmbt.ob page.ob\
    454454     mmisc.ob mmtables.ob weight0.ob find_exec.ob getopt.ob fereadl.ob
    455455
  • Singular/cntrlc.cc

    r7f0e6f r93266c5  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: cntrlc.cc,v 1.20 1998-09-24 09:59:36 Singular Exp $ */
     4/* $Id: cntrlc.cc,v 1.21 1998-12-07 08:48:23 Singular Exp $ */
    55/*
    66* ABSTRACT - interupt handling
     
    132132
    133133#ifdef PAGE_TEST
    134 #ifdef PAGE_COUNT
    135   static int page_segv_count=0;
    136 #endif
    137134void sig11_handler(int sig, sigcontext s)
    138135{
    139 #ifdef PAGE_COUNT
    140   page_segv_count++;
    141 #endif
    142   long base =s.cr2&(~4095);
    143   int i=page_tab_ind-1;
     136  unsigned long base =(unsigned long)(s.cr2&(~4095));
     137  int i;
     138  i=mmPage_tab_ind-1;
     139  while (mmPage_tab[i]!=base) i--;
     140  mmUse_tab[i]='1';
     141  mmPage_tab_acc++;
     142  mmPage_AllowAccess((void *)base);
     143  signal(SIGSEGV,(si_hdl_typ)sig11_handler);
     144}
     145
     146void sigalarm_handler(int sig, sigcontext s)
     147{
     148  int i=mmPage_tab_ind-1;
     149  mmWriteStat();
    144150  for(;i>=0;i--)
    145151  {
    146     if (page_tab[i]==base) { use_tab[i]='X'; break; }
    147   }
    148   Page_AllowAccess((void *)base, 4096);
    149   signal(SIGSEGV,(si_hdl_typ)sig11_handler);
    150 }
    151 
    152 void sigalarm_handler(int sig, sigcontext s)
    153 {
    154   int i=page_tab_ind-1;
    155 #ifdef PAGE_COUNT
    156   write(2,use_tab,page_segv_count);
    157   page_segv_count=0;
    158 #else
    159   write(2,use_tab,page_tab_ind);
    160 #endif
    161   write(2,"<\n",2);
    162   for(;i>=0;i--)
    163   {
    164     Page_DenyAccess((void *)page_tab[i],4096);
    165 #ifndef PAGE_COUNT
    166     use_tab[i]=' ';
    167 #endif
     152    mmPage_DenyAccess((void *)mmPage_tab[i]);
    168153  }
    169154  struct itimerval t,o;
     
    176161  signal(SIGVTALRM,(si_hdl_typ)sigalarm_handler);
    177162}
    178 
    179163#endif
    180164
     
    187171#ifdef PAGE_TEST
    188172  signal(SIGSEGV,(si_hdl_typ)sig11_handler);
    189   page_tab_ind=0;
    190173  struct itimerval t,o;
    191174  memset(&t,0,sizeof(t));
  • Singular/misc.cc

    r7f0e6f r93266c5  
    1919#include "cntrlc.h"
    2020#include "mmemory.h"
     21#include "page.h"
    2122#include "ipid.h"
    2223#include "ipshell.h"
     
    8889void m2_end(short i)
    8990{
     91  #ifdef PAGE_TEST
     92  mmEndStat();
     93  #endif
    9094  #ifdef HAVE_TCL
    9195  if (tclmode)
  • Singular/mmpage.h

    r7f0e6f r93266c5  
    11#ifndef MMPAGE_H
    22#define MMPAGE_H
    3 #include "mod2.h"
     3
     4#ifdef PAGE_TEST
     5#undef PALLOC
     6#define PALLOC mmPage_Create
     7#undef PFREE
     8#define PFREE mmPage_Delete
     9#endif
    410
    511/***********************************************************************
  • Singular/mmprivate.h

    r7f0e6f r93266c5  
    44*  Computer Algebra System SINGULAR     *
    55****************************************/
    6 /* $Id: mmprivate.h,v 1.1 1998-12-02 13:57:36 obachman Exp $ */
     6/* $Id: mmprivate.h,v 1.2 1998-12-07 08:48:25 Singular Exp $ */
    77/*
    88* ABSTRACT
    99*/
    10 #include "mod2.h"
    1110#include "structs.h"
    1211#include "mmheap.h"
  • Singular/mod2.h.in

    r7f0e6f r93266c5  
    346346/* #define MM_STAT 1 */
    347347/* #define PAGE_TEST */
    348 /* #define PAGE_COUNT */
    349348
    350349/* define YYDEBUG 1 for debugging bison texts, 0 otherwise */
     
    384383#define buildin_rand 1
    385384#endif
    386 #endif
    387 
    388 #ifdef PAGE_COUNT
    389 #define PAGE_TEST
    390385#endif
    391386
  • Singular/page.c

    r7f0e6f r93266c5  
    1212#include <sys/types.h>
    1313#include <sys/times.h>
    14 
    15 unsigned long page_tab[2048];
    16 char          use_tab [2048];
    17 int           page_tab_ind=2049;
    18 void *
    19 Page_Create(size_t size);
    20 void
    21 Page_AllowAccess(void * address, size_t size);
    22 void
    23 Page_DenyAccess(void * address, size_t size);
    24 size_t
    25 Page_Size(void);
     14#include "tok.h"
     15#include "page.h"
     16
     17unsigned long mmPage_tab[MAX_PAGE_TAB];
     18char          mmUse_tab [MAX_PAGE_TAB];
     19int           mmPage_tab_ind=0;
     20int           mmPage_tab_acc=0;
     21static caddr_t  startAddr = (caddr_t) 0;
     22
    2623#ifndef  PROT_NONE
    2724#define  PROT_NONE  0
     
    3229#endif
    3330
    34 static caddr_t  startAddr = (caddr_t) 0;
    3531
    3632extern int  sys_nerr;
    3733extern char *  sys_errlist[];
    3834
    39 static const char *
    40 stringErrorReport(void)
     35static const char * mmStringErrorReport(void)
    4136{
    4237  if ( errno > 0 && errno < sys_nerr )
     
    5146#if defined(MAP_ANONYMOUS)
    5247void *
    53 Page_Create(size_t size)
     48mmPage_Create(size_t size)
    5449{
    5550  caddr_t    allocation;
     
    8681
    8782  if ( allocation == (caddr_t)-1 )
    88     printf("mmap() failed: %s", stringErrorReport());
    89 
    90   page_tab[page_tab_ind]=allocation;
    91   page_tab_ind++;
     83    printf("mmap() failed: %s", mmStringErrorReport());
     84
     85  if (mmPage_tab_ind<MAX_PAGE_TAB)
     86  {
     87    mmPage_tab[mmPage_tab_ind]=(long)allocation;
     88    if (mmPage_tab_ind==0)
     89    {
     90      memset(mmUse_tab,'0',MAX_PAGE_TAB);
     91    }
     92    mmPage_tab_ind++;
     93  }
    9294  return (void *)allocation;
    9395}
    9496#else
    95 void *
    96 Page_Create(size_t size)
     97void * mmPage_Create(size_t size)
    9798{
    9899  static int  devZeroFd = -1;
    99100  caddr_t    allocation;
    100101
    101   if ( devZeroFd == -1 ) {
     102  if ( devZeroFd == -1 )
     103  {
    102104    devZeroFd = open("/dev/zero", O_RDWR);
    103105    if ( devZeroFd < 0 )
    104       printf(
    105        "open() on /dev/zero failed: %s"
    106       ,stringErrorReport());
     106      printf( "open() on /dev/zero failed: %s",mmStringErrorReport());
    107107  }
    108108
     
    128128
    129129  if ( allocation == (caddr_t)-1 )
    130     printf("mmap() failed: %s", stringErrorReport());
    131 
    132   page_tab[page_tab_ind]=allocation;
    133   page_tab_ind++;
     130    printf("mmap() failed: %s", mmStringErrorReport());
     131
     132  if (mmPage_tab_ind<MAX_PAGE_TAB)
     133  {
     134    mmPage_tab[mmPage_tab_ind]=allocation;
     135    if (mmPage_tab_ind==0)
     136    {
     137      memset(mmUse_tab,'0',MAX_PAGE_TAB);
     138    }
     139    mmPage_tab_ind++;
     140  }
    134141  return (void *)allocation;
    135142}
    136143#endif
    137144
    138 static void
    139 mprotectFailed(void)
    140 {
    141   printf("mprotect() failed: %s", stringErrorReport());
    142 }
    143 
    144 void
    145 Page_AllowAccess(void * address, size_t size)
    146 {
    147   if ( mprotect((caddr_t)address, size, PROT_READ|PROT_WRITE) < 0 )
    148     mprotectFailed();
    149 }
    150 
    151 void
    152 Page_DenyAccess(void * address, size_t size)
    153 {
    154   if ( mprotect((caddr_t)address, size, PROT_NONE) < 0 )
    155     mprotectFailed();
    156 }
    157 
    158 void
    159 Page_Delete(void * address, size_t size)
    160 {
    161   if ( munmap((caddr_t)address, size) < 0 )
    162     Page_DenyAccess(address, size);
    163 }
    164 
    165 #if defined(_SC_PAGESIZE)
    166 size_t
    167 Page_Size(void)
    168 {
    169   return (size_t)sysconf(_SC_PAGESIZE);
    170 }
    171 #elif defined(_SC_PAGE_SIZE)
    172 size_t
    173 Page_Size(void)
    174 {
    175   return (size_t)sysconf(_SC_PAGE_SIZE);
    176 }
    177 #else
    178 /* extern int  getpagesize(); */
    179 size_t
    180 Page_Size(void)
    181 {
    182   return getpagesize();
    183 }
    184 #endif
    185 
    186 #endif
     145void mmPage_AllowAccess(void * address)
     146{
     147  if ( mprotect((caddr_t)address, 4096, PROT_READ|PROT_WRITE) < 0 )
     148    printf("mprotect(READ|WRITE) failed: %s", mmStringErrorReport());
     149}
     150
     151void mmPage_DenyAccess(void * address)
     152{
     153  if ( mprotect((caddr_t)address, 4096, PROT_NONE) < 0 )
     154    printf("mprotect(NONE) failed: %s", mmStringErrorReport());
     155}
     156
     157void mmPage_Delete(void * address)
     158{
     159  if ( munmap((caddr_t)address, 4096) < 0 )
     160    mmPage_DenyAccess(address);
     161}
     162
     163FILE *mmStatFile=NULL;
     164unsigned mmStatLines=0;
     165void mmWriteStat()
     166{
     167  int i,l,start;
     168  if (mmStatFile==NULL)
     169  {
     170    mmStatFile=fopen(MM_STAT_FILE,"w");
     171#if 0   
     172    fprintf(mmStatFile,"P1\n%d ???\n",MAX_PAGE_TAB);
     173#endif
     174  }
     175  if ((mmUse_tab[MAX_PAGE_TAB-1]=='0')
     176   || (mmUse_tab[MAX_PAGE_TAB-1]=='1'))
     177  {
     178    mmStatLines++;
     179    l=MAX_PAGE_TAB;
     180    start=0;
     181    fprintf(mmStatFile,"%d\n",mmPage_tab_acc);
     182    /* fwrite("#\n", 2, 1, mmStatFile);*/
     183#if 0
     184    fflush(mmStatFile);
     185#endif
     186    /* fwrite("#\n", 2, 1, mmStatFile);*/
     187#if 0
     188    do
     189    {
     190      i=min(70,l);
     191      fwrite(&(mmUse_tab[start]), i, 1, mmStatFile);
     192      fwrite("\n", 1, 1, mmStatFile);
     193      start+=i;
     194      l-=i;
     195    } while (l>0);
     196#endif
     197  }
     198  memset(mmUse_tab,'0',MAX_PAGE_TAB);
     199  mmPage_tab_acc=0;
     200}
     201
     202void mmEndStat()
     203{
     204  if (mmStatFile!=NULL)
     205  {
     206    mmWriteStat();
     207#if 0
     208    fprintf(mmStatFile,"# %d %d\n",MAX_PAGE_TAB,mmStatLines);
     209#endif
     210    fclose(mmStatFile);
     211  }
     212}
     213#endif
  • Singular/page.h

    r7f0e6f r93266c5  
    11#ifndef PAGE_H
    22#define PAGE_H
    3 #if defined(PAGE_TEST) || defined(PAGE_COUNT)
     3#if defined(PAGE_TEST)
    44#ifdef __cplusplus
    55extern "C" {
     
    1212#include <sys/times.h>
    1313
    14 void * Page_Create(size_t size);
    15 void Page_AllowAccess(void * address, size_t size);
    16 void Page_DenyAccess(void * address, size_t size);
    17 size_t Page_Size(void);
    18 extern unsigned long page_tab[2048];
    19 extern char          use_tab [2048];
    20 extern int           page_tab_ind;
     14void * mmPage_Create(size_t size);
     15void mmPage_Delete(void * address);
     16
     17void mmPage_AllowAccess(void * address);
     18void mmPage_DenyAccess(void * address);
     19void mmWriteStat();
     20void mmEndStat();
     21#define MAX_PAGE_TAB 4096
     22#define MM_STAT_FILE "mem_stat.txt"
     23
     24extern unsigned long mmPage_tab[MAX_PAGE_TAB];
     25extern char          mmUse_tab [MAX_PAGE_TAB];
     26extern int           mmPage_tab_ind;
     27extern int           mmPage_tab_acc;
    2128#ifdef __cplusplus
    2229}
Note: See TracChangeset for help on using the changeset viewer.