Skip to content

Remove more PAL wrappers from pal/src/misc - #137579

Merged
jkotas merged 13 commits into
dotnet:mainfrom
am11:chore/pal-formatmessage
Nov 19, 2026
Merged

jkotas merged 13 commits into
dotnet:mainfrom
am11:chore/pal-formatmessage

Conversation

@am11

@am11 am11 commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

Named objects: PAL objects are never created with a name, so delete CPalString (pal/src/misc/strutil.cpp), CObjectAttributes, the named object list and LocateObject from the PAL object manager.

perfjitdump.cpp: move it to the VM next to its only user, perfmap.cpp, and drop the PAL_ prefix.

time.cpp: delete it.

  • PAL_nanosleep: use nanosleep directly in its two callers.
  • QueryThreadCycleTime: use clock_gettime(CLOCK_THREAD_CPUTIME_ID) in the utilcode and superpmi cycle timers. Delete GetThreadTimesInternal, which only it used, and its PAL test.

GetSystemInfo: delete it and its PAL test.

  • Fill g_SystemInfo directly on Unix, and trim the PAL SYSTEM_INFO to the two fields that are used.
  • Use minipal_getpagesize for the page size in the DAC and metadata, and PAL_GetLogicalCpuCountFromOS for the processor count in EventPipe and superpmi.
  • Compile isRetAddr and the TOP_MEMORY/BOT_MEMORY helpers only where they are used (x86, Windows).

Remove the configure checks that are left without users.

FormatMessageW moved to #137598.

`FormatMessageW`: all Unix callers are in utilcode, so handle them there:

- `SString::FormatMessage` expands `%1`..`%10` inserts itself for
  `FORMAT_MESSAGE_FROM_STRING`, and uses the error message table for
  `FORMAT_MESSAGE_FROM_SYSTEM`.
- `FormatRuntimeErrorVA` (`posterror.cpp`) uses the error message table.
- Move the error message table from `pal/src/misc/errorstrings.cpp` to
  `utilcode/errorstrings.cpp` as `GetSystemErrorMessage`.
- Delete `pal/src/misc/fmtmessage.cpp` and its PAL tests.

Named objects: PAL objects are never created with a name, so delete
`CPalString` (`pal/src/misc/strutil.cpp`), `CObjectAttributes`, the named
object list and `LocateObject` from the PAL object manager.

`perfjitdump.cpp`: move it to the VM next to its only user, `perfmap.cpp`,
and drop the `PAL_` prefix.

`time.cpp`: delete it.

- `PAL_nanosleep`: use `nanosleep` directly in its two callers.
- `QueryThreadCycleTime`: use `clock_gettime(CLOCK_THREAD_CPUTIME_ID)` in
  the utilcode and superpmi cycle timers. Delete `GetThreadTimesInternal`,
  which only it used, and its PAL test.

`GetSystemInfo`: delete it and its PAL test.

- Fill `g_SystemInfo` directly on Unix, and trim the PAL `SYSTEM_INFO` to
  the two fields that are used.
- Use `minipal_getpagesize` for the page size in the DAC and metadata, and
  `PAL_GetLogicalCpuCountFromOS` for the processor count in EventPipe and
  superpmi.
- Compile `isRetAddr` and the `TOP_MEMORY`/`BOT_MEMORY` helpers only where
  they are used (x86, Windows).

Remove the configure checks that are left without users.

Co-authored-by: Cursor <[email protected]>
@github-actions github-actions Bot added the area-PAL-coreclr only for closed issues label Nov 15, 2026
@am11
am11 requested a review from jkotas November 15, 2026 08:45
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 4 pipeline(s).
11 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Nov 15, 2026
- `perfjitdump.cpp`: drop `<cstddef>`, which conflicts with musl's
  `uint8_t` after `common.h`.
- Cycle timers: WASI has no `CLOCK_THREAD_CPUTIME_ID`.

Co-authored-by: Cursor <[email protected]>
Comment thread src/coreclr/utilcode/posterror.cpp Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The changes span Unix startup, diagnostics, profiling, and PAL/VM/DAC boundaries, while formatter tests are removed and cross-platform build and runtime validation was unavailable.

No open issues 🎉

What changed in this PR

This PR reduces CoreCLR’s Platform Abstraction Layer (PAL) by moving specialized functionality closer to its callers and replacing thin Unix wrappers with direct platform calls.

Changes:

  • Move error-message handling into utilcode and JIT dump support into the VM.
  • Remove unused named-object infrastructure and replace PAL timing and system-information wrappers.
  • Remove obsolete PAL tests, declarations, build entries, and configure checks.
