<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux-toradex.git/tools/include/nolibc, branch master</title>
<subtitle>Linux kernel for Apalis and Colibri modules</subtitle>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/'/>
<entry>
<title>tools/nolibc: fix the function argument order of calloc()</title>
<updated>2026-09-30T19:36:28+00:00</updated>
<author>
<name>Thomas Weißschuh</name>
<email>linux@weissschuh.net</email>
</author>
<published>2026-09-24T07:11:58+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=5f81ffdf26072fd262093c4127e656276564395f'/>
<id>5f81ffdf26072fd262093c4127e656276564395f</id>
<content type='text'>
As per the man page, the number of elements should be the first argument
and the size of each one the second.

Switch the arguments around.

The behavior will not change, as both arguments are only multiplied with
each other.

Reported-by: Sean Christopherson &lt;seanjc@google.com&gt;
Link: https://lore.kernel.org/lkml/aqQmCtPf_5M-BjRW@google.com/
Signed-off-by: Thomas Weißschuh &lt;linux@weissschuh.net&gt;
Link: https://patch.msgid.link/20260924-nolibc-calloc-v1-1-c49b383475d5@weissschuh.net
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
As per the man page, the number of elements should be the first argument
and the size of each one the second.

Switch the arguments around.

The behavior will not change, as both arguments are only multiplied with
each other.

Reported-by: Sean Christopherson &lt;seanjc@google.com&gt;
Link: https://lore.kernel.org/lkml/aqQmCtPf_5M-BjRW@google.com/
Signed-off-by: Thomas Weißschuh &lt;linux@weissschuh.net&gt;
Link: https://patch.msgid.link/20260924-nolibc-calloc-v1-1-c49b383475d5@weissschuh.net
</pre>
</div>
</content>
</entry>
<entry>
<title>tools/nolibc: check for overflow in malloc()</title>
<updated>2026-09-30T19:27:03+00:00</updated>
<author>
<name>Danish Khateeb</name>
<email>danishkhateeb03@gmail.com</email>
</author>
<published>2026-09-26T15:24:14+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=2111eb4273e7fda0815de85319653104f323c441'/>
<id>2111eb4273e7fda0815de85319653104f323c441</id>
<content type='text'>
malloc() adds the size of its header to the requested size without
checking for overflow. For a size within the header size of SIZE_MAX,
the sum wraps around to a few bytes, and malloc() returns a single page
instead of NULL.

calloc() checks its multiplication for overflow, but then passes the
product to malloc(), so calloc(SIZE_MAX, 1) returns a single page too.
So does realloc(ptr, SIZE_MAX).

Such a size is usually a bug in the caller, for instance a length of -1
used as a size_t, and returning a page instead of NULL can turn it into
a heap overflow.

Fail with ENOMEM when adding the header overflows, as glibc does for
sizes this large.

Fixes: 0e0ff638400b ("tools/nolibc/stdlib: Implement `malloc()`, `calloc()`, `realloc()` and `free()`")
Assisted-by: LLM
Signed-off-by: Danish Khateeb &lt;danishkhateeb03@gmail.com&gt;
Link: https://patch.msgid.link/20260926152414.251214-3-danishkhateeb03@gmail.com
Signed-off-by: Thomas Weißschuh &lt;linux@weissschuh.net&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
malloc() adds the size of its header to the requested size without
checking for overflow. For a size within the header size of SIZE_MAX,
the sum wraps around to a few bytes, and malloc() returns a single page
instead of NULL.

calloc() checks its multiplication for overflow, but then passes the
product to malloc(), so calloc(SIZE_MAX, 1) returns a single page too.
So does realloc(ptr, SIZE_MAX).

Such a size is usually a bug in the caller, for instance a length of -1
used as a size_t, and returning a page instead of NULL can turn it into
a heap overflow.

Fail with ENOMEM when adding the header overflows, as glibc does for
sizes this large.

