Subject: | Segfaults on some fc13 |
Date: | Wed, 9 Apr 2014 11:57:34 +0000 |
To: | "bug-Sys-CpuAffinity [...] rt.cpan.org" <bug-Sys-CpuAffinity [...] rt.cpan.org> |
From: | Marcin Wielgosz <Marcin.Wielgosz [...] imc.ch> |
Hi,
I’ve been using highly modified version of your module and I found out that it tends to segfault on some of FC13 boxes(Linux and distribution is irrelevant here).
Program received signal SIGSEGV, Segmentation fault.
0x00000035e1682d84 in memset () from /lib64/libc.so.6
(gdb) backtrace
#0 0x00000035e1682d84 in memset () from /lib64/libc.so.6
#1 0x00000035e16c7dc4 in sched_getaffinity@@GLIBC_2.3.4 () from /lib64/libc.so.6
Here is a part of linux-sched_getaffinity.xs:
if(debug_flag) fprintf(stderr,"getaffinity0\n");
_set1 = &_set2;
if(debug_flag) fprintf(stderr,"getaffinity1 pid=%d size=%d cpuset=0x%d\n",
(int) pid, (int) CPU_SETSIZE, (int) _set1);
z = sched_getaffinity((pid_t) pid, CPU_SETSIZE, _set1);
if(debug_flag) fprintf(stderr,"getaffinity2\n”);
And some facts from /usr/include/bits/sched.h:
# define __CPU_SETSIZE 1024
typedef unsigned long int __cpu_mask; // size 4B
# define __NCPUBITS (8 * sizeof (__cpu_mask)) // 32
typedef struct
{
__cpu_mask __bits[__CPU_SETSIZE / __NCPUBITS]; // size 4B * [1024/32] = 128B
} cpu_set_t;
So, 'sched_getaffinity((pid_t) pid, CPU_SETSIZE, _set1)’ requests libc to fill out _set1(128B) and zero the rest up to 1024nth byte which is beyond the size of the structure and leads to segfaults. I’d recommend to replace CPU_SETSIZE with sizeof(_set2);
Secondly, this module works up to 32 cores and needs to be rewritten.
Marcin Wielgosz
System Integration Engineer
[Description: Description: http://www.imc.nl/Global/Logos/IMC-logo-rgb_150.gif]
IMC financial markets | Poststrasse 20, 6300, Zug, Switzerland | www.imc.nl <http://www.imc.nl/>
T +41 (0)41 560 32 05 | M +41 (0)79 570 03 05 | E Marcin.Wielgosz@imc.ch<mailto:Marcin.Wielgosz@imc.ch>
Show quoted text
________________________________
The information in this e-mail is intended only for the person or entity to which it is addressed.
It may contain confidential and /or privileged material. If someone other than the intended recipient should receive this e-mail, he / she shall not be entitled to read, disseminate, disclose or duplicate it.
If you receive this e-mail unintentionally, please inform us immediately by "reply" and then delete it from your system. Although this information has been compiled with great care, neither IMC Financial Markets & Asset Management nor any of its related entities shall accept any responsibility for any errors, omissions or other inaccuracies in this information or for the consequences thereof, nor shall it be bound in any way by the contents of this e-mail or its attachments. In the event of incomplete or incorrect transmission, please return the e-mail to the sender and permanently delete this message and any attachments.
Messages and attachments are scanned for all known viruses. Always scan attachments before opening them.