bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Add support to define structures in mig.


From: Luca
Subject: Re: [PATCH] Add support to define structures in mig.
Date: Thu, 3 Nov 2022 09:02:03 +0100

Hi,

Il 03/11/22 06:09, Flavio Cruz ha scritto:
+/*
+ *  Handles the declaration
+ *     type new = struct { type1 a1; type2 a2; ... };
+ */
+ipc_type_t *
+itStructDecl(u_int min_type_size_in_bytes, u_int required_alignment_in_bytes)
+{
+    int final_struct_bytes = min_type_size_in_bytes;
+    if (final_struct_bytes % required_alignment_in_bytes) {
+         final_struct_bytes += required_alignment_in_bytes - 
(final_struct_bytes % required_alignment_in_bytes);
+    }
+    ipc_type_t *element_type = NULL;
+    int number_elements = 0;
+    // If the struct is short or int aligned, use that as the base type.
+    switch (required_alignment_in_bytes) {
+       case 2:
+           element_type = itShortType;
+           assert(final_struct_bytes % 2 == 0);
+           number_elements = final_struct_bytes / 2;
+           break;
+       case 4:
+           element_type = itIntType;
+           assert(final_struct_bytes % 4 == 0);
+           number_elements = final_struct_bytes / 4;
+           break;
+        case 1:
+       default:
+           element_type = itByteType;
+           number_elements = final_struct_bytes;
+           break;
+    }

Due to 64-bit gnumach compatibility, my last patches on mig forced a 4-byte alignment for all data fields. IIRC it's also forced on 32 bit, so I think the alignment of struct here might not be working as expected.


Luca



reply via email to

[Prev in Thread] Current Thread [Next in Thread]