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:
parent
98482d429b
commit
d888df9673
|
@ -585,10 +585,10 @@ static void note_record_taskname(pid_t pid, FAR const char *name)
|
||||||
|
|
||||||
ti = (FAR struct note_taskname_info_s *)
|
ti = (FAR struct note_taskname_info_s *)
|
||||||
&g_note_taskname.buffer[g_note_taskname.head];
|
&g_note_taskname.buffer[g_note_taskname.head];
|
||||||
ti->size = tilen;
|
ti->size = NOTE_ALIGN(tilen);
|
||||||
ti->pid = pid;
|
ti->pid = pid;
|
||||||
strlcpy(ti->name, name, namelen + 1);
|
strlcpy(ti->name, name, namelen + 1);
|
||||||
g_note_taskname.head += tilen;
|
g_note_taskname.head += ti->size;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -295,7 +295,7 @@ static void noteram_remove(FAR struct noteram_driver_s *drv)
|
||||||
|
|
||||||
/* Get the length of the note at the tail index */
|
/* 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));
|
DEBUGASSERT(length <= noteram_length(drv));
|
||||||
|
|
||||||
/* Increment the tail index to remove the entire note from the circular
|
/* 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--;
|
remaining--;
|
||||||
}
|
}
|
||||||
|
|
||||||
drv->ni_read = read;
|
drv->ni_read = NOTE_ALIGN(read);
|
||||||
|
|
||||||
return notelen;
|
return notelen;
|
||||||
}
|
}
|
||||||
|
@ -594,7 +594,7 @@ static void noteram_add(FAR struct note_driver_s *driver,
|
||||||
space = space < notelen ? space : notelen;
|
space = space < notelen ? space : notelen;
|
||||||
memcpy(drv->ni_buffer + head, note, space);
|
memcpy(drv->ni_buffer + head, note, space);
|
||||||
memcpy(drv->ni_buffer, buf + space, notelen - 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);
|
spin_unlock_irqrestore_wo_note(&drv->lock, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,9 @@
|
||||||
* Pre-processor Definitions
|
* 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
|
/* Provide defaults for some configuration settings (could be undefined with
|
||||||
* old configuration files)
|
* old configuration files)
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue