Lines Matching full:block

273     """An abstract block that represents a syscall comparison in a DAG."""
378 def visited(self, block): argument
379 if id(block) in self._visited:
381 self._visited.add(id(block))
384 def process(self, block): argument
385 block.accept(self)
386 return block
388 def visit(self, block): argument
389 if isinstance(block, KillProcess):
390 self.visitKillProcess(block)
391 elif isinstance(block, KillThread):
392 self.visitKillThread(block)
393 elif isinstance(block, Trap):
394 self.visitTrap(block)
395 elif isinstance(block, ReturnErrno):
396 self.visitReturnErrno(block)
397 elif isinstance(block, Trace):
398 self.visitTrace(block)
399 elif isinstance(block, UserNotify):
400 self.visitUserNotify(block)
401 elif isinstance(block, Log):
402 self.visitLog(block)
403 elif isinstance(block, Allow):
404 self.visitAllow(block)
405 elif isinstance(block, BasicBlock):
406 self.visitBasicBlock(block)
407 elif isinstance(block, ValidateArch):
408 self.visitValidateArch(block)
409 elif isinstance(block, SyscallEntry):
410 self.visitSyscallEntry(block)
411 elif isinstance(block, WideAtom):
412 self.visitWideAtom(block)
413 elif isinstance(block, Atom):
414 self.visitAtom(block)
416 raise Exception('Unknown block type: %r' % block)
419 def visitKillProcess(self, block): argument
423 def visitKillThread(self, block): argument
427 def visitTrap(self, block): argument
431 def visitReturnErrno(self, block): argument
435 def visitTrace(self, block): argument
439 def visitUserNotify(self, block): argument
443 def visitLog(self, block): argument
447 def visitAllow(self, block): argument
451 def visitBasicBlock(self, block): argument
455 def visitValidateArch(self, block): argument
459 def visitSyscallEntry(self, block): argument
463 def visitWideAtom(self, block): argument
467 def visitAtom(self, block): argument
478 def process(self, block): argument
480 block.accept(self)
481 return self._mapping[id(block)]
483 def visitKillProcess(self, block): argument
484 assert id(block) not in self._mapping
485 self._mapping[id(block)] = KillProcess()
487 def visitKillThread(self, block): argument
488 assert id(block) not in self._mapping
489 self._mapping[id(block)] = KillThread()
491 def visitTrap(self, block): argument
492 assert id(block) not in self._mapping
493 self._mapping[id(block)] = Trap()
495 def visitReturnErrno(self, block): argument
496 assert id(block) not in self._mapping
497 self._mapping[id(block)] = ReturnErrno(block.errno)
499 def visitTrace(self, block): argument
500 assert id(block) not in self._mapping
501 self._mapping[id(block)] = Trace()
503 def visitUserNotify(self, block): argument
504 assert id(block) not in self._mapping
505 self._mapping[id(block)] = UserNotify()
507 def visitLog(self, block): argument
508 assert id(block) not in self._mapping
509 self._mapping[id(block)] = Log()
511 def visitAllow(self, block): argument
512 assert id(block) not in self._mapping
513 self._mapping[id(block)] = Allow()
515 def visitBasicBlock(self, block): argument
516 assert id(block) not in self._mapping
517 self._mapping[id(block)] = BasicBlock(block.instructions)
519 def visitValidateArch(self, block): argument
520 assert id(block) not in self._mapping
521 self._mapping[id(block)] = ValidateArch(
522 block.arch, self._mapping[id(block.next_block)])
524 def visitSyscallEntry(self, block): argument
525 assert id(block) not in self._mapping
526 self._mapping[id(block)] = SyscallEntry(
527 block.syscall_number,
528 self._mapping[id(block.jt)],
529 self._mapping[id(block.jf)],
530 op=block.op)
532 def visitWideAtom(self, block): argument
533 assert id(block) not in self._mapping
534 self._mapping[id(block)] = WideAtom(
535 block.arg_offset, block.op, block.value, self._mapping[id(
536 block.jt)], self._mapping[id(block.jf)])
538 def visitAtom(self, block): argument
539 assert id(block) not in self._mapping
540 self._mapping[id(block)] = Atom(block.arg_index, block.op, block.value,
541 self._mapping[id(block.jt)],
542 self._mapping[id(block.jf)])
552 def visitAtom(self, block): argument
553 assert id(block) not in self._mapping
555 lo = block.value & 0xFFFFFFFF
556 hi = (block.value >> 32) & 0xFFFFFFFF
559 arg_offset(block.arg_index, False), block.op, lo,
560 self._mapping[id(block.jt)], self._mapping[id(block.jf)])
563 self._mapping[id(block)] = lo_block
566 if block.op in (BPF_JGE, BPF_JGT):
573 self._mapping[id(block)] = WideAtom(
574 arg_offset(block.arg_index, True), BPF_JGT, hi,
575 self._mapping[id(block.jt)], lo_block)
578 arg_offset(block.arg_index, True), BPF_JEQ, hi, lo_block,
579 self._mapping[id(block.jf)])
580 self._mapping[id(block)] = WideAtom(
581 arg_offset(block.arg_index, True), BPF_JGT, hi,
582 self._mapping[id(block.jt)], hi_eq_block)
584 if block.op == BPF_JSET:
591 self._mapping[id(block)] = lo_block
593 self._mapping[id(block)] = WideAtom(
594 arg_offset(block.arg_index, True), block.op, hi,
595 self._mapping[id(block.jt)], lo_block)
598 assert block.op == BPF_JEQ, block.op
603 self._mapping[id(block)] = WideAtom(
604 arg_offset(block.arg_index, True), block.op, hi, lo_block,
605 self._mapping[id(block.jf)])
609 """A visitor that flattens a DAG of Block objects."""
622 def _distance(self, block): argument
623 distance = self._offsets[id(block)] + len(self._instructions)
652 def visited(self, block): argument
653 if id(block) in self._visited:
655 self._visited.add(id(block))
658 def visit(self, block): argument
659 assert id(block) not in self._offsets
661 if isinstance(block, BasicBlock):
662 instructions = block.instructions
663 elif isinstance(block, ValidateArch):
667 self._distance(block.next_block) + 1, 0,
672 elif isinstance(block, SyscallEntry):
673 instructions = self._emit_jmp(block.op, block.syscall_number,
674 self._distance(block.jt),
675 self._distance(block.jf))
676 elif isinstance(block, WideAtom):
678 self._emit_load_arg(block.arg_offset) + self._emit_jmp(
679 block.op, block.value, self._distance(block.jt),
680 self._distance(block.jf)))
682 raise Exception('Unknown block type: %r' % block)
685 self._offsets[id(block)] = -len(self._instructions)
696 def visited(self, block): argument
697 if id(block) in self._visited:
699 self._visited.add(id(block))
702 def visit(self, block): argument
704 if not isinstance(block, BasicBlock):
708 if (isinstance(block, KillProcess) or isinstance(block, KillThread)
709 or isinstance(block, Trap) or isinstance(block, ReturnErrno)
710 or isinstance(block, Trace) or isinstance(block, UserNotify)
711 or isinstance(block, Log) or isinstance(block, Allow)):
713 block.accept(self.visitor)