lsteamclient: Use plain memory allocation / free for SteamNetworkingMessage_t wrapper.

CW-Bug-Id: #22649
This commit is contained in:
Paul Gofman 2023-08-23 17:34:40 -06:00 committed by Arkadiusz Hiler
parent 6ed890c9e9
commit a7bdd61d20
8 changed files with 4 additions and 153 deletions

View File

@ -1,113 +0,0 @@
/* $OpenBSD: queue.h,v 1.45 2018/07/12 14:22:54 sashan Exp $ */
/* $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $ */
/*
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)queue.h 8.5 (Berkeley) 8/20/94
*/
#if defined(QUEUE_MACRO_DEBUG) || (defined(_KERNEL) && defined(DIAGNOSTIC))
#define _Q_INVALID ((void *)-1)
#define _Q_INVALIDATE(a) (a) = _Q_INVALID
#else
#define _Q_INVALIDATE(a)
#endif
/*
* Singly-linked List definitions.
*/
#define SLIST_HEAD(name, type) \
struct name { \
struct type *slh_first; /* first element */ \
}
#define SLIST_HEAD_INITIALIZER(head) \
{ NULL }
#define SLIST_ENTRY(type) \
struct { \
struct type *sle_next; /* next element */ \
}
/*
* Singly-linked List access methods.
*/
#define SLIST_FIRST(head) ((head)->slh_first)
#define SLIST_END(head) NULL
#define SLIST_EMPTY(head) (SLIST_FIRST(head) == SLIST_END(head))
#define SLIST_NEXT(elm, field) ((elm)->field.sle_next)
#define SLIST_FOREACH(var, head, field) \
for((var) = SLIST_FIRST(head); \
(var) != SLIST_END(head); \
(var) = SLIST_NEXT(var, field))
#define SLIST_FOREACH_SAFE(var, head, field, tvar) \
for ((var) = SLIST_FIRST(head); \
(var) && ((tvar) = SLIST_NEXT(var, field), 1); \
(var) = (tvar))
/*
* Singly-linked List functions.
*/
#define SLIST_INIT(head) { \
SLIST_FIRST(head) = SLIST_END(head); \
}
#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \
(elm)->field.sle_next = (slistelm)->field.sle_next; \
(slistelm)->field.sle_next = (elm); \
} while (0)
#define SLIST_INSERT_HEAD(head, elm, field) do { \
(elm)->field.sle_next = (head)->slh_first; \
(head)->slh_first = (elm); \
} while (0)
#define SLIST_REMOVE_AFTER(elm, field) do { \
(elm)->field.sle_next = (elm)->field.sle_next->field.sle_next; \
} while (0)
#define SLIST_REMOVE_HEAD(head, field) do { \
(head)->slh_first = (head)->slh_first->field.sle_next; \
} while (0)
#define SLIST_REMOVE(head, elm, type, field) do { \
if ((head)->slh_first == (elm)) { \
SLIST_REMOVE_HEAD((head), field); \
} else { \
struct type *curelm = (head)->slh_first; \
\
while (curelm->field.sle_next != (elm)) \
curelm = curelm->field.sle_next; \
curelm->field.sle_next = \
curelm->field.sle_next->field.sle_next; \
} \
_Q_INVALIDATE((elm)->field.sle_next); \
} while (0)

View File

