Line data Source code
1 : /* SPDX-FileCopyrightText: Copyright 2026 Cozens Software Solutions Limited
2 : * SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0 OR LicenseRef-PolyForm-Internal-Use-1.0.0 OR LicenseRef-COSOSO-Commercial
3 : */
4 :
5 : #include "SolidSyslogStackScratch.h"
6 :
7 : #include <stddef.h>
8 :
9 : #include "SolidSyslogFormatter.h"
10 : #include "SolidSyslogScratch.h"
11 : #include "SolidSyslogTunables.h"
12 :
13 : static void StackScratch_WithScratch(struct SolidSyslogScratch* self, SolidSyslogScratchUser use, void* context);
14 :
15 967 : struct SolidSyslogScratch* SolidSyslogStackScratch_Get(void)
16 : {
17 : static struct SolidSyslogScratch instance = {StackScratch_WithScratch};
18 967 : return &instance;
19 : }
20 :
21 : /* The array lives in this frame and no other, so a logger wired with a
22 : * different scratch never has it on its stack: this function is reached only
23 : * through the vtable, which keeps it out of the caller's frame. */
24 6129 : static void StackScratch_WithScratch(struct SolidSyslogScratch* self, SolidSyslogScratchUser use, void* context)
25 : {
26 : SolidSyslogFormatterStorage storage[SOLIDSYSLOG_FORMATTER_STORAGE_SIZE(SOLIDSYSLOG_MAX_MESSAGE_SIZE)];
27 : (void) self;
28 6129 : use(storage, SOLIDSYSLOG_MAX_MESSAGE_SIZE, context);
29 6129 : }
|