Skip to content

Commit dde5625

Browse files
committed
tools/nolibc: add support for sys_llseek()
Not all architectures have the old sys_lseek(), notably riscv32. Implement lseek() in terms of sys_llseek() in that case. Signed-off-by: Thomas Weißschuh <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Thomas Weißschuh <[email protected]>
1 parent c1f4a7a commit dde5625

File tree

1 file changed

+28
-1
lines changed
  • tools/include/nolibc

1 file changed

+28
-1
lines changed

tools/include/nolibc/sys.h

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,10 +597,37 @@ off_t sys_lseek(int fd, off_t offset, int whence)
597597
#endif
598598
}
599599

600+
static __attribute__((unused))
601+
int sys_llseek(int fd, unsigned long offset_high, unsigned long offset_low,
602+
__kernel_loff_t *result, int whence)
603+
{
604+
#ifdef __NR_llseek
605+
return my_syscall5(__NR_llseek, fd, offset_high, offset_low, result, whence);
606+
#else
607+
return __nolibc_enosys(__func__, fd, offset_high, offset_low, result, whence);
608+
#endif
609+
}
610+
600611
static __attribute__((unused))
601612
off_t lseek(int fd, off_t offset, int whence)
602613
{
603-
return __sysret(sys_lseek(fd, offset, whence));
614+
__kernel_loff_t loff = 0;
615+
off_t result;
616+
int ret;
617+
618+
result = sys_lseek(fd, offset, whence);
619+
if (result == -ENOSYS) {
620+
/* Only exists on 32bit where nolibc off_t is also 32bit */
621+
ret = sys_llseek(fd, 0, offset, &loff, whence);
622+
if (ret < 0)
623+
result = ret;
624+
else if (loff != (off_t)loff)
625+
result = -EOVERFLOW;
626+
else
627+
result = loff;
628+
}
629+
630+
return __sysret(result);
604631
}
605632

606633

0 commit comments

Comments
 (0)