FreeBSD/lib/libthread_db/thread_db.c
/*
 * Support functions for reading from and writing to the target
 * address space.
 */
Support functions for reading from and writing to the target
address space.
Support functions for reading from and writing to the target address space .
static int
thr_pread(struct ps_prochandle *ph, psaddr_t addr, uint64_t *val,
    u_int size, u_int byteorder)
{
	uint8_t buf[sizeof(*val)];
	ps_err_e err;
	if (size > sizeof(buf))
		return (EOVERFLOW);
	err = ps_pread(ph, addr, buf, size);
	if (err != PS_OK)
		return (EFAULT);
	switch (byteorder) {
	case BIG_ENDIAN:
		switch (size) {
		case 1:
			*val = buf[0];
			break;
		case 2:
			*val = be16dec(buf);
			break;
		case 4:
			*val = be32dec(buf);
			break;
		case 8:
			*val = be64dec(buf);
			break;
		default:
			return (EINVAL);
		}
		break;
	case LITTLE_ENDIAN:
		switch (size) {
		case 1:
			*val = buf[0];
			break;
		case 2:
			*val = le16dec(buf);
			break;
		case 4:
			*val = le32dec(buf);
			break;
		case 8:
			*val = le64dec(buf);
			break;
		default:
			return (EINVAL);
		}
		break;
	default:
		return (EINVAL);
	}
	return (0);
}
static int thr_pread ( struct ps_prochandle * ph , psaddr_t addr , uint64_t * val , u_int size , u_int byteorder ) { uint8_t buf [ sizeof ( * val ) ] ; ps_err_e err ; if ( size > sizeof ( buf ) ) return ( EOVERFLOW ) ; err = ps_pread ( ph , addr , buf , size ) ; if ( err != PS_OK ) return ( EFAULT ) ; switch ( byteorder ) { case BIG_ENDIAN : switch ( size ) { case 1 : * val = buf [ 0 ] ; break ; case 2 : * val = be16dec ( buf ) ; break ; case 4 : * val = be32dec ( buf ) ; break ; case 8 : * val = be64dec ( buf ) ; break ; default : return ( EINVAL ) ; } break ; case LITTLE_ENDIAN : switch ( size ) { case 1 : * val = buf [ 0 ] ; break ; case 2 : * val = le16dec ( buf ) ; break ; case 4 : * val = le32dec ( buf ) ; break ; case 8 : * val = le64dec ( buf ) ; break ; default : return ( EINVAL ) ; } break ; default : return ( EINVAL ) ; } return ( 0 ) ; }
Support functions for reading from and writing to the target
 address space.
Support functions for reading from and writing to the target address space .