File Description
src/​coreclr/​vm/​perfmap.cpp Call VM-local JIT dump functions.
src/​coreclr/​vm/​perfjitdump.h Declare VM-local JIT dump functions.
src/​coreclr/​vm/​perfjitdump.cpp Move JIT dump implementation from PAL to VM.
src/​coreclr/​vm/​frames.h Restrict isRetAddr declaration to x86.
src/​coreclr/​vm/​eventing/​eventpipe/​ep-rt-coreclr.h Use direct Unix sleep and CPU-count calls.
src/​coreclr/​vm/​debughelp.cpp Restrict isRetAddr implementation to x86.
src/​coreclr/​vm/​CMakeLists.txt Include relocated JIT dump files.
src/​coreclr/​vm/​ceemain.cpp Initialize Unix system information directly.
src/​coreclr/​utilcode/​sstring.cpp Handle Unix message formatting within SString.
src/​coreclr/​utilcode/​posterror.cpp Use utilcode’s system-error lookup on Unix.
src/​coreclr/​utilcode/​errorstrings.cpp Relocate error strings and provide buffered lookup.
src/​coreclr/​utilcode/​cycletimer.cpp Query Unix thread CPU time directly.
src/​coreclr/​utilcode/​CMakeLists.txt Include relocated error-message implementation.
src/​coreclr/​tools/​superpmi/​superpmi/​parallelsuperpmi.cpp Query Unix CPU count without GetSystemInfo.
src/​coreclr/​tools/​superpmi/​superpmi/​cycletimer.cpp Replace PAL thread-cycle calls with a local helper.
src/​coreclr/​pal/​tests/​palsuite/​threading/​QueryThreadCycleTime/​test1/​test1.cpp Delete the removed timing API’s test.
src/​coreclr/​pal/​tests/​palsuite/​paltestlist.txt Remove obsolete test registrations.
src/​coreclr/​pal/​tests/​palsuite/​paltestlist_to_be_reviewed.txt Remove deleted formatting tests.
src/​coreclr/​pal/​tests/​palsuite/​miscellaneous/​GetSystemInfo/​test1/​test.cpp Delete the removed system-information API’s test.
src/​coreclr/​pal/​tests/​palsuite/​miscellaneous/​FormatMessageW/​test6/​test.cpp Delete PAL system-message lookup test.
src/​coreclr/​pal/​tests/​palsuite/​miscellaneous/​FormatMessageW/​test5/​test.cpp Delete PAL allocated-buffer insert test.
src/​coreclr/​pal/​tests/​palsuite/​miscellaneous/​FormatMessageW/​test4/​test.cpp Delete PAL argument-array formatting test.
src/​coreclr/​pal/​tests/​palsuite/​miscellaneous/​FormatMessageW/​test3/​test.cpp Delete PAL ignored-inserts test.
src/​coreclr/​pal/​tests/​palsuite/​miscellaneous/​FormatMessageW/​test2/​test.cpp Delete PAL variadic formatting tests.
src/​coreclr/​pal/​tests/​palsuite/​miscellaneous/​FormatMessageW/​test1/​test.cpp Delete PAL basic formatting test.
src/​coreclr/​pal/​tests/​palsuite/​compilableTests.txt Remove deleted tests from the compilation list.
src/​coreclr/​pal/​tests/​palsuite/​CMakeLists.txt Remove deleted test sources.
src/​coreclr/​pal/​src/​thread/​thread.cpp Remove internal timing implementation and object attributes.
src/​coreclr/​pal/​src/​thread/​process.cpp Use nanosleep directly and remove unused attributes.
src/​coreclr/​pal/​src/​objmgr/​palobjbase.hpp Remove object-attribute storage and interfaces.
src/​coreclr/​pal/​src/​objmgr/​palobjbase.cpp Remove object-name initialization and cleanup.
src/​coreclr/​pal/​src/​objmgr/​listedobjectmanager.hpp Remove named-object list and lookup declarations.
src/​coreclr/​pal/​src/​objmgr/​listedobjectmanager.cpp Simplify registration to anonymous objects.
src/​coreclr/​pal/​src/​objmgr/​listedobject.hpp Remove attributes from initialization signature.
src/​coreclr/​pal/​src/​objmgr/​listedobject.cpp Update initialization to omit attributes.
src/​coreclr/​pal/​src/​misc/​time.cpp Delete PAL timing wrappers.
src/​coreclr/​pal/​src/​misc/​sysinfo.cpp Retain CPU queries while removing GetSystemInfo.
src/​coreclr/​pal/​src/​misc/​strutil.cpp Delete unused CPalString implementation.
src/​coreclr/​pal/​src/​misc/​fmtmessage.cpp Delete PAL message-formatting implementation.
src/​coreclr/​pal/​src/​misc/​errorstrings.h Delete obsolete PAL error-string declaration.
src/​coreclr/​pal/​src/​include/​pal/​thread.hpp Remove internal thread-timing declaration.
src/​coreclr/​pal/​src/​include/​pal/​corunix.hpp Remove named-object types and interfaces.
src/​coreclr/​pal/​src/​configure.cmake Remove unused platform capability checks.
src/​coreclr/​pal/​src/​config.h.in Remove obsolete configuration macros.
src/​coreclr/​pal/​src/​CMakeLists.txt Remove deleted and relocated PAL sources.
src/​coreclr/​pal/​inc/​pal.h Remove obsolete APIs and reduce SYSTEM_INFO.
src/​coreclr/​md/​enc/​stgio.cpp Query Unix page size through minipal.
src/​coreclr/​inc/​utilcode.h Declare Unix system-error message helper.
src/​coreclr/​inc/​stdmacros.h Restrict memory-bound helpers to non-Unix hosts.
src/​coreclr/​dlls/​mscordac/​mscordac_unixexports.src Remove obsolete PAL export entries.
src/​coreclr/​debug/​daccess/​dacdbiimpl.cpp Query Unix cache page size through minipal.
eng/​native/​tryrun.cmake Remove thread CPU-clock probe results.
eng/​native/​tryrun.browser.cmake Remove obsolete browser capability-cache entries.
eng/​native/​tryrun_ios_tvos.cmake Remove thread CPU-clock probe result.

