Hi, I want to be able to detect a userland module when it is loaded. For example, when I run some graphics test, the library libGL.so.1 will be loaded for each test case and I want to find the pid of the process to which libGL.so.1 is loaded. A D-program example will be greatly appreciated. Thanks. ************************************************ * C P Lin, Common Technology Project Lead. * * Sun Microsystems Inc. * * E-Mail: c.lin at sun.com * * Address: 4150 Network Circle, M/S UMPK12-210 * * Santa Clara, CA 95054 * * Phone: 650/352-4967 Fax: 650/786-7816 * ************************************************
Jonathan Adams
2005-Jul-27 22:53 UTC
[dtrace-discuss] How to detect a userland module in kernel?
On Wed, Jul 27, 2005 at 03:42:34PM -0700, C Lin wrote:> Hi, > > I want to be able to detect a userland module when it is > loaded. For example, when I run some graphics test, the > library libGL.so.1 will be loaded for each test case and > I want to find the pid of the process to which libGL.so.1 > is loaded. > > A D-program example will be greatly appreciated.Well, it''s easy to detect the opening of a particular string. It''s very hard to isolate the detection to just the dynamic linker, though. In any case, here''s a script which detects *any* program opening a path ending in "libGL.so.1", and reports the execname and pid: % cat > libload.d <<EOF #!/usr/sbin/dtrace -s #pragma D option quiet syscall::open:entry { self->arg = arg0; } syscall::open:return /self->arg != 0 && arg1 >= 0 && basename(copyinstr(self->arg)) == "libGL.so.1"/ { printf("prog %s (%d) opened libGL\n", execname, pid); } syscall::open:return { self->arg = 0; } EOF % chmod +x libload.d Enjoy, - jonathan -- Jonathan Adams, Solaris Kernel Development
vitezslav batrla
2005-Jul-28 12:15 UTC
[dtrace-discuss] How to detect a userland module in kernel?
Hi Jonathan, why did you use arg1 and not arg0 in testing return value from syscall, is there any document explaining this ? Is it due to syscall implementation in Solaris ? I tried to check it in source code, but got lost :( Thanks. - Vita On ?t, 2005-07-28 at 00:53, Jonathan Adams wrote:> On Wed, Jul 27, 2005 at 03:42:34PM -0700, C Lin wrote: > > Hi, > > > > I want to be able to detect a userland module when it is > > loaded. For example, when I run some graphics test, the > > library libGL.so.1 will be loaded for each test case and > > I want to find the pid of the process to which libGL.so.1 > > is loaded. > > > > A D-program example will be greatly appreciated. > > Well, it''s easy to detect the opening of a particular string. It''s very > hard to isolate the detection to just the dynamic linker, though. > > In any case, here''s a script which detects *any* program opening a > path ending in "libGL.so.1", and reports the execname and pid: > > % cat > libload.d <<EOF > #!/usr/sbin/dtrace -s > > #pragma D option quiet > > syscall::open:entry > { > self->arg = arg0; > } > > syscall::open:return > /self->arg != 0 && arg1 >= 0 && > basename(copyinstr(self->arg)) == "libGL.so.1"/ > { > printf("prog %s (%d) opened libGL\n", execname, pid); > } > > syscall::open:return > { > self->arg = 0; > } > EOF > % chmod +x libload.d > > Enjoy, > - jonathan > > -- > Jonathan Adams, Solaris Kernel Development > _______________________________________________ > dtrace-discuss mailing list > dtrace-discuss at opensolaris.org-------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 185 bytes Desc: This is a digitally signed message part URL: <http://mail.opensolaris.org/pipermail/dtrace-discuss/attachments/20050728/0d3cd55f/attachment.bin>
Adam Leventhal
2005-Jul-28 13:18 UTC
[dtrace-discuss] How to detect a userland module in kernel?
The return value from a syscall probe is actually in both arg0 and arg1 -- they''re identical in this case. The reason for this is an attempt at convenience: fbt and pid use arg1 to store the return value, and there''s no equivalent to the function offset for arg0 so we put the return value there as well. Adam On Thu, Jul 28, 2005 at 02:15:01PM +0200, vitezslav batrla wrote:> Hi Jonathan, > > why did you use arg1 and not arg0 in testing return value from syscall, is there any document explaining this ? Is it due to syscall implementation in Solaris ? I tried to check it in source code, but got lost :( > > Thanks. > > - Vita > > > On ?t, 2005-07-28 at 00:53, Jonathan Adams wrote: > > On Wed, Jul 27, 2005 at 03:42:34PM -0700, C Lin wrote: > > > Hi, > > > > > > I want to be able to detect a userland module when it is > > > loaded. For example, when I run some graphics test, the > > > library libGL.so.1 will be loaded for each test case and > > > I want to find the pid of the process to which libGL.so.1 > > > is loaded. > > > > > > A D-program example will be greatly appreciated. > > > > Well, it''s easy to detect the opening of a particular string. It''s very > > hard to isolate the detection to just the dynamic linker, though. > > > > In any case, here''s a script which detects *any* program opening a > > path ending in "libGL.so.1", and reports the execname and pid: > > > > % cat > libload.d <<EOF > > #!/usr/sbin/dtrace -s > > > > #pragma D option quiet > > > > syscall::open:entry > > { > > self->arg = arg0; > > } > > > > syscall::open:return > > /self->arg != 0 && arg1 >= 0 && > > basename(copyinstr(self->arg)) == "libGL.so.1"/ > > { > > printf("prog %s (%d) opened libGL\n", execname, pid); > > } > > > > syscall::open:return > > { > > self->arg = 0; > > } > > EOF > > % chmod +x libload.d > > > > Enjoy, > > - jonathan > > > > -- > > Jonathan Adams, Solaris Kernel Development > > _______________________________________________ > > dtrace-discuss mailing list > > dtrace-discuss at opensolaris.org> _______________________________________________ > dtrace-discuss mailing list > dtrace-discuss at opensolaris.org-- Adam Leventhal, Solaris Kernel Development http://blogs.sun.com/ahl
vitezslav batrla
2005-Jul-28 13:34 UTC
[dtrace-discuss] How to detect a userland module in kernel?
Understand, that''s a good reason :) - Vita On ?t, 2005-07-28 at 15:18, Adam Leventhal wrote:> The return value from a syscall probe is actually in both arg0 and arg1 -- > they''re identical in this case. The reason for this is an attempt at > convenience: fbt and pid use arg1 to store the return value, and there''s > no equivalent to the function offset for arg0 so we put the return value > there as well. > > Adam > > On Thu, Jul 28, 2005 at 02:15:01PM +0200, vitezslav batrla wrote: > > Hi Jonathan, > > > > why did you use arg1 and not arg0 in testing return value from syscall, is there any document explaining this ? Is it due to syscall implementation in Solaris ? I tried to check it in source code, but got lost :( > > > > Thanks. > > > > - Vita > > > > > > On ?t, 2005-07-28 at 00:53, Jonathan Adams wrote: > > > On Wed, Jul 27, 2005 at 03:42:34PM -0700, C Lin wrote: > > > > Hi, > > > > > > > > I want to be able to detect a userland module when it is > > > > loaded. For example, when I run some graphics test, the > > > > library libGL.so.1 will be loaded for each test case and > > > > I want to find the pid of the process to which libGL.so.1 > > > > is loaded. > > > > > > > > A D-program example will be greatly appreciated. > > > > > > Well, it''s easy to detect the opening of a particular string. It''s very > > > hard to isolate the detection to just the dynamic linker, though. > > > > > > In any case, here''s a script which detects *any* program opening a > > > path ending in "libGL.so.1", and reports the execname and pid: > > > > > > % cat > libload.d <<EOF > > > #!/usr/sbin/dtrace -s > > > > > > #pragma D option quiet > > > > > > syscall::open:entry > > > { > > > self->arg = arg0; > > > } > > > > > > syscall::open:return > > > /self->arg != 0 && arg1 >= 0 && > > > basename(copyinstr(self->arg)) == "libGL.so.1"/ > > > { > > > printf("prog %s (%d) opened libGL\n", execname, pid); > > > } > > > > > > syscall::open:return > > > { > > > self->arg = 0; > > > } > > > EOF > > > % chmod +x libload.d > > > > > > Enjoy, > > > - jonathan > > > > > > -- > > > Jonathan Adams, Solaris Kernel Development > > > _______________________________________________ > > > dtrace-discuss mailing list > > > dtrace-discuss at opensolaris.org > > > > > _______________________________________________ > > dtrace-discuss mailing list > > dtrace-discuss at opensolaris.org > > -- > Adam Leventhal, Solaris Kernel Development http://blogs.sun.com/ahl > _______________________________________________ > dtrace-discuss mailing list > dtrace-discuss at opensolaris.org-------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 185 bytes Desc: This is a digitally signed message part URL: <http://mail.opensolaris.org/pipermail/dtrace-discuss/attachments/20050728/07024037/attachment.bin>
Jonathan, This example works and it will be a huge boost to my Qtrace project and I really don''t know how to say thank you for this kind of help. You are really a great resource for Sun. Thanks a lot.>Date: Wed, 27 Jul 2005 15:53:55 -0700 >From: Jonathan Adams <jonathan.adams at sun.com> >To: C Lin <c.lin at sun.com> >Cc: dtrace-discuss at opensolaris.org >Subject: Re: [dtrace-discuss] How to detect a userland module in kernel? >Mime-Version: 1.0 >Content-Disposition: inline >User-Agent: Mutt/1.4.2.1i > >On Wed, Jul 27, 2005 at 03:42:34PM -0700, C Lin wrote: >> Hi, >> >> I want to be able to detect a userland module when it is >> loaded. For example, when I run some graphics test, the >> library libGL.so.1 will be loaded for each test case and >> I want to find the pid of the process to which libGL.so.1 >> is loaded. >> >> A D-program example will be greatly appreciated. > >Well, it''s easy to detect the opening of a particular string. It''s very >hard to isolate the detection to just the dynamic linker, though. > >In any case, here''s a script which detects *any* program opening a >path ending in "libGL.so.1", and reports the execname and pid: > >% cat > libload.d <<EOF >#!/usr/sbin/dtrace -s > >#pragma D option quiet > >syscall::open:entry >{ > self->arg = arg0; >} > >syscall::open:return >/self->arg != 0 && arg1 >= 0 && > basename(copyinstr(self->arg)) == "libGL.so.1"/ >{ > printf("prog %s (%d) opened libGL\n", execname, pid); >} > >syscall::open:return >{ > self->arg = 0; >} >EOF >% chmod +x libload.d > >Enjoy, >- jonathan > >-- >Jonathan Adams, Solaris Kernel Development************************************************ * C P Lin, Common Technology Project Lead. * * Sun Microsystems Inc. * * E-Mail: c.lin at sun.com * * Address: 4150 Network Circle, M/S UMPK12-210 * * Santa Clara, CA 95054 * * Phone: 650/352-4967 Fax: 650/786-7816 * ************************************************