public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [BUG] problem with timer_create(2) for SIGEV_NONE ??
@ 2003-05-05 13:13 Aniruddha M Marathe
  2003-05-05 23:35 ` george anzinger
  2003-05-07 15:21 ` george anzinger
  0 siblings, 2 replies; 3+ messages in thread
From: Aniruddha M Marathe @ 2003-05-05 13:13 UTC (permalink / raw)
  To: george anzinger, linux-kernel; +Cc: Chandrashekhar RS

George,

 timer_create(2) fails in the case where sigev_notify parameter of
sigevent structure is SIGEV_NONE. I believe this should not happen.

Consider following code which was run on x86:

#include <stdio.h>
#include <syscall.h>
#include <errno.h>
#include <time.h>
#include <signal.h>

#define ANYSIG SIGALRM  /* Any signal value works*/

#ifndef __NR_timer_create
#if defined(__i386__)
#define __NR_timer_create 259
#elif defined(__ppc__)
#define __NR_timer_create 240
#elif defined(__powerpc64__)
#define __NR_timer_create 240
#elif defined(__x86_64__)
#define __NR_timer_create 222
#endif
#endif

_syscall3(int, timer_create, clockid_t, which_clock, struct sigevent *,
        timer_event_spec, timer_t *, created_timer_id);

 int main(int ac, char **av)
{
	timer_t created_timer_id;     /* holds the returned timer_id*/
	struct sigevent evp;
	int retval;

	evp.sigev_value =  (sigval_t) 0;
	evp.sigev_signo = ANYSIG;
	evp.sigev_notify = SIGEV_NONE;

	retval =	timer_create(CLOCK_REALTIME, &evp,
                                                &created_timer_id);

	if (retval < 0) {
		perror("timer_crete");
		printf("timer_create returned %d\n", retval); 
	} else {
		printf("timer_create success");
	}
	return 0;
}  /* End of main */

My analysis of this problem:

Kernel/include/asm-generic/siginfo.h contains following defintions

#define SIGEV_SIGNAL    0       /* notify via signal */
#define SIGEV_NONE      1       /* other notification: meaningless */
#define SIGEV_THREAD    2       /* deliver via thread creation */
#define SIGEV_THREAD_ID 4       /* deliver to thread */

In 2.5.68/kernel/posix-timers.c

Line 86:
MIPS_SEGV = ~(SIGEV_NONE & \
                      SIGEV_SIGNAL & \
                      SIGEV_THREAD &  \
                      SIGEV_THREAD_ID)
= (001 & 000 & 010 & 100) = ~(000) = 111

Line 364: in good_sigevent()
Lets assume that event->sigev_notify = SIGEV_NONE = 001
 
Line 368:
SIGEV_NONE & SIGEV_THREAD_ID = 001 & 100 = 000. Therefore the if
statement becomes false
 
Line 373:
SIGEV_NONE & SIGEV_SIGNAL = 001 & 000 = 000. Therefore the if statement
is false
 
Line 377:
SIGEV_NONE & ~(SIGEV_SIGNAL | SIGEV_THREAD_ID)
= 001 & ~(000 | 100)
= 001 & ~(100)
= 001 & 011
= 001
therefore the if condition is true
therefore the function returns NULL from line 378.
 
Now in sys_timer_create() at line number 462
Process = NULL
 
Now at line 489
if (!process) becomes TRUE
and function returns with EINVAL

Is my analysis right? If so can you comment on this behaviour?

-Aniruddha

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

end of thread, other threads:[~2003-05-07 15:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-05-05 13:13 [BUG] problem with timer_create(2) for SIGEV_NONE ?? Aniruddha M Marathe
2003-05-05 23:35 ` george anzinger
2003-05-07 15:21 ` george anzinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox