Skip to contentSkip to conversation

Posix timer syscalls [Bug 1042388]

Qemu-devel Erik de Castro Lopo 2 participants 3 messages Aug 29, 2012

lore
Share & tools
lore
#0 lore raw

Hi all,

I've spent some time messing about in linux-user/syscall.c and I have stubs for all 5 posix timer syscalls:

    int timer_create(clockid_t clockid, struct sigevent *sevp,
                     timer_t *timerid);

    int timer_settime(timer_t timerid, int flags,
                      const struct itimerspec *new_value,
                      struct itimerspec * old_value);

    int timer_gettime(timer_t timerid, struct itimerspec *curr_value);

    int timer_getoverrun(timer_t timerid);

    int timer_delete(timer_t timerid);

Obviously all these parameters need to be converted between host and target. I've already found struct target_itimerspec in linux-user/syscall_defs.h and that looks like it will be useful.

I'm having trouble struct sigevent pointer that is passed to timer_create() which is defined as:

    typedef struct sigevent {
        sigval_t sigev_value;
        int sigev_signo;
        int sigev_notify;
        union {
            int _pad[SIGEV_PAD_SIZE];
            int _tid;

            struct {
                void (*_function)(sigval_t);
                void *_attribute;	/* really pthread_attr_t */
            } _sigev_thread;
        } _sigev_un;
    } sigevent_t;

Any ideas on how to handle the union within this struct?

Cheers,
Erik

Signature · 3 lines
----------------------------------------------------------------------
Erik de Castro Lopo
http://www.mega-nerd.com/
#1 lore raw
Quoted 18 lines · Erik de Castro Lopo

I'm having trouble struct sigevent pointer that is passed to timer_create() which is defined as:

    typedef struct sigevent {
        sigval_t sigev_value;
        int sigev_signo;
        int sigev_notify;
        union {
            int _pad[SIGEV_PAD_SIZE];
            int _tid;

            struct {
                void (*_function)(sigval_t);
                void *_attribute;       /* really pthread_attr_t */
            } _sigev_thread;
        } _sigev_un;
    } sigevent_t;
Quoted 1 line

Any ideas on how to handle the union within this struct?

You need to look at how the kernel decides which of the fields of the union is valid, and use the same logic to decide how to convert it in qemu.

In this case I think that means that if (sigev_notify & SIGEV_THREAD_ID) != 0, _tid is valid and must be converted. Otherwise convert _sigev_thread.

-- PMM

#2 lore raw
Quoted 7 lines · Peter Maydell

You need to look at how the kernel decides which of the fields of the union is valid, and use the same logic to decide how to convert it in qemu.

In this case I think that means that if (sigev_notify & SIGEV_THREAD_ID) != 0, _tid is valid and must be converted. Otherwise convert _sigev_thread.

Ah, that makes sense. Thanks.

Cheers,
Erik

Signature · 3 lines
----------------------------------------------------------------------
Erik de Castro Lopo
http://www.mega-nerd.com/