Fixes: 0e0ff638400b ("tools/nolibc/stdlib: Implement `malloc()`, `calloc()`, `realloc()` and `free()`")
Assisted-by: LLM
Signed-off-by: Danish Khateeb &lt;danishkhateeb03@gmail.com&gt;
Link: https://patch.msgid.link/20260926152414.251214-3-danishkhateeb03@gmail.com
Signed-off-by: Thomas Weißschuh &lt;linux@weissschuh.net&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>tools/nolibc: stop rounding malloc() sizes up to 4096 bytes</title>
<updated>2026-09-30T19:27:03+00:00</updated>
<author>
<name>Danish Khateeb</name>
<email>danishkhateeb03@gmail.com</email>
</author>
<published>2026-09-26T15:24:13+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=b7db3ba9434cbad3d15f62500104525bfa28a304'/>
<id>b7db3ba9434cbad3d15f62500104525bfa28a304</id>
<content type='text'>
malloc() rounds the size of each mapping up to a multiple of 4096,
presumably to align it to a page boundary. But the page size is not 4096
on all architectures, and mmap() and munmap() round the length up to the
page size themselves.

Drop the rounding. As heap-&gt;len is no longer rounded up, growing a block
with realloc() now always creates a new mapping.

Assisted-by: LLM
Signed-off-by: Danish Khateeb &lt;danishkhateeb03@gmail.com&gt;
Reviewed-by: Willy Tarreau &lt;w@1wt.eu&gt;
Link: https://patch.msgid.link/20260926152414.251214-2-danishkhateeb03@gmail.com
Signed-off-by: Thomas Weißschuh &lt;linux@weissschuh.net&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
malloc() rounds the size of each mapping up to a multiple of 4096,
presumably to align it to a page boundary. But the page size is not 4096
on all architectures, and mmap() and munmap() round the length up to the
page size themselves.

Drop the rounding. As heap-&gt;len is no longer rounded up, growing a block
with realloc() now always creates a new mapping.

Assisted-by: LLM
Signed-off-by: Danish Khateeb &lt;danishkhateeb03@gmail.com&gt;
Reviewed-by: Willy Tarreau &lt;w@1wt.eu&gt;
Link: https://patch.msgid.link/20260926152414.251214-2-danishkhateeb03@gmail.com
Signed-off-by: Thomas Weißschuh &lt;linux@weissschuh.net&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>tools/nolibc: add support for pread() and pwrite()</title>
<updated>2026-09-27T09:32:20+00:00</updated>
<author>
<name>Thomas Weißschuh</name>
<email>linux@weissschuh.net</email>
</author>
<published>2026-09-27T08:49:16+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=da27722051fdf0775d8c5b3e33dc21bcf605dbd4'/>
<id>da27722051fdf0775d8c5b3e33dc21bcf605dbd4</id>
<content type='text'>
These are standard function to interact with a file descriptor without
touching its internal file offset.

Signed-off-by: Thomas Weißschuh &lt;linux@weissschuh.net&gt;
Reviewed-by: Willy Tarreau &lt;w@1wt.eu&gt;
Link: https://patch.msgid.link/20260927-nolibc-pread-v1-5-e9af6e47b37a@weissschuh.net
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
These are standard function to interact with a file descriptor without
touching its internal file offset.

Signed-off-by: Thomas Weißschuh &lt;linux@weissschuh.net&gt;
Reviewed-by: Willy Tarreau &lt;w@1wt.eu&gt;
Link: https://patch.msgid.link/20260927-nolibc-pread-v1-5-e9af6e47b37a@weissschuh.net
</pre>
</div>
</content>
</entry>
<entry>
<title>tools/nolibc: introduce __NOLIBC_BITS_PER_SYSCALL_ARG</title>
<updated>2026-09-27T09:32:13+00:00</updated>
<author>
<name>Thomas Weißschuh</name>
<email>linux@weissschuh.net</email>
</author>
<published>2026-09-27T08:49:15+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=abafa291e52ac95c46ba0744b64e4d0d3adae4b7'/>
<id>abafa291e52ac95c46ba0744b64e4d0d3adae4b7</id>
<content type='text'>
ILP32 architectures, like x32 and n32, support 64-bit system call
arguments, although they are nominally 32-bit architectures.

Add a new define which provides the size of system call arguments
so generic libc code can use the best system call for those.

