Android-specific prctl

enh enh at google.com
Tue Jul 28 21:28:00 UTC 2015


On 7/25/15, Dmitry V. Levin <ldv at altlinux.org> wrote:
> On Fri, Jul 24, 2015 at 09:17:59PM -0700, enh wrote:
>> Android kernels have an extra prctl that lets us set a name for an
>> anonymous VMA, which is useful for debugging. at the moment strace
>> shows it like this:
>>
>> prctl(0x53564d41 /* PR_??? */, 0, 0x7f7ab0e000, 0x2000, 0x7f7aaf76d0) = 0
>> prctl(0x53564d41 /* PR_??? */, 0, 0x7f7ab0d000, 0x1000, 0x7f7aaf76e8) = 0
>>
>> with this patch:
>>
>> diff --git a/prctl.c b/prctl.c
>> index 4a6bd25..e43569c 100644
>> --- a/prctl.c
>> +++ b/prctl.c
>> @@ -94,6 +94,22 @@ prctl_enter(struct tcb *tcp)
>>  		printstr(tcp, tcp->u_arg[1], TASK_COMM_LEN);
>>  		break;
>>
>> +#define PR_SET_VMA   0x53564d41
>> +#define PR_SET_VMA_ANON_NAME    0
>
> If there is a chance of these constants being defined in system headers
> some day, please wrap these definitions in ifdefs.

i'm told not, but never is a long time. sounds like a good idea to me.
i've wrapped the whole thing in an #ifdef __ANDROID__ too.

>> +	case PR_SET_VMA:
>> +		if (tcp->u_arg[1] == PR_SET_VMA_ANON_NAME) {
>> +			tprintf(", %lu", tcp->u_arg[1]);
>> +			tprintf(", %#lx", tcp->u_arg[2]);
>> +			tprintf(", %lu, ", tcp->u_arg[3]);
>> +			printstr(tcp, tcp->u_arg[4], -1);
>> +		} else {
>> +			// There are no other sub-options now, but there
>> +			// might be in future...
>> +			for (i = 1; i < tcp->s_ent->nargs; i++)
>> +				tprintf(", %#lx", tcp->u_arg[i]);
>
> Starting with commit v4.10-259-g3691562, this loop should be replaced with
>
> 			print_prctl_args(tcp, 1);

done.

>> +		}
>> +		break;
>> +
>>  	case PR_SET_MM:
>>  		tprints(", ");
>>  		printxval(pr_set_mm, tcp->u_arg[1], "PR_SET_MM_???");
>>
>> we get this instead:
>>
>> prctl(0x53564d41 /* PR_??? */, 0, 0x7f7ffe0000, 8192, "thread signal
>> stack") = 0
>> prctl(0x53564d41 /* PR_??? */, 0, 0x7f7ffdf000, 4096, "thread signal
>> stack guard page") = 0
>>
>> obviously i could change the xlat prctl_options.in file to add
>> PR_SET_VMA, but this isn't in upstream kernels so that seems wrong.
>
> Agreed.
>
>> i can easily keep the patch above and/or the one that touches the xlat
>> file in our tree, but i thought i'd ask what -- if anything -- of this
>> you'd be interested in having in upstream strace.
>
> I think this change would be OK for upstream strace.

cool. here's a cleaned up patch then:

diff --git a/prctl.c b/prctl.c
index 4c12bac..f5f655c 100644
--- a/prctl.c
+++ b/prctl.c
@@ -168,6 +168,27 @@ SYS_FUNC(prctl)
 		printstr(tcp, tcp->u_arg[1], TASK_COMM_LEN);
 		return RVAL_DECODED;

+#ifdef __ANDROID__
+# ifndef PR_SET_VMA
+#  define PR_SET_VMA   0x53564d41
+# endif
+# ifndef PR_SET_VMA_ANON_NAME
+#  define PR_SET_VMA_ANON_NAME    0
+# endif
+	case PR_SET_VMA:
+		if (tcp->u_arg[1] == PR_SET_VMA_ANON_NAME) {
+			tprintf(", %lu", tcp->u_arg[1]);
+			tprintf(", %#lx", tcp->u_arg[2]);
+			tprintf(", %lu, ", tcp->u_arg[3]);
+			printstr(tcp, tcp->u_arg[4], -1);
+		} else {
+			// There are no other sub-options now, but there
+			// might be in future...
+			print_prctl_args(tcp, 1);
+		}
+		break;
+#endif
+
 	case PR_SET_MM:
 		tprints(", ");
 		printxval(pr_set_mm, tcp->u_arg[1], "PR_SET_MM_???");


>
> --
> ldv
>


-- 
Elliott Hughes - http://who/enh - http://jessies.org/~enh/
Android native code/tools questions? Mail me/drop by/add me as a reviewer.




More information about the Strace-devel mailing list