@ -21,8 +21,6 @@ extern "C" {
#define SDKVER_144
#include "struct_converters.h"
#include "queue.h"
#define SDK_VERSION 1440
#include "steamclient_manual_common.h"

View File

@ -22,8 +22,6 @@ extern "C" {
#define SDKVER_146
#include "struct_converters.h"
#include "queue.h"
#define SDK_VERSION 1460
#include "steamclient_manual_common.h"

View File

@ -22,8 +22,6 @@ extern "C" {
#define SDKVER_147
#include "struct_converters.h"
#include "queue.h"
#define SDK_VERSION 1470
#include "steamclient_manual_common.h"

View File

@ -22,8 +22,6 @@ extern "C" {
#define SDKVER_148a
#include "struct_converters.h"
#include "queue.h"
#define SDK_VERSION 1481
#include "steamclient_manual_common.h"

View File

@ -23,8 +23,6 @@ extern "C" {
#include "struct_converters.h"
#include "cb_converters.h"
#include "queue.h"
#define SDK_VERSION 1500
#include "steamclient_manual_common.h"

View File

@ -25,8 +25,6 @@ extern "C" {
#include "cb_converters.h"
#include "win_constructors.h"
#include "queue.h"
#define SDK_VERSION 1531
#include "steamclient_manual_common.h"

View File

@ -23,8 +23,6 @@ extern "C" {
#include "cb_converters.h"
#include "win_constructors.h"
#include "queue.h"
#define SDK_VERSION 1531
#include "steamclient_manual_common.h"
@ -33,15 +31,10 @@ struct msg_wrapper {
struct SteamNetworkingMessage_t *lin_msg;
void (*orig_FreeData)(SteamNetworkingMessage_t *);
SLIST_ENTRY(msg_wrapper) entry;
};
/***** manual struct converter for SteamNetworkingMessage_t *****/
static SLIST_HEAD(free_msgs_head, msg_wrapper) free_msgs = SLIST_HEAD_INITIALIZER(free_msgs);
static CRITICAL_SECTION free_msgs_lock = { NULL, -1, 0, 0, 0, 0 };
static void __attribute__((ms_abi)) win_FreeData(struct winSteamNetworkingMessage_t_153a *win_msg)
{
struct msg_wrapper *msg = CONTAINING_RECORD(win_msg, struct msg_wrapper, win_msg);
@ -56,13 +49,11 @@ static void __attribute__((ms_abi)) win_FreeData(struct winSteamNetworkingMessag
static void __attribute__((ms_abi)) win_Release(struct winSteamNetworkingMessage_t_153a *win_msg)
{
struct msg_wrapper *msg = CONTAINING_RECORD(win_msg, struct msg_wrapper, win_msg);
TRACE("%p\n", msg);
msg->lin_msg->m_pfnRelease(msg->lin_msg);
msg->lin_msg = NULL;
msg->orig_FreeData = NULL;
EnterCriticalSection(&free_msgs_lock);
SLIST_INSERT_HEAD(&free_msgs, msg, entry);
LeaveCriticalSection(&free_msgs_lock);
SecureZeroMemory(msg, sizeof(*msg));
HeapFree(GetProcessHeap(), 0, msg);
}
static void lin_FreeData(struct SteamNetworkingMessage_t *lin_msg)
@ -78,22 +69,7 @@ void *network_message_lin_to_win_(void *msg_, unsigned int version)
struct SteamNetworkingMessage_t *lin_msg = (struct SteamNetworkingMessage_t *)msg_;
struct msg_wrapper *msg;
EnterCriticalSection(&free_msgs_lock);
msg = SLIST_FIRST(&free_msgs);
if(!msg){
int n;
/* allocs can be pricey, so alloc in blocks */
#define MSGS_PER_BLOCK 16
struct msg_wrapper *msgs = (struct msg_wrapper *)HeapAlloc(GetProcessHeap(), 0, sizeof(struct msg_wrapper) * MSGS_PER_BLOCK);
for(n = 1; n < MSGS_PER_BLOCK; ++n)
SLIST_INSERT_HEAD(&free_msgs, &msgs[n], entry);
msg = &msgs[0];
}else
SLIST_REMOVE_HEAD(&free_msgs, entry);
LeaveCriticalSection(&free_msgs_lock);
msg = (struct msg_wrapper *)HeapAlloc(GetProcessHeap(), 0, sizeof(*msg));
TRACE("lin_msg %p, msg %p.\n", lin_msg, msg);