linux-modules.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] testsuite: also wrap gettid in syscall()
@ 2018-01-08 16:27 Lucas De Marchi
  2018-01-08 21:28 ` [PATCH v2] " Lucas De Marchi
  0 siblings, 1 reply; 4+ messages in thread
From: Lucas De Marchi @ 2018-01-08 16:27 UTC (permalink / raw)
  To: linux-modules; +Cc: caio.oliveira

Not a perfect solution for overriding syscall(), but at least
it makes the testsuite to pass in a modified nsswitch.conf (one that has
a module which calls syscall() to get the thread id).
---
 testsuite/init_module.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/testsuite/init_module.c b/testsuite/init_module.c
index 199186b..130dd32 100644
--- a/testsuite/init_module.c
+++ b/testsuite/init_module.c
@@ -355,6 +355,22 @@ TS_EXPORT long int syscall(long int __sysno, ...)
 		return ret;
 	}
 
+	if (__sysno == __NR_gettid) {
+		static void *nextlib = NULL;
+		static long (*nextlib_syscall)(long number, ...);
+
+		if (nextlib == NULL) {
+#ifdef RTLD_NEXT
+			nextlib = RTLD_NEXT;
+#else
+			nextlib = dlopen("libc.so.6", RTLD_LAZY);
+#endif
+			nextlib_syscall = dlsym(nextlib, "syscall");
+		}
+
+		return nextlib_syscall(__NR_gettid);
+	}
+
 	/*
 	 * FIXME: no way to call the libc function due since this is a
 	 * variadic argument function and we don't have a vsyscall() variant
-- 
2.14.3


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2] testsuite: also wrap gettid in syscall()
  2018-01-08 16:27 [PATCH] testsuite: also wrap gettid in syscall() Lucas De Marchi
@ 2018-01-08 21:28 ` Lucas De Marchi
  2018-01-08 21:31   ` Caio Marcelo de Oliveira Filho
  0 siblings, 1 reply; 4+ messages in thread
From: Lucas De Marchi @ 2018-01-08 21:28 UTC (permalink / raw)
  To: linux-modules; +Cc: caio.oliveira

Not a perfect solution for overriding syscall(), but at least
it makes the testsuite to pass in a modified nsswitch.conf (one that has
a module which calls syscall() to get the thread id).
---

v2:
	- Check nextlib_syscall rather than nextlib to avoid races in
	  multithreaded programs
	- Add error message in case we fail to get symbol

 testsuite/init_module.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/testsuite/init_module.c b/testsuite/init_module.c
index 199186b..c70147e 100644
--- a/testsuite/init_module.c
+++ b/testsuite/init_module.c
@@ -355,6 +355,26 @@ TS_EXPORT long int syscall(long int __sysno, ...)
 		return ret;
 	}
 
+	if (__sysno == __NR_gettid) {
+		static void *nextlib = NULL;
+		static long (*nextlib_syscall)(long number, ...);
+
+		if (nextlib_syscall == NULL) {
+#ifdef RTLD_NEXT
+			nextlib = RTLD_NEXT;
+#else
+			nextlib = dlopen("libc.so.6", RTLD_LAZY);
+#endif
+			nextlib_syscall = dlsym(nextlib, "syscall");
+			if (nextlib_syscall == NULL) {
+				fprintf(stderr, "FIXME FIXME FIXME: libc is missing syscall symbol\n");
+				abort();
+			}
+		}
+
+		return nextlib_syscall(__NR_gettid);
+	}
+
 	/*
 	 * FIXME: no way to call the libc function due since this is a
 	 * variadic argument function and we don't have a vsyscall() variant
-- 
2.14.3


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] testsuite: also wrap gettid in syscall()
  2018-01-08 21:28 ` [PATCH v2] " Lucas De Marchi
@ 2018-01-08 21:31   ` Caio Marcelo de Oliveira Filho
  2018-01-08 21:55     ` Lucas De Marchi
  0 siblings, 1 reply; 4+ messages in thread
From: Caio Marcelo de Oliveira Filho @ 2018-01-08 21:31 UTC (permalink / raw)
  To: Lucas De Marchi; +Cc: linux-modules

+1

