Skip to contentSkip to conversation

util/cacheinfo: fix crash when compiling with uClibc

PATCH In review [email protected] 3 participants 6 messages Oct 17, 2019 – Jan 20, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 util/cacheinfo: fix crash when compiling with uClibc

From: Carlos Santos <[email protected]>

uClibc defines _SC_LEVEL1_ICACHE_LINESIZE and _SC_LEVEL1_DCACHE_LINESIZE but the corresponding sysconf calls returns -1, which is a valid result, meaning that the limit is indeterminate.

Handle this situation using the fallback values instead of crashing due to an assertion failure.

---
 util/cacheinfo.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
util/cacheinfo.c +8 -2
index ea6f3e99bf..d94dc6adc8 100644
@@ -93,10 +93,16 @@ static void sys_cache_info(int *isize, int *dsize)
 static void sys_cache_info(int *isize, int *dsize)
 {
 # ifdef _SC_LEVEL1_ICACHE_LINESIZE
-    *isize = sysconf(_SC_LEVEL1_ICACHE_LINESIZE);
+    int tmp_isize = (int) sysconf(_SC_LEVEL1_ICACHE_LINESIZE);
+    if (tmp_isize > 0) {
+        *isize = tmp_isize;
+    }
 # endif
 # ifdef _SC_LEVEL1_DCACHE_LINESIZE
-    *dsize = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
+    int tmp_dsize = (int) sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
+    if (tmp_dsize > 0) {
+        *dsize = tmp_dsize;
+    }
 # endif
 }
 #endif /* sys_cache_info */
Signature · 1 line
2.18.1
#1 lore raw
Quoted 20 lines · On Thu, 17 Oct 2019 at 13:39, <[email protected]> wrote:

From: Carlos Santos <[email protected]>

uClibc defines _SC_LEVEL1_ICACHE_LINESIZE and _SC_LEVEL1_DCACHE_LINESIZE but the corresponding sysconf calls returns -1, which is a valid result, meaning that the limit is indeterminate.

Handle this situation using the fallback values instead of crashing due to an assertion failure.

---
 util/cacheinfo.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
util/cacheinfo.c +0 -0
index ea6f3e99bf..d94dc6adc8 100644

util/cacheinfo.c static void sys_cache_info(int *isize, int *dsize) · line 96

Quoted 5 lines
util/cacheinfo.c +1 -1
@@ -93,10 +93,16 @@ static void sys_cache_info(int *isize, int *dsize)
 static void sys_cache_info(int *isize, int *dsize)
 {
 # ifdef _SC_LEVEL1_ICACHE_LINESIZE
-    *isize = sysconf(_SC_LEVEL1_ICACHE_LINESIZE);
+    int tmp_isize = (int) sysconf(_SC_LEVEL1_ICACHE_LINESIZE);

Do we need the cast here ?

Quoted 4 lines
util/cacheinfo.c +3 -0
+    if (tmp_isize > 0) {
+        *isize = tmp_isize;
+    }
 # endif

util/cacheinfo.c static void sys_cache_info(int *isize, int *dsize)

Quoted 10 lines
util/cacheinfo.c +4 -2
 # ifdef _SC_LEVEL1_DCACHE_LINESIZE
-    *dsize = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
+    int tmp_dsize = (int) sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
+    if (tmp_dsize > 0) {
+        *dsize = tmp_dsize;
+    }
 # endif
 }
 #endif /* sys_cache_info */
--

thanks
-- PMM

#2 lore raw
Quoted 17 lines · Peter Maydell
Quoted 15 lines · On Thu, 17 Oct 2019 at 13:39, <[email protected]> wrote:

From: Carlos Santos <[email protected]>

uClibc defines _SC_LEVEL1_ICACHE_LINESIZE and _SC_LEVEL1_DCACHE_LINESIZE but the corresponding sysconf calls returns -1, which is a valid result, meaning that the limit is indeterminate.

Handle this situation using the fallback values instead of crashing due to an assertion failure.

---
 util/cacheinfo.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
Quoted 12 lines

util/cacheinfo.c static void sys_cache_info(int *isize, int *dsize) · line 96

