Changeset View
Changeset View
Standalone View
Standalone View
sys/opencrypto/criov.c
Show All 32 Lines | |||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/systm.h> | #include <sys/systm.h> | ||||
#include <sys/proc.h> | #include <sys/proc.h> | ||||
#include <sys/errno.h> | #include <sys/errno.h> | ||||
#include <sys/malloc.h> | #include <sys/malloc.h> | ||||
#include <sys/kernel.h> | #include <sys/kernel.h> | ||||
#include <sys/mbuf.h> | #include <sys/mbuf.h> | ||||
#include <sys/uio.h> | #include <sys/uio.h> | ||||
#include <sys/limits.h> | |||||
#include <opencrypto/cryptodev.h> | #include <opencrypto/cryptodev.h> | ||||
/* | /* | ||||
* This macro is only for avoiding code duplication, as we need to skip | * This macro is only for avoiding code duplication, as we need to skip | ||||
* given number of bytes in the same way in three functions below. | * given number of bytes in the same way in three functions below. | ||||
*/ | */ | ||||
#define CUIO_SKIP() do { \ | #define CUIO_SKIP() do { \ | ||||
▲ Show 20 Lines • Show All 185 Lines • ▼ Show 20 Lines | crypto_mbuftoiov(struct mbuf *mbuf, struct iovec **iovptr, int *cnt, | ||||
if (*allocated) | if (*allocated) | ||||
KASSERT(*cnt == i, ("did not allocate correct amount: %d != %d", | KASSERT(*cnt == i, ("did not allocate correct amount: %d != %d", | ||||
*cnt, i)); | *cnt, i)); | ||||
*iovptr = iov; | *iovptr = iov; | ||||
*cnt = i; | *cnt = i; | ||||
return 0; | return 0; | ||||
} | } | ||||
static inline void * | |||||
m_contiguous_subsegment(struct mbuf *m, size_t skip, size_t len) | |||||
{ | |||||
int rel_off; | |||||
MPASS(skip <= INT_MAX); | |||||
m = m_getptr(m, (int)skip, &rel_off); | |||||
if (m == NULL) | |||||
return (NULL); | |||||
MPASS(rel_off >= 0); | |||||
skip = rel_off; | |||||
if (skip + len > m->m_len) | |||||
return (NULL); | |||||
return (mtod(m, char*) + skip); | |||||
} | |||||
static inline void * | |||||
cuio_contiguous_segment(struct uio *uio, size_t skip, size_t len) | |||||
{ | |||||
int rel_off, idx; | |||||
MPASS(skip <= INT_MAX); | |||||
idx = cuio_getptr(uio, (int)skip, &rel_off); | |||||
if (idx < 0) | |||||
return (NULL); | |||||
MPASS(rel_off >= 0); | |||||
skip = rel_off; | |||||
if (skip + len > uio->uio_iov[idx].iov_len) | |||||
return (NULL); | |||||
return ((char *)uio->uio_iov[idx].iov_base + skip); | |||||
} | |||||
void * | |||||
crypto_contiguous_subsegment(int crp_flags, void *crpbuf, | |||||
size_t skip, size_t len) | |||||
{ | |||||
if ((crp_flags & CRYPTO_F_IMBUF) != 0) | |||||
return (m_contiguous_subsegment(crpbuf, skip, len)); | |||||
else if ((crp_flags & CRYPTO_F_IOV) != 0) | |||||
return (cuio_contiguous_segment(crpbuf, skip, len)); | |||||
else { | |||||
MPASS((crp_flags & (CRYPTO_F_IMBUF | CRYPTO_F_IOV)) != | |||||
(CRYPTO_F_IMBUF | CRYPTO_F_IOV)); | |||||
return ((char*)crpbuf + skip); | |||||
} | |||||
} | |||||