@@ -11,7 +11,11 @@
struct stat64 buf;
int save_errno;
+#ifdef __loongarch64
+ int existed = (real_stat64(path, &buf) != -1);
+#else
int existed = (real___xstat64(_STAT_VER, path, &buf) != -1);
+#endif
rc = real_fopen64(path, mode);
save_errno = errno;
@@ -20,7 +24,11 @@
int fd = fileno(rc);
pseudo_debug(PDBGF_FILE, "fopen64 '%s': fd %d <FILE %p>\n", path, fd, (void *) rc);
+#ifdef __loongarch64
+ if (real_fstat64( fd, &buf) != -1) {
+#else
if (real___fxstat64(_STAT_VER, fd, &buf) != -1) {
+#endif
if (!existed) {
real_fchmod(fd, PSEUDO_FS_MODE(0666 & ~pseudo_umask, 0));
pseudo_client_op(OP_CREAT, 0, -1, -1, path, &buf);
@@ -10,7 +10,11 @@
*/
struct stat64 buf;
int save_errno;
+#ifdef __loongarch64
+ int existed = (real_stat64(path, &buf) != -1);
+#else
int existed = (real___xstat64(_STAT_VER, path, &buf) != -1);
+#endif
rc = real_freopen64(path, mode, stream);
save_errno = errno;
@@ -19,7 +23,11 @@
int fd = fileno(rc);
pseudo_debug(PDBGF_FILE, "freopen64 '%s': fd %d\n", path, fd);
+#ifdef __loongarch64
+ if (real_fstat64(fd, &buf) != -1) {
+#else
if (real___fxstat64(_STAT_VER, fd, &buf) != -1) {
+#endif
if (!existed) {
real_fchmod(fd, PSEUDO_FS_MODE(0666 & ~pseudo_umask, 0));
pseudo_client_op(OP_CREAT, 0, -1, -1, path, &buf);
@@ -7,8 +7,17 @@
* int fstat(int fd, struct stat *buf)
* int rc = -1;
*/
-
+#ifdef __loongarch64
+ struct stat64 buf64;
+ /* populate buffer with complete data */
+ real_fstat(fd, buf);
+ /* obtain fake data */
+ rc = wrap_fstat64(fd, &buf64);
+ /* overwrite */
+ pseudo_stat32_from64(buf, &buf64);
+#else
rc = wrap___fxstat(_STAT_VER, fd, buf);
+#endif
/* return rc;
* }
@@ -7,8 +7,24 @@
* int fstat64(int fd, struct stat *buf)
* int rc = -1;
*/
+#ifdef __loongarch64
+ pseudo_msg_t *msg;
+ int save_errno;
+ rc = real_fstat64(fd, buf);
+ save_errno = errno;
+ if (rc == -1) {
+ return rc;
+ }
+ msg = pseudo_client_op(OP_FSTAT, 0, fd, -1, 0, buf);
+ if (msg && msg->result == RESULT_SUCCEED) {
+ pseudo_stat_msg(buf, msg);
+ }
+
+ errno = save_errno;
+#else
rc = wrap___fxstat64(_STAT_VER, fd, buf);
+#endif
/* return rc;
* }
@@ -7,8 +7,14 @@
* int fstatat(int dirfd, const char *path, struct stat *buf, int flags)
* int rc = -1;
*/
-
+#ifdef __loongarch64
+ struct stat64 buf64;
+ real_fstatat(dirfd,path,buf,flags);
+ rc = wrap_fstatat64(dirfd, path, &buf64, flags);
+ pseudo_stat32_from64(buf, &buf64);
+#else
rc = wrap___fxstatat(_STAT_VER, dirfd, path, buf, flags);
+#endif
/* return rc;
* }
@@ -8,7 +8,50 @@
* int rc = -1;
*/
+#ifdef __loongarch64
+ pseudo_msg_t *msg;
+ int save_errno;
+
+#ifdef PSEUDO_NO_REAL_AT_FUNCTIONS
+ if (dirfd != AT_FDCWD) {
+ errno = ENOSYS;
+ return -1;
+ }
+#endif
+ if (flags & AT_SYMLINK_NOFOLLOW) {
+#ifdef PSEUDO_NO_REAL_AT_FUNCTIONS
+ rc = real_lstat64(path, buf);
+#else
+ rc = real_fstatat64(dirfd, path, buf, flags);
+#endif
+ if (rc == -1) {
+ return rc;
+ }
+ } else {
+#ifdef PSEUDO_NO_REAL_AT_FUNCTIONS
+ rc = real_stat64( path, buf);
+#else
+ rc = real_fstatat64(dirfd, path, buf, flags);
+#endif
+ if (rc == -1) {
+ return rc;
+ }
+ }
+ save_errno = errno;
+
+ /* query database
+ * note that symlink canonicalizing is now automatic, so we
+ * don't need to check for a symlink on this end
+ */
+ msg = pseudo_client_op(OP_STAT, 0, -1, dirfd, path, buf);
+ if (msg && msg->result == RESULT_SUCCEED) {
+ pseudo_stat_msg(buf, msg);
+ }
+
+ errno = save_errno;
+#else
rc = wrap___fxstatat64(_STAT_VER, dirfd, path, buf, flags);
+#endif
/* return rc;
* }
@@ -7,8 +7,11 @@
* int lstat(const char *path, struct stat *buf)
* int rc = -1;
*/
-
+#ifdef __loongarch64
+ rc = wrap_fstatat(AT_FDCWD, path, buf, AT_SYMLINK_NOFOLLOW);
+#else
rc = wrap___fxstatat(_STAT_VER, AT_FDCWD, path, buf, AT_SYMLINK_NOFOLLOW);
+#endif
/* return rc;
* }
@@ -7,8 +7,11 @@
* int lstat64(const char *path, struct stat *buf)
* int rc = -1;
*/
-
+#ifdef __loongarch64
+ rc = wrap_fstatat64( AT_FDCWD, path, buf, AT_SYMLINK_NOFOLLOW);
+#else
rc = wrap___fxstatat64(_STAT_VER, AT_FDCWD, path, buf, AT_SYMLINK_NOFOLLOW);
+#endif
/* return rc;
* }
@@ -8,7 +8,11 @@
* int rc = -1;
*/
+#ifdef __loongarch64
+ rc = wrap_mknodat(AT_FDCWD, path, mode, dev);
+#else
rc = wrap___xmknod(_MKNOD_VER, path, mode, &dev);
+#endif
/* return rc;
* }
@@ -7,8 +7,80 @@
* int mknodat(int dirfd, const char *path, mode_t mode, dev_t dev)
* int rc = -1;
*/
+#ifdef __loongarch64
+ pseudo_msg_t *msg;
+ struct stat64 buf;
+ /* mask out mode bits appropriately */
+ mode = mode & ~pseudo_umask;
+ /* if you don't specify a type, assume regular file */
+ if (!(mode & S_IFMT)) {
+ mode |= S_IFREG;
+ }
+ pseudo_debug(PDBGF_FILE, "mknodat creating '%s', mode 0%o\n",
+ path ? path : "<no name>", (int) mode);
+
+ /* we don't use underlying call, so _ver is irrelevant to us */
+#ifdef PSEUDO_NO_REAL_AT_FUNCTIONS
+ if (dirfd != AT_FDCWD) {
+ errno = ENOSYS;
+ return -1;
+ }
+ rc = real_stat64( path, &buf);
+#else
+ rc = real_fstatat64( dirfd, path, &buf, AT_SYMLINK_NOFOLLOW);
+#endif
+ if (rc != -1) {
+ /* if we can stat the file, you can't mknod it */
+ errno = EEXIST;
+ return -1;
+ }
+ if (!dev) {
+ errno = EINVAL;
+ return -1;
+ }
+#ifdef PSEUDO_NO_REAL_AT_FUNCTIONS
+ rc = real_open(path, O_CREAT | O_WRONLY | O_EXCL,
+ PSEUDO_FS_MODE(mode, 0));
+#else
+ rc = real_openat(dirfd, path, O_CREAT | O_WRONLY | O_EXCL,
+ PSEUDO_FS_MODE(mode, 0));
+#endif
+ if (rc == -1) {
+ return -1;
+ }
+ real_fchmod(rc, PSEUDO_FS_MODE(mode, 0));
+ real_fstat64( rc, &buf);
+ /* mknod does not really open the file. We don't have
+ * to use wrap_close because we've never exposed this file
+ * descriptor to the client code.
+ */
+ real_close(rc);
+
+ /* mask in the mode type bits again */
+ buf.st_mode = (PSEUDO_DB_MODE(buf.st_mode, mode) & 07777) |
+ (mode & ~07777);
+ buf.st_rdev = dev;
+ msg = pseudo_client_op(OP_MKNOD, 0, -1, dirfd, path, &buf);
+ if (msg && msg->result != RESULT_SUCCEED) {
+ errno = EPERM;
+ rc = -1;
+ } else {
+ /* just pretend we worked */
+ rc = 0;
+ }
+ if (rc == -1) {
+ int save_errno = errno;
+#ifdef PSEUDO_NO_REAL_AT_FUNCTIONS
+ real_unlink(path);
+#else
+ real_unlinkat(dirfd, path, AT_SYMLINK_NOFOLLOW);
+#endif
+ errno = save_errno;
+ }
+#else
rc = wrap___xmknodat(_MKNOD_VER, dirfd, path, mode, &dev);
+#endif
/* return rc;
* }
@@ -35,7 +35,11 @@
if (rc != -1) {
save_errno = errno;
+#ifdef __loongarch64
+ if (real_fstat64(rc, &buf) != -1) {
+#else
if (real___fxstat64(_STAT_VER, rc, &buf) != -1) {
+#endif
real_fchmod(rc, PSEUDO_FS_MODE(0600, 0));
pseudo_client_op(OP_CREAT, 0, -1, -1, tmp_template, &buf);
pseudo_client_op(OP_OPEN, PSA_READ | PSA_WRITE, rc, -1, tmp_template, &buf);
@@ -56,12 +56,24 @@
save_errno = errno;
#ifdef PSEUDO_NO_REAL_AT_FUNCTIONS
if (flags & O_NOFOLLOW) {
+#ifdef __loongarch64
+ rc = real_lstat64(path,&buf);
+#else
rc = real___lxstat64(_STAT_VER, path, &buf);
+#endif
} else {
+#ifdef __loongarch64
+ rc = real_stat64(path,&buf);
+#else
rc = real___xstat64(_STAT_VER, path, &buf);
+#endif
}
+#else
+#ifdef __loongarch64
+ rc = real_fstatat64(dirfd, path, &buf, (flags & O_NOFOLLOW) ? AT_SYMLINK_NOFOLLOW : 0);
#else
rc = real___fxstatat64(_STAT_VER, dirfd, path, &buf, (flags & O_NOFOLLOW) ? AT_SYMLINK_NOFOLLOW : 0);
+#endif
#endif
existed = (rc != -1);
if (!existed)
@@ -77,12 +89,24 @@
save_errno = errno;
#ifdef PSEUDO_NO_REAL_AT_FUNCTIONS
if (flags & O_NOFOLLOW) {
+#ifdef __loongarch64
+ rc = real_lstat64(path, &buf);
+#else
rc = real___lxstat64(_STAT_VER, path, &buf);
+#endif
} else {
+#ifdef __loongarch64
+ rc = real_stat64(path, &buf);
+#else
rc = real___xstat64(_STAT_VER, path, &buf);
+#endif
}
+#else
+#ifdef __loongarch64
+ rc = real_fstatat64(dirfd, path, &buf, (flags & O_NOFOLLOW) ? AT_SYMLINK_NOFOLLOW : 0);
#else
rc = real___fxstatat64(_STAT_VER, dirfd, path, &buf, (flags & O_NOFOLLOW) ? AT_SYMLINK_NOFOLLOW : 0);
+#endif
#endif
if (rc != -1 && S_ISFIFO(buf.st_mode)) {
overly_magic_nonblocking = 1;
@@ -135,12 +159,24 @@
#endif
#ifdef PSEUDO_NO_REAL_AT_FUNCTIONS
if (flags & O_NOFOLLOW) {
+#ifdef __loongarch64
+ stat_rc = real_lstat64( path, &buf);
+#else
stat_rc = real___lxstat64(_STAT_VER, path, &buf);
+#endif
} else {
+#ifdef __loongarch64
+ stat_rc = real_stat64(path, &buf);
+#else
stat_rc = real___xstat64(_STAT_VER, path, &buf);
+#endif
}
+#else
+#ifdef __loongarch64
+ stat_rc = real_fstatat64(dirfd, path, &buf, (flags & O_NOFOLLOW) ? AT_SYMLINK_NOFOLLOW : 0);
#else
stat_rc = real___fxstatat64(_STAT_VER, dirfd, path, &buf, (flags & O_NOFOLLOW) ? AT_SYMLINK_NOFOLLOW : 0);
+#endif
#endif
pseudo_debug(PDBGF_FILE, "openat(path %s), flags %o, stat rc %d, stat mode %o\n",
new file mode 100644
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2023 Peter Seebach/Seebs <seebs@seebs.net>; see
+ * guts/COPYRIGHT for information.
+ *
+ * [Note: copyright added by code generator, may be
+ * incorrect. Remove this if you fix it.]
+ *
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ * int prctl(int option, va_list ap)
+ * int rc = -1;
+ */
+
+ rc = real_prctl(option, ap);
+
+/* return rc;
+ * }
+ */
@@ -7,8 +7,11 @@
* int stat(const char *path, struct stat *buf)
* int rc = -1;
*/
-
+#ifdef __loongarch64
+ rc = wrap_fstatat(AT_FDCWD, path, buf, 0);
+#else
rc = wrap___fxstatat(_STAT_VER, AT_FDCWD, path, buf, 0);
+#endif
/* return rc;
* }
@@ -7,8 +7,11 @@
* int stat64(const char *path, struct stat *buf)
* int rc = -1;
*/
-
+#ifdef __loongarch64
+ rc = wrap_fstatat64(AT_FDCWD, path, buf, 0);
+#else
rc = wrap___fxstatat64(_STAT_VER, AT_FDCWD, path, buf, 0);
+#endif
/* return rc;
* }
@@ -8,43 +8,75 @@
*/
int
pseudo_stat(const char *path, struct stat *buf) {
+#ifdef __loongarch64
+ return real_stat( path, buf);
+#else
return real___xstat(_STAT_VER, path, buf);
+#endif
}
int
pseudo_lstat(const char *path, struct stat *buf) {
+#ifdef __loongarch64
+ return real_lstat(path,buf);
+#else
return real___lxstat(_STAT_VER, path, buf);
+#endif
}
int
pseudo_fstat(int fd, struct stat *buf) {
+#ifdef __loongarch64
+ return real_fstat(fd,buf);
+#else
return real___fxstat(_STAT_VER, fd, buf);
+#endif
}
int
pseudo_stat64(const char *path, struct stat64 *buf) {
+#ifdef __loongarch64
+ return real_stat64(path,buf);
+#else
return real___xstat64(_STAT_VER, path, buf);
+#endif
}
int
pseudo_lstat64(const char *path, struct stat64 *buf) {
+#ifdef __loongarch64
+ return real_lstat64(path,buf);
+#else
return real___lxstat64(_STAT_VER, path, buf);
+#endif
}
int
pseudo_fstat64(int fd, struct stat64 *buf) {
+#ifdef __loongarch64
+ return real_fstat64(fd,buf);
+#else
return real___fxstat64(_STAT_VER, fd, buf);
+#endif
}
/* similar thing happens with mknod */
int
pseudo_mknod(const char *path, mode_t mode, dev_t dev) {
+#ifdef __loongarch64
+ return real_mknod(path,mode,dev);
+#else
return real___xmknod(_MKNOD_VER, path, mode, &dev);
+#endif
}
int
pseudo_mknodat(int dirfd, const char *path, mode_t mode, dev_t dev) {
+#ifdef __loongarch64
+ return real_mknodat(dirfd,path,mode,dev);
+#else
return real___xmknodat(_MKNOD_VER, dirfd, path, mode, &dev);
+#endif
}
int pseudo_capset(cap_user_header_t hdrp, const cap_user_data_t datap) {
@@ -14,13 +14,21 @@ extern void pseudo_client_linked_paths(const char *oldpath, const char *newpath)
#define base_lstat real_lstat64
#define base_fstat real_fstat64
#define base_stat real_stat64
+#ifdef __loongarch64
+#define base_fstatat(dirfd, path, buf, flags) real_fstatat64( dirfd, path, buf, flags)
+#else
#define base_fstatat(dirfd, path, buf, flags) real___fxstatat64(_STAT_VER, dirfd, path, buf, flags)
+#endif
#else
#define base_lstat real_lstat
#define base_fstat real_fstat
#define base_stat real_stat
+#ifdef __loongarch64
+#define base_fstatat(dirfd, path, buf, flags) real_fstatat( dirfd, path, buf, flags
+#else
#define base_fstatat(dirfd, path, buf, flags) real___fxstatat(_STAT_VER, dirfd, path, buf, flags)
#endif
+#endif
extern void pseudo_antimagic(void);
extern void pseudo_magic(void);
extern void pseudo_client_touchuid(void);
@@ -13,7 +13,9 @@
* script if you want to modify this. */
@body
+#ifndef __loongarch64
static ${type} (*real_${name})(${decl_args}) = ${real_init};
+#endif
${maybe_skip}