From: Mathieu Desnoyers Date: Thu, 25 Aug 2011 17:49:01 +0000 (-0400) Subject: Fix reversed mask usage of subbuffer offset X-Git-Tag: v1.9.1~255 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=aead202565d65894df2899a1c6095ffde1f1a779;p=lttng-ust.git Fix reversed mask usage of subbuffer offset Signed-off-by: Mathieu Desnoyers --- diff --git a/libringbuffer/backend.h b/libringbuffer/backend.h index d93f6d1f..83e07e42 100644 --- a/libringbuffer/backend.h +++ b/libringbuffer/backend.h @@ -88,7 +88,7 @@ void lib_ring_buffer_write(const struct lib_ring_buffer_config *config, */ CHAN_WARN_ON(chanb, offset >= chanb->buf_size); lib_ring_buffer_do_copy(config, - shmp_index(handle, shmp(handle, rpages->shmp)->p, offset & ~(chanb->subbuf_size - 1)), + shmp_index(handle, shmp(handle, rpages->shmp)->p, offset & (chanb->subbuf_size - 1)), src, len); ctx->buf_offset += len; } diff --git a/libringbuffer/ring_buffer_backend.c b/libringbuffer/ring_buffer_backend.c index bec31a30..3e202978 100644 --- a/libringbuffer/ring_buffer_backend.c +++ b/libringbuffer/ring_buffer_backend.c @@ -62,7 +62,7 @@ int lib_ring_buffer_backend_allocate(const struct lib_ring_buffer_config *config /* Allocate backend pages array elements */ for (i = 0; i < num_subbuf_alloc; i++) { align_shm(shmobj, __alignof__(struct lib_ring_buffer_backend_pages)); - set_shmp(shmp(handle, bufb->array)[i].shmp, + set_shmp(shmp_index(handle, bufb->array, i)->shmp, zalloc_shm(shmobj, sizeof(struct lib_ring_buffer_backend_pages))); if (!shmp(handle, shmp_index(handle, bufb->array, i)->shmp)) @@ -390,7 +390,7 @@ size_t lib_ring_buffer_read(struct lib_ring_buffer_backend *bufb, size_t offset, CHAN_WARN_ON(chanb, offset >= chanb->buf_size); CHAN_WARN_ON(chanb, config->mode == RING_BUFFER_OVERWRITE && subbuffer_id_is_noref(config, id)); - memcpy(dest, shmp_index(handle, shmp(handle, rpages->shmp)->p, offset & ~(chanb->subbuf_size - 1)), len); + memcpy(dest, shmp_index(handle, shmp(handle, rpages->shmp)->p, offset & (chanb->subbuf_size - 1)), len); return orig_len; } @@ -426,7 +426,7 @@ int lib_ring_buffer_read_cstr(struct lib_ring_buffer_backend *bufb, size_t offse CHAN_WARN_ON(chanb, offset >= chanb->buf_size); CHAN_WARN_ON(chanb, config->mode == RING_BUFFER_OVERWRITE && subbuffer_id_is_noref(config, id)); - str = shmp_index(handle, shmp(handle, rpages->shmp)->p, offset & ~(chanb->subbuf_size - 1)); + str = shmp_index(handle, shmp(handle, rpages->shmp)->p, offset & (chanb->subbuf_size - 1)); string_len = strnlen(str, len); if (dest && len) { memcpy(dest, str, string_len); @@ -460,7 +460,7 @@ void *lib_ring_buffer_read_offset_address(struct lib_ring_buffer_backend *bufb, rpages = shmp_index(handle, bufb->array, sb_bindex); CHAN_WARN_ON(chanb, config->mode == RING_BUFFER_OVERWRITE && subbuffer_id_is_noref(config, id)); - return shmp_index(handle, shmp(handle, rpages->shmp)->p, offset & ~(chanb->subbuf_size - 1)); + return shmp_index(handle, shmp(handle, rpages->shmp)->p, offset & (chanb->subbuf_size - 1)); } /** @@ -482,6 +482,7 @@ void *lib_ring_buffer_offset_address(struct lib_ring_buffer_backend *bufb, struct channel_backend *chanb = &shmp(handle, bufb->chan)->backend; const struct lib_ring_buffer_config *config = chanb->config; unsigned long sb_bindex, id; + void *ret; offset &= chanb->buf_size - 1; sbidx = offset >> chanb->subbuf_size_order; @@ -490,5 +491,5 @@ void *lib_ring_buffer_offset_address(struct lib_ring_buffer_backend *bufb, rpages = shmp_index(handle, bufb->array, sb_bindex); CHAN_WARN_ON(chanb, config->mode == RING_BUFFER_OVERWRITE && subbuffer_id_is_noref(config, id)); - return shmp_index(handle, shmp(handle, rpages->shmp)->p, offset & ~(chanb->subbuf_size - 1)); + return shmp_index(handle, shmp(handle, rpages->shmp)->p, offset & (chanb->subbuf_size - 1)); }