Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Enumerating threads in own process: (1 Item)
   
Enumerating threads in own process  
Hi,

I am trying to enumerate all the threads in my current process. I need to get the cpu registers, so I'm trying to use 
the procfs, specifically DCMD_PROC_CURTHREAD, DCMD_PROC_GETGREG, and DCMD_PROC_SETREG.

I am encountering different behaviour if I try to use DCMD_PROC_CURTHREAD on a thread in my process, as opposed to in 
another process. When trying to set the current thread in my own process I get EINVAL, while on another process I get 
EOK.

Does DCMD_PROC_CURTHREAD/_GETGREG/_SETGREG not work on the current process? 

Is there a way to enumerate the threads in the current process including the CPU register values?

Here's some test code:
[code]
#include <stdio.h>
#include <sys/procfs.h>
#include <pthread.h>
#include <fcntl.h>
#include <sys/neutrino.h>

int main (int argc, char ** argv)
{
    char as_path[PATH_MAX];
    procfs_greg gregs;
    int fd, res;
    pthread_t thread_id;

    //sprintf (as_path, "/proc/%d/as", 19091494 );
    sprintf (as_path, "/proc/%d/as", getpid() );

    fd = open(as_path, O_RDWR);

    thread_id = 1;

    res = ThreadCtl (_NTO_TCTL_ONE_THREAD_HOLD, (void *) thread_id);
    printf ("ThreadCtl HOLD res: %d\n", res);

    res = devctl (fd, DCMD_PROC_CURTHREAD, &thread_id, sizeof(thread_id), 0);
    printf ("CURTHREAD res: %d\n", res);

    res = devctl (fd, DCMD_PROC_GETGREG, &gregs, sizeof(gregs), 0);
    printf ("GETGREG res: %d\n", res);

    res = devctl (fd, DCMD_PROC_SETGREG, &gregs, sizeof(gregs), 0);
    printf ("SETGREG res: %d\n", res);

    ThreadCtl (_NTO_TCTL_ONE_THREAD_CONT, (void *) thread_id);
    printf ("ThreadCtl CONT res: %d\n", res);
    return 0;
}
[/code]

When using getpid, I get the following output:
[code]
ThreadCtl HOLD res: 0
CURTHREAD res: 22
GETGREG res: 22
SETGREG res: 22
ThreadCtl CONT res: 22
[/code]

When using the pid of a different process, I get:
[code]
ThreadCtl HOLD res: 0
CURTHREAD res: 0
GETGREG res: 0
SETGREG res: 0
ThreadCtl CONT res: 0
[/code]

I'd appreciate any help with this.