mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-21 20:42:44 +02:00
fsdev/romfsdev: Reduce TLS usage by sharing the path buffer
This commit is contained in:
parent
a774fb81cc
commit
26a0ee4af3
@ -14,6 +14,7 @@
|
|||||||
#include "services/fs.h"
|
#include "services/fs.h"
|
||||||
#include "services/time.h"
|
#include "services/time.h"
|
||||||
|
|
||||||
|
#include "path_buf.h"
|
||||||
|
|
||||||
/*! @internal
|
/*! @internal
|
||||||
*
|
*
|
||||||
@ -109,7 +110,6 @@ static fsdev_fsdevice fsdev_fsdevices[32];
|
|||||||
/*! @endcond */
|
/*! @endcond */
|
||||||
|
|
||||||
static char __cwd[PATH_MAX+1] = "/";
|
static char __cwd[PATH_MAX+1] = "/";
|
||||||
static __thread char __fixedpath[PATH_MAX+1];
|
|
||||||
|
|
||||||
__attribute__((weak)) u32 __nx_fsdev_direntry_cache_size = 32;
|
__attribute__((weak)) u32 __nx_fsdev_direntry_cache_size = 32;
|
||||||
|
|
||||||
@ -202,17 +202,17 @@ fsdev_fixpath(struct _reent *r,
|
|||||||
} while(code != 0);
|
} while(code != 0);
|
||||||
|
|
||||||
if(path[0] == '/')
|
if(path[0] == '/')
|
||||||
strncpy(__fixedpath, path, PATH_MAX);
|
strncpy(__nx_dev_path_buf, path, PATH_MAX);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strncpy(__fixedpath, __cwd, PATH_MAX);
|
strncpy(__nx_dev_path_buf, __cwd, PATH_MAX);
|
||||||
__fixedpath[PATH_MAX] = '\0';
|
__nx_dev_path_buf[PATH_MAX] = '\0';
|
||||||
strncat(__fixedpath, path, PATH_MAX - strlen(__cwd));
|
strncat(__nx_dev_path_buf, path, PATH_MAX - strlen(__cwd));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(__fixedpath[PATH_MAX] != 0)
|
if(__nx_dev_path_buf[PATH_MAX] != 0)
|
||||||
{
|
{
|
||||||
__fixedpath[PATH_MAX] = 0;
|
__nx_dev_path_buf[PATH_MAX] = 0;
|
||||||
r->_errno = ENAMETOOLONG;
|
r->_errno = ENAMETOOLONG;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -236,7 +236,7 @@ fsdev_fixpath(struct _reent *r,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return __fixedpath;
|
return __nx_dev_path_buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -248,7 +248,7 @@ fsdev_getfspath(struct _reent *r,
|
|||||||
if(fsdev_fixpath(r, path, device) == NULL)
|
if(fsdev_fixpath(r, path, device) == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
memcpy(outpath, __fixedpath,FS_MAX_PATH-1);
|
memcpy(outpath, __nx_dev_path_buf,FS_MAX_PATH-1);
|
||||||
outpath[FS_MAX_PATH-1] = '\0';
|
outpath[FS_MAX_PATH-1] = '\0';
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -462,15 +462,15 @@ Result fsdevMountSdmc(void)
|
|||||||
{
|
{
|
||||||
if(FindDevice(__system_argv[0]) == dev)
|
if(FindDevice(__system_argv[0]) == dev)
|
||||||
{
|
{
|
||||||
strncpy(__fixedpath,__system_argv[0],PATH_MAX);
|
strncpy(__nx_dev_path_buf,__system_argv[0],PATH_MAX);
|
||||||
if(__fixedpath[PATH_MAX] != 0)
|
if(__nx_dev_path_buf[PATH_MAX] != 0)
|
||||||
{
|
{
|
||||||
__fixedpath[PATH_MAX] = 0;
|
__nx_dev_path_buf[PATH_MAX] = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char *last_slash = NULL;
|
char *last_slash = NULL;
|
||||||
p = __fixedpath;
|
p = __nx_dev_path_buf;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
units = decode_utf8(&code, (const uint8_t*)p);
|
units = decode_utf8(&code, (const uint8_t*)p);
|
||||||
@ -489,7 +489,7 @@ Result fsdevMountSdmc(void)
|
|||||||
if(last_slash != NULL)
|
if(last_slash != NULL)
|
||||||
{
|
{
|
||||||
last_slash[0] = 0;
|
last_slash[0] = 0;
|
||||||
chdir(__fixedpath);
|
chdir(__nx_dev_path_buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
3
nx/source/runtime/devices/path_buf.c
Normal file
3
nx/source/runtime/devices/path_buf.c
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#include "path_buf.h"
|
||||||
|
|
||||||
|
char __thread __nx_dev_path_buf[PATH_MAX+1];
|
4
nx/source/runtime/devices/path_buf.h
Normal file
4
nx/source/runtime/devices/path_buf.h
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
|
extern char __thread __nx_dev_path_buf[PATH_MAX+1];
|
@ -15,6 +15,8 @@
|
|||||||
#include "runtime/env.h"
|
#include "runtime/env.h"
|
||||||
#include "nro.h"
|
#include "nro.h"
|
||||||
|
|
||||||
|
#include "path_buf.h"
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
RomfsSource_FsFile,
|
RomfsSource_FsFile,
|
||||||
RomfsSource_FsStorage,
|
RomfsSource_FsStorage,
|
||||||
@ -40,8 +42,6 @@ typedef struct romfs_mount
|
|||||||
extern int __system_argc;
|
extern int __system_argc;
|
||||||
extern char** __system_argv;
|
extern char** __system_argv;
|
||||||
|
|
||||||
static char __thread __component[PATH_MAX+1];
|
|
||||||
|
|
||||||
#define romFS_root(m) ((romfs_dir*)(m)->dirTable)
|
#define romFS_root(m) ((romfs_dir*)(m)->dirTable)
|
||||||
#define romFS_dir(m,x) ((romfs_dir*) ((u8*)(m)->dirTable + (x)))
|
#define romFS_dir(m,x) ((romfs_dir*) ((u8*)(m)->dirTable + (x)))
|
||||||
#define romFS_file(m,x) ((romfs_file*)((u8*)(m)->fileTable + (x)))
|
#define romFS_file(m,x) ((romfs_file*)((u8*)(m)->fileTable + (x)))
|
||||||
@ -233,10 +233,10 @@ Result romfsMount(const char *name)
|
|||||||
filename += 5;
|
filename += 5;
|
||||||
else if (strncmp(filename, "nxlink:/", 8) == 0)
|
else if (strncmp(filename, "nxlink:/", 8) == 0)
|
||||||
{
|
{
|
||||||
strncpy(__component, "/switch", PATH_MAX);
|
strncpy(__nx_dev_path_buf, "/switch", PATH_MAX);
|
||||||
strncat(__component, filename+7, PATH_MAX);
|
strncat(__nx_dev_path_buf, filename+7, PATH_MAX);
|
||||||
__component[PATH_MAX] = 0;
|
__nx_dev_path_buf[PATH_MAX] = 0;
|
||||||
filename = __component;
|
filename = __nx_dev_path_buf;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -501,7 +501,7 @@ static int navigateToDir(romfs_mount *mount, romfs_dir** ppDir, const char** pPa
|
|||||||
while (**pPath)
|
while (**pPath)
|
||||||
{
|
{
|
||||||
char* slashPos = strchr(*pPath, '/');
|
char* slashPos = strchr(*pPath, '/');
|
||||||
char* component = __component;
|
char* component = __nx_dev_path_buf;
|
||||||
|
|
||||||
if (slashPos)
|
if (slashPos)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user