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

[Xen-devel] [PATCH v11 6/9] xen/common: use DECLARE_BOUNDS as required



Use DECLARE_BOUNDS and the two static inline functions that come with it
for comparisons and subtractions of:

__note_gnu_build_id_start, __note_gnu_build_id_end,
__lock_profile_start, __lock_profile_end, __initcall_start,
__initcall_end, __presmp_initcall_end, __ctors_start, __ctors_end,
__end_schedulers_array, __start_schedulers_array, __start_bug_frames,
__stop_bug_frames_0, __stop_bug_frames_1, __stop_bug_frames_2,
__stop_bug_frames_3,

In the case of __initcall_start, __presmp_initcall_end, and
__initcall_end, turn the three variables into two proper ranges
introducing __presmp_initcall_start.

M3CM: Rule-18.2: Subtraction between pointers shall only be applied to
pointers that address elements of the same array

Since we are changing the body of is_kernel_text and friends, take the
opportunity to remove the leading underscores in the local variables
names, which are violationg namespace rules. Also make the local p__
variable const.

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

QAVerify: 2761
Signed-off-by: Stefano Stabellini <stefanos@xxxxxxxxxx>
CC: JBeulich@xxxxxxxx
CC: andrew.cooper3@xxxxxxxxxx
---
Changes in v11:
- split (__initcall_start,__initcall_end) and
  (__initcall_start,__initcall_end)
- make use of elf_note_bytediff
- use DECLARE_BOUNDS

Changes in v10:
- use DEFINE_SYMBOL
- move changes for _start, _end, _stext, _etext, _srodata, _erodata,
  _sinittext, _einittext to a different patch

Changes in v9:
- use SYMBOLS_SUBTRACT and SYMBOLS_COMPARE
---
 xen/arch/arm/xen.lds.S |  3 ++-
 xen/arch/x86/xen.lds.S |  3 ++-
 xen/common/kernel.c    | 13 +++++++++----
 xen/common/lib.c       |  7 +++++--
 xen/common/schedule.c  | 11 +++++++++--
 xen/common/spinlock.c  |  8 +++++---
 xen/common/version.c   |  9 +++++----
 7 files changed, 37 insertions(+), 17 deletions(-)

diff --git a/xen/arch/arm/xen.lds.S b/xen/arch/arm/xen.lds.S
index 1e72906..7ec762e 100644
--- a/xen/arch/arm/xen.lds.S
+++ b/xen/arch/arm/xen.lds.S
@@ -155,9 +155,10 @@ SECTIONS
        *(.init.setup)
        __setup_end = .;
 
-       __initcall_start = .;
+       __presmp_initcall_start = .;
        *(.initcallpresmp.init)
        __presmp_initcall_end = .;
+       __initcall_start = .;
        *(.initcall1.init)
        __initcall_end = .;
 
diff --git a/xen/arch/x86/xen.lds.S b/xen/arch/x86/xen.lds.S
index 6e9bda5..5ec89ae 100644
--- a/xen/arch/x86/xen.lds.S
+++ b/xen/arch/x86/xen.lds.S
@@ -210,9 +210,10 @@ SECTIONS
        *(.init.setup)
        __setup_end = .;
 
-       __initcall_start = .;
+       __presmp_initcall_start = .;
        *(.initcallpresmp.init)
        __presmp_initcall_end = .;
+       __initcall_start = .;
        *(.initcall1.init)
        __initcall_end = .;
 
diff --git a/xen/common/kernel.c b/xen/common/kernel.c
index 5766a0f..1743939 100644
--- a/xen/common/kernel.c
+++ b/xen/common/kernel.c
@@ -306,20 +306,25 @@ void add_taint(unsigned int flag)
     tainted |= flag;
 }
 
-extern const initcall_t __initcall_start[], __presmp_initcall_end[],
-    __initcall_end[];
+DECLARE_ARRAY_BOUNDS(initcall);
+typedef initcall_t presmp_initcall_t;
+DECLARE_ARRAY_BOUNDS(presmp_initcall);
 
 void __init do_presmp_initcalls(void)
 {
     const initcall_t *call;
-    for ( call = __initcall_start; call < __presmp_initcall_end; call++ )
+    for ( call = __presmp_initcall_start;
+                 presmp_initcall_lt(call, __presmp_initcall_end);
+                 call++ )
         (*call)();
 }
 
 void __init do_initcalls(void)
 {
     const initcall_t *call;
-    for ( call = __presmp_initcall_end; call < __initcall_end; call++ )
+    for ( call = __initcall_start;
+          initcall_lt(call, __initcall_end);
+          call++ )
         (*call)();
 }
 
