Page MenuHomeFreeBSD

strdup.c, strndup.c: Prefer memcpy() over bcopy()
ClosedPublic

Authored by zlei on Feb 15 2025, 6:49 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Jul 1, 6:21 AM
Unknown Object (File)
Wed, Jun 25, 4:49 PM
Unknown Object (File)
Tue, Jun 24, 11:33 PM
Unknown Object (File)
Wed, Jun 18, 12:47 PM
Unknown Object (File)
Jun 2 2025, 1:00 PM
Unknown Object (File)
Jun 2 2025, 9:24 AM
Unknown Object (File)
May 13 2025, 3:55 PM
Unknown Object (File)
Apr 29 2025, 6:38 PM
Subscribers

Details

Summary

The newly allocated memory can not overlap with the string if the string
is properly null-terminated or the maxlen is a valid lengh. Prefer memcpy()
over memmove(), aka bcopy(), for slight performance gain.

No functional change intended.

MFC after: 2 weeks

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

zlei requested review of this revision.Feb 15 2025, 6:49 PM
zlei created this revision.

Out of topic,
@imp
I see @andrew made the change to redirect memcpy() to compiler provided __buildin_memcpy() [1] , but powerpc and riscv still have libkern/bcopy.c compiled into the kernel. I have not tested yet but I guess libkern/bcopy.c is no longer required for powerpc and riscv ?

[1] 849aef496d2a Port the NetBSD KCSAN runtime to FreeBSD

This revision is now accepted and ready to land.Feb 16 2025, 1:48 PM

Out of topic,
@imp
I see @andrew made the change to redirect memcpy() to compiler provided __buildin_memcpy() [1] , but powerpc and riscv still have libkern/bcopy.c compiled into the kernel. I have not tested yet but I guess libkern/bcopy.c is no longer required for powerpc and riscv ?

[1] 849aef496d2a Port the NetBSD KCSAN runtime to FreeBSD

Please ignore the above comment. I thought __buildin_memcpy() always inline and behaves the same with __buildin_memcpy_inline() but that is not true [2].

[2] https://clang.llvm.org/docs/LanguageExtensions.html#memory-builtins