Operating System - HP-UX
1827286 Members
1722 Online
109717 Solutions
New Discussion

how to get current process in hpux11 dlkm

 
SOLVED
Go to solution
Laurent Menase
Honored Contributor

Re: how to get current process in hpux11 dlkm

lsof is using pstat_getpathname().
in the kernel this get the filename from the dnlc, or rebuild it which has no public API because needing multiple locks

The easiest way to do it is to have a daemon process in charge of identifying process pathname.
For instance your dlkm read() ( or a ioctl) could return the pid of current process calling kill, and sleeping to get the answer
then your user process run at rtprio read() the pid and call pstat* to get the pathname,
then write the answer to your dlkm ( with write or ioctl())
I think it is the more easy way to do it.

But again what exactly are you trying to develop? are you in contact with hp partners program? - it is a way sometime to get access to private APIs
kaijile
Frequent Advisor

Re: how to get current process in hpux11 dlkm

In application layer get the full pathname then return value to kernel, the system performance
will be changed,so i want to do it in kernel

I haven't contact with hp partners program hp patners program .


Sunny123_1
Esteemed Contributor

Re: how to get current process in hpux11 dlkm

Hi

I assume it is preferable to contact with hp partners program.

Regards
Sunny
kaijile
Frequent Advisor

Re: how to get current process in hpux11 dlkm

"then write the answer to your dlkm ( with write or ioctl())"
it need to use mknod commond to create a character device file.

Is it exist a method that not need to create a new file (such as mknod),can transmit data
from application layer to kernel?
Laurent Menase
Honored Contributor

Re: how to get current process in hpux11 dlkm

yes create a new syscall :D
What problem do you see to have a new node?

your dlkm can create the node itself.

Laurent Menase
Honored Contributor

Re: how to get current process in hpux11 dlkm

you can also make one ioctl and run everything from the kernel but passing user buffers with the ioctl().
The thread running only in the kernel.
but you need to use copyin/copyout to use the data.
kaijile
Frequent Advisor

Re: how to get current process in hpux11 dlkm

"your dlkm can create the node itself"
I don't know

In my experiment after make load


bash-4.0# lsdev |grep mymod
96 3 mymod pseudo

I use the mknod commond
#mknod /dev/mytest c 96 0

AT last i write a application program to use ioctl.

"create a new syscall" is replace the system call?
kaijile
Frequent Advisor

Re: how to get current process in hpux11 dlkm

before ioctl open the /dev/mytest file
Laurent Menase
Honored Contributor

Re: how to get current process in hpux11 dlkm

yes it is the simplest method to create the node
- the other being to use vn_create() in your _load function using the c_major field of the drv_info.
the ioctl can be used to start a function which will answer to any request using the same buffer each time.



kaijile
Frequent Advisor

Re: how to get current process in hpux11 dlkm

int mymod_ioctl( dev_t dev, int cmd, caddr_t arg, int flag )
{
struct test_data {
char buf[16];
uint32_t len;
};
struct test_data *ptr = NULL;
int ret = ESUCCESS;

switch (cmd) {
case CHGR_SSRFC_IS_PRESENT:
ptr = (struct test_data *)arg;
printf("%s:arg addr 0x%lx\n", __FUNCTION__, (uint32_t)(arg));
printf("%s:buf=%s,len=%d\n", __FUNCTION__, ptr->buf, ptr->len);
(void) strcpy(ptr->buf, "TESTIOCLtest");
break;

default:
break;
}
printf("%s: Exit mymod_ioctl \n", __FUNCTION__);
out:
return ret;
}

#include
#include
#include
#include
#include
#include
#include

struct test_data {
char buf[16];
uint32_t len;
};


int main()
{
int fd;
int ret;
struct test_data test;

fd = open("/dev/test", O_RDWR);
if(fd == -1)
perror("open()");

strncpy(test.buf, "hpuxxxx3hp", 16);
test.len = strlen(test.buf);

printf("before ioctl: test.buf=%s,test.len=%d\n", test.buf, test.len);

ret = ioctl(fd, CHGR_SSRFC_IS_PRESENT, &test);
if(ret == -1)
perror("ioctl()");

printf("after ioctl: test.buf=%s,test.len=%d\n", test.buf, test.len);

close(fd);
return 0;
}

bash-4.0# ./ioctl
before ioctl: test.buf=hpuxxxx3hp,test.len=10
after ioctl: test.buf=TESTxxx3hp,test.len=10

#dmesg|grep mymod_ioctl
mymod_ioctl:arg addr 0x49e31040
mymod_ioctl:buf=,len=-16777216
mymod_ioctl: Exit mymod_ioctl

why test data is not correct?
Laurent Menase
Honored Contributor

Re: how to get current process in hpux11 dlkm

In fact you used
#define CHGR_SSRFC_IS_PRESENT _IOR('X', 1, int)
which define it as needing to copy 1 int from the kernel on ioctl return.
in your case you must define:
struct test_data {
char buf[16];
uint32_t len;
};
#define MYIOCTL _IORW('Z',1,struct test_data)
This will make ioctl to copy your structure to the kernel (W), and back on exit (R) if the return value is 0.
if you want to pass user buffer address to the ioctl then you need to use
_IO('Z',1)

in that case data will point to uarea containing the value directly.
and you need to use copyin()/copyout() to copy to and from data to that buffer. But you will have user space address.

kaijile
Frequent Advisor

Re: how to get current process in hpux11 dlkm

"struct test_data {
char buf[16];
uint32_t len;
};
#define MYIOCTL _IORW('Z',1,struct test_data)"

It's work fine

when i replace the test_data structure to
struct test_data {
char *buf;
uint64_t len;
};

I used copyin(arg->buf, tmp, arg->len),but can't get the data .

why the copyin function return a error number 14(Bad address)?

I printf the arg->buf is 0x400051e800000000
In application layer my program ioctl.c printf the addr is 0x400051e8


Laurent Menase
Honored Contributor

Re: how to get current process in hpux11 dlkm

your buf pointer is a 32 bits pointer
so you need first move it to a 64 bit pointer before colling copyin
in fact it depends if your application is a 32bit one or a 64bit one.
so you must do:

struct test_data {
char *buf;
uint64_t len;
};
struct test_data32 {
unsigned int buf;
uint64_t len;
} *arg32;
if (ThisCallis32bit())
{
arg32=arg;
error = copyin(arg32->buf,tmp,arg32->len);
}

why the copyin function return a error number 14(Bad address)?

I printf the arg->buf is 0x400051e800000000
In application layer my program ioctl.c printf the addr is 0x400051e8
just a remark, don't forget to test the len before copyin, else you can garbage the memory
Laurent Menase
Honored Contributor

Re: how to get current process in hpux11 dlkm

don't forget to have the prototype of copyin() else the call may fail because arg32->buf is a 32 bits
if you want to be sure you can still do
copyin((unsigned long) arg32->buf,....)
kaijile
Frequent Advisor

Re: how to get current process in hpux11 dlkm

bash-4.0# nm -x /stand/vmunix |grep lookupname
[30860] |0x0000000000174c30|0x00000064|FUNC |GLOB |0| .text|lookupname
bash-4.0# nm -x /stand/vmunix |grep vn_create
[21615] |0x00000000001998f0|0x0000019c|FUNC |GLOB |0| .text|vn_create


where can i get the man pages for the exported interfaces?, like lookupname/vn_create/proc_pstat_idx_lookup_hold/proc_pstat_lookup_next_hold/proc_release
.
I cannot find these exported interfaces in the DDR.pdf and DDG.pdf
kaijile
Frequent Advisor

Re: how to get current process in hpux11 dlkm

close