Quoted 10 lines
util/cacheinfo.c +1 -1
index ea6f3e99bf..d94dc6adc8 100644
@@ -93,10 +93,16 @@ static void sys_cache_info(int *isize, int *dsize)
 static void sys_cache_info(int *isize, int *dsize)
 {
 # ifdef _SC_LEVEL1_ICACHE_LINESIZE
-    *isize = sysconf(_SC_LEVEL1_ICACHE_LINESIZE);
+    int tmp_isize = (int) sysconf(_SC_LEVEL1_ICACHE_LINESIZE);

Do we need the cast here ?

It's there to remind the reader that a type coercion may occur, since sysconf() returns a long and isize is an int.

Quoted 17 lines
Quoted 4 lines
util/cacheinfo.c +3 -0
+    if (tmp_isize > 0) {
+        *isize = tmp_isize;
+    }
 # endif

util/cacheinfo.c static void sys_cache_info(int *isize, int *dsize)

Quoted 10 lines
util/cacheinfo.c +4 -2
 # ifdef _SC_LEVEL1_DCACHE_LINESIZE
-    *dsize = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
+    int tmp_dsize = (int) sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
+    if (tmp_dsize > 0) {
+        *dsize = tmp_dsize;
+    }
 # endif
 }
 #endif /* sys_cache_info */
--

thanks
-- PMM

Signature · 4 lines
Carlos Santos
Senior Software Maintenance Engineer
Red Hat
[email protected]    T: +55-11-3534-6186
#3 lore raw
Quoted 50 lines · Carlos Santos
Quoted 17 lines · Peter Maydell
Quoted 15 lines · On Thu, 17 Oct 2019 at 13:39, <[email protected]> wrote:

From: Carlos Santos <[email protected]>

uClibc defines _SC_LEVEL1_ICACHE_LINESIZE and _SC_LEVEL1_DCACHE_LINESIZE but the corresponding sysconf calls returns -1, which is a valid result, meaning that the limit is indeterminate.

Handle this situation using the fallback values instead of crashing due to an assertion failure.

---
 util/cacheinfo.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
Quoted 12 lines

util/cacheinfo.c static void sys_cache_info(int *isize, int *dsize) · line 96

Quoted 10 lines
util/cacheinfo.c +1 -1
index ea6f3e99bf..d94dc6adc8 100644
@@ -93,10 +93,16 @@ static void sys_cache_info(int *isize, int *dsize)
 static void sys_cache_info(int *isize, int *dsize)
 {
 # ifdef _SC_LEVEL1_ICACHE_LINESIZE
-    *isize = sysconf(_SC_LEVEL1_ICACHE_LINESIZE);
+    int tmp_isize = (int) sysconf(_SC_LEVEL1_ICACHE_LINESIZE);

Do we need the cast here ?

It's there to remind the reader that a type coercion may occur, since sysconf() returns a long and isize is an int.

Quoted 15 lines
Quoted 14 lines
util/cacheinfo.c +7 -2
+    if (tmp_isize > 0) {
+        *isize = tmp_isize;
+    }
 # endif
 # ifdef _SC_LEVEL1_DCACHE_LINESIZE
-    *dsize = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
+    int tmp_dsize = (int) sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
+    if (tmp_dsize > 0) {
+        *dsize = tmp_dsize;
+    }
 # endif
 }
 #endif /* sys_cache_info */
--
Quoted 8 lines
Quoted 2 lines

thanks
-- PMM

--
Carlos Santos
Senior Software Maintenance Engineer
Red Hat
[email protected] T: +55-11-3534-6186

Hi,

Any chance to have this merged for Christmas? :-)

Signature · 4 lines
Carlos Santos
Senior Software Maintenance Engineer
Red Hat
[email protected]    T: +55-11-3534-6186
#4 lore raw
Quoted 60 lines · Carlos Santos
Quoted 50 lines · Carlos Santos
Quoted 17 lines · Peter Maydell
Quoted 15 lines · On Thu, 17 Oct 2019 at 13:39, <[email protected]> wrote:

From: Carlos Santos <[email protected]>

uClibc defines _SC_LEVEL1_ICACHE_LINESIZE and _SC_LEVEL1_DCACHE_LINESIZE but the corresponding sysconf calls returns -1, which is a valid result, meaning that the limit is indeterminate.

Handle this situation using the fallback values instead of crashing due to an assertion failure.

