Skip to content

Commit

Permalink
Final touchups
Browse files Browse the repository at this point in the history
  • Loading branch information
elicn committed Feb 15, 2024
1 parent 12eaf05 commit 545dda3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
20 changes: 12 additions & 8 deletions qiling/os/posix/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,10 @@ class qnx_arm_open_flags(QlPrettyFlag):
O_LARGEFILE = 0x08000


################################
# mmap flags #
################################

# see: https://github.com/torvalds/linux/blob/master/include/uapi/asm-generic/mman-common.h
class linux_mmap_flags(Flag):
MAP_FILE = 0x00000000
Expand Down Expand Up @@ -727,14 +731,14 @@ class qnx_mmap_flags(Flag):
MAP_UNINITIALIZED = MAP_NOINIT

# fcntl flags
F_DUPFD = 0
F_GETFD = 1
F_SETFD = 2
F_GETFL = 3
F_SETFL = 4
F_GETLK = 5
F_SETLK = 6
F_SETLKW = 7
F_DUPFD = 0
F_GETFD = 1
F_SETFD = 2
F_GETFL = 3
F_SETFL = 4
F_GETLK = 5
F_SETLK = 6
F_SETLKW = 7

FD_CLOEXEC = 1

Expand Down
2 changes: 1 addition & 1 deletion qiling/os/posix/const_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def ql_open_flag_mapping(ql: Qiling, flags: int) -> int:
return ret


def mmap_flag_mapping(flags):
def mmap_flag_mapping(flags: int) -> str:
mmap_flags = {
'MAP_SHARED' : 0x00000001,
'MAP_PRIVATE' : 0x00000002,
Expand Down
1 change: 0 additions & 1 deletion qiling/os/posix/syscall/fcntl.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

from qiling import Qiling
from qiling.const import QL_OS, QL_ARCH
from qiling.exception import QlSyscallError
from qiling.os.posix.const import *
from qiling.os.posix.const_mapping import ql_open_flag_mapping, get_open_flags_class
from qiling.os.posix.filestruct import ql_socket
Expand Down
13 changes: 7 additions & 6 deletions qiling/os/posix/syscall/unistd.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import itertools
import pathlib

from typing import TYPE_CHECKING, Iterator, Optional
from typing import TYPE_CHECKING, IO, Iterator, Optional, Union

from qiling import Qiling
from qiling.const import QL_ARCH, QL_OS
Expand Down Expand Up @@ -155,16 +155,17 @@ def ql_syscall_kill(ql: Qiling, pid: int, sig: int):
return 0


def get_opened_fd(os: QlOsPosix, fd: int):
def get_opened_fd(os: QlOsPosix, fd: int) -> Optional[IO]:
"""Retrieve a file instance by its file descriptor id.
"""

if fd not in range(NR_OPEN):
# TODO: set errno to EBADF
return None
return None # EBADF

f = os.fd[fd]

if f is None:
# TODO: set errno to EBADF
return None
return None # EBADF

return f

Expand Down

0 comments on commit 545dda3

Please sign in to comment.