2021-05-17 23:08:09 +00:00
|
|
|
const builtin = @import("builtin");
|
2019-11-17 02:59:52 +00:00
|
|
|
const std = @import("std.zig");
|
|
|
|
const math = std.math;
|
2018-12-30 15:55:24 +00:00
|
|
|
|
2019-05-12 16:56:01 +00:00
|
|
|
pub fn doClientRequest(default: usize, request: usize, a1: usize, a2: usize, a3: usize, a4: usize, a5: usize) usize {
|
2018-12-30 15:55:24 +00:00
|
|
|
if (!builtin.valgrind_support) {
|
|
|
|
return default;
|
|
|
|
}
|
|
|
|
|
2021-05-17 23:08:09 +00:00
|
|
|
switch (builtin.target.cpu.arch) {
|
2022-10-07 17:54:44 +00:00
|
|
|
.x86 => {
|
2018-12-30 15:55:24 +00:00
|
|
|
return asm volatile (
|
|
|
|
\\ roll $3, %%edi ; roll $13, %%edi
|
|
|
|
\\ roll $29, %%edi ; roll $19, %%edi
|
|
|
|
\\ xchgl %%ebx,%%ebx
|
2021-08-29 09:57:32 +00:00
|
|
|
: [_] "={edx}" (-> usize),
|
2019-11-17 02:59:52 +00:00
|
|
|
: [_] "{eax}" (&[_]usize{ request, a1, a2, a3, a4, a5 }),
|
2021-08-29 09:57:32 +00:00
|
|
|
[_] "0" (default),
|
2018-12-30 15:55:24 +00:00
|
|
|
: "cc", "memory"
|
|
|
|
);
|
|
|
|
},
|
2020-02-25 20:29:56 +00:00
|
|
|
.x86_64 => {
|
2018-12-30 15:55:24 +00:00
|
|
|
return asm volatile (
|
|
|
|
\\ rolq $3, %%rdi ; rolq $13, %%rdi
|
|
|
|
\\ rolq $61, %%rdi ; rolq $51, %%rdi
|
|
|
|
\\ xchgq %%rbx,%%rbx
|
2021-08-29 09:57:32 +00:00
|
|
|
: [_] "={rdx}" (-> usize),
|
2019-11-17 02:59:52 +00:00
|
|
|
: [_] "{rax}" (&[_]usize{ request, a1, a2, a3, a4, a5 }),
|
2021-08-29 09:57:32 +00:00
|
|
|
[_] "0" (default),
|
2018-12-30 15:55:24 +00:00
|
|
|
: "cc", "memory"
|
|
|
|
);
|
|
|
|
},
|
2022-10-24 22:30:00 +00:00
|
|
|
.aarch64 => {
|
|
|
|
return asm volatile (
|
|
|
|
\\ ror x12, x12, #3 ; ror x12, x12, #13
|
|
|
|
\\ ror x12, x12, #51 ; ror x12, x12, #61
|
|
|
|
\\ orr x10, x10, x10
|
2022-11-20 02:32:26 +00:00
|
|
|
: [_] "={x3}" (-> usize),
|
|
|
|
: [_] "{x4}" (&[_]usize{ request, a1, a2, a3, a4, a5 }),
|
|
|
|
[_] "0" (default),
|
|
|
|
: "cc", "memory"
|
2022-10-24 22:30:00 +00:00
|
|
|
);
|
|
|
|
},
|
2018-12-30 15:55:24 +00:00
|
|
|
// ppc32
|
|
|
|
// ppc64
|
|
|
|
// arm
|
|
|
|
// s390x
|
|
|
|
// mips32
|
|
|
|
// mips64
|
|
|
|
else => {
|
|
|
|
return default;
|
2019-05-12 16:56:01 +00:00
|
|
|
},
|
2018-12-30 15:55:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-23 01:07:46 +00:00
|
|
|
pub const ClientRequest = enum(u32) {
|
2018-12-30 15:55:24 +00:00
|
|
|
RunningOnValgrind = 4097,
|
|
|
|
DiscardTranslations = 4098,
|
|
|
|
ClientCall0 = 4353,
|
|
|
|
ClientCall1 = 4354,
|
|
|
|
ClientCall2 = 4355,
|
|
|
|
ClientCall3 = 4356,
|
|
|
|
CountErrors = 4609,
|
|
|
|
GdbMonitorCommand = 4610,
|
|
|
|
MalloclikeBlock = 4865,
|
|
|
|
ResizeinplaceBlock = 4875,
|
|
|
|
FreelikeBlock = 4866,
|
|
|
|
CreateMempool = 4867,
|
|
|
|
DestroyMempool = 4868,
|
|
|
|
MempoolAlloc = 4869,
|
|
|
|
MempoolFree = 4870,
|
|
|
|
MempoolTrim = 4871,
|
|
|
|
MoveMempool = 4872,
|
|
|
|
MempoolChange = 4873,
|
|
|
|
MempoolExists = 4874,
|
|
|
|
Printf = 5121,
|
|
|
|
PrintfBacktrace = 5122,
|
|
|
|
PrintfValistByRef = 5123,
|
|
|
|
PrintfBacktraceValistByRef = 5124,
|
|
|
|
StackRegister = 5377,
|
|
|
|
StackDeregister = 5378,
|
|
|
|
StackChange = 5379,
|
|
|
|
LoadPdbDebuginfo = 5633,
|
|
|
|
MapIpToSrcloc = 5889,
|
|
|
|
ChangeErrDisablement = 6145,
|
|
|
|
VexInitForIri = 6401,
|
|
|
|
InnerThreads = 6402,
|
|
|
|
};
|
|
|
|
pub fn ToolBase(base: [2]u8) u32 {
|
2019-11-07 04:25:57 +00:00
|
|
|
return (@as(u32, base[0] & 0xff) << 24) | (@as(u32, base[1] & 0xff) << 16);
|
2018-12-30 15:55:24 +00:00
|
|
|
}
|
|
|
|
pub fn IsTool(base: [2]u8, code: usize) bool {
|
|
|
|
return ToolBase(base) == (code & 0xffff0000);
|
|
|
|
}
|
|
|
|
|
2019-05-12 16:56:01 +00:00
|
|
|
fn doClientRequestExpr(default: usize, request: ClientRequest, a1: usize, a2: usize, a3: usize, a4: usize, a5: usize) usize {
|
2023-06-22 17:46:56 +00:00
|
|
|
return doClientRequest(default, @as(usize, @intCast(@intFromEnum(request))), a1, a2, a3, a4, a5);
|
2018-12-30 15:55:24 +00:00
|
|
|
}
|
|
|
|
|
2019-05-12 16:56:01 +00:00
|
|
|
fn doClientRequestStmt(request: ClientRequest, a1: usize, a2: usize, a3: usize, a4: usize, a5: usize) void {
|
2018-12-30 15:55:24 +00:00
|
|
|
_ = doClientRequestExpr(0, request, a1, a2, a3, a4, a5);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the number of Valgrinds this code is running under. That
|
|
|
|
/// is, 0 if running natively, 1 if running under Valgrind, 2 if
|
|
|
|
/// running under Valgrind which is running under another Valgrind,
|
|
|
|
/// etc.
|
|
|
|
pub fn runningOnValgrind() usize {
|
2019-11-17 03:03:52 +00:00
|
|
|
return doClientRequestExpr(0, .RunningOnValgrind, 0, 0, 0, 0, 0);
|
2018-12-30 15:55:24 +00:00
|
|
|
}
|
|
|
|
|
2019-11-17 03:16:09 +00:00
|
|
|
test "works whether running on valgrind or not" {
|
|
|
|
_ = runningOnValgrind();
|
|
|
|
}
|
|
|
|
|
2018-12-30 15:55:24 +00:00
|
|
|
/// Discard translation of code in the slice qzz. Useful if you are debugging
|
|
|
|
/// a JITter or some such, since it provides a way to make sure valgrind will
|
|
|
|
/// retranslate the invalidated area. Returns no value.
|
|
|
|
pub fn discardTranslations(qzz: []const u8) void {
|
2023-06-15 07:14:16 +00:00
|
|
|
doClientRequestStmt(.DiscardTranslations, @intFromPtr(qzz.ptr), qzz.len, 0, 0, 0);
|
2018-12-30 15:55:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn innerThreads(qzz: [*]u8) void {
|
2019-11-17 03:03:52 +00:00
|
|
|
doClientRequestStmt(.InnerThreads, qzz, 0, 0, 0, 0);
|
2018-12-30 15:55:24 +00:00
|
|
|
}
|
|
|
|
|
2024-06-28 15:27:00 +00:00
|
|
|
pub fn nonSimdCall0(func: fn (usize) usize) usize {
|
2023-06-15 07:14:16 +00:00
|
|
|
return doClientRequestExpr(0, .ClientCall0, @intFromPtr(func), 0, 0, 0, 0);
|
2018-12-30 15:55:24 +00:00
|
|
|
}
|
|
|
|
|
2024-06-28 15:27:00 +00:00
|
|
|
pub fn nonSimdCall1(func: fn (usize, usize) usize, a1: usize) usize {
|
2023-06-15 07:14:16 +00:00
|
|
|
return doClientRequestExpr(0, .ClientCall1, @intFromPtr(func), a1, 0, 0, 0);
|
2018-12-30 15:55:24 +00:00
|
|
|
}
|
|
|
|
|
2024-06-28 15:27:00 +00:00
|
|
|
pub fn nonSimdCall2(func: fn (usize, usize, usize) usize, a1: usize, a2: usize) usize {
|
2023-06-15 07:14:16 +00:00
|
|
|
return doClientRequestExpr(0, .ClientCall2, @intFromPtr(func), a1, a2, 0, 0);
|
2018-12-30 15:55:24 +00:00
|
|
|
}
|
|
|
|
|
2024-06-28 15:27:00 +00:00
|
|
|
pub fn nonSimdCall3(func: fn (usize, usize, usize, usize) usize, a1: usize, a2: usize, a3: usize) usize {
|
2023-06-15 07:14:16 +00:00
|
|
|
return doClientRequestExpr(0, .ClientCall3, @intFromPtr(func), a1, a2, a3, 0);
|
2018-12-30 15:55:24 +00:00
|
|
|
}
|
|
|
|
|
2024-06-28 15:27:00 +00:00
|
|
|
/// Deprecated: use `nonSimdCall0`
|
|
|
|
pub const nonSIMDCall0 = nonSimdCall0;
|
|
|
|
|
|
|
|
/// Deprecated: use `nonSimdCall1`
|
|
|
|
pub const nonSIMDCall1 = nonSimdCall1;
|
|
|
|
|
|
|
|
/// Deprecated: use `nonSimdCall2`
|
|
|
|
pub const nonSIMDCall2 = nonSimdCall2;
|
|
|
|
|
|
|
|
/// Deprecated: use `nonSimdCall3`
|
|
|
|
pub const nonSIMDCall3 = nonSimdCall3;
|
|
|
|
|
2018-12-30 15:55:24 +00:00
|
|
|
/// Counts the number of errors that have been recorded by a tool. Nb:
|
|
|
|
/// the tool must record the errors with VG_(maybe_record_error)() or
|
|
|
|
/// VG_(unique_error)() for them to be counted.
|
|
|
|
pub fn countErrors() usize {
|
|
|
|
return doClientRequestExpr(0, // default return
|
2019-11-17 03:03:52 +00:00
|
|
|
.CountErrors, 0, 0, 0, 0, 0);
|
2018-12-30 15:55:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn mallocLikeBlock(mem: []u8, rzB: usize, is_zeroed: bool) void {
|
2023-06-15 07:14:16 +00:00
|
|
|
doClientRequestStmt(.MalloclikeBlock, @intFromPtr(mem.ptr), mem.len, rzB, @intFromBool(is_zeroed), 0);
|
2018-12-30 15:55:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn resizeInPlaceBlock(oldmem: []u8, newsize: usize, rzB: usize) void {
|
2023-06-15 07:14:16 +00:00
|
|
|
doClientRequestStmt(.ResizeinplaceBlock, @intFromPtr(oldmem.ptr), oldmem.len, newsize, rzB, 0);
|
2018-12-30 15:55:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn freeLikeBlock(addr: [*]u8, rzB: usize) void {
|
2023-06-15 07:14:16 +00:00
|
|
|
doClientRequestStmt(.FreelikeBlock, @intFromPtr(addr), rzB, 0, 0, 0);
|
2018-12-30 15:55:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Create a memory pool.
|
2021-04-23 01:07:46 +00:00
|
|
|
pub const MempoolFlags = struct {
|
|
|
|
pub const AutoFree = 1;
|
|
|
|
pub const MetaPool = 2;
|
2018-12-30 15:55:24 +00:00
|
|
|
};
|
|
|
|
pub fn createMempool(pool: [*]u8, rzB: usize, is_zeroed: bool, flags: usize) void {
|
2023-06-15 07:14:16 +00:00
|
|
|
doClientRequestStmt(.CreateMempool, @intFromPtr(pool), rzB, @intFromBool(is_zeroed), flags, 0);
|
2018-12-30 15:55:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Destroy a memory pool.
|
|
|
|
pub fn destroyMempool(pool: [*]u8) void {
|
2023-10-12 09:00:25 +00:00
|
|
|
doClientRequestStmt(.DestroyMempool, @intFromPtr(pool), 0, 0, 0, 0);
|
2018-12-30 15:55:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Associate a piece of memory with a memory pool.
|
|
|
|
pub fn mempoolAlloc(pool: [*]u8, mem: []u8) void {
|
2023-06-15 07:14:16 +00:00
|
|
|
doClientRequestStmt(.MempoolAlloc, @intFromPtr(pool), @intFromPtr(mem.ptr), mem.len, 0, 0);
|
2018-12-30 15:55:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Disassociate a piece of memory from a memory pool.
|
|
|
|
pub fn mempoolFree(pool: [*]u8, addr: [*]u8) void {
|
2023-06-15 07:14:16 +00:00
|
|
|
doClientRequestStmt(.MempoolFree, @intFromPtr(pool), @intFromPtr(addr), 0, 0, 0);
|
2018-12-30 15:55:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Disassociate any pieces outside a particular range.
|
|
|
|
pub fn mempoolTrim(pool: [*]u8, mem: []u8) void {
|
2023-06-15 07:14:16 +00:00
|
|
|
doClientRequestStmt(.MempoolTrim, @intFromPtr(pool), @intFromPtr(mem.ptr), mem.len, 0, 0);
|
2018-12-30 15:55:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Resize and/or move a piece associated with a memory pool.
|
|
|
|
pub fn moveMempool(poolA: [*]u8, poolB: [*]u8) void {
|
2023-06-15 07:14:16 +00:00
|
|
|
doClientRequestStmt(.MoveMempool, @intFromPtr(poolA), @intFromPtr(poolB), 0, 0, 0);
|
2018-12-30 15:55:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Resize and/or move a piece associated with a memory pool.
|
|
|
|
pub fn mempoolChange(pool: [*]u8, addrA: [*]u8, mem: []u8) void {
|
2023-06-15 07:14:16 +00:00
|
|
|
doClientRequestStmt(.MempoolChange, @intFromPtr(pool), @intFromPtr(addrA), @intFromPtr(mem.ptr), mem.len, 0);
|
2018-12-30 15:55:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Return if a mempool exists.
|
|
|
|
pub fn mempoolExists(pool: [*]u8) bool {
|
2023-06-15 07:14:16 +00:00
|
|
|
return doClientRequestExpr(0, .MempoolExists, @intFromPtr(pool), 0, 0, 0, 0) != 0;
|
2018-12-30 15:55:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Mark a piece of memory as being a stack. Returns a stack id.
|
|
|
|
/// start is the lowest addressable stack byte, end is the highest
|
|
|
|
/// addressable stack byte.
|
|
|
|
pub fn stackRegister(stack: []u8) usize {
|
2023-06-15 07:14:16 +00:00
|
|
|
return doClientRequestExpr(0, .StackRegister, @intFromPtr(stack.ptr), @intFromPtr(stack.ptr) + stack.len, 0, 0, 0);
|
2018-12-30 15:55:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Unmark the piece of memory associated with a stack id as being a stack.
|
|
|
|
pub fn stackDeregister(id: usize) void {
|
2019-11-17 03:03:52 +00:00
|
|
|
doClientRequestStmt(.StackDeregister, id, 0, 0, 0, 0);
|
2018-12-30 15:55:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Change the start and end address of the stack id.
|
|
|
|
/// start is the new lowest addressable stack byte, end is the new highest
|
|
|
|
/// addressable stack byte.
|
|
|
|
pub fn stackChange(id: usize, newstack: []u8) void {
|
2023-06-15 07:14:16 +00:00
|
|
|
doClientRequestStmt(.StackChange, id, @intFromPtr(newstack.ptr), @intFromPtr(newstack.ptr) + newstack.len, 0, 0);
|
2018-12-30 15:55:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Load PDB debug info for Wine PE image_map.
|
|
|
|
// pub fn loadPdbDebuginfo(fd, ptr, total_size, delta) void {
|
2019-11-17 03:03:52 +00:00
|
|
|
// doClientRequestStmt(.LoadPdbDebuginfo,
|
2018-12-30 15:55:24 +00:00
|
|
|
// fd, ptr, total_size, delta,
|
|
|
|
// 0);
|
|
|
|
// }
|
|
|
|
|
|
|
|
/// Map a code address to a source file name and line number. buf64
|
|
|
|
/// must point to a 64-byte buffer in the caller's address space. The
|
|
|
|
/// result will be dumped in there and is guaranteed to be zero
|
|
|
|
/// terminated. If no info is found, the first byte is set to zero.
|
|
|
|
pub fn mapIpToSrcloc(addr: *const u8, buf64: [64]u8) usize {
|
2023-06-15 07:14:16 +00:00
|
|
|
return doClientRequestExpr(0, .MapIpToSrcloc, @intFromPtr(addr), @intFromPtr(&buf64[0]), 0, 0, 0);
|
2018-12-30 15:55:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Disable error reporting for this thread. Behaves in a stack like
|
|
|
|
/// way, so you can safely call this multiple times provided that
|
|
|
|
/// enableErrorReporting() is called the same number of times
|
|
|
|
/// to re-enable reporting. The first call of this macro disables
|
|
|
|
/// reporting. Subsequent calls have no effect except to increase the
|
|
|
|
/// number of enableErrorReporting() calls needed to re-enable
|
|
|
|
/// reporting. Child threads do not inherit this setting from their
|
|
|
|
/// parents -- they are always created with reporting enabled.
|
|
|
|
pub fn disableErrorReporting() void {
|
2019-11-17 03:03:52 +00:00
|
|
|
doClientRequestStmt(.ChangeErrDisablement, 1, 0, 0, 0, 0);
|
2018-12-30 15:55:24 +00:00
|
|
|
}
|
|
|
|
|
Fix simple doc mistakes. (#17624)
* Add missing period in Stack's description
This looks fine in the source, but looks bad when seen on the documentation website.
* Correct documentation for attachSegfaultHandler()
The description for attachSegfaultHandler() looks pretty bad without indicating that the stuff at the end is code
* Added missing 'the's in Queue.put's documentation
* Fixed several errors in Stack's documentation
`push()` and `pop()` were not styled as code
There was no period after `pop()`, which looks bad on the documentation.
* Fix multiple problems in base64.zig
Both "invalid"s in Base64.decoder were not capitalized.
Missing period in documentation of Base64DecoderWithIgnore.calcSizeUpperBound.
* Fix capitalization typos in bit_set.zig
In DynamicBitSetUnmanaged.deinit's and DynamicBitSet.deinit's documentation, "deinitializes" was uncapitalized.
* Fix typos in fifo.zig's documentation
Added a previously missing period to the end of the first line of LinearFifo.writableSlice's documentation.
Added missing periods to both lines of LinearFifo.pump's documentation.
* Fix typos in fmt.bufPrint's documentation
The starts of both lines were not capitalized.
* Fix minor documentation problems in fs/file.zig
Missing periods in documentation for Permissions.setReadOnly, PermissionsWindows.setReadOnly, MetadataUnix.created, MetadataLinux.created, and MetadataWindows.created.
* Fix a glaring typo in enums.zig
* Correct errors in fs.zig
* Fixed documentation problems in hash_map.zig
The added empty line in verify_context's documentation is needed, otherwise autodoc for some reason assumes that the list hasn't been terminated and continues reading off the rest of the documentation as if it were part of the second list item.
* Added lines between consecutive URLs in http.zig
Makes the documentation conform closer to what was intended.
* Fix wrongfully ended sentence in Uri.zig
* Handle wrongly entered comma in valgrind.zig.
* Add missing periods in wasm.zig's documentation
* Fix odd spacing in event/loop.zig
* Add missing period in http/Headers.zig
* Added missing period in io/limited_reader.zig
This isn't in the documentation due to what I guess is a limitation of autodoc, but it's clearly supposed to be. If it was, it would look pretty bad.
* Correct documentation in math/big/int.zig
* Correct formatting in math/big/rational.zig
* Create an actual link to ZIGNOR's paper.
* Fixed grammatical issues in sort/block.zig
This will not show up in the documentation currently.
* Fix typo in hash_map.zig
2023-10-21 21:24:55 +00:00
|
|
|
/// Re-enable error reporting. (see disableErrorReporting())
|
2018-12-30 15:55:24 +00:00
|
|
|
pub fn enableErrorReporting() void {
|
2019-11-17 03:03:52 +00:00
|
|
|
doClientRequestStmt(.ChangeErrDisablement, math.maxInt(usize), 0, 0, 0, 0);
|
2018-12-30 15:55:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Execute a monitor command from the client program.
|
|
|
|
/// If a connection is opened with GDB, the output will be sent
|
|
|
|
/// according to the output mode set for vgdb.
|
|
|
|
/// If no connection is opened, output will go to the log output.
|
|
|
|
/// Returns 1 if command not recognised, 0 otherwise.
|
|
|
|
pub fn monitorCommand(command: [*]u8) bool {
|
2023-06-15 07:14:16 +00:00
|
|
|
return doClientRequestExpr(0, .GdbMonitorCommand, @intFromPtr(command.ptr), 0, 0, 0, 0) != 0;
|
2018-12-30 15:55:24 +00:00
|
|
|
}
|
|
|
|
|
2019-11-17 02:59:52 +00:00
|
|
|
pub const memcheck = @import("valgrind/memcheck.zig");
|
|
|
|
pub const callgrind = @import("valgrind/callgrind.zig");
|
2019-11-17 03:16:09 +00:00
|
|
|
|
2021-01-22 14:45:28 +00:00
|
|
|
test {
|
2022-01-07 05:06:06 +00:00
|
|
|
_ = memcheck;
|
|
|
|
_ = callgrind;
|
2019-11-17 03:16:09 +00:00
|
|
|
}
|