Go to main content

man pages section 3: Extended Library Functions, Volume 3

Exit Print View

Updated: Wednesday, July 27, 2022
 
 

Pwrite (3PROC)

Name

Pread, Pwrite, Pread_string - read and write the process address space

Synopsis

#include <libproc.h>
ssize_t Pread(ps_prochandle_t *Pr, void *buf, size_t nbyte,
         uintptr_t address);
ssize_t Pwrite(ps_prochandle_t *Pr, const void *buf, size_t nbyte,
         uintptr_t address);
ssize_t Pread_string(ps_prochandle_t *Pr, char *buf, size_t size,
         uintptr_t address);

Description

The Pr argument identifies a victim process or core file attached to the controlling process by the create and grab interfaces. For more information, see the Pcreate(3PROC) and Pgrab(3PROC) man pages.

The Pread() function reads nbyte bytes from the virtual address space of the victim, starting at the location specified by the address argument, into the buffer of the caller, buf.

The Pwrite() function writes nbyte bytes into the virtual address space of the victim, starting at the location specified by the address argument, from the buffer of the caller, buf.

The Pread_string() function reads bytes from the virtual address space of the victim, starting at the location specified by the address argument, into the buffer of the caller, buf. The read is terminated upon reaching size bytes or upon encountering a null byte. The buffer is always null-terminated. The return value is the length of the string, not counting the null byte terminator.

Return Values

On successful completion, the Pread() function returns the actual number of bytes read. On error, it returns -1 and sets errno to indicate the error.

On successful completion, the Pwrite() function returns the actual number of bytes written. On error, it returns -1 and sets errno to indicate the error.

On successful completion, the Pread_string() function returns the length of the string that was read, not counting the null byte terminator. The return value is at least one less than the size argument. On error, it returns -1 and sets errno to indicate the error.

Errors

On failure, these errno values may be set:

EAGAIN

Process has been lost to control, needs the Preopen() function

EBUSY

Process is not stopped (Psetrun())

EINTR

Signal received while waiting for stop

EINVAL

Invalid argument

ENOENT

The victim process has terminated

Attributes

See attributes(7) for descriptions of the following attributes:

ATTRIBUTE TYPE
ATTRIBUTE VALUE
Interface Stability
Committed
MT-Level
Unsafe

See Also

libproc.h(3HEAD), libproc(3LIB), Pcreate(3PROC), Pgrab(3PROC), proc(5)