Skip to content

Commit 2b82f3f

Browse files
committed
Indicate if process is MTE enabled
Indicate whether a process instance is running with MTE enabled in the response to the `qProcessInfo` packet.
1 parent 99ea474 commit 2b82f3f

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

lldb/tools/debugserver/source/MacOSX/MachVMMemory.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,9 @@ nub_bool_t MachVMMemory::GetMemoryTags(task_t task, nub_addr_t address,
172172
(size / tag_granule) + ((size % tag_granule > 0) ? 1 : 0);
173173
ptr_count = std::min(ptr_count, max_ptr_count);
174174

175-
auto ptr_arr = std::make_unique<nub_addr_t[]>(ptr_count);
176-
for (size_t i = 0; i < ptr_count; i++) {
175+
auto ptr_arr = std::make_unique<mach_vm_offset_t[]>(ptr_count);
176+
for (size_t i = 0; i < ptr_count; i++)
177177
ptr_arr[i] = (address + i * tag_granule);
178-
}
179178

180179
mach_msg_type_number_t ptr_count_out = ptr_count;
181180
m_err = ::mach_vm_update_pointers_with_remote_tags(

lldb/tools/debugserver/source/RNBRemote.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6247,6 +6247,30 @@ GetCPUTypesFromHost(nub_process_t pid) {
62476247
return {cputype, cpusubtype};
62486248
}
62496249

6250+
#if !__has_include(<os/security_config.h>) // macOS 26.1
6251+
extern "C" {
6252+
using os_security_config_t = uint64_t;
6253+
#define OS_SECURITY_CONFIG_MTE 0x4
6254+
6255+
API_AVAILABLE(macos(26.0), ios(26.0), tvos(26.0), watchos(26.0), visionos(26.0),
6256+
driverkit(25.0))
6257+
OS_EXPORT OS_NOTHROW OS_NONNULL_ALL int
6258+
os_security_config_get_for_proc(pid_t pid, os_security_config_t *config);
6259+
}
6260+
#endif
6261+
static bool ProcessRunningWithMemoryTagging(pid_t pid) {
6262+
if (__builtin_available(macOS 26.0, iOS 26.0, tvOS 26.0, watchOS 26.0,
6263+
visionOS 26.0, driverkit 25.0, *)) {
6264+
os_security_config_t config;
6265+
int ret = ::os_security_config_get_for_proc(pid, &config);
6266+
if (ret != 0)
6267+
return false;
6268+
6269+
return (config & OS_SECURITY_CONFIG_MTE);
6270+
}
6271+
return false;
6272+
}
6273+
62506274
// Note that all numeric values returned by qProcessInfo are hex encoded,
62516275
// including the pid and the cpu type.
62526276

@@ -6423,6 +6447,9 @@ rnb_err_t RNBRemote::HandlePacket_qProcessInfo(const char *p) {
64236447

64246448
rep << "vendor:apple;";
64256449

6450+
if (ProcessRunningWithMemoryTagging(pid))
6451+
rep << "mte:enabled;";
6452+
64266453
#if defined(__LITTLE_ENDIAN__)
64276454
rep << "endian:little;";
64286455
#elif defined(__BIG_ENDIAN__)

0 commit comments

Comments
 (0)