# The simplified rename model from the SOSP '13 paper import simsym import symtypes import model import errno SymByte = simsym.tuninterpreted('SymByte') SymInode = simsym.tstruct(data=symtypes.tlist(SymByte), nlink=simsym.SInt) SymIMap = simsym.tmap(simsym.SInt, SymInode) SymFilename = simsym.tuninterpreted('Filename') SymDir = symtypes.tdict(SymFilename, simsym.SInt) class Rename(simsym.tstruct(fname_to_inum=SymDir, inodes=SymIMap)): @model.methodwrap(src=SymFilename, dst=SymFilename) def rename(self, src, dst): if simsym.symnot(self.fname_to_inum.contains(src)): #return (-1, errno.ENOENT) return -1 if src == dst: return 0 if self.fname_to_inum.contains(dst): self.inodes[self.fname_to_inum[dst]].nlink -= 1 self.fname_to_inum[dst] = self.fname_to_inum[src] del self.fname_to_inum[src] return 0 model_class = Rename
# The simplified rename model from the SOSP '13 paper import simsym import symtypes import model import errno SymByte = simsym.tuninterpreted('SymByte') SymInode = simsym.tstruct(data = symtypes.tlist(SymByte), nlink = simsym.SInt) SymIMap = simsym.tmap(simsym.SInt, SymInode) SymFilename = simsym.tuninterpreted('Filename') SymDir = symtypes.tdict(SymFilename, simsym.SInt) class Rename(simsym.tstruct( fname_to_inum=SymDir, inodes=SymIMap)): @model.methodwrap(src=SymFilename, dst=SymFilename) def rename(self, src, dst): if simsym.symnot(self.fname_to_inum.contains(src)): #return (-1, errno.ENOENT) return -1 if src == dst: return 0 if self.fname_to_inum.contains(dst): self.inodes[self.fname_to_inum[dst]].nlink -= 1 self.fname_to_inum[dst] = self.fname_to_inum[src] del self.fname_to_inum[src] return 0
def _eq_internal(self, o): if type(self) != type(o): return NotImplemented return simsym.symand([ self.ispipe == o.ispipe, simsym.symif( self.ispipe, simsym.symand( [self.pipeid == o.pipeid, self.pipewriter == o.pipewriter]), simsym.symand([self.inum == o.inum, self.off == o.off])) ]) SFdNum = simsym.tsynonym("SFdNum", simsym.SInt) SFdMap = symtypes.tdict(SFdNum, SFd) class SVMA( simsym.tstruct( anon=simsym.SBool, writable=simsym.SBool, inum=SInum, # This offset is in datavals off=SOffset, anondata=SDataVal)): def _declare_assumptions(self, assume): super(SVMA, self)._declare_assumptions(assume) assume(self.off >= 0) assume(self.off % PAGE_DATAVALS == 0)
def _declare_assumptions(self, assume): super(SFd, self)._declare_assumptions(assume) assume(self.off >= 0) def _eq_internal(self, o): if type(self) != type(o): return NotImplemented return simsym.symand( [self.ispipe == o.ispipe, simsym.symif(self.ispipe, simsym.symand([self.pipeid == o.pipeid, self.pipewriter == o.pipewriter]), simsym.symand([self.inum == o.inum, self.off == o.off]))]) SFdNum = simsym.tsynonym("SFdNum", simsym.SInt) SFdMap = symtypes.tdict(SFdNum, SFd) class SVMA(simsym.tstruct(anon = simsym.SBool, writable = simsym.SBool, inum = SInum, # This offset is in datavals off = SOffset, anondata = SDataVal)): def _declare_assumptions(self, assume): super(SVMA, self)._declare_assumptions(assume) assume(self.off >= 0) assume(self.off % PAGE_DATAVALS == 0) def _eq_internal(self, o): if type(self) != type(o): return NotImplemented return simsym.symand(
SDataVal = simsym.tuninterpreted("SDataVal") DATAVAL_BYTES = 4096 PAGE_BYTES = 4096 PAGE_DATAVALS = PAGE_BYTES / DATAVAL_BYTES assert PAGE_BYTES % DATAVAL_BYTES == 0 DATA_MAX_LEN = 8 SPid = simsym.SBool # TODO: bool ??? SOffset = simsym.tsynonym("SOffset", simsym.SInt) SAddr = simsym.tsynonym("SAddr", simsym.SInt) SPort = simsym.tsynonym("SPort", simsym.SInt) SData = symtypes.tsmalllist(DATA_MAX_LEN, SDataVal, lenType=SOffset) SBuffer = simsym.tstruct(data=SData) SBindRecord = symtypes.tdict(SPort, symtypes.tdict(SPid, simsym.SBool)) class SFd( simsym.tstruct(domain=simsym.SInt, type=simsym.SInt, prot=simsym.SInt, can_read=simsym.SBool, can_write=simsym.SBool, is_bound=simsym.SBool, is_connected=simsym.SBool, local_addr=SAddr, local_port=SPort, remote_addr=SAddr, remote_port=SPort, send_buffer=SBuffer,