Review effort: Balanced

Comment thread src/coreclr/pal/src/thread/process.cpp Resolved
Comment thread src/coreclr/utilcode/cycletimer.cpp Resolved
Comment thread src/coreclr/inc/stdmacros.h Resolved
- Use `minipal_sleep` for the pipe open retry and in `ep_rt_thread_sleep`
  on all platforms.
- Sample profiler: use `minipal_microdelay` for sub-millisecond sampling
  rates.
- Delete `TOP_MEMORY`/`BOT_MEMORY` and the early out in `isRetAddr` that
  used them.

Co-authored-by: Cursor <[email protected]>
Call `minipal_microdelay` unconditionally in the sample profiler.

Co-authored-by: Cursor <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new sleep call turns the default 1 ms interval into a one-second wait on Unix and bypasses Mono’s GC-safe transition, degrading sampling and potentially delaying garbage collection.

2 open issues

Review effort: Balanced

The seconds were computed from milliseconds, so delays of 1ms or more slept
1000 times too long. Also retry the sleep when nanosleep is interrupted.

Co-authored-by: Cursor <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The direct sleep bypasses Mono’s GC-safe transition, leaving the sampling thread GC-unsafe and potentially extending GC pauses by up to the configured sampling interval.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Restore GC-safe sleep for Mono sampling thread

src/​native/​eventpipe/​ep-sample-profiler.c:103

On Mono, this direct sleep bypasses the GC-safe transition in src/mono/mono/eventpipe/ep-rt-mono.h:1102-1113; the attached sampling thread remains GC-unsafe because Mono's EP_GCX_PREEMP_ENTER is only a brace. Cooperative or hybrid garbage collection can therefore wait for the sampler to wake, adding up to the configured sampling interval to a GC pause. Restore ep_rt_thread_sleep here and preserve sub-millisecond sleep precision in the CoreCLR adapter at src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h:1154.

2 resolved since last review

Review effort: Balanced

Comment thread src/coreclr/md/enc/stgio.cpp Resolved
Comment thread src/coreclr/vm/perfjitdump.cpp Resolved
Comment thread src/native/minipal/time.c Resolved
Co-authored-by: Cursor <[email protected]>

# Conflicts:
#	src/coreclr/vm/perfmap.cpp
am11 and others added 2 commits November 18, 2026 14:25
Co-authored-by: Cursor <[email protected]>

# Conflicts:
#	src/coreclr/pal/src/CMakeLists.txt
#	src/coreclr/pal/src/misc/sysinfo.cpp
- Use `minipal_getpagesize` on all platforms in the DAC and metadata.
- Use digit separators.

Co-authored-by: Cursor <[email protected]>
Comment thread src/native/minipal/cpucount.c Resolved
@jkotas

jkotas commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

I would leave any (non-trivial) Windows changes to a separate PR.

This reverts commit 317d483.
@am11

am11 commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

@jkotas, I've reverted windows changes.

@am11

am11 commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

osx-arm64 dead-lettered.

@jkotas

jkotas commented Nov 19, 2026

Copy link
Copy Markdown
Member

/ba-g osx dead letter

@jkotas
jkotas merged commit 6ac9471 into dotnet:main Nov 19, 2026
105 of 109 checks passed
@am11
am11 deleted the chore/pal-formatmessage branch November 19, 2026 17:27
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-PAL-coreclr only for closed issues community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants