Provide string functions for use before ifuncs get resolved.

The change is a no-op for architectures which don't ifunc memset,
memcpy nor memmove.

Convert places which need them. Xen bits by royger.

Reviewed by:	kib
Approved by:	re (gjb)
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D17487
This commit is contained in:
Mateusz Guzik 2018-10-11 23:28:04 +00:00
parent f38828cbc7
commit 3f102f5881
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=339321
6 changed files with 15 additions and 9 deletions

View File

@ -92,6 +92,10 @@ get_cyclecount(void)
return (rdtsc());
}
#define MEMSET_EARLY_FUNC memset_std
#define MEMCPY_EARLY_FUNC memcpy_std
#define MEMMOVE_EARLY_FUNC memmove_std
#endif
#endif /* !_MACHINE_CPU_H_ */

View File

@ -3876,6 +3876,7 @@ kern/subr_compressor.c standard \
kern/subr_counter.c standard
kern/subr_devstat.c standard
kern/subr_disk.c standard
kern/subr_early.c standard
kern/subr_epoch.c standard
kern/subr_eventhandler.c standard
kern/subr_fattime.c standard

View File

@ -1682,14 +1682,10 @@ link_elf_ireloc(caddr_t kmdp)
{
struct elf_file eff;
elf_file_t ef;
volatile char *c;
size_t i;
ef = &eff;
/* Do not use bzero/memset before ireloc is done. */
for (c = (char *)ef, i = 0; i < sizeof(*ef); i++)
c[i] = 0;
bzero_early(ef, sizeof(*ef));
ef->modptr = kmdp;
ef->dynamic = (Elf_Dyn *)&_DYNAMIC;

View File

@ -324,6 +324,12 @@ void *memmove(void * _Nonnull dest, const void * _Nonnull src, size_t n);
int memcmp(const void *b1, const void *b2, size_t len);
#define memcmp(b1, b2, len) __builtin_memcmp((b1), (b2), (len))
void *memset_early(void * _Nonnull buf, int c, size_t len);
#define bzero_early(buf, len) memset_early((buf), 0, (len))
void *memcpy_early(void * _Nonnull to, const void * _Nonnull from, size_t len);
void *memmove_early(void * _Nonnull dest, const void * _Nonnull src, size_t n);
#define bcopy_early(from, to, len) memmove_early((to), (from), (len))
int copystr(const void * _Nonnull __restrict kfaddr,
void * _Nonnull __restrict kdaddr, size_t len,
size_t * __restrict lencopied);

View File

@ -355,8 +355,7 @@ ucode_load_bsp(uintptr_t free)
if (match != NULL) {
addr = map_ucode(free, len);
/* We can't use memcpy() before ifunc resolution. */
for (i = 0; i < len; i++)
addr[i] = ((volatile uint8_t *)match)[i];
memcpy_early(addr, match, len);
match = addr;
error = ucode_loader->load(match, false, &nrev, &orev);

View File

@ -259,7 +259,7 @@ hammer_time_xen_legacy(start_info_t *si, uint64_t xenstack)
*/
kenv = (void *)(physfree + KERNBASE);
physfree += PAGE_SIZE;
bzero(kenv, PAGE_SIZE);
bzero_early(kenv, PAGE_SIZE);
init_static_kenv(kenv, PAGE_SIZE);
/* Set the hooks for early functions that diverge from bare metal */
@ -320,7 +320,7 @@ hammer_time_xen(vm_paddr_t start_info_paddr)
*/
kenv = (void *)(physfree + KERNBASE);
physfree += PAGE_SIZE;
bzero(kenv, PAGE_SIZE);
bzero_early(kenv, PAGE_SIZE);
init_static_kenv(kenv, PAGE_SIZE);
if (start_info->modlist_paddr != 0) {