From patchwork Thu Aug 17 12:23:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 13356379 Received: from esa1.hc3370-68.iphmx.com (esa1.hc3370-68.iphmx.com [216.71.145.142]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 391C213AD4 for ; Thu, 17 Aug 2023 12:24:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1692275064; h=message-id:date:to:from:subject:mime-version; bh=fAY5UBc+FZVxU+jvgXw1saPEdsyvVQT+q+eZ12auT38=; b=Jbf+P5BL/lAD2dgpxXg2UuR6NtCcs+ndjJkqAUDGWdUwjknZ8uBCKaiy Ia4N8+QoyBJIZg4kDubhp0EHZhmdlehyRrjkVRVdNoxnsSJqQnAcvfN8/ zKqSRQ9FdjvsBFVQWe8KBs99QbW4J3rT+az5SQw/9im58LKBpvcb8IoMb 4=; X-IronPort-RemoteIP: 104.47.51.41 X-IronPort-MID: 120202686 X-IronPort-Reputation: None X-IronPort-Listener: OutboundMail X-IronPort-SenderGroup: RELAY_O365 X-IronPort-MailFlowPolicy: $RELAYED IronPort-Data: A9a23:cUFtkK+djWBj+xsNc+WvDrUDBX+TJUtcMsCJ2f8bNWPdYAtSk2BPi n1XRCnXfqzSUtbHC5sjL9L0rldB+8eV0JYyDFE0nZ0GZyITpZOZWNrFI0qvZnKfdsefERo25 pRHOoeYJZtpQ3bW9k2kY+m6p3MljviGGOClBuXIYX0sT1Q7Qyor0h47wOBRbuKE4zScK1rlV YTa/ZSHYDdJogJJD1/4y55viTsw7amu4WlE5AwzOK4U5AWPmigbAsoSdfrudCf2HtBaFL/mS 77Pwo/i8zKC9X/BKD8HfpXTKRRWH+GIbWBirlIMBsBOVzAb/nRaPp4TbaZaMgEPzW3Sx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1684814400"; d="scan'208";a="120202686" Received: from mail-bn1nam02lp2041.outbound.protection.outlook.com (HELO NAM02-BN1-obe.outbound.protection.outlook.com) ([104.47.51.41]) by ob1.hc3370-68.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 17 Aug 2023 08:23:14 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TfKrJpNYGNg3lTY8zRDWFvaLp6oQ42Cpaw3joFl1e5y0ktECdjantp6cs7+5/6zBv4sCv3mS7+dsWR2JUP7B/NtWZbtJxdnLPsiBzPA5qHRSeD3dRgOc10mCNyVfdIU2J3mQIL5ZDn+Y76HJA+IaHXVB7u1CMmtWFDw4+N/SjN1teQPCPZEo5UWn4czwRZ42F52F/wnZH9EFg2TK6ZbgiGQi4377PXnDmmrD2eRjCvVtcLlF/Yl7JMtLHsHp8e/ubGcv8iioqFYdRbsaeWBsqLJ6BoosaLY+AsydC/GuAVYe0Nm1DOUAgKsOynFh2HV/vPcpxQBLDQXGAmTSaxW6Ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=fAY5UBc+FZVxU+jvgXw1saPEdsyvVQT+q+eZ12auT38=; b=Azpc4C2rI733nLHuRVUJXKoXOOKXmyQHgDHo0LOtNHBARX+y/ADpHzmCTriedesdynEKGsxlpMM9uhDUrPEEPLtO9Tiq+gO2lgDtYCRwvYynfW80wQgo2l93KAohJLXDAomw1nhOfp7oGSof4uIAjUxA3NrJgSwMRMDUunPVtPzkJ1KNO1bsPqISM36DEStC8I6PnOYoBu4FoK0G0exZgNQOLThQEZou+DtbobFbz54B6a3X0+tl71u/NuQRQvKD2u+I2HVC6oq3ag1QyCf6+ht1Nwetv3GBiIJMQTvT/4tfBuVKLZm+ZFQAeSaEgVXXQ104o/fWJ4dmYa2p1T/rkA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.onmicrosoft.com; s=selector2-citrix-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fAY5UBc+FZVxU+jvgXw1saPEdsyvVQT+q+eZ12auT38=; b=oh4AOKNAq6iOB9QY+GbWzplRe+4hY0GfxkWh0y8apNxCjBECu7tXkMJsGChwzULeKJYxaKw7dzljuDSjsl7JyliSWorSuxGEPKhUYXuEADCBQ51Gih3M2Uqf+LzNhTiw/yhtlL+VkzUMyoJstXfiPouFIWmGNblnKU///dCGMFg= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com; Received: from BYAPR03MB3623.namprd03.prod.outlook.com (2603:10b6:a02:aa::12) by CO1PR03MB5827.namprd03.prod.outlook.com (2603:10b6:303:9a::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.31; Thu, 17 Aug 2023 12:23:12 +0000 Received: from BYAPR03MB3623.namprd03.prod.outlook.com ([fe80::afa:50df:158a:a912]) by BYAPR03MB3623.namprd03.prod.outlook.com ([fe80::afa:50df:158a:a912%5]) with mapi id 15.20.6678.029; Thu, 17 Aug 2023 12:23:12 +0000 Message-ID: Date: Thu, 17 Aug 2023 13:23:06 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Content-Language: en-GB To: tools@linux.kernel.org From: Andrew Cooper Subject: b4 patch corruption X-ClientProxiedBy: LO4P123CA0496.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1ab::15) To BYAPR03MB3623.namprd03.prod.outlook.com (2603:10b6:a02:aa::12) Precedence: bulk X-Mailing-List: tools@linux.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR03MB3623:EE_|CO1PR03MB5827:EE_ X-MS-Office365-Filtering-Correlation-Id: b61b2a7a-4944-4143-e1e9-08db9f1cb913 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +VgZqZjWK9aeKnHVGdoHfXLHZCFIp3Rjt4ulCoqxTIlpKCCa1EbYyt49CHDiyXkC5YucnonqJ7Z0+fAT3NuROitnwqPnWZtwLksIcIcEYtjKoByiUofD7gIm7lEUmfgIgCmEEFloYN0osjt6PYpMmVR4C6egEGsO6MkBXCG4ltFHh53+Uv+ulx9MFW0uRO69IgTE8PH4tKTd9nBvdHkGaaqKpGi6ErU3YHE9o0T2q2/FS86fAuUk+ZhxCH8f8/bsxdKY66X0GSDM+2KR9rNnntQz7bvuQa8ghmqPaIkNv2tMGrhC3qX0gT/NzQcDUh5xmOaQCDOWk8GVwxAILQ41u10nKnnSZ/obU+c7QJFlRrOgUu/wfnGUk3ulUIqHIfwXBHLYfOzzjIouK/0NW4iGSc3js4WQn0Dq6aIiv97IOIl7CwYG5HTbCUsUi2y8kBR8wu4bVZRvr3LWGU/9/kRbAX6UhwNh55AjkTSD0vOgLB6Z8dtJeoLHegZ/exx878e9+SaAEpbW1Jaf6qJjGcjdDkiio+HRYnSzoDVRuNB5zBsXQ0j9IMsSwFqW/zetXYMOnhrOizRxffuEmhR4rQnydlf/YRDdheJ2kqZwJrml3sXCYNBvj6VR8PFUfCnrAjClXbjfpBnQ7uMMqKonv8S+fA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR03MB3623.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(396003)(136003)(366004)(39860400002)(346002)(376002)(1800799009)(186009)(451199024)(83380400001)(235185007)(2906002)(66946007)(478600001)(66556008)(66476007)(6666004)(6506007)(33964004)(6486002)(6916009)(316002)(5660300002)(2616005)(7116003)(26005)(6512007)(8936002)(8676002)(41300700001)(36756003)(31696002)(86362001)(38100700002)(82960400001)(31686004)(84970400001)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?jUXYr8b9vx03sJnQbEKzKpIAH9o4?= =?utf-8?q?6hGjrLtwGZJYyUl8ozUAGRiDs3iAX2XU1CysBdcMohide6oVWH6km5SA4VUiCri1Z?= =?utf-8?q?YUbtx+P+ohy8QCRVgzJIBoyDiSJB2CjcdH087jOqIRRZ/hwEnyRcDkgljD50Rd37h?= =?utf-8?q?U72DvzTfNvoc3sB92mpZ2v7VCfKRfZfzZUTKwJit4/z6YTEBY+VsOQPxNO/Z4gVhX?= =?utf-8?q?ZqNhpKr/nC2JcaKhendvLsD3SrIyywb/2+ThAyxtAW71itdEVAZ0OTQD7dRkAOwzH?= =?utf-8?q?ENqO3WbndK4B4hIei6VB2Wdu4ru1gGWs7UfN6J19xsJOJaaq4jqATU7rWudsryyW2?= =?utf-8?q?cITS8znFqfUdksS3X2l31dMC0JH6UpLG+Uq5d5IWkBnEGnhskWbaVye98snH25/pQ?= =?utf-8?q?kUnZMHCcTwIVzYvaZyt8B1p3sGPN39o8ij3wgNVLpkRiHJ75HxiQQZ0tqbUpYE1Cw?= =?utf-8?q?hhtYkLG2jWA+oahj1scWmUZVXJJHl+xsH5Dspf8VYyWkSdxnMUwbNiT1dpySWgn8c?= =?utf-8?q?lqXj4yRNDgc9ouFwZG02Xvoa0ZaufXscj8mb3P3mhd4ARf5yhDhpWi+iZkImahTtB?= =?utf-8?q?PwJpRjg2bafWM23xe9AeVJnKxgP9OCbPbp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jEWJSrVSjw?= =?utf-8?q?oMt+RI/5XOBXxnW9mjf5yWlgIeE0k75KVg=3D=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: /UvLo59Ib9RGOgrl7Sj2kFn1/VyGt+XA6t6ZX+FgK+gNJryiXwjtWF6JtMFutjR0qeB5rUgilLr0G99as/2Bx1wZSTYB2/iKaV2iRRwMEXnuNOgaD4BjJaFV3Umd8m1F9zo0D9HW+93eva0mrslA8gd1aRKdyxfRgrmnVdBy0V+SnqOa9WXK5khEvnJtDz0kF2jODXsgTBCL/SxZAzGCz6o7ME7rLUbry58/8lkTnIyihbIaKSTv13k//cs/PViBnyqul5Ka0m+K8eAwnSOKz9IB4GzxST+LvcpLBH/rTlGIKPglvSKy+QNxUgexIqUXclhjkAwFTE3nwLz6tpvnWs46WAv2Yp+4Wjj6Epy3h01kojoTTSx/yvNtWUDCnREBngflHZsdcYwNYAxW2D1UUt74L3/Wi+a4wzYzmtU1XM0mr4Ud3kSmM7yShArMd8TLG+t+WvT4KsQwpfqm7Bb+iXh/tEFrFhkdvQsPSU7ZCYPsQc4UAN/2yG8F6RJ3V1S2BCNti12gvj1/TLoWcLa/ZsRDdS5DRxxPlToZXhgvuVj0ZoccJKoadXTU5NuKeNs6li1hKi7uDiW3YtGNO6kgHFdRnez7yMMqQUNVttvW7zAT7uVubL8CVZJ5hWP/IJ1eh3g/B7Srd5dCssGXOMjj3OiMuvbJPDkk2YC7wMBBv+k8HfMPY4XQmt+/u6Tu7ROq0zoqiYZz/z/7jRS1v+CNvjvSzMF3YH5M3PGq34tDvX6qSiPvEtMTsi1kbiy2JaZ0hXkGtMfD5+i4NUK+cBOEGA== X-OriginatorOrg: citrix.com X-MS-Exchange-CrossTenant-Network-Message-Id: b61b2a7a-4944-4143-e1e9-08db9f1cb913 X-MS-Exchange-CrossTenant-AuthSource: BYAPR03MB3623.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2023 12:23:11.9001 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335836de-42ef-43a2-b145-348c2ee9ca5b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: vz487rq5IVCxBZMyW9qKjK4aIwAkvV7c3pTqzaYo+7BY+57QEIF9QSNFSPDwDE2WIQBcl6qlvFd+NMQuJj7c6EsdDJz9Ij4AlAIMVEYiGW8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR03MB5827 Hi, I'm using b4 v0.12.3, and getting some kind of patch corruption issue: xen.git$ b4 shazam a67c2fa3-ba1c-3783-c3ee-250aff6903d5@suse.com Grabbing thread from lore.kernel.org/all/a67c2fa3-ba1c-3783-c3ee-250aff6903d5@suse.com/t.mbox.gz Checking for newer revisions Grabbing search results from lore.kernel.org Analyzing 1 messages in the thread Checking attestation on all messages, may take a moment... Reported-by: Andrew Cooper Signed-off-by: Konstantin Ryabitsev ---   ✓ [PATCH] x86emul: rework wrapping of libc functions in test and fuzzing harnesses   ---   ✓ Signed: DKIM/suse.com --- Total patches: 1 --- Applying: x86emul: rework wrapping of libc functions in test and fuzzing harnesses Patch failed at 0001 x86emul: rework wrapping of libc functions in test and fuzzing harnesses When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort". error: corrupt patch at line 11 hint: Use 'git am --show-current-patch=diff' to see the failed patch Forwarding this to patch does produce a more specific complaint: xen.git$ git am --show-current-patch=diff | patch patching file Makefile patch: **** malformed patch at line 11: @@ -51,10 +53,10 @@ x86-insn-fuzzer.a: $(OBJS) cpuid.o but it's not clear what exactly is wrong here. If I copy the patch out of the email and feed it to `git am` directly, it's happy: xen.git$ git am rework-wrap.patch Applying: x86emul: rework wrapping of libc functions in test and fuzzing harnesses I can't spot any interesting differences between what failed and what `git format-patch` reproduced, but I'm out of my depth here. My gut feeling is that something has been mangled while b4 was processing the change, but it's only a guess. I've attached the copied-off-list patch, and the base commit is d0eabe3eaf0db5b78843095a2918d50961e99e96 Thanks, ~Andrew From: Jan Beulich Subject: [PATCH] x86emul: rework wrapping of libc functions in test and fuzzing harnesses Our present approach is working fully behind the compiler's back. This was found to not work with LTO. Employ ld's --wrap= option instead. Note that while this makes the build work at least with new enough gcc (it doesn't with gcc7, for example, due to tool chain side issues afaict), according to my testing things still won't work when building the fuzzing harness with afl-cc: While with the gcc7 tool chain I see afl-as getting invoked, this does not happen with gcc13. Yet without using that assembler wrapper the resulting binary will look uninstrumented to afl-fuzz. While checking the resulting binaries I noticed that we've gained uses of snprintf() and strstr(), which only just so happen to not cause any problems. Add a wrappers for them as well. Since we don't have any actual uses of v{,sn}printf(), no definitions of their wrappers appear (just yet). But I think we want __wrap_{,sn}printf() to properly use __real_v{,sn}printf() right away, which means we need delarations of the latter. Reported-by: Andrew Cooper Suggested-by: Andrew Cooper Signed-off-by: Jan Beulich --- a/tools/fuzz/x86_instruction_emulator/Makefile +++ b/tools/fuzz/x86_instruction_emulator/Makefile @@ -35,6 +35,8 @@ OBJS := fuzz-emul.o x86-emulate.o OBJS += x86_emulate/0f01.o x86_emulate/0fae.o x86_emulate/0fc7.o OBJS += x86_emulate/decode.o x86_emulate/fpu.o +WRAPPED = $(shell sed -n 's,^ *WRAP(\([[:alnum:]_]*\));,\1,p' x86-emulate.h) + private.h := x86-emulate.h x86_emulate/x86_emulate.h x86_emulate/private.h x86-emulate.h: x86_emulate/x86_emulate.h @@ -51,10 +53,10 @@ x86-insn-fuzzer.a: $(OBJS) cpuid.o $(AR) rc $@ $^ afl-harness: afl-harness.o $(OBJS) cpuid.o wrappers.o - $(CC) $(CFLAGS) $^ -o $@ + $(CC) $(CFLAGS) $(addprefix -Wl$(comma)--wrap=,$(WRAPPED)) $^ -o $@ afl-harness-cov: afl-harness-cov.o $(patsubst %.o,%-cov.o,$(OBJS)) cpuid.o wrappers.o - $(CC) $(CFLAGS) $(GCOV_FLAGS) $^ -o $@ + $(CC) $(CFLAGS) $(GCOV_FLAGS) $(addprefix -Wl$(comma)--wrap=,$(WRAPPED)) $^ -o $@ # Common targets .PHONY: all --- a/tools/tests/x86_emulator/Makefile +++ b/tools/tests/x86_emulator/Makefile @@ -259,8 +259,10 @@ OBJS := x86-emulate.o cpuid.o test_x86_e OBJS += x86_emulate/0f01.o x86_emulate/0fae.o x86_emulate/0fc7.o OBJS += x86_emulate/blk.o x86_emulate/decode.o x86_emulate/fpu.o x86_emulate/util.o +WRAPPED := $(shell sed -n 's,^ *WRAP(\([[:alnum:]_]*\));,\1,p' x86-emulate.h) + $(TARGET): $(OBJS) - $(HOSTCC) $(HOSTCFLAGS) -o $@ $^ + $(HOSTCC) $(HOSTCFLAGS) $(addprefix -Wl$(comma)--wrap=,$(WRAPPED)) -o $@ $^ .PHONY: clean clean: --- a/tools/tests/x86_emulator/wrappers.c +++ b/tools/tests/x86_emulator/wrappers.c @@ -1,78 +1,103 @@ #include -#define WRAP(x) typeof(x) emul_##x +#define WRAP(x) typeof(x) __wrap_ ## x, __real_ ## x #include "x86-emulate.h" -size_t emul_fwrite(const void *src, size_t sz, size_t n, FILE *f) +size_t __wrap_fwrite(const void *src, size_t sz, size_t n, FILE *f) { emul_save_fpu_state(); - sz = fwrite(src, sz, n, f); + sz = __real_fwrite(src, sz, n, f); emul_restore_fpu_state(); return sz; } -int emul_memcmp(const void *p1, const void *p2, size_t sz) +int __wrap_memcmp(const void *p1, const void *p2, size_t sz) { int rc; emul_save_fpu_state(); - rc = memcmp(p1, p2, sz); + rc = __real_memcmp(p1, p2, sz); emul_restore_fpu_state(); return rc; } -void *emul_memcpy(void *dst, const void *src, size_t sz) +void *__wrap_memcpy(void *dst, const void *src, size_t sz) { emul_save_fpu_state(); - memcpy(dst, src, sz); + __real_memcpy(dst, src, sz); emul_restore_fpu_state(); return dst; } -void *emul_memset(void *dst, int c, size_t sz) +void *__wrap_memset(void *dst, int c, size_t sz) { emul_save_fpu_state(); - memset(dst, c, sz); + __real_memset(dst, c, sz); emul_restore_fpu_state(); return dst; } -int emul_printf(const char *fmt, ...) +int __wrap_printf(const char *fmt, ...) { va_list varg; int rc; emul_save_fpu_state(); va_start(varg, fmt); - rc = vprintf(fmt, varg); + rc = __real_vprintf(fmt, varg); va_end(varg); emul_restore_fpu_state(); return rc; } -int emul_putchar(int c) +int __wrap_putchar(int c) { int rc; emul_save_fpu_state(); - rc = putchar(c); + rc = __real_putchar(c); emul_restore_fpu_state(); return rc; } -int emul_puts(const char *str) +int __wrap_puts(const char *str) { int rc; emul_save_fpu_state(); - rc = puts(str); + rc = __real_puts(str); emul_restore_fpu_state(); return rc; } + +int __wrap_snprintf(char *buf, size_t n, const char *fmt, ...) +{ + va_list varg; + int rc; + + emul_save_fpu_state(); + va_start(varg, fmt); + rc = __real_vsnprintf(buf, n, fmt, varg); + va_end(varg); + emul_restore_fpu_state(); + + return rc; +} + +char *__wrap_strstr(const char *s1, const char *s2) +{ + char *s; + + emul_save_fpu_state(); + s = __real_strstr(s1, s2); + emul_restore_fpu_state(); + + return s; +} --- a/tools/tests/x86_emulator/x86-emulate.h +++ b/tools/tests/x86_emulator/x86-emulate.h @@ -32,9 +32,7 @@ #ifdef EOF # error "Must not include before x86-emulate.h" #endif -#ifdef WRAP -# include -#endif +#include #include @@ -88,11 +86,7 @@ struct x86_fxsr *get_fpu_save_area(void) * around the actual function. */ #ifndef WRAP -# if 0 /* This only works for explicit calls, not for compiler generated ones. */ -# define WRAP(x) typeof(x) x asm("emul_" #x) -# else -# define WRAP(x) asm(".equ " #x ", emul_" #x) -# endif +# define WRAP(x) typeof(x) __wrap_ ## x #endif WRAP(fwrite); @@ -102,6 +96,10 @@ WRAP(memset); WRAP(printf); WRAP(putchar); WRAP(puts); +WRAP(snprintf); +WRAP(strstr); +WRAP(vprintf); +WRAP(vsnprintf); #undef WRAP