Skip to content

Centralize interposer init with pthread_once and use CLOCK_MONOTONIC#1

Open
Religious-J wants to merge 1 commit intomainfrom
codex/explain-the-library-s-functionality
Open

Centralize interposer init with pthread_once and use CLOCK_MONOTONIC#1
Religious-J wants to merge 1 commit intomainfrom
codex/explain-the-library-s-functionality

Conversation

@Religious-J
Copy link
Copy Markdown
Owner

Motivation

  • Harden and centralize initialization of the malloc interposer to avoid racey per-function lazy init and ensure consistent real-function resolution.
  • Improve timestamp stability and avoid allocator reentrancy issues while recording backtraces and ensure symbol buffers are freed to prevent leaks.

Description

  • Replace per-wrapper lazy initialization with a single init_real_functions invoked via pthread_once, and store resolved pointers in malloc_cp, realloc_cp, calloc_cp, and free_cp.
  • Replace gettimeofday with monotonic timing using clock_gettime(CLOCK_MONOTONIC) in get_cur_ms and initialize time_base during init.
  • Make the recording guard allow_record thread_local and mark globals as static to limit scope, then call pthread_once at the start of each wrapper (malloc, realloc, calloc, free).
  • Free the buffer returned by backtrace_symbols with free_cp(symbols) after logging to avoid leaking that memory.

Testing

  • No automated tests were run for this change.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant