diff mbox series

[pseudo,1/3] pseudo_wrappers.c: Add support for LoongArch64

Message ID 20250309060039.454124-2-wuxiaotian@loongson.cn
State New
Headers show
Series Porting pseudo to LoongArch | expand

Commit Message

Xiaotian Wu March 9, 2025, 6 a.m. UTC
Since these symbols do not exist in LoongArch's libc.so, they
need to be remapped, and the first "ver" function parameter
does not exist in the mapped function.

__fxstat __fxstat64 __fxstatat __fxstatat64 __lxstat __lxstat64
__xmknod __xmknodat __xstat __xstat64

Signed-off-by: Xiaotian Wu <wuxiaotian@loongson.cn>
---
 pseudo_wrappers.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)
diff mbox series

Patch

diff --git a/pseudo_wrappers.c b/pseudo_wrappers.c
index 9ae1200..b54b0c3 100644
--- a/pseudo_wrappers.c
+++ b/pseudo_wrappers.c
@@ -122,6 +122,64 @@  pseudo_reinit_libpseudo(void) {
 	_libpseudo_init();
 }
 
+#if defined(__loongarch_lp64)
+#define LOAD_REAL_SYMBOL(name, symbol) \
+    pseudo_real_##name = dlsym(RTLD_NEXT, symbol); \
+    real_##name = pseudo_##name
+
+static int (*pseudo_real___fxstat)(int fd, struct stat *buf) = NULL;
+static int (*pseudo_real___fxstat64)(int fd, struct stat64 *buf) = NULL;
+static int (*pseudo_real___fxstatat)(int dirfd, const char *path, struct stat *buf, int flags) = NULL;
+static int (*pseudo_real___fxstatat64)(int dirfd, const char *path, struct stat64 *buf, int flags) = NULL;
+static int (*pseudo_real___lxstat)(const char *path, struct stat *buf) = NULL;
+static int (*pseudo_real___lxstat64)(const char *path, struct stat64 *buf) = NULL;
+static int (*pseudo_real___xmknod)(const char *path, mode_t mode, dev_t *dev) = NULL;
+static int (*pseudo_real___xmknodat)(int dirfd, const char *path, mode_t mode, dev_t *dev) = NULL;
+static int (*pseudo_real___xstat)(const char *path, struct stat *buf) = NULL;
+static int (*pseudo_real___xstat64)(const char *path, struct stat64 *buf) = NULL;
+
+static int pseudo___fxstat(int ver __attribute__((unused)), int fd, struct stat *buf)
+{
+	return pseudo_real___fxstat(fd, buf);
+}
+static int pseudo___fxstat64(int ver __attribute__((unused)), int fd, struct stat64 *buf)
+{
+	return pseudo_real___fxstat64(fd, buf);
+}
+static int pseudo___fxstatat(int ver __attribute__((unused)), int dirfd, const char *path, struct stat *buf, int flags)
+{
+	return pseudo_real___fxstatat(dirfd, path, buf, flags);
+}
+static int pseudo___fxstatat64(int ver __attribute__((unused)), int dirfd, const char *path, struct stat64 *buf, int flags)
+{
+	return pseudo_real___fxstatat64(dirfd, path, buf, flags);
+}
+static int pseudo___lxstat(int ver __attribute__((unused)), const char *path, struct stat *buf)
+{
+	return pseudo_real___lxstat(path, buf);
+}
+static int pseudo___lxstat64(int ver __attribute__((unused)), const char *path, struct stat64 *buf)
+{
+	return pseudo_real___lxstat64(path, buf);
+}
+static int pseudo___xmknod(int ver __attribute__((unused)), const char *path, mode_t mode, dev_t *dev)
+{
+	return pseudo_real___xmknod(path, mode, dev);
+}
+static int pseudo___xmknodat(int ver __attribute__((unused)), int dirfd, const char *path, mode_t mode, dev_t *dev)
+{
+	return pseudo_real___xmknodat(dirfd, path, mode, dev);
+}
+static int pseudo___xstat(int ver __attribute__((unused)), const char *path, struct stat *buf)
+{
+	return pseudo_real___xstat(path, buf);
+}
+static int pseudo___xstat64(int ver __attribute__((unused)), const char *path, struct stat64 *buf)
+{
+	return pseudo_real___xstat64(path, buf);
+}
+#endif
+
 static void
 pseudo_init_one_wrapper(pseudo_function *func) {
 	int (*f)(void) = (int (*)(void)) NULL;
@@ -185,6 +243,18 @@  pseudo_init_wrappers(void) {
 	pseudo_real_fork = dlsym(RTLD_NEXT, "fork");
 	pseudo_real_execv = dlsym(RTLD_NEXT, "execv");
 
+#if defined(__loongarch_lp64)
+	LOAD_REAL_SYMBOL(__fxstat, "fstat");
+	LOAD_REAL_SYMBOL(__fxstat64, "fstat64");
+	LOAD_REAL_SYMBOL(__fxstatat, "fstatat");
+	LOAD_REAL_SYMBOL(__fxstatat64, "fstatat64");
+	LOAD_REAL_SYMBOL(__lxstat, "lstat");
+	LOAD_REAL_SYMBOL(__lxstat64, "lstat64");
+	LOAD_REAL_SYMBOL(__xmknod, "mknod");
+	LOAD_REAL_SYMBOL(__xmknodat, "mknodat");
+	LOAD_REAL_SYMBOL(__xstat, "stat");
+	LOAD_REAL_SYMBOL(__xstat64, "stat64");
+#endif
 	/* Once the wrappers are setup, we can now use open... so
 	 * setup the logfile, if necessary...
 	 */