RSIM Bug Report #10

Version of RSIM1.0
Bug number10
Bug class2
Date12/10/98
Reported byInternal
AffectsUsers using file input/output
Filestraps.cc

Problem Description

The read system call implementation was returning incorrect values in cases when EOF was reached. The write system call was returning incorrect values in cases when there was no more space to write to disk.

Suggested work-around

ReadHandler and WriteHandler routines (in the traps.cc file) should be corrected as follows: /*************************************************************************/ /* ReadHandler : Simulator exception routine that handles read */ /*************************************************************************/ static void ReadHandler(instance *inst,state *proc) { #ifdef COREFILE if (YS__Simtime > DEBUG_TIME) fprintf(corefile,"traps.cc: In Read Handler\n"); #endif int fd,number_of_items; int buffer; int lr,pr; int count=0; int return_register; int retval, done; /*read the parameters */ lr = convert_to_logical(proc->cwp,8); return_register = pr = proc->intmapper[lr]; fd = proc->physical_int_reg_file[pr]; lr = convert_to_logical(proc->cwp,9); pr = proc->intmapper[lr]; inst->addr = proc->physical_int_reg_file[pr]; lr = convert_to_logical(proc->cwp,10); pr = proc->intmapper[lr]; number_of_items = proc->physical_int_reg_file[pr]; int st = inst->addr & (ALLOC_SIZE-1); done = 0; if(number_of_items > ALLOC_SIZE-st) { buffer = GetMap(inst,proc); retval = read(fd,(char*)buffer,ALLOC_SIZE-st); count+=retval; inst->addr+=retval; number_of_items-=retval; if (retval != ALLOC_SIZE-st) done = 1; while(!done && number_of_items>=ALLOC_SIZE) { buffer = GetMap(inst,proc); retval = read(fd,(char*)buffer,ALLOC_SIZE); if (retval < 0) /* some sort of error other than EOF */ count = retval; else { count += retval; number_of_items-=retval; inst->addr+=retval; } if (retval != ALLOC_SIZE) { done = 1; break; } } } buffer = GetMap(inst,proc); if(!done) { retval = read(fd,(char*)buffer,number_of_items); if (retval < 0) /* some sort of error other than EOF */ count = retval; else { count+=retval; } } proc->physical_int_reg_file[return_register] = count; } /*************************************************************************/ /* WriteHandler : Simulator exception routine that handles write */ /*************************************************************************/ static void WriteHandler(instance *inst,state *proc) { #ifdef COREFILE if (YS__Simtime > DEBUG_TIME) fprintf(corefile,"traps.cc: In Write Handler\n"); #endif int fd,number_of_items; int buffer; int lr,pr; int count = 0; /* return value */ int return_register; int retval, done; /*read the parameters */ lr = convert_to_logical(proc->cwp,8); return_register = pr = proc->intmapper[lr]; fd = proc->physical_int_reg_file[pr]; lr = convert_to_logical(proc->cwp,9); pr = proc->intmapper[lr]; inst->addr = proc->physical_int_reg_file[pr]; lr = convert_to_logical(proc->cwp,10); pr = proc->intmapper[lr]; number_of_items = proc->physical_int_reg_file[pr]; int st = inst->addr & (ALLOC_SIZE-1); done = 0; if(number_of_items > ALLOC_SIZE-st) { buffer = GetMap(inst,proc); retval = write(fd,(char*)buffer,ALLOC_SIZE-st); count+=retval; inst->addr+=retval; number_of_items-=retval; if (retval != ALLOC_SIZE-st) done = 1; while(number_of_items>=ALLOC_SIZE) { buffer = GetMap(inst,proc); retval = write(fd,(char*)buffer,ALLOC_SIZE); if (retval < 0) /* some sort of error other than EOF */ count = retval; else { count += retval; number_of_items-=retval; inst->addr+=retval; } if (retval != ALLOC_SIZE) { done = 1; break; } } } buffer = GetMap(inst,proc); if(!done) { retval = write(fd,(char*)buffer,number_of_items); if (retval < 0) /* some sort of error other than EOF */ count = retval; else { count+=retval; } } proc->physical_int_reg_file[return_register] = count; }