Signed-off-by: Thomas Weißschuh &lt;linux@weissschuh.net&gt;
Reviewed-by: Willy Tarreau &lt;w@1wt.eu&gt;
Link: https://patch.msgid.link/20260927-nolibc-pread-v1-4-e9af6e47b37a@weissschuh.net
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
ILP32 architectures, like x32 and n32, support 64-bit system call
arguments, although they are nominally 32-bit architectures.

Add a new define which provides the size of system call arguments
so generic libc code can use the best system call for those.

Signed-off-by: Thomas Weißschuh &lt;linux@weissschuh.net&gt;
Reviewed-by: Willy Tarreau &lt;w@1wt.eu&gt;
Link: https://patch.msgid.link/20260927-nolibc-pread-v1-4-e9af6e47b37a@weissschuh.net
</pre>
</div>
</content>
</entry>
<entry>
<title>tools/nolibc: move __NOLIBC_LLARGPART() to compiler.h</title>
<updated>2026-09-27T09:32:06+00:00</updated>
<author>
<name>Thomas Weißschuh</name>
<email>linux@weissschuh.net</email>
</author>
<published>2026-09-27T08:49:14+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=ddcf77b0350b2eaca4ba2f9db7c4569045c0c46f'/>
<id>ddcf77b0350b2eaca4ba2f9db7c4569045c0c46f</id>
<content type='text'>
pread() and pwrite() support will require the usage of the macro from
the arch-*.h headers. sys.h can not be used from those.

Move the macro to a more generic header.

Signed-off-by: Thomas Weißschuh &lt;linux@weissschuh.net&gt;
Reviewed-by: Willy Tarreau &lt;w@1wt.eu&gt;
Link: https://patch.msgid.link/20260927-nolibc-pread-v1-3-e9af6e47b37a@weissschuh.net
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
pread() and pwrite() support will require the usage of the macro from
the arch-*.h headers. sys.h can not be used from those.

Move the macro to a more generic header.

Signed-off-by: Thomas Weißschuh &lt;linux@weissschuh.net&gt;
Reviewed-by: Willy Tarreau &lt;w@1wt.eu&gt;
Link: https://patch.msgid.link/20260927-nolibc-pread-v1-3-e9af6e47b37a@weissschuh.net
</pre>
</div>
</content>
</entry>
<entry>
<title>tools/nolibc: make 64-bit systemcall argument padding generic</title>
<updated>2026-09-27T09:32:00+00:00</updated>
<author>
<name>Thomas Weißschuh</name>
<email>linux@weissschuh.net</email>
</author>
<published>2026-09-27T08:49:13+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=74136192e3f6f48670a0bccc7bdc5005b13d94f9'/>
<id>74136192e3f6f48670a0bccc7bdc5005b13d94f9</id>
<content type='text'>
Several 32-bit architectures pass a 64-bit systemcall argument
as two 32-bit values requiring alignment to an even register pair.
This case is currently relevant for the ftruncate64() wrapper and handled
by those architectures providing custom wrappers.
With the introduction of pread() and pwrite() wrappers, the same pattern
would lead to a lot of repeated code.

Add a #define, so that the generic code can do the padding where
necessary, without any per-architecture duplication.

Signed-off-by: Thomas Weißschuh &lt;linux@weissschuh.net&gt;
Reviewed-by: Willy Tarreau &lt;w@1wt.eu&gt;
Link: https://patch.msgid.link/20260927-nolibc-pread-v1-2-e9af6e47b37a@weissschuh.net
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Several 32-bit architectures pass a 64-bit systemcall argument
as two 32-bit values requiring alignment to an even register pair.
This case is currently relevant for the ftruncate64() wrapper and handled
by those architectures providing custom wrappers.
With the introduction of pread() and pwrite() wrappers, the same pattern
would lead to a lot of repeated code.

Add a #define, so that the generic code can do the padding where
necessary, without any per-architecture duplication.

