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

[Minios-devel] [UNIKRAFT PATCHv3 04/25] plat/common: Do obfuscates arithmetic for kernel image symbols



As we discussed in [1], the C spec states that comparing 2 pointers
belonging to distinct object is undefined [2]. In this case, we defined
macros to wrap kernel image symbols. they  will make GCC can not
recognize varirable's original type, and do further assumptions for it.

[1] https://lists.xen.org/archives/html/minios-devel/2018-11/msg00054.html
[2] 
https://wiki.sei.cmu.edu/confluence/display/c/ARR36-C.+Do+not+subtract+or+compare+two+pointers+that+do+not+refer+to+the+same+array

Signed-off-by: Wei Chen <wei.chen@xxxxxxx>
---
 plat/common/include/sections.h | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/plat/common/include/sections.h b/plat/common/include/sections.h
index 42f41d2..b32389c 100644
--- a/plat/common/include/sections.h
+++ b/plat/common/include/sections.h
@@ -62,4 +62,36 @@ extern char __bss_start[];
 /* _end: end of kernel image */
 extern char _end[];
 
+
+/* The C spec states that comparing 2 pointers belonging to distinct object is 
undefined:
+ * 
https://wiki.sei.cmu.edu/confluence/display/c/ARR36-C.+Do+not+subtract+or+compare+two+pointers+that+do+not+refer+to+the+same+array
+ *
+ * In this case, we define following macro to access above symbols. This will
+ * help us to avoid subtracting or comparing these symbols as distinct 
pointers.
+ *
+ * This macro hide the original variable for a variable address, it will make
+ * GCC couldn't recognize varirable's original type, and do further assumptions
+ * for it.
+ */
+#define HIDE_VAR_FOR_GCC(var, ofs)     \
+({                                     \
+       unsigned long __var;            \
+       __var = (unsigned long) (var);  \
+       (typeof(var))(__var + (ofs));   \
+})
+
+#define __uk_image_symbol(addr)        HIDE_VAR_FOR_GCC((unsigned long)(addr), 
0)
+
+#define __DTB          __uk_image_symbol(_dtb)
+#define __TEXT         __uk_image_symbol(_text)
+#define __ETEXT                __uk_image_symbol(_etext)
+#define __RODATA       __uk_image_symbol(_rodata)
+#define __ERODATA      __uk_image_symbol(_erodata)
+#define __DATA         __uk_image_symbol(_data)
+#define __EDATA                __uk_image_symbol(_edata)
+#define __CTORS                __uk_image_symbol(_ctors)
+#define __ECTORS       __uk_image_symbol(_ectors)
+#define __BSS_START    __uk_image_symbol(__bss_start)
+#define __END          __uk_image_symbol(_end)
+
 #endif /* __PLAT_CMN_SECTIONS_H__ */
-- 
2.17.1


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.