Skip to content

Commit

Permalink
preload: Provide wrappers for functions specific to 64-bit time_t
Browse files Browse the repository at this point in the history
  • Loading branch information
vorlonofportland authored and martinpitt committed Mar 24, 2024
1 parent 8ed5dbb commit 635c86e
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/libumockdev-preload.c
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,8 @@ rettype name(const char *path, arg2t arg2, arg3t arg3, arg4t arg4) \
* the emulated /dev to indicate a block device (the sticky bit has no
* real functionality for device nodes) */
#define WRAP_STAT(prefix, suffix) \
extern int prefix ## stat ## suffix (const char *path, \
struct stat ## suffix *st); \
int prefix ## stat ## suffix (const char *path, struct stat ## suffix *st) \
{ \
const char *p; \
Expand All @@ -1259,6 +1261,8 @@ int prefix ## stat ## suffix (const char *path, struct stat ## suffix *st) \

/* wrapper template for fstatat family */
#define WRAP_FSTATAT(prefix, suffix) \
extern int prefix ## fstatat ## suffix (int dirfd, const char *path, \
struct stat ## suffix *st, int flags); \
int prefix ## fstatat ## suffix (int dirfd, const char *path, struct stat ## suffix *st, int flags) \
{ \
const char *p; \
Expand Down Expand Up @@ -1416,6 +1420,12 @@ WRAP_STAT(,64);
WRAP_STAT(l,64);
WRAP_FSTATAT(,64);
WRAP_FOPEN(,64);
#if defined(__USE_FILE_OFFSET64) && defined(__USE_TIME_BITS64)
#define stat64_time64 stat64
WRAP_STAT(__,64_time64);
WRAP_STAT(__l,64_time64);
WRAP_FSTATAT(__,64_time64);
#endif
#endif

WRAP_3ARGS(ssize_t, -1, readlink, char *, size_t);
Expand Down Expand Up @@ -1785,6 +1795,18 @@ recvmsg(int sockfd, struct msghdr * msg, int flags)
return ret;
}

extern ssize_t __recvmsg64(int sockfd, struct msghdr * msg, int flags);
ssize_t
__recvmsg64(int sockfd, struct msghdr * msg, int flags)
{
libc_func(__recvmsg64, int, int, struct msghdr *, int);
ssize_t ret = ___recvmsg64(sockfd, msg, flags);

netlink_recvmsg(sockfd, msg, ret);

return ret;
}

int
socket(int domain, int type, int protocol)
{
Expand Down Expand Up @@ -1902,6 +1924,42 @@ ioctl(int d, IOCTL_REQUEST_TYPE request, ...)
return result;
}

#ifdef __GLIBC__

extern int __ioctl_time64 (int __fd, unsigned long int __request, ...) __THROW;
int
__ioctl_time64(int d, IOCTL_REQUEST_TYPE request, ...)
{
libc_func(__ioctl_time64, int, int, IOCTL_REQUEST_TYPE, ...);
int result;
va_list ap;
void* arg;

/* one cannot reliably forward arbitrary varargs
* (http://c-faq.com/varargs/handoff.html), but we know that ioctl gets at
* most one extra argument, and almost all of them are pointers or ints,
* both of which fit into a void*.
*/
va_start(ap, request);
arg = va_arg(ap, void*);
va_end(ap);

result = remote_emulate(d, IOCTL_REQ_IOCTL, (unsigned int) request, (long) arg);
if (result != UNHANDLED) {
DBG(DBG_IOCTL, "ioctl fd %i request %X: emulated, result %i\n", d, (unsigned) request, result);
return result;
}

/* fallback to call original ioctl */
result = ___ioctl_time64(d, request, arg);
DBG(DBG_IOCTL, "ioctl fd %i request %X: original, result %i\n", d, (unsigned) request, result);

return result;
}

#endif /* __GLIBC__ */


int
isatty(int fd)
{
Expand Down

0 comments on commit 635c86e

Please sign in to comment.