Skip to content

Commit fb01ff6

Browse files
committed
tools/nolibc: keep brk(), sbrk(), mmap() away from __sysret()
The __sysret() function causes some undesirable casts so we'll revert it. In order to keep it simple it will now only support integer return values like in the past, so we must basically revert the changes that were made to these 3 syscalls which return a pointer so that they simply rely on their own test and the SET_ERRNO() macro. Fixes: 4201cfc ("tools/nolibc: clean up sbrk() routine") Fixes: 924e953 ("tools/nolibc: clean up mmap() routine") Fixes: d27447b ("tools/nolibc: sys.h: apply __sysret() helper") Link: https://lore.kernel.org/lkml/20230806095846.GB10627@1wt.eu/ Link: https://lore.kernel.org/lkml/ZNKOJY+g66nkIyvv@1wt.eu/ Cc: Zhangjin Wu <falcon@tinylab.org> Cc: David Laight <David.Laight@ACULAB.COM> Cc: Thomas Weißschuh <thomas@t-8ch.de> Signed-off-by: Willy Tarreau <w@1wt.eu>
1 parent 872dbfa commit fb01ff6

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

  • tools/include/nolibc

tools/include/nolibc/sys.h

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,13 @@ void *sys_brk(void *addr)
8282
static __attribute__((unused))
8383
int brk(void *addr)
8484
{
85-
return __sysret(sys_brk(addr) ? 0 : -ENOMEM);
85+
void *ret = sys_brk(addr);
86+
87+
if (!ret) {
88+
SET_ERRNO(ENOMEM);
89+
return -1;
90+
}
91+
return 0;
8692
}
8793

8894
static __attribute__((unused))
@@ -94,7 +100,8 @@ void *sbrk(intptr_t inc)
94100
if (ret && sys_brk(ret + inc) == ret + inc)
95101
return ret + inc;
96102

97-
return (void *)__sysret(-ENOMEM);
103+
SET_ERRNO(ENOMEM);
104+
return (void *)-1;
98105
}
99106

100107

@@ -682,7 +689,13 @@ void *sys_mmap(void *addr, size_t length, int prot, int flags, int fd,
682689
static __attribute__((unused))
683690
void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset)
684691
{
685-
return (void *)__sysret((unsigned long)sys_mmap(addr, length, prot, flags, fd, offset));
692+
void *ret = sys_mmap(addr, length, prot, flags, fd, offset);
693+
694+
if ((unsigned long)ret >= -4095UL) {
695+
SET_ERRNO(-(long)ret);
696+
ret = MAP_FAILED;
697+
}
698+
return ret;
686699
}
687700

688701
static __attribute__((unused))

0 commit comments

Comments
 (0)