[PATCH] Fix BZ#5070
Jakub Jelinek
jakub@redhat.com
Wed Oct 3 07:49:00 GMT 2007
Hi!
This patch should IMHO cure the weirdo struct layout problem on arm
while not pessimizing code on sane architectures (on x86_64-linux
the routine with this patch has minor differences in insn scheduling,
but it is the same size and same instructions, just reordered and it is
unclear what is more efficient if not equivalent).
On arm at least with cross compiler distilled testcase also passes
compile time assertion made from the assert and the memset looks good as
well.
2007-10-03 Jakub Jelinek <jakub@redhat.com>
[BZ #5070]
* sysdeps/unix/sysv/linux/check_pf.c (make_request): Remove
pad array from req, instead use offsetof and sizeof to clear
padding.
--- libc/sysdeps/unix/sysv/linux/check_pf.c.jj 2007-09-02 19:09:33.000000000 +0200
+++ libc/sysdeps/unix/sysv/linux/check_pf.c 2007-10-03 09:26:18.000000000 +0200
@@ -54,10 +54,6 @@ make_request (int fd, pid_t pid, bool *s
{
struct nlmsghdr nlh;
struct rtgenmsg g;
- /* struct rtgenmsg consists of a single byte. This means there
- are three bytes of padding included in the REQ definition.
- We make them explicit here. */
- char pad[3];
} req;
struct sockaddr_nl nladdr;
@@ -68,8 +64,11 @@ make_request (int fd, pid_t pid, bool *s
req.nlh.nlmsg_seq = time (NULL);
req.g.rtgen_family = AF_UNSPEC;
- assert (sizeof (req) - offsetof (struct req, pad) == 3);
- memset (req.pad, '\0', sizeof (req.pad));
+ assert (sizeof (req) - offsetof (struct req, g)
+ - sizeof (req.g.rtgen_family) == 3);
+ memset (&req.g.rtgen_family + 1, '\0',
+ sizeof (req) - offsetof (struct req, g)
+ - sizeof (req.g.rtgen_family));
memset (&nladdr, '\0', sizeof (nladdr));
nladdr.nl_family = AF_NETLINK;
Jakub
More information about the Libc-hacker
mailing list