On Mon, Jan 08, 2018 at 01:28:29PM -0800, Lucas De Marchi wrote:
> Not a perfect solution for overriding syscall(), but at least
> it makes the testsuite to pass in a modified nsswitch.conf (one that has
> a module which calls syscall() to get the thread id).
> ---
> 
> v2:
> 	- Check nextlib_syscall rather than nextlib to avoid races in
> 	  multithreaded programs
> 	- Add error message in case we fail to get symbol
> 
>  testsuite/init_module.c | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/testsuite/init_module.c b/testsuite/init_module.c
> index 199186b..c70147e 100644
> --- a/testsuite/init_module.c
> +++ b/testsuite/init_module.c
> @@ -355,6 +355,26 @@ TS_EXPORT long int syscall(long int __sysno, ...)
>  		return ret;
>  	}
>  
> +	if (__sysno == __NR_gettid) {
> +		static void *nextlib = NULL;
> +		static long (*nextlib_syscall)(long number, ...);
> +
> +		if (nextlib_syscall == NULL) {
> +#ifdef RTLD_NEXT
> +			nextlib = RTLD_NEXT;
> +#else
> +			nextlib = dlopen("libc.so.6", RTLD_LAZY);
> +#endif
> +			nextlib_syscall = dlsym(nextlib, "syscall");
> +			if (nextlib_syscall == NULL) {
> +				fprintf(stderr, "FIXME FIXME FIXME: libc is missing syscall symbol\n");
> +				abort();
> +			}
> +		}
> +
> +		return nextlib_syscall(__NR_gettid);
> +	}
> +
>  	/*
>  	 * FIXME: no way to call the libc function due since this is a
>  	 * variadic argument function and we don't have a vsyscall() variant
> -- 
> 2.14.3
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] testsuite: also wrap gettid in syscall()
  2018-01-08 21:31   ` Caio Marcelo de Oliveira Filho
@ 2018-01-08 21:55     ` Lucas De Marchi
  0 siblings, 0 replies; 4+ messages in thread
From: Lucas De Marchi @ 2018-01-08 21:55 UTC (permalink / raw)
  To: Caio Marcelo de Oliveira Filho; +Cc: Lucas De Marchi, linux-modules

On Mon, Jan 8, 2018 at 1:31 PM, Caio Marcelo de Oliveira Filho
<caio.oliveira@intel.com> wrote:
> +1
>
> On Mon, Jan 08, 2018 at 01:28:29PM -0800, Lucas De Marchi wrote:
>> Not a perfect solution for overriding syscall(), but at least
>> it makes the testsuite to pass in a modified nsswitch.conf (one that has
>> a module which calls syscall() to get the thread id).
>> ---
>>
>> v2:
>>       - Check nextlib_syscall rather than nextlib to avoid races in
>>         multithreaded programs
>>       - Add error message in case we fail to get symbol
>>
>>  testsuite/init_module.c | 20 ++++++++++++++++++++
>>  1 file changed, 20 insertions(+)
>>
>> diff --git a/testsuite/init_module.c b/testsuite/init_module.c
>> index 199186b..c70147e 100644
>> --- a/testsuite/init_module.c
>> +++ b/testsuite/init_module.c
>> @@ -355,6 +355,26 @@ TS_EXPORT long int syscall(long int __sysno, ...)
>>               return ret;
>>       }
>>
>> +     if (__sysno == __NR_gettid) {
>> +             static void *nextlib = NULL;
>> +             static long (*nextlib_syscall)(long number, ...);
>> +
>> +             if (nextlib_syscall == NULL) {
>> +#ifdef RTLD_NEXT
>> +                     nextlib = RTLD_NEXT;
>> +#else
>> +                     nextlib = dlopen("libc.so.6", RTLD_LAZY);
>> +#endif
>> +                     nextlib_syscall = dlsym(nextlib, "syscall");
>> +                     if (nextlib_syscall == NULL) {
>> +                             fprintf(stderr, "FIXME FIXME FIXME: libc is missing syscall symbol\n");

I added a call to dlerror() here and applied.

thanks for reviewing.

Lucas De Marchi

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-01-08 21:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-08 16:27 [PATCH] testsuite: also wrap gettid in syscall() Lucas De Marchi
2018-01-08 21:28 ` [PATCH v2] " Lucas De Marchi
2018-01-08 21:31   ` Caio Marcelo de Oliveira Filho
2018-01-08 21:55     ` Lucas De Marchi

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).