mailing list of musl libc
 help / color / mirror / code / Atom feed
* ptrace addr2 weirdness
@ 2016-05-04 22:54 Alexander Monakov
  0 siblings, 0 replies; only message in thread
From: Alexander Monakov @ 2016-05-04 22:54 UTC (permalink / raw)
  To: musl

I was eyeballing musl's ptrace syscall wrapper and noticed it passes an extra
argument to the kernel:

long ptrace(int req, ...)
{
[snip]
	va_start(ap, req);
	pid = va_arg(ap, pid_t);
	addr = va_arg(ap, void *);
	data = va_arg(ap, void *);
	addr2 = va_arg(ap, void *);
	va_end(ap);

	if (req-1U < 3) data = &result;
	ret = syscall(SYS_ptrace, req, pid, addr, data, addr2);
[snip]
}

The last argument is completely undocumented in the Linux manpage and if you
look at generic kernel source you'll find that the syscall indeed only looks
at four arguments, req, pid, addr, data. Turns out the fifth 'addr2' argument
is used on sparc with PTRACE_{READ,WRITE}{DATA,TEXT} requests, but given that
musl neither supports sparc, nor (correctly) exposes those request kinds in
sys/ptrace.h, this argument passing is unnecessary, puzzling, and can be
either removed or at least a comment would be nice :)

The reason I was eyeballing it is to see how the variadicness is handled. In
principle the caller can supply fewer arguments for some request kinds,
although the manpage discourages that practice. musl could accept such calls
like this:

	pid = 0; addr = data = 0;
	if (req != PTRACE_TRACEME) {
		va_start(ap, req);
		pid = va_arg(ap, pid_t);
		if (req != PTRACE_KILL && /*other 2-arg reqs*/) {
			addr = va_arg(ap, void *);
			if (req != PTRACE_PEEKDATA && /*other 3-arg reqs*/)
				data = va_arg(ap, void *);
		}
		va_end(ap);
	}

Thanks.
Alexander


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2016-05-04 22:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-04 22:54 ptrace addr2 weirdness Alexander Monakov

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).