Fix 32-bit alignment issues.
authorDavid Given <dg@cowlark.com>
Tue, 19 Jan 2016 20:46:44 +0000 (21:46 +0100)
committerDavid Given <dg@cowlark.com>
Tue, 19 Jan 2016 20:46:44 +0000 (21:46 +0100)
Applications/util/init.c
Kernel/syscall_fs.c
Library/include/syscalls.h

index f8b2f13..678f90a 100644 (file)
@@ -6,6 +6,7 @@
 #include <string.h>
 #include <signal.h>
 #include <stdlib.h>
+#include <stdio.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <pwd.h>
@@ -328,10 +329,10 @@ static void parse_inittab(void)
        while (sdata < sdata_end)
                parse_initline();
        /* Allocate space for the control arrays */
-       initpid = (uint16_t *) idata;
-       idata += 2 * initcount;
        initptr = (uint8_t **) idata;
        idata += sizeof(void *) * initcount;
+       initpid = (uint16_t *) idata;
+       idata += 2 * initcount;
        if (brk(idata) == -1)
                putstr("unable to return space\n");
        memset(initpid, 0, 2 * initcount);
index 2c8056a..ac86884 100644 (file)
@@ -134,9 +134,10 @@ arg_t _fstat(void)
 /* Utility for stat and fstat */
 int stcpy(inoptr ino, char *buf)
 {
-       int err = uput((char *) &(ino->c_dev), buf, 12);
-       err |= uput((char *) &(ino->c_node.i_addr[0]), buf + 12, 2);
-       err |= uput((char *) &(ino->c_node.i_size), buf + 14, 16);
+       int err = uput((char *) &(ino->c_node.i_size),    buf + 0,         5*4);
+       err |=    uput((char *) &(ino->c_dev),            buf + 5*4,       2*2);
+       err |=    uput((char *) &(ino->c_node.i_mode),    buf + 5*4 + 2*2, 4*2);
+       err |=    uput((char *) &(ino->c_node.i_addr[0]), buf + 5*4 + 6*2, 1*2);
        return err;
 }
 
index 3adde78..dd501ee 100644 (file)
@@ -15,6 +15,13 @@ extern int syscall(int callno, ...);
 
 struct  _uzistat
 {
+       /* For alignment reasons, arrange this structure with largest objects
+        * first. */
+       uint32_t   st_size;
+       uint32_t   st_atime;
+       uint32_t   st_mtime;
+       uint32_t   st_ctime;
+       uint32_t   st_timeh;    /* Time high bytes */
        int16_t    st_dev;
        uint16_t   st_ino;
        uint16_t   st_mode;
@@ -22,11 +29,6 @@ struct  _uzistat
        uint16_t   st_uid;
        uint16_t   st_gid;
        uint16_t   st_rdev;
-       uint32_t   st_size;
-       uint32_t   st_atime;
-       uint32_t   st_mtime;
-       uint32_t   st_ctime;
-       uint32_t   st_timeh;    /* Time high bytes */
 };
 
 struct _uzisysinfoblk {