Signed-off-by: Thomas Weißschuh &lt;linux@weissschuh.net&gt;
Reviewed-by: Willy Tarreau &lt;w@1wt.eu&gt;
Link: https://patch.msgid.link/20260927-nolibc-pread-v1-2-e9af6e47b37a@weissschuh.net
</pre>
</div>
</content>
</entry>
<entry>
<title>tools/nolibc: add 64-bit parisc support</title>
<updated>2026-09-26T07:17:52+00:00</updated>
<author>
<name>Thomas Weißschuh</name>
<email>linux@weissschuh.net</email>
</author>
<published>2026-04-07T11:44:12+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=0e1c44b472e1ec21efdad1df21b10e5c568b65b5'/>
<id>0e1c44b472e1ec21efdad1df21b10e5c568b65b5</id>
<content type='text'>
Extend the existing parisc support to also handle 64-bit mode.

Some peculiarities:
* The nonstandard ftruncate64 system call requires a workaround.
* The linker defaults to main() as entry point, which needs to be
  switched to _start() explicitly.
* The linker defaults to dynamic linking, which needs to be disabled
  explicitly.
* With the default -Os, gcc does not use 64-bit multiplication
  instructions, requiring libgcc. Use -O2 instead.
* There is no qemu-user available.
* CONFIG_COMPAT needs to be disabled to avoid build errors due to a
  missing 32-bit vDSO compiler.

Signed-off-by: Thomas Weißschuh &lt;linux@weissschuh.net&gt;
Link: https://patch.msgid.link/20260914-nolibc-parisc64-v3-1-f14b320117c1@weissschuh.net
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Extend the existing parisc support to also handle 64-bit mode.

Some peculiarities:
* The nonstandard ftruncate64 system call requires a workaround.
* The linker defaults to main() as entry point, which needs to be
  switched to _start() explicitly.
* The linker defaults to dynamic linking, which needs to be disabled
  explicitly.
* With the default -Os, gcc does not use 64-bit multiplication
  instructions, requiring libgcc. Use -O2 instead.
* There is no qemu-user available.
* CONFIG_COMPAT needs to be disabled to avoid build errors due to a
  missing 32-bit vDSO compiler.

Signed-off-by: Thomas Weißschuh &lt;linux@weissschuh.net&gt;
Link: https://patch.msgid.link/20260914-nolibc-parisc64-v3-1-f14b320117c1@weissschuh.net
</pre>
</div>
</content>
</entry>
<entry>
<title>tools/nolibc: fix FD_SET(), FD_CLR() and FD_ISSET() on 64-bit</title>
<updated>2026-09-26T06:43:26+00:00</updated>
<author>
<name>Danish Khateeb</name>
<email>danishkhateeb03@gmail.com</email>
</author>
<published>2026-09-25T21:15:59+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=929ea5b3481fdbbb419f3986703280fb2b819504'/>
<id>929ea5b3481fdbbb419f3986703280fb2b819504</id>
<content type='text'>
Since commit feaf75658783 ("nolibc: fix fd_set type"), an fd_set is an
array of unsigned long, but the FD_* macros still build their masks as
an int or an unsigned int: 1 &lt;&lt; n in FD_SET(), 1U &lt;&lt; n in FD_CLR() and
FD_ISSET(), where n is the fd modulo 64 on 64-bit architectures. So:

- FD_SET() of an fd with n == 31 sets the bits for n = 31-63, as
  1 &lt;&lt; 31 is negative and gets sign-extended.
- For n &gt;= 32 the shifts are undefined. x86-64, for instance, masks
  the shift count, so FD_SET(40) and FD_ISSET(40) use the bit of fd 8.
- FD_CLR() zero-extends ~(1U &lt;&lt; n), so it also clears the bits for
  n = 32-63, whichever fd it is given.

select() on fd 40, for instance, fails with EBADF, or watches fd 8
instead if that one is open.

Build the masks from 1UL.

Fixes: feaf75658783 ("nolibc: fix fd_set type")
Assisted-by: LLM
Signed-off-by: Danish Khateeb &lt;danishkhateeb03@gmail.com&gt;
Link: https://patch.msgid.link/20260925211600.119116-3-danishkhateeb03@gmail.com
Signed-off-by: Thomas Weißschuh &lt;linux@weissschuh.net&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Since commit feaf75658783 ("nolibc: fix fd_set type"), an fd_set is an
array of unsigned long, but the FD_* macros still build their masks as
an int or an unsigned int: 1 &lt;&lt; n in FD_SET(), 1U &lt;&lt; n in FD_CLR() and
FD_ISSET(), where n is the fd modulo 64 on 64-bit architectures. So:

