util/cacheinfo: fix crash when compiling with uClibc
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
@@ -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
Quoted 20 lines · On Thu, 17 Oct 2019 at 13:39, <[email protected]> wrote:
From: Carlos Santos <[email protected]>
uClibc defines
_SC_LEVEL1_ICACHE_LINESIZEand_SC_LEVEL1_DCACHE_LINESIZEbut 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.
Signed-off-by Carlos Santos <[email protected]>--- util/cacheinfo.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)util/cacheinfo.c +0
-0
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
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_LINESIZEand_SC_LEVEL1_DCACHE_LINESIZEbut 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.
Signed-off-by Carlos Santos <[email protected]>--- 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@@ -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
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_LINESIZEand_SC_LEVEL1_DCACHE_LINESIZEbut 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.
Signed-off-by Carlos Santos <[email protected]>--- 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@@ -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
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_LINESIZEand_SC_LEVEL1_DCACHE_LINESIZEbut 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.
Signed-off-by Carlos Santos <[email protected]>--- 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@@ -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~
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_LINESIZEand_SC_LEVEL1_DCACHE_LINESIZEbut 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.
Signed-off-by Carlos Santos <[email protected]>--- 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@@ -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