All of lore.kernel.org
 help / color / mirror / Atom feed
From: Aaron Lewis <aaronlewis@google.com>
To: kvm@vger.kernel.org
Cc: pbonzini@redhat.com, jmattson@google.com, seanjc@google.com,
	Aaron Lewis <aaronlewis@google.com>
Subject: [PATCH v2 1/6] KVM: selftests: Add strnlen() to the string overrides
Date: Mon, 24 Apr 2023 22:58:49 +0000	[thread overview]
Message-ID: <20230424225854.4023978-2-aaronlewis@google.com> (raw)
In-Reply-To: <20230424225854.4023978-1-aaronlewis@google.com>

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>
---
 tools/testing/selftests/kvm/Makefile              | 1 +
 tools/testing/selftests/kvm/lib/string_override.c | 9 +++++++++
 2 files changed, 10 insertions(+)

diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile
index 18cadc669798..d93bee00c72a 100644
--- a/tools/testing/selftests/kvm/Makefile
+++ b/tools/testing/selftests/kvm/Makefile
@@ -198,6 +198,7 @@ endif
 CFLAGS += -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=gnu99 \
 	-Wno-gnu-variable-sized-type-not-at-end \
 	-fno-builtin-memcmp -fno-builtin-memcpy -fno-builtin-memset \
+	-fno-builtin-strnlen \
 	-fno-stack-protector -fno-PIE -I$(LINUX_TOOL_INCLUDE) \
 	-I$(LINUX_TOOL_ARCH_INCLUDE) -I$(LINUX_HDR_PATH) -Iinclude \
 	-I$(<D) -Iinclude/$(ARCH_DIR) -I ../rseq -I.. $(EXTRA_CFLAGS) \
diff --git a/tools/testing/selftests/kvm/lib/string_override.c b/tools/testing/selftests/kvm/lib/string_override.c
index 632398adc229..5d1c87277c49 100644
--- a/tools/testing/selftests/kvm/lib/string_override.c
+++ b/tools/testing/selftests/kvm/lib/string_override.c
@@ -37,3 +37,12 @@ void *memset(void *s, int c, size_t count)
 		*xs++ = c;
 	return s;
 }
+
+size_t strnlen(const char *s, size_t count)
+{
+	const char *sc;
+
+	for (sc = s; count-- && *sc != '\0'; ++sc)
+		/* nothing */;
+	return sc - s;
+}
-- 
2.40.0.634.g4ca3ef3211-goog


  reply	other threads:[~2023-04-24 22:59 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-24 22:58 [PATCH v2 0/6] Add printf and formatted asserts in the guest Aaron Lewis
2023-04-24 22:58 ` Aaron Lewis [this message]
2023-04-24 22:58 ` [PATCH v2 2/6] KVM: selftests: Add kvm_snprintf() to KVM selftests Aaron Lewis
2023-06-06  0:05   ` Sean Christopherson
2023-04-24 22:58 ` [PATCH v2 3/6] KVM: selftests: Add additional pages to the guest to accommodate ucall Aaron Lewis
2023-06-05 20:43   ` Sean Christopherson
2023-04-24 22:58 ` [PATCH v2 4/6] KVM: selftests: Add string formatting options to ucall Aaron Lewis
2023-06-05 21:44   ` Sean Christopherson
2023-06-07 16:55     ` Aaron Lewis
2023-04-24 22:58 ` [PATCH v2 5/6] KVM: selftests: Add ucall_fmt2() Aaron Lewis
2023-06-05 22:41   ` Sean Christopherson
2023-06-07 16:55     ` Aaron Lewis
2023-04-24 22:58 ` [PATCH v2 6/6] KVM: selftests: Add a selftest for guest prints and formatted asserts Aaron Lewis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230424225854.4023978-2-aaronlewis@google.com \
    --to=aaronlewis@google.com \
    --cc=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.