- FD_SET() of an fd with n == 31 sets the bits for n = 31-63, as
  1 &lt;&lt; 31 is negative and gets sign-extended.
- For n &gt;= 32 the shifts are undefined. x86-64, for instance, masks
  the shift count, so FD_SET(40) and FD_ISSET(40) use the bit of fd 8.
- FD_CLR() zero-extends ~(1U &lt;&lt; n), so it also clears the bits for
  n = 32-63, whichever fd it is given.

select() on fd 40, for instance, fails with EBADF, or watches fd 8
instead if that one is open.

Build the masks from 1UL.

Fixes: feaf75658783 ("nolibc: fix fd_set type")
Assisted-by: LLM
Signed-off-by: Danish Khateeb &lt;danishkhateeb03@gmail.com&gt;
Link: https://patch.msgid.link/20260925211600.119116-3-danishkhateeb03@gmail.com
Signed-off-by: Thomas Weißschuh &lt;linux@weissschuh.net&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>tools/nolibc: fix readdir_r() with 64-bit directory offsets</title>
<updated>2026-09-26T06:43:26+00:00</updated>
<author>
<name>Danish Khateeb</name>
<email>danishkhateeb03@gmail.com</email>
</author>
<published>2026-09-25T21:15:58+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=00c81514ad49110574e4b9bdbc448551004161f2'/>
<id>00c81514ad49110574e4b9bdbc448551004161f2</id>
<content type='text'>
readdir_r() stores the result of _sys_lseek() in an int. Directory
offsets are opaque cookies which can use all 64 bits: ext4, for
instance, gives 64-bit processes 63-bit hashes, and
0x7fffffffffffffff as the offset after the last entry. Truncated to an
int, such an offset is negative about half the time, and readdir_r()
takes it for an error.

Since commit 4ada5679f18d ("tools/nolibc/dirent: avoid errno in
readdir_r"), readdir_r() fails at the first entry whose offset has
bit 31 set, which on ext4 is usually one of the first few, and returns
the truncated offset as the error number. Before that, only -1 counted
as an error, which the last entry always hits: readdir_r() then
returned errno, usually 0, without filling in the entry, so the caller
got the previous entry a second time and never saw the last one.

32-bit processes get 31-bit hashes from ext4 and are not affected.

Keep the offset in an off_t.

Fixes: 665fa8dea90d ("tools/nolibc: add support for directory access")
Assisted-by: LLM
Signed-off-by: Danish Khateeb &lt;danishkhateeb03@gmail.com&gt;
Link: https://patch.msgid.link/20260925211600.119116-2-danishkhateeb03@gmail.com
Signed-off-by: Thomas Weißschuh &lt;linux@weissschuh.net&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
readdir_r() stores the result of _sys_lseek() in an int. Directory
offsets are opaque cookies which can use all 64 bits: ext4, for
instance, gives 64-bit processes 63-bit hashes, and
0x7fffffffffffffff as the offset after the last entry. Truncated to an
int, such an offset is negative about half the time, and readdir_r()
takes it for an error.

Since commit 4ada5679f18d ("tools/nolibc/dirent: avoid errno in
readdir_r"), readdir_r() fails at the first entry whose offset has
bit 31 set, which on ext4 is usually one of the first few, and returns
the truncated offset as the error number. Before that, only -1 counted
as an error, which the last entry always hits: readdir_r() then
returned errno, usually 0, without filling in the entry, so the caller
got the previous entry a second time and never saw the last one.

32-bit processes get 31-bit hashes from ext4 and are not affected.

Keep the offset in an off_t.

Fixes: 665fa8dea90d ("tools/nolibc: add support for directory access")
Assisted-by: LLM
Signed-off-by: Danish Khateeb &lt;danishkhateeb03@gmail.com&gt;
Link: https://patch.msgid.link/20260925211600.119116-2-danishkhateeb03@gmail.com
Signed-off-by: Thomas Weißschuh &lt;linux@weissschuh.net&gt;
</pre>
</div>
</content>
</entry>
</feed>
