12.1.1 Avoiding Errors

The copyin and copyinstr subroutines cannot read from user addresses that have not yet been touched, so even a valid address could cause an error if the page containing that address has not yet been faulted in by being accessed. Consider the following example:

# dtrace -n syscall::open:entry'{ trace(copyinstr(arg0)); }'
dtrace: description 'syscall::open:entry' matched 1 probe
CPU     ID                    FUNCTION:NAME
  1      8                       open:entry   /dev/sr0                         
  1      8                       open:entry   /var/run/utmp                    
  1      8                       open:entry   /dev/sr0
dtrace: error on enabled probe ID 2 (ID 8: syscall::open:entry): \
invalid address (0x9af1b) in action #1 at DIF offset 52

In the example output, the application was functioning properly, and the address in arg0 was valid, but it referred to a page that had not yet been accessed by the corresponding process. To resolve this issue, you would need to wait for the kernel or an application to use the data before tracing it.

For example, you might wait until the system call returns to apply copyinstr, as shown here:

# dtrace -n syscall::open:entry'{ self->file = arg0; }' \
  -n syscall::open:return'{ trace(copyinstr(self->file)); self->file = 0; }'
dtrace: description 'syscall::open:entry' matched 1 probe
dtrace: description 'syscall::open:return' matched 1 probe
CPU     ID                    FUNCTION:NAME
  0      9                      open:return   /dev/sr0                         
  1      9                      open:return   /usr/lib64/gconv/gconv-modules.cache
  0      9                      open:return   /dev/sr0                         
  0      9                      open:return   public/pickup                    
  1      9                      open:return   maildrop                         
  1      9                      open:return   /dev/sr0                         
  1      9                      open:return   /dev/sr0                         
  1      9                      open:return   /var/run/utmp
...