mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-01 10:20:59 +00:00
wip
This commit is contained in:
parent
8fe0868d1b
commit
34ae443d82
@ -39,6 +39,27 @@ DISABLE_ENCRYPTION: bool = False
|
|||||||
|
|
||||||
ALLOW_DEBUG_MESSAGES: bool = False
|
ALLOW_DEBUG_MESSAGES: bool = False
|
||||||
|
|
||||||
|
last_allocation_count: int = 0
|
||||||
|
|
||||||
|
|
||||||
|
def print_and_update_alloc(name: str = "unknown") -> None:
|
||||||
|
try:
|
||||||
|
import micropython
|
||||||
|
|
||||||
|
global last_allocation_count
|
||||||
|
current_count = micropython.alloc_count()
|
||||||
|
print("------------------------")
|
||||||
|
micropython.mem_info()
|
||||||
|
print("### Called from: ", name)
|
||||||
|
print("### Allocation count:", current_count)
|
||||||
|
print("### Allocation diff: ", current_count - last_allocation_count)
|
||||||
|
print("------------------------")
|
||||||
|
|
||||||
|
last_allocation_count = current_count
|
||||||
|
except Exception:
|
||||||
|
print("Memory profiling failed")
|
||||||
|
|
||||||
|
|
||||||
if __debug__:
|
if __debug__:
|
||||||
if EMULATOR:
|
if EMULATOR:
|
||||||
import uos
|
import uos
|
||||||
|
@ -60,7 +60,7 @@ def setup(iface: WireInterface) -> None:
|
|||||||
if utils.USE_THP:
|
if utils.USE_THP:
|
||||||
|
|
||||||
async def handle_thp_session(iface: WireInterface):
|
async def handle_thp_session(iface: WireInterface):
|
||||||
|
utils.print_and_update_alloc(__name__)
|
||||||
thp_main.set_read_buffer(WIRE_BUFFER)
|
thp_main.set_read_buffer(WIRE_BUFFER)
|
||||||
thp_main.set_write_buffer(WIRE_BUFFER_2)
|
thp_main.set_write_buffer(WIRE_BUFFER_2)
|
||||||
|
|
||||||
|
@ -65,6 +65,7 @@ async def handle_received_message(
|
|||||||
ctx: Channel, message_buffer: utils.BufferType
|
ctx: Channel, message_buffer: utils.BufferType
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Handle a message received from the channel."""
|
"""Handle a message received from the channel."""
|
||||||
|
utils.print_and_update_alloc(__name__)
|
||||||
|
|
||||||
if __debug__ and utils.ALLOW_DEBUG_MESSAGES:
|
if __debug__ and utils.ALLOW_DEBUG_MESSAGES:
|
||||||
log.debug(__name__, "handle_received_message")
|
log.debug(__name__, "handle_received_message")
|
||||||
@ -99,7 +100,10 @@ async def handle_received_message(
|
|||||||
|
|
||||||
# 1: Handle ACKs
|
# 1: Handle ACKs
|
||||||
if control_byte.is_ack(ctrl_byte):
|
if control_byte.is_ack(ctrl_byte):
|
||||||
|
utils.print_and_update_alloc("ACK before handling")
|
||||||
await _handle_ack(ctx, ack_bit)
|
await _handle_ack(ctx, ack_bit)
|
||||||
|
utils.print_and_update_alloc("ACK after handling")
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if _should_have_ctrl_byte_encrypted_transport(
|
if _should_have_ctrl_byte_encrypted_transport(
|
||||||
@ -173,11 +177,19 @@ async def _handle_ack(ctx: Channel, ack_bit: int):
|
|||||||
log.debug(__name__, "Stopped transmission loop")
|
log.debug(__name__, "Stopped transmission loop")
|
||||||
|
|
||||||
ABP.set_sending_allowed(ctx.channel_cache, True)
|
ABP.set_sending_allowed(ctx.channel_cache, True)
|
||||||
|
utils.print_and_update_alloc("Handle ACK, after cache edit")
|
||||||
if ctx.write_task_spawn is not None:
|
if ctx.write_task_spawn is not None:
|
||||||
if __debug__ and utils.ALLOW_DEBUG_MESSAGES:
|
if __debug__ and utils.ALLOW_DEBUG_MESSAGES:
|
||||||
log.debug(__name__, 'Control to "write_encrypted_payload_loop" task')
|
log.debug(__name__, 'Control to "write_encrypted_payload_loop" task')
|
||||||
await ctx.write_task_spawn
|
await ctx.write_task_spawn
|
||||||
|
try:
|
||||||
|
ctx.write_task_spawn.close()
|
||||||
|
ctx.write_task_spawn = None
|
||||||
|
except Exception as e:
|
||||||
|
print("\nTHE KILLING FAILED, SO IT IS ONLY ATTEMPTED MURDER")
|
||||||
|
print(type(e))
|
||||||
|
utils.print_and_update_alloc("Handle ACK, after write task spawn")
|
||||||
|
|
||||||
# Note that no the write_task_spawn could result in loop.clear(),
|
# Note that no the write_task_spawn could result in loop.clear(),
|
||||||
# which will result in termination of this function - any code after
|
# which will result in termination of this function - any code after
|
||||||
# this await might not be executed
|
# this await might not be executed
|
||||||
|
Loading…
Reference in New Issue
Block a user