mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Alexander Monakov <amonakov@ispras.ru>
To: "musl@lists.openwall.com" <musl@lists.openwall.com>
Subject: RE: [PATCH] Define and use the __ptrace_request enumeration type in ptrace.
Date: Thu, 1 Oct 2015 23:08:55 +0300 (MSK)	[thread overview]
Message-ID: <alpine.LNX.2.20.1510012250220.16756@monopod.intra.ispras.ru> (raw)
In-Reply-To: <8B7D5EC97CB15C4DBFDCE766959C1607C6C43E@hhmail02.hh.imgtec.org>

On Mon, 21 Sep 2015, Vasileios Kalintiris wrote:
> Out of curiosity, what is the general implementation choice in this case in
> other C libraries? I'm asking because discovering GLIBC and handing it as a
> special case would be easy through the __GLIBC__ macro. However, musl doesn't
> provide any such macro (and other C libraries probably).

Such unfortunate exposure of __ptrace_request appears to be specific to glibc
and uclibc (which wants to mirror glibc interfaces in other ways also).  BSD
libcs and Android's Bionic libc have a plain 'int' there.

As a result, LLDB already had to workaround __ptrace_request on Android:
https://github.com/llvm-mirror/lldb/blob/303c5382c20618cd07944023b259d138fc07c822/include/lldb/Host/linux/Ptrace.h#L19

It would make sense to 'typedef int __ptrace_request' in LLDB under '#ifndef
__GLIBC__' instead of '#ifdef __ANDROID_NDK__'.

(likewise it makes sense to guard '#define PT_DETACH PTRACE_DETACH' with
'#ifndef PT_DETACH')

If a more fancy fix is desired, it is also possible to hide the variations in
the first argument type via a bit of preprocessor and C++ duct tape:

#include <sys/ptrace.h>

#define ptrace(arg1, ...) ptrace(_pcast(PTRACE_TRACEME, arg1), __VA_ARGS__)

template<class T, class V>
T _pcast(T, V v)
{
  return static_cast<T>(v);
}


The above would allow to eliminate explicit typecasts where LLDB uses ptrace.

Or alternatively if GNU features are acceptable, one can simply use
__typeof__(PTRACE_TRACEME) to retrieve the underlying type.

Alexander


      reply	other threads:[~2015-10-01 20:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-17 14:20 Vasileios Kalintiris
2015-09-21 20:31 ` Rich Felker
2015-09-21 21:39   ` Vasileios Kalintiris
2015-10-01 20:08     ` Alexander Monakov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LNX.2.20.1510012250220.16756@monopod.intra.ispras.ru \
    --to=amonakov@ispras.ru \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).