bsd: allow user-specified tmem backing buffer

This commit is contained in:
Michael Scire 2021-02-23 21:28:32 -08:00 committed by fincs
parent 38ee48032f
commit c8f8145195
2 changed files with 14 additions and 2 deletions

View File

@ -18,6 +18,9 @@
typedef struct {
u32 version; ///< Observed 1 on [2.0.0+] LibAppletWeb, 2 on [3.0.0+].
void *tmem_buffer; ///< User-provided buffer to use as backing for transfer memory. If NULL, a buffer will be allocated automatically. Must be large enough and page-aligned.
size_t tmem_buffer_size; ///< Size of the user-provided transfer memory backing buffer. Must be large enough and page-aligned.
u32 tcp_tx_buf_size; ///< Size of the TCP transfer (send) buffer (initial or fixed).
u32 tcp_rx_buf_size; ///< Size of the TCP receive buffer (initial or fixed).
u32 tcp_tx_buf_max_size; ///< Maximum size of the TCP transfer (send) buffer. If it is 0, the size of the buffer is fixed to its initial value.

View File

@ -37,6 +37,9 @@ static TransferMemory g_bsdTmem;
static const BsdInitConfig g_defaultBsdInitConfig = {
.version = 1,
.tmem_buffer = NULL,
.tmem_buffer_size = 0,
.tcp_tx_buf_size = 0x8000,
.tcp_rx_buf_size = 0x10000,
.tcp_tx_buf_max_size = 0x40000,
@ -213,8 +216,14 @@ Result _bsdInitialize(const BsdInitConfig *config, u32 num_sessions, u32 service
if (R_SUCCEEDED(rc))
rc = smGetServiceWrapper(&g_bsdMonitor, bsd_srv);
if (R_SUCCEEDED(rc))
rc = tmemCreate(&g_bsdTmem, _bsdGetTransferMemSizeForConfig(config), 0);
if (R_SUCCEEDED(rc)) {
const size_t min_tmem_size = _bsdGetTransferMemSizeForConfig(config);
if (config->tmem_buffer != NULL && config->tmem_buffer_size >= min_tmem_size)
rc = tmemCreateFromMemory(&g_bsdTmem, config->tmem_buffer, config->tmem_buffer_size, 0);
else
rc = tmemCreate(&g_bsdTmem, min_tmem_size, 0);
}
if (R_SUCCEEDED(rc))
rc = _bsdRegisterClient(&g_bsdTmem, config, &g_bsdClientPid);