mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-02 07:28:21 +00:00
ringbuffer: add a RINGBUFFER_USER_COPY_FAILED macro
This commit is contained in:
@@ -47,5 +47,6 @@ size_t ringbuffer_remove(ringbuffer_t *ringbuffer, size_t count);
|
|||||||
#define RINGBUFFER_DATACOUNT(x) ((x)->write - (x)->read)
|
#define RINGBUFFER_DATACOUNT(x) ((x)->write - (x)->read)
|
||||||
#define RINGBUFFER_SIZE(x) (x)->size
|
#define RINGBUFFER_SIZE(x) (x)->size
|
||||||
#define RINGBUFFER_FREESPACE(x) (RINGBUFFER_SIZE(x) - RINGBUFFER_DATACOUNT(x))
|
#define RINGBUFFER_FREESPACE(x) (RINGBUFFER_SIZE(x) - RINGBUFFER_DATACOUNT(x))
|
||||||
|
#define RINGBUFFER_USER_COPY_FAILED -1lu
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -34,13 +34,13 @@ size_t ringbuffer_read(ringbuffer_t *ringbuffer, void *buffer, size_t count) {
|
|||||||
size_t firstpasscount = min(count, firstpassremaining);
|
size_t firstpasscount = min(count, firstpassremaining);
|
||||||
|
|
||||||
if (USERCOPY_POSSIBLY_FROM_USER(buffer, (void *)((uintptr_t)ringbuffer->data + firstpassoffset), firstpasscount))
|
if (USERCOPY_POSSIBLY_FROM_USER(buffer, (void *)((uintptr_t)ringbuffer->data + firstpassoffset), firstpasscount))
|
||||||
return -1;
|
return RINGBUFFER_USER_COPY_FAILED;
|
||||||
|
|
||||||
if (firstpasscount == count)
|
if (firstpasscount == count)
|
||||||
goto leave;
|
goto leave;
|
||||||
|
|
||||||
if (USERCOPY_POSSIBLY_FROM_USER((void *)((uintptr_t)buffer + firstpasscount), ringbuffer->data, count - firstpasscount))
|
if (USERCOPY_POSSIBLY_FROM_USER((void *)((uintptr_t)buffer + firstpasscount), ringbuffer->data, count - firstpasscount))
|
||||||
return -1;
|
return RINGBUFFER_USER_COPY_FAILED;
|
||||||
|
|
||||||
leave:
|
leave:
|
||||||
ringbuffer->read += count;
|
ringbuffer->read += count;
|
||||||
@@ -62,13 +62,13 @@ size_t ringbuffer_peek(ringbuffer_t *ringbuffer, void *buffer, uintmax_t offset,
|
|||||||
size_t firstpasscount = min(count, firstpassremaining);
|
size_t firstpasscount = min(count, firstpassremaining);
|
||||||
|
|
||||||
if (USERCOPY_POSSIBLY_TO_USER(buffer, (void *)((uintptr_t)ringbuffer->data + firstpassoffset), firstpasscount))
|
if (USERCOPY_POSSIBLY_TO_USER(buffer, (void *)((uintptr_t)ringbuffer->data + firstpassoffset), firstpasscount))
|
||||||
return -1;
|
return RINGBUFFER_USER_COPY_FAILED;
|
||||||
|
|
||||||
if (firstpasscount == count)
|
if (firstpasscount == count)
|
||||||
return count;
|
return count;
|
||||||
|
|
||||||
if (USERCOPY_POSSIBLY_TO_USER((void *)((uintptr_t)buffer + firstpasscount), ringbuffer->data, count - firstpasscount))
|
if (USERCOPY_POSSIBLY_TO_USER((void *)((uintptr_t)buffer + firstpasscount), ringbuffer->data, count - firstpasscount))
|
||||||
return -1;
|
return -RINGBUFFER_USER_COPY_FAILED;
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
@@ -81,13 +81,13 @@ size_t ringbuffer_write(ringbuffer_t *ringbuffer, void *buffer, size_t count) {
|
|||||||
size_t firstpasscount = min(count, firstpassremaining);
|
size_t firstpasscount = min(count, firstpassremaining);
|
||||||
|
|
||||||
if (USERCOPY_POSSIBLY_FROM_USER((void *)((uintptr_t)ringbuffer->data + firstpassoffset), buffer, firstpasscount))
|
if (USERCOPY_POSSIBLY_FROM_USER((void *)((uintptr_t)ringbuffer->data + firstpassoffset), buffer, firstpasscount))
|
||||||
return -1;
|
return RINGBUFFER_USER_COPY_FAILED;
|
||||||
|
|
||||||
if (firstpasscount == count)
|
if (firstpasscount == count)
|
||||||
goto leave;
|
goto leave;
|
||||||
|
|
||||||
if (USERCOPY_POSSIBLY_FROM_USER(ringbuffer->data, (void *)((uintptr_t)buffer + firstpasscount), count - firstpasscount))
|
if (USERCOPY_POSSIBLY_FROM_USER(ringbuffer->data, (void *)((uintptr_t)buffer + firstpasscount), count - firstpasscount))
|
||||||
return -1;
|
return RINGBUFFER_USER_COPY_FAILED;
|
||||||
|
|
||||||
leave:
|
leave:
|
||||||
ringbuffer->write += count;
|
ringbuffer->write += count;
|
||||||
|
|||||||
Reference in New Issue
Block a user