---
 util/cacheinfo.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
Quoted 12 lines

util/cacheinfo.c static void sys_cache_info(int *isize, int *dsize) · line 96

Quoted 10 lines
util/cacheinfo.c +1 -1
index ea6f3e99bf..d94dc6adc8 100644
@@ -93,10 +93,16 @@ static void sys_cache_info(int *isize, int *dsize)
 static void sys_cache_info(int *isize, int *dsize)
 {
 # ifdef _SC_LEVEL1_ICACHE_LINESIZE
-    *isize = sysconf(_SC_LEVEL1_ICACHE_LINESIZE);
+    int tmp_isize = (int) sysconf(_SC_LEVEL1_ICACHE_LINESIZE);

Do we need the cast here ?

It's there to remind the reader that a type coercion may occur, since sysconf() returns a long and isize is an int.

Quoted 15 lines
Quoted 14 lines
util/cacheinfo.c +7 -2
+    if (tmp_isize > 0) {
+        *isize = tmp_isize;
+    }
 # endif
 # ifdef _SC_LEVEL1_DCACHE_LINESIZE
-    *dsize = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
+    int tmp_dsize = (int) sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
+    if (tmp_dsize > 0) {
+        *dsize = tmp_dsize;
+    }
 # endif
 }
 #endif /* sys_cache_info */
--
Quoted 8 lines
Quoted 2 lines

thanks
-- PMM

--
Carlos Santos
Senior Software Maintenance Engineer
Red Hat
[email protected] T: +55-11-3534-6186

Quoted 3 lines

Hi,

Any chance to have this merged for Christmas? :-)

No, but it's queued now. ;-)

r~

#5 lore raw
Quoted 62 lines · Richard Henderson
Quoted 60 lines · Carlos Santos
Quoted 58 lines · Carlos Santos
Quoted 17 lines · Peter Maydell
Quoted 15 lines · On Thu, 17 Oct 2019 at 13:39, <[email protected]> wrote:

From: Carlos Santos <[email protected]>

uClibc defines _SC_LEVEL1_ICACHE_LINESIZE and _SC_LEVEL1_DCACHE_LINESIZE but the corresponding sysconf calls returns -1, which is a valid result, meaning that the limit is indeterminate.

Handle this situation using the fallback values instead of crashing due to an assertion failure.

---
 util/cacheinfo.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
Quoted 12 lines

util/cacheinfo.c static void sys_cache_info(int *isize, int *dsize) · line 96

Quoted 10 lines
util/cacheinfo.c +1 -1
index ea6f3e99bf..d94dc6adc8 100644
@@ -93,10 +93,16 @@ static void sys_cache_info(int *isize, int *dsize)
 static void sys_cache_info(int *isize, int *dsize)
 {
 # ifdef _SC_LEVEL1_ICACHE_LINESIZE
-    *isize = sysconf(_SC_LEVEL1_ICACHE_LINESIZE);
+    int tmp_isize = (int) sysconf(_SC_LEVEL1_ICACHE_LINESIZE);

Do we need the cast here ?

It's there to remind the reader that a type coercion may occur, since sysconf() returns a long and isize is an int.

Quoted 15 lines
Quoted 4 lines
util/cacheinfo.c +3 -0
+    if (tmp_isize > 0) {
+        *isize = tmp_isize;
+    }
 # endif

util/cacheinfo.c static void sys_cache_info(int *isize, int *dsize)

Quoted 10 lines
util/cacheinfo.c +4 -2
 # ifdef _SC_LEVEL1_DCACHE_LINESIZE
-    *dsize = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
+    int tmp_dsize = (int) sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
+    if (tmp_dsize > 0) {
+        *dsize = tmp_dsize;
+    }
 # endif
 }
 #endif /* sys_cache_info */
--
Quoted 2 lines

thanks
-- PMM

--
Carlos Santos
Senior Software Maintenance Engineer
Red Hat
[email protected] T: +55-11-3534-6186

Quoted 9 lines
Quoted 3 lines

Hi,

Any chance to have this merged for Christmas? :-)

No, but it's queued now. ;-)

r~

Ah, Easter, perhaps. :-)

Signature · 4 lines
Carlos Santos
Senior Software Maintenance Engineer
Red Hat
[email protected]    T: +55-11-3534-6186