diff --git a/xen/common/lib.c b/xen/common/lib.c
index 8ebec81..f4a2fd5 100644
--- a/xen/common/lib.c
+++ b/xen/common/lib.c
@@ -492,12 +492,15 @@ unsigned long long parse_size_and_unit(const char *s, 
const char **ps)
 }
 
 typedef void (*ctor_func_t)(void);
-extern const ctor_func_t __ctors_start[], __ctors_end[];
+DECLARE_BOUNDS(ctor_func, __ctors_start, __ctors_end);
 
 void __init init_constructors(void)
 {
     const ctor_func_t *f;
-    for ( f = __ctors_start; f < __ctors_end; ++f )
+
+    for ( f = __ctors_start;
+          ctor_func_lt(f, __ctors_end);
+          ++f )
         (*f)();
 
     /* Putting this here seems as good (or bad) as any other place. */
diff --git a/xen/common/schedule.c b/xen/common/schedule.c
index a957c5e..30e9b4a 100644
--- a/xen/common/schedule.c
+++ b/xen/common/schedule.c
@@ -67,8 +67,15 @@ DEFINE_PER_CPU(struct scheduler *, scheduler);
 /* Scratch space for cpumasks. */
 DEFINE_PER_CPU(cpumask_t, cpumask_scratch);
 
-extern const struct scheduler *__start_schedulers_array[], 
*__end_schedulers_array[];
-#define NUM_SCHEDULERS (__end_schedulers_array - __start_schedulers_array)
+/*
+ * Cannot use typedef because it would make the schedulers array
+ * const: the pointers become const, instead of the pointed
+ * struct schedulers.
+ */
+#define schedulers_t struct scheduler*
+DECLARE_BOUNDS(schedulers, __start_schedulers_array, __end_schedulers_array);
+#define NUM_SCHEDULERS (schedulers_diff(__start_schedulers_array, \
+                                        __end_schedulers_array))
 #define schedulers __start_schedulers_array
 
 static struct scheduler __read_mostly ops;
diff --git a/xen/common/spinlock.c b/xen/common/spinlock.c
index 6bc52d7..20439f7 100644
--- a/xen/common/spinlock.c
+++ b/xen/common/spinlock.c
@@ -318,8 +318,8 @@ struct lock_profile_anc {
 typedef void lock_profile_subfunc(
     struct lock_profile *, int32_t, int32_t, void *);
 
-extern struct lock_profile *__lock_profile_start;
-extern struct lock_profile *__lock_profile_end;
+typedef struct lock_profile* lock_profile_t;
+DECLARE_BOUNDS(lock_profile, __lock_profile_start, __lock_profile_end);
 
 static s_time_t lock_profile_start;
 static struct lock_profile_anc lock_profile_ancs[LOCKPROF_TYPE_N];
@@ -474,7 +474,9 @@ static int __init lock_prof_init(void)
 {
     struct lock_profile **q;
 
-    for ( q = &__lock_profile_start; q < &__lock_profile_end; q++ )
+    for ( q = &__lock_profile_start;
+          lock_profile_lt(q, &__lock_profile_end);
+          q++ )
     {
         (*q)->next = lock_profile_glb_q.elem_q;
         lock_profile_glb_q.elem_q = *q;
diff --git a/xen/common/version.c b/xen/common/version.c
index 223cb52..b4abf69 100644
--- a/xen/common/version.c
+++ b/xen/common/version.c
@@ -86,7 +86,8 @@ int xen_build_id(const void **p, unsigned int *len)
 
 #ifdef BUILD_ID
 /* Defined in linker script. */
-extern const Elf_Note __note_gnu_build_id_start[], __note_gnu_build_id_end[];
+typedef Elf_Note elf_note_t;
+DECLARE_BOUNDS(elf_note, __note_gnu_build_id_start, __note_gnu_build_id_end);
 
 int xen_build_id_check(const Elf_Note *n, unsigned int n_sz,
                        const void **p, unsigned int *len)
@@ -147,14 +148,14 @@ static int __init xen_build_init(void)
     int rc;
 
     /* --build-id invoked with wrong parameters. */
-    if ( __note_gnu_build_id_end <= &n[0] )
+    if ( !elf_note_lt(&n[0], __note_gnu_build_id_end) )
         return -ENODATA;
 
     /* Check for full Note header. */
-    if ( &n[1] >= __note_gnu_build_id_end )
+    if ( !elf_note_lt(&n[1], __note_gnu_build_id_end) )
         return -ENODATA;
 
-    sz = (void *)__note_gnu_build_id_end - (void *)n;
+    sz = elf_note_bytediff(n, __note_gnu_build_id_end);
 
     rc = xen_build_id_check(n, sz, &build_id_p, &build_id_len);
 
-- 
1.9.1


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

 


Rackspace

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