Exemplo n.º 1
0
 def unlink(engine: Engine):
     try:
         name = engine.read_string()
         os_.unlink(name)
         engine.write_int(0)
     except OSError as e:
         engine.write_int(map_errno(int(str(e)), errno, Flags))
Exemplo n.º 2
0
 def symlink(engine: Engine):
     try:
         existing = engine.read_string()
         _new = engine.read_string()
         os_.symlink(existing, _new)
         engine.write_int(0)
     except OSError as e:
         engine.write_int(map_errno(int(str(e)), errno, Flags))
Exemplo n.º 3
0
 def stat_(engine: Engine):
     try:
         file = engine.read_string()
         st = os_.stat(file)
         engine.write_int(0)
         write_stat(engine, st)
     except OSError as e:
         engine.write_int(map_errno(int(str(e)), errno, Flags))
Exemplo n.º 4
0
 def fstat(engine: Engine):
     try:
         fd = engine.read_int()
         st = os_.fstat(fd)
         engine.write_int(0)
         write_stat(engine, st)
     except OSError as e:
         engine.write_int(map_errno(int(str(e)), errno, Flags))
Exemplo n.º 5
0
 def read_full(engine: Engine):
     try:
         fd = engine.read_int()
         len_ = engine.read_int()
         buf = os_.read(fd, len_)
         engine.write_int(0)
         engine.write_memory(buf)
     except OSError as e:
         engine.write_int(map_errno(int(str(e)), errno, Flags))
Exemplo n.º 6
0
    def invoke(self, engine: Engine, macro_expansion: MacroExpansion):

        engine.write_int(len(self.argv))
        data = b'\0'.join(arg.encode() for arg in self.argv) + b'\0'
        res = engine.write_memory(data)
        if res != len(data):
            print(
                "***metal.serial***: Couldn't write all of argv, buffer size was {}"
                .format(res),
                file=sys.stderr)
Exemplo n.º 7
0
    def read_buffered(engine: Engine):
        try:
            fd = engine.read_int()
            len_ = engine.read_int()

            cur = os_.lseek(fd, 0, os_.SEEK_CUR)
            end = os_.lseek(fd, 0, os_.SEEK_END)

            available = end - cur
            read_len = min(available, len_)

            buf = os_.read(fd, read_len)
            engine.write_int(0)
            engine.write_memory(buf)
        except OSError as e:
            engine.write_int(map_errno(int(str(e)), errno, Flags))
Exemplo n.º 8
0
 def isatty(engine: Engine):
     try:
         fd = engine.read_int()
         isatty_ = os_.isatty(fd)
         engine.write_int(0)
         engine.write_int(isatty_)
     except OSError as e:
         engine.write_int(map_errno(int(str(e)), errno, Flags))
Exemplo n.º 9
0
 def write_full(engine: Engine):
     try:
         fd = engine.read_int()
         dt = engine.read_memory()
         engine.write_int(os_.write(fd, dt))
     except OSError as e:
         engine.write_int(-1)
         engine.write_int(map_errno(int(str(e)), errno, Flags))
Exemplo n.º 10
0
 def close_full(engine: Engine):
     try:
         fd = engine.read_int()
         os_.close(fd)
         engine.write_int(0)
     except OSError as e:
         engine.write_int(-1)
         engine.write_int(map_errno(int(str(e)), errno, Flags))
Exemplo n.º 11
0
 def open_full(engine: Engine):
     try:
         file = engine.read_string()
         flags = map_open_flags(engine.read_int(), Flags, os_)
         mode = map_file_mode(engine.read_int(), Flags, os_)
         engine.write_int(os_.open(file, flags, mode))
     except OSError as e:
         engine.write_int(-1)
         engine.write_int(map_errno(int(str(e)), errno, Flags))
Exemplo n.º 12
0
 def lseek(engine: Engine):
     try:
         file = engine.read_int()
         ptr = engine.read_int()
         dir_ = engine.read_int()
         engine.write_int(os_.lseek(file, ptr, dir_))
     except OSError as e:
         engine.write_int(-1)
         engine.write_int(map_errno(int(str(e)), errno, Flags))
Exemplo n.º 13
0
p = Popen(args.binary,
          stdin=PIPE,
          stdout=PIPE,
          stderr=sys.stdout.buffer,
          close_fds=True)

engine = Engine(input=p.stdout, output=p.stdin, serial_info=serial_info)

assert engine.init_marker.file.endswith('write.c')
assert engine.init_marker.line == 25

engine.write_byte(b'0')
assert engine.read_byte() == b'9'

engine.write_int(22)
assert engine.read_int() == 44

assert engine.write_string("str") == 3
assert engine.read_string() == "tr"

engine.write_int(11)
assert engine.read_int() == 33

assert engine.write_string("overflow") == 6
assert engine.read_string() == "erfl"

engine.write_int(4)
assert engine.read_int() == 16

assert engine.write_memory(b'\x00\x01\x02\x03\x04') == 4
Exemplo n.º 14
0
    def write_stat(engine: Engine, st: os_.stat_result):
        engine.write_int(st.st_dev)
        engine.write_int(st.st_ino)
        engine.write_int(map_file_mode(st.st_mode, Flags, os_))
        engine.write_int(st.st_nlink)
        engine.write_int(st.st_uid)
        engine.write_int(st.st_gid)

        if hasattr(st, 'st_rdev'):
            engine.write_int(getattr(st, 'st_rdev') or 0)
        else:
            engine.write_int(0)

        engine.write_int(st.st_size)

        if hasattr(st, 'st_blksize'):
            engine.write_int(getattr(st, 'st_blksize') or 0)
        else:
            engine.write_int(0)

        if hasattr(st, 'st_blocks'):
            engine.write_int(getattr(st, 'st_blocks') or 0)
        else:
            engine.write_int(0)

        engine.write_int(int(st.st_atime))
        engine.write_int(
            (st.st_atime_ns or int(st.st_atime * 1000000000)) % 1000000000)
        engine.write_int(int(st.st_mtime))
        engine.write_int(
            (st.st_mtime_ns or int(st.st_mtime * 1000000000)) % 1000000000)
        engine.write_int(int(st.st_ctime))
        engine.write_int(
            (st.st_ctime_ns or int(st.st_ctime * 1000000000)) % 1000000000)