Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion chb/app/CHVersion.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
chbversion: str = "0.3.0-20250821"
chbversion: str = "0.3.0-20250823"
4 changes: 4 additions & 0 deletions chb/app/GlobalMemoryMap.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ def gtype(self) -> Optional["BCTyp"]:
return self.mmap.bcdictionary.typ(int(tix))
return None

@property
def is_volatile(self) -> bool:
return self.gtype is not None and self.gtype.is_volatile

@property
def size(self) -> Optional[int]:
s = self._xnode.get("size", None)
Expand Down
3 changes: 1 addition & 2 deletions chb/arm/opcodes/ARMLoadRegisterHalfword.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,8 @@ def has_cast() -> bool:

if xd.is_ok:
rhs = xd.cxrmem
rhsval = None if has_cast() else xd.cxrmem
hl_lhs = XU.xvariable_to_ast_lval(
lhs, xdata, iaddr, astree, rhs=rhsval)
lhs, xdata, iaddr, astree, rhs=xd.cxrmem)
hl_rhs = XU.xxpr_to_ast_def_expr(rhs, xdata, iaddr, astree)

elif xd.is_cxaddr_ok:
Expand Down
4 changes: 4 additions & 0 deletions chb/bctypes/BCAttribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ def name(self) -> str:
def params(self) -> List["BCAttrParam"]:
return [self.bcd.attrparam(i) for i in self.args]

@property
def is_volatile(self) -> bool:
return self.name == "volatile"

def __str__(self) -> str:
return self.name + "(" + ", ".join(str(p) for p in self.params) + ")"

Expand Down
6 changes: 5 additions & 1 deletion chb/bctypes/BCTyp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# ------------------------------------------------------------------------------
# The MIT License (MIT)
#
# Copyright (c) 2021-2024 Aarno Labs LLC
# Copyright (c) 2021-2025 Aarno Labs LLC
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -191,6 +191,10 @@ def is_typedef(self) -> bool:
def is_unknown(self) -> bool:
return False

@property
def is_volatile(self) -> bool:
return any(a.is_volatile for a in self.attrs)

@property
def attrs(self) -> List["BCAttribute"]:
attrs = self.bcd.attributes(self.args[-1])
Expand Down
7 changes: 6 additions & 1 deletion chb/cmdline/commandutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -2534,11 +2534,16 @@ def ddata_gvars(args: argparse.Namespace) -> NoReturn:
sgtype = str(gtype)
else:
sgtype = ""
if gloc.is_volatile:
vt = " (volatile)"
else:
vt = ""
print(gloc.addr.rjust(8)
+ " "
+ gloc.name.ljust(60)
+ " "
+ sgtype.ljust(20))
+ sgtype.ljust(20)
+ vt)

(count, coverage) = memmap.coverage()

Expand Down
16 changes: 15 additions & 1 deletion chb/invariants/VAssemblyVariable.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

"""

from typing import Any, Dict, List, Sequence, Tuple, TYPE_CHECKING
from typing import Any, Dict, List, Optional, Sequence, Tuple, TYPE_CHECKING

from chb.app.Register import Register

Expand Down Expand Up @@ -96,6 +96,9 @@ def is_auxiliary_variable(self) -> bool:
def is_global_variable(self) -> bool:
return False

def get_global_variable_address(self) -> Optional[str]:
return None

@property
def is_global_value(self) -> bool:
return False
Expand Down Expand Up @@ -297,6 +300,12 @@ def argument_index(self) -> int:
"Assembly variable is not a stack argument: "
+ str(self))

def get_global_variable_address(self) -> Optional[str]:
if self.is_global_variable:
if self.offset.is_constant_value_offset:
return hex(self.offset.offsetvalue())
return None

def has_unknown_base(self) -> bool:
return self.base.is_unknown

Expand Down Expand Up @@ -417,6 +426,11 @@ def is_auxiliary_variable(self) -> bool:
def is_global_value(self) -> bool:
return self.auxvar.is_global_value

def get_global_variable_address(self) -> Optional[str]:
if self.is_global_value:
return self.auxvar.get_global_variable_address()
return None

@property
def is_stack_base_address(self) -> bool:
return self.auxvar.is_stack_base_address
Expand Down
8 changes: 8 additions & 0 deletions chb/invariants/VConstantValueVariable.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ def is_bridge_variable(self) -> bool:
def is_global_value(self) -> bool:
return False

def get_global_variable_address(self) -> Optional[str]:
return None

@property
def is_function_return_value(self) -> bool:
return False
Expand Down Expand Up @@ -350,6 +353,11 @@ def is_global_value(self) -> bool:
avar = self.variable.denotation
return avar.is_memory_variable and avar.is_global_variable

def get_global_variable_address(self) -> Optional[str]:
if self.is_global_value:
return self.variable.denotation.get_global_variable_address()
return None

@property
def is_argument_value(self) -> bool:
avar = self.variable.denotation
Expand Down
7 changes: 6 additions & 1 deletion chb/invariants/XVariable.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# ------------------------------------------------------------------------------
"""Symbolic value, identified by name and sequence number"""

from typing import Any, cast, Dict, List, Tuple, TYPE_CHECKING
from typing import Any, cast, Dict, List, Optional, Tuple, TYPE_CHECKING

from chb.app.Register import Register

Expand Down Expand Up @@ -201,6 +201,11 @@ def is_global_variable(self) -> bool:
return (self.has_denotation()
and (self.denotation.is_global_variable or self.is_global_value))

def get_global_variable_address(self) -> Optional[str]:
if self.is_global_variable:
return self.denotation.get_global_variable_address()
return None

@property
def is_structured_var(self) -> bool:
return (self.has_denotation() and self.denotation.is_structured_var)
Expand Down
6 changes: 6 additions & 0 deletions chb/invariants/XXpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ def is_global_address(self) -> bool:
def is_global_variable(self) -> bool:
return False

def get_global_variable_address(self) -> Optional[str]:
return None

def is_int_const_value(self, n: int) -> bool:
return False

Expand Down Expand Up @@ -381,6 +384,9 @@ def is_structured_expr(self) -> bool:
def is_global_variable(self) -> bool:
return self.variable.is_global_variable

def get_global_variable_address(self) -> Optional[str]:
return self.variable.get_global_variable_address()

@property
def is_function_return_value(self) -> bool:
return (self.variable.has_denotation()
Expand Down
19 changes: 19 additions & 0 deletions chb/invariants/XXprUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -1768,8 +1768,27 @@ def xvariable_to_ast_lval(
to an ssa value, while a high-level register that is part of some rhs
should be delegated to its reaching definitions, and thus should stay
confined to functions dealing with rhs values.

Note: another check should be added to this function as to whether the
rhs (if provided) is volatile. If so, it should not be used to propagate
that value.
"""

if (
astree.has_register_variable_intro(iaddr)
and astree.get_register_variable_intro(iaddr).has_cast()):
rhs = None

if (rhs is not None and rhs.is_global_variable):
gaddr = rhs.get_global_variable_address()
if gaddr is not None:
gmemmap = xdata.app.globalmemorymap
if gaddr in gmemmap.locations:
gloc = gmemmap.get_location(gaddr)
if gloc is not None and gloc.gtype is not None:
if gloc.gtype.is_volatile:
rhs = None

# unknown memory value
if xv.is_tmp or xv.has_unknown_memory_base():
if memaddr is not None:
Expand Down