note: add ringbuffer aligned access handle

Fix ubsan warning that writes need to be aligned to memory boundaries when writing data

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
This commit is contained in:
yinshengkai 2023-11-13 12:11:23 +08:00 committed by Xiang Xiao
parent ca989b5101
commit 1c8d0bfdc7
3 changed files with 8 additions and 5 deletions

View File

@ -585,10 +585,10 @@ static void note_record_taskname(pid_t pid, FAR const char *name)
ti = (FAR struct note_taskname_info_s *)
&g_note_taskname.buffer[g_note_taskname.head];
ti->size = tilen;
ti->size = NOTE_ALIGN(tilen);
ti->pid = pid;
strlcpy(ti->name, name, namelen + 1);
g_note_taskname.head += tilen;
g_note_taskname.head += ti->size;
}
#endif

View File

@ -295,7 +295,7 @@ static void noteram_remove(FAR struct noteram_driver_s *drv)
/* Get the length of the note at the tail index */
length = drv->ni_buffer[tail];
length = NOTE_ALIGN(drv->ni_buffer[tail]);
DEBUGASSERT(length <= noteram_length(drv));
/* Increment the tail index to remove the entire note from the circular
@ -387,7 +387,7 @@ static ssize_t noteram_get(FAR struct noteram_driver_s *drv,
remaining--;
}
drv->ni_read = read;
drv->ni_read = NOTE_ALIGN(read);
return notelen;
}
@ -594,7 +594,7 @@ static void noteram_add(FAR struct note_driver_s *driver,
space = space < notelen ? space : notelen;
memcpy(drv->ni_buffer + head, note, space);
memcpy(drv->ni_buffer, buf + space, notelen - space);
drv->ni_head = noteram_next(drv, head, notelen);
drv->ni_head = noteram_next(drv, head, NOTE_ALIGN(notelen));
spin_unlock_irqrestore_wo_note(&drv->lock, flags);
}

View File

@ -51,6 +51,9 @@
* Pre-processor Definitions
****************************************************************************/
#define NOTE_ALIGN(a) (((a) + sizeof(uintptr_t) - 1) & \
~(sizeof(uintptr_t) - 1))
/* Provide defaults for some configuration settings (could be undefined with
* old configuration files)
*/