Skip to content

Commit a1c1b55

Browse files
suomilewissean-jc
authored andcommitted
KVM: selftests: Add strnlen() to the string overrides
Add strnlen() to the string overrides to allow it to be called in the guest. The implementation for strnlen() was taken from the kernel's generic version, lib/string.c. This will be needed when printf() is introduced. Signed-off-by: Aaron Lewis <aaronlewis@google.com> Link: https://lore.kernel.org/r/20230729003643.1053367-5-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 6783ca4 commit a1c1b55

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

tools/testing/selftests/kvm/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ endif
204204
CFLAGS += -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=gnu99 \
205205
-Wno-gnu-variable-sized-type-not-at-end -MD\
206206
-fno-builtin-memcmp -fno-builtin-memcpy -fno-builtin-memset \
207+
-fno-builtin-strnlen \
207208
-fno-stack-protector -fno-PIE -I$(LINUX_TOOL_INCLUDE) \
208209
-I$(LINUX_TOOL_ARCH_INCLUDE) -I$(LINUX_HDR_PATH) -Iinclude \
209210
-I$(<D) -Iinclude/$(ARCH_DIR) -I ../rseq -I.. $(EXTRA_CFLAGS) \

tools/testing/selftests/kvm/lib/string_override.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,12 @@ void *memset(void *s, int c, size_t count)
3737
*xs++ = c;
3838
return s;
3939
}
40+
41+
size_t strnlen(const char *s, size_t count)
42+
{
43+
const char *sc;
44+
45+
for (sc = s; count-- && *sc != '\0'; ++sc)
46+
/* nothing */;
47+
return sc - s;
48+
}

0 commit comments

Comments
 (0)